First post

Hi there!

You've found my blog, that's great! It's called 'Learning MSX machine code' and that's exactly what the purpose of this blog is: learning how to write a machine code program for a MSX computer. 

So why does anyone want to learn this...?

Well... that's a good question. The best reason is: just for fun. You'll not make money by learning this, you don't get a job with it. You should to do it because you like it, as a hobby. For me, someone who is almost 50 years old, MSX computers are nostalgia. I got a MSX-1 computer in the eighties, when I was about 12 years old and I really liked it. Not just for playing games, but also for writing my own programs. I learned MSX BASIC by by reading the computer manual, computer books and magazines. It was my first programming language and after a while I was good enough at it to make (simple) programs, like a text-adventure, a basic game with graphics or a sprite-editor. 

When I got older I lost interest in the MSX computer. I bought a different, faster computer and continued to enjoy programming as a hobby, learning new languages like Pascal, Actionscript, Javascript and Python. At some point I sold my old MSX-1. That's just the way things go, but nevertheless MSX still is special for me. Whenever I see an old MSX computer for sale I'm always interested and I would like to buy it. The same goes for MSX-books, magazines, games and other stuff. I'm not buying it because I know I'm not actually going to use it. Luckily there are emulators nowadays and once in a while I play some of my favourite old MSX games, like Kings Valley or Boulderdash. 

So why do I want to return to MSX-programming and especially programming machine code? That's just because it's something that I found too difficult when I was about 12 or 13 years old. I read a book and some articles about machine code, but could not get the hang of it. I messed around a bit with changing the videomemory of my MSX using the VPOKE command in BASIC, which gave some funny graphical effects, but I could not figure out how it actually worked. There was no internet at that time to get information or to ask questions on a forum and so I stuck to using BASIC. Nowadays there's a lot of information available and I want to see if I can now manage to learn this. Just for fun 😉

Learning curve

As I mentioned, machine code is not the most simple thing to learn. Machine code in itself is actually pretty simple and straightforward, but to get things done you need a lot of short instructions and also quite a bit of technical computer knowledge. For example, take a simple task like displaying some text on the screen. In BASIC this can be done by just entering a simple command and pressing <ENTER>:

print "Hello world! 





But with machine language (what is used to create machine code) it would look something like this:

; bios call to print a character on screen
CHPUT:      equ 0x00a2

            ; the address of our program
            org 0xD000

start:
            ld hl, message
mainLoop:   ld a, (hl)
            cp 0
            ret z
            call CHPUT
            inc hl
            jr mainLoop

message:
            db "Hello world!",0

            ; use the label "start" as the entry point
            end start

After writing this program in an editor you have to translate (assemble) it to machine code, then transfer it to your computer or emulator, load and execute it. Which eventually has the same result....

And what happens if there is a bug (an error) in your program? If you make a mistake in BASIC, you get an error message. Just figure out what goes wrong, fix the problem and try again:





But if there's a bug in your machine code program it is not so obvious what goes wrong. Your computer might just crash. Good luck with that 😉

So machine code has a steep learning curve. Why even bother to learn it? I think there are 2 main benefits:

  1. Speed
    Machine code is much faster then BASIC, which first has to be 'translated' to machine code before it can be executed. You can't write a fast graphic game in MSX-BASIC. You really need (some) machine code for that.

  2. Control
    Everything that a computer has to offer can be accessed with machine code. Higher programming languages don't have all the options that machine code has. Machine code gives you full control.

And now?

At this moment I am a real machine code beginner. I've collected a lot of information (websites, documents, books, ...), I have read quite a bit about it and even tried a few things. That's just a very little step in the world of machine code. So how can this blog help someone to learn MSX machine code? The purpose of this blog is twofold:

  1. For me it's a way to document my learning so that I keep all my information together for reference. 
  2. For the reader it hopefully provides information to start creating MSX machine code with a slightly less steep learning curve. You can it learn together with me. 
Don't expect any flashy results right from the start. This blog is not (yet) about making a full featured graphical action game with cool music and sound effects. Nope, it's more about making the computer beep, putting a single character on the screen. It's about understanding the basics. But I can tell you that just to hear a beep that is produced by handmade machine code can be very satisfying... 😉

Disclaimer (as in 'I told you so')

  • I'm a beginner, so I will make mistakes and there will be errors in the information that I post. Well...that's what learning is all about, isn't it? Making mistakes. Feel free to add comments to the blogs with your questions or remarks so that I can update my information. 

  • I don't know how long I will be writing this blog. I'm interested in machine code now, but who knows, I might be done with it in a while. We'll see how it goes. 

  • This blog will be only about MSX-1 computers as that was the model that I owned. But once you master machine code for the MSX-1 you can easily make the step to MSX-2. 

  • Are you new to programming? Are you new to MSX computers? Then this blog might still be a bit to hard for you. I assume that you already have some programming experience and that you know what an MSX computer is. 

Next blog

In the next blog we will get started. I'll cover some basic knowledge about MSX computers, and explain what tools we need to create machine code. And by then we're actually going to make the first program. The inevitable 'Hello world!'


Reacties

  1. Hey Paul, great stuff! Send me an email and let's learn together. For 30 years I've been wanting to learn, now it's the chance, we have all the info.

    BeantwoordenVerwijderen

Een reactie posten

Populaire posts van deze blog

#1 - Hello world! (part 1 of 2 - basic knowledge)

#2 Hello world (part 2 of 2 - programming)

#3 More on BIOS calls for the text screen