Advertisement
Guest User

pokemon gold backup bg palette copy

a guest
Jan 17th, 2017
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.83 KB | None | 0 0
  1. 0x3557: LD A, 0xE4
  2. CALL 0x0C61
  3.  
  4. LDH BGP, A ; Stores 0xE4 in BGP
  5. PUSH AF
  6. LDH A, 0xFFE8 ; The value at this address is 0x01, unsure of it's significance
  7. AND A
  8. JR Z, + 0x18 ; Jump not taken
  9. PUSH HL
  10. PUSH DE
  11. PUSH BC
  12. LD HL, 0xC280 ; In the render loop, Pokemon Gold copies 64 bytes starting at 0xC280 into BG palette ram
  13. LD DE, 0xC200 ; In the loop below, it copies 64 bytes offset from 0xC200 into the 0xC280 region
  14. LDH A, BGP ; Reads value stored in BGP into A, even in CGB mode
  15. LD B, A
  16. LD C, 0x08
  17. CALL 0x0CEA
  18.  
  19. loop0: PUSH BC ; Store outer loop counter
  20. LD C, 0x04
  21. loop1: PUSH DE
  22. PUSH HL ; Stores the pointer into the backup palette ram region
  23. LD A, B ; On the first iteration, B holds the value in BGP
  24. AND 0x03
  25. ADD A, A
  26. LD L, A ; The game uses the shifted BGP as an offset from 0xC200 to copy values from there into the
  27. ; backup palette region
  28. LD H, 0x00
  29. ADD HL, DE
  30. LD E, (HL)
  31. INC HL
  32. LD D, (HL)
  33. POP HL ; Retrieves the pointer into the backup palette ram region
  34. LD (HL), E
  35. INC HL
  36. LD (HL), D
  37. INC HL
  38. SRL B
  39. SRL B ; Right shifts the BGP value twice
  40. POP DE
  41. DEC C
  42. JR NZ, loop1
  43. LD A, 0x08
  44. ADD A, E ; Increments the pointer which intitially pointed to 0xC200
  45. JR NC, skip
  46. INC D
  47. skip: LD E, A
  48. POP BC ; After 4 inner loop iterations, the value of BGP has been shifted out of B. Here, the
  49. ; original value of BGP is popped back in.
  50. DEC C
  51. JR NZ, loop0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement