Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimization prevents use of CGB palette autoincrement #859

Open
nummacway opened this issue Jul 16, 2024 · 0 comments
Open

Optimization prevents use of CGB palette autoincrement #859

nummacway opened this issue Jul 16, 2024 · 0 comments

Comments

@nummacway
Copy link

The CGB has 8 BG and OBJ palettes each. Each palette has 4 colors. Each color has two bytes (RGB1555) LE. So they're 64 bytes.
One does not simply write the CGB palette. You ask the CGB to make $FF69 (BG) or $FF6B (OBJ) the desired byte, by writing the index in $FF68 (BG) or $FF6A (OBJ). Now you can read or write $FF69 or $FF6B like it was that byte of the palette. Because you'll always want to write at least 2 bytes, the CGB thankfully has an autoincrement feature, so it increments $FF68 after every write to $FF69 (BG, OBJ is comparable). You simply or $80 when writing the index and then repeatedly write to $FF69 or $FF6B.

var
  BCPS: Byte absolute $FF68;
  BCPD: Byte absolute $FF69;

// ...

begin
  // ...

  // request palette 0, color 0, byte 0 and enable autoincrement
  BCPS := $80;
  // write black to that color
  BCPD := 0;
  BCPD := 0;
  // write white to the next color
  BCPD := $ff; 
  BCPD := $7f;

  // ...
end;

This doesn't work because OrgAsm simply ignores the second write to BCPD. If you write more colors after that, the consecutive colors begin to shift. So the color first color isn't black but #ff3f00 orange (the last 3 bits of the green component aren't actually defined, but it will still be orange) and the second color isn't white either.
Is there a way to make this work without inline Asm?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant