Make more globals per player and index into them with the player number at game time.

This commit is contained in:
Jeremy Rand 2021-01-10 23:17:05 -05:00
parent 1cd4ccea3a
commit 384a9ea233
12 changed files with 127 additions and 71 deletions

View File

@ -98,7 +98,7 @@
9D6DB0B825932CA600CDBF05 /* scorpion.raw */ = {isa = PBXFileReference; lastKnownFileType = text; path = scorpion.raw; sourceTree = "<group>"; }; 9D6DB0B825932CA600CDBF05 /* scorpion.raw */ = {isa = PBXFileReference; lastKnownFileType = text; path = scorpion.raw; sourceTree = "<group>"; };
9D6DB164259D759C00CDBF05 /* tileConvert.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = tileConvert.s; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.asm.orcam; }; 9D6DB164259D759C00CDBF05 /* tileConvert.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = tileConvert.s; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.asm.orcam; };
9D6DB18625A411DA00CDBF05 /* BuGS.2mg */ = {isa = PBXFileReference; lastKnownFileType = file; path = BuGS.2mg; sourceTree = "<group>"; }; 9D6DB18625A411DA00CDBF05 /* BuGS.2mg */ = {isa = PBXFileReference; lastKnownFileType = file; path = BuGS.2mg; sourceTree = "<group>"; };
9D8AF0B72535542400C10E3C /* level.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = level.s; sourceTree = "<group>"; }; 9D8AF0B72535542400C10E3C /* level.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = level.s; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.asm.orcam; };
9D8AF0B82535543000C10E3C /* score.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = score.s; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.asm.orcam; }; 9D8AF0B82535543000C10E3C /* score.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = score.s; sourceTree = "<group>"; xcLanguageSpecificationIdentifier = xcode.lang.asm.orcam; };
9D8FFC602491CA28005C9327 /* game.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = game.s; sourceTree = "<group>"; }; 9D8FFC602491CA28005C9327 /* game.s */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.asm; path = game.s; sourceTree = "<group>"; };
9D8FFC612491CAF0005C9327 /* game.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = game.h; sourceTree = "<group>"; }; 9D8FFC612491CAF0005C9327 /* game.h */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.c.h; path = game.h; sourceTree = "<group>"; };

View File

@ -188,9 +188,9 @@ startGame entry
startGame_notRunning anop startGame_notRunning anop
sta isSinglePlayer sta isSinglePlayer
stz gameRunning stz gameRunning
jsl addRandomMushrooms
jsl scoreStartGame
jsl initPlayer jsl initPlayer
jsl scoreStartGame
jsl addRandomMushrooms
jsl spiderInitGame jsl spiderInitGame
jsl levelInit jsl levelInit
jsl soundInit jsl soundInit

View File

@ -98,9 +98,10 @@ updateFlea_explosionDone anop
updateFlea_maybeAdd anop updateFlea_maybeAdd anop
lda gameRunning lda gameRunning
bne updateFlea_doNotAdd bne updateFlea_doNotAdd
lda gameLevel ldx playerNum
lda gameLevel,x
beq updateFlea_doNotAdd beq updateFlea_doNotAdd
lda scoreNum20000 lda scoreNum20000,x
bne updateFlea_moreThan20000 bne updateFlea_moreThan20000
; Below 20000 points, 5 or more mushrooms do not result in a flea ; Below 20000 points, 5 or more mushrooms do not result in a flea
lda #4 lda #4
@ -119,7 +120,7 @@ updateFlea_moreThan120000 anop
clc clc
adc #8 adc #8
updateFlea_checkNumMushrooms anop updateFlea_checkNumMushrooms anop
cmp numInfieldMushrooms cmp numInfieldMushrooms,x
blt updateFlea_doNotAdd blt updateFlea_doNotAdd
jmp addFlea jmp addFlea
@ -181,7 +182,8 @@ updateFlea_nextTile anop
sta tileDirty,x sta tileDirty,x
cpx #SPIDER_STARTING_TOP_ROW_OFFSET cpx #SPIDER_STARTING_TOP_ROW_OFFSET
blt updateFlea_nextAction blt updateFlea_nextAction
inc numInfieldMushrooms ldx playerNum
inc numInfieldMushrooms,x
bra updateFlea_nextAction bra updateFlea_nextAction
updateFlea_bottom anop updateFlea_bottom anop
@ -203,7 +205,8 @@ addFlea entry
lda fleaState lda fleaState
bne addFlea_done bne addFlea_done
lda scoreNum20000 ldx playerNum
lda scoreNum20000,x
cmp #3 cmp #3
bge addFlea_fast bge addFlea_fast
lda #SPRITE_SPEED_SLOW lda #SPRITE_SPEED_SLOW

View File

@ -98,39 +98,41 @@ addRandomMushrooms entry
lda #INVALID_TILE_NUM lda #INVALID_TILE_NUM
sta mushroomToRefresh sta mushroomToRefresh
ldx #RHS_FIRST_TILE_OFFSET-2 ldy #RHS_FIRST_TILE_OFFSET-2
addRandomMushrooms_clear anop addRandomMushrooms_clear anop
lda tileType,x lda tileType,y
beq addRandomMushrooms_skipClear beq addRandomMushrooms_skipClear
lda #TILE_EMPTY lda #TILE_EMPTY
sta tileType,x sta tileType,y
lda #TILE_STATE_DIRTY lda #TILE_STATE_DIRTY
sta tileDirty,x sta tileDirty,y
addRandomMushrooms_skipClear anop addRandomMushrooms_skipClear anop
dex dey
dex dey
bpl addRandomMushrooms_clear bpl addRandomMushrooms_clear
stz numInfieldMushrooms ldx playerNum
ldy #STARTING_NUM_MUSHROOMS stz numInfieldMushrooms,x
ldx #STARTING_NUM_MUSHROOMS
addRandomMushrooms_loop anop addRandomMushrooms_loop anop
phy phx
addRandomMushrooms_tryAgain anop addRandomMushrooms_tryAgain anop
jsl randomMushroomOffset jsl randomMushroomOffset
tax tay
lda tileType,x lda tileType,y
bne addRandomMushrooms_tryAgain bne addRandomMushrooms_tryAgain
lda #TILE_MUSHROOM4 lda #TILE_MUSHROOM4
sta tileType,x sta tileType,y
lda #TILE_STATE_DIRTY lda #TILE_STATE_DIRTY
sta tileDirty,x sta tileDirty,y
cpx #SPIDER_STARTING_TOP_ROW_OFFSET cpy #SPIDER_STARTING_TOP_ROW_OFFSET
blt addRandomMushrooms_notInfield blt addRandomMushrooms_notInfield
inc numInfieldMushrooms ldx playerNum
inc numInfieldMushrooms,x
addRandomMushrooms_notInfield anop addRandomMushrooms_notInfield anop
ply plx
dey dex
bne addRandomMushrooms_loop bne addRandomMushrooms_loop
rtl rtl
@ -157,7 +159,8 @@ shootMushroom_poisoned anop
shootMushroom_empty anop shootMushroom_empty anop
cpx #SPIDER_STARTING_TOP_ROW_OFFSET cpx #SPIDER_STARTING_TOP_ROW_OFFSET
blt shootMushrom_notInfield blt shootMushrom_notInfield
dec numInfieldMushrooms ldx playerNum
dec numInfieldMushrooms,x
shootMushrom_notInfield anop shootMushrom_notInfield anop
jmp scoreAddOne jmp scoreAddOne

View File

@ -110,9 +110,9 @@ playerAddLife_playerOne anop
lda #P1_LIVES_OFFSET lda #P1_LIVES_OFFSET
playerAddLife_cont anop playerAddLife_cont anop
sec sec
sbc numLives sbc numLives,x
sec sec
sbc numLives sbc numLives,x
inc numLives,x inc numLives,x
tax tax
lda #TILE_PLAYER lda #TILE_PLAYER

View File

@ -90,7 +90,8 @@ updateScorpion entry
updateScorpion_playerOnscreen anop updateScorpion_playerOnscreen anop
lda scorpionState lda scorpionState
bne updateScorpion_cont bne updateScorpion_cont
lda gameLevel ldx playerNum
lda gameLevel,x
cmp #3 cmp #3
blt updateScorpion_doNotAdd blt updateScorpion_doNotAdd
jsl rand0_to_65534 jsl rand0_to_65534
@ -265,7 +266,8 @@ addScorpion entry
rtl rtl
addScorpion_doit anop addScorpion_doit anop
lda scoreNum20000 ldx playerNum
lda scoreNum20000,x
bne addScorpion_randomSpeed bne addScorpion_randomSpeed
addScorpion_slow anop addScorpion_slow anop
lda #SPRITE_SPEED_SLOW lda #SPRITE_SPEED_SLOW

View File

@ -1811,7 +1811,8 @@ shootSegment_doneScore anop
shootSegment_noMushroom anop shootSegment_noMushroom anop
cpy #SPIDER_STARTING_TOP_ROW_OFFSET cpy #SPIDER_STARTING_TOP_ROW_OFFSET
blt shootSegment_normalMushroom blt shootSegment_normalMushroom
inc numInfieldMushrooms ldx playerNum
inc numInfieldMushrooms,x
shootSegment_normalMushroom anop shootSegment_normalMushroom anop
lda #TILE_MUSHROOM4 lda #TILE_MUSHROOM4
shootSegment_dirtyTile anop shootSegment_dirtyTile anop

View File

@ -444,7 +444,10 @@ updateSpider_tilesUp anop
sta tileDirty,x sta tileDirty,x
cpx #SPIDER_STARTING_TOP_ROW_OFFSET cpx #SPIDER_STARTING_TOP_ROW_OFFSET
blt updateSpider_tilesUpCont blt updateSpider_tilesUpCont
dec numInfieldMushrooms ldy playerNum
lda numInfieldMushrooms,y
dec a
sta numInfieldMushrooms,y
updateSpider_tilesUpCont anop updateSpider_tilesUpCont anop
ldx spiderTileOffsets+10 ldx spiderTileOffsets+10
@ -523,7 +526,10 @@ updateSpider_tilesDown anop
sta tileDirty,x sta tileDirty,x
cpx #SPIDER_STARTING_TOP_ROW_OFFSET cpx #SPIDER_STARTING_TOP_ROW_OFFSET
blt updateSpider_tilesDownCont blt updateSpider_tilesDownCont
dec numInfieldMushrooms ldy playerNum
lda numInfieldMushrooms,y
dec a
sta numInfieldMushrooms,y
updateSpider_tilesDownCont anop updateSpider_tilesDownCont anop
ldx spiderTileOffsets+8 ldx spiderTileOffsets+8
@ -581,9 +587,12 @@ addSpider entry
rtl rtl
addSpider_checkSpeed anop addSpider_checkSpeed anop
lda gameScore+2 lda playerNum
asl a
tax
lda gameScore+2,x
bne addSpider_fast bne addSpider_fast
lda gameScore lda gameScore,x
cmp #5000 cmp #5000
bge addSpider_fast bge addSpider_fast
lda #SPRITE_SPEED_SLOW lda #SPRITE_SPEED_SLOW
@ -602,7 +611,8 @@ addSpider_setHeight anop
; 120,000 to 139,999 - 9th row from bottom ; 120,000 to 139,999 - 9th row from bottom
; 140,000 to 159,999 - 8th row from bottom ; 140,000 to 159,999 - 8th row from bottom
; 160,000 to ... - 7th row from bottom ; 160,000 to ... - 7th row from bottom
lda scoreNum20000 ldx playerNum
lda scoreNum20000,x
cmp #6 cmp #6
blt addSpider_height10 blt addSpider_height10
beq addSpider_height9 beq addSpider_height9

View File

@ -218,16 +218,20 @@ _dirtyNonGameTile_skip&SYSCNT anop
; Update the score ; Update the score
macro macro
_incrementScore &increment _incrementScore &increment
lda playerNum
asl a
tax
lda #&increment lda #&increment
clc clc
adc gameScore adc gameScore,x
sta gameScore sta gameScore,x
bcc _incrementScore_noCarry&SYSCNT bcc _incrementScore_noCarry&SYSCNT
inc gameScore+2 inc gameScore+2,x
_incrementScore_noCarry&SYSCNT anop _incrementScore_noCarry&SYSCNT anop
ldx playerNum
lda #&increment lda #&increment
clc clc
adc scoreWithin12000 adc scoreWithin12000,x
cmp #12000 cmp #12000
blt _incrementScore_noExtraMan&SYSCNT blt _incrementScore_noExtraMan&SYSCNT
sec sec
@ -235,16 +239,17 @@ _incrementScore_noCarry&SYSCNT anop
pha pha
jsl playerAddLife jsl playerAddLife
pla pla
ldx playerNum
_incrementScore_noExtraMan&SYSCNT anop _incrementScore_noExtraMan&SYSCNT anop
sta scoreWithin12000 sta scoreWithin12000,x
lda #&increment lda #&increment
clc clc
adc scoreWithin20000 adc scoreWithin20000,x
cmp #20000 cmp #20000
blt _incrementScore_no2000&SYSCNT blt _incrementScore_no2000&SYSCNT
sec sec
sbc #20000 sbc #20000
inc scoreNum20000 inc scoreNum20000,x
_incrementScore_no2000&SYSCNT anop _incrementScore_no2000&SYSCNT anop
sta scoreWithin20000 sta scoreWithin20000,x
mend mend

View File

@ -143,15 +143,6 @@ gameRunning dc i2'1'
; The following data values hold the game state and when/if 2 player is supported, ; The following data values hold the game state and when/if 2 player is supported,
; this information will need to be copied to a backup location when the player ; this information will need to be copied to a backup location when the player
; switches. ; switches.
numSegments dc i2'0'
gameLevel dc i2'0'
gameScore dc i4'0'
scoreWithin12000 dc i2'0'
scoreWithin20000 dc i2'0'
scoreNum20000 dc i2'0'
centipedeLevelNum dc i2'0'
colourLevelNum dc i2'0'
numInfieldMushrooms dc i2'0'
scoreOnesOffset dc i2'0' scoreOnesOffset dc i2'0'
scoreTensOffset dc i2'0' scoreTensOffset dc i2'0'
scoreHundredsOffset dc i2'0' scoreHundredsOffset dc i2'0'
@ -159,17 +150,37 @@ scoreThousandsOffset dc i2'0'
; tileType ; tileType
; Two values for each of these, indexed by playerNum
gameScore dc i4'0'
dc i4'0'
scoreWithin12000 dc i2'0'
dc i2'0'
scoreWithin20000 dc i2'0'
dc i2'0'
scoreNum20000 dc i2'0'
dc i2'0'
numInfieldMushrooms dc i2'0'
dc i2'0'
numLives dc i2'0'
dc i2'0'
gameLevel dc i2'0'
dc i2'0'
colourLevelNum dc i2'0'
dc i2'0'
centipedeLevelNum dc i2'0'
dc i2'0'
playerState dc i2'PLAYER_STATE_NONE' playerState dc i2'PLAYER_STATE_NONE'
playerNum dc i2'0' playerNum dc i2'0'
isSinglePlayer dc i2'0' isSinglePlayer dc i2'0'
numLives dc i2'0' ; Two values for this, indexed by playerNum
dc i2'0'
mouseX dc i2'0' mouseX dc i2'0'
mouseY dc i2'0' mouseY dc i2'0'
mouseAddress dc i2'0' mouseAddress dc i2'0'
backupStack dc i2'0' backupStack dc i2'0'
collision dc i2'0' collision dc i2'0'
collisionAddr dc i2'0' collisionAddr dc i2'0'
numSegments dc i2'0'
tileJumpTable dc a4'solid0' tileJumpTable dc a4'solid0'

View File

@ -19,19 +19,24 @@ NEXT_LEVEL_FRAME_COUNT equ 60
levelInit entry levelInit entry
stz gameLevel stz gameLevel
stz gameLevel+2
stz centipedeLevelNum stz centipedeLevelNum
stz centipedeLevelNum+2
stz colourLevelNum stz colourLevelNum
stz colourLevelNum+2
lda #SEGMENT_SPEED_FAST lda #SEGMENT_SPEED_FAST
sta levelOne+2 sta levelOne+2
rtl rtl
levelStart entry levelStart entry
lda colourLevelNum ldx playerNum
lda colourLevelNum,x
jsl setColour jsl setColour
jsl startSegmentSound jsl startSegmentSound
ldx centipedeLevelNum ldy playerNum
ldx centipedeLevelNum,y
lda levelTable,x lda levelTable,x
tax tax
lda |$0,x lda |$0,x
@ -50,7 +55,7 @@ levelStart entry
asl a asl a
asl a asl a
asl a asl a
ldx centipedeLevelNum ldx centipedeLevelNum,y
clc clc
adc levelTable,x adc levelTable,x
tax tax
@ -98,20 +103,23 @@ updateLevel_done anop
rtl rtl
levelNext entry levelNext entry
lda colourLevelNum ldx playerNum
lda colourLevelNum,x
inc a inc a
cmp #NUM_COLOUR_PALETTES cmp #NUM_COLOUR_PALETTES
blt levelNext_skip blt levelNext_skip
lda #0 lda #0
levelNext_skip anop levelNext_skip anop
sta colourLevelNum sta colourLevelNum,x
inc gameLevel ldx playerNum
inc gameLevel,x
lda scoreNum20000 lda scoreNum20000,x
cmp #2 cmp #2
bge levelNext_fastOnly bge levelNext_fastOnly
ldy centipedeLevelNum ldx playerNum
ldy centipedeLevelNum,x
ldx levelTable,y ldx levelTable,y
lda |$2,x lda |$2,x
cmp #SEGMENT_SPEED_FAST cmp #SEGMENT_SPEED_FAST
@ -121,7 +129,8 @@ levelNext_skip anop
rtl rtl
levelNext_slowIncrement anop levelNext_slowIncrement anop
lda centipedeLevelNum ldx playerNum
lda centipedeLevelNum,x
cmp #LEVEL_TABLE_LAST_OFFSET cmp #LEVEL_TABLE_LAST_OFFSET
bge levelNext_slowWrap bge levelNext_slowWrap
inc a inc a
@ -130,7 +139,7 @@ levelNext_slowIncrement anop
levelNext_slowWrap anop levelNext_slowWrap anop
lda #0 lda #0
levelNext_slowNoWrap anop levelNext_slowNoWrap anop
sta centipedeLevelNum sta centipedeLevelNum,x
tay tay
ldx levelTable,y ldx levelTable,y
lda #SEGMENT_SPEED_SLOW lda #SEGMENT_SPEED_SLOW
@ -138,7 +147,8 @@ levelNext_slowNoWrap anop
rtl rtl
levelNext_fastOnly anop levelNext_fastOnly anop
lda centipedeLevelNum ldx playerNum
lda centipedeLevelNum,x
cmp #LEVEL_TABLE_LAST_OFFSET cmp #LEVEL_TABLE_LAST_OFFSET
bge levelNext_fastWrap bge levelNext_fastWrap
inc a inc a
@ -147,7 +157,7 @@ levelNext_fastOnly anop
levelNext_fastWrap anop levelNext_fastWrap anop
lda #0 lda #0
levelNext_fastNoWrap anop levelNext_fastNoWrap anop
sta centipedeLevelNum sta centipedeLevelNum,x
tay tay
ldx levelTable,y ldx levelTable,y
lda #SEGMENT_SPEED_FAST lda #SEGMENT_SPEED_FAST

View File

@ -91,9 +91,14 @@ updateHighScore entry
scoreStartGame entry scoreStartGame entry
stz gameScore stz gameScore
stz gameScore+2 stz gameScore+2
stz gameScore+4
stz gameScore+6
stz scoreWithin12000 stz scoreWithin12000
stz scoreWithin12000+2
stz scoreWithin20000 stz scoreWithin20000
stz scoreWithin20000+2
stz scoreNum20000 stz scoreNum20000
stz scoreNum20000+2
ldx #P1_SCORE_ONES_OFFSET ldx #P1_SCORE_ONES_OFFSET
lda #TILE_NUMBER_0 lda #TILE_NUMBER_0
@ -378,12 +383,15 @@ scoreAddOneThousand_skipZeroHundreds anop
checkHighScore entry checkHighScore entry
ldy #0 ldy #0
checkHighScore_loop anop checkHighScore_loop anop
lda playerNum
asl a
tax
lda settings+SETTINGS_HIGH_SCORE_OFFSET+HIGH_SCORE_SCORE_OFFSET+2,y lda settings+SETTINGS_HIGH_SCORE_OFFSET+HIGH_SCORE_SCORE_OFFSET+2,y
cmp gameScore+2 cmp gameScore+2,x
blt checkHighScore_isHighScore blt checkHighScore_isHighScore
bne checkHighScore_next bne checkHighScore_next
lda settings+SETTINGS_HIGH_SCORE_OFFSET+HIGH_SCORE_SCORE_OFFSET,y lda settings+SETTINGS_HIGH_SCORE_OFFSET+HIGH_SCORE_SCORE_OFFSET,y
cmp gameScore cmp gameScore,x
blt checkHighScore_isHighScore blt checkHighScore_isHighScore
checkHighScore_next anop checkHighScore_next anop
tya tya
@ -411,9 +419,12 @@ checkHighScore_copyLoop anop
bra checkHighScore_copyLoop bra checkHighScore_copyLoop
checkHighScore_doneCopy anop checkHighScore_doneCopy anop
ldy scoreIndex ldy scoreIndex
lda gameScore lda playerNum
asl a
tax
lda gameScore,x
sta settings+SETTINGS_HIGH_SCORE_OFFSET+HIGH_SCORE_SCORE_OFFSET,y sta settings+SETTINGS_HIGH_SCORE_OFFSET+HIGH_SCORE_SCORE_OFFSET,y
lda gameScore+2 lda gameScore+2,x
sta settings+SETTINGS_HIGH_SCORE_OFFSET+HIGH_SCORE_SCORE_OFFSET+2,y sta settings+SETTINGS_HIGH_SCORE_OFFSET+HIGH_SCORE_SCORE_OFFSET+2,y
lda playerNum lda playerNum