Zophar's Message Domain

Go Back   Zophar's Message Domain > Emulation Talk > General Emulation

Reply
 
Thread Tools Display Modes
Old 08-13-2009, 05:44 AM   #1
Aphex19
Junior Member
 
Join Date: Jul 2009
Posts: 10
Default Question about reading ROM's.

Exuse me if i sound stupid with this question.

How does an emulator read the data from ROM's? What i mean is that, how do you read the data from a rom file into its raw information, so the emulator can then work with (interpret) the values contained in the file?

When i look at a gb rom in a text editor, all i see is garbage. Im not sure if i made clear the question but im basically asking if specific initial decoding needs to take place to read the data from a rom.

thanks
Aphex19 is offline   Reply With Quote
Old 08-13-2009, 12:00 PM   #2
InVerse
Senior Member
 
Join Date: Jul 2002
Location: Midwest, U.S.
Posts: 1,489
Default

A ROM is compiled, just like any other program. If you were to look at, say, Solitaire in a text editor, you would see the same thing.

A computer, of course, can interpret that compiled information because, well, that's what computers do. If you're really interested in the down and dirty technical details, you might read the Wikipedia article on compiling.

When a game is created, it's written in a language that you or I could read. (Now, if it's written in assembly, you might not understand anything it says, but you could read the words out loud, at least, much like you could with, say French or Swedish or some language you don't know.) And a computer can certainly run a program in that form, but it would be extremely slow, as it would have to interpret each line individually.

Whereas when a program is compiled, it's converted to machine code which doesn't make any sense to a human that hasn't studied it extensively, but makes perfect sense to a computer.

(On a slightly related note, if you're interested in seeing the Super Mario Bros. disassembly, it can be found over here. What this is is the Super Mario Bros ROM disassembled into 6502 assembly code. And just to stave off the question, while you can disassemble a ROM, you can not decompile it back into C or whatever language it was written in. Also, you can not simply disassemble any ROM, you have to figure out what portions of the ROM and code and which portions are data, because the disassembler has no way of knowing.)

Anyway, as for an emulator... Consoles don't use the same processor as PCs. For instance, the Gameboy uses a custom 4.19Mhz 8-bit Sharp LR35902. Gameboy games were written for that processor and the Gameboy BIOS, which is why they won't run on a regular PC. What an emulator does is emulate that processor so that it can interpret the ROMs. So, basically, a Gameboy emulator runs Tetris just like a Windows PC runs Solitaire.

Anyway, that's a pretty rough explanation because hardware is far from my specialty, but it should give you a basic idea of how it works.
InVerse is offline   Reply With Quote
Old 08-13-2009, 08:07 PM   #3
Aphex19
Junior Member
 
Join Date: Jul 2009
Posts: 10
Default

This has cleared up alot of questions i have regarding this subject, thank you for taking you time to exain that to me.

But machine code must be translated into understandable assembly instructions for a processor so would you have to write that decompiler yourself for an emulated CPU?

Im just still confused about how a cpu would actually interpret all that unreadable machine code into assembly instructions to execute. It seems that the people who disasembled that mario rom had quite a hard time doing so, but does a (emulated) CPU not do that everytime it loads up a ROM?

Basically, how does a CPU go from machine code, to assembly instructions?

thank you
Aphex19 is offline   Reply With Quote
Old 08-14-2009, 12:26 AM   #4
InVerse
Senior Member
 
Join Date: Jul 2002
Location: Midwest, U.S.
Posts: 1,489
Default

Erm... the CPU can read the machine language, that's why it's called machine language. It doesn't have to interpret it as assembly.

The only time a ROM needs to be disassembled is if a human wants to be able to understand the code. And, actually, a human *can* read machine code, it's just... really really hard. Basically, if you want to be able to read machine code, you're going to have to sacrifice.. pretty much anything in life worth living for.
InVerse is offline   Reply With Quote
Old 08-14-2009, 02:31 AM   #5
Aphex19
Junior Member
 
Join Date: Jul 2009
Posts: 10
Default

haha, sorry i was kinda missing the point.

I can find those instructions actually. Thanks for you patience, you have helped me alot.

Ill keep reading up on machine code.

Last edited by Aphex19; 08-14-2009 at 02:37 AM.
Aphex19 is offline   Reply With Quote
Old 08-14-2009, 07:54 AM   #6
Iconoclast
Senior Member
 
Join Date: Jul 2008
Posts: 278
Default

Basically assembly is still text, so it is compiled only into RAM for execution, which is called interpretation.
Through compilation, the primary memory is already written in machine language form so that it does not have to be translated.
In instance, HTML isn't compiled to a file; it's compiled into random access memory--or interpreted by the web browser.

Assembly is considered a second generation language in part because there are divisions of "assembly" specific to the hardware architecture. This specific design makes compilation easy.

Third and fourth generation languages often use English symbols that humans can more easily understand.
Iconoclast is offline   Reply With Quote
Old 08-14-2009, 04:44 PM   #7
Isildur
Senior Member
 
Isildur's Avatar
 
Join Date: Nov 2004
Posts: 1,339
Default

Quote:
Originally Posted by Iconoclast View Post
Basically assembly is still text, so it is compiled only into RAM for execution, which is called interpretation.
er... not really. On an end-user's machine, there normally isn't any compilation of assembly going on. The code has already been compiled into machine language (edit: except for installations that use GCC). Interpretted languages are something different.

Quote:
Originally Posted by Iconoclast View Post
Through compilation, the primary memory is already written in machine language form so that it does not have to be translated.
In instance, HTML isn't compiled to a file; it's compiled into random access memory--or interpreted by the web browser.
HTML is not compiled in that sense, as it is a markup language, not a programming language.

Quote:
Originally Posted by Iconoclast View Post
Assembly is considered a second generation language in part because there are divisions of "assembly" specific to the hardware architecture. This specific design makes compilation easy.

Third and fourth generation languages often use English symbols that humans can more easily understand.
Beyond 1GL and 2GL, the categories that you're describing are usually refered to among programmers not as generations but as programming language classifications, namely, low-level programming languages, high-level programming languages, and very high-level programming languages. (See http://en.wikipedia.org/wiki/Talk:Se...mming_language)


I don't mean to be harsh, but when someone has already given a good answer like InVerse did, it's unhelpful to tack on an explanation based on an incomplete understanding of the subject, even if the impetus was a genuine desire to be helpful.
__________________
Holding out for Hostess Snack Cakes...

Last edited by Isildur; 08-14-2009 at 05:09 PM. Reason: inserted reference to GCC, link to wikipedia discussion
Isildur is offline   Reply With Quote
Old 08-15-2009, 12:02 AM   #8
Iconoclast
Senior Member
 
Join Date: Jul 2008
Posts: 278
Default

Quote:
there normally isn't any compilation of assembly going on
interpret does not compile
Iconoclast 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. The time now is 11:36 PM.

Contact Us - Zophar's Domain - Archive - Top

Powered by vBulletin® Version 3.8.4
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.