Display/IO Ports

From WSdev Wiki
Revision as of 15:21, 22 February 2025 by Asie (talk | contribs) (Created page with "== Graphics I/O ports == {{Anchor|Display Control}} === Display Control ($00) === <pre> 7 bit 0 ---- ---- ..wo Ws21 || |||| || |||+- Enable Screen 1 layer || ||+-- Enable Screen 2 layer || |+--- Enable Sprite layer || +---- Enable Sprite window |+------ Screen 2 tiles are drawn (if window enabled): | 0 = inside window, | 1 = outside window. +------- Enable Screen 2 window </pre> {{Anchor|Display Background}} === Display Background Co...")
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigationJump to search

Graphics I/O ports

Display Control ($00)

7  bit  0
---- ----
..wo Ws21
  || ||||
  || |||+- Enable Screen 1 layer
  || ||+-- Enable Screen 2 layer
  || |+--- Enable Sprite layer
  || +---- Enable Sprite window
  |+------ Screen 2 tiles are drawn (if window enabled):
  |        0 = inside window,
  |        1 = outside window.
  +------- Enable Screen 2 window

Display Background Color ($01)

  (mono)             (color)
7  bit  0           7  bit  0
---- ----           ---- ----
.... .sss           pppp iiii
      |||           |||| ||||
      +++- Value    |||| ++++- Index in palette (0-15)
           (0-7)    ++++------ Color palette (0-15)

Display Current Line ($02 read)

The current line being drawn by the display.

Note that lines are sent to the display with a one-line delay. This matters for color palette or shade LUT manipulation; changing these values when current line == 1 will actually affect line 0.

Display Interrupt Line ($03)

The line to emit an interrupt on.

Sprite Table Address ($04)

7  bit  0
---- ----
..Aa aaaa
  || ||||
  |+-++++- Address (bits 9-13)
  +------- Address (bit 14) - color only

Sprite Table First ($05)

7  bit  0
---- ----
.iii iiii
 ||| ||||
 +++-++++- Index of first sprite entry to draw (0-127)

Sprite Table Count ($06)

7  bit  0
---- ----
cccc cccc
|||| ||||
++++-++++- Count of sprite entries to draw (1-128)

Screen Address ($07)

7  bit  0
---- ----
2222 1111
|||| ||||
|||| |+++- Screen 1 address (bits 11-13)
|||| +---- Screen 1 address (bit 14) - color only
|+++------ Screen 2 address (bits 11-13)
+--------- Screen 2 address (bit 14) - color only

Screen 2 Window Left ($08)

Screen 2 Window Top ($09)

Screen 2 Window Right ($0A)

Screen 2 Window Bottom ($0B)

The X and Y coordinates of the Screen 2 window.

Note that all coordinates are inclusive; for example, for a 200x100 window in the top-left corner, the values should be set as follows:

  • Left - 0,
  • Top - 0,
  • Right - 199,
  • Bottom - 99.

Sprite Window Left ($0C)

Sprite Window Top ($0D)

Sprite Window Right ($0E)

Sprite Window Bottom ($0F)

The X and Y coordinates of the Sprite window.

Note that all coordinates are inclusive.

Screen 1 Scroll X ($10)

Screen 1 Scroll Y ($11)

The X and Y coordinates that Screen 1 is scrolled by.

For example, setting Scroll X to 24 and Scroll Y to 8 will omit, in 8x8 tile units, the first three rows and the first two columns of the 32x32 screen.

Screen 2 Scroll X ($12)

Screen 2 Scroll Y ($13)

The X and Y coordinates that Screen 2 is scrolled by.

Palette I/O ports

These I/O ports are only used in the monochrome display mode. Color display modes use the memory locations $FE00 - $FFFF to store the color palette.

Mono Shade LUT ($1C, $1D, $1E, $1F)

   $1C         $1D         $1E         $1F
7  bit  0   7  bit  0   7  bit  0   7  bit  0
---- ----   ---- ----   ---- ----   ---- ----
1111 0000   3333 2222   5555 4444   7777 6666
|||| ||||   |||| ||||   |||| ||||   |||| ||||
|||| ||||   |||| ||||   |||| ||||   |||| ++++- Shade for LUT index 6
|||| ||||   |||| ||||   |||| ||||   ++++------ Shade for LUT index 7
|||| ||||   |||| ||||   |||| ++++------------- Shade for LUT index 4
|||| ||||   |||| ||||   ++++------------------ Shade for LUT index 5
|||| ||||   |||| ++++------------------------- Shade for LUT index 2
|||| ||||   ++++------------------------------ Shade for LUT index 3
|||| ++++------------------------------------- Shade for LUT index 0
++++------------------------------------------ Shade for LUT index 1

Mono Palette 0..15 ($20, $21 .. $3E, $3F)

The monochrome palette is laid out as sixteen words:

    N+1         N
15  bit  8  7  bit  0
 ---- ----  ---- ----
 .333 .222  .111 .000
  |||  |||   |||  |||
  |||  |||   |||  +++- Shade LUT index for color 0
  |||  |||   +++------ Shade LUT index for color 1
  |||  +++------------ Shade LUT index for color 2
  +++----------------- Shade LUT index for color 3

LCD I/O ports

LCD Control ($14)

7  bit  0
---- ----
.... ..Ce
       ||
       |+- LCD enable: 0 = sleep, 1 = enabled
       +-- Contrast (WSC): 0 = low, 1 = high

The enable bit controls whether or not the LCD screen is displaying graphics; if sleeping, it displays nothing (all white). Note that icon segments continue displaying regardless of this configuration.

Note that port $1A provides a separate LCD sleep bit; the display will be disabled in the same way if any of those bits are set to "sleep".

The contrast bit allows enabling a "high contrast" mode: this works by having the LCD drive two lines with data received from the SoC - so the first line of the LCD is driven by the first line from the SoC, then additionally by the second line from the SoC.

LCD Icon Control ($15)

7  bit  0
---- ----
..32 1hvs
  || ||||
  || |||+- Sleep (Star)
  || ||+-- Vertical orientation
  || |+--- Horizontal orientation
  || +---- Etc. 1 (Small circle)
  |+------ Etc. 2 (Medium circle)
  +------- Etc. 3 (Large circle)

LCD internal I/O ports

These I/O ports are not used and most likely not intended for use by commercial games.

LCD Final Line ($16)

The final line preceding line counter restart and the beginning of active display. By default, this is set to 158, which equals 159 total lines per frame.

It is said setting this register to an odd value on SwanCrystal has an adverse effect to the LCD panel,[1] but the exact mechanism is unknown. A starting point for research is that an even value, or odd total line count, is needed to balance positive and negative charges on the LCD.[2]

LCD Back Porch Line ($17, WSC only)

This port is available on the WonderSwan Color only - not the SwanCrystal!

The final line preceding the vertical back porch; by default, this should be set to 155.

The vertical back porch of the LCD is assumed to be 4 lines by some hardware, including IPS mods, as well as the official "TV Swan" capture device. Given that the first visible line is sent to the LCD on the display's line 1, this should be generally set to LCD Final Line - 3.

Conversely, it is said moving this value closer to vertical blank improves LCD visibility[3], but the exact mechanism is unknown.

LCD Status ($1A)

7  bit  0
---- ----
...v vvhs
   | ||||
   | |||+- LCD sleep: 0 = no, 1 = sleep
   | ||+-- Headphone icon
   | ||
   | ||    Volume icons:
   | |+--- - Volume B (medium, high)
   | +---- - Volume A (low, high)
   +------ - Speaker

The LCD sleep bit is writable. The remaining bits are read-only.

The volume and headphone icon are enabled when pressing the SOUND button, according to this algorithm:

  • If headphones are plugged in, show the Headphone icon.
  • If headphones are not plugged in, show the Speaker icon and the following Volume icons:
    • Volume level 0: None
    • Volume level 1: A
    • Volume level 2: B
    • Volume level 3: A, B
  • Hide all visible icons after 128 frames from the last press.

TODO: This documents the WonderSwan Color. The specifics probably work differently on the mono WonderSwan.

TFT LCD Configuration ($70, $71, $72, $73, $74, $75, $76, $77 SwanCrystal only)

These eight bytes are read from internal EEPROM and configure unknown aspects of the console's TFT LCD panel.

They are only writable while the Boot ROM is unlocked - locking has the side effect of making them read-only.

Notes

  1. REG_LCD_VTOTAL - WSMan
  2. W.A. Steer. "LCD monitor technology and tests". Techmind, 2011-12-03. Accessed 2024-11-19.
  3. REG_LCD_VSYNC - WSMan