.include "errno.inc"
+ .macpack cpu
+
; ---------------------------------------------------------------------------
.proc _atexit
ldy exitfunc_index
cpy #exitfunc_max ; Slot available?
- beq @Error ; Jump if no
+ beq @Error ; Jump if no
; Enter the function into the table
lda exitfunc_table,y
sty exitfunc_index
jsr callax ; Call the function
-.ifpc02
+.if (.cpu .bitand ::CPU_ISET_65SC02)
bra doatexit
.else
jmp doatexit ; Next one
@L9: rts
-.endproc
+.endproc
.import _strlen, _malloc, _memcpy
.export _strdup
+ .macpack cpu
.macpack generic
_strdup:
; Since we need some place to store the intermediate results, allocate a
; stack frame. To make this somewhat more efficient, create the stackframe
; as needed for the final call to the memcpy function.
-
+
pha ; decsp will destroy A (but not X)
jsr decsp4 ; Target/source
ldy #1
txa
sta (sp),y
- pla
-.ifpc02
+ pla
+.if (.cpu .bitand CPU_ISET_65SC02)
sta (sp)
.else
dey
.export tosadda0, tosaddax
.importzp sp
+ .macpack cpu
+
tosadda0:
ldx #0
tosaddax:
clc
-.ifpc02
- adc (sp) ; 65C02 version - saves 2 cycles
+.if (.cpu .bitand CPU_ISET_65SC02)
+ adc (sp) ; 65SC02 version - saves 2 cycles
ldy #1
.else
ldy #0
.import addysp1
.importzp sp, ptr4
+ .macpack cpu
+
tosanda0:
ldx #$00
tosandax:
-.ifpc02
- and (sp) ; 65C02 version, saves 2 cycles and 1 byte
+.if (.cpu .bitand CPU_ISET_65SC02)
+ and (sp) ; 65SC02 version, saves 2 cycles and 1 byte
ldy #1
.else
ldy #0
.import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__
.import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__
-
+ .macpack cpu
.code
sta getbyt+1
stx getbyt+2
- sty index
+ sty index
loop: ldy index
beq done
jsr getbyt
sty index
jsr callax
-.ifpc02
+.if (.cpu .bitand ::CPU_ISET_65SC02)
bra loop
.else
jmp loop
.export incax1
.macpack generic
+ .macpack cpu
.proc incax1
-.ifpc02
+.if (.cpu .bitand ::CPU_ISET_65SC02)
ina ; 65C02 version
bne @L9
.else
.export popax, incsp2
.importzp sp
+ .macpack cpu
+
; Pop a/x from stack. This function will run directly into incsp2
.proc popax
ldy #1
- lda (sp),y ; get hi byte
- tax ; into x
-.ifpc02
+ lda (sp),y ; get hi byte
+ tax ; into x
+.if (.cpu .bitand ::CPU_ISET_65SC02)
lda (sp) ; get lo byte
.else
dey
.export ldau00sp, ldau0ysp
.importzp sp, ptr1
+ .macpack cpu
+
ldau00sp:
ldy #1
ldau0ysp:
lda (sp),y
sta ptr1
ldx #0
-.ifpc02
+.if (.cpu .bitand CPU_ISET_65SC02)
lda (ptr1) ; Save one cycle for the C02
.else
lda (ptr1,x)
.export popa
.importzp sp
+ .macpack cpu
+
.proc popa
-.ifpc02
+.if (.cpu .bitand ::CPU_ISET_65SC02)
lda (sp)
.else
ldy #0 ; (2)
.export pusha0sp, pushaysp, pusha
.importzp sp
+ .macpack cpu
+
; Beware: The optimizer knows about this function!
pusha0sp:
pusha: ldy sp ; (3)
beq @L1 ; (6)
dec sp ; (11)
-.ifpc02
+.if (.cpu .bitand CPU_ISET_65SC02)
sta (sp)
.else
ldy #0 ; (13)
.import pushax
.importzp ptr1
+ .macpack cpu
+
pushbidx:
sty ptr1
clc
inx
pushb: sta ptr1
stx ptr1+1
- ldx #0 ; Load index/high byte
-.ifpc02
- lda (ptr1) ; Save one cycle for the C02
+ ldx #0 ; Load index/high byte
+.if (.cpu .bitand CPU_ISET_65SC02)
+ lda (ptr1) ; Save one cycle for the C02
.else
lda (ptr1,x)
.endif
.import addysp1
.importzp sp
-;
+ .macpack cpu
+
; AX = TOS - AX
-;
tossuba0:
ldx #0
tossubax:
sec
eor #$FF
-.ifpc02
+.if (.cpu .bitand CPU_ISET_65SC02)
adc (sp)
ldy #1
.else
.import incsp2
.importzp sp
+ .macpack cpu
+
; Convert TOS from long to int by cutting of the high 16bit
.proc tosint
pha
-.ifpc02
+.if (.cpu .bitand ::CPU_ISET_65SC02)
lda (sp)
.else
ldy #0
.import decsp2
.importzp sp
+ .macpack cpu
+
; Convert TOS from int to long
tosulong:
jsr decsp2 ; Make room
ldy #2
lda (sp),y
-.ifpc02
+.if (.cpu .bitand CPU_ISET_65SC02)
sta (sp) ; 65C02 version
iny ; Y = 3
.else
jsr decsp2 ; Make room
ldy #2
lda (sp),y
-.ifpc02
+.if (.cpu .bitand CPU_ISET_65SC02)
sta (sp) ; 65C02 version
iny ; Y = 3
.else