Improved 65c02 support
git-svn-id: svn://svn.cc65.org/cc65/trunk@2507 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
parent
02d7d8faa7
commit
23c35f27f8
14 changed files with 51 additions and 29 deletions
|
@ -11,13 +11,15 @@
|
||||||
|
|
||||||
.include "errno.inc"
|
.include "errno.inc"
|
||||||
|
|
||||||
|
.macpack cpu
|
||||||
|
|
||||||
; ---------------------------------------------------------------------------
|
; ---------------------------------------------------------------------------
|
||||||
|
|
||||||
.proc _atexit
|
.proc _atexit
|
||||||
|
|
||||||
ldy exitfunc_index
|
ldy exitfunc_index
|
||||||
cpy #exitfunc_max ; Slot available?
|
cpy #exitfunc_max ; Slot available?
|
||||||
beq @Error ; Jump if no
|
beq @Error ; Jump if no
|
||||||
|
|
||||||
; Enter the function into the table
|
; Enter the function into the table
|
||||||
|
|
||||||
|
@ -63,7 +65,7 @@
|
||||||
lda exitfunc_table,y
|
lda exitfunc_table,y
|
||||||
sty exitfunc_index
|
sty exitfunc_index
|
||||||
jsr callax ; Call the function
|
jsr callax ; Call the function
|
||||||
.ifpc02
|
.if (.cpu .bitand ::CPU_ISET_65SC02)
|
||||||
bra doatexit
|
bra doatexit
|
||||||
.else
|
.else
|
||||||
jmp doatexit ; Next one
|
jmp doatexit ; Next one
|
||||||
|
@ -71,7 +73,7 @@
|
||||||
|
|
||||||
@L9: rts
|
@L9: rts
|
||||||
|
|
||||||
.endproc
|
.endproc
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -11,6 +11,7 @@
|
||||||
.import _strlen, _malloc, _memcpy
|
.import _strlen, _malloc, _memcpy
|
||||||
.export _strdup
|
.export _strdup
|
||||||
|
|
||||||
|
.macpack cpu
|
||||||
.macpack generic
|
.macpack generic
|
||||||
|
|
||||||
_strdup:
|
_strdup:
|
||||||
|
@ -18,7 +19,7 @@ _strdup:
|
||||||
; Since we need some place to store the intermediate results, allocate a
|
; Since we need some place to store the intermediate results, allocate a
|
||||||
; stack frame. To make this somewhat more efficient, create the stackframe
|
; stack frame. To make this somewhat more efficient, create the stackframe
|
||||||
; as needed for the final call to the memcpy function.
|
; as needed for the final call to the memcpy function.
|
||||||
|
|
||||||
pha ; decsp will destroy A (but not X)
|
pha ; decsp will destroy A (but not X)
|
||||||
jsr decsp4 ; Target/source
|
jsr decsp4 ; Target/source
|
||||||
|
|
||||||
|
@ -27,8 +28,8 @@ _strdup:
|
||||||
ldy #1
|
ldy #1
|
||||||
txa
|
txa
|
||||||
sta (sp),y
|
sta (sp),y
|
||||||
pla
|
pla
|
||||||
.ifpc02
|
.if (.cpu .bitand CPU_ISET_65SC02)
|
||||||
sta (sp)
|
sta (sp)
|
||||||
.else
|
.else
|
||||||
dey
|
dey
|
||||||
|
|
|
@ -10,12 +10,14 @@
|
||||||
.export tosadda0, tosaddax
|
.export tosadda0, tosaddax
|
||||||
.importzp sp
|
.importzp sp
|
||||||
|
|
||||||
|
.macpack cpu
|
||||||
|
|
||||||
tosadda0:
|
tosadda0:
|
||||||
ldx #0
|
ldx #0
|
||||||
tosaddax:
|
tosaddax:
|
||||||
clc
|
clc
|
||||||
.ifpc02
|
.if (.cpu .bitand CPU_ISET_65SC02)
|
||||||
adc (sp) ; 65C02 version - saves 2 cycles
|
adc (sp) ; 65SC02 version - saves 2 cycles
|
||||||
ldy #1
|
ldy #1
|
||||||
.else
|
.else
|
||||||
ldy #0
|
ldy #0
|
||||||
|
|
|
@ -8,11 +8,13 @@
|
||||||
.import addysp1
|
.import addysp1
|
||||||
.importzp sp, ptr4
|
.importzp sp, ptr4
|
||||||
|
|
||||||
|
.macpack cpu
|
||||||
|
|
||||||
tosanda0:
|
tosanda0:
|
||||||
ldx #$00
|
ldx #$00
|
||||||
tosandax:
|
tosandax:
|
||||||
.ifpc02
|
.if (.cpu .bitand CPU_ISET_65SC02)
|
||||||
and (sp) ; 65C02 version, saves 2 cycles and 1 byte
|
and (sp) ; 65SC02 version, saves 2 cycles and 1 byte
|
||||||
ldy #1
|
ldy #1
|
||||||
.else
|
.else
|
||||||
ldy #0
|
ldy #0
|
||||||
|
|
|
@ -19,7 +19,7 @@
|
||||||
.import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__
|
.import __CONSTRUCTOR_TABLE__, __CONSTRUCTOR_COUNT__
|
||||||
.import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__
|
.import __DESTRUCTOR_TABLE__, __DESTRUCTOR_COUNT__
|
||||||
|
|
||||||
|
.macpack cpu
|
||||||
|
|
||||||
.code
|
.code
|
||||||
|
|
||||||
|
@ -58,7 +58,7 @@
|
||||||
|
|
||||||
sta getbyt+1
|
sta getbyt+1
|
||||||
stx getbyt+2
|
stx getbyt+2
|
||||||
sty index
|
sty index
|
||||||
|
|
||||||
loop: ldy index
|
loop: ldy index
|
||||||
beq done
|
beq done
|
||||||
|
@ -69,7 +69,7 @@ loop: ldy index
|
||||||
jsr getbyt
|
jsr getbyt
|
||||||
sty index
|
sty index
|
||||||
jsr callax
|
jsr callax
|
||||||
.ifpc02
|
.if (.cpu .bitand ::CPU_ISET_65SC02)
|
||||||
bra loop
|
bra loop
|
||||||
.else
|
.else
|
||||||
jmp loop
|
jmp loop
|
||||||
|
|
|
@ -7,10 +7,11 @@
|
||||||
.export incax1
|
.export incax1
|
||||||
|
|
||||||
.macpack generic
|
.macpack generic
|
||||||
|
.macpack cpu
|
||||||
|
|
||||||
.proc incax1
|
.proc incax1
|
||||||
|
|
||||||
.ifpc02
|
.if (.cpu .bitand ::CPU_ISET_65SC02)
|
||||||
ina ; 65C02 version
|
ina ; 65C02 version
|
||||||
bne @L9
|
bne @L9
|
||||||
.else
|
.else
|
||||||
|
|
|
@ -7,14 +7,16 @@
|
||||||
.export popax, incsp2
|
.export popax, incsp2
|
||||||
.importzp sp
|
.importzp sp
|
||||||
|
|
||||||
|
.macpack cpu
|
||||||
|
|
||||||
; Pop a/x from stack. This function will run directly into incsp2
|
; Pop a/x from stack. This function will run directly into incsp2
|
||||||
|
|
||||||
.proc popax
|
.proc popax
|
||||||
|
|
||||||
ldy #1
|
ldy #1
|
||||||
lda (sp),y ; get hi byte
|
lda (sp),y ; get hi byte
|
||||||
tax ; into x
|
tax ; into x
|
||||||
.ifpc02
|
.if (.cpu .bitand ::CPU_ISET_65SC02)
|
||||||
lda (sp) ; get lo byte
|
lda (sp) ; get lo byte
|
||||||
.else
|
.else
|
||||||
dey
|
dey
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
.export ldau00sp, ldau0ysp
|
.export ldau00sp, ldau0ysp
|
||||||
.importzp sp, ptr1
|
.importzp sp, ptr1
|
||||||
|
|
||||||
|
.macpack cpu
|
||||||
|
|
||||||
ldau00sp:
|
ldau00sp:
|
||||||
ldy #1
|
ldy #1
|
||||||
ldau0ysp:
|
ldau0ysp:
|
||||||
|
@ -16,7 +18,7 @@ ldau0ysp:
|
||||||
lda (sp),y
|
lda (sp),y
|
||||||
sta ptr1
|
sta ptr1
|
||||||
ldx #0
|
ldx #0
|
||||||
.ifpc02
|
.if (.cpu .bitand CPU_ISET_65SC02)
|
||||||
lda (ptr1) ; Save one cycle for the C02
|
lda (ptr1) ; Save one cycle for the C02
|
||||||
.else
|
.else
|
||||||
lda (ptr1,x)
|
lda (ptr1,x)
|
||||||
|
|
|
@ -7,9 +7,11 @@
|
||||||
.export popa
|
.export popa
|
||||||
.importzp sp
|
.importzp sp
|
||||||
|
|
||||||
|
.macpack cpu
|
||||||
|
|
||||||
.proc popa
|
.proc popa
|
||||||
|
|
||||||
.ifpc02
|
.if (.cpu .bitand ::CPU_ISET_65SC02)
|
||||||
lda (sp)
|
lda (sp)
|
||||||
.else
|
.else
|
||||||
ldy #0 ; (2)
|
ldy #0 ; (2)
|
||||||
|
|
|
@ -7,6 +7,8 @@
|
||||||
.export pusha0sp, pushaysp, pusha
|
.export pusha0sp, pushaysp, pusha
|
||||||
.importzp sp
|
.importzp sp
|
||||||
|
|
||||||
|
.macpack cpu
|
||||||
|
|
||||||
; Beware: The optimizer knows about this function!
|
; Beware: The optimizer knows about this function!
|
||||||
|
|
||||||
pusha0sp:
|
pusha0sp:
|
||||||
|
@ -16,7 +18,7 @@ pushaysp:
|
||||||
pusha: ldy sp ; (3)
|
pusha: ldy sp ; (3)
|
||||||
beq @L1 ; (6)
|
beq @L1 ; (6)
|
||||||
dec sp ; (11)
|
dec sp ; (11)
|
||||||
.ifpc02
|
.if (.cpu .bitand CPU_ISET_65SC02)
|
||||||
sta (sp)
|
sta (sp)
|
||||||
.else
|
.else
|
||||||
ldy #0 ; (13)
|
ldy #0 ; (13)
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
.import pushax
|
.import pushax
|
||||||
.importzp ptr1
|
.importzp ptr1
|
||||||
|
|
||||||
|
.macpack cpu
|
||||||
|
|
||||||
pushbidx:
|
pushbidx:
|
||||||
sty ptr1
|
sty ptr1
|
||||||
clc
|
clc
|
||||||
|
@ -16,9 +18,9 @@ pushbidx:
|
||||||
inx
|
inx
|
||||||
pushb: sta ptr1
|
pushb: sta ptr1
|
||||||
stx ptr1+1
|
stx ptr1+1
|
||||||
ldx #0 ; Load index/high byte
|
ldx #0 ; Load index/high byte
|
||||||
.ifpc02
|
.if (.cpu .bitand CPU_ISET_65SC02)
|
||||||
lda (ptr1) ; Save one cycle for the C02
|
lda (ptr1) ; Save one cycle for the C02
|
||||||
.else
|
.else
|
||||||
lda (ptr1,x)
|
lda (ptr1,x)
|
||||||
.endif
|
.endif
|
||||||
|
|
|
@ -8,16 +8,16 @@
|
||||||
.import addysp1
|
.import addysp1
|
||||||
.importzp sp
|
.importzp sp
|
||||||
|
|
||||||
;
|
.macpack cpu
|
||||||
|
|
||||||
; AX = TOS - AX
|
; AX = TOS - AX
|
||||||
;
|
|
||||||
|
|
||||||
tossuba0:
|
tossuba0:
|
||||||
ldx #0
|
ldx #0
|
||||||
tossubax:
|
tossubax:
|
||||||
sec
|
sec
|
||||||
eor #$FF
|
eor #$FF
|
||||||
.ifpc02
|
.if (.cpu .bitand CPU_ISET_65SC02)
|
||||||
adc (sp)
|
adc (sp)
|
||||||
ldy #1
|
ldy #1
|
||||||
.else
|
.else
|
||||||
|
|
|
@ -8,12 +8,14 @@
|
||||||
.import incsp2
|
.import incsp2
|
||||||
.importzp sp
|
.importzp sp
|
||||||
|
|
||||||
|
.macpack cpu
|
||||||
|
|
||||||
; Convert TOS from long to int by cutting of the high 16bit
|
; Convert TOS from long to int by cutting of the high 16bit
|
||||||
|
|
||||||
.proc tosint
|
.proc tosint
|
||||||
|
|
||||||
pha
|
pha
|
||||||
.ifpc02
|
.if (.cpu .bitand ::CPU_ISET_65SC02)
|
||||||
lda (sp)
|
lda (sp)
|
||||||
.else
|
.else
|
||||||
ldy #0
|
ldy #0
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
.import decsp2
|
.import decsp2
|
||||||
.importzp sp
|
.importzp sp
|
||||||
|
|
||||||
|
.macpack cpu
|
||||||
|
|
||||||
; Convert TOS from int to long
|
; Convert TOS from int to long
|
||||||
|
|
||||||
tosulong:
|
tosulong:
|
||||||
|
@ -15,7 +17,7 @@ tosulong:
|
||||||
jsr decsp2 ; Make room
|
jsr decsp2 ; Make room
|
||||||
ldy #2
|
ldy #2
|
||||||
lda (sp),y
|
lda (sp),y
|
||||||
.ifpc02
|
.if (.cpu .bitand CPU_ISET_65SC02)
|
||||||
sta (sp) ; 65C02 version
|
sta (sp) ; 65C02 version
|
||||||
iny ; Y = 3
|
iny ; Y = 3
|
||||||
.else
|
.else
|
||||||
|
@ -41,7 +43,7 @@ toslong:
|
||||||
jsr decsp2 ; Make room
|
jsr decsp2 ; Make room
|
||||||
ldy #2
|
ldy #2
|
||||||
lda (sp),y
|
lda (sp),y
|
||||||
.ifpc02
|
.if (.cpu .bitand CPU_ISET_65SC02)
|
||||||
sta (sp) ; 65C02 version
|
sta (sp) ; 65C02 version
|
||||||
iny ; Y = 3
|
iny ; Y = 3
|
||||||
.else
|
.else
|
||||||
|
|
Loading…
Add table
Reference in a new issue