View Full Version : Chip 8
sammyboy
April 14th, 2004, 00:05
If I was to create a chip 8 emulator what roms would it play (I have never heard of one until I looked at this emu programming site). It has so less functions do you reckon it would be possible to emulate in Visual Basic I mean if gameboy ones have written in VB (rather slow though) it must be possible for a chip 8 emulator. And once I have programmed this were would I go next and where can I find documents for chip 8. Hopefully requesting docs arent against the rules like requesting roms are.
Marce1991
April 14th, 2004, 00:35
I've seen the site you'd be able to play pong,space invaders those ooooooold games.
BlueYoshi
April 15th, 2004, 12:10
I have made Chip8 & SuperChip emulator. It's on my site http://koti.mbnet.fi/smiika/chippy.htm (sources included). You can make it just fine in VB, I made it in pascal and had to implement slowdown system because the games were running way too fast. Though you might have few problems with VB because it doesn't support bitwise xor (afaik) and bit shifting operators are missing in VB too...
Here's some documentation:
http://www.goldroad.co.uk/chip8.html
http://www.pdc.kth.se/~lfo/chip8/CHIP8.htm
http://members.aol.com/autismuk/chip8/chip8def.htm
roms: (legal ones)
http://www.zophar.net/roms.phtml?op=show&type=chip8
sammyboy
April 15th, 2004, 19:39
I am getting VB.net soon which is actually backwards compatible with some Visual C++.net functions so that would be ok.
Doomulation
April 19th, 2004, 13:47
Hmmmmm, if I remember correctly, doesn't VB have "XOR" or something? The logical operators could be replaced with multiplication or division.
Left shift is multiplication. Shift by 1 is equal to times 2. Shift by 2 is 4, 3 is 8, etc, afaik.
Same goes for right shift, only that it's multiplication instead.
I've also made a chip8 emulator called "Chippu."
A good documentation would be dave winter's, although probably the best one would be mine, but I haven't made that one public yet.
mesman00
April 19th, 2004, 18:19
Hmmmmm, if I remember correctly, doesn't VB have "XOR" or something? The logical operators could be replaced with multiplication or division.
Left shift is multiplication. Shift by 1 is equal to times 2. Shift by 2 is 4, 3 is 8, etc, afaik.
Same goes for right shift, only that it's multiplication instead.
I've also made a chip8 emulator called "Chippu."
A good documentation would be dave winter's, although probably the best one would be mine, but I haven't made that one public yet.
well make it public! :naughty:
sammyboy
April 19th, 2004, 18:45
No I like a site. www.goldroad.com
Doomulation
April 20th, 2004, 13:22
well make it public! :naughty:
It's incomplete and it's at home, so I can't do that right now :P
Oh yeah and goldroad euqals NOTHING compared to the tech docs, btw. It only tells you the very basics of how to make a chip8 emulator.
EDIT: Crap, I realized the name I wrote for my emulator is wrong. I'm stuck with the old name I came up with before deciding the real name :P The real name is "Chuit," not "Chippu."
Villela
April 20th, 2004, 15:12
To emulate chip8 you don't need to much things, just needs little things like this table:
http://members.aol.com/autismuk/chip8/chip8def.htm
sammyboy
April 20th, 2004, 20:27
Yeah I cant do anything at the moment because of the fact that my Visual Studio hasnt came yet (I have ordered it from Bangkok). But when it comes I will make two versions of my chip 8 emu. 0ne using the goldroad docs and the other using the table thingy I dont know (if only other emus would be as simple as this). I have decided to emulate the SCHIP after then try something like a gameboy then work on a next gen emu. See how that goes.
Teamz
April 20th, 2004, 23:37
Yeah I cant do anything at the moment because of the fact that my Visual Studio hasnt came yet (I have ordered it from Bangkok). But when it comes I will make two versions of my chip 8 emu. 0ne using the goldroad docs and the other using the table thingy I dont know (if only other emus would be as simple as this). I have decided to emulate the SCHIP after then try something like a gameboy then work on a next gen emu. See how that goes.
lol
come on man try to be a little more realistic :doh:
Niggy G
April 21st, 2004, 00:44
lol
come on man try to be a little more realistic :doh:
At least he’s being semi-realistic. Better than the n00bs that come on saying there going to make a game cube emu will VB be alright to write it in, lol, shit I forgot sammyboy did that.
Seriously at least he now understands that it would take immense effort and he’s starting in the right place with a basic emu, good luck to you sammyboy, everyone starts somewhere!
Doomulation
April 21st, 2004, 12:35
To emulate chip8 you don't need to much things, just needs little things like this table:
http://members.aol.com/autismuk/chip8/chip8def.htm
That list is even incomplete. Sure, it lists all opcodes you'd need for chip8, but not all schip8 opcodes, oh no. I recommend dave winter's documetation. It lists all opcodes there is. And in some complicated way, it also describes the cpu, memory, etc.
And I know that goldroad HAS NO documentation for chip8 that I'm aware of. The tutorial links were even all broken.
Oh and even if you do a gameboy emulator, you won't even get a single demo of a next-gen system working, oh no. You need far more experience with emulators before starting such an emulator.
euphoria
April 21st, 2004, 14:02
sammyboy, One word of advice: "The more you know, the more you know what you don't know". This is so true when it comes to emulation.
But anyways good luck to your next-gen console emu (PS4? ;))
Old gil
April 21st, 2004, 21:57
i noticed in your other post that u mentioned that you never programmed any program before this, if this is the case, i wouldnt even reconmend starting with a simple emulator like that, i would mess around with some basic programs ie: simple games (tic tac toe) i wouldnt start out with an emulator...
mesman00
April 22nd, 2004, 01:31
i noticed in your other post that u mentioned that you never programmed any program before this, if this is the case, i wouldnt even reconmend starting with a simple emulator like that, i would mess around with some basic programs ie: simple games (tic tac toe) i wouldnt start out with an emulator...
take old gil's advice...wait a minute, hasn't gil failed at everything he's tried? haha, seriously though, take his advice, as it's my advice too.
sammyboy
April 22nd, 2004, 09:17
Yeah I have got a Visual C++ book and I have created things like hello world, the lottery program, and like talking games where it comes up with different animal noises at random. I am going to work on a calculator then some simple games
Doomulation
April 22nd, 2004, 10:40
Muahahahahaha, that will get you nowhere!
Can you handle input? Can you handle gfx? Can you handle sound? Can you handle bits & bytes & shifting? Can you handle binary operations?
If you answer "no" to any of these questions, I recommend you go learn these before attempting an emulator. :whistling
Villela
April 22nd, 2004, 21:20
Muahahahahaha, that will get you nowhere!
Can you handle input? Can you handle gfx? Can you handle sound? Can you handle bits & bytes & shifting? Can you handle binary operations?
If you answer "no" to any of these questions, I recommend you go learn these before attempting an emulator. :whistling
handle bits & bytes & shifting isn't a hard thing, if he takes a look to some code he can do this kind of thing, and it ins't the only way, you can find others
Gfx can be do it using an ascii output, sound doesn't are necessary, imput also is unecessary, you can just simulate random imputs to test the emulator
A chip-8 emu doesn't need to be playable, an *i believe* it can be used to learn some language, btw some logical of programing is necessary
Doomulation
April 26th, 2004, 14:26
*Cough*
Just getting an emulator to "work" isn't quite enough. Sure, it's a great deal, however, to extend it to its fullest and REAL practice, you need to make it WORKING.
handle bits & bytes & shifting isn't a hard thing, if he takes a look to some code he can do this kind of thing, and it ins't the only way, you can find others
No of course it isn't hard. Nothing is hard once you learn it, but in the beginning it might be. What other ways?
Gfx can be do it using an ascii output, sound doesn't are necessary, imput also is unecessary, you can just simulate random imputs to test the emulator
Ascii output, huh? There just isn't enough space to output using cout or such functions. Besides that, on more complex emulators (even gameboy) it is a MUST to learn this. Ascii won't do. Sound *IS* necessary, although not that much in chip8.
Just putting in random input is cheating and you won't learn anything from it.
A chip-8 emu doesn't need to be playable, an *i believe* it can be used to learn some language, btw some logical of programing is necessary
Yeah right...
You need to get the emulator working to get an understanding on how the real emulators work, to trace DOWN BUGS, etc etc. No, you need to learn it a little more than just get it working actually...
refraction
April 26th, 2004, 15:41
*Cough*
Ascii output, huh? There just isn't enough space to output using cout or such functions.
actually its very possible, its just quite slow, as you can see from the screenshots from my emu HERE (http://djxander.artists.mpfspromotions.com/chip8/chipscreens.htm) :P
this document is the only one you need, ive added a couple of comments in case of confusion on some of the op codes.
Chip8 Documentation (http://djxander.artists.mpfspromotions.com/CHIP8.htm)
Villela
April 26th, 2004, 16:40
No of course it isn't hard. Nothing is hard once you learn it, but in the beginning it might be. What other ways?
Puting the rom in a long char array
Ascii output, huh? There just isn't enough space to output using cout or such functions. Besides that, on more complex emulators (even gameboy) it is a MUST to learn this. Ascii won't do. Sound *IS* necessary, although not that much in chip8.
Its just chip-8, sound can be a beep beep, not emulating the sound will of course make the emulator limited but will not make you unable to emulate chip-8
Just putting in random input is cheating and you won't learn anything from it.
You learn the instruction and will implement the imput instruction, just from another way
You need to get the emulator working to get an understanding on how the real emulators work, to trace DOWN BUGS, etc etc. No, you need to learn it a little more than just get it working actually...
A simple and incomplete emulator don't need to have bugs, but can make the one who does learn the basics of an emulator
@refraction: nice :)
Doomulation
April 27th, 2004, 08:32
Puting the rom in a long char array
Each instruction is two byte. Do you want to put it in a WORD array? If you do, what if the gfx data is no even-addressed? You need bifts, bytes & shifting anyhow you do it.
Its just chip-8, sound can be a beep beep, not emulating the sound will of course make the emulator limited but will not make you unable to emulate chip-8
I agree somewhat with you there. Chip8 only has a beep sound, but still, it would be a good thing to emulate the sound opcodes.
You learn the instruction and will implement the imput instruction, just from another way
I mean, you won't learn how to do real input ;)
A simple and incomplete emulator don't need to have bugs, but can make the one who does learn the basics of an emulator
Well, then you miss out essential parts needed for experience of a more advanced emulator, see?
Villela
April 27th, 2004, 13:59
the long char array: convert it, when reading you do an array like: long char rom[] = "00E0621A...." i don't know how can be do it in C or C++ but i believe it can
the soud: yes it will be nice to emulate all, put a beep beep message in ascii
input: will not learn to make an input but will learn how to emulate the chip8 input
What i'm saying is that someone don't need to do a chip emu to play or to the others play, and if find problems or things that don't know how to do can do an alternative way, if someday the one learns how to make an imput and grafics in other output he can go there and emulate correct, but isn't the way you do the things, what matter is doing the emulator and learn
Doomulation
April 28th, 2004, 08:47
How do you suppose to convert it, then?
int smthing = (int)memory[i]; // Will convert only that char
int smthing = (int)(memory[i] + memory[i+1]); // Wonder if it does work?
Besides, there are instructions that wants you to shift bits in strings. Although this can be done with division or multiplication, it's much more expensive in time rather than shift.
About input...you know, knowing how to use & recieve input is all part of the training...it's not something you really want to be without. It can be used for many things, in many applications.
Of course you can do things an alternate way, that's how emulators work. They don't do it exactly like the consoles does, they do it an "alternate" way, which achieves the same result.
Say, if there's a bug that causes some games to go weird, what do you do to fix it?
All these parts are essential to making a more advanced emulator. If you can't find the simplest bugs, then probably no game at all will boot in any emulator you make. And that's no experience since you don't get it right...
euphoria
April 28th, 2004, 12:16
How do you suppose to convert it, then?
int smthing = (int)memory[i]; // Will convert only that char
int smthing = (int)(memory[i] + memory[i+1]); // Wonder if it does work?
int wSmthing = *(int *)&chMem[i]; // makes integer out of char-array element
long dwSmthing = *(long *)&chMem[i]; // makes long integer out of char-array element
There are other ways ofcourse, this was just an example.
Doomulation
April 28th, 2004, 12:56
Right, didn't think of that. I have used that method once, though.
I suppose it can be done without shifting in chip8, but for other things, such as wonderswan (oh, I've seen it), it's pretty damn hard without shifting and logic understanding.
ector
May 10th, 2004, 14:01
euphoria's method depends on the endian-ness of your processor though. On x86 (little endian) the low byte comes first, on PowerPC and many others the high byte comes first.
BTW, I don't understand why people are making such a big deal of nextgen emulators. In fact, I went from Chip8 to Gameboy to nextgen. Granted, I do have a lot of other coding experience but if you understand the concepts, the only difference about nextgen emulation compared to emulating older systems are the immense speeds of the newer CPU:s and the complexity of some systems. The Gamecube is actually one of the "simplest" consoles above 8 bits to ever come out. The real challenge with the Gamecube lies in the insane CPU requirements of emulating the 485MHz PowerPC at full speed, and reverse engineering the graphics chip (it's pretty damn complex but nothing I can't handle, in theory at least :) ) . And of course the sound has to be HLE:d since the DSP is completely unknown.
euphoria
May 11th, 2004, 10:27
euphoria's method depends on the endian-ness of your processor though. On x86 (little endian) the low byte comes first, on PowerPC and many others the high byte comes first.
BTW, I don't understand why people are making such a big deal of nextgen emulators. In fact, I went from Chip8 to Gameboy to nextgen. Granted, I do have a lot of other coding experience but if you understand the concepts, the only difference about nextgen emulation compared to emulating older systems are the immense speeds of the newer CPU:s and the complexity of some systems. The Gamecube is actually one of the "simplest" consoles above 8 bits to ever come out. The real challenge with the Gamecube lies in the insane CPU requirements of emulating the 485MHz PowerPC at full speed, and reverse engineering the graphics chip (it's pretty damn complex but nothing I can't handle, in theory at least :) ) . And of course the sound has to be HLE:d since the DSP is completely unknown.
This must be nothing new to you ector but to others interested (if any?) the endianess situation can be solved like this:
int wSmthing = *(int *)&chMem[i ^ a];
long dwSmthing = *(long *)&chMem[i ^ a];
where a is a number that corresponds to what we want to XOR.
The XOR binary operator turns the wanted lower bits to what we want when accessing byte-swapped (^1) or word-swapped (^3) or byte&word-swapped (^2)
Example: we have address 0x0000 which is byte&word-swapped. We want to access its first byte (which is in address 2) we apply 0x0000 ^ 2 = 0x0002,
second byte 0x0001 ^ 2 = 0x0003,
third byte 0x0002 ^ 2 = 0x0000,
fourth byte 0x0003 ^ 2 = 0x0001.
If you play with it for a while it comes apparent to you how this works.
Doomulation
May 11th, 2004, 13:22
Errr, I don't think I get what that means. I think I'll just stick with shifting; much easier imo.
ector
May 11th, 2004, 18:04
Stick to shifting; what euphoria proposes just won't work. The XOR will fix the *starting* address of the large read, so one byte will be right, but the rest will be wrong.
euphoria
May 12th, 2004, 13:39
Stick to shifting; what euphoria proposes just won't work. The XOR will fix the *starting* address of the large read, so one byte will be right, but the rest will be wrong.
Yes, you're right. I was only thinking of byte-sized reads but at the same time wrote code for 4-byte-sized read :doh:
Like ector said it's best to stick with per-byte reads and shift and AND them together.
Doomulation
May 12th, 2004, 14:29
Yeah... so, making an emulator without shifting and logic understanding isn't a good thing.
I didn't get HOW that method worked, anyway.
sammyboy
May 12th, 2004, 17:26
I thought this topic was dead ages ago
Doomulation
May 14th, 2004, 13:10
Well...no. April 28th -> 10th may.
-//zAe\\-
May 18th, 2004, 18:03
Well, it would be great if you will continue this topic. I am about to code my own chip8 emu ;) and this topic is quite usefull for me.
sammyboy
May 18th, 2004, 19:07
Could you keep us informed on all your latest progress. The emul;ator will prbably (at the most) only take you a couple of days).
-//zAe\\-
May 18th, 2004, 20:33
Could you keep us informed on all your latest progress. The emul;ator will prbably (at the most) only take you a couple of days).
Well.. yes! As soon as i will gain a few days of free time to spend :(
And you? Have you already done your Emu?
sammyboy
May 18th, 2004, 21:31
Well.. yes! As soon as i will gain a few days of free time to spend :(
And you? Have you already done your Emu?
I cant I realised (looking aty the comments on download.com) that my compiler doesnt have the functions for emulation deving. Anyways I am getting Visual Studio.net on Thurs so YAY.
Doomulation
May 19th, 2004, 09:01
Hehe, all you need to do a chip8 emulator, huh?
Damn, only a couple of days to do the emulator, but to get it perfect? :P
I still have bugs in the core which I can't be arsed to iron out.
Meh. Well, if you're wondering something about the chip8 system, don't hestitate to ask.
-//zAe\\-
May 19th, 2004, 12:31
Hi! I have perfectly understood your point ;) !
No! I am not going to code the bugless Emu in couple of days ;P ! Just wanna code a little interpreter, witch will show "something". I am not really a newbie to programming, and i know how mutch time things take... But i am almost complete newbie to the emulation...
And... thaks for being interested ;) !
-//zAe\\-
May 19th, 2004, 16:03
(Sorry for double post :) )
Well, it took me about 3 or 4 hours to understand how the interpreter should work (and how should i code it)... Is this a good time for chip8 emu?
sammyboy
May 19th, 2004, 18:12
Proably.. yeah I mean its olny basic stuff so program what you know and if you forget something just check back to the docs (or whatever you use).
-//zAe\\-
May 19th, 2004, 21:45
After a while i have coded a crappy Chip8 Disassembler :)
sammyboy
May 19th, 2004, 23:22
When you think its ready send it to me!!!! Maybe a couple of versions during development... Already compiled if you think that I might use the source... No actually wait it would have to be compiled because my Compiler doesn support alot of functions (early development compiler).
dreamer
May 20th, 2004, 00:19
hey sammyboy, you finally decided to go for something a bit easier than a next-gen console emu, if im correct wasn't it me who told you to try something more simple first? not that i know anything about programing myself but its pretty obvious you can't jump into programming and expect to build something a team of skilled programmers take months and months to build - good luck with whatever you're trying anyway :P
-//zAe\\-
May 20th, 2004, 07:54
Everyone must realize that he must begin with someting simple by hisself.
sammyboy
May 20th, 2004, 07:59
hey sammyboy, you finally decided to go for something a bit easier than a next-gen console emu, if im correct wasn't it me who told you to try something more simple first? not that i know anything about programing myself but its pretty obvious you can't jump into programming and expect to build something a team of skilled programmers take months and months to build - good luck with whatever you're trying anyway :P
Yeah kinda.... But thats just on myself :whistling
Everyone must realize that he must begin with someting simple by hisself.
I dont actually understand this quote.
-//zAe\\-
May 20th, 2004, 09:33
Hello, Doomulation!
You sayed that i should not hestitate to ask you about Chip8.
So, i have one little tecnical question:
When i wrote a Chi8 Disasm, i have got unknown opcodes, for example in BLITZ rom:
(This is the part of my crappy disassambling program output)
----------------------------------------
Rom name: BLITZ
----------------------------------------
ProgramCounter Opcode ASM
----------------------------------------
.......
0x0000021A 0x00000461 ???
0x0000021C 0x00000962 ???
0x0000021E 0x00000E67 ???
0x00000220 0x000004D0 ???
.......
0x0000022C 0x00000A00 ???
0x0000022E 0x0000E022 ???
.......
0x00000232 0x00000A00 ???
0x00000234 0x0000E08E ???
.......
0x00000242 0x00000112 ???
.......
0x0000024A 0x0000077A ???
0x0000024C 0x0000017B ???
0x0000024E 0x0000FEDC ???
........
0x00000252 0x0000FF3A ???
0x00000254 0x00000012 ???
........
0x00000258 0x0000FF3E ???
0x0000025A 0x00000012 ???
.............
What are these opcodes?
P.S. Sammyboy, if you do not understand my quotes, just forget about them :) !
sammyboy
May 20th, 2004, 17:50
I will
aprentice
May 20th, 2004, 21:33
Since everyone was doing a chip8 emulator and its the "hip thing to be doing" nowadays, ive coded my own as well, just to say "I did it too!" :P
It took me about a day and a half to code, and its very fast since i coded the interpreter on a jump table instead of giant switch. It just needs to be slowed down now :P
If anyone needs help with their chip8 emu, feel free to post in the board, I might be able to help :P
http://darkengine.net/chip8/ap_chip8.jpg
Slougi
May 21st, 2004, 14:35
Heh well I got interested too :P
Got a disassembler going in around 1 hour. Seems pretty simple so far ;)
Remote
May 21st, 2004, 14:43
Can't any of you do a "how to" ?
Slougi
May 21st, 2004, 14:54
It doesn't get much simpler than the sites already mentioned.
Remote
May 21st, 2004, 15:21
Oki, but still? :P
-//zAe\\-
May 21st, 2004, 15:53
Maybe i will do a "how to", but first, i wanna finish my emu :)
But..... that "how to" will be written in Russian :( . I do not know English well because it is my 4th language ;)
So.. how about these opcodes? Are they really *important*? Or interpreter should never meet them?
krow
May 21st, 2004, 16:04
Hello, im making a chip8 emulator too... well is not mine but im doing better, i hope some day i will make my emulator
Doomulation
May 21st, 2004, 16:07
Hello, Doomulation!
You sayed that i should not hestitate to ask you about Chip8.
So, i have one little tecnical question:
When i wrote a Chi8 Disasm, i have got unknown opcodes, for example in BLITZ rom:
(This is the part of my crappy disassambling program output)
----------------------------------------
Rom name: BLITZ
----------------------------------------
ProgramCounter Opcode ASM
----------------------------------------
.......
0x0000021A 0x00000461 ???
0x0000021C 0x00000962 ???
0x0000021E 0x00000E67 ???
0x00000220 0x000004D0 ???
.......
0x0000022C 0x00000A00 ???
0x0000022E 0x0000E022 ???
.......
0x00000232 0x00000A00 ???
0x00000234 0x0000E08E ???
.......
0x00000242 0x00000112 ???
.......
0x0000024A 0x0000077A ???
0x0000024C 0x0000017B ???
0x0000024E 0x0000FEDC ???
........
0x00000252 0x0000FF3A ???
0x00000254 0x00000012 ???
........
0x00000258 0x0000FF3E ???
0x0000025A 0x00000012 ???
.............
What are these opcodes?
P.S. Sammyboy, if you do not understand my quotes, just forget about them :) !
Maybe if you explain to me what opcodes it doesn't find =]
Remote: Declare a memory array of chars, define stack pointer, define code pointer, declare and make all opcodes in functions, fetch two bytes of data from the memory and execute the opcode. Also define screen in chars and optionally if it's chip8 or schip8 (screen size is dependant, y'know).
Of course, you also need something like d3d to output the gfx and maybe the Beep! function to do the little beeping. Don't forget the sound timer and the delay timer ;) And oohhhh... the I! Which is manually set by the code to point to data.
That's basically it :P Unless you want that in code ;)
Remote
May 21st, 2004, 16:47
Ok, thanks. Nah, if you would write in in code, why should I do the same thing later on :P
Will have a look next week and see if I get hooked on programming again..
-//zAe\\-
May 21st, 2004, 17:19
Doomulation:
Well.... I will *try* to explain my point:
As you well know chip8 has common opcodes, like jmp, jsr, and, or, cls, mvi....., so when i wrote a disasm, and run it i had a lot of unknown opcodes such as:
0112
FEDC
0012
....
i compared the output of my disasm with crazychip8 one. It was the same, but crazychip8 marked my unknown upcodes as "scdown x", but in is not right! If i am not wrong scdown is 00Cx, but not 0112,FEDC,0012... What are these opcodes for?
aprentice
May 21st, 2004, 19:58
Sammyboy, 95% of the opcodes you have there are: Call 1802 machine code program at NNN
sammyboy
May 22nd, 2004, 13:52
What are you on... I aint makin no chip 8 emu.
Now in English...
Excuse me please can you tell me what the devil are you talking about. I am not developing any chip 8 emulator at the moment.
-//zAe\\-
May 22nd, 2004, 16:41
Finaly! My emu starts to show something ;)......
aprentice
May 22nd, 2004, 20:30
What are you on... I aint makin no chip 8 emu.
Now in English...
Excuse me please can you tell me what the devil are you talking about. I am not developing any chip 8 emulator at the moment.
opps, i confused you for someone who actually could code, sorry :P
ector
May 22nd, 2004, 23:30
nice job, it's fun to see so many new emu authors take their first steps, i started with chip8 too :)
-//zAe\\-
May 23rd, 2004, 00:31
nice job, it's fun to see so many new emu authors take their first steps, i started with chip8 too :)
So? What next? What system can you advice me?
P.S. Thanks for being interested :) !
Doomulation
May 23rd, 2004, 16:14
Gameboy? Just a guess.
-//zAe\\-
May 23rd, 2004, 16:33
Maybe...
I mean, what is the next simple system to emulate? What system should i emulate next?
I need an advice... :)
ector
May 23rd, 2004, 17:18
My next one was a Gameboy emulator for my personal use on my slow MIPS based Cassiopeia PocketPC for my but I cheated a little by looking at the source of other gb emus :)
My next emulator project after that was a little dreamcast emulator that never really got anywhere, and then I wrote a graphics plugin for Icarus (i had lots of experience with 3D programming before). And then when all the Gamecube hacking started, it was a natural step to try to make a GC emulator together with F|RES who had done some initial research. He's a reverse-engineering wizard.
-//zAe\\-
May 23rd, 2004, 18:33
Thanks, ector!
I will try to follow your experience! :)
P.S. I am a 3D programmer too :p
P.P.S. Can you advice me some usefull GameBoy docs?
ector
May 23rd, 2004, 22:06
I don't remember where you can find Gameboy docs, it was a long time ago.. just use Google :)
Anyhow Gameboy isn't necessarily the "next" platform in complexity, there are a lot of 8-bit systems with similar complexity.. The SMS (Sega Master System) is said to be quite easy, and there's a lot of information about it out there too, and there are a lot of games out for it (probably not as many as gameboy, but still tons). Having lots of games to try in your emulator is important, since it will help you find bugs. I'd recommend that you should at least take a look at Master System :) NES is however a lot more complex because of all the "mappers". There is still no 100% perfect NES emulator!
aprentice
May 23rd, 2004, 22:28
This thread is interesting, but we are going off topic :P
Someone should try something that hasnt been done before
with the chip8, like maybe "enhancing" it in some way. I've given my code
to bjz (who i know on irc) and he ported it to opengl with textured quads. Stuff like this would be interesting to try :P
-//zAe\\-
May 23rd, 2004, 22:46
Well.. I have created a new thread named "Game Boy" to serve these puropses :)
Doomulation
May 24th, 2004, 13:05
Well hmm, actually I *HAVE* thought about doing some misc hacks for the chip8 emulators...
I enhanced it by enlarging the gfx in a nice fullscreen. But there's always other features you could do for it... like manipulating the gfx, but I have no other ideas than that, though :P
aprentice
May 27th, 2004, 04:42
Heres some screen shots from my chip8 emu :P
90% of chip8 games run. More info as I progress.
Blitz:
http://darkengine.net/chip8/blitz1.gif
http://darkengine.net/chip8/blitz2.gif
Invaders:
http://darkengine.net/chip8/invaders1.gif
Missle:
http://darkengine.net/chip8/missle1.gif
UFO:
http://darkengine.net/chip8/ufo1.gif
VBrix:
http://darkengine.net/chip8/vbtrix1.gif
Wipeoff:
http://darkengine.net/chip8/wipeoff1.gif
refraction
May 27th, 2004, 11:19
well done :) nice to see some progress :)
if you have any problems let me know ill see if i can help.
Nice pictures Aprentice :P
http://xenge.emulation64.com/c83dpong.jpg
http://xenge.emulation64.com/3dc8.jpg
As fas as I know I have the first 3d c8 emulator that allows camera controlling and all :D just started this port of ren's emu last night and got it 3d today.
aprentice
May 27th, 2004, 19:07
Nice pictures Aprentice :P
As fas as I know I have the first 3d c8 emulator that allows camera controlling and all :D just started this port of ren's emu last night and got it 3d today.
Nice job bjz :D
kurni
May 27th, 2004, 19:10
:)
btw for anyone wondering thats opengl rendering :D i hate d3d
this pic shows off the 3d alot more
http://xenge.emulation64.com/invaders.jpg
refraction
May 27th, 2004, 23:32
nice job bjz :) thats kinda what im aiming for, but without the evil blue background.
see youve come across the same bug (in every way) i had with the scrolling writing on the space invaders title screen! i cant remember how i fixed it now either!
Mario image painted on every pixel :P looks messy but i was playin around
http://xenge.emulation64.com/c8mario.jpg
And here is a video ingame of pong, its to fast to be playable, we need to slow it down somehow.
http://xenge.emulation64.com/pong.avi
*********UPDATE***********
I added some cpu slowdown as you can see its much more playable. As to why its sped up some i have no clue i guess its the codec i used.
http://xenge.emulation64.com/pong2.avi
*********UPDATE***********
nice job bjz :) thats kinda what im aiming for, but without the evil blue background.
see youve come across the same bug (in every way) i had with the scrolling writing on the space invaders title screen! i cant remember how i fixed it now either!
nope got that fixed up yesterday by aprentice i didnt implement till now, text works now.
refraction
May 27th, 2004, 23:51
nope got that fixed up yesterday by aprentice i didnt implement till now, text works now.
ahh right, nice one man :)
check out the above post if you missed it i posred a small video of pong. 960kb or so
refraction
May 28th, 2004, 00:16
ahh wicked mate! i see what you mean, n that camera could get confusing! hope that was just you showing off the moveable camera :P
one way of slowing it down would to be just stick in an empty loop for example
for (int i = 0, i < 1000, i++){
}
either that or put in some code to detect the processor speed and make it only do so many operations per cpu clock cycle. think the docs say the chip8 system does 60 cycles per second.
say on a 2ghz system that 2000/60 = 33.3
so 1 operation per 33 mhz
Or just add a little counter allowing a new operation to be performed each CHip8 real clock tick.
Doomulation
June 3rd, 2004, 08:35
We don't know how much each time each opcode takes. So emulating speed is a little tricky. I guess.
refraction
June 3rd, 2004, 09:09
well with interpreters, on every op code call it cycles through the list of opcodes till it finds the one it wants. i suppose the only (and best) way to do it is put the code in where it tells it to interpret the next op code, i spose that would be classed as a chip8 cycle.
I've read once opcodes timing for Chip8, and they were probably wrong cause I remember they said opcode timing was a constant...
refraction
June 5th, 2004, 10:08
op code timing hmm, there is no certain amount of cycles for a chip8 code, far as i know theyre all 1 cycle and the system does 60 cycles per second.
Yes I've read that, the only thing to do in the interpreters is to execute each 1000/60 ms a instruction. Chip8 was my first experience in emulation programming :)
refraction
June 5th, 2004, 11:03
its my ONLY experience haha, but the timing is pretty constant on chip8, unlike other systems.
euphoria
June 5th, 2004, 13:41
well with interpreters, on every op code call it cycles through the list of opcodes till it finds the one it wants. i suppose the only (and best) way to do it is put the code in where it tells it to interpret the next op code, i spose that would be classed as a chip8 cycle.
That it cycles through the list of opcodes sounds bad. If you're doing it with if-else-statements, you should consider other options like function pointer tables. Because if you do it with if-else then the last instruction in your list takes the longest time to find and non-constant values in instruction calls are no good. Maybe a switch-case could work better, because function pointers are little obscure, if not familiar with them.
But i don't think that all this matters for performance in chip8.
sammyboy
June 5th, 2004, 14:21
You double posted exactly the same thing
Moreover, switch case *ARE* if-else if-else statements...
refraction
June 5th, 2004, 17:40
i am using switch case statements :plain:
euphoria
June 6th, 2004, 22:02
Moreover, switch case *ARE* if-else if-else statements...
I think that if the compiler is smart enough and it is possible it converts switch-cases to jump tables, but generally you're right.
sorry about the double post, little problems with my connection/browser, i thought that the message was never posted...
aprentice
June 7th, 2004, 08:22
I think that if the compiler is smart enough and it is possible it converts switch-cases to jump tables, but generally you're right.
sorry about the double post, little problems with my connection/browser, i thought that the message was never posted...
nope, i havent seen a compiler that does that yet :P
ector
June 7th, 2004, 09:10
aprentice, LXS: 1992 called, they want their compiler back :P
Modern compilers have compiled switches to jump tables wherever possible (and where it would improve performance) since many many years. Switches can be MUCH MUCH faster than a row of if/elses, and often ever so slightly faster than even function pointer arrays. I don't have MSVC right here (i'm not at my place atm), otherwise I'd show an example of what assembly it will output for some switch examples.
RipNLa
June 10th, 2004, 11:18
Hey, this is my first post here. I'm a veteran-n00b programmer and I've decided to try and make a Chip8 emulator as well.
I was just wondering if anyone could direct me to some basic Windows programming, so I can learn to make a GUI for my emu. Someone posted a screenshot earlier in this thread of their emulator where they had what looked like a Dialog box acting as the debugger for their emulator. What's the best way to implement this? Win32, MFC, .NET? Any resources/links I can look at that would help? I need to learn some of these basic things, as well as how to like have a FILE..OPEN work (i know how to make Menu's, just not how to call the function..) Thanks in advance. Oh, and sorry if this isn't the correct thread for this...
smcd
June 10th, 2004, 19:28
If you want to go the Win32 API route, www.winprog.org/tutorial/ is a good place to start.
refraction
June 10th, 2004, 21:53
well if you want the basics of C++ first there is a brilliant tutorial on http://www.cplusplus.com which is very easy to understand and well explained :)
RipNLa
June 11th, 2004, 02:10
sethmcdoogle: Thx, that had exactly what I was looking for.
refraction: At first, I wanted to laugh since I thought cplusplus.com only had basic C++ tutorials. But then I saw their Win32 examples, and there is a couple of useful things in there as well, so thanks.
krow
June 11th, 2004, 03:09
can someone give me an chip8 source code, please?
smcd
June 11th, 2004, 04:00
look up v8 or crazy chip-8 but if you read someone else's source you're likely to just want to copy it instead of trying stuff on your own :huh:
refraction
June 11th, 2004, 11:12
its not hard to do, just read up on the command, ive put a document HERE (http://djxander.artists.mpfspromotions.com/CHIP8.htm)
just remember, start the program reading at position 0x200 and incrament it by 2 each cycle.
refraction
June 13th, 2004, 16:43
heres the source the Chuit chip 8 emulator by Doomulation with a couple of fixes by myself :) (he told me to upload it!!)
its not the easiest code to understand but it does pretty much everything
chuit8.zip (http://djxander.artists.mpfspromotions.com/chuit8.zip)
Doomulation
June 13th, 2004, 21:07
Save for that it's pretty slow. Hope it helps... to any n00b out there who wants to do their own chip8 emu.
aprentice
June 13th, 2004, 23:56
i guess i'll release my chip8 source as well so people can learn from it. my source is probably the easiest to understand out of all chip8 emus cause its very neat and i kept the code simple :P
its fully emulates chip8 and schip8 but schip8 with problems. I havent had time lately to look into these bugs so if anyone fixes em, just post a reply to this post with the fix.
coded in vc++
refraction
June 14th, 2004, 00:58
only problems i can see is with the scroll
Scroll Left and Right are fixed to 4 pixel shifts.
there is no scroll up :P
Collision detection, set VF to 0 at the beginning of the command, cos if one part of the sprite collides, it will set to 1 , but then the next bit it draws, if it doesnt then its gonna set it to 0 again, so it thinks it aint collided :P
just before it plots the pixel put
if(vreg.memory[offset])
{
reg.v[0xF]=1;
vreg.memory[offset]=0;
}
and take the other bit out.
on drawsprite16 to cut the code down, just add
change xline to 16 and increase the yli
if(xline>8)
pixel=mem.memory[reg.i+yline+1];
else
pixel=mem.memory[reg.i+yline];
then modulate the shift
so its
if((pixel&(0x80>>(xline%8))
aprentice
June 14th, 2004, 02:37
only problems i can see is with the scroll
Scroll Left and Right are fixed to 4 pixel shifts.
2 for chip8 and 4 for schip8
there is no scroll up :P
There is but its not working right :P
Collision detection, set VF to 0 at the beginning of the command, cos if one part of the sprite collides, it will set to 1 , but then the next bit it draws, if it doesnt then its gonna set it to 0 again, so it thinks it aint collided :P
just before it plots the pixel put
if(vreg.memory[offset])
{
reg.v[0xF]=1;
vreg.memory[offset]=0;
}
and take the other bit out.
im not sure i understand what you mean there :P
on drawsprite16 to cut the code down, just add
change xline to 16 and increase the yli
if(xline>8)
pixel=mem.memory[reg.i+yline+1];
else
pixel=mem.memory[reg.i+yline];
then modulate the shift
so its
if((pixel&(0x80>>(xline%8))
code size isnt an issue to me :P
Btw, the gfx glitches i speak of are in dragon1 schip8 game and dragon2 has problems too but its with scrolling.
smcd
June 14th, 2004, 07:10
aprentice i managed to crash your emulator in various ways. =)
1) don't load a rom & go to debug->Registers window, click "start" or "step"
2) don't load a rom & go to debug->Dump Video
3) load an invalid file (0bytes or non-chip8)
smcd
June 14th, 2004, 07:11
Oh, and another way is to not load a file & CPU->Start
refraction
June 14th, 2004, 14:31
i didnt know about the scrolling in chip8, i knew it was available but ive never seen a game use it :P
what i mean with the collision detection, is on yours you set VF to 0 before it draws the sprite, thats good. but down the bottom just before it actually draws the sprite you have this
if(vreg.memory[offset])
{
reg.v[0xF]=1;
vreg.memory[offset]=0;
}
else
{
reg.v[0xF]=0;
vreg.memory[offset]=1;
}
say the shape is **** right, the left 2 pixels collide with something, VF is set to 1, then it draws the other 2 pixels, VF is set to 0 again, so by the time the op is finished running, VF = 0, so the system thinks there hasnt been a collision ;) so just take out the else VF = 0 part.
Ill show you what i have for drawing a 16x16 sprite which works perfectly, im sure you can work the code out :)
//Draw 16x16 Sprite
int x = registers[((opcode&0x0F00)>>8)];
int y = registers[((opcode&0x00F0)>>4)];
int whatline = 0;
registers[15] = 0x0;
for(int yline = 0; yline < 32; yline++) {
char data = memory->readmem(I + yline);
for(int xpix = 0; xpix < 16; xpix++) {
if(xpix == 8) {
yline++;
data = memory->readmem(I + yline);}
if((data&(0x80>>xpix%8)) != 0) {
if((screen->GetPixel((x+xpix), (y+whatline)))==1) registers[15] = 0x1;
screen->SetPixel((x+xpix), (y+whatline));
}
}
whatline++;
}
For scroll down i could see this being the problem
int offset2=x+((y*scrolly)*128);
i would have said more
int offset2=x+((y+scrolly)*128);
scroll right change
offset2=(x+(y*128))+scrollx;
to
offset2=((x+scrollx)+(y*128)); (altho it probably wount change much :P )
and same sort of thing for Scroll Left
offset2=(x+(y*128))-scrollx;
to
offset2=((x-scrollx)+(y*128));
hope that helps :)
aprentice
June 14th, 2004, 17:50
thanks for the heads up, i fixed those bugs you pointed out.
on the side note, i think the gfx glitches in the schip8 games are
comming from the 8bit sprite routine and not the 16bit sprite routine.
for example, the fighters in dragon1 are disfigured :P
refraction
June 18th, 2004, 00:01
i see what you mean, ive got it with mien as well, after about 5 seconds or so on Dragon1 it hangs after making some illegal calls, could be a corrupt game?
2nd one, got the scrolling working almost properly, just got like a trail on the propellers, but i dont know whats causing that
aprentice
June 18th, 2004, 05:33
i see what you mean, ive got it with mien as well, after about 5 seconds or so on Dragon1 it hangs after making some illegal calls, could be a corrupt game?.....
on your emu?
it works fine on mine except for the corrupt character sprites.
The rom is not corrupt because it works fine under other schip8 emus.
refraction
June 18th, 2004, 19:44
on your emu?
it works fine on mine except for the corrupt character sprites.
The rom is not corrupt because it works fine under other schip8 emus.
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.
aprentice
June 19th, 2004, 05:06
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
June 19th, 2004, 06:09
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:
refraction
June 19th, 2004, 15:26
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
June 20th, 2004, 14:23
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
June 20th, 2004, 18:01
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
June 21st, 2004, 04:06
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
June 21st, 2004, 08:40
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
June 21st, 2004, 09:53
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
June 21st, 2004, 11:36
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
June 21st, 2004, 20:54
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
June 21st, 2004, 21:01
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 :)
http://djxander.artists.mpfspromotions.com/chip8/dragon.JPG
Doomulation
June 21st, 2004, 21:11
Good job, refraction. :flowers:
aprentice
June 22nd, 2004, 03:00
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
June 22nd, 2004, 08:41
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
June 22nd, 2004, 12:37
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
June 22nd, 2004, 13:37
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
June 22nd, 2004, 23:10
Bueh! Don't use ifs...
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! :o
Neat about your emulator... hope it develops into something soon.
RipNLa
June 23rd, 2004, 04:59
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!
refraction
June 23rd, 2004, 11:39
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.
EDIT: MMM, boundary checking, good stuff =D Blitz works great now!
:saint:
manboy
June 24th, 2004, 03:59
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:
aprentice
June 24th, 2004, 04:07
http://msdn.microsoft.com/library/default.asp?url=/library/en-us/vclang/html/_pluslang_fundamental_types.asp
1111 (4bit) = 15 decimal or 0xF hex
11111111 (8bit) = 255 decimal or 0xFF hex
111111111111 (12bit) = 4095 or 0xFFF hex
Every chip 8 opcode is 16 bits (unsigned short).
X and Y are used to illustrate the register index. it is 4 bit because the chip 8 only has 15 general purpose registers.
KK is the data stored in the op
NNN is the jump address stored in the opcode
Example: Opcode 4XKK
bits 12-16 is the opcode, you could mask the bits out then shift them right 12 bits: opcode = (data&0xF000)>>12
bits 8-12 is the register index, register_index = (data&0x0F00)>>8
bits 0-8 is the data we do a compare on: misc_data=(data&0x00FF)
edit: if someone can explain this better than me, feel free to do so, i dont have the time or patience to explain this more in dept :P
refraction
June 24th, 2004, 11:44
following on from what aprentice said ;p the op code 4XKK is for "skip next instruction if vX is not equal to KK" for example
45D3
broken down that is
4 = opcode
5 = the register we want
D3 = the constant number
that would be, if register 5 doesnt contain the value D3 then skip the next instruction.
in c++ thats something like this
if (register[((opcode&0x0F00)>>8)] != (opcode&0x00FF) PC+=2
the reason we do opcode&0x0F00, what we are saying to the computer is:
from the variable "opcode" we was the value that sits in 0x0F00, but we dont want it that big so move it over so its a smaller number.
see :) now some explination on how we get the opcode variable.
When you load a rom into the memory, because the memory is 8 bit it can only store 2 hex values in each, to get the opcode you want 16bits which is 4 hex digits, so the opcode variable MUST be 16bit. when you load it from memory you want something like this
opcode = memory(pc)<<8 + memory(pc+1)
memory(pc) will contain 45, memory(pc+1) will contain D3, the reason i bit shift the first part over is because else you will just add the second value on to the first one. say if you had the number 23 and the other part was 10 (this is decimal btw) you put them together and you get 33, so the shift takes the first values over 2 places (4 bits for each) so you start with 4500, then when you add the 10 on, you will have 4510 :)
as you can see that uses 2 memory spaces, which is why we have to incrament the variable PC by 2 every cycle.
theres my screwed up explination, i hope that helps ;p
RipNLa
June 24th, 2004, 12:40
following on from what aprentice said ;p the op code 4XKK is for "skip next instruction if vX is not equal to KK" for example
...
that would be, if register 5 doesnt contain the value D3 then skip the next instruction.
in c++ thats something like this
if (register[((opcode&0x0F00)>>8)] != (opcode&0x00FF) PC+=2
Minor clarification just because I got thrown off for a split second =p It's only PC+=2, if you plan on doing it again (like at the end of a switch). As written, it should be PC+=4 to skip the next instruction since its !=
refraction
June 24th, 2004, 13:37
Minor clarification just because I got thrown off for a split second =p It's only PC+=2, if you plan on doing it again (like at the end of a switch). As written, it should be PC+=4 to skip the next instruction since its !=
ah yes forgot to mention that :P cos we i fetch my opcode i incrament it by 2 anyway so i dont have to put PC+=2 after each opcode is executed.
so if you dont do what i do then yes you want PC+=4 :)
RipNLa
June 26th, 2004, 07:34
ARGH! This timing thing is bugging me. It's pretty much the only thing holding me back from a complete Chip8 Emulator (haven't implemented the SCHIP stuff yet). I tried doing one op every 16ms and then decrementing the DelayTimer by one each loop as well.. But this doesn't work for Space Invaders, the monsters move way too fast..so I changed it to decrement the DelayTimer once every 3 operations, so once every 48ms, and thats better, but I don't know exactly what it SHOULD be..
Any help would be great. I tried just running the DelayTimer in a separate thread as well, but that was about the same. For now I've just got a variable speed limiter...which is good enough I guess..
refraction
June 26th, 2004, 15:19
to slow it down i used this cos that bjz kindly told me on here, on your loop where you tell it to fetch the next opcode then execute it, stick it inside this
DWORD lt = GetTickCount();
for(;;)
{
if(GetTickCount() - lt >= 1000/60)
{
lt=GetTickCount();
//execute command goes here
}
}
that should slow down how many cycles it does per second, controlling the speed for you :)
Doomulation
June 26th, 2004, 19:59
Just for the sake...
value = 0x1234;
value & 0xF000 = 0x1000
value & 0x0F00 = 0x0200
value & 0x00F0 = 0x0030
value & 0x000F = 0x0004
value & 0x0FF0 = 0x0230
Hope you got that.
Work goes on. With my powerful debugger I discover more and more what's wrong.
There's one thing that you should be alert of.
The FX55 and FX65 instructions. Some docs say increment I after saving or loading each register. That is WRONG. You should NOT do that.
And... I'll attach my newest version as well ;)
Just so you have something to look forward to. It's mostly untested, though, so don't blame me if anything goes wrong (goes mostly to speed).
I hope there's no missing DLLs or stuff now. Tell me if anything's missing, 'kay? You need DX9 to run this.
RipNLa
June 27th, 2004, 03:24
Refraction:
Yeah, I figured out how to get the timing down..I used a similar approach. I don't think that the DelayTimer is configured correctly. Right now, I decrement it 60 times per second. But at this rate..Space Invaders is realllly hard by the 4th wave, maybe its SUPPOSED to be that hard? If I decrement my DelayTimer like say..45 times per second, it makes the game a lot easier since it relies on the DelayTimer..so yeah, I'm just not sure how hard the game is supposed to be.
Doomulation:
Missing Registry.dll
RipNLa
June 27th, 2004, 09:31
Alright! Here it is finally! For your consumption! Just don't try and load files that aren't roms, because I don't know what will happen... except for something bad!
======================================== ==============
RIPxCHIP8 v1.0.0
======================================== ==============
- S key Enables/Disables sound.
- PGUP/PGDN keys speed up or slow down the emulator
- NUMPAD Keys to play, Games.txt to tell you what keys to use!
(Blinky, the PACMAN clone, uses 1,2,6,9 not 2,4,6,8)
Go to TOOLS->Options to tweak speed, change graphics color, and change the tone of the BEEP! WooO talk about customization!
Oh, and I added the Chip8 Roms into this zip (their all freeware to my knowledge) just incase you didnt have it already, total zip file size is less than 100k, no DLL necessary, enjoy.
refraction
June 27th, 2004, 15:39
RipNLa thats a very good chip8 emu!! every game works which is a big achievement!! now all you need to do is add SChip8 support (which i can tell you how to do) and itll be brilliant, itd be worth submitting to emulation sites :)
Doomulation
June 27th, 2004, 21:30
Damn, how the hell did it get so fast?
I new a new damn API to render, because this system doesn't seem fit for d3d rendering.
Source code for directdraw please? :whistling
I don't have ddraw since I have dx9 :saint:
EDIT:
I reuploaded a new version of the emulator. I've gotten rid of the d3d and registry libraries and it's about 100 kb smaller. The rest of the libraries I'll keep, I will. I also tweaked speed a little more since last time.
Btw, all chip8 games are freeware, actually.
refraction
June 28th, 2004, 03:18
Right heres the emu ive been working on, pretty much fully functional, please read the Readme.txt :) if you need the msvcr71.dll or anything simular, its in the dll.zip ive also attached:) any other missing files just let me know.
Edit: i just remembered this version is compiled to work only on P4 or AMD 4 machines :S its now been replaced so it should work ok on any machine.
Edit Number 2: updated it again! (i know i only just updated it) Heres the changes log as of 2 minutes before i posted it :P
[ Legend: ]
[ + Added feature ]
[ * Improved/changed feature ]
[ - Bug fixed (we hope) ]
[ ! Attention (Notes) ]
Added code in ChipVideo.cpp so it draws the black pixels as well..
seems to want it else you just get a mountain of White :P
[+] Added SChip8 Extended Op codes. (what a pain they were too!)
[-] Fixed a couple of opcodes.
Changed the key register so its an array, so more than one key can be checked at once.
28/06/04
Added Code to speedup/slow down the emu
[-] Blitz works now (maybe any other broken games), bit of code was ruining it!
RipNLa
June 28th, 2004, 04:03
Damn, how the hell did it get so fast?
I new a new damn API to render, because this system doesn't seem fit for d3d rendering.
Source code for directdraw please? :whistling
I don't have ddraw since I have dx9 :saint:
Actually, my rendering was all in D3D. I don't use DDRAW either, since I use DX8 (I still have a GF4 Ti4200) =\
refraction
June 28th, 2004, 17:08
emu uploaded and updated :) afaik, it pretty much works fine now.
Doomulation
June 28th, 2004, 19:55
Actually, my rendering was all in D3D. I don't use DDRAW either, since I use DX8 (I still have a GF4 Ti4200) =\
Then how the hell did you do!? Lol, I'm trying every possible thing to get it faster.
I will concentrate on speed until I'm satisfied until I start fixing compability again.
aprentice
June 29th, 2004, 00:27
Then how the hell did you do!? Lol, I'm trying every possible thing to get it faster.
I will concentrate on speed until I'm satisfied until I start fixing compability again.
are you doing any pixel enlargements? if you are, you lose your speed down to playable because of it :P
My chip8 emu would be lightening fast if i wasnt doing any pixel enlargements in the video core due to my cpu core being highly optimized (to make up for the speed loss in the pixel enlarger).
A solution would be to use quads, which would bring it back up on speed.
RipNLa
June 29th, 2004, 01:57
are you doing any pixel enlargements? if you are, you lose your speed down to playable because of it :P
My chip8 emu would be lightening fast if i wasnt doing any pixel enlargements in the video core due to my cpu core being highly optimized (to make up for the speed loss in the pixel enlarger).
A solution would be to use quads, which would bring it back up on speed.
What do you mean by pixel enlargements? Mine makes every 1x1 pixel a 10x10 pixel...is that considered pixel enlargement?...I'm even wondering if I even needed to do that since you can stretch the window to any size you want anyways...
zenogais
June 29th, 2004, 02:19
hehe, cool Refraction, well I'm back from my Bahamas vacation, I was working on the tutorial every chance I got on vacation, I've also decided on a few things I wanted to demonstrate in this emulation tutorial (if I can), My list is as follows:
* Dynamic Recompilation
* Static Recompilation
* High-level of cross-platform compatability
Sadly I didn't get a chance to download the emulator sources before I left, so I haven't worked on it, but I did find a few bugs right before I left, which I'm now working on fixing. Also refraction, you can release the sources since I did license it under the GPL. Also I meant to make it more usable than in its current state, as having to type the ROM name in the DOS prompt is relatively annoying. Also, I'd rather not have any more releases until I can finish the tutorials, but great work, you've become a Chip8 expert! :P
refraction
June 29th, 2004, 15:38
glad to see you back mate :) the emu works 100% apart from the lack of sound and the fact you need to use a dos prompt ;p
but as requested, heres the source under GPL
NeoChip8-src.zip (http://djxander.artists.mpfspromotions.com/NeoChip8-src.zip)
zenogais
June 30th, 2004, 06:02
Hehe, well I've just fixed the BCD encoding for NeoChip8, and I figured I'd share the solution as this is a common problem:
//======================================== ==========
// Write BCD Encoded Value Of Register To Memory
//======================================== ==========
case 0x33:
{
unsigned char ucRegister = (m_cpuContext.opcode&0x0F00)>>8;
// Calculate BCD Encoding
char ucBCD1 = m_pMemory->getRegister(ucRegister)/100;
char ucBCD2 = (m_pMemory->getRegister(ucRegister) - (100*ucBCD1))/10;
char ucBCD3 = (m_pMemory->getRegister(ucRegister) - (10 *ucBCD2));
// Write BCD Encoded Values
m_pMemory->writeByte(m_cpuContext.I , ucBCD1);
m_pMemory->writeByte(m_cpuContext.I + 1, ucBCD2);
m_pMemory->writeByte(m_cpuContext.I + 2, ucBCD3);
}
break;
GbaGuy
June 30th, 2004, 07:23
char ucBCD1 = m_pMemory->getRegister(ucRegister)/100;
char ucBCD2 = (m_pMemory->getRegister(ucRegister) - (100*ucBCD1))/10;
char ucBCD3 = (m_pMemory->getRegister(ucRegister) - (10 *ucBCD2));
shouldn't that last one be:
char ucBCD3 = (m_pMemory->getRegister(ucRegister) - (100*ucBDC1) - (10 *ucBCD2));
?
otherwise, say getRegister returns 253:
BCD1 = 2
BCD2 = 5
BCD3 = 253 - ((10*5)==50) = 203...
Did I miss something? I never use BCD so I could be completely off here...
refraction
June 30th, 2004, 14:17
Hehe, well I've just fixed the BCD encoding for NeoChip8, and I figured I'd share the solution as this is a common problem:
//======================================== ==========
// Write BCD Encoded Value Of Register To Memory
//======================================== ==========
case 0x33:
{
unsigned char ucRegister = (m_cpuContext.opcode&0x0F00)>>8;
// Calculate BCD Encoding
char ucBCD1 = m_pMemory->getRegister(ucRegister)/100;
char ucBCD2 = (m_pMemory->getRegister(ucRegister) - (100*ucBCD1))/10;
char ucBCD3 = (m_pMemory->getRegister(ucRegister) - (10 *ucBCD2));
// Write BCD Encoded Values
m_pMemory->writeByte(m_cpuContext.I , ucBCD1);
m_pMemory->writeByte(m_cpuContext.I + 1, ucBCD2);
m_pMemory->writeByte(m_cpuContext.I + 2, ucBCD3);
}
break;
umm that makes the p2 score dissapear in pong when P1 reaches 10.
this code seems to work the best, as i had when i gave you the code :P
case 0x33:
{
unsigned char ucRegister = (m_cpuContext.opcode&0x0F00)>>8;
m_pMemory->writeByte(m_cpuContext.I, (m_pMemory->getRegister(ucRegister)/100));
m_pMemory->writeByte(m_cpuContext.I + 1, ((m_pMemory->getRegister(ucRegister)%100)/10));
m_pMemory->writeByte(m_cpuContext.I + 2, (m_pMemory->getRegister(ucRegister)%10));
}
break;
altho there is aproblem with the scores, the source of pong says it checks V3 to see if it should add 10 or 1 to the score.. but it doesnt do it properly. oh well :P
Doomulation
June 30th, 2004, 19:13
are you doing any pixel enlargements? if you are, you lose your speed down to playable because of it :P
My chip8 emu would be lightening fast if i wasnt doing any pixel enlargements in the video core due to my cpu core being highly optimized (to make up for the speed loss in the pixel enlarger).
A solution would be to use quads, which would bring it back up on speed.
Yes, I use enlargment. I use two traingles for every pixel, because I can't see how to use quads. As far as I can see, d3d doesn't support them, even though the hardware does.
The time is wasted in pDevice->DrawPrimitive.
Btw zenogais, refraction has pretty much worked on that system 24 hours a day without ANY work on any other project :P He's like... possessed :evil:
zenogais
June 30th, 2004, 20:43
Yes, I use enlargment. I use two traingles for every pixel, because I can't see how to use quads. As far as I can see, d3d doesn't support them, even though the hardware does.
The time is wasted in pDevice->DrawPrimitive.
Btw zenogais, refraction has pretty much worked on that system 24 hours a day without ANY work on any other project :P He's like... possessed :evil:
I dunno, it works very well here. But BCD encoding is only used for storing of scores as far as I can tell.
EDIT: Whoops, there was a math error in the old BCD encoding, heres the new technique, works exactly as it should (refraction tested it mmm k :P )
//======================================== ==========
// Opcode: 0xFX33 - Store BCD Encoding Of VX At I
// Write BCD Encoded Value Of Register To Memory
//======================================== ==========
case 0x33:
{
unsigned char ucRegister = (m_cpuContext.opcode&0x0F00)>>8;
// Calculate BCD Encoding
unsigned char ucBCD1 = ((m_pMemory->getRegister(ucRegister)/100));
unsigned char ucBCD2 = ((m_pMemory->getRegister(ucRegister) - (ucBCD1*100))/10);
unsigned char ucBCD3 = ((m_pMemory->getRegister(ucRegister) - ((ucBCD1*100) + (ucBCD2*10))));
// Write BCD Encoded Values
m_pMemory->writeByte(m_cpuContext.I , ucBCD1);
m_pMemory->writeByte(m_cpuContext.I + 1, ucBCD2);
m_pMemory->writeByte(m_cpuContext.I + 2, ucBCD3);
}
break;
Also, sometimes DrawPrimitiveUP can be faster than DrawPrimitive.
Doomulation
June 30th, 2004, 22:58
Indeed, it was faster. Thanks for the tip zenogais.
But I'd want to speed it up more! :P After all, this is an ancient machine!
zenogais
June 30th, 2004, 23:15
Run a profiler, unless you've got a really poorly designed drawing routine, Direct3D shouldn't be the bottleneck.
Doomulation
June 30th, 2004, 23:57
I have. I've pretty much optimized all my code. I made a lot of functions inline... removed some code... and such. The profiler shows almost all cpu power spent in the draw function.
And even so, when I comment out the drawprimitive functions, I gain a big noticeable speedup.
Now this is truly a mystery to me.
I tried to look for a way to disable all the passes done in the pipeline to no avail. I mean, it pretty much just has to show the damn contents on the screen!
zenogais
July 1st, 2004, 00:14
If you could send me the source (zenogais@gmail.com) code or post it, I can have a look and try to speed it up. Also inlining alot of functions isn't necessarily the best idea, as it just bloats the executable and may even slow the program down. I would only inline functions that have a high hit rate(called very often i.e. >= 40% of all calls), everything else would not benefit from inlining.
EDIT: Here's (http://www.zenogais.net/projects/NeoChip8) the official NeoChip8 website I started last week. You can find doxygen documentation, the latest sources, and an image of Space Invaders working. I've managed to get sound working as well (Thats the executable I've attached).
RipNLa
July 1st, 2004, 10:50
Hey Doomulation, this might be a stupid suggestion, but are you calling the Render function after every op? I was doing that before I realized I only really have to call it on the drawsprite op
refraction
July 1st, 2004, 13:24
Hey Doomulation, this might be a stupid suggestion, but are you calling the Render function after every op? I was doing that before I realized I only really have to call it on the drawsprite op
yeh i realised that as well, only call it on the drawing command and scroll commands if you have SChip8 implemented.
refraction
July 1st, 2004, 16:03
zenogais: cheers for that bit of code mate! i didnt quite have my shift right correct that was causing my problem in Blinky!!! so now every game works, plus i implamented sound on it from your source, and the sound triggers almost everytime its suppose to ;p altho on occasion it sounds a bit retarded.
Doomulation
July 1st, 2004, 20:21
Hey Doomulation, this might be a stupid suggestion, but are you calling the Render function after every op? I was doing that before I realized I only really have to call it on the drawsprite op
It doesn't. It only draws on the draw op and the scroll ones.
Zenogais: I found that your suggestion took away all load from the draw function. In my profiler, it takes 0% of the cpu time. The slow code lies elsewhere now... mostly, it seems th cpu takes about 75% of the time. Maybe some ops could be optimized, but those heavily called are mostly the scrolls and draw (I've mostly tried car).
Actually, I think I'll try to merge some of the ops of neochip8 first. Then I'll update my documentation. Then I can post the source.
I'll probably re-write this emulator from scratch later, as copying off others ops aren't fun.
EDIT: Here's the new source. Just watch out, some games run darned fast =)
I also updated the DirectInput library for more speed. So be sure to grab this as well. And don't forget you still need the d3dfont.dll library found in the previous build (I haven't touched it).
EDIT2: You probably want the lib headers too so you can compile the source.
zenogais
July 1st, 2004, 21:26
I've tried to make my version of NeoChip8 as portable as possible, which is why I am also working on writing a function similar to Beep() for Linux users. I've found a way and am currently implementing it into my source code. Here's the Linux version of Beep:
EDIT: Whoops, made some mistakes, here ya go:
#if defined(__LINUX__) || defined(__MACOSX__)
#include <stdlib.h>
#include <unistd.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <linux/kd.h>
#define DWORD unsigned long
void Beep(DWORD dwFreq, DWORD dwDuration)
{
int fd, arg;
fd = open("/dev/tty0", O_RDONLY);
arg = (dwDuration<<16)+(1193180/dwFreq);
ioctl(fd,KDMKTONE,arg);
usleep(dwDuration * 1000);
}
#endif
Doomulation
July 2nd, 2004, 20:36
I noticed in refraction's source, your scroll op isn't perfect. This is noticeable in spacefic. Don't know if it's in others.
You need to check so that it doesn't wrap to another line when it goes outside the screen.
Here's mine so far which seems to work:
case 0x000B: // Scroll screen 4 pixels right
byte temp_screenr[128*64];
int scroll_right; scroll_right = bExtendedScreen ? 4 : 2;
ZeroMemory(temp_screenr,sizeof(temp_scre enr));
for (int i=0; i<64; i++)
{
for (int j=0; j<128; j++)
{
if (screen[i*128+j])
if ( ( (i*128+j) + scroll_right ) < ( (i+1)*128 ) )
temp_screenr[(i*128+j)+scroll_right] = 1;
}
}
memcpy(screen,temp_screenr,sizeof(screen ));
RenderScreen();
return;
case 0x000C: // Scroll screen 4 pixels left
byte temp_screenl[128*64];
int scroll_left; scroll_left = bExtendedScreen ? 4 : 2;
ZeroMemory(temp_screenl,sizeof(temp_scre enl));
for (int i=0; i<64; i++)
{
for (int j=0; j<128; j++)
{
if (screen[i*128+j])
if ( ( (i*128+j) - scroll_left ) >= (i*128) )
temp_screenl[(i*128+j)-scroll_left] = 1;
}
}
memcpy(screen,temp_screenl,sizeof(screen ));
RenderScreen();
break;
RipNLa
July 4th, 2004, 14:42
Hey, quick question.. I put the SCHIP stuff into my emulator today and have a few little problems to iron out. On the game ALIEN, right as the actual game is going to start, my emu hangs on opcode 0xF030..and in CAR, if I beat the level (cross finish line) my emu hangs on that same opcode, 0xF030. As far as I can tell, that opcode isn't documented... I put in a skip call for it, and ALIEN went on with the game =\ I forgot what other games, but one or two other games hit the same problem eventually as well =\ Any idea anyone?
refraction
July 4th, 2004, 15:04
try getting the document for VChip8, it has opcodes that arent in the david winter document, FX30 is set I to the SChip8 font sprite in VX.
RipNLa
July 5th, 2004, 15:46
Damn it! Can't decide which thread to post in! SO THIS ONE IT IS! Thanks for the info Refraction. Stupid me, I had the documentation, I just didnt look at it! I was hooked on the Winter document. BTW, Doomulation, awesome debugger I just saw on the PotatoChip thread! Crazy cool!
SO THEN! I "finished" my RIPxSCHIP8 emulator. Some stuff is still a little weird (like Spacefig and Dragon2) , but most works prretty good! I even made a webpage for it with screenshots blahblah
http://home.comcast.net/~reepal/images/RIPxSCHIP8/car2.jpg
http://home.comcast.net/~reepal/images/RIPxSCHIP8/alien.jpg
http://home.comcast.net/~reepal/images/RIPxSCHIP8/worm3.jpg
http://home.comcast.net/~reepal/images/RIPxSCHIP8/dragon1.jpg
http://home.comcast.net/~reepal/images/RIPxSCHIP8/uboat.jpg
You can download the all the latest stuff from here now.
http://www.reepal.com/RIPxSCHIP8.htm
refraction
July 6th, 2004, 12:43
well done :) ill check it over when i get home on thurday or friday, see if we can fix them remaining problems :)
sammyboy
July 6th, 2004, 18:42
Just out of interest can anyone tell me a chip 8 emulator developed using vb. People say that you can do it but noone here has tried it.
ripnla - I only thought that chip8 was black and white, or did you just change the colours on certain roms.
Talking of chip 8 roms, is there such thing as a chip 8 pd rom, normal chip 8 games are ususally the same as most pd games.
zenogais
July 6th, 2004, 20:38
Here's my scrolling code, it doesn't deal with allocating memory on the heap every call, so it is probably slightly more efficient than your method Doomulation. Although I'm still getting an error with ANT, where after the ground is scrolled completely to the left, the ant is created on the ground so the game shuts down.
EDIT: Fixed the ANT problem.
void ChipVideo::scrollHorizontal(bool bScrollRight)
{
//======================================== ===========
// Calculate The Scrolling Amount
//======================================== ===========
unsigned short sScrollAmount = m_fSChipModeOn ? 4 : 2;
//======================================== ===========
// Using Scrolling Amount, Scroll Screen Right
//======================================== ===========
if(bScrollRight == true)
{
for(unsigned int y = 0; y < m_usMaxY; y++)
{
for(unsigned int x = 0; x < m_usMaxX; x++)
{
if(m_pVideoMemory[(x + (y*m_usMaxX))] && x < sScrollAmount)
{
m_pVideoMemory[ ((x + (y*m_usMaxX)) + sScrollAmount) ] = 1;
} else {
m_pVideoMemory[(x + (y*m_usMaxX))] = 0;
}
}
}
}
//======================================== ===========
// Using Scrolling Amount, Scroll Screen Left
//======================================== ===========
if(bScrollRight == false)
{
for(unsigned int y = 0; y < m_usMaxY; y++)
{
for(unsigned int x = 0; x < m_usMaxX; x++)
{
if(m_pVideoMemory[(x + (y*m_usMaxX))] && x >= sScrollAmount)
{
m_pVideoMemory[ ((x + (y*m_usMaxX)) - sScrollAmount) ] = 1;
} else {
m_pVideoMemory[(x + (y*m_usMaxX))] = 0;
}
}
}
}
}
Also, finally completed the emulator, should work on almost every game (I haven't tried them all :P ) I've attached the binary, but the source code and everything else is here (http://www.zenogais.net/projects/NeoChip8)
aprentice
July 7th, 2004, 05:32
nice job, all you need to do is just include msvcp71.dll and everyone without the 2003 ide can run it :P
so you say you are using a dynarec? are you going to release a document explaining what you have done and how it works?
zenogais
July 7th, 2004, 08:35
Shouldn't need msvcp71.dll, but just in case I've completely recompiled it with no debug functionality whatsoever. I've attached a new version to the last post.
As for the dynarec. I didn't say I was using one, only that I was planning on adding the functionality and ability to use one. And yes I will be releasing a document explaining how the dynarec works.
RipNLa
July 7th, 2004, 09:07
ripnla - I only thought that chip8 was black and white, or did you just change the colours on certain roms.
I put in an option to change the color to whatever you want other than white, so black background and whatever color pixels you want. =p Black and white makes me feel old!
Zenogais: Waiting for that Dynarec doc man!
sammyboy
July 7th, 2004, 09:13
nice answer, what about my other questions (especially the first one)
zenogais
July 7th, 2004, 09:42
I put in an option to change the color to whatever you want other than white, so black background and whatever color pixels you want. =p Black and white makes me feel old!
Zenogais: Waiting for that Dynarec doc man!
I've already written one, though it was very basic and alot sloppier than my current implementation.
Dynarec Document (http://www.zenogais.net/projects/tutorials/DynarecDoc.txt)
My Projects & Tutorials (http://www.zenogais.net/projects/)
RipNLa
July 8th, 2004, 02:20
Hmm, that Dynarec document is a good introduction for people like me who have no idea how it works. A suggestion for your next document though. If you could explain the second half more, like purpose/function of the buffer and the emitter functions. I know you did vaguely go over it, but I think something like documentation in the code on the 2nd half would've been helpful. Seriously, I was reading along fine, then the 2nd half came and I just had to stop, and say "...What?"
I'm missing how this is so much faster than an interperter though (which is what I've read everywhere for years it seems). Don't you still have to parse the individual opcodes to find some block of code, function or switch-case, to execute it? And in that case, isn't this basically the same as writing all your switch-cases as assembly instructions? Or am I thinking too high level?
I see the asm call to execute the buffer (and I'm assuming the emitter functions as they are setup, would fill the buffer so it could be executed with a call statement from asm). But if the buffer has to be filled each opcode, that seems like more work than an interperter would have to do.
Yeah..I don't even know if I'm making sense anymore, someone explain por favor =D
zenogais
July 8th, 2004, 02:52
Hmm, that Dynarec document is a good introduction for people like me who have no idea how it works. A suggestion for your next document though. If you could explain the second half more, like purpose/function of the buffer and the emitter functions. I know you did vaguely go over it, but I think something like documentation in the code on the 2nd half would've been helpful. Seriously, I was reading along fine, then the 2nd half came and I just had to stop, and say "...What?"
I'm missing how this is so much faster than an interperter though (which is what I've read everywhere for years it seems). Don't you still have to parse the individual opcodes to find some block of code, function or switch-case, to execute it? And in that case, isn't this basically the same as writing all your switch-cases as assembly instructions? Or am I thinking too high level?
I see the asm call to execute the buffer (and I'm assuming the emitter functions as they are setup, would fill the buffer so it could be executed with a call statement from asm). But if the buffer has to be filled each opcode, that seems like more work than an interperter would have to do.
Yeah..I don't even know if I'm making sense anymore, someone explain por favor =D
The implementation in that tutorial wouldn't necessarily be faster. But we're talking about recompiling an entire program into blocks, a block being the number of instructions between successive jump/branches. These recompiled blocks are then "cached", meaning they only need to be recompiled once. Then next time they are arrived upon in the code, the block has already been recompiled and can be executed with no need to interpret the instructions ever again. As for the exact details of how this is done, I'll explain in my next document, but you can figure it out by looking at ChipAssembler.h/.cpp in the NeoChip8 source code.
Basically, it would be like having a precompiled, optimized version, of the Chip8 game in memory generated on the fly. You compile it once and thats it. And you can get as fancy with the optimizations as you like.
Doomulation
July 8th, 2004, 22:13
Here's my scrolling code, it doesn't deal with allocating memory on the heap every call, so it is probably slightly more efficient than your method Doomulation. Although I'm still getting an error with ANT, where after the ground is scrolled completely to the left, the ant is created on the ground so the game shuts down.
EDIT: Fixed the ANT problem.
void ChipVideo::scrollHorizontal(bool bScrollRight)
{
//======================================== ===========
// Calculate The Scrolling Amount
//======================================== ===========
unsigned short sScrollAmount = m_fSChipModeOn ? 4 : 2;
//======================================== ===========
// Using Scrolling Amount, Scroll Screen Right
//======================================== ===========
if(bScrollRight == true)
{
for(unsigned int y = 0; y < m_usMaxY; y++)
{
for(unsigned int x = 0; x < m_usMaxX; x++)
{
if(m_pVideoMemory[(x + (y*m_usMaxX))] && x < sScrollAmount)
{
m_pVideoMemory[ ((x + (y*m_usMaxX)) + sScrollAmount) ] = 1;
} else {
m_pVideoMemory[(x + (y*m_usMaxX))] = 0;
}
}
}
}
//======================================== ===========
// Using Scrolling Amount, Scroll Screen Left
//======================================== ===========
if(bScrollRight == false)
{
for(unsigned int y = 0; y < m_usMaxY; y++)
{
for(unsigned int x = 0; x < m_usMaxX; x++)
{
if(m_pVideoMemory[(x + (y*m_usMaxX))] && x >= sScrollAmount)
{
m_pVideoMemory[ ((x + (y*m_usMaxX)) - sScrollAmount) ] = 1;
} else {
m_pVideoMemory[(x + (y*m_usMaxX))] = 0;
}
}
}
}
}
Also, finally completed the emulator, should work on almost every game (I haven't tried them all :P ) I've attached the binary, but the source code and everything else is here (http://www.zenogais.net/projects/NeoChip8)
It's certainly true that my method was bad concidering the amount of heap allocation. However, I saw no big means to optimize it since the real amount of cpu power was spent elsewhere.
The time has come! Chuit has reached its competion! Almost every game is emulated perfecly. Thus, I'm releasing the latest binary AND the source. I'm now putting down this project. Finished and discontinued.
It has been fun writing this emulator, and I hope it will be fun with the gb emulator I'm working on with some others. I'm releasing the source as-is, without any license. Do whatever you want with it. Take code to your project, make changes to it and compile a new version... it's all up to you. But remember it's lame to steal someone's source and claiming it your own.
To all those who are trying to write their own chip8 emulator out there... I can only say, good luck! And may the source of my emulator help you if you get stuck on something!
Lastly, thanks goes to refraction for all his hard work on fixing the opcodes. Without him, Chuit would still have some way to go :)
All other chip8 emu writers out there... good luck on your emulators!
Remember: the source includes the source files and the libs; not the external libraries. Nor, will the source of those be provided. This should be all you need to compile and run the emulator.
Have phun! :)
EDIT: I just recently figured out how to use colors in labels :O So I added the feature I wanted to have--to be able to change the pixel color! I also found a bug. So I'm re-uploading the source and binary.
Of course, I will still fix bugs if found, as I won't delete my source.
zenogais
July 10th, 2004, 01:22
Ok, I spent a little bit of time revamping my projects website to make it less of an eyesore. I've also added the latest source code for NeoPSX, my Playstation emulator. I just started rewrites last night but I've already got a bit done. Check it out! (http://www.zenogais.net/projects/index.htm)
Doomulation
July 10th, 2004, 23:13
Cool.
I also updated the source and binary. Enjoy.
bcrew1375
July 17th, 2004, 08:17
Okay, first post here, so let me introduce myself. I'm bcrew1375, I'm a regular at Emuforums, I'm a pretty easy going person, and I've already read the rules :P. Also, hi to refraction, zenogais, and anyone else I know out there. I realize the thread is about a week old, sorry for not posting sooner.
Now, since all of you have been programming Chip8 interpreters, I was wondering if someone could help with a little problem I'm having. In the game "BLITZ", all the building bottoms are wrapping around and ending up on the top. I cannot for the life of me figure out why. I checked the results of all my opcodes, they all are giving the results I expect them to. I've also disassembled the code for the game. The building drawing routine seems to be doing this intentionally! I know the game is not supposed to run this way, so either I'm doing something wrong with one or more opcodes that I've overlooked, or my understanding of the system is flawed. I can post the source if need be. Anyone help with this would be greatly appreciated.
Oh, I have also tested the other Chip8 games and they all run flawlessly.
RipNLa
July 17th, 2004, 09:17
Sounds to me like your DXY0 opcode is flawed. I think Blitz draws all the way to the very bottom (possibly one below the bottom?). You'll have to debug through it to see. I remember when I first moved to SCHIP8 and was drawing an extended view of the screen that when you drop a bomb on a tower, it leaves one block at the bottom, which I didnt see in my Chip8 emu since it was probably out of range. All I can say is to make sure you're checking the screen boundaries, and not just throwing out of range values back through the top of the screen.
bcrew1375
July 17th, 2004, 10:35
Here is my draw sprite routine:
void DrawSprite()
{
int j;
int i;
unsigned char plotX, plotY;
unsigned char data;
// If no collision, default VF to 0.
V[0xF] = 0;
for(j = 0; j < opcode4; j++)
{
data = romBuffer[Index + j];
for (i = 0; i < 8; i++)
{
plotX = (V[opcode2] + i) & 63;
plotY = (V[opcode3] + j) & 31;
if ((data & (0x80 >> i)) != 0)
{
if (screenData[plotY * 64 + plotX] == 1)
V[0xF] = 1;
screenData[plotY * 64 + plotX] ^= 1;
}
}
}
}
The way I handle opcodes is a little strange compared to everyone else. I pretty much split the opcode into 4 nibbles.
opcode1 = (*(romBuffer + PC) & 0xF0) >> 4;
opcode2 = *(romBuffer + PC) & 0x0F;
opcode3 = (*(romBuffer + (PC + 1)) & 0xF0) >> 4;
opcode4 = *(romBuffer + (PC + 1)) & 0x0F;
I also attached the Blitz source I made. I'm not through documenting it, but it should be pretty easy to understand.
refraction
July 17th, 2004, 19:06
hmm it may be looking at your code wrong, you need to put in some brackets as it might be seeing the code like PlotY * (64 + PlotX)
try doing this on the lines for collisions and drawing the pixel
if (screenData[plotX + (plotY* 64)] == 1)
V[0xF] = 1;
screenData[plotX + (plotY* 64)] ^= 1;
also this bit i think might be causing problems...
plotX = (V[opcode2] + i) & 63;
plotY = (V[opcode3] + j) & 31;
The number needs to be modulated, it think it does the same thing but try it as
plotX = (V[opcode2] + i)%63;
plotY = (V[opcode3] + j)%31;
if that doesnt work try changing the 63 and 31 to 64 and 32.
bcrew1375
July 17th, 2004, 19:56
Tried all 3 of those suggestions. None of them worked. Like I said, maybe my understanding of the system is flawed. When I looked at the BLITZ source, it seems that my interpreter is executing it perfectly.
refraction
July 17th, 2004, 20:12
hmm its an odd one, i had the same problem, which i fixed by putting the module code in a different place..
try taking it off the plotX = and plotY = lines and putting it here
if (screenData[(plotY%32) * 64 + (plotX%64)] == 1)
V[0xF] = 1;
screenData[(plotY%32) * 64 + (plotX%64)] ^= 1;
bcrew1375
July 17th, 2004, 20:22
Tried that too, still seems to be no effect. At any rate, I'll post the source here.
Oh, and don't ask about the name :P.
refraction
July 17th, 2004, 20:34
ill load it up n see if i can work something out, just installing VS atm, so ill let you know if i figure it out.
refraction
July 17th, 2004, 21:21
Right ive had a look and the code seems to work without the module on the plot's, so it would be an idea to leave it off for them, the only place you should need that is on a 16x16 sprite on Field (schip8 game) so that would be seperate code anyway.
bcrew1375
July 18th, 2004, 01:00
If I don't modulate the coordinates, it screws up other games like UFO. I think that also makes it go out of its memory range.
refraction
July 18th, 2004, 01:07
well then you have some problems somewhere, im sure UFO ran on mine without modulating, back on my text graphics chip8 emu every game ran fine except field without modulating the co-ordinates.
but apart from that problem your drawsprite looks fine.
Edit: UFO works fine here without it, heres the code for your drawsprite as i have it.
void DrawSprite()
{
int j;
int i;
int plotX, plotY;
char data;
// If no collision, default VF to 0.
V[0xF] = 0;
plotX = V[opcode2];
plotY = V[opcode3];
for(j = 0; j < opcode4; j++)
{
data = romBuffer[Index + j];
for (i = 0; i < 8; i++)
{
if ((data & (0x80 >> i)) != 0)
{
if (screenData[(((plotY + j) * 64) + ((plotX + i))] == 1)
V[0xF] = 1;
screenData[(((plotY + j) * 64) + ((plotX + i))] ^= 1;
}
}
}
}
if that doesnt work, try modulating Y by 33 and X by 64. quite odd i know.. but for some reason i had that in the code O_o
bcrew1375
July 18th, 2004, 06:35
Um, are you sure UFO works okay? How long did you play it? I let it run for a bit and eventually the lower sprite collided with the upper one and I got 225 points :P. The modulating by 33 seems to work except the paddles in PONG don't wrap correctly, and it also feels sort of like a 'quickfix'. :/ It just doesn't feel right if you make hacks for specific games :(. Thanks for those suggestions though. If you think of any others, please tell me. I'll see what else I can get it to do.
refraction
July 18th, 2004, 14:34
well i havent got some games (like field) to work any other way, like on field the bird flies to the top of the screen then it crashes, only other way i can think of doing it is say if the sprite goes out of the array range, dont draw it.
Doomulation
July 19th, 2004, 16:26
Why modulate them in the first place? Every game besides field seems to work fine without it. In field, the bird goes outside screen; but then you simply don't draw it.
There's also at least two fully working chip8 emus which source are posted at the forum.
vma
October 6th, 2004, 10:42
Hi,
After reading this thread, I did my own VB6 Chip-8 Emu.
For that I used a C-Source from an ankown author, do understand how a Chip-8 virtual machine works.
In case anyone is interested in it, let me know.
The emu still has a few bugs, because of which a few games won't run properly.
When the emu is ready, I will make a small website and release it together with source code.
Cheers,
vma
N|zol
October 12th, 2004, 20:12
I've done Chip8 emulator, too. You can download it from my webpage:
http://n-zol.narod.ru. Now i'm going to write GameBoy emulator.
Doomulation
October 13th, 2004, 08:40
Meh. I was hoping more n00bs would come asking "what did I do wrong?!" :P
Oh well, nice to see some new chip8 emulators, though.
extro
October 14th, 2004, 22:50
Meh. I was hoping more n00bs would come asking "what did I do wrong?!" :P
Oh well, nice to see some new chip8 emulators, though.
Does somebody have an idea how to realize the sprite stuff in Java? thx.
glVertex3f
October 15th, 2004, 00:40
Meh. I was hoping more n00bs would come asking "what did I do wrong?!" :P
Oh well, nice to see some new chip8 emulators, though.
Lol they probably just went to my thread.. I asked mor questions than any noob ever would
:P
bcrew1375
October 15th, 2004, 05:12
Congratulations on your emulators guys :happy:. Now why don't you upgrade to Gameboy? I'd love to help people write them(As long as you don't ask obvious, stupid questions :P). There is already a Gameboy thread on the list if you guys need some help.
Doomulation
October 15th, 2004, 12:30
Does somebody have an idea how to realize the sprite stuff in Java? thx.
Get J++ and write it as you normally would?
zenogais
October 15th, 2004, 14:58
Get J++ and write it as you normally would?
Horrible idea, J++ is outdated and non-standard. Have you even tried googling it? Because there are plenty of resources there, like this (http://javaboutique.internet.com/tutorials/Java_Game_Programming/) one.
Doomulation
October 15th, 2004, 19:02
Well, java sucks anyway.
Btw, has anyone encountered any game that actually uses the chip8->schip8 and back technique? According to the manual, when going from chip8 to schip8, all chip8 pixels will be doubled.
And scrolling using schip8 opcodes will be counted in half. So scrolling 3 pixels, will make it 1½ in chip8! Does anyone (have found?) have such a game? I wish to test it.
aprentice
October 15th, 2004, 22:45
Dooomulation, what ever happened to the gameboy emu you and a team were working on it? Everyone in your team is pretending it never existed.
Just wondering hows the status, if its even alive..
Edit:
also, i havent worked on my chip8 emu for many months. But the last thing i did (about a few months ago) was a decompiler that decompiled chip8 roms to C code. I never did finish it, just decided to throw it out there for you guys as an idea :P
extro
October 17th, 2004, 10:28
Well, java sucks anyway.
Well, it would say it depends on what you are going to do. I don't want to discuss about the programming language itself. But if you are going to do an emulator which runs on linux as well, java should be fine even for emulating the chip8. Anyway I'm not sure how to deal with the sprite stuff, should be possible in java as well. I will do some more research on it, but if someone did already something similiar, help will be appreciated.
aprentice
October 18th, 2004, 01:13
Well, it would say it depends on what you are going to do. I don't want to discuss about the programming language itself. But if you are going to do an emulator which runs on linux as well, java should be fine even for emulating the chip8. Anyway I'm not sure how to deal with the sprite stuff, should be possible in java as well. I will do some more research on it, but if someone did already something similiar, help will be appreciated.
its just a matter of figuring out how to plot pixels to the screen in java
Doomulation
October 18th, 2004, 12:49
Dooomulation, what ever happened to the gameboy emu you and a team were working on it? Everyone in your team is pretending it never existed.
Just wondering hows the status, if its even alive..
Edit:
also, i havent worked on my chip8 emu for many months. But the last thing i did (about a few months ago) was a decompiler that decompiled chip8 roms to C code. I never did finish it, just decided to throw it out there for you guys as an idea :P
Ahh well, the rest of my crew just kinda died. Heh, I've been to lazy to work on it myself as well... I need ta get contact with them before anything can really be done about it :P
vma
October 20th, 2004, 10:57
Hi guys,
After two busy weeks, I am back and I have the following questions:
My Visual Basic Chip-8 emu does also support Super Chip-8. However, comparing it with other emu's, I notice that some games act slightly different on my emu and I don't know why:
- Dragon 1 game, which looks like a fighting game: on my emu you can only kick, but not move the caracter - no idea why, as other games have no major controller problem
- Dragon 2 game, which looks like scramble but with an helicopter: when you crash, the game just goes on, while on an other emu a windows messagebox pops up saying "Game Over". How does one know that the game is over??? Is that an instruction or why is it not supported by the game itself?
For others: the source code is in my modest opinion very readable, so if you plan to program a Chip-8 emu in whatever language - just take a look at the code! If it runs in VB6, it must run properly in any other modern language.
Cheers,
vma
Doomulation
October 20th, 2004, 14:23
Vma, I have NO idea! :P
The game itself knows that it's game over and prints data on the screen to show it. Something is wrong in your ops (probably) and I don't know where. Maybe if you posted them.
vma
October 21st, 2004, 00:56
Not with Dragon2! The Game does NOT show Game Over. This other Chip-8 Emu I have (can't remeber the name) will pop up a Windows Messagebox. I wonder how the autor knew that the game was over?
Cheers,
vma
aprentice
October 21st, 2004, 02:09
Not with Dragon2! The Game does NOT show Game Over. This other Chip-8 Emu I have (can't remeber the name) will pop up a Windows Messagebox. I wonder how the autor knew that the game was over?
Cheers,
vma
the other emus pop a message box when the quit opcode is called
vma
October 21st, 2004, 22:35
Ahhh!
Stupid of mine not to think about that one!!!!
:P
Update coming up, I guess!
Cheers,
vma
extro
October 24th, 2004, 20:03
hi, here is another question. Can somebody explain to me how to implement the binary translation stuff into the chip8 emu? Some example code would be really helpful, thx.
zenogais
October 24th, 2004, 20:29
hi, here is another question. Can somebody explain to me how to implement the binary translation stuff into the chip8 emu? Some example code would be really helpful, thx.
Binary translation, as in dynamic recompilation?
extro
October 24th, 2004, 23:21
hm, that would lead to another question what is exactly the difference? It seems that these two methods are mixed up sometimes.
zenogais
October 25th, 2004, 06:23
hm, that would lead to another question what is exactly the difference? It seems that these two methods are mixed up sometimes.
They are the exact same, there is no difference. There are, however, two different flavors of binary translation:
dynamic recompilation - CPU instructions are decoded and compiled to native code on the fly.
static recompilation - An entire program is compiled to the native architecture at load time.
extro
October 25th, 2004, 14:01
They are the exact same, there is no difference. There are, however, two different flavors of binary translation:
dynamic recompilation - CPU instructions are decoded and compiled to native code on the fly.
static recompilation - An entire program is compiled to the native architecture at load time.
can you provide a little step by step introduction (just pseudo code) how dynamic recompilation works? Does it create binary or just assembler code for the target workstation?
Im little confused now, because I read something about binary translation and at the they came up with something like that.
switch(mem_adr){
case 0xABCD: do_something();
case 0xABCE: do_something();
}
they are not switching opcodes, instead they switch memory adresses?
zenogais
October 26th, 2004, 02:41
Chances are it would be more helpful for you to check out my tutorial on Dynamic Recompilation (http://www.zenogais.net/projects/tutorials). Basically you're emitting pure binary, but working with the binary emitters at the assembly langauge level.
Doomulation
October 26th, 2004, 08:15
Your tutorial doesn't say how to translate chip8 ops into the compilation, though ;) Afaik.
Though other than that I think it was pretty good...
extro
October 26th, 2004, 11:08
Your tutorial doesn't say how to translate chip8 ops into the compilation, though ;) Afaik.
Though other than that I think it was pretty good...
yeah exactly, an example with the chip8 opcode and dynarec would be really great :)
Doomulation
October 26th, 2004, 14:35
Yes, that would be very nice!
zenogais
October 27th, 2004, 14:44
Yes, that would be very nice!
Ok, I'll work on translating a Chip8 opcode/series of opcodes and modify this post. Its really not that difficult if you understand assembly language :P I kept the tutorial non-chip8 specific because I wanted people emulating any system to be able to grab useful code from it.
extro
October 27th, 2004, 16:59
Ok, I'll work on translating a Chip8 opcode/series of opcodes and modify this post. Its really not that difficult if you understand assembly language :P I kept the tutorial non-chip8 specific because I wanted people emulating any system to be able to grab useful code from it.
woah, you are my man. That's good news indeed, hope it takes not to much effort. Otherwise let us know if you need any help :) thx
Doomulation
October 27th, 2004, 18:15
Ok, I'll work on translating a Chip8 opcode/series of opcodes and modify this post. Its really not that difficult if you understand assembly language :P I kept the tutorial non-chip8 specific because I wanted people emulating any system to be able to grab useful code from it.
Well ehhh actually, I'm too lazy to work it out plus I'm not all-knowledgeable about assembly. I know a little, but not so many instructions.
But this will be very nice, because I was thinking of rebuilding chuit with a dynarec.
aprentice
November 1st, 2004, 05:47
I was browsing through my programming folder and found this in my chip8 emu's directory. Since im not working on the chip8, i'll just post this here for any current or future chip8 programmers that are interested :P
This file dates back to july 6, so it was awhile ago, i dont quite remember everything in it :P
extro
November 3rd, 2004, 01:34
man that looks weird ;)
Could be helpful thx, I will take a look at it for sometime :)
Doomulation
November 8th, 2004, 13:32
Ok, I'll work on translating a Chip8 opcode/series of opcodes and modify this post. Its really not that difficult if you understand assembly language :P I kept the tutorial non-chip8 specific because I wanted people emulating any system to be able to grab useful code from it.
What happens to those dynamic recompilation opcodes? :cry: :down:
extro
November 8th, 2004, 16:26
I was browsing through my programming folder and found this in my chip8 emu's directory. Since im not working on the chip8, i'll just post this here for any current or future chip8 programmers that are interested :P
This file dates back to july 6, so it was awhile ago, i dont quite remember everything in it :P
hi this looks like a static version of recompilation, isn't it?
Still exited about the dynamic stuff ;)
zenogais
November 10th, 2004, 00:27
Apprentice: Sorry about that, I've been incredibly busy and meant to post something on these forums. But basically for a simple Chip8 register to register move you would merely do something like this:
// Opcode: 0x8**0
mX86Assembler.MovMtoR(EAX, &mReg[((Opcode&0x00F0)>>4)]);
mX86Assembler.MovRtoM(&mReg[((Opcode&0x0F00)>>8)], EAX);
Now of course this is in unoptimized form, but this is the basic concept. Where mX86Assembler is an instance of the class X86Assembler which emits opcodes to memory.
extro
November 12th, 2004, 00:19
Apprentice: Sorry about that, I've been incredibly busy and meant to post something on these forums. But basically for a simple Chip8 register to register move you would merely do something like this:
// Opcode: 0x8**0
mX86Assembler.MovMtoR(EAX, &mReg[((Opcode&0x00F0)>>4)]);
mX86Assembler.MovRtoM(&mReg[((Opcode&0x0F00)>>8)], EAX);
Now of course this is in unoptimized form, but this is the basic concept. Where mX86Assembler is an instance of the class X86Assembler which emits opcodes to memory.
looks interesting, how would that MoMtoR Method look like?
zenogais
November 12th, 2004, 00:22
looks interesting, how would that MoMtoR Method look like?
Thats an exercise best left up to the person making the dynarec, I give most of the necessary info in my tutorial. Its merely a matter of emitting the opcode and its parameters. Using the NASM or Intel documents you should be able to do that.
extro
November 15th, 2004, 18:14
Thats an exercise best left up to the person making the dynarec, I give most of the necessary info in my tutorial. Its merely a matter of emitting the opcode and its parameters. Using the NASM or Intel documents you should be able to do that.
I had a look a the dynarec stuff from pearpc (http://pearpc.sourceforge.net), which looks real nice. I think I got it now :)
extro
November 26th, 2004, 11:34
@zenogais did you have a look at this pearpc stuff? It would be interesting how good the implementation of their dynarec stuff is.
Marce1991
December 12th, 2004, 14:56
what is needed to make the 8 chip emu?e.g.
-cpu
-opcodes
And I'd need some help with directX, anyone knows a good tutorial except goldroad thx in advance
refraction
December 12th, 2004, 17:04
read the whole thread, everything you need is in this thread, i know theres a few pages, plus dont be lazy please, all is explained.
Marce1991
December 12th, 2004, 19:28
ok ok sorry :(
bcrew1375
December 14th, 2004, 07:44
Good luck, Marce. Chip 8 is really easy to start with, hopefully it goes smooth. If you need help, we're here(or at least I am, I can't say for the other guys :P).
Doomulation
December 14th, 2004, 08:07
We do check the board reguarly... yes...
If you have trouble, we'll gladly help.
Falcon4ever
December 14th, 2004, 15:36
what is needed to make the 8 chip emu?e.g.
-cpu
-opcodes
And I'd need some help with directX, anyone knows a good tutorial except goldroad thx in advance
I've seen several posts of you at this forum and actually i think you should do some win32 api programming first. Then if you want to learn dx try searching for "drunken hyena tutorial" which has one of the best dx/d3d tutorials.
the cpu/opcodes can easily be found here:
http://members.aol.com/autismuk/chip8/chip8def.htm
and that's all you need...
i did my chip8 in 5 days or smth...
http://www.falcon4ever.com/gallery/gallery1/20041204_chipv2.jpg
aprentice
December 14th, 2004, 17:26
graphic filters for chip8 could be a good idea :P
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.