* GSINIT - Initialise for GSTRANS string parsing ************************************************ * On entry, * (OSLPTR),Y=>start of string (spaces will be skipped) * CLC = filename style parsing * SEC = *KEY style parsing * On exit, * X = preserved * Y = prepared for future calls to GSREAD * EQ = end of line (nb: not "" null string) * NE = not end of line * * Very difficult to write this without it being a direct clone * from the BBC MOS. ;) * GSINTGO ROR GSFLAG ; CY initially into bit 7 JSR SKIPSPC ; Skip any spaces INY ; Step past in case it's a quote CMP #$22 ; Is it a quote? BEQ GSINTGO1 DEY ; Wasn't a quote, step back CLC ; Prepare CC=no leading quote GSINTGO1 ROR GSFLAG ; Rotate 'leading-quote' into flags CMP #$0D RTS ; Return EQ if end of line * GSFLAG set to: * bit7: leading quote found * bit6: CC=filename CS=*KEY * GSREAD - Read a character from a GSTRANS parsed string ******************************************************** * On entry, * (OSLPTR),Y=>current string pointer * On exit, * A = parsed character * X = preserved * CS = end of string (space or or ") * Y =updated to start of next word or end of line * EQ=end of line after this string * NE=not end of line, more words follow * CC = not end of string * Y =updated for future calls to GSREAD * VS=7-bit control character, (char AND $7F)<$20 * VC=not 7-bit control character (char AND $7F)>$1F * EQ= char=$00, NE= char>$00 * PL= char<$80, MI= char>$7F * * No string present is checked for with: * JSR GSINIT:BEQ missingstring * * A null string is checked for with: * JSR GSINIT:JSR GSREAD:BCS nullstring * * A string is skipped with: * JSR GSINIT * loop * JSR GSREAD:BCC loop * * A string is copied with: * JSR GSINIT * LDX #0 * loop * JSR GSREAD:BCS done * STA data,X * INX:BNE loop * done * GSRDGO LDA #$00 ; Prepare to clear accumulator GSREADLP STA GSCHAR ; Update accumulator LDA (OSLPTR),Y ; Get current character CMP #$0D ; End of line? BNE GSREAD2 ; No, check character BIT GSFLAG BPL GSREADEND ; We aren't waiting for a closing quote * ; End of line before closing quote ERRBADSTR BRK DB $FD ASC 'Bad string' BRK GSREAD2 CMP #' ' BCC ERRBADSTR ; Embedded control char BNE GSREAD3 ; Not a space, process it BIT GSFLAG ; Can space terminate string? BMI GSREADCHAR ; We're waiting for a terminating quote * ; so return the space character BVC GSREADEND ; Space is a terminator, finish GSREAD3 CMP #$22 ; Is it a quote? BNE GSREADESC ; Not quote, check for escapes BIT GSFLAG ; Was there an opening quote? BPL GSREADCHAR ; Not waiting for a closing quote INY ; Waiting for quote, check next character LDA (OSLPTR),Y CMP #$22 ; Is it another quote? BEQ GSREADCHAR ; Quote-Quote, expand to single quote * End of string * Either closing quote, or a space seperator, or end of line GSREADEND JSR SKIPSPC ; Skip any spaces to next word SEC ; SEC=end of string RTS ; and (OSLPTR),Y=>next word or end of line * CS=end of string * EQ=end of line * NE=not end of line, more words follow GSREADESC CMP #$7C ; Is it '|' escape character BNE GSREADCHAR ; No, return as character INY ; Step to next character LDA (OSLPTR),Y CMP #$7C BEQ GSREADCHAR ; bar-bar expands to bar CMP #$22 BEQ GSREADCHAR ; bar-quote expands to quote CMP #'!' ; Is it bar-pling? BNE GSREAD5 ; No, check for bar-letter INY ; Step past it LDA #$80 ; Set bit 7 in accumulator BNE GSREADLP ; Loop back to check next character(s) GSREAD5 CMP #'?' ; Check for '?' BCC ERRBADSTR ; <'?', bad character BEQ GSREADDEL ; bar-query -> DEL AND #$1F ; Convert bar-letter to control code BIT SETV ; SEV=control character BVS GSREADOK GSREADDEL LDA #$7F GSREADCHAR CLV ; CLV=not control character GSREADOK INY ; Step to next character ORA GSCHAR ; Add in any bit 7 from |! prefix CLC ; CLC=not end of string SETV RTS * CC=not end of string * VS=control character * VC=not control character * * Skip spaces SKIPSPC1 INY ; Step past a character SKIPSPC LDA (OSLPTR),Y CMP #' ' BEQ SKIPSPC1 CMP #$0D ; Return EQ= RTS