mirror of
https://github.com/deater/dos33fsprogs.git
synced 2024-12-27 02:31:00 +00:00
xmas2019: update snow
This commit is contained in:
parent
35f6558cb7
commit
6787c7a58c
119
xmas_2019/random16.s
Normal file
119
xmas_2019/random16.s
Normal file
@ -0,0 +1,119 @@
|
||||
; 16-bit 6502 Random Number Generator (cycle-invariant version)
|
||||
|
||||
; Linear feedback shift register PRNG by White Flame
|
||||
; http://codebase64.org/doku.php?id=base:small_fast_16-bit_prng
|
||||
|
||||
; The Apple II KEYIN routine increments SEEDL:SEEDH
|
||||
; while waiting for keypress
|
||||
|
||||
;SEEDL = $4E
|
||||
;SEEDH = $4F
|
||||
|
||||
XOR_MAGIC = $7657 ; "vW"
|
||||
|
||||
;=============================
|
||||
; random16
|
||||
;=============================
|
||||
; takes:
|
||||
; not 0, cs = 6(r16)+12(lnz)+5(nop)+ 19(deo) = 42
|
||||
; not 0, cc = 6(r16)+14(lnz)+2(nop)+ 20(neo) = 42
|
||||
|
||||
; $0000 = 6(r16)+ 6(loz)+11nops+ 19(deo) = 42
|
||||
; $8000 = 6(r16)+ 6(loz)+ 4(ceo) + 6nops+ 20(neo) = 42
|
||||
|
||||
; $XX00 cc = 6(r16)+ 6(loz)+4(ceo)+2(cep) +4nops+ 20(neo) = 42
|
||||
; $XX00 cs = 6(r16)+ 6(loz)+4(ceo)+4(cep) +3nops+ 19(deo) = 42*
|
||||
random16:
|
||||
|
||||
lda SEEDL ; 3
|
||||
beq low_zero ; $0000 and $8000 are special values ; 3
|
||||
;==========
|
||||
; 6
|
||||
lownz:
|
||||
; -1
|
||||
asl SEEDL ; Do a normal shift ; 5
|
||||
lda SEEDH ; 3
|
||||
rol ; 2
|
||||
bcs five_cycle_do_eor ; 3
|
||||
;===========
|
||||
; 12
|
||||
|
||||
bcc two_cycle_no_eor ; 3
|
||||
;==========
|
||||
; 12+3-1 = 14
|
||||
|
||||
|
||||
;===================================================================
|
||||
|
||||
eleven_cycle_do_eor:
|
||||
nop ; 2
|
||||
nop ; 2
|
||||
nop ; 2
|
||||
five_cycle_do_eor:
|
||||
nop ; 2
|
||||
three_cycle_do_eor:
|
||||
sta SEEDH ; nop ; 3
|
||||
|
||||
do_eor:
|
||||
; high byte is in A
|
||||
|
||||
eor #>XOR_MAGIC ; 2
|
||||
sta SEEDH ; 3
|
||||
lda SEEDL ; 3
|
||||
eor #<XOR_MAGIC ; 2
|
||||
sta SEEDL ; 3
|
||||
eor_rts:
|
||||
rts ; 6
|
||||
;===========
|
||||
; 19
|
||||
|
||||
;=========================================================================
|
||||
|
||||
six_cycles_no_eor:
|
||||
nop ; 2
|
||||
four_cycle_no_eor:
|
||||
nop ; 2
|
||||
two_cycle_no_eor:
|
||||
nop ; 2
|
||||
no_eor:
|
||||
nop ; 2
|
||||
nop ; 2
|
||||
nop ; 2
|
||||
nop ; 2
|
||||
sta SEEDH ; 3
|
||||
jmp eor_rts ; 3+6
|
||||
;===========
|
||||
; 20
|
||||
|
||||
|
||||
;======================================================================
|
||||
;======================================================================
|
||||
|
||||
low_zero:
|
||||
lda SEEDH ; 3
|
||||
beq eleven_cycle_do_eor ; High byte is also zero ; 3
|
||||
; so apply the EOR
|
||||
;============
|
||||
; 6
|
||||
ceo:
|
||||
|
||||
; -1
|
||||
; wasn't zero, check for $8000
|
||||
asl ; 2
|
||||
beq six_cycles_no_eor ; if $00 is left after the shift; 3
|
||||
; then it was $80
|
||||
;===========
|
||||
; 4
|
||||
|
||||
; else, do the EOR based on the carry
|
||||
cep:
|
||||
; -1
|
||||
bcc four_cycle_no_eor ; 3
|
||||
;============
|
||||
; 2
|
||||
|
||||
bcs three_cycle_do_eor ; 2+3-1 = 4
|
||||
|
||||
|
||||
|
||||
|
@ -9,11 +9,19 @@ GBASL = $26
|
||||
GBASH = $27
|
||||
BASL = $28
|
||||
BASH = $29
|
||||
|
||||
SEEDL = $4E
|
||||
SEEDH = $4F
|
||||
|
||||
HGR_COLOR = $E4
|
||||
SNOWX = $F0
|
||||
|
||||
HGR = $F3E2
|
||||
|
||||
|
||||
NUMFLAKES = 10
|
||||
|
||||
|
||||
.include "hardware.inc"
|
||||
|
||||
|
||||
@ -33,23 +41,23 @@ display_loop:
|
||||
|
||||
ldx #0
|
||||
erase_loop:
|
||||
lda snow_y,X
|
||||
lda snow_y,X ; get Y
|
||||
lsr
|
||||
lsr
|
||||
and #$fe
|
||||
; lsr
|
||||
lsr ; divide by 8
|
||||
tay
|
||||
|
||||
clc
|
||||
lda hgr_offsets,Y
|
||||
lda hgr_offsets_l,Y
|
||||
adc snow_x,X
|
||||
sta GBASL
|
||||
sta GBASL ; point GBASL to right location
|
||||
|
||||
lda snow_y,X
|
||||
asl
|
||||
asl
|
||||
and #$1f
|
||||
clc
|
||||
adc hgr_offsets+1,Y
|
||||
adc hgr_offsets_h,Y
|
||||
sta GBASH
|
||||
|
||||
ldy #0
|
||||
@ -57,7 +65,7 @@ erase_loop:
|
||||
sta (GBASL),Y
|
||||
|
||||
inx
|
||||
cpx #8
|
||||
cpx #NUMFLAKES
|
||||
bne erase_loop
|
||||
|
||||
;==========================
|
||||
@ -75,10 +83,30 @@ move_snow:
|
||||
|
||||
|
||||
just_inc:
|
||||
|
||||
jsr random16
|
||||
lda SEEDL
|
||||
and #$f
|
||||
|
||||
beq snow_left
|
||||
cmp #$1
|
||||
beq snow_right
|
||||
|
||||
inc snow_y,X
|
||||
|
||||
jmp snow_no
|
||||
|
||||
snow_right:
|
||||
inc snow_offset,X
|
||||
jmp snow_no
|
||||
|
||||
snow_left:
|
||||
dec snow_offset,X
|
||||
snow_no:
|
||||
|
||||
done_inc:
|
||||
inx
|
||||
cpx #8
|
||||
cpx #NUMFLAKES
|
||||
bne move_snow
|
||||
|
||||
|
||||
@ -90,11 +118,10 @@ draw_loop:
|
||||
lda snow_y,X
|
||||
lsr
|
||||
lsr
|
||||
; lsr
|
||||
and #$fe
|
||||
lsr
|
||||
tay
|
||||
clc
|
||||
lda hgr_offsets,Y
|
||||
lda hgr_offsets_l,Y
|
||||
adc snow_x,X
|
||||
sta GBASL
|
||||
|
||||
@ -103,7 +130,7 @@ draw_loop:
|
||||
asl
|
||||
and #$1f
|
||||
clc
|
||||
adc hgr_offsets+1,Y
|
||||
adc hgr_offsets_h,Y
|
||||
sta GBASH
|
||||
|
||||
ldy #0
|
||||
@ -111,7 +138,7 @@ draw_loop:
|
||||
sta (GBASL),Y
|
||||
|
||||
inx
|
||||
cpx #8
|
||||
cpx #NUMFLAKES
|
||||
bne draw_loop
|
||||
|
||||
lda #100
|
||||
@ -121,15 +148,23 @@ draw_loop:
|
||||
|
||||
|
||||
snow_x:
|
||||
.byte 2,4,6,8,10,12,14,16
|
||||
.byte 2,4,6,8,10,12,14,16,18,20
|
||||
|
||||
snow_offset:
|
||||
.byte 0,1,2,3,4,5,6,7
|
||||
.byte 0,1,2,3,4,5,6,7,0,1
|
||||
|
||||
snow_y:
|
||||
.byte 0,0,0,0,0,0,0,0
|
||||
.byte 0,0,0,0,0,0,0,0,0,0
|
||||
|
||||
hgr_offsets:
|
||||
.word $2000,$2080,$2100,$2180,$2200,$2280,$2300,$2380
|
||||
.word $2028,$20A8,$2128,$21A8,$2228,$22A8,$2328,$23A8
|
||||
.word $2050,$20D0,$2150,$21D0,$2250,$22D0,$2350,$23D0
|
||||
hgr_offsets_h:
|
||||
.byte >$2000,>$2080,>$2100,>$2180,>$2200,>$2280,>$2300,>$2380
|
||||
.byte >$2028,>$20A8,>$2128,>$21A8,>$2228,>$22A8,>$2328,>$23A8
|
||||
.byte >$2050,>$20D0,>$2150,>$21D0,>$2250,>$22D0,>$2350,>$23D0
|
||||
|
||||
hgr_offsets_l:
|
||||
.byte <$2000,<$2080,<$2100,<$2180,<$2200,<$2280,<$2300,<$2380
|
||||
.byte <$2028,<$20A8,<$2128,<$21A8,<$2228,<$22A8,<$2328,<$23A8
|
||||
.byte <$2050,<$20D0,<$2150,<$21D0,<$2250,<$22D0,<$2350,<$23D0
|
||||
|
||||
|
||||
.include "random16.s"
|
||||
|
Loading…
Reference in New Issue
Block a user