Use more compact loops.
This commit is contained in:
parent
99c0815cdb
commit
f59cb9af06
13 changed files with 90 additions and 94 deletions
|
@ -20,18 +20,19 @@
|
|||
|
||||
sta ptr3
|
||||
stx ptr3+1 ; save count as result
|
||||
eor #$FF
|
||||
sta ptr2
|
||||
txa
|
||||
eor #$FF
|
||||
sta ptr2+1 ; Remember -count-1
|
||||
|
||||
inx
|
||||
stx ptr2+1
|
||||
tax
|
||||
inx
|
||||
stx ptr2 ; save count with each byte incremented separately
|
||||
|
||||
jsr popptr1 ; get buf
|
||||
jsr popax ; get fd and discard
|
||||
|
||||
L1: inc ptr2
|
||||
L1: dec ptr2
|
||||
bnz L2
|
||||
inc ptr2+1
|
||||
dec ptr2+1
|
||||
bze L9 ; no more room in buf
|
||||
|
||||
; If there are no more characters in BASIC's input buffer, then get a line from
|
||||
|
|
|
@ -17,17 +17,17 @@
|
|||
sta ptr3
|
||||
stx ptr3+1 ; save count as result
|
||||
|
||||
eor #$FF
|
||||
sta ptr2
|
||||
txa
|
||||
eor #$FF
|
||||
sta ptr2+1 ; Remember -count-1
|
||||
inx
|
||||
stx ptr2+1
|
||||
tax
|
||||
inx
|
||||
stx ptr2 ; save count with each byte incremented separately
|
||||
|
||||
jsr popptr1 ; get buf
|
||||
jsr popax ; get fd and discard
|
||||
L1: inc ptr2
|
||||
L1: dec ptr2
|
||||
bne L2
|
||||
inc ptr2+1
|
||||
dec ptr2+1
|
||||
beq L9
|
||||
L2: ldy #0
|
||||
lda (ptr1),y
|
||||
|
|
|
@ -106,9 +106,9 @@
|
|||
|
||||
; Decrement the count
|
||||
|
||||
@L3: inc ptr2
|
||||
@L3: dec ptr2
|
||||
bne @L0
|
||||
inc ptr2+1
|
||||
dec ptr2+1
|
||||
bne @L0
|
||||
beq done ; Branch always
|
||||
|
||||
|
|
|
@ -21,11 +21,11 @@
|
|||
|
||||
.proc rwcommon
|
||||
|
||||
eor #$FF
|
||||
sta ptr2
|
||||
txa
|
||||
eor #$FF
|
||||
sta ptr2+1 ; Remember -count-1
|
||||
inx
|
||||
stx ptr2+1
|
||||
tax
|
||||
inx
|
||||
stx ptr2 ; Save count with each byte incremented separately
|
||||
|
||||
jsr popptr1 ; Get buf to ptr1, Y=0 by call
|
||||
|
||||
|
|
|
@ -83,9 +83,9 @@
|
|||
|
||||
; Decrement count
|
||||
|
||||
@L2: inc ptr2
|
||||
@L2: dec ptr2
|
||||
bne @L0
|
||||
inc ptr2+1
|
||||
dec ptr2+1
|
||||
bne @L0
|
||||
|
||||
; Wrote all chars or disk full. Close the output channel
|
||||
|
|
|
@ -13,11 +13,11 @@ _memcmp:
|
|||
; Calculate (-count-1) and store it into ptr3. This is some overhead here but
|
||||
; saves time in the compare loop
|
||||
|
||||
eor #$FF
|
||||
sta ptr3
|
||||
txa
|
||||
eor #$FF
|
||||
sta ptr3+1
|
||||
inx
|
||||
stx ptr3+1
|
||||
tax
|
||||
inx
|
||||
stx ptr3 ; Save count with each byte incremented separately
|
||||
|
||||
; Get the pointer parameters
|
||||
|
||||
|
@ -33,7 +33,7 @@ _memcmp:
|
|||
|
||||
; Head of compare loop: Test for the end condition
|
||||
|
||||
Loop: inx ; Bump low byte of (-count-1)
|
||||
Loop: dex ; Bump low byte of (-count-1)
|
||||
beq BumpHiCnt ; Jump on overflow
|
||||
|
||||
; Do the compare
|
||||
|
@ -53,7 +53,7 @@ Comp: lda (ptr1),y
|
|||
; Entry on low counter byte overflow
|
||||
|
||||
BumpHiCnt:
|
||||
inc ptr3+1 ; Bump high byte of (-count-1)
|
||||
dec ptr3+1 ; Bump high byte of (-count-1)
|
||||
bne Comp ; Jump if not done
|
||||
jmp return0 ; Count is zero, areas are identical
|
||||
|
||||
|
@ -67,4 +67,3 @@ NotEqual:
|
|||
Greater:
|
||||
ldx #$01 ; Make result positive
|
||||
rts
|
||||
|
||||
|
|
|
@ -5,17 +5,17 @@
|
|||
; char* strncat (char* dest, const char* src, size_t n);
|
||||
;
|
||||
|
||||
.export _strncat
|
||||
.import popax, popptr1
|
||||
.importzp ptr1, ptr2, ptr3, tmp1, tmp2
|
||||
.macpack cpu
|
||||
.export _strncat
|
||||
.import popax, popptr1
|
||||
.importzp ptr1, ptr2, ptr3, tmp1, tmp2
|
||||
.macpack cpu
|
||||
|
||||
_strncat:
|
||||
eor #$FF ; one's complement to count upwards
|
||||
sta tmp1
|
||||
txa
|
||||
eor #$FF
|
||||
sta tmp2
|
||||
inx
|
||||
stx tmp2
|
||||
tax
|
||||
inx
|
||||
stx tmp1 ; save count with each byte incremented separately
|
||||
|
||||
jsr popptr1 ; get src
|
||||
|
||||
|
@ -49,9 +49,9 @@ L2: sty ptr2
|
|||
L3: ldy #0
|
||||
ldx tmp1 ; low counter byte
|
||||
|
||||
L4: inx
|
||||
L4: dex
|
||||
bne L5
|
||||
inc tmp2
|
||||
dec tmp2
|
||||
beq L6 ; jump if done
|
||||
L5: lda (ptr1),y
|
||||
sta (ptr2),y
|
||||
|
|
|
@ -10,11 +10,11 @@
|
|||
|
||||
.proc _strncpy
|
||||
|
||||
eor #$FF
|
||||
sta tmp1
|
||||
txa
|
||||
eor #$FF
|
||||
sta tmp2 ; Store -size - 1
|
||||
inx
|
||||
stx tmp2
|
||||
tax
|
||||
inx
|
||||
stx tmp1 ; save count with each byte incremented separately
|
||||
|
||||
jsr popptr1 ; get src
|
||||
jsr popax ; get dest
|
||||
|
@ -26,9 +26,9 @@
|
|||
|
||||
ldx tmp1 ; Load low byte of ones complement of size
|
||||
ldy #$00
|
||||
L1: inx
|
||||
L1: dex
|
||||
bne L2
|
||||
inc tmp2
|
||||
dec tmp2
|
||||
beq L9
|
||||
|
||||
L2: lda (ptr1),y ; Copy one character
|
||||
|
@ -42,7 +42,7 @@ L2: lda (ptr1),y ; Copy one character
|
|||
|
||||
; Fill the remaining bytes.
|
||||
|
||||
L3: inx ; Counter low byte
|
||||
L3: dex ; Counter low byte
|
||||
beq L6 ; Branch on overflow
|
||||
L4: sta (ptr2),y ; Clear one byte
|
||||
L5: iny ; Bump pointer
|
||||
|
@ -52,7 +52,7 @@ L5: iny ; Bump pointer
|
|||
|
||||
; Bump the counter high byte
|
||||
|
||||
L6: inc tmp2
|
||||
L6: dec tmp2
|
||||
bne L4
|
||||
|
||||
; Done, return dest
|
||||
|
|
|
@ -15,17 +15,11 @@
|
|||
_strnicmp:
|
||||
_strncasecmp:
|
||||
|
||||
; Convert the given counter value in a/x from a downward counter into an
|
||||
; upward counter, so we can increment the counter in the loop below instead
|
||||
; of decrementing it. This adds some overhead now, but is cheaper than
|
||||
; executing a more complex test in each iteration of the loop. We do also
|
||||
; correct the value by one, so we can do the test on top of the loop.
|
||||
|
||||
eor #$FF
|
||||
sta ptr3
|
||||
txa
|
||||
eor #$FF
|
||||
sta ptr3+1
|
||||
inx
|
||||
stx ptr3+1
|
||||
tax
|
||||
inx
|
||||
stx ptr3 ; save count with each byte incremented separately
|
||||
|
||||
; Get the remaining arguments
|
||||
|
||||
|
@ -40,7 +34,7 @@ _strncasecmp:
|
|||
|
||||
; Start of compare loop. Check the counter.
|
||||
|
||||
Loop: inc ptr3
|
||||
Loop: dec ptr3
|
||||
beq IncHi ; increment high byte
|
||||
|
||||
; Compare a byte from the strings
|
||||
|
@ -79,7 +73,7 @@ L2: ldx tmp1
|
|||
|
||||
; Increment hi byte
|
||||
|
||||
IncHi: inc ptr3+1
|
||||
IncHi: dec ptr3+1
|
||||
bne Comp ; jump if counter not zero
|
||||
|
||||
; Exit code if strings are equal. a/x not set
|
||||
|
|
|
@ -47,12 +47,12 @@ outdesc: ; Static outdesc structure
|
|||
|
||||
out: jsr popax ; count
|
||||
sta ptr2
|
||||
eor #$FF
|
||||
sta outdesc+6
|
||||
txa
|
||||
sta ptr2+1
|
||||
eor #$FF
|
||||
sta outdesc+7
|
||||
stx ptr2+1
|
||||
inx
|
||||
stx outdesc+7
|
||||
tax
|
||||
inx
|
||||
stx outdesc+6
|
||||
|
||||
jsr popptr1 ; buf
|
||||
|
||||
|
@ -74,7 +74,7 @@ out: jsr popax ; count
|
|||
|
||||
; Loop outputting characters
|
||||
|
||||
@L1: inc outdesc+6
|
||||
@L1: dec outdesc+6
|
||||
beq @L4
|
||||
@L2: ldy tmp1
|
||||
lda (ptr1),y
|
||||
|
@ -85,7 +85,7 @@ out: jsr popax ; count
|
|||
jsr _cputc
|
||||
jmp @L1
|
||||
|
||||
@L4: inc outdesc+7
|
||||
@L4: dec outdesc+7
|
||||
bne @L2
|
||||
rts
|
||||
|
||||
|
|
|
@ -94,11 +94,12 @@ _read:
|
|||
; popax - fd, must be == to the above one
|
||||
; return -1+__oserror or number of bytes read
|
||||
|
||||
eor #$ff
|
||||
sta ptr1
|
||||
txa
|
||||
eor #$ff
|
||||
sta ptr1+1 ; -(# of bytes to read)-1
|
||||
inx
|
||||
stx ptr1+1
|
||||
tax
|
||||
inx
|
||||
stx ptr1 ; save count with each byte incremented separately
|
||||
|
||||
jsr popax
|
||||
sta ptr2
|
||||
stx ptr2+1 ; buffer ptr
|
||||
|
@ -152,9 +153,9 @@ _read:
|
|||
beq @done ; yes, we're done
|
||||
jmp __mappederrno ; no, we're screwed
|
||||
|
||||
@L3: inc ptr1 ; decrement the count
|
||||
@L3: dec ptr1 ; decrement the count
|
||||
bne @L0
|
||||
inc ptr1+1
|
||||
dec ptr1+1
|
||||
bne @L0
|
||||
|
||||
@done:
|
||||
|
|
|
@ -50,16 +50,17 @@ LINEDIST = $20 ; Offset in video RAM between two lines
|
|||
ldx #>load_addr
|
||||
sta load
|
||||
stx load+1
|
||||
lda #<load_size
|
||||
eor #$FF
|
||||
sta count ; store (-size - 1)
|
||||
lda #>load_size
|
||||
eor #$FF
|
||||
sta count+1
|
||||
|
||||
L1: inc count ; pre-count one's-complement upwards
|
||||
ldx #<load_size
|
||||
inx
|
||||
stx count
|
||||
ldx #>load_size
|
||||
inx
|
||||
stx count+1 ; save size with each byte incremented separately
|
||||
|
||||
L1: dec count ; pre-count one's-complement upwards
|
||||
bnz L2
|
||||
inc count+1
|
||||
dec count+1
|
||||
bze L3
|
||||
L2: jsr GETCHAR ; (doesn't change .Y)
|
||||
sta (load),y
|
||||
|
|
|
@ -13,11 +13,11 @@
|
|||
sta ptr3
|
||||
stx ptr3+1 ; save count as result
|
||||
|
||||
eor #$FF
|
||||
sta ptr2
|
||||
txa
|
||||
eor #$FF
|
||||
sta ptr2+1 ; remember -count-1
|
||||
inx
|
||||
stx ptr2+1
|
||||
tax
|
||||
inx
|
||||
stx ptr2 ; save count with each byte incremented separately
|
||||
|
||||
jsr popptr1 ; get buf
|
||||
jsr popax ; get fd and discard
|
||||
|
@ -51,9 +51,9 @@ next:
|
|||
rts
|
||||
|
||||
|
||||
L1: inc ptr2
|
||||
L1: dec ptr2
|
||||
bne L2
|
||||
inc ptr2+1
|
||||
dec ptr2+1
|
||||
beq L9
|
||||
L2: ldy #0
|
||||
lda (ptr1),y
|
||||
|
|
Loading…
Add table
Reference in a new issue