Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- 0x3557: LD A, 0xE4
- CALL 0x0C61
- LDH BGP, A ; Stores 0xE4 in BGP
- PUSH AF
- LDH A, 0xFFE8 ; The value at this address is 0x01, unsure of it's significance
- AND A
- JR Z, + 0x18 ; Jump not taken
- PUSH HL
- PUSH DE
- PUSH BC
- LD HL, 0xC280 ; In the render loop, Pokemon Gold copies 64 bytes starting at 0xC280 into BG palette ram
- LD DE, 0xC200 ; In the loop below, it copies 64 bytes offset from 0xC200 into the 0xC280 region
- LDH A, BGP ; Reads value stored in BGP into A, even in CGB mode
- LD B, A
- LD C, 0x08
- CALL 0x0CEA
- loop0: PUSH BC ; Store outer loop counter
- LD C, 0x04
- loop1: PUSH DE
- PUSH HL ; Stores the pointer into the backup palette ram region
- LD A, B ; On the first iteration, B holds the value in BGP
- AND 0x03
- ADD A, A
- LD L, A ; The game uses the shifted BGP as an offset from 0xC200 to copy values from there into the
- ; backup palette region
- LD H, 0x00
- ADD HL, DE
- LD E, (HL)
- INC HL
- LD D, (HL)
- POP HL ; Retrieves the pointer into the backup palette ram region
- LD (HL), E
- INC HL
- LD (HL), D
- INC HL
- SRL B
- SRL B ; Right shifts the BGP value twice
- POP DE
- DEC C
- JR NZ, loop1
- LD A, 0x08
- ADD A, E ; Increments the pointer which intitially pointed to 0xC200
- JR NC, skip
- INC D
- skip: LD E, A
- POP BC ; After 4 inner loop iterations, the value of BGP has been shifted out of B. Here, the
- ; original value of BGP is popped back in.
- DEC C
- JR NZ, loop0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement