I tried to display 2 or more UDGs on screen, but I can't get it right.
See the game loop.
Code: Select all
ORG #4009 ;#4009
; program starts here, both BASIC and machinecode
basic EX AF,AF' ; delay intrupt,opcode no bit 6
LD H,B ; preset for 48K bug to #40
JR init0 ; continue where room
DEFB 236,212,28 ; The BASIC
DEFB 126 ; fully placed over sysvar
DEFB 143,0,18 ; start BASIC=#4009 also MC
DEFW last ; needed by loading
chadd DEFW last-1
xptr DEFW 0
stkbot DEFW last
stkend DEFW last
berg DEFB 0
mem DEFW 0
DEFB 128
DEFB 0,0,0
; all above reusable AFTER loading
lastk DEFB 255,255,255 ; used by ZX81
margin DEFB 55 ; used by ZX81
nxtlin DEFW basic ; reusable after load
nop
defb #40,#40,#40
nop
taddr DEFW 0 ; used by ZX81 on LOAD only
; unharmed code
DEFW 0
frames
DEFB 255
DEFB 255 ; highbyte must have bit 7 set
coords DEFW 0
prcc DB 0,0,0
cdflag DEFB 64 ; used by ZX81
;-------------------------------------------------------------------
; Place ANY code to fill up to #4040
; init
init0
ld ix,hr
ld hl,screen
ld de,screen+1
ld (hl),0
ld bc,6143
ldir ; clear hires screen
;-------------------------------------------------------------------
; game loop
ploop
ld bc,(mycoord1) ; get X and Y UDG on screen in BC
call mydisplay1
ld bc,(mycoord2) ; get X and Y UDG on screen in BC
call mydisplay2
call mydelay
ld de,myudg1
call prudg ; erase udg
ld de,myudg2
call prudg ; erase udg
jr ploop ; do playloop
;-------------------------------------------------------------------
; mydisplay
mydisplay1
call scrad ; calculate screen address
push hl ; save position
ld de,myudg1
call prudg ; show UDG
pop hl
ret
mydisplay2
call scrad ; calculate screen address
push hl ; save position
ld de,myudg2
call prudg ; show UDG
pop hl
ret
;-------------------------------------------------------------------
; delay
mydelay
push hl
ld hl,frames
ld a,(hl)
sub 5 ; lower number will speed up game.
mywait
cp (hl)
jr nz,mywait ; wait some time
pop hl
ret
;-------------------------------------------------------------------
; show/erase udg
prudg
ld b,8
prudg1
ld a,(de) ; get udg
xor (hl) ; xor udg on screen
ld (hl),a ; write on screen
inc de
inc hl
ld a,(de) ; also second position
xor (hl)
ld (hl),a
inc de
ld a,l
add a,31 ; move to next line on screen
ld l,a
jr nc,bdec
inc h ; next block on screen when needed
bdec djnz prudg1
ret
;-------------------------------------------------------------------
; calculate screenaddress for XY-pos in BC (optimized in speed)
; Right address = SCREEN + B*32 + INT (C/8)
; B*32 = B/8 where B MOD 8 must be in 3 highbits C
scrad srl b ; B / 2
rr c ; Bit 0 from B in bit 7 C, and C/2
srl b ; B / 2, now B = B/4
rr c ; Bit 0 from B in bit 7 C, and C/2, C= C/4
srl b ; B / 2, now B = B/8
rr c ; Bit 0 from B in bit 7 C, and C/2, C= C/8
ld hl,screen ; BC now B*32+ INT (C/8), now we need start of screen too
add hl,bc ; HL now screenaddress
ret
;-------------------------------------------------------------------
; some lowres, HR must start AFTER #403F, but before #4070
hr LD HL,lowres+#8000 ; the lowres display
LD BC,#211 ; 1 line lowres text
LD A,#1E
LD I,A
LD A,#Fb
CALL #2B5 ; show lowres screen
LD B,11 ; match hires display with lowres
hr00 DJNZ hr00
ld hl,screen-32 ; start of hiresscreen (must be NNX0) where X = 0 2 4 8 A C E
ld de,32 ; screen line length
;-------------------------------------------------------------------
; the hr part
ld b,176 ; display 176 lines
hr1 add hl,de ; next line
ld a,h ; preset first line to show
ld i,a ; set highbyte of display (always the same)
call lbuf+#8000
dec b
jp nz,hr1
; fixed end of HR-routine
exit CALL #292 ; back from intrupt
CALL #220
LD IX,hr
JP #2A4
lbuf ld a,l
ld r,a
block 32,0
ret nc
;-------------------------------------------------------------------
lowres db 118
db "T"+101,"E"+101,"S"+101,"T"+101,0,"W"+101,"I"+101,"T"+101
db "H"+101,0,"U"+101,"D"+101,"G"+101
db 118
mycoord1 db 128,92 ; middle of the screen
mycoord2 db 128,74
myudg1
db %00011000,0
db %00101100,0
db %00111100,0
db %00011000,0
db %00111100,0
db %00101100,0
db %01011110,0
db %01111110,0
myudg2
db %11111111,0
db %10000001,0
db %10000001,0
db %10000001,0
db %10000001,0
db %10000001,0
db %10000001,0
db %11111111,0
vars db 128
last equ $
screen equ #6000 ; somewhere far away in memory