One final splash of colour

There’s only one thing left to mention about colour – and that’s the border.

You can set it to any of the 8 main colours – bright and flash have no effect – using the ‘out’ command.

‘out’, and it’s mirror ‘in’, are somewhat special, as what they do is entirely down to the hardware you run it on.  Out writes something to the hardware, where In reads from it. Both use a ‘port address’ – just a term for a certain part of the hardware.

To see the border to red, using the following:

ld a, 1
out (254), a

And that’s it!  The colour, 0 to 7, is in A, and we send that out of port 254 – which the machine interprets as wanting to set the border colour.  That port does other things to, both writing to, and reading from, but those are for another day…

There’s is literally nothing more to learn about displaying colours on the Spectrum – you can now put any colour you like on both the screen and the border 🙂

14 thoughts on “One final splash of colour

  1. Really hope you keep this going Bob. Looking forward to when you get to topics I’m not as clear on…which I suspect won’t be long 🙂

    Liked by 2 people

      1. It’s fun to get back to the Z-80. Really back to the roots stuff – and a universe away from Microsoft Azure development (where I am at now). It’s a great series you have here, as I’m a ZX-81 person (parents couldn’t afford a Spectrum but could afford a 2nd hand ZX-81).

        Personally, I’m looking forward to where you start banging pixels on-screen. But that might be some distance away…

        Liked by 1 person

      2. yes you’ve hit the ground running haven’t you 🙂 within a lesson or two theres gonna be so much information that anyone following will be able to experiment with and get a lot from.. that presenting material too fast will be difficult for us lot to keep up with.
        Guessing you will be discussing plotting a coloured square in a chosen position soon.
        Just thought I’d give you some feedback to let you know your efforts are being appreciated.

        Liked by 1 person

      3. I for one don’t expect you to post everyday Bob. I am just thankful that you have put your time into this. All the books I have read just bang on with all the arithmetic (Binary, hex, add, dec, two’s compliment, setting flags, handling virtual registers etc) for the first few chapters without any physical tutorials and code examples. Every time I have closed the book thinking this is far too heavy for me and just gave up. You have taught me more by the way of doing things which are very comparable to writing the same in Basic and now I am starting to grasp it.

        Liked by 2 people

      4. Being able to plot a pixel at a specific coord without using the rom routine (which I also can’t get to work). i.e converting x,y into a screen address. That’s my sticking point at the moment (no pun intended).


      5. I had a headache or two with the ROM PLOT routine, and here’s what I did (this is working here in a piece of code):

        ld a, (ypos) ; crappy hack to easily plot the pixel
        ld b, a ;
        ld a, (xpos) ;
        ld c, a ;
        call 8937 ; ROM PLOT – not the entry point, this point assumes BC is setup

        the ROM routine uses settings in P_FLAG sysvar (23697) to control over, inverse etc.

        You could probably load BC directly if you had the x and y points in adjacent memory locations but I haven’t in my case (I’m using another rom routine to print the contents of BC, so to make life easier I have zero byte values padding the x and y)


  2. Woo! Minor success! As a test, I wondered if I could loop through the colours and stop at a predetermined one. More of a test to see if I could do it. And, yes, I could, though it feels a little lumpy to me.

    ld a,0
    inc a
    out (254), a
    ld b,a
    and 1
    ld a,b
    jp nz, LOOP2

    The thing that I feel is wrong is that I have to use A to do all the additions, so I find myself copying it to B, doing the CPL, and then copying B back to A.

    Is that right? Whenever I try to use just B, pasmo tells me it’s expecting A.

    Still, I’m pretty pleased I got something beyond your tutorial working, even if there may be a better way!

    Liked by 1 person

    1. That’s good! Z80 only has a limited set of instructions, and most of those involved with calculations either work on A or HL, and little else. It’s such limitations that make it a challenge, but also so rewarding when it does work. You’ll soon learn those restrictions though 🙂

      Liked by 1 person

Leave a Reply

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

You are commenting using your 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