2005-03-02 23:49:38 +00:00
|
|
|
|
|
|
|
|
|
|
|
#include "rockmacros.h"
|
|
|
|
#include "fastmem.h"
|
|
|
|
|
|
|
|
byte readb(int a)
|
|
|
|
{
|
2007-02-06 21:41:08 +00:00
|
|
|
byte *p = mbc.rmap[a>>12];
|
|
|
|
if (p) return p[a];
|
|
|
|
else return mem_read(a);
|
2005-03-02 23:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void writeb(int a, byte b)
|
|
|
|
{
|
2007-02-06 21:41:08 +00:00
|
|
|
byte *p = mbc.wmap[a>>12];
|
|
|
|
if (p) p[a] = b;
|
|
|
|
else mem_write(a, b);
|
2005-03-02 23:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
int readw(int a)
|
|
|
|
{
|
2007-02-06 21:41:08 +00:00
|
|
|
if ((a+1) & 0xfff)
|
|
|
|
{
|
|
|
|
byte *p = mbc.rmap[a>>12];
|
|
|
|
if (p)
|
|
|
|
{
|
2005-05-07 22:41:17 +00:00
|
|
|
#ifdef ROCKBOX_LITTLE_ENDIAN
|
2005-03-02 23:49:38 +00:00
|
|
|
#ifndef ALLOW_UNALIGNED_IO
|
2007-02-06 21:41:08 +00:00
|
|
|
if (a&1) return p[a] | (p[a+1]<<8);
|
2005-03-02 23:49:38 +00:00
|
|
|
#endif
|
2007-02-06 21:41:08 +00:00
|
|
|
return *(word *)(p+a);
|
2005-03-02 23:49:38 +00:00
|
|
|
#else
|
2007-02-06 21:41:08 +00:00
|
|
|
return p[a] | (p[a+1]<<8);
|
2005-03-02 23:49:38 +00:00
|
|
|
#endif
|
2007-02-06 21:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
return mem_read(a) | (mem_read(a+1)<<8);
|
2005-03-02 23:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void writew(int a, int w)
|
|
|
|
{
|
2007-02-06 21:41:08 +00:00
|
|
|
if ((a+1) & 0xfff)
|
|
|
|
{
|
|
|
|
byte *p = mbc.wmap[a>>12];
|
|
|
|
if (p)
|
|
|
|
{
|
2005-05-07 22:41:17 +00:00
|
|
|
#ifdef ROCKBOX_LITTLE_ENDIAN
|
2005-03-02 23:49:38 +00:00
|
|
|
#ifndef ALLOW_UNALIGNED_IO
|
2007-02-06 21:41:08 +00:00
|
|
|
if (a&1)
|
|
|
|
{
|
|
|
|
p[a] = w;
|
|
|
|
p[a+1] = w >> 8;
|
|
|
|
return;
|
|
|
|
}
|
2005-03-02 23:49:38 +00:00
|
|
|
#endif
|
2007-02-06 21:41:08 +00:00
|
|
|
*(word *)(p+a) = w;
|
|
|
|
return;
|
2005-03-02 23:49:38 +00:00
|
|
|
#else
|
2007-02-06 21:41:08 +00:00
|
|
|
p[a] = w;
|
|
|
|
p[a+1] = w >> 8;
|
|
|
|
return;
|
2005-03-02 23:49:38 +00:00
|
|
|
#endif
|
2007-02-06 21:41:08 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
mem_write(a, w);
|
|
|
|
mem_write(a+1, w>>8);
|
2005-03-02 23:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
byte readhi(int a)
|
|
|
|
{
|
2007-02-06 21:41:08 +00:00
|
|
|
return readb(a | 0xff00);
|
2005-03-02 23:49:38 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void writehi(int a, byte b)
|
|
|
|
{
|
2007-02-06 21:41:08 +00:00
|
|
|
writeb(a | 0xff00, b);
|
2005-03-02 23:49:38 +00:00
|
|
|
}
|