Minor optimizations and refactoring

This commit is contained in:
Dagen Brock 2014-05-08 15:26:37 -05:00
parent a41677dd7b
commit 4a0248ce28
5 changed files with 128 additions and 107 deletions

View File

@ -140,20 +140,17 @@ UndrawBird lda BIRD_Y
:continue ldx BIRD_X
cmp #4
beq :undraw4
:undraw3 tya ; we don't need height anymore, trash it
asl
tay
lda LoLineTable,y
:undraw3 lda LoLineTableL,y
sta SPRITE_SCREEN_P
lda LoLineTable+1,y
lda LoLineTableH,y
sta SPRITE_SCREEN_P+1
lda LoLineTable+2,y
lda LoLineTableL+1,y
sta SPRITE_SCREEN_P2
lda LoLineTable+3,y
lda LoLineTableH+1,y
sta SPRITE_SCREEN_P2+1
lda LoLineTable+4,y
lda LoLineTableL+2,y
sta SPRITE_SCREEN_P3
lda LoLineTable+5,y
lda LoLineTableH+2,y
sta SPRITE_SCREEN_P3+1
txa
@ -183,24 +180,21 @@ UndrawBird lda BIRD_Y
:undraw4 tya ; we don't need height anymore, trash it
asl
tay
lda LoLineTable,y
:undraw4 lda LoLineTableL,y
sta SPRITE_SCREEN_P
lda LoLineTable+1,y
lda LoLineTableH,y
sta SPRITE_SCREEN_P+1
lda LoLineTable+2,y
lda LoLineTableL+1,y
sta SPRITE_SCREEN_P2
lda LoLineTable+3,y
lda LoLineTableH+1,y
sta SPRITE_SCREEN_P2+1
lda LoLineTable+4,y
lda LoLineTableL+2,y
sta SPRITE_SCREEN_P3
lda LoLineTable+5,y
lda LoLineTableH+2,y
sta SPRITE_SCREEN_P3+1
lda LoLineTable+6,y
lda LoLineTableL+3,y
sta SPRITE_SCREEN_P4
lda LoLineTable+7,y
lda LoLineTableH+3,y
sta SPRITE_SCREEN_P4+1
txa
@ -231,11 +225,6 @@ UndrawBird lda BIRD_Y
jmp UndrawBirdDone
DrawBird
lda BIRD_X
sta SPRITE_X
lda #5
sta SPRITE_W ; all birds are same width
lda BIRD_Y
lsr
bcs :oddHeight

View File

@ -99,6 +99,18 @@ LoLineTable da Lo01,Lo02,Lo03,Lo04,Lo05,Lo06
da Lo07,Lo08,Lo09,Lo10,Lo11,Lo12
da Lo13,Lo14,Lo15,Lo16,Lo17,Lo18
da Lo19,Lo20,Lo21,Lo22,Lo23,Lo24
** Here we split the table for an optimization
** We can directly get our line numbers now
** Without using ASL
LoLineTableH db >Lo01,>Lo02,>Lo03,>Lo04,>Lo05,>Lo06
db >Lo07,>Lo08,>Lo09,>Lo10,>Lo11,>Lo12
db >Lo13,>Lo14,>Lo15,>Lo16,>Lo17,>Lo18
db >Lo19,>Lo20,>Lo21,>Lo22,>Lo23,>Lo24
LoLineTableL db <Lo01,<Lo02,<Lo03,<Lo04,<Lo05,<Lo06
db <Lo07,<Lo08,<Lo09,<Lo10,<Lo11,<Lo12
db <Lo13,<Lo14,<Lo15,<Lo16,<Lo17,<Lo18
db <Lo19,<Lo20,<Lo21,<Lo22,<Lo23,<Lo24
MainAuxMap
hex 00,08,01,09,02,0A,03,0B,04,0C,05,0D,06,0E,07,0F
hex 80,88,81,89,82,8A,83,8B,84,8C,85,8D,86,8E,87,8F

View File

@ -31,6 +31,13 @@ Main
lda #$77
jsr DL_Clear
** taken from DrawBird
** these don't really change so saving some cycles
lda BIRD_X
sta SPRITE_X
lda #5
sta SPRITE_W ; all birds are same width
GameLoop
; handle input
@ -42,20 +49,32 @@ GameLoop
; update score
jsr VBlank
jmp UndrawBird
UndrawBirdDone
lda #3
sta $c034
jmp UpdatePipes
UpdatePipesDone
jsr FlapBird
jmp UpdateGrass
UpdateGrassDone
lda #4
sta $c034
jmp UndrawBird
UndrawBirdDone
lda #5
sta $c034
jmp DrawPipes
DrawPipesDone
lda #6
sta $c034
jmp HandleInput
HandleInputDone
jmp DrawBird
DrawBirdDone
lda #7
sta $c034
jmp DrawScore
DrawScoreDone
jmp UpdateGrass
UpdateGrassDone
jsr FlapBird
;jsr WaitKey
lda QuitFlag
beq GameLoop
@ -385,12 +404,18 @@ _vblType db 0 ; 0 - normal, 1 - IIc
* Wait for vertical blanking interval - IIe/IIgs
**************************************************
VBlankNormal
VBlankGS lda #$FE
VBlankGS lda #0
sta $c034
lda #$FE
:vblInProgress cmp RDVBLBAR
bpl :vblInProgress
bmi :vblInProgress
lda #1
sta $c034
lda #$FE
:vblWaitForStart cmp RDVBLBAR
bmi :vblWaitForStart
bpl :vblWaitForStart
lda #2
sta $c034
rts

View File

@ -16,27 +16,28 @@
* DrawPipeEvenL - draw even aligned pipes / clipped left
*
**************************************************
PipeSpr_Main
hex 55,e5,e5,c5,e5,c5,c5,c5,c5,45,c5,45,45,55,77
hex 55,5e,5e,5c,5e,5c,5c,5c,5c,54,5c,54,54,55,77
hex 77,55,ee,ee,cc,ee,cc,cc,44,cc,44,44,55,77,77
** DEPRECATED, but this is the "linear" format
*PipeSpr_Main hex 55,e5,e5,c5,e5,c5,c5,c5,c5,45,c5,45,45,55,77
* hex 55,5e,5e,5c,5e,5c,5c,5c,5c,54,5c,54,54,55,77
* hex 77,55,ee,ee,cc,ee,cc,cc,44,cc,44,44,55,77,77
*PipeSpr_Aux hex aa,7a,7a,6a,7a,6a,6a,6a,6a,2a,6a,2a,2a,aa,bb
* hex aa,a7,a7,a6,a7,a6,a6,a6,a6,a2,a6,a2,a2,aa,bb
* hex bb,aa,77,77,66,77,66,66,22,66,22,22,aa,bb,bb
** "interleave" format
PipeBody_Main_E hex 55,ee,ee,cc,cc,44,77
PipeBody_Main_O hex 77,ee,cc,cc,44,44,55,77
PipeSpr_Aux
hex aa,7a,7a,6a,7a,6a,6a,6a,6a,2a,6a,2a,2a,aa,bb
hex aa,a7,a7,a6,a7,a6,a6,a6,a6,a2,a6,a2,a2,aa,bb
hex bb,aa,77,77,66,77,66,66,22,66,22,22,aa,bb,bb
PipeBody_Aux_E hex bb,77,66,66,22,22,aa,bb
PipeBody_Aux_O hex aa,77,77,66,66,22,bb
PipeInterval equ #60 ; game ticks to spawn new pipe
PipeSpawn db 0 ; our counter
PipeInterval equ #65 ; game ticks to spawn new pipe
PipeSpawn db #45 ; our counter, starting point for spawning
PipeSpawnSema db 0 ; points to next spot (even if currently unavailable)
MaxPipes equ 2
TopPipes hex 00,00,00,00
BotPipes hex 00,00,00,00
TopPipes ds MaxPipes*2 ; Space for pipe X,Y
BotPipes ds MaxPipes*2 ; "
BotPipeMin equ 3
BotPipeMax equ 8
@ -59,10 +60,9 @@ PIPE_EVEN_ODD db 0 ; 0=even, Y=odd
PIPE_TOP equ 0 ; enum for top pipe type
PIPE_BOT equ 1 ; enum for bottom pipe type
PipeXScore equ 50
ScoreLo db 0
ScoreHi db 0
PipeXScore equ 50 ; pipe at this value causes score increase
ScoreLo db 0 ; 0-99
ScoreHi db 0 ; hundreds, not shown on screen
* pipe min = 15x6 pixels = 15x3 bytes
* playfield = 80x48 pixels = 80x24 bytes
@ -79,9 +79,30 @@ UpdatePipes inc PipeSpawn
lda #0
sta PipeSpawn
:noSpawn
MoveDrawPipes
jsr MovePipes
jsr DrawPipes
MovePipes
ldx #2 ;MaxPipes*2?
:loop lda BotPipes,x
beq :noPipe
dec BotPipes,x
dec TopPipes,x
cmp #PipeXScore+1 ; A should still be set
bne :noScore
:ScoreUp sed
lda ScoreLo
clc
adc #1
sta ScoreLo
bcc :noFlip
lda ScoreHi
adc #0
sta ScoreHi
:noFlip cld
:noScore
:noPipe dex
dex
bpl :loop
jmp UpdatePipesDone
@ -107,69 +128,43 @@ SpawnPipe lda PipeSpawnSema
:done rts
MovePipes
ldx #2 ;MaxPipes*2?
:loop lda BotPipes,x
beq :noPipe
dec BotPipes,x
dec TopPipes,x
cmp #PipeXScore+1 ; A should still be set
bne :noScore
:ScoreUp sed
lda ScoreLo
clc
adc #1
sta ScoreLo
bcc :noFlip
lda ScoreHi
adc #0
sta ScoreHi
:noFlip cld
:noScore
:noPipe dex
dex
bpl :loop
rts
DrawPipes
lda BotPipes ;BotPipes[0]
beq :noP1
sta PIPE_X_FULL
ldx #PIPE_BOT
stx PIPE_T_B
ldy BotPipes+1
sty PIPE_Y
jsr DrawPipe
DrawPipes
lda #PIPE_TOP ; =0
sta PIPE_T_B
lda TopPipes ;TopPipes[0]
beq :noTP0
sta PIPE_X_FULL
ldx #PIPE_TOP
stx PIPE_T_B
ldy TopPipes+1
sty PIPE_Y
jsr DrawPipe
:noP1
lda BotPipes+2 ;BotPipes[1]
beq :noP2
ldx #PIPE_BOT
stx PIPE_T_B
sta PIPE_X_FULL
ldy BotPipes+3
sty PIPE_Y
jsr DrawPipe
ldx #PIPE_TOP
stx PIPE_T_B
lda TopPipes+2
:noTP0
lda TopPipes+2 ;TopPipes[0]
beq :noTP1
sta PIPE_X_FULL
ldy TopPipes+3
sty PIPE_Y
jsr DrawPipe
:noP2
rts
:noTP1
inc PIPE_T_B ; =1 now (see above)
lda BotPipes ;BotPipes[0]
beq :noBP0
sta PIPE_X_FULL
ldy BotPipes+1
sty PIPE_Y
jsr DrawPipe
:noBP0
lda BotPipes+2 ;BotPipes[1]
beq :noBP1
sta PIPE_X_FULL
ldy BotPipes+3
sty PIPE_Y
jsr DrawPipe
:noBP1
jmp DrawPipesDone
* Used by all of the routines that draw the pipe caps

View File

@ -93,7 +93,7 @@ DD_EVEN lda #0
beq :noCollision
cmp #$0B
beq :noCollision
lda #1
lda #9
sta SPRITE_COLLISION
sta $c034
@ -139,7 +139,7 @@ DD_ODD
beq :noCollision
cmp #$07
beq :noCollision
lda #1
lda #9
sta SPRITE_COLLISION
sta $c034