forked from len0rd/rockbox
Lee Pilgrim's patch to enable the chip8 plugin for the simulator
I also code-policed it somewhat. git-svn-id: svn://svn.rockbox.org/rockbox/trunk@4207 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
parent
0f68958b11
commit
aac303e17b
1 changed files with 231 additions and 221 deletions
|
|
@ -20,7 +20,6 @@
|
||||||
#include "plugin.h"
|
#include "plugin.h"
|
||||||
|
|
||||||
/* Only build for (correct) target */
|
/* Only build for (correct) target */
|
||||||
#ifndef SIMULATOR
|
|
||||||
#ifdef HAVE_LCD_BITMAP
|
#ifdef HAVE_LCD_BITMAP
|
||||||
|
|
||||||
static struct plugin_api* rb; /* here is a global api struct pointer */
|
static struct plugin_api* rb; /* here is a global api struct pointer */
|
||||||
|
|
@ -96,27 +95,32 @@ static void op_key (word opcode)
|
||||||
else
|
else
|
||||||
return;
|
return;
|
||||||
key_value=chip8_keys[get_reg_value(opcode)&0x0f];
|
key_value=chip8_keys[get_reg_value(opcode)&0x0f];
|
||||||
if (cp_value==key_value) chip8_regs.pc+=2;
|
if (cp_value==key_value)
|
||||||
|
chip8_regs.pc+=2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void op_skeq_const (word opcode)
|
static void op_skeq_const (word opcode)
|
||||||
{
|
{
|
||||||
if (get_reg_value(opcode)==(opcode&0xff)) chip8_regs.pc+=2;
|
if (get_reg_value(opcode)==(opcode&0xff))
|
||||||
|
chip8_regs.pc+=2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void op_skne_const (word opcode)
|
static void op_skne_const (word opcode)
|
||||||
{
|
{
|
||||||
if (get_reg_value(opcode)!=(opcode&0xff)) chip8_regs.pc+=2;
|
if (get_reg_value(opcode)!=(opcode&0xff))
|
||||||
|
chip8_regs.pc+=2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void op_skeq_reg (word opcode)
|
static void op_skeq_reg (word opcode)
|
||||||
{
|
{
|
||||||
if (get_reg_value(opcode)==get_reg_value_2(opcode)) chip8_regs.pc+=2;
|
if (get_reg_value(opcode)==get_reg_value_2(opcode))
|
||||||
|
chip8_regs.pc+=2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void op_skne_reg (word opcode)
|
static void op_skne_reg (word opcode)
|
||||||
{
|
{
|
||||||
if (get_reg_value(opcode)!=get_reg_value_2(opcode)) chip8_regs.pc+=2;
|
if (get_reg_value(opcode)!=get_reg_value_2(opcode))
|
||||||
|
chip8_regs.pc+=2;
|
||||||
}
|
}
|
||||||
|
|
||||||
static void op_mov_const (word opcode)
|
static void op_mov_const (word opcode)
|
||||||
|
|
@ -244,7 +248,8 @@ static void op_misc (word opcode)
|
||||||
break;
|
break;
|
||||||
case 0x18:
|
case 0x18:
|
||||||
chip8_regs.sound=*reg;
|
chip8_regs.sound=*reg;
|
||||||
if (chip8_regs.sound) chip8_sound_on();
|
if (chip8_regs.sound)
|
||||||
|
chip8_sound_on();
|
||||||
break;
|
break;
|
||||||
case 0x1e:
|
case 0x1e:
|
||||||
chip8_regs.i+=(*reg);
|
chip8_regs.i+=(*reg);
|
||||||
|
|
@ -254,18 +259,20 @@ static void op_misc (word opcode)
|
||||||
break;
|
break;
|
||||||
case 0x33:
|
case 0x33:
|
||||||
i=*reg;
|
i=*reg;
|
||||||
for (j=0;i>=100;i-=100) j++;
|
for (j=0;i>=100;i-=100)
|
||||||
|
j++;
|
||||||
write_mem (chip8_regs.i,j);
|
write_mem (chip8_regs.i,j);
|
||||||
for (j=0;i>=10;i-=10) j++;
|
for (j=0;i>=10;i-=10)
|
||||||
|
j++;
|
||||||
write_mem (chip8_regs.i+1,j);
|
write_mem (chip8_regs.i+1,j);
|
||||||
write_mem (chip8_regs.i+2,i);
|
write_mem (chip8_regs.i+2,i);
|
||||||
break;
|
break;
|
||||||
case 0x55:
|
case 0x55:
|
||||||
for (i=0,j=(opcode>>8)&0x0f;i<=j;++i)
|
for (i=0,j=(opcode>>8)&0x0f; i<=j; ++i)
|
||||||
write_mem(chip8_regs.i+i,chip8_regs.alg[i]);
|
write_mem(chip8_regs.i+i,chip8_regs.alg[i]);
|
||||||
break;
|
break;
|
||||||
case 0x65:
|
case 0x65:
|
||||||
for (i=0,j=(opcode>>8)&0x0f;i<=j;++i)
|
for (i=0,j=(opcode>>8)&0x0f; i<=j; ++i)
|
||||||
chip8_regs.alg[i]=read_mem(chip8_regs.i+i);
|
chip8_regs.alg[i]=read_mem(chip8_regs.i+i);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -281,7 +288,8 @@ static void op_sprite (word opcode)
|
||||||
p=chip8_regs.i;
|
p=chip8_regs.i;
|
||||||
q=chip8_display+y*64;
|
q=chip8_display+y*64;
|
||||||
n=opcode&0x0f;
|
n=opcode&0x0f;
|
||||||
if (n+y>32) n=32-y;
|
if (n+y>32)
|
||||||
|
n=32-y;
|
||||||
for (collision=1;n;--n,q+=64)
|
for (collision=1;n;--n,q+=64)
|
||||||
{
|
{
|
||||||
for (y=read_mem(p++),x2=x;y;y<<=1,x2=(x2+1)&63)
|
for (y=read_mem(p++),x2=x;y;y<<=1,x2=(x2+1)&63)
|
||||||
|
|
@ -365,7 +373,6 @@ static void chip8_update_display(void)
|
||||||
rb->lcd_blit(lcd_framebuf[0], 24, 0, 64, 8, 64);
|
rb->lcd_blit(lcd_framebuf[0], 24, 0, 64, 8, 64);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
static void chip8_keyboard(void)
|
static void chip8_keyboard(void)
|
||||||
{
|
{
|
||||||
switch (rb->button_get(false))
|
switch (rb->button_get(false))
|
||||||
|
|
@ -419,15 +426,19 @@ static void chip8_execute(void)
|
||||||
(*(main_opcodes[opcode>>12]))(opcode&0x0fff); /* Emulate this opcode */
|
(*(main_opcodes[opcode>>12]))(opcode&0x0fff); /* Emulate this opcode */
|
||||||
}
|
}
|
||||||
/* Update timers */
|
/* Update timers */
|
||||||
if (chip8_regs.delay) --chip8_regs.delay;
|
if (chip8_regs.delay)
|
||||||
if (chip8_regs.sound) --chip8_regs.sound; /* How could we make sound on the archos? */
|
--chip8_regs.delay;
|
||||||
|
|
||||||
|
if (chip8_regs.sound)
|
||||||
|
--chip8_regs.sound; /* How could we make sound on the archos? */
|
||||||
/* Update the machine status */
|
/* Update the machine status */
|
||||||
chip8_update_display();
|
chip8_update_display();
|
||||||
chip8_keyboard();
|
chip8_keyboard();
|
||||||
rb->yield(); /* we should regulate the speed by timer query, sleep/yield */
|
rb->yield(); /* we should regulate the speed by timer query, sleep/yield */
|
||||||
|
|
||||||
for (i=key_pressed=0;i<16;++i) /* check if a key was first */
|
for (i=key_pressed=0;i<16;++i) /* check if a key was first */
|
||||||
if (chip8_keys[i]) key_pressed=i+1; /* pressed */
|
if (chip8_keys[i])
|
||||||
|
key_pressed=i+1; /* pressed */
|
||||||
if (key_pressed && key_pressed!=chip8_key_pressed)
|
if (key_pressed && key_pressed!=chip8_key_pressed)
|
||||||
chip8_key_pressed=key_pressed;
|
chip8_key_pressed=key_pressed;
|
||||||
else
|
else
|
||||||
|
|
@ -541,5 +552,4 @@ enum plugin_status plugin_start(struct plugin_api* api, void* parameter)
|
||||||
return chip8_run(filename) ? PLUGIN_OK : PLUGIN_ERROR;
|
return chip8_run(filename) ? PLUGIN_OK : PLUGIN_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif // #ifdef HAVE_LCD_BITMAP
|
#endif /* #ifdef HAVE_LCD_BITMAP */
|
||||||
#endif // #ifndef SIMULATOR
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue