OK, I didn't test the code as I hadn't integrated a plot routine. It had some bugs! Here it is with a plot routine.
Assemble it, create and run this BASIC program:
1 BORDER 7: CLS: BORDER 1
10 RANDOMIZE USR 32768: GOTO 10
crank your emulator speed up
I think that gets pretty even coverage despite using a weak RND function, and a very quick and dirty correction of the values over 191.
Adding LSb of R after 3*(Y-192) might be another improvement.
The plot code is simplified version of the ROM routine.
Code: Select all
org 32768
UpdateXY:
ld bc,(Xpos)
call random ;random (0-256) in a
add a,c
ld (Xpos),a
call random ;random (0-256) in a
add a,b
cp 192
jr c, validY
sub 192 ;random (0-63)
ld b,a
add a,b
add a,b ;random (0-189)
validY:
ld (Ypos),a
ld bc,(Xpos)
call plotpoint
ret
Xpos:
db 0
Ypos:
db 0
RandData:
dw 9999
random:
ld hl,(randData)
ld a,r
ld d,a
ld e,(hl)
add hl,de
add a,l
xor h
ld (randData),hl
ret
plotpoint: ;y=0 is top of screen
ld a,b
and a
rra
scf
rra
and a
rra
xor b
and 248
xor b
ld h,a
ld a,c
rlca
rlca
rlca
xor b
and 199
xor b
rlca
rlca
ld l,a
ld a,c
and 7
;HL=display address, A=pixel offset in byte
ld b,a
ld a,128 ;set pixel and shift to correct place
plotloop:
rrca
djnz plotloop
or (hl) ;write pixel to screen
ld (hl),a
ret