Merge pull request #2674 from GorillaSapiens/c_sp

rename "sp" to "c_sp", avoid conflict with 4510 opcodes
This commit is contained in:
Bob Andrews
2025-06-24 17:44:13 +02:00
committed by GitHub
204 changed files with 915 additions and 912 deletions

View File

@@ -9,7 +9,7 @@
.import _open
.import pushax, incsp4, return0
.importzp sp, ptr1
.importzp c_sp, ptr1
.include "errno.inc"
@@ -28,10 +28,10 @@
; Get a pointer to the mode string
ldy #1
lda (sp),y
lda (c_sp),y
sta ptr1+1
dey
lda (sp),y
lda (c_sp),y
sta ptr1
; Look at the first character in mode
@@ -78,10 +78,10 @@ invmode:
modeok: ldy #$00
txa ; Mode -> A
sta (sp),y
sta (c_sp),y
tya
iny
sta (sp),y
sta (c_sp),y
ldy #4 ; Size of arguments in bytes
jsr _open ; Will cleanup the stack

View File

@@ -6,7 +6,7 @@
.constructor initheap, 24
.import __BSS_RUN__, __BSS_SIZE__, __STACKSIZE__
.importzp sp
.importzp c_sp
.include "_heap.inc"
@@ -31,10 +31,10 @@ ___heaplast:
initheap:
sec
lda sp
lda c_sp
sbc #<__STACKSIZE__
sta ___heapend
lda sp+1
lda c_sp+1
sbc #>__STACKSIZE__
sta ___heapend+1
rts

View File

@@ -20,17 +20,17 @@
; Copy from stack to zeropage. This assumes ptr1 and ptr2 are adjacent.
ldy #3
@L1: lda (sp),y
@L1: lda (c_sp),y
sta ptr1,y
dey
bpl @L1
lda #4
clc
adc sp
sta sp
adc c_sp
sta c_sp
bcc @L2
inc sp+1
inc c_sp+1
@L2: pla ; Old rhs
jmp idiv32by16r16

View File

@@ -338,25 +338,25 @@ MainLoop:
jsr decsp6 ; 3 args
ldy #5
lda OutData+1
sta (sp),y
sta (c_sp),y
dey
lda OutData
sta (sp),y
sta (c_sp),y
dey
lda FSave+1
sta (sp),y
sta (c_sp),y
dey
lda FSave
sta (sp),y
sta (c_sp),y
dey
lda FCount+1
sta (sp),y
sta (c_sp),y
dey
lda FCount
.if (.cpu .bitand ::CPU_ISET_65SC02)
sta (sp)
sta (c_sp)
.else
sta (sp),y
sta (c_sp),y
.endif
jsr CallOutFunc ; Call the output function

View File

@@ -21,17 +21,17 @@
; Copy from stack to zeropage. This assumes ptr1 and ptr2 are adjacent.
ldy #3
@L1: lda (sp),y
@L1: lda (c_sp),y
sta ptr1,y
dey
bpl @L1
lda #4
clc
adc sp
sta sp
adc c_sp
sta c_sp
bcc @L2
inc sp+1
inc c_sp+1
@L2: jmp udiv32by16r16m

View File

@@ -6,7 +6,7 @@
.export _fprintf
.import addysp, decsp4, _vfprintf
.importzp sp, ptr1
.importzp c_sp, ptr1
.macpack generic
@@ -38,9 +38,9 @@ _fprintf:
; Calculate a pointer to the Format argument
lda ParamSize
add sp
add c_sp
sta ptr1
ldx sp+1
ldx c_sp+1
bcc @L1
inx
@L1: stx ptr1+1
@@ -49,7 +49,7 @@ _fprintf:
ldy #4-1
@L2: lda (ptr1),y
sta (sp),y
sta (c_sp),y
dey
bpl @L2

View File

@@ -14,7 +14,7 @@
.import pushwysp
.import tosumulax, tosudivax
.importzp ptr1, sp
.importzp ptr1, c_sp
.include "errno.inc"
.include "_file.inc"
@@ -136,23 +136,23 @@
; to read() by one, so read() starts to store data at buf+1.
.if (.cpu .bitand ::CPU_ISET_65SC02)
lda (sp)
lda (c_sp)
sta ptr1
add #1
sta (sp)
sta (c_sp)
ldy #1
.else
ldy #0
lda (sp),y
lda (c_sp),y
sta ptr1
add #1
sta (sp),y
sta (c_sp),y
iny
.endif
lda (sp),y
lda (c_sp),y
sta ptr1+1
adc #0
sta (sp),y ; ptr1 = buf++;
sta (c_sp),y ; ptr1 = buf++;
; Get the buffered character and place it as first character into the read
; buffer.

View File

@@ -6,7 +6,7 @@
.export _fscanf
.import addysp, decsp4, _vfscanf
.importzp sp, ptr1
.importzp c_sp, ptr1
.macpack generic
@@ -50,9 +50,9 @@ _fscanf:
; Calculate a pointer to the Format argument
lda ParamSize
add sp
add c_sp
sta ptr1
ldx sp+1
ldx c_sp+1
bcc @L1
inx
@L1: stx ptr1+1
@@ -61,7 +61,7 @@ _fscanf:
ldy #4-1
@L2: lda (ptr1),y
sta (sp),y
sta (c_sp),y
dey
bpl @L2

View File

@@ -93,8 +93,8 @@ zpsave: .res zpsavespace
; Set C level interrupt stack
lda irqsp
ldx irqsp+1
sta sp
stx sp+1
sta c_sp
stx c_sp+1
; Call C level interrupt request handler
jsr irqvec

View File

@@ -8,7 +8,7 @@
.export _itoa, _utoa
.import addysp1
.import __hextab
.importzp sp, sreg, ptr2, ptr3, tmp1
.importzp c_sp, sreg, ptr2, ptr3, tmp1
.rodata
specval:
@@ -21,18 +21,18 @@ specval:
dopop: sta tmp1 ; will lose high byte
ldy #0
lda (sp),y
lda (c_sp),y
sta ptr2
sta ptr3
iny
lda (sp),y
lda (c_sp),y
sta ptr2+1
sta ptr3+1
iny
lda (sp),y
lda (c_sp),y
sta sreg
iny
lda (sp),y
lda (c_sp),y
sta sreg+1
jmp addysp1 ; Bump stack pointer

View File

@@ -7,7 +7,7 @@
.export _longjmp
.import popptr1
.importzp sp, ptr1, ptr2
.importzp c_sp, ptr1, ptr2
_longjmp:
sta ptr2 ; Save retval
@@ -23,10 +23,10 @@ _longjmp:
lda (ptr1),y
iny
sta sp
sta c_sp
lda (ptr1),y
iny
sta sp+1
sta c_sp+1
; Get the old stack pointer

View File

@@ -61,7 +61,7 @@
; }
; }
.importzp sp, sreg, regsave, regbank
.importzp c_sp, sreg, regsave, regbank
.importzp tmp1, tmp2, tmp3, tmp4, ptr1, ptr2, ptr3, ptr4
.macpack longbranch
.import memcpy_upwards,pushax,popax

View File

@@ -12,7 +12,7 @@
.export _memcpy, memcpy_upwards, memcpy_getparams
.import popax, popptr1
.importzp sp, ptr1, ptr2, ptr3
.importzp c_sp, ptr1, ptr2, ptr3
; ----------------------------------------------------------------------
_memcpy:
@@ -70,10 +70,10 @@ memcpy_getparams: ; IMPORTANT! Function has to leave with Y=0!
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
lda (c_sp),y
tax
stx ptr2+1 ; save high byte of ptr2
dey ; Y = 0
lda (sp),y ; Get ptr2 low
lda (c_sp),y ; Get ptr2 low
sta ptr2
rts

View File

@@ -17,7 +17,7 @@
.export _memset, _bzero, ___bzero
.import popax
.importzp sp, ptr1, ptr2, ptr3
.importzp c_sp, ptr1, ptr2, ptr3
_bzero:
___bzero:
@@ -36,10 +36,10 @@ _memset:
common: ; Fill value is in X!
ldy #1
lda (sp),y
lda (c_sp),y
sta ptr1+1 ; save high byte of ptr
dey ; Y = 0
lda (sp),y ; Get ptr
lda (c_sp),y ; Get ptr
sta ptr1
lsr ptr3+1 ; divide number of

View File

@@ -6,7 +6,7 @@
.export _printf
.import _stdout, pushax, addysp, _vfprintf
.importzp sp, ptr1
.importzp c_sp, ptr1
.macpack generic
@@ -43,8 +43,8 @@ _printf:
; Now calculate the va_list pointer, which does points to Format
lda sp
ldx sp+1
lda c_sp
ldx c_sp+1
add ParamSize
bcc @L1
inx

View File

@@ -4,7 +4,7 @@
; void* __fastcall__ realloc (void* block, register size_t size)
;
.importzp ptr1, ptr2, ptr3, ptr4, tmp1, tmp2, tmp3, tmp4, sp
.importzp ptr1, ptr2, ptr3, ptr4, tmp1, tmp2, tmp3, tmp4, c_sp
.import _malloc, _memcpy, _free
.import pushax, popptr1, return0
.import incsp2, decsp2

View File

@@ -8,7 +8,7 @@
.export _scanf
.import _stdin, pushax, addysp, _vfscanf
.import sp:zp, ptr1:zp
.import c_sp:zp, ptr1:zp
.macpack generic
@@ -34,8 +34,8 @@ _scanf:
; Now, calculate the va_list pointer, which does point to Format.
lda sp
ldx sp+1
lda c_sp
ldx c_sp+1
add ArgSize
bcc @L1
inx

View File

@@ -8,7 +8,7 @@
.export ___setjmp
.import return0
.importzp sp, ptr1
.importzp c_sp, ptr1
___setjmp:
sta ptr1 ; Save buf
@@ -17,10 +17,10 @@ ___setjmp:
; The parameter stack is now empty, put it into buf
lda sp
lda c_sp
sta (ptr1),y
iny
lda sp+1
lda c_sp+1
sta (ptr1),y
iny

View File

@@ -6,7 +6,7 @@
.export _snprintf
.import pushax, addysp, decsp6, _vsnprintf
.importzp sp, ptr1
.importzp c_sp, ptr1
.macpack generic
@@ -38,9 +38,9 @@ _snprintf:
; Calculate a pointer to the Format argument
lda ParamSize
add sp
add c_sp
sta ptr1
ldx sp+1
ldx c_sp+1
bcc @L1
inx
@L1: stx ptr1+1
@@ -49,7 +49,7 @@ _snprintf:
ldy #6-1
@L2: lda (ptr1),y
sta (sp),y
sta (c_sp),y
dey
bpl @L2

View File

@@ -6,7 +6,7 @@
.export _sprintf
.import pushax, addysp, decsp4, _vsprintf
.importzp sp, ptr1
.importzp c_sp, ptr1
.macpack generic
@@ -38,9 +38,9 @@ _sprintf:
; Calculate a pointer to the Format argument
lda ParamSize
add sp
add c_sp
sta ptr1
ldx sp+1
ldx c_sp+1
bcc @L1
inx
@L1: stx ptr1+1
@@ -49,7 +49,7 @@ _sprintf:
ldy #4-1
@L2: lda (ptr1),y
sta (sp),y
sta (c_sp),y
dey
bpl @L2

View File

@@ -6,7 +6,7 @@
.export _sscanf
.import addysp, decsp4, _vsscanf
.importzp sp, ptr1
.importzp c_sp, ptr1
.macpack generic
@@ -51,9 +51,9 @@ _sscanf:
; Calculate a pointer to the fixed parameters
lda ParamSize
add sp
add c_sp
sta ptr1
ldx sp+1
ldx c_sp+1
bcc @L1
inx
@L1: stx ptr1+1
@@ -62,7 +62,7 @@ _sscanf:
ldy #4-1
@L2: lda (ptr1),y
sta (sp),y
sta (c_sp),y
dey
bpl @L2

View File

@@ -8,7 +8,7 @@
.export _vfprintf
.import push1, pushwysp, incsp6
.import _fwrite, __printf
.importzp sp, ptr1
.importzp c_sp, ptr1
.macpack generic
@@ -121,15 +121,15 @@ _vfprintf:
; exactly as _printf expects it. Parameters will get dropped by _printf.
ldy #2
lda (sp),y ; Low byte of f
lda (c_sp),y ; Low byte of f
sta ptr
lda #<outdesc
sta (sp),y
sta (c_sp),y
iny
lda (sp),y ; High byte of f
lda (c_sp),y ; High byte of f
sta ptr+1
lda #>outdesc
sta (sp),y
sta (c_sp),y
; Restore low byte of ap and call _printf

View File

@@ -61,16 +61,16 @@ _vfscanf:
; Swap f against &d on the stack, placing f into d.data
ldy #2 ; Offset of f on the stack
lda (sp),y
lda (c_sp),y
sta d + SCANFDATA::DATA
lda #<d
sta (sp),y
sta (c_sp),y
iny ; High byte
lda (sp),y
lda (c_sp),y
sta d + SCANFDATA::DATA + 1
lda #>d
sta (sp),y
sta (c_sp),y
; Restore the low byte of ap, and call the _scanf function

View File

@@ -7,7 +7,7 @@
.export _vprintf
.import _vfprintf, _stdout
.import decsp2
.importzp sp
.importzp c_sp
.proc _vprintf
@@ -23,20 +23,20 @@
; Move the format parameter down and store stdout in it's place
ldy #2
lda (sp),y
lda (c_sp),y
ldy #0
sta (sp),y
sta (c_sp),y
ldy #3
lda (sp),y
lda (c_sp),y
ldy #1
sta (sp),y
sta (c_sp),y
iny
lda _stdout
sta (sp),y
sta (c_sp),y
iny
lda _stdout+1
sta (sp),y
sta (c_sp),y
; Restore A

View File

@@ -31,22 +31,22 @@ _vscanf:
; Move the format down
ldy #2
lda (sp),y ; Load byte of format
lda (c_sp),y ; Load byte of format
ldy #0
sta (sp),y
sta (c_sp),y
ldy #3
lda (sp),y
lda (c_sp),y
ldy #1
sta (sp),y
sta (c_sp),y
; Store stdin into the stack frame
iny
lda _stdin
sta (sp),y
sta (c_sp),y
iny
lda _stdin+1
sta (sp),y
sta (c_sp),y
; Restore the low byte of ap and jump to vfscanf, which will cleanup the stack

View File

@@ -8,7 +8,7 @@
.export _vsnprintf, vsnprintf
.import ldaxysp, popax, incsp2, incsp6
.import _memcpy, __printf
.importzp sp, ptr1
.importzp c_sp, ptr1
.include "errno.inc"
@@ -55,19 +55,19 @@ vsnprintf:
; be formatted and counted.
ldy #2
lda (sp),y
lda (c_sp),y
sta ptr1
lda #<outdesc
sta (sp),y
sta (c_sp),y
iny
lda (sp),y
lda (c_sp),y
bmi L9 ; More than $7FFF
sta ptr1+1
lda #>outdesc
sta (sp),y
sta (c_sp),y
; Write size-1 to outdesc.uns. It will be -1 if there is no buffer.
@@ -178,12 +178,12 @@ out:
clc
adc ccount+0
ldy #4
sta (sp),y
sta (c_sp),y
lda bufptr+1
adc ccount+1
iny
sta (sp),y
sta (c_sp),y
; Get Count from stack

View File

@@ -9,7 +9,7 @@
.export _vsscanf
.import popax, __scanf
.importzp sp, ptr1, ptr2
.importzp c_sp, ptr1, ptr2
.macpack generic
@@ -165,15 +165,15 @@ d: .addr get
; to d
ldy #2 ; Stack offset of str
lda (sp),y
lda (c_sp),y
sta sd + SSCANFDATA::STR
lda #<d
sta (sp),y
sta (c_sp),y
iny
lda (sp),y
lda (c_sp),y
sta sd + SSCANFDATA::STR+1
lda #>d
sta (sp),y
sta (c_sp),y
lda #$00
sta sd + SSCANFDATA::INDEX