|
|
Search
|
|||||||
| Home | Register | Downloads | FAQ | Members List | Calendar | Arcade | Mark Forums Read |
![]() |
|
|
LinkBack | Thread Tools | Display Modes |
|
|
#61 (permalink) |
|
Registered User
Join Date: Sep 2006
Location: surrey
Posts: 45
|
I've started a space invaders emulator as well now. I decided that rather than using a huge switch statement this time I would create an array of function pointers instead. Working perfectly so far. I'm still fuzzy about interrupts, cycles, and IO. cycles - would just putting in a variable that is set after after every execution and then decrements as the program loops (with no other executions) be sufficient? interrupts - so I can just have a counter that decrements once per cycle and when it reaches zero I immediately generate the interrupt (so execute a RST opcode based on the interrupt) correct? If thats right then I'm just wondering where I can find info on what interrupts I need, vblank and end of vblank are mentioned on emutalk. is that all? IO - anyone have any good sources of information for this, I'm just confused. oh and the ram mirror. That's just an area in memory that mirrors the ram right? So if I write to the ram I have to write to the mirror and vice versa? Do I even need it or can I just have any writes to the mirror go to ram instead? |
|
|
|
| Advertisement | [Remove Advertisement] | ||
|
|
|
|
#62 (permalink) |
|
Emu Author
![]() ![]() ![]() Join Date: Dec 2004
Location: North Carolina
Posts: 374
|
check out the thread at emutalk, i listed the exact amount of ram space invaders requires to function perfectly. as for cycles, it runs at 2 mhz, divide by 60 to get cycles per frame(2,048,000 / 60) at this point i can say you only need 2 interrupts to be called every frame. way i did it(there i am sure more ways but this is mine lol) i called first half of the cycles than called first interrupt than vblank, second set than last interrupt, worked very well for me. every opcode has an amount of cycles it takes to be called and you must keep track of this, by either adding or subtracting from a total. the interrupts in space invaders do have an opcode but usually are not called directly by the program but by the emulator. but other systems have what i consider hardware interrupts that have no opcode. the io in space invaders is controlled by io ports, info is listed on emutalk and if you need more feel free to ask, i can give you pages i found on them. btw, ram mirror is not needed but you will be allowing some access into there as without it, the game will crash during the demo like what happened to me. also i highly recommend that you completely read the info supplied on the emutalk thread, helps a lot. if you need more info let me know. i also been thinking about a unique way of doing a opcode decoding process which i am unsure as of now would benefit greatly or cause issues but if done right, would completely get rid of the switch entirely. |
|
|
|
|
|
#63 (permalink) |
|
Registered User
Join Date: Sep 2006
Location: surrey
Posts: 45
|
I already got rid of my switch void (*operation[256])(Processor *p) operation[opcode](this) if i wasn't using C++ then it would be easier. As it is now it works but I'm not sure if it's that good of an idea, eliminates the need to check every time but I don't know if there is any issue doing it that way. I think I'm doing the interrupts correctly then. I did read through the emutalk but I had questions and this place seems more active. |
|
|
|
|
|
#65 (permalink) |
|
Emu Author
![]() ![]() ![]() Join Date: Dec 2004
Location: North Carolina
Posts: 374
|
not sure who you are asking but for me i am thinking of replacing it just because i would like to test my theory, of course i wont be testing it on anything complex, i plan to test it when i get around to rewriting my chip 8 to see if it does any good.
|
|
|
|
|
|
#67 (permalink) |
|
Emu Author
![]() ![]() ![]() Join Date: Dec 2004
Location: North Carolina
Posts: 374
|
well a while back i came across an interesting method in c#, where i can call any function i want on the fly, as long as the function exists in the exe i can call it as in i was calling a function. say i have a text box on a form, and in my exe exists a function called Resize_Window with a parameter for the size in this format x_y. i can type Resize_Window 200x200 and it immediately calls and resizes the window without doing any real checks except just to make sure the function receives the correct parameters. also, if i wanted to extend functionality, all i need do is add the function to the program, no extra work would be needed to make sure it can be used.
|
|
|
|
|
|
#68 (permalink) |
|
Emu author
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Apr 2001
Location: Cleveland OH, USA
Posts: 1,184
|
I guess the question I have is in what ways would this be superior to a switch statement? Is it for organization purposes or is it for performance? I'm saying this because there has been a common belief amongst emulator coders that function tables are faster than switches, when in reality the opposite should be true. |
|
|
|
|
|
#69 (permalink) |
|
Emu Author
![]() ![]() ![]() Join Date: Dec 2004
Location: North Carolina
Posts: 374
|
well actually i was wondering that myself, as to how this method would perform. thats why i was looking to eventually test it but not on a current emulator i am working on. any insight into a similar method and as to how it performed would be welcomed.
|
|
|
|
|
|
#70 (permalink) |
|
Emu author
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Apr 2001
Location: Cleveland OH, USA
Posts: 1,184
|
I don't know what would be faster on C# because I don't know how switches or the indirect function calls you mention are implemented. I just know that theoretically a switch can be faster than an indirect function call because there's less return overhead, more stack frame/register consistency (frame and calling convention overhead) and better potential for optimization. If the function table performs better then the compiler is not doing a good enough job. I wrote a big post on this once but all I could find was one that was basically like this one :/ |
|
|
|
|
|
#71 (permalink) |
|
Emu Author
![]() ![]() ![]() Join Date: Dec 2004
Location: North Carolina
Posts: 374
|
well thanks for the reply, maybe i could recode chip 8 to use my current methods and than make a copy using the other and see which performs better, though seeing as how well a switch performs in space invaders and gameboy i am sure the switch may win but i wont know until i at least test it out.
|
|
|
|
|
|
#74 (permalink) | |
|
Emu author
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Nov 2002
Location: Austria (originally from Dominican Republic)
Posts: 2,381
|
Quote:
__________________
Current development tools: Visual C++.net, Visual C#.net Visual VB.net, Visual Webdeveloper.net Bloodshed Dev C++, Borland C++ Visual Basic 6 |
|
|
|
|
|
|
#75 (permalink) |
|
Human Metal
![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() Join Date: Oct 2002
Location: Holland / Hungary
Posts: 13,552
|
Since this is one of the overlooked sections, if you would still like a namechange, please write down your desired thread title in a reply to my post, and report your own post. This will make it easy for any mod to notice your request and it will be changed the very same day
__________________
PC Specs: CPU: Intel Q8200 @ 2.8GHz ![]() GPU: Sapphire ATi HD4870 / 1024MB / Core: 801 / Mem: 1000 Mobo: Gigabyte EP35-DS3 (rev 2.1) SPU: Creative X-Fi Xtreme Music RAM: 2GB Kingston HyperX DDR2 1066 @ 4-4-4-12 ~ 800MHz HDD: 1TB Samsung Spinpoint, 32MB PSU: Hiper Type-R 580W Monitor: Iiyama B2403WS / 1920*1200 Geometry Wars: 198.400 Lumines: 999.999 Join the NGEmu Folding @ Home community NOW! |
|
|
|
|
|
#76 (permalink) |
|
Registered User
Join Date: Sep 2006
Location: surrey
Posts: 45
|
eliminate the switch? you can create an array of function pointers. Code:
void (*operations[256])(Processor *p); Then just fill in the table with the appropriate functions. Unfortunately I have a bug somewhere and am having loads of trouble finding it. ![]()
|
|
|
|
|
|
#79 (permalink) |
|
Registered User
Join Date: Sep 2006
Location: surrey
Posts: 45
|
I decided to scrap almost all of my original code. The function table idea could have worked but I just didn't plan it out well enough so it became a huge pain to debug. Progress on my new version though ![]() No colours yet and I still have a few more opcodes to work on. and obviously the graphics there are wrong, need to fix that too. |
|
|
|
![]() |
| Thread Tools | |
| Display Modes | |
|
|