1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2024-11-22 01:31:33 +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 Note: Calls putdec() and putspc(). Leaves the value
of b in varible temp3. 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. putspc(b); Writes a space character to the screen.
Note: Used by the putdel() and putder() functions. 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 one value argument may be passed and that value is
used for each formatting tag in the format string. 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 The letter in the formatting tag may be upper or
lower case with either a 0 or 1 in the high bit. lower case with either a 0 or 1 in the high bit.
Unrecognized formatting tags are interpreted as %C. Unrecognized formatting tags are interpreted as %C.
Note: Calls putdec(), putdel(), putder(), or prbyte() Note: Calls putdec(), putdel(), putder(), prbyte(), or
depending on which formatting tags are used. The value putdst() depending on which formatting tags are used.
of b is left in variable temp3. The value of b is left in variable temp3.
Note: This library expects the following functions to be defined: 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 GETSY: TYA ; Return String Length
RTS RTS
;char puts(n, &s) ;char puts(&s)
PUTS: LDA #$00 ;Set Start Position to 0 PUTS: LDA #$00 ;Set Start Position to 0
;and fall into putsub ;and fall into putsub
;char putsub(n, &s) ;char putsub(n, &s)
@ -45,9 +45,9 @@ PUTSUL: LDA (SRCLO),Y ;Read next character in string
JSR PUTC ; Print character at offset, JSR PUTC ; Print character at offset,
INY ; increment offset, and INY ; increment offset, and
BPL PUTSUL ; loop if less than 128 BPL PUTSUL ; loop if less than 128
PUTSUX: TAY ;Return number of PUTSUX: TYA ;Return number of
RTS ; characters printed RTS ; characters printed
;char putln(&s) ;char putln(&s)
PUTLN: JSR PUTS ;Write string to screen 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

@ -65,38 +65,55 @@ PRINTF: JSR SETSRC ;Initialize Source String
STA TEMP3 ;Save Byte to Format STA TEMP3 ;Save Byte to Format
PRINTL: LDA (SRCLO),Y ;Read next character in string PRINTL: LDA (SRCLO),Y ;Read next character in string
BEQ PRINTX ;If Not 0 BEQ PRINTX ;If Not 0
CMP #'% ; If Format Specified CMP #'% ;' If Format Specified
BEQ PRINTS ; Jump to Formatter BEQ PRINTP ; Jump to Formatter
PRINTC: JSR PRCHR ; Print character at offset, PRINTC: JSR PRCHR ; Print character at offset,
PRINTY: INY ; increment offset, and PRINTY: INY ; increment offset, and
BPL PRINTL ; loop if less than 128 BPL PRINTL ; loop if less than 128
PRINTX: RTS ; characters printed PRINTX: RTS ; characters printed
;Process Format Specifier ;Process Format Specifier
PRINTS: INY ;Increment Offset PRINTP: INY ;Increment Offset
LDA (SRCLO),Y ;Get Formatting Character LDA (SRCLO),Y ;Get Formatting Character
BEQ PRINTX ;If NUL, then Exit BEQ PRINTX ;If NUL, then Exit
CMP #'% ;If Percent Sign CMP #'% ;'If Percent Sign
BEQ PRINTC ; Print it and Continue BEQ PRINTC ; Print it and Continue
AND #$DF ;Convert to Upper Case AND #$DF ;Convert to Upper Case
CMP #'L ;If "l" or "L" CMP #'L ;'If "l" or "L"
BNE PRINTR BNE PRINTR
LDA TEMP3 ; Load Byte to Format LDA TEMP3 ; Load Byte to Format
JSR PUTDEM ; Print Left Justified JSR PUTDEM ; Print Left Justified
JMP PRINTY ; and Continue Printing Screen JMP PRINTY ; and Continue Printing Screen
PRINTR: CMP #'R ;If "r" or "R" PRINTR: CMP #'R ;'If "r" or "R"
BNE PRINTD BNE PRINTD
LDA TEMP3 ; Load Byte to Format LDA TEMP3 ; Load Byte to Format
JSR PUTDES ; Print Right Justified JSR PUTDES ; Print Right Justified
JMP PRINTY ; and Continue Printing Screen JMP PRINTY ; and Continue Printing Screen
PRINTD: CMP #'D ;If "d" or "D" PRINTD: CMP #'D ;'Else If "d" or "D"
BNE PRINTH BNE PRINTH
LDA TEMP3 ; Load Byte to Format LDA TEMP3 ; Load Byte to Format
JSR PUTDEC ; Print as Decimal JSR PUTDEC ; Print as Decimal
JMP PRINTY ; and Continue Printing Screen JMP PRINTY ; and Continue Printing Screen
PRINTH: CMP #'H ;Else If "h" or "H" PRINTH: CMP #'H ;'Else If "h" or "H"
BNE PRINTB BNE PRINTS
LDA TEMP3 ; Load Byte to Format LDA TEMP3 ; Load Byte to Format
JSR PRBYTE ; Print as Hexadecimal JSR PRBYTE ; Print as Hexadecimal
JMP PRINTY ; and Continue Printing Screen JMP PRINTY ; and Continue Printing Screen
PRINTB: LDA TEMP3 ;Otherwise PRINTS: CMP #'S ;'Else If "s" or "s"
BNE PRINTB
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 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 */ * Args: b - Number to print */
void putder(); void putder();
/* Print Destination String */
void putdst();
/* Print a Space Character */ /* Print a Space Character */
void putspc(); void putspc();

View File

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