6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sat Nov 23, 2024 1:48 am

All times are UTC




Post new topic Reply to topic  [ 9 posts ] 
Author Message
 Post subject: 65C02 Disassembler
PostPosted: Wed Jul 13, 2016 3:15 am 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
Well, sad to say but any real progress has been slow this year towards doing any coding, since I came out of retirement in January. Since my C02Monitor was posted here, I did manage to shrink it quite a bit and add some function. End result was a total of 3KB for the monitor which also required a BIOS, which takes less than 768 bytes. So in all, 4KB at the top of memory holds the core monitor, BIOS and I/O page. That was where I left off.

I recently had a few restless nights and started on a disassembler that handles every opcode and addressing mode of the W65C02S per the datasheet. While not exactly anything revolutionary or new, I did write one which is relatively small, but also uses 65C02 opcodes to build it. It's table driven but I managed to keep the data size fairly small: 256 bytes for the Opcode table (points to the Mnemonic data), 128 bytes for address mode handlers (4-bits per handler, upper nibble holds odd opcode handler pointers, lower nibble holds even opcode handler pointers) and another 32 bytes for the handler address pointers. On top of this another 142 bytes for the Mnemonic data, compressed so each Mnemonic can be printed with two bytes (an old technique for sure). In all, to handle all possible addressing modes and all opcodes, 558 bytes of data. The executable code is 406 bytes but does utilize the C02Monitor and C02BIOS for core functions.

Since working on this as an app for the C02Monitor, I never had to write anything to an EEPROM, just used the Xmodem Loader which automagically handles S-record data generated by the WDC toolset. Now that it's working, I integrated it into C02Monitor code, which is now another 1KB in size... adding the Disasssembler to the Query command, an intro message and command sequence to invoke it. So far I'm pretty happy with it, and even handles the BRK opcode as a two byte instruction, showing the following byte after the BRK opcode. It may not be fully optimized for size yet, but I'll spend some additional sleepless nights going over the code at some point. As for a matching assembler, I've not yet given it any thought, as I find it pretty quick and painless to write code in a Windows VM and download it to the board via Xmodem.

Happy to post the source should anyone care to check it out. Could probably use a tad of cleanup however.

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
 Post subject: Re: 65C02 Disassembler
PostPosted: Wed Jul 13, 2016 6:27 am 
Offline

Joined: Sun Jun 29, 2014 5:42 am
Posts: 352
floobydust wrote:
Happy to post the source should anyone care to check it out. Could probably use a tad of cleanup however.

I'm very interested in seeing any compact disassembler implementations.

Slight topic drift, but....

I had fun squeezing 6502/Z80/6809 disassemblers into a DIY Multi-Platform In-Circuit Emulator I was working on last year.

The environment is bit different from yours, as it's all implemented in a small FPGA (on a GODIL):
Attachment:
GODIL48-250-byy-4C_t1.jpg
GODIL48-250-byy-4C_t1.jpg [ 62.59 KiB | Viewed 1631 times ]

The FPGA contains the target processor, plus a second supervisory AVR8 soft core. This simply replaces the target processor, and you talk to it over a serial link.

The code for the ICE was all written in C, rather than assembler, and runs on the AVR soft core in the FPGA, using FPGA block RAM as program memory. The total available program memory was 9Kx16.

The various disassemblers (all from existing open source projects) are here:
https://github.com/hoglet67/AtomBusMon/ ... /dis6502.c
https://github.com/hoglet67/AtomBusMon/ ... /dis6809.c
https://github.com/hoglet67/AtomBusMon/ ... e/disz80.c

and the supervisor core is here:
https://github.com/hoglet67/AtomBusMon/ ... omBusMon.c

The name (AtomBusMon) is largely historic - it's morphed from the humble originals of being a 6502 single-stepper for the Acorn Atom, to being a full-featured multiple-platform ICE.

I have promised Ed that I'll do some more documentation on this project, in the form of a github wiki.

Dave


Top
 Profile  
Reply with quote  
 Post subject: Re: 65C02 Disassembler
PostPosted: Wed Jul 13, 2016 8:37 am 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
Dave,
Interesting project no doubt. I've attached the disassembler source here for anyone to view. Note that it does require the C02Monitor and C02BIOS to work. With a little extra work, it should run on another monitor setup.

Attachment:
C02_Disassembler.asm [30.71 KiB]
Downloaded 133 times

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
 Post subject: Re: 65C02 Disassembler
PostPosted: Wed Jul 13, 2016 8:49 am 
Offline

Joined: Sun Jun 29, 2014 5:42 am
Posts: 352
Hi KM,
floobydust wrote:
Interesting project no doubt.

Apologies, I didn't mean to divert attention from your project.
floobydust wrote:
I've attached the disassembler source here for anyone to view. Note that it does require the C02Monitor and C02BIOS to work. With a little extra work, it should run on another monitor setup.

Thanks for posting this. It's very helpful to see the techniques used to compress the mnemonic and opcode data.

Would you mind if I borrowed some of your data structures to try to reduce the code size of the 6502 disassembler I'm using?

Dave


Top
 Profile  
Reply with quote  
 Post subject: Re: 65C02 Disassembler
PostPosted: Wed Jul 13, 2016 8:57 am 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
Dave,
No problem on using the data structure and routines, I think the old VicMon (and other monitor programs) used the same basic technique to compress Mnemonic data, but I put all of the data together based on how I wanted to represent it. Same goes for the handler table which is half the size of a normal table. There's a bit of extra coding required but the savings in table data more than compensates for it.

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
 Post subject: Re: 65C02 Disassembler
PostPosted: Wed Jul 13, 2016 5:17 pm 
Offline
User avatar

Joined: Thu May 28, 2009 9:46 pm
Posts: 8507
Location: Midwestern USA
floobydust wrote:
I think the old VicMon (and other monitor programs) used the same basic technique to compress Mnemonic data...

The use of the 3:2 mnemonic encoding technique in Commodore M/L monitors has been credited to Jim Butterfield, who was the author of Supermon for the PET/CBM computers. Supermon was the basis of VICMon, as well as the monitor in the C-128. I got a lot of use out of Supermon 64 back in the day, as it was indispensable in developing Commodore 64 M/L programs.

_________________
x86?  We ain't got no x86.  We don't NEED no stinking x86!


Top
 Profile  
Reply with quote  
 Post subject: Re: 65C02 Disassembler
PostPosted: Wed Jul 13, 2016 7:16 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
BigDumbDinosaur wrote:
floobydust wrote:
I think the old VicMon (and other monitor programs) used the same basic technique to compress Mnemonic data...

The use of the 3:2 mnemonic encoding technique in Commodore M/L monitors has been credited to Jim Butterfield, who was the author of Supermon for the PET/CBM computers. Supermon was the basis of VICMon, as well as the monitor in the C-128. I got a lot of use out of Supermon 64 back in the day, as it was indispensable in developing Commodore 64 M/L programs.


I believe you are correct on that. Jim Butterfield was also a frequent contributor to Compute Magazine and IIRC Gazette later on. I don't recall anyone compressing the handler table to half size however, so perhaps I'm a first on that one... but somehow I doubt it as it seems too logical not to do. I too made good use of the C64 monitor that was part of the their macro assembler development package. Back then using the C64 and a 1541 disk drive, assembling my 4KB DOS shell took over 20 minutes. On a Win7 VM, it's less than 2 seconds for an 8KB assembly.

In any case, my goal was a full W65C02 disassembler in under 1KB and I was able to manage it with a fair amount of space to spare. I also decreased the page zero usage in the C02Monitor/BIOS by quite a bit as well. It just takes time constantly going through the code looking for ways to decrease usage... at least it takes me a fair amount of time ;-)

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
 Post subject: Re: 65C02 Disassembler
PostPosted: Wed Jul 13, 2016 8:17 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
As noted previously by Mike (barrym95838) the Apple II monitor's List command also packs three characters into two bytes. See
https://github.com/cmosher01/Apple-II-S ... asm.m4#L80

(I would think that would have to be earlier)


Top
 Profile  
Reply with quote  
 Post subject: Re: 65C02 Disassembler
PostPosted: Wed Jul 13, 2016 10:33 pm 
Offline
User avatar

Joined: Sun Jun 30, 2013 10:26 pm
Posts: 1949
Location: Sacramento, CA, USA
Woz was a highly prolific 6502 coder in 1976 and 1977. During that time, he wrote WozMon, the Apple 2 monitor (which included the dis-assembler), Integer BASIC, the mini-assembler, the hi-res Apple 2 graphics routines, the 32-bit floating point mini-library, and the Apple 2 floppy disk software interface. Most (if not all of the 1976 stuff) was hand-assembled by Woz himself.

Mike B.

P.S. oh ... and SWEET-16!


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 9 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 44 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: