1
0
Fork 0
forked from len0rd/rockbox

Code police and clean up for rockboy.

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@15144 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Tom Ross 2007-10-16 18:16:22 +00:00
parent 0b911fefea
commit 437c3e40ca
26 changed files with 167 additions and 309 deletions

View file

@ -18,7 +18,7 @@ endif
LINKFILE := $(OBJDIR)/link.lds LINKFILE := $(OBJDIR)/link.lds
DEPFILE = $(OBJDIR)/dep-rockboy DEPFILE = $(OBJDIR)/dep-rockboy
SRC = cpu.c emu.c events.c fastmem.c hw.c lcd.c lcdc.c loader.c main.c \ SRC = cpu.c emu.c events.c fastmem.c hw.c lcd.c lcdc.c loader.c \
mem.c menu.c rbsound.c rockboy.c rtc.c save.c sound.c sys_rockbox.c \ mem.c menu.c rbsound.c rockboy.c rtc.c save.c sound.c sys_rockbox.c \
../../../firmware/common/sscanf.c ../../../firmware/common/sscanf.c

View file

@ -23,9 +23,10 @@ struct cpu
union reg pc, sp, bc, de, hl, af; union reg pc, sp, bc, de, hl, af;
#endif #endif
int ime, ima; int ime, ima;
int speed; unsigned int speed;
int halt; unsigned int halt;
int div, tim; unsigned int div;
int tim;
int lcdc; int lcdc;
int snd; int snd;
}; };
@ -48,12 +49,7 @@ extern int blockclen;
#endif #endif
void cpu_reset(void); void cpu_reset(void);
void div_advance(int cnt) ICODE_ATTR;
void timer_advance(int cnt) ICODE_ATTR;
void lcdc_advance(int cnt) ICODE_ATTR;
void sound_advance(int cnt) ICODE_ATTR;
void cpu_timers(int cnt) ICODE_ATTR; void cpu_timers(int cnt) ICODE_ATTR;
int cpu_emulate(int cycles) ICODE_ATTR; int cpu_emulate(int cycles) ICODE_ATTR;
inline int cpu_step(int max) ICODE_ATTR;
#endif #endif

View file

@ -37,14 +37,14 @@ F = (F & (FL|FC)) | decflag_table[(r)]; }
#define DECW(r) ( (r)-- ) #define DECW(r) ( (r)-- )
#define ADD(n) { \ #define ADD(n) { \
W(acc) = (un16)A + (un16)(n); \ W(acc) = (un32)A + (un32)(n); \
F = (ZFLAG(LB(acc))) \ F = (ZFLAG(LB(acc))) \
| (FH & ((A ^ (n) ^ LB(acc)) << 1)) \ | (FH & ((A ^ (n) ^ LB(acc)) << 1)) \
| (HB(acc) << 4); \ | (HB(acc) << 4); \
A = LB(acc); } A = LB(acc); }
#define ADC(n) { \ #define ADC(n) { \
W(acc) = (un16)A + (un16)(n) + (un16)((F&FC)>>4); \ W(acc) = (un32)A + (un32)(n) + (un32)((F&FC)>>4); \
F = (ZFLAG(LB(acc))) \ F = (ZFLAG(LB(acc))) \
| (FH & ((A ^ (n) ^ LB(acc)) << 1)) \ | (FH & ((A ^ (n) ^ LB(acc)) << 1)) \
| (HB(acc) << 4); \ | (HB(acc) << 4); \
@ -70,7 +70,7 @@ F = (FH & (((SP>>8) ^ ((n)>>8) ^ HB(acc)) << 1)) \
HL = W(acc); } HL = W(acc); }
#define CP(n) { \ #define CP(n) { \
W(acc) = (un16)A - (un16)(n); \ W(acc) = (un32)A - (un32)(n); \
F = FN \ F = FN \
| (ZFLAG(LB(acc))) \ | (ZFLAG(LB(acc))) \
| (FH & ((A ^ (n) ^ LB(acc)) << 1)) \ | (FH & ((A ^ (n) ^ LB(acc)) << 1)) \
@ -79,7 +79,7 @@ F = FN \
#define SUB(n) { CP((n)); A = LB(acc); } #define SUB(n) { CP((n)); A = LB(acc); }
#define SBC(n) { \ #define SBC(n) { \
W(acc) = (un16)A - (un16)(n) - (un16)((F&FC)>>4); \ W(acc) = (un32)A - (un32)(n) - (un32)((F&FC)>>4); \
F = FN \ F = FN \
| (ZFLAG((n8)LB(acc))) \ | (ZFLAG((n8)LB(acc))) \
| (FH & ((A ^ (n) ^ LB(acc)) << 1)) \ | (FH & ((A ^ (n) ^ LB(acc)) << 1)) \
@ -273,18 +273,19 @@ void cpu_reset(void)
#endif #endif
} }
static void div_advance(int cnt) ICODE_ATTR;
void div_advance(int cnt) static void div_advance(int cnt)
{ {
cpu.div += (cnt<<1); cpu.div += (cnt<<1);
if (cpu.div >= 256) if (cpu.div >> 8)
{ {
R_DIV += (cpu.div >> 8); R_DIV += (cpu.div >> 8);
cpu.div &= 0xff; cpu.div &= 0xff;
} }
} }
void timer_advance(int cnt) static void timer_advance(int cnt) ICODE_ATTR;
static void timer_advance(int cnt)
{ {
int unit, tima; int unit, tima;
@ -293,28 +294,30 @@ void timer_advance(int cnt)
unit = ((-R_TAC) & 3) << 1; unit = ((-R_TAC) & 3) << 1;
cpu.tim += (cnt<<unit); cpu.tim += (cnt<<unit);
if (cpu.tim >= 512) if (cpu.tim >> 9)
{ {
tima = R_TIMA + (cpu.tim >> 9); tima = R_TIMA + (cpu.tim >> 9);
cpu.tim &= 0x1ff; cpu.tim &= 0x1ff;
if (tima >= 256) if (tima >> 8)
{ {
hw_interrupt(IF_TIMER, IF_TIMER); hw_interrupt(IF_TIMER, IF_TIMER);
hw_interrupt(0, IF_TIMER); hw_interrupt(0, IF_TIMER);
} }
while (tima >= 256) while (tima >> 8)
tima = tima - 256 + R_TMA; tima = tima - 256 + R_TMA;
R_TIMA = tima; R_TIMA = tima;
} }
} }
void lcdc_advance(int cnt) static void lcdc_advance(int cnt) ICODE_ATTR;
static void lcdc_advance(int cnt)
{ {
cpu.lcdc -= cnt; cpu.lcdc -= cnt;
if (cpu.lcdc <= 0) lcdc_trans(); if (cpu.lcdc <= 0) lcdc_trans();
} }
void sound_advance(int cnt) static void sound_advance(int cnt) ICODE_ATTR;
static void sound_advance(int cnt)
{ {
cpu.snd += cnt; cpu.snd += cnt;
} }
@ -328,11 +331,16 @@ void cpu_timers(int cnt)
sound_advance(cnt); sound_advance(cnt);
} }
int cpu_idle(int max) static int cpu_idle(int max)
{ {
int cnt, unit; int cnt, unit;
if (!(cpu.halt && IME)) return 0; if (!(cpu.halt && IME)) return 0;
if (R_IF & R_IE)
{
cpu.halt = 0;
return 0;
}
/* Make sure we don't miss lcdc status events! */ /* Make sure we don't miss lcdc status events! */
if ((R_IE & (IF_VBLANK | IF_STAT)) && (max > cpu.lcdc)) if ((R_IE & (IF_VBLANK | IF_STAT)) && (max > cpu.lcdc))
@ -878,7 +886,7 @@ next:
PC++; PC++;
if (R_KEY1 & 1) if (R_KEY1 & 1)
{ {
cpu.speed = cpu.speed ^ 1; cpu.speed ^= 1;
R_KEY1 = (R_KEY1 & 0x7E) | (cpu.speed << 7); R_KEY1 = (R_KEY1 & 0x7E) | (cpu.speed << 7);
break; break;
} }
@ -996,27 +1004,3 @@ next:
} }
#endif /* ASM_CPU_EMULATE */ #endif /* ASM_CPU_EMULATE */
#ifndef ASM_CPU_STEP
inline int cpu_step(int max)
{
register int cnt;
if ((cnt = cpu_idle(max))) return cnt;
return cpu_emulate(1);
}
#endif /* ASM_CPU_STEP */

View file

@ -7,6 +7,7 @@
#include "lcd-gb.h" #include "lcd-gb.h"
#include "sound.h" #include "sound.h"
#include "rtc-gb.h" #include "rtc-gb.h"
#include "pcm.h"
/* /*
* emu_reset is called to initialize the state of the emulated * emu_reset is called to initialize the state of the emulated
@ -23,7 +24,7 @@ void emu_reset(void)
sound_reset(); sound_reset();
} }
void emu_step(void) static void emu_step(void)
{ {
cpu_emulate(cpu.lcdc); cpu_emulate(cpu.lcdc);
} }

View file

@ -10,15 +10,15 @@
struct fb struct fb
{ {
fb_data *ptr; #ifdef HAVE_LCD_COLOR
struct struct
{ {
int l, r; int l, r;
} cc[3]; } cc[3];
int enabled; #else
#if !defined(HAVE_LCD_COLOR)
int mode; int mode;
#endif #endif
int enabled;
}; };

View file

@ -63,8 +63,7 @@ void hw_hdma(void)
sa = ((addr)R_HDMA1 << 8) | (R_HDMA2&0xf0); sa = ((addr)R_HDMA1 << 8) | (R_HDMA2&0xf0);
da = 0x8000 | ((int)(R_HDMA3&0x1f) << 8) | (R_HDMA4&0xf0); da = 0x8000 | ((int)(R_HDMA3&0x1f) << 8) | (R_HDMA4&0xf0);
cnt = 16; for (cnt=16; cnt>0; cnt--)
while (cnt--)
writeb(da++, readb(sa++)); writeb(da++, readb(sa++));
cpu_timers(16); cpu_timers(16);
R_HDMA1 = sa >> 8; R_HDMA1 = sa >> 8;
@ -93,12 +92,11 @@ void hw_hdma_cmd(byte c)
/* Perform GDMA */ /* Perform GDMA */
sa = ((addr)R_HDMA1 << 8) | (R_HDMA2&0xf0); sa = ((addr)R_HDMA1 << 8) | (R_HDMA2&0xf0);
da = 0x8000 | ((int)(R_HDMA3&0x1f) << 8) | (R_HDMA4&0xf0); da = 0x8000 | ((int)(R_HDMA3&0x1f) << 8) | (R_HDMA4&0xf0);
cnt = ((int)c)+1; cnt = (((int)c)+1) << 4;
/* FIXME - this should use cpu time! */ /* FIXME - this should use cpu time! */
/*cpu_timers(102 * cnt);*/ /*cpu_timers(102 * cnt);*/
cpu_timers((460>>cpu.speed)+cnt*16); /*dalias*/ cpu_timers((460>>cpu.speed)+cnt); /*dalias*/
/*cpu_timers(228 + (16*cnt));*/ /* this should be right according to no$ */ /*cpu_timers(228 + (16*cnt));*/ /* this should be right according to no$ */
cnt <<= 4;
while (cnt--) while (cnt--)
writeb(da++, readb(sa++)); writeb(da++, readb(sa++));
R_HDMA1 = sa >> 8; R_HDMA1 = sa >> 8;
@ -115,7 +113,7 @@ void hw_hdma_cmd(byte c)
* interrupt line) if a transition has been made. * interrupt line) if a transition has been made.
*/ */
void pad_refresh() void pad_refresh(void)
{ {
byte oldp1; byte oldp1;
oldp1 = R_P1; oldp1 = R_P1;
@ -139,7 +137,8 @@ void pad_refresh()
* pad. * pad.
*/ */
void pad_press(byte k) static void pad_press(byte k) ICODE_ATTR;
static void pad_press(byte k)
{ {
if (hw.pad & k) if (hw.pad & k)
return; return;
@ -147,7 +146,8 @@ void pad_press(byte k)
pad_refresh(); pad_refresh();
} }
void pad_release(byte k) static void pad_release(byte k) ICODE_ATTR;
static void pad_release(byte k)
{ {
if (!(hw.pad & k)) if (!(hw.pad & k))
return; return;
@ -160,7 +160,7 @@ void pad_set(byte k, int st)
st ? pad_press(k) : pad_release(k); st ? pad_press(k) : pad_release(k);
} }
void hw_reset() void hw_reset(void)
{ {
hw.ilines = hw.pad = 0; hw.ilines = hw.pad = 0;

View file

@ -39,8 +39,6 @@ void hw_dma(byte b) ICODE_ATTR;
void hw_hdma_cmd(byte c) ICODE_ATTR; void hw_hdma_cmd(byte c) ICODE_ATTR;
void hw_hdma(void) ICODE_ATTR; void hw_hdma(void) ICODE_ATTR;
void pad_refresh(void) ICODE_ATTR; void pad_refresh(void) ICODE_ATTR;
void pad_press(byte k) ICODE_ATTR;
void pad_release(byte k) ICODE_ATTR;
void pad_set(byte k, int st) ICODE_ATTR; void pad_set(byte k, int st) ICODE_ATTR;
void hw_reset(void); void hw_reset(void);

View file

@ -9,7 +9,7 @@ struct vissprite
{ {
byte *buf; byte *buf;
int x; int x;
byte pal, pri, pad[6]; byte pal, pri;
}; };
struct scan struct scan
@ -51,15 +51,6 @@ struct lcd
extern struct lcd lcd; extern struct lcd lcd;
extern struct scan scan; extern struct scan scan;
void updatepatpix(void) ICODE_ATTR;
void tilebuf(void) ICODE_ATTR;
void bg_scan(void) ICODE_ATTR;
void wnd_scan(void) ICODE_ATTR;
void bg_scan_pri(void) ICODE_ATTR;
void wnd_scan_pri(void) ICODE_ATTR;
void spr_enum(void) ICODE_ATTR;
void spr_scan(void) ICODE_ATTR;
void lcd_begin(void) ICODE_ATTR; void lcd_begin(void) ICODE_ATTR;
void lcd_refreshline(void) ICODE_ATTR; void lcd_refreshline(void) ICODE_ATTR;
void pal_write(int i, byte b) ICODE_ATTR; void pal_write(int i, byte b) ICODE_ATTR;

View file

@ -5,7 +5,9 @@
#include "mem.h" #include "mem.h"
#include "lcd-gb.h" #include "lcd-gb.h"
#include "fb.h" #include "fb.h"
#ifdef HAVE_LCD_COLOR
#include "palette-presets.h" #include "palette-presets.h"
#endif
#ifdef USE_ASM #ifdef USE_ASM
#include "asm.h" #include "asm.h"
#endif #endif
@ -59,7 +61,8 @@ static int dmg_pal[4][4];
fb_data *vdest; fb_data *vdest;
#ifndef ASM_UPDATEPATPIX #ifndef ASM_UPDATEPATPIX
void updatepatpix(void) static void updatepatpix(void) ICODE_ATTR;
static void updatepatpix(void)
{ {
int i, j; int i, j;
#if ((CONFIG_CPU != SH7034) && !defined(CPU_COLDFIRE)) #if ((CONFIG_CPU != SH7034) && !defined(CPU_COLDFIRE))
@ -366,7 +369,8 @@ void updatepatpix(void)
void tilebuf(void) static void tilebuf(void) ICODE_ATTR;
static void tilebuf(void)
{ {
int i, cnt; int i, cnt;
int base; int base;
@ -468,7 +472,8 @@ void tilebuf(void)
* WX = WND start (if 0, no need to do anything) -> WY * WX = WND start (if 0, no need to do anything) -> WY
* U = start...something...thingy... 7 at most * U = start...something...thingy... 7 at most
*/ */
void bg_scan(void) static void bg_scan(void) ICODE_ATTR;
static void bg_scan(void)
{ {
int cnt; int cnt;
byte *src, *dest; byte *src, *dest;
@ -508,7 +513,8 @@ void bg_scan(void)
*(dest++) = *(src++); *(dest++) = *(src++);
} }
void wnd_scan(void) static void wnd_scan(void) ICODE_ATTR;
static void wnd_scan(void)
{ {
int cnt; int cnt;
byte *src, *dest; byte *src, *dest;
@ -554,7 +560,8 @@ static int priused(void *attr)
return (int)((a[0]|a[1]|a[2]|a[3]|a[4]|a[5]|a[6]|a[7])&0x80808080); return (int)((a[0]|a[1]|a[2]|a[3]|a[4]|a[5]|a[6]|a[7])&0x80808080);
} }
void bg_scan_pri(void) static void bg_scan_pri(void) ICODE_ATTR;
static void bg_scan_pri(void)
{ {
int cnt, i; int cnt, i;
byte *src, *dest; byte *src, *dest;
@ -584,7 +591,8 @@ void bg_scan_pri(void)
memset(dest, src[i&31]&128, cnt); memset(dest, src[i&31]&128, cnt);
} }
void wnd_scan_pri(void) static void wnd_scan_pri(void) ICODE_ATTR;
static void wnd_scan_pri(void)
{ {
int cnt, i; int cnt, i;
byte *src, *dest; byte *src, *dest;
@ -610,7 +618,7 @@ void wnd_scan_pri(void)
memset(dest, src[i]&128, cnt); memset(dest, src[i]&128, cnt);
} }
void bg_scan_color(void) static void bg_scan_color(void)
{ {
int cnt; int cnt;
byte *src, *dest; byte *src, *dest;
@ -684,7 +692,7 @@ void bg_scan_color(void)
blendcpy(dest, src, *(tile++), cnt); blendcpy(dest, src, *(tile++), cnt);
} }
void wnd_scan_color(void) static void wnd_scan_color(void)
{ {
int cnt; int cnt;
byte *src, *dest; byte *src, *dest;
@ -706,12 +714,8 @@ void wnd_scan_color(void)
blendcpy(dest, src, *(tile++), cnt); blendcpy(dest, src, *(tile++), cnt);
} }
static void recolor(byte *buf, byte fill, int cnt) static void spr_enum(void) ICODE_ATTR;
{ static void spr_enum(void)
while (cnt--) *(buf++) |= fill;
}
void spr_enum(void)
{ {
int i, j; int i, j;
struct obj *o; struct obj *o;
@ -764,14 +768,15 @@ void spr_enum(void)
if (VS[i].x > VS[j].x) if (VS[i].x > VS[j].x)
{ {
ts = VS[i]; ts = VS[i];
VS[i] = VS[j]; VS[i] = VS[j];
VS[j] = ts; VS[j] = ts;
} }
} }
} }
} }
void spr_scan(void) static void spr_scan(void) ICODE_ATTR;
static void spr_scan(void)
{ {
int i, x; int i, x;
byte pal, b, ns = NS; byte pal, b, ns = NS;
@ -874,26 +879,27 @@ void lcd_begin(void)
#define S3R ((LCD_HEIGHT-((160*DXR)>>16))/2)*LCD_WIDTH+LCD_WIDTH-1 #define S3R ((LCD_HEIGHT-((160*DXR)>>16))/2)*LCD_WIDTH+LCD_WIDTH-1
#endif #endif
set_pal(); vdest=rb->lcd_framebuffer;
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
set_pal();
if(options.rotate) if(options.rotate)
{ {
if(options.fullscreen == 0) if(options.scaling == 0)
vdest=fb.ptr+S2R; vdest+=+S2R;
else if (options.fullscreen == 1) else if (options.scaling == 1)
vdest=fb.ptr+S3R; vdest+=S3R;
else else
vdest=fb.ptr+S1R; vdest+=S1R;
} }
else else
{ {
if(options.fullscreen == 0) if(options.scaling == 0)
vdest=fb.ptr+S2; vdest+=S2;
else if (options.fullscreen == 1) else if (options.scaling == 1)
vdest=fb.ptr+S3; vdest+=S3;
else else
vdest=fb.ptr+S1; vdest+=S1;
} }
#endif #endif
WY = R_WY; WY = R_WY;
@ -911,7 +917,7 @@ int sremain IDATA_ATTR=LCD_WIDTH-160;
void setvidmode(void) void setvidmode(void)
{ {
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
switch(options.fullscreen) switch(options.scaling)
{ {
case 0: case 0:
if(options.rotate) if(options.rotate)
@ -1036,7 +1042,6 @@ void lcd_refreshline(void)
bg_scan(); bg_scan();
wnd_scan(); wnd_scan();
recolor(BUF+WX, 0x04, 160-WX);
} }
spr_scan(); spr_scan();
@ -1097,13 +1102,13 @@ void lcd_refreshline(void)
#endif #endif
} }
#ifdef HAVE_LCD_COLOR
void set_pal(void) void set_pal(void)
{ {
memcpy(dmg_pal,palettes[options.pal], sizeof dmg_pal); memcpy(dmg_pal,palettes[options.pal], sizeof(dmg_pal));
pal_dirty(); pal_dirty();
} }
#ifdef HAVE_LCD_COLOR
static void updatepalette(int i) static void updatepalette(int i)
{ {
int c, r, g, b; int c, r, g, b;
@ -1127,13 +1132,13 @@ static void updatepalette(int i)
#endif #endif
PAL[i] = c; PAL[i] = c;
} }
#endif #endif /* HAVE_LCD_COLOR */
void pal_write(int i, byte b) void pal_write(int i, byte b)
{ {
if (lcd.pal[i] == b) return; if (lcd.pal[i] == b) return;
lcd.pal[i] = b; lcd.pal[i] = b;
#if LCD_DEPTH ==16 #ifdef HAVE_LCD_COLOR
updatepalette(i>>1); updatepalette(i>>1);
#endif #endif
} }
@ -1175,7 +1180,7 @@ void vram_dirty(void)
void pal_dirty(void) void pal_dirty(void)
{ {
#if LCD_DEPTH ==16 #ifdef HAVE_LCD_COLOR
int i; int i;
#endif #endif
if (!hw.cgb) if (!hw.cgb)
@ -1186,7 +1191,7 @@ void pal_dirty(void)
pal_write_dmg(64, 2, R_OBP0); pal_write_dmg(64, 2, R_OBP0);
pal_write_dmg(72, 3, R_OBP1); pal_write_dmg(72, 3, R_OBP1);
} }
#if LCD_DEPTH ==16 #ifdef HAVE_LCD_COLOR
for (i = 0; i < 64; i++) for (i = 0; i < 64; i++)
updatepalette(i); updatepalette(i);
#endif #endif
@ -1198,19 +1203,3 @@ void lcd_reset(void)
lcd_begin(); lcd_begin();
vram_dirty(); vram_dirty();
} }

View file

@ -47,9 +47,8 @@ void stat_trigger(void)
* update the STAT interrupt line. * update the STAT interrupt line.
*/ */
static void stat_change(int stat) static void stat_change(unsigned int stat)
{ {
stat &= 3;
R_STAT = (R_STAT & 0x7C) | stat; R_STAT = (R_STAT & 0x7C) | stat;
if (stat != 1) hw_interrupt(0, IF_VBLANK); if (stat != 1) hw_interrupt(0, IF_VBLANK);

View file

@ -26,7 +26,7 @@
* 11 - ROM+MBC3 * 11 - ROM+MBC3
*/ */
static int mbc_table[256] = static const int mbc_table[256] =
{ {
MBC_NONE, MBC_NONE,
MBC_MBC1, MBC_MBC1,
@ -81,7 +81,7 @@ static int mbc_table[256] =
MBC_HUC1 MBC_HUC1
}; };
static unsigned short romsize_table[56] = static const unsigned short romsize_table[56] =
{ {
2, 4, 8, 16, 32, 64, 128, 256, 2, 4, 8, 16, 32, 64, 128, 256,
512, 0, 0, 0, 0, 0, 0, 0, 512, 0, 0, 0, 0, 0, 0, 0,
@ -94,7 +94,7 @@ static unsigned short romsize_table[56] =
}; };
/* Ram size should be no larger then 16 banks 1Mbit */ /* Ram size should be no larger then 16 banks 1Mbit */
static unsigned char ramsize_table[5] = static const unsigned char ramsize_table[5] =
{ {
0, 1, 1, 4, 16 0, 1, 1, 4, 16
}; };
@ -104,8 +104,6 @@ static char sramfile[500];
static char rtcfile[500]; static char rtcfile[500];
static char saveprefix[500]; static char saveprefix[500];
static int saveslot;
static int forcebatt, nobatt; static int forcebatt, nobatt;
static int forcedmg; static int forcedmg;
@ -142,7 +140,7 @@ static byte *loadfile(int fd, int *len)
return d; return d;
} }
int rom_load(void) static int rom_load(void)
{ {
int fd; int fd;
byte c, *data, *header; byte c, *data, *header;
@ -220,7 +218,7 @@ int rom_load(void)
return 0; return 0;
} }
int sram_load(void) static int sram_load(void)
{ {
int fd; int fd;
char meow[500]; char meow[500];
@ -243,7 +241,7 @@ int sram_load(void)
} }
int sram_save(void) static int sram_save(void)
{ {
int fd; int fd;
char meow[500]; char meow[500];
@ -261,45 +259,7 @@ int sram_save(void)
return 0; return 0;
} }
static void rtc_save(void)
void state_save(int n)
{
int fd;
char name[500];
if (n < 0) n = saveslot;
if (n < 0) n = 0;
snprintf(name, 499,"%s.%03d", saveprefix, n);
if ((fd = open(name, O_WRONLY|O_CREAT|O_TRUNC)>=0))
{
savestate(fd);
close(fd);
}
}
void state_load(int n)
{
int fd;
char name[500];
if (n < 0) n = saveslot;
if (n < 0) n = 0;
snprintf(name, 499, "%s.%03d", saveprefix, n);
if ((fd = open(name, O_RDONLY)>=0))
{
loadstate(fd);
close(fd);
vram_dirty();
pal_dirty();
sound_dirty();
mem_updatemap();
}
}
void rtc_save(void)
{ {
int fd; int fd;
if (!rtc.batt) return; if (!rtc.batt) return;
@ -308,7 +268,7 @@ void rtc_save(void)
close(fd); close(fd);
} }
void rtc_load(void) static void rtc_load(void)
{ {
int fd; int fd;
if (!rtc.batt) return; if (!rtc.batt) return;
@ -317,21 +277,6 @@ void rtc_load(void)
close(fd); close(fd);
} }
void loader_unload(void)
{
sram_save();
/* if (romfile) free(romfile);
if (sramfile) free(sramfile);
if (saveprefix) free(saveprefix);
if (rom.bank) free(rom.bank);
if (ram.sbank) free(ram.sbank); */
romfile = 0;
rom.bank = 0;
ram.sbank = 0;
mbc.type = mbc.romsize = mbc.ramsize = mbc.batt = 0;
}
void cleanup(void) void cleanup(void)
{ {
sram_save(); sram_save();

View file

@ -3,23 +3,6 @@
#ifndef __LOADER_H__ #ifndef __LOADER_H__
#define __LOADER_H__ #define __LOADER_H__
typedef struct loader_s
{
char *rom;
char *base;
char *sram;
char *state;
int ramloaded;
} loader_t;
extern loader_t loader;
int rom_load(void);
int sram_load(void);
int sram_save(void);
void loader_init(char *s); void loader_init(char *s);
void cleanup(void); void cleanup(void);

View file

@ -1,41 +0,0 @@
#include "rockmacros.h"
#include "input.h"
#include "emu.h"
#include "loader.h"
#include "hw.h"
void doevents()
{
event_t ev;
int st;
ev_poll();
while (ev_getevent(&ev))
{
if (ev.type != EV_PRESS && ev.type != EV_RELEASE)
continue;
st = (ev.type != EV_RELEASE);
pad_set(ev.code, st);
}
}
int gnuboy_main(char *rom)
{
rb->lcd_puts(0,0,"Init video");
vid_init();
rb->lcd_puts(0,1,"Init sound");
pcm_init();
rb->lcd_puts(0,2,"Loading rom");
loader_init(rom);
if(shut)
return PLUGIN_ERROR;
rb->lcd_puts(0,3,"Emu reset");
emu_reset();
rb->lcd_puts(0,4,"Emu run");
rb->lcd_clear_display();
rb->lcd_update();
emu_run();
/* never reached */
return PLUGIN_OK;
}

View file

@ -28,7 +28,7 @@ struct ram ram;
* make the old maps potentially invalid. * make the old maps potentially invalid.
*/ */
void mem_updatemap() void mem_updatemap(void)
{ {
int n; int n;
static byte **map; static byte **map;
@ -93,7 +93,8 @@ void mem_updatemap()
* byte value to be written. * byte value to be written.
*/ */
void ioreg_write(byte r, byte b) static void ioreg_write(byte r, byte b) ICODE_ATTR;
static void ioreg_write(byte r, byte b)
{ {
if (!hw.cgb) if (!hw.cgb)
{ {
@ -225,7 +226,7 @@ void ioreg_write(byte r, byte b)
} }
byte ioreg_read(byte r) static byte ioreg_read(byte r)
{ {
switch(r) switch(r)
{ {
@ -282,7 +283,8 @@ byte ioreg_read(byte r)
* and a byte value written to the address. * and a byte value written to the address.
*/ */
void mbc_write(int a, byte b) static void mbc_write(int a, byte b) ICODE_ATTR;
static void mbc_write(int a, byte b)
{ {
byte ha = (a>>12); byte ha = (a>>12);

View file

@ -46,8 +46,6 @@ extern struct rom rom;
extern struct ram ram; extern struct ram ram;
void mem_updatemap(void) ICODE_ATTR; void mem_updatemap(void) ICODE_ATTR;
void ioreg_write(byte r, byte b) ICODE_ATTR;
void mbc_write(int a, byte b) ICODE_ATTR;
void mem_write(int a, byte b) ICODE_ATTR; void mem_write(int a, byte b) ICODE_ATTR;
byte mem_read(int a) ICODE_ATTR; byte mem_read(int a) ICODE_ATTR;
void mbc_reset(void); void mbc_reset(void);

View file

@ -7,16 +7,17 @@
#include "button.h" #include "button.h"
#include "rockmacros.h" #include "rockmacros.h"
#include "mem.h" #include "mem.h"
#include "save.h"
#include "lib/oldmenuapi.h" #include "lib/oldmenuapi.h"
#include "rtc-gb.h" #include "rtc-gb.h"
#if (CONFIG_KEYPAD == IPOD_4G_PAD) #if CONFIG_KEYPAD == IPOD_4G_PAD
#define MENU_BUTTON_UP BUTTON_SCROLL_BACK #define MENU_BUTTON_UP BUTTON_SCROLL_BACK
#define MENU_BUTTON_DOWN BUTTON_SCROLL_FWD #define MENU_BUTTON_DOWN BUTTON_SCROLL_FWD
#define MENU_BUTTON_LEFT BUTTON_LEFT #define MENU_BUTTON_LEFT BUTTON_LEFT
#define MENU_BUTTON_RIGHT BUTTON_RIGHT #define MENU_BUTTON_RIGHT BUTTON_RIGHT
#elif (CONFIG_KEYPAD == IRIVER_H10_PAD) #elif CONFIG_KEYPAD == IRIVER_H10_PAD
#define MENU_BUTTON_UP BUTTON_SCROLL_UP #define MENU_BUTTON_UP BUTTON_SCROLL_UP
#define MENU_BUTTON_DOWN BUTTON_SCROLL_DOWN #define MENU_BUTTON_DOWN BUTTON_SCROLL_DOWN
#define MENU_BUTTON_LEFT BUTTON_LEFT #define MENU_BUTTON_LEFT BUTTON_LEFT
@ -37,7 +38,7 @@ static void munge_name(char *buf, size_t bufsiz);
/* directory ROM save slots belong in */ /* directory ROM save slots belong in */
#define STATE_DIR ROCKBOX_DIR "/rockboy" #define STATE_DIR ROCKBOX_DIR "/rockboy"
int getbutton(char *text) static int getbutton(char *text)
{ {
int fw, fh; int fw, fh;
rb->lcd_clear_display(); rb->lcd_clear_display();
@ -59,7 +60,7 @@ int getbutton(char *text)
} }
} }
void setupkeys(void) static void setupkeys(void)
{ {
options.UP=getbutton ("Press Up"); options.UP=getbutton ("Press Up");
options.DOWN=getbutton ("Press Down"); options.DOWN=getbutton ("Press Down");
@ -348,7 +349,7 @@ static void do_opt_menu(void)
}; };
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
static const struct opt_items fullscreen[]= { static const struct opt_items scaling[]= {
{ "Scaled", -1 }, { "Scaled", -1 },
{ "Scaled - Maintain Ratio", -1 }, { "Scaled - Maintain Ratio", -1 },
#if (LCD_WIDTH>=160) && (LCD_HEIGHT>=144) #if (LCD_WIDTH>=160) && (LCD_HEIGHT>=144)
@ -417,8 +418,8 @@ static void do_opt_menu(void)
break; break;
#ifdef HAVE_LCD_COLOR #ifdef HAVE_LCD_COLOR
case 4: /* Screen Size */ case 4: /* Screen Size */
rb->set_option(items[4].desc, &options.fullscreen, INT, fullscreen, rb->set_option(items[4].desc, &options.scaling, INT, scaling,
sizeof(fullscreen)/sizeof(*fullscreen), NULL ); sizeof(scaling)/sizeof(*scaling), NULL );
setvidmode(); setvidmode();
break; break;
case 5: /* Screen rotate */ case 5: /* Screen rotate */

View file

@ -5,7 +5,7 @@
* Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < < * Jukebox | | ( <_> ) \___| < | \_\ ( <_> > < <
* Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \ * Firmware |____|_ /\____/ \___ >__|_ \|___ /\____/__/\_ \
* \/ \/ \/ \/ \/ * \/ \/ \/ \/ \/
* $Id: palette-presets.h $ * $Id$
* *
* All files in this archive are subject to the GNU General Public License. * All files in this archive are subject to the GNU General Public License.
* See the file COPYING in the source tree root for full license agreement. * See the file COPYING in the source tree root for full license agreement.

View file

@ -15,6 +15,9 @@ struct pcm
extern struct pcm pcm; extern struct pcm pcm;
void pcm_init(void);
int pcm_submit(void);
void pcm_close(void);
#endif #endif

View file

@ -16,7 +16,7 @@ static unsigned short *buf=0, *hwbuf=0;
static bool newly_started; static bool newly_started;
void get_more(unsigned char** start, size_t* size) static void get_more(unsigned char** start, size_t* size)
{ {
memcpy(hwbuf, &buf[pcm.len*doneplay], BUF_SIZE*sizeof(short)); memcpy(hwbuf, &buf[pcm.len*doneplay], BUF_SIZE*sizeof(short));
*start = (unsigned char*)(hwbuf); *start = (unsigned char*)(hwbuf);

View file

@ -19,6 +19,10 @@
#include "plugin.h" #include "plugin.h"
#include "loader.h" #include "loader.h"
#include "rockmacros.h" #include "rockmacros.h"
#include "input.h"
#include "emu.h"
#include "hw.h"
#include "pcm.h"
PLUGIN_HEADER PLUGIN_HEADER
PLUGIN_IRAM_DECLARE PLUGIN_IRAM_DECLARE
@ -29,8 +33,6 @@ PLUGIN_IRAM_DECLARE
struct plugin_api* rb; struct plugin_api* rb;
int shut,cleanshut; int shut,cleanshut;
char *errormsg; char *errormsg;
int gnuboy_main(char *rom);
void pcm_close(void);
#define optionname "options" #define optionname "options"
@ -65,7 +67,7 @@ void* memcpy(void* dst, const void* src, size_t size)
return rb->memcpy(dst, src, size); return rb->memcpy(dst, src, size);
} }
void setoptions (void) static void setoptions (void)
{ {
int fd; int fd;
DIR* dir; DIR* dir;
@ -85,7 +87,7 @@ void setoptions (void)
options.LEFT=BUTTON_LEFT; options.LEFT=BUTTON_LEFT;
options.RIGHT=BUTTON_RIGHT; options.RIGHT=BUTTON_RIGHT;
#if (CONFIG_KEYPAD == IRIVER_H100_PAD) #if CONFIG_KEYPAD == IRIVER_H100_PAD
options.UP=BUTTON_UP; options.UP=BUTTON_UP;
options.DOWN=BUTTON_DOWN; options.DOWN=BUTTON_DOWN;
@ -95,7 +97,7 @@ void setoptions (void)
options.SELECT=BUTTON_SELECT; options.SELECT=BUTTON_SELECT;
options.MENU=BUTTON_MODE; options.MENU=BUTTON_MODE;
#elif (CONFIG_KEYPAD == IRIVER_H300_PAD) #elif CONFIG_KEYPAD == IRIVER_H300_PAD
options.UP=BUTTON_UP; options.UP=BUTTON_UP;
options.DOWN=BUTTON_DOWN; options.DOWN=BUTTON_DOWN;
@ -190,9 +192,9 @@ void setoptions (void)
options.fps=0; options.fps=0;
options.showstats=0; options.showstats=0;
#if (LCD_WIDTH>=160) && (LCD_HEIGHT>=144) #if (LCD_WIDTH>=160) && (LCD_HEIGHT>=144)
options.fullscreen=0; options.scaling=0;
#else #else
options.fullscreen=1; options.scaling=1;
#endif #endif
options.sound=1; options.sound=1;
options.pal=0; options.pal=0;
@ -203,7 +205,7 @@ void setoptions (void)
close(fd); close(fd);
} }
void savesettings(void) static void savesettings(void)
{ {
int fd; int fd;
char optionsave[sizeof(savedir)+sizeof(optionname)]; char optionsave[sizeof(savedir)+sizeof(optionname)];
@ -218,6 +220,42 @@ void savesettings(void)
} }
} }
void doevents(void)
{
event_t ev;
int st;
ev_poll();
while (ev_getevent(&ev))
{
if (ev.type != EV_PRESS && ev.type != EV_RELEASE)
continue;
st = (ev.type != EV_RELEASE);
pad_set(ev.code, st);
}
}
static int gnuboy_main(char *rom)
{
rb->lcd_puts(0,0,"Init video");
vid_init();
rb->lcd_puts(0,1,"Init sound");
pcm_init();
rb->lcd_puts(0,2,"Loading rom");
loader_init(rom);
if(shut)
return PLUGIN_ERROR;
rb->lcd_puts(0,3,"Emu reset");
emu_reset();
rb->lcd_puts(0,4,"Emu run");
rb->lcd_clear_display();
rb->lcd_update();
emu_run();
/* never reached */
return PLUGIN_OK;
}
/* this is the plugin entry point */ /* this is the plugin entry point */
enum plugin_status plugin_start(struct plugin_api* api, void* parameter) enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
{ {

View file

@ -31,18 +31,13 @@ extern int shut,cleanshut;
void vid_init(void); void vid_init(void);
inline void vid_begin(void); inline void vid_begin(void);
void die(char *message, ...); void die(char *message, ...);
void *sys_timer(void);
int sys_elapsed(long *oldtick);
int pcm_submit(void);
void pcm_init(void);
void doevents(void) ICODE_ATTR; void doevents(void) ICODE_ATTR;
void ev_poll(void); void ev_poll(void);
int do_user_menu(void); int do_user_menu(void);
void loadstate(int fd);
void savestate(int fd);
void setvidmode(void); void setvidmode(void);
#if defined(HAVE_LCD_COLOR)
void set_pal(void); void set_pal(void);
#if !defined(HAVE_LCD_COLOR) #else
void vid_update(int scanline); void vid_update(int scanline);
#endif #endif
#ifdef DYNAREC #ifdef DYNAREC
@ -106,7 +101,7 @@ struct options {
int A, B, START, SELECT, MENU; int A, B, START, SELECT, MENU;
int UP, DOWN, LEFT, RIGHT; int UP, DOWN, LEFT, RIGHT;
int frameskip, fps, maxskip; int frameskip, fps, maxskip;
int sound, fullscreen, showstats; int sound, scaling, showstats;
int rotate; int rotate;
int pal; int pal;
int dirty; int dirty;

View file

@ -58,7 +58,7 @@ void rtc_write(byte b)
} }
} }
void rtc_tick() void rtc_tick(void)
{ {
if (rtc.stop) return; if (rtc.stop) return;
if (++rtc.t == 60) if (++rtc.t == 60)

View file

@ -274,22 +274,3 @@ void savestate(int fd)
lseek(fd, base_offset + (sramblock << 12), SEEK_SET); lseek(fd, base_offset + (sramblock << 12), SEEK_SET);
write(fd,ram.sbank, 4096*srl); write(fd,ram.sbank, 4096*srl);
} }

View file

@ -1,4 +1,2 @@
void loadstate(int fd); void loadstate(int fd);
void savestate(int fd); void savestate(int fd);
void state_save(int n);
void state_load(int n);

View file

@ -302,7 +302,7 @@ static void gbSoundChannel3(int *r, int *l)
} }
} }
void gbSoundChannel4(int *r, int *l) static void gbSoundChannel4(int *r, int *l)
{ {
int vol = S4.envol; int vol = S4.envol;
@ -669,7 +669,7 @@ void sound_write(byte r, byte b)
snd.gbDigitalSound = false; snd.gbDigitalSound = false;
} }
void sound_reset() void sound_reset(void)
{ {
snd.level1 = 7; snd.level1 = 7;
snd.level2 = 7; snd.level2 = 7;
@ -737,7 +737,7 @@ void sound_reset()
else snd.rate = 0; else snd.rate = 0;
} }
void sound_dirty() void sound_dirty(void)
{ {
sound_write(RI_NR10, R_NR10); sound_write(RI_NR10, R_NR10);
sound_write(RI_NR11, R_NR11); sound_write(RI_NR11, R_NR11);

View file

@ -24,12 +24,10 @@
#include "hw.h" #include "hw.h"
#include "config.h" #include "config.h"
#if (CONFIG_KEYPAD == SANSA_E200_PAD) #if CONFIG_KEYPAD == SANSA_E200_PAD
#define ROCKBOY_SCROLLWHEEL #define ROCKBOY_SCROLLWHEEL
#define ROCKBOY_SCROLLWHEEL_CC BUTTON_SCROLL_UP #define ROCKBOY_SCROLLWHEEL_CC BUTTON_SCROLL_UP
#define ROCKBOY_SCROLLWHEEL_CW BUTTON_SCROLL_DOWN #define ROCKBOY_SCROLLWHEEL_CW BUTTON_SCROLL_DOWN
#endif #endif
struct fb fb IBSS_ATTR; struct fb fb IBSS_ATTR;
@ -210,7 +208,6 @@ inline void vid_begin(void)
void vid_init(void) void vid_init(void)
{ {
fb.enabled=1; fb.enabled=1;
fb.ptr=rb->lcd_framebuffer;
#if defined(HAVE_LCD_COLOR) #if defined(HAVE_LCD_COLOR)
fb.cc[0].r = 3; /* 8-5 (wasted bits on red) */ fb.cc[0].r = 3; /* 8-5 (wasted bits on red) */