fire: minimal working

This commit is contained in:
Vince Weaver 2018-12-30 01:03:07 -05:00
parent 4c77a7713f
commit 2c56c3c57d
7 changed files with 400 additions and 733 deletions

View File

@ -15,7 +15,7 @@ fire.dsk: FIRE HELLO
FIRE: fire.o
ld65 -o FIRE fire.o -C ../linker_scripts/apple2_1000.inc
fire.o: fire.s gr_copy.s gr_unrolled_copy.s vapor_lock.s \
fire.o: fire.s gr_fast_clear.s vapor_lock.s \
delay_a.s
ca65 -o fire.o fire.s -l fire.lst

View File

@ -5,32 +5,13 @@
; based on code described here http://fabiensanglard.net/doom_fire_psx/
; Zero Page
FRAMEBUFFER = $00 ; $00 - $0F
YPOS = $10
YPOS_SIN = $11
CH = $24
CV = $25
GBASL = $26
GBASH = $27
BASL = $28
BASH = $29
MASK = $2E
COLOR = $30
FRAME = $60
MB_VALUE = $91
BIRD_STATE = $E0
BIRD_DIR = $E1
SEEDL = $4E
DRAW_PAGE = $EE
LASTKEY = $F1
PADDLE_STATUS = $F2
XPOS = $F3
OLD_XPOS = $F4
TEMP = $FA
TEMPY = $FB
INL = $FC
INH = $FD
OUTL = $FE
OUTH = $FF
; Soft Switches
KEYPRESS= $C000
@ -95,7 +76,68 @@ fire_demo:
; bne wfloopA ; 2nt/3
jsr clear_screens_notext
; Setup white line on bottom
lda #$ff
ldx #39
white_loop:
sta $7d0,X ; hline 24 (46+47)
dex
bpl white_loop
fire_loop:
ldy #44 ; 22 * 2
yloop:
lda gr_offsets,Y
sta smc2+1
lda gr_offsets+1,Y
sta smc2+2
lda gr_offsets+2,Y
sta smc1+1
lda gr_offsets+3,Y
sta smc1+2
sty TEMPY
ldx #39
xloop:
smc1:
lda $7d0,X
sta TEMP
and #$f ; mask off
tay
jsr random16
lda SEEDL
and #$1
beq no_change
decrement:
lda color_progression,Y
jmp done_change
no_change:
lda TEMP
done_change:
smc2:
sta $750,X
dex
bpl xloop
ldy TEMPY
dey
dey
bpl yloop
;======================================================
; We have 4550 cycles in the vblank, use them wisely
;======================================================
@ -119,10 +161,26 @@ keypress:
jmp keypress
color_progression:
.byte 0 ; 0->0
.byte $88 ; 1->8
.byte 0 ; 2->0
.byte 0 ; 3->0
.byte 0 ; 4->0
.byte 0 ; 5->0
.byte 0 ; 6->0
.byte 0 ; 7->0
.byte $55 ; 8->5
.byte $11 ; 9->1
.byte 0 ; 10->0
.byte 0 ; 11->0
.byte 0 ; 12->0
.byte $99 ; 13->9
.byte 0 ; 14->0
.byte $dd ; 15->13
.include "gr_hline.s"
;.include "../asm_routines/keypress.s"
.include "gr_copy.s"
.include "gr_unrolled_copy.s"
.include "gr_fast_clear.s"
.include "vapor_lock.s"
.include "delay_a.s"
.include "random16.s"

View File

@ -1,58 +0,0 @@
;=========================================================
; gr_copy_to_current, 40x48 version
;=========================================================
; copy 0xc00 to DRAW_PAGE
;
; 45 + 2 + 120*(8*9 + 5) -1 + 6 = 9292
gr_copy_to_current:
lda DRAW_PAGE ; 3
clc ; 2
adc #$4 ; 2
sta gr_copy_line+5 ; 4
sta gr_copy_line+11 ; 4
adc #$1 ; 2
sta gr_copy_line+17 ; 4
sta gr_copy_line+23 ; 4
adc #$1 ; 2
sta gr_copy_line+29 ; 4
sta gr_copy_line+35 ; 4
adc #$1 ; 2
sta gr_copy_line+41 ; 4
sta gr_copy_line+47 ; 4
;===========
; 45
ldy #119 ; for early ones, copy 120 bytes ; 2
gr_copy_line:
lda $C00,Y ; load a byte (self modified) ; 4
sta $400,Y ; store a byte (self modified) ; 5
lda $C80,Y ; load a byte (self modified) ; 4
sta $480,Y ; store a byte (self modified) ; 5
lda $D00,Y ; load a byte (self modified) ; 4
sta $500,Y ; store a byte (self modified) ; 5
lda $D80,Y ; load a byte (self modified) ; 4
sta $580,Y ; store a byte (self modified) ; 5
lda $E00,Y ; load a byte (self modified) ; 4
sta $600,Y ; store a byte (self modified) ; 5
lda $E80,Y ; load a byte (self modified) ; 4
sta $680,Y ; store a byte (self modified) ; 5
lda $F00,Y ; load a byte (self modified) ; 4
sta $700,Y ; store a byte (self modified) ; 5
lda $F80,Y ; load a byte (self modified) ; 4
sta $780,Y ; store a byte (self modified) ; 5
dey ; decrement pointer ; 2
bpl gr_copy_line ; ; 2nt/3
rts ; 6

192
fire/gr_fast_clear.s Normal file
View File

@ -0,0 +1,192 @@
clear_screens:
;===================================
; Clear top/bottom of page 0
;===================================
lda #$0
sta DRAW_PAGE
jsr clear_top
jsr clear_bottom
;===================================
; Clear top/bottom of page 1
;===================================
lda #$4
sta DRAW_PAGE
jsr clear_top
jsr clear_bottom
rts
clear_bottoms:
;===================================
; Clear bottom of page 0
;===================================
lda #$0
sta DRAW_PAGE
jsr clear_bottom
;===================================
; Clear bottom of page 1
;===================================
lda #$4
sta DRAW_PAGE
jsr clear_bottom
rts
;=========================================================
; clear_top
;=========================================================
; clear DRAW_PAGE
; original = 14,558 cycles(?) 15ms, 70Hz
; OPTIMIZED MAX (page0,48rows): 45*120+4+6 = 5410 = 5.4ms 185Hz
; (pageX,40rows): 50*120+4+6 = 6010 = 6.0ms 166Hz
; 50*120+4+6+37 = 6055 = 6.0ms 166Hz
clear_top:
lda #0 ; 2
clear_top_a:
sta COLOR ; 3
clc ; 2
lda DRAW_PAGE ; 3
adc #4 ; 2
sta __ctf+2 ; 3
sta __ctf+5 ; 3
adc #1 ; 2
sta __ctf+8 ; 3
sta __ctf+11 ; 3
adc #1 ; 2
sta __ctf2+2 ; 3
sta __ctf2+5 ; 3
adc #1 ; 2
sta __ctf2+8 ; 3
sta __ctf2+11 ; 3
ldy #120 ; 2
lda COLOR ; 3
clear_top_fast_loop:
__ctf:
sta $400,Y ; 5
sta $480,Y ; 5
sta $500,Y ; 5
sta $580,Y ; 5
cpy #80 ; 2
bpl no_draw_bottom ; 2nt/3
__ctf2:
sta $600,Y ; 5
sta $680,Y ; 5
sta $700,Y ; 5
sta $780,Y ; 5
no_draw_bottom:
dey ; 2
bpl clear_top_fast_loop ; 2nt/3
rts ; 6
;=========================================================
; clear_bottom
;=========================================================
; clear bottom of draw page
clear_bottom:
clc ; 2
lda DRAW_PAGE ; 3
adc #6 ; 2
sta __cbf2+2 ; 3
sta __cbf2+5 ; 3
adc #1 ; 2
sta __cbf2+8 ; 3
sta __cbf2+11 ; 3
ldy #120 ; 2
lda #$a0 ; Normal Space ; 2
clear_bottom_fast_loop:
__cbf2:
sta $600,Y ; 5
sta $680,Y ; 5
sta $700,Y ; 5
sta $780,Y ; 5
dey ; 2
cpy #80 ; 2
bpl clear_bottom_fast_loop ; 2nt/3
rts ; 6
clear_screens_notext:
;===================================
; Clear top/bottom of page 0
;===================================
lda #$0
sta DRAW_PAGE
jsr clear_all
;===================================
; Clear top/bottom of page 1
;===================================
lda #$4
sta DRAW_PAGE
jsr clear_all
rts
;=========================================================
; clear_all
;=========================================================
; clear 48 rows
clear_all:
clc ; 2
lda DRAW_PAGE ; 3
adc #4 ; 2
sta __caf+2 ; 3
sta __caf+5 ; 3
adc #1 ; 2
sta __caf+8 ; 3
sta __caf+11 ; 3
adc #1 ; 2
sta __caf2+2 ; 3
sta __caf2+5 ; 3
adc #1 ; 2
sta __caf2+8 ; 3
sta __caf2+11 ; 3
ldy #120 ; 2
clear_all_color:
lda #0 ; 2
clear_all_fast_loop:
__caf:
sta $400,Y ; 5
sta $480,Y ; 5
sta $500,Y ; 5
sta $580,Y ; 5
__caf2:
sta $600,Y ; 5
sta $680,Y ; 5
sta $700,Y ; 5
sta $780,Y ; 5
dey ; 2
bpl clear_all_fast_loop ; 2nt/3
rts ; 6

4
fire/gr_offsets.s Normal file
View File

@ -0,0 +1,4 @@
gr_offsets:
.word $400,$480,$500,$580,$600,$680,$700,$780
.word $428,$4a8,$528,$5a8,$628,$6a8,$728,$7a8
.word $450,$4d0,$550,$5d0,$650,$6d0,$750,$7d0

View File

@ -1,648 +0,0 @@
;=========================================================
; fast copy rows 22-36 from $C00 to $400
;=========================================================
;
; 6 + 7*8*40 = 2246 cycles
; 6*7*40 = 1680 bytes of code?
gr_copy_row22:
;= y = 22 $5a8 $da8/$9a8 =========================
; x=0,y=22
lda $da8
sta $5a8
lda $da9
sta $5a9
lda $daa
sta $5aa
lda $dab
sta $5ab
lda $dac
sta $5ac
lda $dad
sta $5ad
lda $dae
sta $5ae
lda $daf
sta $5af
; x=8,y=22
lda $db0
sta $5b0
lda $db1
sta $5b1
lda $db2
sta $5b2
lda $db3
sta $5b3
lda $db4
sta $5b4
lda $db5
sta $5b5
lda $db6
sta $5b6
lda $db7
sta $5b7
; x=16,y=22
lda $db8
sta $5b8
lda $db9
sta $5b9
lda $dba
sta $5ba
lda $dbb
sta $5bb
lda $dbc
sta $5bc
lda $dbd
sta $5bd
lda $dbe
sta $5be
lda $dbf
sta $5bf
; x=24,y=22
lda $dc0
sta $5c0
lda $dc1
sta $5c1
lda $dc2
sta $5c2
lda $dc3
sta $5c3
lda $dc4
sta $5c4
lda $dc5
sta $5c5
lda $dc6
sta $5c6
lda $dc7
sta $5c7
; x=32,y=22
lda $dc8
sta $5c8
lda $dc9
sta $5c9
lda $dca
sta $5ca
lda $dcb
sta $5cb
lda $dcc
sta $5cc
lda $dcd
sta $5cd
lda $dce
sta $5ce
lda $dcf
sta $5cf
;= y = 24 $628 $e28/$a28 =========================
; x=0,y=24
lda $e28
sta $628
lda $e29
sta $629
lda $e2a
sta $62a
lda $e2b
sta $62b
lda $e2c
sta $62c
lda $e2d
sta $62d
lda $e2e
sta $62e
lda $e2f
sta $62f
; x=8,y=24
lda $e30
sta $630
lda $e31
sta $631
lda $e32
sta $632
lda $e33
sta $633
lda $e34
sta $634
lda $e35
sta $635
lda $e36
sta $636
lda $e37
sta $637
; x=16,y=24
lda $e38
sta $638
lda $e39
sta $639
lda $e3a
sta $63a
lda $e3b
sta $63b
lda $e3c
sta $63c
lda $e3d
sta $63d
lda $e3e
sta $63e
lda $e3f
sta $63f
; x=24,y=24
lda $e40
sta $640
lda $e41
sta $641
lda $e42
sta $642
lda $e43
sta $643
lda $e44
sta $644
lda $e45
sta $645
lda $e46
sta $646
lda $e47
sta $647
; x=32,y=24
lda $e48
sta $648
lda $e49
sta $649
lda $e4a
sta $64a
lda $e4b
sta $64b
lda $e4c
sta $64c
lda $e4d
sta $64d
lda $e4e
sta $64e
lda $e4f
sta $64f
;= y = 26 $6a8 $ea8/$aa8 =========================
; x=0,y=26
lda $ea8
sta $6a8
lda $ea9
sta $6a9
lda $eaa
sta $6aa
lda $eab
sta $6ab
lda $eac
sta $6ac
lda $ead
sta $6ad
lda $eae
sta $6ae
lda $eaf
sta $6af
; x=8,y=26
lda $eb0
sta $6b0
lda $eb1
sta $6b1
lda $eb2
sta $6b2
lda $eb3
sta $6b3
lda $eb4
sta $6b4
lda $eb5
sta $6b5
lda $eb6
sta $6b6
lda $eb7
sta $6b7
; x=16,y=26
lda $eb8
sta $6b8
lda $eb9
sta $6b9
lda $eba
sta $6ba
lda $ebb
sta $6bb
lda $ebc
sta $6bc
lda $ebd
sta $6bd
lda $ebe
sta $6be
lda $ebf
sta $6bf
; x=24,y=26
lda $ec0
sta $6c0
lda $ec1
sta $6c1
lda $ec2
sta $6c2
lda $ec3
sta $6c3
lda $ec4
sta $6c4
lda $ec5
sta $6c5
lda $ec6
sta $6c6
lda $ec7
sta $6c7
; x=32,y=26
lda $ec8
sta $6c8
lda $ec9
sta $6c9
lda $eca
sta $6ca
lda $ecb
sta $6cb
lda $ecc
sta $6cc
lda $ecd
sta $6cd
lda $ece
sta $6ce
lda $ecf
sta $6cf
;= y = 28 $728 $f28/$b28 =========================
; x=0,y=28
lda $f28
sta $728
lda $f29
sta $729
lda $f2a
sta $72a
lda $f2b
sta $72b
lda $f2c
sta $72c
lda $f2d
sta $72d
lda $f2e
sta $72e
lda $f2f
sta $72f
; x=8,y=28
lda $f30
sta $730
lda $f31
sta $731
lda $f32
sta $732
lda $f33
sta $733
lda $f34
sta $734
lda $f35
sta $735
lda $f36
sta $736
lda $f37
sta $737
; x=16,y=28
lda $f38
sta $738
lda $f39
sta $739
lda $f3a
sta $73a
lda $f3b
sta $73b
lda $f3c
sta $73c
lda $f3d
sta $73d
lda $f3e
sta $73e
lda $f3f
sta $73f
; x=24,y=28
lda $f40
sta $740
lda $f41
sta $741
lda $f42
sta $742
lda $f43
sta $743
lda $f44
sta $744
lda $f45
sta $745
lda $f46
sta $746
lda $f47
sta $747
; x=32,y=28
lda $f48
sta $748
lda $f49
sta $749
lda $f4a
sta $74a
lda $f4b
sta $74b
lda $f4c
sta $74c
lda $f4d
sta $74d
lda $f4e
sta $74e
lda $f4f
sta $74f
;= y = 30 $7a8 $fa8/$ba8 =========================
; x=0,y=30
lda $fa8
sta $7a8
lda $fa9
sta $7a9
lda $faa
sta $7aa
lda $fab
sta $7ab
lda $fac
sta $7ac
lda $fad
sta $7ad
lda $fae
sta $7ae
lda $faf
sta $7af
; x=8,y=30
lda $fb0
sta $7b0
lda $fb1
sta $7b1
lda $fb2
sta $7b2
lda $fb3
sta $7b3
lda $fb4
sta $7b4
lda $fb5
sta $7b5
lda $fb6
sta $7b6
lda $fb7
sta $7b7
; x=16,y=30
lda $fb8
sta $7b8
lda $fb9
sta $7b9
lda $fba
sta $7ba
lda $fbb
sta $7bb
lda $fbc
sta $7bc
lda $fbd
sta $7bd
lda $fbe
sta $7be
lda $fbf
sta $7bf
; x=24,y=30
lda $fc0
sta $7c0
lda $fc1
sta $7c1
lda $fc2
sta $7c2
lda $fc3
sta $7c3
lda $fc4
sta $7c4
lda $fc5
sta $7c5
lda $fc6
sta $7c6
lda $fc7
sta $7c7
; x=32,y=30
lda $fc8
sta $7c8
lda $fc9
sta $7c9
lda $fca
sta $7ca
lda $fcb
sta $7cb
lda $fcc
sta $7cc
lda $fcd
sta $7cd
lda $fce
sta $7ce
lda $fcf
sta $7cf
;= y = 32 $450 $c50/$850 =========================
; x=0,y=32
lda $c50
sta $450
lda $c51
sta $451
lda $c52
sta $452
lda $c53
sta $453
lda $c54
sta $454
lda $c55
sta $455
lda $c56
sta $456
lda $c57
sta $457
; x=8,y=32
lda $c58
sta $458
lda $c59
sta $459
lda $c5a
sta $45a
lda $c5b
sta $45b
lda $c5c
sta $45c
lda $c5d
sta $45d
lda $c5e
sta $45e
lda $c5f
sta $45f
; x=16,y=32
lda $c60
sta $460
lda $c61
sta $461
lda $c62
sta $462
lda $c63
sta $463
lda $c64
sta $464
lda $c65
sta $465
lda $c66
sta $466
lda $c67
sta $467
; x=24,y=32
lda $c68
sta $468
lda $c69
sta $469
lda $c6a
sta $46a
lda $c6b
sta $46b
lda $c6c
sta $46c
lda $c6d
sta $46d
lda $c6e
sta $46e
lda $c6f
sta $46f
; x=32,y=32
lda $c70
sta $470
lda $c71
sta $471
lda $c72
sta $472
lda $c73
sta $473
lda $c74
sta $474
lda $c75
sta $475
lda $c76
sta $476
lda $c77
sta $477
;= y = 34 $4d0 $cd0/$8d0 =========================
; x=0,y=34
lda $cd0
sta $4d0
lda $cd1
sta $4d1
lda $cd2
sta $4d2
lda $cd3
sta $4d3
lda $cd4
sta $4d4
lda $cd5
sta $4d5
lda $cd6
sta $4d6
lda $cd7
sta $4d7
; x=8,y=34
lda $cd8
sta $4d8
lda $cd9
sta $4d9
lda $cda
sta $4da
lda $cdb
sta $4db
lda $cdc
sta $4dc
lda $cdd
sta $4dd
lda $cde
sta $4de
lda $cdf
sta $4df
; x=16,y=34
lda $ce0
sta $4e0
lda $ce1
sta $4e1
lda $ce2
sta $4e2
lda $ce3
sta $4e3
lda $ce4
sta $4e4
lda $ce5
sta $4e5
lda $ce6
sta $4e6
lda $ce7
sta $4e7
; x=24,y=34
lda $ce8
sta $4e8
lda $ce9
sta $4e9
lda $cea
sta $4ea
lda $ceb
sta $4eb
lda $cec
sta $4ec
lda $ced
sta $4ed
lda $cee
sta $4ee
lda $cef
sta $4ef
; x=32,y=34
lda $cf0
sta $4f0
lda $cf1
sta $4f1
lda $cf2
sta $4f2
lda $cf3
sta $4f3
lda $cf4
sta $4f4
lda $cf5
sta $4f5
lda $cf6
sta $4f6
lda $cf7
sta $4f7
rts ; 6

119
fire/random16.s Normal file
View 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