TITLE "MP4 by Douglas Jones, post-order version" ; plots the subtrees first, then the branches joining them ; to plot a tree, passes the coordinates of the center of the tree USE "hawk.h" USE "stdio.h" INT MAIN S MAIN ; activation record for PLOTTREE ;RETAD = 0 SAVER8 = 4 SAVER9 = 8 SAVER10 = 12 ARSIZE = 20 PLOTTREE: ; expects R3 = size -- vertical size of this tree node ; R4 = x -- x coordinate of center ; R5 = y -- y coordinate of center STORES R1,R2 STORE R8,R2,SAVER8 STORE R9,R2,SAVER9 STORE R10,R2,SAVER10 ADDI R2,R2,ARSIZE MOVE R8,R3 ; -- move size into place MOVE R9,R4 ; -- move x into place MOVE R10,R5 ; -- move y into place TESTR R8 BZS PLOTQT ; if (size >= 1) { MOVE R3,R8 SR R3,1 ; -- parameter size/2 MOVE R4,R9 SUB R4,R4,R8 ; -- parameter x - size MOVE R5,R10 ADD R5,R5,R3 ; -- parameter y + size/2 JSR R1,PLOTTREE ; plottree( size/2, x-size, y+size/2 ) MOVE R3,R8 SR R3,1 ; -- parameter size/2 MOVE R4,R9 ADD R4,R4,R8 ; -- parameter x + size MOVE R5,R10 ADD R5,R5,R3 ; -- parameter y + size/2 JSR R1,PLOTTREE ; plottree( size/2, x+size, y+size/2 ) PLOTLP: ; do { -- output size rows of /\ MOVE R3,R9 SUB R3,R3,R8 ; -- parameter x - size MOVE R4,R10 ; -- parameter y LIL R1,PUTAT JSRS R1,R1 ; putat( x - size, y ) LIS R3,'/' ; -- parameter LIL R1,PUTCHAR JSRS R1,R1 ; putchar( '/' ) MOVE R3,R9 ADD R3,R3,R8 ADDSI R3,-1 ; -- parameter x + size - 1 MOVE R4,R10 ; -- parameter y LIL R1,PUTAT JSRS R1,R1 ; putat( x + size - 1, y - 1 ) LIS R3,'\' ; -- parameter LIL R1,PUTCHAR JSRS R1,R1 ; putchar( '\' ) ADDSI R10,-1 ; y = y - 1 -- move up ADDSI R8,-1 ; size = size - 1 BGT PLOTLP ; } while (size > 0) PLOTQT: ; } ADDI R2,R2,-ARSIZE LOAD R8,R2,SAVER8 LOAD R9,R2,SAVER9 LOAD R10,R2,SAVER10 LOADS PC,R2 ; activation record for MAIN ;RETAD = 0 ARSIZE = 4 MAIN: STORES R1,R2 ADDSI R2,ARSIZE LIL R3,TERMINFO LOAD R4,R3,TERMCOLS ; -- get termcols LOAD R5,R3,TERMROWS ; -- get termrows ; -- problem 1, what size fits? LIS R3,1 ; size = 1 ; here R3 = size ; -- size is always a power of 2 ; R4 = termcols ; R5 = termrows ; R6 = height then width SIZELP: ; for (;;) { MOVESL R6,R3,1 ADDSI R6,-1 ; height = 2*size - 1 CMP R5,R6 BLT SIZEQT ; if (termrows < height) break SL R6,1 ; width = 2*height CMP R4,R6 BLT SIZEQT ; if (termcols < width) break SL R3,1 ; size = size * 2 BR SIZELP SIZEQT: ; } ; -- we computed one size too large SRU R3,1 ; -- parameter size = size/2 SR R4,1 ; -- parameter x = termcols/2 SR R5,1 ; -- parameter y = termrows/2 - size + 1 JSR R1,PLOTTREE ; plottree( size, x, y ) ADDSI R2,-ARSIZE LOADS PC,R2 ; return END