TITLE "recur.txt, a recursive program" ; plots a centered line of x marks 1/2 the width ; in the center of the screen, to divide the screen ; then subdivides each half screen recursively ; using lines half as long so you get something like ; this: ;----------------; ; xx ; ; xxxx ; ; xx ; ; xxxxxxxx ; ; xx ; ; xxxx ; ; xx ; ;----------------; ; this version is not systematically optimized S START USE "hawk.macs" USE "monitor.h" EXT UNUSED SUBTITLE "main program" ; the program starts here! START: LIL R2,UNUSED ; set up the stack ; --- begin aplication code LIL R1,DSPINI JSRS R1,R1 ; initialize the display ; R3=width, R4=height MOVE R5,R3 SR R5,1 MOVE R6,R5 ; --- compute width/2 ADDSI R4,-1 LIS R3,0 JSR R1,LINE ; line(0,height-1,width/2,width/2) LIL R1,EXIT JSRS R1,R1 ; stop! SUBTITLE "recursive subroutine" ; the line routine activation record RETAD = 0 BOT = 4 ; parameter TOP = 8 ; parameter WID = 12 ; parameter CENT = 16 ; parameter MID = 20 ; midpoint of top, bot QUART = 24 ; half of wid ARSIZE = 28 LINE: ; called by standard calling sequence ; expects R3: bot, bottom of window ; expects R4: top, top of window ; expects R5: wid, width of window ; expects R6: cent, centerline of window STORE R1,R2,RETAD STORE R3,R2,BOT STORE R4,R2,TOP STORE R5,R2,WID STORE R6,R2,CENT ADD R3,R3,R4 SR R3,1 STORE R3,R2,MID ; mid = (bot + top)/2 SR R5,1 STORE R5,R2,QUART ; quart = wid/2 SUB R3,R6,R5 ; -- compute cent-quart LOAD R4,R2,MID ADDI R2,R2,ARSIZE LIL R1,DSPAT JSRS R1,R1 ; dspat(cent-quart,mid) ADDI R2,R2,-ARSIZE LOOP: ; do { LIS R3,'x' ADDI R2,R2,ARSIZE LIL R1,DSPCH JSRS R1,R1 ; dspch('x') ADDI R2,R2,-ARSIZE LOAD R3,R2,WID ADDSI R3,-1 STORE R3,R2,WID ; wid = wid-1 BGT LOOP ; } while (wid > 0) LOAD R3,R2,BOT LOAD R4,R2,MID CMP R3,R4 BGE NORECUR ; if (bot < mid) { LOAD R3,R2,BOT LOAD R4,R2,MID ADDSI R4,-1 ; -- mid-1 LOAD R5,R2,QUART LOAD R6,R2,CENT ADDI R2,R2,ARSIZE JSR R1,LINE ; line(bot,mid-1,quart,cent) ADDI R2,R2,-ARSIZE LOAD R3,R2,MID ADDSI R3,1 ; -- mid+1 LOAD R4,R2,TOP LOAD R5,R2,QUART LOAD R6,R2,CENT ADDI R2,R2,ARSIZE JSR R1,LINE ; line(mid+1,top,quart,cent) ADDI R2,R2,-ARSIZE NORECUR: ; } LOAD R1,R2,RETAD JUMPS R1 ; return END