puppydrum64
Active member
I'm trying to figure out how the game knows to switch background palettes when warping to a new screen that has a different palette from the old screen.
The following code for a warp tile causes the proper background palette to be loaded, despite never jumping to a subroutine or using the update background palettes macro:
This code works properly. However, this code which I wrote does not. It loads the correct background tiles but the old palette is retained from the previous screen. As far as I can tell this code does all the same things the warp tile code does.
The code that seems to update background palettes is never used in either script listed above. Yet the first one somehow updates the palettes correctly. Why?
From what I can tell, neither the above subroutine (nor its parent macro) are used whatsoever in the warp tile script or my modified game start script.
The following code for a warp tile causes the proper background palette to be loaded, despite never jumping to a subroutine or using the update background palettes macro:
Code:
TYA
PHA
CPX player1_object
BNE notPlayerForWarpTile
LDA warpToScreen
STA continueScreen
WarpToScreen warpToMap, warpToScreen, #$01
;; arg0 = warp to map. 0= map1. 1= map2.
;; arg1 = screen to warp to.
;; arg2 = screen transition type - most likely use 1 here.
;; 1 = warp, where it observes the warp in position for the player.
INC bossHealthPointer
LDY bossHealthPointer
LDA BossHealthTable,y
STA bossHealth ;; resets boss health for the new level.
notPlayerForWarpTile:
PLA
TAY
This code works properly. However, this code which I wrote does not. It loads the correct background tiles but the old palette is retained from the previous screen. As far as I can tell this code does all the same things the warp tile code does.
Code:
startGameWithNewContinuePoints:
LDA screenUpdateByte
ORA #%00000100
STA screenUpdateByte
LDA warpToMap
STA warpMap
LDA warpToScreen
STA currentNametable
LDX player1_object
STA Object_screen,x
LDA #$01
STA screenTransitionType ;; is of warp type
LDA #$00
STA isTwoPlayerGame
LDA Code1Verified
CMP #$01
BEQ +ExtraLives
LDA #$03
STA myLives
JMP +SkipCheats
+ExtraLives
LDA #$06
STA myLives
+SkipCheats
LDA #$00
STA CheatCode1CorrectCount ;resets the code input counters and code usage. Otherwise the memory of an unfinished cheat code would be "stored" for next time the game is continued from the title screen.
STA CheatCode2CorrectCount
WarpToScreen warpToMap, warpToScreen, #$01
RTS
;============================================================
; TWO PLAYER GAME
;============================================================
startTwoPlayerGame:
LDA screenUpdateByte
ORA #%00000100
STA screenUpdateByte
LDA warpToMap
STA warpMap
LDA warpToScreen
STA currentNametable
LDX player1_object
STA Object_screen,x
LDX player2_object
STA Object_screen,x
LDA #$01
STA isTwoPlayerGame
LDA #$01
STA screenTransitionType ;; is of warp type
LDA Code1Verified
CMP #$01
BEQ +ExtraLives
LDA #$03
STA myLives
STA player2Lives
JMP +SkipCheats
+ExtraLives
LDA #$06
STA myLives
STA player2Lives
+SkipCheats
WarpToScreen warpToMap, warpToScreen, #$01
RTS
The code that seems to update background palettes is never used in either script listed above. Yet the first one somehow updates the palettes correctly. Why?
Code:
0C5AE doLoadBackgroundPalettes:
0C5AE ;; This is tied to the macro LoadBackgroundPalettes.
0C5AE ;; It uses bank and 16 bit label.
0C5AE 8A TXA
0C5AF 48 PHA
0C5B0 98 TYA
0C5B1 48 PHA
0C5B2 ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
0C5B2 ;Get Palette Label based on INDEX
0C5B2 98 48 AD 20 06 8D 21 06.. SwitchBank #$16
0C5C1 A4 0C LDY arg0_hold
0C5C3 B9 00 84 LDA GameBckPalLo,y
0C5C6 85 14 STA temp16
0C5C8 B9 40 84 LDA GameBckPalHi,y
0C5CB 85 15 STA temp16+1
0C5CD
0C5CD
0C5CD A0 00 LDY #$00
0C5CF loop_LoadBackgroundPalette:
0C5CF B1 14 LDA (temp16),y
0C5D1 99 25 06 STA bckPal,y
0C5D4 C8 INY
0C5D5 C0 10 CPY #$10
0C5D7 D0 F6 BNE loop_LoadBackgroundPalette
0C5D9 ;;;; end of loop.
0C5D9 AD 24 06 LDA updateScreenData
0C5DC 09 01 ORA #%00000001 ;; palette
0C5DE 8D 24 06 STA updateScreenData
0C5E1
0C5E1
0C5E1 98 48 AC 21 06 20 9F C5.. ReturnBank
0C5EB ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
0C5EB
0C5EB 68 PLA
0C5EC A8 TAY
0C5ED 68 PLA
0C5EE AA TAX
0C5EF 60 RTS0C5F0
From what I can tell, neither the above subroutine (nor its parent macro) are used whatsoever in the warp tile script or my modified game start script.