notaz.gp2x.de
/
picodrive.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
32x: drc: mmap dram+rom for direct dereference
[picodrive.git]
/
pico
/
cart.c
diff --git
a/pico/cart.c
b/pico/cart.c
index
cbd4bb6
..
8d30a93
100644
(file)
--- a/
pico/cart.c
+++ b/
pico/cart.c
@@
-13,6
+13,7
@@
#include "../unzip/unzip_stream.h"
\r
\r
\r
#include "../unzip/unzip_stream.h"
\r
\r
\r
+static int rom_alloc_size;
\r
static const char *rom_exts[] = { "bin", "gen", "smd", "iso", "sms", "gg", "sg" };
\r
\r
void (*PicoCartUnloadHook)(void);
\r
static const char *rom_exts[] = { "bin", "gen", "smd", "iso", "sms", "gg", "sg" };
\r
\r
void (*PicoCartUnloadHook)(void);
\r
@@
-21,7
+22,7
@@
void (*PicoCartMemSetup)(void);
void (*PicoCartLoadProgressCB)(int percent) = NULL;
\r
void (*PicoCDLoadProgressCB)(const char *fname, int percent) = NULL; // handled in Pico/cd/cd_file.c
\r
\r
void (*PicoCartLoadProgressCB)(int percent) = NULL;
\r
void (*PicoCDLoadProgressCB)(const char *fname, int percent) = NULL; // handled in Pico/cd/cd_file.c
\r
\r
-static void PicoCartDetect(
void
);
\r
+static void PicoCartDetect(
const char *carthw_cfg
);
\r
\r
/* cso struct */
\r
typedef struct _cso_struct
\r
\r
/* cso struct */
\r
typedef struct _cso_struct
\r
@@
-378,23
+379,21
@@
int pm_close(pm_file *fp)
return ret;
\r
}
\r
\r
return ret;
\r
}
\r
\r
-
\r
-
static void Byteswap(unsigned char *data,
int len)
\r
+// byteswap, data needs to be int aligned, src can match dst
\r
+
void Byteswap(void *dst, const void *src,
int len)
\r
{
\r
{
\r
-
int i=0
;
\r
-
\r
- i
f (len<2) return; // Too short
\r
+
const unsigned int *ps = src
;
\r
+ unsigned int *pd = dst;
\r
+ i
nt i, m;
\r
\r
\r
- do
\r
- {
\r
- unsigned short *pd=(unsigned short *)(data+i);
\r
- int value=*pd; // Get 2 bytes
\r
+ if (len < 2)
\r
+ return;
\r
\r
\r
- value=(value<<8)|(value>>8); // Byteswap it
\r
- *pd=(unsigned short)value; // Put 2b ytes
\r
- i+=2;
\r
+ m = 0x00ff00ff;
\r
+ for (i = 0; i < len / 4; i++) {
\r
+ unsigned int t = ps[i];
\r
+ pd[i] = ((t & m) << 8) | ((t & ~m) >> 8);
\r
}
\r
}
\r
- while (i+2<=len);
\r
}
\r
\r
// Interleve a 16k block and byteswap
\r
}
\r
\r
// Interleve a 16k block and byteswap
\r
@@
-427,22
+426,10
@@
static int DecodeSmd(unsigned char *data,int len)
return 0;
\r
}
\r
\r
return 0;
\r
}
\r
\r
-static unsigned char *cd_realloc(void *old, int filesize)
\r
-{
\r
- unsigned char *rom;
\r
- rom=realloc(old, sizeof(mcd_state));
\r
- if (rom) memset(rom+0x20000, 0, sizeof(mcd_state)-0x20000);
\r
- return rom;
\r
-}
\r
-
\r
static unsigned char *PicoCartAlloc(int filesize, int is_sms)
\r
{
\r
static unsigned char *PicoCartAlloc(int filesize, int is_sms)
\r
{
\r
- int alloc_size;
\r
unsigned char *rom;
\r
\r
unsigned char *rom;
\r
\r
- if (PicoAHW & PAHW_MCD)
\r
- return cd_realloc(NULL, filesize);
\r
-
\r
if (is_sms) {
\r
// make size power of 2 for easier banking handling
\r
int s = 0, tmp = filesize;
\r
if (is_sms) {
\r
// make size power of 2 for easier banking handling
\r
int s = 0, tmp = filesize;
\r
@@
-450,18
+437,24
@@
static unsigned char *PicoCartAlloc(int filesize, int is_sms)
s++;
\r
if (filesize > (1 << s))
\r
s++;
\r
s++;
\r
if (filesize > (1 << s))
\r
s++;
\r
- alloc_size = 1 << s;
\r
+
rom_
alloc_size = 1 << s;
\r
}
\r
else {
\r
}
\r
else {
\r
+ // make alloc size at least sizeof(mcd_state),
\r
+ // in case we want to switch to CD mode
\r
+ if (filesize < sizeof(mcd_state))
\r
+ filesize = sizeof(mcd_state);
\r
+
\r
// align to 512K for memhandlers
\r
// align to 512K for memhandlers
\r
- alloc_size = (filesize + 0x7ffff) & ~0x7ffff;
\r
+
rom_
alloc_size = (filesize + 0x7ffff) & ~0x7ffff;
\r
}
\r
\r
}
\r
\r
- if (alloc_size - filesize < 4)
\r
- alloc_size += 4; // padding for out-of-bound exec protection
\r
+ if (
rom_
alloc_size - filesize < 4)
\r
+
rom_
alloc_size += 4; // padding for out-of-bound exec protection
\r
\r
// Allocate space for the rom plus padding
\r
\r
// Allocate space for the rom plus padding
\r
- rom = calloc(alloc_size, 1);
\r
+ // use special address for 32x dynarec
\r
+ rom = plat_mmap(0x02000000, rom_alloc_size);
\r
return rom;
\r
}
\r
\r
return rom;
\r
}
\r
\r
@@
-515,7
+508,6
@@
int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize,int is_sms)
if (!(PicoAHW & PAHW_MCD) && size == 0x20000 && (!strncmp((char *)rom+0x124, "BOOT", 4) ||
\r
!strncmp((char *)rom+0x128, "BOOT", 4))) {
\r
PicoAHW |= PAHW_MCD;
\r
if (!(PicoAHW & PAHW_MCD) && size == 0x20000 && (!strncmp((char *)rom+0x124, "BOOT", 4) ||
\r
!strncmp((char *)rom+0x128, "BOOT", 4))) {
\r
PicoAHW |= PAHW_MCD;
\r
- rom = cd_realloc(rom, size);
\r
}
\r
\r
// Check for SMD:
\r
}
\r
\r
// Check for SMD:
\r
@@
-524,7
+516,7
@@
int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize,int is_sms)
elprintf(EL_STATUS, "SMD format detected.");
\r
DecodeSmd(rom,size); size-=0x200; // Decode and byteswap SMD
\r
}
\r
elprintf(EL_STATUS, "SMD format detected.");
\r
DecodeSmd(rom,size); size-=0x200; // Decode and byteswap SMD
\r
}
\r
- else Byteswap(rom,size); // Just byteswap
\r
+ else Byteswap(rom,
rom,
size); // Just byteswap
\r
}
\r
else
\r
{
\r
}
\r
else
\r
{
\r
@@
-543,7
+535,7
@@
int PicoCartLoad(pm_file *f,unsigned char **prom,unsigned int *psize,int is_sms)
}
\r
\r
// Insert a cartridge:
\r
}
\r
\r
// Insert a cartridge:
\r
-int PicoCartInsert(unsigned char *rom,
unsigned int romsize
)
\r
+int PicoCartInsert(unsigned char *rom,
unsigned int romsize, const char *carthw_cfg
)
\r
{
\r
// notaz: add a 68k "jump one op back" opcode to the end of ROM.
\r
// This will hang the emu, but will prevent nasty crashes.
\r
{
\r
// notaz: add a 68k "jump one op back" opcode to the end of ROM.
\r
// This will hang the emu, but will prevent nasty crashes.
\r
@@
-574,7
+566,7
@@
int PicoCartInsert(unsigned char *rom,unsigned int romsize)
carthw_chunks = NULL;
\r
\r
if (!(PicoAHW & (PAHW_MCD|PAHW_SMS)))
\r
carthw_chunks = NULL;
\r
\r
if (!(PicoAHW & (PAHW_MCD|PAHW_SMS)))
\r
- PicoCartDetect();
\r
+ PicoCartDetect(
carthw_cfg
);
\r
\r
// setup correct memory map for loaded ROM
\r
switch (PicoAHW) {
\r
\r
// setup correct memory map for loaded ROM
\r
switch (PicoAHW) {
\r
@@
-610,8
+602,8
@@
void PicoCartUnload(void)
\r
if (Pico.rom != NULL) {
\r
SekFinishIdleDet();
\r
\r
if (Pico.rom != NULL) {
\r
SekFinishIdleDet();
\r
-
free(Pico.rom
);
\r
- Pico.rom
=
NULL;
\r
+
plat_munmap(Pico.rom, rom_alloc_size
);
\r
+ Pico.rom
=
NULL;
\r
}
\r
}
\r
\r
}
\r
}
\r
\r
@@
-621,9
+613,9
@@
static unsigned int rom_crc32(void)
elprintf(EL_STATUS, "caclulating CRC32..");
\r
\r
// have to unbyteswap for calculation..
\r
elprintf(EL_STATUS, "caclulating CRC32..");
\r
\r
// have to unbyteswap for calculation..
\r
- Byteswap(Pico.rom, Pico.romsize);
\r
+ Byteswap(Pico.rom, Pico.rom
, Pico.rom
size);
\r
crc = crc32(0, Pico.rom, Pico.romsize);
\r
crc = crc32(0, Pico.rom, Pico.romsize);
\r
- Byteswap(Pico.rom, Pico.romsize);
\r
+ Byteswap(Pico.rom, Pico.rom
, Pico.rom
size);
\r
return crc;
\r
}
\r
\r
return crc;
\r
}
\r
\r
@@
-697,16
+689,16
@@
static int is_expr(const char *expr, char **pr)
return 1;
\r
}
\r
\r
return 1;
\r
}
\r
\r
-static void parse_carthw(int *fill_sram)
\r
+static void parse_carthw(
const char *carthw_cfg,
int *fill_sram)
\r
{
\r
int line = 0, any_checks_passed = 0, skip_sect = 0;
\r
int tmp, rom_crc = 0;
\r
char buff[256], *p, *r;
\r
FILE *f;
\r
\r
{
\r
int line = 0, any_checks_passed = 0, skip_sect = 0;
\r
int tmp, rom_crc = 0;
\r
char buff[256], *p, *r;
\r
FILE *f;
\r
\r
- f = fopen(
"carthw.cfg"
, "r");
\r
+ f = fopen(
carthw_cfg
, "r");
\r
if (f == NULL) {
\r
if (f == NULL) {
\r
- elprintf(EL_STATUS, "couldn't open carthw.
txt
!");
\r
+ elprintf(EL_STATUS, "couldn't open carthw.
cfg
!");
\r
return;
\r
}
\r
\r
return;
\r
}
\r
\r
@@
-926,7
+918,7
@@
no_checks:
/*
\r
* various cart-specific things, which can't be handled by generic code
\r
*/
\r
/*
\r
* various cart-specific things, which can't be handled by generic code
\r
*/
\r
-static void PicoCartDetect(
void
)
\r
+static void PicoCartDetect(
const char *carthw_cfg
)
\r
{
\r
int fill_sram = 0;
\r
\r
{
\r
int fill_sram = 0;
\r
\r
@@
-956,7
+948,8
@@
static void PicoCartDetect(void)
SRam.eeprom_bit_in = 0;
\r
SRam.eeprom_bit_out= 0;
\r
\r
SRam.eeprom_bit_in = 0;
\r
SRam.eeprom_bit_out= 0;
\r
\r
- parse_carthw(&fill_sram);
\r
+ if (carthw_cfg != NULL)
\r
+ parse_carthw(carthw_cfg, &fill_sram);
\r
\r
if (SRam.flags & SRF_ENABLED)
\r
{
\r
\r
if (SRam.flags & SRF_ENABLED)
\r
{
\r