; General purpose macro assembler/translator - predef file customises ; for any source and destination system. This example takes z80 code ; as source and generates C as output. ; Actually the way this works is that this file is used to generate ; a 'tacc' grammar file, and it is that file in turn which is run to do ; the actual assembly/translation. ; Incidentally the program which turns this into a tacc grammar is itself ; a tacc program... ; $strdef's are executed by the assembler ; A and B map to variables RA and RB $strdef X = "(A|B)" R\1 $end ; HL, DE, and BC are themselves $strdef XX = "(HL|DE|BC)" \1 $end $strdef XY = "(IX|IY)" \1 $end ; $1234 maps to 0x1234 $strdef WORD = "\$[0-9A-Fa-f][0-9A-Fa-f]?[0-9A-Fa-f]?[0-9A-Fa-f]?" strformat("0x%s", \1+1) $end ; $12 maps to 0x12 $strdef BYTE = "\$[0-9A-Fa-f][0-9A-Fa-f]?" strformat("0x%s", \1+1) $end ; $def's output their text to the output file $def ld (), mem[\XX] = \X; // \* $end $def ld ,() \X = mem[\XX]; // \* $end $def ld (), mem[\WORD] = \XX; // \* $end $def ld (+), mem[\XY+\XX] = \X; // \* $end $def rlca RA=(RA<<1)|((RA&0x80)>>7); // rlca RF=(RF&0xEC)|(RA&C_FLAG); // rotate left cyclic A $end ; ; Sample input: ; ld (ix+$02),a ; ld ($4eef),de ; ; Output: ; mem[IX+0x02] = RA; // ld (ix+$02),a ; mem[0x4eef] = DE; // ld ($4eef),de ;