Let there be colour!

So, for the first program in assembly, we’re going to draw a block of colour.  It’s very simple – just four lines of actual code – but it’ll test that your setup works, and then we can move more quickly after that.

Open your code editor, and create a new file – call it ‘First.z80‘, or ‘First.asm‘.  The name, and file extension, could probably be anything, but z80 & asm are both commonly used, and good to describe what kind of file it is, and might be what instructs your syntax highlighter to treat the file as Z80 assembly.  Now type the following into your file:

org 32768
ld a, 32
ld (22528), a

END 32768

And that’s it, just six lines.  Make sure the file has been saved.

Now you need to convert your code into something the Speccy will understand, by compiling it.  In the case of Pasmo, this needs to be done on the command line, using the command:

pasmo --tapbas first.z80 first.tap

That will instruct Pasmo to compile your first.z80 file into first.tap, and create it as a TAP file which the Spectrum will understand.  The option –tapbas tells Pasmo to create a BASIC loader for your code, which it will then use to load the code, and run it – all automatically.  You might need to add the path to the location you installed Pasmo in, so it can be found.  It’s best to run it from the folder your stored your code file though, so the TAP file is created there as well.

And finally you should be able to load the created file – first.tap – into your emulator to run it.  And the result should look something like this:


Wow!” you must be thinking, “It’s drawn a green square!”  I promise you it’ll get more interesting soon!

If it doesn’t work, then the problem could be one of the following:

  1. You’ve mistyped the program – make sure it is exactly as shown above.
  2. Your compiler doesn’t understand it.  The first four lines are very standard Z80 code, so there shouldn’t be a problem with those if it’s been typed correctly.  The problem would most likely be with the last line – END 32768 – which is used to tell Pasmo to stop compiling, but more importantly where to start running the code from – in our case 32768 – as it matches the ‘org’ instruction in the first line.  If you use a different compiler you might need to find out how it handles that.
  3. Your compiler can’t create a TAP file.  Again, you’ll likely have to check your compiler’s documentation as to how to get this to work.  If your compiler can create a TZX file that’s just a good, but if it can do neither then things could get difficult for you – and so is probably best that you try to find one that does.

Hopefully it all works though, and you’ve got that warm fuzzy feeling of success.  In the next post I’ll describe what exactly it is that you wrote, and why it does what it does.

13 thoughts on “Let there be colour!

  1. Inspired to have have a look into zx81 programming after seeing your amazing results on youtube video..looking forward to following these tutorials. Keep up the fine work!


    1. The Spectrum is an improved ZX81, and so much of what I cover will work on both, although graphics are handled differently, no colour or sound, and a few other things. I’ll be writing some special posts about ZX81-specifics later on.


  2. I’m running into an issue when executing code compiled with pasmo. I’m including a line in BASIC at the beginning of my program:

    defb _NL
    basic_0010: defb 0,10 ; 10 PRINT AT 0,0;”SCORE=000″
    defw basic_0020-basic_0010-4
    defb _PRINT,_AT,_0,_CMA,_0,_SMC,_DQT,_S,_C,_O,_R,_E,_EQU,_0,_0,_0,_DQT
    defb _NL

    It compiles with no issue. Unfortunately, when I run the program, I have a C/10 error. It is probably because the line in non well formed. But I have no clue what it is. When I list it, is seems correct 😦


    1. Sorry Bruno, but I’m not entirely sure what your code is meant to do – but I think your problem is that you can’t simply put a BASIC line into code as characters and expect it to work – numbers especially don’t work that way.

      Liked by 1 person

    2. I *think* any number in BASIC has to be followed by its 5-byte internal exponent+mantissa representation. You could maybe use VAL “0” instead of zero?

      I really don’t know though – I’d just do it in machine code, especially as the ZX81 has a character mapped display and you can just copy the string into the display directly

      Liked by 1 person

      1. You’re right Bob. Easy in machine code. I was lazy… However, I can still find usefulness in being able to write BASIC like this, for instance when I first tried Rear Gunner. I’m using ZX-IDE for that, it has the ability to let you embed BASIC natively. Now I’m trying the same with pasmo. That being said, you’re right about number representation. I looked at the hex code generated through ZX-IDE and can confirm your assumption. I’ll try your suggestion to use VAL after my nap (long run this morning got me exhausted :-))


  3. The following code works:
    basic_0010: defb 0,10 ; 10 PRINT AT VAL “0”,VAL “0”;”SCORE=000″
    defw basic_end-basic_0010-4
    defb _PRINT,_AT,_VAL,_SPC,_DQT,_0,_DQT,_CMA,_VAL,_SPC,_DQT,_0,_DQT,_SMC,_DQT,_S,_C,_O,_R,_E,_EQU,_0,_0,_0,_DQT
    defb _NL
    As you suggested. It’s actually for the same reason that one has to call machine code with RAND USR VAL “16514”!

    Thanks a lot. In the meantime, I replaced my BASIC lines with machine code 🙂

    Liked by 1 person

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google photo

You are commenting using your Google account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s