CEMETECH
Leading The Way To The Future
Login [Register]
Username:
Password:
Autologin:

Don't have an account? Register now to chat, post, use our tools, and much more.
Latest Headlines
Online Users
There are 99 users online: 6 members, 70 guests and 23 bots.
Members: adriweb, alain, legodude, tifreak8x.
Bots: VoilaBot (1), Magpie Crawler (3), Googlebot (13), Googlebot (5), MSN/Bing (1).
RSS & Social Media
SAX
You must log in to view the SAX chat widget
    » Goto page 1, 2  Next
» View previous topic :: View next topic  
Author Message
souvik1997


Guru-in-Training


Joined: 19 Apr 2010
Posts: 2870

Posted: 19 Jun 2012 06:18:36 pm    Post subject: [Prizm] CHIP-8 Emulator

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.
_________________
CALCnet Tournament-38%


deviantArt
Back to top
souvik1997


Guru-in-Training


Joined: 19 Apr 2010
Posts: 2870

Posted: 20 Jun 2012 09:06:50 am    Post subject:

*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.
_________________
CALCnet Tournament-38%


deviantArt
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55736
Location: Earth, Sol, Milky Way

Posted: 20 Jun 2012 09:25:12 am    Post subject:

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.
_________________


Back to top
flyingfisch


Super-Expert


Joined: 02 Feb 2012
Posts: 893
Location: Akron, OH

Posted: 20 Jun 2012 05:35:36 pm    Post subject:

There was one of these for the 9860, it can be found on UCF. I think it includes source, if you want it Wink
_________________



Back to top
souvik1997


Guru-in-Training


Joined: 19 Apr 2010
Posts: 2870

Posted: 20 Jun 2012 10:06:24 pm    Post subject:

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
_________________
CALCnet Tournament-38%


deviantArt
Back to top
helder7


Member


Joined: 23 Dec 2011
Posts: 136

Posted: 21 Jun 2012 06:20:54 am    Post subject:

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!
_________________
SiO2 + CaCO3 ----------> CaSiO3 + CO2
Back to top
souvik1997


Guru-in-Training


Joined: 19 Apr 2010
Posts: 2870

Posted: 24 Jun 2012 11:47:26 am    Post subject:

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:





_________________
CALCnet Tournament-38%


deviantArt
Back to top
benryves


Cemetech Expert


Joined: 12 Aug 2008
Posts: 1357
Location: London, United Kingdom

Posted: 25 Jun 2012 09:07:52 am    Post subject:

Great stuff. Smile How well do SCHIP games play? They always struck me as more impressive, especially Ant.
Back to top
souvik1997


Guru-in-Training


Joined: 19 Apr 2010
Posts: 2870

Posted: 25 Jun 2012 09:14:54 am    Post subject:

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.
_________________
CALCnet Tournament-38%


deviantArt
Back to top
KermMartian


Site Admin


Joined: 14 Mar 2005
Posts: 55736
Location: Earth, Sol, Milky Way

Posted: 25 Jun 2012 01:01:49 pm    Post subject:

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
_________________


Back to top
souvik1997


Guru-in-Training


Joined: 19 Apr 2010
Posts: 2870

Posted: 25 Jun 2012 01:30:51 pm    Post subject:

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
_________________
CALCnet Tournament-38%


deviantArt
Back to top
souvik1997


Guru-in-Training


Joined: 19 Apr 2010
Posts: 2870

Posted: 26 Jun 2012 07:39:24 am    Post subject:

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
_________________
CALCnet Tournament-38%


deviantArt
Back to top
gbl08ma


Power User


Joined: 26 Nov 2011
Posts: 475
Location: Portugal

Posted: 26 Jun 2012 07:48:16 am    Post subject:

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...
_________________
My blog, where I write about random things... | tiny URL shortener
View JPEG images on your Prizm | Utilities for the Casio Prizm - clock, stopwatch, calendar/agenda, add-in manager and more!
Back to top
souvik1997


Guru-in-Training


Joined: 19 Apr 2010
Posts: 2870

Posted: 26 Jun 2012 08:18:25 am    Post subject:

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().
_________________
CALCnet Tournament-38%


deviantArt
Back to top
gbl08ma


Power User


Joined: 26 Nov 2011
Posts: 475
Location: Portugal

Posted: 26 Jun 2012 08:23:45 am    Post subject:

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.
_________________
My blog, where I write about random things... | tiny URL shortener
View JPEG images on your Prizm | Utilities for the Casio Prizm - clock, stopwatch, calendar/agenda, add-in manager and more!
Back to top
souvik1997


Guru-in-Training


Joined: 19 Apr 2010
Posts: 2870

Posted: 26 Jun 2012 08:44:35 am    Post subject:

Thanks for that link. Smile Here's an updated version:
https://dl.dropbox.com/u/3601919/ChipEmu.g3a
_________________
CALCnet Tournament-38%


deviantArt
Back to top
gbl08ma


Power User


Joined: 26 Nov 2011
Posts: 475
Location: Portugal

Posted: 26 Jun 2012 08:52:17 am    Post subject:

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.
_________________
My blog, where I write about random things... | tiny URL shortener
View JPEG images on your Prizm | Utilities for the Casio Prizm - clock, stopwatch, calendar/agenda, add-in manager and more!
Back to top
souvik1997


Guru-in-Training


Joined: 19 Apr 2010
Posts: 2870

Posted: 26 Jun 2012 08:54:23 am    Post subject:

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
_________________
CALCnet Tournament-38%


deviantArt
Back to top
gbl08ma


Power User


Joined: 26 Nov 2011
Posts: 475
Location: Portugal

Posted: 26 Jun 2012 09:00:42 am    Post subject:

I was pressing the wrong keys, sorry. It works fine, and very fast.
_________________
My blog, where I write about random things... | tiny URL shortener
View JPEG images on your Prizm | Utilities for the Casio Prizm - clock, stopwatch, calendar/agenda, add-in manager and more!
Back to top
souvik1997


Guru-in-Training


Joined: 19 Apr 2010
Posts: 2870

Posted: 27 Jun 2012 10:31:13 am    Post subject:

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.
_________________
CALCnet Tournament-38%


deviantArt
Back to top
Display posts from previous:   
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
    » Goto page 1, 2  Next
» View previous topic :: View next topic  
Page 1 of 2 » All times are GMT - 5 Hours

 
Jump to:  
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

© Copyright 2000-2013 Cemetech & Kerm Martian :: Page Execution Time: 0.039809 seconds.