I'm trying to port my CHIP-8 emulator from C# to C for the Prizm. I'm having a problem loading files, though:

Code:
void LoadFile(void)
{
   char errcode = 0;
   char fh = 0;
   PrintXY(1,2,"XXEnter filename:",TEXT_MODE_NORMAL, TEXT_COLOR_BLUE);
 
   getTextLine(inputBuf, INPUT_MAX_LEN, 1, 3, INPUT_MAX_LEN, INPUT_MODE_TEXT);   
   int a = strlen(inputBuf);
   inputBuf[a] = '.'; //add file extension
   inputBuf[a+1] = 'c';
   inputBuf[a+2] = 'h';
   inputBuf[a+3] = '8';
   for (int x = 0; inputBuf[x]!=NULL && x < INPUT_MAX_LEN+4; x++)
   {
      file[x + FILENAME_OFFSET] = (unsigned short)inputBuf[x];   
   }
   if (0 > (fh = Bfile_OpenFile_OS(file,0x01))) {
           errcode= ERR_FILE_NOT_FOUND;
   }
   if (fh >= 0)
      Bfile_CloseFile_OS(fh);
   if (0 <= (fh = Bfile_OpenFile_OS(file,0x01)) && errcode != ERR_FILE_NOT_FOUND) {
         if (Bfile_ReadFile_OS(fh,(void*)(RAM+0x0200),144,0) < 0) //this is where the file read fails
            PrintXY(1,6,"XXERR",TEXT_MODE_NORMAL, TEXT_COLOR_BLUE);
         Bfile_CloseFile_OS(fh);
   }
   if (errcode == ERR_FILE_NOT_FOUND)
      PrintXY(1,7,"XXERR: Not found",TEXT_MODE_NORMAL, TEXT_COLOR_BLUE);
 
}

It should prompt for a filename without the extension. The file is a .ch8 ROM, and it fails to load the file into memory. The file that I'm using is exactly 144 bytes, so I'm using that magic number for testing. I would like to get it working with files of any size in the future, but right now I want to get this file loaded successfully.
*bump*
I've fixed the file loading problem. Smile There seems to be a few problems with the CPU emulation and drawing sprites, so I'll work on that next.
Sorry, I got so caught up working on graph3DP last night that I utterly failed to get to your topic. Smile I think this is a great idea for a project, and I hope that it goes very smoothly. As you probably know, benryves wrote such an emulator for the TI-8x calculators, so perhaps he might be able to answer questions about emulation details if you get stuck. It sounds like your emulator is quite mature if you say that there are only a few problems with CPU instructions, so great going thus far.
There was one of these for the 9860, it can be found on UCF. I think it includes source, if you want it Wink
Here's the latest build of ChipEmu. As of right now, it lets you open any .ch8 file and runs it. Key input and the timers aren't functional, and there may still be a few bugs in the CPU emulation. You can press F1 to view the registers, program counter, stack counter, current opcode, and the key value of the last key press (which doesn't work yet). F2 returns to the normal screen. F3 and F4 are used to pause and resume emulation, and F5 can be used to step through the code while it's paused. I would like to get it faster, though.

https://dl.dropbox.com/u/3601919/ChipEmu.g3a
Sample ROM: https://dl.dropbox.com/u/3601919/ZERO.ch8
flyingfisch wrote:
There was one of these for the 9860, it can be found on UCF. I think it includes source, if you want it Wink


here is the chip8 for fx9860 -> http://www.casio-scene.com/downloads.php?do=file&id=20 (include the C code of the chip8 emu library used)

classpad.org closed, here is the ship8 for classpad (latest build) -> http://www.casio-scene.com/downloads.php?do=file&id=460 (no source, only sample games include)

in your prizm chip8 emu, i tried 1 rom that return system error, and pong (does not move) and your sample rom

continues the good work!
I added all of the SCHIP opcodes. Smile I also fixed a bug with ROMs that weren't word-aligned, so it should not crash your calculator any more. It also has an icon.

http://www.cemetech.net/programs/index.php?mode=file&path=/prizm/programs/ChipEmu.zip

Edit: Screenshots:




Great stuff. Smile How well do SCHIP games play? They always struck me as more impressive, especially Ant.
Games don't really work very well, unless they are really simple (like Magic Square). More complex games like Tetris and Blinky take a really long time to load and they are pretty much unplayable.
Do you have any idea what makes them take so long? Do you suspect that it's an inefficiency in the emulator, the screen-rendering code, or simple platform inadequacy? I personally tend to not suspect the last one, since BenRyves wrote a successful 6MHz SCHIP emulator. Smile
I think it's something to do with the CPU emulation code or the screen updating code.
CPU code: http://pastebin.com/7bXKbNKA
Screen code: http://pastebin.com/isAKfxjn
This version is a LOT faster than the previous versions. I removed some stuff from the main loop and compiled it with -ofast. The file size is slightly larger, but I think it's worth it for the additional speed. You can also press EXIT to reset the emulator and load a new ROM.

https://dl.dropbox.com/u/3601919/ChipEmu.g3a
I don't know if it's just me and this game I'm playing, but the game is a lot faster when a key is pressed...
I've noticed that too, but I don't think I can do anything to fix it. I'm thinking it has something to do with PRGM_GetKey().
Then, don't use PRGM_GetKey, but other routines such as Ashbad's ones. They are very fast.

EDIT: find them here: http://prizm.cemetech.net/index.php?title=Debouncing_Multiple-Keypress_PRGM_GetKey

Their purpose is to provide multiple key detection, but they can be used to detect single keys as well. They don't seem to use GetKey directly, see if they solve the problem.
Thanks for that link. Smile Here's an updated version:
https://dl.dropbox.com/u/3601919/ChipEmu.g3a
The updated version is indeed much faster, but it doesn't seem to detect any keypresses... you can't use the new routines the same way you used GetKey, it needs some adaptation.
Strange, it detects keypresses on my Prizm. Try running this program:
https://dl.dropbox.com/u/3601919/KEY.ch8

Also, if you want to re-update:
https://dl.dropbox.com/u/3601919/ChipEmu.g3a
I was pressing the wrong keys, sorry. It works fine, and very fast.
I uploaded a new version to the archives after optimizing the CPU code a little more and adding boundary checks to the sprite drawing routine. It also lets you scale the display using the SHIFT and ALPHA keys.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 1 of 2
» All times are GMT - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement