Next Generation Emulation banner

CHIP8 thread

99K views 485 replies 57 participants last post by  @ruantec 
#1 · (Edited)
[Super/MEGA]CHIPX thread

Let's keep a CHIPX discussion thread.

CHIP8 Specs:
16 8bit general purpose registers(really, 15 registers, as Register F(16) is typically used as a flag for subtraction/addition/sprite collision)
16bit Program Counter(Ranges from 0-0xFFF)
16bit Memory addressing register(referred to as I)
8bit Stack Pointer(can be any size you want, it doesn't matter, but I use 8bit; it simply points to a 16bit elementn the stack)
256 byte stack(16 16bit spaces(something like u16 Stack[16])
4KBytes RAM(512 bytes reserved for chip8 font at location 0x000-0x050(80 bytes), and interpreter(which on emulators, will be zeroes since the interpreter would be useless))
64 x 32 screen resolution
2 colour screen(black and white)
Hex keypad for input(16 keys, labeled 1-0, A-F)


Note: Super/Mega are both backward compatible with CHIP8, and inherit its base specs[except for MEGAChip, which gains colour]. They simply add on to CHIP8.
SuperChip 48 Specs:
128 x 64 screen resolution
Adds 7 8bit registers(HP48 flags?)

SuperChip 48 adds new opcodes:
00CN* Scroll display N lines down
00FB* Scroll display 4 pixels right
00FC* Scroll display 4 pixels left
00FD* Exit CHIP interpreter
00FE* Disable extended screen mode
00FF* Enable extended screen mode for full-screen graphics
DXYN* Show N-byte sprite from M(I) at coords (VX,VY), VF :=
collision. If N=0 and extended mode, show 16x16 sprite.

FX30* Point I to 10-byte font sprite for digit VX (0..9)
FX75* Store V0..VX in RPL user flags (X <= 7)
FX85* Read V0..VX from RPL user flags (X <= 7)

MEGAChip Specs:
- 256x192 resolution
- Indexed coloring (255 colors max + transparency)
- Fixed high-speed speed in megachip mode
- Custom sprite sizes
- Update timing at ClearScreen
- Extended I-register range (24 bit addessing, 32MB max)
- Digitised sound (mono 8bit)
- Downward compability (you can run your old CHIP/S-CHIP games)
- Spritecolor 0 = transparent.
- Spritecollision will occur if (backgroundcolor>0) when plotting spritepixel.

MEGAChip adds new opcodes:
0010+ Disable Megachip mode (MEGAoFF)
0011+ Enable Megachip mode (MEGAON)
01nn+ I=(nn<<16)+nnnn , PC+=2; (LDHI I,nnnnnn , always follow LDHI with a NOP)
02nn+ Load nn-colors palette at I (LDPAL nn)
03nn+ Set Sprite-width to nn (SPRW nn)
04nn+ Set Sprite-height to nn (SPRH nn)
05nn+ Set Screenalpha to nn (ALPHA nn, will become FADE nn)
060n+ Play digitised sound at I (DIGISND), will add n for loop/noloop
0700+ Stop digitised sound (STOPSND)
080n+ Set sprite blendmode (BMODE n) (0=normal,1=25%,2=50%,3=75%,4=addative,5=multiply)
00BN+ Scroll display N lines up (SCRU n)

Documents:
1. Chip8 thread on Emutalk: Chip 8 - EmuTalk.net
3. Cowgod's documentation: Cowgod's Chip-8 Technical Reference
4. Wikipedia: CHIP-8 - Wikipedia, the free encyclopedia
5. David Winter's docs: CHIP8
6. CHIP8 tutorial by Codeslinger(Try to avoid using this unless you really need help since it has full source!): codeslinger.co.uk
7. MEGAChip document from the development kit: chip8.com - Dedicated to Chip-8 , SuperChip and MegaChip Emulation / Development
8. RCA 1802(required for hybrid CHIP8 games) CPU documents:
COSMAC ELF and the TinyELF Emulator - The 1802 in Microcomputer History
RCA 1802 - Wikipedia, the free encyclopedia
The 1802 Instruction Set
http://mess.redump.net/sysinfo:vip
RCA Cosmac VIP - Instruction manual for VP-111
RCA COS/MAC Microprocessor Trainers
RCA 1802
http://www.hobbylabs.org/files/1802/RCA1802UserManual1976.pdf


Test ROM(s)/Public Domain ROM(s):
Snafu by Shendo
Source to above rom by Shendo
0xFX0A test rom by Shendo
Test rom by tronix286
Test rom by BestCoder


Cool stuff/toys:
Chip8 pascal compiler by tronix286


Update (August 7, 2012): Updated first post with yet another new test rom by BestCoder.
 
See less See more
#427 ·
I'm not really using any fancy API to do the graphics, just the regular Graphics class which is kinda like java's equivalent to c# GDI. So it's really slow :(
unchecked the chip 8 emulator I developed in java runs so fast its hardly useable
I had to use Thread.Sleep() to slow it down to playable speeds
and thats running on my core 2 duo laptop.

I dont think the use of java's graphics class is your issue
 
#428 ·
Yeah maybe i should try JOGL... it's just that i didn't wanna get involved with OGL on simple emulator as this one >.<

And about the slowdowns... it's only noticeable on space invaders... all the games (that i have tested) run fine but when i run invaders it starts well but when i get to about the 5th stage (if they can be called stages) when the ships start coming down faster i start to get some noticeable slowdown...
 
#432 ·
I'm not really using any fancy API to do the graphics, just the regular Graphics class which is kinda like java's equivalent to c# GDI. So it's really slow :(
My chip-8/schip emulator also uses gdi for a plugin, but it runs about as fast as fish n' chips. I believe your problem is how you are using gdi in java. Perhaps it has to do with the way you're managing the screen refresh rate, try putting the refresh rate into a seperate thread, a more viable way would be a timer for 1ms.
 
#433 · (Edited)
Well I have managed to get a chip8 hybrid game called Bingo working. Using my CDP1802 hybrid IL dyanrec, it will make the game happier. One of bingo's 1802 functions is pixel scrolling and it works with some little pixel garbage at the last pixel row. The only bug I see there and it doesn't seem to grab the key values but reacts to the keys. I am trying to get BlackJack to work as well, which where the compiled functions seem to be working fine but the chip8 PC is somehow off somewhere so I think one of the compiled 1802 functions is a culprit and its causing the PC to be off. Using a hack that corrects the PC value makes the game show the 200 at the bottom screen but still breaks probably because of the same issue, but I am close finding out why the bug happens.

EDIT: I fixed the graphics bug by letting the game exactly set the X and Y pixel pointers (R6, R7)

Bingo Hybrid Chip8 Game showing the entries scrolling up every round
 
#435 ·
some games require the hardware side of the chip-8 interpreter to be emulated, these are generally called hybrid games. so if you manage to emulate the hardware than you should be able to get that game to run. i currently have yet to emulate the 1802 in my chip8 and instead working on another project but the document that has been found should make it relatively easy to do. not sure if its been put up on this thread, if not i can include it in another post.
 
#436 · (Edited)
Hybrid games need support of the syscall chip8 opcode which points to a block of CDP1802 instructions loaded in memory by the chip8 rom, my emulator supports recompiling the CDP1802 code functions and then executing it. All CDP1802 code blocks are required to end with SEP 04 as the VIP doc says, and makes it easy for me to find the end point of each syscall.

Also, the Add_7 chip8 opcode uses carry, so I assume all addition operations in chip8 uses 0xF for carry. Supporting the carry gets blackjack hybrid game to show the 200 score at the bottom of the screen else its all black screen.

Edit: I think somehow V register 7 is also used as a carry flag, blackjack is happy with that and almost works, but the input still doesn't function right for hybrid games:

Docs on 1802 CPU and VIP:

http://www.cosmacelf.com/shortcourse.htm
RCA 1802 - Wikipedia, the free encyclopedia
The 1802 Instruction Set
http://mess.redump.net/sysinfo:vip
RCA Cosmac VIP - Instruction manual for VP-111
RCA COS/MAC Microprocessor Trainers
RCA 1802
http://www.hobbylabs.org/files/1802/RCA1802UserManual1976.pdf


Blackjack

 
#437 · (Edited)
Ok, news update about hybrids, as I have gotten Blackjack and Bingo to fully work. ;)

First to support to the syscalls for chip8 programs, you need to understand some CDP1802 instructions that are in the chip8 rom. The syscall instruction has an address that points to CDP1802 code to execute. Second, all CDP1820 code should end with SEP 04 code.

Note: Add7 doesn't do carry and Vreg 7 isn't used as one either. My hypothesis was wrong.

The 1802 code needs the following in memory access:

- Font Ram in current interpreters, prolly not important though
- The chip memory
- the stack memory of the chip8 interpreter, I haven't implemented this yet
- the registers and memory of the chip8 interpreter itself, mine only allows I/O of the Vregs so far
- the video memory with an address like 0xXX00, the low byte has to always be zero, the 1802 code always AND's the HI part of the video pointer address with an offset and then stores in register A (the chip I address on the VIP).

I always generate a syscall method where registers P is set to 2, and X is set to 3 and there are some other default register values you need and how it should be setup since we are doing a hybrid mode.

CDP1802 General Registers
R0: let the game set this value, its used for DMA pointers
R1: Some Interrupt pointer, I let the game do anything with it
R2: Pointer to stack memory, I left this at 0
R3: This should always return the routine address alas the syscall address
R4: This is normally used as the VIP PC, let the game set it to anything
R5: Must return the chip8 PC value, and let the game set it
R6: must be set to the pointer of the chip8 core values such as vregs and let the game set it
R7: same as R6
R8: chip8 timer data: ((DT << 8) & ST), and let the game set it
R9: return the last random value generated in chip8 core
RA: Must return the value of the chip8 I register, and let the game set it too
RB: return pointer to video memory, don't let game change it
RC: scratch register
RD: scratch register
RE: scratch register
RF: set to the video pointer address, let game change it



Here are some screenshots




 
#441 ·


:)

I want to make a test unit some day:

- Test Math results / Binary Coded Decimal
- Test 0xF Flag on AND, OR, XOR, ADD, SUB, Collision
- Test syscalls
- Test Save/Load RPL flags
- Test Call / Jump
- Test for Vertical Wrap hack (Blitz was created on machines that didn't support vertical wrap)
- Test for normal wrapping
- Test fonts
- Super Chip8 tests
- maybe mega chip tests?


Note about hybrid games: They are special chip8 programs containing native runtime code. Some are really whole native programs that doesn't use the chip8 interpreter at all (I wouldn't call them chip8 programs or hybrid :p). The normal [real] hybrids just use syscalls to call native CDP1802 code inside the rom itself which help chip8 games access any part of memory such as the video buffer, chip8 registers, stack memory, chip8 interpreter work memory. Also can read the cdp1802 register for some info such as pointers, PCs, and interrupt info. I also think its illegal in chip8 programming to have programs call code outside the rom such as interpreter code or the HW rom.
 
#445 ·
confusion over SHR instruction

hi guys,

I am following cowgod's chip 8 documentation to code up my emulator in java and i am having problem understanding the following instruction

8xy6 - SHR Vx {, Vy}
Set Vx = Vx SHR 1.

If the least-significant bit of Vx is 1, then VF is set to 1, otherwise 0. Then Vx is divided by 2.

It says to shift by 1, if so, what is the use of y in the instruction 8xy6. Can anyone clarify that for me? Appreciate your help!:thumb:
 
#447 ·
Thanks! refraction,

I have another question. I am implementing the draw function. According to the specs, when writing new pixels the pixels are xored. That would mean if in a position there is a pixel written and if i write 0 then the pixel wont get cleared. Is that correct? I was assuming the sprite bits in the memory is what will be written in the screen.
 
#449 ·
Hello I'm new here and have been recently working on programming a chip-8 emulator in c++. I have split the code into three parts, chip8.h, chip8.cpp, and main.cpp. I have finished chip8.h and am working on chip8.cpp however have one question:
What memory location is 'NN' or 'NNN' referring to? Sorry if this is in the wrong section.

Thanks
Stefonzo
 
#450 ·
Hello I'm new here and have been recently working on programming a chip-8 emulator in c++. I have split the code into three parts, chip8.h, chip8.cpp, and main.cpp. I have finished chip8.h and am working on chip8.cpp however have one question:
What memory location is 'NN' or 'NNN' referring to? Sorry if this is in the wrong section.

Thanks
Stefonzo

NN literally refers to 2 numbers and 3 for NNN. So NN can be any number from 0x00 up to 0xFF and NNN can be anything from 0x000 up to 0xFFF
 
#451 ·
Just wanted post my dynarec chip8 emulator that I wrote in the past. Thought it might be helpful for people who wants to learn how write a dynarec cpu. I created this just for learning purpose, to teach myself about dynarec so the code isn't perfect.

And no input and sound emulation, so it just shows the first screen. :p
Link: http://www.pradsprojects.com/downloads/Chip 8 dynarec.7z
 
This is an older thread, you may not receive a response, and could be reviving an old thread. Please consider creating a new thread.
Top