mirror of https://github.com/LemonBoy/grape.git
Fast and correct color renderer! yay! And some minor fixes.
This commit is contained in:
parent
764c97dfb7
commit
d8b825ce6e
24
source/emu.c
24
source/emu.c
|
@ -46,22 +46,23 @@ void emu_init ()
|
||||||
|
|
||||||
// Set some sane defaults
|
// Set some sane defaults
|
||||||
emu_vsync = 1;
|
emu_vsync = 1;
|
||||||
|
emu_hires = 2;
|
||||||
|
|
||||||
// Setup the video hardware
|
// Setup the video hardware
|
||||||
video_init();
|
video_init();
|
||||||
#if 1
|
#if 1
|
||||||
crc = 0xffff;
|
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) < 0) {
|
||||||
valid_crc = valid_rom_crc(crc);
|
print_msg("No BASIC.ROM found. Halting.");
|
||||||
iprintf("BIOS CRC16 %04x (%s)\n", crc, (valid_crc) ? "Valid" : "Invalid");
|
|
||||||
// Refuse to load a wrong bios
|
|
||||||
if (!valid_crc)
|
|
||||||
while (1);
|
|
||||||
} else {
|
|
||||||
iprintf("No BASIC.ROM found. Halting.");
|
|
||||||
while (1);
|
while (1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
valid_crc = valid_rom_crc(crc);
|
||||||
|
iprintf("BIOS CRC16 %04x (%s)\n", crc, (valid_crc) ? "Valid" : "Invalid");
|
||||||
|
// Refuse to load the incorrect bios
|
||||||
|
if (!valid_crc)
|
||||||
|
while (1);
|
||||||
|
|
||||||
// Load the disk rom in place
|
// Load the disk rom in place
|
||||||
load_buf(disk_rom, 0xc600, 0x100);
|
load_buf(disk_rom, 0xc600, 0x100);
|
||||||
|
@ -76,8 +77,6 @@ void emu_init ()
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
basename = NULL;
|
|
||||||
|
|
||||||
// Used by the fps counter
|
// Used by the fps counter
|
||||||
frames_done = 0;
|
frames_done = 0;
|
||||||
vblanks = 0;
|
vblanks = 0;
|
||||||
|
@ -100,8 +99,11 @@ void emu_run ()
|
||||||
update_input();
|
update_input();
|
||||||
frames_done++;
|
frames_done++;
|
||||||
|
|
||||||
if (keysDown()&KEY_START)
|
if (keysDown()&KEY_START) {
|
||||||
|
irqDisable(IRQ_VBLANK);
|
||||||
pause_menu();
|
pause_menu();
|
||||||
|
irqEnable(IRQ_VBLANK);
|
||||||
|
}
|
||||||
|
|
||||||
sound_play();
|
sound_play();
|
||||||
|
|
||||||
|
|
|
@ -8,15 +8,16 @@
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
#include "state.h"
|
#include "state.h"
|
||||||
|
|
||||||
#define INPUT_JSTK 0
|
#define INPUT_JOYSTICK 0
|
||||||
#define INPUT_KBD 1
|
#define INPUT_KEYBOARD 1
|
||||||
|
|
||||||
int emu_vsync;
|
int emu_vsync;
|
||||||
int emu_input;
|
int emu_input;
|
||||||
int emu_screen;
|
int emu_screen;
|
||||||
int emu_scale;
|
int emu_scale;
|
||||||
|
int emu_hires;
|
||||||
|
|
||||||
static char *basename = NULL;
|
char *basename;
|
||||||
|
|
||||||
void emu_init ();
|
void emu_init ();
|
||||||
void emu_run ();
|
void emu_run ();
|
||||||
|
|
|
@ -25,13 +25,13 @@ void update_input ()
|
||||||
keys = keysDown() | keysHeld();
|
keys = keysDown() | keysHeld();
|
||||||
|
|
||||||
// Send keyboard scancodes when a key is pressed
|
// Send keyboard scancodes when a key is pressed
|
||||||
if (emu_input == INPUT_KBD && (keys&0xfff)) {
|
if (emu_input == INPUT_KEYBOARD && (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];
|
||||||
}
|
}
|
||||||
|
|
||||||
if (emu_input == INPUT_JSTK) {
|
if (emu_input == INPUT_JOYSTICK) {
|
||||||
jstk_btn[0] = (keys&KEY_X) ? 0x80 : 0x00;
|
jstk_btn[0] = (keys&KEY_X) ? 0x80 : 0x00;
|
||||||
jstk_btn[1] = (keys&KEY_Y) ? 0x80 : 0x00;
|
jstk_btn[1] = (keys&KEY_Y) ? 0x80 : 0x00;
|
||||||
jstk_btn[2] = (keys&KEY_B) ? 0x80 : 0x00;
|
jstk_btn[2] = (keys&KEY_B) ? 0x80 : 0x00;
|
||||||
|
|
|
@ -42,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
|
||||||
|
@ -53,7 +53,11 @@ int main(int argc, char **argv)
|
||||||
// SP Crash
|
// SP Crash
|
||||||
/*load_disk("Apple II Business Graphics 1.0 (1981).nib");*/
|
/*load_disk("Apple II Business Graphics 1.0 (1981).nib");*/
|
||||||
} else {
|
} else {
|
||||||
load_disk(argv[1]);
|
if (!load_disk(argv[1])) {
|
||||||
|
print_msg("Cannot open the selected rom!");
|
||||||
|
exit(0);
|
||||||
|
}
|
||||||
|
basename = argv[1];
|
||||||
}
|
}
|
||||||
|
|
||||||
emu_run();
|
emu_run();
|
||||||
|
|
|
@ -7,6 +7,7 @@ typedef struct entry_t {
|
||||||
const int opts_no;
|
const int opts_no;
|
||||||
const char *opts[10];
|
const char *opts[10];
|
||||||
int *opt_ptr;
|
int *opt_ptr;
|
||||||
|
int confirm;
|
||||||
int (*cb)(int);
|
int (*cb)(int);
|
||||||
} entry_t;
|
} entry_t;
|
||||||
|
|
||||||
|
@ -51,27 +52,27 @@ static int opt_exit (const int sel)
|
||||||
static int opt_hires (const int sel)
|
static int opt_hires (const int sel)
|
||||||
{
|
{
|
||||||
video_set_hires(sel);
|
video_set_hires(sel);
|
||||||
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
static int sel_slot_l = 0, sel_slot_s = 0, sel_hires = 0;
|
static int sel_slot_l = 0, sel_slot_s = 0;
|
||||||
|
|
||||||
const static struct page_t paused_pg = {
|
const static struct page_t paused_pg = {
|
||||||
"Paused", 8, (const entry_t []){
|
"Paused", 8, (const entry_t []){
|
||||||
{ "Vsync", 2, { "No", "Yes" }, &emu_vsync, opt_vsync },
|
{ "Vsync", 2, { "No", "Yes" }, &emu_vsync, 0, opt_vsync },
|
||||||
{ "Scale", 2, { "No", "Yes" }, &emu_scale, opt_scale },
|
{ "Scale", 2, { "No", "Yes" }, &emu_scale, 0, opt_scale },
|
||||||
{ "Screen", 2, { "Top", "Bottom" }, &emu_screen, opt_screen },
|
{ "Screen", 2, { "Top", "Bottom" }, &emu_screen, 0, opt_screen },
|
||||||
{ "Hires mode", 2, { "B/W", "Color" }, &sel_hires, opt_hires },
|
{ "Hires mode", 3, { "B/W", "Old", "Color" }, &emu_hires, 0, opt_hires },
|
||||||
{ "Map keys to", 2, { "joystick", "keyboard" }, &emu_input, opt_input },
|
{ "Map keys to", 2, { "joystick", "keyboard" }, &emu_input, 0, 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, 1, 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, 1, state_load },
|
||||||
{ "Exit", 0, { }, NULL, opt_exit },
|
{ "Exit", 0, { }, NULL, 1, opt_exit },
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
void menu_print_page (const page_t *page)
|
void menu_print_page (const page_t *page)
|
||||||
{
|
{
|
||||||
int i;
|
int i, cur;
|
||||||
int cur;
|
|
||||||
u32 keys, keys_;
|
u32 keys, keys_;
|
||||||
|
|
||||||
cur = 0;
|
cur = 0;
|
||||||
|
@ -102,19 +103,21 @@ void menu_print_page (const page_t *page)
|
||||||
if (cur == page->entries_no)
|
if (cur == page->entries_no)
|
||||||
cur = 0;
|
cur = 0;
|
||||||
}
|
}
|
||||||
if (sel_entry->opts_no) {
|
if (sel_entry->opts_no && (keys_&(KEY_LEFT|KEY_RIGHT))) {
|
||||||
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 (!sel_entry->confirm && sel_entry->cb)
|
||||||
|
sel_entry->cb(*sel_entry->opt_ptr);
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keys&KEY_A) {
|
if (keys&KEY_A && sel_entry->confirm && sel_entry->cb) {
|
||||||
if (sel_entry->cb && sel_entry->cb(*sel_entry->opt_ptr))
|
sel_entry->cb(*sel_entry->opt_ptr);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (keys&KEY_START)
|
if (keys&KEY_B)
|
||||||
return;
|
return;
|
||||||
|
|
||||||
swiWaitForVBlank();
|
swiWaitForVBlank();
|
||||||
|
@ -124,7 +127,7 @@ void menu_print_page (const page_t *page)
|
||||||
void print_msg (const char *msg)
|
void print_msg (const char *msg)
|
||||||
{
|
{
|
||||||
iprintf("\n-- %s\n", msg);
|
iprintf("\n-- %s\n", msg);
|
||||||
swiDelay(10000000);
|
swiDelay(50000000);
|
||||||
}
|
}
|
||||||
|
|
||||||
void pause_menu () { menu_print_page(&paused_pg); }
|
void pause_menu () { menu_print_page(&paused_pg); }
|
||||||
|
|
|
@ -1,5 +1,6 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <nds.h>
|
#include <nds.h>
|
||||||
|
#include "emu.h"
|
||||||
#include "mem.h"
|
#include "mem.h"
|
||||||
|
|
||||||
const u8 apple_font[] = {
|
const u8 apple_font[] = {
|
||||||
|
@ -240,6 +241,73 @@ static void draw_hires_line_color (u16 *__restrict map, u8 *__restrict ptr)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
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)
|
||||||
|
{
|
||||||
|
static const u8 lut[]={
|
||||||
|
// even
|
||||||
|
// msb low
|
||||||
|
0, 0, 3, 15,
|
||||||
|
0, 12, 15, 15,
|
||||||
|
// msb high
|
||||||
|
0, 0, 6, 15,
|
||||||
|
0, 9, 15, 15,
|
||||||
|
// odd
|
||||||
|
// msb low
|
||||||
|
0, 0, 12, 15,
|
||||||
|
0, 3, 15, 15,
|
||||||
|
// msb high
|
||||||
|
0, 0, 9, 15,
|
||||||
|
0, 6, 15, 15
|
||||||
|
};
|
||||||
|
int j, k;
|
||||||
|
u16 window, msb;
|
||||||
|
|
||||||
|
// Three-bit sliding window
|
||||||
|
// Based off infos from
|
||||||
|
// http://www.kreativekorp.com/miscpages/a2info/stdhires.shtml
|
||||||
|
for (window = j = 0; j < 280/14; j++) {
|
||||||
|
const u8 b1 = *ptr++;
|
||||||
|
const u8 b2 = *ptr++;
|
||||||
|
const u8 b3 = *ptr;
|
||||||
|
|
||||||
|
window |= (b3&1)<<15 | (b2&0x7f)<<8 | (b1&0x7f)<<1;
|
||||||
|
|
||||||
|
// Replicate the msb of b1 and b2 7 times
|
||||||
|
asm volatile (
|
||||||
|
"mov %0,#0;"
|
||||||
|
"tst %1,#0x80;"
|
||||||
|
"movne %0,#0x7f;"
|
||||||
|
"tst %2,#0x80;"
|
||||||
|
"orrne %0,#(0x7f<<7);"
|
||||||
|
: "=&r"(msb)
|
||||||
|
: "r"(b1), "r"(b2)
|
||||||
|
:
|
||||||
|
);
|
||||||
|
|
||||||
|
for (k = 0; k < 7; k++) {
|
||||||
|
asm volatile (
|
||||||
|
"movs %1,%1,lsr #1;"
|
||||||
|
"and r1,%2,#7;"
|
||||||
|
"addcs r1,#8;"
|
||||||
|
"lsr %2,#1;"
|
||||||
|
"ldrb r0,[%3,r1];"
|
||||||
|
"movs %1,%1,lsr #1;"
|
||||||
|
"and r1,%2,#7;"
|
||||||
|
"add r1,#16;"
|
||||||
|
"addcs r1,#8;"
|
||||||
|
"lsr %2,#1;"
|
||||||
|
"ldrb r2,[%3,r1];"
|
||||||
|
"orr r0, r2, lsl #8;"
|
||||||
|
"strh r0,[%0],#2;"
|
||||||
|
: "+r"(map)
|
||||||
|
: "r"(msb), "r"(window), "r"(lut)
|
||||||
|
: "r0", "r1", "r2"
|
||||||
|
);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
static void draw_hires_scr (u16 *map) ITCM_CODE;
|
static void draw_hires_scr (u16 *map) ITCM_CODE;
|
||||||
static void draw_hires_scr (u16 *__restrict map)
|
static void draw_hires_scr (u16 *__restrict map)
|
||||||
{
|
{
|
||||||
|
@ -323,6 +391,9 @@ void video_set_hires (int renderer)
|
||||||
case 1:
|
case 1:
|
||||||
draw_hires_line = draw_hires_line_color;
|
draw_hires_line = draw_hires_line_color;
|
||||||
break;
|
break;
|
||||||
|
case 2:
|
||||||
|
draw_hires_line = draw_hires_line_color_;
|
||||||
|
break;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -373,12 +444,12 @@ void video_init ()
|
||||||
// BG2 outside
|
// BG2 outside
|
||||||
WIN_OUT = 0x4;
|
WIN_OUT = 0x4;
|
||||||
|
|
||||||
video_set_hires(-1);
|
video_set_hires(emu_hires);
|
||||||
|
|
||||||
memcpy(BG_PALETTE, palette, sizeof(palette));
|
memcpy(BG_PALETTE, palette, sizeof(palette));
|
||||||
|
|
||||||
struct UnpackStruct unpack_bit;
|
struct UnpackStruct unpack_bit;
|
||||||
unpack_bit.dataOffset = 14;
|
unpack_bit.dataOffset = 11;
|
||||||
unpack_bit.destWidth = 8;
|
unpack_bit.destWidth = 8;
|
||||||
unpack_bit.sourceSize = 64*8;
|
unpack_bit.sourceSize = 64*8;
|
||||||
unpack_bit.sourceWidth = 1;
|
unpack_bit.sourceWidth = 1;
|
||||||
|
|
Loading…
Reference in New Issue