]> git.sur5r.net Git - cc65/blobdiff - libsrc/common/_printf.s
The spans do now contain the size of a span, no longer the end offset.
[cc65] / libsrc / common / _printf.s
index d58744e40b7d5b1434221e182547eeef29c8ee8e..a8470df3e55ddc802ee455b41c0cd34e7d79c84e 100644 (file)
@@ -7,7 +7,6 @@
        .export         __printf
 
        .import         popax, pushax, pusheax, decsp6, push1, axlong, axulong
-       .import         __ctype
        .import         _ltoa, _ultoa
        .import         _strlower, _strlen
        .importzp       sp, ptr1, ptr2, tmp1, regbank, sreg
@@ -59,9 +58,8 @@ Output1:
        lda     #<CharArg
        ldx     #>CharArg
        jsr     pushax
-       jsr     push1
-CallOutFunc:
-       jmp     (OutFunc)       ; fout (OutData, &CharArg, 1)
+       jsr     push1
+       jmp     CallOutFunc     ; fout (OutData, &CharArg, 1)
 
 ; ----------------------------------------------------------------------------
 ; Decrement the argument list pointer by 2
@@ -213,7 +211,7 @@ OutputArg:
        lda     ArgLen
        ldx     ArgLen+1
        jsr     pushax
-       jmp     (OutFunc)
+       jmp     CallOutFunc
 
 ; ----------------------------------------------------------------------------
 ; ltoa: Wrapper for _ltoa that pushes all arguments
@@ -259,7 +257,7 @@ Save:       lda     regbank,y
        sta     Format
        stx     Format+1
 
-       jsr     popax                   ; Output descriptor
+       jsr     popax                   ; Output descriptor
        sta     OutData
        stx     OutData+1
 
@@ -275,10 +273,10 @@ Save:     lda     regbank,y
 
        iny
        lda     (OutData),y
-       sta     OutFunc
+       sta     CallOutFunc+1
        iny
        lda     (OutData),y
-       sta     OutFunc+1
+       sta     CallOutFunc+2
 
 ; Start parsing the format string
 
@@ -461,19 +459,21 @@ ReadPrec:
 
 ReadMod:
        lda     (Format),y
-       cmp     #'F'
-       beq     @L1                     ; Read and ignore this one
-       cmp     #'N'
-       beq     @L1                     ; Read and ignore this one
-       cmp     #'h'
-       beq     @L1                     ; Read and ignore this one
-       cmp     #'L'
-       beq     @L1                     ; Read and ignore this one
-       cmp     #'l'
+       cmp     #'z'                    ; size_t - same as unsigned
+       beq     @L2
+       cmp     #'h'                    ; short - same as int
+       beq     @L2
+        cmp     #'t'                    ; ptrdiff_t - same as int
+        beq     @L2
+        cmp     #'j'                    ; intmax_t/uintmax_t - same as long
+        beq     @L1
+       cmp     #'L'                    ; long double
+       beq     @L1
+       cmp     #'l'                    ; long int
        bne     DoFormat
-       lda     #$FF
+@L1:    lda    #$FF
        sta     IsLong
-@L1:   jsr     IncFormatPtr
+@L2:   jsr     IncFormatPtr
        jmp     ReadMod
 
 ; Initialize the argument buffer pointers. We use a static buffer (ArgBuf) to
@@ -527,7 +527,7 @@ CheckInt:
 
 ; Integer argument
 
-       jsr     GetSignedArg                    ; Get argument as a long
+       jsr     GetSignedArg            ; Get argument as a long
        ldy     sreg+1                  ; Check sign
        bmi     @Int1
        ldy     Leader
@@ -562,29 +562,44 @@ CheckCount:
 
 CheckOctal:
        cmp     #'o'
-       bne     CheckString
+       bne     CheckPointer
 
 ; Integer in octal representation
 
-       jsr     GetSignedArg            ; Get argument as a long
-               ldy     AltForm                 ; Alternative form?
-       beq     @Oct1                   ; Jump if no
-       pha                             ; Save low byte of value
+       jsr     GetSignedArg            ; Get argument as a long
+               ldy     AltForm                 ; Alternative form?
+       beq     @Oct1                   ; Jump if no
+       pha                             ; Save low byte of value
        stx     tmp1
        ora     tmp1
        ora     sreg
        ora     sreg+1
        ora     Prec
-       ora     Prec+1                  ; Check if value or Prec != 0
+       ora     Prec+1                  ; Check if value or Prec != 0
        beq     @Oct1
        lda     #'0'
        jsr     PutBuf
-       pla                             ; Restore low byte
+       pla                             ; Restore low byte
 
-@Oct1: ldy     #8                      ; Load base
-       jsr     ltoa                    ; Push arguments, call _ltoa
+@Oct1: ldy     #8                      ; Load base
+       jsr     ltoa                    ; Push arguments, call _ltoa
        jmp     HaveArg
 
+; Check for a pointer specifier (%p)
+
+CheckPointer:
+       cmp     #'p'
+       bne     CheckString
+
+; It's a pointer. Use %#x conversion
+
+       ldx     #0
+       stx     IsLong                  ; IsLong = 0;
+       inx
+               stx     AltForm                 ; AltForm = 1;
+       lda     #'x'
+       bne     IsHex                   ; Branch always
+
 ; Check for a string specifier (%s)
 
 CheckString:
@@ -615,13 +630,13 @@ CheckUnsigned:
 
 CheckHex:
        cmp     #'x'
-       beq     @IsHex
+       beq     IsHex
        cmp     #'X'
        bne     UnknownFormat
 
 ; Hexadecimal integer
 
-@IsHex:        pha                             ; Save the format spec
+IsHex: pha                             ; Save the format spec
        lda     AltForm
        beq     @L1
        lda     #'0'
@@ -641,7 +656,7 @@ CheckHex:
        jsr     _strlower               ; Make characters lower case
 @L2:   jmp     HaveArg
 
-; Unsigned format character, skip it
+; Unknown format character, skip it
 
 UnknownFormat:
        jmp     MainLoop
@@ -668,7 +683,7 @@ HaveArg:
        lda     Prec+1
        tay
        sbc     ArgLen+1
-       bcc     @L1
+        bcs    @L1
        stx     ArgLen
        sty     ArgLen+1
 
@@ -737,9 +752,6 @@ HaveArg:
 ; Save area for the zero page registers
 RegSave:       .res    6
 
-; Stuff from OutData. Is used as a vector and must be aligned
-OutFunc:       .word   0
-
 ; One character argument for OutFunc
 CharArg:       .byte   0
 
@@ -762,3 +774,10 @@ Buf:               .res    20
 Str:           .word   0
 ArgLen:                .res    2
 
+.data
+
+; Stuff from OutData. Is used as a vector and must be aligned
+CallOutFunc:   jmp     $0000
+
+
+