Emuforums.com

Go Back   Emuforums.com > General Discussion > Web development / Programming
Home Register Downloads FAQ Members List Calendar Arcade Mark Forums Read


Reply
 
LinkBack Thread Tools Display Modes
Old November 21st, 2008   #1 (permalink)
Dax
ライチュウ
 
Dax's Avatar
 
Join Date: Nov 2006
Location: USA
Posts: 3,289
CHIP8 thread

Inspired by RAP, I decided to write a C8 emulator too. Here's the progress so far:

Documents used:
1. Chip8 thread on Emutalk: http://www.emutalk.net/showthread.php?t=19894
2. Chip8 thread on our forums
3. Cowgod's documentation: http://devernay.free.fr/hacks/chip8/C8TECH10.HTM
4. Wikipedia: http://en.wikipedia.org/wiki/CHIP-8
5. David Winter's docs: http://www.pdc.kth.se/~lfo/chip8/CHIP8.htm

Opcodes:

Regular C8:

0nnn - SYS addr: Yes(Ignored)
00E0 - CLS: Yes
00EE - RET: Yes
1nnn - JP: Yes
2nnn - CALL: Yes
3xkk - SE: Yes
4xkk - SNE: Yes
5xy0 - SE: Yes
6xkk - LD: Yes
7xkk - ADD: Yes
8xy0 - LD: Yes
8xy1 - OR: Yes
8xy2 - AND: Yes
8xy3 - XOR: Yes
8xy4 - ADD: Yes
8xy5 - SUB: Yes
8xy6 - SHR: Yes
8xy7 - SUBN: Yes
8xyE - SHL: Yes
9xy0 - SNE: Yes
Annn - LD: Yes
Bnnn - JP: Yes
Cxkk - RND: Yes
Dxyn - DRW: Yes
Ex9E - SKP: Yes
ExA1 - SKNP: Yes
Fx07 - LD: Yes
Fx0A - LD: Yes
Fx15 - LD: Yes
Fx18 - LD: Yes
Fx1E - ADD: Yes
Fx29 - LD: Yes
Fx33 - LD: Yes
Fx55 - LD: Yes
Fx65 - LD: Yes

Total: 35/35

Super C8:
00Cn - SCD: No
00FB - SCR: No
00FC - SCL: No
00FD - EXIT: No
00FE - LOW: No
00FF - HIGH: No
Dxy0 - DRW: No
Fx30 - LD: No
Fx75 - LD: No
Fx85 - LD: No

Total: 0/10

Grand Total: 35/45


Compatibility List[Playable, Ingame, Title, Broken]:
Pong: Title: Never crashes, graphics glitches.
Blitz: Broken: Crashes after about 3 seconds, graphics glitches.

Status:
Registers/memory array written out: Yes.
Graphics: Yes, DirectX for now.
Sound: Not yet[Who cares? It's a bloody beep!].
Input: Not yet.

Update March 26: It has graphics!!




Update(2/27/2009): I'm going to rewrite this thing from scratch eventually in C++/SDL. Here's the 'final' version of the old source, for those who might want to see it: http://code.google.com/p/chip8-emu/
Update(3/26/2009): "Rewrite" is complete. The emulator is using C++/DirectX[for now]. No source release yet, as I want it to work as close to 100% as possible before sharing. If you want proof, I'll show the source, but it's not ready for general consumption yet.

Last edited by Dax; March 26th, 2009 at 18:19.. Reason: Status of emulator
Dax is offline   Reply With Quote

Advertisement [Remove Advertisement]
Old November 21st, 2008   #2 (permalink)
Moderator
 
ShendoXT's Avatar
 
Join Date: Feb 2006
Location: Croatia
Posts: 4,191
Cool. I highly recommend that you make a debugger also which can really help you to iron bugs.
__________________
C2D E8400 3.00 Ghz | EP45-DS3 | HD4850 512MB | 4GB DDR2 800 | 640 + 250 GB HDD
SyncMaster 2233BW 22" | Logitech G5 | Logitech G15 | Windows 7 x64
ShendoXT is offline   Reply With Quote
Old November 21st, 2008   #3 (permalink)
Behind ur girlfriend :D
 
Squall-Leonhart's Avatar
 
Join Date: Feb 2006
Location: Sydney, Australia
Posts: 18,832
OpenGL or gtfo!
__________________


VBA-M | Xtemu | NGOHQ | Post Impact Productions | TNHW | XBCD 0.2.6 | Satanic666's Emulator Compiles
Don't be a NOOB, READ THE NGEmu/EmuForums Rules of Conduct
Need Help with ePSXe? This is your first stop!.

If you don't post all the required information, you don't get help.
Everytime someone posts a romsite, God kills a beautiful woman.
Squall-Leonhart is offline   Reply With Quote
Old November 21st, 2008   #4 (permalink)
Dax
ライチュウ
 
Dax's Avatar
 
Join Date: Nov 2006
Location: USA
Posts: 3,289
Quote:
Originally Posted by Shendo View Post
Cool. I highly recommend that you make a debugger also which can really help you to iron bugs.
Not totally sure how to do that, but I'll read up on it. ;
Dax is offline   Reply With Quote
Old November 21st, 2008   #5 (permalink)
 
P_RePTiLe's Avatar
 
Join Date: Sep 2006
Location: Sweden
Posts: 509
Quote:
Originally Posted by Squall-Leonhart View Post
OpenGL or gtfo!
You DO know what SDL is, right?!
__________________


( #1 Core2Duo E8400 @ 3.61 Ghz, 3072 MB DDR2-RAM @ 802mhz, XFX Geforce GTX260 XT - N-Lited WinXP SP3 and Arch Linux 64-bit).

<- http://www.myspace.com/preptile ->
|
/P. Rep.
P_RePTiLe is offline   Reply With Quote
Old November 21st, 2008   #6 (permalink)
Behind ur girlfriend :D
 
Squall-Leonhart's Avatar
 
Join Date: Feb 2006
Location: Sydney, Australia
Posts: 18,832
Simple Directmedia Layer, can connect with any available API in the system, most commonly video implementation connects to OpenGL.
__________________


VBA-M | Xtemu | NGOHQ | Post Impact Productions | TNHW | XBCD 0.2.6 | Satanic666's Emulator Compiles
Don't be a NOOB, READ THE NGEmu/EmuForums Rules of Conduct
Need Help with ePSXe? This is your first stop!.

If you don't post all the required information, you don't get help.
Everytime someone posts a romsite, God kills a beautiful woman.
Squall-Leonhart is offline   Reply With Quote
Old November 21st, 2008   #7 (permalink)
You're already dead...
 
cottonvibes's Avatar
 
Join Date: Sep 2007
Location: Post-Apocalyptic Earth
Posts: 3,902
Quote:
Originally Posted by daxtsu View Post
Not totally sure how to do that, but I'll read up on it. ;
its basically a way to show you what instructions are being run and at what address; it also can show registers, and what they have in them.

you can also make it so that the debugger goes by 1 instruction at a time, so you can find bugs easier.

shendo has a pic of his debugger in his chip8 thread:


anyways, its not really needed, but it helps 'debugging' for problems.
pcsx2's debugger for example, doesn't even work.
__________________

Quote:
Eccentricity is often associated with genius, giftedness, or creativity. The individual's eccentric behavior is perceived to be the outward expression of his or her unique intelligence or creative impulse. In this vein, the eccentric's habits are incomprehensible not because they are illogical or the result of madness, but because they stem from a mind so original that it cannot be conformed to societal norms.
check out my blog
cottonvibes is offline   Reply With Quote
Old November 21st, 2008   #8 (permalink)
Moderator
 
ShendoXT's Avatar
 
Join Date: Feb 2006
Location: Croatia
Posts: 4,191
Quote:
Originally Posted by daxtsu View Post
Not totally sure how to do that, but I'll read up on it. ;
Well it doesn't have to be anything special.
If you take a look at my thread you will see that my debugger is simply 2 listboxes, one showing values of registers and other disassembled code.
When you have that you are able to check if each opcode you execute gives desired result.

Edit: I see cottonvibes beat me to it
__________________
C2D E8400 3.00 Ghz | EP45-DS3 | HD4850 512MB | 4GB DDR2 800 | 640 + 250 GB HDD
SyncMaster 2233BW 22" | Logitech G5 | Logitech G15 | Windows 7 x64
ShendoXT is offline   Reply With Quote
Old November 21st, 2008   #9 (permalink)
Administrator
 
Chrono Archangel's Avatar
 
Join Date: Dec 2001
Location: Montreal, Canada
Posts: 7,842
ITs always nice to see new people making emulators. Even if its just a small step, its sometimes enough to get them hooked

Hmmm I should redo mine in a standard programming language eventually
Chrono Archangel is offline   Reply With Quote
Old November 21st, 2008   #10 (permalink)
Dax
ライチュウ
 
Dax's Avatar
 
Join Date: Nov 2006
Location: USA
Posts: 3,289
I have a question. I'm looking at Cowgod's documentation(http://devernay.free.fr/hacks/chip8/C8TECH10.HTM#3.0) and he says the following about the character data/sprites:

Quote:
The data should be stored in the interpreter area of Chip-8 memory (0x000 to 0x1FF).
He doesn't specify where though. Can I just put the 16 characters[0-F] in the first 80 bytes with no issue?

Also, thanks for all the positive feedback. It's encouraging.
Dax is offline   Reply With Quote
Old November 21st, 2008   #11 (permalink)
Mobile Fanatic
 
runawayprisoner's Avatar
 
Join Date: Nov 2006
Location: Santa Cruz, CA
Posts: 6,205
Yep, put the characters anywhere. Later on, when you run across an opcode that asks for the address, point it there.

P.S.: You may also put your own custom Chip8/SChip instructions there just for lols and giggles when something tries to call a system instruction in those addresses. But that's just for fun. It may mess what you are running up badly... so that's not very recommended.
__________________
cChip interpreter WIP - current status: Release Candidate
LRx Filter RC - current performance rating: 9/10
runawayprisoner is offline   Reply With Quote
Old November 21st, 2008   #12 (permalink)
Dax
ライチュウ
 
Dax's Avatar
 
Join Date: Nov 2006
Location: USA
Posts: 3,289
Well, the characters are in the first bytes[0x0-0x5d], the ROM gets loaded at 0x200, and the rest of the RAM is zeroed. Now I'm ready to start fetching opcodes, right? Or did I miss any steps?
Dax is offline   Reply With Quote
Old November 21st, 2008   #13 (permalink)
Moderator
 
ShendoXT's Avatar
 
Join Date: Feb 2006
Location: Croatia
Posts: 4,191
That's basically it.
Don't forget that almost all opcodes increase program counter by 2.
__________________
C2D E8400 3.00 Ghz | EP45-DS3 | HD4850 512MB | 4GB DDR2 800 | 640 + 250 GB HDD
SyncMaster 2233BW 22" | Logitech G5 | Logitech G15 | Windows 7 x64
ShendoXT is offline   Reply With Quote
Old November 21st, 2008   #14 (permalink)
Emu author
 
Zack's Avatar
 
Join Date: Sep 2007
Location: idk
Posts: 251
On the subject.... kind of a silly question but.. how does one decode the opcodes from that list?

I understand 1nnn is an address but what address? One that I specify?
__________________

My Releases :



^-------------------------^

^-------------------------^


Last edited by Zack; November 21st, 2008 at 21:27..
Zack is offline   Reply With Quote
Old November 21st, 2008   #15 (permalink)
Mobile Fanatic
 
runawayprisoner's Avatar
 
Join Date: Nov 2006
Location: Santa Cruz, CA
Posts: 6,205
Actually, I think program counter should be increased by 2 after every opcode regardless. Then if it's an opcode that skips the next instruction, increase the program counter by 2, if it's an opcode that delays the instruction, decrease program counter by 2.
__________________
cChip interpreter WIP - current status: Release Candidate
LRx Filter RC - current performance rating: 9/10
runawayprisoner is offline   Reply With Quote
Old November 21st, 2008   #16 (permalink)
Dax
ライチュウ
 
Dax's Avatar
 
Join Date: Nov 2006
Location: USA
Posts: 3,289
Well I think I'm sort of getting it. I have it printing whatever opcodes it finds out to the screen[and it's wildly printing info like zeroes, FF98, etc], but I'm not sure if I'm reading the opcodes correctly.
I set regs.PC equal to 0x200 and have it going from there.

Code:
opcode = RAM[regs.PC] + RAM[regs.PC++];
cout << hex << opcode << endl;
Isn't this where bit shifting is supposed to come in?
Dax is offline   Reply With Quote
Old November 21st, 2008   #17 (permalink)
Moderator
 
ShendoXT's Avatar
 
Join Date: Feb 2006
Location: Croatia
Posts: 4,191
opcode = (RAM[regs.PC]<<8) | RAM[regs.PC+1];

Quote:
Originally Posted by Zack View Post
I understand 1nnn is an address but what address? One that I specify?
If for example you have 1342 opcode which is a jump opcode,
by ANDing that opcode with 0xFFF you will get 0x342 which is the address you have to jump to.
__________________
C2D E8400 3.00 Ghz | EP45-DS3 | HD4850 512MB | 4GB DDR2 800 | 640 + 250 GB HDD
SyncMaster 2233BW 22" | Logitech G5 | Logitech G15 | Windows 7 x64

Last edited by ShendoXT; November 21st, 2008 at 21:38..
ShendoXT is offline   Reply With Quote
Old November 21st, 2008   #18 (permalink)
Dax
ライチュウ
 
Dax's Avatar
 
Join Date: Nov 2006
Location: USA
Posts: 3,289
Should I AND the opcodes with 0xFFF or 0xFF? I've been reading Emutalk a bit and I think they said 0xFF. :o
Dax is offline   Reply With Quote
Old November 21st, 2008   #19 (permalink)
Moderator
 
ShendoXT's Avatar
 
Join Date: Feb 2006
Location: Croatia
Posts: 4,191
If you are asking how to know what instruction should be executed when you fetch an opcode you should AND it with 0xF000 and shift it to the right by 12.

You can also use higher part of the opcode (RAM[PC]) to get the same result:
Code:
switch ((RAM[PC] & 0xF0)>>4)
            {
                case 0x00:
                    break;

                case 0x01:
                    break;

                case 0x02:
                    break;

                ...
            }
Some people split opcodes into nibbles so you may also take that approach.
__________________
C2D E8400 3.00 Ghz | EP45-DS3 | HD4850 512MB | 4GB DDR2 800 | 640 + 250 GB HDD
SyncMaster 2233BW 22" | Logitech G5 | Logitech G15 | Windows 7 x64
ShendoXT is offline   Reply With Quote
Old November 21st, 2008   #20 (permalink)
Dax
ライチュウ
 
Dax's Avatar
 
Join Date: Nov 2006
Location: USA
Posts: 3,289
Thanks, I'm going to take a break for now. I'll update later. Sorry for all the annoying questions!
Dax is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On


All times are GMT. The time now is 00:56.

© 2006 - 2008 Emu Forums | About Emu Forums | Legal | A member of the Crowdgather Forum Community


Powered by vBulletin® Version 3.7.6
Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0 RC5