; ; 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, "strtoul.c", 2843, 1356265749 .dbg file, "../../include/limits.h", 2978, 1039954353 .dbg file, "../../include/ctype.h", 7770, 1087856531 .dbg file, "../../include/errno.h", 3647, 1060696125 .dbg file, "../../include/stdlib.h", 5578, 1253048480 .import __ctype .import __maperrno .import __errno .export _strtoul ; --------------------------------------------------------------- ; unsigned long __near__ __fastcall__ strtoul (__near__ const unsigned char*, __near__ __near__ unsigned char**, int) ; --------------------------------------------------------------- .segment "CODE" .proc _strtoul: near .segment "CODE" ; ; { ; .dbg line, "strtoul.c", 10 jsr pushax ; ; register const char* S = nptr; ; .dbg line, "strtoul.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, "strtoul.c", 12 ldx #$00 txa jsr push0ax ; ; unsigned char Minus = 0; ; .dbg line, "strtoul.c", 13 jsr pusha ; ; unsigned char Ovf = 0; ; .dbg line, "strtoul.c", 14 jsr pusha ; ; unsigned CvtCount = 0; ; .dbg line, "strtoul.c", 15 jsr push0 ; ; while (isspace (*S)) { ; .dbg line, "strtoul.c", 22 jsr decsp6 L0009: lda (regbank+4) tay lda __ctype,y and #$60 beq L000A ; ; ++S; ; .dbg line, "strtoul.c", 23 inc regbank+4 bne L0009 inc regbank+4+1 ; ; } ; .dbg line, "strtoul.c", 24 bra L0009 ; ; switch (*S) { ; .dbg line, "strtoul.c", 27 L000A: lda (regbank+4) ; ; } ; .dbg line, "strtoul.c", 33 cmp #$2B beq L001F cmp #$2D bne L0019 ; ; Minus = 1; ; .dbg line, "strtoul.c", 29 lda #$01 ldy #$09 sta (sp),y ; ; ++S; ; .dbg line, "strtoul.c", 32 L001F: inc regbank+4 bne L0019 inc regbank+4+1 ; ; if (base == 0) { ; .dbg line, "strtoul.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, "strtoul.c", 39 lda (regbank+4) cmp #$30 bne L0025 ; ; ++S; ; .dbg line, "strtoul.c", 40 inc regbank+4 bne L0028 inc regbank+4+1 ; ; if (*S == 'x' || *S == 'X') { ; .dbg line, "strtoul.c", 41 L0028: lda (regbank+4) cmp #$78 beq L002A lda (regbank+4) cmp #$58 bne L0029 ; ; ++S; ; .dbg line, "strtoul.c", 42 L002A: inc regbank+4 bne L002D inc regbank+4+1 ; ; base = 16; ; .dbg line, "strtoul.c", 43 L002D: tya ; ; } else { ; .dbg line, "strtoul.c", 44 bra L00A2 ; ; base = 8; ; .dbg line, "strtoul.c", 45 L0029: lda #$08 ldy #$10 jsr staxysp ; ; } else { ; .dbg line, "strtoul.c", 47 bra L0037 ; ; base = 10; ; .dbg line, "strtoul.c", 48 L0025: lda #$0A L00A2: ldy #$10 jsr staxysp ; ; } else if (base == 16 && *S == '0' && (S[1] == 'x' || S[1] == 'X')) { ; .dbg line, "strtoul.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, "strtoul.c", 51 L0038: lda #$02 clc adc regbank+4 sta regbank+4 bcc L0037 inc regbank+4+1 ; ; MaxDigit = ULONG_MAX % base; ; .dbg line, "strtoul.c", 57 L0037: ldx #$FF stx sreg stx sreg+1 txa jsr pusheax ldy #$15 lda (sp),y tax dey lda (sp),y jsr axlong jsr tosumodeax sta (sp) ; ; MaxVal = ULONG_MAX / base; ; .dbg line, "strtoul.c", 58 ldx #$FF stx sreg stx sreg+1 txa 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, "strtoul.c", 64 L0047: lda (regbank+4) tay lda __ctype,y and #$04 beq L004A ; ; DigitVal = *S - '0'; ; .dbg line, "strtoul.c", 65 lda (regbank+4) sec sbc #$30 ; ; } else if (isupper (*S)) { ; .dbg line, "strtoul.c", 66 bra L00A4 L004A: lda (regbank+4) tay lda __ctype,y and #$02 beq L0058 ; ; DigitVal = *S - ('A' - 10); ; .dbg line, "strtoul.c", 67 lda (regbank+4) sec sbc #$37 ; ; } else if (islower (*S)) { ; .dbg line, "strtoul.c", 68 bra L00A4 L0058: lda (regbank+4) tay lda __ctype,y and #$01 jeq L0048 ; ; DigitVal = *S - ('a' - 10); ; .dbg line, "strtoul.c", 69 lda (regbank+4) sec sbc #$57 L00A4: ldy #$05 sta (sp),y ; ; if (DigitVal >= base) { ; .dbg line, "strtoul.c", 76 lda (sp),y jsr pusha0 ldy #$13 lda (sp),y tax dey lda (sp),y jsr tosicmp ; ; break; ; .dbg line, "strtoul.c", 77 bcs L0048 ; ; if (Val > MaxVal || (Val == MaxVal && DigitVal > MaxDigit)) { ; .dbg line, "strtoul.c", 81 ldy #$0D jsr ldeaxysp jsr pusheax ldy #$08 jsr ldeaxysp jsr tosugteax bne L0079 ldy #$0D jsr ldeaxysp jsr pusheax ldy #$08 jsr ldeaxysp jsr toseqeax beq L0078 ldy #$05 lda (sp),y sec sbc (sp) sta tmp1 lda tmp1 beq L0078 bcc L0078 ; ; Ovf = 1; ; .dbg line, "strtoul.c", 82 L0079: lda #$01 ldy #$08 sta (sp),y ; ; if (Ovf == 0) { ; .dbg line, "strtoul.c", 86 L0078: ldy #$08 lda (sp),y bne L0080 ; ; Val = (Val * base) + DigitVal; ; .dbg line, "strtoul.c", 87 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, "strtoul.c", 88 ldy #$06 ldx #$00 lda #$01 jsr addeqysp ; ; ++S; ; .dbg line, "strtoul.c", 92 L0080: inc regbank+4 jne L0047 inc regbank+4+1 ; ; } ; .dbg line, "strtoul.c", 93 jmp L0047 ; ; if (endptr) { ; .dbg line, "strtoul.c", 98 L0048: ldy #$13 lda (sp),y dey ora (sp),y beq L0090 ; ; if (CvtCount > 0) { ; .dbg line, "strtoul.c", 99 ldy #$07 lda (sp),y tax dey lda (sp),y cpx #$00 bne L00A1 cmp #$00 beq L008A ; ; *endptr = (char*) S - 1; ; .dbg line, "strtoul.c", 100 L00A1: 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 L008F dex L008F: sta (sreg) ldy #$01 txa sta (sreg),y ; ; } else { ; .dbg line, "strtoul.c", 101 bra L0090 ; ; *endptr = (char*) nptr; ; .dbg line, "strtoul.c", 102 L008A: 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, "strtoul.c", 107 L0090: ldy #$08 lda (sp),y beq L0093 ; ; errno = ERANGE; ; .dbg line, "strtoul.c", 108 jsr __maperrno lda #$0F sta __errno stz __errno+1 ; ; return ULONG_MAX; ; .dbg line, "strtoul.c", 109 ldx #$FF stx sreg stx sreg+1 txa bra L009D ; ; if (Minus) { ; .dbg line, "strtoul.c", 113 L0093: iny lda (sp),y beq L009A ; ; return (unsigned long) -(long)Val; ; .dbg line, "strtoul.c", 114 ldy #$0D jsr ldeaxysp jsr negeax bra L009D ; ; return Val; ; .dbg line, "strtoul.c", 116 L009A: ldy #$0D jsr ldeaxysp ; ; } ; .dbg line, "strtoul.c", 118 L009D: pha ldy #$0E lda (sp),y sta regbank+4 iny lda (sp),y sta regbank+5 pla ldy #$16 jmp addysp .dbg line .endproc