libElysianVMU 1.6.0
Full-featured, accurate, cross-platform library emulating the Dreamcast's Visual Memory Unit
Loading...
Searching...
No Matches
evmu_address_space.h
Go to the documentation of this file.
1/*! \file
2 * \brief Defines for all known memory regions and addresses
3 * \ingroup address_space
4 * \sa evmu_sfr.h
5 *
6 * This single file serves as an amalgomation of years worth of
7 * research, scouring the internet, pouring over documents, and
8 * attepting to reverse engineer the VMU. It represents everything
9 * I know about every address compromising its main RAM address
10 * space.
11 *
12 * \author 2023 Falco Girgis
13 * \copyright MIT License
14 */
15
16#ifndef EVMU_ADDRESS_SPACE_H
17#define EVMU_ADDRESS_SPACE_H
18
19#ifdef __cplusplus
20extern "C" {
21#endif
22
23/*! \defgroup address_space Address Space
24 * \brief Macro definitions for main data address space
25 */
26
27//============== Segments Within Address Space ==============
28/*! \defgroup address_space_segments Segments
29 * \ingroup address_space
30 * \brief General info for internal/RAM addres space
31 * @{ */
32#define EVMU_ADDRESS_SEGMENT_RAM_BASE 0x00 //!< Start address of RAM
33#define EVMU_ADDRESS_SEGMENT_RAM_END 0xff //!< Last address of RAM
34#define EVMU_ADDRESS_SEGMENT_RAM_SIZE 256 //!< Size of RAM
35#define EVMU_ADDRESS_SEGMENT_RAM_BANKS 2 //!< Number of RAM banks
36#define EVMU_RAM_OFFSET(a) (a - EVMU_ADDRESS_SEGMENT_RAM_BASE) //! Returns an offset relative to RAM
37#define EVMU_RAM_ADDRESS(o) (EVMU_ADDRESS_SEGMENT_RAM_BASE + o) //! Returns an address from RAM offset
38
39#define EVMU_ADDRESS_SEGMENT_STACK_BASE 0x80 //!< Start address of stack
40#define EVMU_ADDRESS_SEGMENT_STACK_END 0xff //!< Last address of stack
41#define EVMU_ADDRESS_SEGMENT_STACK_SIZE 128 //!< Stack size
42#define EVMU_ADDRESS_SEGMENT_STACK_BANKS 1 //!< Number of stack banks
43#define EVMU_STACK_OFFSET(a) (a - EVMU_ADDRESS_SEGMENT_STACK_BASE) //!< Returns an offset relative to stack
44#define EVMU_STACK_ADDRESS(o) (EVMU_ADDRESS_SEGMENT_STACK_BEGIN + o) //!< Returns an address from stack offset
45
46#define EVMU_ADDRESS_SEGMENT_SFR_BASE 0x100 //!< Start address of SFR segment
47#define EVMU_ADDRESS_SEGMENT_SFR_END 0x17f //!< Last address of SFR segment
48#define EVMU_ADDRESS_SEGMENT_SFR_SIZE 128 //!< Size of SFR segment
49#define EVMU_ADDRESS_SEGMENT_SFR_BANKS 1 //!< Number of SFR banks
50#define EVMU_SFR_OFFSET(a) (a - EVMU_ADDRESS_SEGMENT_SFR_BASE) //!< Returns an SFR offset from address
51#define EVMU_SFR_ADDRESS(o) (EVMU_ADDRESS_SEGMENT_SFR_BEGIN + o) //!< Returns an address from SFR offsset
52
53#define EVMU_XRAM_ROW_BYTES 6 //!< Number of bytes per row in XRAM
54#define EVMU_XRAM_ROW_COUNT 16 //!< Number of rows in XRAM
55#define EVMU_ADDRESS_SEGMENT_XRAM_BASE 0x180 //!< Start address of XRAM
56#define EVMU_ADDRESS_SEGMENT_XRAM_END 0x1fb //!< Last address of XRAM
57#define EVMU_ADDRESS_SEGMENT_XRAM_SIZE 0x80 //!< Size of XRAM
58#define EVMU_ADDRESS_SEGMENT_XRAM_BANKS 3 //!< Number of XRAM banks
59#define EVMU_XRAM_OFFSET(a) (a - EVMU_ADDRESS_SEGMENT_XRAM_BASE) //!< Returns an address from XRAM offset
60#define EVMU_XRAM_ADDRESS(o) (EVMU_ADDRESS_SEGMENT_XRAM_BASE + o) //!< Returns an XRAM offset from address
61//! @}
62
63//================= System Variables (Ram Bank 0) ==================
64/*! \defgroup system_variables System Variables
65 * \ingroup address_space
66 * \brief Reserved system variables (Ram Bank 0)
67 *
68 * Addresses which are used by the BIOS routines for OS-related tasks
69 */
70
71/*! \defgroup system_date_time Date/Time Variables
72 * \ingroup system_variables
73 * \brief BIOS variables used to maintain date and time
74 * @{
75 */
76// -------------------- System Date/Time Storage --------------------
77#define EVMU_ADDRESS_SYSTEM_YEAR_MSB_BCD 0x10 //!< BCD Year High Byte
78#define EVMU_ADDRESS_SYSTEM_YEAR_LSB_BCD 0x11 //!< BCD Year Low Byte
79#define EVMU_ADDRESS_SYSTEM_MONTH_BCD 0x12 //!< BCD Month
80#define EVMU_ADDRESS_SYSTEM_DAY_BCD 0x13 //!< BCD Day
81#define EVMU_ADDRESS_SYSTEM_HOUR_BCD 0x14 //!< BCD Hour
82#define EVMU_ADDRESS_SYSTEM_MINUTE_BCD 0x15 //!< BCD Minute
83#define EVMU_ADDRESS_SYSTEM_SEC_BCD 0x16 //!< BCD Seconds(?) (MAYBE DAY OF WEEK)
84#define EVMU_ADDRESS_SYSTEM_YEAR_MSB 0x17 //!< Non-BCD Year High Byte
85#define EVMU_ADDRESS_SYSTEM_YEAR_LSB 0x18 //!< Non-BCD Year Low Byte
86#define EVMU_ADDRESS_SYSTEM_MONTH 0x19 //!< Non-BCD Month
87#define EVMU_ADDRESS_SYSTEM_DAY 0x1a //!< Non-BCD Day
88#define EVMU_ADDRESS_SYSTEM_HOUR 0x1b //!< Non-BCD Hour
89#define EVMU_ADDRESS_SYSTEM_MINUTE 0x1c //!< Non-BCD Minute
90#define EVMU_ADDRESS_SYSTEM_SEC 0x1d //!< Non-BCD Second
91#define EVMU_ADDRESS_SYSTEM_HALF_SEC 0x1e //!< 0 or 1, driven by base-timer interrupt every 0.5s, WORK AREA, DON'T WRITE
92#define EVMU_ADDRESS_SYSTEM_LEAP_YEAR 0x1f //!< 0 for no, 1 for yes, WORK AREA, DON'T WRITE
93//! @}
94
95/*! \defgroup system-general General Variables
96 * \ingroup system_variables
97 * \brief Known general system variables
98 * @{
99 */
100//-------------------- General Bios Variables --------------------
101#define EVMU_ADDRESS_SYSTEM_MODE 0x30 //!< probably BIOS logic... LOOKS LIKE ITS THE MODE INDEX!!!
102#define EVMU_ADDRESS_SYSTEM_DATE_SET 0x31 //!< 0xff - date set, 00 - date not set
103//0x33 - 0x34 seem to be INACTIVITY COUNTERS for putting the bitch to sleep!!!!
104// UNKKNOWN [32 bytes] 0x32-0x49 //!< other BIOS settings?
105#define EVMU_ADDRESS_SYSTEM_QUART_YEAR_MSB 0x50 //!< current year divided by 4 (high byte)
106#define EVMU_ADDRESS_SYSTEM_QUART_YEAR_LSB 0x51 //!< current year divided by 4 (low byte)
107#define EVMU_ADDRESS_SYSTEM_CURSOR_POS_COL 0x60 //!< cursor position, column (0-7)
108#define EVMU_ADDRESS_SYSTEM_CURSOR_POS_ROW 0x61 //!< cursor position, row (0-3)
109#define EVMU_ADDRESS_SYSTEM_GAME_LAST_BLK 0x6d //!< Last block used by mini-game
110#define EVMU_ADDRESS_SYSTEM_BATTERY_CHECK 0x6e //!< Battery check flag (0xff - disable auto battery check, 0x00 - enable auto battery check)
111// UNKNOWN [17 bytes] 0x6f-0x7f //!< Other BIOS magical shit?
112//-------------------- Stack Storage --------------------
113#define EVMU_ADDRESS_SYSTEM_STACK_BASE 0x80 //!< First entry for stack storage
114// STACK STORAGE [126 BYTES] 0x81-0xfe //!< Generic storage on the stack
115#define EVMU_ADDRESS_SYSTEM_STACK_END 0xff //!< Last entry for stack storage
116/*! @} */
117//============== Firmware Argument Addresses (Ram Bank 1) =======================
118/*! \defgroup bios_input_variables Firmware Input Variables
119 * \ingroup address_space
120 * \brief BIOS input variables (RAM bank 1)
121 *
122 * Ram Bank 1 variables which are used for passing values to firmware routines.
123 *
124 * @{*/
125#define EVMU_ADDRESS_USER_FMBANK 0x7d //!< Flash memory read bank address
126#define EVMU_ADDRESS_USER_FMADD_H 0x7e //!< Flash memory read start upper address
127#define EVMU_ADDRESS_USER_FMADD_L 0x7f //!< Flash memory read start lower address
128#define EVMU_ADDRESS_USER_FM_RET_BASE 0x80 //!< Flash read/write start address
129#define EVMU_ADDRESS_USER_FM_RET_SIZE 128 //!< Flash read/write count (128 bytes)
130#define EVMU_ADDRESS_USER_FM_RET_END 0xff //!< Flash read/write end address
131/*! @} */
132//==================== SPECIAL FUNCTION REGISTERS ====================
133/*! \defgroup sfrs Special Function Registers
134 * \ingroup address_space
135 * \brief Special function register locations and descriptions
136 *
137 * These are registers which are reserved by the SoC and its peripherals,
138 * which typically have special usages and properties.
139 *
140 * @{*/
141//-------------------- CPU, Interrupts, Clocks Registers --------------------
142#define EVMU_ADDRESS_SFR_ACC 0x100 //!< Accumulator
143#define EVMU_ADDRESS_SFR_PSW 0x101 //!< Processor Status Word
144#define EVMU_ADDRESS_SFR_B 0x102 //!< B Register (general purpose)
145#define EVMU_ADDRESS_SFR_C 0x103 //!< C Register (general purpose)
146#define EVMU_ADDRESS_SFR_TRL 0x104 //!< Table Reference (low byte)
147#define EVMU_ADDRESS_SFR_TRH 0x105 //!< Table Reference (high byte)
148#define EVMU_ADDRESS_SFR_SP 0x106 //!< Stack Pointer
149#define EVMU_ADDRESS_SFR_PCON 0x107 //!< Power Control register
150#define EVMU_ADDRESS_SFR_IE 0x108 //!< Interrupt Enable control
151#define EVMU_ADDRESS_SFR_IP 0x109 //!< Interrupt Priority Ranking control
152// ALL 1s 0x10a-0x10c //!< OPEN BUS
153#define EVMU_ADDRESS_SFR_EXT 0x10d //!< External Memory control - Whether program is read from ROM (BIOS) or FLASH (GAME)
154#define EVMU_ADDRESS_SFR_OCR 0x10e //!< Oscillation Control Register (32kHz/600kHz/6MHz)
155// ALL 1s 0x10f //!< OPEN BUS
156//--------------------Timer 0 Config Regisers --------------------
157#define EVMU_ADDRESS_SFR_T0CNT 0x110 //!< Timer 0 control
158#define EVMU_ADDRESS_SFR_T0PRR 0x111 //!< Timer 0 Prescalar Data register
159#define EVMU_ADDRESS_SFR_T0L 0x112 //!< Timer 0 Low Byte
160#define EVMU_ADDRESS_SFR_T0LR 0x113 //!< Timer 0 Low Byte Reload register
161#define EVMU_ADDRESS_SFR_T0H 0x114 //!< Timer 0 High Byte
162#define EVMU_ADDRESS_SFR_T0HR 0x115 //!< Timer 0 High Byte Reload register
163// ALL 1s 0x116 //!< OPEN BUS
164// ALL 1s 0x117 //!< OPEN BUS
165//-------------------- Timer 1 Config Registers --------------------
166#define EVMU_ADDRESS_SFR_T1CNT 0x118 //!< Timer 1 control
167// ALL 1s 0x119 //!< OPEN BUS
168#define EVMU_ADDRESS_SFR_T1LC 0x11a //!< Timer 1 Low Compare Data register
169#define EVMU_ADDRESS_SFR_T1L 0x11b //!< Timer 1 Low (Read-only)
170#define EVMU_ADDRESS_SFR_T1LR 0x11b //!< Timer 1 Low Reload register (Write-only)
171#define EVMU_ADDRESS_SFR_T1HC 0x11c //!< Timer 1 High Compare Data register
172#define EVMU_ADDRESS_SFR_T1H 0x11d //!< Timer 1 High (Read-only)
173#define EVMU_ADDRESS_SFR_T1HR 0x11d //!< Timer 1 High Reload Register (Write-only)
174// ALL 1s 0x11e-0x11f //!< OPEN BUS
175//-------------------- LCD Controller Registers --------------------
176#define EVMU_ADDRESS_SFR_MCR 0x120 //!< Mode Control register
177// ALL 1s 0x121 //!< OPEN BUS
178#define EVMU_ADDRESS_SFR_STAD 0x122 //!< Start Address register
179#define EVMU_ADDRESS_SFR_CNR 0x123 //!< Character Number register
180#define EVMU_ADDRESS_SFR_TDR 0x124 //!< Time Division register
181#define EVMU_ADDRESS_SFR_XBNK 0x125 //!< Bank Address register
182// ALL 1s 0x126 //!< OPEN BUS
183#define EVMU_ADDRESS_SFR_VCCR 0x127 //!< LCD Contrast Control register
184// ALL 1s 0x128-0x12f //!< LCD or Serial or Maple registers?
185//-------------------- Serial Interface 0 Registers --------------------
186#define EVMU_ADDRESS_SFR_SCON0 0x130 //!< SIO0 Control register
187#define EVMU_ADDRESS_SFR_SBUF0 0x131 //!< SIO0 Buffer
188#define EVMU_ADDRESS_SFR_SBR 0x132 //!< SIO Baud Rate Generator register
189// ALL 1s 0x133 //!< OPEN BUS
190//-------------------- Serial Interface 1 Registers --------------------
191#define EVMU_ADDRESS_SFR_SCON1 0x134 //!< SI01 Control register
192#define EVMU_ADDRESS_SFR_SBUF1 0x135 //!< SI01 Buffer
193// ALL 1s 0x136-0x143 //!< Serial or Maple Xfer settings? DC Mode? Port1 config?
194//-------------------- Port 1 Registers --------------------
195#define EVMU_ADDRESS_SFR_P1 0x144 //!< Port 1 Latch
196#define EVMU_ADDRESS_SFR_P1DDR 0x145 //!< Port 1 Data Direction register
197#define EVMU_ADDRESS_SFR_P1FCR 0x146 //!< Port 1 Function Control register
198// 0xfe 0x147 //!< Unknown Port1 configuration (All high EXCEPT bit 7 R/W)
199// ALL 1s 0x148 //!< "unknown, rom writes this once with 0x00 only, related to SFR_x51, SFR_x55"
200// ALL 1s 0x149-0x14b //!< Extra Port 1 or Port3 config?
201//-------------------- Port 3 Registers --------------------
202#define EVMU_ADDRESS_SFR_P3 0x14c //!< Port 3 Latch
203#define EVMU_ADDRESS_SFR_P3DDR 0x14d //!< Port 3 Data Direction register
204#define EVMU_ADDRESS_SFR_P3INT 0x14e //!< Port 3 Interrupt Control register
205// ALL 1s 0x14f-0x150 //!< Port 3 Shit?
206// ALL 1s 0x151 //!< "unknown, rom sets bit 5 only, related to SFR_x48, SFR_x55"
207// ALL 1s 0x152-0x153 //!< P3 or Flash shit?
208//-------------------- Flash Controller Register --------------------
209#define EVMU_ADDRESS_SFR_FPR 0x154 //!< (READ: all 1s) Flash Program Register: Used by LDF and STF flash instructions (in BIOS)
210// ALL 1s 0x155 //!< "unknown, rom writes this once with 0xFF only, related to SFR_x48, SFR_x51"
211// ALL 1s 0x156-0x15b //!< Maybe more flash controller-y shit?
212//-------------------- Port 7 Registers ----------
213#define EVMU_ADDRESS_SFR_P7 0x15c //!< Port 7 Latch
214#define EVMU_ADDRESS_SFR_I01CR 0x15d //!< External Interrupt 0, 1 Control
215#define EVMU_ADDRESS_SFR_I23CR 0x15e //!< External Interrupt 2, 3 Control
216#define EVMU_ADDRESS_SFR_ISL 0x15f //!< Input Signal Selection register
217//-------------------- Maple Communications Controller Registers ----------
218#define EVMU_ADDRESS_SFR_MPLESW 0x160 //!< "UNDOC [ - | - | - | LASTPKT (Set if packet is last) | - | HW_ENA (is hw on?) | TX (TX normal packet) | TXS (tx starting packet) ]"
219#define EVMU_ADDRESS_SFR_MPLESTA 0x161 //!< "UNDOC [ - | UNK (if set causes bus to be reinited) | ERR3 | ERR2 | - | IRQREQ (cleared by handler) | ERR1 | TXDONE (Set when tx done) ] (errs s\et if RXed packet was bad)"}
220#define EVMU_ADDRESS_SFR_MPLERST 0x162 //!< Set and clear to reset Maple BUS
221// UNDISCOVERED BIOS? [3 bytes] 0x160-0x162 //!< Control WRAM<=>Maple BUS transition
222/*
223 0x160-0x162 Not (officially) Used
224 The BIOS clears bits 2 and 4, and sets bits 0 and 1.
225
226 These registers seem to write data to the Maple bus from the Work RAM.
227 One little routine does this series of operations:
228
229 1. Write 3 to VLREG
230 2. Clears VSEL.0
231 3. sets VRMAD1 to 0 (zeros address)
232 4. writes 32 bytes to VTRBF
233 5. Sets VSEL.0
234 6. Sets SFR161.1
235 7. Waits for SFR161.0 to be set
236 8. loop lines 2-7
237
238ACCORDING TO SANYO VMU SIMULATOR SCREENSHOTS IN DOCS
2390x162 - Control Flag2 (VCFLG2)
240 - bit 7: SRES (only one shown)
241*/
242//-------------------- WRAM Registers --------------------
243#define EVMU_ADDRESS_SFR_VSEL 0x163 //!< VMS Control register
244#define EVMU_ADDRESS_SFR_VRMAD1 0x164 //!< Work RAM Access Address 1
245#define EVMU_ADDRESS_SFR_VRMAD2 0x165 //!< Work RAM Access Address 2
246#define EVMU_ADDRESS_SFR_VTRBF 0x166 //!< Send/Receive Buffer
247#define EVMU_ADDRESS_SFR_VLREG 0x167 //!< Length registration, # of maple words to send on BUS
248/*
249 * 0x168 - ALL 0s
250 * 0x169-0x16a - ALL 0s
251 * 0x16b - 00101001
252 * 0x16c - ALL 1s
253 * 0x16d-0x17e - ALL 1s
254 */
255// UNKNOWN [23 bytes] 0x168-0x17e //!< WRAM/maple control or base timer shit?
256//-------------------- Base Timer Registers --------------------
257#define EVMU_ADDRESS_SFR_BTCR 0x17f //!< Base Time Control register
258/*! @} */
259
260//==================== XRAM Registers ====================
261/*! \defgroup xram_sfrs XRAM Registers
262 * \ingroup address_space
263 * \brief Special registers within XRAM region
264 *
265 * These are addresses within the XRAM memory region,
266 * which is basically used as VRAM and a framebuffer.
267 *
268 * @{*/
269// -------------------- LCD Framebuffer (0x180f - 0x1fb) [Banks 0 + 1 ] --------------------
270//! Retrurns the XRAM byte containing the pixel value at the given location
271#define EVMU_ADDRESS_XRAM_BYTE(x, y)
272 (EVMU_ADDRESS_SEGMENT_XRAM_BASE+(y*EVMU_XRAM_ROW_BYTES)+x) //LCD Frame Buffer Grid
273
274// -------------------- BIOS Icons [Bank 2] --------------------
275// FREE RAM 0x180
276#define EVMU_ADDRESS_XRAM_ICN_FILE 0x181 //!< File Icon - XRAM Bank 2
277#define EVMU_ADDRESS_XRAM_ICN_GAME 0x182 //!< Game Icon - XRAM Bank 2
278#define EVMU_ADDRESS_XRAM_ICN_CLOCK 0x183 //!< Clock Icon - XRAM Bank 2
279#define EVMU_ADDRESS_XRAM_ICN_FLASH 0x184 //!< Flash Access Icon - XRAM Bank 2
280// FREE RAM 0x185-18b
281// ALL 1s 0x18c-0x1ff
282//==================== EXTRA? ====================
283// UNKNOWN [4 bytes] 0x1fc-0x1ff //!< End of address-space... anything else going on? In Xram?
284/*! @} */
285
286#ifdef __cplusplus
287}
288#endif
289
290#endif // EVMU_ADDRESS_SPACE_H
#define EVMU_ADDRESS_SEGMENT_RAM_BASE
Start address of RAM.
#define EVMU_ADDRESS_SEGMENT_STACK_BASE
Start address of stack.
#define EVMU_XRAM_ROW_BYTES
Number of bytes per row in XRAM.
#define EVMU_ADDRESS_SEGMENT_XRAM_BASE
Start address of XRAM.
#define EVMU_ADDRESS_SEGMENT_SFR_BASE
Start address of SFR segment.