Flangy > Software Development > Crass
Crass is the start of a 6502 Cross Assembler written in Python. It lacks some important features (Zero Page mode, simple expressions), but can output object code that can be run in various C64 emulators.
By default crass.py looks for test.s and creates an output file bin.c64. This can be loaded into most C64 emulators. To run your program you need to then sys the starting address. (In the future it would be nice to support BASIC prefix code, for creating auto-loaders.)
Crass cheats at parsing assembly files by not doing any lexing. Instead it picks apart source lines using regular expressions. Each entry in the opcode table has a pattern for the mnemonic's arguments. This pattern is turned into a regex which is used to test for a single addressing mode of a single mnemonic.
When a mnemonic is encountered in a source file, the arguments are tested against each addressing mode for that mnemonic. If any of the regexes match, the line is compiled for that addressing mode. If not, the source line is in error. There is no ambiguity between addressing modes.
Sources: crass.zip
To compile files you need TASM65.TAB from the TASM cross assembler. You can get it from the shareware release of TASM. (At some point I'll write my own opcode table.)
This outputs some characters to the screen, first accessing video memory direction, then using a Kernal routine.
CHROUT: = $ffd2 screen: = 1024 .org $c000 ldy #0 lda #1 store: sta screen,y iny bne store ldx #$41 onechar: txa jsr CHROUT inx cpx #$5B bne onechar rts
The first loop pokes 256 A's to the start of screen memory. The second loop prints the alphabet at the current cursor position using the Kernal chrout routine. Note that the first loop uses screen codes, while the second uses ASCII. The Kernal routine translates ASCII to screen codes.
toolbox.py has a couple of support classes:
Indexed lets you iterate over the index and item. Python 2.3 will have a built-in function, enumerate, to do this. I use this to get source lines with line numbers.
MapList has a single function appenditem which adds an item to the list with the given key, or creates a new list with the given item. I use this to map opcodes to valid addressing modes.