What's new

[CHIP-8] Unknown opcode..

guidono

New member
Hi !

First of all, excuse me if my english is not perfect, I'm french and even if I do my best, I will certainly do a lot of mistakes...

I'm currently doing a Chip 8 emulator, it's currently working on some rom, but for some of them, I found a few unknown opcodes... I wrote a disassembly to see the content of the game, but obviously, I found theses unknown opcodes again !

These are a some examples :
- BRIX game : opcode 0xE000 (location 780 (0x030C) in the memory)
- Rocket2 : opcode 0xFF00 (location 606 (0x025E))
- AIRPLANE : opcode 0x80F8 (location 852 (0x0354))

Do you have any idea of what's going on ?

Let's see my algorithm, maybe you will see something wrong...

Code:
opcodes_list <- list of existing opcodes

For each opcode in program Do
    For each op in opcodes_list Do
        If ((opcode & op.mask) == op.id)
            op.emulate ()
        EndIf
    EndFor
EndFor

Have a nice day !
 

fleroviux

Member
Hey,

thinking back around 3-4 years when I wrote my CHIP-8 emulator I can't remember that I stumbled upon any of these.
I think that it's likely that your emulator has a bug in some other instruction that causes it to jump to a bad address (somewhere in data, not valid code).
Eventually somewhere there is a JP V0, addr (Bnnn) being executed but V0 doesn't contain the right address.

Kind Regards,
flerovium^-^
 
OP
G

guidono

New member
Thank you for your answer !

I thought about that... I checked my instructions three times already ! Moreover, when I disassemble the rom, I can found the unknown instruction... so it seems not to be corruption of the memory during the execution. And I found out that the unknown instruction is not in other chip 8 version either.

I'm not sure about a few instructions, maybe you will see a mistake :
Code:
/**
Bnnn - JP V0, addr
Jump to location nnn + V0.

The program counter is set to nnn plus the value of V0.
*/
void OpJpV0Addr::execute (const uint16_t opcode, Cpu * cpu, Screen * screen) {
    cpu->pc = (opcode & 0x0FFF) + cpu->reg[0];
    cpu->pc -= 2; //because of the +=2 in the cpu's code
}

If you have suspicious about an other one, you can find the code here.

I will check the code for the fourth time...
 
OP
G

guidono

New member
I finally solved my problem ! I wasn't checking which instruction to execute in the good order (we can obtain the same opcode id with two different masks... so the order is very important, I now use a big switch for each opcode).
 

Top