“At last!”, the followers cheer, “He’s doing the screen!!” 🙂
Yes! But only in a very simple way to begin with… I once mentioned that the screen starts at address 16384, and is 6144 bytes long. This means that you could use roughly the same code as the colour-fill example to fill it with content (maybe you already have?)
That routine can be used for filling with a single value, but it’s actually somewhat overblown for that task, so lets use a quicker, and much simpler method.
LDIR – LoaD Increase and Repeat – is used for copying a block of memory from one location to another. You set HL to the memory address what you want to copy from, DE to the address you want to copy to, and BC for the number of bytes to copy. Simples! So, for example, to copy the first 6144 bytes of ROM into the screen, you’d use:
ld hl, 0 ld de, 16384 ld bc, 6144 ldir
Very neat, and pretty fast. (There are faster methods, but that’s good for starters, and actually for most of the cases you’re likely to need). You can also be a little crafty with it, if you know how it works…
In the above case, it starts by copying the data at 0 (from HL) into 16384 (to DE). HL and DE are then increased (to 1 & 16385 respectively), and BC is decreased (to 6143), and it keeps doing that until BC is zero. Knowing that, it’s straightforward to use it to fill a block of memory with a single value (or even a set number of repeating values), if you copy to an area inside the area of memory you are copying from.
ld hl, 16384 ld de, 16385 ld bc, 6143 ld (hl), 15 ldir
We initially puts 15 into 16384, and then LDIR copies that value into 16385, then copies from 16385 to 16386, and so on. Notice that the loop is one shorter than before, as we’ve already set the first value.
With this, you should be able to modify the colours program to fill the screen with a value (zero to blank it) before we colour it, and then wait for a keypress afterwards before returning to BASIC. And if you’re feeling adventurous, see what happens if you try to fill half the screen (the first 3072 bytes) with one value, and the other half (the last 3072) with another – it might not show quite what you are expecting… the explanation is next…