Correct and faster hires mode. Added b/w hires mode. Input fixes.

This commit is contained in:
LemonBoy 2014-04-30 21:57:03 +02:00
parent 3b5d7bc6b3
commit 764c97dfb7
7 changed files with 119 additions and 87 deletions

View File

@ -8,6 +8,8 @@ endif
include $(DEVKITARM)/ds_rules include $(DEVKITARM)/ds_rules
EMU_BUILD=0
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# TARGET is the name of the output # TARGET is the name of the output
# BUILD is the directory where object files & intermediate files will be placed # BUILD is the directory where object files & intermediate files will be placed
@ -20,7 +22,6 @@ BUILD := build
SOURCES := source SOURCES := source
DATA := DATA :=
INCLUDES := include INCLUDES := include
NITRODATA := fs
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# options for code generation # options for code generation
@ -34,7 +35,7 @@ CFLAGS := -save-temps \
$(ARCH) $(ARCH)
#-finstrument-functions -mpoke-function-name \ #-finstrument-functions -mpoke-function-name \
CFLAGS += $(INCLUDE) -DARM9 -DEMU_BUILD CFLAGS += $(INCLUDE) -DARM9
CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions CXXFLAGS := $(CFLAGS) -fno-rtti -fno-exceptions
ASFLAGS := $(ARCH) ASFLAGS := $(ARCH)
@ -43,14 +44,21 @@ LDFLAGS = -specs=ds_arm9.specs $(ARCH) -Wl,-Map,$(notdir $*.map)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# any extra libraries we wish to link with the project (order is important) # any extra libraries we wish to link with the project (order is important)
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
LIBS := -lfilesystem -lfat -lnds9 LIBS := -lfat -lnds9
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# list of directories containing libraries, this must be the top level containing # list of directories containing libraries, this must be the top level containing
# include and lib # include and lib
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
LIBDIRS := $(LIBNDS) LIBDIRS := $(LIBNDS)
ifeq ($(strip $(EMU_BUILD)),1)
NITRODATA := fs
CFLAGS += -DEMU_BUILD
LIBS := -lfilesystem $(LIBS)
else
CFLAGS += -DHW_BUILD
endif
#--------------------------------------------------------------------------------- #---------------------------------------------------------------------------------
# no real need to edit anything past this point unless you need to add additional # no real need to edit anything past this point unless you need to add additional

View File

@ -42,7 +42,6 @@ void emu_init ()
u16 crc; u16 crc;
int valid_crc; int valid_crc;
keysSetRepeat(30, 10);
keyboardShow(); keyboardShow();
// Set some sane defaults // Set some sane defaults
@ -51,6 +50,7 @@ void emu_init ()
// Setup the video hardware // Setup the video hardware
video_init(); video_init();
#if 1 #if 1
crc = 0xffff;
// Load the appropriate bios // Load the appropriate bios
if (load_bin("BASIC.ROM", 0xD000, 0x3000, &crc)) { if (load_bin("BASIC.ROM", 0xD000, 0x3000, &crc)) {
valid_crc = valid_rom_crc(crc); valid_crc = valid_rom_crc(crc);
@ -95,6 +95,8 @@ void emu_run ()
video_draw(); video_draw();
scanKeys();
update_input(); update_input();
frames_done++; frames_done++;

View File

@ -22,11 +22,10 @@ void update_input ()
u32 keys; u32 keys;
int kbd_key; int kbd_key;
scanKeys(); keys = keysDown() | keysHeld();
keys = (keysDownRepeat()|keysDown())&0xfff;
// Send keyboard scancodes when a key is pressed // Send keyboard scancodes when a key is pressed
if (emu_input == INPUT_KBD && keys) { if (emu_input == INPUT_KBD && (keys&0xfff)) {
int bit_set = __builtin_ffs(keys); int bit_set = __builtin_ffs(keys);
if (bit_set) if (bit_set)
keybd_latch = 0x80 ^ key_map[bit_set-1]; keybd_latch = 0x80 ^ key_map[bit_set-1];

View File

@ -12,13 +12,18 @@ int main(int argc, char **argv)
consoleDemoInit(); consoleDemoInit();
keyboardDemoInit(); keyboardDemoInit();
fatInitDefault(); #ifdef EMU_BUILD
nitroFSInit(NULL); nitroFSInit(NULL);
#else
fatInitDefault();
#endif
soundEnable(); soundEnable();
iprintf("-- grape\n"); iprintf("-- grape\n");
keysSetRepeat(30, 10);
emu_init(); emu_init();
if (argc != 2) { if (argc != 2) {
@ -27,7 +32,7 @@ int main(int argc, char **argv)
/*load_disk("PACMAN.DSK");*/ /*load_disk("PACMAN.DSK");*/
/*load_disk("Karateka (1984)(Broderbund).dsk");*/ /*load_disk("Karateka (1984)(Broderbund).dsk");*/
// Awesome! // Awesome!
load_disk("lode.dsk"); /*load_disk("lode.dsk");*/
// AppleII+ // AppleII+
/*load_disk("Prince of Persia (1989)(Broderbund)(Disk 1 of 3)[cr].dsk");*/ /*load_disk("Prince of Persia (1989)(Broderbund)(Disk 1 of 3)[cr].dsk");*/
// Gfx heavy // Gfx heavy
@ -37,7 +42,7 @@ int main(int argc, char **argv)
/*load_disk("Round About (1983)(Datamost).dsk");*/ /*load_disk("Round About (1983)(Datamost).dsk");*/
/*load_disk("Bug Attack (1981)(Cavalier Computer).dsk");*/ /*load_disk("Bug Attack (1981)(Cavalier Computer).dsk");*/
// Scroller // Scroller
/*load_disk("TetrisII.DSK");*/ load_disk("TetrisII.DSK");
// Mixed mode // Mixed mode
/*load_disk("tetris48k.nib");*/ /*load_disk("tetris48k.nib");*/
// Lowres // Lowres

View File

@ -48,13 +48,19 @@ static int opt_exit (const int sel)
return 1; return 1;
} }
static int sel_slot_l = 0, sel_slot_s = 0; static int opt_hires (const int sel)
{
video_set_hires(sel);
}
static int sel_slot_l = 0, sel_slot_s = 0, sel_hires = 0;
const static struct page_t paused_pg = { const static struct page_t paused_pg = {
"Paused", 7, (const entry_t []){ "Paused", 8, (const entry_t []){
{ "Vsync", 2, { "No", "Yes" }, &emu_vsync, opt_vsync }, { "Vsync", 2, { "No", "Yes" }, &emu_vsync, opt_vsync },
{ "Scale", 2, { "No", "Yes" }, &emu_scale, opt_scale }, { "Scale", 2, { "No", "Yes" }, &emu_scale, opt_scale },
{ "Screen", 2, { "Top", "Bottom" }, &emu_screen, opt_screen }, { "Screen", 2, { "Top", "Bottom" }, &emu_screen, opt_screen },
{ "Hires mode", 2, { "B/W", "Color" }, &sel_hires, opt_hires },
{ "Map keys to", 2, { "joystick", "keyboard" }, &emu_input, opt_input }, { "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 }, { "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 }, { "Load state", 9, { "1", "2", "3", "4", "5", "6", "7", "8", "9" }, &sel_slot_l, state_load },
@ -66,7 +72,7 @@ void menu_print_page (const page_t *page)
{ {
int i; int i;
int cur; int cur;
int keys; u32 keys, keys_;
cur = 0; cur = 0;
@ -83,32 +89,34 @@ void menu_print_page (const page_t *page)
} }
scanKeys(); scanKeys();
keys = keysDownRepeat(); keys = keysDown();
keys_ = keysDownRepeat();
if (keys&KEY_UP) { if (keys_&KEY_UP) {
cur--; cur--;
if (cur < 0) if (cur < 0)
cur = page->entries_no - 1; cur = page->entries_no - 1;
} }
if (keys&KEY_DOWN) { if (keys_&KEY_DOWN) {
cur++; cur++;
if (cur == page->entries_no) if (cur == page->entries_no)
cur = 0; cur = 0;
} }
if (sel_entry->opts_no) { if (sel_entry->opts_no) {
if (keys&KEY_LEFT && *sel_entry->opt_ptr > 0) if (keys_&KEY_LEFT && *sel_entry->opt_ptr > 0)
(*sel_entry->opt_ptr)--; (*sel_entry->opt_ptr)--;
if (keys&KEY_RIGHT && *sel_entry->opt_ptr < sel_entry->opts_no - 1) if (keys_&KEY_RIGHT && *sel_entry->opt_ptr < sel_entry->opts_no - 1)
(*sel_entry->opt_ptr)++; (*sel_entry->opt_ptr)++;
} }
if (keys&(KEY_TOUCH|KEY_START|KEY_A)) { if (keys&KEY_A) {
if (sel_entry->cb && sel_entry->cb(*sel_entry->opt_ptr)) if (sel_entry->cb && sel_entry->cb(*sel_entry->opt_ptr))
return; return;
if (!(keys&KEY_A))
return;
} }
if (keys&KEY_START)
return;
swiWaitForVBlank(); swiWaitForVBlank();
} }
} }

View File

@ -73,6 +73,8 @@ static int mixed_mode;
static int sel_page; static int sel_page;
static int hires; static int hires;
static void (* draw_hires_line)(u16 *, u8 *);
// The mixed mode can be enabled only if graphic mode is set // The mixed mode can be enabled only if graphic mode is set
#define render_mixed_mode (mixed_mode&(!text_mode)) #define render_mixed_mode (mixed_mode&(!text_mode))
@ -185,94 +187,86 @@ void draw_lores_scr (u16 *__restrict map)
} }
} }
void draw_hires_scr (u16 *map) ITCM_CODE;
#if 0
/*odd_color = (b1&0x80) ? 6 : 3;*/ /*odd_color = (b1&0x80) ? 6 : 3;*/
/*even_color = (b1&0x80) ? 9 : 12;*/ /*even_color = (b1&0x80) ? 9 : 12;*/
void draw_hires_scr (u16 *__restrict map)
static void draw_hires_line_mono (u16 *__restrict map, u8 *__restrict ptr) ITCM_CODE;
static void draw_hires_line_mono (u16 *__restrict map, u8 *__restrict ptr)
{ {
int last_line; const u16 lut[] = {0x0000, 0x000c, 0x0c00, 0x0c0c};
int i, j, k; int j;
u8 *__restrict ptr, tmp; for (j = 0; j < 280/14; j++) {
static u8 tmp_line[0x200]; u16 tmp = (ptr[0]&0x7f) | ((ptr[1]&0x7f) << 7);
static const u8 color_lut[] DTCM_DATA = { 0, 12, 0, 15, 0, 9, 0, 15, 0, 3, 0, 15, 0, 6, 0, 15 }; ptr += 2;
*map++ = lut[tmp&3]; tmp >>= 2;
last_line = render_mixed_mode ? 168 : 192; *map++ = lut[tmp&3]; tmp >>= 2;
*map++ = lut[tmp&3]; tmp >>= 2;
for (i = 0; i < last_line; i++, map += 0x100) { *map++ = lut[tmp&3]; tmp >>= 2;
if (!page_dirty[8 + (i&7)]) *map++ = lut[tmp&3]; tmp >>= 2;
continue; *map++ = lut[tmp&3]; tmp >>= 2;
*map++ = lut[tmp&3];
ptr = mainram + (sel_page << 13) + ((i&7) * 0x400) + video_addr[i>>3];
for (j = 0, tmp = 0; j < 280; j += 7) {
const u8 b1 = *ptr++;
tmp = (b1&0x7f) << 1 | tmp;
// embb
// e = even / odd
// m = msb
// b = data
for (k = 0; k <= 7; k++)
tmp_line[j+k] = color_lut[(((j+k)&1) ? 0x8 : 0x0) + ((b1&0x80)>>5) + ((tmp>>k)&3)];
tmp >>= 7;
}
DC_FlushRange(tmp_line, sizeof(tmp_line));
dmaCopyAsynch(tmp_line, map, sizeof(tmp_line));
DC_InvalidateRange(map, sizeof(tmp_line));
} }
} }
#else
void draw_hires_scr (u16 *__restrict map) static void draw_hires_line_color (u16 *__restrict map, u8 *__restrict ptr) ITCM_CODE;
static void draw_hires_line_color (u16 *__restrict map, u8 *__restrict ptr)
{ {
int last_line; static u8 tmp_line[280];
int i, j, k, x; static const u8 color_lut[] DTCM_DATA = {
u8 *__restrict xptr, *__restrict ptr, tmp; 0, 12, 0, 15, 0, 9, 0, 15, 0, 3, 0, 15, 0, 6, 0, 15
};
int j, k;
u16 tmp;
for (j = 0, tmp = 0; j < 280; j += 7) {
const u8 b1 = *ptr++;
tmp = (b1&0x7f) << 1 | tmp;
const u8 *__restrict lut_b = color_lut + ((b1&0x80)>>5);
for (k = 0; k < 7; k+=2)
{
tmp_line[j+k+0] = lut_b[((j&1) << 3) + (tmp&3)];
tmp >>= 1;
if(k == 6)
break;
tmp_line[j+k+1] = lut_b[((~j&1) << 3) + (tmp&3)];
tmp >>= 1;
}
}
DC_FlushRange(tmp_line, sizeof(tmp_line));
dmaCopyAsynch(tmp_line, map, sizeof(tmp_line));
DC_InvalidateRange(map, sizeof(tmp_line));
}
static void draw_hires_scr (u16 *map) ITCM_CODE;
static void draw_hires_scr (u16 *__restrict map)
{
int i, x, last_line;
u8 *__restrict xptr, *__restrict ptr;
u16 *__restrict omap; 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 = render_mixed_mode ? 168/8 : 192/8; last_line = render_mixed_mode ? 168/8 : 192/8;
for(x = 0; x < 8; x++, map += 0x100) { for(x = 0; x < 8; x++, map += 0x100) {
if (!page_dirty[8+x]) if (!page_dirty[(sel_page<<3)+x])
continue; continue;
xptr = mainram + (sel_page << 13) + (x << 10); xptr = mainram + (sel_page << 13) + (x << 10);
for(omap = map, i = 0; i < last_line; i++, omap += 0x800) { for(omap = map, i = 0; i < last_line; i++, omap += 0x800) {
ptr = xptr + video_addr[i]; ptr = xptr + video_addr[i];
for (j = 0, tmp = 0; j < 280; j += 7) { draw_hires_line(omap, ptr);
const u8 b1 = *ptr++;
tmp = (b1&0x7f) << 1 | tmp;
const u8 *__restrict lut_b = color_lut + ((b1&0x80)>>5);
for (k = 0; k < 7; k+=2)
{
tmp_line[j+k+0] = lut_b[((j&1) << 3) + (tmp&3)];
tmp >>= 1;
if(k == 6)
break;
tmp_line[j+k+1] = lut_b[((~j&1) << 3) + (tmp&3)];
tmp >>= 1;
}
}
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; page_dirty[(sel_page<<3)+x] = 0;
} }
} }
#endif
void draw_text_scr (u16 *map) ITCM_CODE; void draw_text_scr (u16 *map) ITCM_CODE;
void draw_text_scr (u16 *map) void draw_text_scr (u16 *__restrict map)
{ {
int start_line; int start_line;
int i, j; int i, j;
@ -319,6 +313,19 @@ void video_draw ()
page_dirty[sel_page] = 0; page_dirty[sel_page] = 0;
} }
void video_set_hires (int renderer)
{
switch (renderer) {
default:
case 0:
draw_hires_line = draw_hires_line_mono;
break;
case 1:
draw_hires_line = draw_hires_line_color;
break;
}
}
int video_set_scale (int mode) int video_set_scale (int mode)
{ {
int scaleg_x, scalet_x; int scaleg_x, scalet_x;
@ -366,6 +373,8 @@ void video_init ()
// BG2 outside // BG2 outside
WIN_OUT = 0x4; WIN_OUT = 0x4;
video_set_hires(-1);
memcpy(BG_PALETTE, palette, sizeof(palette)); memcpy(BG_PALETTE, palette, sizeof(palette));
struct UnpackStruct unpack_bit; struct UnpackStruct unpack_bit;

View File

@ -1,6 +1,7 @@
#ifndef VIDEO_H #ifndef VIDEO_H
#define VIDEO_H #define VIDEO_H
void video_set_hires (int renderer);
int video_set_scale (int mode); int video_set_scale (int mode);
void video_draw (); void video_draw ();
void video_init (); void video_init ();