libws libws
WSwan hardware library for the Wonderful toolchain
Loading...
Searching...
No Matches
hardware.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2022 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
27#ifndef __WF_LIBWS_HARDWARE_H__
28#define __WF_LIBWS_HARDWARE_H__
29
30#include <wonderful.h>
31
37#define CPUINT_DIV 0x01
38#define CPUINT_STEP 0x02
39#define CPUINT_NMI 0x04
40#define CPUINT_BREAK 0x08
41#define CPUINT_INTO 0x10
42#define CPUINT_BOUNDS 0x20
43
44#define CPUINT_IDX_DIV 0
45#define CPUINT_IDX_STEP 1
46#define CPUINT_IDX_NMI 2
47#define CPUINT_IDX_BREAK 3
48#define CPUINT_IDX_INTO 4
49#define CPUINT_IDX_BOUNDS 5
50
51#define HWINT_SERIAL_TX 0x01
52#define HWINT_KEY 0x02
53#define HWINT_CARTRIDGE 0x04
54#define HWINT_SERIAL_RX 0x08
55#define HWINT_LINE 0x10
56#define HWINT_VBLANK_TIMER 0x20
57#define HWINT_VBLANK 0x40
58#define HWINT_HBLANK_TIMER 0x80
59
60#define HWINT_IDX_SERIAL_TX 0
61#define HWINT_IDX_KEY 1
62#define HWINT_IDX_CARTRIDGE 2
63#define HWINT_IDX_SERIAL_RX 3
64#define HWINT_IDX_LINE 4
65#define HWINT_IDX_VBLANK_TIMER 5
66#define HWINT_IDX_VBLANK 6
67#define HWINT_IDX_HBLANK_TIMER 7
68
76#define IO_DISPLAY_CTRL 0x00
77#define DISPLAY_SCR1_ENABLE 0x0001
78#define DISPLAY_SCR2_ENABLE 0x0002
79#define DISPLAY_SPR_ENABLE 0x0004
80#define DISPLAY_SPR_WIN_ENABLE 0x0008
81#define DISPLAY_SCR2_WIN_INSIDE 0x0020
82#define DISPLAY_SCR2_WIN_OUTSIDE 0x0030
83
84#define IO_DISPLAY_BACK 0x01
85#define DISPLAY_BACK_COLOR(p, i) (((p) << 4) | (i))
86
87#define IO_LCD_LINE 0x02
88#define IO_LCD_INTERRUPT 0x03
89
90#define IO_SPR_BASE 0x04
91#define SPR_BASE(x) ((__WF_IRAM_TO_OFFSET(x)) >> 9)
92
93#define IO_SPR_FIRST 0x05
94#define IO_SPR_COUNT 0x06
95
96#define IO_SCR_BASE 0x07
97#define SCR1_BASE(x) (((__WF_IRAM_TO_OFFSET(x)) >> 11))
98#define SCR2_BASE(x) (((__WF_IRAM_TO_OFFSET(x)) >> 11) << 4)
99
100#define IO_SCR2_WIN_X1 0x08
101#define IO_SCR2_WIN_Y1 0x09
102#define IO_SCR2_WIN_X2 0x0A
103#define IO_SCR2_WIN_Y2 0x0B
104
105#define IO_SPR_WIN_X1 0x0C
106#define IO_SPR_WIN_Y1 0x0D
107#define IO_SPR_WIN_X2 0x0E
108#define IO_SPR_WIN_Y2 0x0F
109
110#define IO_SCR1_SCRL_X 0x10
111#define IO_SCR1_SCRL_Y 0x11
112#define IO_SCR2_SCRL_X 0x12
113#define IO_SCR2_SCRL_Y 0x13
114
115#define IO_LCD_CTRL 0x14
116#define LCD_CONTRAST 0x02 /* WSC only (not SC!) */
117#define LCD_CONTRAST_LOW 0x00 /* WSC only (not SC!) */
118#define LCD_CONTRAST_HIGH 0x02 /* WSC only (not SC!) */
119#define LCD_SLEEP_MASK 0x01
120
121#define IO_LCD_SEG 0x15
122#define LCD_SEG_AUX3 0x20
123#define LCD_SEG_AUX2 0x10
124#define LCD_SEG_AUX1 0x08
125#define LCD_SEG_ORIENT_H 0x04
126#define LCD_SEG_ORIENT_V 0x02
127#define LCD_SEG_SLEEP 0x01
128
129#define IO_LCD_VTOTAL 0x16
130#define IO_LCD_VSYNC 0x17 /* WSC only */
131
132#define IO_LCD_STATUS 0x1A
133
134#define IO_LCD_SHADE_01 0x1C
135#define IO_LCD_SHADE_23 0x1D
136#define IO_LCD_SHADE_45 0x1E
137#define IO_LCD_SHADE_67 0x1F
138
139#define LCD_SHADES(c0, c1) ((c0) | ((c1) << 4))
140
141#define IO_SCR_PAL(x) (0x20 + ((x) << 1))
142#define IO_SCR_PAL_0 0x20
143#define IO_SCR_PAL_1 0x22
144#define IO_SCR_PAL_2 0x24
145#define IO_SCR_PAL_3 0x26
146#define IO_SCR_PAL_4 0x28
147#define IO_SCR_PAL_5 0x2A
148#define IO_SCR_PAL_6 0x2C
149#define IO_SCR_PAL_7 0x2E
150#define IO_SCR_PAL_8 0x30
151#define IO_SCR_PAL_9 0x32
152#define IO_SCR_PAL_10 0x34
153#define IO_SCR_PAL_11 0x36
154#define IO_SCR_PAL_12 0x38
155#define IO_SCR_PAL_13 0x3A
156#define IO_SCR_PAL_14 0x3C
157#define IO_SCR_PAL_15 0x3E
158#define IO_SPR_PAL(x) (0x30 + ((x) << 1))
159#define IO_SPR_PAL_0 0x30
160#define IO_SPR_PAL_1 0x32
161#define IO_SPR_PAL_2 0x34
162#define IO_SPR_PAL_3 0x36
163#define IO_SPR_PAL_4 0x38
164#define IO_SPR_PAL_5 0x3A
165#define IO_SPR_PAL_6 0x3C
166#define IO_SPR_PAL_7 0x3E
167
168#define MONO_PAL_COLORS(c0, c1, c2, c3) ((c0) | ((c1) << 4) | ((c2) << 8) | ((c3) << 12))
169#define MONO_PAL_COLOR0(x) ((x))
170#define MONO_PAL_COLOR1(x) ((x) << 4)
171#define MONO_PAL_COLOR2(x) ((x) << 8)
172#define MONO_PAL_COLOR3(x) ((x) << 12)
173
174#define IO_DMA_SOURCE_L 0x40
175#define IO_DMA_SOURCE_H 0x42
176#define IO_DMA_DEST 0x44
177#define IO_DMA_LENGTH 0x46
178#define IO_DMA_CTRL 0x48
179
180#define IO_SDMA_SOURCE_L 0x4A
181#define IO_SDMA_SOURCE_H 0x4C
182#define IO_SDMA_LENGTH_L 0x4E
183#define IO_SDMA_LENGTH_H 0x50
184#define IO_SDMA_CTRL 0x52
185
186#define DMA_TRANSFER_ENABLE 0x80
187#define DMA_ADDRESS_INC 0x00
188#define DMA_ADDRESS_DEC 0x40
189
190#define SDMA_RATE_4000 0x00
191#define SDMA_RATE_6000 0x01
192#define SDMA_RATE_12000 0x02
193#define SDMA_RATE_24000 0x03
194#define SDMA_RATE_MASK 0x03
195#define SDMA_HOLD 0x04
196#define SDMA_REPEAT 0x08
197#define SDMA_ONESHOT 0x00
198#define SDMA_TARGET_HYPERV 0x10
199#define SDMA_TARGET_CH2 0x00
200
201#define IO_SYSTEM_CTRL2 0x60
202
203#define SYSTEM_CTRL2_SRAM_WAIT 0x02
204#define SYSTEM_CTRL2_CART_IO_WAIT 0x08
205#define SYSTEM_CTRL2_PACKED 0x20
206#define SYSTEM_CTRL2_4BPP 0x40
207#define SYSTEM_CTRL2_COLOR 0x80
208
209#define IO_SYSTEM_CTRL3 0x62
210
211#define SYSTEM_CTRL3_POWEROFF 0x01
212#define SYSTEM_CTRL3_SWANCRYSTAL 0x80
213
214#define IO_HYPERV_OUT_L 0x64
215#define IO_HYPERV_OUT_R 0x66
216#define IO_HYPERV_IN_L 0x68
217#define IO_HYPERV_IN_R 0x69
218#define IO_HYPERV_CTRL 0x6A
219
220#define HYPERV_ENABLE 0x0080
221#define HYPERV_RESET 0x1000
222
223#define HYPERV_VOLUME_100 (0)
224#define HYPERV_VOLUME_50 (1)
225#define HYPERV_VOLUME_25 (2)
226#define HYPERV_VOLUME_12_5 (3)
227#define HYPERV_VOLUME_MASK (3)
228#define HYPERV_SHIFT(n) (n)
229#define HYPERV_MODE_UNSIGNED (0 << 2)
230#define HYPERV_MODE_UNSIGNED_NEGATE (1 << 2)
231#define HYPERV_MODE_SIGNED (2 << 2)
232#define HYPERV_MODE_SIGNED_FULL (3 << 2)
233#define HYPERV_MODE_MASK (3 << 2)
234#define HYPERV_RATE_24000 (0 << 4)
235#define HYPERV_RATE_12000 (1 << 4)
236#define HYPERV_RATE_8000 (2 << 4)
237#define HYPERV_RATE_6000 (3 << 4)
238#define HYPERV_RATE_4800 (4 << 4)
239#define HYPERV_RATE_4000 (5 << 4)
240#define HYPERV_RATE_3000 (6 << 4)
241#define HYPERV_RATE_2000 (7 << 4)
242#define HYPERV_RATE_MASK (7 << 4)
243#define HYPERV_TARGET_STEREO (0 << 13)
244#define HYPERV_TARGET_LEFT (1 << 13)
245#define HYPERV_TARGET_RIGHT (2 << 13)
246#define HYPERV_TARGET_MONO (3 << 13)
247#define HYPERV_TARGET_MASK (3 << 13)
248
249#define SND_FREQ_HZ(hz) (2048 - (96000 / (hz)))
250#define IO_SND_FREQ_CH1 0x80
251#define IO_SND_FREQ_CH2 0x82
252#define IO_SND_FREQ_CH3 0x84
253#define IO_SND_FREQ_CH4 0x86
254#define IO_SND_FREQ(ch) (0x80 + (((ch) - 1) << 1))
255
256#define IO_SND_VOL_CH1 0x88
257#define IO_SND_VOL_CH2 0x89
258#define IO_SND_VOL_CH3 0x8A
259#define IO_SND_VOL_CH4 0x8B
260#define IO_SND_VOL(ch) (0x88 + ((ch) - 1))
261#define SND_VOL_LEFT(l) ((l) << 4)
262#define SND_VOL_RIGHT(r) (r)
263#define SND_VOL(l, r) (((l) << 4) | (r))
264
265#define IO_SND_SWEEP 0x8C
266#define IO_SND_SWEEP_TIME 0x8D
267
268#define IO_SND_NOISE_CTRL 0x8E
269#define SND_NOISE_ENABLE 0x10
270#define SND_NOISE_RESET 0x08
271#define SND_NOISE_LEN_32767 0x00
272#define SND_NOISE_LEN_1953 0x01
273#define SND_NOISE_LEN_254 0x02
274#define SND_NOISE_LEN_217 0x03
275#define SND_NOISE_LEN_73 0x04
276#define SND_NOISE_LEN_63 0x05
277#define SND_NOISE_LEN_42 0x06
278#define SND_NOISE_LEN_28 0x07
279#define SND_NOISE_TAP_14 0x00
280#define SND_NOISE_TAP_10 0x01
281#define SND_NOISE_TAP_13 0x02
282#define SND_NOISE_TAP_4 0x03
283#define SND_NOISE_TAP_8 0x04
284#define SND_NOISE_TAP_6 0x05
285#define SND_NOISE_TAP_9 0x06
286#define SND_NOISE_TAP_11 0x07
287#define SND_NOISE_TAP_MASK 0x07
288
289#define IO_SND_WAVE_BASE 0x8F
290#define SND_WAVE_BASE(x) ((__WF_IRAM_TO_OFFSET(x)) >> 6)
291
292#define IO_SND_CH_CTRL 0x90
293#define SND_CH1_ENABLE 0x01
294#define SND_CH2_ENABLE 0x02
295#define SND_CH3_ENABLE 0x04
296#define SND_CH4_ENABLE 0x08
297#define SND_CH_ENABLE(i) (1 << (i))
298#define SND_CH2_WAVE 0x00
299#define SND_CH2_VOICE 0x20
300#define SND_CH3_NO_SWEEP 0x00
301#define SND_CH3_SWEEP 0x40
302#define SND_CH4_WAVE 0x00
303#define SND_CH4_NOISE 0x80
304
305#define IO_SND_OUT_CTRL 0x91
306#define SND_OUT_HEADPHONES 0x80
307#define SND_OUT_HEADPHONES_ENABLE 0x08
308#define SND_OUT_VOLUME_100 0x00
309#define SND_OUT_VOLUME_50 0x02
310#define SND_OUT_VOLUME_25 0x04
311#define SND_OUT_VOLUME_12_5 0x06
312#define SND_OUT_SHIFT(n) ((n) << 1)
313#define SND_OUT_DIVIDER_1 0x00
314#define SND_OUT_DIVIDER_2 0x02
315#define SND_OUT_DIVIDER_4 0x04
316#define SND_OUT_DIVIDER_8 0x06
317#define SND_OUT_SPEAKER_ENABLE 0x01
318
319#define IO_SND_RANDOM 0x92
320
321#define IO_SND_VOL_CH2_VOICE 0x94
322#define SND_VOL_CH2_LEFT_HALF 0x08
323#define SND_VOL_CH2_LEFT_FULL 0x0C
324#define SND_VOL_CH2_RIGHT_HALF 0x02
325#define SND_VOL_CH2_RIGHT_FULL 0x03
326#define SND_VOL_CH2_HALF 0x0A
327#define SND_VOL_CH2_FULL 0x0F
328
329#define IO_SND_TEST 0x95
330#define SND_TEST_CH_OUT_4 0x80
331#define SND_TEST_CH_OUT_2 0x40
332#define SND_TEST_CH_SUM_55 0x20
333#define SND_TEST_FAST_SWEEP 0x02
334#define SND_TEST_HOLD_CH 0x01
335
336#define IO_SND_CH_OUT_R 0x96
337#define IO_SND_CH_OUT_L 0x98
338#define IO_SND_CH_OUT_LR 0x9A
339
340#define IO_SND_HW_VOL 0x9E
341
342#define IO_SYSTEM_CTRL1 0xA0
343#define SYSTEM_CTRL1_IPL_LOCKED 0x01
344#define SYSTEM_CTRL1_COLOR 0x02
345#define SYSTEM_CTRL1_ROM_16BIT 0x04
346#define SYSTEM_CTRL1_ROM_WAIT 0x08
347#define SYSTEM_CTRL1_SELFTEST_OK 0x80
348
349#define IO_TIMER_CTRL 0xA2
350#define VBLANK_TIMER_REPEAT 0x08
351#define VBLANK_TIMER_ONESHOT 0x00
352#define VBLANK_TIMER_ENABLE 0x04
353#define HBLANK_TIMER_REPEAT 0x02
354#define HBLANK_TIMER_ONESHOT 0x00
355#define HBLANK_TIMER_ENABLE 0x01
356
357#define IO_HBLANK_TIMER 0xA4
358#define IO_VBLANK_TIMER 0xA6
359#define IO_HBLANK_COUNTER 0xA8
360#define IO_VBLANK_COUNTER 0xAA
361
362#define IO_HWINT_VECTOR 0xB0
363#define IO_HWINT_ENABLE 0xB2
364#define IO_HWINT_STATUS 0xB4
365#define IO_HWINT_ACK 0xB6
366
367#define IO_SERIAL_DATA 0xB1
368#define IO_SERIAL_STATUS 0xB3
369#define SERIAL_ENABLE 0x80
370#define SERIAL_BAUD_9600 0x00
371#define SERIAL_BAUD_38400 0x40
372#define SERIAL_OVERRUN_RESET 0x20
373#define SERIAL_TX_READY 0x04
374#define SERIAL_OVERRUN 0x02
375#define SERIAL_RX_READY 0x01
376
377#define IO_KEY_SCAN 0xB5
378#define KEY_SCAN_GROUP_BUTTONS 0x40
379#define KEY_SCAN_GROUP_X 0x20
380#define KEY_SCAN_GROUP_Y 0x10
381#define KEY_SCAN_B 0x08
382#define KEY_SCAN_X4 0x08
383#define KEY_SCAN_Y4 0x08
384#define KEY_SCAN_A 0x04
385#define KEY_SCAN_X3 0x04
386#define KEY_SCAN_Y3 0x04
387#define KEY_SCAN_START 0x02
388#define KEY_SCAN_X2 0x02
389#define KEY_SCAN_Y2 0x02
390#define KEY_SCAN_X1 0x01
391#define KEY_SCAN_Y1 0x01
392
393#define IO_INT_NMI_CTRL 0xB7
394#define NMI_ON_LOW_BATTERY 0x10
395
396#define IO_IEEP_DATA 0xBA
397#define IO_IEEP_CMD 0xBC
398#define IO_IEEP_CTRL 0xBE
399#define IEEP_PROTECT 0x80
400#define EEP_ERASE 0x40
401#define EEP_WRITE 0x20
402#define EEP_READ 0x10
403#define EEP_READY 0x02
404#define EEP_DONE 0x01
405
406#define IO_BANK_RAM 0xC1
407#define IO_BANK_ROM0 0xC2
408#define IO_BANK_ROM1 0xC3
409#define IO_BANK_ROM_LINEAR 0xC0
410
411#define IO_CART_EEP_DATA 0xC4
412#define IO_CART_EEP_CMD 0xC6
413#define IO_CART_EEP_CTRL 0xC8
414
415#define IO_CART_RTC_CTRL 0xCA
416#define CART_RTC_READY 0x80
417#define CART_RTC_ACTIVE 0x10
418#define CART_RTC_READ 0x00
419#define CART_RTC_WRITE 0x01
420#define CART_RTC_CMD_RESET 0x00
421#define CART_RTC_CMD_STATUS 0x02
422#define CART_RTC_CMD_DATETIME 0x04
423#define CART_RTC_CMD_TIME 0x06
424#define CART_RTC_CMD_INTCFG 0x08
425#define CART_RTC_CMD_NOP 0x0A
426
427#define IO_CART_RTC_DATA 0xCB
428
429#define IO_CART_GPO_CTRL 0xCC
430#define IO_CART_GPO_DATA 0xCD
431#define CART_GPO_ENABLE(n) (1 << (n))
432#define CART_GPO_MASK(n) (1 << (n))
433
434#define IO_CART_FLASH 0xCE
435#define CART_FLASH_ENABLE 0x01
436#define CART_FLASH_DISABLE 0x00
437
438#define IO_BANK_2003_RAM 0xD0
439#define IO_BANK_2003_ROM0 0xD2
440#define IO_BANK_2003_ROM1 0xD4
441
442#define IO_CART_KARNAK_TIMER 0xD6
443#define CART_KARNAK_TIMER_ENABLE 0x80
444
445#define IO_CART_KARNAK_ADPCM_INPUT 0xD8
446#define IO_CART_KARNAK_ADPCM_OUTPUT 0xD9
447
450#endif /* __WF_LIBWS_HARDWARE_H__ */