1
0
Fork 0
forked from len0rd/rockbox

Update for Rockboy: - fix scaling for other color screens than H300 - full menu rewrite to display choices properly - some small tweaks to code - some formatting updates

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@10137 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Karl Kurbjun 2006-06-19 01:47:45 +00:00
parent db8316fa52
commit 6952f03a7d
21 changed files with 442 additions and 751 deletions

View file

@ -1,6 +1,3 @@
#include "rockmacros.h"
#include "defs.h"
#include "regs.h"
@ -382,8 +379,8 @@ int cpu_emulate(int cycles)
byte op, cbop;
int clen;
static union reg acc;
static byte b;
static word w;
static byte b IBSS_ATTR;
static word w IBSS_ATTR;
i = cycles;
next:

View file

@ -276,15 +276,3 @@ static const byte daa_carry_table[64] ICONST_ATTR =
FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC,
FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, FC, 00, FC,
};

View file

@ -1,5 +1,3 @@
#ifndef __CPUREGS_H__
#define __CPUREGS_H__

View file

@ -1,6 +1,3 @@
#ifndef __DEFS_H__
#define __DEFS_H__
@ -14,7 +11,6 @@
#define HI 0
#endif
typedef unsigned char byte;
typedef unsigned char un8;
@ -29,8 +25,4 @@ typedef un16 word;
typedef word addr;
#endif

View file

@ -1,6 +1,3 @@
#include "rockmacros.h"
#include "defs.h"
#include "regs.h"
@ -17,23 +14,15 @@ static int framecount;
rcvar_t emu_exports[] =
{
RCV_INT("framelen", &framelen),
RCV_INT("framecount", &framecount),
RCV_END
RCV_INT("framelen", &framelen),
RCV_INT("framecount", &framecount),
RCV_END
};
void emu_init(void)
{
}
/*
* emu_reset is called to initialize the state of the emulated
* system. It should set cpu registers, hardware registers, etc. to
@ -42,100 +31,79 @@ void emu_init(void)
void emu_reset(void)
{
hw_reset();
lcd_reset();
cpu_reset();
mbc_reset();
sound_reset();
hw_reset();
lcd_reset();
cpu_reset();
mbc_reset();
sound_reset();
}
void emu_step(void)
{
cpu_emulate(cpu.lcdc);
cpu_emulate(cpu.lcdc);
}
struct options options;
/* This mess needs to be moved to another module; it's just here to
* make things work in the mean time. */
//extern struct plugin_api* rb;
void emu_run(void)
{
// void *timer = sys_timer();
int framesin=0,frames=0,timeten=*rb->current_tick, timehun=*rb->current_tick;
int framesin=0,frames=0,timeten=*rb->current_tick, timehun=*rb->current_tick;
// int delay;
vid_begin();
lcd_begin();
vid_begin();
lcd_begin();
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
rb->cpu_boost(true);
rb->cpu_boost(true);
#endif
while(!shut)
{
cpu_emulate(2280);
while (R_LY > 0 && R_LY < 144)
emu_step();
while(!shut)
{
cpu_emulate(2280);
while (R_LY > 0 && R_LY < 144)
emu_step();
rtc_tick();
sound_mix();
if (!pcm_submit())
{
/* delay = framelen - sys_elapsed(timer);
sys_sleep(delay);
sys_elapsed(timer);*/
}
doevents();
vid_begin();
rtc_tick();
sound_mix();
if (!pcm_submit())
{
/* delay = framelen - sys_elapsed(timer);
sys_sleep(delay);
sys_elapsed(timer);*/
}
doevents();
vid_begin();
if (!(R_LCDC & 0x80))
cpu_emulate(32832);
if (!(R_LCDC & 0x80))
cpu_emulate(32832);
while (R_LY > 0) /* wait for next frame */
emu_step();
rb->yield();
while (R_LY > 0) /* wait for next frame */
emu_step();
rb->yield();
frames++;
framesin++;
frames++;
framesin++;
if(*rb->current_tick-timeten>=20)
{
timeten=*rb->current_tick;
if(framesin<12) options.frameskip++;
if(framesin>12) options.frameskip--;
if(options.frameskip>options.maxskip) options.frameskip=options.maxskip;
if(options.frameskip<0) options.frameskip=0;
framesin=0;
}
if(*rb->current_tick-timeten>=20)
{
timeten=*rb->current_tick;
if(framesin<12) options.frameskip++;
if(framesin>12) options.frameskip--;
if(options.frameskip>options.maxskip) options.frameskip=options.maxskip;
if(options.frameskip<0) options.frameskip=0;
framesin=0;
}
if(options.showstats)
{
if(*rb->current_tick-timehun>=100) {
options.fps=frames;
frames=0;
timehun=*rb->current_tick;
}
}
}
if(options.showstats)
if(*rb->current_tick-timehun>=100)
{
options.fps=frames;
frames=0;
timehun=*rb->current_tick;
}
}
#ifdef HAVE_ADJUSTABLE_CPU_FREQ
rb->cpu_boost(false);
#endif
}

View file

@ -51,11 +51,3 @@ int ev_getevent(event_t *ev)
}
return 1;
}

View file

@ -14,7 +14,7 @@
const byte himask[256];
const byte hi_rmap[256] ICONST_ATTR =
const byte hi_rmap[256] =
{
0, 0, R, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0,
S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,
@ -26,7 +26,7 @@ const byte hi_rmap[256] ICONST_ATTR =
C, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
};
const byte hi_wmap[256] ICONST_ATTR =
const byte hi_wmap[256] =
{
R, R, R, R, R, R, R, R, R, R, R, R, R, R, R, R,
S, S, S, S, S, S, S, S, S, S, S, S, S, S, S, S,

View file

@ -38,10 +38,10 @@ void hw_interrupt(byte i, byte mask) ICODE_ATTR;
void hw_dma(byte b) ICODE_ATTR;
void hw_hdma_cmd(byte c) ICODE_ATTR;
void hw_hdma(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_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 hw_reset(void);
#endif

View file

@ -65,7 +65,7 @@ void spr_enum(void) ICODE_ATTR;
void spr_scan(void) ICODE_ATTR;
void lcd_begin(void) ICODE_ATTR;
void lcd_refreshline(void) ICODE_ATTR;
void pal_write(int i, byte b);
void pal_write(int i, byte b) ICODE_ATTR;
void pal_write_dmg(int i, int mapnum, byte d) ICODE_ATTR;
void vram_write(int a, byte b) ICODE_ATTR;
void vram_dirty(void) ICODE_ATTR;

View file

@ -1,5 +1,3 @@
#include "rockmacros.h"
#include "defs.h"
#include "regs.h"
@ -102,9 +100,6 @@ fb_data *vdest;
#define MEMCPY8(d, s) memcpy((d), (s), 8)
#endif
#ifndef ASM_UPDATEPATPIX
void updatepatpix(void)
{
@ -901,10 +896,11 @@ void spr_scan(void)
// if (sprdebug) for (i = 0; i < NS; i++) BUF[i<<1] = 36;
}
// Scaling defines
#define DX ((LCD_WIDTH<<16) / 160)
#define DXI ((160<<16) / LCD_WIDTH)
#define DY ((LCD_HEIGHT<<16) / 144)
#define DYI ((144<<16) / LCD_HEIGHT)
void lcd_begin(void)
{
@ -913,23 +909,70 @@ void lcd_begin(void)
if (rgb332) pal_set332();
else pal_expire();
}
while (scale * 160 > fb.w || scale * 144 > fb.h) scale--; */
if(options.fullscreen)
vdest = fb.ptr;
else
vdest = fb.ptr + ((LCD_HEIGHT-144)/2)*LCD_WIDTH + ((LCD_WIDTH-160)/2);
*/
if(options.fullscreen)
vdest = fb.ptr;
else
vdest=fb.ptr+((LCD_HEIGHT-144)/2)*LCD_WIDTH + ((LCD_WIDTH-160)/2);
WY = R_WY;
}
char frameout[25];
int SCALEWL IDATA_ATTR=DY;
int SCALEWS IDATA_ATTR=DYI;
int SCALEHL IDATA_ATTR=DY;
int SCALEHS IDATA_ATTR=DYI;
int swidth IDATA_ATTR=(160*DY)>>16;
int sremain IDATA_ATTR=LCD_WIDTH-((160*DY)>>16);
void setvidmode(int mode)
{
switch(mode)
{
case 1: /* Full screen scale */
SCALEWL=DX;
SCALEWS=DXI;
SCALEHL=DY;
SCALEHS=DYI;
break;
case 2: /* Maintain Ratio */
if (DY<DX)
{
SCALEWL=DY;
SCALEWS=DYI;
SCALEHL=DY;
SCALEHS=DYI;
}
else
{
SCALEWL=DX;
SCALEWS=DXI;
SCALEHL=DX;
SCALEHS=DXI;
}
break;
default: /* No Scaling (or fullscreen for smaller screens) */
#if LCD_WIDTH>160
SCALEWL=1<<16;
SCALEWS=1<<16;
SCALEHL=1<<16;
SCALEHS=1<<16;
#else
SCALEWL=DX;
SCALEWS=DXI;
SCALEHL=DY;
SCALEHS=DYI;
#endif
}
swidth=(160*SCALEWL)>>16;
sremain=LCD_WIDTH-swidth;
}
char frameout[30];
void lcd_refreshline(void)
{
#if LCD_HEIGHT>=144
int cnt=0, two;
#endif
if (!fb.enabled) return;
if(!insync) {
if(R_LY!=0)
return;
@ -990,44 +1033,51 @@ void lcd_refreshline(void)
recolor(BUF+WX, 0x04, 160-WX);
}
spr_scan();
#if !defined(HAVE_LCD_COLOR)
#if LCD_DEPTH == 1
if (scanline_ind == 7)
#elif LCD_DEPTH == 2
if (scanline_ind == 3)
#endif
{
#if LCD_HEIGHT < 144
if(fb.mode!=3)
vid_update(L);
else
vid_update(L-((int)(L/9)));
#else
{
/* Universial Scaling pulled from PrBoom and modified for rockboy */
/* Needs some thought for screens smaller than the gameboy though */
for(two=0;two<( (options.showstats ? (L&0x07)==0x05 : (L&0x07)==0x05 || (L&0x0F)==0x08) && options.fullscreen)+1;two++)
{
while (cnt < 160)
{
*vdest++ = scan.pal2[scan.buf[cnt++]];
if( ((cnt&0x03)==0x03 || (cnt&0x07)==0x06) && options.fullscreen ) *vdest++ = scan.pal2[scan.buf[cnt]];
}
static int hpt IDATA_ATTR=0x8000;
if(!options.fullscreen)
vdest+=(LCD_WIDTH-160);
cnt=0;
}
while((hpt>>16)<L+1)
{
hpt+=SCALEHS;
register unsigned int srcpt=0x8000;
register unsigned int wcount=swidth;
register unsigned int remain=sremain;
while(wcount--)
{
*vdest++ = scan.pal2[scan.buf[srcpt>>16]];
srcpt+=SCALEWS;
}
vdest+=remain;
}
if(L==143)
{
if(options.showstats)
{
snprintf(frameout,sizeof(frameout),"FPS: %d Frameskip: %d ",options.fps, options.frameskip);
rb->lcd_putsxy(0,LCD_HEIGHT-10,frameout);
}
hpt=0x8000;
rb->lcd_update();
}
if(L==143)
{
if(options.showstats) {
snprintf(frameout,sizeof(frameout),"FPS: %d \t %d ",options.fps, options.frameskip);
if(options.fullscreen) rb->lcd_putsxy(0,166,frameout);
else rb->lcd_putsxy((LCD_WIDTH-160)/2,(LCD_HEIGHT-144)/2,frameout);
}
if(options.fullscreen)
rb->lcd_update();
else
rb->lcd_update_rect( (LCD_WIDTH-160)/2, (LCD_HEIGHT-144)/2, 160, 144 );
}
#endif
}
#if LCD_DEPTH == 1

View file

@ -1,5 +1,3 @@
#include "rockmacros.h"
#include "defs.h"
@ -7,6 +5,7 @@
#include "cpu-gb.h"
#include "regs.h"
#include "lcd-gb.h"
#include "fb.h"
#define C (cpu.lcdc)
@ -141,10 +140,11 @@ void lcdc_trans(void)
stat_trigger();
break;
case 2:
lcd_refreshline();
stat_change(3);
C += 86;
break;
if (fb.enabled)
lcd_refreshline();
stat_change(3);
C += 86;
break;
case 3:
stat_change(0);
if (hw.hdma & 0x80)

View file

@ -1,4 +1,4 @@
void stat_trigger(void) ICODE_ATTR;
void stat_write(byte b)ICODE_ATTR;
void lcdc_change(byte b)ICODE_ATTR;
void lcdc_trans(void)ICODE_ATTR;
void stat_write(byte b) ICODE_ATTR;
void lcdc_change(byte b) ICODE_ATTR;
void lcdc_trans(void) ICODE_ATTR;

View file

@ -1,4 +1,3 @@
#ifndef __MEM_H__
#define __MEM_H__
@ -48,10 +47,6 @@ extern struct mbc mbc;
extern struct rom rom;
extern struct ram ram;
void mem_updatemap(void) ICODE_ATTR;
void ioreg_write(byte r, byte b) ICODE_ATTR;
void mbc_write(int a, byte b) ICODE_ATTR;
@ -60,7 +55,6 @@ byte mem_read(int a) ICODE_ATTR;
void mbc_reset(void);
#define READB(a) ( mbc.rmap[(a)>>12] \
? mbc.rmap[(a)>>12][(a)] \
: mem_read((a)) )
@ -71,10 +65,4 @@ void mbc_reset(void);
: ( mem_write((a), (b)), (b) ) )
#define WRITEW(a, w) ( WRITEB((a), (w)&0xFF), WRITEB((a)+1, (w)>>8) )
#endif

View file

@ -4,8 +4,6 @@
/* Note: this file only exposes one function: do_user_menu(). */
/*********************************************************************/
#include "stdlib.h"
#include "string.h"
#include "button.h"
#include "rockmacros.h"
#include "mem.h"
@ -15,149 +13,68 @@
#define MENU_BUTTON_DOWN BUTTON_SCROLL_FWD
#define MENU_BUTTON_LEFT BUTTON_LEFT
#define MENU_BUTTON_RIGHT BUTTON_RIGHT
#define MENU_BUTTON_CANCEL BUTTON_MENU
#elif (CONFIG_KEYPAD == GIGABEAT_PAD)
#define MENU_BUTTON_UP BUTTON_UP
#define MENU_BUTTON_DOWN BUTTON_DOWN
#define MENU_BUTTON_LEFT BUTTON_LEFT
#define MENU_BUTTON_RIGHT BUTTON_RIGHT
#define MENU_BUTTON_CANCEL BUTTON_A
#else
#define MENU_BUTTON_UP BUTTON_UP
#define MENU_BUTTON_DOWN BUTTON_DOWN
#define MENU_BUTTON_LEFT BUTTON_LEFT
#define MENU_BUTTON_RIGHT BUTTON_RIGHT
#define MENU_BUTTON_CANCEL BUTTON_OFF
#endif
void setvidmode(int);
/* load/save state function declarations */
static void do_slot_menu(bool is_load);
static void do_opt_menu(void);
static void do_slot_menu(bool is_load);
static void munge_name(char *buf, size_t bufsiz);
/* directory ROM save slots belong in */
#define STATE_DIR "/.rockbox/rockboy"
#define MENU_CANCEL (-1)
static int do_menu(char *title, char **items, size_t num_items, int sel_item);
/* main menu items */
#define MAIN_MENU_TITLE "Rockboy"
typedef enum {
MM_ITEM_BACK,
MM_ITEM_LOAD,
MM_ITEM_SAVE,
MM_ITEM_OPT,
MM_ITEM_QUIT,
MM_ITEM_LAST
} MainMenuItem;
/* strings for the main menu */
static const char *main_menu[] = {
"Back to Game",
"Load State...",
"Save State...",
"Options...",
"Quit RockBoy"
};
typedef enum {
SM_ITEM_SLOT1,
SM_ITEM_SLOT2,
SM_ITEM_SLOT3,
SM_ITEM_SLOT4,
SM_ITEM_SLOT5,
SM_ITEM_FILE,
SM_ITEM_BACK,
SM_ITEM_LAST
} SlotMenuItem;
/* this semi-evil, but we snprintf() into these strings later
* Note: if you want more save slots, just add more lines
* to this array */
static const char *slot_menu[] = {
"1. ",
"2. ",
"3. ",
"4. ",
"5. ",
"Save to File... ",
"Previous Menu... "
};
#define OPT_MENU_TITLE "Options"
typedef enum {
OM_ITEM_FS,
OM_ITEM_SOUND,
OM_ITEM_STATS,
OM_ITEM_FULLSCREEN,
OM_ITEM_KEYS,
OM_ITEM_BACK,
OM_MENU_LAST
} OptMenuItem;
static const char *opt_menu[] = {
"Frameskip",
"Sound ON/OFF",
"Stats ON/OFF",
"Fullscreen ON/OFF",
"Set Keys (BUGGY)",
"Previous Menu..."
};
#define FS_MENU_TITLE "Frameskip"
typedef enum {
FS_ITEM_FS0,
FS_ITEM_FS1,
FS_ITEM_FS2,
FS_ITEM_FS3,
FS_ITEM_BACK,
FS_MENU_LAST
} FSMenuItem;
static const char *fs_menu[] = {
"Frameskip 3 Max",
"Frameskip 4 Max",
"Frameskip 5 Max",
"Frameskip 7 Max",
"Previous Menu..."
};
int getbutton(char *text)
{
rb->lcd_putsxy(0, 0, text);
rb->lcd_update();
rb->sleep(30);
while (rb->button_get(false) != BUTTON_NONE)
rb->yield();
int button;
while(true){
button = rb->button_get(true);
button=button&0x00000FFF;
switch(button) {
case MENU_BUTTON_LEFT:
case MENU_BUTTON_RIGHT:
case MENU_BUTTON_UP:
case MENU_BUTTON_DOWN:
break;
default:
return button;
break;
}
}
rb->lcd_putsxy(0, 0, text);
rb->lcd_update();
rb->sleep(30);
while (rb->button_get(false) != BUTTON_NONE)
rb->yield();
int button;
while(true)
{
button = rb->button_get(true);
button=button&0x00000FFF;
switch(button)
{
case MENU_BUTTON_LEFT:
case MENU_BUTTON_RIGHT:
case MENU_BUTTON_UP:
case MENU_BUTTON_DOWN:
break;
default:
return button;
break;
}
}
}
void setupkeys(void)
{
options.A=getbutton("Press A");
options.A=getbutton("Press A");
options.B=getbutton("Press B");
options.B=getbutton("Press B");
options.START=getbutton("Press Start");
options.START=getbutton("Press Start");
options.SELECT=getbutton("Press Select");
options.SELECT=getbutton("Press Select");
options.MENU=getbutton("Press Menu");
options.MENU=getbutton("Press Menu");
}
/*
@ -165,67 +82,74 @@ void setupkeys(void)
*
* Returns USER_MENU_QUIT if the user selected "quit", otherwise
* returns zero.
*
* Note: this is the only non-static function in this file at the
* moment. In the future I may turn do_menu/etc into a proper API, in
* which case they'll be exposed as well.
*
*/
int do_user_menu(void) {
int mi, ret, num_items;
bool done = false;
bool done=false;
int m, ret=0;
int result;
pcm_init();
/* Clean out the button Queue */
while (rb->button_get(false) != BUTTON_NONE)
rb->yield();
/* set defaults */
ret = 0; /* return value */
mi = 0; /* initial menu selection */
num_items = sizeof(main_menu) / sizeof(char*);
/* loop until we should exit menu */
while (!done) {
/* get item selection */
mi = do_menu(MAIN_MENU_TITLE, (char**) main_menu, num_items, mi);
/* handle selected menu item */
switch (mi) {
case MM_ITEM_QUIT:
ret = USER_MENU_QUIT;
case MENU_CANCEL:
case MM_ITEM_BACK:
done = true;
break;
case MM_ITEM_LOAD:
do_slot_menu(true);
break;
case MM_ITEM_SAVE:
do_slot_menu(false);
break;
case MM_ITEM_OPT:
do_opt_menu();
break;
static const struct menu_item items[] = {
{"Load Game", NULL },
{"Save Game", NULL },
{"Options", NULL },
{"Quit", NULL },
};
pcm_init();
m = rb->menu_init(items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL);
while(!done)
{
result=rb->menu_show(m);
switch (result)
{
case 0: /* Load Game */
do_slot_menu(true);
break;
case 1: /* Save Game */
do_slot_menu(false);
break;
case 2: /* Options */
do_opt_menu();
break;
case 3: /* Quit */
ret = USER_MENU_QUIT;
done=true;
break;
default:
done=true;
break;
}
}
}
rb->lcd_clear_display();
rb->lcd_update();
/* return somethin' */
return ret;
rb->menu_exit(m);
rb->lcd_setfont(0); /* Reset the font */
rb->lcd_clear_display(); /* Clear display for screen size changes */
return ret;
}
/*
* munge_name - munge a string into a filesystem-safe name
*/
static void munge_name(char *buf, const size_t bufsiz) {
unsigned int i, max;
unsigned int i, max;
/* check strlen */
max = strlen(buf);
max = (max < bufsiz) ? max : bufsiz;
/* check strlen */
max = strlen(buf);
max = (max < bufsiz) ? max : bufsiz;
/* iterate over characters and munge them (if necessary) */
for (i = 0; i < max; i++)
if (!isalnum(buf[i]))
buf[i] = '_';
/* iterate over characters and munge them (if necessary) */
for (i = 0; i < max; i++)
if (!isalnum(buf[i]))
buf[i] = '_';
}
/*
@ -235,15 +159,15 @@ static void munge_name(char *buf, const size_t bufsiz) {
* checksum or something like that?
*/
static void build_slot_path(char *buf, size_t bufsiz, size_t slot_id) {
char name_buf[40];
char name_buf[40];
/* munge state file name */
strncpy(name_buf, rom.name, sizeof(name_buf));
name_buf[16] = '\0';
munge_name(name_buf, strlen(name_buf));
/* munge state file name */
strncpy(name_buf, rom.name, 40);
name_buf[16] = '\0';
munge_name(name_buf, strlen(name_buf));
/* glom the whole mess together */
snprintf(buf, bufsiz, "%s/%s-%d.rbs", STATE_DIR, name_buf, slot_id + 1);
/* glom the whole mess together */
snprintf(buf, bufsiz, "%s/%s-%d.rbs", STATE_DIR, name_buf, slot_id + 1);
}
/*
@ -256,43 +180,46 @@ static void build_slot_path(char *buf, size_t bufsiz, size_t slot_id) {
*
*/
static bool do_file(char *path, char *desc, bool is_load) {
char buf[200], desc_buf[20];
int fd, file_mode;
char buf[200], desc_buf[20];
int fd, file_mode;
/* set file mode */
file_mode = is_load ? O_RDONLY : (O_WRONLY | O_CREAT);
/* set file mode */
file_mode = is_load ? O_RDONLY : (O_WRONLY | O_CREAT);
/* attempt to open file descriptor here */
if ((fd = open(path, file_mode)) <= 0)
return false;
/* attempt to open file descriptor here */
if ((fd = open(path, file_mode)) <= 0)
return false;
/* load/save state */
if (is_load) {
/* load description */
read(fd, desc_buf, 20);
/* load/save state */
if (is_load)
{
/* load description */
read(fd, desc_buf, 20);
/* load state */
loadstate(fd);
/* print out a status message so the user knows the state loaded */
snprintf(buf, 200, "Loaded state from \"%s\"", path);
rb->splash(HZ * 1, true, buf);
}
else
{
/* build description buffer */
memset(desc_buf, 0, 20);
if (desc)
strncpy(desc_buf, desc, 20);
/* load state */
loadstate(fd);
/* save state */
write(fd, desc_buf, 20);
savestate(fd);
}
/* close file descriptor */
close(fd);
/* print out a status message so the user knows the state loaded */
snprintf(buf, sizeof(buf), "Loaded state from \"%s\"", path);
rb->splash(HZ * 1, true, buf);
} else {
/* build description buffer */
memset(desc_buf, 0, sizeof(desc_buf));
if (desc)
strncpy(desc_buf, desc, sizeof(desc_buf));
/* save state */
write(fd, desc_buf, 20);
savestate(fd);
}
/* close file descriptor */
close(fd);
/* return true (for success) */
return true;
/* return true (for success) */
return true;
}
/*
@ -301,339 +228,159 @@ static bool do_file(char *path, char *desc, bool is_load) {
* Returns true on success and false on failure.
*/
static bool do_slot(size_t slot_id, bool is_load) {
char path_buf[256], desc_buf[20];
char path_buf[256], desc_buf[20];
/* build slot filename, clear desc buf */
build_slot_path(path_buf, sizeof(path_buf), slot_id);
memset(desc_buf, 0, sizeof(desc_buf));
/* build slot filename, clear desc buf */
build_slot_path(path_buf, 256, slot_id);
memset(desc_buf, 0, 20);
/* if we're saving to a slot, then get a brief description */
if (!is_load) {
if (rb->kbd_input(desc_buf, sizeof(desc_buf)) || !strlen(desc_buf)) {
memset(desc_buf, 0, sizeof(desc_buf));
strncpy(desc_buf, "Untitled", sizeof(desc_buf));
}
}
/* if we're saving to a slot, then get a brief description */
if (!is_load)
if (rb->kbd_input(desc_buf, 20) || !strlen(desc_buf))
{
memset(desc_buf, 0, 20);
strncpy(desc_buf, "Untitled", 20);
}
/* load/save file */
return do_file(path_buf, desc_buf, is_load);
/* load/save file */
return do_file(path_buf, desc_buf, is_load);
}
/*
* get information on the given slot
*/
static void slot_info(char *info_buf, size_t info_bufsiz, size_t slot_id) {
char buf[256];
int fd;
char buf[256];
int fd;
/* get slot file path */
build_slot_path(buf, sizeof(buf), slot_id);
/* get slot file path */
build_slot_path(buf, 256, slot_id);
/* attempt to open slot */
if ((fd = open(buf, O_RDONLY)) >= 0) {
/* this slot has a some data in it, read it */
if (read(fd, buf, 20) > 0) {
buf[20] = '\0';
snprintf(info_buf, info_bufsiz, "%2d. %s", slot_id + 1, buf);
} else {
snprintf(info_buf, info_bufsiz, "%2d. ERROR", slot_id + 1);
/* attempt to open slot */
if ((fd = open(buf, O_RDONLY)) >= 0)
{
/* this slot has a some data in it, read it */
if (read(fd, buf, 20) > 0)
{
buf[20] = '\0';
snprintf(info_buf, info_bufsiz, "%d. %s", slot_id + 1, buf);
}
else
snprintf(info_buf, info_bufsiz, "%d. ERROR", slot_id + 1);
close(fd);
}
else
{
/* if we couldn't open the file, then the slot is empty */
snprintf(info_buf, info_bufsiz, "%d. %s", slot_id + 1, "<Empty>");
}
close(fd);
} else {
/* if we couldn't open the file, then the slot is empty */
snprintf(info_buf, info_bufsiz, "%2d.", slot_id + 1);
}
}
/*
* do_slot_menu - prompt the user for a load/save memory slot
*/
static void do_slot_menu(bool is_load) {
int i, mi, ret, num_items;
bool done = false;
char *title, buf[256];
bool done=false;
/* set defaults */
ret = 0; /* return value */
mi = 0; /* initial menu selection */
num_items = sizeof(slot_menu) / sizeof(char*);
/* create menu items (the last two are file and previous menu,
* so don't populate those) */
for (i = 0; i < num_items - 2; i++)
slot_info((char*) slot_menu[i], 20, i);
/* set text of file item */
snprintf((char*) slot_menu[SM_ITEM_FILE], 20, "%s File...", is_load ? "Load from" : "Save to");
/* set menu title */
title = is_load ? "Load State" : "Save State";
char buf[5][20];
/* loop until we should exit menu */
while (!done) {
/* get item selection */
mi = do_menu(title, (char**) slot_menu, num_items, mi);
int m;
int result;
int i;
struct menu_item items[] = {
{ buf[0] , NULL },
{ buf[1] , NULL },
{ buf[2] , NULL },
{ buf[3] , NULL },
{ buf[4] , NULL },
};
int num_items = sizeof(items) / sizeof(*items);
/* create menu items */
for (i = 0; i < num_items; i++)
slot_info(buf[i], 20, i);
m = rb->menu_init(items, num_items, NULL, NULL, NULL, NULL);
while(!done)
{
result=rb->menu_show(m);
/* handle selected menu item */
done = true;
if (mi != MENU_CANCEL && mi != SM_ITEM_BACK) {
if (mi == SM_ITEM_FILE) {
char rom_name_buf[40];
/* munge rom name to valid filename */
strncpy(rom_name_buf, rom.name, 16);
munge_name(rom_name_buf, sizeof(rom_name_buf));
/* create default filename */
snprintf(buf, sizeof(buf), "/%s.rbs", rom_name_buf);
/* prompt for output filename, save to file */
if (!rb->kbd_input(buf, sizeof(buf)))
done = do_file(buf, NULL, is_load);
} else {
done = do_slot(mi, is_load);
}
/* if we couldn't save the state file, then print out an
* error message */
if (!is_load && !done)
rb->splash(HZ * 2, true, "Couldn't save state file.");
if (result<num_items && result >= 0 )
done = do_slot(result, is_load);
else
done = true;
}
}
rb->menu_exit(m);
}
static void do_fs_menu(void) {
int mi, ret, num_items;
bool done = false;
static void do_opt_menu(void)
{
bool done=false;
int m;
int result;
/* set defaults */
ret = 0; /* return value */
mi = 0; /* initial menu selection */
num_items = sizeof(fs_menu) / sizeof(char*);
/* loop until we should exit menu */
while (!done) {
/* get item selection */
mi = do_menu(FS_MENU_TITLE, (char**) fs_menu, num_items, mi);
static const struct opt_items onoff[2] = {
{ "Off", NULL },
{ "On" , NULL },
};
static const struct opt_items fullscreen[]= {
{ "Off", NULL },
{ "Fullscreen", NULL },
{ "Full - Maintain Ratio", NULL },
};
static const struct opt_items frameskip[]= {
{ "3 Max", NULL },
{ "4 Max", NULL },
{ "5 Max", NULL },
{ "6 Max", NULL },
};
static const struct menu_item items[] = {
{"Max Frameskip", NULL },
{"Sound" , NULL },
{"Stats" , NULL },
{"Fullscreen" , NULL },
{"Set Keys (Buggy)", NULL },
};
m = rb->menu_init(items, sizeof(items) / sizeof(*items), NULL, NULL, NULL, NULL);
while(!done)
{
result=rb->menu_show(m);
/* handle selected menu item */
switch (mi) {
case MENU_CANCEL:
case FS_ITEM_BACK:
done = true;
break;
case FS_ITEM_FS0:
options.maxskip=3;
break;
case FS_ITEM_FS1:
options.maxskip=4;
break;
case FS_ITEM_FS2:
options.maxskip=5;
break;
case FS_ITEM_FS3:
options.maxskip=7;
break;
switch (result)
{
case 0: /* Frameskip */
options.maxskip-=3;
rb->set_option(items[0].desc, &options.maxskip, INT, frameskip, 4, NULL );
options.maxskip+=3;
break;
case 1: /* Sound */
if(options.sound>1) options.sound=1;
rb->set_option(items[1].desc, &options.sound, INT, onoff, 2, NULL );
break;
case 2: /* Stats */
rb->set_option(items[2].desc, &options.showstats, INT, onoff, 2, NULL );
break;
case 3: /* Fullscreen */
rb->set_option(items[3].desc, &options.fullscreen, INT, fullscreen, 3, NULL );
setvidmode(options.fullscreen);
break;
case 4: /* Keys */
setupkeys();
break;
default:
done=true;
break;
}
}
}
}
static void do_opt_menu(void) {
int mi, num_items;
bool done = false;
/* set a couple of defaults */
num_items = sizeof(opt_menu) / sizeof(char*);
mi = 0;
while (!done) {
mi = do_menu(OPT_MENU_TITLE, (char**) opt_menu, num_items, mi);
switch (mi) {
case OM_ITEM_FS:
do_fs_menu();
break;
case OM_ITEM_SOUND:
options.sound=!options.sound;
break;
case OM_ITEM_STATS:
options.showstats=!options.showstats;
break;
case OM_ITEM_FULLSCREEN:
options.fullscreen=!options.fullscreen;
break;
case OM_ITEM_KEYS:
setupkeys();
break;
case MENU_CANCEL:
case OM_ITEM_BACK:
done = true;
break;
}
}
}
/*********************************************************************/
/* MENU FUNCTIONS */
/*********************************************************************/
/* at some point i'll make this a generic menu interface, but for now,
* these defines will suffice */
#define MENU_X 10
#define MENU_Y 8
#define MENU_WIDTH (LCD_WIDTH - 2 * MENU_X)
#define MENU_HEIGHT (LCD_HEIGHT - 2 * MENU_Y)
#define MENU_RECT MENU_X, MENU_Y, MENU_WIDTH, MENU_HEIGHT
#define SHADOW_RECT MENU_X + 1, MENU_Y + 1, MENU_WIDTH, MENU_HEIGHT
#define MENU_ITEM_PAD 2
/*
* select_item - select menu item (after deselecting current item)
*/
static void select_item(char *title, int curr_item, size_t item_i) {
int x, y, w, h;
/* get size of title, use that as height ofr all lines */
rb->lcd_getstringsize(title, &w, &h);
h += MENU_ITEM_PAD * 2;
/* calc x and width */
x = MENU_X + MENU_ITEM_PAD;
w = MENU_WIDTH - 2 * MENU_ITEM_PAD;
rb->lcd_set_drawmode(DRMODE_COMPLEMENT);
/* if there is a current item, then deselect it */
if (curr_item >= 0) {
/* deselect old item */
y = MENU_Y + h + MENU_ITEM_PAD * 2; /* account for title */
y += h * curr_item;
rb->lcd_fillrect(x, y, w, h);
}
/* select new item */
curr_item = item_i;
/* select new item */
y = MENU_Y + h + MENU_ITEM_PAD * 2; /* account for title */
y += h * curr_item;
rb->lcd_fillrect(x, y, w, h);
rb->lcd_set_drawmode(DRMODE_SOLID);
/* update the menu window */
rb->lcd_update_rect(MENU_RECT);
}
/*
* draw_menu - draw menu on screen
*
* Returns MENU_CANCEL if the user cancelled, or the item number of the
* selected item.
*
*/
static void draw_menu(char *title, char **items, size_t num_items) {
size_t i;
int x, y, w, h, by;
/* set to default? font */
rb->lcd_setfont(0);
/* draw the outline */
rb->lcd_fillrect(SHADOW_RECT);
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
rb->lcd_fillrect(MENU_RECT);
rb->lcd_set_drawmode(DRMODE_SOLID);
rb->lcd_drawrect(MENU_RECT);
/* calculate x/y */
x = MENU_X + MENU_ITEM_PAD;
y = MENU_Y + MENU_ITEM_PAD * 2;
rb->lcd_getstringsize(title, &w, &h);
h += MENU_ITEM_PAD * 2;
/* draw menu stipple */
for (i = MENU_Y; i < (size_t) y + h; i += 2)
rb->lcd_drawline(MENU_X, i, MENU_X + MENU_WIDTH, i);
/* clear title rect */
rb->lcd_set_drawmode(DRMODE_SOLID|DRMODE_INVERSEVID);
rb->lcd_fillrect((LCD_WIDTH - w) / 2 - 2, y - 2, w + 4, h);
rb->lcd_set_drawmode(DRMODE_SOLID);
/* draw centered title on screen */
rb->lcd_putsxy((LCD_WIDTH - w)/2, y, title);
/* calculate base Y for items */
by = y + h + MENU_ITEM_PAD;
/* iterate over each item and draw it on the screen */
for (i = 0; i < num_items; i++)
rb->lcd_putsxy(x, by + h * i, items[i]);
/* update the screen */
rb->lcd_update();
}
/*
* do_menu - draw menu on screen.
*
* Draw a menu titled @title on the screen, with @num_items elements
* from @items, and select the @sel element. If in doubt, set @sel to
* -1 :).
*
*/
static int do_menu(char *title, char **items, size_t num_items, int sel) {
int btn, sel_item, ret, curr_item;
bool done = false;
ret = MENU_CANCEL;
/* draw menu on screen and select the first item */
draw_menu(title, items, num_items);
curr_item = -1;
select_item(title, curr_item, sel);
curr_item = sel;
/* make sure button state is empty */
while (rb->button_get(false) != BUTTON_NONE)
rb->yield();
/* loop until the menu is finished */
while (!done) {
/* grab a button */
btn = rb->button_get(true);
/* handle the button */
switch (btn) {
case MENU_BUTTON_DOWN:
/* select next item in list */
sel_item = curr_item + 1;
if (sel_item >= (int) num_items)
sel_item = 0;
select_item(title, curr_item, sel_item);
curr_item = sel_item;
break;
case MENU_BUTTON_UP:
/* select prev item in list */
sel_item = curr_item - 1;
if (sel_item < 0)
sel_item = num_items - 1;
select_item(title, curr_item, sel_item);
curr_item = sel_item;
break;
case MENU_BUTTON_RIGHT:
/* select current item */
ret = curr_item;
done = true;
break;
case MENU_BUTTON_LEFT:
case MENU_BUTTON_CANCEL:
/* cancel out of menu */
ret = MENU_CANCEL;
done = true;
break;
}
/* give the OS some love */
rb->yield();
}
/* return selected item */
return ret;
rb->menu_exit(m);
}

View file

@ -1,11 +1,6 @@
#ifndef __RC_H__
#define __RC_H__
typedef enum rctype
{
rcv_end,
@ -65,7 +60,3 @@ void rc_dokey(int key, int st);
int rc_command(char *line);
#endif

View file

@ -1,26 +1,12 @@
#include <string.h>
#include "rockmacros.h"
#include "defs.h"
#include "rc.h"
static rcvar_t rcvars[150];
static int nvars;
void rc_export(rcvar_t *v)
{
const rcvar_t end = RCV_END;
@ -223,11 +209,3 @@ char *rc_getstr(char *name)
{
return rc_getstr_n(rc_findvar(name));
}

View file

@ -174,8 +174,3 @@
#endif

View file

@ -47,6 +47,8 @@ void die(char *message, ...)
errormsg=message;
}
struct options options IBSS_ATTR;
void *audio_bufferbase;
void *audio_bufferpointer;
unsigned int audio_buffer_free;
@ -76,7 +78,10 @@ void setmallocpos(void *pointer)
audio_buffer_free = audio_bufferpointer - audio_bufferbase;
}
void setoptions (void) {
void setvidmode(int);
void setoptions (void)
{
int fd;
DIR* dir;
char optionsave[sizeof(savedir)+sizeof(optionname)];
@ -144,6 +149,8 @@ void setoptions (void) {
else
read(fd,&options, sizeof(options));
setvidmode(options.fullscreen);
close(fd);
}
@ -167,6 +174,10 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
rb->lcd_setfont(0);
rb->lcd_set_foreground(LCD_WHITE);
rb->lcd_set_background(LCD_BLACK);
rb->lcd_clear_display();
if (!parameter) {
rb->splash(HZ*3, true, "Play gameboy ROM file! (.gb/.gbc)");
return PLUGIN_OK;

View file

@ -105,7 +105,7 @@ void* memcpy(void* dst, const void* src, size_t size);
struct options {
int A, B, START, SELECT, MENU;
int frameskip, fps, maxskip;
bool sound, fullscreen, showstats;
int sound, fullscreen, showstats;
};
extern struct options options;

View file

@ -1,5 +1,3 @@
#ifndef __SOUND_H__
#define __SOUND_H__
@ -16,7 +14,6 @@ struct sndchan
int envol, endir;
};
struct snd
{
int rate;
@ -24,7 +21,6 @@ struct snd
byte wave[16];
};
extern struct snd snd;
#if defined(ICODE_ATTR) && defined(CPU_ARM)
@ -33,15 +29,14 @@ extern struct snd snd;
#endif
byte sound_read(byte r) ICODE_ATTR;
void sound_write(byte r, byte b)ICODE_ATTR;
void sound_dirty(void)ICODE_ATTR;
void sound_write(byte r, byte b) ICODE_ATTR;
void sound_dirty(void) ICODE_ATTR;
void sound_off(void);
void sound_reset(void);
void sound_mix(void)ICODE_ATTR;
void sound_mix(void) ICODE_ATTR;
void s1_init(void);
void s2_init(void);
void s3_init(void);
void s4_init(void);
#endif

View file

@ -185,7 +185,8 @@ void vid_init(void)
#endif
}
#if LCD_HEIGHT<144
#if !defined(HAVE_LCD_COLOR)
/* Color targets are handled in lcd.c */
fb_data *frameb;
void vid_update(int scanline)
{