DOS Emulator with Debugger / Memory View

Discuss emulation of the Nintendo Entertainment System and Famicom.

Moderator: Moderators

User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: DOS Emulator with Debugger / Memory View

Post by rainwarrior »

I think you could do a lot with a modified console. If you can do something to suspend the CPU and dump RAM periodically that'd go a long way toward mapping that out.

Kevtris made a hardware stepping debugger out of the CopyNES (the "microbug" program), and I definitely think something similar could have been built back then too. It doesn't really require modern parts, or have modern computational requirements.

Edit: linking Kevtris' CopyNES page above for reference.
Last edited by rainwarrior on Wed Aug 31, 2022 12:07 pm, edited 1 time in total.
rludlamjr
Posts: 7
Joined: Tue Mar 02, 2021 8:03 am

Re: DOS Emulator with Debugger / Memory View

Post by rludlamjr »

Yeah, that’s what I expect as well - a modified console with a combination of custom hardware and software would be ideal. I would love to figure out how to diy a hardware dev kit to build directly to a kart and play on hardware with debugging but that is way beyond my abilities with electronics!
Fiskbit
Posts: 891
Joined: Sat Nov 18, 2017 9:15 pm

Re: DOS Emulator with Debugger / Memory View

Post by Fiskbit »

How long can you suspend the CPU and PPU without their internal state decaying? Is OAM the only thing that won't persist?
User avatar
Dwedit
Posts: 4924
Joined: Fri Nov 19, 2004 7:35 pm
Contact:

Re: DOS Emulator with Debugger / Memory View

Post by Dwedit »

You usually would only suspend the CPU and leave the PPU running. Yes, games that rely on PPU stuff like sprite 0 hits or mapper interrupts have a chance of being unable to resume.
Here come the fortune cookies! Here come the fortune cookies! They're wearing paper hats!
Fiskbit
Posts: 891
Joined: Sat Nov 18, 2017 9:15 pm

Re: DOS Emulator with Debugger / Memory View

Post by Fiskbit »

From what I can find online, the 6502 has a minimum clock speed because its registers are dynamic rather than static and will decay if the clock is too slow. I don't know if that applies to the version in the 2A03.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: DOS Emulator with Debugger / Memory View

Post by lidnariq »

It should apply to the 2A03 as well - the 2A03 should have a minimum clock somewhere around the same M2 speed as the bare 6502.

There is dynamic logic is various places in the APU, but the nodes are larger, so have higher capacitance, and thus should hold their values longer.
User avatar
Memblers
Site Admin
Posts: 4044
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: DOS Emulator with Debugger / Memory View

Post by Memblers »

the loopynes version is debug.exe, it's still available here: https://www.zophar.net/nes/loopynes.html. starts up in text mode, and it seems usable enough.

I never did anything with debuggers back then, I often wrote stuff to $6000 and viewed the SAV file in a hex editor. Then on the NES I started using an EPROM emulator for NES PRG ROM and an RS232 adapter on the 2nd controller port for communication. If you're interested, I designed a Cheapocabra devkit that would be compatible with any computer that can send a file with XMODEM/CRC over RS232. It only transfers like 1kB/sec the way it's usually set up at 19.2kbps though, kinda slow. There is a bootloader that supports NROM and GTROM, but there's no debugging feature to it, as the hardware is essentially just a level converter. But from the NES it's easy to output text for logging, or any debug messages in ASCII/ANSI and it'll show up on your terminal.

I remember FWNES running better when I upgraded, which would have been from 486/66 to Celeron 333. I don't remember ever using the debugger, really.

I still have almost all my old NES dev files from back then (stuff from my 386 is long gone except one .NES file I had posted to Usenet). I used to grab anything NES-related I could find, if there's anything that can't be found online still, maybe I have it.

Are you using MS-DOS Editor (QBASIC minus the QBASIC part), or something else? I used to use that, with the colorset as green text on black background to set the mood, heheh. If I needed to see the long text lines, I'd get into 132-column mode by running and quitting (I'm pretty sure was) Nerdtracker 2, that would put it into 132 column mode, edit.com simply stays in that mode. I've seen people say "mode co132" or "mode co132,25" is supposed to do that, too.
User avatar
tokumaru
Posts: 12427
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

Re: DOS Emulator with Debugger / Memory View

Post by tokumaru »

Do you even need to freeze the CPU, though? I suppose you could keep it running and feed it NOPs indefinitely. The original PC could be obtained from the first opcode fetch, and be later fed back to the CPU in a JMP instruction to resume execution.
rludlamjr
Posts: 7
Joined: Tue Mar 02, 2021 8:03 am

Re: DOS Emulator with Debugger / Memory View

Post by rludlamjr »

Memblers wrote: Wed Aug 31, 2022 5:17 pm the loopynes version is debug.exe, it's still available here: https://www.zophar.net/nes/loopynes.html. starts up in text mode, and it seems usable enough.

I never did anything with debuggers back then, I often wrote stuff to $6000 and viewed the SAV file in a hex editor. Then on the NES I started using an EPROM emulator for NES PRG ROM and an RS232 adapter on the 2nd controller port for communication. If you're interested, I designed a Cheapocabra devkit that would be compatible with any computer that can send a file with XMODEM/CRC over RS232. It only transfers like 1kB/sec the way it's usually set up at 19.2kbps though, kinda slow. There is a bootloader that supports NROM and GTROM, but there's no debugging feature to it, as the hardware is essentially just a level converter. But from the NES it's easy to output text for logging, or any debug messages in ASCII/ANSI and it'll show up on your terminal.

I remember FWNES running better when I upgraded, which would have been from 486/66 to Celeron 333. I don't remember ever using the debugger, really.

I still have almost all my old NES dev files from back then (stuff from my 386 is long gone except one .NES file I had posted to Usenet). I used to grab anything NES-related I could find, if there's anything that can't be found online still, maybe I have it.

Are you using MS-DOS Editor (QBASIC minus the QBASIC part), or something else? I used to use that, with the colorset as green text on black background to set the mood, heheh. If I needed to see the long text lines, I'd get into 132-column mode by running and quitting (I'm pretty sure was) Nerdtracker 2, that would put it into 132 column mode, edit.com simply stays in that mode. I've seen people say "mode co132" or "mode co132,25" is supposed to do that, too.

Oh wow, this is amazing info - thank you! Incredibly helpful and really impressive to hear you were doing all this back on a 386. If you are willing to share the plans for your rs232 dev kit that would be so awesome and is exactly the kind of stuff I am looking for.

I’ve been using the same dos editor you mentioned - I like that it’s lightweight and agree that the colors / text modes are pretty much all I need at this point on that score.

I spend most of the day all day looking at my MacBook so at the end of the day I have to force myself to use that for other things and it feels like a chore. Firing up a dos prompt on a CRT and bashing text in on a model m isn’t like work at all to me - it’s like a nostalgic creativity zone that I look forward to. Having something like your hardware dev kit would be such a great addition to that mix! I know it’s weird but I actually miss the days when getting something to work with hardware and so on was half the battle. Writing software on a modern pc is so different for me than that.

Thanks again for the great discussion!
User avatar
Memblers
Site Admin
Posts: 4044
Joined: Mon Sep 20, 2004 6:04 am
Location: Indianapolis
Contact:

Re: DOS Emulator with Debugger / Memory View

Post by Memblers »

The RS232 hardware is the standard schematic in the datasheet for any max232/max202 compatible chip. Other than that, it's just serial port cable and NES extension cable. The NES transmits on the controller OUT pin, and receives on the D0 pin. The NES 5V powers the MAX202.

I'll need to gather up some my old source codes, I'll work on getting the usable parts uploaded somewhere. The main two subroutines are simply sending a character, and receiving a character. On top of that, as a complete program there's the XMODEM bootloader. The bootloader is designed to support GTROM. There's a version you can load onto the cart itself, so you need a programmed cart to start with. And there's another version of the bootloader that can be loaded onto a Game Genie. The latter requires replacing the GG ROM with a 2732 EPROM, but upside is that it can program a completely blank cartridge.

The send and receive code is 19.2kbps, faster speeds are possible though. I've had good experimental results with 115.2kbps, using the NES's DPCM and frame IRQ for long and short timeouts from infinite loops, allowing for faster polling. I also have some experimental code that interleaves the 115.2kbps receiving with the flash programming sequence, I believe it may be possible to do this in parallel, but it's needs a new protocol written around it. That would be something like 10kb/sec, which would be great if it could work.
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: DOS Emulator with Debugger / Memory View

Post by Oziphantom »

The min speed for a 6502 is "up for debate" I've seen 150hz listed, but then also people will say 500hz so..

There is no way to halt the 5A22 though is there? You can use the HALT pin on a real 6502, or to some degree AEC on a 6510/8500.
So you would have to do NOP injection as you can't hold it. The issue then comes from the NMI, in that you won't really be able to stop the NMI from firing randomly, and then you have to end the nop with an RTI to match it, then jmp XXXX. This combined with PPU not stopping makes single stepping on hardware impractical. Unless you have a 6502 ICE, even then it still has some limited practical applications.
Since you have a RAM "cart", you place a BRK instruction into the next spot in the cart, then your BRK handler handles talking to your host and then, it removes the BRK, restores the instruction, sets the BRK to the next dest, jmp and carry on. Since you now have a full handler you can then handle NMI requests properly. This is as fast as you are imagining. You can also JSR injection to an address.
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: DOS Emulator with Debugger / Memory View

Post by rainwarrior »

I don't know how the CopyNES works, but it replaces the CPU with a socket, and then plugs into that socket. This places a little bit of logic between the CPU and the main board, but I haven't personally investigated the exact mechanisms. I will say that microbug works pretty well, and I've used it several times to step through NES code on a live cartridge. It's nowhere near as easy to use as an emulator's debugger, but is does do what it can, and it's a really good tool.

Though, it might be limited to mostly the start of an NES program... I've only used it for figuring out mappers, which I think was Kevtris' main purpose with it. I remember NMI and IRQ had to be manually executed. PPU stuff does display, but it might differ from what you'd normally see on screen.

Links: Main page, technical description, plugin software (including "microbug"). Also: source code for windows/USB client and plugins/BIOS.

So, maybe the details can be pieced together from the above. What makes microbug work would be a combination of the CopyNES hardware, a plugin and/or BIOS that runs on the 6502, and the client software which communicates with it from the PC.

Kevtris' original software (still available on its page) is for DOS with a parallel port, so it should be something OP could run on the desired machine.

Edit: found a document describing microbug at a high level. COPYUSE.TXT. Apparently it might be emulating the 6502 with itself... which I guess would sidestep (or fail to conquer) some of the issues mentioned. Emulator source is in the BIOS: bios.s
Oziphantom
Posts: 1565
Joined: Tue Feb 07, 2017 2:03 am

Re: DOS Emulator with Debugger / Memory View

Post by Oziphantom »

so no HALT pins, it just tristates A11/12/13/14/15 which allows it to bank in its EPROM or actual Cart. So all A0-A10 has to be handled by the CPU as per normal.
Do you have a RAM board attached as well for the microbug? or is it burned into the EEPROM in some way?
User avatar
rainwarrior
Posts: 8732
Joined: Sun Jan 22, 2012 12:03 pm
Location: Canada
Contact:

Re: DOS Emulator with Debugger / Memory View

Post by rainwarrior »

I don't think a CopyNES has any RAM, aside from a byte or two of latches used for communication? COPYUSE.TXT said it reserved a few bytes at the top of the stack for itself. The EEPROM just has the BIOS program on it, which the CopyNES can map into the the CPU memory space. Otherwise, it transmits data back and forth to the attached computer whenever it breaks.

There are plugins (aside from microbug) which upload code to the NES RAM, which the CopyNES BIOS will jump to on command. These have various purposes, but most commonly are for cart dumping.

It could also be used with a RAM cart (e.g. the PowerPak Lite). That was good for uploading and testing a program over USB, or presumably parallel port.
lidnariq
Posts: 11432
Joined: Sun Apr 13, 2008 11:12 am

Re: DOS Emulator with Debugger / Memory View

Post by lidnariq »

5A22 does have HALT and RDY pins, but they're soldered on the mainboard to ground and +5V...
Post Reply