Emuforums.com

Go Back   Emuforums.com > General Discussion > Web development / Programming
Home Register Downloads FAQ Members List Calendar Arcade Mark Forums Read

WON'T YOU JOIN US?
You are not a registered member and
are viewing this site as a guest.
Registration is simple and FREE.
Join this CrowdGather community today.
Registration offers the following perks:

» Less advertising throughout
» Post and participate in discussions
» Network with other forum members
» Free private messaging

join

Reply
 
Thread Tools Display Modes
Old October 18th, 2010, 00:38   #361
Hatorijr
Emu Author
 
Hatorijr's Avatar
 
Join Date: Dec 2004
Location: North Carolina
Posts: 599
i am still working on my chip8 emu that i recoded. rebuilding the input system, which is nearly done. than color change system is next. i had to write code to translate scan codes from the windows forms scancodes into directinput scancodes since there is no easy and direct way to do it -_-.

also, if anyone has any info on the chip8 or superchip games that are considered hybrid games or use system calls, please post.
Hatorijr is offline   Reply With Quote

Advertisement [Remove Advertisement]
Old October 18th, 2010, 01:52   #362
Bill_gates
Linux's worst nightmare..
 
Bill_gates's Avatar
 
Join Date: Feb 2004
Location: USA
Posts: 1,505
the chip16 spec doesnt seem to be finalized though...
__________________
OS: WinXP Professional Service Pack 3
CPU: Intel pentium 4 3.0GHz
Video: Nvidia Geforce 8400GS
Sound: ASUS Xonar DS 7.1 Channels 24-bit 192KHz PCI Interface Audio Card
Memory: 512 MB
HD: [C:] 140.36/449.09 GB
Connection: Marvell Yukon 88E8053 PCI-E Gigabit Ethernet Controller
Bill_gates is offline   Reply With Quote
Old October 18th, 2010, 04:27   #363
Hatorijr
Emu Author
 
Hatorijr's Avatar
 
Join Date: Dec 2004
Location: North Carolina
Posts: 599
so? does not hurt to start implementing it into a fully functional emulator as its being worked on.
Hatorijr is offline   Reply With Quote
Old October 18th, 2010, 04:38   #364
omegadox
Code it the hard way :P
 
omegadox's Avatar
 
Join Date: Jul 2008
Posts: 1,267
Quote:
Originally Posted by Bill_gates View Post
the chip16 spec doesnt seem to be finalized though...
I might start working on a small implementations of it, like the basic parts, like memory class, and the registers, etc.
__________________
Current Projects
Eimu - Chip8X Emulator
Super64 - N64 Emulator

Emulators are for learning, fun and success and not for demanding gamers and freeloaders.

:: I love my Monarch girl ::
omegadox is offline   Reply With Quote
Old October 24th, 2010, 02:28   #365
Bill_gates
Linux's worst nightmare..
 
Bill_gates's Avatar
 
Join Date: Feb 2004
Location: USA
Posts: 1,505
with my chip8 emulator i'm having issues with collision... I was just gonna let it go but its bugging me :/
pong and pong 2 works fine but with other games i have issues with collision
here is my drawing code

Code:
    /*Draw an 8 bit line of pixels. ch represents the line to be drawn*/
    public void drawpline(char ch,int x,int y,char flag,char vid[][]){
    int mask = 1<<7;
    int i=0;
    for(i=0; i<8; i++){
        //System.out.println("x with offset is" + (x+i));
      if(x+i<64 && y<32){
        /*there are 2 cases either vid at the current location is 'X' or 'O'*/
        if(vid[y][x+i]=='X'){
            /*if the bit is 1 at the line to draw */
            if((mask&ch) !=0){
                /*collision has occured*/
                flag= 1;
                vid[y][x+i]='O';
            }
            /*current pixel is X and current bit in ch is 0*/
            /*exclusive or with 0 has no effect*/
            else{

            }
        }
        /*if current pixel is 0 set bit according to vid*/
        else{
            if((mask&ch) != 0){
                vid[y][x+i]= 'X';
            }
            else{
                vid[y][x+i]= 'O';
            }
        }
        mask>>=1;
    }
  }
}

/*Draw pixel on the screen at location*/
public void drawpixel(char ch,int x,int y,int limit,char flag,char vid[][]){
    /*collision flag starts at 0*/
    flag=0;
    int i=0;
    for(i=0; i<limit; i++){
        drawpline(mem[address+i],x,y+i,flag,vid);
    }
}
__________________
OS: WinXP Professional Service Pack 3
CPU: Intel pentium 4 3.0GHz
Video: Nvidia Geforce 8400GS
Sound: ASUS Xonar DS 7.1 Channels 24-bit 192KHz PCI Interface Audio Card
Memory: 512 MB
HD: [C:] 140.36/449.09 GB
Connection: Marvell Yukon 88E8053 PCI-E Gigabit Ethernet Controller

Last edited by Bill_gates; October 25th, 2010 at 01:30..
Bill_gates is offline   Reply With Quote
Old October 24th, 2010, 05:04   #366
Hatorijr
Emu Author
 
Hatorijr's Avatar
 
Join Date: Dec 2004
Location: North Carolina
Posts: 599
it already seems like you got math errors in your code somewhere if you can not use the normal array sizes for the vid ram, as it should only be 32x64 so i would suggest fixing whatever is causing that problem. umm why are you adding x and i? that is most likely your vidram size problem. you read in a byte than you access the individual bits to determine the colors of the 8 pixels in the byte.
Hatorijr is offline   Reply With Quote
Old October 24th, 2010, 12:20   #367
Dax
ライチュウ|タオ
 
Dax's Avatar
 
Join Date: Nov 2006
Location: USA
Posts: 3,956
I'm trying to come up with a way to eliminate having a switch case for CHIP8 by using a function array. Does anyone have a recommended way of doing this? Or am I still sort of stuck using a bunch of ifs/switches to determine which opcode to call(since chip8 opcodes aren't all nice and neat like real CPUs)?

My goal is to be able to do something like(pseudo code):
Code:
void Execute()
{
     GetNextOpcode();
     opcodes[opcode]();
}
instead of a huge switch case of 35-45 cases.

Last edited by Dax; October 24th, 2010 at 12:31..
Dax is offline   Reply With Quote
Old October 24th, 2010, 19:19   #368
Bill_gates
Linux's worst nightmare..
 
Bill_gates's Avatar
 
Join Date: Feb 2004
Location: USA
Posts: 1,505
Quote:
Originally Posted by Hatorijr View Post
it already seems like you got math errors in your code somewhere if you can not use the normal array sizes for the vid ram, as it should only be 32x64 so i would suggest fixing whatever is causing that problem. umm why are you adding x and i? that is most likely your vidram size problem. you read in a byte than you access the individual bits to determine the colors of the 8 pixels in the byte.
No it's much simpler than that. LOL just another example of silly mistakes having huge consequences. My reg[0xF] variable wasnt being passed into my method correctly
(btw the i is there to loop through all 8 bits in the char)

Quote:
Originally Posted by Dax View Post
I'm trying to come up with a way to eliminate having a switch case for CHIP8 by using a function array. Does anyone have a recommended way of doing this? Or am I still sort of stuck using a bunch of ifs/switches to determine which opcode to call(since chip8 opcodes aren't all nice and neat like real CPUs)?

My goal is to be able to do something like(pseudo code):
Code:
void Execute()
{
     GetNextOpcode();
     opcodes[opcode]();
}
instead of a huge switch case of 35-45 cases.
sounds like what you need is a jump table.
For example: Lets say you had 4 functions, funa funb func and fund
(lets also say these functions dont take arguements and dont return anything)
all youd need to do is:

Code:
/*create an array of function pointers that take no args and dont return*/
void (*fun_ptr_arr[])(void) = {funa, funb, func,fund};

/*then to call func simply use:*/
fun_ptr_arr[2]();
__________________
OS: WinXP Professional Service Pack 3
CPU: Intel pentium 4 3.0GHz
Video: Nvidia Geforce 8400GS
Sound: ASUS Xonar DS 7.1 Channels 24-bit 192KHz PCI Interface Audio Card
Memory: 512 MB
HD: [C:] 140.36/449.09 GB
Connection: Marvell Yukon 88E8053 PCI-E Gigabit Ethernet Controller

Last edited by Bill_gates; October 25th, 2010 at 01:50..
Bill_gates is offline   Reply With Quote
Old October 25th, 2010, 07:00   #369
Dax
ライチュウ|タオ
 
Dax's Avatar
 
Join Date: Nov 2006
Location: USA
Posts: 3,956
Err..I know how to make a function array. I was just curious if anyone had come up with a way to utilize it for CHIP8 without having need for extra processing elsewhere due to how funky CHIP8's opcodes are. The best I came up with was a switch case elsewhere that returns an integer in the array of functions to call. But that still has a switch case, which I wanted to avoid. :/
Dax is offline   Reply With Quote
Old October 25th, 2010, 08:26   #370
cottonvibes
You're already dead...
 
cottonvibes's Avatar
 
Join Date: Sep 2007
Location: Planet Vegeta
Posts: 5,387
why do you want to avoid switch tables?

it is possible to use function tables for the chip-8 opcodes; but to avoid having a 65536 element table you have to use nested-function tables.
switch tables are faster though.
__________________

"It was, of course, a lie what you read about my religious convictions, a lie which is being systematically repeated. I do not believe in a personal God and I have never denied this but have expressed it clearly. If something is in me which can be called religious then it is the unbounded admiration for the structure of the world so far as our science can reveal it." - Albert Einstein
check out my blog
cottonvibes is offline   Reply With Quote
Old October 25th, 2010, 20:47   #371
overclocked
Registered User
 
Join Date: Sep 2010
Location: Sweden
Posts: 9
Quote:
Originally Posted by runawayprisoner View Post
ADD V0, 4:
VF = (0xff - v0 < 4) ? 1 : 0;
V0 = (V0 + 4) & 0xff;

SNE VF, 1:
if (VF != 1) PC += 2;

ADD V1, 1:
VF = (0xff - V1 < 1) ? 1 : 0;
V1 = (V1 + 1) & 0xff;

That's basically it for my emulator.
OK, after been doing other stuff for a while, I'm back in game. A question for all who have read the Chip8-specification:

if comparing:
ADD V0, 4
and:
ADD V0, V1

will both be using VF as an overflow flag (setting VF=1 when the sum is >0xff) or just one of them?
According to: CHIP-8 - Wikipedia, the free encyclopedia only the second ADD V0, V1 does that.
overclocked is offline   Reply With Quote
Old October 25th, 2010, 21:29   #372
Hatorijr
Emu Author
 
Hatorijr's Avatar
 
Join Date: Dec 2004
Location: North Carolina
Posts: 599
i believe technically both should, i should check if mine does or not. to get the full documentation i suggest you use multiple sources.
Hatorijr is offline   Reply With Quote
Old October 26th, 2010, 02:04   #373
omegadox
Code it the hard way :P
 
omegadox's Avatar
 
Join Date: Jul 2008
Posts: 1,267
Quote:
Originally Posted by cottonvibes View Post
why do you want to avoid switch tables?

it is possible to use function tables for the chip-8 opcodes; but to avoid having a 65536 element table you have to use nested-function tables.
switch tables are faster though.
Quote:
Originally Posted by Dax View Post
Err..I know how to make a function array. I was just curious if anyone had come up with a way to utilize it for CHIP8 without having need for extra processing elsewhere due to how funky CHIP8's opcodes are. The best I came up with was a switch case elsewhere that returns an integer in the array of functions to call. But that still has a switch case, which I wanted to avoid. :/
Hashtables are faster to lookup than switches. My program automatically makes a hashtable of functions to call for each opcode.
__________________
Current Projects
Eimu - Chip8X Emulator
Super64 - N64 Emulator

Emulators are for learning, fun and success and not for demanding gamers and freeloaders.

:: I love my Monarch girl ::
omegadox is offline   Reply With Quote
Old October 26th, 2010, 02:51   #374
cottonvibes
You're already dead...
 
cottonvibes's Avatar
 
Join Date: Sep 2007
Location: Planet Vegeta
Posts: 5,387
Quote:
Originally Posted by omegadox View Post
Hashtables are faster to lookup than switches. My program automatically makes a hashtable of functions to call for each opcode.
how are you using the hashtable?

in cases where a switch statement is optimized good by the compiler it should be faster than a hash-table.
a hash-table still has the problems of an array function table; its advantage is however you can save space if you don't use all the entries (2^(sizeof(instruction)*8)).
saving space is good because it helps the cpu cache.

in cases where you can use a small function table (<=256) to handle the opcodes, it should be faster than a hash table.
the reasoning is that hash tables rely on a hashing function, and have to handle collisions. an array doesn't have to worry about that and is guaranteed constant time complexity.
but we have shown in another thread that a switch table is faster than a function table in the above case. so in that case it makes sense that: switch table > function table > hash table.

in the case however where you have to nest function tables, like in the chip8, the function tables have more overhead, so this isn't the way to go. (or you can make a 2^16 element function table which probably wouldn't be good cache-wise).

hash-tables essentially are arrays internally, the difference is the array isn't accessed directly by the index, but instead by the hash value computed by a hashing function.
so if a hash table ends up being faster than a function array, the reason is its smaller size.

in the case of chip8 with an odd instruction structure, you need to have nested if/switch cases if you decide to do it with a switch table.
if you decide to do use a hashing table with all possible instruction combinations as the keys, then it is possible its faster than using the switch case if the compiler has trouble optimizing the switch table.

its something that needs to be bench-marked though (and depends on compiler optimizations so programming language and compiler matter), i wouldn't say it objectively is faster.
__________________

"It was, of course, a lie what you read about my religious convictions, a lie which is being systematically repeated. I do not believe in a personal God and I have never denied this but have expressed it clearly. If something is in me which can be called religious then it is the unbounded admiration for the structure of the world so far as our science can reveal it." - Albert Einstein
check out my blog
cottonvibes is offline   Reply With Quote
Old October 26th, 2010, 03:44   #375
Hatorijr
Emu Author
 
Hatorijr's Avatar
 
Join Date: Dec 2004
Location: North Carolina
Posts: 599
i wont have it up tonight due to my laptop being turned off but 1.0 of chip-8 advanced revolution is in a releasable state. it is missing some major features that i want included but i am releasing it now so people can take a look at it and find bugs and to simply break it in any odd way they can lol.

the good news is one of my major features is in a partially working state. i have a function in a newer version that has managed to scan and pull out a list of controls for certain games but due to certain games not being aligned correctly, it is making the task a big more complex than i wanted so it may be a little while before the function is complete, but once complete, i will be working on a game database to auto assign default keys for certain games and allow reassignment for games so users can have an easier time playing the various games for the various chip-8 systems i intend to support.

anyone who would like a detailed explanation as to the way my scanner works, feel free to ask.

o and for anyone who has made any graphical enhancements to any emu or to chip-8 specifically, if you could explain to me how to do enhancements like that, i would greatly appreciate it. also, would appreciate any info on how to do a flicker free mode too.
Hatorijr is offline   Reply With Quote
Old October 26th, 2010, 06:16   #376
Bill_gates
Linux's worst nightmare..
 
Bill_gates's Avatar
 
Join Date: Feb 2004
Location: USA
Posts: 1,505
I've finally cleaned my code up enough to warrant a release.
I'll put it up on google code along with screen shots and such tomorrow. I scrapped the ridiculousness I posted earlier and made a much more efficient and easier to follow drawing routine. I figured out how to use pictures and random colors for the pixels but those are hardly
graphical enhancements :P i'll put up some screens of that tomorrow as well :P
__________________
OS: WinXP Professional Service Pack 3
CPU: Intel pentium 4 3.0GHz
Video: Nvidia Geforce 8400GS
Sound: ASUS Xonar DS 7.1 Channels 24-bit 192KHz PCI Interface Audio Card
Memory: 512 MB
HD: [C:] 140.36/449.09 GB
Connection: Marvell Yukon 88E8053 PCI-E Gigabit Ethernet Controller
Bill_gates is offline   Reply With Quote
Old October 26th, 2010, 06:31   #377
cottonvibes
You're already dead...
 
cottonvibes's Avatar
 
Join Date: Sep 2007
Location: Planet Vegeta
Posts: 5,387
Quote:
Originally Posted by Hatorijr View Post
o and for anyone who has made any graphical enhancements to any emu or to chip-8 specifically, if you could explain to me how to do enhancements like that, i would greatly appreciate it. also, would appreciate any info on how to do a flicker free mode too.
graphical enhancements? like scaling filters?
well essentially there's different algorithms for pixel scaling:
Pixel art scaling algorithms - Wikipedia, the free encyclopedia

i've implemented scale2x, scale3x, eagle2x and eagle3x before.
all of the ones i mentioned have the algorithm listed in the wikipedia page, except eagle3x which i guessed how it worked.

i don't know how 2xSAI works since i havn't been able to find an explanation of the algorithm anywhere.
there's some code available for it, but its messy and hard to read.

hqnx is the most complex as far as pixel scaling algorithms go.
essentially its a 5000+ line switch statement which interpolates values according to what the author thought looked good.
i also haven't implemented that one since there doesn't seem to be any description of the reasoning behind it, and the code is of course a mess.

but anyways, the way they all work is they double, triple, or quadruple the resolution of the output buffer, and the actual pixels that get written to this bigger-buffer are based on the individual pixels in the input-buffer, and the pixels surrounding them.
if you know the actual algorithm for the pixel scalers, then implementing them is pretty simple; but if you don't know the algorithm then you have to read other people's code, which is usually implemented very messy.

as for flicker free mode, you can implement it different ways.
R.A.P's version probably uses some more complex logic; but all mine does is not draw the screen when there's a sprite-hit.
so all you have to do is keep a flag for when you have a sprite hit, and then don't draw if its true.
it will have problems in some games, but i didn't want to waste time coding a better solution when i could spend that time working on something else.

edit:
oh and pixel scaling algorithms aren't going to work good for a chip8 emulator since theres just 2 colors.
it works good for 8-bit/16-bit consoles though because their sprites are composed of different colored pixels.
__________________

"It was, of course, a lie what you read about my religious convictions, a lie which is being systematically repeated. I do not believe in a personal God and I have never denied this but have expressed it clearly. If something is in me which can be called religious then it is the unbounded admiration for the structure of the world so far as our science can reveal it." - Albert Einstein
check out my blog
cottonvibes is offline   Reply With Quote
Old October 26th, 2010, 16:59   #378
omegadox
Code it the hard way :P
 
omegadox's Avatar
 
Join Date: Jul 2008
Posts: 1,267
Quote:
Originally Posted by Hatorijr View Post
i wont have it up tonight due to my laptop being turned off but 1.0 of chip-8 advanced revolution is in a releasable state. it is missing some major features that i want included but i am releasing it now so people can take a look at it and find bugs and to simply break it in any odd way they can lol.

the good news is one of my major features is in a partially working state. i have a function in a newer version that has managed to scan and pull out a list of controls for certain games but due to certain games not being aligned correctly, it is making the task a big more complex than i wanted so it may be a little while before the function is complete, but once complete, i will be working on a game database to auto assign default keys for certain games and allow reassignment for games so users can have an easier time playing the various games for the various chip-8 systems i intend to support.

anyone who would like a detailed explanation as to the way my scanner works, feel free to ask.

o and for anyone who has made any graphical enhancements to any emu or to chip-8 specifically, if you could explain to me how to do enhancements like that, i would greatly appreciate it. also, would appreciate any info on how to do a flicker free mode too.
Use Pixel shaders for effects? For flicker free I suggest timing the frequent use of draw commands, when the code appears to be done drawing
draw whole frame, only way I can see how you might do it.


@cotton: Hashtables are good for huge lookups, since its faster to compute the hash and lookup than doing a lot of compares of 1000 items. switch-case is fine in chip8 but I hate nested code mess. My C# code uses reflection to find all the opcode handling methods based on their attribute and then adds it to the dictionary before the program runs.
__________________
Current Projects
Eimu - Chip8X Emulator
Super64 - N64 Emulator

Emulators are for learning, fun and success and not for demanding gamers and freeloaders.

:: I love my Monarch girl ::
omegadox is offline   Reply With Quote
Old October 27th, 2010, 00:28   #379
Bill_gates
Linux's worst nightmare..
 
Bill_gates's Avatar
 
Join Date: Feb 2004
Location: USA
Posts: 1,505
Some screens and a release
Attached Images
File Type: jpg Screen1.jpg (45.4 KB, 18 views)
File Type: jpg Screen2.jpg (17.9 KB, 10 views)
File Type: jpg Screen3.jpg (18.9 KB, 17 views)
File Type: jpg Screen4.jpg (22.7 KB, 17 views)
Attached Files
File Type: rar JJM Chip8.rar (18.2 KB, 7 views)
__________________
OS: WinXP Professional Service Pack 3
CPU: Intel pentium 4 3.0GHz
Video: Nvidia Geforce 8400GS
Sound: ASUS Xonar DS 7.1 Channels 24-bit 192KHz PCI Interface Audio Card
Memory: 512 MB
HD: [C:] 140.36/449.09 GB
Connection: Marvell Yukon 88E8053 PCI-E Gigabit Ethernet Controller
Bill_gates is offline   Reply With Quote
Old October 28th, 2010, 03:44   #380
Hatorijr
Emu Author
 
Hatorijr's Avatar
 
Join Date: Dec 2004
Location: North Carolina
Posts: 599
here is my rewrite of my chip-8 emulator. let me know how it runs and of any bugs you spot. mind you i am still working on some of the major features.
Attached Files
File Type: zip Chip-8 Advanced Revolution.zip (23.8 KB, 14 views)
Hatorijr is offline   Reply With Quote
Reply

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump

All times are GMT +1. The time now is 06:34.

© 2006 - 2012 Emu Forums | About Emu Forums | Advertisers | Investors | Legal | A member of the Crowdgather Forum Community


Powered by vBulletin® Version 3.8.7
Copyright ©2000 - 2013, vBulletin Solutions, Inc.