summaryrefslogtreecommitdiff
path: root/apps/plugins/rockboy/fastmem.c
diff options
context:
space:
mode:
Diffstat (limited to 'apps/plugins/rockboy/fastmem.c')
-rw-r--r--apps/plugins/rockboy/fastmem.c139
1 files changed, 39 insertions, 100 deletions
diff --git a/apps/plugins/rockboy/fastmem.c b/apps/plugins/rockboy/fastmem.c
index d883438ce1..9092f68fed 100644
--- a/apps/plugins/rockboy/fastmem.c
+++ b/apps/plugins/rockboy/fastmem.c
@@ -3,136 +3,75 @@
3#include "rockmacros.h" 3#include "rockmacros.h"
4#include "fastmem.h" 4#include "fastmem.h"
5 5
6
7#define D 0 /* direct */
8#define C 1 /* direct cgb-only */
9#define R 2 /* io register */
10#define S 3 /* sound register */
11#define W 4 /* wave pattern */
12
13#define F 0xFF /* fail */
14
15const byte himask[256];
16
17const byte hi_rmap[256] =
18{
19 0, 0, R, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
20 S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
21 S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
22 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
23 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, C, 0, C,
24 0, C, C, C, C, C, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
25 0, 0, 0, 0, 0, 0, 0, 0, C, C, C, C, 0, 0, 0, 0,
26 C, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
27};
28
29const byte hi_wmap[256] =
30{
31 R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R,
32 S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
33 S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
34 S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
35 R, R, R, R, R, R, R, R, R, R, R, R, 0, R, 0, R,
36 0, C, C, C, C, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
37 0, 0, 0, 0, 0, 0, 0, 0, R, R, R, R, 0, 0, 0, 0,
38 R, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
39
40 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
41 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
42 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
43 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
44 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
45 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
46 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
47 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, R
48};
49
50
51byte readb(int a) 6byte readb(int a)
52{ 7{
53 byte *p = mbc.rmap[a>>12]; 8 byte *p = mbc.rmap[a>>12];
54 if (p) return p[a]; 9 if (p) return p[a];
55 else return mem_read(a); 10 else return mem_read(a);
56} 11}
57 12
58void writeb(int a, byte b) 13void writeb(int a, byte b)
59{ 14{
60 byte *p = mbc.wmap[a>>12]; 15 byte *p = mbc.wmap[a>>12];
61 if (p) p[a] = b; 16 if (p) p[a] = b;
62 else mem_write(a, b); 17 else mem_write(a, b);
63} 18}
64 19
65int readw(int a) 20int readw(int a)
66{ 21{
67 if ((a+1) & 0xfff) 22 if ((a+1) & 0xfff)
68 { 23 {
69 byte *p = mbc.rmap[a>>12]; 24 byte *p = mbc.rmap[a>>12];
70 if (p) 25 if (p)
71 { 26 {
72#ifdef ROCKBOX_LITTLE_ENDIAN 27#ifdef ROCKBOX_LITTLE_ENDIAN
73#ifndef ALLOW_UNALIGNED_IO 28#ifndef ALLOW_UNALIGNED_IO
74 if (a&1) return p[a] | (p[a+1]<<8); 29 if (a&1) return p[a] | (p[a+1]<<8);
75#endif 30#endif
76 return *(word *)(p+a); 31 return *(word *)(p+a);
77#else 32#else
78 return p[a] | (p[a+1]<<8); 33 return p[a] | (p[a+1]<<8);
79#endif 34#endif
80 } 35 }
81 } 36 }
82 return mem_read(a) | (mem_read(a+1)<<8); 37 return mem_read(a) | (mem_read(a+1)<<8);
83} 38}
84 39
85void writew(int a, int w) 40void writew(int a, int w)
86{ 41{
87 if ((a+1) & 0xfff) 42 if ((a+1) & 0xfff)
88 { 43 {
89 byte *p = mbc.wmap[a>>12]; 44 byte *p = mbc.wmap[a>>12];
90 if (p) 45 if (p)
91 { 46 {
92#ifdef ROCKBOX_LITTLE_ENDIAN 47#ifdef ROCKBOX_LITTLE_ENDIAN
93#ifndef ALLOW_UNALIGNED_IO 48#ifndef ALLOW_UNALIGNED_IO
94 if (a&1) 49 if (a&1)
95 { 50 {
96 p[a] = w; 51 p[a] = w;
97 p[a+1] = w >> 8; 52 p[a+1] = w >> 8;
98 return; 53 return;
99 } 54 }
100#endif 55#endif
101 *(word *)(p+a) = w; 56 *(word *)(p+a) = w;
102 return; 57 return;
103#else 58#else
104 p[a] = w; 59 p[a] = w;
105 p[a+1] = w >> 8; 60 p[a+1] = w >> 8;
106 return; 61 return;
107#endif 62#endif
108 } 63 }
109 } 64 }
110 mem_write(a, w); 65 mem_write(a, w);
111 mem_write(a+1, w>>8); 66 mem_write(a+1, w>>8);
112} 67}
113 68
114byte readhi(int a) 69byte readhi(int a)
115{ 70{
116 return readb(a | 0xff00); 71 return readb(a | 0xff00);
117} 72}
118 73
119void writehi(int a, byte b) 74void writehi(int a, byte b)
120{ 75{
121 writeb(a | 0xff00, b); 76 writeb(a | 0xff00, b);
122} 77}
123
124#if 0
125byte readhi(int a)
126{
127 byte (*rd)() = hi_read[a];
128 return rd ? rd(a) : (ram.hi[a] | himask[a]);
129}
130
131void writehi(int a, byte b)
132{
133 byte (*wr)() = hi_write[a];
134 if (wr) wr(a, b);
135 else ram.hi[a] = b & ~himask[a];
136}
137#endif
138