
S13 drew a ship into the bitmap and rubbed it out again each frame. Over a plain sky that is a fill. Over scenery it isn't: whatever the ship covered has to come back exactly as it was, every frame, and doing that with the CPU means reading and writing every byte under it.
The command engine copies. One command puts a rectangle of background back from a clean copy kept out of sight; another draws a shape over it with its colour-0 dots left transparent. Together they make a software sprite: as many as you like, as big as you like, in all sixteen colours, over any picture. The TC-01's chip could draw nothing over the screen but its own sprites.
All three take a source (SX, SY), a destination (DX, DY) and a size (NX, NY), in S16's registers, with S16's lines numbered on through the pages.
HMMM (CMR = D0h) copies a rectangle byte for byte. In Graphics 4 a byte is two dots, so it ignores the lowest bit of SX, DX and NX: copies start and end on even dots.
YMMM (CMR = E0h) copies from DX to the right-hand edge of the screen, NY lines from line SY to line DY. There is no SX and no NX: the strip is always as wide as the space from DX to the edge. With DX = 0 that is whole lines, which makes it the simplest way to say "copy these lines there".
LMMM (CMR = 90h + a logical operation) copies dot by dot through S16's logical operations. With TIMP (98h), dots of colour 0 in the source leave the destination as it was: the shape is drawn, its background isn't. With IMP (90h) the 0s are copied too.
HMMM and YMMM move bytes, LMMM moves dots. Use the byte copies where the rectangle starts on an even dot and needs no logical operation, and LMMM where it doesn't.
A copy needs a source that the player never sees. You have three places for one, from S5:
The listing keeps its clean background in page 2 and the ball's picture in the expansion.
Before the command engine can copy a graphic, it has to be in video memory. Put it there the way S5 did: set the address and write the bytes to port 8. Do it once, at the start, into a page you never show. From then on, every copy is the command engine's work, not your program's.
Copies can build a picture as well as move one. Draw one 16 x 16 tile with three HMMV fills. Then copy it to its right: 32 wide. Copy those 32 to their right: 64. Four HMMM copies and the row is 256 dots wide. Then YMMM, from DX = 0, doubles it downwards the same way: 16 lines, 32, 64, 128, 256. Eleven commands fill a whole 32K page.
Three pages of Graphics 4 do the job:
| Page | Lines (y) | Holds |
|---|---|---|
| 1, 08000h | 256-511 | the screen (R#2 = 3Fh) |
| 2, 10000h | 512-767 | a clean copy of the background, never shown |
| expansion | 0- | the ball's picture, 16 x 16 |
Each frame, for each sprite:
With two sprites or more, restore them all, then draw them all. Restore one, draw it, then restore the next, and the second restore can copy clean background over part of the first sprite where they overlap.
Keep x even, because the restore is a byte copy. At an odd x HMMM still copies from the even dot below it, and whenever the ball moves left a column of the old ball's dots is left behind. Either move in steps of two, or restore with LMMM (IMP) instead, which works at any dot.
What it costs: the clean copy is a page of video memory, and a sprite is two commands a frame. The CPU only writes 30 bytes to set them off and polls CE; it never touches the picture's bytes.
; S17: software sprites made by the command engine, in Graphics 4.
; Two balls bounce over a checkerboard. Each frame, for each ball, HMMM
; copies the background back from a clean copy, and LMMM with TIMP
; draws the ball at its new place with colour 0 left transparent.
; Runs for 500 frames (10 seconds).
;
; Where everything is, as the command engine counts lines (256 a page):
; page 1, lines 256-511 (VRAM 8000h, R#2 = 3Fh): the screen
; page 2, lines 512-767 (10000h): the clean background, never shown
; the expansion RAM, at (0,0): the ball's picture
; MOS's own screen, in the first 16K, is left alone.
ORG 256
DI
; --- Graphics 4, showing page 1
LD A, 06h
LD B, 0
CALL setreg
LD A, 3Fh
LD B, 2
CALL setreg
; --- sprites out of the way (attribute table at 1FA00h: Y = 216)
LD A, 7
LD B, 14
CALL setreg
XOR A
OUT (9), A
LD A, 3Ah + 40h
OUT (9), A
LD A, 216
OUT (8), A
LD A, 0F7h
LD B, 5
CALL setreg
LD A, 03h
LD B, 11
CALL setreg
EI
; --- the background, built in page 2 by the command engine
LD HL, tile1 ; a 16x16 tile: colour 4 ...
CALL send
LD HL, tile2 ; ... with two squares of colour 5
CALL send
LD HL, tile3
CALL send
LD HL, 16 ; double it across: 16, 32, 64, 128 -> 256 wide
across: LD (wide+4), HL ; DX = the width so far
LD (wide+8), HL ; NX = the same
PUSH HL
LD HL, wide
CALL send
POP HL
ADD HL, HL
BIT 0, H ; until 256
JR Z, across
LD HL, 16 ; then down with YMMM: 16, 32, 64, 128 -> 256 lines
down: PUSH HL
LD DE, 512
ADD HL, DE
LD (deep+6), HL ; DY = 512 + the depth so far
POP HL
LD (deep+10), HL ; NY = the same
PUSH HL
LD HL, deep
CALL send
POP HL
ADD HL, HL
BIT 0, H
JR Z, down
; --- the screen: the whole background copied to page 1
LD HL, copybg
CALL send
; --- the ball's picture into the expansion RAM
CALL upload
; --- the frame interrupt (S7)
CALL irqon
LD A, 0E0h
LD B, 1
CALL setreg
EI
; --- the game loop: every frame, both balls
main: CALL waitf
LD IX, ball1 ; 1. the background back under both balls
CALL restore
LD IX, ball2
CALL restore
LD IX, ball1 ; 2. move them
CALL move
LD IX, ball2
CALL move
LD IX, ball1 ; 3. draw them at their new places
CALL draw
LD IX, ball2
CALL draw
LD HL, (TICKS)
LD DE, 500
OR A
SBC HL, DE
JR C, main
; --- put the machine back for MOS
LD A, 0C0h
CALL irqoff
CALL tomos
RET
onframe: RET ; nothing to do in the interrupt
; --- restore: HMMM 16x16 from the clean copy, at the ball IX's place
restore:
LD A, (IX+0) ; x
LD (rest+0), A ; SX
LD (rest+4), A ; DX
LD A, (IX+1) ; y
LD (rest+2), A ; SY = 512 + y
LD (rest+6), A ; DY = 256 + y
LD HL, rest
JP send
; --- draw: LMMM with TIMP, the ball's picture to the ball IX's place
draw: LD A, (IX+0)
LD (put+4), A ; DX
LD A, (IX+1)
LD (put+6), A ; DY = 256 + y
LD HL, put
JP send
; --- move: the ball IX steps (IX+2) across and (IX+3) down, bouncing
move: LD A, (IX+0)
ADD A, (IX+2)
LD (IX+0), A
OR A ; x = 0 or 240: turn round
JR Z, mv1
CP 240
JR NZ, mv2
mv1: LD A, (IX+2)
NEG
LD (IX+2), A
mv2: LD A, (IX+1)
ADD A, (IX+3)
LD (IX+1), A
OR A ; y = 0 or 176: turn round
JR Z, mv3
CP 176
RET NZ
mv3: LD A, (IX+3)
NEG
LD (IX+3), A
RET
; x, y, step across, step down - x and every step across even
ball1: DEFB 0, 0, 2, 1
ball2: DEFB 200, 100, -2, -1
; --- upload: the ball's picture into the expansion RAM at (0,0), by the
; CPU: R#45 bit 6 switches the CPU's VRAM access to the expansion.
; 16 lines of 8 bytes, each line 128 bytes on from the last (S11).
upload: DI
LD A, 40h
LD B, 45
CALL setreg ; R#45 = 40h: the CPU reaches the expansion
XOR A
LD B, 14
CALL setreg ; its first 16K
LD HL, 0 ; HL = the line's offset
LD DE, ballpic
LD C, 16 ; 16 lines
up1: LD A, L
OUT (9), A
LD A, H
OR 40h
OUT (9), A ; the line's address, for writing
LD B, 8
up2: LD A, (DE)
OUT (8), A
INC DE
DJNZ up2
PUSH DE
LD DE, 128
ADD HL, DE ; the next line
POP DE
DEC C
JR NZ, up1
XOR A
LD B, 45
CALL setreg ; R#45 = 0: main VRAM again
EI
RET
; --- send: the 15 bytes at HL to R#32-R#46 through port 0Bh, with
; R#17 auto-incrementing; writing R#46 starts the command. Then wait.
send: DI
LD A, 32
LD B, 17
CALL setreg
LD BC, 15*256 + 0Bh
OTIR
EI
cwait: DI ; CE, one read at a time, R#15 back to 0 each time
LD A, 2
LD B, 15
CALL setreg
IN A, (9)
LD C, A
XOR A
LD B, 15
CALL setreg
EI
BIT 0, C
JR NZ, cwait
RET
; Command blocks: SX, SY, DX, DY, NX, NY (words), then CLR, ARG, command.
; SX SY DX DY NX NY
tile1: DEFW 0, 0, 0, 512, 16, 16
DEFB 44h, 0, 0C0h ; HMMV colour 4
tile2: DEFW 0, 0, 8, 512, 8, 8
DEFB 55h, 0, 0C0h ; HMMV colour 5
tile3: DEFW 0, 0, 0, 520, 8, 8
DEFB 55h, 0, 0C0h ; HMMV colour 5
wide: DEFW 0, 512, 0, 512, 0, 16
DEFB 0, 0, 0D0h ; HMMM (DX, NX set above)
deep: DEFW 0, 512, 0, 0, 0, 0
DEFB 0, 0, 0E0h ; YMMM from DX = 0: whole lines
copybg: DEFW 0, 512, 0, 256, 256, 192
DEFB 0, 0, 0D0h ; HMMM: page 2 to page 1
rest: DEFW 0, 512, 0, 256, 16, 16
DEFB 0, 0, 0D0h ; HMMM (x, y set above)
put: DEFW 0, 0, 0, 256, 16, 16
DEFB 0, 10h, 98h ; LMMM, TIMP, source in the expansion (MXS)
; the ball, one row a line, one hex digit a dot: A (colour 10) inside,
; F (15) round the edge, 0 (transparent) outside
ballpic:
DEFB 000h,000h,000h,00Fh,0F0h,000h,000h,000h
DEFB 000h,000h,0FFh,0FFh,0FFh,0FFh,000h,000h
DEFB 000h,00Fh,0FFh,0AAh,0AAh,0FFh,0F0h,000h
DEFB 000h,0FFh,0AAh,0AAh,0AAh,0AAh,0FFh,000h
DEFB 00Fh,0FAh,0AAh,0AAh,0AAh,0AAh,0AFh,0F0h
DEFB 00Fh,0FAh,0AAh,0AAh,0AAh,0AAh,0AFh,0F0h
DEFB 00Fh,0AAh,0AAh,0AAh,0AAh,0AAh,0AAh,0F0h
DEFB 0FFh,0AAh,0AAh,0AAh,0AAh,0AAh,0AAh,0FFh
DEFB 0FFh,0AAh,0AAh,0AAh,0AAh,0AAh,0AAh,0FFh
DEFB 00Fh,0AAh,0AAh,0AAh,0AAh,0AAh,0AAh,0F0h
DEFB 00Fh,0FAh,0AAh,0AAh,0AAh,0AAh,0AFh,0F0h
DEFB 00Fh,0FAh,0AAh,0AAh,0AAh,0AAh,0AFh,0F0h
DEFB 000h,0FFh,0AAh,0AAh,0AAh,0AAh,0FFh,000h
DEFB 000h,00Fh,0FFh,0AAh,0AAh,0FFh,0F0h,000h
DEFB 000h,000h,0FFh,0FFh,0FFh,0FFh,000h,000h
DEFB 000h,000h,000h,00Fh,0F0h,000h,000h,000h
INCLUDE "frame.asm"
Build and run
Save it as s17-copying.asm next to frame.asm. Build and run it as in S2.
What you should see
A checkerboard of blue and light blue 8 x 8 squares filling the screen, and two yellow balls with white rims bouncing round it, two dots across and one line down or up every frame. The squares show through the corners of each ball, and behind them the checkerboard is perfect: no trail, no smudge. After ten seconds, MOS's screen and the prompt.

Everything so far, here and in S16, has been in Graphics 4. The commands you have met, HMMV, HMMM, YMMM, LMMV, LMMM, LINE, PSET and POINT, work in all four of S12's bitmap modes, with the same registers and the same logical operations. Three things change with the mode: the coordinates, how many dots a byte command moves, and how many bits make a colour.
The engine always counts in dots and lines, and each mode has its own range:
| Mode | X | Y | A page | Page n starts at Y |
|---|---|---|---|---|
| Graphics 4 | 0-255 | 0-1023 | 32K, 128 bytes a line | 256n |
| Graphics 5 | 0-511 | 0-1023 | 32K, 128 bytes a line | 256n |
| Graphics 6 | 0-511 | 0-511 | 64K, 256 bytes a line | 256n |
| Graphics 7 | 0-255 | 0-511 | 64K, 256 bytes a line | 256n |
Graphics 5 counts its lines exactly as Graphics 4 does: four pages, Y running on through them. In Graphics 6 and 7 a line is 256 bytes, so there are only two pages, and page 1, Y = 256, is the one at 10000h that R#2 = 3Fh shows (S12). In Graphics 5 and 6, X runs to 511: a fill or a copy can reach the right-hand half of the screen, and YMMM's strip runs from DX to dot 511.
S16 and the first part of this section split the commands in two, and the split matters more in the other modes.
The byte commands, HMMV, HMMM and YMMM, move whole bytes, and a byte holds a different number of dots in each mode:
| Mode | Dots a byte | Low bits of SX, DX and NX ignored | HMMV DX = 6, NX = 9 fills |
|---|---|---|---|
| Graphics 4 | 2 | 1 | dots 6-13 |
| Graphics 5 | 4 | 2 | dots 4-11 |
| Graphics 6 | 2 | 1 | dots 6-13 |
| Graphics 7 | 1 | none | dots 6-14 |
HMMV's CLR is the whole byte, so it is 4 dots in Graphics 5, 2 in Graphics 4 and 6, and 1 in Graphics 7. In Graphics 5, CLR = 1Bh (00 01 10 11) fills with colours 0, 1, 2 and 3 repeating; in Graphics 7, CLR is simply the colour.
In Graphics 7 the byte commands lose nothing. A byte is a dot, so HMMV fills from any X to any X, and HMMM copies from any X to any X.
The dot commands, LMMV, LMMM, LINE and PSET, are exact at any X in every mode, as they were in Graphics 4.
For the dot commands, CLR is one dot's colour, and how much of it counts depends on the mode:
| Mode | CLR bits used | A colour is |
|---|---|---|
| Graphics 4, 6 | 3-0 | 0-15, a palette entry |
| Graphics 5 | 1-0 | 0-3, a palette entry |
| Graphics 7 | 7-0 | a GGGRRRBB byte (S12) |
The logical operations work on that many bits. NOT of E6h gives 1 in Graphics 5, 9 in Graphics 4 and 6, and 19h in Graphics 7. POINT reads a dot back into S#7 at the same width.
The T operations leave the destination alone where the source's bits, in that width, are all 0. In Graphics 7 that means only the byte 00h is transparent. F0h, whose low four bits make it colour 0 and transparent in Graphics 4 and 6, is a colour like any other in Graphics 7. So a Graphics 7 sprite has 255 colours of its own, and 00h for its holes.
The software sprite earlier in this section had to stay at even X, because HMMM can only restore whole bytes. In Graphics 7 a byte is one dot, so the same two commands, HMMM to restore and LMMM with TIMP to draw, move a sprite one dot at a time, left or right, with nothing left behind.
In Graphics 6, HMMM ignores X's low bit as it does in Graphics 4, and in Graphics 5 its low two bits. There the old rule stands: restore at even X in Graphics 6, at a multiple of four in Graphics 5, or restore with LMMM, which works at any dot.
Graphics 7 has only two pages, so the picture and its clean copy take both. Show page 1, at 10000h. Page 0 holds MOS's own screen in its first 16K, 00000h to 03FFFh: in Graphics 7 that is lines 0 to 63. Lines 64 to 255, 04000h to 0FFFFh, lie above MOS's screen: 192 lines, exactly room for a clean copy of the picture. Page 1 has 64 more lines under the picture, from line 448, for the sprites' pictures (and, at line 506, 1FA00h, the sprite attribute table).
What it costs: a Graphics 7 picture is 48K, so its clean copy is 48K too, twice Graphics 4's. A sprite is still two commands a frame.
The background is drawn once by HMMV: 24 bands of colour, then a sun and its reflection, one line at a time. Every line of the sun is an odd number of dots wide, centred on dot 128, so many of them start at odd X: in Graphics 7, HMMV doesn't mind. One HMMM copies it all to the screen.
The balloons are one shape, held as bits, one row a line. The program turns each 1 into that row's colour and each 0 into 00h as it writes the pictures under the screen, so one shape makes three balloons in three sets of colours.
; S17: software sprites in Graphics 7, at any X.
; Three hot-air balloons drift over a sunset in 256 colours. The command
; engine draws the background out of sight and copies it to the screen.
; Then, every frame, HMMM puts the background back under each balloon
; and LMMM with TIMP draws each one at its new place. In Graphics 7 a
; byte is one dot, so both work at any X, odd or even.
; Runs for 500 frames (10 seconds).
;
; Where everything is, as the command engine counts lines (256 a page):
; page 0, lines 0-63 (VRAM 0000h-3FFFh): MOS's own screen, left alone
; page 0, lines 64-255 (4000h-FFFFh): the clean background, never shown
; page 1, lines 256-447 (10000h, R#2 = 3Fh): the screen
; page 1, lines 448-463 (1C000h): the balloons' pictures, never shown
ORG 256
DI
; --- Graphics 7, showing page 1, with a black border
LD A, 0Eh
LD B, 0
CALL setreg
LD A, 3Fh
LD B, 2
CALL setreg
XOR A
LD B, 7
CALL setreg ; R#7 = 00h: the border, and 00h dots, black
; --- sprites out of the way (attribute table at 1FA00h: Y = 216)
LD A, 7
LD B, 14
CALL setreg
XOR A
OUT (9), A
LD A, 3Ah + 40h
OUT (9), A
LD A, 216
OUT (8), A
LD A, 0F7h
LD B, 5
CALL setreg
LD A, 03h
LD B, 11
CALL setreg
EI
; --- the background, drawn by HMMV on lines 64-255 of page 0.
; 24 bands of 8 lines, each its own colour byte: sky, then sea
LD HL, bands
LD C, 64 ; C = the band's first line
band: LD A, (HL)
LD (fill+12), A ; CLR: the colour byte
LD A, C
LD (fill+6), A ; DY
PUSH HL
PUSH BC
LD HL, fill
CALL send
POP BC
POP HL
INC HL
LD A, C
ADD A, 8 ; the next band: 8 lines on
LD C, A
JR NZ, band ; until 64 + 192 = 256 wraps C to 0
; the sun: one HMMV a line, centred on x = 128, setting
; into the sea - every line an odd number of dots
LD HL, sunw
LD C, 64+102 ; C = the line
sun: LD E, (HL) ; E = the half-width
CALL centre
INC HL
INC C
LD A, C
CP 64+128
JR NZ, sun
; its reflection: five streaks on the sea
LD A, 0F8h
LD (row+12), A ; pale yellow
LD HL, streaks
str: LD C, (HL) ; the line
INC HL
LD E, (HL) ; the half-width
INC HL
CALL centre
LD A, (HL)
OR A ; a 0 line ends the list
JR NZ, str
; --- the whole background copied to the screen by HMMM
LD HL, copybg
CALL send
; --- the balloons' pictures, written by the CPU below the screen
CALL upload
; --- the frame interrupt (S7)
CALL irqon
LD A, 0E0h
LD B, 1
CALL setreg
EI
; --- the game loop: every frame, all three balloons
main: CALL waitf
LD IX, ball1 ; 1. the background back under every balloon
CALL restore
LD IX, ball2
CALL restore
LD IX, ball3
CALL restore
LD IX, ball1 ; 2. move them
CALL move
LD IX, ball2
CALL move
LD IX, ball3
CALL move
LD IX, ball1 ; 3. draw them at their new places
CALL draw
LD IX, ball2
CALL draw
LD IX, ball3
CALL draw
LD HL, (TICKS)
LD DE, 500
OR A
SBC HL, DE
JR C, main
; --- put the machine back for MOS (BE puts R#7 back)
LD A, 0C0h
CALL irqoff
CALL tomos
RET
onframe: RET ; nothing to do in the interrupt
; --- centre: HMMV one line C, 2E + 1 dots wide, centred on x = 128
centre: LD A, 128
SUB E
LD (row+4), A ; DX = 128 - E
LD A, E
ADD A, A
INC A
LD (row+8), A ; NX = 2E + 1
LD A, C
LD (row+6), A ; DY
PUSH HL
PUSH BC
LD HL, row
CALL send
POP BC
POP HL
RET
; --- restore: HMMM 16x16 from the clean background to the balloon
; IX's place on the screen - at any x
restore:
LD A, (IX+0) ; x
LD (rest+0), A ; SX
LD (rest+4), A ; DX
LD A, (IX+1) ; y
LD (rest+6), A ; DY = 256 + y
ADD A, 64
LD (rest+2), A ; SY = 64 + y
LD HL, rest
JP send
; --- draw: LMMM with TIMP, the balloon's picture to its place
draw: LD A, (IX+4)
LD (put+0), A ; SX = the picture's x: 0, 16 or 32
LD A, (IX+0)
LD (put+4), A ; DX
LD A, (IX+1)
LD (put+6), A ; DY = 256 + y
LD HL, put
JP send
; --- move: the balloon IX steps (IX+2) across and (IX+3) down. It turns
; round at x = 0 and 240, and at y = 96 and 160
move: LD A, (IX+0)
ADD A, (IX+2)
LD (IX+0), A
OR A
JR Z, mv1
CP 240
JR NZ, mv2
mv1: LD A, (IX+2)
NEG
LD (IX+2), A
mv2: LD A, (IX+1)
ADD A, (IX+3)
LD (IX+1), A
CP 96
JR Z, mv3
CP 160
RET NZ
mv3: LD A, (IX+3)
NEG
LD (IX+3), A
RET
; x, y, step across, step down, picture's x
ball1: DEFB 0, 24, 1, 0, 0 ; one dot a frame: odd x every other frame
ball2: DEFB 239, 64, -1, 0, 16 ; leftwards, starting at an odd x
ball3: DEFB 0, 100, 3, 1, 32 ; three across, one down
; --- upload: the three pictures to lines 448-463 (VRAM 1C000h), side by
; side at x = 0, 16 and 32. Each row of the shape is 16 bits; a 1
; becomes that row's colour, a 0 becomes 00h (transparent to TIMP).
upload: DI
LD A, 7
LD B, 14
CALL setreg ; R#14 = 7: VRAM 1C000h-1FFFFh
LD IX, colours ; 16 colours a balloon, one a row
XOR A
upb: LD (picx), A ; this picture's x: 0, 16, 32
LD HL, shape
LD D, 0 ; D = the row, 0-15
upr: LD A, (picx)
OUT (9), A
LD A, D
OR 40h
OUT (9), A ; 1C000h + 256 x row + x, for writing
LD C, (IX+0) ; the row's colour
INC IX
LD A, (HL)
INC HL
CALL dots8 ; the left 8 dots
LD A, (HL)
INC HL
CALL dots8 ; the right 8
INC D
LD A, D
CP 16
JR NZ, upr
LD A, (picx)
ADD A, 16
CP 48
JR NZ, upb
EI
RET
picx: DEFB 0
; --- dots8: 8 dots to port 8 from the bits of A, left dot first:
; colour C for a 1, 00h for a 0
dots8: LD E, A
LD B, 8
dt1: XOR A
RLC E ; the next bit into carry
JR NC, dt2
LD A, C
dt2: OUT (8), A
DJNZ dt1
RET
; --- send: the 15 bytes at HL to R#32-R#46 through port 0Bh, with
; R#17 auto-incrementing; writing R#46 starts the command. Then wait.
send: DI
LD A, 32
LD B, 17
CALL setreg
LD BC, 15*256 + 0Bh
OTIR
EI
cwait: DI ; CE, one read at a time, R#15 back to 0 each time
LD A, 2
LD B, 15
CALL setreg
IN A, (9)
LD C, A
XOR A
LD B, 15
CALL setreg
EI
BIT 0, C
JR NZ, cwait
RET
; Command blocks: SX, SY, DX, DY, NX, NY (words), then CLR, ARG, command.
; SX SY DX DY NX NY
fill: DEFW 0, 0, 0, 0, 256, 8
DEFB 0, 0, 0C0h ; HMMV (CLR, DY set above)
row: DEFW 0, 0, 0, 0, 0, 1
DEFB 0FCh, 0, 0C0h ; HMMV, one line, yellow
copybg: DEFW 0, 64, 0, 256, 256, 192
DEFB 0, 0, 0D0h ; HMMM: page 0 to page 1
rest: DEFW 0, 64, 0, 256, 16, 16
DEFB 0, 0, 0D0h ; HMMM (x, y set above)
put: DEFW 0, 448, 0, 256, 16, 16
DEFB 0, 0, 98h ; LMMM, TIMP
; the bands' colours, GGGRRRBB, from the top: 16 of sky, 8 of sea
bands: DEFB 001h,005h,006h,00Ah,00Eh,02Eh,032h,031h
DEFB 055h,059h,079h,07Dh,09Dh,09Ch,0BCh,0DCh
DEFB 047h,027h,023h,007h,003h,022h,002h,001h
; the sun's half-width on lines 102-127 of the picture
sunw: DEFB 0,6,9,11,12,13,15,16,16,17,18,19,19
DEFB 20,20,20,21,21,21,21,21,21,22,21,21,21
; the streaks: line (64 + the picture's line), half-width; 0 ends the list
streaks: DEFB 64+131,23, 64+135,17, 64+141,11, 64+149,7, 64+159,3, 0
; the balloon, one row a line: envelope, ropes, basket
shape: DEFB 00000111b,11100000b
DEFB 00011111b,11111000b
DEFB 00111111b,11111100b
DEFB 01111111b,11111110b
DEFB 01111111b,11111110b
DEFB 11111111b,11111111b
DEFB 11111111b,11111111b
DEFB 11111111b,11111111b
DEFB 01111111b,11111110b
DEFB 01111111b,11111110b
DEFB 00111111b,11111100b
DEFB 00011111b,11111000b
DEFB 00001000b,00010000b
DEFB 00000100b,00100000b
DEFB 00000011b,11000000b
DEFB 00000011b,11000000b
; each balloon's colour for each row, GGGRRRBB: 12 shades of envelope,
; two grey ropes, a brown basket
colours:
DEFB 07Dh,05Dh,03Dh,01Dh,01Ch,01Ch,01Ch,018h ; red
DEFB 018h,014h,014h,010h,092h,092h,050h,050h
DEFB 0E9h,0E4h,0E0h,0E0h,0E0h,0C0h,0C0h,0A0h ; green
DEFB 0A0h,080h,080h,060h,092h,092h,050h,050h
DEFB 0FFh,0DBh,0B7h,093h,06Fh,04Bh,04Bh,027h ; white to blue
DEFB 027h,003h,003h,002h,092h,092h,050h,050h
INCLUDE "frame.asm"
Build and run
Save it as s17-balloons.asm next to frame.asm. Build and run it as in S2.
What you should see
A sunset. The sky runs in bands from deep blue at the top through purple, red and orange to yellow at the horizon, and below it the sea in eight bands of blue. A yellow sun sits half-set on the horizon, with five pale yellow streaks of reflection on the water beneath it. The border is black.
Three hot-air balloons drift across it. The red one, near the top, moves one dot a frame, and the green one below it one dot a frame the other way; both turn round at the edges. The third, white shading to blue, moves three dots across and one line up or down each frame, over the sun and down across the horizon into the sea and back. Wherever they have been, the sunset is exactly as it was: no trail, at odd X or even, going left or right.


Four frames in a row, magnified: the red balloon at x = 234, 235, 236 and 237, one dot further each frame, the sky behind it untouched.

After ten seconds, MOS's screen and the prompt.
s17-copying.asm, in ball1, change the step across from 2 to 1. What do you expect to see behind that ball, and why only behind that one?s17-copying.asm, in put, change ARG from 10h to 00h. Where does LMMM read the ball's picture from now, and what is there?s17-copying.asm's main loop, reorder the calls so each ball is restored, moved and drawn before the next. When will you see the difference, and what will it look like?s17-balloons.asm, add AND 0FEh after the first LD A, (IX+0) in restore, so every restore starts on an even dot, as a byte copy does in Graphics 4 and 6. Which balloons leave something behind, and when?s17-balloons.asm, change row's command from 0C0h (HMMV) to 80h (LMMV, IMP). What changes on the screen, and why?colours, change one of the red balloon's envelope colours to 00h. What happens to that row of the balloon? Would 0F0h do the same?| Symptom | Cause |
|---|---|
| A dotted trail behind the sprite, in its rim's colour | The sprite is at an odd x and the restore is a byte copy (HMMM). Keep x even, or restore with LMMM |
| Small blobs of other shapes where the balls should be | The draw read main video memory instead of the expansion: MXS (10h) missing from ARG |
You can copy rectangles of video memory in bytes (HMMM), in whole lines (YMMM) and in dots through a logical operation (LMMM, with TIMP for transparency), from any page or from the expansion with MXS. A software sprite is a restore from a clean copy and a transparent draw: restore every sprite, then draw every sprite, at even x.
In Graphics 5, 6 and 7 the same commands work in each mode's own coordinates. The byte commands move 4, 2 or 1 dots a byte, and the dot commands' colours are 2, 4 or 8 bits wide. In Graphics 7, where a byte is a dot, a software sprite moves at any x, with 255 colours and 00h for its holes.
S18, Eighty Columns: the 256's text mode, for menus and status screens.
This form is protected by reCAPTCHA, and the Google Privacy Policy and Terms of Service apply.