Page 1 of 1

nes emulation problem

Posted: Fri Sep 12, 2008 6:46 pm
by bruce_lee
hi there,
i have so far completed all addressing modes, instructions, the routine of fetching opcodes, push/ pop. So in short if i load a game into my emulator, it verifies the nes format, then fetches code and executes instructions etc.
The problem is that upon fetching the first instruction which reads data from RAM area (which contains nothing at this time) the program just loops into BRK (simply because the opcode for BRK is 0x00) . The question i have is - has anyone else faced this problem?
i have been looking into this problem for weeks now and not found any solution :(
any help you guys can give would greatly be appreciated
many thanks

Posted: Fri Sep 12, 2008 9:35 pm
by GARTHWILSON
To start from the beginning-- When the computer starts up, it will always have the reset routine in memory, normally in ROM. The ROM-resident code may load an operating system of some sort from mass storage, or it may already have it so it doesn't have to go get it. That code, in turn, will give the means to load your application (if indeed that is not also already ROM-resident) and jump into it to run it. You say you loaded the game, but then you say there's nothing in RAM where the computer jumps in expecting to find instructions. Perhaps it's not really loading, or you're not jumping into the right address.

On a slightly different subject, but one you or someone else asked about before, if it were data, it should be clear that no program should ever depend on valid data being in unitialized variables or arrays or other data structures. BTW, uninitialized RAM is not normally all 0's. It could be anything.

I think I understand your purpose in this project; but if someone just wants to learn 6502 programming, I do not really encourage starting with a simulator. It temps the newbie with faster initial progress, but IMO, it gives too much insulation from the essentials, such that the student may feel he's progressing nicely when in fact there are certain rudiments he has never conquered. Further down the road, when he has put too much confidence in simulators, his programming is more buggy and less dependable in the long run. He may also run into simple problems that he just does not have the answers to. An emulator BTW includes hardware and can be plugged into your board's processor socket. It is more than a simulator, and can be used to debug the hardware. A simulator is software only. I don't harp on it too much though because the mistake has been made so much that the erroneous terminology is beginning to stick.

Re: nes emulation problem

Posted: Sun Sep 14, 2008 6:50 pm
by tomaitheous
bruce_lee wrote:
hi there,
i have so far completed all addressing modes, instructions, the routine of fetching opcodes, push/ pop. So in short if i load a game into my emulator, it verifies the nes format, then fetches code and executes instructions etc.
The problem is that upon fetching the first instruction which reads data from RAM area (which contains nothing at this time) the program just loops into BRK (simply because the opcode for BRK is 0x00) . The question i have is - has anyone else faced this problem?
i have been looking into this problem for weeks now and not found any solution :(
any help you guys can give would greatly be appreciated
many thanks
Which rom are you having this problem with? Have you emulated any of the mappers? Some games have different revisions and thus have a different starting point for mapping the last 16k address range. These roms are usually labeled PRG 1 or PRG 0.

Anyway, if you can give some details I can help you out (been doing a lot of NES emulation and programming stuff lately).

Posted: Fri Dec 12, 2008 9:51 pm
by TMorita
Sounds like the emulator isn't properly initializing the PC from the reset vector.

Toshi