;
.export _getdevicedir
- .import popax, popa
+ .import popptr1, popa
.include "zeropage.inc"
.include "errno.inc"
stx ptr2+1
; Save buf
- jsr popax
- sta ptr1
- stx ptr1+1
+ jsr popptr1
; Set buf
sta mliparam + MLI::ON_LINE::DATA_BUFFER
.constructor initiobuf
.export iobuf_alloc, iobuf_free
.import __STARTUP_RUN__
- .import incsp2, popax
+ .import incsp2, popptr1
.include "zeropage.inc"
.include "errno.inc"
iobuf_alloc:
; Get and save "memptr"
jsr incsp2
- jsr popax
- sta ptr1
- stx ptr1+1
+ jsr popptr1
; Search table for free entry
ldx #$00
;
.export _lseek
- .import popax
+ .import popax, popptr1
.include "zeropage.inc"
.include "errno.inc"
stx tmp2
; Get and save offset
- jsr popax
- sta ptr1
- stx ptr1+1
+ jsr popptr1
jsr popax
sta ptr2
;
.export rwprolog, rwcommon, rwepilog
- .import popax
+ .import popax, popptr1
.include "zeropage.inc"
.include "errno.inc"
stx ptr2+1
; Get and save buf
- jsr popax
- sta ptr1
- stx ptr1+1
+ jsr popptr1
; Get and process fd
jsr popax
.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
.export __sio_call
.include "atari.inc"
- .import popa,popax
+ .import popa, popax, popptr1
.import sectsizetab,__oserror
.importzp ptr1
sta DAUX1 ; set sector #
stx DAUX2
- jsr popax
- sta ptr1
- stx ptr1+1
+ jsr popptr1
ldy #sst_flag
lda (ptr1),y
.export _read
.constructor initstdin
- .import popax
+ .import popax, popptr1
.importzp ptr1, ptr2, ptr3
.forceimport disable_caps
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
;
.export _write
- .import popax
+ .import popax, popptr1
.importzp ptr1, ptr2, ptr3, tmp1
.include "atmos.inc"
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
.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
.import fnparse, fnadd, fnparsename
.import opencmdchannel, closecmdchannel
.import writefndiskcmd, readdiskerror
- .import popax
+ .import popptr1
.import fncmd, fnunit
.importzp ptr1
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
;
.export __swap
- .import popax
+ .import popax, popptr1
.importzp ptr1, ptr2, ptr3
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
.export _getcwd
- .import popax
+ .import popptr1
.import __cwd
.importzp ptr1, ptr2
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
;
.export _longjmp
- .import popax
+ .import popptr1
.importzp sp, ptr1, ptr2
_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
;
.export _memchr
- .import popax, return0
+ .import popax, popptr1 return0
.importzp ptr1, ptr2
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
;
.export _memcmp
- .import popax, return0
+ .import popax, popptr1, return0
.importzp ptr1, ptr2, ptr3
_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
;
.export _memcpy, memcpy_upwards, memcpy_getparams
- .import popax
+ .import popax, popptr1
.importzp sp, ptr1, ptr2, ptr3
; ----------------------------------------------------------------------
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
;
.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
;
.export _stricmp, _strcasecmp
- .import popax
+ .import popptr1
.import __ctype
.importzp ptr1, ptr2, tmp1
_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
;
.export _strncat
- .import popax
+ .import popax, popptr1
.importzp ptr1, ptr2, ptr3, tmp1, tmp2
.macpack cpu
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
;
.export _strncmp
- .import popax
+ .import popax, popptr1
.importzp ptr1, ptr2, ptr3
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.
;
.export _strncpy
- .import popax
+ .import popptr1
.importzp ptr1, ptr2, tmp1, tmp2, tmp3
.proc _strncpy
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
;
.export _strnicmp, _strncasecmp
- .import popax, __ctype
+ .import popax, popptr1, __ctype
.importzp ptr1, ptr2, ptr3, tmp1
.include "ctype.inc"
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.
;
.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
;
.export _strstr
- .import popax
+ .import popptr1
.importzp ptr1, ptr2, ptr3, ptr4, tmp1
_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
;
.export _vcprintf
- .import pushax, popax
+ .import pushax, popax, popptr1
.import __printf, _cputc
.importzp sp, ptr1, ptr2, ptr3, tmp1
eor #$FF
sta outdesc+7
- jsr popax ; buf
- sta ptr1
- stx ptr1+1
+ jsr popptr1 ; buf
jsr popax ; d
sta ptr3
.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
.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
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
@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
.export _memcpy
.export memcpy_increment, memcpy_transfer, memcpy_getparams
- .import incsp2, popax
+ .import incsp2, popax, popptr1
.importzp sp, ptr1, ptr2, ptr3
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
--- /dev/null
+;
+; 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
+
+
.export steaxspidx
- .import popax
+ .import popptr1
.importzp sreg, ptr1, tmp1, tmp2, tmp3
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
; jede jede@oric.org 2017-01-22
.export _write
- .import popax
+ .import popax, popptr1
.importzp ptr1, ptr2, ptr3, tmp1
.include "telestrat.inc"
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
.include "tgi-kernel.inc"
.importzp ptr1, ptr2, ptr3, ptr4
- .import popax
+ .import popax, popptr1
.proc _tgi_bar
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.
.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
.export _adler32
- .import incsp2, incsp4, popax, popeax
+ .import incsp2, incsp4, popptr1, popeax
.importzp sreg, ptr1, ptr2, tmp1
BASE = 65521 ; largest prime smaller than 65536
@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
.export _crc32
- .import compleax, incsp2, incsp4, popax, popeax
+ .import compleax, incsp2, incsp4, popptr1, popeax
.importzp sreg, ptr1, ptr2, tmp1, tmp2
POLYNOMIAL = $EDB88320
@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