libws libws
WSwan hardware library for the Wonderful toolchain
Loading...
Searching...
No Matches
display.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022, 2023 Adrian "asie" Siekierka
3 *
4 * This software is provided 'as-is', without any express or implied
5 * warranty. In no event will the authors be held liable for any damages
6 * arising from the use of this software.
7 *
8 * Permission is granted to anyone to use this software for any purpose,
9 * including commercial applications, and to alter it and redistribute it
10 * freely, subject to the following restrictions:
11 *
12 * 1. The origin of this software must not be misrepresented; you must not
13 * claim that you wrote the original software. If you use this software
14 * in a product, an acknowledgment in the product documentation would be
15 * appreciated but is not required.
16 *
17 * 2. Altered source versions must be plainly marked as such, and must not be
18 * misrepresented as being the original software.
19 *
20 * 3. This notice may not be removed or altered from any source distribution.
21 */
22
23#ifndef __WF_LIBWS_DISPLAY_H__
24#define __WF_LIBWS_DISPLAY_H__
25
26#include <stdbool.h>
27#include <stdint.h>
28#include <wonderful.h>
29
34#define DISPLAY_WIDTH 28
35#define DISPLAY_HEIGHT 18
36#define DISPLAY_WIDTH_PX (DISPLAY_WIDTH * TILE_WIDTH)
37#define DISPLAY_HEIGHT_PX (DISPLAY_HEIGHT * TILE_HEIGHT)
38
39#define TILE_WIDTH 8
40#define TILE_HEIGHT 8
41#define TILE_LENGTH 16
42#define TILE_4BPP_LENGTH 32
43
44typedef struct {
45 uint8_t row[TILE_HEIGHT][2];
46} ws_tile_t;
47
48typedef struct {
49 uint8_t row[TILE_HEIGHT][4];
51
52#define SCR_ATTR_TILE(x) (x)
53#define SCR_ATTR_TILE_MASK (0x1FF)
54#define SCR_ATTR_PALETTE(x) ((x) << 9)
55#define SCR_ATTR_PALETTE_MASK (0xF << 9)
56#define SCR_ATTR_BANK(x) ((x) << 13)
57#define SCR_ATTR_BANK_MASK (0x2000)
58#define SCR_ATTR_TILE_EX(x) (((x) & 0x1FF) | (((x) >> 13) << 13))
59#define SCR_ATTR_TILE_EX_MASK (0x21FF)
60#define SCR_ATTR_TILE_BANK_MASK (SCR_ATTR_TILE_MASK | SCR_ATTR_BANK_MASK)
61
62#define SCR_ATTR_FLIP_H 0x4000
63#define SCR_ATTR_FLIP_V 0x8000
64#define SCR_ATTR_FLIP 0xC000
65#define SCR_ATTR_FLIP_MASK 0xC000
66
67typedef struct {
68 union {
69 struct {
70 uint16_t tile : 9;
71 uint8_t palette : 4;
72 uint8_t bank : 1;
73 bool flip_h : 1;
74 bool flip_v : 1;
75 };
76 uint16_t attr;
77 };
79
80#define SCR_WIDTH 32
81#define SCR_HEIGHT 32
82#define SCR_WIDTH_PX (SCR_WIDTH * TILE_WIDTH)
83#define SCR_HEIGHT_PX (SCR_HEIGHT * TILE_HEIGHT)
84
85typedef struct {
86 union {
87 struct {
88 uint16_t tile : 9;
89 uint8_t palette : 3;
90 bool inside : 1;
91 bool priority : 1;
92 bool flip_h : 1;
93 bool flip_v : 1;
94 };
95 uint16_t attr;
96 };
97 uint8_t y;
98 uint8_t x;
100
101#define SPR_ATTR_PALETTE(x) ((x) << 9)
102#define SPR_ATTR_PALETTE_MASK (0x7 << 9)
103#define SPR_ATTR_INSIDE 0x1000
104#define SPR_ATTR_PRIORITY 0x2000
105#define SPR_ATTR_FLIP_H 0x4000
106#define SPR_ATTR_FLIP_V 0x8000
107
108#define SPR_MAX_COUNT 128
109
110// legacy defines
111
112#define SCR_ENTRY_TILE(x) (x)
113#define SCR_ENTRY_TILE_MASK (0x1FF)
114#define SCR_ENTRY_PALETTE(x) ((x) << 9)
115#define SCR_ENTRY_PALETTE_MASK (0xF << 9)
116#define SCR_ENTRY_BANK(x) ((x) << 13)
117#define SCR_ENTRY_BANK_MASK (0x2000)
118#define SCR_ENTRY_TILE_EX(x) (((x) & 0x1FF) | (((x) >> 13) << 13))
119#define SCR_ENTRY_TILE_EX_MASK (0x21FF)
120#define SCR_ENTRY_TILE_BANK_MASK (SCR_ENTRY_TILE_MASK | SCR_ENTRY_BANK_MASK)
121
122#define SCR_ENTRY_FLIP_H 0x4000
123#define SCR_ENTRY_FLIP_V 0x8000
124#define SCR_ENTRY_FLIP 0xC000
125#define SCR_ENTRY_FLIP_MASK 0xC000
126
127#define ws_scr_entry_t ws_screen_cell_t
128
129#define SPR_ENTRY_PALETTE(x) ((x) << 9)
130#define SPR_ENTRY_PALETTE_MASK (0x7 << 9)
131#define SPR_ENTRY_INSIDE 0x1000
132#define SPR_ENTRY_PRIORITY 0x2000
133#define SPR_ENTRY_FLIP_H 0x4000
134#define SPR_ENTRY_FLIP_V 0x8000
135
146#define MEM_TILE(i) ((uint8_t __wf_iram*) (0x2000 + ((i) << 4)))
147
153#define MEM_TILE_4BPP(i) MEM_TILE_4BPP_BANK0(i)
154
160#define MEM_TILE_4BPP_BANK0(i) ((uint8_t __wf_iram*) (0x4000 + ((i) << 5)))
161
167#define MEM_TILE_4BPP_BANK1(i) ((uint8_t __wf_iram*) (0x8000 + ((i) << 5)))
168
174#define MEM_COLOR_PALETTE(i) ((uint16_t __wf_iram*) (0xFE00 + ((i) << 5)))
175
181#define MEM_SCR_PALETTE MEM_COLOR_PALETTE
182
188#define MEM_SPR_PALETTE(i) ((uint16_t __wf_iram*) (0xFF00 + ((i) << 5)))
189
192#define SHADE_LUT(c0, c1, c2, c3, c4, c5, c6, c7) \
193 (((uint32_t)(c0)) | (((uint32_t)(c1)) << 4) | (((uint32_t)(c2)) << 8) | (((uint32_t)(c3)) << 12) | \
194 (((uint32_t)(c4)) << 16) | (((uint32_t)(c5)) << 20) | (((uint32_t)(c6)) << 24) | (((uint32_t)(c7)) << 28))
195#define SHADE_LUT_DEFAULT SHADE_LUT(0, 2, 4, 6, 9, 11, 13, 15)
196
209#define RGB(r, g, b) (((r) << 8) | ((g) << 4) | (b))
210
218__attribute__((no_assume_ds_data, no_assume_ss_data, save_all))
219void ws_display_set_shade_lut(uint32_t lut);
220
231static inline void ws_screen_put_tiles(void __wf_iram* dest, const void __far* src, uint16_t x, uint16_t y, uint16_t width, uint16_t height) {
232 void __libws_screen_put_tiles(void __wf_iram* dest, const void __far* src, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t pitch);
233 __libws_screen_put_tiles(dest, src, x, y, width, height, width);
234}
235
250static inline void ws_screen_put_tiles_ex(void __wf_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) {
251 void __libws_screen_put_tiles(void __wf_iram* dest, const void __far* src, uint16_t x, uint16_t y, uint16_t width, uint16_t height, uint16_t pitch);
252 __libws_screen_put_tiles(dest, ((const uint16_t __far*) src) + (sy * pitch) + sx, dx, dy, width, height, pitch);
253}
254
265void ws_screen_get_tiles(void __far* dest, const void __wf_iram* src, uint16_t x, uint16_t y, uint16_t width, uint16_t height);
266
277void ws_screen_fill_tiles(void __wf_iram* dest, uint16_t src, uint16_t x, uint16_t y, uint16_t width, uint16_t height);
278
290void ws_screen_modify_tiles(void __wf_iram* dest, uint16_t mask, uint16_t value, uint16_t x, uint16_t y, uint16_t width, uint16_t height);
291
300static inline void ws_screen_put_tile(void __wf_iram* dest, uint16_t src, uint16_t x, uint16_t y) {
301 ((uint16_t __wf_iram*) dest)[((y & 0x1F) << 5) | (x & 0x1F)] = src;
302}
303
311static inline uint16_t ws_screen_get_tile(void __wf_iram* src, uint16_t x, uint16_t y) {
312 return ((uint16_t __wf_iram*) src)[((y & 0x1F) << 5) | (x & 0x1F)];
313}
314
317#endif /* __WF_LIBWS_DISPLAY_H__ */
#define TILE_HEIGHT
Definition display.h:40
void ws_screen_fill_tiles(void __wf_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.
__attribute__((no_assume_ds_data, no_assume_ss_data, save_all)) void ws_display_set_shade_lut(uint32_t lut)
Configure the shade LUT.
static void ws_screen_put_tile(void __wf_iram *dest, uint16_t src, uint16_t x, uint16_t y)
Put a tile on the screen.
Definition display.h:300
void ws_screen_get_tiles(void __far *dest, const void __wf_iram *src, uint16_t x, uint16_t y, uint16_t width, uint16_t height)
Copy a map of tiles from the screen.
void ws_screen_modify_tiles(void __wf_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 uint16_t ws_screen_get_tile(void __wf_iram *src, uint16_t x, uint16_t y)
Get a tile on the screen.
Definition display.h:311
static void ws_screen_put_tiles(void __wf_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.
Definition display.h:231
static void ws_screen_put_tiles_ex(void __wf_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,...
Definition display.h:250
uint16_t attr
Definition display.h:76
uint8_t palette
Definition display.h:71
uint8_t bank
Definition display.h:72
uint16_t tile
Definition display.h:70
uint8_t x
Definition display.h:98
uint8_t y
Definition display.h:97
bool inside
Definition display.h:90
uint16_t attr
Definition display.h:95
uint8_t palette
Definition display.h:89
bool priority
Definition display.h:91
bool flip_h
Definition display.h:92
bool flip_v
Definition display.h:93
uint16_t tile
Definition display.h:88