What's new

Chip 8

Death the Kid

New member
well am looking for some help with using directx for my emulator, since so far i only have figured out how to intialize a window lol (sorry about not being more specific) any kind of help would be greatly appreciated.
 
H

h4tred

Guest
Oh alright.

Well, first you need to get a pointer/reference to the graphics output of your emulator. Often this is like a buffer which stores the image.

From there, there is heaps of ways to do it. You can use DirectDraw to draw the raw output, blit to a texture in D3D or OpenGL, or just blit to surfaces in SDL.

One site I recommend is Codesampler.com, there contains some D3D and OpenGL tuts. I just blitted to a OpenGL texture for my NES emu using glTexSubImage2D and altering the texture coordinates to scale/skew the image.
 

Death the Kid

New member
uhhh am having a problem with my emualtor, i pretty much coded the entire thing but, there is no screen output, am pretty sure this is because the ROM isnt being loaded in properly. I have used a break point to find the problem

Code:
bool Emu::Load() 
{ 
    CPUReset(); 
    ClearScreen(); 
 
 FILE* in; 
 in = fopen("C:/"Pong", "rb") ; 
 
     
    if (0 == in) 
    { 
        return false; 
    } 
 
    fread(&m_GameMemory[0x200], ROMSIZE, 1, in) ; 
    fclose(in); 
 
    return true; 
 
}

the in pointer has this
error CXX0030: Error: expression cannot be evaluated
 
H

h4tred

Guest
Problem in fopen(), you did it wrong.

Try "pong.rom" or something, or change your loading function like so:

Emu::Load(char* file)

........
in = fopen(file, "rb") ;
 

Exophase

Emulator Developer
uhhh am having a problem with my emualtor, i pretty much coded the entire thing but, there is no screen output, am pretty sure this is because the ROM isnt being loaded in properly. I have used a break point to find the problem

Code:
bool Emu::Load() 
{ 
    CPUReset(); 
    ClearScreen(); 
 
 FILE* in; 
 in = fopen("C:/"Pong", "rb") ; 
 
     
    if (0 == in) 
    { 
        return false; 
    } 
 
    fread(&m_GameMemory[0x200], ROMSIZE, 1, in) ; 
    fclose(in); 
 
    return true; 
 
}

the in pointer has this
error CXX0030: Error: expression cannot be evaluated

The problem is that you have a stray " in the middle of your string - if you really meant to open a file under C:/ called "Pong (I have my doubts) then you need to escape the quote like this: "C:/\"Pong".

Are you sure you coded pretty much all of this, because this is a pretty obvious error, and the inconsistent indentation is a little telling...

Furthermore, you wouldn't have used a breakpoint to find such an error, because barring some rather freak circumstances this shouldn't even compile.

Or maybe you pasted the code incorrectly?
 

Death the Kid

New member
oh yeah that sorry i didnt paste in in properly that line is suppose to be

Code:
 in = fopen("Pong.ch8", "rb");

 in = fopen("Pong", "rb");

i tried both in my program with the same results
 
Last edited:

Exophase

Emulator Developer
Do you actually have a file named Pong.ch8 in the same directory as your executable? Where are you putting the breakpoint to check for in? What is the value of ROMSIZE?
 

Death the Kid

New member
yeah i do have a ROM called Pong there, the I placed the breakpoint at the fclose line and below is the code for ROMSIZE and m_GameMemory

Code:
typedef unsigned char BYTE;  
 
const int ROMSIZE = 0xFFF;  
  
BYTE m_GameMemory[ROMSIZE];
 

Exophase

Emulator Developer
If it made it that far then it probably loaded the ROM and your error(s) can be just about anywhere else.

To debug this you really need to write a debugger that allows you to step through each instruction and view registers and memory to make sure that they're all doing what they're supposed to be doing. Having breakpoints doesn't hurt either.
 

Death the Kid

New member
so the error below i found in the in pointer isnt that significant then ? (just want to make absolutely sure LoL), plus when i checked the game memory to see how much of the ROM was loaded about it was about six bytes short

error CXX0030: Error: expression cannot be evaluated
 
Last edited:

Exophase

Emulator Developer
The "error" in question is probably just that you're trying to display the value of a FILE and the debugger doesn't know how. Although why said debugger would try to display what it's pointing to instead of the pointer itself (which is usually more useful, except for maybe char *) is beyond me.
 

Death the Kid

New member
LOL cool then, just one more thing could you please point me in the right direction with creating a chip 8 debugger cause tbh i dont have a clue where to start.
 

Exophase

Emulator Developer
A good place to start is to have it so before executing each instruction you print out which instruction you're about to execute and the value of all the registers, then wait for the user to press a key. Then from here you can take in commands to do other things like inspect regions of memory, set breakpoints, exit single step debugging, etc. A breakpoint would reenter this kind of debugging mode when the PC is at the breakpoint value. You can also disassemble instructions so that you know what you're executing without having to look it up all the time.
 
H

h4tred

Guest
Are you sure you coded pretty much all of this, because this is a pretty obvious error, and the inconsistent indentation is a little telling...

Yes, its a blatant coderip from CodeSlinger's Chip8 emulator.
 
OP
sammyboy

sammyboy

Certified SuperHero
omg, this thread went on for epic.

I'm famous.

5677751ccc.png
 

Death the Kid

New member
Yeah i followed codeslingers site on how to write an emulator, but even so i entered that qoute Mark after I had pasted it in here because i thought i left it off when i copied it over, and oh yeah the actual erorr was from an opcode I programmed myself i simply mixed up some values.
 
Last edited:

CodeSlinger

New member
Ripping my code is fine, just make sure you understand it. Once you understand it i'd recommend rewriting it using your own style as this will help you tackle your next emulator. Plus you'll feel like you've achieved something if it is all your own work.

Have fun.
 

Death the Kid

New member
LoL yeah i know you mean pretty much did all of opcodes myself, although i had to read through your explanation of the draw opocode a good few times LoL, although still not getting the graphics API side of things too well will need to read that up some more, but i did implement sound using SDL mixer and am currently implementing a GUI for it and all
 
Last edited:

gzaloprgm

New member
Today I finished my second (S)CHIP8 emulator (first was in c, this is in c++). I have removed sounds (I hate the annoying beep) and added a feature I haven't seen in this thread, graphics interpolation. I am using hq2x and hq4x and the quality IS IMPRESSIVE! High quality anti alias ! Look by yourself:





Comparing to a bilinear filter this looks much better.

ASAP I will upload the code so others can learn (I can't attach it here, it gives error "Unable to move/copy file ")

What do you think about it?

Cheers,
Gzaloprgm
 
Last edited:

Top