1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-06-25 14:29:27 +00:00

Added %S tag to printf() function

This commit is contained in:
Curtis F Kaylor 2018-07-19 00:27:50 -04:00
parent 818174a15a
commit 24a427583d
5 changed files with 89 additions and 41 deletions

View File

@ -32,6 +32,16 @@ The following functions are defined:
Note: Calls putdec() and putspc(). Leaves the value
of b in varible temp3.
putdst(); Prints the destination string set by the setdst() or
setstr() functions.
This can be used to print the results of any function
call that stores it's result in the destination string,
such as strcat(), strcpy(), and strcut() in string,
Note: calls putc() and is called by printf() when
processing a %S formatting tag.
putspc(b); Writes a space character to the screen.
Note: Used by the putdel() and putder() functions.
@ -55,13 +65,26 @@ The following functions are defined:
one value argument may be passed and that value is
used for each formatting tag in the format string.
One additional formatting tag is supported:
%S - output the destination string
The destination string is set using the setdst() or
strdst() functions (from the "string" library) before
calling printf(). Multiple occurances of the %S tag
will cause the destination string to be repeated.
When tag types are mixed, the %S tag will output the
destination string, while the other tags will output
the formatted byte. If only the %S tag is used, then
the byte argument may be excluded from the call.
The letter in the formatting tag may be upper or
lower case with either a 0 or 1 in the high bit.
Unrecognized formatting tags are interpreted as %C.
Note: Calls putdec(), putdel(), putder(), or prbyte()
depending on which formatting tags are used. The value
of b is left in variable temp3.
Note: Calls putdec(), putdel(), putder(), prbyte(), or
putdst() depending on which formatting tags are used.
The value of b is left in variable temp3.
Note: This library expects the following functions to be defined:

View File

@ -34,7 +34,7 @@ GETSX: JSR NEWLIN ;Else Advance Cursor to Next Line
GETSY: TYA ; Return String Length
RTS
;char puts(n, &s)
;char puts(&s)
PUTS: LDA #$00 ;Set Start Position to 0
;and fall into putsub
;char putsub(n, &s)
@ -45,9 +45,9 @@ PUTSUL: LDA (SRCLO),Y ;Read next character in string
JSR PUTC ; Print character at offset,
INY ; increment offset, and
BPL PUTSUL ; loop if less than 128
PUTSUX: TAY ;Return number of
PUTSUX: TYA ;Return number of
RTS ; characters printed
;char putln(&s)
PUTLN: JSR PUTS ;Write string to screen
\ JMP NEWLIN ;Execute external NEWLINe routine and return
JMP NEWLIN ;Execute external NEWLINe routine and return

View File

@ -55,48 +55,65 @@ PUTDEP: ORA #$30 ;Convert to ASCII digit
;Print a Space
PUTSPC: LDA #32 ;Load Space Character
JMP PRCHR ;and Print it
;Print Byte in Formatted String
;void printf(b, &s)
;Args: A = number to format
; Y,X = address of formatting string
;Sets: TEMP3 - number to format
PRINTF: JSR SETSRC ;Initialize Source String
STA TEMP3 ;Save Byte to Format
PRINTL: LDA (SRCLO),Y ;Read next character in string
BEQ PRINTX ;If Not 0
CMP #'% ; If Format Specified
BEQ PRINTS ; Jump to Formatter
PRINTC: JSR PRCHR ; Print character at offset,
PRINTY: INY ; increment offset, and
BPL PRINTL ; loop if less than 128
PRINTX: RTS ; characters printed
PRINTF: JSR SETSRC ;Initialize Source String
STA TEMP3 ;Save Byte to Format
PRINTL: LDA (SRCLO),Y ;Read next character in string
BEQ PRINTX ;If Not 0
CMP #'% ;' If Format Specified
BEQ PRINTP ; Jump to Formatter
PRINTC: JSR PRCHR ; Print character at offset,
PRINTY: INY ; increment offset, and
BPL PRINTL ; loop if less than 128
PRINTX: RTS ; characters printed
;Process Format Specifier
PRINTS: INY ;Increment Offset
LDA (SRCLO),Y ;Get Formatting Character
BEQ PRINTX ;If NUL, then Exit
CMP #'% ;If Percent Sign
BEQ PRINTC ; Print it and Continue
AND #$DF ;Convert to Upper Case
CMP #'L ;If "l" or "L"
PRINTP: INY ;Increment Offset
LDA (SRCLO),Y ;Get Formatting Character
BEQ PRINTX ;If NUL, then Exit
CMP #'% ;'If Percent Sign
BEQ PRINTC ; Print it and Continue
AND #$DF ;Convert to Upper Case
CMP #'L ;'If "l" or "L"
BNE PRINTR
LDA TEMP3 ; Load Byte to Format
JSR PUTDEM ; Print Left Justified
JMP PRINTY ; and Continue Printing Screen
PRINTR: CMP #'R ;If "r" or "R"
LDA TEMP3 ; Load Byte to Format
JSR PUTDEM ; Print Left Justified
JMP PRINTY ; and Continue Printing Screen
PRINTR: CMP #'R ;'If "r" or "R"
BNE PRINTD
LDA TEMP3 ; Load Byte to Format
JSR PUTDES ; Print Right Justified
JMP PRINTY ; and Continue Printing Screen
PRINTD: CMP #'D ;If "d" or "D"
LDA TEMP3 ; Load Byte to Format
JSR PUTDES ; Print Right Justified
JMP PRINTY ; and Continue Printing Screen
PRINTD: CMP #'D ;'Else If "d" or "D"
BNE PRINTH
LDA TEMP3 ; Load Byte to Format
JSR PUTDEC ; Print as Decimal
JMP PRINTY ; and Continue Printing Screen
PRINTH: CMP #'H ;Else If "h" or "H"
LDA TEMP3 ; Load Byte to Format
JSR PUTDEC ; Print as Decimal
JMP PRINTY ; and Continue Printing Screen
PRINTH: CMP #'H ;'Else If "h" or "H"
BNE PRINTS
LDA TEMP3 ; Load Byte to Format
JSR PRBYTE ; Print as Hexadecimal
JMP PRINTY ; and Continue Printing Screen
PRINTS: CMP #'S ;'Else If "s" or "s"
BNE PRINTB
LDA TEMP3 ; Load Byte to Format
JSR PRBYTE ; Print as Hexadecimal
JMP PRINTY ; and Continue Printing Screen
PRINTB: LDA TEMP3 ;Otherwise
JMP PRINTC ; Print Raw Byte and Continue
STY TEMP0 ; Save Index
JSR PUTDST ; Print Destination String
LDY TEMP0 ; Restore Index
JMP PRINTY ;
PRINTB: LDA TEMP3 ;Else
JMP PRINTC ; Print Raw Byte and Continue
;and fall into putsub
;char putdst()
PUTDST: LDY #0 ;Initialize character offset
PUTDSL: LDA (DSTLO),Y ;Read next character in string
BEQ PUTDSX ;If Not 0
JSR PUTC ; Print character at offset,
INY ; increment offset, and
BPL PUTDSL ; loop if less than 128
PUTDSX: TYA ;Return number of
RTS ; characters printed

View File

@ -14,6 +14,9 @@ void putdel();
* Args: b - Number to print */
void putder();
/* Print Destination String */
void putdst();
/* Print a Space Character */
void putspc();

View File

@ -8,6 +8,7 @@
#include <stdiox.h02>
char c, i;
char s = "string";
main:
@ -48,6 +49,10 @@ do {
if (!i&15) anykey();
} while (i<128);
setdst(&s);
printf("S=\"%s\"");
newlin();
done:
goto exit;