Fix tabs in chip8 plugin

git-svn-id: svn://svn.rockbox.org/rockbox/trunk@24149 a1c6a512-1295-4272-9138-f99709370657
This commit is contained in:
Bertrik Sikken 2010-01-02 22:51:29 +00:00
parent ce8640d7b8
commit be9cf570a7

View file

@ -75,7 +75,7 @@ EXTERN struct chip8_regs_struct chip8_regs;
#ifdef CHIP8_SUPER #ifdef CHIP8_SUPER
#define CHIP8_WIDTH 128 #define CHIP8_WIDTH 128
#define CHIP8_HEIGHT 64 #define CHIP8_HEIGHT 64
EXTERN byte chip8_super; /* != 0 if in SCHIP display mode */ EXTERN byte chip8_super; /* != 0 if in SCHIP display mode */
#else #else
#define CHIP8_WIDTH 64 #define CHIP8_WIDTH 64
#define CHIP8_HEIGHT 32 #define CHIP8_HEIGHT 32
@ -129,7 +129,7 @@ EXTERN void chip8_debug (word opcode,struct chip8_regs_struct *regs);
*/ */
#ifndef STATIC #ifndef STATIC
#include <stdlib.h> /* for memset, etc. */ #include <stdlib.h> /* for memset, etc. */
#include <string.h> #include <string.h>
#define STATIC #define STATIC
#endif #endif
@ -148,7 +148,7 @@ STATIC byte chip8_keys[16]; /* if 1, key is held down */
STATIC byte chip8_display[CHIP8_WIDTH*CHIP8_HEIGHT]; /* 0xff if pixel is set, */ STATIC byte chip8_display[CHIP8_WIDTH*CHIP8_HEIGHT]; /* 0xff if pixel is set, */
/* 0x00 otherwise */ /* 0x00 otherwise */
#ifdef CHIP8_SUPER #ifdef CHIP8_SUPER
STATIC byte chip8_super; /* != 0 if in SCHIP display mode */ STATIC byte chip8_super; /* != 0 if in SCHIP display mode */
#endif #endif
STATIC byte chip8_mem[4096]; /* machine memory. program */ STATIC byte chip8_mem[4096]; /* machine memory. program */
/* is loaded at 0x200 */ /* is loaded at 0x200 */
@ -179,7 +179,7 @@ static void op_call (word opcode)
chip8_regs.pc=opcode; chip8_regs.pc=opcode;
#ifdef CHIP8_DEBUG #ifdef CHIP8_DEBUG
if(chip8_regs.sp < 0x1c0) if(chip8_regs.sp < 0x1c0)
printf("warning: more than 16 subroutine calls, sp=%x\n", chip8_regs.sp); printf("warning: more than 16 subroutine calls, sp=%x\n", chip8_regs.sp);
#endif #endif
} }
@ -199,14 +199,14 @@ static void op_key (word opcode)
else if ((opcode&0xff)==0xa1) /* sknp */ else if ((opcode&0xff)==0xa1) /* sknp */
cp_value=0; cp_value=0;
else { else {
DBG_(printf("unhandled key opcode 0x%x\n", opcode)); DBG_(printf("unhandled key opcode 0x%x\n", opcode));
return; return;
} }
key = get_reg_value(opcode)&0x0f; key = get_reg_value(opcode)&0x0f;
#ifdef CHIP8_DEBUG #ifdef CHIP8_DEBUG
if (!tested[key]) { if (!tested[key]) {
tested[key] = 1; tested[key] = 1;
DBG_(printf("testing key %d\n", key)); DBG_(printf("testing key %d\n", key));
} }
#endif #endif
key_value=chip8_keys[key]; key_value=chip8_keys[key];
@ -336,10 +336,10 @@ static void scroll_down(word opcode)
byte *dst = chip8_display + CHIP8_WIDTH*CHIP8_HEIGHT -1; byte *dst = chip8_display + CHIP8_WIDTH*CHIP8_HEIGHT -1;
byte *src = dst - n*CHIP8_WIDTH; byte *src = dst - n*CHIP8_WIDTH;
while(src >= chip8_display) { while(src >= chip8_display) {
*dst-- = *src--; *dst-- = *src--;
} }
while(dst >= chip8_display) { while(dst >= chip8_display) {
*dst-- = 0; *dst-- = 0;
} }
} }
/* SUPER: scroll 4 pixels left! */ /* SUPER: scroll 4 pixels left! */
@ -350,15 +350,15 @@ static void scroll_left(void)
byte *eol = chip8_display + CHIP8_WIDTH; byte *eol = chip8_display + CHIP8_WIDTH;
byte *eoi = chip8_display + CHIP8_WIDTH*CHIP8_HEIGHT; byte *eoi = chip8_display + CHIP8_WIDTH*CHIP8_HEIGHT;
while(eol <= eoi) { while(eol <= eoi) {
src+=4; src+=4;
while(src < eol) { while(src < eol) {
*dst++ = *src++; *dst++ = *src++;
} }
*dst++ = 0; *dst++ = 0;
*dst++ = 0; *dst++ = 0;
*dst++ = 0; *dst++ = 0;
*dst++ = 0; *dst++ = 0;
eol += CHIP8_WIDTH; eol += CHIP8_WIDTH;
} }
} }
static void scroll_right(void) static void scroll_right(void)
@ -367,15 +367,15 @@ static void scroll_right(void)
byte *src = dst; byte *src = dst;
byte *bol = chip8_display + CHIP8_WIDTH*(CHIP8_HEIGHT-1); byte *bol = chip8_display + CHIP8_WIDTH*(CHIP8_HEIGHT-1);
while(bol >= chip8_display) { while(bol >= chip8_display) {
src-=4; src-=4;
while(src >= bol) { while(src >= bol) {
*dst-- = *src--; *dst-- = *src--;
} }
*dst-- = 0; *dst-- = 0;
*dst-- = 0; *dst-- = 0;
*dst-- = 0; *dst-- = 0;
*dst-- = 0; *dst-- = 0;
bol -= CHIP8_WIDTH; bol -= CHIP8_WIDTH;
} }
} }
#endif #endif
@ -386,25 +386,25 @@ static void op_system (word opcode)
{ {
#ifdef CHIP8_SUPER #ifdef CHIP8_SUPER
case 0xfb: case 0xfb:
scroll_right(); scroll_right();
break; break;
case 0xfc: case 0xfc:
scroll_left(); scroll_left();
break; break;
case 0xfd: case 0xfd:
DBG_(printf("SUPER: quit the emulator\n")); DBG_(printf("SUPER: quit the emulator\n"));
chip8_reset(); chip8_reset();
break; break;
case 0xfe: case 0xfe:
DBG_(printf("SUPER: set CHIP-8 graphic mode\n")); DBG_(printf("SUPER: set CHIP-8 graphic mode\n"));
memset (chip8_display,0,sizeof(chip8_display)); memset (chip8_display,0,sizeof(chip8_display));
chip8_super = 0; chip8_super = 0;
break; break;
case 0xff: case 0xff:
DBG_(printf("SUPER: set SCHIP graphic mode\n")); DBG_(printf("SUPER: set SCHIP graphic mode\n"));
memset (chip8_display,0,sizeof(chip8_display)); memset (chip8_display,0,sizeof(chip8_display));
chip8_super = 1; chip8_super = 1;
break; break;
#endif #endif
case 0xe0: case 0xe0:
memset (chip8_display,0,sizeof(chip8_display)); memset (chip8_display,0,sizeof(chip8_display));
@ -417,15 +417,15 @@ static void op_system (word opcode)
break; break;
default: default:
#ifdef CHIP8_SUPER #ifdef CHIP8_SUPER
if ((opcode & 0xF0) == 0xC0) if ((opcode & 0xF0) == 0xC0)
scroll_down(opcode); scroll_down(opcode);
else else
#endif #endif
{ {
DBG_(printf("unhandled system opcode 0x%x\n", opcode)); DBG_(printf("unhandled system opcode 0x%x\n", opcode));
chip8_running = 3; chip8_running = 3;
} }
break; break;
} }
} }
@ -438,41 +438,41 @@ static void op_misc (word opcode)
reg=get_reg_offset(opcode); reg=get_reg_offset(opcode);
switch ((byte)opcode) switch ((byte)opcode)
{ {
case 0x07: /* gdelay */ case 0x07: /* gdelay */
*reg=chip8_regs.delay; *reg=chip8_regs.delay;
break; break;
case 0x0a: /* key */ case 0x0a: /* key */
#ifdef CHIP8_DEBUG #ifdef CHIP8_DEBUG
if(firstwait) { if(firstwait) {
printf("waiting for key press\n"); printf("waiting for key press\n");
firstwait = 0; firstwait = 0;
} }
#endif #endif
if (chip8_key_pressed) if (chip8_key_pressed)
*reg=chip8_key_pressed-1; *reg=chip8_key_pressed-1;
else else
chip8_regs.pc-=2; chip8_regs.pc-=2;
break; break;
case 0x15: /* sdelay */ case 0x15: /* sdelay */
chip8_regs.delay=*reg; chip8_regs.delay=*reg;
break; break;
case 0x18: /* ssound */ case 0x18: /* ssound */
chip8_regs.sound=*reg; chip8_regs.sound=*reg;
if (chip8_regs.sound) if (chip8_regs.sound)
chip8_sound_on(); chip8_sound_on();
break; break;
case 0x1e: /* adi */ case 0x1e: /* adi */
chip8_regs.i+=(*reg); chip8_regs.i+=(*reg);
break; break;
case 0x29: /* font */ case 0x29: /* font */
chip8_regs.i=((word)(*reg&0x0f))*5; chip8_regs.i=((word)(*reg&0x0f))*5;
break; break;
#ifdef CHIP8_SUPER #ifdef CHIP8_SUPER
case 0x30: /* xfont */ case 0x30: /* xfont */
chip8_regs.i=((word)(*reg&0x0f))*10+0x50; chip8_regs.i=((word)(*reg&0x0f))*10+0x50;
break; break;
#endif #endif
case 0x33: /* bcd */ case 0x33: /* bcd */
i=*reg; i=*reg;
for (j=0;i>=100;i-=100) for (j=0;i>=100;i-=100)
j++; j++;
@ -482,25 +482,25 @@ static void op_misc (word opcode)
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: /* str */ case 0x55: /* str */
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: /* ldr */ case 0x65: /* ldr */
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;
#ifdef CHIP8_SUPER #ifdef CHIP8_SUPER
case 0x75: case 0x75:
DBG_(printf("SUPER: save V0..V%x (X<8) in the HP48 flags\n", (opcode>>8)&0x0f)); DBG_(printf("SUPER: save V0..V%x (X<8) in the HP48 flags\n", (opcode>>8)&0x0f));
break; break;
case 0x85: case 0x85:
DBG_(printf("SUPER: load V0..V%x (X<8) from the HP48 flags\n", (opcode>>8)&0x0f)); DBG_(printf("SUPER: load V0..V%x (X<8) from the HP48 flags\n", (opcode>>8)&0x0f));
break; break;
#endif #endif
default: default:
DBG_(printf("unhandled misc opcode 0x%x\n", opcode)); DBG_(printf("unhandled misc opcode 0x%x\n", opcode));
break; break;
} }
} }
@ -515,59 +515,59 @@ static void op_sprite (word opcode)
n=opcode&0x0f; n=opcode&0x0f;
#ifdef CHIP8_SUPER #ifdef CHIP8_SUPER
if (chip8_super) { if (chip8_super) {
/*printf("SUPER: sprite(%x)\n", opcode);*/ /*printf("SUPER: sprite(%x)\n", opcode);*/
x &= 128-1; x &= 128-1;
y &= 64-1; y &= 64-1;
q=chip8_display+y*CHIP8_WIDTH; q=chip8_display+y*CHIP8_WIDTH;
if(n == 0) if(n == 0)
{ /* 16x16 sprite */ { /* 16x16 sprite */
n = 16; n = 16;
if (n+y>64) if (n+y>64)
n=64-y; n=64-y;
for (collision=1;n;--n,q+=CHIP8_WIDTH) for (collision=1;n;--n,q+=CHIP8_WIDTH)
{ {
/* first 8 bits */ /* first 8 bits */
for (y=read_mem(p++),x2=x;y;y<<=1,x2=(x2+1)&(CHIP8_WIDTH-1)) for (y=read_mem(p++),x2=x;y;y<<=1,x2=(x2+1)&(CHIP8_WIDTH-1))
if (y&0x80) if (y&0x80)
collision&=(q[x2]^=0xff); collision&=(q[x2]^=0xff);
x2=(x+8)&(CHIP8_WIDTH-1); x2=(x+8)&(CHIP8_WIDTH-1);
/* last 8 bits */ /* last 8 bits */
for (y=read_mem(p++);y;y<<=1,x2=(x2+1)&(CHIP8_WIDTH-1)) for (y=read_mem(p++);y;y<<=1,x2=(x2+1)&(CHIP8_WIDTH-1))
if (y&0x80) if (y&0x80)
collision&=(q[x2]^=0xff); collision&=(q[x2]^=0xff);
} }
} }
else { else {
/* 8xn sprite */ /* 8xn sprite */
if (n+y>64) if (n+y>64)
n=64-y; n=64-y;
for (collision=1;n;--n,q+=CHIP8_WIDTH) for (collision=1;n;--n,q+=CHIP8_WIDTH)
{ {
for (y=read_mem(p++),x2=x;y;y<<=1,x2=(x2+1)&(CHIP8_WIDTH-1)) for (y=read_mem(p++),x2=x;y;y<<=1,x2=(x2+1)&(CHIP8_WIDTH-1))
if (y&0x80) if (y&0x80)
collision&=(q[x2]^=0xff); collision&=(q[x2]^=0xff);
} }
} }
} }
else { else {
x &= 64-1; x &= 64-1;
y &= 32-1; y &= 32-1;
q=chip8_display+y*CHIP8_WIDTH*2; q=chip8_display+y*CHIP8_WIDTH*2;
if(n == 0) if(n == 0)
n = 16; n = 16;
if (n+y>32) if (n+y>32)
n=32-y; n=32-y;
for (collision=1;n;--n,q+=CHIP8_WIDTH*2) for (collision=1;n;--n,q+=CHIP8_WIDTH*2)
{ {
for (y=read_mem(p++),x2=x*2;y;y<<=1,x2=(x2+2)&(CHIP8_WIDTH-1)) for (y=read_mem(p++),x2=x*2;y;y<<=1,x2=(x2+2)&(CHIP8_WIDTH-1))
if (y&0x80) { if (y&0x80) {
q[x2]^=0xff; q[x2]^=0xff;
q[x2+1]^=0xff; q[x2+1]^=0xff;
q[x2+CHIP8_WIDTH]^=0xff; q[x2+CHIP8_WIDTH]^=0xff;
q[x2+CHIP8_WIDTH+1]^=0xff; q[x2+CHIP8_WIDTH+1]^=0xff;
collision &= q[x2]|q[x2+1]|q[x2+CHIP8_WIDTH]|q[x2+CHIP8_WIDTH+1]; collision &= q[x2]|q[x2+1]|q[x2+CHIP8_WIDTH]|q[x2+CHIP8_WIDTH+1];
} }
} }
} }
#else #else
x &= 64-1; x &= 64-1;
@ -579,7 +579,7 @@ static void op_sprite (word opcode)
{ {
for (y=read_mem(p++),x2=x;y;y<<=1,x2=(x2+1)&(CHIP8_WIDTH-1)) for (y=read_mem(p++),x2=x;y;y<<=1,x2=(x2+1)&(CHIP8_WIDTH-1))
if (y&0x80) if (y&0x80)
collision&=(q[x2]^=0xff); collision&=(q[x2]^=0xff);
} }
#endif #endif
chip8_regs.alg[15]=collision^1; chip8_regs.alg[15]=collision^1;
@ -650,163 +650,163 @@ STATIC void chip8_debug (word opcode,struct chip8_regs_struct *regs)
printf ("PC=%04X: %04X - ",regs->pc,opcode); printf ("PC=%04X: %04X - ",regs->pc,opcode);
switch (opcode>>12) { switch (opcode>>12) {
case 0: case 0:
if ((opcode&0xff0) == 0xc0) { if ((opcode&0xff0) == 0xc0) {
printf ("SCD %01X ; Scroll down n lines",opcode&0xf); printf ("SCD %01X ; Scroll down n lines",opcode&0xf);
} }
else switch (opcode&0xfff) { else switch (opcode&0xfff) {
case 0xe0: case 0xe0:
printf ("CLS ; Clear screen"); printf ("CLS ; Clear screen");
break; break;
case 0xee: case 0xee:
printf ("RET ; Return from subroutine call"); printf ("RET ; Return from subroutine call");
break; break;
case 0xfb: case 0xfb:
printf("SCR ; Scroll right"); printf("SCR ; Scroll right");
break; break;
case 0xfc: case 0xfc:
printf("SCL ; Scroll left"); printf("SCL ; Scroll left");
break; break;
case 0xfd: case 0xfd:
printf("EXIT ; Terminate the interpreter"); printf("EXIT ; Terminate the interpreter");
break; break;
case 0xfe: case 0xfe:
printf("LOW ; Disable extended screen mode"); printf("LOW ; Disable extended screen mode");
break; break;
case 0xff: case 0xff:
printf("HIGH ; Enable extended screen mode"); printf("HIGH ; Enable extended screen mode");
break; break;
default: default:
printf ("SYS %03X ; Unknown system call",opcode&0xff); printf ("SYS %03X ; Unknown system call",opcode&0xff);
} }
break; break;
case 1: case 1:
printf ("JP %03X ; Jump to address",opcode&0xfff); printf ("JP %03X ; Jump to address",opcode&0xfff);
break; break;
case 2: case 2:
printf ("CALL %03X ; Call subroutine",opcode&0xfff); printf ("CALL %03X ; Call subroutine",opcode&0xfff);
break; break;
case 3: case 3:
printf ("SE %s,%02X ; Skip if register == constant",v1,opcode&0xff); printf ("SE %s,%02X ; Skip if register == constant",v1,opcode&0xff);
break; break;
case 4: case 4:
printf ("SNE %s,%02X ; Skip if register <> constant",v1,opcode&0xff); printf ("SNE %s,%02X ; Skip if register <> constant",v1,opcode&0xff);
break; break;
case 5: case 5:
printf ("SE %s,%s ; Skip if register == register",v1,v2); printf ("SE %s,%s ; Skip if register == register",v1,v2);
break; break;
case 6: case 6:
printf ("LD %s,%02X ; Set VX = Byte",v1,opcode&0xff); printf ("LD %s,%02X ; Set VX = Byte",v1,opcode&0xff);
break; break;
case 7: case 7:
printf ("ADD %s,%02X ; Set VX = VX + Byte",v1,opcode&0xff); printf ("ADD %s,%02X ; Set VX = VX + Byte",v1,opcode&0xff);
break; break;
case 8: case 8:
switch (opcode&0x0f) { switch (opcode&0x0f) {
case 0: case 0:
printf ("LD %s,%s ; Set VX = VY, VF updates",v1,v2); printf ("LD %s,%s ; Set VX = VY, VF updates",v1,v2);
break; break;
case 1: case 1:
printf ("OR %s,%s ; Set VX = VX | VY, VF updates",v1,v2); printf ("OR %s,%s ; Set VX = VX | VY, VF updates",v1,v2);
break; break;
case 2: case 2:
printf ("AND %s,%s ; Set VX = VX & VY, VF updates",v1,v2); printf ("AND %s,%s ; Set VX = VX & VY, VF updates",v1,v2);
break; break;
case 3: case 3:
printf ("XOR %s,%s ; Set VX = VX ^ VY, VF updates",v1,v2); printf ("XOR %s,%s ; Set VX = VX ^ VY, VF updates",v1,v2);
break; break;
case 4: case 4:
printf ("ADD %s,%s ; Set VX = VX + VY, VF = carry",v1,v2); printf ("ADD %s,%s ; Set VX = VX + VY, VF = carry",v1,v2);
break; break;
case 5: case 5:
printf ("SUB %s,%s ; Set VX = VX - VY, VF = !borrow",v1,v2); printf ("SUB %s,%s ; Set VX = VX - VY, VF = !borrow",v1,v2);
break; break;
case 6: case 6:
printf ("SHR %s,%s ; Set VX = VX >> 1, VF = carry",v1,v2); printf ("SHR %s,%s ; Set VX = VX >> 1, VF = carry",v1,v2);
break; break;
case 7: case 7:
printf ("SUBN %s,%s ; Set VX = VY - VX, VF = !borrow",v1,v2); printf ("SUBN %s,%s ; Set VX = VY - VX, VF = !borrow",v1,v2);
break; break;
case 14: case 14:
printf ("SHL %s,%s ; Set VX = VX << 1, VF = carry",v1,v2); printf ("SHL %s,%s ; Set VX = VX << 1, VF = carry",v1,v2);
break; break;
default: default:
printf ("Illegal opcode"); printf ("Illegal opcode");
} }
break; break;
case 9: case 9:
printf ("SNE %s,%s ; Skip next instruction iv VX!=VY",v1,v2); printf ("SNE %s,%s ; Skip next instruction iv VX!=VY",v1,v2);
break; break;
case 10: case 10:
printf ("LD I,%03X ; Set I = Addr",opcode&0xfff); printf ("LD I,%03X ; Set I = Addr",opcode&0xfff);
break; break;
case 11: case 11:
printf ("JP V0,%03X ; Jump to Addr + V0",opcode&0xfff); printf ("JP V0,%03X ; Jump to Addr + V0",opcode&0xfff);
break; break;
case 12: case 12:
printf ("RND %s,%02X ; Set VX = random & Byte",v1,opcode&0xff); printf ("RND %s,%02X ; Set VX = random & Byte",v1,opcode&0xff);
break; break;
case 13: case 13:
printf ("DRW %s,%s,%X ; Draw n byte sprite stored at [i] at VX,VY. Set VF = collision",v1,v2,opcode&0x0f); printf ("DRW %s,%s,%X ; Draw n byte sprite stored at [i] at VX,VY. Set VF = collision",v1,v2,opcode&0x0f);
break; break;
case 14: case 14:
switch (opcode&0xff) { switch (opcode&0xff) {
case 0x9e: case 0x9e:
printf ("SKP %s ; Skip next instruction if key VX down",v1); printf ("SKP %s ; Skip next instruction if key VX down",v1);
break; break;
case 0xa1: case 0xa1:
printf ("SKNP %s ; Skip next instruction if key VX up",v1); printf ("SKNP %s ; Skip next instruction if key VX up",v1);
break; break;
default: default:
printf ("%04X ; Illegal opcode", opcode); printf ("%04X ; Illegal opcode", opcode);
} }
break; break;
case 15: case 15:
switch (opcode&0xff) { switch (opcode&0xff) {
case 0x07: case 0x07:
printf ("LD %s,DT ; Set VX = delaytimer",v1); printf ("LD %s,DT ; Set VX = delaytimer",v1);
break; break;
case 0x0a: case 0x0a:
printf ("LD %s,K ; Set VX = key, wait for keypress",v1); printf ("LD %s,K ; Set VX = key, wait for keypress",v1);
break; break;
case 0x15: case 0x15:
printf ("LD DT,%s ; Set delaytimer = VX",v1); printf ("LD DT,%s ; Set delaytimer = VX",v1);
break; break;
case 0x18: case 0x18:
printf ("LD ST,%s ; Set soundtimer = VX",v1); printf ("LD ST,%s ; Set soundtimer = VX",v1);
break; break;
case 0x1e: case 0x1e:
printf ("ADD I,%s ; Set I = I + VX",v1); printf ("ADD I,%s ; Set I = I + VX",v1);
break; break;
case 0x29: case 0x29:
printf ("LD LF,%s ; Point I to 5 byte numeric sprite for value in VX",v1); printf ("LD LF,%s ; Point I to 5 byte numeric sprite for value in VX",v1);
break; break;
case 0x30: case 0x30:
printf ("LD HF,%s ; Point I to 10 byte numeric sprite for value in VX",v1); printf ("LD HF,%s ; Point I to 10 byte numeric sprite for value in VX",v1);
break; break;
case 0x33: case 0x33:
printf ("LD B,%s ; Store BCD of VX in [I], [I+1], [I+2]",v1); printf ("LD B,%s ; Store BCD of VX in [I], [I+1], [I+2]",v1);
break; break;
case 0x55: case 0x55:
printf ("LD [I],%s ; Store V0..VX in [I]..[I+X]",v1); printf ("LD [I],%s ; Store V0..VX in [I]..[I+X]",v1);
break; break;
case 0x65: case 0x65:
printf ("LD %s,[I] ; Read V0..VX from [I]..[I+X]",v1); printf ("LD %s,[I] ; Read V0..VX from [I]..[I+X]",v1);
break; break;
case 0x75: case 0x75:
printf ("LD R,%s ; Store V0..VX in RPL user flags (X<=7)",v1); printf ("LD R,%s ; Store V0..VX in RPL user flags (X<=7)",v1);
break; break;
case 0x85: case 0x85:
printf ("LD %s,R ; Read V0..VX from RPL user flags (X<=7)",v1); printf ("LD %s,R ; Read V0..VX from RPL user flags (X<=7)",v1);
break; break;
default: default:
printf ("%04X ; Illegal opcode", opcode); printf ("%04X ; Illegal opcode", opcode);
} }
break; break;
} }
printf ("\n; Registers: "); printf ("\n; Registers: ");
for (i=0;i<16;++i) printf ("%02x ",(regs->alg[i])&0xff); for (i=0;i<16;++i) printf ("%02x ",(regs->alg[i])&0xff);
printf ("\n; Index: %03x Stack:%03x Delay:%02x Sound:%02x\n", printf ("\n; Index: %03x Stack:%03x Delay:%02x Sound:%02x\n",
regs->i&0xfff,regs->sp&0xfff,regs->delay&0xff,regs->sound&0xff); regs->i&0xfff,regs->sp&0xfff,regs->delay&0xff,regs->sound&0xff);
} }
#endif #endif
@ -820,15 +820,15 @@ STATIC void chip8_execute(void)
word opcode; word opcode;
for (i = chip8_iperiod ; i ;--i) for (i = chip8_iperiod ; i ;--i)
{ {
/* Fetch the opcode */ /* Fetch the opcode */
opcode=(read_mem(chip8_regs.pc)<<8)+read_mem(chip8_regs.pc+1); opcode=(read_mem(chip8_regs.pc)<<8)+read_mem(chip8_regs.pc+1);
#ifdef CHIP8_DEBUG #ifdef CHIP8_DEBUG
/* Check if trap address has been reached */ /* Check if trap address has been reached */
if ((chip8_regs.pc&4095)==chip8_trap) if ((chip8_regs.pc&4095)==chip8_trap)
chip8_trace=1; chip8_trace=1;
/* Call the debugger if chip8_trace!=0 */ /* Call the debugger if chip8_trace!=0 */
if (chip8_trace) if (chip8_trace)
chip8_debug (opcode,&chip8_regs); chip8_debug (opcode,&chip8_regs);
#endif #endif
chip8_regs.pc+=2; chip8_regs.pc+=2;
(*(main_opcodes[opcode>>12]))(opcode&0x0fff); /* Emulate this opcode */ (*(main_opcodes[opcode>>12]))(opcode&0x0fff); /* Emulate this opcode */
@ -844,7 +844,7 @@ STATIC void chip8_execute(void)
chip8_interrupt (); chip8_interrupt ();
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]) /* pressed */ if (chip8_keys[i]) /* pressed */
key_pressed=i+1; key_pressed=i+1;
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;
@ -871,16 +871,16 @@ STATIC void chip8_reset(void)
#ifdef CHIP8_SUPER #ifdef CHIP8_SUPER
static byte schip_sprites[10*10]= static byte schip_sprites[10*10]=
{ {
0x3C, 0x7E, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0x7E, 0x3C, /* 0 */ 0x3C, 0x7E, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0x7E, 0x3C, /* 0 */
0x18, 0x38, 0x58, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, /* 1 */ 0x18, 0x38, 0x58, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, /* 1 */
0x3E, 0x7F, 0xC3, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xFF, 0xFF, /* 2 */ 0x3E, 0x7F, 0xC3, 0x06, 0x0C, 0x18, 0x30, 0x60, 0xFF, 0xFF, /* 2 */
0x3C, 0x7E, 0xC3, 0x03, 0x0E, 0x0E, 0x03, 0xC3, 0x7E, 0x3C, /* 3 */ 0x3C, 0x7E, 0xC3, 0x03, 0x0E, 0x0E, 0x03, 0xC3, 0x7E, 0x3C, /* 3 */
0x06, 0x0E, 0x1E, 0x36, 0x66, 0xC6, 0xFF, 0xFF, 0x06, 0x06, /* 4 */ 0x06, 0x0E, 0x1E, 0x36, 0x66, 0xC6, 0xFF, 0xFF, 0x06, 0x06, /* 4 */
0xFF, 0xFF, 0xC0, 0xC0, 0xFC, 0xFE, 0x03, 0xC3, 0x7E, 0x3C, /* 5 */ 0xFF, 0xFF, 0xC0, 0xC0, 0xFC, 0xFE, 0x03, 0xC3, 0x7E, 0x3C, /* 5 */
0x3E, 0x7C, 0xC0, 0xC0, 0xFC, 0xFE, 0xC3, 0xC3, 0x7E, 0x3C, /* 6 */ 0x3E, 0x7C, 0xC0, 0xC0, 0xFC, 0xFE, 0xC3, 0xC3, 0x7E, 0x3C, /* 6 */
0xFF, 0xFF, 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x60, 0x60, /* 7 */ 0xFF, 0xFF, 0x03, 0x06, 0x0C, 0x18, 0x30, 0x60, 0x60, 0x60, /* 7 */
0x3C, 0x7E, 0xC3, 0xC3, 0x7E, 0x7E, 0xC3, 0xC3, 0x7E, 0x3C, /* 8 */ 0x3C, 0x7E, 0xC3, 0xC3, 0x7E, 0x7E, 0xC3, 0xC3, 0x7E, 0x3C, /* 8 */
0x3C, 0x7E, 0xC3, 0xC3, 0x7F, 0x3F, 0x03, 0x03, 0x3E, 0x7C, /* 9 */ 0x3C, 0x7E, 0xC3, 0xC3, 0x7F, 0x3F, 0x03, 0x03, 0x3E, 0x7C, /* 9 */
}; /* 8x10 pixel font patterns (only 10) */ }; /* 8x10 pixel font patterns (only 10) */
#endif #endif
byte i; byte i;
@ -1325,11 +1325,11 @@ static void chip8_interrupt (void)
newtimer = *rb->current_tick; newtimer = *rb->current_tick;
if (TIME_AFTER(timer, newtimer)) if (TIME_AFTER(timer, newtimer))
{ {
rb->sleep(timer - newtimer); rb->sleep(timer - newtimer);
} }
else else
{ {
rb->yield(); rb->yield();
} }
starttimer = newtimer - runtime; starttimer = newtimer - runtime;
} }
@ -1343,13 +1343,13 @@ static bool chip8_init(const char* file)
fd = rb->open(file, O_RDONLY); fd = rb->open(file, O_RDONLY);
if (fd < 0) { if (fd < 0) {
rb->lcd_puts(0, 6, "File Error."); rb->lcd_puts(0, 6, "File Error.");
return false; return false;
} }
numread = rb->read(fd, chip8_mem+0x200, 4096-0x200); numread = rb->read(fd, chip8_mem+0x200, 4096-0x200);
if (numread==-1) { if (numread==-1) {
rb->lcd_puts(0, 6, "I/O Error."); rb->lcd_puts(0, 6, "I/O Error.");
return false; return false;
} }
rb->close(fd); rb->close(fd);
@ -1357,34 +1357,34 @@ static bool chip8_init(const char* file)
char c8kname[MAX_PATH]; char c8kname[MAX_PATH];
rb->strcpy(c8kname, file); rb->strcpy(c8kname, file);
for(i=0; i<16; i++) { for(i=0; i<16; i++) {
chip8_virtual_keys[i] = 0; chip8_virtual_keys[i] = 0;
chip8_keymap[i] = i; chip8_keymap[i] = i;
} }
len = rb->strlen(c8kname); len = rb->strlen(c8kname);
c8kname[len-2] = '8'; c8kname[len-2] = '8';
c8kname[len-1] = 'k'; c8kname[len-1] = 'k';
fd = rb->open(c8kname, O_RDONLY); fd = rb->open(c8kname, O_RDONLY);
if (fd >= 0) { if (fd >= 0) {
rb->lcd_puts(0, 6, "File&Keymap OK."); rb->lcd_puts(0, 6, "File&Keymap OK.");
numread = rb->read(fd, chip8_keymap, 16); numread = rb->read(fd, chip8_keymap, 16);
rb->close(fd); rb->close(fd);
} }
else else
{ {
rb->lcd_puts(0, 6, "File OK."); rb->lcd_puts(0, 6, "File OK.");
} }
for(i=0; i<16; i++) { for(i=0; i<16; i++) {
if (chip8_keymap[i] >= '0' if (chip8_keymap[i] >= '0'
&& chip8_keymap[i] <= '9') && chip8_keymap[i] <= '9')
chip8_keymap[i] -= '0'; chip8_keymap[i] -= '0';
else if (chip8_keymap[i] >= 'A' else if (chip8_keymap[i] >= 'A'
&& chip8_keymap[i] <= 'F') && chip8_keymap[i] <= 'F')
chip8_keymap[i] -= 'A' - 10; chip8_keymap[i] -= 'A' - 10;
else if (chip8_keymap[i] >= 'a' else if (chip8_keymap[i] >= 'a'
&& chip8_keymap[i] <= 'f') && chip8_keymap[i] <= 'f')
chip8_keymap[i] -= 'a' - 10; chip8_keymap[i] -= 'a' - 10;
else else
chip8_keymap[i] %= 16; chip8_keymap[i] %= 16;
} }
return true; return true;
} }
@ -1438,10 +1438,10 @@ bool chip8_run(const char* file)
#endif #endif
if (chip8_running == 3) { if (chip8_running == 3) {
/* unsupported instruction */ /* unsupported instruction */
rb->splash(HZ, "Error: Unsupported" rb->splash(HZ, "Error: Unsupported"
#ifndef CHIP8_SUPER #ifndef CHIP8_SUPER
" CHIP-8 instruction. (maybe S-CHIP)" " CHIP-8 instruction. (maybe S-CHIP)"
#else #else
" (S)CHIP-8 instruction." " (S)CHIP-8 instruction."
#endif #endif