Advertisement

Indirect addressing

Started by July 08, 2000 02:47 PM
13 comments, last by Muzzafarath 24 years, 5 months ago
I've been trying to write a disassembler for the 6502 (I think that what it's called), the CPU that's in the NES (8 bit stuff you know ). So far I've managed to read .nes files correctly. Now I "just" have to translate all the opcodes to 6502 asm Anyway, the description of the opcodes for the 6502 that I have mentions indirect addressing quite often. Well, what is indirect addressing? You might think I shouldn't mess with asm if I don't know what indirect addressing is, but everyone has to start somewhere - Muzzafarath Mad House Software The Field Marshals Edited by - Muzzafarath on 7/8/00 2:50:03 PM
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Muzzafarath,

10 years ago I was pretty good at 6502! (But how difficult can it be to work with 3 registers..X, Y, Accumulator )

Anyway, indirect addressing is the same as using pointers. Instead of operating on a fixed memory address, you''ll be operating on a memory address held within another memory address.

If you want to send me any stuff you find on 6502, I''m sure it will all come flooding back.

Later

Matt



Check out my project at:www.btinternet.com/~Matthew.Bennett
Advertisement
Yes everyone has to start somewhere.. but you''ve started on the wrong side of the bridge... start learning assembler first, and then get into your project as you feel ease working with asm... just my 2 dollars.. (wow.. im givin ya much.. aint i... here''s the 2 cents then... gimme back my 2 bucks..)

btw, the 3DModelMan is right about Inderict addressing...here''s a link...

Indirect Addressing
Thanks for the info!

I'm not attempting to become an asm guru, I just want to have a basic understanding of it before I attempt to write an emulator. I'm not going to write programs in asm (I'm sticking to C++), I just want to be able to play Super Mario with my own emulator

>> If you want to send me any stuff you find on 6502, I'm sure it will all come flooding back. <<

Okay, I'll remember that

- Muzzafarath

Mad House Software
The Field Marshals

Edited by - Muzzafarath on July 9, 2000 1:41:02 PM
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
I found some stuff on 6502, but I'm really curious about what you are doing.

Was the NES limited to 64k? My old Atari ROMS supported bank-switching that opened up the memory capability.

If it is 64k, then I suppose you could hold the entire NES system in one array and maniplute it through a virtual machine!

Have you managed to find information on the ROMS? Attempting emulation will be pointless if you cannot duplicate the effect of ROM routines (like display and sound manipulation). I knew an awful lot about the inner workings of Atari's finest, but I don't know if I could source enough info to write an emulator (not that I want to, I've already got one ).

What info do you have on the NES image files? Can you be sure you know the entry position for the code (perhaps on these cartridge based systems it was always the same)?

Sorry for asking so many questions, hope you don't mind.

Later

Matt



Check out my project at:www.btinternet.com/~Matthew.Bennett

PS You're not trying to write a disassembler, just a 6502 emulator. Disassemblers convert opcodes back into readable source, this is why Gladiator seemed to think you were 'on the wrong side of the bridge'.

Edited by - 3dmodelman on July 9, 2000 3:11:04 PM
Some time ago I used to do a lot of Z80 assembly.
The asm wasn''t that hard, but the I/O ports where REAL hard!!!

Have you got a list of ports and the way to use (emulate) them.
Video ports, sound ports, joystick ports, maybe memory management ports...need I go on...

This port stuff is not only about reading/writing simple values, but this can be real difficult, and information about this isn''t easy to find.

This was my Z80 experience - I hope someone can prove the nes is easier -

Good luck - you might need much of it

Advertisement
>> Was the NES limited to 64k? <<

With memory mappers and bank switching NES games can/could support a lot more, I believe the largest I've seen is 1 mb.

>> If it is 64k, then I suppose you could hold the entire NES system in one array and maniplute it through a virtual machine! <<

That's what I'm planning to do. I'm only planning to support 64kb roms, so if my "parser" encounters "LDA $2000" for example, register a = memory[0x2000]. It would of course be good to check the array bounds

The de-facto standard of storing NES roms is Marat Forgot-Last-Name's .nes format. http://www.komkon.org/fms/EMUL8.

>> You're not trying to write a disassembler, just a 6502 emulator. this is why Gladiator seemed to think you were 'on the wrong side of the bridge. <<

I do know the difference between a disassembler and an emulator I *am* trying to write a dissassembler. Just a simple one, before I attempt to write an emulator. I thought it would be a good way to get familiar with the 6502 instruction set, but I'm thinking of not writing the d-asm and getting started on the emu right away.

>> Can you be sure you know the entry position for the code (perhaps on these cartridge based systems it was always the same)? <<

In .nes files, the first code bank (also called PRG-ROM) starts at offset 0x16 and then continues in ascending order. After that follows the VROM (also called CHR-ROM)banks in ascending order.

The best documentation of the NES I've have found so far is this one. It covers almost everything, except the CPU, but there are plenty of resources for that.

>> Have you got a list of ports and the way to use (emulate) them. <<

Yoshi's document (mentioned above) covers all of the internal registers of the NES (PPU, pAPU, joypad ports).

Input seems to be the easiest part. For example, if I would try to simulate somone pressing LEFT on joypad 1, I would have to set the correct bit at the correct address when the user presses the left arrow on the keyboard. When a program then reads the correct bit from the memory address that contains the state of joypad 1, it will then think that someone's pressing left (which someone is).

Matt, as you've done 6502 asm, is the 6502 low endian or high endian? I haven't found any info on this. Another thing: I have yet to read through a documentation of the 6502 instruction set, but are there any instructions for creating variables? My guess is that there aren't any. Am I right or wrong?

- Muzzafarath

Mad House Software
The Field Marshals

Edited by - Muzzafarath on July 9, 2000 4:20:50 PM
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
Excellent!

I''m pleased to see you have covered everything, I didn''t doubt you or anything, but I was curious about the availability of ALL the info you''re going to need.

Good luck with it!

Matt



Check out my project at:www.btinternet.com/~Matthew.Bennett
I've edited my post above, now there are some questions for you which you probably didn't see when you replied to my post Could you answer them?

Edited by - Muzzafarath on July 9, 2000 4:22:21 PM
I'm reminded of the day my daughter came in, looked over my shoulder at some Perl 4 code, and said, "What is that, swearing?" - Larry Wall
The 6502 is high-endian, same as the x86. I hope I haven''t got my terminology back-to-front though!

With the compiler it was possible to create a ''variable'', but then it was just a static memory address. It''s the same for the subroutine labels, they were ''nameable'' in the compiler so you could write JSR MOVEUP, but it was only ever treated as a static memory address after that. I keep saying the word static, as the machine code was always pretty much written to reside in the same section of memory. Writing re-locatable asm was impossible I reckon for any large application. (By ''large'' I mean over 10k )

You''ve only got the three registers that I mentioned before (X, Y and Accumulator), these are all 8 bit! (So you couldn''t have LDA $2000)

Then you''ve got several ''flags'', these are just a single bit each.

It''s a lonely road from there on in.....

Cheers

Matt




Check out my project at:www.btinternet.com/~Matthew.Bennett

This topic is closed to new replies.

Advertisement