libws libws
WSwan hardware library for the Wonderful toolchain
Loading...
Searching...
No Matches
eeprom.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_EEPROM_H__
28#define __WF_LIBWS_EEPROM_H__
29
30#include <stdbool.h>
31#include <stdint.h>
32#include "hardware.h"
33#include "util.h"
34
40typedef struct {
41 uint8_t port;
42 uint8_t dwords; // bits - 2
44
46
48 ws_eeprom_handle_t handle = {0xC4, bits - 2};
49 return handle;
50}
51
58uint16_t ws_eeprom_read_word(ws_eeprom_handle_t handle, uint16_t address);
59
66uint8_t ws_eeprom_read_byte(ws_eeprom_handle_t handle, uint16_t address);
67
75void ws_eeprom_read_data(ws_eeprom_handle_t handle, uint16_t address, uint8_t *data, uint16_t length);
76
84bool ws_eeprom_write_word(ws_eeprom_handle_t handle, uint16_t address, uint16_t value);
85
92bool ws_eeprom_erase_word(ws_eeprom_handle_t handle, uint16_t address);
93
100
105
113#define WS_IEEP_SIZE_MONO 0x80
114#define WS_IEEP_SIZE_COLOR 0x800
115
116#define IEEP_ADDR_OWNER_NAME 0x60 /* 16 bytes */
117#define IEEP_ADDR_OWNER_BIRTHDAY_YEAR 0x70 /* word */
118#define IEEP_ADDR_OWNER_BIRTHDAY_MONTH 0x72 /* byte */
119#define IEEP_ADDR_OWNER_BIRTHDAY_DAY 0x73 /* byte */
120#define IEEP_ADDR_OWNER_GENDER 0x74 /* byte */
121#define IEEP_ADDR_OWNER_BLOOD_TYPE 0x75 /* byte */
122#define IEEP_ADDR_LAST_CART_PUBLISHER 0x76 /* byte */
123#define IEEP_ADDR_LAST_CART_PLATFORM 0x77 /* byte */
124#define IEEP_ADDR_LAST_CART_GAME_ID 0x78 /* byte */
125#define IEEP_ADDR_CART_CHANGE_COUNT 0x7C /* byte */
126#define IEEP_ADDR_NAME_CHANGE_COUNT 0x7D /* byte */
127#define IEEP_ADDR_STARTUP_COUNT 0x7E /* word */
128
129#define IEEP_ADDR_C_OPTIONS1 0x83 /* byte */
130#define IEEP_C_OPTIONS1_CUSTOM_SPLASH 0x80
131#define IEEP_C_OPTIONS1_WSC_HIGH_CONTRAST 0x40
132#define IEEP_C_OPTIONS1_VOLUME(x) ((x) & 3)
133#define IEEP_C_OPTIONS1_VOLUME_MASK 0x03
134
135#define IEEP_ADDR_C_NAME_COLOR 0x84 /* byte */
136#define IEEP_C_NAME_COLOR_BLACK 0x00 /* RGB(0, 0, 0) */
137#define IEEP_C_NAME_COLOR_RED 0x01 /* RGB(15, 0, 0) */
138#define IEEP_C_NAME_COLOR_ORANGE 0x02 /* RGB(15, 7, 0) */
139#define IEEP_C_NAME_COLOR_YELLOW 0x03 /* RGB(15, 15, 0) */
140#define IEEP_C_NAME_COLOR_LIME 0x04 /* RGB(7, 15, 0) */
141#define IEEP_C_NAME_COLOR_GREEN 0x05 /* RGB(0, 15, 0) */
142#define IEEP_C_NAME_COLOR_TEAL 0x06 /* RGB(0, 15, 7) */
143#define IEEP_C_NAME_COLOR_CYAN 0x07 /* RGB(0, 15, 15) */
144#define IEEP_C_NAME_COLOR_SEABLUE 0x08 /* RGB(0, 7, 15) */
145#define IEEP_C_NAME_COLOR_BLUE 0x09 /* RGB(0, 0, 15) */
146#define IEEP_C_NAME_COLOR_PURPLE 0x0A /* RGB(7, 0, 15) */
147#define IEEP_C_NAME_COLOR_PINK 0x0B /* RGB(15, 0, 15) */
148#define IEEP_C_NAME_COLOR_FUCHSIA 0x0C /* RGB(15, 0, 7) */
149#define IEEP_C_NAME_COLOR_WHITE 0x0D /* RGB(15, 15, 15) */
150#define IEEP_C_NAME_COLOR_GRAY 0x0E /* RGB(7, 7, 7) */
151
157void ws_ieep_read_owner_name(uint8_t *data);
158
165
172uint16_t ws_ieep_name_color_to_rgb(uint8_t value);
173
181static inline void ws_ieep_protect_enable(void) {
182 outportb(IO_IEEP_CTRL, IEEP_PROTECT);
183}
184
188static inline bool ws_ieep_protect_check(void) {
189 return inportb(IO_IEEP_CTRL) & IEEP_PROTECT;
190}
191
194#endif /* __WF_LIBWS_EEPROM_H__ */
#define IO_IEEP_CTRL
Definition hardware.h:398
#define IEEP_PROTECT
Definition hardware.h:399
bool ws_eeprom_write_lock(ws_eeprom_handle_t handle)
Lock the EEPROM, preventing writes and erases.
void ws_eeprom_read_data(ws_eeprom_handle_t handle, uint16_t address, uint8_t *data, uint16_t length)
Read bytes from the EEPROM.
bool ws_eeprom_erase_word(ws_eeprom_handle_t handle, uint16_t address)
Erase a word from the EEPROM, setting it to 0xFFFF.
bool ws_eeprom_write_unlock(ws_eeprom_handle_t handle)
Unlock the EEPROM, allowing writes and erases.
uint8_t ws_eeprom_read_byte(ws_eeprom_handle_t handle, uint16_t address)
Read a byte from the EEPROM.
bool ws_eeprom_write_word(ws_eeprom_handle_t handle, uint16_t address, uint16_t value)
Write a word to the EEPROM.
uint16_t ws_eeprom_read_word(ws_eeprom_handle_t handle, uint16_t address)
Read an aligned word from the EEPROM.
static ws_eeprom_handle_t ws_eeprom_handle_cartridge(uint8_t bits)
Definition eeprom.h:47
ws_eeprom_handle_t ws_eeprom_handle_internal(void)
void ws_ieep_read_owner_name(uint8_t *data)
Read the owner name, as raw data.
static bool ws_ieep_protect_check(void)
Check if the non-cartridge area of the internal EEPROM is currently protected.
Definition eeprom.h:188
void ws_ieep_read_owner_name_ascii(char *str)
Read the owner name, as an ASCII string.
static void ws_ieep_protect_enable(void)
Protect the non-cartridge area of the internal EEPROM.
Definition eeprom.h:181
uint16_t ws_ieep_name_color_to_rgb(uint8_t value)
Convert a given name color to its RGB value.
uint8_t dwords
Definition eeprom.h:42