********************************
*                              *
* MENU SYSTEM SUBROUTINES      *
*                              *
*------------------------------*
*                              *
* CONTAINS:                    *
*                              *
*         MENDISP              *
*         MENLOAD              *
*         MENSAVE              *
*         OPTLOAD              *
*         OPTSAVE              *
*                              *
*------------------------------*
*                              *
* USES:                        *
*       MAC.FILIO              *
*       MAC.STRINGS            *
*       MIN.SUB.CMD            *
*       MIN.SUB.CONCAT         *
*                              *
********************************
*
********************************
*                              *
* VARIABLES                    *
*                              *
********************************
*
         JMP   ENDVARS    ; PUT AT TOP BECAUSE
                          ; OF NO FORWARD REF
]MRETURN DS    2
]MDATA   DS    2
]LCOUNT  DS    1
]LWIDTH  DS    1
]OWIDTH  DS    1
]CURRENT DS    2
]CUR2    DS    2
]TEMP    DS    2
]TEMP2   DS    2
]TEMP3   DS    2
]EXITKEY DS    1
]MARGIN  DS    1
]COPTIONS DS   255
]MTITLE  DS    80
ENDVARS
*
********************************
*                              *
* MENDISP -- DISPLAY MENU      *
*                              *
********************************
*
MENDISP
*
** GET PARAMETERS
*
         PLA
         STA   ]MRETURN
         PLA
         STA   ]MRETURN+1
         PLA
         STA   ]MDATA
         STA   ADDR4
         PLA
         STA   ]MDATA+1
         STA   ADDR4+1
*
** NOW GET MENU VARIABLES
*
         LDY   #0
         LDA   (ADDR4),Y  ; GET LCOUNT
         STA   ]LCOUNT
         INY
         LDA   (ADDR4),Y
         STA   ]LWIDTH    ; GET LABEL WIDTH
         INY
         LDA   (ADDR4),Y  ; GET OPTION WIDTH
         STA   ]OWIDTH
         INY
         LDA   (ADDR4),Y  ; GET EXIT KEY
         STA   ]EXITKEY
         INY
         LDA   (ADDR4),Y  ; GET MENU TITLE
         STA   ]MTITLE
         LDX   #0
:VLP
         INY
         INX
         LDA   (ADDR4),Y
                          ; INVERT THE TEXT
         CMP   #192       ; IS IT A LETTER?
         BCS   :LETTER
         SEC
         SBC   #128       ; NUMBER; INVERT ACCORDINGLY
         JMP   :ICONT
:LETTER
         SEC
         SBC   #192       ; INVERSION FOR LETTERS
:ICONT
         STA   ]MTITLE,X
         CPX   ]MTITLE
         BNE   :VLP
         INY
         STY   ]CURRENT
*
** NOW SET COORDINATES, ETC. BEFORE DISPLAY
*
         JSR   HOME       ; FOR NOW, MUST TAKE WHOLE SCREEN
*
** DISPLAY MENU TITLE
*
         LDA   ]MTITLE    ; FIND CENTER POSITION
         LSR              ; DIV BY 2
         STA   ]TEMP
         LDA   #19
         SEC
         SBC   ]TEMP
         STA   ]TEMP
         SCPOS ]TEMP;#0
         SPRN  #]MTITLE
*
** CALCULATE LEFT MARGIN
*
         LDA   #3
         STA   ]MARGIN    ; STATIC FOR NOW
*
** NOW DISPLAY LABELS
*
         LDA   #1
         STA   ]TEMP      ; FILES THROUGH MENU ITEMS
         LDA   ]MDATA+1
         STA   ]TEMP2+1
         LDA   ]CURRENT
         STA   ]CUR2
         CLC
         ADC   ]MDATA
         STA   ]TEMP2
         BCC   :LLP
         INC   ]TEMP2+1
:LLP
         LDA   ]TEMP
         CLC
         ADC   #1
         STA   ]TEMP3
         SCPOS ]MARGIN;]TEMP3
         SPRN  ]TEMP2
         CLC
         ADC   ]TEMP2     ; .A HOLDS STRING LENGTH
         STA   ]TEMP2
         INC   ]TEMP2
         INC   ]TEMP
         LDA   ]LCOUNT
         CMP   ]TEMP
         BCS   :LLP
         BEQ   :LLP
*
         LDA   ]TEMP2+1
         STA   ]CURRENT+1
         LDA   ]TEMP2
         STA   ]CURRENT
*
** NOW CREATE OPTION BACKGROUND HIGHLIGHT BOX
*
         LDA   #1
         STA   ]TEMP
:OLP
         LDA   ]TEMP
         STA   ]TEMP3
         INC   ]TEMP3
         SCPOS ]LWIDTH;]TEMP3
         LDY   #0
:HLP
         INY
         LDA   #32        ; INVERTED SPACE
         JSR   COUT1
         CPY   ]OWIDTH
         BCC   :HLP
         BEQ   :HLP
*
         INC   ]TEMP
         LDA   ]LCOUNT
         CMP   ]TEMP
         BCS   :OLP
         BEQ   :OLP
*
         WAIT
         SPRN  ]CURRENT
*
:NEXT    JMP   REENTRY
*
********************************
*                              *
* GSOPT -- GET SELECTED OPTION *
*                              *
********************************
*
GSOPT
*
** VARIABLES
*
         JMP   :SKIPVARS
]STRING  DS    2          ; ADDRESS TO STRING TO PARSE
]LENGTH  DS    2
]ONUM    DS    2
]CTMP    DS    2
]STMP    DS    30
:SKIPVARS
*
** GET PARAMETERS
*
         PLA
         STA   ]STRING
         STA   ADDR4
         PLA
         STA   ]STRING+1
         STA   ADDR4+1
*
**
*
         LDY   #0
         LDA   (ADDR4),Y
         STA   ]LENGTH
         INY
*
:LP1
         INC   ]CTMP
         LDA   ]CTMP
         CMP   ]LENGTH
         BEQ   :QLP1
         INY
         LDA   (ADDR4),Y
         CMP   #"#"
         BNE   :CLP1
         INX
:CLP1
         CMP   #"*"
         BNE   :LP1
:FOUND                    ; ASTERISK FOUND
         STX   ]SNUM      ; .X HOLDS THE SELECTION NUMBER
*
** NOW READ SELECTION CONTENT, PUT SUBSTRING IN RETURN
:QLP1
                          ; NO SELECTION FOUND
:DONE
         RTS
