I am working with assembly for the 65C816, specifically to make a SNES ROM. In a guide I found online there was some code to set the background color. The SNES supports 16-bit color so the format is as such:
Code:
0bbbbbgggggrrrrr
It said that the $2122 refers to the Color Data Register. I know that the 65C816 is a 16-bit CPU, and I'm assuming it's word-addressable so that every address refers to a 16-bit location.
Here is a snippet the code the guide provided that changes the background color to blue:
Code:
SEP #$20 ; Set the A register to 8-bit.
LDA #%00000000 ; Load the low byte of the blue color.
STA $2122
LDA #%01111100 ; Load the high byte of the blue color.
STA $2122
What I don't understand is why we set the A register to 8-bit mode if color is a 16-bit value? And then how do 2 STA's with 8-bit operands to $2122 result in a 16-bit write to $2122?
Also according to
this wiki article, $2122 is the "Data for CG-RAM Write" and $2121 is the "Address for CG-RAM Write". How does the write to $2122 happen successfully without first writing to $2121?
My main file also has a line:
Code:
.include "Snes_Init.asm"
and within Snes_Init.asm there is a line
Code:
stz $2121 ; Color number register ($0-ff)
which gets called. Is this is how the CG-RAM Write Address is set?
Any help clarifying would be appreciated!