For starters this routine will print a letter 'A' at the top left of the screen. If you're not already, it's a really good idea to get familiar with the speccy's screen layout. There are examples out there but none of them are a substitute (for me anyway) for investigating the relationships between the screen positions yourself.
A good place to start is to know that the screen starts at memory address 16384, is made of 3 x 2048 byte (so the pixels are a total 6144) repeating segments (which can be seen appear in order in a standard loading screen).
If you RUN this BASIC program you'll see how the screen is organised if you increase by 1 byte each time.
FOR A=16384 TO 16384+6144:POKE A,255:NEXT A
If you observe it fill up the first line of 32 bytes you'll see it then makes a jump, it doesn't move down to the next line directly below. Within a segment you add 256 to move down a line, and 32 to move down a row. I plan to write something more detailed on this sometime.
Code: Select all
ld hl,letter_a_graphic ;8 bytes of graphic
ld de,16384 ;start of screen memory
printchar: ;print a character graphic addressed by HL at screen address DE
ld b,8 ;loop counter for 8 bytes
printloop:
ld a,(hl) ;get byte of graphic
ld (de),a ;put it in screen memory
inc hl ;next byte of graphic
inc d ;move DE down one line, inc d is the same as add 256 to DE
djnz printloop ;repeat B times
ret
;
letter_a_graphic:
db 00000000b
db 00111100b
db 01000010b
db 01000010b
db 01111110b
db 01000010b
db 01000010b
db 00000000b
;
Code: Select all
ld b,8
ld c,8
call yx2cell
ld hl,tilegraphic
call drawtile
ret
;
drawtile: ;arrive HL pointing at tile graphic, DE at screen memory
ld b,16 ;loop counter for 16 px high tile
drawtileloop:
ld a,(hl) ;get byte of graphic
ld (de),a ;plonk it in screen memory
inc hl ;next byte of graphic
inc e ;next column of screen
ld a,(hl) ;right hand side of tile
ld (de),a
inc hl ;next byte of graphic
dec e ;back to left hand side of tile
call nextlinedown ;move DE down one screen line
djnz drawtileloop
ret
;
nextlinedown: ;arrive DE at screen address, move it down one pixel line
inc d
ld a,d
and 7
ret nz
ld a,e
add a,32
ld e,a
ret c
ld a,d
sub 8
ld d,a
ret
;
yx2cell: ;arrive with b=y column 0-23, c=x column 0-31, point DE at corresponding screen address
ld a,b
rrca
rrca
rrca
and 224
or c
ld e,a
ld a,b
and 24
or 64
ld d,a
ret
;
tilegraphic:
db 255,255
db 255,255
db 255,255
db 255,255
db 255,255
db 255,255
db 255,255
db 255,255
db 255,255
db 255,255
db 255,255
db 255,255
db 255,255
db 255,255
db 255,255
db 255,255
;