d6502 - a compact 6502 disassembler in 100 lines of code

Post your FreeBASIC source, examples, tips and tricks here. Please don’t post code without including an explanation.
Post Reply
oog
Posts: 124
Joined: Jul 08, 2011 20:34

d6502 - a compact 6502 disassembler in 100 lines of code

Post by oog »

This is a compact disassembler for the 6502 CPU in just 100 lines of code (plus data tables for opcodes and rom image in separate include-files).

The program has a simple shell. Commands are typed in as single letter instructions. They are almost "TEDMON"- compatible. The address pointer is initially set to the RESET-vector from the ROM image file. A real 6502 CPU would start here after a reset.

There is a demo ROM image included, which starts at hex FE00 and is simply filled with all defined 6502 opcodes. You can simply press Enter to disassemble the next line of opcode.

Code: Select all

'd' [<ADDR>]: disassemble, '': disassemble next line, 'x': exit

.FE00  00        BRK
.FE01  01 12     ORA ($12,X)
.FE03  05 12     ORA $12
.FE05  06 12     ASL $12
.FE07  08        PHP
.FE08  09 12     ORA #$12
.FE0A  0A        ASL
.FE0B  0D 12 34  ORA $3412
.FE0E  0E 12 34  ASL $3412
.FE11  10 12     BPL $FE25
FE13
Some notes for the background of this project

I did build a 2 MByte RAM expansion board for a Microcontroller, that originally has just 2 kilobytes (ATMEGA 328 on an Arduino Nano board). I took the RAM chips from an old PC EDO DIMM module. The RAM expansion module works fine and needs just 12 portbits for the connection. However, it can't expand the internal RAM of the microcontroller - the necessary signals are not available outside of the microcontroller IC. The RAM is just available with special load and store functions via port pins.
So I use a 6502 CPU emulation, which has simulated native access to the external RAM module.

Image

edit: link to image.
Last edited by oog on Jun 12, 2017 9:53, edited 1 time in total.
oog
Posts: 124
Joined: Jul 08, 2011 20:34

Re: d6502 - a compact 6502 disassembler in 100 lines of code

Post by oog »

Upps, can not post code. Get this message:

403
Forbidden
Access to this resource on the server is denied!

edit: Download sourcecode here: http://proog.de/dl/d6502/dl_d6502.zip
srvaldez
Posts: 3379
Joined: Sep 25, 2005 21:54

Re: d6502 - a compact 6502 disassembler in 100 lines of code

Post by srvaldez »

nice :-)
oog
Posts: 124
Joined: Jul 08, 2011 20:34

Re: d6502 - a compact 6502 disassembler in 100 lines of code

Post by oog »

da6502 - a compact 6502 disassembler with assembler.


Added 6502 assembler to the code and renamed file to "da6502", "da" = disassembler / assembler.

To start the assembler, type the letter 'a' an a startaddress for the code.

Code: Select all

Example: a 1000
The assembler shell starts up. You see the actual address ($1000 in this example) and an input prompt next to it. You can directly type in your code. Every line of code will be assembled and checked immediately.
To stop assembling, just press enter in an empty line.

Example:

Code: Select all

	lda #$f0
	clc
	adc #20	; the decimal 20 will be converted into hex
	pha
	nop
			; press enter without any input to close the assembler shell
You can now disassemble your program by typing

Code: Select all

d 1000
New Download is here:

http://proog.de/dl/d6502/dl_da6502.zip

Have fun.
D.J.Peters
Posts: 8586
Joined: May 28, 2005 3:28
Contact:

Re: d6502 - a compact 6502 disassembler in 100 lines of code

Post by D.J.Peters »

Looks like you have some fun with this stuf :-)
From time to time I "play" with my Motorola IC's from the 70'
and yes my MC6801/2/3 disassembler assembler are written in FreeBASIC also.

Joshy
h4tt3n
Posts: 698
Joined: Oct 22, 2005 21:12
Location: Denmark

Re: d6502 - a compact 6502 disassembler in 100 lines of code

Post by h4tt3n »

Nice project :-)
StillLearning
Posts: 54
Joined: Aug 27, 2019 22:22

Re: d6502 - a compact 6502 disassembler in 100 lines of code

Post by StillLearning »

Where do you download this code now?
Post Reply