What is 6502?
6502 is an older CPU running off an 8bit Assembly language, most commonly used in the 80s
It was soo common, even the Terminator was programmed on it!
Assembly in Computercraft what?!?!
The main reason I choose to emulate the 6502 language onto CC was that, well I really enjoy the language and
I wanted to challenge myself to see if I could even do it, with 14 days of continuous study and lots and lots of coding,
here we are!
What are the features of this program so far?
It is a fully functioning 6502 CPU, everything works to that of ~90% accuracy compared to the original, physical version.
Individual features - Multiline Execution, Assembler with label, variables and Decimal Coded Byte support, Syntax Interpreter and Graphical Execution, The entire 6502 Assembly OpCodes.
Memory Specs
The memory method I use utilizes the string.char library to store 1 byte per virtual emulated byte.
Memory - 64K
Stack - 256B
Screen memory - 792B (0200 to 0990, counting end and start indexes.)
Key input - $FF
Random generator - $FE
Each address of the memory is an index divisible by 16, as 16 bytes are used per index, the remainder of this number becomes the memory offset.
Bug Testing
As there are 148 different instruction modes in 6502, I am going to need some help testing if they all work the way they are intended,
if any bugs are found, please post about them below!
Download: pastebin get jEtwni5z 6502
Editor: pastebin get 4YdqE1zS editasm
Example that features key input RNG and screen rendering: pastebin get WxMivJq5 test.asm
P.S I'm also working on getting it working with any vanilla Lua IDE!
Special thanks to, SquidDev for help with the compiler!
Tutorials:
Spoiler
How to compile a program -First, edit a file and put some code in it, example:
lda #$15
loop:
tax
inx
txa
ldx #$00
cmp #$55
bne loop
If you wanted to run your program in Graphics mode, type this6502 -m 2
This will attach a render to your program that will render the screen
when memory within its position is updated, from 0200 to 0990 hex.
Format is as follows, in bytes starting at 0200: TextBack, Char (Where text is MSB and back is LSB and char is full Byte)
If you want to run your program without compiling it first type this
6502 -rn <name of="" file="">
This will compile your program to .tempasm and run it then delete it afterward.
To compile, run this command
6502 -c <name of="" file=""> <exported file="" name="">
This will compile your ASM into something the program runner can
understand.
Now to run your file put
6502 -r <compiled asm=""> (You can also include a -s to run the program step mode)
Screenshots:
Spoiler
http://imgur.com/a/l0Xij Program execution.
http://imgur.com/a/gst4B Branching.
http://imgur.com/a/IbCZK Registers and Bitwise instructions.
http://imgur.com/a/7Xv1R Ascii loading and Indirect instruction modes.
http://imgur.com/a/znpZL Interrupt returning.
http://imgur.com/a/rG6vn Subroutine jumping and returning.
http://imgur.com/a/GKjMZ Editor, with syntax highlighting.
http://imgur.com/a/aG7N3 Rendering to the Screen.
http://imgur.com/jv45ciW Disassembly.
http://imgur.com/a/QOVIX Compiled program.
Update 6/20/17
- Some changes in optimization have broken the screen renderer, I apologize that I didn't notice that sooner, it has been fixed.
- New experimental version (qJ4rjZ8Q, has an extra run mode that is slightly faster. Also, includes an ISP (Instructions Per Second) counter.
- Found a bug with the variable char conversion that made assigning a variable a char, effectively useless, fixed that.
- Added Decimal Flag support!
- Fixed some grammar issues on this page :P/>