Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Envisioning in C++?
#1
For anyone who's good at coding in C++ or any other language:

I was just wondering how, in general, do you see what you are coding? I know you can see the physical code and then debug it to actually see it. But how do you just simply write a bunch of code and then fix the errors, and then have what you meant to code pop up?

Such as putting images into the GUI, do you have to figure a way to convert the image into code itself? Do you do it yourself? Write a program to do it and insert the code? Or when the project compiles, does the images automatically get included into the GUI without a need for an external GUI folder?


Now with things like emulators, is it all basically number and character variables that go to different values constantly? Or is there other codes that allow for different things to be produced?

I don't know if I'm wording this all correctly, but I'm just really curious as to what goes into somewhat advanced programs?
Currently Playing on PCSX2: Star Ocean: Till the End of Time
AMD Athlon 64 X2 3600+ @ 2.1 Ghz and Nvidia GeForce 6150 LE (Playable isn't full speed)
Reply

Sponsored links

#2
I tend to code by the seat of my pants then fix any compiler errors then go about program errors. I also have a tendency to pace as I think things through. It's generally not recommended to just sit down and plop it all on the table like that as you can end up with hours of extra work and ugly hacks when the answer was simple all along.

Only gui I have coded in is glut which is really really easy to handle interfaces. It's not that hard at all. I'm sure more advanced gui's take a little more than that.

When coding an emulator it become a state machine when this opcode appears do this. So it basically a lot of switch statements containing code for operation.
Reply
#3
My biggest question for any emulating dev...

How the hell do you even start?
http://www.twitch.tv/krazytrumpeter05
Want to stream your games? Let me know and I can help you get set up with Open Broadcaster Software.
Reply
#4
Documentation of all the opcodes you need to emulate and what they do.
Reply
#5
(09-17-2009, 03:12 AM)Tetsero Wrote: For anyone who's good at coding in C++ or any other language:

I was just wondering how, in general, do you see what you are coding? I know you can see the physical code and then debug it to actually see it. But how do you just simply write a bunch of code and then fix the errors, and then have what you meant to code pop up?

I write out how the code flows on paper well before I type anything. If it doesn't make sense when doing it by hand, it won't make sense once your fingers hit the keyboard.

As for visualizing, I don't really 'see' anything outside of whatever module/function I'm writing. All the interfaces and calling conventions are written out, to prevent feature creep or unsafe practices when passing anything out or into the program.

Quote:Such as putting images into the GUI, do you have to figure a way to convert the image into code itself? Do you do it yourself? Write a program to do it and insert the code? Or when the project compiles, does the images automatically get included into the GUI without a need for an external GUI folder?

As far as I know, most frameworks compile the graphical elements into the executable. So before compilation you have a collection of images that you created to be compatible with whatever native loading techniques the framework provides, and in the end you get a nice neat exe Smile

Quote:Now with things like emulators, is it all basically number and character variables that go to different values constantly? Or is there other codes that allow for different things to be produced?

In a very very general sense, yes it's all just numbers changing. But the same could be said for all programs Tongue

Emulators begin by setting aside enough system RAM to hold a complete copy of whatever amount of RAM is inside the console. A structure is created to hold the state of the CPU and all it's various components, along with structures to hold the state of every major component. All of these combined let you have what amounts to a snapshot of all the important parts in memory.

The most basic of emulators (an interpreter) literally 'emulates' the system one step at a time. A simplified main loop could be like so:
Code:
while (halt != TRUE)
{
    current_instruction = GetNextInstruction();
    switch(current_instruction)
    {
        case 0x10:
            //It's a jump
            performJump(current_instruction);
            break;
        case 0x11:
            //It's an addition instruction
            performAddition(current_instruction);

        // And so on

        default:
            //unknown opcode
            assert(0);    //kill the program
    }
}

Then it's a matter of figuring out what instruction code does what, and through much trial and error it can be puzzled out.
This is obviously an over-simplified approach, and isn't how the main emulator cores work. Interpreters are just too slow for most situations, and elegant solutions such as binary translation / dynamic recompilers are used.

Quote:I don't know if I'm wording this all correctly, but I'm just really curious as to what goes into somewhat advanced programs?

Blood, sweat and tears Laugh

Anything worth programming is hard, because if it was easy it would have been done before. Emulators are so deceptively simple that it can be disconcerting to new programmers, but with time and effort it's possible to understand enough theory to start writing your own.

Quote:My biggest question for any emulating dev...

How the hell do you even start?

All the devs I've met at my work are either a) CS masters with an emphasis on compilers, or b) entirely self taught.

Either way, it always begins with grabbing a book Tongue
"This thread should be closed immediately, it causes parallel imagination and multiprocess hallucination" --ardhi
Reply
#6
Ah, so there is a proper set of instruction you can have for this sort of programming, then? You mentioned an emphasis in compilers, what other things are compilers used for?
http://www.twitch.tv/krazytrumpeter05
Want to stream your games? Let me know and I can help you get set up with Open Broadcaster Software.
Reply
#7
Emulation of virtual cpu's also any computer language needs it's own compiler for each instruction set also known as an ISA like mips and x86 so on and so forth. Compilers are are all abouit mapping high level code to low level machine language instructions.
Reply
#8
(09-17-2009, 03:12 AM)Tetsero Wrote: I was just wondering how, in general, do you see what you are coding? I know you can see the physical code and then debug it to actually see it. But how do you just simply write a bunch of code and then fix the errors, and then have what you meant to code pop up?

Typically when i code something i basically do:
1) Figure out what the program needs to do.
2) Plan a way to accomplish that in my head.
3) Think about any cases where the algorithm I'm thinking of won't work for and rethink the alogirthm accordingly.
4) Code it!

When its a really tough problem though, I have to take out a sheet of paper and draw a few examples of whats happening. Then eventually I think of a nice way to code it.

One of the worst things about coding an algorithm IMO is when you can't find a nice/cool way to code it. And then your code ends up looking ugly.

Something else I hate is when you think of optimizations for your algorithm, but they're very 'ugly' and complex codewise.
So if you do end up coding it, other people (or yourself) might just think the code is crap (but its really smart speed-wise).

Many times I leave out certain optimizations in order to make the code look better. Of course, this is only done when the speedup of the 'optimization' is very minimal.

(09-17-2009, 04:18 AM)echosierra Wrote: All the devs I've met at my work are either a) CS masters with an emphasis on compilers, or b) entirely self taught.

Either way, it always begins with grabbing a book Tongue

lies xD
most programming books are boring or the code is poorly explained.

i self-taught myself most of what i know through source code and online tutorials.
(although i also have 3 years uni experience for my CS major, but uni is a small factor in my learning (probably around 10%))

i have a lot to learn though, but i still think online articles + messing with sourcecode on your own is a better way to learn than books (for me personally at least).
Check out my blog: Trashcan of Code
Reply
#9
(09-17-2009, 09:54 AM)cottonvibes Wrote: i have a lot to learn though, but i still think online articles + messing with sourcecode on your own is a better way to learn than books (for me personally at least).

My opinion, too.
Depends on where you start though. PCSX2 was already working when most of the current devs started working on it Tongue2
Reply
#10
Quote:Ah, so there is a proper set of instruction you can have for this sort of programming, then? You mentioned an emphasis in compilers, what other things are compilers used for?

Compiler theory covers the ideas used in the field of emulation, at least in theory. A compiler takes as it's input something the computer doesn't understand and (usually) kicks out something it could, which would describe an emulator.

An emulator takes the current block of code and checks if it's already in the code cache.
If it is: run it
If it isn't: "compile" it (for a very loose definition of compile) and store it in cache, run it.

Rinse and repeat, you have yourself the beginning of a dynamic recompiler.

Nitpick: It is my firm belief that this type of emulation should be called 'binary translation' over 'dynamic recompiler', in academia the notion of a 'recompiler' has a specific meaning. But 'BT' doesn't sound nearly as cool as 'dynarec' so maybe it's for the best.

(09-17-2009, 09:54 AM)cottonvibes Wrote:
(09-17-2009, 04:18 AM)echosierra Wrote: All the devs I've met at my work are either a) CS masters with an emphasis on compilers, or b) entirely self taught.

Either way, it always begins with grabbing a book Tongue

lies xD
most programming books are boring or the code is poorly explained.

Maybe. It's been a very long time since I've opened any introductory-level book, maybe nostalgia is coloring my memory.
Online resources are an awesome resource for beginners. Can't believe I forgot that Tongue
"This thread should be closed immediately, it causes parallel imagination and multiprocess hallucination" --ardhi
Reply




Users browsing this thread: 1 Guest(s)