2015-02-18 02:26:26 +00:00
|
|
|
# assembler6502
|
2015-02-18 03:05:37 +00:00
|
|
|
|
2015-02-19 02:40:00 +00:00
|
|
|
An NES assembler for the 6502 microprocessor written in Ruby
|
2015-02-18 03:05:37 +00:00
|
|
|
|
|
|
|
Usage: ./assembler\_6502.rb <infile.asm> -o outfile.nes
|
|
|
|
|
|
|
|
This is a pretty straightfoward assembler, that is currently set up
|
|
|
|
to produce iNES ROM formatted binaries from simple assembly listings.
|
|
|
|
It is good at knowing which addressing modes are and are not allowed for
|
|
|
|
each instruction, and contains some examples of correct syntax.
|
|
|
|
|
|
|
|
Parsing is done by Regular Expression, because, well the language is
|
|
|
|
so regular, it actually took less time than anything else I've tried
|
|
|
|
to parse in the past, including Scheme using parsec.
|
|
|
|
|
|
|
|
It handles labels, and does a two pass assembly, first assembling
|
|
|
|
the byte codes, and then going back and filling in the proper addresses
|
|
|
|
where labels were used.
|
|
|
|
|
|
|
|
I have used this to compile some code for the NES, and it ran correctly
|
2015-02-19 02:40:00 +00:00
|
|
|
on FCEUX, got it to make some sounds, load tiles, sprites, and scrolling.
|
2015-02-18 03:05:37 +00:00
|
|
|
|
2015-02-19 02:44:17 +00:00
|
|
|
![Scrolling NES Demo](assembler_demo.png)
|
|
|
|
|
2015-02-18 03:05:37 +00:00
|
|
|
Some Todos:
|
|
|
|
- I may make this into a Rubygem
|
|
|
|
- Maybe I can put some better error messages.
|
2015-02-19 02:40:00 +00:00
|
|
|
- Should I also make a 6502 Emulator in Ruby?
|
2015-02-18 12:05:00 +00:00
|
|
|
|
|
|
|
Some new additions:
|
2015-02-19 02:40:00 +00:00
|
|
|
- Ported NES101 tutor to this assembler.
|
|
|
|
- Added msb and lsb byte selectors on address labels
|
2015-02-18 12:05:00 +00:00
|
|
|
- added .org directive
|
|
|
|
- added .dw directive
|
|
|
|
- added .bytes directive
|
|
|
|
- added .incbin directive
|
2015-02-19 02:40:00 +00:00
|
|
|
- added .ascii directive
|
2015-02-18 12:05:00 +00:00
|
|
|
- Invented my own iNES header directive that is JSON
|
|
|
|
- Split the project up into separate files per class
|
|
|
|
- Wrote some more unit tests
|
|
|
|
- Added OptionParser for commandline opts
|
|
|
|
- Tested a ROM with Sound output
|
|
|
|
- Tested a ROM that changes background color
|
|
|
|
|
|
|
|
I decided that during the first pass of assembly, I should just initialize
|
|
|
|
an entire 65535 byte virtual memory images, and write the instructions to
|
|
|
|
their correct places, and then after resolving symbols during the second pass,
|
|
|
|
I just clip out the Cartridge ROM area and iNES header at the end, works great
|
|
|
|
so far.
|
|
|
|
|