libws libws
WSwan hardware library for the Wonderful toolchain
Loading...
Searching...
No Matches
system.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
23#ifndef LIBWS_SYSTEM_H_
24#define LIBWS_SYSTEM_H_
25
29
34
38#define WS_INT_UART_TX 0
42#define WS_INT_KEY_SCAN 1
46#define WS_INT_CARTRIDGE 2
50#define WS_INT_UART_RX 3
54#define WS_INT_LINE_MATCH 4
58#define WS_INT_VBL_TIMER 5
62#define WS_INT_VBLANK 6
66#define WS_INT_HBL_TIMER 7
67
68#ifndef __ASSEMBLER__
69
70#include <stdbool.h>
71#include <stdint.h>
72#include <wonderful.h>
73#include "util.h"
74#include "ports.h"
75
84static inline bool ws_system_is_color_model(void) {
86}
87
94static inline bool ws_system_is_color_active(void) {
95 return ws_system_is_color_model() && (inportb(WS_SYSTEM_CTRL_COLOR_PORT) & 0x80);
96}
97
101typedef enum {
106
111
116
122
129
167
174 return inportb(WS_SYSTEM_CTRL_COLOR_PORT) & 0xE0;
175}
176
187
197void ws_int_set_handler(uint8_t idx, ia16_int_handler_t handler);
198
229
235static inline void ws_int_set_enabled(uint8_t mask) {
236 outportb(WS_INT_ENABLE_PORT, mask);
237}
238
239static inline uint8_t ws_int_push_set_enabled(uint8_t mask) {
240 uint8_t prev_mask = inportb(WS_INT_ENABLE_PORT);
241 outportb(WS_INT_ENABLE_PORT, mask);
242 return prev_mask;
243}
244#define ws_int_pop_enabled ws_int_enable_set
245
251void ws_int_enable(uint8_t mask);
252
258void ws_int_disable(uint8_t mask);
259
263static inline void ws_int_disable_all(void) {
264 ws_int_disable(0xFF);
265}
266
272static inline void ws_int_ack(uint8_t mask) {
273 outportb(WS_INT_ACK_PORT, mask);
274}
275
276#endif
277
279
280#endif /* LIBWS_SYSTEM_H_ */
#define WS_INT_ACK_PORT
Definition ports.h:664
#define WS_INT_ENABLE_PORT
Definition ports.h:596
#define WS_SYSTEM_CTRL_COLOR_PORT
Definition ports.h:740
#define WS_SYSTEM_CTRL_PORT
Definition ports.h:782
#define WS_SYSTEM_CTRL_MODEL_COLOR
Definition ports.h:798
static bool ws_system_is_color_active(void)
Check if this device is currently in Color mode.
Definition system.h:94
void ws_int_enable(uint8_t mask)
Enable selected hardware interrupts.
static void ws_int_ack(uint8_t mask)
Acknowledge hardware interrupt.
Definition system.h:272
ws_system_mode_t
WonderSwan system mode.
Definition system.h:133
void ws_int_set_default_handler_line(void)
Register a default, acknowledge-only interrupt handler.
ws_system_model_t ws_system_get_model(void)
Get the device's model.
void ws_int_set_default_handler_vblank(void)
Register a default, acknowledge-only interrupt handler.
void ws_int_set_default_handler_key(void)
Register a default, acknowledge-only interrupt handler.
void ws_int_disable(uint8_t mask)
Disable selected hardware interrupts.
bool ws_system_set_mode(ws_system_mode_t mode)
Set the new system mode.
static void ws_int_disable_all(void)
Disable all hardware interrupts.
Definition system.h:263
void ws_int_set_handler(uint8_t idx, ia16_int_handler_t handler)
Register a hardware interrupt handler.
void ws_int_set_default_handler_serial_rx(void)
Register a default interrupt handler for serial receiving. This handler will automatically disable an...
static ws_system_mode_t ws_system_get_mode(void)
Get the current system mode.
Definition system.h:173
static bool ws_system_is_color_model(void)
Check if this device is capable of supporting Color mode (= is a WonderSwan Color or above).
Definition system.h:84
void ws_int_set_default_handler_vblank_timer(void)
Register a default, acknowledge-only interrupt handler.
ws_system_model_t
WonderSwan device model.
Definition system.h:101
void ws_int_set_default_handler_serial_tx(void)
Register a default interrupt handler for serial transmission. This handler will automatically disable...
static uint8_t ws_int_push_set_enabled(uint8_t mask)
Definition system.h:239
static void ws_int_set_enabled(uint8_t mask)
Set selected hardware interrupts.
Definition system.h:235
void ws_int_set_default_handler_hblank_timer(void)
Register a default, acknowledge-only interrupt handler.
@ WS_MODE_MONO
Mono mode.
Definition system.h:140
@ WS_MODE_COLOR_4BPP
Color/4bpp mode.
Definition system.h:156
@ WS_MODE_COLOR
Color mode.
Definition system.h:148
@ WS_MODE_COLOR_4BPP_PACKED
Color/4bpp/Packed mode.
Definition system.h:165
@ WS_MODEL_CRYSTAL
SwanCrystal.
Definition system.h:120
@ WS_MODEL_PCV2
Pocket Challenge V2.
Definition system.h:110
@ WS_MODEL_COLOR
WonderSwan Color.
Definition system.h:115
@ WS_MODEL_MONO
WonderSwan (mono).
Definition system.h:105