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
26
27#ifndef LIBWS_EEPROM_H_
28#define LIBWS_EEPROM_H_
29
30#define WS_IEEP_SIZE_MONO 0x80
31#define WS_IEEP_SIZE_COLOR 0x800
32
33#define WS_IEEP_USER_ADDR 0x00
34#define WS_IEEP_USER_SIZE 0x60
35
36#define WS_IEEP_OWNER_NAME_ADDR 0x60 /* 16 bytes */
37#define WS_IEEP_OWNER_NAME_SIZE 16
38#define WS_IEEP_OWNER_BIRTHDAY_YEAR_ADDR 0x70 /* word */
39#define WS_IEEP_OWNER_BIRTHDAY_MONTH_ADDR 0x72 /* byte */
40#define WS_IEEP_OWNER_BIRTHDAY_DAY_ADDR 0x73 /* byte */
41#define WS_IEEP_OWNER_GENDER_ADDR 0x74 /* byte */
42
43#ifdef __ASSEMBLER__
44
45#define WS_IEEP_GENDER_UNK 0
46#define WS_IEEP_GENDER_MALE 1
47#define WS_IEEP_GENDER_FEMALE 2
48
49#else
50
59
60#endif
61
62#define WS_IEEP_OWNER_BLOOD_TYPE_ADDR 0x75 /* byte */
63
64#ifdef __ASSEMBLER__
65
66#define WS_IEEP_BLOOD_TYPE_UNK 0
67#define WS_IEEP_BLOOD_TYPE_A 1
68#define WS_IEEP_BLOOD_TYPE_B 2
69#define WS_IEEP_BLOOD_TYPE_0 3
70#define WS_IEEP_BLOOD_TYPE_AB 4
71
72#else
73
84
85#endif
86
87#define WS_IEEP_LAST_CART_PUBLISHER_ADDR 0x76 /* byte */
88#define WS_IEEP_LAST_CART_PLATFORM_ADDR 0x77 /* byte */
89#define WS_IEEP_LAST_CART_GAME_ID_ADDR 0x78 /* byte */
90#define WS_IEEP_CART_CHANGE_COUNT_ADDR 0x7C /* byte */
91#define WS_IEEP_NAME_CHANGE_COUNT_ADDR 0x7D /* byte */
92#define WS_IEEP_STARTUP_COUNT_ADDR 0x7E /* word */
93
94#define WS_IEEP_COLOR_SETTINGS_ADDR 0x83 /* byte */
95#define WS_IEEP_COLOR_SETTINGS_CUSTOM_SPLASH 0x80
96#define WS_IEEP_COLOR_SETTINGS_WSC_HIGH_CONTRAST 0x40
97#define WS_IEEP_COLOR_SETTINGS_VOLUME(x) ((x) & 3)
98#define WS_IEEP_COLOR_SETTINGS_VOLUME_MASK 0x03
99
100#define WS_IEEP_NAME_COLOR_ADDR 0x84 /* byte */
101
102#ifdef __ASSEMBLER__
103
104#define WS_IEEP_NAME_COLOR_BLACK 0x00
105#define WS_IEEP_NAME_COLOR_RED 0x01
106#define WS_IEEP_NAME_COLOR_ORANGE 0x02
107#define WS_IEEP_NAME_COLOR_YELLOW 0x03
108#define WS_IEEP_NAME_COLOR_LIME 0x04
109#define WS_IEEP_NAME_COLOR_GREEN 0x05
110#define WS_IEEP_NAME_COLOR_TEAL 0x06
111#define WS_IEEP_NAME_COLOR_CYAN 0x07
112#define WS_IEEP_NAME_COLOR_SEABLUE 0x08
113#define WS_IEEP_NAME_COLOR_BLUE 0x09
114#define WS_IEEP_NAME_COLOR_PURPLE 0x0A
115#define WS_IEEP_NAME_COLOR_PINK 0x0B
116#define WS_IEEP_NAME_COLOR_FUCHSIA 0x0C
117#define WS_IEEP_NAME_COLOR_WHITE 0x0D
118
119#else
120
140
141#endif
142
143#ifndef __ASSEMBLER__
144
145#include <stdbool.h>
146#include <stdint.h>
147#include "ports.h"
148#include "util.h"
149
154
155typedef struct {
156 uint8_t port;
157 uint8_t dwords; // bits - 2
159
161
163 ws_eeprom_handle_t handle = {0xC4, bits - 2};
164 return handle;
165}
166
173uint16_t ws_eeprom_read_word(ws_eeprom_handle_t handle, uint16_t address);
174
181uint8_t ws_eeprom_read_byte(ws_eeprom_handle_t handle, uint16_t address);
182
190void ws_eeprom_read_data(ws_eeprom_handle_t handle, uint16_t address, uint8_t *data, uint16_t length);
191
199bool ws_eeprom_write_word(ws_eeprom_handle_t handle, uint16_t address, uint16_t value);
200
207bool ws_eeprom_erase_word(ws_eeprom_handle_t handle, uint16_t address);
208
215
220
222
227
233void ws_ieep_read_owner_name(uint8_t *data);
234
241
248uint16_t ws_ieep_name_color_to_rgb(uint8_t value);
249
257static inline void ws_ieep_set_protect(void) {
259}
260
264static inline bool ws_ieep_is_protected(void) {
265 return inportb(WS_IEEP_CTRL_PORT) & WS_IEEP_CTRL_PROTECT;
266}
267
269
270#endif /* __ASSEMBLER__ */
271
272#endif /* LIBWS_EEPROM_H_ */
ws_ieep_name_color
Definition eeprom.h:124
@ WS_IEEP_NAME_COLOR_RED
RGB(15, 0, 0)
Definition eeprom.h:126
@ WS_IEEP_NAME_COLOR_GREEN
RGB(0, 15, 0)
Definition eeprom.h:130
@ WS_IEEP_NAME_COLOR_BLACK
RGB(0, 0, 0)
Definition eeprom.h:125
@ WS_IEEP_NAME_COLOR_FUCHSIA
RGB(15, 0, 7)
Definition eeprom.h:137
@ WS_IEEP_NAME_COLOR_WHITE
RGB(15, 15, 15)
Definition eeprom.h:138
@ WS_IEEP_NAME_COLOR_BLUE
RGB(0, 0, 15)
Definition eeprom.h:134
@ WS_IEEP_NAME_COLOR_LIME
RGB(7, 15, 0)
Definition eeprom.h:129
@ WS_IEEP_NAME_COLOR_PINK
RGB(15, 0, 15)
Definition eeprom.h:136
@ WS_IEEP_NAME_COLOR_CYAN
RGB(0, 15, 15)
Definition eeprom.h:132
@ WS_IEEP_NAME_COLOR_PURPLE
RGB(7, 0, 15)
Definition eeprom.h:135
@ WS_IEEP_NAME_COLOR_TEAL
RGB(0, 15, 7)
Definition eeprom.h:131
@ WS_IEEP_NAME_COLOR_YELLOW
RGB(15, 15, 0)
Definition eeprom.h:128
@ WS_IEEP_NAME_COLOR_SEABLUE
RGB(0, 7, 15)
Definition eeprom.h:133
@ WS_IEEP_NAME_COLOR_ORANGE
RGB(15, 7, 0)
Definition eeprom.h:127
ws_ieep_blood_type
Definition eeprom.h:77
@ WS_IEEP_BLOOD_TYPE_B
Definition eeprom.h:80
@ WS_IEEP_BLOOD_TYPE_AB
Definition eeprom.h:82
@ WS_IEEP_BLOOD_TYPE_UNK
Definition eeprom.h:78
@ WS_IEEP_BLOOD_TYPE_0
Definition eeprom.h:81
@ WS_IEEP_BLOOD_TYPE_A
Definition eeprom.h:79
ws_ieep_gender
Definition eeprom.h:54
@ WS_IEEP_GENDER_MALE
Definition eeprom.h:56
@ WS_IEEP_GENDER_UNK
Definition eeprom.h:55
@ WS_IEEP_GENDER_FEMALE
Definition eeprom.h:57
void ws_ieep_read_owner_name(uint8_t *data)
Read the owner name, as raw data.
static void ws_ieep_set_protect(void)
Protect the non-cartridge area of the internal EEPROM.
Definition eeprom.h:257
static bool ws_ieep_is_protected(void)
Check if the non-cartridge area of the internal EEPROM is currently protected.
Definition eeprom.h:264
void ws_ieep_read_owner_name_ascii(char *str)
Read the owner name, as an ASCII string.
uint16_t ws_ieep_name_color_to_rgb(uint8_t value)
Convert a given name color to its RGB value.
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:162
ws_eeprom_handle_t ws_eeprom_handle_internal(void)
#define WS_IEEP_CTRL_PORT
Definition ports.h:515
#define WS_IEEP_CTRL_PROTECT
Definition ports.h:519