Language…
23 users online: akawo, Alex No,  AmperSam, autisticsceptile1993,  BeeKaay, deadworld2009,  DeppySlide, edgar, Green, JezJitzu,  MarioFanGamer, Metal-Yoshi94, MistaX88, MorrieTheMagpie, Nayfal,  NopeContest, Pink Gold Peach, Rykon-V73, SolveForX,  Telinc1, timeisart, Tulip Time Scholarship Games, wye - Guests: 287 - Bots: 447
Users: 64,795 (2,370 active)
Latest user: mathew

Updating palettes with ASM (resolved)

So I want to make this setting sun effect on my BG; where the further you go in the level, the further down the sun goes. For this to look any decent I need to dynamically update the BG palette.

I suppose this is the question: How in the world do I do that? Normally I would just read through all.log a bit, but I don't think I can really trust it since Lunar Magic makes a lot of changes to the palette related routines.

And I'm already using HDMA, so sadly that's not an option.

allow shy guy emojis in post footers you cowards!
you can use palette exanimation with manual triggers. then, in levelasm, you would modify the trigger based on your location in the level (make it permanent so going backwards in the level wont make it brighter)
Ok, thanks. It's late where I live so I'll try that in the morning. Now I can rest easy :)

allow shy guy emojis in post footers you cowards!
Just throwing it out there, that you could also DMA to the CGRAM controlling the palettes.
Ladida's suggestions is WAY more simple but limited to the triggers so... yeah, just wanted to state that for future generations ending up here. :3
Anime statistic on MyAnimeList:
400 animes completed ✓
6000 episodes completed ✓
100 Days completed ✓
... what even am I doing with my life?
Originally posted by JackTheSpades
Ladida's suggestions is WAY more simple but limited to the triggers so...

there's no limitation on what you can do with the manual/custom triggers, since they are ram addresses you can directly modify. the only limitation is the lm-imposed one on exanimation where slots run every 8th frame
And so morning arrives in the land o' vikings and I try using manual exanimation. I decided to use the time remaining timer (there's gotta be a better term for this) to control what frame to use. The problem is something really weird happens. I use a generator to update the trigger every 0xFF frames but whenever the update happens the game just crashes. I have confirmed that this piece of code is the culprit:

Code

; A is the time remaining (in hex, 16 bit) when this code is run

.CalcPal	LDX #$00			; Start at X = 00
.LoopPal	SEC
		SBC #$0019			; Subtract 0x19 (25)
		BMI .WritePal
		INX				; Add 1 to animation frame for every 25 seconds remaining
		BRA .LoopPal

.WritePal	SEP #$20			; A 8 bit
		TXA				; Transfer animation frame from X
		STA $7FC070			; Store to exanimaiton manual trigger 0


A bit of extra info: If I update the trigger every frame the game gets stuck at the level intro mosaic, which it loops over and over. If I put the generator at a later screen It plays the Mario death sound, messes up some graphics in the BG, and crashes the game when it spawns.

...Yeah, it's really weird. I'm not even storing to anything! How does it crash!?

EDIT: In case it wasn't clear, the loop is what kills the game. If I skip it and just store a value to $7FC070 it works just fine, except that, you know, it's not affected by the timer.

allow shy guy emojis in post footers you cowards!
Do you even RTS/RTL from the branch?
Originally posted by Torchkas
Do you even RTS/RTL from the branch?


Yeah, after a bit. I do my HDMA code after the trigger update.

allow shy guy emojis in post footers you cowards!
would help to see the rest of the code. the one you posted looks fine.

make sure X is 8bit and A is 16bit i guess, since stuff like that easily trips up how the code is assembled vs how it's interpreted
Originally posted by Ladida
would help to see the rest of the code. the one you posted looks fine.

make sure X is 8bit and A is 16bit i guess, since stuff like that easily trips up how the code is assembled vs how it's interpreted


Ok, slight wall of text commencing. This is the entire code:
Code
		LDA $14				;\ Only update palette every #$FF frames to save processing power
		BNE .JustHDMA			;/

		REP #$20			; A 16 bit
		LDX $0F31			; Load 100s of timer in X
		LDA #$0000			; Start at A = 00
.Loop100s	DEX				;\
		BMI .Calc10s			; |
		CLC				; | Convert to hex and add to A
		ADC #$64			; |
		BRA .Loop100s			;/
.Calc10s	LDX $0F32			; Load 10s of timer in X
.Loop10s	DEX				;\
		BMI .Calc1s			; |
		CLC				; | Convert to hex and add to A
		ADC #$0A			; |
		BRA .Loop10s			;/
.Calc1s		LDX $0F32			; Load 1s of timer in X
.Loop1s		DEX				;\
		BMI .BreakLoop			; | Convert to hex and add to A
		INC A				; |
		BRA .Loop1s			;/

; A = timer (in hex)
;
; When the level starts A = 0x190 (400)
;
; The Sun will completely set at A = 0xC8 (200)
; After that the visuals don't change.
; The BG needs to be updated every 0x19 (25) seconds
; The layer 3 Sun needs to be updated more often though.

.BreakLoop	SEC				;\ SUbtract 0xC8 (200)
		SBC #$00C8			;/
		BPL .CalcPal			;\
		LDX #$07			; | Use the last frame if less than 200 seconds are remaining
		BRA .WritePal			;/

.CalcPal	LDX #$00			; Start at X = 00
.LoopPal	SEC
		SBC #$0019			; Subtract 0x19 (25)
		BMI .WritePal
		INX				; Add 1 to animation frame for every 25 seconds remaining
		BRA .LoopPal

.WritePal	SEP #$20			; A 8 bit
		TXA				; Transfer animation frame from X
		STA $7FC070			; Store to exanimaiton manual trigger 0

.JustHDMA


After .JustHDMA comes my HDMA code, as you might have guessed. I can confirm that the HDMA works fine and does not cause crashes.

allow shy guy emojis in post footers you cowards!
in .Loop100s and .Loop10s, you are doing 8bit ADC when it should be 16bit
Originally posted by Ladida
in .Loop100s and .Loop10s, you are doing 8bit ADC when it should be 16bit


That's.. actually correct. I fixed it and it works now. Thanks mate!

allow shy guy emojis in post footers you cowards!