TITLE "MP4 by Douglas Jones" ; displays a fractal on the screen ; this version is deliberately not very optimized USE "hawk.h" USE "monitor.h" SUBTITLE "Plot routine" ; direction encodings (these are arbitrary, so values are rather stupid) LL = 3 ; omit the lower left LR = 7 ; omit the lower right UL = 19 ; omit the upper left UR = 27 ; omit the upper right ; activation record ;RETAD = 0 SIZE = 4 ; size of figure (a power of 2) X = 8 ; x coordinate of figure Y = 12 ; y coordinate of figure DIR = 16 ; direction figure faces ARSIZE = 20 PLOT: ; given R3: size (2 to the order) ; R4: x -- coordinates of center ; R5: y ; R6: direction STORES R1,R2 STORE R3,R2,SIZE STORE R4,R2,X STORE R5,R2,Y STORE R6,R2,DIR CMPI R3,1 ; -- note size is still in R3 BGT PLOTBIG ; if size <= 1 { -- basis case MOVE R3,R4 ; -- note x is still in R4 to here ADDSI R3,-1 ; parameter x-1 MOVE R4,R5 ; parameter y ADDI R2,R2,ARSIZE LIL R1,PUTAT ; putat( x-1, y ) JSRS R1,R1 LIS R3,'[' LIL R1,PUTCHAR JSRS R1,R1 ; putchar( '[' ) LIS R3,']' LIL R1,PUTCHAR JSRS R1,R1 ; putchar( ']' ) ADDI R2,R2,-ARSIZE BR PLOTDONE PLOTBIG: ; } else { -- recursive case LOAD R3,R2,SIZE SR R3,1 STORE R3,R2,SIZE ; size = size/2 LOAD R4,R2,DIR CMPI R4,LL BEQ PLOTX2 ; if (dir != LL) { -- plot lower left ; -- parameter size is already in place LOAD R4,R2,X SUB R4,R4,R3 ; -- parameter x-size LOAD R5,R2,Y ADDI R6,R3,1 SR R6,1 ADD R5,R5,R6 ; -- parameter y+(size+1)/2 LIS R6,UR ; -- parameter dir ADDI R2,R2,ARSIZE JSR R1,PLOT ; plot( size, x-size, y+(size+1)/2, UR ) ADDI R2,R2,-ARSIZE PLOTX2: ; } LOAD R4,R2,DIR CMPI R4,LR BEQ PLOTX3 ; if (dir != LR) { -- plot lower right LOAD R3,R2,SIZE ; -- parameter size LOAD R4,R2,X ADD R4,R4,R3 ; -- parameter x+size LOAD R5,R2,Y ADDI R6,R3,1 SR R6,1 ADD R5,R5,R6 ; -- parameter y+(size+1)/2 LIS R6,UL ; -- parameter dir ADDI R2,R2,ARSIZE JSR R1,PLOT ; plot( size, x+size, y+size/2, UL ) ADDI R2,R2,-ARSIZE PLOTX3: ; } LOAD R4,R2,DIR CMPI R4,UR BEQ PLOTX0 ; if (dir != UR) { -- plot upper right LOAD R3,R2,SIZE ; -- parameter size LOAD R4,R2,X ADD R4,R4,R3 ; -- parameter x+size LOAD R5,R2,Y MOVE R6,R3 SR R6,1 SUB R5,R5,R6 ; -- parameter y-size/2 LIS R6,LL ; -- parameter dir ADDI R2,R2,ARSIZE JSR R1,PLOT ; plot( size, x+size, y-size/2 , LL ) ADDI R2,R2,-ARSIZE PLOTX0: ; } LOAD R4,R2,DIR CMPI R4,UL BEQ PLOTX1 ; if (dir != UL) { -- plot upper left LOAD R3,R2,SIZE ; -- parameter size LOAD R4,R2,X SUB R4,R4,R3 ; -- parameter x-size LOAD R5,R2,Y MOVE R6,R3 SR R6,1 SUB R5,R5,R6 ; -- parameter y-size/2 LIS R6,LR ; -- parameter dir ADDI R2,R2,ARSIZE JSR R1,PLOT ; plot( size, x-size, y-size/2 , LR ) ADDI R2,R2,-ARSIZE PLOTX1: ; } PLOTDONE: ; } LOADS R1,R2 JUMPS R1 ; return SUBTITLE "Main program" INT MAIN S MAIN ; activation record structure ;RETAD = 0 ARSIZE = 4 MAIN: ; given R3: width of display area ; R4: height of display area STORES R1,R2 MOVE R5,R4 ; -- move height to R5 (needed there later) MOVE R4,R3 ; -- move width to R4 (needed there later) MOVE R6,R4 SR R6,1 ; limit = width/2 CMP R6,R5 BLE MAIBIG ; if (limit > height) { MOVE R6,R5 ; limit = height MAIBIG: ; } LIS R3,1 ; size = 1 -- an initial guess MAILP: ; do { -- find largest power of 2 <= limit SR R6,1 ; limit = limit/2 BZS MAIDON ; if (limit == 0) break SL R3,1 ; size = size*2 BR MAILP MAIDON: ; } ; -- parameter size (computed in R3) SR R4,1 ; -- parameter width/2 SR R5,1 ADDSI R5,-1 ; -- parameter height/2-1 LIS R6,UR ; -- parameter dir ADDI R2,R2,ARSIZE JSR R1,PLOT ; plot( order, width/2, height/2-1, UR ) ADDI R2,R2,-ARSIZE LOADS R1,R2 JUMPS R1 ; return END