diff --git a/ctype.asm b/ctype.asm index 3c6bcac..848f66d 100644 --- a/ctype.asm +++ b/ctype.asm @@ -1,5 +1,5 @@ - keep obj/ctype - case on + keep obj/ctype + case on **************************************************************** * * CType - Character Types Library @@ -15,561 +15,561 @@ * **************************************************************** * -CType start dummy routine - copy equates.asm +CType start dummy routine + copy equates.asm - end + end **************************************************************** * * int isalnum (int c) * * Inputs: -* 4,S - digit to test +* 4,S - digit to test * * Outputs: -* A - result +* A - result * **************************************************************** * -isalnum start +isalnum start - lda 4,S fetch the operand - tax - lda 2,S remove parm from stack - sta 4,S - pla - sta 1,S - inx form the result - lda >__ctype,X - and #_upper+_lower+_digit - rtl - end + lda 4,S fetch the operand + tax + lda 2,S remove parm from stack + sta 4,S + pla + sta 1,S + inx form the result + lda >__ctype,X + and #_upper+_lower+_digit + rtl + end **************************************************************** * * int isalpha (int c) * * Inputs: -* 4,S - digit to test +* 4,S - digit to test * * Outputs: -* A - result +* A - result * **************************************************************** * -isalpha start +isalpha start - lda 4,S fetch the operand - tax - lda 2,S remove parm from stack - sta 4,S - pla - sta 1,S - inx form the result - lda >__ctype,X - and #_upper+_lower - rtl - end + lda 4,S fetch the operand + tax + lda 2,S remove parm from stack + sta 4,S + pla + sta 1,S + inx form the result + lda >__ctype,X + and #_upper+_lower + rtl + end **************************************************************** * * int isascii (int c) * * Inputs: -* 4,S - digit to test +* 4,S - digit to test * * Outputs: -* A - result +* A - result * **************************************************************** * -isascii start +isascii start - lda 4,S fetch the operand - tax - lda 2,S remove parm from stack - sta 4,S - pla - sta 1,S - cpx #$0080 form the result - blt yes - lda #0 - rtl + lda 4,S fetch the operand + tax + lda 2,S remove parm from stack + sta 4,S + pla + sta 1,S + cpx #$0080 form the result + blt yes + lda #0 + rtl -yes lda #1 - rtl - end +yes lda #1 + rtl + end **************************************************************** * * int isblank (int c) * * Inputs: -* 4,S - digit to test +* 4,S - digit to test * * Outputs: -* A - result +* A - result * **************************************************************** * -isblank start +isblank start - lda 4,S fetch the operand - tax - lda 2,S remove parm from stack - sta 4,S - pla - sta 1,S - inx form the result - lda >__ctype2,X - and #_blank - rtl - end + lda 4,S fetch the operand + tax + lda 2,S remove parm from stack + sta 4,S + pla + sta 1,S + inx form the result + lda >__ctype2,X + and #_blank + rtl + end **************************************************************** * * int iscntrl (int c) * * Inputs: -* 4,S - digit to test +* 4,S - digit to test * * Outputs: -* A - result +* A - result * **************************************************************** * -iscntrl start +iscntrl start - lda 4,S fetch the operand - tax - lda 2,S remove parm from stack - sta 4,S - pla - sta 1,S - inx form the result - lda >__ctype,X - and #_control - rtl - end + lda 4,S fetch the operand + tax + lda 2,S remove parm from stack + sta 4,S + pla + sta 1,S + inx form the result + lda >__ctype,X + and #_control + rtl + end **************************************************************** * * int iscsym (int c) * * Inputs: -* 4,S - digit to test +* 4,S - digit to test * * Outputs: -* A - result +* A - result * **************************************************************** * -iscsym start +iscsym start - lda 4,S fetch the operand - tax - lda 2,S remove parm from stack - sta 4,S - pla - sta 1,S - inx form the result - lda >__ctype2,X - and #_csym - rtl - end + lda 4,S fetch the operand + tax + lda 2,S remove parm from stack + sta 4,S + pla + sta 1,S + inx form the result + lda >__ctype2,X + and #_csym + rtl + end **************************************************************** * * int iscsymf (int c) * * Inputs: -* 4,S - digit to test +* 4,S - digit to test * * Outputs: -* A - result +* A - result * **************************************************************** * -iscsymf start +iscsymf start - lda 4,S fetch the operand - tax - lda 2,S remove parm from stack - sta 4,S - pla - sta 1,S - inx form the result - lda >__ctype2,X - and #_csymf - rtl - end + lda 4,S fetch the operand + tax + lda 2,S remove parm from stack + sta 4,S + pla + sta 1,S + inx form the result + lda >__ctype2,X + and #_csymf + rtl + end **************************************************************** * * int isdigit (int c) * * Inputs: -* 4,S - digit to test +* 4,S - digit to test * * Outputs: -* A - result +* A - result * **************************************************************** * -isdigit start +isdigit start - lda 4,S fetch the operand - tax - lda 2,S remove parm from stack - sta 4,S - pla - sta 1,S - inx form the result - lda >__ctype,X - and #_digit - rtl - end + lda 4,S fetch the operand + tax + lda 2,S remove parm from stack + sta 4,S + pla + sta 1,S + inx form the result + lda >__ctype,X + and #_digit + rtl + end **************************************************************** * * int isgraph (int c) * * Inputs: -* 4,S - digit to test +* 4,S - digit to test * * Outputs: -* A - result +* A - result * **************************************************************** * -isgraph start +isgraph start - lda 4,S fetch the operand - tax - lda 2,S remove parm from stack - sta 4,S - pla - sta 1,S - inx form the result - lda >__ctype,X - and #_upper+_lower+_digit+_punctuation - rtl - end + lda 4,S fetch the operand + tax + lda 2,S remove parm from stack + sta 4,S + pla + sta 1,S + inx form the result + lda >__ctype,X + and #_upper+_lower+_digit+_punctuation + rtl + end **************************************************************** * * int islower (int c) * * Inputs: -* 4,S - digit to test +* 4,S - digit to test * * Outputs: -* A - result +* A - result * **************************************************************** * -islower start +islower start - lda 4,S fetch the operand - tax - lda 2,S remove parm from stack - sta 4,S - pla - sta 1,S - inx form the result - lda >__ctype,X - and #_lower - rtl - end + lda 4,S fetch the operand + tax + lda 2,S remove parm from stack + sta 4,S + pla + sta 1,S + inx form the result + lda >__ctype,X + and #_lower + rtl + end **************************************************************** * * int isodigit (int c) * * Inputs: -* 4,S - digit to test +* 4,S - digit to test * * Outputs: -* A - result +* A - result * **************************************************************** * -isodigit start +isodigit start - lda 4,S fetch the operand - tax - lda 2,S remove parm from stack - sta 4,S - pla - sta 1,S - inx form the result - lda >__ctype2,X - and #_octal - rtl - end + lda 4,S fetch the operand + tax + lda 2,S remove parm from stack + sta 4,S + pla + sta 1,S + inx form the result + lda >__ctype2,X + and #_octal + rtl + end **************************************************************** * * int isprint (int c) * * Inputs: -* 4,S - digit to test +* 4,S - digit to test * * Outputs: -* A - result +* A - result * **************************************************************** * -isprint start +isprint start - lda 4,S fetch the operand - tax - lda 2,S remove parm from stack - sta 4,S - pla - sta 1,S - inx form the result - lda >__ctype,X - and #_print - rtl - end + lda 4,S fetch the operand + tax + lda 2,S remove parm from stack + sta 4,S + pla + sta 1,S + inx form the result + lda >__ctype,X + and #_print + rtl + end **************************************************************** * * int ispunct (int c) * * Inputs: -* 4,S - digit to test +* 4,S - digit to test * * Outputs: -* A - result +* A - result * **************************************************************** * -ispunct start +ispunct start - lda 4,S fetch the operand - tax - lda 2,S remove parm from stack - sta 4,S - pla - sta 1,S - inx form the result - lda >__ctype,X - and #_punctuation - rtl - end + lda 4,S fetch the operand + tax + lda 2,S remove parm from stack + sta 4,S + pla + sta 1,S + inx form the result + lda >__ctype,X + and #_punctuation + rtl + end **************************************************************** * * int isspace (int c) * * Inputs: -* 4,S - digit to test +* 4,S - digit to test * * Outputs: -* A - result +* A - result * **************************************************************** * -isspace start +isspace start - lda 4,S fetch the operand - tax - lda 2,S remove parm from stack - sta 4,S - pla - sta 1,S - inx form the result - lda >__ctype,X - and #_space - rtl - end + lda 4,S fetch the operand + tax + lda 2,S remove parm from stack + sta 4,S + pla + sta 1,S + inx form the result + lda >__ctype,X + and #_space + rtl + end **************************************************************** * * int isupper (int c) * * Inputs: -* 4,S - digit to test +* 4,S - digit to test * * Outputs: -* A - result +* A - result * **************************************************************** * -isupper start +isupper start - lda 4,S fetch the operand - tax - lda 2,S remove parm from stack - sta 4,S - pla - sta 1,S - inx form the result - lda >__ctype,X - and #_upper - rtl - end + lda 4,S fetch the operand + tax + lda 2,S remove parm from stack + sta 4,S + pla + sta 1,S + inx form the result + lda >__ctype,X + and #_upper + rtl + end **************************************************************** * * int isxdigit (int c) * * Inputs: -* 4,S - digit to test +* 4,S - digit to test * * Outputs: -* A - result +* A - result * **************************************************************** * -isxdigit start +isxdigit start - lda 4,S fetch the operand - tax - lda 2,S remove parm from stack - sta 4,S - pla - sta 1,S - inx form the result - lda >__ctype,X - and #_hex - rtl - end + lda 4,S fetch the operand + tax + lda 2,S remove parm from stack + sta 4,S + pla + sta 1,S + inx form the result + lda >__ctype,X + and #_hex + rtl + end **************************************************************** * * int toascii (int c) * * Inputs: -* 4,S - digit to convert +* 4,S - digit to convert * * Outputs: -* A - result +* A - result * **************************************************************** * -toascii start +toascii start - lda 4,S fetch the operand - tax - lda 2,S remove parm from stack - sta 4,S - pla - sta 1,S - txa form the result - and #$7F - rtl - end + lda 4,S fetch the operand + tax + lda 2,S remove parm from stack + sta 4,S + pla + sta 1,S + txa form the result + and #$7F + rtl + end **************************************************************** * * toint - convert a hex digit to a binary value * * Inputs: -* 4,S - digit to convert +* 4,S - digit to convert * * Outputs: -* A - converted digit +* A - converted digit * **************************************************************** * -toint start -FALSE equ -1 returned for false conditions +toint start +FALSE equ -1 returned for false conditions - lda 4,S fetch the operand - tax - lda 2,S remove parm from stack - sta 4,S - pla - sta 1,S + lda 4,S fetch the operand + tax + lda 2,S remove parm from stack + sta 4,S + pla + sta 1,S - inx branch if not hex - lda >__ctype,X - and #_hex - beq no - txa insure char is uppercase - and #$5F - dec A - cmp #'A' if the character is alpha then - blt lb1 - sbc #7 convert the value -lb1 and #$000F return ordinal value - rtl + inx branch if not hex + lda >__ctype,X + and #_hex + beq no + txa insure char is uppercase + and #$5F + dec A + cmp #'A' if the character is alpha then + blt lb1 + sbc #7 convert the value +lb1 and #$000F return ordinal value + rtl -no lda #FALSE not hex - rtl - end +no lda #FALSE not hex + rtl + end **************************************************************** * * tolower - if the input is uppercase, convert it to lowercase * * Inputs: -* 4,S - digit to convert +* 4,S - digit to convert * * Outputs: -* A - converted character +* A - converted character * **************************************************************** * -tolower start +tolower start - lda 4,S fetch the operand - tax - lda 2,S remove parm from the stack - sta 4,S - pla - sta 1,S + lda 4,S fetch the operand + tax + lda 2,S remove parm from the stack + sta 4,S + pla + sta 1,S - txa - bmi lb2 - lda >__ctype+1,X branch if the character is not uppercase - and #_upper - beq lb1 - txa convert to lowercase - ora #$20 - rtl + txa + bmi lb2 + lda >__ctype+1,X branch if the character is not uppercase + and #_upper + beq lb1 + txa convert to lowercase + ora #$20 + rtl -lb1 txa return the input character -lb2 rtl - end +lb1 txa return the input character +lb2 rtl + end **************************************************************** * * toupper - if the input is lowercase, convert it to uppercase * * Inputs: -* 4,S - digit to convert +* 4,S - digit to convert * * Outputs: -* A - converted character +* A - converted character * **************************************************************** * -toupper start +toupper start - lda 4,S fetch the operand - tax - lda 2,S remove parm from the stack - sta 4,S - pla - sta 1,S + lda 4,S fetch the operand + tax + lda 2,S remove parm from the stack + sta 4,S + pla + sta 1,S - txa - bmi lb2 - lda >__ctype+1,X branch if the character is not lowercase - and #_lower - beq lb1 - txa convert to uppercase - and #$5F - rtl + txa + bmi lb2 + lda >__ctype+1,X branch if the character is not lowercase + and #_lower + beq lb1 + txa convert to uppercase + and #$5F + rtl -lb1 txa return the input character -lb2 rtl - end +lb1 txa return the input character +lb2 rtl + end **************************************************************** * @@ -584,266 +584,266 @@ lb2 rtl * **************************************************************** * -__ctype start +__ctype start - dc i1'0' EOF - dc i1'_control' $00 - dc i1'_control' $01 - dc i1'_control' $02 - dc i1'_control' $03 - dc i1'_control' $04 - dc i1'_control' $05 - dc i1'_control' $06 - dc i1'_control' $07 - dc i1'_control' $08 - dc i1'_control+_space' $09 - dc i1'_control+_space' $0A - dc i1'_control+_space' $0B - dc i1'_control+_space' $0C - dc i1'_control+_space' $0D - dc i1'_control' $0E - dc i1'_control' $0F - dc i1'_control' $10 - dc i1'_control' $11 - dc i1'_control' $12 - dc i1'_control' $13 - dc i1'_control' $14 - dc i1'_control' $15 - dc i1'_control' $16 - dc i1'_control' $17 - dc i1'_control' $18 - dc i1'_control' $19 - dc i1'_control' $1A - dc i1'_control' $1B - dc i1'_control' $1C - dc i1'_control' $1D - dc i1'_control' $1E - dc i1'_control' $1F - dc i1'_space+_print' ' ' - dc i1'_punctuation+_print' ! - dc i1'_punctuation+_print' " - dc i1'_punctuation+_print' # - dc i1'_punctuation+_print' $ - dc i1'_punctuation+_print' % - dc i1'_punctuation+_print' & - dc i1'_punctuation+_print' ' - dc i1'_punctuation+_print' ( - dc i1'_punctuation+_print' ) - dc i1'_punctuation+_print' * - dc i1'_punctuation+_print' + - dc i1'_punctuation+_print' , - dc i1'_punctuation+_print' - - dc i1'_punctuation+_print' . - dc i1'_punctuation+_print' / - dc i1'_digit+_hex+_print' 0 - dc i1'_digit+_hex+_print' 1 - dc i1'_digit+_hex+_print' 2 - dc i1'_digit+_hex+_print' 3 - dc i1'_digit+_hex+_print' 4 - dc i1'_digit+_hex+_print' 5 - dc i1'_digit+_hex+_print' 6 - dc i1'_digit+_hex+_print' 7 - dc i1'_digit+_hex+_print' 8 - dc i1'_digit+_hex+_print' 9 - dc i1'_punctuation+_print' : - dc i1'_punctuation+_print' ; - dc i1'_punctuation+_print' < - dc i1'_punctuation+_print' = - dc i1'_punctuation+_print' > - dc i1'_punctuation+_print' ? - dc i1'_punctuation+_print' @ - dc i1'_upper+_hex+_print' A - dc i1'_upper+_hex+_print' B - dc i1'_upper+_hex+_print' C - dc i1'_upper+_hex+_print' D - dc i1'_upper+_hex+_print' E - dc i1'_upper+_hex+_print' F - dc i1'_upper+_print' G - dc i1'_upper+_print' H - dc i1'_upper+_print' I - dc i1'_upper+_print' J - dc i1'_upper+_print' K - dc i1'_upper+_print' L - dc i1'_upper+_print' M - dc i1'_upper+_print' N - dc i1'_upper+_print' O - dc i1'_upper+_print' P - dc i1'_upper+_print' Q - dc i1'_upper+_print' R - dc i1'_upper+_print' S - dc i1'_upper+_print' T - dc i1'_upper+_print' U - dc i1'_upper+_print' V - dc i1'_upper+_print' W - dc i1'_upper+_print' X - dc i1'_upper+_print' Y - dc i1'_upper+_print' Z - dc i1'_punctuation+_print' [ - dc i1'_punctuation+_print' \ - dc i1'_punctuation+_print' ] - dc i1'_punctuation+_print' ^ - dc i1'_punctuation+_print' _ - dc i1'_punctuation+_print' ` - dc i1'_lower+_hex+_print' a - dc i1'_lower+_hex+_print' b - dc i1'_lower+_hex+_print' c - dc i1'_lower+_hex+_print' d - dc i1'_lower+_hex+_print' e - dc i1'_lower+_hex+_print' f - dc i1'_lower+_print' g - dc i1'_lower+_print' h - dc i1'_lower+_print' i - dc i1'_lower+_print' j - dc i1'_lower+_print' k - dc i1'_lower+_print' l - dc i1'_lower+_print' m - dc i1'_lower+_print' n - dc i1'_lower+_print' o - dc i1'_lower+_print' p - dc i1'_lower+_print' q - dc i1'_lower+_print' r - dc i1'_lower+_print' s - dc i1'_lower+_print' t - dc i1'_lower+_print' u - dc i1'_lower+_print' v - dc i1'_lower+_print' w - dc i1'_lower+_print' x - dc i1'_lower+_print' y - dc i1'_lower+_print' z - dc i1'_punctuation+_print' { - dc i1'_punctuation+_print' | - dc i1'_punctuation+_print' } - dc i1'_punctuation+_print' ~ - dc i1'_control' $7F - dc i1'0' $80 - dc i1'0' $81 - dc i1'0' $82 - dc i1'0' $83 - dc i1'0' $84 - dc i1'0' $85 - dc i1'0' $86 - dc i1'0' $87 - dc i1'0' $88 - dc i1'0' $89 - dc i1'0' $8A - dc i1'0' $8B - dc i1'0' $8C - dc i1'0' $8D - dc i1'0' $8E - dc i1'0' $8F - dc i1'0' $90 - dc i1'0' $91 - dc i1'0' $92 - dc i1'0' $93 - dc i1'0' $94 - dc i1'0' $95 - dc i1'0' $96 - dc i1'0' $97 - dc i1'0' $98 - dc i1'0' $99 - dc i1'0' $9A - dc i1'0' $9B - dc i1'0' $9C - dc i1'0' $9D - dc i1'0' $9E - dc i1'0' $9F - dc i1'0' $A0 - dc i1'0' $A1 - dc i1'0' $A2 - dc i1'0' $A3 - dc i1'0' $A4 - dc i1'0' $A5 - dc i1'0' $A6 - dc i1'0' $A7 - dc i1'0' $A8 - dc i1'0' $A9 - dc i1'0' $AA - dc i1'0' $AB - dc i1'0' $AC - dc i1'0' $AD - dc i1'0' $AE - dc i1'0' $AF - dc i1'0' $B0 - dc i1'0' $B1 - dc i1'0' $B2 - dc i1'0' $B3 - dc i1'0' $B4 - dc i1'0' $B5 - dc i1'0' $B6 - dc i1'0' $B7 - dc i1'0' $B8 - dc i1'0' $B9 - dc i1'0' $BA - dc i1'0' $BB - dc i1'0' $BC - dc i1'0' $BD - dc i1'0' $BE - dc i1'0' $BF - dc i1'0' $C0 - dc i1'0' $C1 - dc i1'0' $C2 - dc i1'0' $C3 - dc i1'0' $C4 - dc i1'0' $C5 - dc i1'0' $C6 - dc i1'0' $C7 - dc i1'0' $C8 - dc i1'0' $C9 - dc i1'0' $CA - dc i1'0' $CB - dc i1'0' $CC - dc i1'0' $CD - dc i1'0' $CE - dc i1'0' $CF - dc i1'0' $D0 - dc i1'0' $D1 - dc i1'0' $D2 - dc i1'0' $D3 - dc i1'0' $D4 - dc i1'0' $D5 - dc i1'0' $D6 - dc i1'0' $D7 - dc i1'0' $D8 - dc i1'0' $D9 - dc i1'0' $DA - dc i1'0' $DB - dc i1'0' $DC - dc i1'0' $DD - dc i1'0' $DE - dc i1'0' $DF - dc i1'0' $E0 - dc i1'0' $E1 - dc i1'0' $E2 - dc i1'0' $E3 - dc i1'0' $E4 - dc i1'0' $E5 - dc i1'0' $E6 - dc i1'0' $E7 - dc i1'0' $E8 - dc i1'0' $E9 - dc i1'0' $EA - dc i1'0' $EB - dc i1'0' $EC - dc i1'0' $ED - dc i1'0' $EE - dc i1'0' $EF - dc i1'0' $F0 - dc i1'0' $F1 - dc i1'0' $F2 - dc i1'0' $F3 - dc i1'0' $F4 - dc i1'0' $F5 - dc i1'0' $F6 - dc i1'0' $F7 - dc i1'0' $F8 - dc i1'0' $F9 - dc i1'0' $FA - dc i1'0' $FB - dc i1'0' $FC - dc i1'0' $FD - dc i1'0' $FE - dc i1'0' $FF - end + dc i1'0' EOF + dc i1'_control' $00 + dc i1'_control' $01 + dc i1'_control' $02 + dc i1'_control' $03 + dc i1'_control' $04 + dc i1'_control' $05 + dc i1'_control' $06 + dc i1'_control' $07 + dc i1'_control' $08 + dc i1'_control+_space' $09 + dc i1'_control+_space' $0A + dc i1'_control+_space' $0B + dc i1'_control+_space' $0C + dc i1'_control+_space' $0D + dc i1'_control' $0E + dc i1'_control' $0F + dc i1'_control' $10 + dc i1'_control' $11 + dc i1'_control' $12 + dc i1'_control' $13 + dc i1'_control' $14 + dc i1'_control' $15 + dc i1'_control' $16 + dc i1'_control' $17 + dc i1'_control' $18 + dc i1'_control' $19 + dc i1'_control' $1A + dc i1'_control' $1B + dc i1'_control' $1C + dc i1'_control' $1D + dc i1'_control' $1E + dc i1'_control' $1F + dc i1'_space+_print' ' ' + dc i1'_punctuation+_print' ! + dc i1'_punctuation+_print' " + dc i1'_punctuation+_print' # + dc i1'_punctuation+_print' $ + dc i1'_punctuation+_print' % + dc i1'_punctuation+_print' & + dc i1'_punctuation+_print' ' + dc i1'_punctuation+_print' ( + dc i1'_punctuation+_print' ) + dc i1'_punctuation+_print' * + dc i1'_punctuation+_print' + + dc i1'_punctuation+_print' , + dc i1'_punctuation+_print' - + dc i1'_punctuation+_print' . + dc i1'_punctuation+_print' / + dc i1'_digit+_hex+_print' 0 + dc i1'_digit+_hex+_print' 1 + dc i1'_digit+_hex+_print' 2 + dc i1'_digit+_hex+_print' 3 + dc i1'_digit+_hex+_print' 4 + dc i1'_digit+_hex+_print' 5 + dc i1'_digit+_hex+_print' 6 + dc i1'_digit+_hex+_print' 7 + dc i1'_digit+_hex+_print' 8 + dc i1'_digit+_hex+_print' 9 + dc i1'_punctuation+_print' : + dc i1'_punctuation+_print' ; + dc i1'_punctuation+_print' < + dc i1'_punctuation+_print' = + dc i1'_punctuation+_print' > + dc i1'_punctuation+_print' ? + dc i1'_punctuation+_print' @ + dc i1'_upper+_hex+_print' A + dc i1'_upper+_hex+_print' B + dc i1'_upper+_hex+_print' C + dc i1'_upper+_hex+_print' D + dc i1'_upper+_hex+_print' E + dc i1'_upper+_hex+_print' F + dc i1'_upper+_print' G + dc i1'_upper+_print' H + dc i1'_upper+_print' I + dc i1'_upper+_print' J + dc i1'_upper+_print' K + dc i1'_upper+_print' L + dc i1'_upper+_print' M + dc i1'_upper+_print' N + dc i1'_upper+_print' O + dc i1'_upper+_print' P + dc i1'_upper+_print' Q + dc i1'_upper+_print' R + dc i1'_upper+_print' S + dc i1'_upper+_print' T + dc i1'_upper+_print' U + dc i1'_upper+_print' V + dc i1'_upper+_print' W + dc i1'_upper+_print' X + dc i1'_upper+_print' Y + dc i1'_upper+_print' Z + dc i1'_punctuation+_print' [ + dc i1'_punctuation+_print' \ + dc i1'_punctuation+_print' ] + dc i1'_punctuation+_print' ^ + dc i1'_punctuation+_print' _ + dc i1'_punctuation+_print' ` + dc i1'_lower+_hex+_print' a + dc i1'_lower+_hex+_print' b + dc i1'_lower+_hex+_print' c + dc i1'_lower+_hex+_print' d + dc i1'_lower+_hex+_print' e + dc i1'_lower+_hex+_print' f + dc i1'_lower+_print' g + dc i1'_lower+_print' h + dc i1'_lower+_print' i + dc i1'_lower+_print' j + dc i1'_lower+_print' k + dc i1'_lower+_print' l + dc i1'_lower+_print' m + dc i1'_lower+_print' n + dc i1'_lower+_print' o + dc i1'_lower+_print' p + dc i1'_lower+_print' q + dc i1'_lower+_print' r + dc i1'_lower+_print' s + dc i1'_lower+_print' t + dc i1'_lower+_print' u + dc i1'_lower+_print' v + dc i1'_lower+_print' w + dc i1'_lower+_print' x + dc i1'_lower+_print' y + dc i1'_lower+_print' z + dc i1'_punctuation+_print' { + dc i1'_punctuation+_print' | + dc i1'_punctuation+_print' } + dc i1'_punctuation+_print' ~ + dc i1'_control' $7F + dc i1'0' $80 + dc i1'0' $81 + dc i1'0' $82 + dc i1'0' $83 + dc i1'0' $84 + dc i1'0' $85 + dc i1'0' $86 + dc i1'0' $87 + dc i1'0' $88 + dc i1'0' $89 + dc i1'0' $8A + dc i1'0' $8B + dc i1'0' $8C + dc i1'0' $8D + dc i1'0' $8E + dc i1'0' $8F + dc i1'0' $90 + dc i1'0' $91 + dc i1'0' $92 + dc i1'0' $93 + dc i1'0' $94 + dc i1'0' $95 + dc i1'0' $96 + dc i1'0' $97 + dc i1'0' $98 + dc i1'0' $99 + dc i1'0' $9A + dc i1'0' $9B + dc i1'0' $9C + dc i1'0' $9D + dc i1'0' $9E + dc i1'0' $9F + dc i1'0' $A0 + dc i1'0' $A1 + dc i1'0' $A2 + dc i1'0' $A3 + dc i1'0' $A4 + dc i1'0' $A5 + dc i1'0' $A6 + dc i1'0' $A7 + dc i1'0' $A8 + dc i1'0' $A9 + dc i1'0' $AA + dc i1'0' $AB + dc i1'0' $AC + dc i1'0' $AD + dc i1'0' $AE + dc i1'0' $AF + dc i1'0' $B0 + dc i1'0' $B1 + dc i1'0' $B2 + dc i1'0' $B3 + dc i1'0' $B4 + dc i1'0' $B5 + dc i1'0' $B6 + dc i1'0' $B7 + dc i1'0' $B8 + dc i1'0' $B9 + dc i1'0' $BA + dc i1'0' $BB + dc i1'0' $BC + dc i1'0' $BD + dc i1'0' $BE + dc i1'0' $BF + dc i1'0' $C0 + dc i1'0' $C1 + dc i1'0' $C2 + dc i1'0' $C3 + dc i1'0' $C4 + dc i1'0' $C5 + dc i1'0' $C6 + dc i1'0' $C7 + dc i1'0' $C8 + dc i1'0' $C9 + dc i1'0' $CA + dc i1'0' $CB + dc i1'0' $CC + dc i1'0' $CD + dc i1'0' $CE + dc i1'0' $CF + dc i1'0' $D0 + dc i1'0' $D1 + dc i1'0' $D2 + dc i1'0' $D3 + dc i1'0' $D4 + dc i1'0' $D5 + dc i1'0' $D6 + dc i1'0' $D7 + dc i1'0' $D8 + dc i1'0' $D9 + dc i1'0' $DA + dc i1'0' $DB + dc i1'0' $DC + dc i1'0' $DD + dc i1'0' $DE + dc i1'0' $DF + dc i1'0' $E0 + dc i1'0' $E1 + dc i1'0' $E2 + dc i1'0' $E3 + dc i1'0' $E4 + dc i1'0' $E5 + dc i1'0' $E6 + dc i1'0' $E7 + dc i1'0' $E8 + dc i1'0' $E9 + dc i1'0' $EA + dc i1'0' $EB + dc i1'0' $EC + dc i1'0' $ED + dc i1'0' $EE + dc i1'0' $EF + dc i1'0' $F0 + dc i1'0' $F1 + dc i1'0' $F2 + dc i1'0' $F3 + dc i1'0' $F4 + dc i1'0' $F5 + dc i1'0' $F6 + dc i1'0' $F7 + dc i1'0' $F8 + dc i1'0' $F9 + dc i1'0' $FA + dc i1'0' $FB + dc i1'0' $FC + dc i1'0' $FD + dc i1'0' $FE + dc i1'0' $FF + end **************************************************************** * @@ -860,261 +860,261 @@ __ctype start * __ctype2 start - dc i1'0' EOF - dc i1'0' $00 - dc i1'0' $01 - dc i1'0' $02 - dc i1'0' $03 - dc i1'0' $04 - dc i1'0' $05 - dc i1'0' $06 - dc i1'0' $07 - dc i1'0' $08 - dc i1'_blank' $09 - dc i1'0' $0A - dc i1'0' $0B - dc i1'0' $0C - dc i1'0' $0D - dc i1'0' $0E - dc i1'0' $0F - dc i1'0' $10 - dc i1'0' $11 - dc i1'0' $12 - dc i1'0' $13 - dc i1'0' $14 - dc i1'0' $15 - dc i1'0' $16 - dc i1'0' $17 - dc i1'0' $18 - dc i1'0' $19 - dc i1'0' $1A - dc i1'0' $1B - dc i1'0' $1C - dc i1'0' $1D - dc i1'0' $1E - dc i1'0' $1F - dc i1'_blank' ' ' - dc i1'0' ! - dc i1'0' " - dc i1'0' # - dc i1'0' $ - dc i1'0' % - dc i1'0' & - dc i1'0' ' - dc i1'0' ( - dc i1'0' ) - dc i1'0' * - dc i1'0' + - dc i1'0' , - dc i1'0' - - dc i1'0' . - dc i1'0' / - dc i1'_csym+_octal' 0 - dc i1'_csym+_octal' 1 - dc i1'_csym+_octal' 2 - dc i1'_csym+_octal' 3 - dc i1'_csym+_octal' 4 - dc i1'_csym+_octal' 5 - dc i1'_csym+_octal' 6 - dc i1'_csym+_octal' 7 - dc i1'_csym' 8 - dc i1'_csym' 9 - dc i1'0' : - dc i1'0' ; - dc i1'0' < - dc i1'0' = - dc i1'0' > - dc i1'0' ? - dc i1'0' @ - dc i1'_csym+_csymf' A - dc i1'_csym+_csymf' B - dc i1'_csym+_csymf' C - dc i1'_csym+_csymf' D - dc i1'_csym+_csymf' E - dc i1'_csym+_csymf' F - dc i1'_csym+_csymf' G - dc i1'_csym+_csymf' H - dc i1'_csym+_csymf' I - dc i1'_csym+_csymf' J - dc i1'_csym+_csymf' K - dc i1'_csym+_csymf' L - dc i1'_csym+_csymf' M - dc i1'_csym+_csymf' N - dc i1'_csym+_csymf' O - dc i1'_csym+_csymf' P - dc i1'_csym+_csymf' Q - dc i1'_csym+_csymf' R - dc i1'_csym+_csymf' S - dc i1'_csym+_csymf' T - dc i1'_csym+_csymf' U - dc i1'_csym+_csymf' V - dc i1'_csym+_csymf' W - dc i1'_csym+_csymf' X - dc i1'_csym+_csymf' Y - dc i1'_csym+_csymf' Z - dc i1'0' [ - dc i1'0' \ - dc i1'0' ] - dc i1'0' ^ - dc i1'_csym+_csymf' _ - dc i1'0' ` - dc i1'_csym+_csymf' a - dc i1'_csym+_csymf' b - dc i1'_csym+_csymf' c - dc i1'_csym+_csymf' d - dc i1'_csym+_csymf' e - dc i1'_csym+_csymf' f - dc i1'_csym+_csymf' g - dc i1'_csym+_csymf' h - dc i1'_csym+_csymf' i - dc i1'_csym+_csymf' j - dc i1'_csym+_csymf' k - dc i1'_csym+_csymf' l - dc i1'_csym+_csymf' m - dc i1'_csym+_csymf' n - dc i1'_csym+_csymf' o - dc i1'_csym+_csymf' p - dc i1'_csym+_csymf' q - dc i1'_csym+_csymf' r - dc i1'_csym+_csymf' s - dc i1'_csym+_csymf' t - dc i1'_csym+_csymf' u - dc i1'_csym+_csymf' v - dc i1'_csym+_csymf' w - dc i1'_csym+_csymf' x - dc i1'_csym+_csymf' y - dc i1'_csym+_csymf' z - dc i1'0' { - dc i1'0' | - dc i1'0' } - dc i1'0' ~ - dc i1'0' $7F - dc i1'0' $80 - dc i1'0' $81 - dc i1'0' $82 - dc i1'0' $83 - dc i1'0' $84 - dc i1'0' $85 - dc i1'0' $86 - dc i1'0' $87 - dc i1'0' $88 - dc i1'0' $89 - dc i1'0' $8A - dc i1'0' $8B - dc i1'0' $8C - dc i1'0' $8D - dc i1'0' $8E - dc i1'0' $8F - dc i1'0' $90 - dc i1'0' $91 - dc i1'0' $92 - dc i1'0' $93 - dc i1'0' $94 - dc i1'0' $95 - dc i1'0' $96 - dc i1'0' $97 - dc i1'0' $98 - dc i1'0' $99 - dc i1'0' $9A - dc i1'0' $9B - dc i1'0' $9C - dc i1'0' $9D - dc i1'0' $9E - dc i1'0' $9F - dc i1'0' $A0 - dc i1'0' $A1 - dc i1'0' $A2 - dc i1'0' $A3 - dc i1'0' $A4 - dc i1'0' $A5 - dc i1'0' $A6 - dc i1'0' $A7 - dc i1'0' $A8 - dc i1'0' $A9 - dc i1'0' $AA - dc i1'0' $AB - dc i1'0' $AC - dc i1'0' $AD - dc i1'0' $AE - dc i1'0' $AF - dc i1'0' $B0 - dc i1'0' $B1 - dc i1'0' $B2 - dc i1'0' $B3 - dc i1'0' $B4 - dc i1'0' $B5 - dc i1'0' $B6 - dc i1'0' $B7 - dc i1'0' $B8 - dc i1'0' $B9 - dc i1'0' $BA - dc i1'0' $BB - dc i1'0' $BC - dc i1'0' $BD - dc i1'0' $BE - dc i1'0' $BF - dc i1'0' $C0 - dc i1'0' $C1 - dc i1'0' $C2 - dc i1'0' $C3 - dc i1'0' $C4 - dc i1'0' $C5 - dc i1'0' $C6 - dc i1'0' $C7 - dc i1'0' $C8 - dc i1'0' $C9 - dc i1'0' $CA - dc i1'0' $CB - dc i1'0' $CC - dc i1'0' $CD - dc i1'0' $CE - dc i1'0' $CF - dc i1'0' $D0 - dc i1'0' $D1 - dc i1'0' $D2 - dc i1'0' $D3 - dc i1'0' $D4 - dc i1'0' $D5 - dc i1'0' $D6 - dc i1'0' $D7 - dc i1'0' $D8 - dc i1'0' $D9 - dc i1'0' $DA - dc i1'0' $DB - dc i1'0' $DC - dc i1'0' $DD - dc i1'0' $DE - dc i1'0' $DF - dc i1'0' $E0 - dc i1'0' $E1 - dc i1'0' $E2 - dc i1'0' $E3 - dc i1'0' $E4 - dc i1'0' $E5 - dc i1'0' $E6 - dc i1'0' $E7 - dc i1'0' $E8 - dc i1'0' $E9 - dc i1'0' $EA - dc i1'0' $EB - dc i1'0' $EC - dc i1'0' $ED - dc i1'0' $EE - dc i1'0' $EF - dc i1'0' $F0 - dc i1'0' $F1 - dc i1'0' $F2 - dc i1'0' $F3 - dc i1'0' $F4 - dc i1'0' $F5 - dc i1'0' $F6 - dc i1'0' $F7 - dc i1'0' $F8 - dc i1'0' $F9 - dc i1'0' $FA - dc i1'0' $FB - dc i1'0' $FC - dc i1'0' $FD - dc i1'0' $FE - dc i1'0' $FF - end + dc i1'0' EOF + dc i1'0' $00 + dc i1'0' $01 + dc i1'0' $02 + dc i1'0' $03 + dc i1'0' $04 + dc i1'0' $05 + dc i1'0' $06 + dc i1'0' $07 + dc i1'0' $08 + dc i1'_blank' $09 + dc i1'0' $0A + dc i1'0' $0B + dc i1'0' $0C + dc i1'0' $0D + dc i1'0' $0E + dc i1'0' $0F + dc i1'0' $10 + dc i1'0' $11 + dc i1'0' $12 + dc i1'0' $13 + dc i1'0' $14 + dc i1'0' $15 + dc i1'0' $16 + dc i1'0' $17 + dc i1'0' $18 + dc i1'0' $19 + dc i1'0' $1A + dc i1'0' $1B + dc i1'0' $1C + dc i1'0' $1D + dc i1'0' $1E + dc i1'0' $1F + dc i1'_blank' ' ' + dc i1'0' ! + dc i1'0' " + dc i1'0' # + dc i1'0' $ + dc i1'0' % + dc i1'0' & + dc i1'0' ' + dc i1'0' ( + dc i1'0' ) + dc i1'0' * + dc i1'0' + + dc i1'0' , + dc i1'0' - + dc i1'0' . + dc i1'0' / + dc i1'_csym+_octal' 0 + dc i1'_csym+_octal' 1 + dc i1'_csym+_octal' 2 + dc i1'_csym+_octal' 3 + dc i1'_csym+_octal' 4 + dc i1'_csym+_octal' 5 + dc i1'_csym+_octal' 6 + dc i1'_csym+_octal' 7 + dc i1'_csym' 8 + dc i1'_csym' 9 + dc i1'0' : + dc i1'0' ; + dc i1'0' < + dc i1'0' = + dc i1'0' > + dc i1'0' ? + dc i1'0' @ + dc i1'_csym+_csymf' A + dc i1'_csym+_csymf' B + dc i1'_csym+_csymf' C + dc i1'_csym+_csymf' D + dc i1'_csym+_csymf' E + dc i1'_csym+_csymf' F + dc i1'_csym+_csymf' G + dc i1'_csym+_csymf' H + dc i1'_csym+_csymf' I + dc i1'_csym+_csymf' J + dc i1'_csym+_csymf' K + dc i1'_csym+_csymf' L + dc i1'_csym+_csymf' M + dc i1'_csym+_csymf' N + dc i1'_csym+_csymf' O + dc i1'_csym+_csymf' P + dc i1'_csym+_csymf' Q + dc i1'_csym+_csymf' R + dc i1'_csym+_csymf' S + dc i1'_csym+_csymf' T + dc i1'_csym+_csymf' U + dc i1'_csym+_csymf' V + dc i1'_csym+_csymf' W + dc i1'_csym+_csymf' X + dc i1'_csym+_csymf' Y + dc i1'_csym+_csymf' Z + dc i1'0' [ + dc i1'0' \ + dc i1'0' ] + dc i1'0' ^ + dc i1'_csym+_csymf' _ + dc i1'0' ` + dc i1'_csym+_csymf' a + dc i1'_csym+_csymf' b + dc i1'_csym+_csymf' c + dc i1'_csym+_csymf' d + dc i1'_csym+_csymf' e + dc i1'_csym+_csymf' f + dc i1'_csym+_csymf' g + dc i1'_csym+_csymf' h + dc i1'_csym+_csymf' i + dc i1'_csym+_csymf' j + dc i1'_csym+_csymf' k + dc i1'_csym+_csymf' l + dc i1'_csym+_csymf' m + dc i1'_csym+_csymf' n + dc i1'_csym+_csymf' o + dc i1'_csym+_csymf' p + dc i1'_csym+_csymf' q + dc i1'_csym+_csymf' r + dc i1'_csym+_csymf' s + dc i1'_csym+_csymf' t + dc i1'_csym+_csymf' u + dc i1'_csym+_csymf' v + dc i1'_csym+_csymf' w + dc i1'_csym+_csymf' x + dc i1'_csym+_csymf' y + dc i1'_csym+_csymf' z + dc i1'0' { + dc i1'0' | + dc i1'0' } + dc i1'0' ~ + dc i1'0' $7F + dc i1'0' $80 + dc i1'0' $81 + dc i1'0' $82 + dc i1'0' $83 + dc i1'0' $84 + dc i1'0' $85 + dc i1'0' $86 + dc i1'0' $87 + dc i1'0' $88 + dc i1'0' $89 + dc i1'0' $8A + dc i1'0' $8B + dc i1'0' $8C + dc i1'0' $8D + dc i1'0' $8E + dc i1'0' $8F + dc i1'0' $90 + dc i1'0' $91 + dc i1'0' $92 + dc i1'0' $93 + dc i1'0' $94 + dc i1'0' $95 + dc i1'0' $96 + dc i1'0' $97 + dc i1'0' $98 + dc i1'0' $99 + dc i1'0' $9A + dc i1'0' $9B + dc i1'0' $9C + dc i1'0' $9D + dc i1'0' $9E + dc i1'0' $9F + dc i1'0' $A0 + dc i1'0' $A1 + dc i1'0' $A2 + dc i1'0' $A3 + dc i1'0' $A4 + dc i1'0' $A5 + dc i1'0' $A6 + dc i1'0' $A7 + dc i1'0' $A8 + dc i1'0' $A9 + dc i1'0' $AA + dc i1'0' $AB + dc i1'0' $AC + dc i1'0' $AD + dc i1'0' $AE + dc i1'0' $AF + dc i1'0' $B0 + dc i1'0' $B1 + dc i1'0' $B2 + dc i1'0' $B3 + dc i1'0' $B4 + dc i1'0' $B5 + dc i1'0' $B6 + dc i1'0' $B7 + dc i1'0' $B8 + dc i1'0' $B9 + dc i1'0' $BA + dc i1'0' $BB + dc i1'0' $BC + dc i1'0' $BD + dc i1'0' $BE + dc i1'0' $BF + dc i1'0' $C0 + dc i1'0' $C1 + dc i1'0' $C2 + dc i1'0' $C3 + dc i1'0' $C4 + dc i1'0' $C5 + dc i1'0' $C6 + dc i1'0' $C7 + dc i1'0' $C8 + dc i1'0' $C9 + dc i1'0' $CA + dc i1'0' $CB + dc i1'0' $CC + dc i1'0' $CD + dc i1'0' $CE + dc i1'0' $CF + dc i1'0' $D0 + dc i1'0' $D1 + dc i1'0' $D2 + dc i1'0' $D3 + dc i1'0' $D4 + dc i1'0' $D5 + dc i1'0' $D6 + dc i1'0' $D7 + dc i1'0' $D8 + dc i1'0' $D9 + dc i1'0' $DA + dc i1'0' $DB + dc i1'0' $DC + dc i1'0' $DD + dc i1'0' $DE + dc i1'0' $DF + dc i1'0' $E0 + dc i1'0' $E1 + dc i1'0' $E2 + dc i1'0' $E3 + dc i1'0' $E4 + dc i1'0' $E5 + dc i1'0' $E6 + dc i1'0' $E7 + dc i1'0' $E8 + dc i1'0' $E9 + dc i1'0' $EA + dc i1'0' $EB + dc i1'0' $EC + dc i1'0' $ED + dc i1'0' $EE + dc i1'0' $EF + dc i1'0' $F0 + dc i1'0' $F1 + dc i1'0' $F2 + dc i1'0' $F3 + dc i1'0' $F4 + dc i1'0' $F5 + dc i1'0' $F6 + dc i1'0' $F7 + dc i1'0' $F8 + dc i1'0' $F9 + dc i1'0' $FA + dc i1'0' $FB + dc i1'0' $FC + dc i1'0' $FD + dc i1'0' $FE + dc i1'0' $FF + end diff --git a/fpextra.asm b/fpextra.asm index 7698c03..0c24d5e 100644 --- a/fpextra.asm +++ b/fpextra.asm @@ -26,8 +26,8 @@ fpextra private dummy segment ~SinglePrecision start tsc clc - adc #4 - ldy #0 + adc #4 + ldy #0 phy pha phy @@ -53,8 +53,8 @@ fpextra private dummy segment ~DoublePrecision start tsc clc - adc #4 - ldy #0 + adc #4 + ldy #0 phy pha phy @@ -83,19 +83,19 @@ fpextra private dummy segment ~CompPrecision start tsc round to integer clc - adc #4 - pea 0 + adc #4 + pea 0 pha FRINTX - lda 4+8,s + lda 4+8,s pha save original sign - asl a force sign to positive - lsr a - sta 6+8,s + asl a force sign to positive + lsr a + sta 6+8,s tsc limit precision clc - adc #6 - ldy #0 + adc #6 + ldy #0 phy pha phy @@ -107,10 +107,10 @@ fpextra private dummy segment FX2C FC2X pla restore original sign - bpl ret - lda 4+8,s - ora #$8000 - sta 4+8,s + bpl ret + lda 4+8,s + ora #$8000 + sta 4+8,s ret rtl end diff --git a/stdio.asm b/stdio.asm index 4baac3c..9a83e7b 100644 --- a/stdio.asm +++ b/stdio.asm @@ -1,6 +1,6 @@ - keep obj/stdio - mcopy stdio.macros - case on + keep obj/stdio + mcopy stdio.macros + case on **************************************************************** * @@ -19,1268 +19,1268 @@ * **************************************************************** * -StdIO start dummy segment - copy equates.asm +StdIO start dummy segment + copy equates.asm - end + end **************************************************************** * * void clearerr(stream) -* FILE *stream; +* FILE *stream; * * Clears the error flag for the given stream. * * Inputs: -* stream - file to clear +* stream - file to clear * **************************************************************** * clearerr start -stream equ 4 input stream +stream equ 4 input stream - tsc - phd - tcd - ph4 stream verify that stream exists - jsl ~VerifyStream - bcs lb1 - ldy #FILE_flag clear the error flag - lda [stream],Y - and #$FFFF-_IOERR-_IOEOF - sta [stream],Y -lb1 pld - lda 2,S - sta 6,S - pla - sta 3,S - pla - rtl - end + tsc + phd + tcd + ph4 stream verify that stream exists + jsl ~VerifyStream + bcs lb1 + ldy #FILE_flag clear the error flag + lda [stream],Y + and #$FFFF-_IOERR-_IOEOF + sta [stream],Y +lb1 pld + lda 2,S + sta 6,S + pla + sta 3,S + pla + rtl + end **************************************************************** * * int fclose(stream) -* FILE *stream; +* FILE *stream; * * Inputs: -* stream - pointer to the file buffer to close +* stream - pointer to the file buffer to close * * Outputs: -* A - EOF for an error; 0 if there was no error +* A - EOF for an error; 0 if there was no error * **************************************************************** * -fclose start -nameBuffSize equ 8*1024 pathname buffer size +fclose start +nameBuffSize equ 8*1024 pathname buffer size -err equ 1 return value -p equ 3 work pointer -stdfile equ 7 is this a standard file? +err equ 1 return value +p equ 3 work pointer +stdfile equ 7 is this a standard file? - csubroutine (4:stream),8 - phb - phk - plb + csubroutine (4:stream),8 + phb + phk + plb - lda #EOF assume we will get an error - sta err - ph4 stream verify that stream exists - jsl ~VerifyStream - jcs rts + lda #EOF assume we will get an error + sta err + ph4 stream verify that stream exists + jsl ~VerifyStream + jcs rts - ph4 stream do any pending I/O - jsl fflush - tax - jne rts + ph4 stream do any pending I/O + jsl fflush + tax + jne rts - stz stdfile not a standard file - lda stream+2 bypass file disposal if the file is - cmp #^stdin+4 one of the standard ones - bne cl0 - lda stream - cmp #stdin+4 - beq lb1 - cmp #stdout+4 - beq lb1 - cmp #stderr+4 - bne cl0 -lb1 inc stdfile - bra cl3a + stz stdfile not a standard file + lda stream+2 bypass file disposal if the file is + cmp #^stdin+4 one of the standard ones + bne cl0 + lda stream + cmp #stdin+4 + beq lb1 + cmp #stdout+4 + beq lb1 + cmp #stderr+4 + bne cl0 +lb1 inc stdfile + bra cl3a -cl0 lla p,stderr+4 find the file record that points to this - ldy #2 one -cl1 lda [p] - ora [p],Y - jeq rts - lda [p],Y - tax - lda [p] - cmp stream - bne cl2 - cpx stream+2 - beq cl3 -cl2 stx p+2 - sta p - bra cl1 +cl0 lla p,stderr+4 find the file record that points to this + ldy #2 one +cl1 lda [p] + ora [p],Y + jeq rts + lda [p],Y + tax + lda [p] + cmp stream + bne cl2 + cpx stream+2 + beq cl3 +cl2 stx p+2 + sta p + bra cl1 -cl3 lda [stream] remove stream from the file list - sta [p] - lda [stream],Y - sta [p],Y -cl3a ldy #FILE_flag if the file was opened by tmpfile then - lda [stream],Y - and #_IOTEMPFILE - beq cl3d - ph4 #nameBuffSize p = malloc(nameBuffSize) - jsl malloc grPathname = p - sta p dsPathname = p+2 - stx p+2 - sta grPathname - stx grPathname+2 - clc - adc #2 - bcc cl3b - inx -cl3b sta dsPathname - stx dsPathname+2 - lda #nameBuffSize p->size = nameBuffSize - sta [p] - ldy #FILE_file clRefnum = grRefnum = stream->_file - lda [stream],Y - beq cl3e - sta grRefnum - GetRefInfoGS gr GetRefInfoGS(gr) - bcs cl3c - lda grRefnum OSClose(cl) - sta clRefNum - OSClose cl - DestroyGS ds DestroyGS(ds) -cl3c ph4 p free(p) - jsl free - bra cl3e else -cl3d ldy #FILE_file close the file - lda [stream],Y - beq cl3e - sta clRefNum - OSClose cl -cl3e ldy #FILE_flag if the buffer was allocated by fopen then - lda [stream],Y - and #_IOMYBUF - beq cl4 - ldy #FILE_base+2 dispose of the file buffer - lda [stream],Y - pha - dey - dey - lda [stream],Y - pha - jsl free -cl4 lda stdfile if this is not a standard file then - bne cl5 - ph4 stream dispose of the file buffer - jsl free - bra cl7 else -cl5 add4 stream,#sizeofFILE-4,p reset the standard out stuff - ldy #sizeofFILE-2 -cl6 lda [p],Y - sta [stream],Y - dey - dey - cpy #2 - bne cl6 -cl7 stz err no error found -rts plb - creturn 2:err +cl3 lda [stream] remove stream from the file list + sta [p] + lda [stream],Y + sta [p],Y +cl3a ldy #FILE_flag if the file was opened by tmpfile then + lda [stream],Y + and #_IOTEMPFILE + beq cl3d + ph4 #nameBuffSize p = malloc(nameBuffSize) + jsl malloc grPathname = p + sta p dsPathname = p+2 + stx p+2 + sta grPathname + stx grPathname+2 + clc + adc #2 + bcc cl3b + inx +cl3b sta dsPathname + stx dsPathname+2 + lda #nameBuffSize p->size = nameBuffSize + sta [p] + ldy #FILE_file clRefnum = grRefnum = stream->_file + lda [stream],Y + beq cl3e + sta grRefnum + GetRefInfoGS gr GetRefInfoGS(gr) + bcs cl3c + lda grRefnum OSClose(cl) + sta clRefNum + OSClose cl + DestroyGS ds DestroyGS(ds) +cl3c ph4 p free(p) + jsl free + bra cl3e else +cl3d ldy #FILE_file close the file + lda [stream],Y + beq cl3e + sta clRefNum + OSClose cl +cl3e ldy #FILE_flag if the buffer was allocated by fopen then + lda [stream],Y + and #_IOMYBUF + beq cl4 + ldy #FILE_base+2 dispose of the file buffer + lda [stream],Y + pha + dey + dey + lda [stream],Y + pha + jsl free +cl4 lda stdfile if this is not a standard file then + bne cl5 + ph4 stream dispose of the file buffer + jsl free + bra cl7 else +cl5 add4 stream,#sizeofFILE-4,p reset the standard out stuff + ldy #sizeofFILE-2 +cl6 lda [p],Y + sta [stream],Y + dey + dey + cpy #2 + bne cl6 +cl7 stz err no error found +rts plb + creturn 2:err -cl dc i'1' parameter block for OSclose -clRefNum ds 2 +cl dc i'1' parameter block for OSclose +clRefNum ds 2 -gr dc i'3' parameter block for GetRefInfoGS -grRefnum ds 2 - ds 2 -grPathname ds 4 +gr dc i'3' parameter block for GetRefInfoGS +grRefnum ds 2 + ds 2 +grPathname ds 4 -ds dc i'1' parameter block for DestroyGS -dsPathname ds 4 - end +ds dc i'1' parameter block for DestroyGS +dsPathname ds 4 + end **************************************************************** * * int feof(stream) -* FILE *stream; +* FILE *stream; * * Inputs: -* stream - file to check +* stream - file to check * * Outputs: -* Returns _IOEOF if an end of file has been reached; else -* 0. +* Returns _IOEOF if an end of file has been reached; else +* 0. * **************************************************************** * -feof start -stream equ 4 input stream +feof start +stream equ 4 input stream - tsc - phd - tcd - ph4 stream verify that stream exists - jsl ~VerifyStream - ldx #_IOEOF - bcs lb1 - ldy #FILE_flag check for eof - lda [stream],Y - and #_IOEOF - tax -lb1 pld - lda 2,S - sta 6,S - pla - sta 3,S - pla - txa - rtl - end + tsc + phd + tcd + ph4 stream verify that stream exists + jsl ~VerifyStream + ldx #_IOEOF + bcs lb1 + ldy #FILE_flag check for eof + lda [stream],Y + and #_IOEOF + tax +lb1 pld + lda 2,S + sta 6,S + pla + sta 3,S + pla + txa + rtl + end **************************************************************** * * int ferror(stream) -* FILE *stream; +* FILE *stream; * * Inputs: -* stream - file to check +* stream - file to check * * Outputs: -* Returns _IOERR if an end of file has been reached; else -* 0. +* Returns _IOERR if an end of file has been reached; else +* 0. * **************************************************************** * -ferror start -stream equ 4 input stream +ferror start +stream equ 4 input stream - tsc - phd - tcd - ph4 stream verify that stream exists - jsl ~VerifyStream - ldx #_IOERR - bcs lb1 - ldy #FILE_flag return the error status - lda [stream],Y - and #_IOERR - tax -lb1 pld - lda 2,S - sta 6,S - pla - sta 3,S - pla - txa - rtl - end + tsc + phd + tcd + ph4 stream verify that stream exists + jsl ~VerifyStream + ldx #_IOERR + bcs lb1 + ldy #FILE_flag return the error status + lda [stream],Y + and #_IOERR + tax +lb1 pld + lda 2,S + sta 6,S + pla + sta 3,S + pla + txa + rtl + end **************************************************************** * * int fflush(steam) -* FILE *stream; +* FILE *stream; * * Write any pending characters to the output file * * Inputs: -* stream - file buffer +* stream - file buffer * * Outputs: -* A - EOF for an error; 0 if there was no error +* A - EOF for an error; 0 if there was no error * **************************************************************** * -fflush start -err equ 1 return value -sp equ 3 stream work pointer +fflush start +err equ 1 return value +sp equ 3 stream work pointer - csubroutine (4:stream),6 - phb - phk - plb + csubroutine (4:stream),6 + phb + phk + plb - lda stream if stream = nil then - ora stream+2 - bne fa3 - lda stderr+4 sp = stderr.next - sta sp - lda stderr+6 - sta sp+2 - stz err err = 0 -fa1 lda sp while sp <> nil - ora sp+2 - jeq rts - ph4 sp fflush(sp); - jsl fflush - tax if returned value <> 0 then - beq fa2 - sta err err = returned value -fa2 ldy #2 sp = sp^.next - lda [sp],Y - tax - lda [sp] - sta sp - stx sp+2 - bra fa1 endwhile + lda stream if stream = nil then + ora stream+2 + bne fa3 + lda stderr+4 sp = stderr.next + sta sp + lda stderr+6 + sta sp+2 + stz err err = 0 +fa1 lda sp while sp <> nil + ora sp+2 + jeq rts + ph4 sp fflush(sp); + jsl fflush + tax if returned value <> 0 then + beq fa2 + sta err err = returned value +fa2 ldy #2 sp = sp^.next + lda [sp],Y + tax + lda [sp] + sta sp + stx sp+2 + bra fa1 endwhile -fa3 lda #EOF assume there is an error - sta err - ph4 stream verify that stream exists - jsl ~VerifyStream - jcs rts - ldy #FILE_flag if the mode is not writing, quit - lda [stream],Y - and #_IOWRT - beq fl1 - ldy #FILE_file set the reference number - lda [stream],Y - sta wrRefNum - ldy #FILE_base set the starting location - lda [stream],Y - sta wrDataBuffer - iny - iny - lda [stream],Y - sta wrDataBuffer+2 - sec set the # of bytes to write - ldy #FILE_ptr - lda [stream],Y - sbc wrDataBuffer - sta wrRequestCount - iny - iny - lda [stream],Y - sbc wrDataBuffer+2 - sta wrRequestCount+2 - ora wrRequestCount skip the write if there are no - beq fl1 characters - OSwrite wr write the info - bcc fl1 - ph4 stream - jsr ~ioerror - bra rts +fa3 lda #EOF assume there is an error + sta err + ph4 stream verify that stream exists + jsl ~VerifyStream + jcs rts + ldy #FILE_flag if the mode is not writing, quit + lda [stream],Y + and #_IOWRT + beq fl1 + ldy #FILE_file set the reference number + lda [stream],Y + sta wrRefNum + ldy #FILE_base set the starting location + lda [stream],Y + sta wrDataBuffer + iny + iny + lda [stream],Y + sta wrDataBuffer+2 + sec set the # of bytes to write + ldy #FILE_ptr + lda [stream],Y + sbc wrDataBuffer + sta wrRequestCount + iny + iny + lda [stream],Y + sbc wrDataBuffer+2 + sta wrRequestCount+2 + ora wrRequestCount skip the write if there are no + beq fl1 characters + OSwrite wr write the info + bcc fl1 + ph4 stream + jsr ~ioerror + bra rts -fl1 ldy #FILE_flag if the file is open for read/write then - lda [stream],Y - bit #_IORW - beq fl3 - bit #_IOREAD if the file is being read then - beq fl2 - ph4 stream use ftell to set the mark - jsl ftell - ldy #FILE_flag - lda [stream],Y -fl2 and #$FFFF-_IOWRT-_IOREAD turn off the reading and writing flags - sta [stream],Y -fl3 ph4 stream prepare file for output - jsl ~InitBuffer - stz err no error found -rts plb - creturn 2:err +fl1 ldy #FILE_flag if the file is open for read/write then + lda [stream],Y + bit #_IORW + beq fl3 + bit #_IOREAD if the file is being read then + beq fl2 + ph4 stream use ftell to set the mark + jsl ftell + ldy #FILE_flag + lda [stream],Y +fl2 and #$FFFF-_IOWRT-_IOREAD turn off the reading and writing flags + sta [stream],Y +fl3 ph4 stream prepare file for output + jsl ~InitBuffer + stz err no error found +rts plb + creturn 2:err -wr dc i'5' parameter block for OSwrite -wrRefNum ds 2 +wr dc i'5' parameter block for OSwrite +wrRefNum ds 2 wrDataBuffer ds 4 wrRequestCount ds 4 - ds 4 - dc i'1' - end + ds 4 + dc i'1' + end **************************************************************** * * int fgetc(stream) -* FILE *stream; +* FILE *stream; * * Read a character from a file * * Inputs: -* stream - file to read from +* stream - file to read from * * Outputs: -* A - character read; EOF for an error +* A - character read; EOF for an error * **************************************************************** * -fgetc start -getc entry +fgetc start +getc entry -c equ 1 character read -p equ 3 work pointer +c equ 1 character read +p equ 3 work pointer - csubroutine (4:stream),6 - phb - phk - plb + csubroutine (4:stream),6 + phb + phk + plb - ph4 stream verify that stream exists - jsl ~VerifyStream - bcs lb0 - ldy #FILE_flag quit with error if the end of file - lda [stream],Y has been reached or an error has been - and #_IOEOF+_IOERR encountered - beq lb1 -lb0 lda #EOF - sta c - brl gc9 + ph4 stream verify that stream exists + jsl ~VerifyStream + bcs lb0 + ldy #FILE_flag quit with error if the end of file + lda [stream],Y has been reached or an error has been + and #_IOEOF+_IOERR encountered + beq lb1 +lb0 lda #EOF + sta c + brl gc9 -lb1 ldy #FILE_pbk if there is a char in the putback buffer - lda [stream],Y - and #$0080 - bne lb2 - lda [stream],Y return it - and #$00FF - sta c - lda [stream],Y pop the putback buffer - xba - ora #$FF00 - sta [stream],Y - brl gc9 +lb1 ldy #FILE_pbk if there is a char in the putback buffer + lda [stream],Y + and #$0080 + bne lb2 + lda [stream],Y return it + and #$00FF + sta c + lda [stream],Y pop the putback buffer + xba + ora #$FF00 + sta [stream],Y + brl gc9 -lb2 ldy #FILE_file branch if this is a disk file - lda [stream],Y - bpl gc2 +lb2 ldy #FILE_file branch if this is a disk file + lda [stream],Y + bpl gc2 - cmp #stdinID if stream = stdin then - bne gc1 - jsl SYSKEYIN get a character - tax branch if not eof - bne st1 - lda #_IOEOF set EOF flag - ora >stdin+4+FILE_flag - sta >stdin+4+FILE_flag - jsl SYSKEYIN read the closing cr - lda #EOF return EOF -st1 sta c - brl gc9 + cmp #stdinID if stream = stdin then + bne gc1 + jsl SYSKEYIN get a character + tax branch if not eof + bne st1 + lda #_IOEOF set EOF flag + ora >stdin+4+FILE_flag + sta >stdin+4+FILE_flag + jsl SYSKEYIN read the closing cr + lda #EOF return EOF +st1 sta c + brl gc9 -gc1 ph4 stream else flag the error - jsr ~ioerror - lda #EOF - sta c - brl gc9 +gc1 ph4 stream else flag the error + jsr ~ioerror + lda #EOF + sta c + brl gc9 -gc2 ldy #FILE_flag if the file is not read enabled then - lda [stream],Y - bit #_IOREAD - bne gc2a - bit #_IOWRT it is an error if it is write enabled - bne gc1 - bra gc2b -gc2a ldy #FILE_cnt we're ready if there are characters - lda [stream],Y left - iny - iny - ora [stream],Y - jne gc8 +gc2 ldy #FILE_flag if the file is not read enabled then + lda [stream],Y + bit #_IOREAD + bne gc2a + bit #_IOWRT it is an error if it is write enabled + bne gc1 + bra gc2b +gc2a ldy #FILE_cnt we're ready if there are characters + lda [stream],Y left + iny + iny + ora [stream],Y + jne gc8 -gc2b ldy #FILE_flag if input is unbuffered then - lda [stream],Y - bit #_IONBF - beq gc3 - stz rdDataBuffer+2 set up to read one char to c - tdc - clc - adc #c - sta rdDataBuffer - lla rdRequestCount,1 - bra gc4 -gc3 ldy #FILE_base else set up to read a buffer full - lda [stream],Y - sta rdDataBuffer - iny - iny - lda [stream],Y - sta rdDataBuffer+2 - ldy #FILE_size - lda [stream],Y - sta rdRequestCount - iny - iny - lda [stream],Y - sta rdRequestCount+2 -gc4 ldy #FILE_file set the file reference number - lda [stream],Y - sta rdRefNum - OSRead rd read the data - bcc gc7 if there was a read error then - ldy #FILE_flag - cmp #$4C if it was eof then - bne gc5 - lda #_IOEOF set the EOF flag - bra gc6 else -gc5 lda #_IOERR set the error flag -gc6 ora [stream],Y - sta [stream],Y - lda #EOF return EOF - sta c - brl gc9 +gc2b ldy #FILE_flag if input is unbuffered then + lda [stream],Y + bit #_IONBF + beq gc3 + stz rdDataBuffer+2 set up to read one char to c + tdc + clc + adc #c + sta rdDataBuffer + lla rdRequestCount,1 + bra gc4 +gc3 ldy #FILE_base else set up to read a buffer full + lda [stream],Y + sta rdDataBuffer + iny + iny + lda [stream],Y + sta rdDataBuffer+2 + ldy #FILE_size + lda [stream],Y + sta rdRequestCount + iny + iny + lda [stream],Y + sta rdRequestCount+2 +gc4 ldy #FILE_file set the file reference number + lda [stream],Y + sta rdRefNum + OSRead rd read the data + bcc gc7 if there was a read error then + ldy #FILE_flag + cmp #$4C if it was eof then + bne gc5 + lda #_IOEOF set the EOF flag + bra gc6 else +gc5 lda #_IOERR set the error flag +gc6 ora [stream],Y + sta [stream],Y + lda #EOF return EOF + sta c + brl gc9 -gc7 ldy #FILE_flag we're done if the read is unbuffered - lda [stream],Y - and #_IONBF - jne gc9 - clc set the end of the file buffer - ldy #FILE_end - lda rdDataBuffer - adc rdTransferCount - sta [stream],Y - iny - iny - lda rdDataBuffer+2 - adc rdTransferCount+2 - sta [stream],Y - ldy #FILE_base reset the file pointer - lda [stream],Y - tax - iny - iny - lda [stream],Y - ldy #FILE_ptr+2 - sta [stream],Y - dey - dey - txa - sta [stream],Y - ldy #FILE_cnt set the # chars in the buffer - lda rdTransferCount - sta [stream],Y - iny - iny - lda rdTransferCount+2 - sta [stream],Y - ldy #FILE_flag note that the file is read enabled - lda [stream],Y - ora #_IOREAD - sta [stream],Y +gc7 ldy #FILE_flag we're done if the read is unbuffered + lda [stream],Y + and #_IONBF + jne gc9 + clc set the end of the file buffer + ldy #FILE_end + lda rdDataBuffer + adc rdTransferCount + sta [stream],Y + iny + iny + lda rdDataBuffer+2 + adc rdTransferCount+2 + sta [stream],Y + ldy #FILE_base reset the file pointer + lda [stream],Y + tax + iny + iny + lda [stream],Y + ldy #FILE_ptr+2 + sta [stream],Y + dey + dey + txa + sta [stream],Y + ldy #FILE_cnt set the # chars in the buffer + lda rdTransferCount + sta [stream],Y + iny + iny + lda rdTransferCount+2 + sta [stream],Y + ldy #FILE_flag note that the file is read enabled + lda [stream],Y + ora #_IOREAD + sta [stream],Y -gc8 ldy #FILE_ptr get the next character - lda [stream],Y - sta p - clc - adc #1 - sta [stream],Y - iny - iny - lda [stream],Y - sta p+2 - adc #0 - sta [stream],Y - lda [p] - and #$00FF - sta c - ldy #FILE_cnt dec the # chars in the buffer - sec - lda [stream],Y - sbc #1 - sta [stream],Y - bcs gc8a - iny - iny - lda [stream],Y - dec A - sta [stream],Y +gc8 ldy #FILE_ptr get the next character + lda [stream],Y + sta p + clc + adc #1 + sta [stream],Y + iny + iny + lda [stream],Y + sta p+2 + adc #0 + sta [stream],Y + lda [p] + and #$00FF + sta c + ldy #FILE_cnt dec the # chars in the buffer + sec + lda [stream],Y + sbc #1 + sta [stream],Y + bcs gc8a + iny + iny + lda [stream],Y + dec A + sta [stream],Y -gc8a ldy #FILE_flag if the file is read/write - lda [stream],Y - and #_IORW - beq gc9 - ldy #FILE_cnt and the buffer is empty then - lda [stream],Y - iny - iny - ora [stream],Y - bne gc9 - ldy #FILE_flag note that no chars are left - lda [stream],Y - eor #_IOREAD - sta [stream],Y +gc8a ldy #FILE_flag if the file is read/write + lda [stream],Y + and #_IORW + beq gc9 + ldy #FILE_cnt and the buffer is empty then + lda [stream],Y + iny + iny + ora [stream],Y + bne gc9 + ldy #FILE_flag note that no chars are left + lda [stream],Y + eor #_IOREAD + sta [stream],Y -gc9 lda c if c = \r then - cmp #13 - bne gc10 - ldy #FILE_flag if this is a text file then - lda [stream],Y - and #_IOTEXT - beq gc10 - lda #10 - sta c +gc9 lda c if c = \r then + cmp #13 + bne gc10 + ldy #FILE_flag if this is a text file then + lda [stream],Y + and #_IOTEXT + beq gc10 + lda #10 + sta c -gc10 plb - creturn 2:c +gc10 plb + creturn 2:c ; ; Local data ; -rd dc i'4' parameter block for OSRead -rdRefNum ds 2 +rd dc i'4' parameter block for OSRead +rdRefNum ds 2 rdDataBuffer ds 4 rdRequestCount ds 4 rdTransferCount ds 4 - dc i'1' cache priority - end + dc i'1' cache priority + end **************************************************************** * * char *fgets(s, n, stream) -* char *s; -* int n; -* FILE *stream; +* char *s; +* int n; +* FILE *stream; * * Reads a line into the string s. * * Inputs: -* s - location to put the string read. -* n - size of the string -* stream - file to read from +* s - location to put the string read. +* n - size of the string +* stream - file to read from * * Outputs: -* Returns NULL if an EOF is encountered, placing any -* characters read before the EOF into s. Returns S if -* a line or part of a line is read. +* Returns NULL if an EOF is encountered, placing any +* characters read before the EOF into s. Returns S if +* a line or part of a line is read. * **************************************************************** * -fgets start -RETURN equ 13 RETURN key code -LF equ 10 newline +fgets start +RETURN equ 13 RETURN key code +LF equ 10 newline -disp equ 1 disp in s +disp equ 1 disp in s - csubroutine (4:s,2:n,4:stream),2 + csubroutine (4:s,2:n,4:stream),2 - ph4 stream verify that stream exists - jsl ~VerifyStream - bcs err1 - ph4 stream quit with NULL if at EOF - jsl feof - tax - beq lb0 -err1 stz s - stz s+2 - bra rts -lb0 stz disp no characters processed so far - lda #0 - sta [s] - dec n leave room for the null terminator - bmi err - beq err -lb1 ph4 stream get a character - jsl fgetc - tax quit with error if it is an EOF - bpl lb2 -err stz s - stz s+2 - bra rts -lb2 cmp #RETURN if the char is a return, switch to lf - bne lb3 - lda #LF -lb3 ldy disp place the char in the string - sta [s],Y (null terminates automatically) - inc disp - cmp #LF quit if it was an LF - beq rts - dec n next character - bne lb1 -rts creturn 4:s - end + ph4 stream verify that stream exists + jsl ~VerifyStream + bcs err1 + ph4 stream quit with NULL if at EOF + jsl feof + tax + beq lb0 +err1 stz s + stz s+2 + bra rts +lb0 stz disp no characters processed so far + lda #0 + sta [s] + dec n leave room for the null terminator + bmi err + beq err +lb1 ph4 stream get a character + jsl fgetc + tax quit with error if it is an EOF + bpl lb2 +err stz s + stz s+2 + bra rts +lb2 cmp #RETURN if the char is a return, switch to lf + bne lb3 + lda #LF +lb3 ldy disp place the char in the string + sta [s],Y (null terminates automatically) + inc disp + cmp #LF quit if it was an LF + beq rts + dec n next character + bne lb1 +rts creturn 4:s + end **************************************************************** * * int fgetpos(FILE *stream, fpos_t *pos); * * Inputs: -* stream - pointer to stream to get position of -* pos - pointer to location to place position +* stream - pointer to stream to get position of +* pos - pointer to location to place position * * Outputs: -* A - 0 if successful; else -1 if not -* errno - if unsuccessful, errno is set to EIO +* A - 0 if successful; else -1 if not +* errno - if unsuccessful, errno is set to EIO * **************************************************************** * -fgetpos start -err equ 1 error code +fgetpos start +err equ 1 error code - csubroutine (4:stream,4:pos),2 + csubroutine (4:stream,4:pos),2 - ph4 stream get the position - jsl ftell - cmp #-1 if the position = -1 then - bne lb1 - cpx #-1 - bne lb1 - sta err err = -1 - bra lb2 return -lb1 sta [pos] else - txa *pos = position - ldy #2 - sta [pos],Y - stz err err = 0 -lb2 anop endif + ph4 stream get the position + jsl ftell + cmp #-1 if the position = -1 then + bne lb1 + cpx #-1 + bne lb1 + sta err err = -1 + bra lb2 return +lb1 sta [pos] else + txa *pos = position + ldy #2 + sta [pos],Y + stz err err = 0 +lb2 anop endif - creturn 2:err - end + creturn 2:err + end **************************************************************** * * FILE *fopen(filename, type) -* char *filename, *type; +* char *filename, *type; * * Inputs: -* filename - pointer to the file name -* type - pointer to the type string +* filename - pointer to the file name +* type - pointer to the type string * * Outputs: -* X-A - pointer to the file variable; NULL for an error +* X-A - pointer to the file variable; NULL for an error * **************************************************************** * -fopen start -BIN equ 6 file type for BIN files -TXT equ 4 file type for TXT files +fopen start +BIN equ 6 file type for BIN files +TXT equ 4 file type for TXT files -fileType equ 1 file type letter -fileBuff equ 3 pointer to the file buffer -buffStart equ 7 start of the file buffer -OSname equ 11 pointer to the GS/OS file name +fileType equ 1 file type letter +fileBuff equ 3 pointer to the file buffer +buffStart equ 7 start of the file buffer +OSname equ 11 pointer to the GS/OS file name ; ; initialization ; - csubroutine (4:filename,4:type),14 + csubroutine (4:filename,4:type),14 - phb use our data bank - phk - plb + phb use our data bank + phk + plb - stz fileBuff no file so far - stz fileBuff+2 + stz fileBuff no file so far + stz fileBuff+2 - lda [type] make sure the file type is in ['a','r','w'] - and #$00FF - sta fileType - ldx #$0002 - cmp #'a' - beq cn1 - cmp #'w' - beq cn1 - ldx #$0001 - cmp #'r' - beq cn1 - lda #EINVAL - sta >errno - brl rt2 + lda [type] make sure the file type is in ['a','r','w'] + and #$00FF + sta fileType + ldx #$0002 + cmp #'a' + beq cn1 + cmp #'w' + beq cn1 + ldx #$0001 + cmp #'r' + beq cn1 + lda #EINVAL + sta >errno + brl rt2 ; ; create a GS/OS file name ; -cn1 stx opAccess set the access flags - ph4 filename get the length of the name buffer - jsl ~osname - sta OSname - stx OSname+2 - ora OSname+2 - jeq rt2 - move4 OSname,opName +cn1 stx opAccess set the access flags + ph4 filename get the length of the name buffer + jsl ~osname + sta OSname + stx OSname+2 + ora OSname+2 + jeq rt2 + move4 OSname,opName ; ; check for file modifier characters + and b ; - lda #TXT we must open a new file - determine it's - sta crFileType type by looking for the 'b' designator - ldy #1 - lda [type],Y - jsr Modifier - bcc cm1 - lda [type],Y - jsr Modifier - bcc cm1 - lda fileType if mode is 'w' or 'a' - cmp #'r' - beq cm1 - lda [type],Y check for 'x' in type string - and #$00FF - cmp #'x' - beq of1 -cm1 anop + lda #TXT we must open a new file - determine it's + sta crFileType type by looking for the 'b' designator + ldy #1 + lda [type],Y + jsr Modifier + bcc cm1 + lda [type],Y + jsr Modifier + bcc cm1 + lda fileType if mode is 'w' or 'a' + cmp #'r' + beq cm1 + lda [type],Y check for 'x' in type string + and #$00FF + cmp #'x' + beq of1 +cm1 anop ; ; open the file ; - OSopen op try to open an existing file - bcc of2 + OSopen op try to open an existing file + bcc of2 - lda fileType if the type is 'r', flag an error - cmp #'r' - bne of1 - lda #ENOENT - sta >errno - brl rt1 + lda fileType if the type is 'r', flag an error + cmp #'r' + bne of1 + lda #ENOENT + sta >errno + brl rt1 -of1 move4 OSname,crPathName create the file - OScreate cr - bcs of1a - OSopen op open the file - bcc of2 -of1a cmp #$0047 check for dupPathname error=>file exists - bne errEIO - lda #EEXIST - bra err1 -errEIO lda #EIO -err1 sta >errno - brl rt1 +of1 move4 OSname,crPathName create the file + OScreate cr + bcs of1a + OSopen op open the file + bcc of2 +of1a cmp #$0047 check for dupPathname error=>file exists + bne errEIO + lda #EEXIST + bra err1 +errEIO lda #EIO +err1 sta >errno + brl rt1 -of2 lda fileType if the file type is 'w' then - cmp #'w' - bne of3 - lda opRefNum reset it - sta efRefNum - OSSet_EOF ef - bcc ar1 allow "not a block device error" - cmp #$0058 - beq ar1 - bra errEIO flag the error -of3 cmp #'a' else if the file type is 'a' then - bne ar1 - lda opRefNum - sta gfRefNum - sta smRefNum - OSGet_EOF gf append to it - bcs errEIO - move4 gfEOF,smDisplacement - OSSet_Mark sm - bcs errEIO +of2 lda fileType if the file type is 'w' then + cmp #'w' + bne of3 + lda opRefNum reset it + sta efRefNum + OSSet_EOF ef + bcc ar1 allow "not a block device error" + cmp #$0058 + beq ar1 + bra errEIO flag the error +of3 cmp #'a' else if the file type is 'a' then + bne ar1 + lda opRefNum + sta gfRefNum + sta smRefNum + OSGet_EOF gf append to it + bcs errEIO + move4 gfEOF,smDisplacement + OSSet_Mark sm + bcs errEIO ; ; allocate and fill in the file record ; -ar1 ph4 #sizeofFILE get space for the file record - jsl malloc - sta fileBuff - stx fileBuff+2 - ora fileBuff+2 - beq ar2 - ph4 #BUFSIZ get space for the file buffer - jsl malloc - sta buffStart - stx buffStart+2 - ora buffStart+2 - bne ar3 - ph4 fileBuff memory error - jsl free -ar2 lda #ENOMEM - sta >errno - brl rt1 +ar1 ph4 #sizeofFILE get space for the file record + jsl malloc + sta fileBuff + stx fileBuff+2 + ora fileBuff+2 + beq ar2 + ph4 #BUFSIZ get space for the file buffer + jsl malloc + sta buffStart + stx buffStart+2 + ora buffStart+2 + bne ar3 + ph4 fileBuff memory error + jsl free +ar2 lda #ENOMEM + sta >errno + brl rt1 -ar3 ldy #2 insert the record right after stderr - lda >stderr+4 - sta [fileBuff] - lda >stderr+6 - sta [fileBuff],Y - lda fileBuff - sta >stderr+4 - lda fileBuff+2 - sta >stderr+6 - lda buffStart set the start of the buffer - ldy #FILE_base - sta [fileBuff],Y - iny - iny - lda buffStart+2 - sta [fileBuff],Y - ldy #FILE_ptr+2 - sta [fileBuff],Y - dey - dey - lda buffStart - sta [fileBuff],Y - ldy #FILE_size set the buffer size - lda #BUFSIZ - sta [fileBuff],Y - iny - iny - lda #^BUFSIZ - sta [fileBuff],Y - ldy #1 set the flags - lda [type],Y - and #$00FF - cmp #'+' - beq ar3a - cmp #'b' - bne ar4 - iny - lda [type],Y - and #$00FF - cmp #'+' - bne ar4 -ar3a lda #_IOFBF+_IORW+_IOMYBUF - bra ar6 -ar4 lda fileType - cmp #'r' - beq ar5 - lda #_IOFBF+_IOWRT+_IOMYBUF - bra ar6 -ar5 lda #_IOFBF+_IOREAD+_IOMYBUF -ar6 ldy #FILE_flag - ldx crFileType - cpx #BIN - beq ar6a - ora #_IOTEXT -ar6a sta [fileBuff],Y - ldy #FILE_cnt no chars in buffer - lda #0 - sta [fileBuff],Y - iny - iny - sta [fileBuff],Y - ldy #FILE_pbk nothing in the putback buffer - lda #$FFFF - sta [fileBuff],Y - ldy #FILE_file set the file ID - lda opRefNum - sta [fileBuff],Y +ar3 ldy #2 insert the record right after stderr + lda >stderr+4 + sta [fileBuff] + lda >stderr+6 + sta [fileBuff],Y + lda fileBuff + sta >stderr+4 + lda fileBuff+2 + sta >stderr+6 + lda buffStart set the start of the buffer + ldy #FILE_base + sta [fileBuff],Y + iny + iny + lda buffStart+2 + sta [fileBuff],Y + ldy #FILE_ptr+2 + sta [fileBuff],Y + dey + dey + lda buffStart + sta [fileBuff],Y + ldy #FILE_size set the buffer size + lda #BUFSIZ + sta [fileBuff],Y + iny + iny + lda #^BUFSIZ + sta [fileBuff],Y + ldy #1 set the flags + lda [type],Y + and #$00FF + cmp #'+' + beq ar3a + cmp #'b' + bne ar4 + iny + lda [type],Y + and #$00FF + cmp #'+' + bne ar4 +ar3a lda #_IOFBF+_IORW+_IOMYBUF + bra ar6 +ar4 lda fileType + cmp #'r' + beq ar5 + lda #_IOFBF+_IOWRT+_IOMYBUF + bra ar6 +ar5 lda #_IOFBF+_IOREAD+_IOMYBUF +ar6 ldy #FILE_flag + ldx crFileType + cpx #BIN + beq ar6a + ora #_IOTEXT +ar6a sta [fileBuff],Y + ldy #FILE_cnt no chars in buffer + lda #0 + sta [fileBuff],Y + iny + iny + sta [fileBuff],Y + ldy #FILE_pbk nothing in the putback buffer + lda #$FFFF + sta [fileBuff],Y + ldy #FILE_file set the file ID + lda opRefNum + sta [fileBuff],Y ; ; return the result ; -rt1 ph4 OSname dispose of the file name buffer - jsl free -rt2 plb restore caller's data bank - creturn 4:fileBuff return +rt1 ph4 OSname dispose of the file name buffer + jsl free +rt2 plb restore caller's data bank + creturn 4:fileBuff return ; ; Modifier - local subroutine to check modifier character ; ; Returns: C=0 if no modifier found, else C=1 ; -Modifier and #$00FF - beq md3 - cmp #'+' - bne md1 - lda #$0003 - sta opAccess - iny - sec - rts -md1 cmp #'b' - bne md2 - lda #BIN - sta crFileType - iny -md2 sec - rts +Modifier and #$00FF + beq md3 + cmp #'+' + bne md1 + lda #$0003 + sta opAccess + iny + sec + rts +md1 cmp #'b' + bne md2 + lda #BIN + sta crFileType + iny +md2 sec + rts -md3 clc - rts +md3 clc + rts ; ; local data areas ; -op dc i'3' parameter block for OSopen -opRefNum ds 2 -opName ds 4 -opAccess ds 2 +op dc i'3' parameter block for OSopen +opRefNum ds 2 +opName ds 4 +opAccess ds 2 -gf dc i'2' GetEOF record -gfRefNum ds 2 -gfEOF ds 4 +gf dc i'2' GetEOF record +gfRefNum ds 2 +gfEOF ds 4 -sm dc i'3' SetMark record -smRefNum ds 2 -smBase dc i'0' +sm dc i'3' SetMark record +smRefNum ds 2 +smBase dc i'0' smDisplacement ds 4 -ef dc i'3' parameter block for OSSet_EOF -efRefNum ds 2 - dc i'0' - dc i4'0' +ef dc i'3' parameter block for OSSet_EOF +efRefNum ds 2 + dc i'0' + dc i4'0' -cr dc i'7' parameter block for OScreate -crPathName ds 4 - dc i'$C3' -crFileType ds 2 - dc i4'0' - dc i'1' - dc i4'0' - dc i4'0' - dc r'fgetc' - dc r'fputc' - dc r'fclose' - end +cr dc i'7' parameter block for OScreate +crPathName ds 4 + dc i'$C3' +crFileType ds 2 + dc i4'0' + dc i'1' + dc i4'0' + dc i4'0' + dc r'fgetc' + dc r'fputc' + dc r'fclose' + end **************************************************************** * * FILE *freopen(filename, type, stream) -* char *filename, *type; -* FILE *stream; +* char *filename, *type; +* FILE *stream; * * Inputs: -* filename - pointer to the file name -* type - pointer to the type string -* stream - file buffer to use +* filename - pointer to the file name +* type - pointer to the type string +* stream - file buffer to use * * Outputs: -* X-A - pointer to the file variable; NULL for an error +* X-A - pointer to the file variable; NULL for an error * **************************************************************** * -freopen start -BIN equ 6 file type for BIN files -TXT equ 4 file type for TXT files +freopen start +BIN equ 6 file type for BIN files +TXT equ 4 file type for TXT files -fileType equ 1 file type letter -buffStart equ 3 start of the file buffer -OSname equ 7 pointer to the GS/OS file name -fileBuff equ 11 file buffer to return +fileType equ 1 file type letter +buffStart equ 3 start of the file buffer +OSname equ 7 pointer to the GS/OS file name +fileBuff equ 11 file buffer to return ; ; initialization ; - csubroutine (4:filename,4:type,4:stream),14 + csubroutine (4:filename,4:type,4:stream),14 - phb use our data bank - phk - plb + phb use our data bank + phk + plb - stz fileBuff the open is not legal, yet - stz fileBuff+2 + stz fileBuff the open is not legal, yet + stz fileBuff+2 - ph4 stream verify that stream exists - jsl ~VerifyStream - jcs rt2 - lda [type] make sure the file type is in ['a','r','w'] - and #$00FF - sta fileType - cmp #'a' - beq cl1 - cmp #'w' - beq cl1 - cmp #'r' - beq cl1 - lda #EINVAL - sta >errno - brl rt2 + ph4 stream verify that stream exists + jsl ~VerifyStream + jcs rt2 + lda [type] make sure the file type is in ['a','r','w'] + and #$00FF + sta fileType + cmp #'a' + beq cl1 + cmp #'w' + beq cl1 + cmp #'r' + beq cl1 + lda #EINVAL + sta >errno + brl rt2 ; ; close the old file ; -cl1 ldy #FILE_file branch if the file is not a disk file - lda [stream],Y - bmi cn1 +cl1 ldy #FILE_file branch if the file is not a disk file + lda [stream],Y + bmi cn1 - ph4 stream do any pending I/O - jsl fflush - ldy #FILE_file close the file - lda [stream],Y - sta clRefNum - OSclose cl - ldy #FILE_flag if the buffer was allocated by fopen then - lda [stream],Y - and #_IOMYBUF - beq cn1 - ldy #FILE_base+2 dispose of the file buffer - lda [stream],Y - pha - dey - dey - lda [stream],Y - pha - jsl free + ph4 stream do any pending I/O + jsl fflush + ldy #FILE_file close the file + lda [stream],Y + sta clRefNum + OSclose cl + ldy #FILE_flag if the buffer was allocated by fopen then + lda [stream],Y + and #_IOMYBUF + beq cn1 + ldy #FILE_base+2 dispose of the file buffer + lda [stream],Y + pha + dey + dey + lda [stream],Y + pha + jsl free ; ; create a GS/OS file name ; -cn1 ph4 filename get the length of the name buffer - jsl ~osname - sta OSname - stx OSname+2 - ora OSname+2 - jeq rt2 - move4 OSname,opName +cn1 ph4 filename get the length of the name buffer + jsl ~osname + sta OSname + stx OSname+2 + ora OSname+2 + jeq rt2 + move4 OSname,opName ; ; open the file ; - lda #TXT we must open a new file - determine it's - sta crFileType type by looking for the 'b' designator - ldy #1 - lda [type],Y - and #$00FF - cmp #'+' - bne nl1 - iny - lda [type],Y - and #$00FF -nl1 cmp #'b' - bne nl2 - lda #BIN - sta crFileType - iny - cpy #2 - bne nl2 - lda [type],Y - and #$00FF - cmp #'+' - bne nl2 - iny -nl2 lda fileType check for 'x' in type string - cmp #'r' - beq nl3 - lda [type],Y - and #$00FF - cmp #'x' - beq of1 + lda #TXT we must open a new file - determine it's + sta crFileType type by looking for the 'b' designator + ldy #1 + lda [type],Y + and #$00FF + cmp #'+' + bne nl1 + iny + lda [type],Y + and #$00FF +nl1 cmp #'b' + bne nl2 + lda #BIN + sta crFileType + iny + cpy #2 + bne nl2 + lda [type],Y + and #$00FF + cmp #'+' + bne nl2 + iny +nl2 lda fileType check for 'x' in type string + cmp #'r' + beq nl3 + lda [type],Y + and #$00FF + cmp #'x' + beq of1 - -nl3 OSopen op try to open an existing file - bcc of2 + +nl3 OSopen op try to open an existing file + bcc of2 - lda fileType if the type is 'r', flag an error - cmp #'r' - bne of1 -errEIO ph4 stream - jsr ~ioerror - brl rt1 + lda fileType if the type is 'r', flag an error + cmp #'r' + bne of1 +errEIO ph4 stream + jsr ~ioerror + brl rt1 -of1 move4 OSname,crPathName create the file - OScreate cr - bcc of1a - cmp #$0047 check for dupPathname error=>file exists - bne errEIO - ph4 stream - jsr ~ioerror - lda #EEXIST - sta >errno - brl rt1 -of1a OSopen op open the file - bcs errEIO +of1 move4 OSname,crPathName create the file + OScreate cr + bcc of1a + cmp #$0047 check for dupPathname error=>file exists + bne errEIO + ph4 stream + jsr ~ioerror + lda #EEXIST + sta >errno + brl rt1 +of1a OSopen op open the file + bcs errEIO -of2 lda fileType if the file type is 'w', reset it - cmp #'w' - bne ar1 - lda opRefNum - sta efRefNum - OSSet_EOF ef - bcs errEIO +of2 lda fileType if the file type is 'w', reset it + cmp #'w' + bne ar1 + lda opRefNum + sta efRefNum + OSSet_EOF ef + bcs errEIO ; ; fill in the file record ; -ar1 ph4 #BUFSIZ get space for the file buffer - jsl malloc - sta buffStart - stx buffStart+2 - ora buffStart+2 - bne ar3 - lda #ENOMEM memory error - sta >errno - brl rt1 +ar1 ph4 #BUFSIZ get space for the file buffer + jsl malloc + sta buffStart + stx buffStart+2 + ora buffStart+2 + bne ar3 + lda #ENOMEM memory error + sta >errno + brl rt1 -ar3 move4 stream,fileBuff set the file buffer address - lda buffStart set the start of the buffer - ldy #FILE_base - sta [fileBuff],Y - iny - iny - lda buffStart+2 - sta [fileBuff],Y - ldy #FILE_ptr+2 - sta [fileBuff],Y - dey - dey - lda buffStart - sta [fileBuff],Y - ldy #FILE_size set the buffer size - lda #BUFSIZ - sta [fileBuff],Y - iny - iny - lda #^BUFSIZ - sta [fileBuff],Y - ldy #1 set the flags - lda [type],Y - cmp #'+b' - beq ar3a - and #$00FF - cmp #'+' - bne ar4 -ar3a lda #_IOFBF+_IORW+_IOMYBUF - bra ar6 -ar4 lda fileType - cmp #'r' - beq ar5 - lda #_IOFBF+_IOWRT+_IOMYBUF - bra ar6 -ar5 lda #_IOFBF+_IOREAD+_IOMYBUF -ar6 ldy #FILE_flag - ldx crFileType - cpx #BIN - beq ar6a - ora #_IOTEXT -ar6a sta [fileBuff],Y - ldy #FILE_cnt no chars in buffer - lda #0 - sta [fileBuff],Y - iny - iny - sta [fileBuff],Y - ldy #FILE_pbk nothing in the putback buffer - lda #$FFFF - sta [fileBuff],Y - ldy #FILE_file set the file ID - lda opRefNum - sta [fileBuff],Y +ar3 move4 stream,fileBuff set the file buffer address + lda buffStart set the start of the buffer + ldy #FILE_base + sta [fileBuff],Y + iny + iny + lda buffStart+2 + sta [fileBuff],Y + ldy #FILE_ptr+2 + sta [fileBuff],Y + dey + dey + lda buffStart + sta [fileBuff],Y + ldy #FILE_size set the buffer size + lda #BUFSIZ + sta [fileBuff],Y + iny + iny + lda #^BUFSIZ + sta [fileBuff],Y + ldy #1 set the flags + lda [type],Y + cmp #'+b' + beq ar3a + and #$00FF + cmp #'+' + bne ar4 +ar3a lda #_IOFBF+_IORW+_IOMYBUF + bra ar6 +ar4 lda fileType + cmp #'r' + beq ar5 + lda #_IOFBF+_IOWRT+_IOMYBUF + bra ar6 +ar5 lda #_IOFBF+_IOREAD+_IOMYBUF +ar6 ldy #FILE_flag + ldx crFileType + cpx #BIN + beq ar6a + ora #_IOTEXT +ar6a sta [fileBuff],Y + ldy #FILE_cnt no chars in buffer + lda #0 + sta [fileBuff],Y + iny + iny + sta [fileBuff],Y + ldy #FILE_pbk nothing in the putback buffer + lda #$FFFF + sta [fileBuff],Y + ldy #FILE_file set the file ID + lda opRefNum + sta [fileBuff],Y ; ; return the result ; -rt1 ph4 OSname dispose of the file name buffer - jsl free -rt2 plb restore caller's data bank - creturn 4:fileBuff return +rt1 ph4 OSname dispose of the file name buffer + jsl free +rt2 plb restore caller's data bank + creturn 4:fileBuff return ; ; local data areas ; -op dc i'2' parameter block for OSopen -opRefNum ds 2 -opName ds 4 +op dc i'2' parameter block for OSopen +opRefNum ds 2 +opName ds 4 -ef dc i'3' parameter block for OSSet_EOF -efRefNum ds 2 - dc i'0' - dc i4'0' +ef dc i'3' parameter block for OSSet_EOF +efRefNum ds 2 + dc i'0' + dc i4'0' -cr dc i'7' parameter block for OScreate -crPathName ds 4 - dc i'$C3' -crFileType ds 2 - dc i4'0' - dc i'1' - dc i4'0' - dc i4'0' +cr dc i'7' parameter block for OScreate +crPathName ds 4 + dc i'$C3' +crFileType ds 2 + dc i4'0' + dc i'1' + dc i4'0' + dc i4'0' -cl dc i'1' parameter block for OSclose -clRefNum ds 2 +cl dc i'1' parameter block for OSclose +clRefNum ds 2 ; ; Patch for standard out ; stdoutFile jmp stdoutPatch stdoutPatch phb - plx - ply - pla - pha - pha - pha - phy - phx - plb - lda >stdout - sta 6,S - lda >stdout+2 - sta 8,S - brl fputc + plx + ply + pla + pha + pha + pha + phy + phx + plb + lda >stdout + sta 6,S + lda >stdout+2 + sta 8,S + brl fputc ; ; Patch for standard in ; stdinFile jmp stdinPatch stdinPatch ph4 #stdin+4 - jsl fgetc - rtl - end + jsl fgetc + rtl + end **************************************************************** * @@ -1290,235 +1290,235 @@ stdinPatch ph4 #stdin+4 * **************************************************************** * -fprintf start - using ~printfCommon +fprintf start + using ~printfCommon - phb use local addressing - phk - plb - plx remove the return address - ply - pla save the stream - sta stream - pla - sta stream+2 - phy restore return address/data bank - phx - plb - lda >stream+2 verify that stream exists - pha - lda >stream - pha - jsl ~VerifyStream - bcc lb1 - lda #EIO - sta >errno - lda #EOF - bra rts -lb1 lda #put set up output routine - sta >~putchar+4 - lda #>put - sta >~putchar+5 - tsc find the argument list address - clc - adc #8 - sta >args - pea 0 - pha - jsl ~printf call the formatter - sec compute the space to pull from the stack - pla - sbc >args - clc - adc #4 - sta >args - pla - phb remove the return address - plx - ply - tsc update the stack pointer - clc - adc >args - tcs - phy restore the return address - phx - plb - lda >~numChars return the value - rtl return + phb use local addressing + phk + plb + plx remove the return address + ply + pla save the stream + sta stream + pla + sta stream+2 + phy restore return address/data bank + phx + plb + lda >stream+2 verify that stream exists + pha + lda >stream + pha + jsl ~VerifyStream + bcc lb1 + lda #EIO + sta >errno + lda #EOF + bra rts +lb1 lda #put set up output routine + sta >~putchar+4 + lda #>put + sta >~putchar+5 + tsc find the argument list address + clc + adc #8 + sta >args + pea 0 + pha + jsl ~printf call the formatter + sec compute the space to pull from the stack + pla + sbc >args + clc + adc #4 + sta >args + pla + phb remove the return address + plx + ply + tsc update the stack pointer + clc + adc >args + tcs + phy restore the return address + phx + plb + lda >~numChars return the value + rtl return -put phb remove the char from the stack - phk - plb - plx - pla - ply - pha - phx - plb - lda stream+2 write to a file - pha - lda stream - pha - phy - jsl fputc -rts rtl +put phb remove the char from the stack + phk + plb + plx + pla + ply + pha + phx + plb + lda stream+2 write to a file + pha + lda stream + pha + phy + jsl fputc +rts rtl -args ds 2 original argument address -stream ds 4 stream address - end +args ds 2 original argument address +stream ds 4 stream address + end **************************************************************** * * int fputc(c, stream) -* char c; -* FILE *stream; +* char c; +* FILE *stream; * * Write a character to a file * * Inputs: -* c - character to write -* stream - file to write to +* c - character to write +* stream - file to write to * * Outputs: -* A - character written; EOF for an error +* A - character written; EOF for an error * **************************************************************** * -fputc start -putc entry +fputc start +putc entry -c2 equ 5 output char -p equ 1 work pointer +c2 equ 5 output char +p equ 1 work pointer - csubroutine (2:c,4:stream),6 + csubroutine (2:c,4:stream),6 - ph4 stream verify that stream exists - jsl ~VerifyStream - bcs lb0 - ldy #FILE_flag quit with error if the end of file - lda [stream],Y has been reached or an error has been - and #_IOEOF+_IOERR encountered - beq lb1 -lb0 lda #EOF - sta c - brl pc8 + ph4 stream verify that stream exists + jsl ~VerifyStream + bcs lb0 + ldy #FILE_flag quit with error if the end of file + lda [stream],Y has been reached or an error has been + and #_IOEOF+_IOERR encountered + beq lb1 +lb0 lda #EOF + sta c + brl pc8 -lb1 ldy #FILE_flag if the file is not prepared for - lda [stream],Y writing then - bit #_IOWRT - bne lb2 - bit #_IOREAD if it is being read then - bne pc2 flag the error - ora #_IOWRT set the writing flag - sta [stream],Y -lb2 ldy #FILE_file branch if this is a disk file - lda [stream],Y - bpl pc3 +lb1 ldy #FILE_flag if the file is not prepared for + lda [stream],Y writing then + bit #_IOWRT + bne lb2 + bit #_IOREAD if it is being read then + bne pc2 flag the error + ora #_IOWRT set the writing flag + sta [stream],Y +lb2 ldy #FILE_file branch if this is a disk file + lda [stream],Y + bpl pc3 - cmp #stdoutID if stream = stdout then - bne pc1 - ph2 c write the character - jsl ~stdout - brl pc8 -pc1 cmp #stderrID else if stream = stderr then - bne pc2 - lda c (for \n, write \r) - cmp #10 - bne pc1a - lda #13 -pc1a pha write to error out - jsl SYSCHARERROUT - brl pc8 -pc2 ph4 stream else stream = stdin; flag the error - jsr ~ioerror - lda #EOF - sta c - brl pc8 + cmp #stdoutID if stream = stdout then + bne pc1 + ph2 c write the character + jsl ~stdout + brl pc8 +pc1 cmp #stderrID else if stream = stderr then + bne pc2 + lda c (for \n, write \r) + cmp #10 + bne pc1a + lda #13 +pc1a pha write to error out + jsl SYSCHARERROUT + brl pc8 +pc2 ph4 stream else stream = stdin; flag the error + jsr ~ioerror + lda #EOF + sta c + brl pc8 -pc3 lda c set the output char - sta c2 - ldy #FILE_flag if this is a text file then - lda [stream],Y - and #_IOTEXT - beq pc3a - lda c if the char is lf then - cmp #10 - bne pc3a - lda #13 substitute a cr - sta c2 -pc3a ldy #FILE_cnt if the buffer is full then - lda [stream],Y - iny - iny - ora [stream],Y - bne pc4 -pc3b ldy #FILE_flag purge it - lda [stream],Y - pha - ph4 stream - jsl fflush - ldy #FILE_flag - pla - sta [stream],Y +pc3 lda c set the output char + sta c2 + ldy #FILE_flag if this is a text file then + lda [stream],Y + and #_IOTEXT + beq pc3a + lda c if the char is lf then + cmp #10 + bne pc3a + lda #13 substitute a cr + sta c2 +pc3a ldy #FILE_cnt if the buffer is full then + lda [stream],Y + iny + iny + ora [stream],Y + bne pc4 +pc3b ldy #FILE_flag purge it + lda [stream],Y + pha + ph4 stream + jsl fflush + ldy #FILE_flag + pla + sta [stream],Y -pc4 ldy #FILE_ptr deposit the character in the buffer, - lda [stream],Y incrementing the buffer pointer - sta p - clc - adc #1 - sta [stream],Y - iny - iny - lda [stream],Y - sta p+2 - adc #0 - sta [stream],Y - short M - lda c2 - sta [p] - long M - ldy #FILE_cnt dec the buffer counter - sec - lda [stream],Y - sbc #1 - sta [stream],Y - bcs pc5 - iny - iny - lda [stream],Y - dec A - sta [stream],Y +pc4 ldy #FILE_ptr deposit the character in the buffer, + lda [stream],Y incrementing the buffer pointer + sta p + clc + adc #1 + sta [stream],Y + iny + iny + lda [stream],Y + sta p+2 + adc #0 + sta [stream],Y + short M + lda c2 + sta [p] + long M + ldy #FILE_cnt dec the buffer counter + sec + lda [stream],Y + sbc #1 + sta [stream],Y + bcs pc5 + iny + iny + lda [stream],Y + dec A + sta [stream],Y -pc5 ldy #FILE_cnt if the buffer is full - lda [stream],Y - iny - iny - ora [stream],Y - beq pc7 - lda c2 or if (c = '\n') and (flag & _IOLBF) - cmp #13 - beq pc5a - cmp #10 - bne pc6 -pc5a ldy #FILE_flag - lda [stream],Y - and #_IOLBF - bne pc7 -pc6 ldy #FILE_flag or is flag & _IONBF then - lda [stream],Y - and #_IONBF - beq pc8 -pc7 ldy #FILE_flag flush the stream - lda [stream],Y - pha - ph4 stream - jsl fflush - ldy #FILE_flag - pla - sta [stream],Y +pc5 ldy #FILE_cnt if the buffer is full + lda [stream],Y + iny + iny + ora [stream],Y + beq pc7 + lda c2 or if (c = '\n') and (flag & _IOLBF) + cmp #13 + beq pc5a + cmp #10 + bne pc6 +pc5a ldy #FILE_flag + lda [stream],Y + and #_IOLBF + bne pc7 +pc6 ldy #FILE_flag or is flag & _IONBF then + lda [stream],Y + and #_IONBF + beq pc8 +pc7 ldy #FILE_flag flush the stream + lda [stream],Y + pha + ph4 stream + jsl fflush + ldy #FILE_flag + pla + sta [stream],Y -pc8 creturn 2:c - end +pc8 creturn 2:c + end **************************************************************** * @@ -1529,148 +1529,148 @@ pc8 creturn 2:c * **************************************************************** * -fputs start -err equ 1 return code +fputs start +err equ 1 return code - csubroutine (4:s,4:stream),2 + csubroutine (4:s,4:stream),2 - ph4 stream verify that stream exists - jsl ~VerifyStream - lda #EOF - sta err - bcs lb4 - stz err no error so far - bra lb2 skip initial increment -lb1 inc4 s next char -lb2 ph4 stream push the stream, just in case... - lda [s] exit loop if at end of string - and #$00FF - beq lb3 - pha push char to write - jsl fputc write the character - cmp #EOF loop if no error - bne lb1 + ph4 stream verify that stream exists + jsl ~VerifyStream + lda #EOF + sta err + bcs lb4 + stz err no error so far + bra lb2 skip initial increment +lb1 inc4 s next char +lb2 ph4 stream push the stream, just in case... + lda [s] exit loop if at end of string + and #$00FF + beq lb3 + pha push char to write + jsl fputc write the character + cmp #EOF loop if no error + bne lb1 - sta err set the error code - bra lb4 + sta err set the error code + bra lb4 -lb3 pla remove stream from the stack - pla -lb4 creturn 2:err - end +lb3 pla remove stream from the stack + pla +lb4 creturn 2:err + end **************************************************************** * * size_t fread(ptr, element_size, count, stream) -* void *ptr; -* size_t element_size; -* size_t count; -* FILE *stream; +* void *ptr; +* size_t element_size; +* size_t count; +* FILE *stream; * * Reads element*count bytes to stream, putting the bytes in * ptr. * * Inputs: -* ptr - location to store the bytes read -* element_size - size of each element -* count - number of elements -* stream - file to read from +* ptr - location to store the bytes read +* element_size - size of each element +* count - number of elements +* stream - file to read from * * Outputs: -* Returns the number of elements actually read. +* Returns the number of elements actually read. * **************************************************************** * -fread start -temp equ 1 +fread start +temp equ 1 - csubroutine (4:ptr,4:element_size,4:count,4:stream),4 - phb - phk - plb + csubroutine (4:ptr,4:element_size,4:count,4:stream),4 + phb + phk + plb - stz rdTransferCount set the # of elements read - stz rdTransferCount+2 - ph4 stream verify that stream exists - jsl ~VerifyStream - jcs lb6 - ph4 stream reset file pointer - jsl ~SetFilePointer - mul4 element_size,count,rdRequestCount set the # of bytes - lda rdRequestCount quit if the request count is 0 - ora rdRequestCount+2 - jeq lb6 - ldy #FILE_file set the file ID number - lda [stream],Y - bpl lb2 branch if it is a file + stz rdTransferCount set the # of elements read + stz rdTransferCount+2 + ph4 stream verify that stream exists + jsl ~VerifyStream + jcs lb6 + ph4 stream reset file pointer + jsl ~SetFilePointer + mul4 element_size,count,rdRequestCount set the # of bytes + lda rdRequestCount quit if the request count is 0 + ora rdRequestCount+2 + jeq lb6 + ldy #FILE_file set the file ID number + lda [stream],Y + bpl lb2 branch if it is a file - cmp #stdinID if the file is stdin then - jne lb6 - stz rdTransferCount - stz rdTransferCount+2 - lda >stdin+4+FILE_flag - and #_IOEOF - jne lb6 -lb1 jsl SYSKEYIN read the bytes - tax branch if not eof - bne lb1a - lda #_IOEOF set EOF flag - ora >stdin+4+FILE_flag - sta >stdin+4+FILE_flag - jsl SYSKEYIN read the closing cr - brl lb6 -lb1a short M set character - sta [ptr] - long M - inc4 rdTransferCount - inc4 ptr - dec4 rdRequestCount - lda rdRequestCount - ora rdRequestCount+2 - bne lb1 - bra lb6 + cmp #stdinID if the file is stdin then + jne lb6 + stz rdTransferCount + stz rdTransferCount+2 + lda >stdin+4+FILE_flag + and #_IOEOF + jne lb6 +lb1 jsl SYSKEYIN read the bytes + tax branch if not eof + bne lb1a + lda #_IOEOF set EOF flag + ora >stdin+4+FILE_flag + sta >stdin+4+FILE_flag + jsl SYSKEYIN read the closing cr + brl lb6 +lb1a short M set character + sta [ptr] + long M + inc4 rdTransferCount + inc4 ptr + dec4 rdRequestCount + lda rdRequestCount + ora rdRequestCount+2 + bne lb1 + bra lb6 -lb2 sta rdRefNum set the reference number - move4 ptr,rdDataBuffer set the start address - OSRead rd read the bytes - bcc lb5 - cmp #$4C if the error was $4C then - bne lb3 - jsr SetEOF set the EOF flag - bra lb5 -lb3 ph4 stream I/O error - jsr ~ioerror -! set the # records read -lb5 div4 rdTransferCount,element_size - lda count if there were too few elements read then - cmp rdTransferCount - bne lb5a - lda count+2 - cmp rdTransferCount+2 - beq lb6 -lb5a jsr SetEOF set the EOF flag -lb6 move4 rdTransferCount,temp - plb +lb2 sta rdRefNum set the reference number + move4 ptr,rdDataBuffer set the start address + OSRead rd read the bytes + bcc lb5 + cmp #$4C if the error was $4C then + bne lb3 + jsr SetEOF set the EOF flag + bra lb5 +lb3 ph4 stream I/O error + jsr ~ioerror +! set the # records read +lb5 div4 rdTransferCount,element_size + lda count if there were too few elements read then + cmp rdTransferCount + bne lb5a + lda count+2 + cmp rdTransferCount+2 + beq lb6 +lb5a jsr SetEOF set the EOF flag +lb6 move4 rdTransferCount,temp + plb - creturn 4:temp + creturn 4:temp ; ; Local data ; -rd dc i'5' parameter block for OSRead -rdRefNum ds 2 +rd dc i'5' parameter block for OSRead +rdRefNum ds 2 rdDataBuffer ds 4 rdRequestCount ds 4 rdTransferCount ds 4 - dc i'1' + dc i'1' ; ; Set the EOF flag ; -SetEOF ldy #FILE_flag set the eof flag - lda [stream],Y - ora #_IOEOF - sta [stream],Y - rts - end +SetEOF ldy #FILE_flag set the eof flag + lda [stream],Y + ora #_IOEOF + sta [stream],Y + rts + end **************************************************************** * @@ -1682,388 +1682,388 @@ SetEOF ldy #FILE_flag set the eof flag * **************************************************************** * -fscanf start - using ~scanfCommon +fscanf start + using ~scanfCommon - phb use local addressing - phk - plb - plx remove the return address - ply - pla save the stream - sta stream - pla - sta stream+2 - phy restore return address/data bank - phx - plb + phb use local addressing + phk + plb + plx remove the return address + ply + pla save the stream + sta stream + pla + sta stream+2 + phy restore return address/data bank + phx + plb - ph4 >stream verify that stream exists - jsl ~VerifyStream - bcc lb1 - lda #EOF - rtl -lb1 lda #get set up our routines - sta >~getchar+10 - lda #>get - sta >~getchar+11 + ph4 >stream verify that stream exists + jsl ~VerifyStream + bcc lb1 + lda #EOF + rtl +lb1 lda #get set up our routines + sta >~getchar+10 + lda #>get + sta >~getchar+11 - lda #unget - sta >~putback+12 - lda #>unget - sta >~putback+13 + lda #unget + sta >~putback+12 + lda #>unget + sta >~putback+13 - lda #~RemoveWordFromStack - sta >~RemoveWord+1 - lda #>~RemoveWordFromStack - sta >~RemoveWord+2 + lda #~RemoveWordFromStack + sta >~RemoveWord+1 + lda #>~RemoveWordFromStack + sta >~RemoveWord+2 - lda #0 - sta >~isVarArgs + lda #0 + sta >~isVarArgs - brl ~scanf + brl ~scanf -get ph4 stream get a character - jsl fgetc - rtl +get ph4 stream get a character + jsl fgetc + rtl -unget ldx stream+2 put a character back - phx - ldx stream - phx - pha - jsl ungetc - rtl +unget ldx stream+2 put a character back + phx + ldx stream + phx + pha + jsl ungetc + rtl -stream ds 4 - end +stream ds 4 + end **************************************************************** * * int fseek(stream,offset,wherefrom) -* FILE *stream; -* long int offset; -* int wherefrom; +* FILE *stream; +* long int offset; +* int wherefrom; * * Change the read/write location for the stream. * * Inputs: -* stream - file to change -* offset - position to move to -* wherefrom - move relative to this location +* stream - file to change +* offset - position to move to +* wherefrom - move relative to this location * * Outputs: -* Returns non-zero for error +* Returns non-zero for error * **************************************************************** * -fseek start - jmp __fseek - end +fseek start + jmp __fseek + end -__fseek start +__fseek start -err equ 1 return value +err equ 1 return value - csubroutine (4:stream,4:offset,2:wherefrom),2 - phb - phk - plb + csubroutine (4:stream,4:offset,2:wherefrom),2 + phb + phk + plb - lda #-1 assume we will get an error - sta err - ph4 stream verify that stream exists - jsl ~VerifyStream - jcs rts - ph4 stream purge the file - jsl fflush - ldy #FILE_file set the file reference - lda [stream],Y - jmi lb6 - sta gpRefNum - sta spRefNum - lda wherefrom if position is relative to the end then - cmp #SEEK_END - bne lb2 - OSGet_EOF gp get the eof - jcs erEIO - add4 offset,gpPosition add it to the offset - bra lb3 -lb2 cmp #SEEK_CUR else if relative to current position then - bne lb3 - ph4 stream get the current position - jsl ftell - clc add it to the offset - adc offset - sta offset - txa - adc offset+2 - sta offset+2 -lb3 OSGet_EOF gp get the end of the file - jcs erEIO - lda offset+2 if the offset is >= EOF then - cmp gpPosition+2 - bne lb4 - lda offset - cmp gpPosition -lb4 ble lb5 - move4 offset,spPosition extend the file - OSSet_EOF sp - bcs erEIO -lb5 move4 offset,spPosition - OSSet_Mark sp - bcs erEIO + lda #-1 assume we will get an error + sta err + ph4 stream verify that stream exists + jsl ~VerifyStream + jcs rts + ph4 stream purge the file + jsl fflush + ldy #FILE_file set the file reference + lda [stream],Y + jmi lb6 + sta gpRefNum + sta spRefNum + lda wherefrom if position is relative to the end then + cmp #SEEK_END + bne lb2 + OSGet_EOF gp get the eof + jcs erEIO + add4 offset,gpPosition add it to the offset + bra lb3 +lb2 cmp #SEEK_CUR else if relative to current position then + bne lb3 + ph4 stream get the current position + jsl ftell + clc add it to the offset + adc offset + sta offset + txa + adc offset+2 + sta offset+2 +lb3 OSGet_EOF gp get the end of the file + jcs erEIO + lda offset+2 if the offset is >= EOF then + cmp gpPosition+2 + bne lb4 + lda offset + cmp gpPosition +lb4 ble lb5 + move4 offset,spPosition extend the file + OSSet_EOF sp + bcs erEIO +lb5 move4 offset,spPosition + OSSet_Mark sp + bcs erEIO -lb6 ldy #FILE_flag clear the EOF , READ, WRITE flags - lda #$FFFF-_IOEOF-_IOREAD-_IOWRT - and [stream],Y - sta [stream],Y - ldy #FILE_cnt clear the character count - lda #0 - sta [stream],Y - iny - iny - sta [stream],Y - ldy #FILE_base+2 reset the file pointer - lda [stream],Y - tax - dey - dey - lda [stream],Y - ldy #FILE_ptr - sta [stream],Y - iny - iny - txa - sta [stream],Y - ldy #FILE_pbk nothing in the putback buffer - lda #$FFFF - sta [stream],Y +lb6 ldy #FILE_flag clear the EOF , READ, WRITE flags + lda #$FFFF-_IOEOF-_IOREAD-_IOWRT + and [stream],Y + sta [stream],Y + ldy #FILE_cnt clear the character count + lda #0 + sta [stream],Y + iny + iny + sta [stream],Y + ldy #FILE_base+2 reset the file pointer + lda [stream],Y + tax + dey + dey + lda [stream],Y + ldy #FILE_ptr + sta [stream],Y + iny + iny + txa + sta [stream],Y + ldy #FILE_pbk nothing in the putback buffer + lda #$FFFF + sta [stream],Y - stz err -rts plb - creturn 2:err + stz err +rts plb + creturn 2:err -erEIO ph4 stream flag an IO error - jsr ~ioerror - bra rts +erEIO ph4 stream flag an IO error + jsr ~ioerror + bra rts -gp dc i'2' parameter block for OSGet_EOF -gpRefNum ds 2 -gpPosition ds 4 +gp dc i'2' parameter block for OSGet_EOF +gpRefNum ds 2 +gpPosition ds 4 -sp dc i'3' parameter block for OSSet_EOF -spRefNum ds 2 and OSSet_Mark - dc i'0' -spPosition ds 4 - end +sp dc i'3' parameter block for OSSet_EOF +spRefNum ds 2 and OSSet_Mark + dc i'0' +spPosition ds 4 + end **************************************************************** * * int fsetpos(FILE *stream, fpos_t *pos); * * Inputs: -* stream - pointer to stream to set position of -* pos - pointer to location to set position +* stream - pointer to stream to set position of +* pos - pointer to location to set position * * Outputs: -* A - 0 if successful; else -1 if not -* errno - if unsuccessful, errno is set to EIO +* A - 0 if successful; else -1 if not +* errno - if unsuccessful, errno is set to EIO * **************************************************************** * -fsetpos start -err equ 1 error code +fsetpos start +err equ 1 error code - csubroutine (4:stream,4:pos),2 + csubroutine (4:stream,4:pos),2 - ph2 #SEEK_SET - ldy #2 - lda [pos],Y - pha - lda [pos] - pha - ph4 stream - jsl fseek - sta err + ph2 #SEEK_SET + ldy #2 + lda [pos],Y + pha + lda [pos] + pha + ph4 stream + jsl fseek + sta err - creturn 2:err - end + creturn 2:err + end **************************************************************** * * long int ftell(stream) -* FILE *stream; +* FILE *stream; * * Find the number of characters already passed in the file. * * Inputs: -* stream - strem to find the location in +* stream - strem to find the location in * * Outputs: -* Returns the position, or -1L for an error. +* Returns the position, or -1L for an error. * **************************************************************** * -ftell start +ftell start -pos equ 1 position in the file +pos equ 1 position in the file - csubroutine (4:stream),4 - phb - phk - plb + csubroutine (4:stream),4 + phb + phk + plb - lda #-1 assume an error - sta pos - sta pos+2 - ph4 stream verify that stream exists - jsl ~VerifyStream - jcs rts - ldy #FILE_flag if the file is being written then - lda [stream],Y - bit #_IOWRT - beq lb0 - ph4 stream do any pending writes - jsl fflush - tax - bne rts -lb0 ldy #FILE_file get the file's mark - lda [stream],Y - sta gmRefNum - OSGet_Mark gm - bcc lb1 - ph4 stream - jsr ~ioerror - bra rts + lda #-1 assume an error + sta pos + sta pos+2 + ph4 stream verify that stream exists + jsl ~VerifyStream + jcs rts + ldy #FILE_flag if the file is being written then + lda [stream],Y + bit #_IOWRT + beq lb0 + ph4 stream do any pending writes + jsl fflush + tax + bne rts +lb0 ldy #FILE_file get the file's mark + lda [stream],Y + sta gmRefNum + OSGet_Mark gm + bcc lb1 + ph4 stream + jsr ~ioerror + bra rts -lb1 move4 gmPosition,pos set the position - ldy #FILE_flag if the file is being read then - lda [stream],Y - bit #_IOREAD - beq rts - sec subtract off characters left to be - ldy #FILE_cnt read - lda pos - sbc [stream],Y - sta pos - iny - iny - lda pos+2 - sbc [stream],Y - sta pos+2 - ldy #FILE_pbk if there is a char in the putback - lda [stream],Y buffer then - and #$0080 - bne rts - dec4 pos dec pos by 1 - ldy #FILE_file set the file's mark - lda [stream],Y - sta spRefNum - move4 pos,spPosition - OSSet_Mark sp +lb1 move4 gmPosition,pos set the position + ldy #FILE_flag if the file is being read then + lda [stream],Y + bit #_IOREAD + beq rts + sec subtract off characters left to be + ldy #FILE_cnt read + lda pos + sbc [stream],Y + sta pos + iny + iny + lda pos+2 + sbc [stream],Y + sta pos+2 + ldy #FILE_pbk if there is a char in the putback + lda [stream],Y buffer then + and #$0080 + bne rts + dec4 pos dec pos by 1 + ldy #FILE_file set the file's mark + lda [stream],Y + sta spRefNum + move4 pos,spPosition + OSSet_Mark sp -rts plb - creturn 4:pos +rts plb + creturn 4:pos -sp dc i'3' parameter block for OSSet_Mark -spRefNum ds 2 - dc i'0' -spPosition ds 4 +sp dc i'3' parameter block for OSSet_Mark +spRefNum ds 2 + dc i'0' +spPosition ds 4 -gm dc i'2' parameter block for OSGetMark -gmRefNum ds 2 -gmPosition ds 4 - end +gm dc i'2' parameter block for OSGetMark +gmRefNum ds 2 +gmPosition ds 4 + end **************************************************************** * * size_t fwrite(ptr, element_size, count, stream) -* void *ptr; -* size_t element_size; -* size_t count; -* FILE *stream; +* void *ptr; +* size_t element_size; +* size_t count; +* FILE *stream; * * Writes element*count bytes to stream, taking the bytes from * ptr. * * Inputs: -* ptr - pointer to the bytes to write -* element_size - size of each element -* count - number of elements -* stream - file to write to +* ptr - pointer to the bytes to write +* element_size - size of each element +* count - number of elements +* stream - file to write to * * Outputs: -* Returns the number of elements actually written. +* Returns the number of elements actually written. * **************************************************************** * -fwrite start +fwrite start - csubroutine (4:ptr,4:element_size,4:count,4:stream),0 - phb - phk - plb + csubroutine (4:ptr,4:element_size,4:count,4:stream),0 + phb + phk + plb - stz wrTransferCount set the # of elements written - stz wrTransferCount+2 - ph4 stream verify that stream exists - jsl ~VerifyStream - jcs lb6 - mul4 element_size,count,wrRequestCount set the # of bytes - lda wrRequestCount quit if the request count is 0 - ora wrRequestCount+2 - jeq lb6 - ldy #FILE_file set the file ID number - lda [stream],Y - bpl lb4 branch if it is a file + stz wrTransferCount set the # of elements written + stz wrTransferCount+2 + ph4 stream verify that stream exists + jsl ~VerifyStream + jcs lb6 + mul4 element_size,count,wrRequestCount set the # of bytes + lda wrRequestCount quit if the request count is 0 + ora wrRequestCount+2 + jeq lb6 + ldy #FILE_file set the file ID number + lda [stream],Y + bpl lb4 branch if it is a file - cmp #stdoutID if the file is stdout then - bne lb2 -lb1 lda [ptr] write the bytes - pha - jsl ~stdout - inc4 ptr - dec4 wrRequestCount - lda wrRequestCount - ora wrRequestCount+2 - bne lb1 - move4 count,wrTransferCount set the # of elements written - bra lb6 + cmp #stdoutID if the file is stdout then + bne lb2 +lb1 lda [ptr] write the bytes + pha + jsl ~stdout + inc4 ptr + dec4 wrRequestCount + lda wrRequestCount + ora wrRequestCount+2 + bne lb1 + move4 count,wrTransferCount set the # of elements written + bra lb6 -lb2 cmp #stderrID if the file is stderr then - bne lb6 -lb3 lda [ptr] write the bytes - pha - jsl SYSCHARERROUT - inc4 ptr - dec4 wrRequestCount - lda wrRequestCount - ora wrRequestCount+2 - bne lb3 - move4 count,wrTransferCount set the # of elements written - bra lb6 +lb2 cmp #stderrID if the file is stderr then + bne lb6 +lb3 lda [ptr] write the bytes + pha + jsl SYSCHARERROUT + inc4 ptr + dec4 wrRequestCount + lda wrRequestCount + ora wrRequestCount+2 + bne lb3 + move4 count,wrTransferCount set the # of elements written + bra lb6 -lb4 sta wrRefNum set the reference number - ph4 stream purge the file - jsl fflush - move4 ptr,wrDataBuffer set the start address - OSWrite wr write the bytes - bcc lb5 - ph4 stream I/O error - jsr ~ioerror -! set the # records written -lb5 div4 wrTransferCount,element_size,count -lb6 plb - creturn 4:count return +lb4 sta wrRefNum set the reference number + ph4 stream purge the file + jsl fflush + move4 ptr,wrDataBuffer set the start address + OSWrite wr write the bytes + bcc lb5 + ph4 stream I/O error + jsr ~ioerror +! set the # records written +lb5 div4 wrTransferCount,element_size,count +lb6 plb + creturn 4:count return -wr dc i'5' parameter block for OSRead -wrRefNum ds 2 +wr dc i'5' parameter block for OSRead +wrRefNum ds 2 wrDataBuffer ds 4 wrRequestCount ds 4 wrTransferCount ds 4 - dc i'1' - end + dc i'1' + end **************************************************************** * @@ -2076,158 +2076,158 @@ wrTransferCount ds 4 * **************************************************************** * -getchar start +getchar start ; ; Determine which method to use ; - lda >stdin use fgetc if stdin has changed - cmp #stdin+4 - bne fl1 - lda >stdin+2 - cmp #^stdin+4 - bne fl1 - lda >stdin+4+FILE_file use fgetc if stdio has a bogus file ID - cmp #stdinID - bne fl1 + lda >stdin use fgetc if stdin has changed + cmp #stdin+4 + bne fl1 + lda >stdin+2 + cmp #^stdin+4 + bne fl1 + lda >stdin+4+FILE_file use fgetc if stdio has a bogus file ID + cmp #stdinID + bne fl1 ; ; get the char from the keyboard ; - lda >stdin+4+FILE_pbk if there is a char in the putback - and #$0080 buffer then - bne lb1 - lda >stdin+4+FILE_pbk save it in x - and #$00FF - tax - lda >stdin+4+FILE_pbk pop the buffer - xba - ora #$FF00 - sta >stdin+4+FILE_pbk - txa restore the char - bra lb2 + lda >stdin+4+FILE_pbk if there is a char in the putback + and #$0080 buffer then + bne lb1 + lda >stdin+4+FILE_pbk save it in x + and #$00FF + tax + lda >stdin+4+FILE_pbk pop the buffer + xba + ora #$FF00 + sta >stdin+4+FILE_pbk + txa restore the char + bra lb2 -lb1 jsl SYSKEYIN else get a char from the keyboard - tax branch if not eof - bne lb2 - lda #_IOEOF set EOF flag - ora >stdin+4+FILE_flag - sta >stdin+4+FILE_flag - jsl SYSKEYIN read the closing cr - lda #EOF return EOF -lb2 cmp #13 if the char is \r then - bne lb3 - lda #10 return \n -lb3 rtl +lb1 jsl SYSKEYIN else get a char from the keyboard + tax branch if not eof + bne lb2 + lda #_IOEOF set EOF flag + ora >stdin+4+FILE_flag + sta >stdin+4+FILE_flag + jsl SYSKEYIN read the closing cr + lda #EOF return EOF +lb2 cmp #13 if the char is \r then + bne lb3 + lda #10 return \n +lb3 rtl ; ; Call fgetc ; -fl1 ph4 >stdin - dc i1'$22',s3'fgetc' jsl fgetc - rtl - end +fl1 ph4 >stdin + dc i1'$22',s3'fgetc' jsl fgetc + rtl + end **************************************************************** * * char *gets(s) -* char s; +* char s; * * Read a line from standard in. * * Inputs: -* s - string to read to. +* s - string to read to. * * Outputs: -* Returns a pointer to the string +* Returns a pointer to the string * **************************************************************** * -gets start -LF equ 10 \n key code +gets start +LF equ 10 \n key code -disp equ 1 disp in s +disp equ 1 disp in s - csubroutine (4:s),2 + csubroutine (4:s),2 - stz disp no characters processed so far -lb1 jsl getchar get a character - tax quit with error if it is an EOF - bpl lb2 - stz s - stz s+2 - bra rts -lb2 cmp #LF quit if it was a \n - beq lb3 - ldy disp place the char in the string - sta [s],Y - inc disp - bra lb1 next character -lb3 ldy disp null terminate - short M - lda #0 - sta [s],Y - long M + stz disp no characters processed so far +lb1 jsl getchar get a character + tax quit with error if it is an EOF + bpl lb2 + stz s + stz s+2 + bra rts +lb2 cmp #LF quit if it was a \n + beq lb3 + ldy disp place the char in the string + sta [s],Y + inc disp + bra lb1 next character +lb3 ldy disp null terminate + short M + lda #0 + sta [s],Y + long M -rts creturn 4:s - end +rts creturn 4:s + end **************************************************************** * * void perror(s); -* char *s; +* char *s; * * Prints the string s and the error in errno to standard out. * **************************************************************** * -perror start -maxErr equ EILSEQ max error in sys_errlist +perror start +maxErr equ EILSEQ max error in sys_errlist -s equ 4 string address +s equ 4 string address - tsc set up DP addressing - phd - tcd - - lda s skip prefix string if it is NULL/empty - ora s+2 - beq lb0 - lda [s] - and #$00FF - beq lb0 + tsc set up DP addressing + phd + tcd + + lda s skip prefix string if it is NULL/empty + ora s+2 + beq lb0 + lda [s] + and #$00FF + beq lb0 - ph4 >stderr write the error string - ph4 s - jsl fputs - ph4 >stderr write ': ' - pea ':' - jsl fputc - ph4 >stderr - pea ' ' - jsl fputc -lb0 ph4 >stderr write the error message - lda >errno - cmp #maxErr+1 - blt lb1 - lda #0 -lb1 asl A - asl A - tax - lda >sys_errlist+2,X - pha - lda >sys_errlist,X - pha - jsl fputs - ph4 >stderr write lf - pea 10 - jsl fputc + ph4 >stderr write the error string + ph4 s + jsl fputs + ph4 >stderr write ': ' + pea ':' + jsl fputc + ph4 >stderr + pea ' ' + jsl fputc +lb0 ph4 >stderr write the error message + lda >errno + cmp #maxErr+1 + blt lb1 + lda #0 +lb1 asl A + asl A + tax + lda >sys_errlist+2,X + pha + lda >sys_errlist,X + pha + jsl fputs + ph4 >stderr write lf + pea 10 + jsl fputc - pld remove parm and return - lda 2,S - sta 6,S - pla - sta 3,S - pla - rtl - end + pld remove parm and return + lda 2,S + sta 6,S + pla + sta 3,S + pla + rtl + end **************************************************************** * @@ -2238,42 +2238,42 @@ lb1 asl A * **************************************************************** * -printf start - using ~printfCommon +printf start + using ~printfCommon - lda #putchar - sta >~putchar+4 - lda #>putchar - sta >~putchar+5 - tsc find the argument list address - clc - adc #8 - sta >args - pea 0 - pha - jsl ~printf call the formatter - sec compute the space to pull from the stack - pla - sbc >args - clc - adc #4 - sta >args - pla - phb remove the return address - plx - ply - tsc update the stack pointer - clc - adc >args - tcs - phy restore the return address - phx - plb - lda >~numChars return the value - rtl return + lda #putchar + sta >~putchar+4 + lda #>putchar + sta >~putchar+5 + tsc find the argument list address + clc + adc #8 + sta >args + pea 0 + pha + jsl ~printf call the formatter + sec compute the space to pull from the stack + pla + sbc >args + clc + adc #4 + sta >args + pla + phb remove the return address + plx + ply + tsc update the stack pointer + clc + adc >args + tcs + phy restore the return address + phx + plb + lda >~numChars return the value + rtl return -args ds 2 original argument address - end +args ds 2 original argument address + end **************************************************************** * @@ -2288,58 +2288,58 @@ args ds 2 original argument address * **************************************************************** * -putchar start - using ~printfCommon -_n equ 10 linefeed character -_r equ 13 RETURN key code +putchar start + using ~printfCommon +_n equ 10 linefeed character +_r equ 13 RETURN key code ; ; Determine which method to use ; - lda >stdout use fgetc if stdin has changed - cmp #stdout+4 - bne fl1 - lda >stdout+1 - cmp #>stdout+4 - bne fl1 - lda >stdout+4+FILE_file use fgetc if stdio has a bogus file ID - cmp #stdoutID - bne fl1 + lda >stdout use fgetc if stdin has changed + cmp #stdout+4 + bne fl1 + lda >stdout+1 + cmp #>stdout+4 + bne fl1 + lda >stdout+4+FILE_file use fgetc if stdio has a bogus file ID + cmp #stdoutID + bne fl1 ; ; Write to the CRT ; -~stdout entry - php remove the parameter from the stack - plx - ply - pla - phy - phx - plp - pha save the parameter - cmp #_n if this is a line feed, do a - bne lb1 carriage return, instead. - lda #_r -lb1 pha write the character - jsl SYSCHAROUT - pla return the input character - rtl +~stdout entry + php remove the parameter from the stack + plx + ply + pla + phy + phx + plp + pha save the parameter + cmp #_n if this is a line feed, do a + bne lb1 carriage return, instead. + lda #_r +lb1 pha write the character + jsl SYSCHAROUT + pla return the input character + rtl ; ; Use fputc ; -fl1 ph4 >stdout - lda 8,S - pha - dc i1'$22' jsl fputc - dc s3'fputc' - phb - plx - ply - pla - phy - phx - plb - rtl - end +fl1 ph4 >stdout + lda 8,S + pha + dc i1'$22' jsl fputc + dc s3'fputc' + phb + plx + ply + pla + phy + phx + plb + rtl + end **************************************************************** * @@ -2351,157 +2351,157 @@ fl1 ph4 >stdout * **************************************************************** * -puts start -LINEFEED equ 10 linefeed character +puts start +LINEFEED equ 10 linefeed character -err equ 1 erro code +err equ 1 erro code - csubroutine (4:s),2 + csubroutine (4:s),2 - stz err no error -lb1 lda [s] print the string - and #$00FF - beq lb2 - pha - jsl putchar - inc4 s - bra lb1 -lb2 pea LINEFEED print the linefeed - jsl putchar + stz err no error +lb1 lda [s] print the string + and #$00FF + beq lb2 + pha + jsl putchar + inc4 s + bra lb1 +lb2 pea LINEFEED print the linefeed + jsl putchar - creturn 2:err - end + creturn 2:err + end **************************************************************** * * int remove(filename) -* char *filename; +* char *filename; * * Inputs: -* filename - name of the file to delete +* filename - name of the file to delete * * Outputs: -* Returns zero if successful, GS/OS error code if not. +* Returns zero if successful, GS/OS error code if not. * **************************************************************** * -remove start -err equ 1 return code +remove start +err equ 1 return code - csubroutine (4:filename),2 - phb - phk - plb + csubroutine (4:filename),2 + phb + phk + plb - ph4 filename convert to a GS/OS file name - jsl ~osname - sta dsPathName - stx dsPathName+2 - ora dsPathName+2 - bne lb1 - lda #$FFFF - sta err - bra lb2 -lb1 OSDestroy ds delete the file - sta err set the error code - bcc lb1a - lda #ENOENT - sta >errno -lb1a ph4 dsPathName dispose of the name buffer - jsl free + ph4 filename convert to a GS/OS file name + jsl ~osname + sta dsPathName + stx dsPathName+2 + ora dsPathName+2 + bne lb1 + lda #$FFFF + sta err + bra lb2 +lb1 OSDestroy ds delete the file + sta err set the error code + bcc lb1a + lda #ENOENT + sta >errno +lb1a ph4 dsPathName dispose of the name buffer + jsl free -lb2 plb - creturn 2:err +lb2 plb + creturn 2:err -ds dc i'1' parameter block for OSDestroy -dsPathName ds 4 - end +ds dc i'1' parameter block for OSDestroy +dsPathName ds 4 + end **************************************************************** * * int rename(oldname,newname) -* char *filename; +* char *filename; * * Inputs: -* filename - name of the file to delete +* filename - name of the file to delete * * Outputs: -* Returns zero if successful, GS/OS error code if not. +* Returns zero if successful, GS/OS error code if not. * **************************************************************** * -rename start -err equ 1 return code +rename start +err equ 1 return code - csubroutine (4:oldname,4:newname),2 - phb - phk - plb + csubroutine (4:oldname,4:newname),2 + phb + phk + plb - ph4 oldname convert oldname to a GS/OS file name - jsl ~osname - sta cpPathName - stx cpPathName+2 - ora cpPathName+2 - bne lb1 - lda #$FFFF - sta err - bra lb4 -lb1 ph4 newname convert newname to a GS/OS file name - jsl ~osname - sta cpNewPathName - stx cpNewPathName+2 - ora cpNewPathName+2 - bne lb2 - lda #$FFFF - sta err - bra lb3 -lb2 OSChange_Path cp rename the file - sta err set the error code - ph4 cpNewPathName dispose of the new name buffer - jsl free -lb3 ph4 cpPathName dispose of the old name buffer - jsl free + ph4 oldname convert oldname to a GS/OS file name + jsl ~osname + sta cpPathName + stx cpPathName+2 + ora cpPathName+2 + bne lb1 + lda #$FFFF + sta err + bra lb4 +lb1 ph4 newname convert newname to a GS/OS file name + jsl ~osname + sta cpNewPathName + stx cpNewPathName+2 + ora cpNewPathName+2 + bne lb2 + lda #$FFFF + sta err + bra lb3 +lb2 OSChange_Path cp rename the file + sta err set the error code + ph4 cpNewPathName dispose of the new name buffer + jsl free +lb3 ph4 cpPathName dispose of the old name buffer + jsl free -lb4 plb - creturn 2:err +lb4 plb + creturn 2:err -cp dc i'2' parameter block for OSChange_Path -cpPathName ds 4 +cp dc i'2' parameter block for OSChange_Path +cpPathName ds 4 cpNewPathName ds 4 - end + end **************************************************************** * * void rewind(stream) -* FILE *stream; +* FILE *stream; * * Rewind the read/write location for the stream. * * Inputs: -* stream - file to change +* stream - file to change * **************************************************************** * -rewind start - csubroutine (4:stream),0 +rewind start + csubroutine (4:stream),0 - ph4 stream verify that stream exists - jsl ~VerifyStream - bcs ret + ph4 stream verify that stream exists + jsl ~VerifyStream + bcs ret - ph2 #SEEK_SET - ph4 #0 - ph4 stream - jsl __fseek + ph2 #SEEK_SET + ph4 #0 + ph4 stream + jsl __fseek - ldy #FILE_flag clear the error flag - lda [stream],Y - and #$FFFF-_IOERR - sta [stream],Y + ldy #FILE_flag clear the error flag + lda [stream],Y + and #$FFFF-_IOERR + sta [stream],Y -ret creturn - end +ret creturn + end **************************************************************** * @@ -2512,38 +2512,38 @@ ret creturn * **************************************************************** * -scanf start - using ~scanfCommon +scanf start + using ~scanfCommon - lda #getchar - sta >~getchar+10 - lda #>getchar - sta >~getchar+11 + lda #getchar + sta >~getchar+10 + lda #>getchar + sta >~getchar+11 - lda #unget - sta >~putback+12 - lda #>unget - sta >~putback+13 + lda #unget + sta >~putback+12 + lda #>unget + sta >~putback+13 - lda #~RemoveWordFromStack - sta >~RemoveWord+1 - lda #>~RemoveWordFromStack - sta >~RemoveWord+2 + lda #~RemoveWordFromStack + sta >~RemoveWord+1 + lda #>~RemoveWordFromStack + sta >~RemoveWord+2 - lda #0 - sta >~isVarArgs + lda #0 + sta >~isVarArgs - brl ~scanf + brl ~scanf -unget tax - lda >stdin+2 - pha - lda >stdin - pha - phx - jsl ungetc - rtl - end +unget tax + lda >stdin+2 + pha + lda >stdin + pha + phx + jsl ungetc + rtl + end **************************************************************** * @@ -2552,158 +2552,158 @@ unget tax * Set the buffer type and size. * * Inputs: -* stream - file to set the buffer for -* buf - buffer to use, or NULL for automatic buffer +* stream - file to set the buffer for +* buf - buffer to use, or NULL for automatic buffer * * Outputs: -* Returns zero if successful, -1 for an error +* Returns zero if successful, -1 for an error * **************************************************************** * -setbuf start -err equ 1 return code +setbuf start +err equ 1 return code - csubroutine (4:stream,4:buf),2 + csubroutine (4:stream,4:buf),2 - lda buf - ora buf+2 - bne lb1 - ph4 #0 - ph2 #_IONBF - bra lb2 -lb1 ph4 #BUFSIZ - ph2 #_IOFBF -lb2 ph4 buf - ph4 stream - jsl __setvbuf - sta err + lda buf + ora buf+2 + bne lb1 + ph4 #0 + ph2 #_IONBF + bra lb2 +lb1 ph4 #BUFSIZ + ph2 #_IOFBF +lb2 ph4 buf + ph4 stream + jsl __setvbuf + sta err - creturn 2:err - end + creturn 2:err + end **************************************************************** * * int setvbuf(stream,buf,type,size) -* FILE *stream; -* char *buf; -* int type,size; +* FILE *stream; +* char *buf; +* int type,size; * * Set the buffer type and size. * * Inputs: -* stream - file to set the buffer for -* buf - buffer to use, or NULL for automatic buffer -* type - buffer type; _IOFBF, _IOLBF or _IONBF -* size - size of the buffer +* stream - file to set the buffer for +* buf - buffer to use, or NULL for automatic buffer +* type - buffer type; _IOFBF, _IOLBF or _IONBF +* size - size of the buffer * * Outputs: -* Returns zero if successful, -1 for an error +* Returns zero if successful, -1 for an error * **************************************************************** * -setvbuf start - jmp __setvbuf - end +setvbuf start + jmp __setvbuf + end __setvbuf start -err equ 1 return code +err equ 1 return code - csubroutine (4:stream,4:buf,2:type,4:size),2 + csubroutine (4:stream,4:buf,2:type,4:size),2 - phb - phk - plb - lda #-1 assume we will get an error - sta err - ph4 stream verify that stream exists - jsl ~VerifyStream - jcs rts - ldy #FILE_ptr make sure the buffer is not in use - lda [stream],Y - ldy #FILE_base - cmp [stream],Y - jne rts - ldy #FILE_ptr+2 - lda [stream],Y - ldy #FILE_base+2 - cmp [stream],Y - jne rts -cb1 lda size if size is zero then - ora size+2 - bne lb1 - lda type if ~(type & _IONBF) then - and #_IONBF - jeq rts flag the error - inc size else size = 1 -lb1 lda type error if type is not one of these - cmp #_IOFBF - beq lb2 - cmp #_IOLBF - beq lb2 - cmp #_IONBF - bne rts -lb2 lda buf if the buffer is not supplied by the - ora buf+2 caller then - bne sb1 - ph4 size allocate a buffer - jsl malloc - sta buf - stx buf+2 - ora buf+2 quit if there was no memory - beq rts - lda type set the buffer flag - ora #_IOMYBUF - sta type + phb + phk + plb + lda #-1 assume we will get an error + sta err + ph4 stream verify that stream exists + jsl ~VerifyStream + jcs rts + ldy #FILE_ptr make sure the buffer is not in use + lda [stream],Y + ldy #FILE_base + cmp [stream],Y + jne rts + ldy #FILE_ptr+2 + lda [stream],Y + ldy #FILE_base+2 + cmp [stream],Y + jne rts +cb1 lda size if size is zero then + ora size+2 + bne lb1 + lda type if ~(type & _IONBF) then + and #_IONBF + jeq rts flag the error + inc size else size = 1 +lb1 lda type error if type is not one of these + cmp #_IOFBF + beq lb2 + cmp #_IOLBF + beq lb2 + cmp #_IONBF + bne rts +lb2 lda buf if the buffer is not supplied by the + ora buf+2 caller then + bne sb1 + ph4 size allocate a buffer + jsl malloc + sta buf + stx buf+2 + ora buf+2 quit if there was no memory + beq rts + lda type set the buffer flag + ora #_IOMYBUF + sta type -sb1 ldy #FILE_flag if the buffer was allocated by fopen then - lda [stream],Y - bit #_IOMYBUF - beq sb2 - ldy #FILE_base+2 dispose of the old buffer - lda [stream],Y - pha - dey - dey - lda [stream],Y - pha - jsl free -sb2 ldy #FILE_flag clear the old buffering flags - lda #$FFFF-_IOFBF-_IOLBF-_IONBF-_IOMYBUF - and [stream],Y - ora type set the new buffer flag - sta [stream],Y +sb1 ldy #FILE_flag if the buffer was allocated by fopen then + lda [stream],Y + bit #_IOMYBUF + beq sb2 + ldy #FILE_base+2 dispose of the old buffer + lda [stream],Y + pha + dey + dey + lda [stream],Y + pha + jsl free +sb2 ldy #FILE_flag clear the old buffering flags + lda #$FFFF-_IOFBF-_IOLBF-_IONBF-_IOMYBUF + and [stream],Y + ora type set the new buffer flag + sta [stream],Y - lda buf set the start of the buffer - ldy #FILE_base - sta [stream],Y - iny - iny - lda buf+2 - sta [stream],Y - ldy #FILE_ptr+2 - sta [stream],Y - dey - dey - lda buf - sta [stream],Y - ldy #FILE_size set the buffer size - lda size - sta [stream],Y - iny - iny - lda size+2 - sta [stream],Y - ldy #FILE_cnt no chars in buffer - lda #0 - sta [stream],Y - iny - iny - sta [stream],Y - stz err no error + lda buf set the start of the buffer + ldy #FILE_base + sta [stream],Y + iny + iny + lda buf+2 + sta [stream],Y + ldy #FILE_ptr+2 + sta [stream],Y + dey + dey + lda buf + sta [stream],Y + ldy #FILE_size set the buffer size + lda size + sta [stream],Y + iny + iny + lda size+2 + sta [stream],Y + ldy #FILE_cnt no chars in buffer + lda #0 + sta [stream],Y + iny + iny + sta [stream],Y + stz err no error -rts plb - creturn 2:err - end +rts plb + creturn 2:err + end **************************************************************** * @@ -2714,91 +2714,91 @@ rts plb * **************************************************************** * -sprintf start - using ~printfCommon +sprintf start + using ~printfCommon - phb use local addressing - phk - plb - plx remove the return address - ply - phd initialize output to empty string - tsc - tcd - short M - lda #0 - sta [3] - long M - pld - pla save the stream - sta string - pla - sta string+2 - phy restore return address/data bank - phx - plb - lda #put set up output routine - sta >~putchar+4 - lda #>put - sta >~putchar+5 + phb use local addressing + phk + plb + plx remove the return address + ply + phd initialize output to empty string + tsc + tcd + short M + lda #0 + sta [3] + long M + pld + pla save the stream + sta string + pla + sta string+2 + phy restore return address/data bank + phx + plb + lda #put set up output routine + sta >~putchar+4 + lda #>put + sta >~putchar+5 - tsc find the argument list address - clc - adc #8 - sta >args - pea 0 - pha - jsl ~printf call the formatter - sec compute the space to pull from the stack - pla - sbc >args - clc - adc #4 - sta >args - pla - phb remove the return address - plx - ply - tsc update the stack pointer - clc - adc >args - tcs - phy restore the return address - phx - plb - lda >~numChars return the value - rtl return - -put phb remove the char from the stack - plx - pla - ply - pha - phx - plb - ldx string+2 write to a file - phx - ldx string - phx - phd - tsc - tcd - tya - and #$00FF - sta [3] - pld - pla - pla - phb - phk - plb - inc4 string - plb - rtl + tsc find the argument list address + clc + adc #8 + sta >args + pea 0 + pha + jsl ~printf call the formatter + sec compute the space to pull from the stack + pla + sbc >args + clc + adc #4 + sta >args + pla + phb remove the return address + plx + ply + tsc update the stack pointer + clc + adc >args + tcs + phy restore the return address + phx + plb + lda >~numChars return the value + rtl return + +put phb remove the char from the stack + plx + pla + ply + pha + phx + plb + ldx string+2 write to a file + phx + ldx string + phx + phd + tsc + tcd + tya + and #$00FF + sta [3] + pld + pla + pla + phb + phk + plb + inc4 string + plb + rtl -args ds 2 original argument address -string ds 4 string address - end +args ds 2 original argument address +string ds 4 string address + end **************************************************************** * @@ -2809,122 +2809,122 @@ string ds 4 string address **************************************************************** * snprintf start - using ~printfCommon + using ~printfCommon - phb use local addressing - phk - plb - plx remove the return address - ply - lda 5,S check if n == 0 - ora 7,S - bne lb1 - lda #put2 set up do-nothing output routine - sta >~putchar+4 - lda #>put2 - sta >~putchar+5 - bra lb2 -lb1 phd initialize output to empty string - tsc - tcd - short M - lda #0 - sta [3] - long M - pld - lda #put set up output routine - sta >~putchar+4 - lda #>put - sta >~putchar+5 -lb2 pla save the destination string - sta string - pla - sta string+2 - pla save n value - sta count - pla - sta count+2 - phy restore return address/data bank - phx - plb + phb use local addressing + phk + plb + plx remove the return address + ply + lda 5,S check if n == 0 + ora 7,S + bne lb1 + lda #put2 set up do-nothing output routine + sta >~putchar+4 + lda #>put2 + sta >~putchar+5 + bra lb2 +lb1 phd initialize output to empty string + tsc + tcd + short M + lda #0 + sta [3] + long M + pld + lda #put set up output routine + sta >~putchar+4 + lda #>put + sta >~putchar+5 +lb2 pla save the destination string + sta string + pla + sta string+2 + pla save n value + sta count + pla + sta count+2 + phy restore return address/data bank + phx + plb - tsc find the argument list address - clc - adc #8 - sta >args - pea 0 - pha - jsl ~printf call the formatter - sec compute the space to pull from the stack - pla - sbc >args - clc - adc #4 - sta >args - pla - phb remove the return address - plx - ply - tsc update the stack pointer - clc - adc >args - tcs - phy restore the return address - phx - plb - lda >~numChars return the value - rtl return - -put phb remove the char from the stack - phk - plb - plx - pla - ply - pha - phx - lda count decrement count - bne pt1 - dec count+2 -pt1 dec count - bne pt2 if count == 0: - lda count+2 - bne pt2 -pt1a lda #put2 set up do-nothing output routine - sta >~putchar+4 - lda #>put2 - sta >~putchar+5 - bra pt3 return without writing -pt2 ldx string+2 write to string - phx - ldx string - phx - phd - tsc - tcd - tya - and #$00FF - sta [3] - pld - pla - pla - inc4 string -pt3 plb - rtl + tsc find the argument list address + clc + adc #8 + sta >args + pea 0 + pha + jsl ~printf call the formatter + sec compute the space to pull from the stack + pla + sbc >args + clc + adc #4 + sta >args + pla + phb remove the return address + plx + ply + tsc update the stack pointer + clc + adc >args + tcs + phy restore the return address + phx + plb + lda >~numChars return the value + rtl return + +put phb remove the char from the stack + phk + plb + plx + pla + ply + pha + phx + lda count decrement count + bne pt1 + dec count+2 +pt1 dec count + bne pt2 if count == 0: + lda count+2 + bne pt2 +pt1a lda #put2 set up do-nothing output routine + sta >~putchar+4 + lda #>put2 + sta >~putchar+5 + bra pt3 return without writing +pt2 ldx string+2 write to string + phx + ldx string + phx + phd + tsc + tcd + tya + and #$00FF + sta [3] + pld + pla + pla + inc4 string +pt3 plb + rtl -put2 phb remove the char from the stack - plx - pla - ply - pha - phx - plb - rtl return, discarding the character +put2 phb remove the char from the stack + plx + pla + ply + pha + phx + plb + rtl return, discarding the character -args ds 2 original argument address -string ds 4 string address -count ds 4 chars left to write - end +args ds 2 original argument address +string ds 4 string address +count ds 4 chars left to write + end **************************************************************** * @@ -2935,64 +2935,64 @@ count ds 4 chars left to write * **************************************************************** * -sscanf start - using ~scanfCommon +sscanf start + using ~scanfCommon - phb use local addressing - phk - plb - plx remove the return address - ply - pla save the stream - sta string - pla - sta string+2 - phy restore return address/data bank - phx - plb + phb use local addressing + phk + plb + plx remove the return address + ply + pla save the stream + sta string + pla + sta string+2 + phy restore return address/data bank + phx + plb - lda #get set up our routines - sta >~getchar+10 - lda #>get - sta >~getchar+11 + lda #get set up our routines + sta >~getchar+10 + lda #>get + sta >~getchar+11 - lda #unget - sta >~putback+12 - lda #>unget - sta >~putback+13 + lda #unget + sta >~putback+12 + lda #>unget + sta >~putback+13 - lda #~RemoveWordFromStack - sta >~RemoveWord+1 - lda #>~RemoveWordFromStack - sta >~RemoveWord+2 + lda #~RemoveWordFromStack + sta >~RemoveWord+1 + lda #>~RemoveWordFromStack + sta >~RemoveWord+2 - lda #0 - sta >~isVarArgs + lda #0 + sta >~isVarArgs - brl ~scanf + brl ~scanf -get ph4 string get a character - phd - tsc - tcd - lda [3] - and #$00FF - bne gt1 - dec4 string - lda #EOF -gt1 pld - ply - ply - inc4 string - rtl +get ph4 string get a character + phd + tsc + tcd + lda [3] + and #$00FF + bne gt1 + dec4 string + lda #EOF +gt1 pld + ply + ply + inc4 string + rtl -unget cmp #EOF put a character back - beq ug1 - dec4 string -ug1 rtl +unget cmp #EOF put a character back + beq ug1 + dec4 string +ug1 rtl -string ds 4 - end +string ds 4 + end **************************************************************** * @@ -3001,205 +3001,205 @@ string ds 4 **************************************************************** * sys_errlist start - dc a4'EUNDEF' 0th message is undefined - dc a4'EDOM' (if the size of this list changes, - dc a4'ERANGE' change sys_nerr in VARS.ASM) - dc a4'ENOMEM' - dc a4'ENOENT' - dc a4'EIO' - dc a4'EINVAL' - dc a4'EBADF' - dc a4'EMFILE' - dc a4'EACCESS' - dc a4'EEXISTS' - dc a4'ENOSPC' - dc a4'EILSEQ' + dc a4'EUNDEF' 0th message is undefined + dc a4'EDOM' (if the size of this list changes, + dc a4'ERANGE' change sys_nerr in VARS.ASM) + dc a4'ENOMEM' + dc a4'ENOENT' + dc a4'EIO' + dc a4'EINVAL' + dc a4'EBADF' + dc a4'EMFILE' + dc a4'EACCESS' + dc a4'EEXISTS' + dc a4'ENOSPC' + dc a4'EILSEQ' ! Note: if more errors are added, change maxErr in perror() and strerror(). -EUNDEF cstr 'invalid error number' -EDOM cstr 'domain error' -ERANGE cstr '# too large, too small, or illegal' -ENOMEM cstr 'not enough memory' -ENOENT cstr 'no such file or directory' -EIO cstr 'I/O error' -EINVAL cstr 'invalid argument' -EBADF cstr 'bad file descriptor' -EMFILE cstr 'too many files are open' -EACCESS cstr 'access bits prevent the operation' -EEXISTS cstr 'the file exists' -ENOSPC cstr 'the file is too large' -EILSEQ cstr 'encoding error' - end +EUNDEF cstr 'invalid error number' +EDOM cstr 'domain error' +ERANGE cstr '# too large, too small, or illegal' +ENOMEM cstr 'not enough memory' +ENOENT cstr 'no such file or directory' +EIO cstr 'I/O error' +EINVAL cstr 'invalid argument' +EBADF cstr 'bad file descriptor' +EMFILE cstr 'too many files are open' +EACCESS cstr 'access bits prevent the operation' +EEXISTS cstr 'the file exists' +ENOSPC cstr 'the file is too large' +EILSEQ cstr 'encoding error' + end **************************************************************** * * char *tmpnam(buf) -* char *buf; +* char *buf; * * Inputs: -* buf - Buffer to write the name to. Buf is assumed to -* be at least L_tmpnam characters long. It may be -* NULL, in which case the name is not written to -* a buffer. +* buf - Buffer to write the name to. Buf is assumed to +* be at least L_tmpnam characters long. It may be +* NULL, in which case the name is not written to +* a buffer. * * Outputs: -* Returns a pointer to the name, which is changed on the -* next call to tmpnam or tmpfile. +* Returns a pointer to the name, which is changed on the +* next call to tmpnam or tmpfile. * * Notes: -* If the work prefix is set, and is less than or equal -* to 15 characters in length, the file name returned is -* in the work prefix (3); otherwise, it is a partial path -* name. +* If the work prefix is set, and is less than or equal +* to 15 characters in length, the file name returned is +* in the work prefix (3); otherwise, it is a partial path +* name. * **************************************************************** * -tmpnam start +tmpnam start - csubroutine (4:buf),0 - phb - phk - plb + csubroutine (4:buf),0 + phb + phk + plb -lb1 OSGet_Prefix pr get the prefix - bcc lb2 - stz name+2 -lb2 short M - ldx name+2 - stz cname,X - ldx #7 update the file number -lb3 inc syscxxxx,X - lda syscxxxx,X - cmp #'9'+1 - bne lb4 - lda #'0' - sta syscxxxx,X - dex - cpx #3 - bne lb3 -lb4 long M append the two strings - ph4 #syscxxxx - ph4 #cname - jsl strcat +lb1 OSGet_Prefix pr get the prefix + bcc lb2 + stz name+2 +lb2 short M + ldx name+2 + stz cname,X + ldx #7 update the file number +lb3 inc syscxxxx,X + lda syscxxxx,X + cmp #'9'+1 + bne lb4 + lda #'0' + sta syscxxxx,X + dex + cpx #3 + bne lb3 +lb4 long M append the two strings + ph4 #syscxxxx + ph4 #cname + jsl strcat - ph4 #cname if the file exists then - jsl strlen - sta name+2 - OSGet_File_Info GIParm - bcc lb1 get a different name + ph4 #cname if the file exists then + jsl strlen + sta name+2 + OSGet_File_Info GIParm + bcc lb1 get a different name - lda buf if buf != NULL then - ora buf+2 - beq lb5 - ph4 #cname move the string - ph4 buf - jsl strcpy - bra lb6 + lda buf if buf != NULL then + ora buf+2 + beq lb5 + ph4 #cname move the string + ph4 buf + jsl strcpy + bra lb6 -lb5 lla buf,cname return the string pointer -lb6 plb - creturn 4:buf +lb5 lla buf,cname return the string pointer +lb6 plb + creturn 4:buf -pr dc i'2' parameter block for OSGet_Prefix - dc i'3' - dc a4'name' +pr dc i'2' parameter block for OSGet_Prefix + dc i'3' + dc a4'name' -name dc i'16,0' GS/OS name buffer -cname ds 26 part of name; also C buffer -GS_OSname dc i'8' used for OSGet_File_Info -syscxxxx dc c'SYSC0000',i1'0' for creating unique names +name dc i'16,0' GS/OS name buffer +cname ds 26 part of name; also C buffer +GS_OSname dc i'8' used for OSGet_File_Info +syscxxxx dc c'SYSC0000',i1'0' for creating unique names -GIParm dc i'2' used to see if the file exists - dc a4'name+2' - dc i'0' - end +GIParm dc i'2' used to see if the file exists + dc a4'name+2' + dc i'0' + end **************************************************************** * * FILE *tmpfile() * * Outputs: -* Returns a pointer to a temp file; NULL for error. +* Returns a pointer to a temp file; NULL for error. * **************************************************************** * -tmpfile start -f equ 1 file pointer +tmpfile start +f equ 1 file pointer - csubroutine ,4 + csubroutine ,4 - ph4 #type open a file with a temp name - ph4 #0 - jsl tmpnam - phx - pha - jsl fopen - sta f - stx f+2 - ora f+2 if successful then - beq lb1 - ldy #FILE_flag f->_flag |= _IOTEMPFILE - lda [f],Y - ora #_IOTEMPFILE - sta [f],Y - -lb1 creturn 4:f + ph4 #type open a file with a temp name + ph4 #0 + jsl tmpnam + phx + pha + jsl fopen + sta f + stx f+2 + ora f+2 if successful then + beq lb1 + ldy #FILE_flag f->_flag |= _IOTEMPFILE + lda [f],Y + ora #_IOTEMPFILE + sta [f],Y + +lb1 creturn 4:f -type cstr 'w+bx' - end +type cstr 'w+bx' + end **************************************************************** * * int ungetc(c, stream) -* char c; -* FILE *stream; +* char c; +* FILE *stream; * * Return a character to the input stream. * * Inputs: -* c - character to return -* stream - stream to put it back in +* c - character to return +* stream - stream to put it back in * * Outputs: -* Returns EOF if the attempt was unsuccessful; c if the -* attempt succeeded. +* Returns EOF if the attempt was unsuccessful; c if the +* attempt succeeded. * **************************************************************** * -ungetc start +ungetc start -char equ 1 character to return +char equ 1 character to return - csubroutine (2:c,4:stream),2 + csubroutine (2:c,4:stream),2 - lda #EOF assume we will fail - sta char - ldy #FILE_flag error if the file is open for output - lda [stream],Y - bit #_IOWRT - bne rts - lda c error if EOF is pushed - cmp #EOF - beq rts - ldy #FILE_pbk+1 error if the buffer is full - short M - lda [stream],Y - bpl rts - dey push the old character (if any) - lda [stream],Y - iny - sta [stream],Y - dey - lda c put back the character - sta [stream],Y - sta char - stz char+1 - bpl rts - dec char+1 -rts long M - creturn 2:char - end + lda #EOF assume we will fail + sta char + ldy #FILE_flag error if the file is open for output + lda [stream],Y + bit #_IOWRT + bne rts + lda c error if EOF is pushed + cmp #EOF + beq rts + ldy #FILE_pbk+1 error if the buffer is full + short M + lda [stream],Y + bpl rts + dey push the old character (if any) + lda [stream],Y + iny + sta [stream],Y + dey + lda c put back the character + sta [stream],Y + sta char + stz char+1 + bpl rts + dec char+1 +rts long M + creturn 2:char + end **************************************************************** * @@ -3209,83 +3209,83 @@ rts long M * **************************************************************** * -vfprintf start - using ~printfCommon +vfprintf start + using ~printfCommon - phb use local addressing - phk - plb - plx remove the return address - ply - pla save the stream - sta stream - pla - sta stream+2 - phy restore return address/data bank - phx - plb - lda >stream+2 verify that stream exists - pha - lda >stream - pha - jsl ~VerifyStream - bcc lb1 - lda #EIO - sta >errno - lda #EOF - bra rts -lb1 lda #put set up output routine - sta >~putchar+4 - lda #>put - sta >~putchar+5 - phd find the argument list address - tsc - tcd - lda [10] - pld - pea 0 - pha - jsl ~printf call the formatter - ply update the argument list pointer - plx - phd - tsc - tcd - tya - sta [10] - pld - phb remove the return address - plx - ply - tsc update the stack pointer - clc - adc #8 - tcs - phy restore the return address - phx - plb - lda >~numChars return the value - rtl return + phb use local addressing + phk + plb + plx remove the return address + ply + pla save the stream + sta stream + pla + sta stream+2 + phy restore return address/data bank + phx + plb + lda >stream+2 verify that stream exists + pha + lda >stream + pha + jsl ~VerifyStream + bcc lb1 + lda #EIO + sta >errno + lda #EOF + bra rts +lb1 lda #put set up output routine + sta >~putchar+4 + lda #>put + sta >~putchar+5 + phd find the argument list address + tsc + tcd + lda [10] + pld + pea 0 + pha + jsl ~printf call the formatter + ply update the argument list pointer + plx + phd + tsc + tcd + tya + sta [10] + pld + phb remove the return address + plx + ply + tsc update the stack pointer + clc + adc #8 + tcs + phy restore the return address + phx + plb + lda >~numChars return the value + rtl return -put phb remove the char from the stack - phk - plb - plx - pla - ply - pha - phx - plb - lda stream+2 write to a file - pha - lda stream - pha - phy - jsl fputc -rts rtl +put phb remove the char from the stack + phk + plb + plx + pla + ply + pha + phx + plb + lda stream+2 write to a file + pha + lda stream + pha + phy + jsl fputc +rts rtl -stream ds 4 stream address - end +stream ds 4 stream address + end **************************************************************** * @@ -3295,42 +3295,42 @@ stream ds 4 stream address * **************************************************************** * -vprintf start - using ~printfCommon +vprintf start + using ~printfCommon - lda #putchar set up the output hooks - sta >~putchar+4 - lda #>putchar - sta >~putchar+5 - phd find the argument list address - tsc - tcd - lda [10] - pld - pea 0 - pha - jsl ~printf call the formatter - ply update the argument list pointer - plx - phd - tsc - tcd - tya - sta [10] - pld - phb remove the return address - plx - ply - tsc update the stack pointer - clc - adc #8 - tcs - phy restore the return address - phx - plb - lda >~numChars return the value - rtl return - end + lda #putchar set up the output hooks + sta >~putchar+4 + lda #>putchar + sta >~putchar+5 + phd find the argument list address + tsc + tcd + lda [10] + pld + pea 0 + pha + jsl ~printf call the formatter + ply update the argument list pointer + plx + phd + tsc + tcd + tya + sta [10] + pld + phb remove the return address + plx + ply + tsc update the stack pointer + clc + adc #8 + tcs + phy restore the return address + phx + plb + lda >~numChars return the value + rtl return + end **************************************************************** * @@ -3340,92 +3340,92 @@ vprintf start * **************************************************************** * -vsprintf start - using ~printfCommon +vsprintf start + using ~printfCommon - phb use local addressing - phk - plb - plx remove the return address - ply - phd initialize output to empty string - tsc - tcd - short M - lda #0 - sta [3] - long M - pld - pla save the stream - sta string - pla - sta string+2 - phy restore return address/data bank - phx - plb - lda #put set up output routine - sta >~putchar+4 - lda #>put - sta >~putchar+5 + phb use local addressing + phk + plb + plx remove the return address + ply + phd initialize output to empty string + tsc + tcd + short M + lda #0 + sta [3] + long M + pld + pla save the stream + sta string + pla + sta string+2 + phy restore return address/data bank + phx + plb + lda #put set up output routine + sta >~putchar+4 + lda #>put + sta >~putchar+5 - phd find the argument list address - tsc - tcd - lda [10] - pld - pea 0 - pha - jsl ~printf call the formatter - ply update the argument list pointer - plx - phd - tsc - tcd - tya - sta [10] - pld - phb remove the return address - plx - ply - tsc update the stack pointer - clc - adc #8 - tcs - phy restore the return address - phx - plb - lda >~numChars return the value - rtl return - -put phb remove the char from the stack - plx - pla - ply - pha - phx - plb - ldx string+2 write to a file - phx - ldx string - phx - phd - tsc - tcd - tya - and #$00FF - sta [3] - pld - pla - pla - phb - phk - plb - inc4 string - plb - rtl + phd find the argument list address + tsc + tcd + lda [10] + pld + pea 0 + pha + jsl ~printf call the formatter + ply update the argument list pointer + plx + phd + tsc + tcd + tya + sta [10] + pld + phb remove the return address + plx + ply + tsc update the stack pointer + clc + adc #8 + tcs + phy restore the return address + phx + plb + lda >~numChars return the value + rtl return + +put phb remove the char from the stack + plx + pla + ply + pha + phx + plb + ldx string+2 write to a file + phx + ldx string + phx + phd + tsc + tcd + tya + and #$00FF + sta [3] + pld + pla + pla + phb + phk + plb + inc4 string + plb + rtl -string ds 4 string address - end +string ds 4 string address + end **************************************************************** * @@ -3435,124 +3435,124 @@ string ds 4 string address * **************************************************************** * -vsnprintf start - using ~printfCommon +vsnprintf start + using ~printfCommon - phb use local addressing - phk - plb - plx remove the return address - ply - lda 5,S check if n == 0 - ora 7,S - bne lb1 - lda #put2 set up do-nothing output routine - sta >~putchar+4 - lda #>put2 - sta >~putchar+5 - bra lb2 -lb1 phd initialize output to empty string - tsc - tcd - short M - lda #0 - sta [3] - long M - pld - lda #put set up output routine - sta >~putchar+4 - lda #>put - sta >~putchar+5 -lb2 pla save the stream - sta string - pla - sta string+2 - pla save n value - sta count - pla - sta count+2 - phy restore return address/data bank - phx - plb + phb use local addressing + phk + plb + plx remove the return address + ply + lda 5,S check if n == 0 + ora 7,S + bne lb1 + lda #put2 set up do-nothing output routine + sta >~putchar+4 + lda #>put2 + sta >~putchar+5 + bra lb2 +lb1 phd initialize output to empty string + tsc + tcd + short M + lda #0 + sta [3] + long M + pld + lda #put set up output routine + sta >~putchar+4 + lda #>put + sta >~putchar+5 +lb2 pla save the stream + sta string + pla + sta string+2 + pla save n value + sta count + pla + sta count+2 + phy restore return address/data bank + phx + plb - phd find the argument list address - tsc - tcd - lda [10] - pld - pea 0 - pha - jsl ~printf call the formatter - ply update the argument list pointer - plx - phd - tsc - tcd - tya - sta [10] - pld - phb remove the return address - plx - ply - tsc update the stack pointer - clc - adc #8 - tcs - phy restore the return address - phx - plb - lda >~numChars return the value - rtl return - -put phb remove the char from the stack - phk - plb - plx - pla - ply - pha - phx - lda count decrement count - bne pt1 - dec count+2 -pt1 dec count - bne pt2 if count == 0: - lda count+2 - bne pt2 -pt1a lda #put2 set up do-nothing output routine - sta >~putchar+4 - lda #>put2 - sta >~putchar+5 - bra pt3 return without writing -pt2 ldx string+2 write to string - phx - ldx string - phx - phd - tsc - tcd - tya - and #$00FF - sta [3] - pld - pla - pla - inc4 string -pt3 plb - rtl + phd find the argument list address + tsc + tcd + lda [10] + pld + pea 0 + pha + jsl ~printf call the formatter + ply update the argument list pointer + plx + phd + tsc + tcd + tya + sta [10] + pld + phb remove the return address + plx + ply + tsc update the stack pointer + clc + adc #8 + tcs + phy restore the return address + phx + plb + lda >~numChars return the value + rtl return + +put phb remove the char from the stack + phk + plb + plx + pla + ply + pha + phx + lda count decrement count + bne pt1 + dec count+2 +pt1 dec count + bne pt2 if count == 0: + lda count+2 + bne pt2 +pt1a lda #put2 set up do-nothing output routine + sta >~putchar+4 + lda #>put2 + sta >~putchar+5 + bra pt3 return without writing +pt2 ldx string+2 write to string + phx + ldx string + phx + phd + tsc + tcd + tya + and #$00FF + sta [3] + pld + pla + pla + inc4 string +pt3 plb + rtl -put2 phb remove the char from the stack - plx - pla - ply - pha - phx - plb - rtl return, discarding the character +put2 phb remove the char from the stack + plx + pla + ply + pha + phx + plb + rtl return, discarding the character -string ds 4 string address -count ds 4 chars left to write - end +string ds 4 string address +count ds 4 chars left to write + end **************************************************************** * @@ -3562,61 +3562,61 @@ count ds 4 chars left to write * **************************************************************** * -vfscanf start - using ~scanfCommon +vfscanf start + using ~scanfCommon - phb use local addressing - phk - plb - plx remove the return address - ply - pla save the stream - sta stream - pla - sta stream+2 - phy restore return address/data bank - phx - plb + phb use local addressing + phk + plb + plx remove the return address + ply + pla save the stream + sta stream + pla + sta stream+2 + phy restore return address/data bank + phx + plb - ph4 >stream verify that stream exists - jsl ~VerifyStream - bcc lb1 - lda #EOF - rtl -lb1 lda #get set up our routines - sta >~getchar+10 - lda #>get - sta >~getchar+11 + ph4 >stream verify that stream exists + jsl ~VerifyStream + bcc lb1 + lda #EOF + rtl +lb1 lda #get set up our routines + sta >~getchar+10 + lda #>get + sta >~getchar+11 - lda #unget - sta >~putback+12 - lda #>unget - sta >~putback+13 + lda #unget + sta >~putback+12 + lda #>unget + sta >~putback+13 - lda #~RemoveWordFromVarArgs - sta >~RemoveWord+1 - lda #>~RemoveWordFromVarArgs - sta >~RemoveWord+2 + lda #~RemoveWordFromVarArgs + sta >~RemoveWord+1 + lda #>~RemoveWordFromVarArgs + sta >~RemoveWord+2 - lda #1 - sta >~isVarArgs + lda #1 + sta >~isVarArgs - brl ~scanf + brl ~scanf -get ph4 stream get a character - jsl fgetc - rtl +get ph4 stream get a character + jsl fgetc + rtl -unget ldx stream+2 put a character back - phx - ldx stream - phx - pha - jsl ungetc - rtl +unget ldx stream+2 put a character back + phx + ldx stream + phx + pha + jsl ungetc + rtl -stream ds 4 - end +stream ds 4 + end **************************************************************** * @@ -3626,38 +3626,38 @@ stream ds 4 * **************************************************************** * -vscanf start - using ~scanfCommon +vscanf start + using ~scanfCommon - lda #getchar - sta >~getchar+10 - lda #>getchar - sta >~getchar+11 + lda #getchar + sta >~getchar+10 + lda #>getchar + sta >~getchar+11 - lda #unget - sta >~putback+12 - lda #>unget - sta >~putback+13 + lda #unget + sta >~putback+12 + lda #>unget + sta >~putback+13 - lda #~RemoveWordFromVarArgs - sta >~RemoveWord+1 - lda #>~RemoveWordFromVarArgs - sta >~RemoveWord+2 + lda #~RemoveWordFromVarArgs + sta >~RemoveWord+1 + lda #>~RemoveWordFromVarArgs + sta >~RemoveWord+2 - lda #1 - sta >~isVarArgs + lda #1 + sta >~isVarArgs - brl ~scanf + brl ~scanf -unget tax - lda >stdin+2 - pha - lda >stdin - pha - phx - jsl ungetc - rtl - end +unget tax + lda >stdin+2 + pha + lda >stdin + pha + phx + jsl ungetc + rtl + end **************************************************************** * @@ -3667,89 +3667,89 @@ unget tax * **************************************************************** * -vsscanf start - using ~scanfCommon +vsscanf start + using ~scanfCommon - phb use local addressing - phk - plb - plx remove the return address - ply - pla save the stream - sta string - pla - sta string+2 - phy restore return address/data bank - phx - plb + phb use local addressing + phk + plb + plx remove the return address + ply + pla save the stream + sta string + pla + sta string+2 + phy restore return address/data bank + phx + plb - lda #get set up our routines - sta >~getchar+10 - lda #>get - sta >~getchar+11 + lda #get set up our routines + sta >~getchar+10 + lda #>get + sta >~getchar+11 - lda #unget - sta >~putback+12 - lda #>unget - sta >~putback+13 + lda #unget + sta >~putback+12 + lda #>unget + sta >~putback+13 - lda #~RemoveWordFromVarArgs - sta >~RemoveWord+1 - lda #>~RemoveWordFromVarArgs - sta >~RemoveWord+2 + lda #~RemoveWordFromVarArgs + sta >~RemoveWord+1 + lda #>~RemoveWordFromVarArgs + sta >~RemoveWord+2 - lda #1 - sta >~isVarArgs + lda #1 + sta >~isVarArgs - brl ~scanf + brl ~scanf -get ph4 string get a character - phd - tsc - tcd - lda [3] - and #$00FF - bne gt1 - dec4 string - lda #EOF -gt1 pld - ply - ply - inc4 string - rtl +get ph4 string get a character + phd + tsc + tcd + lda [3] + and #$00FF + bne gt1 + dec4 string + lda #EOF +gt1 pld + ply + ply + inc4 string + rtl -unget cmp #EOF put a character back - beq ug1 - dec4 string -ug1 rtl +unget cmp #EOF put a character back + beq ug1 + dec4 string +ug1 rtl -string ds 4 - end +string ds 4 + end **************************************************************** * * ~Format_c - format a '%' character * * Inputs: -* ~fieldWidth - output field width -* ~paddChar - padd character -* ~leftJustify - left justify the output? +* ~fieldWidth - output field width +* ~paddChar - padd character +* ~leftJustify - left justify the output? * **************************************************************** * ~Format_c private - using ~printfCommon -argp equ 7 argument pointer + using ~printfCommon +argp equ 7 argument pointer - dec ~fieldWidth account for the width of the value - jsr ~RightJustify handle right justification - lda [argp] print the character - pha - jsl ~putchar - inc argp remove the parameter from the stack - inc argp - brl ~LeftJustify handle left justification - end + dec ~fieldWidth account for the width of the value + jsr ~RightJustify handle right justification + lda [argp] print the character + pha + jsl ~putchar + inc argp remove the parameter from the stack + inc argp + brl ~LeftJustify handle left justification + end **************************************************************** * @@ -3757,14 +3757,14 @@ argp equ 7 argument pointer * ~Format_u - format an unsigned decimal number * * Inputs: -* ~fieldWidth - output field width -* ~paddChar - padd character -* ~leftJustify - left justify the output? -* ~isLong - is the operand long? -* ~isLongLong - is the operand long long? -* ~precision - precision of output -* ~precisionSpecified - was the precision specified? -* ~sign - char to use for positive sign +* ~fieldWidth - output field width +* ~paddChar - padd character +* ~leftJustify - left justify the output? +* ~isLong - is the operand long? +* ~isLongLong - is the operand long long? +* ~precision - precision of output +* ~precisionSpecified - was the precision specified? +* ~sign - char to use for positive sign * * Note: The ~Format_IntOut entry point is used by other number * formatting routines to write their number strings. @@ -3772,469 +3772,469 @@ argp equ 7 argument pointer **************************************************************** * ~Format_d private - using ~printfCommon -argp equ 7 argument pointer + using ~printfCommon +argp equ 7 argument pointer ; ; For signed numbers, if the value is negative, use the sign flag ; - lda ~isLongLong handle long long values - beq sn0 - ldy #6 - lda [argp],Y - bpl cn0 - sec - lda #0 - sbc [argp] - sta [argp] - ldy #2 - lda #0 - sbc [argp],Y - sta [argp],Y - iny - iny - lda #0 - sbc [argp],Y - sta [argp],Y - iny - iny - lda #0 - sbc [argp],Y - sta [argp],Y - bra sn2 -sn0 lda ~isLong handle long values - beq sn0a - ldy #2 - lda [argp],Y - bpl cn0 - sec - lda #0 - sbc [argp] - sta [argp] - lda #0 - sbc [argp],Y - sta [argp],Y - bra sn2 -sn0a lda ~isByte handle (originally) byte-size values - beq sn1 - lda [argp] - and #$00FF - sta [argp] - bit #$0080 - beq cn0 - eor #$00FF - bra sn1a -sn1 lda [argp] handle int values - bpl cn0 - eor #$FFFF -sn1a inc a - sta [argp] -sn2 lda #'-' - sta ~sign + lda ~isLongLong handle long long values + beq sn0 + ldy #6 + lda [argp],Y + bpl cn0 + sec + lda #0 + sbc [argp] + sta [argp] + ldy #2 + lda #0 + sbc [argp],Y + sta [argp],Y + iny + iny + lda #0 + sbc [argp],Y + sta [argp],Y + iny + iny + lda #0 + sbc [argp],Y + sta [argp],Y + bra sn2 +sn0 lda ~isLong handle long values + beq sn0a + ldy #2 + lda [argp],Y + bpl cn0 + sec + lda #0 + sbc [argp] + sta [argp] + lda #0 + sbc [argp],Y + sta [argp],Y + bra sn2 +sn0a lda ~isByte handle (originally) byte-size values + beq sn1 + lda [argp] + and #$00FF + sta [argp] + bit #$0080 + beq cn0 + eor #$00FF + bra sn1a +sn1 lda [argp] handle int values + bpl cn0 + eor #$FFFF +sn1a inc a + sta [argp] +sn2 lda #'-' + sta ~sign ~Format_u entry ; ; Convert the number to an ASCII string ; -cn0 stz ~hexPrefix don't lead with 0x - lda ~isLongLong if the value is long long then - beq cn0a - ldy #6 push a long long value - lda [argp],Y - pha - dey - dey - lda [argp],Y - pha -cn0a lda ~isLong else if the value is long then - beq cn1 - ldy #2 push a long value - lda [argp],Y - pha -! lda [argp] -! pha -! bra cn2 else -cn1 lda [argp] push an int value - ldx ~isByte - beq cn1a - and #$00FF -cn1a pha -cn2 ph4 #~str push the string addr - ph2 #l:~str push the string buffer length - ph2 #0 do an unsigned conversion - lda ~isLongLong do the proper conversion - beq cn2a - pla - jsr ~ULongLong2Dec - bra pd1 -cn2a lda ~isLong - beq cn3 - _Long2Dec - bra pd1 -cn3 _Int2Dec +cn0 stz ~hexPrefix don't lead with 0x + lda ~isLongLong if the value is long long then + beq cn0a + ldy #6 push a long long value + lda [argp],Y + pha + dey + dey + lda [argp],Y + pha +cn0a lda ~isLong else if the value is long then + beq cn1 + ldy #2 push a long value + lda [argp],Y + pha +! lda [argp] +! pha +! bra cn2 else +cn1 lda [argp] push an int value + ldx ~isByte + beq cn1a + and #$00FF +cn1a pha +cn2 ph4 #~str push the string addr + ph2 #l:~str push the string buffer length + ph2 #0 do an unsigned conversion + lda ~isLongLong do the proper conversion + beq cn2a + pla + jsr ~ULongLong2Dec + bra pd1 +cn2a lda ~isLong + beq cn3 + _Long2Dec + bra pd1 +cn3 _Int2Dec ; ; Padd with the proper number of zeros ; ~Format_IntOut entry -pd1 lda ~precisionSpecified if the precision was not specified then - bne pd1a - lda #1 use a precision of 1 - sta ~precision - bra pd2 -pd1a lda #' ' if the precision was specified then - sta ~paddChar do not do 0 padding -pd2 ldx ~precision if the precision is zero then - bne pd2a - lda ~str+l:~str-2 if the result is ' 0' then - cmp #'0 ' - bne dp0 - lda #' ' set the result to the null string - sta ~str+l:~str-2 - stz ~hexPrefix erase any hex prefix - bra dp0 -pd2a ldy #0 skip leading blanks - short M - lda #' ' -pd3 cmp ~str,Y - bne pd4 - iny - cpy #l:~str - bne pd3 - bra pd6 -pd4 cmp ~str,Y deduct any characters from the precision - beq pd5 - dex - beq pd5 - iny - cpy #l:~str - bne pd4 -pd5 stx ~precision -pd6 long M +pd1 lda ~precisionSpecified if the precision was not specified then + bne pd1a + lda #1 use a precision of 1 + sta ~precision + bra pd2 +pd1a lda #' ' if the precision was specified then + sta ~paddChar do not do 0 padding +pd2 ldx ~precision if the precision is zero then + bne pd2a + lda ~str+l:~str-2 if the result is ' 0' then + cmp #'0 ' + bne dp0 + lda #' ' set the result to the null string + sta ~str+l:~str-2 + stz ~hexPrefix erase any hex prefix + bra dp0 +pd2a ldy #0 skip leading blanks + short M + lda #' ' +pd3 cmp ~str,Y + bne pd4 + iny + cpy #l:~str + bne pd3 + bra pd6 +pd4 cmp ~str,Y deduct any characters from the precision + beq pd5 + dex + beq pd5 + iny + cpy #l:~str + bne pd4 +pd5 stx ~precision +pd6 long M ; ; Determine the padding and do left padding ; -dp0 sub2 ~fieldWidth,~precision subtract off any remaining 0 padds - lda ~sign if the sign is non-zero, allow for it - beq dp1 - dec ~fieldWidth -dp1 lda ~hexPrefix if there is a hex prefix, allow for it - beq dp1a - dec ~fieldWidth - dec ~fieldWidth -dp1a ldx #0 determine the length of the buffer - ldy #l:~str-1 - short M - lda #' ' -dp2 cmp ~str,Y - beq dp3 - inx - dey - bpl dp2 -dp3 long M - sec subtract it from ~fieldWidth - txa - sbc ~fieldWidth - eor #$FFFF - inc a - sta ~fieldWidth - lda ~paddChar skip justification if we are padding - cmp #'0' - beq pn0 - jsr ~RightJustify handle right justification +dp0 sub2 ~fieldWidth,~precision subtract off any remaining 0 padds + lda ~sign if the sign is non-zero, allow for it + beq dp1 + dec ~fieldWidth +dp1 lda ~hexPrefix if there is a hex prefix, allow for it + beq dp1a + dec ~fieldWidth + dec ~fieldWidth +dp1a ldx #0 determine the length of the buffer + ldy #l:~str-1 + short M + lda #' ' +dp2 cmp ~str,Y + beq dp3 + inx + dey + bpl dp2 +dp3 long M + sec subtract it from ~fieldWidth + txa + sbc ~fieldWidth + eor #$FFFF + inc a + sta ~fieldWidth + lda ~paddChar skip justification if we are padding + cmp #'0' + beq pn0 + jsr ~RightJustify handle right justification ; ; Print the number ; -pn0 lda ~sign if there is a sign character then - beq pn1 - pha print it - jsl ~putchar -pn1 lda ~hexPrefix if there is a hex prefix then - beq pn1a - pha print it - jsl ~putchar - ph2 ~hexPrefix+1 - jsl ~putchar -pn1a lda ~paddChar if the number needs 0 padding then - cmp #'0' - bne pn1c - lda ~fieldWidth - bmi pn1c - beq pn1c -pn1b ph2 ~paddChar print padd zeros - jsl ~putchar - dec ~fieldWidth - bne pn1b -pn1c lda ~precision if the number needs more padding then - beq pn3 -pn2 ph2 #'0' print padd characters - jsl ~putchar - dec ~precision - bne pn2 -pn3 ldy #-1 skip leading blanks in the number -pn4 iny - lda ~str,Y - and #$00FF - cmp #' ' - beq pn4 +pn0 lda ~sign if there is a sign character then + beq pn1 + pha print it + jsl ~putchar +pn1 lda ~hexPrefix if there is a hex prefix then + beq pn1a + pha print it + jsl ~putchar + ph2 ~hexPrefix+1 + jsl ~putchar +pn1a lda ~paddChar if the number needs 0 padding then + cmp #'0' + bne pn1c + lda ~fieldWidth + bmi pn1c + beq pn1c +pn1b ph2 ~paddChar print padd zeros + jsl ~putchar + dec ~fieldWidth + bne pn1b +pn1c lda ~precision if the number needs more padding then + beq pn3 +pn2 ph2 #'0' print padd characters + jsl ~putchar + dec ~precision + bne pn2 +pn3 ldy #-1 skip leading blanks in the number +pn4 iny + lda ~str,Y + and #$00FF + cmp #' ' + beq pn4 -pn5 cpy #l:~str quit if we're at the end of the ~str - beq rn1 - phy save Y - lda ~str,Y print the character - and #$00FF - pha - jsl ~putchar - ply next character - iny - bra pn5 +pn5 cpy #l:~str quit if we're at the end of the ~str + beq rn1 + phy save Y + lda ~str,Y print the character + and #$00FF + pha + jsl ~putchar + ply next character + iny + bra pn5 ; ; remove the number from the argument list ; -rn1 lda ~isLongLong - beq rn2 - inc argp - inc argp - inc argp - inc argp -rn2 lda ~isLong - beq rn3 - inc argp - inc argp -rn3 inc argp - inc argp +rn1 lda ~isLongLong + beq rn2 + inc argp + inc argp + inc argp + inc argp +rn2 lda ~isLong + beq rn3 + inc argp + inc argp +rn3 inc argp + inc argp ; ; Handle left justification ; - brl ~LeftJustify handle left justification - end + brl ~LeftJustify handle left justification + end **************************************************************** * * ~ULongLong2Dec - produce a string from an unsigned long long * * Inputs: -* llValue - the unsigned long long value -* strPtr - pointer to string buffer -* strLength - length of string buffer (must be >= 20) +* llValue - the unsigned long long value +* strPtr - pointer to string buffer +* strLength - length of string buffer (must be >= 20) * **************************************************************** * ~ULongLong2Dec private - lsub (8:llValue,4:strPtr,2:strLength),0 + lsub (8:llValue,4:strPtr,2:strLength),0 - dec strLength + dec strLength - ldx #8 -initbcd stz bcdnum,x - dex - dex - bpl initbcd + ldx #8 +initbcd stz bcdnum,x + dex + dex + bpl initbcd - ldy #64 - sed use BCD -bitloop asl llValue - rol llValue+2 - rol llValue+4 - rol llValue+6 carry is now high bit from llValue - ldx #8 -addloop lda bcdnum,x bcdNum := bcdNum*2 + carry (in BCD) - adc bcdnum,x - dey make fully big-endian on last iteration - bne notlast - xba -notlast iny - sta bcdnum,x - dex - dex - bpl addloop - dey - bne bitloop - cld + ldy #64 + sed use BCD +bitloop asl llValue + rol llValue+2 + rol llValue+4 + rol llValue+6 carry is now high bit from llValue + ldx #8 +addloop lda bcdnum,x bcdNum := bcdNum*2 + carry (in BCD) + adc bcdnum,x + dey make fully big-endian on last iteration + bne notlast + xba +notlast iny + sta bcdnum,x + dex + dex + bpl addloop + dey + bne bitloop + cld - short M convert BCD to ASCII - ldx #9 - ldy strLength -bcdloop lda bcdnum,x - and #$0F - ora #$30 low digit to ASCII - sta [strPtr],y - dey - lda bcdnum,x - lsr a - lsr a - lsr a - lsr a - ora #$30 high digit to ASCII - sta [strPtr],y - dey - dex - bpl bcdloop - -rmzeros iny remove leading zeros - lda [strPtr],y - cmp #'0' - bne padit - cpy strLength - bne rmzeros -padit dey pad with spaces - lda #' ' -padloop sta [strPtr],y - dey - bpl padloop - - long M - lret + short M convert BCD to ASCII + ldx #9 + ldy strLength +bcdloop lda bcdnum,x + and #$0F + ora #$30 low digit to ASCII + sta [strPtr],y + dey + lda bcdnum,x + lsr a + lsr a + lsr a + lsr a + ora #$30 high digit to ASCII + sta [strPtr],y + dey + dex + bpl bcdloop + +rmzeros iny remove leading zeros + lda [strPtr],y + cmp #'0' + bne padit + cpy strLength + bne rmzeros +padit dey pad with spaces + lda #' ' +padloop sta [strPtr],y + dey + bpl padloop + + long M + lret -bcdnum ds 10 - end +bcdnum ds 10 + end **************************************************************** * * ~Format_n - return the number of characters printed * * Inputs: -* ~numChars - characters written -* ~isLong - is the operand long? -* ~isLong - is the operand long long? +* ~numChars - characters written +* ~isLong - is the operand long? +* ~isLong - is the operand long long? * **************************************************************** * ~Format_n private - using ~printfCommon -argp equ 7 argument pointer + using ~printfCommon +argp equ 7 argument pointer - ph4 argp save the original argp - ldy #2 dereference argp - lda [argp],Y - tax - lda [argp] - sta argp - stx argp+2 - lda ~numChars return the value - ldx ~isByte if byte, store only low byte - beq lb0 - sep #$20 -lb0 sta [argp] - rep #$20 - lda ~isLongLong if long long, set the high words - beq lb0a - ldy #6 - lda #0 - sta [argp],Y - dey - dey - sta [argp],Y -lb0a lda ~isLong if long, set the high word - beq lb1 - ldy #2 - lda #0 - sta [argp],Y -lb1 clc restore the original argp+4 - pla - adc #4 - sta argp - pla - sta argp+2 - rts - end + ph4 argp save the original argp + ldy #2 dereference argp + lda [argp],Y + tax + lda [argp] + sta argp + stx argp+2 + lda ~numChars return the value + ldx ~isByte if byte, store only low byte + beq lb0 + sep #$20 +lb0 sta [argp] + rep #$20 + lda ~isLongLong if long long, set the high words + beq lb0a + ldy #6 + lda #0 + sta [argp],Y + dey + dey + sta [argp],Y +lb0a lda ~isLong if long, set the high word + beq lb1 + ldy #2 + lda #0 + sta [argp],Y +lb1 clc restore the original argp+4 + pla + adc #4 + sta argp + pla + sta argp+2 + rts + end **************************************************************** * * ~Format_o - format an octal number * * Inputs: -* ~altForm - use a leading '0'? -* ~fieldWidth - output field width -* ~paddChar - padd character -* ~leftJustify - left justify the output? -* ~isLong - is the operand long? -* ~isLongLong - is the operand long long? -* ~precision - precision of output -* ~precisionSpecified - was the precision specified? +* ~altForm - use a leading '0'? +* ~fieldWidth - output field width +* ~paddChar - padd character +* ~leftJustify - left justify the output? +* ~isLong - is the operand long? +* ~isLongLong - is the operand long long? +* ~precision - precision of output +* ~precisionSpecified - was the precision specified? * **************************************************************** * ~Format_o private - using ~printfCommon -argp equ 7 argument pointer + using ~printfCommon +argp equ 7 argument pointer ; ; Initialization ; - stz ~sign ignore the sign flag - lda #' ' initialize the string to blanks - sta ~str - move ~str,~str+1,#l:~str-1 - stz ~num+2 get the value to convert - lda ~isLongLong - beq cn1 - ldy #6 - lda [argp],Y - sta ~num+6 - dey - dey - lda [argp],Y - sta ~num+4 -cn1 lda ~isLong - beq cn2 -cn1a ldy #2 - lda [argp],Y - sta ~num+2 -cn2 lda [argp] - ldx ~isByte - beq cn2a - and #$00FF -cn2a sta ~num + stz ~sign ignore the sign flag + lda #' ' initialize the string to blanks + sta ~str + move ~str,~str+1,#l:~str-1 + stz ~num+2 get the value to convert + lda ~isLongLong + beq cn1 + ldy #6 + lda [argp],Y + sta ~num+6 + dey + dey + lda [argp],Y + sta ~num+4 +cn1 lda ~isLong + beq cn2 +cn1a ldy #2 + lda [argp],Y + sta ~num+2 +cn2 lda [argp] + ldx ~isByte + beq cn2a + and #$00FF +cn2a sta ~num ; ; Convert the number to an ASCII string ; - short I,M - ldy #l:~str-1 set up the character index -cn3 lda ~num+7 quit if the number is zero - ora ~num+6 - ora ~num+5 - ora ~num+4 - ora ~num+3 - ora ~num+2 - ora ~num+1 - ora ~num - beq al1 - lda #0 roll off 3 bits - ldx #3 -cn4 lsr ~num+7 - ror ~num+6 - ror ~num+5 - ror ~num+4 - ror ~num+3 - ror ~num+2 - ror ~num+1 - ror ~num - ror A - dex - bne cn4 - lsr A form a character - lsr A - lsr A - lsr A - lsr A - ora #'0' - sta ~str,Y save the character - dey - bra cn3 + short I,M + ldy #l:~str-1 set up the character index +cn3 lda ~num+7 quit if the number is zero + ora ~num+6 + ora ~num+5 + ora ~num+4 + ora ~num+3 + ora ~num+2 + ora ~num+1 + ora ~num + beq al1 + lda #0 roll off 3 bits + ldx #3 +cn4 lsr ~num+7 + ror ~num+6 + ror ~num+5 + ror ~num+4 + ror ~num+3 + ror ~num+2 + ror ~num+1 + ror ~num + ror A + dex + bne cn4 + lsr A form a character + lsr A + lsr A + lsr A + lsr A + ora #'0' + sta ~str,Y save the character + dey + bra cn3 ; ; If a leading zero is required, be sure we include one ; -al1 cpy #l:~str-1 include a zero if no characters have - beq al2 been placed in the string - lda ~altForm branch if no leading zero is required - beq al3 -al2 lda #'0' - sta ~str,Y -al3 long I,M +al1 cpy #l:~str-1 include a zero if no characters have + beq al2 been placed in the string + lda ~altForm branch if no leading zero is required + beq al3 +al2 lda #'0' + sta ~str,Y +al3 long I,M ; ; Piggy back off of ~Format_d for output ; - stz ~hexPrefix don't lead with 0x - brl ~Format_IntOut - end + stz ~hexPrefix don't lead with 0x + brl ~Format_IntOut + end **************************************************************** * @@ -4243,73 +4243,73 @@ al3 long I,M * ~Format_P - format a p-string * * Inputs: -* ~fieldWidth - output field width -* ~paddChar - padd character -* ~leftJustify - left justify the output? +* ~fieldWidth - output field width +* ~paddChar - padd character +* ~leftJustify - left justify the output? * **************************************************************** * ~Format_s private - using ~printfCommon -argp equ 7 argument pointer + using ~printfCommon +argp equ 7 argument pointer - ph4 argp save the original argp - ldy #2 dereference argp - lda [argp],Y - tax - lda [argp] - sta argp - stx argp+2 - short M determine the length of the string - ldy #-1 -lb1 iny - lda [argp],Y - bne lb1 - long M - tya - bra lb1a + ph4 argp save the original argp + ldy #2 dereference argp + lda [argp],Y + tax + lda [argp] + sta argp + stx argp+2 + short M determine the length of the string + ldy #-1 +lb1 iny + lda [argp],Y + bne lb1 + long M + tya + bra lb1a ~Format_b entry ~Format_P entry - ph4 argp save the original argp - ldy #2 dereference argp - lda [argp],Y - tax - lda [argp] - sta argp - stx argp+2 - lda [argp] get the length of the string - and #$00FF - inc4 argp + ph4 argp save the original argp + ldy #2 dereference argp + lda [argp],Y + tax + lda [argp] + sta argp + stx argp+2 + lda [argp] get the length of the string + and #$00FF + inc4 argp -lb1a ldx ~precisionSpecified if the precision is specified then - beq lb2 - cmp ~precision if the precision is smaller then - blt lb2 - lda ~precision process only precision characters -lb2 sta ~num save the length in the temp variable area - sub2 ~fieldWidth,~num account for the width of the value - jsr ~RightJustify handle right justification - ldx ~num skip printing if the length is 0 - beq lb4 - ldy #0 print the characters -lb3 phy - lda [argp],Y - and #$00FF - pha - jsl ~putchar - ply - iny - dec ~num - bne lb3 -lb4 clc restore and increment argp - pla - adc #4 - sta argp - pla - sta argp+2 - brl ~LeftJustify handle left justification - end +lb1a ldx ~precisionSpecified if the precision is specified then + beq lb2 + cmp ~precision if the precision is smaller then + blt lb2 + lda ~precision process only precision characters +lb2 sta ~num save the length in the temp variable area + sub2 ~fieldWidth,~num account for the width of the value + jsr ~RightJustify handle right justification + ldx ~num skip printing if the length is 0 + beq lb4 + ldy #0 print the characters +lb3 phy + lda [argp],Y + and #$00FF + pha + jsl ~putchar + ply + iny + dec ~num + bne lb3 +lb4 clc restore and increment argp + pla + adc #4 + sta argp + pla + sta argp+2 + brl ~LeftJustify handle left justification + end **************************************************************** * @@ -4318,236 +4318,236 @@ lb4 clc restore and increment argp * ~Format_p - format a pointer * * Inputs: -* ~altForm - use a leading '0x'? -* ~fieldWidth - output field width -* ~paddChar - padd character -* ~leftJustify - left justify the output? -* ~isLong - is the operand long? -* ~isLongLong - is the operand long long? -* ~precision - precision of output -* ~precisionSpecified - was the precision specified? +* ~altForm - use a leading '0x'? +* ~fieldWidth - output field width +* ~paddChar - padd character +* ~leftJustify - left justify the output? +* ~isLong - is the operand long? +* ~isLongLong - is the operand long long? +* ~precision - precision of output +* ~precisionSpecified - was the precision specified? * **************************************************************** * ~Format_x private - using ~printfCommon -argp equ 7 argument pointer + using ~printfCommon +argp equ 7 argument pointer ; ; Set the "or" value; this is used to set the case of character results ; - lda #$20 - sta orVal - bra cn0 + lda #$20 + sta orVal + bra cn0 ~Format_p entry - lda #1 - sta ~isLong + lda #1 + sta ~isLong ~Format_X entry - stz orVal + stz orVal ; ; Initialization ; -cn0 stz ~sign ignore the sign flag - lda #' ' initialize the string to blanks - sta ~str - move ~str,~str+1,#l:~str-1 - stz ~num+2 get the value to convert - stz ~num+4 - stz ~num+6 - lda ~isLongLong - beq cn1 - ldy #6 - lda [argp],Y - sta ~num+6 - dey - dey - lda [argp],Y - sta ~num+4 -cn1 lda ~isLong - beq cn2 - ldy #2 - lda [argp],Y - sta ~num+2 -cn2 lda [argp] - ldx ~isByte - beq cn2a - and #$00FF -cn2a sta ~num - ora ~num+2 - ora ~num+4 - ora ~num+6 - bne cn2b - stz ~altForm if value is 0, do not print hex prefix -cn2b stz ~hexPrefix assume we won't lead with 0x +cn0 stz ~sign ignore the sign flag + lda #' ' initialize the string to blanks + sta ~str + move ~str,~str+1,#l:~str-1 + stz ~num+2 get the value to convert + stz ~num+4 + stz ~num+6 + lda ~isLongLong + beq cn1 + ldy #6 + lda [argp],Y + sta ~num+6 + dey + dey + lda [argp],Y + sta ~num+4 +cn1 lda ~isLong + beq cn2 + ldy #2 + lda [argp],Y + sta ~num+2 +cn2 lda [argp] + ldx ~isByte + beq cn2a + and #$00FF +cn2a sta ~num + ora ~num+2 + ora ~num+4 + ora ~num+6 + bne cn2b + stz ~altForm if value is 0, do not print hex prefix +cn2b stz ~hexPrefix assume we won't lead with 0x ; ; Convert the number to an ASCII string ; - short I,M - ldy #l:~str-1 set up the character index -cn3 lda #0 roll off 4 bits - ldx #4 -cn4 lsr ~num+7 - ror ~num+6 - ror ~num+5 - ror ~num+4 - ror ~num+3 - ror ~num+2 - ror ~num+1 - ror ~num - ror A - dex - bne cn4 - lsr A form a character - lsr A - lsr A - lsr A - ora #'0' - cmp #'9'+1 if the character should be alpha, - blt cn5 adjust it - adc #6 - ora orVal -cn5 sta ~str,Y save the character - dey - lda ~num+7 loop if the number is not zero - ora ~num+6 - ora ~num+5 - ora ~num+4 - ora ~num+3 - ora ~num+2 - ora ~num+1 - ora ~num - bne cn3 + short I,M + ldy #l:~str-1 set up the character index +cn3 lda #0 roll off 4 bits + ldx #4 +cn4 lsr ~num+7 + ror ~num+6 + ror ~num+5 + ror ~num+4 + ror ~num+3 + ror ~num+2 + ror ~num+1 + ror ~num + ror A + dex + bne cn4 + lsr A form a character + lsr A + lsr A + lsr A + ora #'0' + cmp #'9'+1 if the character should be alpha, + blt cn5 adjust it + adc #6 + ora orVal +cn5 sta ~str,Y save the character + dey + lda ~num+7 loop if the number is not zero + ora ~num+6 + ora ~num+5 + ora ~num+4 + ora ~num+3 + ora ~num+2 + ora ~num+1 + ora ~num + bne cn3 ; ; If a leading '0x' is required, be sure we include one ; - lda ~altForm branch if no leading '0x' is required - beq al3 -al2 lda #'X' insert leading '0x' - ora orVal - sta ~hexPrefix+1 - lda #'0' - sta ~hexPrefix -al3 long I,M + lda ~altForm branch if no leading '0x' is required + beq al3 +al2 lda #'X' insert leading '0x' + ora orVal + sta ~hexPrefix+1 + lda #'0' + sta ~hexPrefix +al3 long I,M ; ; Piggy back off of ~Format_d for output ; - brl ~Format_IntOut + brl ~Format_IntOut ; ; Local data ; -orVal ds 2 for setting the case of characters - end +orVal ds 2 for setting the case of characters + end **************************************************************** * * ~Format_Percent - format the '%' character * * Inputs: -* ~fieldWidth - output field width -* ~paddChar - padd character -* ~leftJustify - left justify the output? +* ~fieldWidth - output field width +* ~paddChar - padd character +* ~leftJustify - left justify the output? * **************************************************************** * ~Format_Percent private - using ~printfCommon + using ~printfCommon - dec ~fieldWidth account for the width of the value - jsr ~RightJustify handle right justification - pea '%' print the character - jsl ~putchar - brl ~LeftJustify handle left justification - end + dec ~fieldWidth account for the width of the value + jsr ~RightJustify handle right justification + pea '%' print the character + jsl ~putchar + brl ~LeftJustify handle left justification + end **************************************************************** * * ~InitBuffer - prepare a file buffer for output * * Inputs: -* stream - buffer to prepare +* stream - buffer to prepare * **************************************************************** * ~InitBuffer start - csubroutine (4:stream),0 + csubroutine (4:stream),0 - ldy #FILE_base+2 set the next buffer location - lda [stream],Y - tax - dey - dey - lda [stream],Y - ldy #FILE_ptr - sta [stream],Y - iny - iny - txa - sta [stream],Y - ldy #FILE_base set the end of buffer mark - lda [stream],Y - ldy #FILE_size - clc - adc [stream],Y - pha - txa - iny - iny - adc [stream],Y - ldy #FILE_end+2 - sta [stream],Y - pla - dey - dey - sta [stream],Y - ldy #FILE_size set the number of chars the buffer - lda [stream],Y can hold - tax - iny - iny - lda [stream],Y - ldy #FILE_cnt+2 - sta [stream],Y - dey - dey - txa - sta [stream],Y + ldy #FILE_base+2 set the next buffer location + lda [stream],Y + tax + dey + dey + lda [stream],Y + ldy #FILE_ptr + sta [stream],Y + iny + iny + txa + sta [stream],Y + ldy #FILE_base set the end of buffer mark + lda [stream],Y + ldy #FILE_size + clc + adc [stream],Y + pha + txa + iny + iny + adc [stream],Y + ldy #FILE_end+2 + sta [stream],Y + pla + dey + dey + sta [stream],Y + ldy #FILE_size set the number of chars the buffer + lda [stream],Y can hold + tax + iny + iny + lda [stream],Y + ldy #FILE_cnt+2 + sta [stream],Y + dey + dey + txa + sta [stream],Y - creturn - end + creturn + end **************************************************************** * * ~ioerror - flag an I/O error * * Inputs: -* stream - file to clear +* stream - file to clear * * Outputs: -* errno - set to EIO -* stream->flag - error flag set +* errno - set to EIO +* stream->flag - error flag set * **************************************************************** * ~ioerror start -stream equ 3 input stream +stream equ 3 input stream - tsc - phd - tcd - ldy #FILE_flag - lda [stream],Y - ora #_IOERR - sta [stream],Y - lda #EIO - sta >errno - pld - pla - ply - ply - pha - rts - end + tsc + phd + tcd + ldy #FILE_flag + lda [stream],Y + ora #_IOERR + sta [stream],Y + lda #EIO + sta >errno + pld + pla + ply + ply + pha + rts + end **************************************************************** * @@ -4555,85 +4555,85 @@ stream equ 3 input stream * ~RightJustify - print padd characters for right justification * * Inputs: -* ~fieldWidth - # chars to print ( <= 0 prints none) -* ~leftJustify - left justify the output? +* ~fieldWidth - # chars to print ( <= 0 prints none) +* ~leftJustify - left justify the output? * **************************************************************** * ~LeftJustify start - using ~printfCommon + using ~printfCommon - lda ~leftJustify padd if we are to left justify the field - bne padd -rts rts + lda ~leftJustify padd if we are to left justify the field + bne padd +rts rts ~RightJustify entry - lda ~leftJustify quit if we are to left justify the field - bne rts -padd lda ~fieldWidth quit if the field width is <= 0 - bmi rts - beq rts -lb1 ph2 #' ' write the proper # of padd characters - jsl ~putchar - dec ~fieldWidth - bne lb1 - rts - end + lda ~leftJustify quit if we are to left justify the field + bne rts +padd lda ~fieldWidth quit if the field width is <= 0 + bmi rts + beq rts +lb1 ph2 #' ' write the proper # of padd characters + jsl ~putchar + dec ~fieldWidth + bne lb1 + rts + end **************************************************************** * * ~osname - convert a c string to a GS/OS file name * * Inputs: -* filename - ptr to the c string +* filename - ptr to the c string * * Outputs: -* X-A - ptr to GS/OS file name +* X-A - ptr to GS/OS file name * * Notes: -* 1. Returns nil for error. -* 2. Caller must dispose of the name with a free call. +* 1. Returns nil for error. +* 2. Caller must dispose of the name with a free call. * **************************************************************** * -~osname private -namelen equ 1 length of the string -ptr equ 3 pointer to return +~osname private +namelen equ 1 length of the string +ptr equ 3 pointer to return - csubroutine (4:filename),6 + csubroutine (4:filename),6 - ph4 filename get the length of the name buffer - jsl strlen - sta namelen - inc A - inc A - pea 0 reserve some memory - pha - jsl malloc - sta ptr - stx ptr+2 - ora ptr+2 - bne lb1 - lda #ENOMEM - sta >errno - brl lb3 -lb1 lda namelen set the name length - sta [ptr] - pea 0 copy the file name to the OS name buffer - pha - ph4 filename - clc - lda ptr - ldx ptr+2 - adc #2 - bcc lb2 - inx -lb2 phx - pha - jsl memcpy -lb3 creturn 4:ptr - end + ph4 filename get the length of the name buffer + jsl strlen + sta namelen + inc A + inc A + pea 0 reserve some memory + pha + jsl malloc + sta ptr + stx ptr+2 + ora ptr+2 + bne lb1 + lda #ENOMEM + sta >errno + brl lb3 +lb1 lda namelen set the name length + sta [ptr] + pea 0 copy the file name to the OS name buffer + pha + ph4 filename + clc + lda ptr + ldx ptr+2 + adc #2 + bcc lb2 + inx +lb2 phx + pha + jsl memcpy +lb3 creturn 4:ptr + end **************************************************************** * @@ -4645,17 +4645,17 @@ lb3 creturn 4:ptr * Optional Flag Characters * ------------------------ * -* '-' Left justify the output. -* '0' Use '0' for the pad character rather than ' '. This -* flag is ignored if the '-' flag is also used. -* '+' Only used for conversion operations 'd' 'e' 'E' 'f' 'g' 'G'. -* Specifies that a leading sign is to be printed for -* positive values. -* ' ' Only used for conversion operations 'd' 'e' 'E' 'f' 'g' 'G'. -* Ignored if '+' is specified. For positive values, this -* causes a padd space to be written where the sign would -* appear. -* '#' Modify the conversion operation. +* '-' Left justify the output. +* '0' Use '0' for the pad character rather than ' '. This +* flag is ignored if the '-' flag is also used. +* '+' Only used for conversion operations 'd' 'e' 'E' 'f' 'g' 'G'. +* Specifies that a leading sign is to be printed for +* positive values. +* ' ' Only used for conversion operations 'd' 'e' 'E' 'f' 'g' 'G'. +* Ignored if '+' is specified. For positive values, this +* causes a padd space to be written where the sign would +* appear. +* '#' Modify the conversion operation. * * Optional Min Field Width * ------------------------ @@ -4683,250 +4683,250 @@ lb3 creturn 4:ptr * Conversion Specifier * -------------------- * -* d,i Signed decimal conversion from type int or long. -* u Signed decimal conversion from type unsigned or unsigned long. -* o Octal conversion. -* x,X Hexadecimal conversion. 'x' generates lowercase hex digits, -* while 'X' generates uppercase hex digits. -* c Character. -* s String. -* p Pascal string. -* n The argument is (int *); the number of characters written so -* far is written to the location. -* f Signed decimal floating point. -* e,E Exponential format floating point. -* g,G Use f,e or E, as appropriate. -* % Write a '%' character. +* d,i Signed decimal conversion from type int or long. +* u Signed decimal conversion from type unsigned or unsigned long. +* o Octal conversion. +* x,X Hexadecimal conversion. 'x' generates lowercase hex digits, +* while 'X' generates uppercase hex digits. +* c Character. +* s String. +* p Pascal string. +* n The argument is (int *); the number of characters written so +* far is written to the location. +* f Signed decimal floating point. +* e,E Exponential format floating point. +* g,G Use f,e or E, as appropriate. +* % Write a '%' character. * **************************************************************** * -~printf private - using ~printfCommon +~printf private + using ~printfCommon -argp equ 7 pointer to first argument -format equ 14 pointer to format code +argp equ 7 pointer to first argument +format equ 14 pointer to format code ; ; Set up the stack frame ; - phb save the caller's B - phk use local addressing - plb - phd save the caller's DP - tsc set up a DP - tcd + phb save the caller's B + phk use local addressing + plb + phd save the caller's DP + tsc set up a DP + tcd ; ; Process the format string ; - stz ~numChars initialize the character counter -ps1 lda [format] get a character - and #$00FF - beq rt1 branch if at the end of the format string - cmp #'%' branch if this is a conversion - beq fm1 specification - pha write the character - jsl ~putchar - inc4 format - bra ps1 + stz ~numChars initialize the character counter +ps1 lda [format] get a character + and #$00FF + beq rt1 branch if at the end of the format string + cmp #'%' branch if this is a conversion + beq fm1 specification + pha write the character + jsl ~putchar + inc4 format + bra ps1 ; ; Remove the format parameter and return ; -rt1 lda format-2 move the return address - sta format+2 - lda format-3 - sta format+1 - pld restore DP - plb restore B - rtl return to top level formatter +rt1 lda format-2 move the return address + sta format+2 + lda format-3 + sta format+1 + pld restore DP + plb restore B + rtl return to top level formatter ; ; Handle a format specification ; -fm1 inc4 format skip the '%' +fm1 inc4 format skip the '%' - stz ~removeZeros not a G specifier - stz ~fieldWidth use only the space required - stz ~precision use the default precision - stz ~precisionSpecified - stz ~isLong assume short operands - stz ~isLongLong - stz ~isByte - lda #' ' use a blank for padding - sta ~paddChar - stz ~leftJustify right justify the output - stz ~sign don't print the sign unless arg < 0 - stz ~altForm use the primary output format + stz ~removeZeros not a G specifier + stz ~fieldWidth use only the space required + stz ~precision use the default precision + stz ~precisionSpecified + stz ~isLong assume short operands + stz ~isLongLong + stz ~isByte + lda #' ' use a blank for padding + sta ~paddChar + stz ~leftJustify right justify the output + stz ~sign don't print the sign unless arg < 0 + stz ~altForm use the primary output format -fm2 jsr Flag read and interpret flag characters - bcs fm2 - jsr GetSize get the field width (if any) - sta ~fieldWidth - lda [format] if format == '.' then - and #$00FF - cmp #'.' - bne fm3 - inc4 format skip the '.' - inc ~precisionSpecified note that the precision is specified - jsr GetSize get the precision - sta ~precision - lda [format] if *format in ['l','z','t','j'] then - and #$00FF ~isLong = true -fm3 cmp #'l' - bne fm3b - inc4 format for 'll' or 'j', also set ~isLongLong - lda [format] - and #$00FF - cmp #'l' - beq fm3a - inc ~isLong - bra fm6 -fm3a inc ~isLongLong - bra fm3c -fm3b cmp #'j' - beq fm3a - cmp #'z' - beq fm3c - cmp #'t' - bne fm4 -fm3c inc ~isLong - bra fm5 ++format -fm4 cmp #'L' else if *format in ['L','h'] then - beq fm5 - cmp #'h' - bne fm6 - inc4 format check for 'hh' - lda [format] - and #$00FF - cmp #'h' - bne fm6 - inc ~isByte -fm5 inc4 format ++format - lda [format] find the proper format character - and #$00FF -fm6 inc4 format - ldx #fListEnd-fList-4 -fm7 cmp fList,X - beq fm8 - dex - dex - dex - dex - bpl fm7 - brl ps1 none found - continue -fm8 pea ps1-1 push the return address - inx call the subroutine - inx - jmp (fList,X) +fm2 jsr Flag read and interpret flag characters + bcs fm2 + jsr GetSize get the field width (if any) + sta ~fieldWidth + lda [format] if format == '.' then + and #$00FF + cmp #'.' + bne fm3 + inc4 format skip the '.' + inc ~precisionSpecified note that the precision is specified + jsr GetSize get the precision + sta ~precision + lda [format] if *format in ['l','z','t','j'] then + and #$00FF ~isLong = true +fm3 cmp #'l' + bne fm3b + inc4 format for 'll' or 'j', also set ~isLongLong + lda [format] + and #$00FF + cmp #'l' + beq fm3a + inc ~isLong + bra fm6 +fm3a inc ~isLongLong + bra fm3c +fm3b cmp #'j' + beq fm3a + cmp #'z' + beq fm3c + cmp #'t' + bne fm4 +fm3c inc ~isLong + bra fm5 ++format +fm4 cmp #'L' else if *format in ['L','h'] then + beq fm5 + cmp #'h' + bne fm6 + inc4 format check for 'hh' + lda [format] + and #$00FF + cmp #'h' + bne fm6 + inc ~isByte +fm5 inc4 format ++format + lda [format] find the proper format character + and #$00FF +fm6 inc4 format + ldx #fListEnd-fList-4 +fm7 cmp fList,X + beq fm8 + dex + dex + dex + dex + bpl fm7 + brl ps1 none found - continue +fm8 pea ps1-1 push the return address + inx call the subroutine + inx + jmp (fList,X) ; ; Flag - Read and process a flag character ; ; If a flag character was found, the carry flag is set. ; -Flag lda [format] get the character - and #$00FF - cmp #'-' if it is a '-' then - bne fl1 - lda #1 left justify the output - sta ~leftJustify - bra fl5 +Flag lda [format] get the character + and #$00FF + cmp #'-' if it is a '-' then + bne fl1 + lda #1 left justify the output + sta ~leftJustify + bra fl5 -fl1 cmp #'0' if it is a '0' then - bne fl2 - sta ~paddChar padd with '0' characters - bra fl5 +fl1 cmp #'0' if it is a '0' then + bne fl2 + sta ~paddChar padd with '0' characters + bra fl5 -fl2 cmp #'+' if it is a '+' or ' ' then - beq fl3 - cmp #' ' - bne fl4 - ldx ~sign - cpx #'+' - beq fl5 -fl3 sta ~sign set the sign flag - bra fl5 +fl2 cmp #'+' if it is a '+' or ' ' then + beq fl3 + cmp #' ' + bne fl4 + ldx ~sign + cpx #'+' + beq fl5 +fl3 sta ~sign set the sign flag + bra fl5 -fl4 cmp #'#' if it is a '#' then - bne fl6 - lda #1 use the alternate output form - sta ~altForm -fl5 inc4 format skip the format character - sec - rts +fl4 cmp #'#' if it is a '#' then + bne fl6 + lda #1 use the alternate output form + sta ~altForm +fl5 inc4 format skip the format character + sec + rts -fl6 clc no flag was found - rts +fl6 clc no flag was found + rts ; ; GetSize - get a numeric value ; ; The value is returned in A ; -GetSize stz val assume a value of 0 - lda [format] if the format character is '*' then - and #$00FF - cmp #'*' - bne gs1 - inc4 format skip the '*' char - lda [argp] fetch the value - bpl fv1 do adjustments if negative: - ldx ~precisionSpecified - bne fv0 - eor #$ffff negative field width is like - inc a positive with - flag - ldx #1 - stx ~leftJustify - bra fv1 -fv0 lda #0 negative precision is ignored - stz ~precisionSpecified -fv1 sta val - inc argp remove it from the argument list - inc argp -gs0 lda val - rts +GetSize stz val assume a value of 0 + lda [format] if the format character is '*' then + and #$00FF + cmp #'*' + bne gs1 + inc4 format skip the '*' char + lda [argp] fetch the value + bpl fv1 do adjustments if negative: + ldx ~precisionSpecified + bne fv0 + eor #$ffff negative field width is like + inc a positive with - flag + ldx #1 + stx ~leftJustify + bra fv1 +fv0 lda #0 negative precision is ignored + stz ~precisionSpecified +fv1 sta val + inc argp remove it from the argument list + inc argp +gs0 lda val + rts -gs1 lda [format] while the character stream had digits do - and #$00FF - cmp #'0' - blt gs0 - cmp #'9'+1 - bge gs0 -gs2 and #$000F save the ordinal value - pha - asl val A := val*10 - lda val - asl a - asl a - adc val - adc 1,S A := A+ord([format]) - plx - sta val val := A - inc4 format skip the character - bra gs1 +gs1 lda [format] while the character stream had digits do + and #$00FF + cmp #'0' + blt gs0 + cmp #'9'+1 + bge gs0 +gs2 and #$000F save the ordinal value + pha + asl val A := val*10 + lda val + asl a + asl a + adc val + adc 1,S A := A+ord([format]) + plx + sta val val := A + inc4 format skip the character + bra gs1 -val ds 2 value +val ds 2 value ; ; List of format specifiers and the equivalent subroutines ; -fList dc c'%',i1'0',a'~Format_Percent' % - dc c'a',i1'0',a'~Format_e' a (not formatted correctly) - dc c'A',i1'0',a'~Format_E' A (not formatted correctly) - dc c'f',i1'0',a'~Format_f' f - dc c'F',i1'0',a'~Format_f' F - dc c'e',i1'0',a'~Format_e' e - dc c'E',i1'0',a'~Format_E' E - dc c'g',i1'0',a'~Format_g' g - dc c'G',i1'0',a'~Format_G' G - dc c'n',i1'0',a'~Format_n' n - dc c's',i1'0',a'~Format_s' s - dc c'b',i1'0',a'~Format_b' b - dc c'P',i1'0',a'~Format_P' P - dc c'p',i1'0',a'~Format_p' p - dc c'c',i1'0',a'~Format_c' c - dc c'X',i1'0',a'~Format_X' X - dc c'x',i1'0',a'~Format_x' x - dc c'o',i1'0',a'~Format_o' o - dc c'u',i1'0',a'~Format_u' u - dc c'd',i1'0',a'~Format_d' d - dc c'i',i1'0',a'~Format_d' i +fList dc c'%',i1'0',a'~Format_Percent' % + dc c'a',i1'0',a'~Format_e' a (not formatted correctly) + dc c'A',i1'0',a'~Format_E' A (not formatted correctly) + dc c'f',i1'0',a'~Format_f' f + dc c'F',i1'0',a'~Format_f' F + dc c'e',i1'0',a'~Format_e' e + dc c'E',i1'0',a'~Format_E' E + dc c'g',i1'0',a'~Format_g' g + dc c'G',i1'0',a'~Format_G' G + dc c'n',i1'0',a'~Format_n' n + dc c's',i1'0',a'~Format_s' s + dc c'b',i1'0',a'~Format_b' b + dc c'P',i1'0',a'~Format_P' P + dc c'p',i1'0',a'~Format_p' p + dc c'c',i1'0',a'~Format_c' c + dc c'X',i1'0',a'~Format_X' X + dc c'x',i1'0',a'~Format_x' x + dc c'o',i1'0',a'~Format_o' o + dc c'u',i1'0',a'~Format_u' u + dc c'd',i1'0',a'~Format_d' d + dc c'i',i1'0',a'~Format_d' i fListEnd anop - end + end **************************************************************** * @@ -4938,77 +4938,77 @@ fListEnd anop ; ; ~putchar is a vector to the proper output routine. ; -~putchar dc h'EE',i'~numChars' inc ~numChars - dc h'5C 00 00 00' +~putchar dc h'EE',i'~numChars' inc ~numChars + dc h'5C 00 00 00' ; ; Format options ; -~altForm ds 2 use alternate output format? -~fieldWidth ds 2 output field width -~hexPrefix ds 2 hex 0x prefix characters (if present) -~isLong ds 2 is the operand long _or_ long long ? -~isLongLong ds 2 is the operand long long (64-bit)? -~isByte ds 2 is operand byte-size (converted to int)? -~leftJustify ds 2 left justify the output? -~paddChar ds 2 output padd character -~precision ds 2 precision of output -~precisionSpecified ds 2 was the precision specified? -~removeZeros ds 2 remove insignificant zeros? (g specifier) -~sign ds 2 char to use for positive sign +~altForm ds 2 use alternate output format? +~fieldWidth ds 2 output field width +~hexPrefix ds 2 hex 0x prefix characters (if present) +~isLong ds 2 is the operand long _or_ long long ? +~isLongLong ds 2 is the operand long long (64-bit)? +~isByte ds 2 is operand byte-size (converted to int)? +~leftJustify ds 2 left justify the output? +~paddChar ds 2 output padd character +~precision ds 2 precision of output +~precisionSpecified ds 2 was the precision specified? +~removeZeros ds 2 remove insignificant zeros? (g specifier) +~sign ds 2 char to use for positive sign ; ; Work buffers ; -~num ds 8 long long integer -~numChars ds 2 number of characters printed with this printf -~str ds 83 string buffer +~num ds 8 long long integer +~numChars ds 2 number of characters printed with this printf +~str ds 83 string buffer ; ; Real formatting ; -~decForm anop controls SANE's formatting styles -~style ds 2 0 -> exponential; 1 -> fixed -~digits ds 2 sig. digits; decimal digits +~decForm anop controls SANE's formatting styles +~style ds 2 0 -> exponential; 1 -> fixed +~digits ds 2 sig. digits; decimal digits -~decRec anop decimal record -~sgn ds 2 sign -~exp ds 2 exponent -~sig ds 29 significant digits - end +~decRec anop decimal record +~sgn ds 2 sign +~exp ds 2 exponent +~sig ds 29 significant digits + end **************************************************************** * * ~RemoveWordFromStack - remove Y words from the stack for scanf * * Inputs: -* Y - number of words to remove (must be >0) +* Y - number of words to remove (must be >0) * **************************************************************** * ~RemoveWordFromStack private -lb1 lda 13,S move the critical values - sta 15,S - lda 11,S - sta 13,S - lda 9,S - sta 11,S - lda 7,S - sta 9,S - lda 5,S - sta 7,S - lda 3,S - sta 5,S - pla - sta 1,S +lb1 lda 13,S move the critical values + sta 15,S + lda 11,S + sta 13,S + lda 9,S + sta 11,S + lda 7,S + sta 9,S + lda 5,S + sta 7,S + lda 3,S + sta 5,S + pla + sta 1,S - tdc update the direct page location - inc a - inc a - tcd + tdc update the direct page location + inc a + inc a + tcd - dey next word - bne lb1 - rts - end + dey next word + bne lb1 + rts + end **************************************************************** * @@ -5016,82 +5016,82 @@ lb1 lda 13,S move the critical values * arguments for scanf * * Inputs: -* Y - number of words to remove (must be 1 or 2) +* Y - number of words to remove (must be 1 or 2) * **************************************************************** * ~RemoveWordFromVarArgs private - using ~scanfCommon -arg equ 11 argument position + using ~scanfCommon +arg equ 11 argument position - tya advance argument pointer - asl a -lb2 inc4 ~va_arg_ptr - dec a - bne lb2 + tya advance argument pointer + asl a +lb2 inc4 ~va_arg_ptr + dec a + bne lb2 - lda ~va_arg_ptr stick next argument in arg location - sta arg - lda ~va_arg_ptr+2 - sta arg+2 - lda [arg] - tax - cpy #2 - bne lb1 - lda [arg],y - sta arg+2 -lb1 stx arg - rts - end + lda ~va_arg_ptr stick next argument in arg location + sta arg + lda ~va_arg_ptr+2 + sta arg+2 + lda [arg] + tax + cpy #2 + bne lb1 + lda [arg],y + sta arg+2 +lb1 stx arg + rts + end **************************************************************** * * ~Scan_c - read a character or multiple characters * * Inputs: -* ~scanWidth - # of characters to read (0 implies one) -* ~suppress - suppress save? +* ~scanWidth - # of characters to read (0 implies one) +* ~suppress - suppress save? * **************************************************************** * -~Scan_c private - using ~scanfCommon -arg equ 11 argument +~Scan_c private + using ~scanfCommon +arg equ 11 argument - stz didOne no characters scanned from the stream - lda ~scanWidth if ~scanWidth == 0 then - bne lb1 - inc ~scanWidth ~scanWidth = 1 + stz didOne no characters scanned from the stream + lda ~scanWidth if ~scanWidth == 0 then + bne lb1 + inc ~scanWidth ~scanWidth = 1 -lb1 jsl ~getchar get the character - cmp #EOF if at EOF then - bne lb1b - ldx didOne if no characters read then - bne lb1a - sta ~eofFound ~eofFound = EOF -lb1a lda ~suppress if input is not suppressed then - bne lb3 - dec ~assignments no assignment made - bra lb3 bail out +lb1 jsl ~getchar get the character + cmp #EOF if at EOF then + bne lb1b + ldx didOne if no characters read then + bne lb1a + sta ~eofFound ~eofFound = EOF +lb1a lda ~suppress if input is not suppressed then + bne lb3 + dec ~assignments no assignment made + bra lb3 bail out -lb1b ldx #1 - stx didOne - ldx ~suppress if input is not suppressed then - bne lb2 - short M save the value - sta [arg] - long M - inc4 arg update the pointer -lb2 dec ~scanWidth next character - bne lb1 -lb3 lda ~suppress if input is not suppressed then - bne lb4 - ldy #2 - jsr ~RemoveWord remove the parameter from the stack -lb4 rts +lb1b ldx #1 + stx didOne + ldx ~suppress if input is not suppressed then + bne lb2 + short M save the value + sta [arg] + long M + inc4 arg update the pointer +lb2 dec ~scanWidth next character + bne lb1 +lb3 lda ~suppress if input is not suppressed then + bne lb4 + ldy #2 + jsr ~RemoveWord remove the parameter from the stack +lb4 rts -didOne ds 2 non-zero if we have scanned a character - end +didOne ds 2 non-zero if we have scanned a character + end **************************************************************** * @@ -5099,329 +5099,329 @@ didOne ds 2 non-zero if we have scanned a character * ~Scan_i - read a based integer * * Inputs: -* ~scanError - has a scan error occurred? -* ~scanWidth - max input length -* ~suppress - suppress save? -* ~size - size specifier +* ~scanError - has a scan error occurred? +* ~scanWidth - max input length +* ~suppress - suppress save? +* ~size - size specifier * **************************************************************** * -~Scan_d private - using ~scanfCommon -arg equ 11 argument +~Scan_d private + using ~scanfCommon +arg equ 11 argument - stz based always use base 10 - bra bs1 -~Scan_i entry - lda #1 allow base 8, 10, 16 - sta based + stz based always use base 10 + bra bs1 +~Scan_i entry + lda #1 allow base 8, 10, 16 + sta based -bs1 stz read no digits read - lda #10 assume base 10 - sta base - stz val initialize the value to 0 - stz val+2 - stz val+4 - stz val+6 -lb1 jsl ~getchar skip leading whitespace... - cmp #EOF if EOF then - bne ef1 - sta ~eofFound ~eofFound = EOF - lda ~suppress if input is not suppressed then - bne lb6l - dec ~assignments no assignment made -lb6l brl lb6 bail out -ef1 tax {...back to skipping whitespace} - lda __ctype+1,X - and #_space - bne lb1 - txa - stz minus assume positive number - cmp #'+' skip leading + - beq sg1 - cmp #'-' if - then set minus flag - bne sg3 - inc minus -sg1 dec ~scanWidth - jeq lb4a - bpl sg2 - stz ~scanWidth -sg2 jsl ~getchar -sg3 inc read - ldx based if base 8, 16 are allowed then - beq lb2 - cmp #'0' if the digit is '0' then - bne lb2 - lda #8 assume base 8 - sta base - dec ~scanWidth get the next character - jeq lb4a - bpl lb1a - stz ~scanWidth -lb1a jsl ~getchar - inc read - cmp #'X' if it is X then - beq lb1b - cmp #'x' - bne lb2 -lb1b asl base use base 16 - stz read '0x' alone should not match - dec ~scanWidth get the next character - jeq lb4a - bpl lb1c - stz ~scanWidth -lb1c jsl ~getchar - inc read +bs1 stz read no digits read + lda #10 assume base 10 + sta base + stz val initialize the value to 0 + stz val+2 + stz val+4 + stz val+6 +lb1 jsl ~getchar skip leading whitespace... + cmp #EOF if EOF then + bne ef1 + sta ~eofFound ~eofFound = EOF + lda ~suppress if input is not suppressed then + bne lb6l + dec ~assignments no assignment made +lb6l brl lb6 bail out +ef1 tax {...back to skipping whitespace} + lda __ctype+1,X + and #_space + bne lb1 + txa + stz minus assume positive number + cmp #'+' skip leading + + beq sg1 + cmp #'-' if - then set minus flag + bne sg3 + inc minus +sg1 dec ~scanWidth + jeq lb4a + bpl sg2 + stz ~scanWidth +sg2 jsl ~getchar +sg3 inc read + ldx based if base 8, 16 are allowed then + beq lb2 + cmp #'0' if the digit is '0' then + bne lb2 + lda #8 assume base 8 + sta base + dec ~scanWidth get the next character + jeq lb4a + bpl lb1a + stz ~scanWidth +lb1a jsl ~getchar + inc read + cmp #'X' if it is X then + beq lb1b + cmp #'x' + bne lb2 +lb1b asl base use base 16 + stz read '0x' alone should not match + dec ~scanWidth get the next character + jeq lb4a + bpl lb1c + stz ~scanWidth +lb1c jsl ~getchar + inc read -lb2 cmp #'0' if the char is a digit then - blt lb4 - cmp #'7'+1 - blt lb2a - ldx base - cpx #8 - beq lb4 - cmp #'9'+1 - blt lb2a - cpx #16 - bne lb4 - and #$00DF - cmp #'A' - blt lb4 - cmp #'F'+1 - bge lb4 - sbc #6 -lb2a and #$000F convert it to a value - pha save the value - ph8 val update the old value - ldx #0 - phx - phx - phx - lda base - pha - jsl ~UMUL8 - pl8 val - pla add in the new digit - clc - adc val - sta val - bcc lb3 - inc val+2 - bne lb3 - inc val+4 - bne lb3 - inc val+6 -lb3 dec ~scanWidth quit if the max # chars have been - beq lb4a scanned - bpl lb3a make sure 0 stays a 0 - stz ~scanWidth -lb3a jsl ~getchar next char - inc read - brl lb2 +lb2 cmp #'0' if the char is a digit then + blt lb4 + cmp #'7'+1 + blt lb2a + ldx base + cpx #8 + beq lb4 + cmp #'9'+1 + blt lb2a + cpx #16 + bne lb4 + and #$00DF + cmp #'A' + blt lb4 + cmp #'F'+1 + bge lb4 + sbc #6 +lb2a and #$000F convert it to a value + pha save the value + ph8 val update the old value + ldx #0 + phx + phx + phx + lda base + pha + jsl ~UMUL8 + pl8 val + pla add in the new digit + clc + adc val + sta val + bcc lb3 + inc val+2 + bne lb3 + inc val+4 + bne lb3 + inc val+6 +lb3 dec ~scanWidth quit if the max # chars have been + beq lb4a scanned + bpl lb3a make sure 0 stays a 0 + stz ~scanWidth +lb3a jsl ~getchar next char + inc read + brl lb2 -lb4 jsl ~putback put the last character back - dec read -lb4a lda read if no chars read then - bne lb4b - inc ~scanError ~scanError = true - lda ~suppress if input is not suppressed then - bne lb6 - dec ~assignments no assignment made - bra lb6 skip the save -lb4b lda ~suppress if input is not suppressed then - bne lb7 - lda minus if minus then - beq lb4c - negate8 val negate the value -lb4c lda val save the value - ldx ~size - bpl lb4d - sep #$20 -lb4d sta [arg] - rep #$20 - dex - bmi lb6 - ldy #2 - lda val+2 - sta [arg],Y - dex - bmi lb6 - iny - iny - lda val+4 - sta [arg],Y - iny - iny - lda val+6 - sta [arg],Y -lb6 lda ~suppress if input is not suppressed then - bne lb7 - ldy #2 remove the parameter from the stack - jsr ~RemoveWord -lb7 rts +lb4 jsl ~putback put the last character back + dec read +lb4a lda read if no chars read then + bne lb4b + inc ~scanError ~scanError = true + lda ~suppress if input is not suppressed then + bne lb6 + dec ~assignments no assignment made + bra lb6 skip the save +lb4b lda ~suppress if input is not suppressed then + bne lb7 + lda minus if minus then + beq lb4c + negate8 val negate the value +lb4c lda val save the value + ldx ~size + bpl lb4d + sep #$20 +lb4d sta [arg] + rep #$20 + dex + bmi lb6 + ldy #2 + lda val+2 + sta [arg],Y + dex + bmi lb6 + iny + iny + lda val+4 + sta [arg],Y + iny + iny + lda val+6 + sta [arg],Y +lb6 lda ~suppress if input is not suppressed then + bne lb7 + ldy #2 remove the parameter from the stack + jsr ~RemoveWord +lb7 rts -val ds 8 value -base dc i2'10' number base -based ds 2 based conversion? -minus ds 2 is the value negative? -read ds 2 # of digits read - end +val ds 8 value +base dc i2'10' number base +based ds 2 based conversion? +minus ds 2 is the value negative? +read ds 2 # of digits read + end **************************************************************** * * ~Scan_lbrack - read character in a set * * Inputs: -* ~scanWidth - max input length -* ~suppress - suppress save? -* ~size - size specifier +* ~scanWidth - max input length +* ~suppress - suppress save? +* ~size - size specifier * **************************************************************** * ~Scan_lbrack private - using ~scanfCommon - using ~printfCommon -arg equ 11 argument -format equ 7 pointer to format code + using ~scanfCommon + using ~printfCommon +arg equ 11 argument +format equ 7 pointer to format code - stz read no characters read into the set - stz didOne no characters scanned from the stream - move #0,~str,#32 clear the set - stz negate don't negate the set - lda [format] if the first char is '^' then - and #$00FF - cmp #'^' - bne lb2 - dec negate negate the set -lb1 inc4 format skip the ^ -lb2 lda [format] while *format != ']' do - and #$00FF - ldx read but wait: ']' as the first char is - beq lb2a allowed! - cmp #']' - beq lb3 -lb2a inc read - jsr Set set the char's bit - ora ~str,X - sta ~str,X - bra lb1 next char -lb3 inc4 format skip the ']' - ldy #30 negate the set (if needed) -lb4 lda ~str,Y - eor negate - sta ~str,Y - dey - dey - bpl lb4 + stz read no characters read into the set + stz didOne no characters scanned from the stream + move #0,~str,#32 clear the set + stz negate don't negate the set + lda [format] if the first char is '^' then + and #$00FF + cmp #'^' + bne lb2 + dec negate negate the set +lb1 inc4 format skip the ^ +lb2 lda [format] while *format != ']' do + and #$00FF + ldx read but wait: ']' as the first char is + beq lb2a allowed! + cmp #']' + beq lb3 +lb2a inc read + jsr Set set the char's bit + ora ~str,X + sta ~str,X + bra lb1 next char +lb3 inc4 format skip the ']' + ldy #30 negate the set (if needed) +lb4 lda ~str,Y + eor negate + sta ~str,Y + dey + dey + bpl lb4 -lb5 jsl ~getchar get a character - cmp #EOF quit if at EOF - beq lb7a - pha quit if not in the set - jsr Set - ply - and ~str,X - beq lb7 - sty didOne note that we scanned a character - ldx ~suppress if output is not suppressed then - bne lb6 - tya - short M save the character - sta [arg] - long M - inc4 arg update the argument -lb6 dec ~scanWidth note that we processed one - beq lb8 - bpl lb5 - stz ~scanWidth - bra lb5 next char +lb5 jsl ~getchar get a character + cmp #EOF quit if at EOF + beq lb7a + pha quit if not in the set + jsr Set + ply + and ~str,X + beq lb7 + sty didOne note that we scanned a character + ldx ~suppress if output is not suppressed then + bne lb6 + tya + short M save the character + sta [arg] + long M + inc4 arg update the argument +lb6 dec ~scanWidth note that we processed one + beq lb8 + bpl lb5 + stz ~scanWidth + bra lb5 next char -lb7 tya put back the last char scanned -lb7a jsl ~putback +lb7 tya put back the last char scanned +lb7a jsl ~putback -lb8 lda didOne if no chars read then - bne lb8a - inc ~scanError ~scanError = true - lda ~suppress if input is not suppressed then - bne lb9 - dec ~assignments no assignment made - bra lb8b skip the save -lb8a lda ~suppress if output is not suppressed then - bne lb9 - short M set the terminating null - lda #0 - sta [arg] - long M +lb8 lda didOne if no chars read then + bne lb8a + inc ~scanError ~scanError = true + lda ~suppress if input is not suppressed then + bne lb9 + dec ~assignments no assignment made + bra lb8b skip the save +lb8a lda ~suppress if output is not suppressed then + bne lb9 + short M set the terminating null + lda #0 + sta [arg] + long M -lb8b ldy #2 remove the parameter from the stack - jsr ~RemoveWord -lb9 rts +lb8b ldy #2 remove the parameter from the stack + jsr ~RemoveWord +lb9 rts ; ; Set - form a set disp/bit pattern from a character value ; -Set ldx #1 - stx disp -st1 bit #$0007 - beq st2 - asl disp - dec A - bra st1 -st2 lsr A - lsr A - lsr A - tax - lda disp - rts +Set ldx #1 + stx disp +st1 bit #$0007 + beq st2 + asl disp + dec A + bra st1 +st2 lsr A + lsr A + lsr A + tax + lda disp + rts -negate ds 2 negate the set? -disp ds 2 used to form the set disp -read ds 2 number of characters in the scan set -didOne ds 2 non-zero if we have scanned a character - end +negate ds 2 negate the set? +disp ds 2 used to form the set disp +read ds 2 number of characters in the scan set +didOne ds 2 non-zero if we have scanned a character + end **************************************************************** * * ~Scan_n - return the # of characters scanned so far * * Inputs: -* ~suppress - suppress save? +* ~suppress - suppress save? * * Notes: -* Decrements ~assignments so the increment in scanf will -* leave the assignment count unaffected by this call. +* Decrements ~assignments so the increment in scanf will +* leave the assignment count unaffected by this call. * **************************************************************** * -~Scan_n private - using ~scanfCommon -arg equ 11 argument +~Scan_n private + using ~scanfCommon +arg equ 11 argument - ldx ~suppress if output is not suppressed then - bne lb1 - lda ~scanCount save the count - ldx ~size - bpl lb0 - sep #$20 -lb0 sta [arg] - rep #$20 - dex - bmi lb0a - lda #0 - ldy #2 - sta [arg],y - dex - bmi lb0a - iny - iny - sta [arg],y - iny - iny - sta [arg],y -lb0a dec ~assignments fix assignment count -lb1 ldy #2 remove the parameter from the stack - jsr ~RemoveWord - rts - end + ldx ~suppress if output is not suppressed then + bne lb1 + lda ~scanCount save the count + ldx ~size + bpl lb0 + sep #$20 +lb0 sta [arg] + rep #$20 + dex + bmi lb0a + lda #0 + ldy #2 + sta [arg],y + dex + bmi lb0a + iny + iny + sta [arg],y + iny + iny + sta [arg],y +lb0a dec ~assignments fix assignment count +lb1 ldy #2 remove the parameter from the stack + jsr ~RemoveWord + rts + end **************************************************************** * @@ -5430,126 +5430,126 @@ lb1 ldy #2 remove the parameter from the stack * ~Scan_s - read a c string * * Inputs: -* ~scanError - has a scan error occurred? -* ~scanWidth - max input length -* ~suppress - suppress save? -* ~size - size specifier +* ~scanError - has a scan error occurred? +* ~scanWidth - max input length +* ~suppress - suppress save? +* ~size - size specifier * **************************************************************** * -~Scan_b private -~Scan_P entry - using ~scanfCommon -arg equ 11 argument +~Scan_b private +~Scan_P entry + using ~scanfCommon +arg equ 11 argument - move4 arg,length save the location to store the length - inc4 arg increment to the first char position - lda #1 - sta pString set the p-string flag - bra lb1 -~Scan_s entry - stz pString clear the p-string flag + move4 arg,length save the location to store the length + inc4 arg increment to the first char position + lda #1 + sta pString set the p-string flag + bra lb1 +~Scan_s entry + stz pString clear the p-string flag -lb1 jsl ~getchar skip leading whitespace - cmp #EOF - bne lb2 - sta ~eofFound - inc ~scanError - lda ~suppress (no assignment made) - bne lb6 - dec ~assignments - bra lb6 -lb2 tax - lda __ctype+1,X - and #_space - bne lb1 +lb1 jsl ~getchar skip leading whitespace + cmp #EOF + bne lb2 + sta ~eofFound + inc ~scanError + lda ~suppress (no assignment made) + bne lb6 + dec ~assignments + bra lb6 +lb2 tax + lda __ctype+1,X + and #_space + bne lb1 -lb2a txa - ldx ~suppress if output is not suppressed then - bne lb3 - short M save the character - sta [arg] - long M - inc4 arg update the argument -lb3 dec ~scanWidth note that we processed one - beq lb5 - bpl lb4 - stz ~scanWidth -lb4 jsl ~getchar next char - cmp #EOF quit if at EOF - beq lb4a - and #$00FF loop if not whitespace - tax - lda __ctype+1,X - and #_space - beq lb2a - txa whitespace: put it back -lb4a jsl ~putback +lb2a txa + ldx ~suppress if output is not suppressed then + bne lb3 + short M save the character + sta [arg] + long M + inc4 arg update the argument +lb3 dec ~scanWidth note that we processed one + beq lb5 + bpl lb4 + stz ~scanWidth +lb4 jsl ~getchar next char + cmp #EOF quit if at EOF + beq lb4a + and #$00FF loop if not whitespace + tax + lda __ctype+1,X + and #_space + beq lb2a + txa whitespace: put it back +lb4a jsl ~putback -lb5 lda ~suppress if output is not suppressed then - bne lb6 - short M set the terminating null - lda #0 - sta [arg] - long M - lda pString if this is a p-string then - beq lb6 - sec compute the length - lda arg - sbc length - dec A - ldx length set up the address - stx arg - ldx length+2 - stx arg+2 - short M save the length - sta [arg] - long M +lb5 lda ~suppress if output is not suppressed then + bne lb6 + short M set the terminating null + lda #0 + sta [arg] + long M + lda pString if this is a p-string then + beq lb6 + sec compute the length + lda arg + sbc length + dec A + ldx length set up the address + stx arg + ldx length+2 + stx arg+2 + short M save the length + sta [arg] + long M -lb6 lda ~suppress if output is not suppressed then - bne lb7 - ldy #2 remove the parameter from the stack - jsr ~RemoveWord -lb7 rts +lb6 lda ~suppress if output is not suppressed then + bne lb7 + ldy #2 remove the parameter from the stack + jsr ~RemoveWord +lb7 rts -length ds 4 ptr to the length byte (p string only) -pString ds 2 is this a p string? - end +length ds 4 ptr to the length byte (p string only) +pString ds 2 is this a p string? + end **************************************************************** * * ~Scan_percent - read a % character * * Inputs: -* ~scanWidth - max input length -* ~suppress - suppress save? -* ~size - size specifier +* ~scanWidth - max input length +* ~suppress - suppress save? +* ~size - size specifier * **************************************************************** * ~Scan_percent private - using ~scanfCommon -arg equ 11 argument + using ~scanfCommon +arg equ 11 argument - lda ~suppress if input is not suppressed then - bne lb1 - dec ~assignments no assignment done -lb1 jsl ~getchar skip leading whitespace... - cmp #EOF if EOF then - bne lb2 - sta ~eofFound ~eofFound = EOF - rts -lb2 tax ...back to skipping whitespace - lda __ctype+1,X - and #_space - bne lb1 - txa - cmp #'%' if it is not a percent then - beq lb3 - jsl ~putback put it back - inc ~scanError note the error -lb3 rts - end + lda ~suppress if input is not suppressed then + bne lb1 + dec ~assignments no assignment done +lb1 jsl ~getchar skip leading whitespace... + cmp #EOF if EOF then + bne lb2 + sta ~eofFound ~eofFound = EOF + rts +lb2 tax ...back to skipping whitespace + lda __ctype+1,X + and #_space + bne lb1 + txa + cmp #'%' if it is not a percent then + beq lb3 + jsl ~putback put it back + inc ~scanError note the error +lb3 rts + end **************************************************************** * @@ -5559,197 +5559,197 @@ lb3 rts * ~Scan_p - read a pointer * * Inputs: -* ~scanWidth - max input length -* ~suppress - suppress save? -* ~size - size specifier +* ~scanWidth - max input length +* ~suppress - suppress save? +* ~size - size specifier * **************************************************************** * -~Scan_u private - using ~scanfCommon -arg equ 11 argument +~Scan_u private + using ~scanfCommon +arg equ 11 argument - jsr Init - lda #10 base 10 - bra bs1 + jsr Init + lda #10 base 10 + bra bs1 -~Scan_o entry - jsr Init - lda #8 base 8 - bra bs1 +~Scan_o entry + jsr Init + lda #8 base 8 + bra bs1 -~Scan_p entry - lda #1 - sta ~size -~Scan_x entry - jsr Init - jsl ~getchar if the initial char is a '0' then - inc read - sta ch - cmp #'0' - bne hx2 - dec ~scanWidth get the next character - jeq lb4a - bpl hx1 - stz ~scanWidth -hx1 jsl ~getchar - inc read - sta ch - cmp #'x' if it is an 'x' or 'X' then - beq hx1a - cmp #'X' - bne hx2 -hx1a stz read ('0x' alone should not match) - dec ~scanWidth accept the character - jeq lb4a - bpl hx3 - stz ~scanWidth - bra hx3 -hx2 jsl ~putback put back the character - dec read -hx3 lda #16 base 16 +~Scan_p entry + lda #1 + sta ~size +~Scan_x entry + jsr Init + jsl ~getchar if the initial char is a '0' then + inc read + sta ch + cmp #'0' + bne hx2 + dec ~scanWidth get the next character + jeq lb4a + bpl hx1 + stz ~scanWidth +hx1 jsl ~getchar + inc read + sta ch + cmp #'x' if it is an 'x' or 'X' then + beq hx1a + cmp #'X' + bne hx2 +hx1a stz read ('0x' alone should not match) + dec ~scanWidth accept the character + jeq lb4a + bpl hx3 + stz ~scanWidth + bra hx3 +hx2 jsl ~putback put back the character + dec read +hx3 lda #16 base 16 -bs1 sta base set the base +bs1 sta base set the base -lb2 jsl ~getchar if the char is a digit then - inc read - sta ch - cmp #'0' - blt lb4 - cmp #'7'+1 - blt lb2a - ldx base - cpx #8 - beq lb4 - cmp #'9'+1 - blt lb2a - cpx #16 - bne lb4 - and #$00DF - cmp #'A' - blt lb4 - cmp #'F'+1 - bge lb4 - sbc #6 -lb2a and #$000F convert it to a value - pha save the value - ph8 val update the old value - ldx #0 - phx - phx - phx - lda base - pha - jsl ~UMUL8 - pl8 val - pla add in the new digit - clc - adc val - sta val - bcc lb3 - inc val+2 - bne lb3 - inc val+4 - bne lb3 - inc val+6 -lb3 dec ~scanWidth quit if the max # chars have been - beq lb4a scanned - jpl lb2 make sure 0 stays a 0 - stz ~scanWidth - brl lb2 +lb2 jsl ~getchar if the char is a digit then + inc read + sta ch + cmp #'0' + blt lb4 + cmp #'7'+1 + blt lb2a + ldx base + cpx #8 + beq lb4 + cmp #'9'+1 + blt lb2a + cpx #16 + bne lb4 + and #$00DF + cmp #'A' + blt lb4 + cmp #'F'+1 + bge lb4 + sbc #6 +lb2a and #$000F convert it to a value + pha save the value + ph8 val update the old value + ldx #0 + phx + phx + phx + lda base + pha + jsl ~UMUL8 + pl8 val + pla add in the new digit + clc + adc val + sta val + bcc lb3 + inc val+2 + bne lb3 + inc val+4 + bne lb3 + inc val+6 +lb3 dec ~scanWidth quit if the max # chars have been + beq lb4a scanned + jpl lb2 make sure 0 stays a 0 + stz ~scanWidth + brl lb2 -lb4 lda ch put the last character back - jsl ~putback - dec read -lb4a lda read if no chars read then - bne lb4b - inc ~scanError ~scanError = true - lda ~suppress if input is not suppressed then - bne lb6 - dec ~assignments no assignment made - bra lb6 remove the parameter -lb4b lda ~suppress if input is not suppressed then - bne lb7 - lda minus if minus then - beq lb4c - negate8 val negate the value -lb4c lda val save the value - ldx ~size - bpl lb4d - sep #$20 -lb4d sta [arg] - rep #$20 - dex - bmi lb6 - ldy #2 - lda val+2 - sta [arg],Y - dex - bmi lb6 - iny - iny - lda val+4 - sta [arg],Y - iny - iny - lda val+6 - sta [arg],Y -lb6 lda ~suppress if input is not suppressed then - bne lb7 - ldy #2 remove the parameter from the stack - jsr ~RemoveWord -lb7 rts +lb4 lda ch put the last character back + jsl ~putback + dec read +lb4a lda read if no chars read then + bne lb4b + inc ~scanError ~scanError = true + lda ~suppress if input is not suppressed then + bne lb6 + dec ~assignments no assignment made + bra lb6 remove the parameter +lb4b lda ~suppress if input is not suppressed then + bne lb7 + lda minus if minus then + beq lb4c + negate8 val negate the value +lb4c lda val save the value + ldx ~size + bpl lb4d + sep #$20 +lb4d sta [arg] + rep #$20 + dex + bmi lb6 + ldy #2 + lda val+2 + sta [arg],Y + dex + bmi lb6 + iny + iny + lda val+4 + sta [arg],Y + iny + iny + lda val+6 + sta [arg],Y +lb6 lda ~suppress if input is not suppressed then + bne lb7 + ldy #2 remove the parameter from the stack + jsr ~RemoveWord +lb7 rts ; ; Initialization ; -Init stz read no chars read - stz val initialize the value to 0 - stz val+2 - stz val+4 - stz val+6 -in1 jsl ~getchar skip leading whitespace... - cmp #EOF if at EOF then - bne in2 - sta ~eofFound eofFound = EOF - lda ~suppress if input is not suppressed then - bne in1a - dec ~assignments no assignment made -in1a pla pop stack - bra lb6 bail out -in2 tax ...back to skipping whitespace - lda __ctype+1,X - and #_space - bne in1 - txa check for leading sign - stz minus assume positive number - cmp #'+' skip leading + - beq in3 - cmp #'-' if - then set minus flag - bne in5 - inc minus -in3 dec ~scanWidth update ~scanWidth - beq in6 sign only is not a matching sequence - bpl in4 make sure 0 stays a 0 - stz ~scanWidth -in4 rts +Init stz read no chars read + stz val initialize the value to 0 + stz val+2 + stz val+4 + stz val+6 +in1 jsl ~getchar skip leading whitespace... + cmp #EOF if at EOF then + bne in2 + sta ~eofFound eofFound = EOF + lda ~suppress if input is not suppressed then + bne in1a + dec ~assignments no assignment made +in1a pla pop stack + bra lb6 bail out +in2 tax ...back to skipping whitespace + lda __ctype+1,X + and #_space + bne in1 + txa check for leading sign + stz minus assume positive number + cmp #'+' skip leading + + beq in3 + cmp #'-' if - then set minus flag + bne in5 + inc minus +in3 dec ~scanWidth update ~scanWidth + beq in6 sign only is not a matching sequence + bpl in4 make sure 0 stays a 0 + stz ~scanWidth +in4 rts -in5 jsl ~putback - rts +in5 jsl ~putback + rts -in6 inc ~scanError ~scanError = true - lda ~suppress if input is not suppressed then - bne in7 - dec ~assignments no assignment made -in7 pla pop stack - bra lb6 bail out +in6 inc ~scanError ~scanError = true + lda ~suppress if input is not suppressed then + bne in7 + dec ~assignments no assignment made +in7 pla pop stack + bra lb6 bail out -ch ds 2 char buffer -val ds 8 value -base dc i2'10' number base -based ds 2 based conversion? -minus ds 2 is there a minus sign? -read ds 2 # of digits read - end +ch ds 2 char buffer +val ds 8 value +base dc i2'10' number base +based ds 2 based conversion? +minus ds 2 is there a minus sign? +read ds 2 # of digits read + end **************************************************************** * @@ -5762,8 +5762,8 @@ read ds 2 # of digits read * Assignment Suppression Flag * --------------------------- * -* '*' Do everything but save the result and remove a pointer from -* the stack. +* '*' Do everything but save the result and remove a pointer from +* the stack. * * Max Field Width * --------------- @@ -5774,333 +5774,333 @@ read ds 2 # of digits read * Size Specification * ------------------ * -* 'h' Used with 'd', 'u', 'o' or 'x' to indicate a short store. -* 'l' Used with 'd', 'u', 'o' or 'x' to indicate a four-byte store. -* Also used with 'e', 'f' or 'g' to indicate double reals. +* 'h' Used with 'd', 'u', 'o' or 'x' to indicate a short store. +* 'l' Used with 'd', 'u', 'o' or 'x' to indicate a four-byte store. +* Also used with 'e', 'f' or 'g' to indicate double reals. * * Conversion Specifier * -------------------- * -* d,i Signed decimal conversion to type int or long. -* u Signed decimal conversion to type unsigned short, unsigned or -* unsigned long. -* o Octal conversion. -* x,X Hexadecimal conversion. -* c Character. -* s String. -* b Pascal string. -* p Pointer. -* n The argument is (int *); the number of characters written so -* far is written to the location. +* d,i Signed decimal conversion to type int or long. +* u Signed decimal conversion to type unsigned short, unsigned or +* unsigned long. +* o Octal conversion. +* x,X Hexadecimal conversion. +* c Character. +* s String. +* b Pascal string. +* p Pointer. +* n The argument is (int *); the number of characters written so +* far is written to the location. * f,e,E,g,G Signed floating point conversion. -* % Read a '%' character. -* [ Scan and included characters and place them in a string. +* % Read a '%' character. +* [ Scan and included characters and place them in a string. * **************************************************************** * -~scanf private - using ~scanfCommon +~scanf private + using ~scanfCommon -arg equ format+4 first argument -format equ 7 pointer to format code +arg equ format+4 first argument +format equ 7 pointer to format code ; ; Set up the stack frame ; - phb save the caller's B - phk use local addressing - plb - phd save the caller's DP - tsc set up a DP - tcd + phb save the caller's B + phk use local addressing + plb + phd save the caller's DP + tsc set up a DP + tcd ; ; Set up for varargs, if we are using them ; - lda ~isVarArgs - beq ps - lda arg initialize ~va_list_ptr - sta ~va_list_ptr - lda arg+2 - sta ~va_list_ptr+2 - lda [arg] initialize ~va_arg_ptr - sta ~va_arg_ptr - tax - ldy #2 - lda [arg],y - sta ~va_arg_ptr+2 - stx arg - sta arg+2 + lda ~isVarArgs + beq ps + lda arg initialize ~va_list_ptr + sta ~va_list_ptr + lda arg+2 + sta ~va_list_ptr+2 + lda [arg] initialize ~va_arg_ptr + sta ~va_arg_ptr + tax + ldy #2 + lda [arg],y + sta ~va_arg_ptr+2 + stx arg + sta arg+2 - lda [arg] put first variable arg in arg location - tax - lda [arg],y - stx arg - sta arg+2 + lda [arg] put first variable arg in arg location + tax + lda [arg],y + stx arg + sta arg+2 ; ; Process the format string ; -ps stz ~assignments no assignments yet - stz ~scanCount no characters scanned - stz ~scanError no scan error so far - stz ~eofFound eof was not the first char - jsl ~getchar test for eof - cmp #EOF - bne ps0 - sta ~eofFound -ps0 jsl ~putback +ps stz ~assignments no assignments yet + stz ~scanCount no characters scanned + stz ~scanError no scan error so far + stz ~eofFound eof was not the first char + jsl ~getchar test for eof + cmp #EOF + bne ps0 + sta ~eofFound +ps0 jsl ~putback -ps1 lda ~scanError quit if a scan error has occurred - bne rm1 - lda [format] get a character - and #$00FF - jeq rt1 branch if at the end of the format string +ps1 lda ~scanError quit if a scan error has occurred + bne rm1 + lda [format] get a character + and #$00FF + jeq rt1 branch if at the end of the format string - tax if this is a whitespace char then - lda __ctype+1,X - and #_space - beq ps4 -ps2 inc4 format skip whitespace in the format string - lda [format] - and #$00FF - tax - lda __ctype+1,X - and #_space - bne ps2 -ps3 jsl ~getchar skip whitespace in the input stream - tax - cpx #EOF - beq ps3a - lda __ctype+1,X - and #_space - bne ps3 -ps3a txa - jsl ~putback - bra ps1 + tax if this is a whitespace char then + lda __ctype+1,X + and #_space + beq ps4 +ps2 inc4 format skip whitespace in the format string + lda [format] + and #$00FF + tax + lda __ctype+1,X + and #_space + bne ps2 +ps3 jsl ~getchar skip whitespace in the input stream + tax + cpx #EOF + beq ps3a + lda __ctype+1,X + and #_space + bne ps3 +ps3a txa + jsl ~putback + bra ps1 -ps4 cpx #'%' branch if this is a conversion - bne ps5 specification - brl fm1 +ps4 cpx #'%' branch if this is a conversion + bne ps5 specification + brl fm1 -ps5 stx ch make sure the char matches the format - inc4 format specifier - jsl ~getchar - cmp ch - beq ps1 - cmp #EOF check for EOF - bne ps6 - sta ~eofFound -ps6 jsl ~putback put the character back +ps5 stx ch make sure the char matches the format + inc4 format specifier + jsl ~getchar + cmp ch + beq ps1 + cmp #EOF check for EOF + bne ps6 + sta ~eofFound +ps6 jsl ~putback put the character back ; ; Remove the parameters for remaining conversion specifications ; -rm1 lda [format] if this is a format specifier then - and #$00FF - beq rt1 - cmp #'%' - bne rm4 - ldy #2 plan to remove 2 words - jsr IncFormat - beq rt1 - cmp #'*' - bne rm1a - dey ...but not if '*' found - dey - jsr IncFormat -rm1a cmp #'0' skip field width, if present - blt rm1b - cmp #'9'+1 - bge rm1b - jsr IncFormat - bra rm1a -rm1b cmp #'l' skip 'l' length modifier, if present - bne rm1c - jsr IncFormat -rm1c cmp #'%' ignore if it is '%%' format specifier - beq rm4 - cmp #'[' if it is a '[' then - bne rm3 - jsr IncFormat - cmp #'^' skip '^', if present - bne rm1d - jsr IncFormat -rm1d cmp #']' skip ']' in scanset, if present - bne rm2a -rm2 jsr IncFormat -rm2a tax - beq rt1 skip up to the closing ']' - cmp #']' - bne rm2 -rm3 tyx if '*' not found - beq rm4 - pha lay out stack as ~RemoveWord needs - jsr ~RemoveWord remove an addr from the stack - pla -rm4 inc4 format next format character - bra rm1 +rm1 lda [format] if this is a format specifier then + and #$00FF + beq rt1 + cmp #'%' + bne rm4 + ldy #2 plan to remove 2 words + jsr IncFormat + beq rt1 + cmp #'*' + bne rm1a + dey ...but not if '*' found + dey + jsr IncFormat +rm1a cmp #'0' skip field width, if present + blt rm1b + cmp #'9'+1 + bge rm1b + jsr IncFormat + bra rm1a +rm1b cmp #'l' skip 'l' length modifier, if present + bne rm1c + jsr IncFormat +rm1c cmp #'%' ignore if it is '%%' format specifier + beq rm4 + cmp #'[' if it is a '[' then + bne rm3 + jsr IncFormat + cmp #'^' skip '^', if present + bne rm1d + jsr IncFormat +rm1d cmp #']' skip ']' in scanset, if present + bne rm2a +rm2 jsr IncFormat +rm2a tax + beq rt1 skip up to the closing ']' + cmp #']' + bne rm2 +rm3 tyx if '*' not found + beq rm4 + pha lay out stack as ~RemoveWord needs + jsr ~RemoveWord remove an addr from the stack + pla +rm4 inc4 format next format character + bra rm1 ; ; Remove the format parameter and return ; -rt1 lda ~isVarArgs if it is a varargs call then - beq rt1a - lda ~va_list_ptr get pointer to va_list - sta arg - lda ~va_list_ptr+2 - sta arg+2 - lda ~va_arg_ptr update pointer in va_list - sta [arg] - lda ~va_arg_ptr+2 - ldy #2 - sta [arg],y - pha remove the va_list parameter - jsr ~RemoveWordFromStack - pla -rt1a lda format-2 move the return address - sta format+2 - lda format-3 - sta format+1 - pld restore DP - plb restore B - pla remove the extra 4 bytes from the stack - pla - lda >~assignments return the number of assignments - bne rt2 - lda >~eofFound return EOF if no characters scanned -rt2 rtl +rt1 lda ~isVarArgs if it is a varargs call then + beq rt1a + lda ~va_list_ptr get pointer to va_list + sta arg + lda ~va_list_ptr+2 + sta arg+2 + lda ~va_arg_ptr update pointer in va_list + sta [arg] + lda ~va_arg_ptr+2 + ldy #2 + sta [arg],y + pha remove the va_list parameter + jsr ~RemoveWordFromStack + pla +rt1a lda format-2 move the return address + sta format+2 + lda format-3 + sta format+1 + pld restore DP + plb restore B + pla remove the extra 4 bytes from the stack + pla + lda >~assignments return the number of assignments + bne rt2 + lda >~eofFound return EOF if no characters scanned +rt2 rtl ; ; Handle a format specification ; -fm1 inc4 format skip the '%' - inc ~assignments another one made... +fm1 inc4 format skip the '%' + inc ~assignments another one made... - stz ~suppress assignment is not suppressed - stz ~size default operand size + stz ~suppress assignment is not suppressed + stz ~size default operand size - lda [format] if the char is an '*' then - and #$00FF - cmp #'*' - bne fm2 - inc ~suppress suppress the output - dec ~assignments no assignment made - inc4 format skip the '*' + lda [format] if the char is an '*' then + and #$00FF + cmp #'*' + bne fm2 + inc ~suppress suppress the output + dec ~assignments no assignment made + inc4 format skip the '*' -fm2 jsr GetSize get the field width specifier - sta ~scanWidth +fm2 jsr GetSize get the field width specifier + sta ~scanWidth - lda [format] - and #$00FF - cmp #'l' 'l' specifies long int or double - bne fm2a - inc ~size - inc4 format unless it is 'll' for long long - lda [format] - and #$00FF - cmp #'l' - bne fm6 - bra fm2c -fm2a cmp #'z' 'z' specifies size_t (long int) - beq fm2c - cmp #'t' 't' specifies ptrdiff_t (long int) - beq fm2c - cmp #'j' 'j' specifies intmax_t (long long) - beq fm2b - cmp #'L' 'L' specifies long double - bne fm3 -fm2b inc ~size -fm2c inc ~size - bra fm4 -fm3 cmp #'h' 'h' specifies short int - bne fm5 - inc4 format unless it is 'hh' for char types - lda [format] - and #$00FF - cmp #'h' - bne fm6 - dec ~size -fm4 inc4 format ignore the character + lda [format] + and #$00FF + cmp #'l' 'l' specifies long int or double + bne fm2a + inc ~size + inc4 format unless it is 'll' for long long + lda [format] + and #$00FF + cmp #'l' + bne fm6 + bra fm2c +fm2a cmp #'z' 'z' specifies size_t (long int) + beq fm2c + cmp #'t' 't' specifies ptrdiff_t (long int) + beq fm2c + cmp #'j' 'j' specifies intmax_t (long long) + beq fm2b + cmp #'L' 'L' specifies long double + bne fm3 +fm2b inc ~size +fm2c inc ~size + bra fm4 +fm3 cmp #'h' 'h' specifies short int + bne fm5 + inc4 format unless it is 'hh' for char types + lda [format] + and #$00FF + cmp #'h' + bne fm6 + dec ~size +fm4 inc4 format ignore the character -fm5 lda [format] find the proper format character - and #$00FF -fm6 inc4 format - ldx #fListEnd-fList-4 -fm7 cmp fList,X - beq fm8 - dex - dex - dex - dex - bpl fm7 - brl ps1 none found - continue -fm8 pea ps1-1 push the return address - inx call the subroutine - inx - jmp (fList,X) +fm5 lda [format] find the proper format character + and #$00FF +fm6 inc4 format + ldx #fListEnd-fList-4 +fm7 cmp fList,X + beq fm8 + dex + dex + dex + dex + bpl fm7 + brl ps1 none found - continue +fm8 pea ps1-1 push the return address + inx call the subroutine + inx + jmp (fList,X) ; ; GetSize - get a numeric value ; ; The value is returned in A ; -GetSize stz val assume a value of 0 -gs1 lda [format] while the character stream had digits do - and #$00FF - cmp #'0' - blt gs3 - cmp #'9'+1 - bge gs3 -gs2 and #$000F save the ordinal value - pha - asl val A := val*10 - lda val - asl a - asl a - adc val - adc 1,S A := A+ord([format]) - plx - sta val val := A - inc4 format skip the character - bra gs1 -gs3 lda val - rts +GetSize stz val assume a value of 0 +gs1 lda [format] while the character stream had digits do + and #$00FF + cmp #'0' + blt gs3 + cmp #'9'+1 + bge gs3 +gs2 and #$000F save the ordinal value + pha + asl val A := val*10 + lda val + asl a + asl a + adc val + adc 1,S A := A+ord([format]) + plx + sta val val := A + inc4 format skip the character + bra gs1 +gs3 lda val + rts ; ; Increment format and load the new character ; IncFormat anop - inc4 format - lda [format] - and #$00FF - rts + inc4 format + lda [format] + and #$00FF + rts -val ds 2 value +val ds 2 value ; ; List of format specifiers and the equivalent subroutines ; -fList dc c'd',i1'0',a'~Scan_d' d - dc c'i',i1'0',a'~Scan_i' i - dc c'u',i1'0',a'~Scan_u' u - dc c'o',i1'0',a'~Scan_o' o - dc c'x',i1'0',a'~Scan_x' x - dc c'X',i1'0',a'~Scan_x' X - dc c'p',i1'0',a'~Scan_p' p - dc c'c',i1'0',a'~Scan_c' c - dc c's',i1'0',a'~Scan_s' s - dc c'b',i1'0',a'~Scan_b' b - dc c'P',i1'0',a'~Scan_P' P - dc c'n',i1'0',a'~Scan_n' n - dc c'a',i1'0',a'~Scan_f' a - dc c'A',i1'0',a'~Scan_f' A - dc c'f',i1'0',a'~Scan_f' f - dc c'F',i1'0',a'~Scan_f' F - dc c'e',i1'0',a'~Scan_f' e - dc c'E',i1'0',a'~Scan_f' E - dc c'g',i1'0',a'~Scan_f' g - dc c'G',i1'0',a'~Scan_f' G - dc c'%',i1'0',a'~Scan_percent' % - dc c'[',i1'0',a'~Scan_lbrack' [ +fList dc c'd',i1'0',a'~Scan_d' d + dc c'i',i1'0',a'~Scan_i' i + dc c'u',i1'0',a'~Scan_u' u + dc c'o',i1'0',a'~Scan_o' o + dc c'x',i1'0',a'~Scan_x' x + dc c'X',i1'0',a'~Scan_x' X + dc c'p',i1'0',a'~Scan_p' p + dc c'c',i1'0',a'~Scan_c' c + dc c's',i1'0',a'~Scan_s' s + dc c'b',i1'0',a'~Scan_b' b + dc c'P',i1'0',a'~Scan_P' P + dc c'n',i1'0',a'~Scan_n' n + dc c'a',i1'0',a'~Scan_f' a + dc c'A',i1'0',a'~Scan_f' A + dc c'f',i1'0',a'~Scan_f' f + dc c'F',i1'0',a'~Scan_f' F + dc c'e',i1'0',a'~Scan_f' e + dc c'E',i1'0',a'~Scan_f' E + dc c'g',i1'0',a'~Scan_f' g + dc c'G',i1'0',a'~Scan_f' G + dc c'%',i1'0',a'~Scan_percent' % + dc c'[',i1'0',a'~Scan_lbrack' [ fListEnd anop ; ; Other local data ; -ch ds 2 temp storage - end +ch ds 2 temp storage + end **************************************************************** * @@ -6112,126 +6112,126 @@ ch ds 2 temp storage ; ; ~getchar is a vector to the proper input routine. ; -~getchar dc h'AF',a3'~scanCount' lda >~scanCount - dc h'1A' inc A - dc h'8F',a3'~scanCount' sta >~scanCount - dc h'5C 00 00 00' +~getchar dc h'AF',a3'~scanCount' lda >~scanCount + dc h'1A' inc A + dc h'8F',a3'~scanCount' sta >~scanCount + dc h'5C 00 00 00' ; ; ~putback is a vector to the proper putback routine. ; -~putback dc h'48' pha - dc h'AF',a3'~scanCount' lda >~scanCount - dc h'3A' dec A - dc h'8F',a3'~scanCount' sta >~scanCount - dc h'68' pla - dc h'5C 00 00 00' +~putback dc h'48' pha + dc h'AF',a3'~scanCount' lda >~scanCount + dc h'3A' dec A + dc h'8F',a3'~scanCount' sta >~scanCount + dc h'68' pla + dc h'5C 00 00 00' ; ; ~RemoveWord is a vector to the proper routine to remove a parameter word. ; -~RemoveWord dc h'5C 00 00 00' +~RemoveWord dc h'5C 00 00 00' ; ; global variables ; -~assignments ds 2 # of assignments made -~eofFound ds 2 was EOF found during the scan? -~suppress ds 2 suppress assignment? -~scanCount ds 2 # of characters scanned -~scanError ds 2 set to 1 by scanners if an error occurs -~scanWidth ds 2 max # characters to scan -~size ds 2 size specifier; -1 -> char, 0 -> default, -! 1 -> long, 2 -> long long/long double -~va_arg_ptr ds 4 pointer to next variable argument -~va_list_ptr ds 4 pointer to the va_list array -~isVarArgs ds 2 is this a varargs call (vscanf etc.)? - end +~assignments ds 2 # of assignments made +~eofFound ds 2 was EOF found during the scan? +~suppress ds 2 suppress assignment? +~scanCount ds 2 # of characters scanned +~scanError ds 2 set to 1 by scanners if an error occurs +~scanWidth ds 2 max # characters to scan +~size ds 2 size specifier; -1 -> char, 0 -> default, +! 1 -> long, 2 -> long long/long double +~va_arg_ptr ds 4 pointer to next variable argument +~va_list_ptr ds 4 pointer to the va_list array +~isVarArgs ds 2 is this a varargs call (vscanf etc.)? + end **************************************************************** * * ~SetFilePointer - makes sure nothing is in the input buffer * * Inputs: -* stream - stream to check +* stream - stream to check * **************************************************************** * ~SetFilePointer private - csubroutine (4:stream),0 + csubroutine (4:stream),0 - ldy #FILE_pbk if stream->FILE_pbk != -1 - lda [stream],Y - inc A - ldy #FILE_cnt or stream->FILE_cnt != 0 then - ora [stream],Y - iny - iny - ora [stream],Y - beq lb1 - ph2 #SEEK_CUR fseek(stream, 0L, SEEK_CUR) - ph4 #0 - ph4 stream - jsl fseek + ldy #FILE_pbk if stream->FILE_pbk != -1 + lda [stream],Y + inc A + ldy #FILE_cnt or stream->FILE_cnt != 0 then + ora [stream],Y + iny + iny + ora [stream],Y + beq lb1 + ph2 #SEEK_CUR fseek(stream, 0L, SEEK_CUR) + ph4 #0 + ph4 stream + jsl fseek -lb1 anop - creturn - end +lb1 anop + creturn + end **************************************************************** * * ~VerifyStream - insures that a stream actually exists * * Inputs: -* stream - stream to check +* stream - stream to check * * Outputs: -* C - set for error; clear if the stream exists +* C - set for error; clear if the stream exists * **************************************************************** * ~VerifyStream private -stream equ 9 stream to check -ptr equ 1 stream pointer +stream equ 9 stream to check +ptr equ 1 stream pointer - phb set up the stack frame - phk - plb - ph4 #stdin+4 - tsc - phd - tcd + phb set up the stack frame + phk + plb + ph4 #stdin+4 + tsc + phd + tcd -lb1 lda ptr error if the list is exhausted - ora ptr+2 - beq err - lda ptr OK if the steams match - cmp stream - bne lb2 - lda ptr+2 - cmp stream+2 - beq OK -lb2 ldy #2 next pointer - lda [ptr],Y - tax - lda [ptr] - sta ptr - stx ptr+2 - bra lb1 +lb1 lda ptr error if the list is exhausted + ora ptr+2 + beq err + lda ptr OK if the steams match + cmp stream + bne lb2 + lda ptr+2 + cmp stream+2 + beq OK +lb2 ldy #2 next pointer + lda [ptr],Y + tax + lda [ptr] + sta ptr + stx ptr+2 + bra lb1 -err lda #EIO set the error code - sta >errno - sec return with error - bra OK2 +err lda #EIO set the error code + sta >errno + sec return with error + bra OK2 -OK clc return with no error -OK2 pld - pla - pla - plx - ply - pla - pla - phy - phx - plb - rtl - end +OK clc return with no error +OK2 pld + pla + pla + plx + ply + pla + pla + phy + phx + plb + rtl + end diff --git a/string.asm b/string.asm index d93be8e..4f221a0 100644 --- a/string.asm +++ b/string.asm @@ -1,6 +1,6 @@ - keep obj/string - case on - mcopy string.macros + keep obj/string + case on + mcopy string.macros **************************************************************** * * String - String Processing Library @@ -16,10 +16,10 @@ * **************************************************************** * -String start dummy routine - copy equates.asm +String start dummy routine + copy equates.asm - end + end **************************************************************** * @@ -29,50 +29,50 @@ String start dummy routine * c2pCommon privdata -str1 ds 258 - end +str1 ds 258 + end **************************************************************** * * char *c2pstr(str) -* char *str; +* char *str; * * Inputs: -* str - pointer to the c string to convert +* str - pointer to the c string to convert * * Outputs: -* Returns a pointer to the p string. +* Returns a pointer to the p string. * * Notes: -* Any characters after the 255th are truncated without -* warning. +* Any characters after the 255th are truncated without +* warning. * **************************************************************** * -c2pstr start - using c2pCommon -addr equ 1 +c2pstr start + using c2pCommon +addr equ 1 - csubroutine (4:str),4 - phb - phk - plb + csubroutine (4:str),4 + phb + phk + plb - short I,M - ldy #0 -lb1 lda [str],Y - sta str1+1,Y - beq lb2 - iny - bne lb1 - dey -lb2 sty str1 - long I,M - lla addr,str1 + short I,M + ldy #0 +lb1 lda [str],Y + sta str1+1,Y + beq lb2 + iny + bne lb1 + dey +lb2 sty str1 + long I,M + lla addr,str1 - plb - creturn 4:addr - end + plb + creturn 4:addr + end **************************************************************** * @@ -82,43 +82,43 @@ lb2 sty str1 * strrpbrk to create a set of characters. * * Inputs: -* set - pointer to the set of characters +* set - pointer to the set of characters * * Outputs: -* strset - set of bytes; non-zero for chars in set +* strset - set of bytes; non-zero for chars in set * **************************************************************** * -makeset private -set equ 8 string set +makeset private +set equ 8 string set - lda set if the set is null then - ora set+2 - beq lb3 return + lda set if the set is null then + ora set+2 + beq lb3 return - lda #0 clear the string set - sta >strset - phb - move strset,strset+1,#255 - plb + lda #0 clear the string set + sta >strset + phb + move strset,strset+1,#255 + plb - short I,M while there are chars in the set do - ldy #0 -lb1 lda [set],Y - beq lb2 - tax set the array element for this char - lda #1 - sta >strset,X - iny endwhile - bne lb1 - inc set+1 - bne lb1 - inc set+2 - bra lb1 + short I,M while there are chars in the set do + ldy #0 +lb1 lda [set],Y + beq lb2 + tax set the array element for this char + lda #1 + sta >strset,X + iny endwhile + bne lb1 + inc set+1 + bne lb1 + inc set+2 + bra lb1 -lb2 long I,M -lb3 rts - end +lb2 long I,M +lb3 rts + end **************************************************************** * @@ -127,73 +127,73 @@ lb3 rts * Returns a pointer to the byte in memory * * Inputs: -* ptr - first byte to search -* val - byte to search for -* len - # bytes to search +* ptr - first byte to search +* val - byte to search for +* len - # bytes to search * * Outputs: -* A,X - pointer to the byte; NULL for no match +* A,X - pointer to the byte; NULL for no match * **************************************************************** * -memchr start -ptr equ 4 pointer to the first byte -val equ 8 byte to search for -len equ 10 # bytes to search -rtl equ 1 return address +memchr start +ptr equ 4 pointer to the first byte +val equ 8 byte to search for +len equ 10 # bytes to search +rtl equ 1 return address - tsc establish DP addressing - phd - tcd + tsc establish DP addressing + phd + tcd - short M - ldy #0 - ldx len+2 scan 64K blocks - beq lb1a -lb1 lda [ptr],Y - cmp val - beq lb3 - iny - bne lb1 - inc ptr+2 - dex - bne lb1 + short M + ldy #0 + ldx len+2 scan 64K blocks + beq lb1a +lb1 lda [ptr],Y + cmp val + beq lb3 + iny + bne lb1 + inc ptr+2 + dex + bne lb1 -lb1a ldx len - beq lb2a -lb2 lda [ptr],Y scan the remaining characters - cmp val - beq lb3 - iny - dex - bne lb2 +lb1a ldx len + beq lb2a +lb2 lda [ptr],Y scan the remaining characters + cmp val + beq lb3 + iny + dex + bne lb2 -lb2a long M no match found -> return NULL - ldx #0 - txy - bra lb4 +lb2a long M no match found -> return NULL + ldx #0 + txy + bra lb4 -lb3 long M compute the length - tya - clc - adc ptr - tay - ldx ptr+2 - bcc lb4 - inx +lb3 long M compute the length + tya + clc + adc ptr + tay + ldx ptr+2 + bcc lb4 + inx -lb4 lda rtl+1 remove parameters from the stack - sta len+2 - lda rtl - sta len+1 - pld - tsc - clc - adc #10 - tcs - tya return the pointer in X-A - rtl - end +lb4 lda rtl+1 remove parameters from the stack + sta len+2 + lda rtl + sta len+1 + pld + tsc + clc + adc #10 + tcs + tya return the pointer in X-A + rtl + end **************************************************************** * @@ -203,69 +203,69 @@ lb4 lda rtl+1 remove parameters from the stack * equal, return 0; otherwise, return 1. * * Inputs: -* p1 - string to concatenate to -* p2 - string to concatenate +* p1 - string to concatenate to +* p2 - string to concatenate * * Outputs: -* A - result +* A - result * **************************************************************** * -memcmp start -p1 equ 4 pointer to memory area 1 -p2 equ 8 pointer to memory area 2 -len equ 12 length to compare -rtl equ 1 return address +memcmp start +p1 equ 4 pointer to memory area 1 +p2 equ 8 pointer to memory area 2 +len equ 12 length to compare +rtl equ 1 return address - tsc establish DP addressing - phd - tcd + tsc establish DP addressing + phd + tcd - short M - ldy #0 scan 64K chunks - ldx len+2 - beq lb2 -lb1 lda [p1],Y - cmp [p2],Y - bne lb4 - iny - bne lb1 - inc p1+2 - inc p2+2 - dex - bne lb1 + short M + ldy #0 scan 64K chunks + ldx len+2 + beq lb2 +lb1 lda [p1],Y + cmp [p2],Y + bne lb4 + iny + bne lb1 + inc p1+2 + inc p2+2 + dex + bne lb1 -lb2 ldx len - beq lb5 -lb3 lda [p1],Y scan until the end of memory is reached - cmp [p2],Y or a difference is found - bne lb4 - iny - dex - bne lb3 +lb2 ldx len + beq lb5 +lb3 lda [p1],Y scan until the end of memory is reached + cmp [p2],Y or a difference is found + bne lb4 + iny + dex + bne lb3 - ldx #0 memory matches - bra lb5 + ldx #0 memory matches + bra lb5 -lb4 blt less memory differs - set the result - ldx #1 - bra lb5 +lb4 blt less memory differs - set the result + ldx #1 + bra lb5 -less ldx #-1 +less ldx #-1 -lb5 long M - lda rtl remove the parameters from the stack - sta len+1 - lda rtl+1 - sta len+2 - pld - tsc - clc - adc #12 - tcs - txa return the result - rtl - end +lb5 long M + lda rtl remove the parameters from the stack + sta len+1 + lda rtl+1 + sta len+2 + pld + tsc + clc + adc #12 + tcs + txa return the result + rtl + end **************************************************************** * @@ -274,80 +274,80 @@ lb5 long M * Copy len bytes from p1 to p2. * * Inputs: -* p1 - destination pointer -* p2 - source pointer -* len - # bytes to copy +* p1 - destination pointer +* p2 - source pointer +* len - # bytes to copy * * Outputs: -* X-A - p1 +* X-A - p1 * * Notes: The memory areas should not overlap * **************************************************************** * -memcpy start -p1 equ 4 destination pointer -p2 equ 8 source pointer -len equ 12 length to compare -rtl equ 1 return address +memcpy start +p1 equ 4 destination pointer +p2 equ 8 source pointer +len equ 12 length to compare +rtl equ 1 return address - tsc establish DP addressing - phd - tcd + tsc establish DP addressing + phd + tcd - ph4 p1 save the dest pointer + ph4 p1 save the dest pointer - lda len if there are an odd # of bytes then - lsr A - bcc lb1 - short M move 1 byte now - lda [p2] - sta [p1] - long M - dec len - inc4 p1 - inc4 p2 -lb1 anop endif + lda len if there are an odd # of bytes then + lsr A + bcc lb1 + short M move 1 byte now + lda [p2] + sta [p1] + long M + dec len + inc4 p1 + inc4 p2 +lb1 anop endif - ldx len+2 move full banks of memory - beq lb1b - ldy #0 -lb1a lda [p2],Y - sta [p1],Y - dey - dey - bne lb1a - inc p2+2 - inc p1+2 - dex - bne lb1a -lb1b ldy len move len bytes - beq lb4 - dey - dey - beq lb3 -lb2 lda [p2],Y - sta [p1],Y - dey - dey - bne lb2 -lb3 lda [p2] - sta [p1] + ldx len+2 move full banks of memory + beq lb1b + ldy #0 +lb1a lda [p2],Y + sta [p1],Y + dey + dey + bne lb1a + inc p2+2 + inc p1+2 + dex + bne lb1a +lb1b ldy len move len bytes + beq lb4 + dey + dey + beq lb3 +lb2 lda [p2],Y + sta [p1],Y + dey + dey + bne lb2 +lb3 lda [p2] + sta [p1] -lb4 ply get the original source pointer - plx - lda rtl remove the parameters from the stack - sta len+1 - lda rtl+1 - sta len+2 - pld - tsc - clc - adc #12 - tcs - tya return the result - rtl - end +lb4 ply get the original source pointer + plx + lda rtl remove the parameters from the stack + sta len+1 + lda rtl+1 + sta len+2 + pld + tsc + clc + adc #12 + tcs + tya return the result + rtl + end **************************************************************** * @@ -356,101 +356,101 @@ lb4 ply get the original source pointer * Move len bytes from p1 to p2. * * Inputs: -* p1 - destination pointer -* p2 - source pointer -* len - # bytes to copy +* p1 - destination pointer +* p2 - source pointer +* len - # bytes to copy * * Outputs: -* X-A - p2 +* X-A - p2 * * Notes: The memory areas may overlap; the move will still work * **************************************************************** * -memmove start -p1 equ 4 destination pointer -p2 equ 8 source pointer -len equ 12 length to compare -rtl equ 1 return address +memmove start +p1 equ 4 destination pointer +p2 equ 8 source pointer +len equ 12 length to compare +rtl equ 1 return address - tsc establish DP addressing - phd - tcd + tsc establish DP addressing + phd + tcd - ph4 p1 save the dest pointer + ph4 p1 save the dest pointer - lda p1+2 if p1 < p2 then - cmp p2+2 - bne lb1 - lda p1 - cmp p2 -lb1 bge lb5 + lda p1+2 if p1 < p2 then + cmp p2+2 + bne lb1 + lda p1 + cmp p2 +lb1 bge lb5 - short M move len bytes, starting with the 1st - ldy #0 - ldx len+2 move 64K chunks - beq lb3 -lb2 lda [p2],Y - sta [p1],Y - iny - bne lb2 - inc p2+2 - inc p1+2 - dex - bne lb2 -lb3 ldx len skip if there are no more bytes to - beq lb11 move -lb4 lda [p2],Y move the remaining bytes - sta [p1],Y - iny - dex - bne lb4 - bra lb11 else + short M move len bytes, starting with the 1st + ldy #0 + ldx len+2 move 64K chunks + beq lb3 +lb2 lda [p2],Y + sta [p1],Y + iny + bne lb2 + inc p2+2 + inc p1+2 + dex + bne lb2 +lb3 ldx len skip if there are no more bytes to + beq lb11 move +lb4 lda [p2],Y move the remaining bytes + sta [p1],Y + iny + dex + bne lb4 + bra lb11 else - longa on + longa on -lb5 add2 p1+2,len+2 move len bytes, starting from the end - add2 p2+2,len+2 - short M - ldy len branch if there are no individual - beq lb8 bytes to move - dey move the individual bytes - beq lb7 -lb6 lda [p2],Y - sta [p1],Y - dey - bne lb6 -lb7 lda [p2] - sta [p1] -lb8 ldx len+2 branch if there are no 64K chunks to - beq lb11 move -lb9 dec p1+2 move the 64K chunks - dec p2+2 - ldy #$FFFF -lb10 lda [p2],Y - sta [p1],Y - dey - bne lb10 - lda [p2] - sta [p1] - dex - bne lb9 +lb5 add2 p1+2,len+2 move len bytes, starting from the end + add2 p2+2,len+2 + short M + ldy len branch if there are no individual + beq lb8 bytes to move + dey move the individual bytes + beq lb7 +lb6 lda [p2],Y + sta [p1],Y + dey + bne lb6 +lb7 lda [p2] + sta [p1] +lb8 ldx len+2 branch if there are no 64K chunks to + beq lb11 move +lb9 dec p1+2 move the 64K chunks + dec p2+2 + ldy #$FFFF +lb10 lda [p2],Y + sta [p1],Y + dey + bne lb10 + lda [p2] + sta [p1] + dex + bne lb9 -lb11 long M - ply get the original source pointer - plx - lda rtl remove the parameters from the stack - sta len+1 - lda rtl+1 - sta len+2 - pld - tsc - clc - adc #12 - tcs - tya return the result - rtl - end +lb11 long M + ply get the original source pointer + plx + lda rtl remove the parameters from the stack + sta len+1 + lda rtl+1 + sta len+2 + pld + tsc + clc + adc #12 + tcs + tya return the result + rtl + end **************************************************************** * @@ -459,119 +459,119 @@ lb11 long M * Set len bytes, starting at p, to val. * * Inputs: -* p - destination pointer -* val - value (byte!) to set memory to -* len - # bytes to set +* p - destination pointer +* val - value (byte!) to set memory to +* len - # bytes to set * * Outputs: -* X-A - p +* X-A - p * * Notes: The memory areas should not overlap * **************************************************************** * -memset start -p equ 4 destination pointer -val equ 8 source pointer -len equ 10 length to compare -rtl equ 1 return address +memset start +p equ 4 destination pointer +val equ 8 source pointer +len equ 10 length to compare +rtl equ 1 return address - tsc establish DP addressing - phd - tcd + tsc establish DP addressing + phd + tcd - ph4 p save the pointer + ph4 p save the pointer - short M - lda val form a 2 byte value - sta val+1 + short M + lda val form a 2 byte value + sta val+1 - lda len if there are an odd # of bytes then - lsr A - bcc lb1 - lda val set 1 byte now - sta [p] - long M - dec len - inc4 p -lb1 long M endif + lda len if there are an odd # of bytes then + lsr A + bcc lb1 + lda val set 1 byte now + sta [p] + long M + dec len + inc4 p +lb1 long M endif - lda val set len bytes - ldx len+2 set full banks - beq lb1b - ldy #0 -lb1a sta [p],Y - dey - dey - bne lb1a - inc p+2 - dex - bne lb1a -lb1b ldy len set a partial bank - beq lb4 - dey - dey - beq lb3 -lb2 sta [p],Y - dey - dey - bne lb2 -lb3 sta [p] + lda val set len bytes + ldx len+2 set full banks + beq lb1b + ldy #0 +lb1a sta [p],Y + dey + dey + bne lb1a + inc p+2 + dex + bne lb1a +lb1b ldy len set a partial bank + beq lb4 + dey + dey + beq lb3 +lb2 sta [p],Y + dey + dey + bne lb2 +lb3 sta [p] -lb4 ply get the original source pointer - plx - lda rtl remove the parameters from the stack - sta len+1 - lda rtl+1 - sta len+2 - pld - tsc - clc - adc #10 - tcs - tya return the result - rtl - end +lb4 ply get the original source pointer + plx + lda rtl remove the parameters from the stack + sta len+1 + lda rtl+1 + sta len+2 + pld + tsc + clc + adc #10 + tcs + tya return the result + rtl + end **************************************************************** * * char *p2cstr(str) -* char *str; +* char *str; * * Inputs: -* str - pointer to the p string to convert +* str - pointer to the p string to convert * * Outputs: -* Returns a pointer to the c string. +* Returns a pointer to the c string. * **************************************************************** * -p2cstr start - using c2pCommon -addr equ 1 +p2cstr start + using c2pCommon +addr equ 1 - csubroutine (4:str),4 - phb - phk - plb + csubroutine (4:str),4 + phb + phk + plb - short I,M - lda [str] - tay - lda #0 - sta str1,Y - tyx - beq lb2 -lb1 lda [str],Y - sta str1-1,Y - dey - bne lb1 -lb2 long I,M - lla addr,str1 + short I,M + lda [str] + tay + lda #0 + sta str1,Y + tyx + beq lb2 +lb1 lda [str],Y + sta str1-1,Y + dey + bne lb1 +lb2 long I,M + lla addr,str1 - plb - creturn 4:addr - end + plb + creturn 4:addr + end **************************************************************** * @@ -581,67 +581,67 @@ lb2 long I,M * checking for length is performed. * * Inputs: -* s1 - string to concatenate to -* s2 - string to concatenate +* s1 - string to concatenate to +* s2 - string to concatenate * * Outputs: -* X-A - pointer to the result (s1) +* X-A - pointer to the result (s1) * **************************************************************** * -strcat start -s1 equ 8 pointer to string 1 -s2 equ 12 pointer to string 2 -rtl equ 5 return address -rval equ 1 string value to return +strcat start +s1 equ 8 pointer to string 1 +s2 equ 12 pointer to string 2 +rtl equ 5 return address +rval equ 1 string value to return - lda 6,S save the starting value of s1 - pha - lda 6,S - pha - tsc establish DP addressing - phd - tcd + lda 6,S save the starting value of s1 + pha + lda 6,S + pha + tsc establish DP addressing + phd + tcd - ldy #0 advance s1 to point to the terminating - short M null -lb1 lda [s1],Y - beq lb2 - iny - bne lb1 - inc s1+2 - bra lb1 -lb2 long M - tya - clc - adc s1 - sta s1 - short M copy characters 'til the null is found - ldy #0 -lb3 lda [s2],Y - sta [s1],Y - beq lb4 - iny - bne lb3 - inc s1+2 - inc s2+2 - bra lb3 + ldy #0 advance s1 to point to the terminating + short M null +lb1 lda [s1],Y + beq lb2 + iny + bne lb1 + inc s1+2 + bra lb1 +lb2 long M + tya + clc + adc s1 + sta s1 + short M copy characters 'til the null is found + ldy #0 +lb3 lda [s2],Y + sta [s1],Y + beq lb4 + iny + bne lb3 + inc s1+2 + inc s2+2 + bra lb3 -lb4 long M return to the caller - lda rtl - sta s2+1 - lda rtl+1 - sta s2+2 - ldx rval+2 - ldy rval - pld - tsc - clc - adc #12 - tcs - tya - rtl - end +lb4 long M return to the caller + lda rtl + sta s2+1 + lda rtl+1 + sta s2+2 + ldx rval+2 + ldy rval + pld + tsc + clc + adc #12 + tcs + tya + rtl + end **************************************************************** * @@ -650,58 +650,58 @@ lb4 long M return to the caller * Returns a pointer to the character in the string * * Inputs: -* str - string to search -* c - character to search for +* str - string to search +* c - character to search for * * Outputs: -* A,X - pointer to the character; NULL for no match +* A,X - pointer to the character; NULL for no match * **************************************************************** * -strchr start -str equ 4 pointer to the string -c equ 8 character +strchr start +str equ 4 pointer to the string +c equ 8 character - tsc establish DP addressing - phd - tcd + tsc establish DP addressing + phd + tcd - short M advance s1 to point to the char - ldy #0 -lb1 lda [str],Y - cmp c - beq lb3 - cmp #0 - beq lb2 - iny - bne lb1 - inc str+2 - bra lb1 + short M advance s1 to point to the char + ldy #0 +lb1 lda [str],Y + cmp c + beq lb3 + cmp #0 + beq lb2 + iny + bne lb1 + inc str+2 + bra lb1 -lb2 long M no match found -> return NULL - ldy #0 - tyx - bra lb4 +lb2 long M no match found -> return NULL + ldy #0 + tyx + bra lb4 -lb3 long M compute the length - tya - clc - adc str - tay - ldx str+2 - bcc lb4 - inx +lb3 long M compute the length + tya + clc + adc str + tay + ldx str+2 + bcc lb4 + inx -lb4 pld remove parameters from the stack - lda 2,S - sta 8,S - pla - sta 5,S - pla - pla - tya return the pointer in X-A - rtl - end +lb4 pld remove parameters from the stack + lda 2,S + sta 8,S + pla + sta 5,S + pla + pla + tya return the pointer in X-A + rtl + end **************************************************************** * @@ -711,57 +711,57 @@ lb4 pld remove parameters from the stack * equal, return 0; otherwise, return 1. * * Inputs: -* s1 - first string ptr -* s2 - second string ptr +* s1 - first string ptr +* s2 - second string ptr * * Outputs: -* A - result +* A - result * **************************************************************** * -strcmp start -s1 equ 4 pointer to string 1 -s2 equ 8 pointer to string 2 -rtl equ 1 return address +strcmp start +s1 equ 4 pointer to string 1 +s2 equ 8 pointer to string 2 +rtl equ 1 return address - tsc establish DP addressing - phd - tcd + tsc establish DP addressing + phd + tcd - ldy #0 scan until the end of string is reached - short M or a difference is found -lb1 lda [s1],Y - beq lb2 - cmp [s2],Y - bne lb3 - iny - bne lb1 - inc s1+2 - inc s2+2 - bra lb1 + ldy #0 scan until the end of string is reached + short M or a difference is found +lb1 lda [s1],Y + beq lb2 + cmp [s2],Y + bne lb3 + iny + bne lb1 + inc s1+2 + inc s2+2 + bra lb1 -lb2 ldx #0 s1 is finished. If s2 is, too, the - lda [s2],Y strings are equal. - beq lb4 -less ldx #-1 It wasn't, so *s1 < *s2 - bra lb4 +lb2 ldx #0 s1 is finished. If s2 is, too, the + lda [s2],Y strings are equal. + beq lb4 +less ldx #-1 It wasn't, so *s1 < *s2 + bra lb4 -lb3 blt less the strings differ - set the result - ldx #1 +lb3 blt less the strings differ - set the result + ldx #1 -lb4 long M - lda rtl remove the parameters from the stack - sta s2+1 - lda rtl+1 - sta s2+2 - pld - tsc - clc - adc #8 - tcs - txa return the result - rtl - end +lb4 long M + lda rtl remove the parameters from the stack + sta s2+1 + lda rtl+1 + sta s2+2 + pld + tsc + clc + adc #8 + tcs + txa return the result + rtl + end **************************************************************** * @@ -772,21 +772,21 @@ lb4 long M * equal, return 0; otherwise, return a positive number. * * Inputs: -* s1 - first string ptr -* s2 - second string ptr +* s1 - first string ptr +* s2 - second string ptr * * Outputs: -* A - result +* A - result * * Notes: -* The current implementation assumes all supported locales -* have the same collation order as given by strcmp. +* The current implementation assumes all supported locales +* have the same collation order as given by strcmp. * **************************************************************** * -strcoll start - jml strcmp - end +strcoll start + jml strcmp + end **************************************************************** * @@ -795,144 +795,144 @@ strcoll start * Copy string *s2 to string *s1. Return a pointer to s1. * * Inputs: -* s1 - string to copy to -* s2 - string to copy +* s1 - string to copy to +* s2 - string to copy * * Outputs: -* X-A - pointer to the result (s1) +* X-A - pointer to the result (s1) * **************************************************************** * -strcpy start -s1 equ 8 pointer to string 1 -s2 equ 12 pointer to string 2 -rtl equ 5 return address -rval equ 1 string value to return +strcpy start +s1 equ 8 pointer to string 1 +s2 equ 12 pointer to string 2 +rtl equ 5 return address +rval equ 1 string value to return - lda 6,S save the starting value of s1 - pha - lda 6,S - pha - tsc establish DP addressing - phd - tcd + lda 6,S save the starting value of s1 + pha + lda 6,S + pha + tsc establish DP addressing + phd + tcd - short M copy characters 'til the null is found - ldy #0 -lb1 lda [s2],Y - sta [s1],Y - beq lb2 - iny - bne lb1 - inc s1+2 - inc s2+2 - bra lb1 + short M copy characters 'til the null is found + ldy #0 +lb1 lda [s2],Y + sta [s1],Y + beq lb2 + iny + bne lb1 + inc s1+2 + inc s2+2 + bra lb1 -lb2 long M return to the caller - lda rtl - sta s2+1 - lda rtl+1 - sta s2+2 - ldx rval+2 - ldy rval - pld - tsc - clc - adc #12 - tcs - tya - rtl - end +lb2 long M return to the caller + lda rtl + sta s2+1 + lda rtl+1 + sta s2+2 + ldx rval+2 + ldy rval + pld + tsc + clc + adc #12 + tcs + tya + rtl + end **************************************************************** * * strcspn - find the first char in s in set * * Inputs: -* s - pointer to the string to scan -* set - set of characters to check against +* s - pointer to the string to scan +* set - set of characters to check against * * Outputs: -* A - disp to first char in s +* A - disp to first char in s * **************************************************************** * -strcspn start -s equ 4 string to scan -set equ 8 set of characters -rtl equ 1 return address +strcspn start +s equ 4 string to scan +set equ 8 set of characters +rtl equ 1 return address - tsc establish DP addressing - phd - tcd + tsc establish DP addressing + phd + tcd - jsr makeset form the set of characters + jsr makeset form the set of characters - stz set set initial displacement - stz set+2 - short I,M scan for a matching char - ldy #0 -lb1 lda [s],Y - beq lb2 - tax - lda >strset,X - bne lb2 - iny - bne lb1 - long M - inc s+1 - inc set+1 - short M - bra lb1 -lb2 sty set set the disp past the current disp + stz set set initial displacement + stz set+2 + short I,M scan for a matching char + ldy #0 +lb1 lda [s],Y + beq lb2 + tax + lda >strset,X + bne lb2 + iny + bne lb1 + long M + inc s+1 + inc set+1 + short M + bra lb1 +lb2 sty set set the disp past the current disp - long I,M - ldx set+2 get the return value - ldy set - lda rtl+1 remove the parameters - sta set+2 - lda rtl - sta set+1 - pld - tsc - clc - adc #8 - tcs - tya return the disp - rtl - end + long I,M + ldx set+2 get the return value + ldy set + lda rtl+1 remove the parameters + sta set+2 + lda rtl + sta set+1 + pld + tsc + clc + adc #8 + tcs + tya return the disp + rtl + end **************************************************************** * * strerror - return the addr of an error message * * Inputs: -* err - error number to return the error for +* err - error number to return the error for * **************************************************************** * strerror start -maxErr equ EILSEQ max error in sys_errlist +maxErr equ EILSEQ max error in sys_errlist - phb get the error number - plx - ply - pla - phy - phx - phk use local data bank - plb - cmp #maxErr+1 - blt lb1 - lda #0 -lb1 asl A compute the index - asl A - tay - ldx sys_errlist+2,Y load the address - lda sys_errlist,Y - plb restore caller's data bank - rtl - end + phb get the error number + plx + ply + pla + phy + phx + phk use local data bank + plb + cmp #maxErr+1 + blt lb1 + lda #0 +lb1 asl A compute the index + asl A + tay + ldx sys_errlist+2,Y load the address + lda sys_errlist,Y + plb restore caller's data bank + rtl + end **************************************************************** * @@ -941,41 +941,41 @@ lb1 asl A compute the index * Returns the length of the string. * * Inputs: -* str - string to find the length of +* str - string to find the length of * * Outputs: -* X-A - length of the string +* X-A - length of the string * **************************************************************** * -strlen start -str equ 4 pointer to the string +strlen start +str equ 4 pointer to the string - tsc establish DP addressing - phd - tcd + tsc establish DP addressing + phd + tcd - ldy #0 advance s1 to point to the terminating - ldx #0 null - short M -lb1 lda [str],Y - beq lb2 - iny - bne lb1 - inx - inc str+2 - bra lb1 + ldy #0 advance s1 to point to the terminating + ldx #0 null + short M +lb1 lda [str],Y + beq lb2 + iny + bne lb1 + inx + inc str+2 + bra lb1 -lb2 long M - pld remove str from the stack - lda 2,S - sta 6,S - pla - sta 3,S - pla - tya return the length - rtl - end +lb2 long M + pld remove str from the stack + lda 2,S + sta 6,S + pla + sta 3,S + pla + tya return the length + rtl + end **************************************************************** * @@ -985,56 +985,56 @@ lb2 long M * checking for length is performed. * * Inputs: -* s1 - string to concatenate to -* s2 - string to concatenate -* n - max # chars to copy +* s1 - string to concatenate to +* s2 - string to concatenate +* n - max # chars to copy * * Outputs: -* X-A - pointer to the result (s1) +* X-A - pointer to the result (s1) * **************************************************************** * -strncat start -rval equ 1 string value to return +strncat start +rval equ 1 string value to return - csubroutine (4:s1,4:s2,4:n),4 + csubroutine (4:s1,4:s2,4:n),4 - move4 s1,rval save the address to return - ldy #0 advance s1 to point to the terminating - short M null -lb1 lda [s1],Y - beq lb2 - iny - bne lb1 - inc s1+2 - bra lb1 -lb2 long M - tya - clc - adc s1 - sta s1 - short M copy characters 'til the null is found - ldy #0 - ldx n - beq lb4 - bmi lb4 -lb3 lda [s2],Y - sta [s1],Y - beq lb4 - iny - dex - bne lb3 - lda n+2 - beq lb4 - dec n+2 - bra lb3 + move4 s1,rval save the address to return + ldy #0 advance s1 to point to the terminating + short M null +lb1 lda [s1],Y + beq lb2 + iny + bne lb1 + inc s1+2 + bra lb1 +lb2 long M + tya + clc + adc s1 + sta s1 + short M copy characters 'til the null is found + ldy #0 + ldx n + beq lb4 + bmi lb4 +lb3 lda [s2],Y + sta [s1],Y + beq lb4 + iny + dex + bne lb3 + lda n+2 + beq lb4 + dec n+2 + bra lb3 -lb4 lda #0 write the terminating null - sta [s1],Y - long M return to the caller +lb4 lda #0 write the terminating null + sta [s1],Y + long M return to the caller - creturn 4:rval - end + creturn 4:rval + end **************************************************************** * @@ -1044,59 +1044,59 @@ lb4 lda #0 write the terminating null * equal, return 0; otherwise, return 1. * * Inputs: -* s1 - string to concatenate to -* s2 - string to concatenate -* n - max length of the strings +* s1 - string to concatenate to +* s2 - string to concatenate +* n - max length of the strings * * Outputs: -* A - result +* A - result * **************************************************************** * -strncmp start -flag equ 1 return flag +strncmp start +flag equ 1 return flag - csubroutine (4:s1,4:s2,4:n),2 + csubroutine (4:s1,4:s2,4:n),2 - ldy #0 scan until the end of string is reached - ldx n+2 or a difference is found - bmi equal - bne lb0 - ldx n - beq equal -lb0 ldx n - short M -lb1 lda [s1],Y - beq lb2 - cmp [s2],Y - bne lb3 - dex - bne lb1a - lda n+2 - beq equal - dec n+2 -lb1a iny - bne lb1 - inc s1+2 - inc s2+2 - bra lb1 + ldy #0 scan until the end of string is reached + ldx n+2 or a difference is found + bmi equal + bne lb0 + ldx n + beq equal +lb0 ldx n + short M +lb1 lda [s1],Y + beq lb2 + cmp [s2],Y + bne lb3 + dex + bne lb1a + lda n+2 + beq equal + dec n+2 +lb1a iny + bne lb1 + inc s1+2 + inc s2+2 + bra lb1 -lb2 ldx #0 s1 is finished. If s2 is, too, the - lda [s2],Y strings are equal. - beq lb4 -less ldx #-1 It wasn't, so *s1 < *s2 - bra lb4 +lb2 ldx #0 s1 is finished. If s2 is, too, the + lda [s2],Y strings are equal. + beq lb4 +less ldx #-1 It wasn't, so *s1 < *s2 + bra lb4 -equal ldx #0 - bra lb4 +equal ldx #0 + bra lb4 -lb3 blt less the strings differ - set the result - ldx #1 +lb3 blt less the strings differ - set the result + ldx #1 -lb4 stx flag return the result - long M - creturn 2:flag - end +lb4 stx flag return the result + long M + creturn 2:flag + end **************************************************************** * @@ -1105,117 +1105,117 @@ lb4 stx flag return the result * Copy string *s2 to string *s1. Return a pointer to s1. * * Inputs: -* s1 - string to copy to -* s2 - string to copy -* n - max length of the string +* s1 - string to copy to +* s2 - string to copy +* n - max length of the string * * Outputs: -* X-A - pointer to the result (s1) +* X-A - pointer to the result (s1) * **************************************************************** * -strncpy start -rval equ 1 string value to return +strncpy start +rval equ 1 string value to return - csubroutine (4:s1,4:s2,4:n),4 + csubroutine (4:s1,4:s2,4:n),4 - move4 s1,rval save the address to return - short M copy characters 'til the null is found - ldy #0 or we have copied n characters - ldx n+2 - bmi lb4 - bne lb0 - ldx n - beq lb4 -lb0 ldx n -lb1 lda [s2],Y - sta [s1],Y - beq lb2 - dex - bne lb1a - lda n+2 - beq lb4 - dec n+2 -lb1a iny - bne lb1 - inc s1+2 - inc s2+2 - bra lb1 + move4 s1,rval save the address to return + short M copy characters 'til the null is found + ldy #0 or we have copied n characters + ldx n+2 + bmi lb4 + bne lb0 + ldx n + beq lb4 +lb0 ldx n +lb1 lda [s2],Y + sta [s1],Y + beq lb2 + dex + bne lb1a + lda n+2 + beq lb4 + dec n+2 +lb1a iny + bne lb1 + inc s1+2 + inc s2+2 + bra lb1 -lb3 iny null terminate the string - sta [s1],Y -lb2 dex - bne lb3 +lb3 iny null terminate the string + sta [s1],Y +lb2 dex + bne lb3 -lb4 long M return to the caller - creturn 4:rval - end +lb4 long M return to the caller + creturn 4:rval + end **************************************************************** * * strpbrk - find the first char in s in set * * Inputs: -* s - pointer to the string to scan -* set - set of characters to check against +* s - pointer to the string to scan +* set - set of characters to check against * * Outputs: -* X-A - pointer to first char in s; NULL if none found +* X-A - pointer to first char in s; NULL if none found * **************************************************************** * -strpbrk start -s equ 4 string to scan -set equ 8 set of characters -rtl equ 1 return address +strpbrk start +s equ 4 string to scan +set equ 8 set of characters +rtl equ 1 return address - tsc establish DP addressing - phd - tcd + tsc establish DP addressing + phd + tcd - jsr makeset form the set of characters + jsr makeset form the set of characters - short I,M scan for a matching char - ldy #0 -lb1 lda [s],Y - beq lb2 - tax - lda >strset,X - bne lb3 - iny - bne lb1 - long M - inc s+1 - short M - bra lb1 + short I,M scan for a matching char + ldy #0 +lb1 lda [s],Y + beq lb2 + tax + lda >strset,X + bne lb3 + iny + bne lb1 + long M + inc s+1 + short M + bra lb1 -lb2 long I,M no match found -> return NULL - ldx #0 - txy - bra lb4 +lb2 long I,M no match found -> return NULL + ldx #0 + txy + bra lb4 -lb3 long I,M increment s by Y and load the value - tya - and #$00FF - clc - adc s - tay - lda s+2 - adc #0 - tax +lb3 long I,M increment s by Y and load the value + tya + and #$00FF + clc + adc s + tay + lda s+2 + adc #0 + tax -lb4 lda rtl+1 remove the parameters - sta set+2 - lda rtl - sta set+1 - pld - tsc - clc - adc #8 - tcs - tya return the ptr - rtl - end +lb4 lda rtl+1 remove the parameters + sta set+2 + lda rtl + sta set+1 + pld + tsc + clc + adc #8 + tcs + tya return the ptr + rtl + end **************************************************************** * @@ -1224,45 +1224,45 @@ lb4 lda rtl+1 remove the parameters * Returns the position of a character in a string * * Inputs: -* str - string to search -* c - character to search for +* str - string to search +* c - character to search for * * Outputs: -* A - position of the character; -1 of none +* A - position of the character; -1 of none * **************************************************************** * -strpos start -str equ 4 pointer to the string -c equ 8 character +strpos start +str equ 4 pointer to the string +c equ 8 character - tsc establish DP addressing - phd - tcd + tsc establish DP addressing + phd + tcd - ldy #0 advance s1 to point to the char - short M -lb1 lda [str],Y - cmp c - beq lb3 - cmp #0 - beq lb2 - iny - bpl lb1 + ldy #0 advance s1 to point to the char + short M +lb1 lda [str],Y + cmp c + beq lb3 + cmp #0 + beq lb2 + iny + bpl lb1 -lb2 ldy #-1 no match found -> return -1 +lb2 ldy #-1 no match found -> return -1 -lb3 long M - pld remove parameters from the stack - lda 2,S - sta 8,S - pla - sta 5,S - pla - pla - tya return the result - rtl - end +lb3 long M + pld remove parameters from the stack + lda 2,S + sta 8,S + pla + sta 5,S + pla + pla + tya return the result + rtl + end **************************************************************** * @@ -1271,62 +1271,62 @@ lb3 long M * Returns a pointer to the last occurrence of the character * * Inputs: -* str - string to search -* c - character to search for +* str - string to search +* c - character to search for * * Outputs: -* A,X - pointer to the character; NULL for no match +* A,X - pointer to the character; NULL for no match * **************************************************************** * -strrchr start -str equ 8 pointer to the string -c equ 12 character -ptr equ 1 result pointer +strrchr start +str equ 8 pointer to the string +c equ 12 character +ptr equ 1 result pointer - pea 0 initialize the result - pea 0 - tsc establish DP addressing - phd - tcd + pea 0 initialize the result + pea 0 + tsc establish DP addressing + phd + tcd - short M advance s1 to point to the char - ldy #0 -lb1 lda [str],Y - cmp c - beq lb3 - cmp #0 - beq lb4 -lb2 iny - bne lb1 - inc str+2 - bra lb1 + short M advance s1 to point to the char + ldy #0 +lb1 lda [str],Y + cmp c + beq lb3 + cmp #0 + beq lb4 +lb2 iny + bne lb1 + inc str+2 + bra lb1 -lb3 long M compute the pointer - tya - clc - adc str - sta ptr - lda str+2 - adc #0 - sta ptr+2 - sep #$20 - lda [str],Y - bne lb2 +lb3 long M compute the pointer + tya + clc + adc str + sta ptr + lda str+2 + adc #0 + sta ptr+2 + sep #$20 + lda [str],Y + bne lb2 -lb4 long M - pld rest DP - ply remove the return value - plx - lda 2,S remove the parameters - sta 8,S - pla - sta 5,S - pla - pla - tya return the pointer in X-A - rtl - end +lb4 long M + pld rest DP + ply remove the return value + plx + lda 2,S remove the parameters + sta 8,S + pla + sta 5,S + pla + pla + tya return the pointer in X-A + rtl + end **************************************************************** * @@ -1335,113 +1335,113 @@ lb4 long M * Returns the position of the last occurrence of the character * * Inputs: -* str - string to search -* c - character to search for +* str - string to search +* c - character to search for * * Outputs: -* A - position of the character; -1 of none +* A - position of the character; -1 of none * **************************************************************** * -strrpos start -str equ 4 pointer to the string -c equ 8 character +strrpos start +str equ 4 pointer to the string +c equ 8 character - tsc establish DP addressing - phd - tcd + tsc establish DP addressing + phd + tcd - ldx #-1 assume we won't find it - ldy #0 advance s1 to point to the char - short M -lb1 lda [str],Y - cmp c - bne lb2 - tyx -lb2 cmp #0 - beq lb3 - iny - bpl lb1 + ldx #-1 assume we won't find it + ldy #0 advance s1 to point to the char + short M +lb1 lda [str],Y + cmp c + bne lb2 + tyx +lb2 cmp #0 + beq lb3 + iny + bpl lb1 -lb3 long M - pld remove parameters from the stack - lda 2,S - sta 8,S - pla - sta 5,S - pla - pla - txa return the result - rtl - end +lb3 long M + pld remove parameters from the stack + lda 2,S + sta 8,S + pla + sta 5,S + pla + pla + txa return the result + rtl + end **************************************************************** * * strrpbrk - find the first char in s in set * * Inputs: -* s - pointer to the string to scan -* set - set of characters to check against +* s - pointer to the string to scan +* set - set of characters to check against * * Outputs: -* X-A - pointer to first char in s; NULL if none found +* X-A - pointer to first char in s; NULL if none found * **************************************************************** * strrpbrk start -s equ 4 string to scan -set equ 8 set of characters -rtl equ 1 return address +s equ 4 string to scan +set equ 8 set of characters +rtl equ 1 return address - tsc establish DP addressing - phd - tcd + tsc establish DP addressing + phd + tcd - jsr makeset form the set of characters + jsr makeset form the set of characters - stz set assume no match will be found - stz set+2 - short I,M scan for a matching char - ldy #0 -lb1 lda [s],Y - beq lb4 - tax - lda >strset,X - bne lb3 -lb2 iny - bne lb1 - long M - inc s+1 - short M - bra lb1 + stz set assume no match will be found + stz set+2 + short I,M scan for a matching char + ldy #0 +lb1 lda [s],Y + beq lb4 + tax + lda >strset,X + bne lb3 +lb2 iny + bne lb1 + long M + inc s+1 + short M + bra lb1 -lb3 long I,M set the address of the match found - tya - and #$00FF - clc - adc s - sta set - lda s+2 - adc #0 - sta set+2 - short I,M - bra lb2 +lb3 long I,M set the address of the match found + tya + and #$00FF + clc + adc s + sta set + lda s+2 + adc #0 + sta set+2 + short I,M + bra lb2 -lb4 long I,M - ldy set get the address - ldx set+2 - lda rtl+1 remove the parameters - sta set+2 - lda rtl - sta set+1 - pld - tsc - clc - adc #8 - tcs - tya return the ptr - rtl - end +lb4 long I,M + ldy set get the address + ldx set+2 + lda rtl+1 remove the parameters + sta set+2 + lda rtl + sta set+1 + pld + tsc + clc + adc #8 + tcs + tya return the ptr + rtl + end **************************************************************** * @@ -1449,372 +1449,372 @@ lb4 long I,M * **************************************************************** * -strset private +strset private - ds 256 - end + ds 256 + end **************************************************************** * * strspn - find the first char in s not in set * * Inputs: -* s - pointer to the string to scan -* set - set of characters to check against +* s - pointer to the string to scan +* set - set of characters to check against * * Outputs: -* A - disp to first char not in s +* A - disp to first char not in s * **************************************************************** * -strspn start -s equ 4 string to scan -set equ 8 set of characters -rtl equ 1 return address +strspn start +s equ 4 string to scan +set equ 8 set of characters +rtl equ 1 return address - tsc establish DP addressing - phd - tcd + tsc establish DP addressing + phd + tcd - jsr makeset form the set of characters + jsr makeset form the set of characters - stz set set initial displacement - stz set+2 - short I,M scan for a non-matching char - ldy #0 -lb1 lda [s],Y - beq lb2 - tax - lda >strset,X - beq lb2 - iny - bne lb1 - long M - inc s+1 - inc set+1 - short M - bra lb1 -lb2 sty set set the disp past the current disp + stz set set initial displacement + stz set+2 + short I,M scan for a non-matching char + ldy #0 +lb1 lda [s],Y + beq lb2 + tax + lda >strset,X + beq lb2 + iny + bne lb1 + long M + inc s+1 + inc set+1 + short M + bra lb1 +lb2 sty set set the disp past the current disp - long I,M - ldx set+2 get the return value - ldy set - lda rtl+1 remove the parameters - sta set+2 - lda rtl - sta set+1 - pld - tsc - clc - adc #8 - tcs - tya return the disp - rtl - end + long I,M + ldx set+2 get the return value + ldy set + lda rtl+1 remove the parameters + sta set+2 + lda rtl + sta set+1 + pld + tsc + clc + adc #8 + tcs + tya return the disp + rtl + end **************************************************************** * * strstr - string search * * Inputs: -* src - string to search -* sub - string to search for +* src - string to search +* sub - string to search for * * Outputs: -* X-A - pointer to the string; NULL if not found +* X-A - pointer to the string; NULL if not found * **************************************************************** * -strstr start -len equ 1 length of remaining string - strlen(sub) -lensub equ 5 strlen(sub) -p1 equ 9 temp pointer -p2 equ 13 -cnt equ 17 temp counter -num1 equ 21 temp number +strstr start +len equ 1 length of remaining string - strlen(sub) +lensub equ 5 strlen(sub) +p1 equ 9 temp pointer +p2 equ 13 +cnt equ 17 temp counter +num1 equ 21 temp number -workLen equ 24 length of work space +workLen equ 24 length of work space -src equ workLen+4 string to scan -sub equ workLen+8 string to search for -rtl equ workLen+1 return address +src equ workLen+4 string to scan +sub equ workLen+8 string to search for +rtl equ workLen+1 return address ; ; Set up our local variables ; - tsc create work space - sec - sbc #workLen - tcs - tsc establish DP addressing - phd - tcd - phb use local data areas - phk - plb + tsc create work space + sec + sbc #workLen + tcs + tsc establish DP addressing + phd + tcd + phb use local data areas + phk + plb ; ; Calculate the max # chars we can search ; - lda sub if the search string is null, return null - ora sub+2 - beq fl2 - lda src if the string to search is null, - ora src+2 return null - beq fl2 - ph4 sub get the length of the search string - jsl strlen - stx strset+2 - sta strset - stx lensub+2 - sta lensub - ora lensub+2 if the length is 0 then - jeq rt1 return the search string - ph4 src get the length of the string to search - jsl strlen - sec subtract off the length of the search - sbc lensub string - bvs fl2 - sta len - txa - sbc lensub+2 - sta len+2 - bpl fl3 if there aren't enough chars for a match -fl2 stz src - stz src+2 then return NULL - brl rt1 -fl3 anop + lda sub if the search string is null, return null + ora sub+2 + beq fl2 + lda src if the string to search is null, + ora src+2 return null + beq fl2 + ph4 sub get the length of the search string + jsl strlen + stx strset+2 + sta strset + stx lensub+2 + sta lensub + ora lensub+2 if the length is 0 then + jeq rt1 return the search string + ph4 src get the length of the string to search + jsl strlen + sec subtract off the length of the search + sbc lensub string + bvs fl2 + sta len + txa + sbc lensub+2 + sta len+2 + bpl fl3 if there aren't enough chars for a match +fl2 stz src + stz src+2 then return NULL + brl rt1 +fl3 anop ; ; Set up the displacement array (used to see how far we can shift) ; - lda strset+1 if strlen(sub) > 255 then - ora strset+2 use 255 for the max move - beq ds1 - lda #255 - sta strset -ds1 move strset,strset+1,#255 init all char disps to strlen(sub) + lda strset+1 if strlen(sub) > 255 then + ora strset+2 use 255 for the max move + beq ds1 + lda #255 + sta strset +ds1 move strset,strset+1,#255 init all char disps to strlen(sub) - lda strset skip if the length is 1 - and #$00FF - dec A - beq ds5 + lda strset skip if the length is 1 + and #$00FF + dec A + beq ds5 - stz cnt no chars processed so far - stz cnt+2 - move4 sub,p1 for each char but the last do -ds3 lda [p1] branch if this is the last char - and #$FF00 - beq ds5 - sub4 lensub,cnt,num1 compute strlen(sub) - cnt - 1 - dec4 num1 - lda num1+1 - ora num1+2 - bne ds4 if the result is <= 255 then - short I,M set the char index - lda [p1] - tax - lda num1 - sta strset,X - long I,M -ds4 inc4 cnt next char - inc4 p1 - bra ds3 -ds5 anop + stz cnt no chars processed so far + stz cnt+2 + move4 sub,p1 for each char but the last do +ds3 lda [p1] branch if this is the last char + and #$FF00 + beq ds5 + sub4 lensub,cnt,num1 compute strlen(sub) - cnt - 1 + dec4 num1 + lda num1+1 + ora num1+2 + bne ds4 if the result is <= 255 then + short I,M set the char index + lda [p1] + tax + lda num1 + sta strset,X + long I,M +ds4 inc4 cnt next char + inc4 p1 + bra ds3 +ds5 anop ; ; Search for the string ; -ss0 lda lensub if the length of the search string is - and #$8000 > 32767 then use a long method - ora lensub+2 - beq ss3 +ss0 lda lensub if the length of the search string is + and #$8000 > 32767 then use a long method + ora lensub+2 + beq ss3 - add4 lensub,src,p1 set the pointer to the end of the - dec4 p1 string to search - add4 lensub,sub,p2 set the pointer to the end of the - dec4 p2 search string - move4 lensub,cnt set the # chars to check -ss1 lda [p1] branch if the characters do not match - eor [p2] - and #$00FF - bne ss2 - dec4 p1 match - next char - dec4 p2 - dec4 cnt - lda cnt - ora cnt+2 - bne ss1 - bra rt1 match - return the pointer + add4 lensub,src,p1 set the pointer to the end of the + dec4 p1 string to search + add4 lensub,sub,p2 set the pointer to the end of the + dec4 p2 search string + move4 lensub,cnt set the # chars to check +ss1 lda [p1] branch if the characters do not match + eor [p2] + and #$00FF + bne ss2 + dec4 p1 match - next char + dec4 p2 + dec4 cnt + lda cnt + ora cnt+2 + bne ss1 + bra rt1 match - return the pointer -ss2 add4 lensub,src,p1 no match - find the skip length - dec4 p1 - lda [p1] - bra ss6 go to common handling for no match +ss2 add4 lensub,src,p1 no match - find the skip length + dec4 p1 + lda [p1] + bra ss6 go to common handling for no match -ss3 ldy lensub strlen(sub) < 32K, so use fast search - dey - short M -ss4 lda [src],Y - cmp [sub],Y - bne ss5 - dey - bpl ss4 - long M match - return the pointer - bra rt1 +ss3 ldy lensub strlen(sub) < 32K, so use fast search + dey + short M +ss4 lda [src],Y + cmp [sub],Y + bne ss5 + dey + bpl ss4 + long M match - return the pointer + bra rt1 -ss5 long M no match - find the skip length - ldy lensub - dey - lda [src],Y -ss6 and #$00FF - tax - lda strset,X - and #$00FF - sta cnt update the source string pointer - clc - adc src - sta src - bcc ss7 - inc src+2 -ss7 sec update the # of chars left - lda len - sbc cnt - sta len - lda len+2 - sbc #0 - sta len+2 - jcs ss0 go try for another match +ss5 long M no match - find the skip length + ldy lensub + dey + lda [src],Y +ss6 and #$00FF + tax + lda strset,X + and #$00FF + sta cnt update the source string pointer + clc + adc src + sta src + bcc ss7 + inc src+2 +ss7 sec update the # of chars left + lda len + sbc cnt + sta len + lda len+2 + sbc #0 + sta len+2 + jcs ss0 go try for another match - stz src no match - return NULL - stz src+2 + stz src no match - return NULL + stz src+2 ; ; Return to the caller ; -rt1 ldx src+2 get the return value - ldy src - lda rtl+1 remove the parameters - sta sub+2 - lda rtl - sta sub+1 - plb - pld - tsc - clc - adc #8+workLen - tcs - tya return the disp - rtl - end +rt1 ldx src+2 get the return value + ldy src + lda rtl+1 remove the parameters + sta sub+2 + lda rtl + sta sub+1 + plb + pld + tsc + clc + adc #8+workLen + tcs + tya return the disp + rtl + end **************************************************************** * * strtok - find a token * * Inputs: -* s - pointer to the string to scan -* set - set of characters to check against +* s - pointer to the string to scan +* set - set of characters to check against * * Outputs: -* X-A - pointer to the token; NULL if none +* X-A - pointer to the token; NULL if none * **************************************************************** * -strtok start -s equ 4 string to scan -set equ 8 set of characters -rtl equ 1 return address +strtok start +s equ 4 string to scan +set equ 8 set of characters +rtl equ 1 return address - tsc establish DP addressing - phd - tcd - phb use our local direct page - phk - plb + tsc establish DP addressing + phd + tcd + phb use our local direct page + phk + plb - jsr makeset form the set of characters + jsr makeset form the set of characters - lda s if s is not NULL then - ora s+2 - beq lb3 - short I,M scan for a non-matching char - ldy s - stz s -lb1 lda [s],Y - tax - lda strset,X - beq lb2 - iny - bne lb1 - long M - inc s+1 - short M - bra lb1 -lb2 sty s set the disp past the current disp - long I,M - bra lb4 else -lb3 lda isp s := internal state pointer - ldx isp+2 - sta s - stx s+2 - ora s+2 check if already at end of string - beq lb4a -lb4 anop endif + lda s if s is not NULL then + ora s+2 + beq lb3 + short I,M scan for a non-matching char + ldy s + stz s +lb1 lda [s],Y + tax + lda strset,X + beq lb2 + iny + bne lb1 + long M + inc s+1 + short M + bra lb1 +lb2 sty s set the disp past the current disp + long I,M + bra lb4 else +lb3 lda isp s := internal state pointer + ldx isp+2 + sta s + stx s+2 + ora s+2 check if already at end of string + beq lb4a +lb4 anop endif - lda [s] if we are at the end of the string then - and #$00FF - bne lb5 - stz isp set the isp to NULL - stz isp+2 -lb4a stz set return NULL - stz set+2 - bra lb10 else -lb5 lda [s] scan to the 1st char not in the set - and #$00FF - beq lb8a - tax - lda strset,X - and #$00FF - beq lb6 - inc4 s - bra lb5 -lb6 lda s return a ptr to the string - sta set - lda s+2 - sta set+2 -lb7 lda [s] scan to the 1st char in the set - and #$00FF - beq lb8a - tax - lda strset,X - and #$00FF - bne lb8 - inc4 s - bra lb7 -lb8 short M if a match was found then - lda #0 null terminate the token - sta [s] - long I,M set isp to the char past the token - add4 s,#1,isp - bra lb9 -lb8a long I,M else - stz isp set isp to NULL - stz isp+2 -lb9 anop endif + lda [s] if we are at the end of the string then + and #$00FF + bne lb5 + stz isp set the isp to NULL + stz isp+2 +lb4a stz set return NULL + stz set+2 + bra lb10 else +lb5 lda [s] scan to the 1st char not in the set + and #$00FF + beq lb8a + tax + lda strset,X + and #$00FF + beq lb6 + inc4 s + bra lb5 +lb6 lda s return a ptr to the string + sta set + lda s+2 + sta set+2 +lb7 lda [s] scan to the 1st char in the set + and #$00FF + beq lb8a + tax + lda strset,X + and #$00FF + bne lb8 + inc4 s + bra lb7 +lb8 short M if a match was found then + lda #0 null terminate the token + sta [s] + long I,M set isp to the char past the token + add4 s,#1,isp + bra lb9 +lb8a long I,M else + stz isp set isp to NULL + stz isp+2 +lb9 anop endif -lb10 ldx set+2 get the return value - ldy set - lda rtl+1 remove the parameters - sta set+2 - lda rtl - sta set+1 - plb - pld - tsc - clc - adc #8 - tcs - tya return the disp - rtl +lb10 ldx set+2 get the return value + ldy set + lda rtl+1 remove the parameters + sta set+2 + lda rtl + sta set+1 + plb + pld + tsc + clc + adc #8 + tcs + tya return the disp + rtl -isp ds 4 internal state pointer (isp) - end +isp ds 4 internal state pointer (isp) + end **************************************************************** * @@ -1825,34 +1825,34 @@ isp ds 4 internal state pointer (isp) * input strings would with strcoll. Writes at most n bytes. * * Inputs: -* s1 - output string pointer -* s2 - input string pointer -* n - max length to write +* s1 - output string pointer +* s2 - input string pointer +* n - max length to write * * Outputs: -* *s1 - transformed output string (if it fits) -* A - length of full transformed string -* (not including terminating null) +* *s1 - transformed output string (if it fits) +* A - length of full transformed string +* (not including terminating null) * * Notes: -* The current implementation assumes all supported locales -* have the same collation order as given by strcmp. +* The current implementation assumes all supported locales +* have the same collation order as given by strcmp. * **************************************************************** * strxfrm start - csubroutine (4:s1,4:s2,4:n),4 -len equ 1 length of s2 - - ph4 s2 len = strlen(s2) - jsl strlen - sta len - stx len+2 - cmpl len,n if len < n - bge ret - ph4 s2 - ph4 s1 - jsl strcpy strcpy(s1,s2) -ret creturn 4:len return len - end + csubroutine (4:s1,4:s2,4:n),4 +len equ 1 length of s2 + + ph4 s2 len = strlen(s2) + jsl strlen + sta len + stx len+2 + cmpl len,n if len < n + bge ret + ph4 s2 + ph4 s1 + jsl strcpy strcpy(s1,s2) +ret creturn 4:len return len + end