Information down below is partially obsolete, refer to README-NintendulatorDX.txt in the release package instead.
---
Because of new features in CC65 I've been able to add a new feature to Nintendulator's debugger. Now it's possible to view the original source code when debugging if the ROM has been assembled with CC65. I'm not sure how much I'm going to be working on this in the future so I'll just release it now. Here's a screenshot:
This was a quick hack so there probably are some bugs in there. Even in its current state I think it's quite useful though.
How to use
Pass the "--dbgfile foo.nes.dbg" switch to linker to generate the debug file. You'll also need to include the debug information in object files using the "-g" switch when assembling/compiling. The debug file has to have the same name as the iNES rom with ".dbg" extension added, for example "foo.nes.dbg".
NOTE! You need to use the latest snapshot version of CC65 because these features do not exist in the stable version.
For now it only works with iNES roms! Also it will not work if the linker config outputs to more than one file.
How to use the cycle counting timers
Write to $402x to start the timer and $403x to stop it (where x is the timer ID 0-15). $401E/$401F are aliases for $4020/$4030 (for VirtuaNES compatibility). Timer title can be specified with a symbol named "__timerX_title" which points to the zero padded timer title.
Now, one important thing about the timers. If you do STA $4020 followed by STA $4030 it'll report 0 cycles, so the STA cycles don't count. But it also subtracts 4 cycles from all running counters when nested timers are used. For example:
Code: Select all
; this code will report 0 cycles for both timers!
sta $4020
sta $4021
sta $4030
sta $4031
Code: Select all
.macro start_timer timer
sta $4020+timer
.endmacro
.macro stop_timer timer
sta $4030+timer
.endmacro
.macro timer_title timer, title
.ident(.sprintf("__timer%d_title", timer)):
.byte title, 0
.endmacro
This feature allows you to do "printf" style debugging from your applications. It works like this: when the emulator detects a write to $4040, it reads a string from PC+3 and outputs it in the debug window. This feature can thus be used from any assembler. Some simple number formatting is also supported.
Some helper macros for CA65:
Code: Select all
.macro debugOut str
.local over
sta $4040
jmp over
.byte str, 0
over:
.endmacro
.define fHex8( addr ) 1, 0, <(addr), >(addr)
.define fDec8( addr ) 1, 1, <(addr), >(addr)
.define fHex16( addr ) 1, 2, <(addr), >(addr)
.define fDec16( addr ) 1, 3, <(addr), >(addr)
Code: Select all
.zeropage
some_var: .res 2
other_var: .res 1
.code
entry:
lda #$34
sta some_var
lda #$12
sta some_var+1
debugOut {"entry point reached, some_var = ", fHex16{some_var}, ", isn't that exciting?"}
lda #123
sta other_var
debugOut {"other var is ", fDec8{other_var}, " in decimal"}
Code: Select all
#define DEBUG_OUT( str ) \
do { \
( ( void __fastcall__ ( * )( void ) )"\x8D\x40\x40\x60\xEA\xEA" str )(); \
} while ( 0 )
Code: Select all
DEBUG_OUT( "Testing NintendulatorDX debug output from CC65!" );
How to use the .proc/.scope profiling feature
This feature allows you to find out how many cycles each .proc/.scope is taking in your program. It works by keeping count of number of cycles taken by each value of the PC register, and writes out the results in a file named "<romname>.nes.profiling.txt" when the ROM is unloaded.
Write to $4041 to start collecting profiling data, and $4042 to stop. You don't have to write to $4042 if you want the data collecting to end when the ROM is unloaded. If you simply want to collect data for the entire run of the program, write to $4041 somewhere in your reset routine.
Currently the feature does NOT support banking, so if you use banked ROMs with it you will get erroneous results.
The results are something like this:
Code: Select all
[module general.o]: 4328012 (91.6 %)
init: 89352 (2.06 %)
detectSystem: 60556 (1.4 %)
initVariables: 44 (0.00102 %)
reset: 2771377 (64 %)
setPalette: 24 (0.000555 %)
updateControllerState: 4903 (0.113 %)
nmi: 1401756 (32.4 %)
irq: 0 (0 %)
Downloads
Emulator + mappers (Unicode, Win2K/XP/Vista/7): http://kkfos.aspekt.fi/downloads/ninten ... x-0.33.zip
I have included a compatible version of the CC65 snapshot in the above package.
That should be all for now.
EDIT: Now supports bankswitching, updated download links.
EDIT: Added the screenshot as an image instead of link
EDIT 2011-01-05: Added some features, updated link to v0.20.
EDIT 2011-02-04: Added a note below CC65 snapshot link
EDIT 2011-02-26: Pulled latest version of Nintendulator from SourceForge SVN and applied the updates, the new version includes timer support, download link updated
EDIT 2011-03-27: Updated to version 0.26, shows init and play cycles for NSF, some bugs fixed
EDIT 2011-07-06: Version 0.27
EDIT 2011-08-03: Version 0.28. Preliminary support for debug messages. Sources added to the package.
EDIT 2011-09-12: Version 0.33. Includes proc/scope profiling support.
EDIT 2012-03-23: Added an example of using the debug output feature from C code.[/size]