libws libws
WSwan hardware library for the Wonderful toolchain
Loading...
Searching...
No Matches
cartridge.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_CARTRIDGE_H__
28#define __WF_LIBWS_CARTRIDGE_H__
29
30#include <stdbool.h>
31#include <stdint.h>
32#include <wonderful.h>
33#include "hardware.h"
34#include "util.h"
35
36typedef uint8_t ws_bank_t;
37
38#define WF_BANK_INDEX(x) (x)
39
45#define MEM_RAM ((uint8_t __wf_iram*) 0x00000000)
46#define MEM_SRAM ((uint8_t __far*) 0x10000000)
47#define MEM_ROM0 ((uint8_t __far*) 0x20000000)
48#define MEM_ROM1 ((uint8_t __far*) 0x30000000)
49#define MEM_ROM_LINEAR ((uint8_t __far*) 0x40000000)
50
58static inline ws_bank_t __ws_bank_save(uint8_t port, ws_bank_t new_bank) {
59 asm volatile("" ::: "memory");
60 uint8_t old_bank = inportb(port);
61 outportb(port, new_bank);
62 asm volatile("" ::: "memory");
63 return old_bank;
64}
65
66static inline void __ws_bank_set(uint8_t port, ws_bank_t new_bank) {
67 asm volatile("" ::: "memory");
68 outportb(port, new_bank);
69 asm volatile("" ::: "memory");
70}
71
78#define ws_bank_ram_save(new_bank) __ws_bank_save(IO_BANK_RAM, (new_bank))
79
85#define ws_bank_ram_set(new_bank) __ws_bank_set(IO_BANK_RAM, (new_bank))
86#define ws_bank_ram_restore ws_bank_ram_set
87
94#define ws_bank_rom0_save(new_bank) __ws_bank_save(IO_BANK_ROM0, (new_bank))
95
101#define ws_bank_rom0_set(new_bank) __ws_bank_set(IO_BANK_ROM0, (new_bank))
102#define ws_bank_rom0_restore ws_bank_rom0_set
103
110#define ws_bank_rom1_save(new_bank) __ws_bank_save(IO_BANK_ROM1, (new_bank))
111
117#define ws_bank_rom1_set(new_bank) __ws_bank_set(IO_BANK_ROM1, (new_bank))
118#define ws_bank_rom1_restore ws_bank_rom1_set
119
126#define ws_bank_rom_linear_save(new_bank) __ws_bank_save(IO_BANK_ROM_LINEAR, (new_bank))
127
133#define ws_bank_rom_linear_set(new_bank) __ws_bank_set(IO_BANK_ROM_LINEAR, (new_bank))
134#define ws_bank_rom_linear_restore ws_bank_rom_linear_set
135
141void ws_cart_gpo_enable(uint8_t id);
142
148void ws_cart_gpo_disable(uint8_t id);
149
156void ws_cart_gpo_set(uint8_t id, bool val);
157
160#endif /* __WF_LIBWS_CARTRIDGE_H__ */
uint8_t ws_bank_t
Definition cartridge.h:36
void ws_cart_gpo_disable(uint8_t id)
Disable general-purpose output.
static void __ws_bank_set(uint8_t port, ws_bank_t new_bank)
Definition cartridge.h:66
void ws_cart_gpo_set(uint8_t id, bool val)
Set general-purpose output value.
void ws_cart_gpo_enable(uint8_t id)
Enable general-purpose output.
static ws_bank_t __ws_bank_save(uint8_t port, ws_bank_t new_bank)
Definition cartridge.h:58