1
0
mirror of https://github.com/cc65/cc65.git synced 2024-12-27 00:29:31 +00:00

Added "popptr1" which is of common use to save some bytes.

This commit is contained in:
IrgendwerA8 2018-05-20 15:30:18 +02:00
parent 3a6430b13d
commit c95ed4b8b5
35 changed files with 113 additions and 151 deletions

View File

@ -5,7 +5,7 @@
;
.export _getdevicedir
.import popax, popa
.import popptr1, popa
.include "zeropage.inc"
.include "errno.inc"
@ -17,9 +17,7 @@ _getdevicedir:
stx ptr2+1
; Save buf
jsr popax
sta ptr1
stx ptr1+1
jsr popptr1
; Set buf
sta mliparam + MLI::ON_LINE::DATA_BUFFER

View File

@ -8,7 +8,7 @@
.constructor initiobuf
.export iobuf_alloc, iobuf_free
.import __STARTUP_RUN__
.import incsp2, popax
.import incsp2, popptr1
.include "zeropage.inc"
.include "errno.inc"
@ -41,9 +41,7 @@ initiobuf:
iobuf_alloc:
; Get and save "memptr"
jsr incsp2
jsr popax
sta ptr1
stx ptr1+1
jsr popptr1
; Search table for free entry
ldx #$00

View File

@ -5,7 +5,7 @@
;
.export _lseek
.import popax
.import popax, popptr1
.include "zeropage.inc"
.include "errno.inc"
@ -18,9 +18,7 @@ _lseek:
stx tmp2
; Get and save offset
jsr popax
sta ptr1
stx ptr1+1
jsr popptr1
jsr popax
sta ptr2

View File

@ -3,7 +3,7 @@
;
.export rwprolog, rwcommon, rwepilog
.import popax
.import popax, popptr1
.include "zeropage.inc"
.include "errno.inc"
@ -17,9 +17,7 @@ rwprolog:
stx ptr2+1
; Get and save buf
jsr popax
sta ptr1
stx ptr1+1
jsr popptr1
; Get and process fd
jsr popax

View File

@ -17,16 +17,14 @@
.export _dio_log_to_phys
.include "atari.inc"
.importzp ptr1,ptr2,ptr3
.import popax,__oserror
.import popax, popptr1, __oserror
.proc _dio_log_to_phys
sta ptr2
stx ptr2+1 ; pointer to output structure
jsr popax
sta ptr1
stx ptr1+1 ; save pointer to input data
jsr popptr1 ; save pointer to input data
jsr popax
sta ptr3

View File

@ -16,7 +16,7 @@
.export __sio_call
.include "atari.inc"
.import popa,popax
.import popa, popax, popptr1
.import sectsizetab,__oserror
.importzp ptr1
@ -31,9 +31,7 @@
sta DAUX1 ; set sector #
stx DAUX2
jsr popax
sta ptr1
stx ptr1+1
jsr popptr1
ldy #sst_flag
lda (ptr1),y

View File

@ -9,7 +9,7 @@
.export _read
.constructor initstdin
.import popax
.import popax, popptr1
.importzp ptr1, ptr2, ptr3
.forceimport disable_caps
@ -26,9 +26,7 @@
eor #$FF
sta ptr2+1 ; Remember -count-1
jsr popax ; get buf
sta ptr1
stx ptr1+1
jsr popptr1 ; get buf
jsr popax ; get fd and discard
L1: inc ptr2

View File

@ -7,7 +7,7 @@
;
.export _write
.import popax
.import popax, popptr1
.importzp ptr1, ptr2, ptr3, tmp1
.include "atmos.inc"
@ -23,9 +23,7 @@
eor #$FF
sta ptr2+1 ; Remember -count-1
jsr popax ; get buf
sta ptr1
stx ptr1+1
jsr popptr1 ; get buf
jsr popax ; get fd and discard
L1: inc ptr2
bne L2

View File

@ -6,16 +6,14 @@
.export _cbm_k_save
.import SAVE
.import popax
.import popptr1
.importzp ptr1, tmp1
_cbm_k_save:
sta tmp1 ; store end address
stx tmp1+1
jsr popax ; pop start address
sta ptr1
stx ptr1+1
jsr popptr1 ; pop start address
lda #ptr1
ldx tmp1
ldy tmp1+1

View File

@ -9,7 +9,7 @@
.import fnparse, fnadd, fnparsename
.import opencmdchannel, closecmdchannel
.import writefndiskcmd, readdiskerror
.import popax
.import popptr1
.import fncmd, fnunit
.importzp ptr1
@ -26,10 +26,8 @@
lda #'='
jsr fnadd
jsr popax
sta ptr1
stx ptr1+1
ldy #0
jsr popptr1
; ldy #0 Y=0 guaranteed by popptr1
jsr fnparsename ; Parse second filename
bne done

View File

@ -5,7 +5,7 @@
;
.export __swap
.import popax
.import popax, popptr1
.importzp ptr1, ptr2, ptr3
@ -19,13 +19,11 @@ __swap: eor #$FF
sta ptr2
stx ptr2+1
jsr popax ; Get p
sta ptr1
stx ptr1+1
jsr popptr1 ; Get p
; Prepare for swap
ldy #$00
; ldy #$00 is guaranteed by popptr1
; Swap loop

View File

@ -6,7 +6,7 @@
.export _getcwd
.import popax
.import popptr1
.import __cwd
.importzp ptr1, ptr2
@ -25,13 +25,11 @@
eor #$FF
sta ptr2+1
jsr popax ; Get buf
sta ptr1
stx ptr1+1 ; Save buf
jsr popptr1 ; Get buf to ptr1
; Copy __cwd to the given buffer checking the length
ldy #$00
; ldy #$00 is guaranteed by popptr10
loop: inc ptr2
bne @L1
inc ptr2+1

View File

@ -6,7 +6,7 @@
;
.export _longjmp
.import popax
.import popptr1
.importzp sp, ptr1, ptr2
_longjmp:
@ -16,10 +16,8 @@ _longjmp:
bne @L1
inc ptr2 ; 0 is illegal, according to the standard ...
; ... and, must be replaced by 1
@L1: jsr popax ; get buf
sta ptr1
stx ptr1+1
ldy #0
@L1: jsr popptr1 ; get buf
; ldy #0 is guaranteed by popptr1
; Get the old parameter stack

View File

@ -5,7 +5,7 @@
;
.export _memchr
.import popax, return0
.import popax, popptr1 return0
.importzp ptr1, ptr2
@ -18,11 +18,10 @@
sta ptr2+1 ; Save ones complement of n
jsr popax ; get c
pha
jsr popax ; get p
sta ptr1
stx ptr1+1
ldy #$00
jsr popptr1 ; get p
; ldy #$00 is guaranteed by popptr1
pla ; Get c
ldx ptr2 ; Use X as low counter byte

View File

@ -5,7 +5,7 @@
;
.export _memcmp
.import popax, return0
.import popax, popptr1, return0
.importzp ptr1, ptr2, ptr3
_memcmp:
@ -24,14 +24,12 @@ _memcmp:
jsr popax ; Get p2
sta ptr2
stx ptr2+1
jsr popax ; Get p1
sta ptr1
stx ptr1+1
jsr popptr1 ; Get p1
; Loop initialization
;ldy #$00 ; Initialize pointer (Y=0 guaranteed by popptr1)
ldx ptr3 ; Load low counter byte into X
ldy #$00 ; Initialize pointer
; Head of compare loop: Test for the end condition

View File

@ -11,7 +11,7 @@
;
.export _memcpy, memcpy_upwards, memcpy_getparams
.import popax
.import popax, popptr1
.importzp sp, ptr1, ptr2, ptr3
; ----------------------------------------------------------------------
@ -64,12 +64,11 @@ memcpy_getparams: ; IMPORTANT! Function has to leave with Y=0!
sta ptr3
stx ptr3+1 ; save n to ptr3
jsr popax
sta ptr1
stx ptr1+1 ; save src to ptr1
jsr popptr1 ; save src to ptr1
; save dest to ptr2
ldy #1 ; (direct stack access is three cycles faster
iny ; Y=0 guaranteed by popptr1, we need '1' here...
; (direct stack access is three cycles faster
; (total cycle count with return))
lda (sp),y
tax

View File

@ -5,16 +5,14 @@
;
.export _strcmp
.import popax
.import popptr1
.importzp ptr1, ptr2
_strcmp:
sta ptr2 ; Save s2
stx ptr2+1
jsr popax ; Get s1
sta ptr1
stx ptr1+1
ldy #0
jsr popptr1 ; Get s1
;ldy #0 ; Y=0 guaranteed by popptr1
loop: lda (ptr1),y
cmp (ptr2),y

View File

@ -6,7 +6,7 @@
;
.export _stricmp, _strcasecmp
.import popax
.import popptr1
.import __ctype
.importzp ptr1, ptr2, tmp1
@ -16,10 +16,8 @@ _stricmp:
_strcasecmp:
sta ptr2 ; Save s2
stx ptr2+1
jsr popax ; get s1
sta ptr1
stx ptr1+1
ldy #0
jsr popptr1 ; get s1
; ldy #0 ; Y=0 guaranteed by popptr1
loop: lda (ptr2),y ; get char from second string
tax

View File

@ -6,7 +6,7 @@
;
.export _strncat
.import popax
.import popax, popptr1
.importzp ptr1, ptr2, ptr3, tmp1, tmp2
.macpack cpu
@ -17,9 +17,7 @@ _strncat:
eor #$FF
sta tmp2
jsr popax ; get src
sta ptr1
stx ptr1+1
jsr popptr1 ; get src
jsr popax ; get dest
sta ptr3 ; remember for function return

View File

@ -5,7 +5,7 @@
;
.export _strncmp
.import popax
.import popax, popptr1
.importzp ptr1, ptr2, ptr3
@ -28,13 +28,11 @@ _strncmp:
jsr popax ; get s2
sta ptr2
stx ptr2+1
jsr popax ; get s1
sta ptr1
stx ptr1+1
jsr popptr1 ; get s1
; Loop setup
ldy #0
;ldy #0 Y=0 guaranteed by popptr1
; Start of compare loop. Check the counter.

View File

@ -5,7 +5,7 @@
;
.export _strncpy
.import popax
.import popptr1
.importzp ptr1, ptr2, tmp1, tmp2, tmp3
.proc _strncpy
@ -16,9 +16,7 @@
eor #$FF
sta tmp2 ; Store -size - 1
jsr popax ; get src
sta ptr1
stx ptr1+1
jsr popptr1 ; get src
jsr popax ; get dest
sta ptr2
stx ptr2+1

View File

@ -7,7 +7,7 @@
;
.export _strnicmp, _strncasecmp
.import popax, __ctype
.import popax, popptr1, __ctype
.importzp ptr1, ptr2, ptr3, tmp1
.include "ctype.inc"
@ -32,13 +32,11 @@ _strncasecmp:
jsr popax ; get s2
sta ptr2
stx ptr2+1
jsr popax ; get s1
sta ptr1
stx ptr1+1
jsr popptr1 ; get s1
; Loop setup
ldy #0
; ldy #0 Y=0 guaranteed by popptr1
; Start of compare loop. Check the counter.

View File

@ -5,17 +5,15 @@
;
.export _strpbrk
.import popax, return0
.import popax, popptr1, return0
.importzp ptr1, ptr2, tmp1, tmp2, tmp3
_strpbrk:
jsr popax ; get s2
sta ptr2
stx ptr2+1
jsr popax ; get s1
sta ptr1
stx ptr1+1
ldy #$00
jsr popptr1 ; get s1
; ldy #$00 Y=0 guaranteed by popptr1
L1: lda (ptr1),y ; get next char from s1
beq L9 ; jump if done

View File

@ -5,7 +5,7 @@
;
.export _strstr
.import popax
.import popptr1
.importzp ptr1, ptr2, ptr3, ptr4, tmp1
_strstr:
@ -13,13 +13,11 @@ _strstr:
stx ptr2+1
sta ptr4 ; Setup temp copy for later
jsr popax ; Get haystack
sta ptr1
stx ptr1+1 ; Save haystack
jsr popptr1 ; Get haystack to ptr1
; If needle is empty, return haystack
ldy #$00
; ldy #$00 Y=0 guaranteed by popptr1
lda (ptr2),y ; Get first byte of needle
beq @Found ; Needle is empty --> we're done

View File

@ -5,7 +5,7 @@
;
.export _vcprintf
.import pushax, popax
.import pushax, popax, popptr1
.import __printf, _cputc
.importzp sp, ptr1, ptr2, ptr3, tmp1
@ -54,9 +54,7 @@ out: jsr popax ; count
eor #$FF
sta outdesc+7
jsr popax ; buf
sta ptr1
stx ptr1+1
jsr popptr1 ; buf
jsr popax ; d
sta ptr3

View File

@ -6,7 +6,7 @@
.export _DbgInit
.export _DbgSP, _DbgCS, _DbgHI
.import popax, return0, _DbgEntry, _set_brk, _end_brk
.import popptr1, return0, _DbgEntry, _set_brk, _end_brk
.import _DbgBreaks
.import _brk_pc
.import __ZP_START__ ; Linker generated
@ -170,9 +170,7 @@ L12: ldy #1 ; Force != 0
.export _DbgIsBreak
_DbgIsBreak:
jsr popax ; Get address
sta ptr1
stx ptr1+1
jsr popptr1 ; Get address
ldx #0
L20: lda _DbgBreaks+3,x ; Get bk_use
beq L21 ; Jump if not set

View File

@ -13,7 +13,7 @@
FILEDES = 3 ; first free to use file descriptor
.importzp ptr1, ptr2, ptr3, tmp1
.import addysp, popax
.import addysp, popax, poptr1
.import __oserror
.import _FindFile, _ReadByte
.export _open, _close, _read
@ -37,9 +37,7 @@ _open:
@parmok:
jsr popax ; Get flags
sta tmp1
jsr popax ; Get name
sta ptr1
stx ptr1+1
jsr popptr1 ; Get name
lda filedesc ; is there a file already open?
bne @alreadyopen

View File

@ -17,7 +17,7 @@
.export _memcpy
.export memcpy_increment, memcpy_transfer, memcpy_getparams
.import incsp2, popax
.import incsp2, popax, popptr1
.importzp sp, ptr1, ptr2, ptr3
@ -81,13 +81,11 @@ memcpy_getparams:
jsr incsp2 ; drop src address
jmp popax ; get pointer; return it as result
@L1: jsr popax
sta ptr1
stx ptr1+1 ; save src
@L1: jsr popptr1 ; save src
; (Direct stack access is six cycles faster [total cycle count].)
ldy #1 ; save dest
iny ; (Y=0 by popptr1, need '1' here) save dest
lda (sp),y ; get high byte
tax
lda (sp) ; get low byte

29
libsrc/runtime/popptr1.s Normal file
View File

@ -0,0 +1,29 @@
;
; Christian Kruger, 20-May-2018
;
; CC65 runtime: Pop registers on stack to ptr1 or ptr2 and ptr1.
; X is untouched, low byte in A, Y is defined to be 0!
.export popptr1
.import incsp2
.importzp sp, ptr1
.macpack cpu
.proc popptr1 ; 14 bytes,
ldy #1
lda (sp),y ; get hi byte
sta ptr+1 ; into ptr hi
dey ; note: apply even for 65C02 to have Y=0 at exit!
.if (.cpu .bitand ::CPU_ISET_65SC02)
lda (sp) ; get lo byte
.else
lda (sp),y ; get lo byte
.endif
sta ptr1 ; to ptr lo
jmp incsp2
.endproc

View File

@ -6,7 +6,7 @@
.export steaxspidx
.import popax
.import popptr1
.importzp sreg, ptr1, tmp1, tmp2, tmp3
@ -15,9 +15,7 @@
sta tmp1
stx tmp2
sty tmp3
jsr popax ; get the pointer
sta ptr1
stx ptr1+1
jsr popptr1 ; get the pointer
ldy tmp3
lda tmp1
sta (ptr1),y

View File

@ -2,7 +2,7 @@
; jede jede@oric.org 2017-01-22
.export _write
.import popax
.import popax, popptr1
.importzp ptr1, ptr2, ptr3, tmp1
.include "telestrat.inc"
@ -19,9 +19,7 @@
eor #$FF
sta ptr2+1 ; Remember -count-1
jsr popax ; get buf
sta ptr1
stx ptr1+1
jsr popptr1 ; get buf
jsr popax ; get fd and discard
; if fd=0001 then it stdout

View File

@ -8,7 +8,7 @@
.include "tgi-kernel.inc"
.importzp ptr1, ptr2, ptr3, ptr4
.import popax
.import popax, popptr1
.proc _tgi_bar
@ -24,9 +24,7 @@
sta ptr2 ; Y1
stx ptr2+1
jsr popax
sta ptr1 ; X1
stx ptr1+1
jsr popptr1 ; X1
; Make sure X1 is less than X2. Swap both if not.

View File

@ -6,17 +6,14 @@
.include "tgi-kernel.inc"
.import popax
.import popptr1
.importzp ptr1, ptr2
.proc tgi_popxy
sta ptr2 ; Y
stx ptr2+1
jsr popax
sta ptr1 ; X
stx ptr1+1
rts
jmp popptr1 ; X
.endproc

View File

@ -7,7 +7,7 @@
.export _adler32
.import incsp2, incsp4, popax, popeax
.import incsp2, incsp4, popptr1, popeax
.importzp sreg, ptr1, ptr2, tmp1
BASE = 65521 ; largest prime smaller than 65536
@ -20,9 +20,7 @@ _adler32:
@L1: sta ptr2
stx ptr2+1
; ptr1 = buf
jsr popax
sta ptr1
stx ptr1+1
jsr popptr1
; if (buf == NULL) return 1L;
ora ptr1+1
beq @L0

View File

@ -7,7 +7,7 @@
.export _crc32
.import compleax, incsp2, incsp4, popax, popeax
.import compleax, incsp2, incsp4, popptr1, popeax
.importzp sreg, ptr1, ptr2, tmp1, tmp2
POLYNOMIAL = $EDB88320
@ -67,9 +67,7 @@ _crc32:
@L1: sta ptr2
stx ptr2+1
; ptr1 = buf
jsr popax
sta ptr1
stx ptr1+1
jsr popptr1
; if (buf == NULL) return 0;
ora ptr1+1
beq @L0