Skip to content

Commit

Permalink
Border uses palettes 4-6 only (gbdev#440)
Browse files Browse the repository at this point in the history
SGB firmware in Mesen-S updates palette 7 during menu navigation 
and fades palettes 4, 5, and 6 during border updates. This means a
border cannot safely use palette 7.

Also clarify the meaning of letterboxing, and document the tile format.

Co-authored-by: Antonio Vivace <[email protected]>
Co-authored-by: Eldred Habert <[email protected]>
  • Loading branch information
3 people authored Oct 9, 2022
1 parent ae89342 commit 0fbd0ec
Showing 1 changed file with 16 additions and 10 deletions.
26 changes: 16 additions & 10 deletions src/SGB_Command_Border.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,8 @@ tiles 00h-7Fh, and once for tiles 80h-FFh). Note: The BG/OBJ Bit seems
to have no effect and writes to the same VRAM addresses for both BG and
OBJ ???

TODO: explain tile format
Each tile is stored in 4-bit-per-pixel format consisting of bit planes 0 and 1 interleaved by row, followed by bit planes 2 and 3 interleaved by row.
In effect, each tile consists of two Game Boy tiles, the first to determine bits 0 and 1 (choosing among color 0, 1, 2, or 3 within a 4-color subpalette), and the second to determine bits 2 and 3 (choosing among colors 0-3, 4-7, 8-11, or 12-15).

## SGB Command $14 — PCT_TRN

Expand All @@ -48,16 +49,16 @@ The map data is sent by VRAM-Transfer (4 KBytes).
```
000-6FF BG Map 32x28 Entries of 16 bits each (1792 bytes)
700-7FF Not used, don't care
800-87F BG Palette Data (Palettes 4-7, each 16 colors of 16 bits each)
880-FFF Not used, don't care
800-85F BG Palette Data (Palettes 4-6, 16 little-endian RGB555 colors each)
860-FFF Not used, don't care
```

Each BG Map Entry consists of a 16-bit value as such:
`VH01 PP00 NNNN NNNN```

```
Bit 0-9 - Character Number (use only 00h-FFh, upper 2 bits zero)
Bit 10-12 - Palette Number (use only 4-7, officially use only 4-6)
Bit 10-12 - Palette Number (use only 4-6)
Bit 13 - BG Priority (use only 0)
Bit 14 - X-Flip (0=Normal, 1=Mirror horizontally)
Bit 15 - Y-Flip (0=Normal, 1=Mirror vertically)
Expand All @@ -70,16 +71,21 @@ window to be displayed inside. Non-transparent border data will cover
the Game Boy window (for example, *Mario's Picross* does this, as does
*WildSnake* to a lesser extent).

A border designed for a modern (post-2006) widescreen television may use the center 256×176 pixels and leave the top and bottom 24 lines blank.
Using letterbox allows more tile variety in the portion of the border that a widescreen TV's zoom mode does not cut off.

All borders repeat tiles. Assuming that the blank space for the GB
screen is a single tile, as is the letterbox in a widescreen border, a
screen is a blank tile, and the letterbox (if any) is a solid tile, a
border defining all unique tiles would have to define this many tiles:

- (256\*224-160\*144)/64+1 = 537 tiles in fullscreen border
- (256\*176-160\*144)/64+2 = 346 tiles in widescreen border
- (256\*224-160\*144)/64+1 = 537 tiles in full-screen border
- (256\*176-160\*144)/64+2 = 346 tiles in letterboxed border

Because the CHR RAM allocated by SGB for border holds only 256 tiles, a full-screen border must repeat at least 281 tiles and a letterboxed border at least 90.

But the CHR RAM allocated by SGB for border holds only 256 tiles. This
means a fullscreen border must repeat at least 281 tiles and a
widescreen border at least 90.
The Super NES supports 8 background palettes.
The SGB system software (when run in a LLE such as Mesen-S) has been observed to use background palette 0 for the GB screen, palettes 1, 2, 3, and 7 for the menus, and palettes 4, 5, and 6 for the border.
Thus a border can use three 15-color palettes.

## SGB Command $18 — OBJ_TRN

Expand Down

0 comments on commit 0fbd0ec

Please sign in to comment.