TITLE "mp3.a solved by Douglas Jones" S START USE "hawk.macs" USE "monitor.h" COMMON STACK,#1000 PSTACK: W STACK ; ----------------- linkage ------------------ ; these lines provide a link to the data structures from mp1 EXT ITEM1 PITEM1: W ITEM1 ; these lines provide a link to the code in mp3test.o EXT PLOTROW EXT PLOTSTR PPLOTROW: W PLOTROW PPLOTSTR: W PLOTSTR ; -------- the structure of one item --------- NEXT = 0 ; pointer to next item in list X = 4 ; X coordinate of this item Y = 8 ; Y coordinate of this item WIDTH = 12 ; width of this item HEIGHT = 16 ; height of this item TEXT = 20 ; pointer to text of this item or null NULL = 0 ; value of null pointers SUBTITLE "main program" ; -------------------------------------------- START: LOAD R2,PSTACK ; set up the stack LOAD R1,PDSPINI JSRS R1,R1 ; initialize the display LOAD R8,PITEM1 ; p = pitem1, points to start of list MAINLP: ; for (;;) { TESTR R8 BZS MAINQ ; if (p == NULL) exit MOVE R3,R8 ; parameter p JSR R1,SHOWITEM ; call showitem( p ) LOADS R8,R8 ; p = p->next BR MAINLP ; } MAINQ: LOAD R1,PEXIT JSRS R1,R1 ; call monitor routine to stop! SUBTITLE "showitem" ; -------------------------------------------- RETAD = 0 R8SAVE = 4 R9SAVE = 8 RASAVE = 12 ARSIZE = 16 SHOWITEM: ; expects R3 = item pointer STORES R1,R2 STORE R8,R2,R8SAVE MOVE R8,R3 ; R8 = item pointer in SHOWITEM body LOAD R9,R8,HEIGHT ; R9 = rows = item.height LOAD R10,R8,Y ; R10 = y = item.y LOAD R3,R8,X ; -- parameter x = item.x MOVE R4,R10 ; -- parameter y = y LOAD R5,R8,WIDTH ; -- parameter w = item.width LIS R6,'+' ; -- parameter = '+' LIS R7,'-' ; -- parameter = '-' ADDI R2,R2,ARSIZE LOAD R1,PPLOTROW JSRS R1,R1 ; plotrow( x, y, w,'+','-') ADDI R2,R2,-ARSIZE TESTR R9 BLE SHOWITEMENDIF ; if (rows > 0) { SHOWITEMLP: CMPI R9,1 BLE SHOWITEMENDLP ; while (rows > 1) { ADDSI R10,1 ; y = y + 1 ADDSI R9,-1 ; rows = rows - 1 LOAD R3,R8,X ; -- parameter x = item.x MOVE R4,R10 ; -- parameter y = y LOAD R5,R8,WIDTH ; -- parameter w = item.width LIS R6,'|' ; -- parameter = '|' LIS R7,' ' ; -- parameter = ' ' ADDI R2,R2,ARSIZE LOAD R1,PPLOTROW JSRS R1,R1 ; plotrow( x, y, w,'|',' ') ADDI R2,R2,-ARSIZE BR SHOWITEMLP ; } SHOWITEMENDLP: ADDSI R10,1 ; y = y + 1 LOAD R3,R8,X ; -- parameter x = item.x MOVE R4,R10 ; -- parameter y = y LOAD R5,R8,WIDTH ; -- parameter w = item.width LIS R6,'+' ; -- parameter = '+' LIS R7,'-' ; -- parameter = '-' ADDI R2,R2,ARSIZE LOAD R1,PPLOTROW JSRS R1,R1 ; plotrow( x, y, w,'+','-') ADDI R2,R2,-ARSIZE SHOWITEMENDIF: ; } LOADCC R3,R8,TEXT BZS SHOWITEMBLANK ; if (item.text != NULL) { LOAD R3,R8,X ADDI R3,R3,2 ; -- parameter x = item.x + 2 LOAD R4,R8,Y ADDI R4,R4,1 ; -- parameter y = item.y + 1 LOAD R5,R8,TEXT ; -- parameter ADDI R2,R2,ARSIZE LOAD R1,PPLOTSTR JSRS R1,R1 ; call plotstr( x, y, text ) ADDI R2,R2,-ARSIZE SHOWITEMBLANK: ; } LOAD R8,R2,R8SAVE LOAD R9,R2,R9SAVE LOAD R10,R2,RASAVE LOADS R1,R2 JUMPS R1 ; return END