Changed most of the library sources to use .CAP instead of .CPU.

This commit is contained in:
Kugel Fuhr
2025-07-01 07:25:32 +02:00
parent f333b300f1
commit c72126e68f
59 changed files with 122 additions and 232 deletions

View File

@@ -11,14 +11,12 @@
.export tosadda0, tosaddax
.importzp c_sp, tmp1
.macpack cpu
tosadda0:
ldx #0
tosaddax:
clc ; (2)
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
adc (c_sp) ; (7)
tay ; (9)

View File

@@ -8,12 +8,10 @@
.import addysp1
.importzp c_sp, ptr4
.macpack cpu
tosanda0:
ldx #$00
tosandax:
.if (.cpu .bitand CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
and (c_sp) ; 65SC02 version, saves 2 cycles and 1 byte
ldy #1
.else

View File

@@ -18,8 +18,6 @@
.import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__
.import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__
.macpack cpu
; --------------------------------------------------------------------------
; Initialize library modules

View File

@@ -7,11 +7,10 @@
.export incax1
.macpack generic
.macpack cpu
.proc incax1
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_INA)
ina ; 65C02 version
bne @L9
.else

View File

@@ -7,8 +7,6 @@
.export popax, incsp2
.importzp c_sp
.macpack cpu
; Pop a/x from stack. This function will run directly into incsp2
.proc popax
@@ -16,7 +14,7 @@
ldy #1
lda (c_sp),y ; get hi byte
tax ; into x
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
lda (c_sp) ; get lo byte
.else
dey

View File

@@ -8,8 +8,6 @@
.import addysp1
.importzp c_sp, sreg, tmp1
.macpack cpu
; EAX = TOS + EAX
tosadd0ax:
@@ -19,7 +17,7 @@ tosadd0ax:
tosaddeax:
clc
.if (.cpu .bitand CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
adc (c_sp) ; 65SC02 version - saves 2 cycles
ldy #1
.else

View File

@@ -11,8 +11,6 @@
.export laddeq1, laddeqa, laddeq
.importzp sreg, ptr1, tmp1
.macpack cpu
laddeq1:
lda #$01
@@ -24,7 +22,7 @@ laddeqa:
laddeq: sty ptr1+1 ; Store high byte of address
clc
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
adc (ptr1)
sta (ptr1)
ldy #$01 ; Address byte 1

View File

@@ -9,10 +9,8 @@
.import addysp1
.importzp c_sp, sreg, tmp1
.macpack cpu
tosand0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_STZ)
stz sreg
stz sreg+1
.else
@@ -22,7 +20,7 @@ tosand0ax:
.endif
tosandeax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
and (c_sp) ; byte 0
ldy #1
.else

View File

@@ -7,8 +7,6 @@
.export ldau00sp, ldau0ysp
.importzp c_sp, ptr1
.macpack cpu
ldau00sp:
ldy #1
ldau0ysp:
@@ -18,7 +16,7 @@ ldau0ysp:
lda (c_sp),y
sta ptr1
ldx #0
.if (.cpu .bitand CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
lda (ptr1) ; Save one cycle for the C02
.else
lda (ptr1,x)

View File

@@ -14,8 +14,6 @@
.import addysp
.importzp c_sp
.macpack cpu
leave00:
lda #0
leave0: ldx #0
@@ -28,7 +26,7 @@ leavey0:
leavey:
jsr addysp ; drop stack frame
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
leave: tay ; save A a sec
lda (c_sp) ; that's the pushed arg size

View File

@@ -11,10 +11,8 @@
.import poplsargs, udiv32, negeax
.importzp sreg, ptr1, ptr2, tmp1, tmp3, tmp4
.macpack cpu
tosmod0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_STZ)
stz sreg
stz sreg+1
.else

View File

@@ -9,11 +9,9 @@
.import addysp1
.importzp c_sp, sreg, tmp1, tmp2, tmp3, tmp4, ptr1, ptr3, ptr4
.macpack cpu
tosmul0ax:
tosumul0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_STZ)
stz sreg
stz sreg+1
.else
@@ -26,7 +24,7 @@ tosmuleax:
tosumuleax:
mul32: sta ptr1
stx ptr1+1 ; op2 now in ptr1/sreg
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
lda (c_sp)
ldy #1
.else

View File

@@ -9,10 +9,8 @@
.import addysp1
.importzp c_sp, sreg, tmp1
.macpack cpu
tosor0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_STZ)
stz sreg
stz sreg+1
.else
@@ -22,7 +20,7 @@ tosor0ax:
.endif
tosoreax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
ora (c_sp)
ldy #1
.else

View File

@@ -9,8 +9,6 @@
.import incsp4
.importzp c_sp, sreg
.macpack cpu
popeax: ldy #3
lda (c_sp),y
sta sreg+1
@@ -20,7 +18,7 @@ popeax: ldy #3
dey
lda (c_sp),y
tax
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
lda (c_sp)
.else
dey

View File

@@ -12,13 +12,11 @@
.import decsp4
.importzp c_sp, sreg
.macpack cpu
pushl0:
lda #0
tax
push0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_STZ)
stz sreg
stz sreg+1
.else
@@ -39,7 +37,7 @@ pusheax:
txa
sta (c_sp),y
pla
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
sta (c_sp)
.else
dey

View File

@@ -12,10 +12,8 @@
.import addysp1
.importzp c_sp, sreg, tmp1
.macpack cpu
tosrsub0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_STZ)
stz sreg
stz sreg+1
.else
@@ -26,7 +24,7 @@ tosrsub0ax:
tosrsubeax:
sec
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
sbc (c_sp)
ldy #1
.else

View File

@@ -11,10 +11,8 @@
.import addysp1
.importzp c_sp, sreg
.macpack cpu
tossub0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_STZ)
stz sreg
stz sreg+1
.else
@@ -26,7 +24,7 @@ tossub0ax:
tossubeax:
sec
eor #$FF
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
adc (c_sp) ; 65SC02 version - saves 2 cycles
ldy #1
.else

View File

@@ -11,8 +11,6 @@
.export lsubeq1, lsubeqa, lsubeq
.importzp sreg, ptr1
.macpack cpu
lsubeq1:
lda #$01
@@ -25,7 +23,7 @@ lsubeq: sty ptr1+1 ; Store high byte of address
sec
eor #$FF
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
adc (ptr1) ; Subtract byte 0
sta (ptr1)
ldy #$01 ; Address byte 1

View File

@@ -9,10 +9,8 @@
.import addysp1
.importzp c_sp, sreg, tmp3, tmp4, ptr1, ptr2, ptr3, ptr4
.macpack cpu
tosudiv0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_STZ)
stz sreg
stz sreg+1
.else
@@ -38,7 +36,7 @@ getlop: sta ptr3 ; Put right operand in place
lda sreg+1
sta ptr4+1
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
lda (c_sp)
ldy #1
.else

View File

@@ -9,10 +9,8 @@
.import getlop, udiv32
.importzp sreg, tmp3, tmp4, ptr2
.macpack cpu
tosumod0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_STZ)
stz sreg
stz sreg+1
.else

View File

@@ -9,10 +9,8 @@
.import addysp1
.importzp c_sp, sreg, tmp1
.macpack cpu
tosxor0ax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_STZ)
stz sreg
stz sreg+1
.else
@@ -22,7 +20,7 @@ tosxor0ax:
.endif
tosxoreax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
eor (c_sp) ; byte 0
ldy #1
.else

View File

@@ -9,12 +9,10 @@
.import addysp1
.importzp c_sp, tmp1
.macpack cpu
tosora0:
ldx #$00
tosorax:
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
ora (c_sp)
ldy #1
.else

View File

@@ -7,11 +7,9 @@
.export popa
.importzp c_sp
.macpack cpu
.proc popa
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
lda (c_sp)
.else
ldy #0 ; (2)

View File

@@ -8,14 +8,12 @@
.import incsp2
.importzp c_sp, ptr1
.macpack cpu
.proc popptr1 ; 14 bytes (four usages = at least 2 bytes saved)
ldy #1
lda (c_sp),y ; get hi byte
sta ptr1+1 ; into ptr hi
dey ; dey even for for 65C02 here to have Y=0 at exit!
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
lda (c_sp) ; get lo byte
.else
lda (c_sp),y ; get lo byte

View File

@@ -8,14 +8,12 @@
.import incsp2
.importzp c_sp, sreg
.macpack cpu
popsreg:
pha ; save A
ldy #1
lda (c_sp),y ; get hi byte
sta sreg+1 ; store it
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
lda (c_sp) ; get lo byte
.else
dey

View File

@@ -7,8 +7,6 @@
.export pusha0sp, pushaysp, pusha
.importzp c_sp
.macpack cpu
; Beware: The optimizer knows about this function!
pusha0sp:

View File

@@ -7,8 +7,6 @@
.export push0, pusha0, pushax
.importzp c_sp
.macpack cpu
push0: lda #0
pusha0: ldx #0
@@ -31,7 +29,7 @@ pusha0: ldx #0
sta (c_sp),y ; (27)
pla ; (31)
dey ; (33)
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
sta (c_sp) ; (37)
.else
sta (c_sp),y ; (38)

View File

@@ -8,8 +8,6 @@
.import pushax
.importzp ptr1
.macpack cpu
pushbidx:
sty ptr1
clc
@@ -19,7 +17,7 @@ pushbidx:
pushb: sta ptr1
stx ptr1+1
ldx #0 ; Load index/high byte
.if (.cpu .bitand CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
lda (ptr1) ; Save one cycle for the C02
.else
lda (ptr1,x)

View File

@@ -9,8 +9,6 @@
.import addysp1
.importzp c_sp, tmp1
.macpack cpu
;
; AX = AX - TOS
;
@@ -19,7 +17,7 @@ tosrsuba0:
ldx #0
tosrsubax:
sec
.if (.cpu .bitand CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
sbc (c_sp)
ldy #1
.else

View File

@@ -15,8 +15,6 @@
.import popax
.importzp tmp1
.macpack cpu
tosshlax:
tosaslax:
sta tmp1 ; Save shift count
@@ -55,7 +53,7 @@ L2: pla
; Shift count is exactly 8
.if (.cpu .bitand CPU_ISET_65SC02)
.if .cap(CPU_HAS_PUSHXY)
L3: plx ; Low byte from stack into X
rts ; A is already zero
.else

View File

@@ -9,8 +9,6 @@
.import incsp2
.importzp c_sp, tmp1, ptr1
.macpack cpu
.proc staxspidx
sty tmp1 ; Save Y
@@ -18,7 +16,7 @@
ldy #1
lda (c_sp),y
sta ptr1+1
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
lda (c_sp)
.else
dey

View File

@@ -21,7 +21,6 @@
; Use macros for better readability
.macpack generic
.macpack cpu
; ----------------------------------------------------------------------------
@@ -39,7 +38,7 @@
lda c_sp+1
sta initialsp+1
sbc #>__STACKSIZE__
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_INA)
ina ; Add 256 bytes safety area
.else
add #1 ; Add 256 bytes safety area

View File

@@ -8,8 +8,6 @@
.import addysp1
.importzp c_sp
.macpack cpu
; AX = TOS - AX
tossuba0:
@@ -17,7 +15,7 @@ tossuba0:
tossubax:
sec
eor #$FF
.if (.cpu .bitand CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
adc (c_sp)
ldy #1
.else

View File

@@ -8,8 +8,6 @@
.export swapstk
.importzp c_sp, ptr4
.macpack cpu
swapstk:
sta ptr4
stx ptr4+1
@@ -18,7 +16,7 @@ swapstk:
tax
lda ptr4+1
sta (c_sp),y
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
lda (c_sp)
tay
lda ptr4

View File

@@ -8,14 +8,12 @@
.import incsp2
.importzp c_sp
.macpack cpu
; Convert TOS from long to int by cutting of the high 16bit
.proc tosint
pha
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
lda (c_sp)
.else
ldy #0

View File

@@ -8,8 +8,6 @@
.import decsp2
.importzp c_sp
.macpack cpu
; Convert TOS from int to long
tosulong:
@@ -17,7 +15,7 @@ tosulong:
jsr decsp2 ; Make room
ldy #2
lda (c_sp),y
.if (.cpu .bitand CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
sta (c_sp) ; 65C02 version
iny ; Y = 3
.else
@@ -43,7 +41,7 @@ toslong:
jsr decsp2 ; Make room
ldy #2
lda (c_sp),y
.if (.cpu .bitand CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
sta (c_sp) ; 65C02 version
iny ; Y = 3
.else

View File

@@ -9,8 +9,6 @@
.include "zeropage.inc"
.macpack cpu
;---------------------------------------------------------------------------
; 8x16 => 24 unsigned multiplication routine. Because the overhead for a
; 8x16 => 16 unsigned multiplication routine is small, we will tag it with
@@ -31,7 +29,7 @@ umul8x16r16:
umul8x16r24m:
umul8x16r16m:
.if (.cpu .bitand ::CPU_ISET_65SC02)
.if .cap(CPU_HAS_STZ)
stz ptr1+1
stz sreg
.else

View File

@@ -9,12 +9,10 @@
.import addysp1
.importzp c_sp, tmp1
.macpack cpu
tosxora0:
ldx #$00
tosxorax:
.if (.cpu .bitand CPU_ISET_65SC02)
.if .cap(CPU_HAS_ZPIND)
eor (c_sp)
ldy #1
.else