Hmm...no one posted here at all for 2009, I hope this isn't a forbidden topic or something now. Anyway here's a few routines that I thought were kinda helpful
Code:
This one could probably be optimized. Also, ld a,48 could be changed to ld a,c to center text at a manual x co-ordinate
Code:
Code:
random2:
;input: b= max rand number
;output: a = rand num at max or below
inc b
ld a,r
randloop:
add a,b
ret c
jp randloop
This one could probably be optimized. Also, ld a,48 could be changed to ld a,c to center text at a manual x co-ordinate
Code:
CenterText:
;hl= start of string, y co-ordinate already loaded
;check how many chars
ld b,0
push hl
centertext1:
ld a,(hl)
or a
jr z,centertext2
inc hl
cp 'f' \ jr z,ctinc3
cp 't' \ jr z,ctinc3
cp 's' \ jr z,ctinc3
cp 'l' \ jr z,ctinc3
cp '\'' \ jr z,ctinc3
cp ',' \ jr z,ctinc3
cp 'i' \ jr z,ctinc2
cp '!' \ jr z,ctinc2
cp '.' \ jr z,ctinc2
cp 'z' \ jr z,ctinc5
cp 'm' \ jr z,ctinc6
cp 'w' \ jr z,ctinc6
cp ' ' \ jr z,ctinc1
jr ctinc4
ctinc6:
inc b
ctinc5:
inc b
ctinc4:
inc b
ctinc3:
inc b
ctinc2:
inc b
ctinc1:
inc b
jr centertext1
centertext2:
ld a,48
srl b ;div by 2
sub b ;subtract from 48
ld (pencol),a
pop hl
ret