It is currently Sat Dec 16, 2017 5:59 am

All times are UTC - 7 hours





Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Tue Nov 30, 2004 5:35 pm 
Hello, I am a 16 year old, programmer with 5 years of programming experience that wants to create a NES emulator. So far I have code that reads the headers (easy), and im pretty sure, the correct rom memory. I understand assembly programming concepts, and I know it seems like much for me, but I honestly feel that I am at this level. I have educated myself thoroughly before writing this post, and I have been writing many different types of tests dealing with rom images to prepare myself.

[iFirst off,[/i] let me ask you this... Is it possible to do all of my memory handling using the decimal system? For example, when I declare my memory array, may I declare it as memory(65536)? If not, I may be discouraged at writing this, because I want to start off in a basic language, one that I know well, and one that is very quick (Blitz Basic)

Second off, I have read all of the available 6502 documents, as well as NES-related documents, and I have yet to know what a trainer is?

Third, does the memory-from-rom-file to memory-array transfer start immediately after bytes 8-15 in the rom file (those 'unused' values)?

Four, It is fully possible to write a working emulator without emulating the graphics and sound, right? Like, I can complete the core before i show anything on the screen?

Ok, one last one, I promise:

I loaded 'Super Mario Bros (E).nes' into memory, and from what i can tell, it starts off with the following in the PRG ram: $D0 $11

If any of you could tell me if this is correct, I would be happy. I am not sure how to tell if the stuff I am loading is in the correct spaces or not, but i'm sure that this performs "BNE $11" (in the assembly form)

I hope you guys dont mind to answer my questions. And if I seem to have the wrong perception on some things, feel free to lead me on the right path.

Thank you VERY much in advance.


Top
  
 
PostPosted: Tue Nov 30, 2004 6:18 pm 
Offline

Joined: Mon Nov 22, 2004 3:24 pm
Posts: 162
Location: Sweden
1. Yes, you can use the decimal system, though you're going to be using different constants than everyone else. Many basic dialects supports hexadecmial constants though (i.e. &H40F3).
I don't know much about the current versions of Blitz basic but if it's anything like the Amiga version I used to love then it should at the very least be possible to pull it off. Keep in mind that there's a good chance that you'll spend your time fighting the language, trying to make it do something it just wasn't designed for, and that's not something you'd want to discover half-way through the project.
It's also going to be tough to integerate any external libraries into Blitz Basic, thus you'll probably end up writing your own CPU and APU code (and PPU, but that's pretty much a given anyway).

2. Don't worry about the iNES header's trainer. I don't think anybody's ever used it.

3. Yes, the program ROM directly follows the header. And after that you've got the character ROM.

4. Few games rely on proper sound emulation, so that's something you can hold of for a while. Most games need a somewhat accurate PPU emulation though. You can test most subsystems without involving an actual NES game so you don't have to write everything simultaneously.

Lastly I want to note that this is a major project. Maybe you should start off by writing a small NES game or demo, this really helps you understand how the console works.
Another tip is to limit the scope of the project by splitting it up into smaller independent projects. Writing a 6502 emulator is a worthy project in itself.

Oh, and don't forget to have fun writing it =)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 30, 2004 6:23 pm 
Offline

Joined: Tue Nov 30, 2004 5:37 pm
Posts: 7
By CPU code, you mean writing what happens when say the "LDA" command is used? Its stuff like that that I WANT to program :) The WHOLE thing, from scratch. I have read other people's source code and my mouth waters just thinking of coding it.

I am completely aducated about how large this project is.

What tools will I need to begin NES game creation? I could probably figure this out, but hey, perhaps you could lead me to the best ones.

_________________
~
Nev, nev6502@hotmail.com (MSN)


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 30, 2004 6:54 pm 
Offline

Joined: Mon Nov 22, 2004 3:24 pm
Posts: 162
Location: Sweden
Nev wrote:
By CPU code, you mean writing what happens when say the "LDA" command is used? Its stuff like that that I WANT to program :) The WHOLE thing, from scratch. I have read other people's source code and my mouth waters just thinking of coding it.
Well, I can understand that =)
At least start out by writing a dissassembler. That's the (de-facto) standard way of writing a CPU emulator anyway.

Nev wrote:
What tools will I need to begin NES game creation? I could probably figure this out, but hey, perhaps you could lead me to the best ones.
Mostly just an assembler and an emulator to test it on. Don't worry about graphics or sound editors as you probably want to write out the data by hand to learn the formats.
Don't use a custom NES assembler but go for the generic variety instead, that way you'll have to pratice dealing with the iNES header and ROM layout. Apart from that any assembler will do, and since I don't want to start a flame war I'll let you pick one yourself.
Find a somewhat accurate emulator with a decent debugger. I think there was a thread about this on the old board.
Above all what you need is good documentation, most of which is available on this site.

Hm.. Maybe that wasn't too helpful. So I'll recommend the ACME 6502 assembler and an FCEU version with the debugger enabled, while these might not be the best choices available it is enough to get you started.

edit: Probably should've read your question the first time around ;)


Top
 Profile  
 
 Post subject: :)
PostPosted: Tue Nov 30, 2004 7:33 pm 
Offline
User avatar

Joined: Wed Nov 17, 2004 12:34 pm
Posts: 41
Good choice picking an NES EMU first - I wrote a gameboy color emulator also and, although more complex, having to do deal with the major timing issues of the nes emu made emulating a gameboy seem like a vacation in maui. I mean MY GOODNESS. With the gameboy emu since the system ACTUALLY HAD FEATURES the games didn't have to HACK their way into special effects which ALWAYS SEEM TO SCREW UP nes emulators. :) Hehehe.

Although NES emulators are more fun in the end.

And make sure you start with getting simple demos working, and ask lots of question so we sound smart, and remember when Quietust says something, it is so. I have posters of him on my wall... :| I'm getting help though.

"I have read other people's source code and my mouth waters just thinking of coding it. "

haha who needs women when we have nes emulation.


Top
 Profile  
 
 Post subject:
PostPosted: Tue Nov 30, 2004 11:06 pm 
Offline

Joined: Tue Nov 30, 2004 5:37 pm
Posts: 7
Thank you both for your generosity, I am very confident now that I have chosen the right 'home community' :)

As for the disassembler, doynax, that was one of the test tools I made.. The only thing being that I didnt complete all of the commands, just two simple ones; BMI and LDA. Is it necessary to do all of the different commands? Are some different to disassemble, or does it show that I have the basics down?

The only thing i'm having a problem knowing is whether im reading from the right memory locations in my program memory... here is what I have (keep in mind I MUST use decimals because blitz has no hexidecimal support):

Code:
Const memsize=65536 ; <-- Decimal for $10000
Dim memory(memsize)
Global FinalMemuse ; <-- This is the very last location that contains something


And the memory I am thinking is program memory is:

Code:
SaveRam("ram.log",1,28672)


(this saves the contents in the memory() array in hex format, with returns between each byte)

Would 28672 be the right location for reading the actual 'instructions'?

Once again, I appreciate your help!

On a side note, I will downlaod that assembler and I use FCEU already, so it should be good.

(PS. laughy: I chose the NES because to me there is not any other console more 'classic' and 'entertaining')

_________________
~
Nev, nev6502@hotmail.com (MSN)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 1:21 am 
Offline

Joined: Mon Nov 22, 2004 3:24 pm
Posts: 162
Location: Sweden
Nev wrote:
As for the disassembler, doynax, that was one of the test tools I made.. The only thing being that I didnt complete all of the commands, just two simple ones; BMI and LDA. Is it necessary to do all of the different commands? Are some different to disassemble, or does it show that I have the basics down?
It's not really any difference. But completeing the dissassembler will force you to write some of the tables involved and handle opcode/address mode decoding properly before starting on the actual emulator.

Nev wrote:
keep in mind I MUST use decimals because blitz has no hexidecimal support
You mean that Blitz has actually gotten lamer since my days? I remember beeing able to write inline asm and everything =)

New wrote:
The only thing i'm having a problem knowing is whether im reading from the right memory locations in my program memory... here is what I have

Let's ignore mappers for a while and deal cartidges using 32 kB of prg-rom.
The first 32 kB of such a cartridge (after the 16-byte header that is) would be loaded to address $8000 (32768) in the NES's memory, I'm not sure where did got 28672 ($7000) from..
The thing is that you can't just start executing code at $8000, instead there's a special word at the rom's end called the reset vector that tells you where to start the execution. Just grab the little-endian word from $fffc (65532) to get this address.


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 4:33 pm 
Offline

Joined: Tue Nov 30, 2004 5:37 pm
Posts: 7
Alright, what I did was take your info, and turned it into something I think is a step forward. If you wouldnt mind, please take a look at the (416Kb) ram-dump of 'Super Mario Bros (E).nes' I made. Do not worry about how to read it, as you may open it in notepad, as I dumped the addresses and values in hex format, with a return between each address for very easy reading. You may get this at:

http://nev.syntesis.org/neso/ram.log

It starts at $8000 and goes to $FFFFFF.

This must mean that the program starts off at $80, right? Does it mean I begin execution at ($8000+80) $8080?

Also, if you could confirm that the values are indeed in the right spots, I would be very happy. I am still not so confident that I have loaded things 100% correctly...


Thank you very much. Also, one more thing;

On an exection, for example (JMP): $4C,$00,$F0 , I need to use the low byte / high byte conversion. Any idea of how I would convert these in decimal format?


** EDIT
I figured it out... r=number on the right, l=number on the left

LOCATION = (r*256) Or l

** EDIT #2
Using rocknes, I opened smb and guess what? I looked at the "asm source" (which shows addresses and what commands are run beside them, and my ram.log file is correct, EXCEPT it is off by one byte. Meaning what is at $8000 in RockNES is at $8001 in mine. Easily fixable bug :)

It makes me very happy that I have loaded the rom successfully :)

It seems as though I have answered both of my own questions... hehe.

_________________
~
Nev, nev6502@hotmail.com (MSN)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 5:31 pm 
Offline

Joined: Tue Nov 30, 2004 5:37 pm
Posts: 7
Here is a good quesiton (or horrendously bad)...

What is the stack? What does it do?

I have found many mentions of it, but I am unfortunately unable to clearly see what it is.

I'm VERY close to starting the emulation of the 6502 in NES roms :)

It is getting extremely interesting...

_________________
~
Nev, nev6502@hotmail.com (MSN)


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 5:40 pm 
Offline
User avatar

Joined: Wed Nov 10, 2004 6:47 pm
Posts: 1845
The stack is an area in RAM which is commonly used to store return addresses for subroutines, as well as other things. Several instructions push values onto the stack, and some pull values from it.

The stack lies in the $0100-$01FF range and grows downward... meaning $01FF is the bottom (start) of the stack.. and the stack grows towards $0100.

The 6502 has a Stack Pointer register which is used when pushing/pulling values from the stack. When emulating... a push can be done like so:

RAM[ 0x0100 + SP ] = value_pushed;
SP--;

and a pull can be done like so:

SP++;
value_pulled = RAM[ 0x100 + SP ];

where 'SP' is your variable representing the stack pointer (8-bit... always between $00 and $FF)


To visualize a stack... think of a stack of plates. When you "push" a value... it's like placing a new plate on the stack... and when you "pull" a value, you're taking the plate which is currently on the very top of the stack off (and the plate below it becomes the new top).


Top
 Profile  
 
 Post subject:
PostPosted: Wed Dec 01, 2004 6:32 pm 
Offline

Joined: Tue Nov 30, 2004 5:37 pm
Posts: 7
Oh! Thank you very much!

Some great news:
I have begun 6502 emulation.. The CPU core should be done by Friday. Once this is done, is when it gets interesting (graphics)!

As for sound, that will not be completed unless I find a sound library for blitz, OR a dll that can help me.

I cant believe it! Im coding an emulator :), not only that, but an emulator for a system I love.

THANK YOU ALL VERY MUCH!

_________________
~
Nev, nev6502@hotmail.com (MSN)


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 02, 2004 10:44 am 
Offline
User avatar

Joined: Sun Sep 19, 2004 9:28 pm
Posts: 3192
Location: Mountain View, CA, USA
No offence intended, but...

Sixteen? That means you were born in 1988 -- remarkably, the same time the NES made it's appearance in the United States.

I can't see how this is a system you love when you were _six years old_ at the time developers had moved on to the SNES and Playstation.

Bananamos will have a field day with this one...


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 02, 2004 11:59 am 
Offline

Joined: Mon Nov 22, 2004 3:24 pm
Posts: 162
Location: Sweden
koitsu wrote:
No offence intended, but...

Sixteen? That means you were born in 1988 -- remarkably, the same time the NES made it's appearance in the United States.

I can't see how this is a system you love when you were _six years old_ at the time developers had moved on to the SNES and Playstation.

Bananamos will have a field day with this one...

I resent that remark. There's nothing wrong with older wo..machines!
I personally enjoy coding for the pdp-11 once in a while, a system 15 years older than I am.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 02, 2004 1:20 pm 
Offline

Joined: Tue Nov 23, 2004 10:06 pm
Posts: 16
i myself have spent many hours writing chiptunes for my univac....


support the YOUTH

_________________
Peter Swimm
toilville.com


Top
 Profile  
 
 Post subject:
PostPosted: Thu Dec 02, 2004 2:20 pm 
Offline

Joined: Mon Sep 27, 2004 11:51 pm
Posts: 101
koitsu wrote:
Bananamos will have a field day with this one...


Yea, whatever happened to him...

_________________
http://hydesprojects.cjb.net/


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC - 7 hours


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to:  
Powered by phpBB® Forum Software © phpBB Group