Blog

Category Archives: MSX


Relearning MSX #30: Complex conditional statements in MSX-C

Posted by in How-to,MSX,Retro,Technology | October 13, 2015

In the last post we learnt how to use comparisons in C. This time we’ll see some properties of the comparison operators and also how to test on more complex conditions.

Structure of conditional statements: comparison values

Until now we’ve only seen conditional statements that use the relational operators that we saw in the previous post. However, in adition to these relational operators we can use almost anything as the condition. For example, the code below shows how to test a condition elegantly:

if() condition on MSX-C

(Click to enlarge)

In this example, whether the puts() statement will run or not depends on the value of whatever is inside the parentheses following the if keyword:

  • If the value inside the parentheses is zero, the condition is false and the puts() does not run
  • If the value inside the parentheses is anything other than zero then the condition is true and the puts() statement runs

Because of this, the code above will not do anything if the variable error contains a zero, and it will print the message “Something bad happened.” if it contains any non-zero value.

Read more ›

Relearning MSX: Roadmap

Posted by in How-to,MSX,Retro,Technology | October 12, 2015

Wow, it’s been already almost 30 posts of the Relearning MSX series. Thanks so much for your encouragement and nice comments! And especial thanks to the supporters who are making this possible.

I think this is a good time to see what’s going to come in the future posts. The remaining subjects covering MSX-C are these:

  • Loops
  • Other control structures (break, continue, case…)
  • Handling numeric values with printf()
  • How values are stored in the MSX memory
  • Formatted output with printf()
  • Screen control characters
  • Escape sequences
  • Graphical characters
  • Functions (2-3 chapters)
  • Storage classes and scope of variables
  • Pointers (2-3 chapters)
  • String arrays
  • Structured data and creating types (1-2 chapters)
  • Creating and reading files (2-3 chapters)
  • Essential library functions (3-5 chapters)

This will keep us busy for about 25-30 more chapters and the schedule is well defined already. After completing these we’ll have a pretty solid base of the C language to tackle what’s coming next: the fun stuff, the MSX-especific subjects.

In no particular order:

  • The MSX graphic modes
  • Organization of the video memory
  • Sprites
  • Game control: cursor keys, triggers, joystick, mouse
  • Interrupts
  • Slots and subslots
  • Memory mappers
  • Sound effects
  • Playing music
  • BIOS routines
  • System work area and variables
  • PCM
  • etc

All these subjects will come from the several books I have here:

  • MSX2 Technical Handbook
  • MSX turbo R Technical Handbook
  • MSX-Datapack I, II and III
  • …and others

There’s no schedule decided for these yet. We’ll talk about these subjects in the order we need them, so if there’s anything you’d like to see covered, don’t wait and just ask for it!

And now the important part: please support these posts with a small donation, because I write during my free time and sometimes other priorities take precedence. Increasing the amount of donations increases the priority of writing these articles.

Thanks for your support!

Relearning MSX #29: Conditional statements in MSX-C

Posted by in How-to,MSX,Retro,Technology | October 8, 2015

We’ve seen already how to read from the keyboard, perform some basic operations, and print results on the screen. This may be enough for a few very especific situations, but even the simplest programs will at some point need to take decisions based on the value of a certain variable. This is where conditional statements come in.

The smallest component of a program: statements

Before I explain conditional statements we need to understand what a statement is. To put it simply, a statement in C is a piece of code that performs an operation. So far we’ve seen two types of statements:

  • Assignment statements (assigning a value to a variable):
    i = 1234;
    c = 'a';
    c = getch();
    
    
  • Calls to functions (performing an operation by calling a single function):
    putchar('a');
    puts("abc");
    
    

Note something very important: all of these end in a semicolon (;). While not technically correct, we could think of the semicolon as part of the statement.

These two types of statements are essential. We can’t write useful programs without them. However, they are not enough. We can’t code useful programs with just these two either. We need something else: conditional statements and loops.

Read more ›

Relearning MSX #28: Keyboard input

Posted by in How-to,MSX,Retro | October 6, 2015

In the previous two posts we learnt how to operate with values stored inside variables in our program.

This time we’re going to see how to read characters and text strings from the keyboard in MSX-C.

Reading a single key press: getch()

MSX-C comes with a few functions to read a single character from the keyboard, but probably the easiest to understand is getch(). Let’s see an example:

GETCH1.C (Click to enlarge)

GETCH1.C (Click to enlarge)

Read more ›

Tecnobytes’ MSX Ethernet cartridge

Posted by in Gadgets,Hardware,MSX,Retro,Technology | October 3, 2015

I finally got my Ethernet cartridge from Tecnobytes Classic Computers. It works like a charm on my FS-A1GT with the Internestor Lite TCP/IP stack and related network utilities.

Tecnobytes' MSX Ethernet on the FS-A1GT (click to enlarge)

Tecnobytes’ MSX Ethernet on the FS-A1GT (click to enlarge)

The cartridge is very well built. It has a single Ethernet port mounted on the right side of the case, with two status LEDs next to it: one for power and another for link/operation.

obsonet_msx_ethernet_cartridge

Click to enlarge

Click to enlarge

Click to enlarge

The Ethernet controller supports only 10 mbps links, but that’s not a problem because the TCP/IP stack can only reach a theoretical 30 KB/s transfer speed tops. According to Konamiman, this is because Internestor Lite sends and receives a single 512 byte packet per interrupt, or every 1/60 of a second. In practice, during my tests the average speed I saw was about 8 KB/s when downloading a file from an FTP server.

Konamiman has developed several applications that work with his TCP/IP stack. They’re available in his home page. Among these there are:

  • An FTP client, to transfer files from servers on the Internet
  • An NTP client to synchronize the clock of your MSX with an Internet server
  • A basic telnet client
  • A text-based Twitter client
  • A Dropbox client
  • FTP and SMB servers, to share the files hosted in your MSX

Hopefully we’ll see support for this board in the openMSX emulator in order to do some development.

 

Relearning MSX #27: Variables and arithmetic operations in MSX-C (part 2)

Posted by in How-to,MSX,Retro,Technology | September 30, 2015

In the previous post we saw a couple of variable types and the basic arithmetic operators. Today we’ll complete this part by taking a look at the bitwise operators and seeing a couple of characteristics of the char type.

Bitwise arithmetic operators

You may be aware already that computers store all data internally in binary. This is also the case with all the data types in MSX-C. As an example, the table below shows how some integer values are represented internally in the MSX computer memory:

Integer values represented in binary

Integer values represented in binary

The computer always works in binary, but in most cases we don’t care how MSX-C stores data internally because the compiler handles these details for us. However, there are situations when working with binary data makes sense, as in the case of working with graphics or programming hardware devices.

Read more ›

Relearning MSX #26: Variables and arithmetic operations in MSX-C (part 1)

Posted by in How-to,MSX,Retro,Technology | September 29, 2015

In the previous post we saw how to print text and numbers on the screen. This time we’ll learn how to use variables and how to operate with them.

You probably know already what a variable is. It’s just some place in the computer memory that we use to store a piece of data. In C, a variable can contain data of one of several basic types. Let’s take a look at them.

Character variables – the char type

We have already seen this type in some of the examples in previous posts. The program below assigns the character ‘X’ to the character variable c and prints it to the screen using putchar():

26-1.C (Click to enlarge)

26-1.C (Click to enlarge)

Read more ›

Memories from 1993

Posted by in MSX,Personal,Photography,Retro | September 18, 2015

I had these very old photos lying around and scanned them. This was my desk in my room around 1993. The computer on the left is an MSX2 (a Philips NMS 8280). The other one is a Commodore Amiga 500 with a 1084S display.

JaviLM_room_1993_1

On the shelf to the right there were a few boxes of floppy disks containing several hundreds of them. (Click to enlarge)

JaviLM_room_1993_2

Philips NMS 8280 with an FM-PAC clone and Philips’ Music Module. I used the cassette deck to amplify the sound from the MSX2. (Click to enlarge)

How about yours? Do you also have photos of your old computers?

Relearning MSX #25: Printing on the screen in MSX-C

Posted by in How-to,MSX,Retro,Technology | September 14, 2015

The last two posts were very technical: we saw how to write assembler routines and use them in MSX-C and also the opposite, how to write MSX-C code and then use it in assembler programs.

Today we’re going to go back to where we left it in chapter 18 and continue learning the basics of MSX-C. First, we’re going to see how to display text and numbers on the screen.

Displaying characters one at a time: putchar()

We already saw the function putchar() in chapter 18, but we didn’t explain at the time what this function does.

putchar() outputs a single character to the screen. We can pass the character inside single quotes (this is known as a character constant), or we can pass a variable that contains the character we want to output.

Let’s see a very simple example:

25-1

25-1.C (Click to enlarge)

Read more ›

Relearning MSX #24: Calling MSX-C functions from assembler

Posted by in How-to,MSX,Retro,Technology | September 9, 2015

We saw in the previous post how to run assembler routines from MSX-C. I’m sure you’re about to ask whether it’s possible to do the opposite: Is it possible to write programs in assembler and use the functions from the MSX-C Standard Library or the MSX-C Library disk?

I’m glad you asked. Yes, it’s possible, and it’s actually very easy to do.

Here’s how.

Calling MSX-C library functions from assembler programs

The rules that we saw for how MSX-C passes parameters to assembler functions also apply to MSX-C’s own library functions. This means that we can leave arguments in the CPU registers or in the stack as appropriate and call the function just like that.

As always, let’s see an example:

example

EXAMPLE.MAC (Click to enlarge)

Read more ›