23#ifndef LIBWS_DISPLAY_H_
24#define LIBWS_DISPLAY_H_
44#define WS_DISPLAY_WIDTH_TILES 28
45#define WS_DISPLAY_HEIGHT_TILES 18
46#define WS_DISPLAY_WIDTH_PIXELS (WS_DISPLAY_WIDTH_TILES * WS_DISPLAY_TILE_WIDTH)
47#define WS_DISPLAY_HEIGHT_PIXELS (WS_DISPLAY_HEIGHT_TILES * WS_DISPLAY_TILE_HEIGHT)
49#define WS_DISPLAY_TILE_WIDTH 8
50#define WS_DISPLAY_TILE_HEIGHT 8
54#define WS_DISPLAY_TILE_SIZE 16
58#define WS_DISPLAY_TILE_SIZE_4BPP 32
60#ifndef WS_DISPLAY_VTOTAL
64#define WS_DISPLAY_VTOTAL 159
92#define WS_SCREEN_ATTR_TILE(x) (x)
93#define WS_SCREEN_ATTR_TILE_MASK (0x1FF)
97#define WS_SCREEN_ATTR_PALETTE(x) ((x) << 9)
98#define WS_SCREEN_ATTR_PALETTE_MASK (0xF << 9)
102#define WS_SCREEN_ATTR_BANK(x) ((x) << 13)
103#define WS_SCREEN_ATTR_BANK_MASK (0x2000)
107#define WS_SCREEN_ATTR_TILE_EX(x) (((x) & 0x1FF) | (((x) >> 13) << 13))
108#define WS_SCREEN_ATTR_TILE_EX_MASK (0x21FF)
113#define WS_SCREEN_ATTR_FLIP_H 0x4000
117#define WS_SCREEN_ATTR_FLIP_V 0x8000
121#define WS_SCREEN_ATTR_FLIP 0xC000
122#define WS_SCREEN_ATTR_FLIP_MASK 0xC000
124#define WS_SCREEN_WIDTH_TILES 32
125#define WS_SCREEN_HEIGHT_TILES 32
126#define WS_SCREEN_WIDTH_PIXELS (WS_SCREEN_WIDTH_TILES * WS_DISPLAY_TILE_WIDTH)
127#define WS_SCREEN_HEIGHT_PIXELS (WS_SCREEN_HEIGHT_TILES * WS_DISPLAY_TILE_HEIGHT)
140#define WS_SPRITE_ATTR_PALETTE(x) ((x) << 9)
141#define WS_SPRITE_ATTR_PALETTE_MASK (0x7 << 9)
145#define WS_SPRITE_ATTR_OUTSIDE 0x1000
149#define WS_SPRITE_ATTR_PRIORITY 0x2000
153#define WS_SPRITE_ATTR_FLIP_H 0x4000
157#define WS_SPRITE_ATTR_FLIP_V 0x8000
161#define WS_SPRITE_ATTR_FLIP 0xC000
162#define WS_SPRITE_ATTR_FLIP_MASK 0xC000
164#define WS_SPRITE_MAX_COUNT 128
173#define WS_RGB(r, g, b) (((r) << 8) | ((g) << 4) | (b))
178#define WS_DISPLAY_MONO_PALETTE(c0, c1, c2, c3) ((c0) | ((c1) << 4) | ((c2) << 8) | ((c3) << 12))
187#define WS_TILE_MEM(i) ((ws_display_tile_t ws_iram *) (0x2000 + ((i) << 4)))
194#define WS_TILE_4BPP_MEM(i) ((ws_display_tile_4bpp_t ws_iram *) (0x4000 + ((i) << 5)))
202#define WS_TILE_BANKED_MEM(b, i) ((ws_display_tile_t ws_iram *) (0x2000 + (!!(b) << 13) + ((i) << 4)))
210#define WS_TILE_4BPP_BANKED_MEM(b, i) ((ws_display_tile_4bpp_t ws_iram *) (0x4000 + (!!(b) << 14) + ((i) << 5)))
217#define WS_DISPLAY_COLOR_MEM(i) ((uint16_t ws_iram *) (0xFE00 + ((i) << 5)))
224#define WS_SCREEN_COLOR_MEM WS_DISPLAY_COLOR_MEM
231#define WS_SPRITE_COLOR_MEM(i) ((uint16_t ws_iram *) (0xFF00 + ((i) << 5)))
233#define WS_DISPLAY_SHADE_LUT(c0, c1, c2, c3, c4, c5, c6, c7) \
234 (((uint32_t)(c0)) | (((uint32_t)(c1)) << 4) | (((uint32_t)(c2)) << 8) | (((uint32_t)(c3)) << 12) | \
235 (((uint32_t)(c4)) << 16) | (((uint32_t)(c5)) << 20) | (((uint32_t)(c6)) << 24) | (((uint32_t)(c7)) << 28))
236#define WS_DISPLAY_SHADE_LUT_DEFAULT WS_DISPLAY_SHADE_LUT(0, 2, 4, 6, 9, 11, 13, 15)
271#define ws_sprite_load_palette_mono(data, first, count) ws_display_load_palette_mono((data), (first) + 8, (count))
272#define ws_sprite_load_palette_color_2bpp(data, first, count) ws_display_load_palette_color_2bpp((data), (first) + 8, (count))
273#define ws_sprite_load_palette_color_4bpp(data, first, count) ws_display_load_palette_color_4bpp((data), (first) + 8, (count))
322#define ws_display_set_screen1_address(address) ws_display_set_screen_address(0, (address))
329#define ws_display_set_screen2_address(address) ws_display_set_screen_address(1, (address))
409#define ws_display_scroll_screen1_to(x, y) ws_display_scroll_screen_to(0, (x), (y))
417#define ws_display_scroll_screen2_to(x, y) ws_display_scroll_screen_to(1, (x), (y))
447 "in $0x10, %%ax\nadd %0, %%al\nadd %1, %%ah\nout %%ax, $0x10"
448 : :
"g"(x),
"g"(y) :
"a",
"cc"
460 "in $0x12, %%ax\nadd %0, %%al\nadd %1, %%ah\nout %%ax, $0x12"
461 : :
"g"(x),
"g"(y) :
"a",
"cc"
532__attribute__((no_assume_ds_data, no_assume_ss_data, save_all))
538#define ws_display_set_shade_lut_default() ws_display_set_shade_lut(WS_DISPLAY_SHADE_LUT_DEFAULT)
567 void __libws_screen_put_tiles(
void ws_iram *dest,
const void __far *src, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t pitch);
568 __libws_screen_put_tiles(dest, src, x, y, width, height, width);
585static inline void ws_screen_put_tiles_ex(
void ws_iram *dest,
const void __far *src, uint16_t sx, uint16_t sy, uint16_t pitch, uint16_t dx, uint16_t dy, uint16_t width, uint16_t height) {
586 void __libws_screen_put_tiles(
void ws_iram *dest,
const void __far *src, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t pitch);
587 __libws_screen_put_tiles(dest, ((
const uint16_t __far*) src) + (sy * pitch) + sx, dx, dy, width, height, pitch);
636 ((uint16_t
ws_iram*) dest)[((y & 0x1F) << 5) | (x & 0x1F)] = src;
647 return ((uint16_t
ws_iram*) src)[((y & 0x1F) << 5) | (x & 0x1F)];
static void ws_display_scroll_screen1_by(uint8_t x, uint8_t y)
Scroll screen 1 by a specified number of pixels.
static void ws_display_load_palette_mono(const void __far *data, int first, int count)
Load monochrome palette data (2 bytes per palette).
static void ws_display_set_screen2_window(uint8_t x, uint8_t y, uint8_t width, uint8_t height)
Set the position and size of the screen 2 window.
static void ws_screen_put_tiles_ex(void ws_iram *dest, const void __far *src, uint16_t sx, uint16_t sy, uint16_t pitch, uint16_t dx, uint16_t dy, uint16_t width, uint16_t height)
Place a map of tiles on the screen. This varianta llows specifying the source X position,...
static void ws_display_toggle_icons(uint8_t mask)
Toggle specified LCD icons.
static void ws_display_set_sprite_address(const void __wf_iram *address)
Set the base addresses of the sprite table.
static void ws_display_scroll_screen2_by(uint8_t x, uint8_t y)
Scroll screen 2 by a specified number of pixels.
void ws_display_scroll_screen_by(uint8_t screen, int16_t x, int16_t y)
Scroll the specified screen by a specified number of pixels.
static void ws_screen_put_tile(void ws_iram *dest, uint16_t src, uint16_t x, uint16_t y)
Put a tile on the screen.
static void ws_display_set_control(uint8_t value)
Set which layers and windows are visible on the display.
static void ws_display_set_icons(uint8_t mask)
Set the list of displayed LCD icons, clearing any unspecified icons.
void ws_display_load_palette_color_2bpp(const void __far *data, int first, int count)
Load 2BPP color palette data (4 words per palette).
static void ws_display_set_screen_address(uint8_t screen, const void __wf_iram *address)
Set the base addresses of the specified screen.
void ws_screen_fill_tiles(void ws_iram *dest, uint16_t src, uint16_t x, uint16_t y, uint16_t width, uint16_t height)
Fill an area on the screen with a given tile.
static void ws_display_scroll_screen_to(uint8_t screen, uint8_t x, uint8_t y)
Scroll the specified screen to a specified location.
static void ws_display_set_screen2_window_corners(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom)
Set the corners of the screen 2 window.
static void ws_display_hide_icons(uint8_t mask)
Hide specified LCD icons.
static void ws_display_load_palette_color_4bpp(const void __far *data, int first, int count)
Load 4BPP color palette data (16 words per palette).
static uint16_t ws_screen_get_tile(void ws_iram *src, uint16_t x, uint16_t y)
Get a tile on the screen.
void ws_screen_get_tiles(void __far *dest, const void ws_iram *src, uint16_t x, uint16_t y, uint16_t width, uint16_t height)
Copy a map of tiles from the screen.
static void ws_display_show_icons(uint8_t mask)
Show specified LCD icons.
static void ws_lcd_control_enable(void)
Enable the LCD panel.
static void ws_lcd_control_disable(void)
Disable the LCD panel.
static void ws_screen_put_tiles(void ws_iram *dest, const void __far *src, uint16_t x, uint16_t y, uint16_t width, uint16_t height)
Place a map of tiles on the screen.
static uint8_t ws_display_get_control(void)
Query which layers and windows are visible on the display.
static void ws_display_set_sprite_window(uint8_t x, uint8_t y, uint8_t width, uint8_t height)
Set the position and size of the sprite window.
void ws_screen_modify_tiles(void ws_iram *dest, uint16_t mask, uint16_t value, uint16_t x, uint16_t y, uint16_t width, uint16_t height)
Modify an area on the screen with given data.
static void ws_display_set_screen_addresses(const void __wf_iram *scr1_addr, const void __wf_iram *scr2_addr)
Set the base addresses of screens 1 and 2.
void ws_display_set_shade_lut(uint32_t lut)
Configure the shade LUT.
static uint8_t ws_display_get_current_line(void)
Get the line currently being drawn to the line buffer.
#define WS_DISPLAY_TILE_HEIGHT
static void ws_display_set_sprite_window_corners(uint8_t left, uint8_t top, uint8_t right, uint8_t bottom)
Set the corners of the sprite window.
#define WS_DISPLAY_COLOR_MEM(i)
Pointer to color palette.
#define WS_SCR2_WIN_X2_PORT
#define WS_SCR_PAL_PORT(i)
#define WS_DISPLAY_CTRL_PORT
#define WS_SPR_BASE_ADDR(n)
#define WS_SPR_WIN_X1_PORT
#define WS_DISPLAY_LINE_PORT
#define WS_SCR1_SCRL_X_PORT
#define WS_SCR_BASE_ADDR1(n)
#define WS_SCR_BASE_ADDR2(n)
#define WS_LCD_CTRL_DISPLAY_ENABLE
#define WS_SPR_WIN_X2_PORT
#define WS_SCR2_WIN_X1_PORT
void ws_portcpy(uint16_t port, const void __far *src, uint16_t count)
Copy memory data to I/O ports, in order.
A structure representing a 4 bit per pixel tile.
uint8_t plane[WS_DISPLAY_TILE_HEIGHT][4]
Per-byte access: 8 rows of 4 planes.
uint32_t row[WS_DISPLAY_TILE_HEIGHT]
Per-row access: 32 bits per row.
A structure representing a 2 bit per pixel tile.
uint8_t plane[WS_DISPLAY_TILE_HEIGHT][2]
Per-byte access: 8 rows of 2 planes.
uint16_t row[WS_DISPLAY_TILE_HEIGHT]
Per-row access: 16 bits per row.