diff options
Diffstat (limited to 'apps/plugins')
-rw-r--r-- | apps/plugins/chip8.c | 42 |
1 files changed, 18 insertions, 24 deletions
diff --git a/apps/plugins/chip8.c b/apps/plugins/chip8.c index 4ae32f1502..9c4b09e163 100644 --- a/apps/plugins/chip8.c +++ b/apps/plugins/chip8.c | |||
@@ -90,14 +90,14 @@ EXTERN byte chip8_mem[4096]; /* machine memory. program */ | |||
90 | /* is loaded at 0x200 */ | 90 | /* is loaded at 0x200 */ |
91 | EXTERN byte chip8_running; /* if 0, emulation stops */ | 91 | EXTERN byte chip8_running; /* if 0, emulation stops */ |
92 | 92 | ||
93 | EXTERN void chip8_execute (void); /* execute chip8_iperiod */ | 93 | EXTERN void chip8_execute (void); /* execute chip8_iperiod */ |
94 | /* opcodes */ | 94 | /* opcodes */ |
95 | EXTERN void chip8_reset (void); /* reset virtual machine */ | 95 | EXTERN void chip8_reset (void); /* reset virtual machine */ |
96 | EXTERN void chip8 (void); /* start chip8 emulation */ | 96 | EXTERN void chip8 (void); /* start chip8 emulation */ |
97 | 97 | ||
98 | EXTERN void chip8_sound_on (void); /* turn sound on */ | 98 | EXTERN void chip8_sound_on (void); /* turn sound on */ |
99 | EXTERN void chip8_sound_off (void); /* turn sound off */ | 99 | EXTERN void chip8_sound_off (void); /* turn sound off */ |
100 | EXTERN void chip8_interrupt (void); /* update keyboard, */ | 100 | EXTERN void chip8_interrupt (void); /* update keyboard, */ |
101 | /* display, etc. */ | 101 | /* display, etc. */ |
102 | 102 | ||
103 | #ifdef CHIP8_DEBUG | 103 | #ifdef CHIP8_DEBUG |
@@ -585,7 +585,7 @@ static void op_sprite (word opcode) | |||
585 | chip8_regs.alg[15]=collision^1; | 585 | chip8_regs.alg[15]=collision^1; |
586 | } | 586 | } |
587 | 587 | ||
588 | static math_fn math_opcodes[16]= | 588 | static const math_fn math_opcodes[16]= |
589 | { | 589 | { |
590 | math_mov, | 590 | math_mov, |
591 | math_or, | 591 | math_or, |
@@ -611,7 +611,7 @@ static void op_math (word opcode) | |||
611 | (get_reg_offset(opcode),get_reg_value_2(opcode)); | 611 | (get_reg_offset(opcode),get_reg_value_2(opcode)); |
612 | } | 612 | } |
613 | 613 | ||
614 | static opcode_fn main_opcodes[16]= | 614 | static const opcode_fn main_opcodes[16]= |
615 | { | 615 | { |
616 | op_system, | 616 | op_system, |
617 | op_jmp, | 617 | op_jmp, |
@@ -642,7 +642,7 @@ STATIC word chip8_trap; | |||
642 | STATIC void chip8_debug (word opcode,struct chip8_regs_struct *regs) | 642 | STATIC void chip8_debug (word opcode,struct chip8_regs_struct *regs) |
643 | { | 643 | { |
644 | int i; | 644 | int i; |
645 | byte hextable[16] = "0123456789ABCDEF"; | 645 | static const byte hextable[16] = "0123456789ABCDEF"; |
646 | byte v1[3] = "Vx\0"; | 646 | byte v1[3] = "Vx\0"; |
647 | byte v2[3] = "Vx\0"; | 647 | byte v2[3] = "Vx\0"; |
648 | v1[1] = hextable[(opcode>>8)&0x0f]; | 648 | v1[1] = hextable[(opcode>>8)&0x0f]; |
@@ -857,7 +857,7 @@ STATIC void chip8_execute(void) | |||
857 | /****************************************************************************/ | 857 | /****************************************************************************/ |
858 | STATIC void chip8_reset(void) | 858 | STATIC void chip8_reset(void) |
859 | { | 859 | { |
860 | static byte chip8_sprites[0x50]= | 860 | static const byte chip8_sprites[0x50]= |
861 | { | 861 | { |
862 | 0xf9,0x99,0xf2,0x62,0x27, | 862 | 0xf9,0x99,0xf2,0x62,0x27, |
863 | 0xf1,0xf8,0xff,0x1f,0x1f, | 863 | 0xf1,0xf8,0xff,0x1f,0x1f, |
@@ -869,7 +869,7 @@ STATIC void chip8_reset(void) | |||
869 | 0xf8,0xf8,0xff,0x8f,0x88, | 869 | 0xf8,0xf8,0xff,0x8f,0x88, |
870 | }; /* 4x5 pixel hexadecimal character font patterns */ | 870 | }; /* 4x5 pixel hexadecimal character font patterns */ |
871 | #ifdef CHIP8_SUPER | 871 | #ifdef CHIP8_SUPER |
872 | static byte schip_sprites[10*10]= | 872 | static const byte schip_sprites[10*10]= |
873 | { | 873 | { |
874 | 0x3C, 0x7E, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0x7E, 0x3C, /* 0 */ | 874 | 0x3C, 0x7E, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0xC3, 0x7E, 0x3C, /* 0 */ |
875 | 0x18, 0x38, 0x58, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, /* 1 */ | 875 | 0x18, 0x38, 0x58, 0x18, 0x18, 0x18, 0x18, 0x18, 0x18, 0x3C, /* 1 */ |
@@ -1186,7 +1186,7 @@ static unsigned char beep[]={255, | |||
1186 | 111,181,184,144, 17,148, 21,101,166,227,100, 86, 85, 85, 85}; | 1186 | 111,181,184,144, 17,148, 21,101,166,227,100, 86, 85, 85, 85}; |
1187 | 1187 | ||
1188 | /* callback to request more mp3 data */ | 1188 | /* callback to request more mp3 data */ |
1189 | void callback(unsigned char** start, size_t* size) | 1189 | static void callback(unsigned char** start, size_t* size) |
1190 | { | 1190 | { |
1191 | *start = beep; /* give it the same frame again */ | 1191 | *start = beep; /* give it the same frame again */ |
1192 | *size = sizeof(beep); | 1192 | *size = sizeof(beep); |
@@ -1314,7 +1314,7 @@ static void chip8_keyboard(void) | |||
1314 | /****************************************************************************/ | 1314 | /****************************************************************************/ |
1315 | static void chip8_interrupt (void) | 1315 | static void chip8_interrupt (void) |
1316 | { | 1316 | { |
1317 | unsigned long newtimer; | 1317 | unsigned long current_tick; |
1318 | unsigned long timer, runtime; | 1318 | unsigned long timer, runtime; |
1319 | 1319 | ||
1320 | chip8_update_display(); | 1320 | chip8_update_display(); |
@@ -1322,16 +1322,15 @@ static void chip8_interrupt (void) | |||
1322 | cycles ++; | 1322 | cycles ++; |
1323 | runtime = cycles * HZ / 50; | 1323 | runtime = cycles * HZ / 50; |
1324 | timer = starttimer + runtime; | 1324 | timer = starttimer + runtime; |
1325 | newtimer = *rb->current_tick; | 1325 | current_tick = *rb->current_tick; |
1326 | if (TIME_AFTER(timer, newtimer)) | 1326 | if (TIME_AFTER(timer, current_tick)) |
1327 | { | 1327 | { |
1328 | rb->sleep(timer - newtimer); | 1328 | rb->sleep(timer - current_tick); |
1329 | } | 1329 | } |
1330 | else | 1330 | else |
1331 | { | 1331 | { |
1332 | rb->yield(); | 1332 | rb->yield(); |
1333 | } | 1333 | } |
1334 | starttimer = newtimer - runtime; | ||
1335 | } | 1334 | } |
1336 | 1335 | ||
1337 | static bool chip8_init(const char* file) | 1336 | static bool chip8_init(const char* file) |
@@ -1347,12 +1346,12 @@ static bool chip8_init(const char* file) | |||
1347 | return false; | 1346 | return false; |
1348 | } | 1347 | } |
1349 | numread = rb->read(fd, chip8_mem+0x200, 4096-0x200); | 1348 | numread = rb->read(fd, chip8_mem+0x200, 4096-0x200); |
1349 | rb->close(fd); | ||
1350 | if (numread==-1) { | 1350 | if (numread==-1) { |
1351 | rb->lcd_puts(0, 6, "I/O Error."); | 1351 | rb->lcd_puts(0, 6, "I/O Error."); |
1352 | return false; | 1352 | return false; |
1353 | } | 1353 | } |
1354 | 1354 | ||
1355 | rb->close(fd); | ||
1356 | /* is there a c8k file (chip8 keys) ? */ | 1355 | /* is there a c8k file (chip8 keys) ? */ |
1357 | char c8kname[MAX_PATH]; | 1356 | char c8kname[MAX_PATH]; |
1358 | rb->strcpy(c8kname, file); | 1357 | rb->strcpy(c8kname, file); |
@@ -1389,7 +1388,7 @@ static bool chip8_init(const char* file) | |||
1389 | return true; | 1388 | return true; |
1390 | } | 1389 | } |
1391 | 1390 | ||
1392 | bool chip8_run(const char* file) | 1391 | static bool chip8_run(const char* file) |
1393 | { | 1392 | { |
1394 | int ok; | 1393 | int ok; |
1395 | 1394 | ||
@@ -1425,11 +1424,6 @@ bool chip8_run(const char* file) | |||
1425 | cycles = 0; | 1424 | cycles = 0; |
1426 | chip8(); | 1425 | chip8(); |
1427 | 1426 | ||
1428 | if (!ok) { | ||
1429 | rb->splash(HZ, "Error"); | ||
1430 | return false; | ||
1431 | } | ||
1432 | |||
1433 | #ifndef SIMULATOR | 1427 | #ifndef SIMULATOR |
1434 | if (!is_playing) | 1428 | if (!is_playing) |
1435 | { /* stop it if we used audio */ | 1429 | { /* stop it if we used audio */ |