aboutsummaryrefslogtreecommitdiff
path: root/arm9/source/devices/memory.h
blob: 814f47d9d9a332e020236b2e144455297191dd4c (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
#ifndef MEMORY_H_
    #define MEMORY_H_

    #include "../bang.h"


    // 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