Just because you can doesn't mean you should.... (famous last words!)
So I thought just because... I'll do it in Sweet16... Naively thinking it might be smaller than some of the 6502 asm versions here, however, at $54 or decimal 84 bytes, then sadly no. Much is taken up by switching into and out of sweet16 mode, also given that sweet16 doesn't have any logical operators (e.g. shift) then my standard (terminal width - stars) / 2 calculation to get the leading spaces was going to be tricky, and I couldn't be bothered being clever, so I implemented a 2nd table.
The output is as it ought to be:
Code:
* load tree 8000
* go
Starting program at $8000 (Emulation)
*
***
*****
*******
***
*******
***********
***************
*****
***********
*****************
***********************
***
***
The source code... OK, here it is....
Code:
; runTree.s:
;********************************************************************************
.include "sw16.h"
.include "sw16regs.h"
.include "runTree.h"
.include "osVectors.h"
.proc runTree
goSweet16
set r12,$0100 ; Sweet16 stack pointer
set r2,1 ; Constant 1
set r3,40 ; Constant 40 - width / 2
set r8,treeData ; Address of the tree data table
set r9,spaceData ; Address of the tree branch spaces
loop:
ld @r9 ; Loads and increments r9
bz done ; Reached the end
set r7,' ' ; r7 has character to print
bs printIt
ld @r8 ; Loads and increments r8
set r7,'*'
bs printIt
; Newline
rtn ; Back to 6502 land
.setcpu "65c02"
jsr osNewl
jsr _sweet16 ; Back to sweet16 land
.setcpu "sweet16"
br loop
; printIt:
; Print Acc's worth of r7's...
printIt:
rtn ; Back to 6502 land
.setcpu "65c02"
lda r7l ; r7l has character to print
jsr osWrch
jsr _sweet16 ; Back to sweet16 land
.setcpu "sweet16"
sub r2 ; Subtract r1 (1) from Acc
bnz printIt
rs ; Return from subroutine
done:
exSweet16
rts
.endproc
; treeData:
;********************************************************************************
treeData:
.byte 1,3,5,7, 3,7,11,15, 5,11,17,23, 3,3
spaceData:
.byte 39,38,37,36,38,36,34,32,37,34,31,28,38,38,0
So if anyone ever wanted to know what sweet16 looks like then there you are
Oh, small confession, actually the whole thing is rather longer as my Ruby 816 OS no-longer has Sweet16 as a part of it (the 6502 version still has, but I'm running this on my '816 board), so I had to include the sweet16 code too (my version which can be assembled anywhere), as well as the standard code header I use (to make it an Acorn compatible ROM. That takes it to
Code:
-rw-rw-r-- 1 gordon gordon 782 Dec 22 20:21 tree
So, 782 bytes in total... But then I could also include the Ruby 816 OS, but where would you stop...
Cheers,
-Gordon
_________________
--
Gordon Henderson.
See my
Ruby 6502 and 65816 SBC projects here:
https://projects.drogon.net/ruby/