; ; File generated by cc65 v 2.13.3 ; .fopt compiler,"cc65 v 2.13.3" .setcpu "65C02" .smart on .autoimport on .case on .debuginfo on .importzp sp, sreg, regsave, regbank, tmp1, ptr1, ptr2 .macpack longbranch .dbg file, "strtol.c", 2969, 1667622315 .dbg file, "../../include/limits.h", 2978, 1667622315 .dbg file, "../../include/ctype.h", 7770, 1667622315 .dbg file, "../../include/errno.h", 3647, 1667622315 .dbg file, "../../include/stdlib.h", 5578, 1667622315 .import __ctype .import __maperrno .import __errno .export _strtol ; --------------------------------------------------------------- ; long __near__ __fastcall__ strtol (__near__ const unsigned char*, __near__ __near__ unsigned char**, int) ; --------------------------------------------------------------- .segment "CODE" .proc _strtol: near .segment "CODE" ; ; { ; .dbg line, "strtol.c", 10 jsr pushax ; ; register const char* S = nptr; ; .dbg line, "strtol.c", 11 lda regbank+4 ldx regbank+5 jsr pushax ldy #$07 lda (sp),y tax dey lda (sp),y sta regbank+4 stx regbank+4+1 ; ; unsigned long Val = 0; ; .dbg line, "strtol.c", 12 ldx #$00 txa jsr push0ax ; ; unsigned char Minus = 0; ; .dbg line, "strtol.c", 13 jsr pusha ; ; unsigned char Ovf = 0; ; .dbg line, "strtol.c", 14 jsr pusha ; ; unsigned CvtCount = 0; ; .dbg line, "strtol.c", 15 jsr push0 ; ; while (isspace (*S)) { ; .dbg line, "strtol.c", 22 jsr decsp6 L0009: lda (regbank+4) tay lda __ctype,y and #$60 beq L000A ; ; ++S; ; .dbg line, "strtol.c", 23 inc regbank+4 bne L0009 inc regbank+4+1 ; ; } ; .dbg line, "strtol.c", 24 bra L0009 ; ; switch (*S) { ; .dbg line, "strtol.c", 27 L000A: lda (regbank+4) ; ; } ; .dbg line, "strtol.c", 33 cmp #$2B beq L001F cmp #$2D bne L0019 ; ; Minus = 1; ; .dbg line, "strtol.c", 29 lda #$01 ldy #$09 sta (sp),y ; ; ++S; ; .dbg line, "strtol.c", 32 L001F: inc regbank+4 bne L0019 inc regbank+4+1 ; ; if (base == 0) { ; .dbg line, "strtol.c", 38 L0019: ldy #$11 lda (sp),y tax dey lda (sp),y cpx #$00 bne L0022 cmp #$00 bne L0022 ; ; if (*S == '0') { ; .dbg line, "strtol.c", 39 lda (regbank+4) cmp #$30 bne L0025 ; ; ++S; ; .dbg line, "strtol.c", 40 inc regbank+4 bne L0028 inc regbank+4+1 ; ; if (*S == 'x' || *S == 'X') { ; .dbg line, "strtol.c", 41 L0028: lda (regbank+4) cmp #$78 beq L002A lda (regbank+4) cmp #$58 bne L0029 ; ; ++S; ; .dbg line, "strtol.c", 42 L002A: inc regbank+4 bne L002D inc regbank+4+1 ; ; base = 16; ; .dbg line, "strtol.c", 43 L002D: tya ; ; } else { ; .dbg line, "strtol.c", 44 bra L00B0 ; ; base = 8; ; .dbg line, "strtol.c", 45 L0029: lda #$08 ldy #$10 jsr staxysp ; ; } else { ; .dbg line, "strtol.c", 47 bra L0037 ; ; base = 10; ; .dbg line, "strtol.c", 48 L0025: lda #$0A L00B0: ldy #$10 jsr staxysp ; ; } else if (base == 16 && *S == '0' && (S[1] == 'x' || S[1] == 'X')) { ; .dbg line, "strtol.c", 50 bra L0037 L0022: iny lda (sp),y tax dey lda (sp),y cpx #$00 bne L0037 cmp #$10 bne L0037 lda (regbank+4) cmp #$30 bne L0037 ldy #$01 lda (regbank+4),y cmp #$78 beq L0038 lda (regbank+4),y cmp #$58 bne L0037 ; ; S += 2; ; .dbg line, "strtol.c", 51 L0038: lda #$02 clc adc regbank+4 sta regbank+4 bcc L0037 inc regbank+4+1 ; ; if (Minus) { ; .dbg line, "strtol.c", 57 L0037: ldy #$09 lda (sp),y beq L0043 ; ; MaxVal = LONG_MIN; ; .dbg line, "strtol.c", 58 ldy #$01 lda #$00 sta (sp),y iny sta (sp),y iny sta (sp),y lda #$80 ; ; } else { ; .dbg line, "strtol.c", 59 bra L00B1 ; ; MaxVal = LONG_MAX; ; .dbg line, "strtol.c", 60 L0043: ldy #$01 dea sta (sp),y iny sta (sp),y iny sta (sp),y lda #$7F L00B1: iny sta (sp),y ; ; MaxDigit = MaxVal % base; ; .dbg line, "strtol.c", 62 jsr ldeaxysp jsr pusheax ldy #$15 lda (sp),y tax dey lda (sp),y jsr axlong jsr tosumodeax sta (sp) ; ; MaxVal /= base; ; .dbg line, "strtol.c", 63 ldy #$04 jsr ldeaxysp jsr pusheax ldy #$15 lda (sp),y tax dey lda (sp),y jsr axlong jsr tosudiveax ldy #$01 jsr steaxysp ; ; if (isdigit (*S)) { ; .dbg line, "strtol.c", 69 L004F: lda (regbank+4) tay lda __ctype,y and #$04 beq L0052 ; ; DigitVal = *S - '0'; ; .dbg line, "strtol.c", 70 lda (regbank+4) sec sbc #$30 ; ; } else if (isupper (*S)) { ; .dbg line, "strtol.c", 71 bra L00B3 L0052: lda (regbank+4) tay lda __ctype,y and #$02 beq L0060 ; ; DigitVal = *S - ('A' - 10); ; .dbg line, "strtol.c", 72 lda (regbank+4) sec sbc #$37 ; ; } else if (islower (*S)) { ; .dbg line, "strtol.c", 73 bra L00B3 L0060: lda (regbank+4) tay lda __ctype,y and #$01 jeq L0050 ; ; DigitVal = *S - ('a' - 10); ; .dbg line, "strtol.c", 74 lda (regbank+4) sec sbc #$57 L00B3: ldy #$05 sta (sp),y ; ; if (DigitVal >= base) { ; .dbg line, "strtol.c", 81 lda (sp),y jsr pusha0 ldy #$13 lda (sp),y tax dey lda (sp),y jsr tosicmp ; ; break; ; .dbg line, "strtol.c", 82 bcs L0050 ; ; if (Val > MaxVal || (Val == MaxVal && DigitVal > MaxDigit)) { ; .dbg line, "strtol.c", 86 ldy #$0D jsr ldeaxysp jsr pusheax ldy #$08 jsr ldeaxysp jsr tosugteax bne L0081 ldy #$0D jsr ldeaxysp jsr pusheax ldy #$08 jsr ldeaxysp jsr toseqeax beq L0080 ldy #$05 lda (sp),y sec sbc (sp) sta tmp1 lda tmp1 beq L0080 bcc L0080 ; ; Ovf = 1; ; .dbg line, "strtol.c", 87 L0081: lda #$01 ldy #$08 sta (sp),y ; ; if (Ovf == 0) { ; .dbg line, "strtol.c", 91 L0080: ldy #$08 lda (sp),y bne L0088 ; ; Val = (Val * base) + DigitVal; ; .dbg line, "strtol.c", 92 ldy #$0D jsr ldeaxysp jsr pusheax ldy #$15 lda (sp),y tax dey lda (sp),y jsr axlong jsr tosumuleax jsr pusheax ldy #$09 ldx #$00 lda (sp),y jsr tosadd0ax ldy #$0A jsr steaxysp ; ; ++CvtCount; ; .dbg line, "strtol.c", 93 ldy #$06 ldx #$00 lda #$01 jsr addeqysp ; ; ++S; ; .dbg line, "strtol.c", 97 L0088: inc regbank+4 jne L004F inc regbank+4+1 ; ; } ; .dbg line, "strtol.c", 98 jmp L004F ; ; if (endptr) { ; .dbg line, "strtol.c", 103 L0050: ldy #$13 lda (sp),y dey ora (sp),y beq L0098 ; ; if (CvtCount > 0) { ; .dbg line, "strtol.c", 104 ldy #$07 lda (sp),y tax dey lda (sp),y cpx #$00 bne L00AF cmp #$00 beq L0092 ; ; *endptr = (char*) S - 1; ; .dbg line, "strtol.c", 105 L00AF: ldy #$13 lda (sp),y tax dey lda (sp),y sta sreg stx sreg+1 lda regbank+4 ldx regbank+4+1 sec sbc #$01 bcs L0097 dex L0097: sta (sreg) ldy #$01 txa sta (sreg),y ; ; } else { ; .dbg line, "strtol.c", 106 bra L0098 ; ; *endptr = (char*) nptr; ; .dbg line, "strtol.c", 107 L0092: ldy #$13 lda (sp),y tax dey lda (sp),y jsr pushax ldy #$17 lda (sp),y tax dey lda (sp),y ldy #$00 jsr staxspidx ; ; if (Ovf) { ; .dbg line, "strtol.c", 112 L0098: ldy #$08 lda (sp),y beq L00A5 ; ; errno = ERANGE; ; .dbg line, "strtol.c", 113 jsr __maperrno ldx #$00 lda #$0F sta __errno stz __errno+1 ; ; if (Minus) { ; .dbg line, "strtol.c", 114 ldy #$09 lda (sp),y beq L00A1 ; ; return LONG_MIN; ; .dbg line, "strtol.c", 115 stz sreg lda #$80 sta sreg+1 txa bra L00AA ; ; return LONG_MAX; ; .dbg line, "strtol.c", 117 L00A1: dex stx sreg lda #$7F sta sreg+1 txa bra L00AA ; ; if (Minus) { ; .dbg line, "strtol.c", 122 L00A5: iny lda (sp),y beq L00A7 ; ; return -(long)Val; ; .dbg line, "strtol.c", 123 ldy #$0D jsr ldeaxysp jsr negeax bra L00AA ; ; return Val; ; .dbg line, "strtol.c", 125 L00A7: ldy #$0D jsr ldeaxysp ; ; } ; .dbg line, "strtol.c", 127 L00AA: pha ldy #$0E lda (sp),y sta regbank+4 iny lda (sp),y sta regbank+5 pla ldy #$16 jmp addysp .dbg line .endproc