So far we've only had WLA DX directives. Now it's time for some code.

;==============================================================
; Boot section
;==============================================================
    di              ; disable interrupts
    im 1            ; Interrupt mode 1
    jp main         ; jump to main program

Nearly all SMS programs start this way.

The first three lines are just a big comment to make it clear what's going on here.

The first actual Z80 instruction is di. This means Disable Interrupts. Interrupts are things which cause code execution to jump to somewhere else ("interrupting" the program flow) to handle something, and we don't want that to happen until we're ready.

Next is im 1. This sets the Interrupt Mode of the Z80. For various reasons, the only one it makes sense to use is mode 1. So that's what we set it to.

Now we've got the most important two things done (to stop our program flow being affected) we can get on with the coding. For technical reasons, the start of the ROM is important and reserved for certain things so our "regular" code should be somewhere else. So we want to "jump" to where that is. Later in the code I've defined a label called "main". The CPU will go there and carry on executing the instructions after the label. We'll get to there in a moment.

Note that I've added a comment on each line telling what the instruction means. These are very verbose and once you're more advanced you'll think they're a bit unnecessary, since they don't tell you anything more than the instructions themselves.


< Assembler directives | Lesson 1 | Pause Handler >