ScreenWidth equ 80

*-----------------------------------------------------------------------------
*
* FLEX entry points
*
* Change OSBase to $C000 for 6809 FLEX
*
* Note: 6809 version is one byte bigger, leax 1,X instead of inx
*
OSBase equ $A000

WARMS equ OSBase+$D03 ; Return to FLEX
PUTCHR equ OSBase+$D18 ; Put Character
PCRLF equ OSBase+$D24 ; Print Carriage Return and Line Feed

*-----------------------------------------------------------------------------
*
* Encoded tree
*
Data
 fcb 1  *                *
 fcb 3  *               ***
 fcb 5  *              *****
 fcb 7  *             *******
 fcb 3  *               ***
 fcb 7  *             *******
 fcb 11 *           ***********
 fcb 15 *         ***************
 fcb 5  *              *****
 fcb 11 *           ***********
 fcb 17 *        *****************
 fcb 23 *     ***********************
 fcb 3  *               ***
 fcb 3  *               ***
 fcb 0  *

*-----------------------------------------------------------------------------
*
* Draw the tree
*
Tree
 ldx #Data ; Address the encoded tree

TreeLoop
 jsr PCRLF ; Print Carriage Return and Line Feed

 bsr EmitSpaces
 bsr EmitStars

 inx ; Address the next row

 tst ,X ; More rows?
 bne TreeLoop ; Yes

 jmp WARMS ; Return to FLEX

*-----------------------------------------------------------------------------
*
* Emit a run of spaces
*
* X = address of run information, high nybble is number of spaces
*
EmitSpaces
 ldaa #' '
 ldab #ScreenWidth
 subb ,X ; Number of spaces on the line

 lsrb ; Put half of them on the left

 bra DoRunRun

*-----------------------------------------------------------------------------
*
* Emit a run of stars
*
* X = address of run information, low nybble is number of stars divided by 2
*
EmitStars
 ldaa #'*'
 ldab ,X

* Fall through
* bra DoRunRun

*-----------------------------------------------------------------------------
*
* Emit a run of characters
*
* A = the character
* B = length of the run
*
DoRunRun
 jsr PUTCHR ; Put Character

 decb ; Finished with the run?
 bne DoRunRun ; No

 rts

 end Tree
