fix crash when specifying --source on command line
[rofl0r-gnuboy.git] / fastmem.h
blob33c93e42ca971650f9e9c8019a50bcb64a07e782
2 #ifndef __FASTMEM_H__
3 #define __FASTMEM_H__
6 #include "defs.h"
7 #include "mem.h"
10 static byte readb(int a)
12 byte *p = mbc.rmap[a>>12];
13 if (p) return p[a];
14 else return mem_read(a);
17 static void writeb(int a, byte b)
19 byte *p = mbc.wmap[a>>12];
20 if (p) p[a] = b;
21 else mem_write(a, b);
24 static int readw(int a)
26 if ((a+1) & 0xfff)
28 byte *p = mbc.rmap[a>>12];
29 if (p)
31 #ifdef IS_LITTLE_ENDIAN
32 #ifndef ALLOW_UNALIGNED_IO
33 if (a&1) return p[a] | (p[a+1]<<8);
34 #endif
35 return *(word *)(p+a);
36 #else
37 return p[a] | (p[a+1]<<8);
38 #endif
41 return mem_read(a) | (mem_read(a+1)<<8);
44 static void writew(int a, int w)
46 if ((a+1) & 0xfff)
48 byte *p = mbc.wmap[a>>12];
49 if (p)
51 #ifdef IS_LITTLE_ENDIAN
52 #ifndef ALLOW_UNALIGNED_IO
53 if (a&1)
55 p[a] = w;
56 p[a+1] = w >> 8;
57 return;
59 #endif
60 *(word *)(p+a) = w;
61 return;
62 #else
63 p[a] = w;
64 p[a+1] = w >> 8;
65 return;
66 #endif
69 mem_write(a, w);
70 mem_write(a+1, w>>8);
73 static byte readhi(int a)
75 return readb(a | 0xff00);
78 static void writehi(int a, byte b)
80 writeb(a | 0xff00, b);
83 #if 0
84 static byte readhi(int a)
86 byte (*rd)() = hi_read[a];
87 return rd ? rd(a) : (ram.hi[a] | himask[a]);
90 static void writehi(int a, byte b)
92 byte (*wr)() = hi_write[a];
93 if (wr) wr(a, b);
94 else ram.hi[a] = b & ~himask[a];
96 #endif
99 #endif