From b4163d0e4efe20362a4146ecf923ecf570aaf8db Mon Sep 17 00:00:00 2001 From: cuz Date: Mon, 27 Nov 2000 22:59:03 +0000 Subject: [PATCH] Added some 65C02 code. git-svn-id: svn://svn.cc65.org/cc65/trunk@484 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/runtime/add.s | 17 ++++++---- libsrc/runtime/and.s | 17 ++++++---- libsrc/runtime/condes.s | 7 ++++- libsrc/runtime/incax1.s | 9 ++++-- libsrc/runtime/ldau0sp.s | 6 +++- libsrc/runtime/linc.s | 14 +++++---- libsrc/runtime/pushax.s | 21 +++++++++---- libsrc/runtime/pushb.s | 8 +++-- libsrc/runtime/staxspp.s | 37 +++++++++++++++------- libsrc/runtime/tosint.s | 25 +++++++++------ libsrc/runtime/toslong.s | 68 +++++++++++++++++++++++----------------- 11 files changed, 149 insertions(+), 80 deletions(-) diff --git a/libsrc/runtime/add.s b/libsrc/runtime/add.s index 49c7eca96..b22e16ecc 100644 --- a/libsrc/runtime/add.s +++ b/libsrc/runtime/add.s @@ -13,13 +13,18 @@ tosadda0: ldx #0 tosaddax: - ldy #0 - clc - adc (sp),y ; lo byte + clc +.ifpc02 + adc (sp) ; 65C02 version - saves 2 cycles + ldy #1 +.else + ldy #0 + adc (sp),y ; lo byte + iny +.endif pha ; save it - txa - iny - adc (sp),y ; hi byte + txa + adc (sp),y ; hi byte tax clc lda sp diff --git a/libsrc/runtime/and.s b/libsrc/runtime/and.s index cf1d10ead..2b52c552c 100644 --- a/libsrc/runtime/and.s +++ b/libsrc/runtime/and.s @@ -11,13 +11,18 @@ tosanda0: ldx #$00 tosandax: - ldy #0 +.ifpc02 + and (sp) ; 65C02 version, saves 2 cycles and 1 byte + ldy #1 +.else + ldy #0 and (sp),y - sta ptr4 - iny - txa - and (sp),y + iny +.endif + pha + txa + and (sp),y tax - lda ptr4 + pla jmp addysp1 ; drop TOS, set condition codes diff --git a/libsrc/runtime/condes.s b/libsrc/runtime/condes.s index 51130f404..36940530c 100644 --- a/libsrc/runtime/condes.s +++ b/libsrc/runtime/condes.s @@ -11,6 +11,7 @@ ; libinit and libdone call condes with the predefined module constructor and ; destructor tables, they must be called from the platform specific startup ; code. + ; ; The function does also export jmpvec as general purpose jump vector that ; lies in the data segment so it's address may be patched at runtime. @@ -73,7 +74,11 @@ loop: ldy index sta jmpvec+1 sty index jsr jmpvec - jmp loop +.ifpc02 + bra loop +.else + jmp loop +.endif done: rts diff --git a/libsrc/runtime/incax1.s b/libsrc/runtime/incax1.s index c86cfb96b..8b8b1079a 100644 --- a/libsrc/runtime/incax1.s +++ b/libsrc/runtime/incax1.s @@ -10,8 +10,13 @@ .proc incax1 - add #1 - bcc @L9 +.ifpc02 + ina ; 65C02 version + bne @L9 +.else + add #1 + bcc @L9 +.endif inx @L9: rts diff --git a/libsrc/runtime/ldau0sp.s b/libsrc/runtime/ldau0sp.s index e967f7a82..ff91261c2 100644 --- a/libsrc/runtime/ldau0sp.s +++ b/libsrc/runtime/ldau0sp.s @@ -16,6 +16,10 @@ ldau0ysp: lda (sp),y sta ptr1 ldx #0 - lda (ptr1,x) +.ifpc02 + lda (ptr1) ; Save one cycle for the C02 +.else + lda (ptr1,x) +.endif rts diff --git a/libsrc/runtime/linc.s b/libsrc/runtime/linc.s index 1922a0709..aff3758ee 100644 --- a/libsrc/runtime/linc.s +++ b/libsrc/runtime/linc.s @@ -7,16 +7,18 @@ .export inceaxy .importzp ptr4, sreg -inceaxy: +.proc inceaxy + sty ptr4 clc adc ptr4 - bcc inceax9 + bcc @L9 inx - bne inceax9 + bne @L9 inc sreg - bne inceax9 + bne @L9 inc sreg+1 -inceax9: - rts +@L9: rts + +.endproc diff --git a/libsrc/runtime/pushax.s b/libsrc/runtime/pushax.s index 077c52ca8..24029fe6b 100644 --- a/libsrc/runtime/pushax.s +++ b/libsrc/runtime/pushax.s @@ -21,11 +21,16 @@ pushax: ldy sp beq @L2 dey @L0: sty sp - ldy #0 ; get index - sta (sp),y ; store lo byte - pha ; save it - txa ; get hi byte - iny ; bump idx +.ifpc02 + sta (sp) ; 65C02 version - saves 2 cycles and one byte + ldy #1 ; get hi index +.else + ldy #0 ; get index + sta (sp),y ; store lo byte + iny ; bump idx +.endif + pha ; save it + txa ; get hi byte sta (sp),y ; store hi byte pla ; get A back rts ; done @@ -33,6 +38,10 @@ pushax: ldy sp @L1: dey @L2: dey dec sp+1 +.ifpc02 + bra @L0 +.else jmp @L0 +.endif + - diff --git a/libsrc/runtime/pushb.s b/libsrc/runtime/pushb.s index a0b37faa2..e5a44c777 100644 --- a/libsrc/runtime/pushb.s +++ b/libsrc/runtime/pushb.s @@ -6,7 +6,7 @@ .export pushb, pushbidx .import pushax - .importzp ptr1 + .importzp ptr1 pushbidx: sty ptr1 @@ -17,7 +17,11 @@ pushbidx: pushb: sta ptr1 stx ptr1+1 ldx #0 ; Load index/high byte - lda (ptr1,x) +.ifpc02 + lda (ptr1) ; Save one cycle for the C02 +.else + lda (ptr1,x) +.endif bpl L1 dex ; Make high byte FF L1: jmp pushax diff --git a/libsrc/runtime/staxspp.s b/libsrc/runtime/staxspp.s index 35926fd76..26f19f7be 100644 --- a/libsrc/runtime/staxspp.s +++ b/libsrc/runtime/staxspp.s @@ -1,4 +1,4 @@ -; +; ; Ullrich von Bassewitz, 25.10.2000 ; ; CC65 runtime: Store a/x indirect into address at top of stack @@ -10,18 +10,31 @@ .proc staxspp - ldy #0 +.ifpc02 pha - lda (sp),y - sta ptr1 - iny - lda (sp),y - sta ptr1+1 - txa - sta (ptr1),y - pla - dey - sta (ptr1),y + lda (sp) + sta ptr1 + ldy #1 + lda (sp),y + sta ptr1+1 + txa + sta (ptr1),y + pla + sta (ptr1) +.else + pha + ldy #0 + lda (sp),y + sta ptr1 + iny + lda (sp),y + sta ptr1+1 + txa + sta (ptr1),y + pla + dey + sta (ptr1),y +.endif jmp incsp2 ; Drop address .endproc diff --git a/libsrc/runtime/tosint.s b/libsrc/runtime/tosint.s index aab0dded3..7bbab986e 100644 --- a/libsrc/runtime/tosint.s +++ b/libsrc/runtime/tosint.s @@ -10,15 +10,22 @@ ; Convert TOS from long to int by cutting of the high 16bit -tosint: pha - ldy #0 - lda (sp),y ; sp+1 - ldy #2 - sta (sp),y - ldy #1 - lda (sp),y - ldy #3 - sta (sp),y +.proc tosint + + pha +.ifpc02 + lda (sp) +.else + ldy #0 + lda (sp),y ; sp+1 +.endif + ldy #2 + sta (sp),y + dey + lda (sp),y + ldy #3 + sta (sp),y pla jmp incsp2 ; Drop 16 bit +.endproc diff --git a/libsrc/runtime/toslong.s b/libsrc/runtime/toslong.s index d14915fa5..f26cec121 100644 --- a/libsrc/runtime/toslong.s +++ b/libsrc/runtime/toslong.s @@ -13,40 +13,50 @@ tosulong: pha jsr decsp2 ; Make room - ldy #2 - lda (sp),y - ldy #0 + ldy #2 + lda (sp),y +.ifpc02 + sta (sp) ; 65C02 version + iny ; Y = 3 +.else + ldy #0 sta (sp),y - ldy #3 - lda (sp),y - ldy #1 - sta (sp),y - lda #0 ; Zero extend + ldy #3 +.endif + lda (sp),y + ldy #1 + sta (sp),y + lda #0 ; Zero extend toslong2: - iny - sta (sp),y - iny - sta (sp),y - pla - rts + iny + sta (sp),y + iny + sta (sp),y + pla + rts toslong: pha - jsr decsp2 ; Make room - ldy #2 - lda (sp),y - ldy #0 + jsr decsp2 ; Make room + ldy #2 + lda (sp),y +.ifpc02 + sta (sp) ; 65C02 version + iny ; Y = 3 +.else + ldy #0 sta (sp),y - ldy #3 - lda (sp),y - bmi toslong1 - ldy #1 - sta (sp),y - lda #$00 ; Positive, high word is zero - bne toslong2 + ldy #3 +.endif + lda (sp),y + bmi toslong1 + ldy #1 + sta (sp),y + lda #$00 ; Positive, high word is zero + bne toslong2 toslong1: - ldy #1 - sta (sp),y - lda #$FF - bne toslong2 + ldy #1 + sta (sp),y + lda #$FF + bne toslong2