Menu fixes. Various fixes.

This commit is contained in:
LemonBoy 2014-04-28 18:44:50 +02:00
parent 54d3f3ee3f
commit 3b5d7bc6b3
7 changed files with 133 additions and 117 deletions

View File

@ -25,10 +25,9 @@ NITRODATA := fs
#---------------------------------------------------------------------------------
# options for code generation
#---------------------------------------------------------------------------------
ARCH := -marm -mthumb-interwork -march=armv5te -mtune=arm946e-s
ARCH := -marm -mno-thumb-interwork -march=armv5te -mtune=arm946e-s
CFLAGS := -save-temps \
-funroll-loops -ftree-vectorize \
-Wall -Ofast\
-fomit-frame-pointer\
-ffast-math \

View File

@ -21,6 +21,7 @@ reg_y .req r7
reg_f .req r6
cycles .req r5
// XXX rebase the pc on page cross
.macro fetch
ldrb r0, [reg_pc], #1
.endm
@ -134,19 +135,11 @@ cycles .req r5
ldrsb r0, [reg_pc], #1
#ifdef CHECK_IDLE_JUMP
cmp r0, #-2
bne 2f
// unbase_pc reg_pc
// ldr r0, =idle_loop_msg
// mov r1, reg_pc
// bl iprintf
bne 1f
b _xx
#endif
2: // Sign extend
add r2, reg_pc, r0
eor r1, r2, reg_pc
tst r1, #0x100
subne cycles, #2
add reg_pc, r0
// XXX two cycle penality for page crossing
1: add reg_pc, r0
.endm
#define FLAG_CARRY 0x01<<24

View File

@ -46,7 +46,7 @@ void emu_init ()
keyboardShow();
// Set some sane defaults
emu_vsync = 0;
emu_vsync = 1;
// Setup the video hardware
video_init();

View File

@ -13,8 +13,10 @@
int emu_vsync;
int emu_input;
int emu_screen;
int emu_scale;
static char *basename;
static char *basename = NULL;
void emu_init ();
void emu_run ();

View File

@ -27,7 +27,7 @@ int main(int argc, char **argv)
/*load_disk("PACMAN.DSK");*/
/*load_disk("Karateka (1984)(Broderbund).dsk");*/
// Awesome!
/*load_disk("lode.dsk");*/
load_disk("lode.dsk");
// AppleII+
/*load_disk("Prince of Persia (1989)(Broderbund)(Disk 1 of 3)[cr].dsk");*/
// Gfx heavy
@ -44,7 +44,7 @@ int main(int argc, char **argv)
/*load_disk("Fracas (1980)(Quality Software).dsk");*/
/*load_disk("Colorix.dsk");*/
/*load_disk("LoRes Games.DSK");*/
load_disk("LoRes Hijinks.DSK");
/*load_disk("LoRes Hijinks.DSK");*/
// SP Crash
/*load_disk("Apple II Business Graphics 1.0 (1981).nib");*/
} else {

View File

@ -6,6 +6,7 @@ typedef struct entry_t {
const char *label;
const int opts_no;
const char *opts[10];
int *opt_ptr;
int (*cb)(int);
} entry_t;
@ -15,31 +16,53 @@ typedef struct page_t {
const entry_t *entries;
} page_t;
#define OPT(n) int opt_##n (int sel) { emu_##n = sel; return 1; }
OPT(vsync);
OPT(input);
int opt_screen (int sel)
static int opt_screen (const int sel)
{
emu_screen = sel;
(sel) ? lcdMainOnBottom() : lcdMainOnTop();
return 1;
}
static int opt_vsync (const int sel)
{
emu_vsync = sel;
return 1;
}
static int opt_scale (const int sel)
{
emu_scale = sel;
video_set_scale(emu_scale);
return 1;
}
static int opt_input (const int sel)
{
emu_input = sel;
return 1;
}
static int opt_exit (const int sel)
{
exit(0);
return 1;
}
static int sel_slot_l = 0, sel_slot_s = 0;
const static struct page_t paused_pg = {
"Paused", 7, (const entry_t []){
{ "Vsync", 2, { "No", "Yes" }, opt_vsync },
{ "Scale", 2, { "No", "Yes" }, video_set_scale },
{ "Screen", 2, { "Top", "Bottom" }, opt_screen },
{ "Map keys to", 2, { "joystick", "keyboard" }, opt_input },
{ "Save state", 9, { "1", "2", "3", "4", "5", "6", "7", "8", "9" }, state_save },
{ "Load state", 9, { "1", "2", "3", "4", "5", "6", "7", "8", "9" }, state_load },
{ "Exit", 0, { }, exit },
{ "Vsync", 2, { "No", "Yes" }, &emu_vsync, opt_vsync },
{ "Scale", 2, { "No", "Yes" }, &emu_scale, opt_scale },
{ "Screen", 2, { "Top", "Bottom" }, &emu_screen, opt_screen },
{ "Map keys to", 2, { "joystick", "keyboard" }, &emu_input, opt_input },
{ "Save state", 9, { "1", "2", "3", "4", "5", "6", "7", "8", "9" }, &sel_slot_s, state_save },
{ "Load state", 9, { "1", "2", "3", "4", "5", "6", "7", "8", "9" }, &sel_slot_l, state_load },
{ "Exit", 0, { }, NULL, opt_exit },
}
};
static int paused_pg_opt[6] = { 1, 0, 0, 0, 0, 0 };
void menu_print_page (const page_t *page, int *opts)
void menu_print_page (const page_t *page)
{
int i;
int cur;
@ -56,7 +79,7 @@ void menu_print_page (const page_t *page, int *opts)
for (i = 0; i < page->entries_no; i++) {
const entry_t *entry = &page->entries[i];
iprintf("%c %s %s\n", (i == cur) ? '>' : ' ', entry->label,
(entry->opts_no) ? entry->opts[opts[i]] : "");
(entry->opts_no) ? entry->opts[*entry->opt_ptr] : "");
}
scanKeys();
@ -73,26 +96,19 @@ void menu_print_page (const page_t *page, int *opts)
cur = 0;
}
if (sel_entry->opts_no) {
if (keys&KEY_LEFT && opts[cur] > 0) {
opts[cur]--;
/*if (sel_entry->cb) sel_entry->cb(opts[cur]);*/
}
if (keys&KEY_RIGHT && opts[cur] < sel_entry->opts_no - 1) {
opts[cur]++;
/*if (sel_entry->cb) sel_entry->cb(opts[cur]);*/
}
if (keys&KEY_LEFT && *sel_entry->opt_ptr > 0)
(*sel_entry->opt_ptr)--;
if (keys&KEY_RIGHT && *sel_entry->opt_ptr < sel_entry->opts_no - 1)
(*sel_entry->opt_ptr)++;
}
if (keys&KEY_A) {
if (sel_entry->cb)
if (sel_entry->cb(opts[cur]))
return;
if (keys&(KEY_TOUCH|KEY_START|KEY_A)) {
if (sel_entry->cb && sel_entry->cb(*sel_entry->opt_ptr))
return;
if (!(keys&KEY_A))
return;
}
// Use keysDown to avoid bouncing
if (keysDown()&KEY_START)
return;
swiWaitForVBlank();
}
}
@ -103,4 +119,4 @@ void print_msg (const char *msg)
swiDelay(10000000);
}
void pause_menu () { menu_print_page(&paused_pg, (int *)&paused_pg_opt); }
void pause_menu () { menu_print_page(&paused_pg); }

View File

@ -73,6 +73,9 @@ static int mixed_mode;
static int sel_page;
static int hires;
// The mixed mode can be enabled only if graphic mode is set
#define render_mixed_mode (mixed_mode&(!text_mode))
void video_set_mode ();
void video_save (FILE *f)
@ -95,7 +98,7 @@ void video_load (FILE *f)
void video_set_mode ()
{
if (mixed_mode) {
if (render_mixed_mode) {
bgShow(gfx_bg);
bgShow(text_bg);
REG_DISPCNT |= DISPLAY_WIN0_ON;
@ -115,8 +118,6 @@ u8 video_io_read (u16 addr)
break;
case 0x1:
text_mode = 1;
// The mixed mode can be enabled only if graphic mode is set
mixed_mode = 0;
break;
case 0x2:
mixed_mode = 0;
@ -152,7 +153,7 @@ u8 video_io_read (u16 addr)
}
void draw_lores_scr (u16 *map) ITCM_CODE;
void draw_lores_scr (u16 *map)
void draw_lores_scr (u16 *__restrict map)
{
int last_line;
int i, j;
@ -161,7 +162,7 @@ void draw_lores_scr (u16 *map)
if (!page_dirty[sel_page])
return;
last_line = mixed_mode ? 168 : 192;
last_line = render_mixed_mode ? 168 : 192;
for (i = 0; i < last_line; i++) {
ptr = (u8 *)(mainram + (sel_page << 10) + video_addr[i/8]);
@ -184,17 +185,19 @@ void draw_lores_scr (u16 *map)
}
}
void draw_hires_scr (u16 *map) ITCM_CODE;
#if 0
/*odd_color = (b1&0x80) ? 6 : 3;*/
/*even_color = (b1&0x80) ? 9 : 12;*/
void draw_hires_scr_1 (u16 *map)
void draw_hires_scr (u16 *__restrict map)
{
int last_line;
int i, j, k;
u8 *ptr, tmp;
u8 *__restrict ptr, tmp;
static u8 tmp_line[0x200];
static const u8 color_lut[] DTCM_DATA = { 0, 12, 0, 15, 0, 9, 0, 15, 0, 3, 0, 15, 0, 6, 0, 15 };
last_line = mixed_mode ? 168 : 192;
last_line = render_mixed_mode ? 168 : 192;
for (i = 0; i < last_line; i++, map += 0x100) {
if (!page_dirty[8 + (i&7)])
@ -217,22 +220,23 @@ void draw_hires_scr_1 (u16 *map)
tmp >>= 7;
}
dmaCopyAsynch(tmp_line, map, 0x200);
DC_FlushRange(tmp_line, sizeof(tmp_line));
dmaCopyAsynch(tmp_line, map, sizeof(tmp_line));
DC_InvalidateRange(map, sizeof(tmp_line));
}
}
void draw_hires_scr (u16 *map) ITCM_CODE;
void draw_hires_scr (u16 *map)
#else
void draw_hires_scr (u16 *__restrict map)
{
int last_line;
int i, j, k, x;
u8 *xptr, *ptr, tmp;
u16 *omap;
u8 *__restrict xptr, *__restrict ptr, tmp;
u16 *__restrict omap;
static u8 tmp_line[0x200];
static const u8 color_lut[] DTCM_DATA = { 0, 12, 0, 15, 0, 9, 0, 15, 0, 3, 0, 15, 0, 6, 0, 15 };
last_line = mixed_mode ? 168/8 : 192/8;
last_line = render_mixed_mode ? 168/8 : 192/8;
for(x = 0; x < 8; x++, map += 0x100) {
if (!page_dirty[8+x])
@ -246,7 +250,7 @@ void draw_hires_scr (u16 *map)
const u8 b1 = *ptr++;
tmp = (b1&0x7f) << 1 | tmp;
const u8 *lut_b = color_lut + ((b1&0x80)>>5);
const u8 *__restrict lut_b = color_lut + ((b1&0x80)>>5);
for (k = 0; k < 7; k+=2)
{
@ -258,12 +262,14 @@ void draw_hires_scr (u16 *map)
tmp >>= 1;
}
}
dmaCopyAsynch(tmp_line, omap, 0x200);
/*memcpy(omap, tmp_line, 0x200);*/
DC_FlushRange(tmp_line, sizeof(tmp_line));
dmaCopyAsynch(tmp_line, omap, sizeof(tmp_line));
DC_InvalidateRange(omap, sizeof(tmp_line));
}
page_dirty[8+x] = 0;
}
}
#endif
void draw_text_scr (u16 *map) ITCM_CODE;
void draw_text_scr (u16 *map)
@ -275,7 +281,7 @@ void draw_text_scr (u16 *map)
if (!page_dirty[sel_page])
return;
if ((start_line = mixed_mode ? 21 : 0))
if ((start_line = render_mixed_mode ? 21 : 0))
map += 32 * start_line;
for (i = start_line; i < 24; i++) {
@ -298,7 +304,7 @@ void video_draw ()
u16 *text_ptr = (u16 *)0x6002000;
u16 *gfx_ptr = (u16 *)0x6020000;
if (mixed_mode) {
if (render_mixed_mode) {
draw_text_scr(text_ptr);
(hires) ? draw_hires_scr(gfx_ptr) : draw_lores_scr(gfx_ptr);
} else {