aboutsummaryrefslogtreecommitdiff
path: root/arm9/source/devices/memory.h
diff options
context:
space:
mode:
authorBen Bridle <ben@derelict.engineering>2025-09-19 13:17:14 +1200
committerBen Bridle <ben@derelict.engineering>2025-09-19 13:32:32 +1200
commitbb1aa5958d1b67707dcf0f6b08bfaf0b408bd46e (patch)
treeb26d07ed58aaf7a5230fc3e28c103d616abfa9b8 /arm9/source/devices/memory.h
parent9612c307f00c4313d73fe0c3a86c05c8d8cd514e (diff)
downloadbedrock-nds-bb1aa5958d1b67707dcf0f6b08bfaf0b408bd46e.zip
Massive rewrite
This commit rewrites the emulator halfway from scratch to make it easier to change and maintain in the future. The emulator core was rewritten to adhere to the released Bedrock specification (earlier versions implemented an older prototype specification, which is no longer relevant). This commit also adds proper support for running multiple concurrent Bedrock instances. This was previously supported in a limited manner for the on-screen keyboard, but now works for any regular program as well, with switching being performed by pressing the L or R bumper buttons. This is disabled by default, as programs will still need to be baked into the emulator and hand-loaded.
Diffstat (limited to 'arm9/source/devices/memory.h')
-rw-r--r--arm9/source/devices/memory.h60
1 files changed, 26 insertions, 34 deletions
diff --git a/arm9/source/devices/memory.h b/arm9/source/devices/memory.h
index 0abff16..814f47d 100644
--- a/arm9/source/devices/memory.h
+++ b/arm9/source/devices/memory.h
@@ -1,42 +1,34 @@
#ifndef MEMORY_H_
#define MEMORY_H_
- #define HEAP_SIZE (4096*3)
+ #include "../bang.h"
- typedef struct {
- u8 id; // Unique non-zero identifier for this memory device.
-
- u16 offset1; // Bedrock offset value for head 1
- u8 page1; // Bedrock address value for head 1
- u8 byte1; // Bedrock address value for head 1
- u16 offset2; // Bedrock offset value for head 2
- u8 page2; // Bedrock address value for head 2
- u8 byte2; // Bedrock address value for head 2
-
- u16 count_write; // write cache for page count
- u16 count; // number of pages allocated for this bedrock
- u16 copy_write; // write cache for page copy length
-
- u8 *point1; // pointer to current page for head 1
- u8 *point2; // pointer to current page for head 2
-
- u8* cache1[256];
- u8* cache2[256];
- } MemoryDevice ;
- u8 mem_read1(MemoryDevice *mem);
- u8 mem_read2(MemoryDevice *mem);
- void mem_write1(MemoryDevice *mem, u8 value);
- void mem_write2(MemoryDevice *mem, u8 value);
-
- void mem_load_cache1(MemoryDevice *mem);
- void mem_load_cache2(MemoryDevice *mem);
- void mem_get_page1(MemoryDevice *mem);
- void mem_get_page2(MemoryDevice *mem);
-
-
- void mem_allocate(MemoryDevice *mem);
- void mem_do_copy(MemoryDevice *mem);
+ // Read-write head for memory device.
+ typedef struct {
+ u16 offset; // Index of base page.
+ u8 page; // Index of current page from offset.
+ u8 byte; // Index of current byte in page.
+ u8 *point; // Pointer to current page.
+ u8 *cache[256]; // Pointers to all pages for the current offset.
+ } MemoryHead;
+ // Bedrock memory device.
+ typedef struct {
+ u8 id; // Non-zero ID of this Bedrock instance.
+ u16 allocated; // Number of pages allocated to this instance
+ u16 count; // Write cache for allocation count
+ u16 copy; // Write cache for copy length
+ MemoryHead head1;
+ MemoryHead head2;
+ } MemoryDevice;
+ // Methods.
+ void memory_reset(MemoryDevice *mem);
+ u8 memory_read(MemoryHead *head);
+ void memory_write(MemoryHead *head, u8 value);
+ void memory_refresh_page(MemoryHead *head);
+ void memory_refresh_cache(MemoryDevice *mem, MemoryHead *head);
+ void memory_allocate(MemoryDevice *mem);
+ void memory_copy(MemoryDevice *mem);
#endif