nolist
VRAMLINES_C000 equ &2200
org &4000
run $
xor a
call &bc0e
di
ld de,&C008+240
ld hl,VRAMLINES_C000
;call generate_vram80
; HL dest(256 aligned), DE vram start
generate_vram80
ld c,80
ld a,32
rows25:
ex af,af'
push de
ld b,8
lines8:
ld (hl),e:inc h:ld (hl),d:dec h:inc hl
ld a,d:add 8:ld d,a
dec b
jr nz,lines8
pop de
ex de,hl:add hl,bc:ex de,hl
ex af,af'
dec a
jr nz,rows25
ld c,32
wat:
push bc
ld ix,256*16
rdw:
ld a,(seed):ld b,a
ld a,r:ld a,r:add b:add c:add ixh:ld (seed),a
ld hl,(randp)
call rand
and 3
or a
jr nz,no0
inc h
jr after
no0:
dec a
jr nz,no1
dec h
jr after
no1:
dec a
jr nz,no2
inc l
jr after
no2:
dec l
after:
ld (randp),hl
ld a,l:ld l,h
srl l
ld b,ixh
call putpixel
dec ix
ld a,ixh:or ixl
jr nz,rdw
pop bc
dec c
jr nz,wat
ld hl,&c000:ld de,&c001:ld (hl),0:ld bc,16000:ldir
ld iy,0
xana:
ld c,0
triLoop:
ld hl,tri
ld a,(nframe+1)
cp 3
jr c,no3
ex de,hl
add iy,de
ex de,hl
no3
call rand
and 3
cp 3:jr nz,nomod3
xor a
nomod3:
add a:add l:ld l,a
ld a,ixh:add (hl):srl a:ld ixh,a:inc hl
ld a,ixl:add (hl):srl a:ld ixl,a
add iyl
ld l,a
ld b,32
ld a,iyh
add b
ld b,a
ld a,ixh
add iyl
call putpixel
dec c
jr nz, triLoop
ld hl,(nframe):inc hl:ld (nframe),hl
ld a,h
cp 1
jr c,noL
add iy,de
noL:
jr xana
;loop:
; ld b,&f5
; vsync0:
; in a,(c)
; rra
; jr c,vsync0
; ld b,&f5
; vsync1:
; in a,(c)
; rra
; jr nc,vsync1
;jr loop
;a=x,l=y,b=col
putpixel:
ld h,VRAMLINES_C000/256
ld e,(hl):inc h:ld d,(hl)
ld l,a:srl l:ld h,0:add hl,de
and a,1
jr z,rightPix
srl b
rightPix:
ld a,(hl)
xor b
ld (hl),a
ret
; Fast RND
;
; An 8-bit pseudo-random number generator,
; using a similar method to the Spectrum ROM,
; - without the overhead of the Spectrum ROM.
;
; R = random number seed
; an integer in the range [1, 256]
;
; R -> (33*R) mod 257
;
; S = R - 1
; an 8-bit unsigned integer
nframe:
dw 0
rand:
ld a,(seed)
ld b, a
rrca ; multiply by 32
rrca
rrca
xor &1f
add a, b
sbc a, 255 ; carry
ld (seed), a
ret
seed:
db 211
randp:
db 32,64
tri:
db 64,0
db 0,128
db 128,128
list
aend:
nolist