====== Dragon Basic Inline Assembler ====== This utility (GTAsm) is intended for developing small 6809 machine language routines that enhance programs written mostly in Dragon Basic, for example a routine to scroll the graphics screen. The assembly source code is written in Basic comment statements. This documentation assumes a good working knowledge of the 6809 and the Dragon 32. [[https://6809.uk/cas/GTAsm.cas|Download GTAsm Inline Basic Assembler]] (as a .cas file for the Dragon 32 - get the [[https://www.6809.org.uk/xroar/|XRoar Emulator]]) ==== Reserving Memory ==== With any small micro with limited RAM there's a big problem: the source code, executable program, and the assembler program itself all have to occupy memory at the same time. As well as the limitation on total space, the executable and the assembler might want to occupy the same address space at the same time. GTAsm deals with this problem by loading itself into the graphics pages by default; the assembled code can then freely use the high memory area. Obviously this means the assembler will be corrupted and have to be reloaded every time graphics are drawn. To avoid this, reserve extra pages with PCLEAR and load the assembler in these, or load it into the reserved high memory area. The assembler's workspace (for calculating labels etc.) is limited by the end of the graphics pages, or the top of RAM (&H8000) as appropriate. A typical starter program might look like this: 10 PCLEAR7:CLEAR200,&H6FFF 500 'ORG$7000:CONST TXBASE=$0400,TXEND=$0600,BLANK=$F6:ON 510 'DEFUSR1:@CLRSCR LDX#TXBASE:LDA#BLANK 520 '@LOOP STA,X+:CMPX#TXEND:BLO LOOP 530 'RTS 540 'END The PCLEAR statement clears an extra 3 graphics pages, or 4.5K of RAM. This should be enough for short routines, and leaves the first 4 pages untouched so hi-res modes (PMODE3,1 etc.) work as normal. The CLEAR statement sets the last byte of Basic RAM, so our machine code program can start at &H7000. Run the Basic program. Now load GTAsm and execute it with: CLOADM EXEC That's if we're happy for the assembler to sit in graphics pages 1 to 3 and don't want to bother with offsets. The assembler can be loaded anywhere in RAM as long as it starts at a page boundary; the entry point is &H0900 bytes after the start of the code. To load the assembler with an offset to start at graphics page 5: CLOADM "ASMB0600",&H1800 EXEC &H2700 A trace of addresses and assembled machine code should be listed to screen. If there are no errors, run the assembled routine with: EXEC &H7000 Or, since we used the DEFUSR1 directive: A=USR01(0) EXEC remembers its last address, so as long as we don't use it (or DEFUSR0) for something else we can type plain EXEC to re-run the assembler. ==== Writing a Program ==== GTAsm expects assembly language mnemonics and directives to be written in BASIC comments beginning with the single quote symbol. Use upper-case only, except for string constants. Multiple instructions on one line are separated by colons. Editing is done as per usual for lines of Basic. === Mnemonics === All standard 6809 assembler mnemonics are available, with one exception: TFR (use TRF instead - this is a simple error) === Addressing === Use standard brackets rather than square to specify indirect addressing. Use the "<" and ">" symbols to force 8 and 16 bit offsets respectively. JSR (,X++) call subroutine at address stored at X, then point to the next address in the list LDA (CURSPOS) load A from the address stored at CURSPOS LDB >$0034 load B from $0034 using extended mode rather than direct CLR set the program origin ORG $7C00 ON switch on trace output ON OFF switch off trace output OFF DEFUSR [0..9] define Basic USR entry point DEFUSR1 CONST