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 __WF_LIBWS_SYSTEM_H__
24#define __WF_LIBWS_SYSTEM_H__
25
26#include <stdbool.h>
27#include <stdint.h>
28#include "util.h"
29#include "hardware.h"
30
48static inline bool ws_system_is_color(void) {
49 return inportb(IO_SYSTEM_CTRL1) & SYSTEM_CTRL1_COLOR;
50}
51
58static inline bool ws_system_color_active(void) {
59 return ws_system_is_color() && (inportb(IO_SYSTEM_CTRL2) & 0x80);
60}
61
65typedef enum {
70
75
80
86
93
97typedef enum {
105
113
121
131
138 return inportb(IO_SYSTEM_CTRL2) & 0xE0;
139}
140
151
152// Legacy defines. TODO: Remove
153#define ws_mode_t ws_system_mode_t
154#define ws_mode_get ws_system_mode_get
155#define ws_mode_set ws_system_mode_set
156
157typedef __attribute__((interrupt)) void __far (*ws_int_handler_t)(void);
158
165void ws_cpuint_set_handler(uint8_t idx, ws_int_handler_t handler);
166
176void ws_hwint_set_handler(uint8_t idx, ws_int_handler_t handler);
177
208
214static inline void ws_hwint_set(uint8_t mask) {
215 outportb(IO_HWINT_ENABLE, mask);
216}
217
218static inline uint8_t ws_hwint_push(uint8_t mask) {
219 uint8_t prev_mask = inportb(IO_HWINT_ENABLE);
220 outportb(IO_HWINT_ENABLE, mask);
221 return prev_mask;
222}
223#define ws_hwint_pop ws_hwint_push
224
230void ws_hwint_enable(uint8_t mask);
231
237void ws_hwint_disable(uint8_t mask);
238
242static inline void ws_hwint_disable_all(void) {
243 ws_hwint_disable(0xFF);
244}
245
251static inline void ws_hwint_ack(uint8_t mask) {
252 outportb(IO_HWINT_ACK, mask);
253}
254
257#endif /* __WF_LIBWS_SYSTEM_H__ */
#define IO_HWINT_ACK
Definition hardware.h:365
#define SYSTEM_CTRL1_COLOR
Definition hardware.h:344
#define IO_SYSTEM_CTRL2
Definition hardware.h:201
#define IO_SYSTEM_CTRL1
Definition hardware.h:342
#define IO_HWINT_ENABLE
Definition hardware.h:363
void ws_hwint_set_default_handler_serial_tx(void)
Register a default interrupt handler for serial transmission. This handler will automatically disable...
void ws_hwint_set_default_handler_vblank_timer(void)
Register a default, acknowledge-only interrupt handler.
void ws_hwint_set_default_handler_serial_rx(void)
Register a default interrupt handler for serial receiving. This handler will automatically disable an...
void ws_hwint_set_default_handler_hblank_timer(void)
Register a default, acknowledge-only interrupt handler.
static void ws_hwint_disable_all(void)
Disable all hardware interrupts.
Definition system.h:242
ws_system_mode_t
WonderSwan system mode.
Definition system.h:97
static bool ws_system_color_active(void)
Check if this device is currently in Color mode.
Definition system.h:58
typedef __attribute__((interrupt)) void __far(*ws_int_handler_t)(void)
ws_system_model_t ws_system_get_model(void)
Get the device's model.
static void ws_hwint_ack(uint8_t mask)
Acknowledge hardware interrupt.
Definition system.h:251
void ws_hwint_set_default_handler_key(void)
Register a default, acknowledge-only interrupt handler.
void ws_hwint_disable(uint8_t mask)
Disable selected hardware interrupts.
void ws_hwint_set_default_handler_vblank(void)
Register a default, acknowledge-only interrupt handler.
static ws_system_mode_t ws_system_mode_get(void)
Get the current system mode.
Definition system.h:137
static uint8_t ws_hwint_push(uint8_t mask)
Definition system.h:218
void ws_hwint_set_handler(uint8_t idx, ws_int_handler_t handler)
Register a hardware interrupt handler.
void ws_cpuint_set_handler(uint8_t idx, ws_int_handler_t handler)
Register a CPU interrupt handler.
void ws_hwint_enable(uint8_t mask)
Enable selected hardware interrupts.
ws_system_model_t
WonderSwan device model.
Definition system.h:65
void ws_hwint_set_default_handler_line(void)
Register a default, acknowledge-only interrupt handler.
bool ws_system_mode_set(ws_system_mode_t mode)
Set the new system mode.
static bool ws_system_is_color(void)
Check if this device is capable of supporting Color mode (= is a WonderSwan Color or above).
Definition system.h:48
static void ws_hwint_set(uint8_t mask)
Set selected hardware interrupts.
Definition system.h:214
@ WS_MODE_MONO
Mono mode.
Definition system.h:104
@ WS_MODE_COLOR_4BPP
Color/4bpp mode.
Definition system.h:120
@ WS_MODE_COLOR
Color mode.
Definition system.h:112
@ WS_MODE_COLOR_4BPP_PACKED
Color/4bpp/Packed mode.
Definition system.h:129
@ WS_MODEL_CRYSTAL
SwanCrystal.
Definition system.h:84
@ WS_MODEL_PCV2
Pocket Challenge V2.
Definition system.h:74
@ WS_MODEL_COLOR
WonderSwan Color.
Definition system.h:79
@ WS_MODEL_MONO
WonderSwan (mono).
Definition system.h:69