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