What's new

Chip 8

aprentice

Moderator
refraction said:
yeh, i mean as i said dragon2 (Which is a helicopter game :huh: ) works pretty much fine on mine, as does most if not all schip8 games, just Dragon1 the characters seem to start in the middle of the air for some reason.

plus it starts calling invalid op codes and gets itself into an endless loop.


this is where Dragon1 seems to go all wrong

0x804 Opcode 0x4440 Called.
0x808 Opcode 0x8441 Called.
0x80a Opcode 0x442 Called.
0x80c Opcode 0xfc44 Called.
Invalid Op Call at 0x80e opcode 0xfc44
0x80e Opcode 0x58 Called.
0x810 Opcode 0xffe0 Called.
Invalid Op Call at 0x812 opcode 0xffe0
0x812 Opcode 0x0 Called.
0x814 Opcode 0x0 Called.
0x816 Opcode 0x0 Called.
0x818 Opcode 0x400 Called.

First of all, opcodes are executed, not called :p
Second of all, your probably incramenting the
program counter wrong on one of your opcodes if
your getting invalid ops. Good luck on your problem,
if still cant find the problem, post the cpu source on
this forum.
 

zenogais

New member
aprentice said:
First of all, opcodes are executed, not called :p
Second of all, your probably incramenting the
program counter wrong on one of your opcodes if
your getting invalid ops. Good luck on your problem,
if still cant find the problem, post the cpu source on
this forum.

Closer analysis actually shows a small jump operation, probably one of those increment PC by 2 opcodes, also the fact that it appears to have a problem with the illegal opcode error (i.e. it doesn't appear to increment the program counter). These might be things to check into. Also the value it reads from memory changes while the memory address does not, weird :huh:
 
Last edited:

refraction

PCSX2 Coder
its wierd cos jump calls and sub routine calls work fine on other games, i dont think ive had one with an invalid call apart from that one, its strange :/

ill have to look into it..
 

Doomulation

?????????????????????????
aprentice said:
First of all, opcodes are executed, not called :p
Second of all, your probably incramenting the
program counter wrong on one of your opcodes if
your getting invalid ops. Good luck on your problem,
if still cant find the problem, post the cpu source on
this forum.
There's a jump to XXX + V[0] (BNNN) opcode too... that might mean the math opcodes are wrong... that it's calculating the wrong jump address.
 

refraction

PCSX2 Coder
couple more possible problems in your source aprentice

in 2 minds about this one..

reg.v[(reg.op&0x0F00)>>8]=(rand()&0xFF)&(reg.op&0x00FF);

in one doc it says random number AND 0x00FF, another says random number equal or less than 0x00FF, either way the random number has to be less than 0xFF, but theres no carry so the 2nd one seems more likely.. so its one of these 2 you want

reg.v[(reg.op&0x0F00)>>8]=(rand()%(reg.op&0x00FF));
or
reg.v[(reg.op&0x0F00)>>8]=(rand()%(reg.op&0x00FF))&(reg.op&0x00FF);

other thing is the subroutine calls.

best start it at 0 and increment up kinda like so

void op0x2() //Jump to Subroutine at Address (JSR xxx)
{
if(reg.sp<16){
reg.stack[reg.sp]=reg.pc;
reg.pc=reg.op&0x0FFF;
reg.sp++
}
}

then to return from it increment it downwards

case 0xEE: //Return from Subroutine

reg.sp--
reg.pc=reg.stack[reg.sp];
break;
 

aprentice

Moderator
refraction said:
couple more possible problems in your source aprentice

in 2 minds about this one..

reg.v[(reg.op&0x0F00)>>8]=(rand()&0xFF)&(reg.op&0x00FF);

in one doc it says random number AND 0x00FF, another says random number equal or less than 0x00FF, either way the random number has to be less than 0xFF, but theres no carry so the 2nd one seems more likely.. so its one of these 2 you want

reg.v[(reg.op&0x0F00)>>8]=(rand()%(reg.op&0x00FF));
or
reg.v[(reg.op&0x0F00)>>8]=(rand()%(reg.op&0x00FF))&(reg.op&0x00FF);

other thing is the subroutine calls.

best start it at 0 and increment up kinda like so

void op0x2() //Jump to Subroutine at Address (JSR xxx)
{
if(reg.sp<16){
reg.stack[reg.sp]=reg.pc;
reg.pc=reg.op&0x0FFF;
reg.sp++
}
}

then to return from it increment it downwards

case 0xEE: //Return from Subroutine

reg.sp--
reg.pc=reg.stack[reg.sp];
break;

stacks dont work that way, you pull data from the top of the stack, not the bottom :p

and for the random function, its less than or equal than xx, so there shouldnt really be a problem with that opcode.

did you figure out whats cause dragon1 to lock in your emu?
 

refraction

PCSX2 Coder
no i havent as yet... its doing it on a totally rewritten one too that zenogais is doing for his tutorial (im doing bug fixes while hes on holiday). i tried an emu posted further back in this topic looks like it was done in pascal for windows(?) but it seems to work fine!

but im still on the case!!

Stacks: afaik the chip8 stack works on a FILO method so you can have up to 16 subroutines called within each other, its how every other stack ive seen works anyway ;p
 

RipNLa

New member
Hey, I went to Vegas the last week and I'm finally back and messing with my Chip8 Emu.. I emulated all the calls..(not sure which ones don't work just yet =D), got graphics in most games showing, but things go wrong as soon as the games start.
Other than that, my most playable game is Tetris..but whenever I take input, like to move the piece or rotate, the countdown on my DelayTimer takes FOREVER...the weird thing is, I don't have any timing functions to slow this thing down!

I checked out my Task Manager..and its using 0% cpu... So why is it so slow? Any ideas? Btw, I'm using nested switches to track down the opcodes to execute...is that why its SO slow? Seems unlikely..but I dont know much, so maybe thats just what it is...
 

refraction

PCSX2 Coder
when you have a keyboard input the function breaks from its usual loop and executes a load of other op codes, which increases the execution time, i dont see why its modifying the delay register tho.

i cant really say whats causing the bugs unless i see your code :) sorry i cant help much more than that.
 

Doomulation

?????????????????????????
RipNLa said:
Hey, I went to Vegas the last week and I'm finally back and messing with my Chip8 Emu.. I emulated all the calls..(not sure which ones don't work just yet =D), got graphics in most games showing, but things go wrong as soon as the games start.
Other than that, my most playable game is Tetris..but whenever I take input, like to move the piece or rotate, the countdown on my DelayTimer takes FOREVER...the weird thing is, I don't have any timing functions to slow this thing down!

I checked out my Task Manager..and its using 0% cpu... So why is it so slow? Any ideas? Btw, I'm using nested switches to track down the opcodes to execute...is that why its SO slow? Seems unlikely..but I dont know much, so maybe thats just what it is...
One thing I might admit is that chip8 emus for windows seems to be REALLY slow. And I mean it! Otherwise, use a profiler to check your code to see where it slows down.
It seems to me that most time is used when rendering the gfx (ie, when calling the gfx card to render)
 

refraction

PCSX2 Coder
indeed its wierd.

on a lighter note, ive been working very hard on the emulator Zenogais started for his tutorial, and it has to be one of the best emulators for windows, ive got every game but ANT working sucessfully, this screenshot is for aprentice :)

dragon.JPG
 

aprentice

Moderator
refraction said:
indeed its wierd.

on a lighter note, ive been working very hard on the emulator Zenogais started for his tutorial, and it has to be one of the best emulators for windows, ive got every game but ANT working sucessfully, this screenshot is for aprentice :)

so how'd you fix the sprites problem in dragon1? :p
 

refraction

PCSX2 Coder
aprentice said:
so how'd you fix the sprites problem in dragon1? :p


i have no idea haha, but i managed to do it with this new emulator, hopefully when its finished and zenogais has uploaded the completed version you will be able to learn from it and find the bug :)
 

RipNLa

New member
ArGh! I found the bug I had with 75% of my games! I was using nested switches, with sTupid logic, so one of my op's was getting executed as a different one! Horrible! Anyways, gonna fix it more later, but my compatibility jumped like 75% so I'm happy. Also found out why my emulator was SO damn slow. It was just the DirectX settings I was using from my 3D engine =D bOO! Oh well, hopefully I'll have something to show soon enough, cuz I'm feeling mighty proud of myself!
 

refraction

PCSX2 Coder
yeh you have to be very careful with some ops, i mean obviously most opcodes can just be in the main switch, then you nest the 0x8000 and 0x0000 and 0xF000 opcodes within that, best thing with them is find a value that doesnt change, like with the 0x8000 commands 0x000F doesnt change when the opcode is called, so you can use that part of it for the Case. with 0xF000 commands best to use the last 2 parts (0x00FF) as they dont change, and with 0x0000 commands, best to take 0x00F0 then put another nest inside that for the 0x00F0 commands, but 0x00E0 ones you can get away with an If statement, for example:-

if((opcode&0x00FF)= 0xE0)
screen->clear;
else
PC = stack[SP--];

or somethi8ng simular to that :)
 

Doomulation

?????????????????????????
Bueh! Don't use ifs...

Code:
switch (opcode & 0xFF)
{
    case 0x0F:
       switch(opcode & 0xF)
       {
           case 0xE: break; // do something
           ...
       }
       break;
}

Just a typical example...I doubt it's right by any means! :eek:
Neat about your emulator... hope it develops into something soon.
 

RipNLa

New member
Yeah, I basically did exactly what you guys showed (without the IF's). The main problem I had was that I had my 8000 op in the main switch (opcode & F000), and then nested in my (opcode & F00F) switch I had the rest of the 8000 op's, so basically, 8001, 8002, etc calls were going to the 8000! You have no idea how many times I changed my carry flag setting/checking ops!

EDIT / MORE:
Hey, so I've got this weird problem, where if I run the game Blitz...when I get to the fourth level..it crashes my emulator =\ Weirder..while playing it..around level 3..my debug window crashes on me and I cant open it anymore.. I'm thinking... my memory is getting overwritten somehow? Even weirder..My DirectX crashes after running Blitz too...everytime =(

EDIT: MMM, boundary checking, good stuff =D Blitz works great now!
 
Last edited:

refraction

PCSX2 Coder
RipNLa said:
Yeah, I basically did exactly what you guys showed (without the IF's). The main problem I had was that I had my 8000 op in the main switch (opcode & F000), and then nested in my (opcode & F00F) switch I had the rest of the 8000 op's, so basically, 8001, 8002, etc calls were going to the 8000! You have no idea how many times I changed my carry flag setting/checking ops!
well when you nest inside another switch case, you dont need all 4 hex digits again, if you do switch(opcode&0x000F) then just go underneath with case 0x0: case 0x1: Case 0x2: and so on. that should work fine.

RipNLa said:
EDIT: MMM, boundary checking, good stuff =D Blitz works great now!

:saint:
 

manboy

New member
NNN is an address,

KK is an 8 bit constant

X and Y are two 4 bits constants

this is from david winters doc
Can someone explain it to me in detail please :blush:
edit:
I did a bit more reading and i understand KK, X and Y (lol how could i be so dumb :p ) still in the dark when it comes to NNN i will keep reading....
edit2:
I understand NNN now :bouncy:
 
Last edited:

Top