1
0
Fork 0
forked from len0rd/rockbox

Allow rockboy to run while music is playing with smaller roms. Works on players that do not use the IRAM macros. Only tested on the Gigabeat as I think that is the only player that will run rockboy well with music. Also simplified the sound and reduced the code size a bit.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@13199 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Karl Kurbjun 2007-04-18 07:41:31 +00:00
parent 521d6a5e1f
commit c3dcc87aa4
9 changed files with 176 additions and 176 deletions

View file

@ -1,8 +1,3 @@
#include <stdio.h>
#include <string.h>
#include "rockmacros.h"
#include "defs.h"
#include "regs.h"
@ -13,11 +8,58 @@
#include "save.h"
#include "sound.h"
/* From http://www.semis.demon.co.uk/Gameboy/Gbspec.txt (4/17/2007)
* Cartridge type:
* 0 - ROM ONLY 12 - ROM+MBC3+RAM
* 1 - ROM+MBC1 13 - ROM+MBC3+RAM+BATT
* 2 - ROM+MBC1+RAM 19 - ROM+MBC5
* 3 - ROM+MBC1+RAM+BATT 1A - ROM+MBC5+RAM
* 5 - ROM+MBC2 1B - ROM+MBC5+RAM+BATT
* 6 - ROM+MBC2+BATTERY 1C - ROM+MBC5+RUMBLE
* 8 - ROM+RAM 1D - ROM+MBC5+RUMBLE+SRAM
* 9 - ROM+RAM+BATTERY 1E - ROM+MBC5+RUMBLE+SRAM+BATT
* B - ROM+MMM01 1F - Pocket Camera
* C - ROM+MMM01+SRAM FD - Bandai TAMA5
* D - ROM+MMM01+SRAM+BATT FE - Hudson HuC-3
* F - ROM+MBC3+TIMER+BATT FF - Hudson HuC-1
* 10 - ROM+MBC3+TIMER+RAM+BATT
* 11 - ROM+MBC3
*/
static int mbc_table[256] =
{
0, 1, 1, 1, 0, 2, 2, 0, 0, 0, 0, 0, 0, 0, 0, 3,
3, 3, 3, 3, 0, 0, 0, 0, 0, 5, 5, 5, MBC_RUMBLE, MBC_RUMBLE, MBC_RUMBLE, 0,
MBC_NONE,
MBC_MBC1,
MBC_MBC1,
MBC_MBC1 | MBC_BAT,
0,
MBC_MBC2,
MBC_MBC2 | MBC_BAT,
0,
0,
MBC_BAT,
0,
0,
0,
MBC_BAT,
0,
MBC_MBC3 | MBC_BAT | MBC_RTC,
MBC_MBC3 | MBC_BAT | MBC_RTC,
MBC_MBC3,
MBC_MBC3,
MBC_MBC3 | MBC_BAT,
0,
0,
0,
0,
0,
MBC_MBC5,
MBC_MBC5,
MBC_MBC5 | MBC_BAT,
MBC_RUMBLE,
MBC_RUMBLE,
MBC_RUMBLE | MBC_BAT,
0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
@ -34,46 +76,29 @@ static int mbc_table[256] =
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, MBC_HUC3, MBC_HUC1
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
MBC_HUC3,
MBC_HUC1
};
static int rtc_table[256] =
static unsigned short romsize_table[56] =
{
0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1,
1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
0
2, 4, 8, 16, 32, 64, 128, 256,
512, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 128, 128, 128, 0
/* 0, 0, 0, 0, 72, 80, 96 -- actual values but bad to use these! */
};
static int batt_table[256] =
/* Ram size should be no larger then 16 banks 1Mbit */
static unsigned char ramsize_table[5] =
{
0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 0, 0, 1, 0, 0,
1, 0, 1, 1, 0, 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0,
0
0, 1, 1, 4, 16
};
static int romsize_table[256] =
{
2, 4, 8, 16, 32, 64, 128, 256, 512,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 0, 0, 0, 0, 0, 0,
0, 0, 128, 128, 128
/* 0, 0, 72, 80, 96 -- actual values but bad to use these! */
};
static int ramsize_table[256] =
{
1, 1, 1, 4, 16,
4 /* FIXME - what value should this be?! */
};
static char *romfile;
static char sramfile[500];
static char rtcfile[500];
@ -100,24 +125,23 @@ static void initmem(void *mem, int size)
static byte *loadfile(int fd, int *len)
{
int c, l = 0, p = 0;
byte *d, buf[512];
d=malloc(32768);
for(;;)
int c;
byte *d;
*len=lseek(fd,0,SEEK_END);
d=malloc((*len)*sizeof(char)+64);
if(d==0)
{
c = read(fd, buf, sizeof buf);
if (c <= 0) break;
l += c;
memcpy(d+p, buf, c);
p += c;
die("Not enough memory");
return 0;
}
setmallocpos(d+p+64);
*len = l;
lseek(fd,0,SEEK_SET);
c = read(fd, d, *len);
return d;
}
int rom_load(void)
{
int fd;
@ -126,13 +150,19 @@ int rom_load(void)
fd = open(romfile, O_RDONLY);
if (fd<0) {
die("cannot open rom file");
die(romfile);
if (fd<0)
{
die("cannot open rom file %s", romfile);
return 1;
}
data = loadfile(fd, &len);
close(fd);
if(data==0)
{
die("Not Enough Memory");
return 1;
}
header = data; /* no zip. = decompress(data, &len); */
memcpy(rom.name, header+0x0134, 16);
@ -141,17 +171,22 @@ int rom_load(void)
rom.name[16] = 0;
c = header[0x0147];
mbc.type = mbc_table[c];
mbc.batt = (batt_table[c] && !nobatt) || forcebatt;
rtc.batt = rtc_table[c];
mbc.romsize = romsize_table[header[0x0148]];
mbc.ramsize = ramsize_table[header[0x0149]];
mbc.type = mbc_table[c]&(MBC_MBC1|MBC_MBC2|MBC_MBC3|MBC_MBC5|MBC_RUMBLE|MBC_HUC1|MBC_HUC3);
mbc.batt = ((mbc_table[c]&MBC_BAT) && !nobatt) || forcebatt;
rtc.batt = mbc_table[c]&MBC_RTC;
if (!mbc.romsize) {
if(header[0x0148]<10 || (header[0x0148]>51 && header[0x0148]<55))
mbc.romsize = romsize_table[header[0x0148]];
else
{
die("unknown ROM size %02X\n", header[0x0148]);
return 1;
}
if (!mbc.ramsize) {
if(header[0x0149]<5)
mbc.ramsize = ramsize_table[header[0x0149]];
else
{
die("unknown SRAM size %02X\n", header[0x0149]);
return 1;
}
@ -160,7 +195,17 @@ int rom_load(void)
rom.bank = (void *) data; /* realloc(data, rlen); */
if (rlen > len) memset(rom.bank[0]+len, 0xff, rlen - len);
/* This is the size of the ram on the cartridge
* See http://www.semis.demon.co.uk/Gameboy/Gbspec.txt
* for a full description. (8192*number of banks)
*/
ram.sbank = malloc(8192 * mbc.ramsize);
if(ram.sbank==0 && mbc.ramsize!=0)
{
die("Not enough Memory");
return 1;
}
/* ram.ibank = malloc(4096*8); */
initmem(ram.sbank, 8192 * mbc.ramsize);
@ -171,8 +216,6 @@ int rom_load(void)
c = header[0x0143];
hw.cgb = ((c == 0x80) || (c == 0xc0)) && !forcedmg;
close(fd);
return 0;
}