Starting MSX assembly part 2

May 11, 2019 - by Paul Bosselaar

So, in the previous post we started with a small assembly program to produce a beep:

    db $FE     ; magic number
    dw Begin    ; begin address of the program
    dw End - 1  ; end address of the program
    dw Execute  ; program execution address (for ,R option)

    org $C000   ; The program start at C000h in the MSX's RAM
Begin:
Execute:
    CALL $C0  ; Call the BEEP bios routine
    ret
End:

What I did not talk about was how to actually use an assembler to create an actual file which the MSX can execute. So let’s do that now.

Sjasmplus

We’ll be using Sjasmplus in this tutorial. Sjasmplus is available for Windows, Mac and Linux so no matter what system you are using (hi ray2day!) you can get started.

Download Sjasmplus from https://github.com/sjasmplus/sjasmplus/releases/tag/20190306.1 and install it somewhere in your path. If you do not know how to do this, then simply copy the sjasmplus executable in the same directory as where you will put your .asm files. The site has releases for Windows and Mac available. For Linux you’ll have to compile it yourself (e.g. apt install cmake libboost-all-dev followed by mkdir build && cd build; cmake; make)

Now create a new text file and put the assembly source from above in it. Save the file somewhere as beep.asm. Now open a commandline or terminal window and go to the directory where the beep.asm file is. The following commandline should assemble the MSX program:

sjasmplus beep.asm --raw=beep.bin

That should result in the following output:

$ sjasmplus beep.asm --raw=beep.bin
SjASMPlus Z80 Cross-Assembler v.20190306.1+++WiP
Pass 1 complete (0 errors)
Pass 2 complete (0 errors)
Pass 3 complete
Errors: 0, warnings: 0, compiled: 12 lines

Next to the beep.asm file should now be an beep.bin file as well. Move this file to your MSX or emulator and bload"beep.bin",r should result in a well known sound. For quick testing I usually start the OpenMSX emulator with the current directory as disk A.

paul@paul-XPS-13-9360:~/git/msx/examples$ ls
beep.asm  beep.bin
paul@paul-XPS-13-9360:~/git/msx/examples$ openmsx -machine Boosted_MSX2_EN -diska .

beep

Yes, a screenshot, of a program that only makes a small sound. Oh well ;)