From 5fc15a7a60f16c239c01663be52c48fb20ad1e4f Mon Sep 17 00:00:00 2001 From: mrdudz Date: Mon, 23 Jun 2025 17:09:06 +0200 Subject: [PATCH 01/27] test #2674 --- asminc/zeropage.inc | 2 +- doc/atari.sgml | 2 +- doc/ca65.sgml | 6 +- doc/cc65-intern.sgml | 12 +- doc/customizing.sgml | 4 +- doc/sim65.sgml | 2 +- libsrc/agat/crt0.s | 8 +- libsrc/apple2/callmain.s | 2 +- libsrc/apple2/crt0.s | 6 +- libsrc/apple2/exec.s | 4 +- libsrc/apple2/filename.s | 14 +- libsrc/apple2/mli_file_info_direct.s | 4 +- libsrc/apple2/mou/a2.stdmou.s | 4 +- libsrc/apple2/open.s | 4 +- libsrc/apple2/syschdir.s | 4 +- libsrc/apple2/sysmkdir.s | 4 +- libsrc/apple2/sysremove.s | 4 +- libsrc/apple2/sysrename.s | 8 +- libsrc/atari/crt0.s | 8 +- libsrc/atari/diopncls.s | 8 +- libsrc/atari/fdtable.s | 4 +- libsrc/atari/mcbpm.s | 14 +- libsrc/atari/mou/atrjoy.s | 4 +- libsrc/atari/mou/atrst.s | 4 +- libsrc/atari/mou/atrtt.s | 4 +- libsrc/atari/sysrename.s | 22 ++-- libsrc/atari/ucase_fn.s | 12 +- libsrc/atari2600/crt0.s | 4 +- libsrc/atari5200/crt0.s | 4 +- libsrc/atari7800/crt0.s | 4 +- libsrc/atari7800/mono_setcursor.s | 2 +- libsrc/atari7800/setcursor.s | 2 +- libsrc/atmos/crt0.s | 8 +- libsrc/c128/crt0.s | 8 +- libsrc/c128/mou/c128-1351.s | 4 +- libsrc/c128/mou/c128-inkwell.s | 4 +- libsrc/c128/mou/c128-joy.s | 4 +- libsrc/c128/mou/c128-pot.s | 4 +- libsrc/c16/crt0.s | 8 +- libsrc/c64/crt0.s | 8 +- libsrc/c64/mou/c64-1351.s | 4 +- libsrc/c64/mou/c64-inkwell.s | 4 +- libsrc/c64/mou/c64-joy.s | 4 +- libsrc/c64/mou/c64-pot.s | 4 +- libsrc/cbm/dir.s | 8 +- libsrc/cbm/open.s | 2 +- libsrc/cbm/write.s | 2 +- libsrc/cbm510/crt0.s | 12 +- libsrc/cbm510/mou/cbm510-inkwl.s | 4 +- libsrc/cbm510/mou/cbm510-joy.s | 4 +- libsrc/cbm610/crt0.s | 12 +- libsrc/common/_fopen.s | 10 +- libsrc/common/_heap.s | 6 +- libsrc/common/_idiv32by16r16.s | 8 +- libsrc/common/_printf.s | 14 +- libsrc/common/_udiv32by16r16.s | 8 +- libsrc/common/fprintf.s | 8 +- libsrc/common/fread.s | 14 +- libsrc/common/fscanf.s | 8 +- libsrc/common/interrupt.s | 4 +- libsrc/common/itoa.s | 10 +- libsrc/common/longjmp.s | 6 +- libsrc/common/lz4.s | 2 +- libsrc/common/memcpy.s | 6 +- libsrc/common/memset.s | 6 +- libsrc/common/printf.s | 6 +- libsrc/common/realloc.s | 2 +- libsrc/common/scanf.s | 6 +- libsrc/common/setjmp.s | 6 +- libsrc/common/snprintf.s | 8 +- libsrc/common/sprintf.s | 8 +- libsrc/common/sscanf.s | 8 +- libsrc/common/vfprintf.s | 10 +- libsrc/common/vfscanf.s | 8 +- libsrc/common/vprintf.s | 14 +- libsrc/common/vscanf.s | 12 +- libsrc/common/vsnprintf.s | 14 +- libsrc/common/vsscanf.s | 10 +- libsrc/conio/cprintf.s | 6 +- libsrc/conio/cscanf.s | 4 +- libsrc/conio/vcprintf.s | 10 +- libsrc/creativision/crt0.s | 4 +- libsrc/cx16/crt0.s | 4 +- libsrc/cx16/mou/cx16-std.s | 4 +- libsrc/dbg/dbgdump.s | 12 +- libsrc/dbg/dbgsupp.s | 8 +- libsrc/gamate/crt0.s | 4 +- libsrc/geos-common/drivers/geos-stdmou.s | 12 +- libsrc/geos-common/system/crt0.s | 6 +- libsrc/kim1/crt0.s | 4 +- libsrc/lynx/crt0.s | 4 +- libsrc/lynx/lseek.s | 2 +- libsrc/nes/crt0.s | 4 +- libsrc/none/crt0.s | 4 +- libsrc/osic1p/crt0.s | 4 +- libsrc/pce/_printf.s | 12 +- libsrc/pce/crt0.s | 6 +- libsrc/pce/memcpy.s | 6 +- libsrc/pet/crt0.s | 8 +- libsrc/plus4/crt0.s | 8 +- libsrc/rp6502/crt0.s | 4 +- libsrc/rp6502/ria.s | 2 +- libsrc/rp6502/xreg.s | 6 +- libsrc/runtime/add.s | 24 ++-- libsrc/runtime/addeqsp.s | 10 +- libsrc/runtime/addysp.s | 8 +- libsrc/runtime/and.s | 8 +- libsrc/runtime/bpushbsp.s | 4 +- libsrc/runtime/decsp1.s | 8 +- libsrc/runtime/decsp2.s | 8 +- libsrc/runtime/decsp3.s | 8 +- libsrc/runtime/decsp4.s | 8 +- libsrc/runtime/decsp5.s | 8 +- libsrc/runtime/decsp6.s | 8 +- libsrc/runtime/decsp7.s | 8 +- libsrc/runtime/decsp8.s | 8 +- libsrc/runtime/enter.s | 10 +- libsrc/runtime/eq.s | 2 +- libsrc/runtime/icmp.s | 14 +- libsrc/runtime/incsp1.s | 6 +- libsrc/runtime/incsp2.s | 16 +-- libsrc/runtime/ladd.s | 12 +- libsrc/runtime/laddeqsp.s | 18 +-- libsrc/runtime/land.s | 12 +- libsrc/runtime/lcmp.s | 10 +- libsrc/runtime/ldau0sp.s | 6 +- libsrc/runtime/ldauisp.s | 6 +- libsrc/runtime/ldaxsp.s | 6 +- libsrc/runtime/ldeaxysp.s | 10 +- libsrc/runtime/leaaxsp.s | 6 +- libsrc/runtime/leave.s | 18 +-- libsrc/runtime/lmul.s | 12 +- libsrc/runtime/lor.s | 12 +- libsrc/runtime/lpop.s | 12 +- libsrc/runtime/lpush.s | 12 +- libsrc/runtime/lrsub.s | 12 +- libsrc/runtime/lsub.s | 12 +- libsrc/runtime/lsubeqsp.s | 18 +-- libsrc/runtime/ludiv.s | 12 +- libsrc/runtime/lxor.s | 12 +- libsrc/runtime/or.s | 8 +- libsrc/runtime/popa.s | 10 +- libsrc/runtime/popptr1.s | 8 +- libsrc/runtime/popsreg.s | 8 +- libsrc/runtime/pusha.s | 16 +-- libsrc/runtime/pushax.s | 14 +- libsrc/runtime/pushbsp.s | 4 +- libsrc/runtime/pushlysp.s | 10 +- libsrc/runtime/pushwsp.s | 16 +-- libsrc/runtime/regswap.s | 6 +- libsrc/runtime/regswap1.s | 6 +- libsrc/runtime/regswap2.s | 10 +- libsrc/runtime/rsub.s | 8 +- libsrc/runtime/staspidx.s | 6 +- libsrc/runtime/staxsp.s | 8 +- libsrc/runtime/staxspi.s | 8 +- libsrc/runtime/steaxsp.s | 12 +- libsrc/runtime/stkchk.s | 14 +- libsrc/runtime/sub.s | 8 +- libsrc/runtime/subeqsp.s | 10 +- libsrc/runtime/subysp.s | 8 +- libsrc/runtime/swap.s | 14 +- libsrc/runtime/tosint.s | 12 +- libsrc/runtime/toslong.s | 26 ++-- libsrc/runtime/xor.s | 8 +- libsrc/runtime/zeropage.s | 2 +- libsrc/sim6502/crt0.s | 4 +- libsrc/sim6502/exehdr.s | 4 +- libsrc/supervision/crt0.s | 4 +- libsrc/sym1/crt0.s | 4 +- libsrc/telestrat/crt0.s | 8 +- libsrc/telestrat/open.s | 2 +- libsrc/telestrat/wherex.s | 2 +- libsrc/tgi/tgi_outtextxy.s | 10 +- libsrc/vic20/crt0.s | 8 +- libsrc/zlib/inflatemem.s | 10 +- samples/getsp.s | 6 +- samples/tinyshell.c | 12 +- src/cc65/codegen.c | 155 ++++++++++++----------- src/cc65/codeinfo.c | 4 +- src/cc65/codeinfo.h | 6 +- src/cc65/codeopt.c | 2 +- src/cc65/codeoptutil.c | 22 ++-- src/cc65/coptadd.c | 60 ++++----- src/cc65/coptadd.h | 20 +-- src/cc65/coptbool.c | 12 +- src/cc65/coptcmp.c | 16 +-- src/cc65/coptcmp.h | 4 +- src/cc65/coptmisc.c | 22 ++-- src/cc65/coptptrload.c | 10 +- src/cc65/coptptrload.h | 8 +- src/cc65/coptptrstore.c | 12 +- src/cc65/coptptrstore.h | 10 +- src/cc65/coptstop.c | 6 +- src/cc65/coptstore.c | 2 +- src/cc65/locals.c | 2 +- src/cc65/stdfunc.c | 34 ++--- src/dbginfo/dbgsh.c | 2 +- src/sim65/main.c | 2 +- targettest/atari/mem.c | 2 +- targettest/ft.c | 12 +- targettest/getsp.s | 6 +- test/val/bug1652-optimizer.c | 8 +- test/val/cq85.c | 2 +- 204 files changed, 915 insertions(+), 912 deletions(-) diff --git a/asminc/zeropage.inc b/asminc/zeropage.inc index 6627d86b6..5285779ba 100644 --- a/asminc/zeropage.inc +++ b/asminc/zeropage.inc @@ -8,7 +8,7 @@ ; by the compiler, ready for usage in asm code. - .globalzp sp, sreg, regsave + .globalzp c_sp, sreg, regsave .globalzp ptr1, ptr2, ptr3, ptr4 .globalzp tmp1, tmp2, tmp3, tmp4 .globalzp regbank diff --git a/doc/atari.sgml b/doc/atari.sgml index 060bc8ad4..1a83d74fb 100644 --- a/doc/atari.sgml +++ b/doc/atari.sgml @@ -1121,7 +1121,7 @@ If BSS and/or the stack shouldn't stay at the end of the program, some parts of the cc65 runtime lib need to be replaced/modified. common/_heap.s defines the location of the heap and atari/crt0.s -defines the location of the stack by initializing sp. +defines the location of the stack by initializing c_sp. Upgrading from an older cc65 version

diff --git a/doc/ca65.sgml b/doc/ca65.sgml index d2506d958..7b36abec5 100644 --- a/doc/ca65.sgml +++ b/doc/ca65.sgml @@ -5016,17 +5016,17 @@ bit. Using .if (.cpu .bitand CPU_ISET_65SC02) - lda (sp) + lda (c_sp) .else ldy #$00 - lda (sp),y + lda (c_sp),y .endif it is possible to determine if the - lda (sp) + lda (c_sp) instruction is supported, which is the case for the 65SC02, 65C02 and 65816 diff --git a/doc/cc65-intern.sgml b/doc/cc65-intern.sgml index 904cee070..9c59cd79a 100644 --- a/doc/cc65-intern.sgml +++ b/doc/cc65-intern.sgml @@ -131,7 +131,7 @@ All other parameters will be pushed to the C-stack from left to right. The rightmost parameter will have the lowest address on the stack, and multi-byte parameters will have their least significant byte at the lower address. -The Epilogue, after the function call

@@ -175,12 +175,12 @@ used if the return type is 32-bit. If the function has a void return type, the compiler will not depend on the result of A/X/sreg, so these may be clobbered by the function. -The C-stack pointer 1 byte 1 byte 1 byte 1 word _exit jsr reset diff --git a/libsrc/apple2/callmain.s b/libsrc/apple2/callmain.s index 71a8b5611..c43e339aa 100644 --- a/libsrc/apple2/callmain.s +++ b/libsrc/apple2/callmain.s @@ -54,7 +54,7 @@ exit: ldx #$02 ; Copy back the zero-page stuff. ldx #zpspace-1 : lda zpsave,x - sta sp,x + sta c_sp,x dex bpl :- diff --git a/libsrc/apple2/crt0.s b/libsrc/apple2/crt0.s index ce14cc1e3..47ac70a7e 100644 --- a/libsrc/apple2/crt0.s +++ b/libsrc/apple2/crt0.s @@ -43,7 +43,7 @@ ; Save the zero-page locations that we need. init: ldx #zpspace-1 -: lda sp,x +: lda c_sp,x sta zpsave,x dex bpl :- @@ -82,8 +82,8 @@ basic: lda HIMEM ldx HIMEM+1 ; Set up the C stack. -: sta sp - stx sp+1 +: sta c_sp + stx c_sp+1 ; ProDOS TechRefMan, chapter 5.3.5: ; "Your system program should place in the RESET vector the diff --git a/libsrc/apple2/exec.s b/libsrc/apple2/exec.s index 4e5e77a6e..38f31ee37 100644 --- a/libsrc/apple2/exec.s +++ b/libsrc/apple2/exec.s @@ -42,9 +42,9 @@ _exec: ; binary programs so we should do the same too in any case ; especially as _we_ rely on it in mainargs.s for argv[0] ldy #$00 - lda (sp),y + lda (c_sp),y tay -: lda (sp),y +: lda (c_sp),y sta $0280,y dey bpl :- diff --git a/libsrc/apple2/filename.s b/libsrc/apple2/filename.s index 0d4b6bedd..f4723ee1f 100644 --- a/libsrc/apple2/filename.s +++ b/libsrc/apple2/filename.s @@ -34,8 +34,8 @@ pushname: sta mliparam + MLI::ON_LINE::UNIT_NUM ; Use allocated pathname buffer - lda sp - ldx sp+1 + lda c_sp + ldx c_sp+1 sta mliparam + MLI::ON_LINE::DATA_BUFFER stx mliparam + MLI::ON_LINE::DATA_BUFFER+1 @@ -46,16 +46,16 @@ pushname: bcs addsp65 ; Get volume name length - lda (sp),y + lda (c_sp),y and #15 ; Max volume name length ; Bracket volume name with slashes to form prefix sta tmp1 lda #'/' - sta (sp),y + sta (c_sp),y ldy tmp1 iny ; Leading slash - sta (sp),y + sta (c_sp),y iny ; Trailing slash ; Adjust source pointer for copy @@ -69,7 +69,7 @@ pushname: ; Copy source to allocated pathname buffer copy: lda (ptr1),y - sta (sp),y + sta (c_sp),y beq setlen iny cpy #FILENAME_MAX @@ -86,7 +86,7 @@ addsp65:ldy #FILENAME_MAX setlen: tya jsr decsp1 ; Preserves A ldy #$00 - sta (sp),y + sta (c_sp),y ; Return success tya diff --git a/libsrc/apple2/mli_file_info_direct.s b/libsrc/apple2/mli_file_info_direct.s index c15ebc28f..7fdaa9edf 100644 --- a/libsrc/apple2/mli_file_info_direct.s +++ b/libsrc/apple2/mli_file_info_direct.s @@ -11,8 +11,8 @@ ; Returns with carry set on error, and sets errno mli_file_info_direct: ; Set pushed name - lda sp - ldx sp+1 + lda c_sp + ldx c_sp+1 sta mliparam + MLI::INFO::PATHNAME stx mliparam + MLI::INFO::PATHNAME+1 diff --git a/libsrc/apple2/mou/a2.stdmou.s b/libsrc/apple2/mou/a2.stdmou.s index 9c2f96200..38cd7c957 100644 --- a/libsrc/apple2/mou/a2.stdmou.s +++ b/libsrc/apple2/mou/a2.stdmou.s @@ -341,10 +341,10 @@ MOVE: ldy #$00 ; Start at top of stack ; Set x - lda (sp),y + lda (c_sp),y iny sta pos1_lo,x - lda (sp),y + lda (c_sp),y sta pos1_hi,x ; Update cursor diff --git a/libsrc/apple2/open.s b/libsrc/apple2/open.s index 7ece7f18d..8f1df26df 100644 --- a/libsrc/apple2/open.s +++ b/libsrc/apple2/open.s @@ -101,8 +101,8 @@ found: tya bne oserr1 ; Set pushed name - lda sp - ldx sp+1 + lda c_sp + ldx c_sp+1 sta mliparam + MLI::OPEN::PATHNAME stx mliparam + MLI::OPEN::PATHNAME+1 diff --git a/libsrc/apple2/syschdir.s b/libsrc/apple2/syschdir.s index b3f81e2a5..be78a91b9 100644 --- a/libsrc/apple2/syschdir.s +++ b/libsrc/apple2/syschdir.s @@ -17,8 +17,8 @@ __syschdir: bne oserr ; Set pushed name - lda sp - ldx sp+1 + lda c_sp + ldx c_sp+1 sta mliparam + MLI::PREFIX::PATHNAME stx mliparam + MLI::PREFIX::PATHNAME+1 diff --git a/libsrc/apple2/sysmkdir.s b/libsrc/apple2/sysmkdir.s index 7759da260..e59421319 100644 --- a/libsrc/apple2/sysmkdir.s +++ b/libsrc/apple2/sysmkdir.s @@ -23,8 +23,8 @@ __sysmkdir: bne oserr ; Set pushed name - lda sp - ldx sp+1 + lda c_sp + ldx c_sp+1 sta mliparam + MLI::CREATE::PATHNAME stx mliparam + MLI::CREATE::PATHNAME+1 diff --git a/libsrc/apple2/sysremove.s b/libsrc/apple2/sysremove.s index 08c4dff68..088407024 100644 --- a/libsrc/apple2/sysremove.s +++ b/libsrc/apple2/sysremove.s @@ -16,8 +16,8 @@ __sysremove: bne oserr ; Set pushed name - lda sp - ldx sp+1 + lda c_sp + ldx c_sp+1 sta mliparam + MLI::DESTROY::PATHNAME stx mliparam + MLI::DESTROY::PATHNAME+1 diff --git a/libsrc/apple2/sysrename.s b/libsrc/apple2/sysrename.s index 0fe8dd7b1..3e380548f 100644 --- a/libsrc/apple2/sysrename.s +++ b/libsrc/apple2/sysrename.s @@ -22,8 +22,8 @@ __sysrename: bne oserr1 ; Save pushed oldname - lda sp - ldx sp+1 + lda c_sp + ldx c_sp+1 sta ptr3 stx ptr3+1 @@ -40,8 +40,8 @@ __sysrename: stx mliparam + MLI::RENAME::PATHNAME+1 ; Set pushed newname - lda sp - ldx sp+1 + lda c_sp + ldx c_sp+1 sta mliparam + MLI::RENAME::NEW_PATHNAME stx mliparam + MLI::RENAME::NEW_PATHNAME+1 diff --git a/libsrc/atari/crt0.s b/libsrc/atari/crt0.s index 50e3ca7b6..23c1f580c 100644 --- a/libsrc/atari/crt0.s +++ b/libsrc/atari/crt0.s @@ -59,8 +59,8 @@ start: lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__) ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__) - sta sp - stx sp+1 + sta c_sp + stx c_sp+1 .else @@ -75,11 +75,11 @@ start: lda MEMTOP sbc #<__RESERVED_MEMORY__ sta APPMHI ; initialize our APPMHI value - sta sp ; set up runtime stack part 1 + sta c_sp ; set up runtime stack part 1 lda MEMTOP+1 sbc #>__RESERVED_MEMORY__ sta APPMHI+1 - sta sp+1 ; set up runtime stack part 2 + sta c_sp+1 ; set up runtime stack part 2 .endif diff --git a/libsrc/atari/diopncls.s b/libsrc/atari/diopncls.s index f40d6bba4..a5c145081 100644 --- a/libsrc/atari/diopncls.s +++ b/libsrc/atari/diopncls.s @@ -16,7 +16,7 @@ .export sectsizetab .import ___oserror, __sio_call, _dio_read .import pushax, addysp, subysp - .importzp ptr2, sp + .importzp ptr2, c_sp .include "atari.inc" @@ -78,10 +78,10 @@ _dio_open: ldy #128 jsr subysp ; allocate buffer on the stack - lda sp + lda c_sp pha - lda sp+1 - pha ; save sp (buffer address) on processor stack + lda c_sp+1 + pha ; save c_sp (buffer address) on processor stack lda ptr2 ldx ptr2+1 diff --git a/libsrc/atari/fdtable.s b/libsrc/atari/fdtable.s index fd9f5021b..d1d869387 100644 --- a/libsrc/atari/fdtable.s +++ b/libsrc/atari/fdtable.s @@ -6,7 +6,7 @@ .include "atari.inc" .include "fd.inc" - .importzp tmp1,tmp2,tmp3,ptr4,sp + .importzp tmp1,tmp2,tmp3,ptr4,c_sp .import fd_table,fd_index .import fdt_to_fdi .export clriocb @@ -229,7 +229,7 @@ freefnd:txa beq l2 l1: ldy #0 - lda (sp),y ; get device + lda (c_sp),y ; get device l2: sta fd_table+ft_dev,x ; set device lda #1 sta fd_table+ft_usa,x ; set usage counter diff --git a/libsrc/atari/mcbpm.s b/libsrc/atari/mcbpm.s index 9e6ccc2c5..bc36b6f99 100644 --- a/libsrc/atari/mcbpm.s +++ b/libsrc/atari/mcbpm.s @@ -8,7 +8,7 @@ ; .include "atari.inc" - .importzp sp + .importzp c_sp .export _mouse_pm_callbacks .constructor pm_init, 27 .destructor pm_down @@ -193,22 +193,22 @@ pm_init: .else -; use top of memory and lower sp accordingly - sta sp +; use top of memory and lower c_sp accordingly + sta c_sp sta MOUSE_PM_BASE - lda sp+1 + lda c_sp+1 and #7 ; offset within 2K cmp #3 + MOUSE_PM_RAW + 1 ; can we use it? bcc @decr ; no - lda sp+1 + lda c_sp+1 and #$F8 @set: adc #3 + MOUSE_PM_RAW - 1 ; CF is set, so adding MOUSE_PM_RAW + 3 sta MOUSE_PM_BASE+1 - sta sp+1 + sta c_sp+1 bne @cont ; jump always -@decr: lda sp+1 +@decr: lda c_sp+1 and #$F8 sbc #8 - 1 ; CF is clear, subtracts 8 bcs @set ; jump always diff --git a/libsrc/atari/mou/atrjoy.s b/libsrc/atari/mou/atrjoy.s index a93c7de13..f30d72050 100644 --- a/libsrc/atari/mou/atrjoy.s +++ b/libsrc/atari/mou/atrjoy.s @@ -241,11 +241,11 @@ MOVE: php jsr CMOVEY ; Set it ldy #$01 - lda (sp),y + lda (c_sp),y sta XPos+1 tax dey - lda (sp),y + lda (c_sp),y sta XPos ; New X position jsr CMOVEX ; Move the cursor diff --git a/libsrc/atari/mou/atrst.s b/libsrc/atari/mou/atrst.s index 626b7a8f7..7f915cc36 100644 --- a/libsrc/atari/mou/atrst.s +++ b/libsrc/atari/mou/atrst.s @@ -399,12 +399,12 @@ MOVE: php jsr CMOVEY ; Set it ldy #$01 - lda (sp),y + lda (c_sp),y sta XPos+1 sta XPosWrk+1 tax dey - lda (sp),y + lda (c_sp),y sta XPos ; New X position sta XPosWrk jsr CMOVEX ; Move the cursor diff --git a/libsrc/atari/mou/atrtt.s b/libsrc/atari/mou/atrtt.s index f7c56e9f2..516565844 100644 --- a/libsrc/atari/mou/atrtt.s +++ b/libsrc/atari/mou/atrtt.s @@ -236,11 +236,11 @@ MOVE: php jsr CMOVEY ; Set it ldy #$01 - lda (sp),y + lda (c_sp),y sta XPos+1 tax dey - lda (sp),y + lda (c_sp),y sta XPos ; New X position jsr CMOVEX ; Move the cursor diff --git a/libsrc/atari/sysrename.s b/libsrc/atari/sysrename.s index e526af5c8..b410ebcfd 100644 --- a/libsrc/atari/sysrename.s +++ b/libsrc/atari/sysrename.s @@ -6,7 +6,7 @@ .include "atari.inc" .import findfreeiocb - .importzp tmp4, sp, ptr2, ptr3 + .importzp tmp4, c_sp, ptr2, ptr3 .import incsp2, subysp, addysp, popax .ifdef UCASE_FILENAME .importzp tmp3 @@ -118,19 +118,19 @@ L1: jsr subysp ; make room on the stack ; copy old name ldy #0 con: lda (ptr3),y - sta (sp),y + sta (c_sp),y beq copyend iny bne con copyend:lda #$20 ; space - sta (sp),y + sta (c_sp),y iny tya ; get current offset (beyond old name) clc - adc sp + adc c_sp sta ptr3 - lda sp+1 + lda c_sp+1 adc #0 sta ptr3+1 ; ptr3 now contains pointer to space for new filename @@ -143,9 +143,9 @@ cnn: lda (ptr2),y bne cnn copend2:ldx tmp4 - lda sp + lda c_sp sta ICBAL,x - lda sp+1 + lda c_sp+1 sta ICBAH,x lda #RENAME sta ICCOM,x @@ -160,13 +160,13 @@ copend2:ldx tmp4 ; clean up stack - lda sp + lda c_sp clc adc sspc - sta sp - lda sp+1 + sta c_sp + lda c_sp+1 adc sspc+1 - sta sp+1 + sta c_sp+1 ; handle status diff --git a/libsrc/atari/ucase_fn.s b/libsrc/atari/ucase_fn.s index f7f03915d..534c6a21c 100644 --- a/libsrc/atari/ucase_fn.s +++ b/libsrc/atari/ucase_fn.s @@ -24,7 +24,7 @@ .importzp tmp2 .import __defdev .endif - .importzp tmp3,ptr4,sp + .importzp tmp3,ptr4,c_sp .import subysp,addysp .export ucase_fn @@ -63,13 +63,13 @@ hasdev: ldy #0 loop2: lda (ptr4),y - sta (sp),y + sta (c_sp),y beq copy_end bmi L1 ; Not lowercase (also, invalid, should reject) cmp #'a' bcc L1 ; Not lowercase and #$DF ; make upper case char, assume ASCII chars - sta (sp),y ; store back + sta (c_sp),y ; store back L1: iny bpl loop2 ; bpl: this way we only support a max. length of 127 @@ -93,15 +93,15 @@ copy_end: jsr subysp ; adjust stack pointer dey cpdev: lda __defdev,y - sta (sp),y ; insert device name, number and ':' + sta (c_sp),y ; insert device name, number and ':' dey bpl cpdev hasdev2: .endif ; leave A and X pointing to the modified filename - lda sp - ldx sp+1 + lda c_sp + ldx c_sp+1 clc ; indicate success rts diff --git a/libsrc/atari2600/crt0.s b/libsrc/atari2600/crt0.s index 4f09a0a5a..7b5b679b0 100644 --- a/libsrc/atari2600/crt0.s +++ b/libsrc/atari2600/crt0.s @@ -35,8 +35,8 @@ clearLoop: ; Initialize C stack pointer lda #<(__RAM_START__ + __RAM_SIZE__) ldx #>(__RAM_START__ + __RAM_SIZE__) - sta sp - stx sp+1 + sta c_sp + stx c_sp+1 ; Call main jsr _main diff --git a/libsrc/atari5200/crt0.s b/libsrc/atari5200/crt0.s index 8f6e02273..a72d7f9f6 100644 --- a/libsrc/atari5200/crt0.s +++ b/libsrc/atari5200/crt0.s @@ -27,8 +27,8 @@ start: lda #<(__RAM_START__ + __RAM_SIZE__ - __RESERVED_MEMORY__) ldx #>(__RAM_START__ + __RAM_SIZE__ - __RESERVED_MEMORY__) - sta sp - stx sp+1 ; Set argument stack ptr + sta c_sp + stx c_sp+1 ; Set argument stack ptr ; Call the module constructors. diff --git a/libsrc/atari7800/crt0.s b/libsrc/atari7800/crt0.s index e791179f3..dea351473 100644 --- a/libsrc/atari7800/crt0.s +++ b/libsrc/atari7800/crt0.s @@ -30,9 +30,9 @@ start: ; Set up parameter stack lda #<(__RAM3_START__ + __RAM3_SIZE__) - sta sp + sta c_sp lda #>(__RAM3_START__ + __RAM3_SIZE__) - sta sp+1 + sta c_sp+1 jsr copydata jsr zerobss diff --git a/libsrc/atari7800/mono_setcursor.s b/libsrc/atari7800/mono_setcursor.s index 02e0308f6..995f0d661 100644 --- a/libsrc/atari7800/mono_setcursor.s +++ b/libsrc/atari7800/mono_setcursor.s @@ -27,7 +27,7 @@ .constructor mono_init_cursor .interruptor mono_blink_cursor - .importzp sp + .importzp c_sp .import _zonecounter .import _mono_zones .import cursor diff --git a/libsrc/atari7800/setcursor.s b/libsrc/atari7800/setcursor.s index f438de24f..040732cff 100644 --- a/libsrc/atari7800/setcursor.s +++ b/libsrc/atari7800/setcursor.s @@ -27,7 +27,7 @@ .constructor init_cursor .interruptor blink_cursor - .importzp sp + .importzp c_sp .import _zonecounter .import _zones .import cursor diff --git a/libsrc/atmos/crt0.s b/libsrc/atmos/crt0.s index 8c2be656c..55c60dd30 100644 --- a/libsrc/atmos/crt0.s +++ b/libsrc/atmos/crt0.s @@ -51,7 +51,7 @@ _exit: jsr donelib ldx #zpspace - 1 L2: lda zpsave,x - sta sp,x + sta c_sp,x dex bpl L2 @@ -68,7 +68,7 @@ L2: lda zpsave,x ; Save the zero-page area that we're about to use. init: ldx #zpspace - 1 -L1: lda sp,x +L1: lda c_sp,x sta zpsave,x dex bpl L1 @@ -85,8 +85,8 @@ L1: lda sp,x lda #<(__MAIN_START__ + __MAIN_SIZE__) ldx #>(__MAIN_START__ + __MAIN_SIZE__) - sta sp - stx sp+1 ; Set argument stack ptr + sta c_sp + stx c_sp+1 ; Set argument stack ptr ; Call the module constructors. diff --git a/libsrc/c128/crt0.s b/libsrc/c128/crt0.s index ba6a78ac5..f6a55778c 100644 --- a/libsrc/c128/crt0.s +++ b/libsrc/c128/crt0.s @@ -39,7 +39,7 @@ Start: ; Save the zero-page locations that we need. ldx #zpspace-1 -L1: lda sp,x +L1: lda c_sp,x sta zpsave,x dex bpl L1 @@ -58,8 +58,8 @@ L1: lda sp,x lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__) ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__) - sta sp - stx sp+1 ; Set argument stack ptr + sta c_sp + stx c_sp+1 ; Set argument stack ptr ; Call the module constructors. @@ -85,7 +85,7 @@ _exit: pha ; Save the return code on stack ldx #zpspace-1 L2: lda zpsave,x - sta sp,x + sta c_sp,x dex bpl L2 diff --git a/libsrc/c128/mou/c128-1351.s b/libsrc/c128/mou/c128-1351.s index 76e28d9f7..f6954c823 100644 --- a/libsrc/c128/mou/c128-1351.s +++ b/libsrc/c128/mou/c128-1351.s @@ -296,11 +296,11 @@ MOVE: sei ; No interrupts jsr CMOVEY ; Set it ldy #$01 - lda (sp),y + lda (c_sp),y sta XPos+1 tax dey - lda (sp),y + lda (c_sp),y sta XPos ; New X position jsr CMOVEX ; Move the cursor diff --git a/libsrc/c128/mou/c128-inkwell.s b/libsrc/c128/mou/c128-inkwell.s index 2aac7d32d..b86959788 100644 --- a/libsrc/c128/mou/c128-inkwell.s +++ b/libsrc/c128/mou/c128-inkwell.s @@ -323,10 +323,10 @@ MOVE: sei ; No interrupts jsr MoveY ldy #$01 - lda (sp),y + lda (c_sp),y tax dey - lda (sp),y + lda (c_sp),y jsr MoveX ; Move the cursor cli ; Allow interrupts diff --git a/libsrc/c128/mou/c128-joy.s b/libsrc/c128/mou/c128-joy.s index d809db526..26367f8df 100644 --- a/libsrc/c128/mou/c128-joy.s +++ b/libsrc/c128/mou/c128-joy.s @@ -297,11 +297,11 @@ MOVE: sei ; No interrupts jsr CMOVEY ; Set it ldy #$01 - lda (sp),y + lda (c_sp),y sta XPos+1 tax dey - lda (sp),y + lda (c_sp),y sta XPos ; New X position jsr CMOVEX ; Move the cursor diff --git a/libsrc/c128/mou/c128-pot.s b/libsrc/c128/mou/c128-pot.s index 1cbe4aa18..55de4ac12 100644 --- a/libsrc/c128/mou/c128-pot.s +++ b/libsrc/c128/mou/c128-pot.s @@ -297,11 +297,11 @@ MOVE: sei ; No interrupts jsr CMOVEY ; Set it ldy #$01 - lda (sp),y + lda (c_sp),y sta XPos+1 tax dey - lda (sp),y + lda (c_sp),y sta XPos ; New X position jsr CMOVEX ; Move the cursor diff --git a/libsrc/c16/crt0.s b/libsrc/c16/crt0.s index 1df1e5c62..c203fb20f 100644 --- a/libsrc/c16/crt0.s +++ b/libsrc/c16/crt0.s @@ -24,7 +24,7 @@ Start: ; Save the zero-page locations that we need. ldx #zpspace-1 -L1: lda sp,x +L1: lda c_sp,x sta zpsave,x dex bpl L1 @@ -49,8 +49,8 @@ L1: lda sp,x bcc MemOk ldy #$80 ldx #$00 -MemOk: stx sp - sty sp+1 ; set argument stack ptr +MemOk: stx c_sp + sty c_sp+1 ; set argument stack ptr ; Call the module constructors. @@ -69,7 +69,7 @@ _exit: pha ; Save the return code on stack ldx #zpspace-1 L2: lda zpsave,x - sta sp,x + sta c_sp,x dex bpl L2 diff --git a/libsrc/c64/crt0.s b/libsrc/c64/crt0.s index 4e5c7c9d4..dea9226aa 100644 --- a/libsrc/c64/crt0.s +++ b/libsrc/c64/crt0.s @@ -55,7 +55,7 @@ _exit: pha ; Save the return code on stack ldx #zpspace-1 L2: lda zpsave,x - sta sp,x + sta c_sp,x dex bpl L2 @@ -85,7 +85,7 @@ init: ; Save the zero-page locations that we need. ldx #zpspace-1 -L1: lda sp,x +L1: lda c_sp,x sta zpsave,x dex bpl L1 @@ -94,8 +94,8 @@ L1: lda sp,x lda #<(__MAIN_START__ + __MAIN_SIZE__) ldx #>(__MAIN_START__ + __MAIN_SIZE__) - sta sp - stx sp+1 ; Set argument stack ptr + sta c_sp + stx c_sp+1 ; Set argument stack ptr ; Switch to the second charset. diff --git a/libsrc/c64/mou/c64-1351.s b/libsrc/c64/mou/c64-1351.s index ce0f18803..dcf949730 100644 --- a/libsrc/c64/mou/c64-1351.s +++ b/libsrc/c64/mou/c64-1351.s @@ -239,11 +239,11 @@ MOVE: sei ; No interrupts jsr CMOVEY ; Set it ldy #$01 - lda (sp),y + lda (c_sp),y sta XPos+1 tax dey - lda (sp),y + lda (c_sp),y sta XPos ; New X position jsr CMOVEX ; Move the cursor diff --git a/libsrc/c64/mou/c64-inkwell.s b/libsrc/c64/mou/c64-inkwell.s index d2f14a6f0..68941260c 100644 --- a/libsrc/c64/mou/c64-inkwell.s +++ b/libsrc/c64/mou/c64-inkwell.s @@ -249,10 +249,10 @@ MOVE: sei ; No interrupts jsr MoveY ldy #$01 - lda (sp),y + lda (c_sp),y tax dey - lda (sp),y + lda (c_sp),y jsr MoveX ; Move the cursor cli ; Allow interrupts diff --git a/libsrc/c64/mou/c64-joy.s b/libsrc/c64/mou/c64-joy.s index 5ee1b4f84..901b9c42d 100644 --- a/libsrc/c64/mou/c64-joy.s +++ b/libsrc/c64/mou/c64-joy.s @@ -245,11 +245,11 @@ MOVE: sei ; No interrupts jsr CMOVEY ; Set it ldy #$01 - lda (sp),y + lda (c_sp),y sta XPos+1 tax dey - lda (sp),y + lda (c_sp),y sta XPos ; New X position jsr CMOVEX ; Move the cursor diff --git a/libsrc/c64/mou/c64-pot.s b/libsrc/c64/mou/c64-pot.s index 9bdf24f62..1728913e1 100644 --- a/libsrc/c64/mou/c64-pot.s +++ b/libsrc/c64/mou/c64-pot.s @@ -230,11 +230,11 @@ MOVE: sei ; No interrupts jsr CMOVEY ; Set it ldy #$01 - lda (sp),y + lda (c_sp),y sta XPos+1 tax dey - lda (sp),y + lda (c_sp),y sta XPos ; New X position jsr CMOVEX ; Move the cursor diff --git a/libsrc/cbm/dir.s b/libsrc/cbm/dir.s index 734485aaf..a78fc94a5 100644 --- a/libsrc/cbm/dir.s +++ b/libsrc/cbm/dir.s @@ -44,10 +44,10 @@ __dirread: ; Replace dir by dir->fd ldy #2 - lda (sp),y + lda (c_sp),y sta ptr1 iny - lda (sp),y + lda (c_sp),y sta ptr1+1 ldy #DIR::fd+1 lda (ptr1),y @@ -55,10 +55,10 @@ __dirread: dey lda (ptr1),y ldy #2 - sta (sp),y + sta (c_sp),y pla iny - sta (sp),y + sta (c_sp),y ; Get count, save it again, clear the high byte and call read(). By the ; previous actions, the stack frame is as read() needs it, and read() will diff --git a/libsrc/cbm/open.s b/libsrc/cbm/open.s index 47224925d..bf937ee0f 100644 --- a/libsrc/cbm/open.s +++ b/libsrc/cbm/open.s @@ -12,7 +12,7 @@ .import opencmdchannel, closecmdchannel, readdiskerror .import fnunit, fnisfile .import _close - .importzp sp, tmp2, tmp3 + .importzp c_sp, tmp2, tmp3 .include "errno.inc" .include "fcntl.inc" diff --git a/libsrc/cbm/write.s b/libsrc/cbm/write.s index 172e45382..43c7582f0 100644 --- a/libsrc/cbm/write.s +++ b/libsrc/cbm/write.s @@ -8,7 +8,7 @@ .constructor initstdout .import rwcommon - .importzp sp, ptr1, ptr2, ptr3 + .importzp c_sp, ptr1, ptr2, ptr3 .include "cbm.inc" .include "errno.inc" diff --git a/libsrc/cbm510/crt0.s b/libsrc/cbm510/crt0.s index 86137b1ca..80d587ff5 100644 --- a/libsrc/cbm510/crt0.s +++ b/libsrc/cbm510/crt0.s @@ -117,7 +117,7 @@ entry: php tya sec sbc #7 - sta $1FF ; Save new sp + sta $1FF ; Save new c_sp tay tsx @@ -145,7 +145,7 @@ entry: php iny sta (sysp1),y - ldy $1FF ; Restore sp in bank 15 + ldy $1FF ; Restore c_sp in bank 15 lda #.hibyte(expull-1) sta (sysp1),y @@ -245,7 +245,7 @@ L1: lda extzp,x dex bpl L1 -; Save the old stack pointer from the system bank; and, set up our hw sp. +; Save the old stack pointer from the system bank; and, set up our hw c_sp. tsx txa @@ -279,9 +279,9 @@ L3: lda vectors,x ; Set up the C stack. lda #.lobyte(callbank15::entry) - sta sp + sta c_sp lda #.hibyte(callbank15::entry) - sta sp+1 + sta c_sp+1 ; Set up the subroutine and jump vector table that redirects Kernal calls to ; the system bank. @@ -495,7 +495,7 @@ _exit: pha ; Save the return code on stack ; Set up the welcome code at the stack bottom in the system bank. ldy #$FF - lda (sysp1),y ; Load system bank sp + lda (sysp1),y ; Load system bank c_sp tax iny ; Y = 0 lda #$58 ; CLI opcode diff --git a/libsrc/cbm510/mou/cbm510-inkwl.s b/libsrc/cbm510/mou/cbm510-inkwl.s index ea6d95934..e5328cf75 100644 --- a/libsrc/cbm510/mou/cbm510-inkwl.s +++ b/libsrc/cbm510/mou/cbm510-inkwl.s @@ -256,10 +256,10 @@ MOVE: sei ; No interrupts jsr MoveY ldy #$01 - lda (sp),y + lda (c_sp),y tax dey - lda (sp),y + lda (c_sp),y jsr MoveX ; Move the cursor cli ; Allow interrupts diff --git a/libsrc/cbm510/mou/cbm510-joy.s b/libsrc/cbm510/mou/cbm510-joy.s index 4daa49272..912842be7 100644 --- a/libsrc/cbm510/mou/cbm510-joy.s +++ b/libsrc/cbm510/mou/cbm510-joy.s @@ -225,11 +225,11 @@ MOVE: sei ; No interrupts jsr MoveY ; Set new y position ldy #1 - lda (sp),y + lda (c_sp),y sta XPos+1 tax dey - lda (sp),y + lda (c_sp),y jsr MoveX ; Move the pointer cli ; Allow interrupts diff --git a/libsrc/cbm610/crt0.s b/libsrc/cbm610/crt0.s index 0ad343d7f..dc56fa2de 100644 --- a/libsrc/cbm610/crt0.s +++ b/libsrc/cbm610/crt0.s @@ -115,7 +115,7 @@ entry: php tya sec sbc #7 - sta $1FF ; Save new sp + sta $1FF ; Save new c_sp tay tsx @@ -143,7 +143,7 @@ entry: php iny sta (sysp1),y - ldy $1FF ; Restore sp in bank 15 + ldy $1FF ; Restore c_sp in bank 15 lda #.hibyte(expull-1) sta (sysp1),y @@ -243,7 +243,7 @@ L1: lda extzp,x dex bpl L1 -; Save the old stack pointer from the system bank; and, set up our hw sp. +; Save the old stack pointer from the system bank; and, set up our hw c_sp. tsx txa @@ -277,9 +277,9 @@ L3: lda vectors,x ; Set up the C stack. lda #.lobyte(callbank15::entry) - sta sp + sta c_sp lda #.hibyte(callbank15::entry) - sta sp+1 + sta c_sp+1 ; Set up the subroutine and jump vector table that redirects Kernal calls to ; the system bank. @@ -400,7 +400,7 @@ _exit: pha ; Save the return code ; Set up the welcome code at the stack bottom in the system bank. ldy #$FF - lda (sysp1),y ; Load system bank sp + lda (sysp1),y ; Load system bank c_sp tax iny ; Y = 0 lda #$58 ; CLI opcode diff --git a/libsrc/common/_fopen.s b/libsrc/common/_fopen.s index 17a1ec19b..0c234097e 100644 --- a/libsrc/common/_fopen.s +++ b/libsrc/common/_fopen.s @@ -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 diff --git a/libsrc/common/_heap.s b/libsrc/common/_heap.s index eb680fa20..e5d71d1be 100644 --- a/libsrc/common/_heap.s +++ b/libsrc/common/_heap.s @@ -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 diff --git a/libsrc/common/_idiv32by16r16.s b/libsrc/common/_idiv32by16r16.s index 7df78f4dd..9534f751f 100644 --- a/libsrc/common/_idiv32by16r16.s +++ b/libsrc/common/_idiv32by16r16.s @@ -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 diff --git a/libsrc/common/_printf.s b/libsrc/common/_printf.s index d7eeb072d..40ab0bc64 100644 --- a/libsrc/common/_printf.s +++ b/libsrc/common/_printf.s @@ -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 diff --git a/libsrc/common/_udiv32by16r16.s b/libsrc/common/_udiv32by16r16.s index a1d5f4e66..987390c04 100644 --- a/libsrc/common/_udiv32by16r16.s +++ b/libsrc/common/_udiv32by16r16.s @@ -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 diff --git a/libsrc/common/fprintf.s b/libsrc/common/fprintf.s index 1582e6521..af9a58ebc 100644 --- a/libsrc/common/fprintf.s +++ b/libsrc/common/fprintf.s @@ -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 diff --git a/libsrc/common/fread.s b/libsrc/common/fread.s index b39b9d748..be06c2a62 100644 --- a/libsrc/common/fread.s +++ b/libsrc/common/fread.s @@ -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. diff --git a/libsrc/common/fscanf.s b/libsrc/common/fscanf.s index a3d1ec0a1..c687a0624 100644 --- a/libsrc/common/fscanf.s +++ b/libsrc/common/fscanf.s @@ -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 diff --git a/libsrc/common/interrupt.s b/libsrc/common/interrupt.s index 6bdbb5fe4..a67d51fda 100644 --- a/libsrc/common/interrupt.s +++ b/libsrc/common/interrupt.s @@ -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 diff --git a/libsrc/common/itoa.s b/libsrc/common/itoa.s index 808f9bc33..a1cd53c8b 100644 --- a/libsrc/common/itoa.s +++ b/libsrc/common/itoa.s @@ -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 diff --git a/libsrc/common/longjmp.s b/libsrc/common/longjmp.s index 91606a442..8855286a9 100644 --- a/libsrc/common/longjmp.s +++ b/libsrc/common/longjmp.s @@ -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 diff --git a/libsrc/common/lz4.s b/libsrc/common/lz4.s index c53841897..5d26cb56a 100644 --- a/libsrc/common/lz4.s +++ b/libsrc/common/lz4.s @@ -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 diff --git a/libsrc/common/memcpy.s b/libsrc/common/memcpy.s index fd090c788..8f6531956 100644 --- a/libsrc/common/memcpy.s +++ b/libsrc/common/memcpy.s @@ -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 diff --git a/libsrc/common/memset.s b/libsrc/common/memset.s index be78fc30d..5d56507a5 100644 --- a/libsrc/common/memset.s +++ b/libsrc/common/memset.s @@ -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 diff --git a/libsrc/common/printf.s b/libsrc/common/printf.s index 8d645dfa2..76e08e584 100644 --- a/libsrc/common/printf.s +++ b/libsrc/common/printf.s @@ -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 diff --git a/libsrc/common/realloc.s b/libsrc/common/realloc.s index 176871dd5..16d5eea41 100644 --- a/libsrc/common/realloc.s +++ b/libsrc/common/realloc.s @@ -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 diff --git a/libsrc/common/scanf.s b/libsrc/common/scanf.s index dd6c16ad1..92460b629 100644 --- a/libsrc/common/scanf.s +++ b/libsrc/common/scanf.s @@ -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 diff --git a/libsrc/common/setjmp.s b/libsrc/common/setjmp.s index 886853368..3c0b8aa17 100644 --- a/libsrc/common/setjmp.s +++ b/libsrc/common/setjmp.s @@ -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 diff --git a/libsrc/common/snprintf.s b/libsrc/common/snprintf.s index 33afb434d..c922a55bc 100644 --- a/libsrc/common/snprintf.s +++ b/libsrc/common/snprintf.s @@ -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 diff --git a/libsrc/common/sprintf.s b/libsrc/common/sprintf.s index d502d8638..d2ce6602e 100644 --- a/libsrc/common/sprintf.s +++ b/libsrc/common/sprintf.s @@ -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 diff --git a/libsrc/common/sscanf.s b/libsrc/common/sscanf.s index 941f54e92..d393087d8 100644 --- a/libsrc/common/sscanf.s +++ b/libsrc/common/sscanf.s @@ -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 diff --git a/libsrc/common/vfprintf.s b/libsrc/common/vfprintf.s index 1225bcc47..3dc1e6729 100644 --- a/libsrc/common/vfprintf.s +++ b/libsrc/common/vfprintf.s @@ -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 ; Restore low byte of ap and call _printf diff --git a/libsrc/common/vfscanf.s b/libsrc/common/vfscanf.s index c7d6e5564..71d7c634c 100644 --- a/libsrc/common/vfscanf.s +++ b/libsrc/common/vfscanf.s @@ -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 ; Restore the low byte of ap, and call the _scanf function diff --git a/libsrc/common/vprintf.s b/libsrc/common/vprintf.s index 0958b1038..1c44b61ef 100644 --- a/libsrc/common/vprintf.s +++ b/libsrc/common/vprintf.s @@ -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 diff --git a/libsrc/common/vscanf.s b/libsrc/common/vscanf.s index 94afe527f..a97bd163a 100644 --- a/libsrc/common/vscanf.s +++ b/libsrc/common/vscanf.s @@ -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 diff --git a/libsrc/common/vsnprintf.s b/libsrc/common/vsnprintf.s index 048a756c3..780ab10ee 100644 --- a/libsrc/common/vsnprintf.s +++ b/libsrc/common/vsnprintf.s @@ -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 ; 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 diff --git a/libsrc/common/vsscanf.s b/libsrc/common/vsscanf.s index 335712b20..2061861dc 100644 --- a/libsrc/common/vsscanf.s +++ b/libsrc/common/vsscanf.s @@ -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 lda #$00 sta sd + SSCANFDATA::INDEX diff --git a/libsrc/conio/cprintf.s b/libsrc/conio/cprintf.s index 01bd0bbc6..80bca2308 100644 --- a/libsrc/conio/cprintf.s +++ b/libsrc/conio/cprintf.s @@ -6,7 +6,7 @@ .export _cprintf .import pushax, addysp, _vcprintf - .importzp sp, ptr1 + .importzp c_sp, ptr1 .macpack generic @@ -31,9 +31,9 @@ _cprintf: dey dey ; Sub size of Format tya - add sp + add c_sp sta ptr1 - ldx sp+1 + ldx c_sp+1 bcc @L1 inx @L1: stx ptr1+1 diff --git a/libsrc/conio/cscanf.s b/libsrc/conio/cscanf.s index 7e54a844f..7ee532626 100644 --- a/libsrc/conio/cscanf.s +++ b/libsrc/conio/cscanf.s @@ -23,8 +23,8 @@ _cscanf: ; Now, calculate the va_list pointer -- which points to format. - ldx sp+1 - add sp + ldx c_sp+1 + add c_sp bcc @L1 inx @L1: sta ptr1 diff --git a/libsrc/conio/vcprintf.s b/libsrc/conio/vcprintf.s index 595a2d2c5..c6371f00e 100644 --- a/libsrc/conio/vcprintf.s +++ b/libsrc/conio/vcprintf.s @@ -7,7 +7,7 @@ .export _vcprintf .import pushax, popax, popptr1 .import __printf, _cputc - .importzp sp, ptr1, ptr2, ptr3, tmp1 + .importzp c_sp, ptr1, ptr2, ptr3, tmp1 .macpack generic .macpack cpu @@ -138,10 +138,10 @@ _vcprintf: ; Get the format parameter and push it again ldy #1 - lda (sp),y + lda (c_sp),y tax dey - lda (sp),y + lda (c_sp),y jsr pushax ; Replace the passed format parameter on the stack by &d - this creates @@ -150,10 +150,10 @@ _vcprintf: ldy #2 ; Low byte of d lda #outdesc - sta (sp),y + sta (c_sp),y ; Restore ap and call _printf diff --git a/libsrc/creativision/crt0.s b/libsrc/creativision/crt0.s index 5185ff237..70009e2ba 100644 --- a/libsrc/creativision/crt0.s +++ b/libsrc/creativision/crt0.s @@ -40,8 +40,8 @@ entry: ; Setup the argument stack ptr lda #<(__ZP_LAST__ + __STACKSIZE__) ldx #>(__ZP_LAST__ + __STACKSIZE__) - sta sp - stx sp+1 + sta c_sp + stx c_sp+1 ; Call module constructors jsr initlib diff --git a/libsrc/cx16/crt0.s b/libsrc/cx16/crt0.s index e37a64a7c..5ee81b184 100644 --- a/libsrc/cx16/crt0.s +++ b/libsrc/cx16/crt0.s @@ -80,8 +80,8 @@ init: lda #<(__MAIN_START__ + __MAIN_SIZE__) ldx #>(__MAIN_START__ + __MAIN_SIZE__) - sta sp - stx sp+1 ; Set argument stack ptr + sta c_sp + stx c_sp+1 ; Set argument stack ptr ; Switch to the lower/UPPER PetSCII charset. diff --git a/libsrc/cx16/mou/cx16-std.s b/libsrc/cx16/mou/cx16-std.s index f211815de..5bfe27a7d 100644 --- a/libsrc/cx16/mou/cx16-std.s +++ b/libsrc/cx16/mou/cx16-std.s @@ -238,11 +238,11 @@ MOVE: php jsr CMOVEY ; Set it ldy #$01 - lda (sp),y + lda (c_sp),y sta XPos+1 tax dey - lda (sp),y + lda (c_sp),y sta XPos ; New X position jsr CMOVEX ; Move the cursor diff --git a/libsrc/dbg/dbgdump.s b/libsrc/dbg/dbgdump.s index bc6a4bd40..335175840 100644 --- a/libsrc/dbg/dbgdump.s +++ b/libsrc/dbg/dbgdump.s @@ -7,23 +7,23 @@ .export _DbgMemDump .import addysp1 .import __hextab - .importzp sp, tmp2, tmp3, tmp4, ptr3, ptr4 + .importzp c_sp, tmp2, tmp3, tmp4, ptr3, ptr4 _DbgMemDump: ldy #0 - lda (sp),y ; Get length + lda (c_sp),y ; Get length sta tmp4 iny - lda (sp),y ; Get the string buffer + lda (c_sp),y ; Get the string buffer sta ptr3 iny - lda (sp),y + lda (c_sp),y sta ptr3+1 iny - lda (sp),y ; Get the address + lda (c_sp),y ; Get the address sta ptr4 iny - lda (sp),y + lda (c_sp),y sta ptr4+1 jsr addysp1 ; Drop the parameters diff --git a/libsrc/dbg/dbgsupp.s b/libsrc/dbg/dbgsupp.s index b1f122013..ce503bcab 100644 --- a/libsrc/dbg/dbgsupp.s +++ b/libsrc/dbg/dbgsupp.s @@ -36,9 +36,9 @@ DbgBreak: jsr DbgSwapZP ; Swap stuff lda #DbgStack - sta sp+1 + sta c_sp+1 jsr ResetDbgBreaks ; Reset temporary breakpoints jsr _DbgEntry ; Call C code jsr SetDbgBreaks ; Set temporary breakpoints @@ -61,7 +61,7 @@ DbgStack: ; Swap space for the C temporaries CTemp: -_DbgCS: .res 2 ; sp +_DbgCS: .res 2 ; c_sp _DbgHI: .res 2 ; sreg .res (zpsavespace-4) ; Other stuff @@ -78,7 +78,7 @@ Swap1: ldx CTemp,y lda <__ZP_START__,y sta CTemp,y txa - sta sp,y + sta c_sp,y dey bpl Swap1 rts diff --git a/libsrc/gamate/crt0.s b/libsrc/gamate/crt0.s index 5a5bb3aa0..67fa8813f 100644 --- a/libsrc/gamate/crt0.s +++ b/libsrc/gamate/crt0.s @@ -34,8 +34,8 @@ Start: ; Set up the stack lda #<(__RAM_START__+__RAM_SIZE__) ldx #>(__RAM_START__+__RAM_SIZE__) - sta sp - stx sp + 1 + sta c_sp + stx c_sp + 1 ; Call module constructors jsr initlib diff --git a/libsrc/geos-common/drivers/geos-stdmou.s b/libsrc/geos-common/drivers/geos-stdmou.s index 88bbc7df9..aacb2590e 100644 --- a/libsrc/geos-common/drivers/geos-stdmou.s +++ b/libsrc/geos-common/drivers/geos-stdmou.s @@ -13,7 +13,7 @@ .export _mouse_move, _mouse_buttons .import popsreg, addysp1 - .importzp sp, sreg, ptr1 + .importzp c_sp, sreg, ptr1 .include "const.inc" .include "jumptab.inc" @@ -87,22 +87,22 @@ _mouse_box: sta mouseBottom - lda (sp),y + lda (c_sp),y sta mouseRight iny - lda (sp),y + lda (c_sp),y sta mouseRight+1 ; maxx iny - lda (sp),y + lda (c_sp),y sta mouseTop iny ; Skip high byte iny - lda (sp),y + lda (c_sp),y sta mouseLeft iny - lda (sp),y + lda (c_sp),y sta mouseLeft+1 ; minx jmp addysp1 ; Drop params, return diff --git a/libsrc/geos-common/system/crt0.s b/libsrc/geos-common/system/crt0.s index 47cec74f2..e1751baef 100644 --- a/libsrc/geos-common/system/crt0.s +++ b/libsrc/geos-common/system/crt0.s @@ -11,7 +11,7 @@ .import initlib, donelib .import callmain .import zerobss - .importzp sp + .importzp c_sp .include "jumptab.inc" .include "geossym.inc" @@ -48,8 +48,8 @@ lda #<(__STACKADDR__ + __STACKSIZE__) ldx #>(__STACKADDR__ + __STACKSIZE__) - sta sp - stx sp+1 + sta c_sp + stx c_sp+1 ; Call the module constructors. diff --git a/libsrc/kim1/crt0.s b/libsrc/kim1/crt0.s index 906b3b980..adc934a78 100644 --- a/libsrc/kim1/crt0.s +++ b/libsrc/kim1/crt0.s @@ -26,9 +26,9 @@ _init: cld ; Clear decimal mode ; Set cc65 argument stack pointer lda #<(__RAM_START__ + __RAM_SIZE__) - sta sp + sta c_sp lda #>(__RAM_START__ + __RAM_SIZE__) - sta sp+1 + sta c_sp+1 ; Initialize memory storage diff --git a/libsrc/lynx/crt0.s b/libsrc/lynx/crt0.s index 030f523e9..e1f1c078e 100644 --- a/libsrc/lynx/crt0.s +++ b/libsrc/lynx/crt0.s @@ -80,8 +80,8 @@ MikeyInitData: .byte $9e,$18,$68,$1f,$00,$00,$00,$00,$00,$ff,$1a,$1b,$04,$0d,$2 lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__) ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__) - sta sp - stx sp+1 + sta c_sp + stx c_sp+1 ; Init Mickey. diff --git a/libsrc/lynx/lseek.s b/libsrc/lynx/lseek.s index 04d816945..da0a1922b 100644 --- a/libsrc/lynx/lseek.s +++ b/libsrc/lynx/lseek.s @@ -11,7 +11,7 @@ ; ; off_t __fastcall__ lseek(int fd, off_t offset, int whence); - .importzp sp, sreg, regsave, regbank, tmp1, ptr1, ptr2 + .importzp c_sp, sreg, regsave, regbank, tmp1, ptr1, ptr2 .macpack longbranch .export _lseek .import addysp, stax0sp, tosand0ax, pusheax, asreax2 diff --git a/libsrc/nes/crt0.s b/libsrc/nes/crt0.s index 19e97bb12..dfc26dcde 100644 --- a/libsrc/nes/crt0.s +++ b/libsrc/nes/crt0.s @@ -107,8 +107,8 @@ start: lda #<(__SRAM_START__ + __SRAM_SIZE__) ldx #>(__SRAM_START__ + __SRAM_SIZE__) - sta sp - stx sp+1 ; Set argument stack ptr + sta c_sp + stx c_sp+1 ; Set argument stack ptr ; Call the module constructors. diff --git a/libsrc/none/crt0.s b/libsrc/none/crt0.s index 596fbcd46..443f453b9 100644 --- a/libsrc/none/crt0.s +++ b/libsrc/none/crt0.s @@ -10,8 +10,8 @@ lda #<__STACKSTART__ ldx #>__STACKSTART__ - sta sp - stx sp+1 + sta c_sp + stx c_sp+1 jsr zerobss jsr initlib jsr _main diff --git a/libsrc/osic1p/crt0.s b/libsrc/osic1p/crt0.s index 56abb7cdb..46d29ed66 100644 --- a/libsrc/osic1p/crt0.s +++ b/libsrc/osic1p/crt0.s @@ -34,8 +34,8 @@ _init: ldx #$FF ; Initialize stack pointer to $01FF lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__) ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__) - sta sp - stx sp+1 + sta c_sp + stx c_sp+1 ; --------------------------------------------------------------------------- ; Initialize memory storage diff --git a/libsrc/pce/_printf.s b/libsrc/pce/_printf.s index e1d2a1cf4..675076ec6 100644 --- a/libsrc/pce/_printf.s +++ b/libsrc/pce/_printf.s @@ -329,22 +329,22 @@ 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 - sta (sp),y + sta (c_sp),y jsr CallOutFunc ; Call the output function ; We're back from out(), or we didn't call it. Check for end of string. diff --git a/libsrc/pce/crt0.s b/libsrc/pce/crt0.s index d6dee3ef4..660faae7f 100644 --- a/libsrc/pce/crt0.s +++ b/libsrc/pce/crt0.s @@ -13,7 +13,7 @@ .import initlib, donelib .import push0, _main .import IRQStub, __nmi - .importzp sp + .importzp c_sp ; Linker-generated .import __CARTSIZE__ @@ -86,8 +86,8 @@ start: sei ; Set up the stack lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__) ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__) - sta sp - stx sp+1 + sta c_sp + stx c_sp+1 ; Call the module constructors. jsr initlib diff --git a/libsrc/pce/memcpy.s b/libsrc/pce/memcpy.s index 98db6a964..7ee33477b 100644 --- a/libsrc/pce/memcpy.s +++ b/libsrc/pce/memcpy.s @@ -18,7 +18,7 @@ .export memcpy_increment, memcpy_transfer, memcpy_getparams .import incsp2, popax, popptr1 - .importzp sp, ptr1, ptr2, ptr3 + .importzp c_sp, ptr1, ptr2, ptr3 ; The structure of the transfer instructions @@ -86,9 +86,9 @@ memcpy_getparams: ; (Direct stack access is six cycles faster [total cycle count].) iny ; (Y=0 by popptr1, need '1' here) save dest - lda (sp),y ; get high byte + lda (c_sp),y ; get high byte tax - lda (sp) ; get low byte + lda (c_sp) ; get low byte sta ptr2 stx ptr2+1 rts ; return dest address (for memmove) diff --git a/libsrc/pet/crt0.s b/libsrc/pet/crt0.s index e56a7eca4..e3c6ed4b4 100644 --- a/libsrc/pet/crt0.s +++ b/libsrc/pet/crt0.s @@ -23,7 +23,7 @@ Start: ; Save the zero-page locations that we need. ldx #zpspace-1 -L1: lda sp,x +L1: lda c_sp,x sta zpsave,x dex bpl L1 @@ -52,9 +52,9 @@ L1: lda sp,x stx spsave ; Save the system stack ptr lda MEMSIZE - sta sp + sta c_sp lda MEMSIZE+1 - sta sp+1 ; Set argument stack ptr + sta c_sp+1 ; Set argument stack ptr ; Call the module constructors. @@ -73,7 +73,7 @@ _exit: pha ; Save the return code on stack ldx #zpspace-1 L2: lda zpsave,x - sta sp,x + sta c_sp,x dex bpl L2 diff --git a/libsrc/plus4/crt0.s b/libsrc/plus4/crt0.s index d1eea9472..a8a5b8e63 100644 --- a/libsrc/plus4/crt0.s +++ b/libsrc/plus4/crt0.s @@ -33,7 +33,7 @@ Start: sei ; No interrupts since we're banking out the ROM sta ENABLE_RAM ldx #zpspace-1 -L1: lda sp,x +L1: lda c_sp,x sta zpsave,x dex bpl L1 @@ -53,8 +53,8 @@ L1: lda sp,x lda #<__HIMEM__ ldx #>__HIMEM__ - sta sp - stx sp+1 + sta c_sp + stx c_sp+1 ; Set up the IRQ vector in the banked RAM; and, switch off the ROM. @@ -114,7 +114,7 @@ _exit: pha ; Save the return code ldx #zpspace-1 L2: lda zpsave,x - sta sp,x + sta c_sp,x dex bpl L2 diff --git a/libsrc/rp6502/crt0.s b/libsrc/rp6502/crt0.s index 165ecf0a2..32d565fda 100644 --- a/libsrc/rp6502/crt0.s +++ b/libsrc/rp6502/crt0.s @@ -24,9 +24,9 @@ _init: ; Set cc65 argument stack pointer lda #<(__RAM_START__ + __RAM_SIZE__) - sta sp + sta c_sp lda #>(__RAM_START__ + __RAM_SIZE__) - sta sp+1 + sta c_sp+1 ; Initialize memory storage jsr zerobss ; Clear BSS segment diff --git a/libsrc/rp6502/ria.s b/libsrc/rp6502/ria.s index a1b53efb1..78da4daba 100644 --- a/libsrc/rp6502/ria.s +++ b/libsrc/rp6502/ria.s @@ -11,7 +11,7 @@ .export _ria_call_int, _ria_call_long .export _ria_call_int_errno, _ria_call_long_errno -.importzp sp, sreg +.importzp c_sp, sreg .import ___mappederrno, incsp1 .code diff --git a/libsrc/rp6502/xreg.s b/libsrc/rp6502/xreg.s index 40d4a6705..a882ab10f 100644 --- a/libsrc/rp6502/xreg.s +++ b/libsrc/rp6502/xreg.s @@ -5,7 +5,7 @@ ; int __cdecl__ xreg(char device, char channel, unsigned char address, ...); .export _xreg -.importzp sp +.importzp c_sp .import addysp, _ria_call_int_errno .include "rp6502.inc" @@ -20,12 +20,12 @@ @copy: ; copy stack dey - lda (sp),y + lda (c_sp),y sta RIA_XSTACK tya bne @copy - ; recover variadic size and move sp + ; recover variadic size and move c_sp txa tay jsr addysp diff --git a/libsrc/runtime/add.s b/libsrc/runtime/add.s index a4658cc13..85ddd0f25 100644 --- a/libsrc/runtime/add.s +++ b/libsrc/runtime/add.s @@ -9,7 +9,7 @@ ; called a lot! .export tosadda0, tosaddax - .importzp sp, tmp1 + .importzp c_sp, tmp1 .macpack cpu @@ -20,34 +20,34 @@ tosaddax: .if (.cpu .bitand ::CPU_ISET_65SC02) - adc (sp) ; (7) + adc (c_sp) ; (7) tay ; (9) - inc sp ; (14) + inc c_sp ; (14) bne hiadd ; (17) - inc sp+1 ; (-1+5) + inc c_sp+1 ; (-1+5) hiadd: txa ; (19) - adc (sp) ; (24) + adc (c_sp) ; (24) tax ; (26) - inc sp ; (31) + inc c_sp ; (31) bne done ; (34) - inc sp+1 ; (-1+5) + inc c_sp+1 ; (-1+5) done: tya ; (36) .else ldy #0 ; (4) - adc (sp),y ; (9) lo byte + adc (c_sp),y ; (9) lo byte iny ; (11) sta tmp1 ; (14) save it txa ; (16) - adc (sp),y ; (21) hi byte + adc (c_sp),y ; (21) hi byte tax ; (23) clc ; (25) - lda sp ; (28) + lda c_sp ; (28) adc #2 ; (30) - sta sp ; (33) + sta c_sp ; (33) bcc L1 ; (36) - inc sp+1 ; (-1+5) + inc c_sp+1 ; (-1+5) L1: lda tmp1 ; (39) restore low byte .endif diff --git a/libsrc/runtime/addeqsp.s b/libsrc/runtime/addeqsp.s index 5112d2790..3c098ea5f 100644 --- a/libsrc/runtime/addeqsp.s +++ b/libsrc/runtime/addeqsp.s @@ -5,19 +5,19 @@ ; .export addeq0sp, addeqysp - .importzp sp + .importzp c_sp addeq0sp: ldy #0 addeqysp: clc - adc (sp),y - sta (sp),y + adc (c_sp),y + sta (c_sp),y pha iny txa - adc (sp),y - sta (sp),y + adc (c_sp),y + sta (c_sp),y tax pla rts diff --git a/libsrc/runtime/addysp.s b/libsrc/runtime/addysp.s index e0e7db1ce..d48e048bb 100644 --- a/libsrc/runtime/addysp.s +++ b/libsrc/runtime/addysp.s @@ -5,17 +5,17 @@ ; .export addysp1, addysp - .importzp sp + .importzp c_sp addysp1: iny addysp: pha ; Save A clc tya ; Get the value - adc sp ; Add low byte - sta sp ; Put it back + adc c_sp ; Add low byte + sta c_sp ; Put it back bcc @L1 ; If no carry, we're done - inc sp+1 ; Inc high byte + inc c_sp+1 ; Inc high byte @L1: pla ; Restore A rts diff --git a/libsrc/runtime/and.s b/libsrc/runtime/and.s index 8c180b580..8411660ab 100644 --- a/libsrc/runtime/and.s +++ b/libsrc/runtime/and.s @@ -6,7 +6,7 @@ .export tosanda0, tosandax .import addysp1 - .importzp sp, ptr4 + .importzp c_sp, ptr4 .macpack cpu @@ -14,16 +14,16 @@ tosanda0: ldx #$00 tosandax: .if (.cpu .bitand CPU_ISET_65SC02) - and (sp) ; 65SC02 version, saves 2 cycles and 1 byte + and (c_sp) ; 65SC02 version, saves 2 cycles and 1 byte ldy #1 .else ldy #0 - and (sp),y + and (c_sp),y iny .endif pha txa - and (sp),y + and (c_sp),y tax pla jmp addysp1 ; drop TOS, set condition codes diff --git a/libsrc/runtime/bpushbsp.s b/libsrc/runtime/bpushbsp.s index 1c6add4a9..c2cc18cf6 100644 --- a/libsrc/runtime/bpushbsp.s +++ b/libsrc/runtime/bpushbsp.s @@ -6,12 +6,12 @@ .export bpushbsp, bpushbysp .import pusha - .importzp sp + .importzp c_sp bpushbsp: ldy #0 bpushbysp: - lda (sp),y + lda (c_sp),y jmp pusha diff --git a/libsrc/runtime/decsp1.s b/libsrc/runtime/decsp1.s index 3c673664a..4fd5392bb 100644 --- a/libsrc/runtime/decsp1.s +++ b/libsrc/runtime/decsp1.s @@ -5,14 +5,14 @@ ; .export decsp1 - .importzp sp + .importzp c_sp .proc decsp1 - ldy sp + ldy c_sp bne @L1 - dec sp+1 -@L1: dec sp + dec c_sp+1 +@L1: dec c_sp rts .endproc diff --git a/libsrc/runtime/decsp2.s b/libsrc/runtime/decsp2.s index a3793e778..c6c533d83 100644 --- a/libsrc/runtime/decsp2.s +++ b/libsrc/runtime/decsp2.s @@ -5,18 +5,18 @@ ; .export decsp2 - .importzp sp + .importzp c_sp .proc decsp2 - lda sp + lda c_sp sec sbc #2 - sta sp + sta c_sp bcc @L1 rts -@L1: dec sp+1 +@L1: dec c_sp+1 rts .endproc diff --git a/libsrc/runtime/decsp3.s b/libsrc/runtime/decsp3.s index a3ad7777e..2a2b22a15 100644 --- a/libsrc/runtime/decsp3.s +++ b/libsrc/runtime/decsp3.s @@ -5,18 +5,18 @@ ; .export decsp3 - .importzp sp + .importzp c_sp .proc decsp3 - lda sp + lda c_sp sec sbc #3 - sta sp + sta c_sp bcc @L1 rts -@L1: dec sp+1 +@L1: dec c_sp+1 rts .endproc diff --git a/libsrc/runtime/decsp4.s b/libsrc/runtime/decsp4.s index 5c7e94943..c756473bd 100644 --- a/libsrc/runtime/decsp4.s +++ b/libsrc/runtime/decsp4.s @@ -5,18 +5,18 @@ ; .export decsp4 - .importzp sp + .importzp c_sp .proc decsp4 - lda sp + lda c_sp sec sbc #4 - sta sp + sta c_sp bcc @L1 rts -@L1: dec sp+1 +@L1: dec c_sp+1 rts .endproc diff --git a/libsrc/runtime/decsp5.s b/libsrc/runtime/decsp5.s index 7ff4605cf..71b2fb176 100644 --- a/libsrc/runtime/decsp5.s +++ b/libsrc/runtime/decsp5.s @@ -5,18 +5,18 @@ ; .export decsp5 - .importzp sp + .importzp c_sp .proc decsp5 - lda sp + lda c_sp sec sbc #5 - sta sp + sta c_sp bcc @L1 rts -@L1: dec sp+1 +@L1: dec c_sp+1 rts .endproc diff --git a/libsrc/runtime/decsp6.s b/libsrc/runtime/decsp6.s index 6e55e664d..1d0b93136 100644 --- a/libsrc/runtime/decsp6.s +++ b/libsrc/runtime/decsp6.s @@ -5,18 +5,18 @@ ; .export decsp6 - .importzp sp + .importzp c_sp .proc decsp6 - lda sp + lda c_sp sec sbc #6 - sta sp + sta c_sp bcc @L1 rts -@L1: dec sp+1 +@L1: dec c_sp+1 rts .endproc diff --git a/libsrc/runtime/decsp7.s b/libsrc/runtime/decsp7.s index ee82232f6..1646d9ec9 100644 --- a/libsrc/runtime/decsp7.s +++ b/libsrc/runtime/decsp7.s @@ -5,18 +5,18 @@ ; .export decsp7 - .importzp sp + .importzp c_sp .proc decsp7 - lda sp + lda c_sp sec sbc #7 - sta sp + sta c_sp bcc @L1 rts -@L1: dec sp+1 +@L1: dec c_sp+1 rts .endproc diff --git a/libsrc/runtime/decsp8.s b/libsrc/runtime/decsp8.s index 47d44593e..1726331c5 100644 --- a/libsrc/runtime/decsp8.s +++ b/libsrc/runtime/decsp8.s @@ -5,18 +5,18 @@ ; .export decsp8 - .importzp sp + .importzp c_sp .proc decsp8 - lda sp + lda c_sp sec sbc #8 - sta sp + sta c_sp bcc @L1 rts -@L1: dec sp+1 +@L1: dec c_sp+1 rts .endproc diff --git a/libsrc/runtime/enter.s b/libsrc/runtime/enter.s index c51b4f7bb..454c2a6f9 100644 --- a/libsrc/runtime/enter.s +++ b/libsrc/runtime/enter.s @@ -5,14 +5,14 @@ ; .export enter - .importzp sp + .importzp c_sp enter: tya ; get arg size - ldy sp + ldy c_sp bne L1 - dec sp+1 -L1: dec sp + dec c_sp+1 +L1: dec c_sp ldy #0 - sta (sp),y ; Store the arg count + sta (c_sp),y ; Store the arg count rts diff --git a/libsrc/runtime/eq.s b/libsrc/runtime/eq.s index c2a537a35..87cf1c085 100644 --- a/libsrc/runtime/eq.s +++ b/libsrc/runtime/eq.s @@ -6,7 +6,7 @@ .export toseq00, toseqa0, toseqax .import tosicmp, booleq - .importzp sp, tmp1 + .importzp c_sp, tmp1 toseq00: lda #$00 diff --git a/libsrc/runtime/icmp.s b/libsrc/runtime/icmp.s index 05c73bd01..eba8ce561 100644 --- a/libsrc/runtime/icmp.s +++ b/libsrc/runtime/icmp.s @@ -6,7 +6,7 @@ ; .export tosicmp, tosicmp0 - .importzp sp, sreg + .importzp c_sp, sreg tosicmp0: @@ -17,16 +17,16 @@ tosicmp: stx sreg+1 ; Save ax ldy #$00 - lda (sp),y ; Get low byte + lda (c_sp),y ; Get low byte tax - inc sp ; 5 + inc c_sp ; 5 bne @L1 ; 3 - inc sp+1 ; (5) + inc c_sp+1 ; (5) @L1: - lda (sp),y ; Get high byte - inc sp ; 5 + lda (c_sp),y ; Get high byte + inc c_sp ; 5 bne @L2 ; 3 - inc sp+1 ; (5) + inc c_sp+1 ; (5) ; Do the compare. diff --git a/libsrc/runtime/incsp1.s b/libsrc/runtime/incsp1.s index 2272e200f..dde6c47b2 100644 --- a/libsrc/runtime/incsp1.s +++ b/libsrc/runtime/incsp1.s @@ -5,13 +5,13 @@ ; .export incsp1 - .importzp sp + .importzp c_sp .proc incsp1 - inc sp + inc c_sp bne @L1 - inc sp+1 + inc c_sp+1 @L1: rts .endproc diff --git a/libsrc/runtime/incsp2.s b/libsrc/runtime/incsp2.s index 0ed0ffcdf..c3260c19d 100644 --- a/libsrc/runtime/incsp2.s +++ b/libsrc/runtime/incsp2.s @@ -5,7 +5,7 @@ ; this module also contains the popax function. .export popax, incsp2 - .importzp sp + .importzp c_sp .macpack cpu @@ -14,13 +14,13 @@ .proc popax ldy #1 - lda (sp),y ; get hi byte + lda (c_sp),y ; get hi byte tax ; into x .if (.cpu .bitand ::CPU_ISET_65SC02) - lda (sp) ; get lo byte + lda (c_sp) ; get lo byte .else dey - lda (sp),y ; get lo byte + lda (c_sp),y ; get lo byte .endif .endproc @@ -29,14 +29,14 @@ .proc incsp2 - inc sp ; 5 + inc c_sp ; 5 beq @L1 ; 2 - inc sp ; 5 + inc c_sp ; 5 beq @L2 ; 2 rts -@L1: inc sp ; 5 -@L2: inc sp+1 ; 5 +@L1: inc c_sp ; 5 +@L2: inc c_sp+1 ; 5 rts .endproc diff --git a/libsrc/runtime/ladd.s b/libsrc/runtime/ladd.s index 23b3436c0..6c187f32d 100644 --- a/libsrc/runtime/ladd.s +++ b/libsrc/runtime/ladd.s @@ -6,7 +6,7 @@ .export tosadd0ax, tosaddeax .import addysp1 - .importzp sp, sreg, tmp1 + .importzp c_sp, sreg, tmp1 .macpack cpu @@ -20,24 +20,24 @@ tosadd0ax: tosaddeax: clc .if (.cpu .bitand CPU_ISET_65SC02) - adc (sp) ; 65SC02 version - saves 2 cycles + adc (c_sp) ; 65SC02 version - saves 2 cycles ldy #1 .else ldy #0 - adc (sp),y ; lo byte + adc (c_sp),y ; lo byte iny .endif sta tmp1 ; use as temp storage txa - adc (sp),y ; byte 1 + adc (c_sp),y ; byte 1 tax iny lda sreg - adc (sp),y ; byte 2 + adc (c_sp),y ; byte 2 sta sreg iny lda sreg+1 - adc (sp),y ; byte 3 + adc (c_sp),y ; byte 3 sta sreg+1 lda tmp1 ; load byte 0 jmp addysp1 ; drop TOS diff --git a/libsrc/runtime/laddeqsp.s b/libsrc/runtime/laddeqsp.s index 46c3c1f29..13dbf8112 100644 --- a/libsrc/runtime/laddeqsp.s +++ b/libsrc/runtime/laddeqsp.s @@ -5,29 +5,29 @@ ; .export laddeq0sp, laddeqysp - .importzp sp, sreg + .importzp c_sp, sreg laddeq0sp: ldy #0 laddeqysp: clc - adc (sp),y - sta (sp),y + adc (c_sp),y + sta (c_sp),y pha iny txa - adc (sp),y - sta (sp),y + adc (c_sp),y + sta (c_sp),y tax iny lda sreg - adc (sp),y - sta (sp),y + adc (c_sp),y + sta (c_sp),y sta sreg iny lda sreg+1 - adc (sp),y - sta (sp),y + adc (c_sp),y + sta (c_sp),y sta sreg+1 pla rts diff --git a/libsrc/runtime/land.s b/libsrc/runtime/land.s index 8e21ebb60..400fede3b 100644 --- a/libsrc/runtime/land.s +++ b/libsrc/runtime/land.s @@ -7,7 +7,7 @@ .export tosand0ax, tosandeax .import addysp1 - .importzp sp, sreg, tmp1 + .importzp c_sp, sreg, tmp1 .macpack cpu @@ -23,24 +23,24 @@ tosand0ax: tosandeax: .if (.cpu .bitand ::CPU_ISET_65SC02) - and (sp) ; byte 0 + and (c_sp) ; byte 0 ldy #1 .else ldy #0 - and (sp),y ; byte 0 + and (c_sp),y ; byte 0 iny .endif sta tmp1 txa - and (sp),y ; byte 1 + and (c_sp),y ; byte 1 tax iny lda sreg - and (sp),y ; byte 2 + and (c_sp),y ; byte 2 sta sreg iny lda sreg+1 - and (sp),y ; byte 3 + and (c_sp),y ; byte 3 sta sreg+1 lda tmp1 diff --git a/libsrc/runtime/lcmp.s b/libsrc/runtime/lcmp.s index d0ba4d81f..59c02dd56 100644 --- a/libsrc/runtime/lcmp.s +++ b/libsrc/runtime/lcmp.s @@ -7,7 +7,7 @@ .export toslcmp .import incsp4 - .importzp sp, sreg, ptr1 + .importzp c_sp, sreg, ptr1 toslcmp: @@ -15,23 +15,23 @@ toslcmp: stx ptr1+1 ; EAX now in sreg:ptr1 ldy #$03 - lda (sp),y + lda (c_sp),y sec sbc sreg+1 bne L4 dey - lda (sp),y + lda (c_sp),y cmp sreg bne L1 dey - lda (sp),y + lda (c_sp),y cmp ptr1+1 bne L1 dey - lda (sp),y + lda (c_sp),y cmp ptr1 L1: php ; Save flags diff --git a/libsrc/runtime/ldau0sp.s b/libsrc/runtime/ldau0sp.s index a986d52da..a808f6f84 100644 --- a/libsrc/runtime/ldau0sp.s +++ b/libsrc/runtime/ldau0sp.s @@ -5,17 +5,17 @@ ; .export ldau00sp, ldau0ysp - .importzp sp, ptr1 + .importzp c_sp, ptr1 .macpack cpu ldau00sp: ldy #1 ldau0ysp: - lda (sp),y + lda (c_sp),y sta ptr1+1 dey - lda (sp),y + lda (c_sp),y sta ptr1 ldx #0 .if (.cpu .bitand CPU_ISET_65SC02) diff --git a/libsrc/runtime/ldauisp.s b/libsrc/runtime/ldauisp.s index 54f4d1bd1..957f245be 100644 --- a/libsrc/runtime/ldauisp.s +++ b/libsrc/runtime/ldauisp.s @@ -5,15 +5,15 @@ ; .export ldaui0sp, ldauiysp - .importzp sp, ptr1 + .importzp c_sp, ptr1 ldaui0sp: ldy #1 ldauiysp: - lda (sp),y + lda (c_sp),y sta ptr1+1 dey - lda (sp),y + lda (c_sp),y sta ptr1 txa tay diff --git a/libsrc/runtime/ldaxsp.s b/libsrc/runtime/ldaxsp.s index aa94b43cd..b744ce242 100644 --- a/libsrc/runtime/ldaxsp.s +++ b/libsrc/runtime/ldaxsp.s @@ -5,16 +5,16 @@ ; .export ldax0sp, ldaxysp - .importzp sp + .importzp c_sp ; Beware: The optimizer knows about the value in Y after return! ldax0sp: ldy #1 ldaxysp: - lda (sp),y ; get high byte + lda (c_sp),y ; get high byte tax ; and save it dey ; point to lo byte - lda (sp),y ; load low byte + lda (c_sp),y ; load low byte rts diff --git a/libsrc/runtime/ldeaxysp.s b/libsrc/runtime/ldeaxysp.s index 1d65e9c38..b6ce7254f 100644 --- a/libsrc/runtime/ldeaxysp.s +++ b/libsrc/runtime/ldeaxysp.s @@ -9,20 +9,20 @@ .export ldeax0sp, ldeaxysp - .importzp sreg, sp + .importzp sreg, c_sp ldeax0sp: ldy #3 ldeaxysp: - lda (sp),y + lda (c_sp),y sta sreg+1 dey - lda (sp),y + lda (c_sp),y sta sreg dey - lda (sp),y + lda (c_sp),y tax dey - lda (sp),y + lda (c_sp),y rts diff --git a/libsrc/runtime/leaaxsp.s b/libsrc/runtime/leaaxsp.s index 0741170ca..451d7191f 100644 --- a/libsrc/runtime/leaaxsp.s +++ b/libsrc/runtime/leaaxsp.s @@ -5,16 +5,16 @@ ; .export leaaxsp, leaa0sp - .importzp sp + .importzp c_sp leaa0sp: ldx #$00 leaaxsp: clc - adc sp + adc c_sp pha txa - adc sp+1 + adc c_sp+1 tax pla rts diff --git a/libsrc/runtime/leave.s b/libsrc/runtime/leave.s index 95dcdec9d..408fdd159 100644 --- a/libsrc/runtime/leave.s +++ b/libsrc/runtime/leave.s @@ -12,7 +12,7 @@ .export leave00, leave0, leavey00, leavey0, leavey .export leave .import addysp - .importzp sp + .importzp c_sp .macpack cpu @@ -31,24 +31,24 @@ leavey: .if (.cpu .bitand ::CPU_ISET_65SC02) leave: tay ; save A a sec - lda (sp) ; that's the pushed arg size + lda (c_sp) ; that's the pushed arg size sec ; Count the byte, the count's stored in - adc sp - sta sp + adc c_sp + sta c_sp bcc L1 - inc sp+1 + inc c_sp+1 L1: tya ; Get return value back .else leave: pha ; save A a sec ldy #0 - lda (sp),y ; that's the pushed arg size + lda (c_sp),y ; that's the pushed arg size sec ; Count the byte, the count's stored in - adc sp - sta sp + adc c_sp + sta c_sp bcc L1 - inc sp+1 + inc c_sp+1 L1: pla ; Get return value back .endif diff --git a/libsrc/runtime/lmul.s b/libsrc/runtime/lmul.s index 90d5f1e97..a68c3e5c1 100644 --- a/libsrc/runtime/lmul.s +++ b/libsrc/runtime/lmul.s @@ -7,7 +7,7 @@ .export tosumul0ax, tosumuleax, tosmul0ax, tosmuleax .import addysp1 - .importzp sp, sreg, tmp1, tmp2, tmp3, tmp4, ptr1, ptr3, ptr4 + .importzp c_sp, sreg, tmp1, tmp2, tmp3, tmp4, ptr1, ptr3, ptr4 .macpack cpu @@ -27,21 +27,21 @@ tosumuleax: mul32: sta ptr1 stx ptr1+1 ; op2 now in ptr1/sreg .if (.cpu .bitand ::CPU_ISET_65SC02) - lda (sp) + lda (c_sp) ldy #1 .else ldy #0 - lda (sp),y + lda (c_sp),y iny .endif sta ptr3 - lda (sp),y + lda (c_sp),y sta ptr3+1 iny - lda (sp),y + lda (c_sp),y sta ptr4 iny - lda (sp),y + lda (c_sp),y sta ptr4+1 ; op1 in pre3/ptr4 jsr addysp1 ; Drop TOS diff --git a/libsrc/runtime/lor.s b/libsrc/runtime/lor.s index f2204b981..888a0c611 100644 --- a/libsrc/runtime/lor.s +++ b/libsrc/runtime/lor.s @@ -7,7 +7,7 @@ .export tosor0ax, tosoreax .import addysp1 - .importzp sp, sreg, tmp1 + .importzp c_sp, sreg, tmp1 .macpack cpu @@ -23,24 +23,24 @@ tosor0ax: tosoreax: .if (.cpu .bitand ::CPU_ISET_65SC02) - ora (sp) + ora (c_sp) ldy #1 .else ldy #0 - ora (sp),y ; byte 0 + ora (c_sp),y ; byte 0 iny .endif sta tmp1 txa - ora (sp),y ; byte 1 + ora (c_sp),y ; byte 1 tax iny lda sreg - ora (sp),y ; byte 2 + ora (c_sp),y ; byte 2 sta sreg iny lda sreg+1 - ora (sp),y ; byte 3 + ora (c_sp),y ; byte 3 sta sreg+1 lda tmp1 diff --git a/libsrc/runtime/lpop.s b/libsrc/runtime/lpop.s index a90ea5fcb..9690aff24 100644 --- a/libsrc/runtime/lpop.s +++ b/libsrc/runtime/lpop.s @@ -7,24 +7,24 @@ .export popeax .import incsp4 - .importzp sp, sreg + .importzp c_sp, sreg .macpack cpu popeax: ldy #3 - lda (sp),y + lda (c_sp),y sta sreg+1 dey - lda (sp),y + lda (c_sp),y sta sreg dey - lda (sp),y + lda (c_sp),y tax .if (.cpu .bitand ::CPU_ISET_65SC02) - lda (sp) + lda (c_sp) .else dey - lda (sp),y + lda (c_sp),y .endif jmp incsp4 diff --git a/libsrc/runtime/lpush.s b/libsrc/runtime/lpush.s index 0bc67b523..ec2c865af 100644 --- a/libsrc/runtime/lpush.s +++ b/libsrc/runtime/lpush.s @@ -10,7 +10,7 @@ ; .export pushl0, push0ax, pusheax .import decsp4 - .importzp sp, sreg + .importzp c_sp, sreg .macpack cpu @@ -31,19 +31,19 @@ pusheax: jsr decsp4 ldy #3 lda sreg+1 - sta (sp),y + sta (c_sp),y dey lda sreg - sta (sp),y + sta (c_sp),y dey txa - sta (sp),y + sta (c_sp),y pla .if (.cpu .bitand ::CPU_ISET_65SC02) - sta (sp) + sta (c_sp) .else dey - sta (sp),y + sta (c_sp),y .endif rts diff --git a/libsrc/runtime/lrsub.s b/libsrc/runtime/lrsub.s index 5e8d0b543..456d8d8d5 100644 --- a/libsrc/runtime/lrsub.s +++ b/libsrc/runtime/lrsub.s @@ -10,7 +10,7 @@ ; .export tosrsub0ax, tosrsubeax .import addysp1 - .importzp sp, sreg, tmp1 + .importzp c_sp, sreg, tmp1 .macpack cpu @@ -27,24 +27,24 @@ tosrsub0ax: tosrsubeax: sec .if (.cpu .bitand ::CPU_ISET_65SC02) - sbc (sp) + sbc (c_sp) ldy #1 .else ldy #0 - sbc (sp),y ; byte 0 + sbc (c_sp),y ; byte 0 iny .endif sta tmp1 ; use as temp storage txa - sbc (sp),y ; byte 1 + sbc (c_sp),y ; byte 1 tax iny lda sreg - sbc (sp),y ; byte 2 + sbc (c_sp),y ; byte 2 sta sreg iny lda sreg+1 - sbc (sp),y ; byte 3 + sbc (c_sp),y ; byte 3 sta sreg+1 lda tmp1 jmp addysp1 ; drop TOS diff --git a/libsrc/runtime/lsub.s b/libsrc/runtime/lsub.s index 4c50ded14..17b225404 100644 --- a/libsrc/runtime/lsub.s +++ b/libsrc/runtime/lsub.s @@ -9,7 +9,7 @@ ; .export tossub0ax, tossubeax .import addysp1 - .importzp sp, sreg + .importzp c_sp, sreg .macpack cpu @@ -27,24 +27,24 @@ tossubeax: sec eor #$FF .if (.cpu .bitand ::CPU_ISET_65SC02) - adc (sp) ; 65SC02 version - saves 2 cycles + adc (c_sp) ; 65SC02 version - saves 2 cycles ldy #1 .else ldy #0 - adc (sp),y ; lo byte + adc (c_sp),y ; lo byte iny .endif pha ; Save low byte txa eor #$FF - adc (sp),y ; byte 1 + adc (c_sp),y ; byte 1 tax iny - lda (sp),y + lda (c_sp),y sbc sreg ; byte 2 sta sreg iny - lda (sp),y + lda (c_sp),y sbc sreg+1 ; byte 3 sta sreg+1 pla ; Restore byte 0 diff --git a/libsrc/runtime/lsubeqsp.s b/libsrc/runtime/lsubeqsp.s index f32930c69..6f8377484 100644 --- a/libsrc/runtime/lsubeqsp.s +++ b/libsrc/runtime/lsubeqsp.s @@ -5,31 +5,31 @@ ; .export lsubeq0sp, lsubeqysp - .importzp sp, sreg + .importzp c_sp, sreg lsubeq0sp: ldy #0 lsubeqysp: sec eor #$FF - adc (sp),y - sta (sp),y + adc (c_sp),y + sta (c_sp),y pha ; Save low byte iny txa eor #$FF - adc (sp),y - sta (sp),y + adc (c_sp),y + sta (c_sp),y tax iny - lda (sp),y + lda (c_sp),y sbc sreg - sta (sp),y + sta (c_sp),y sta sreg iny - lda (sp),y + lda (c_sp),y sbc sreg+1 - sta (sp),y + sta (c_sp),y sta sreg+1 pla rts diff --git a/libsrc/runtime/ludiv.s b/libsrc/runtime/ludiv.s index 77335d8f5..b47207222 100644 --- a/libsrc/runtime/ludiv.s +++ b/libsrc/runtime/ludiv.s @@ -7,7 +7,7 @@ .export tosudiv0ax, tosudiveax, getlop, udiv32 .import addysp1 - .importzp sp, sreg, tmp3, tmp4, ptr1, ptr2, ptr3, ptr4 + .importzp c_sp, sreg, tmp3, tmp4, ptr1, ptr2, ptr3, ptr4 .macpack cpu @@ -39,21 +39,21 @@ getlop: sta ptr3 ; Put right operand in place sta ptr4+1 .if (.cpu .bitand ::CPU_ISET_65SC02) - lda (sp) + lda (c_sp) ldy #1 .else ldy #0 ; Put left operand in place - lda (sp),y + lda (c_sp),y iny .endif sta ptr1 - lda (sp),y + lda (c_sp),y sta ptr1+1 iny - lda (sp),y + lda (c_sp),y sta sreg iny - lda (sp),y + lda (c_sp),y sta sreg+1 jmp addysp1 ; Drop parameters diff --git a/libsrc/runtime/lxor.s b/libsrc/runtime/lxor.s index a92a59959..6d9f7db3a 100644 --- a/libsrc/runtime/lxor.s +++ b/libsrc/runtime/lxor.s @@ -7,7 +7,7 @@ .export tosxor0ax, tosxoreax .import addysp1 - .importzp sp, sreg, tmp1 + .importzp c_sp, sreg, tmp1 .macpack cpu @@ -23,24 +23,24 @@ tosxor0ax: tosxoreax: .if (.cpu .bitand ::CPU_ISET_65SC02) - eor (sp) ; byte 0 + eor (c_sp) ; byte 0 ldy #1 .else ldy #0 - eor (sp),y ; byte 0 + eor (c_sp),y ; byte 0 iny .endif sta tmp1 txa - eor (sp),y ; byte 1 + eor (c_sp),y ; byte 1 tax iny lda sreg - eor (sp),y ; byte 2 + eor (c_sp),y ; byte 2 sta sreg iny lda sreg+1 - eor (sp),y ; byte 3 + eor (c_sp),y ; byte 3 sta sreg+1 lda tmp1 diff --git a/libsrc/runtime/or.s b/libsrc/runtime/or.s index 735f30f61..04389be5f 100644 --- a/libsrc/runtime/or.s +++ b/libsrc/runtime/or.s @@ -7,7 +7,7 @@ .export tosora0, tosorax .import addysp1 - .importzp sp, tmp1 + .importzp c_sp, tmp1 .macpack cpu @@ -15,16 +15,16 @@ tosora0: ldx #$00 tosorax: .if (.cpu .bitand ::CPU_ISET_65SC02) - ora (sp) + ora (c_sp) ldy #1 .else ldy #0 - ora (sp),y + ora (c_sp),y iny .endif sta tmp1 txa - ora (sp),y + ora (c_sp),y tax lda tmp1 jmp addysp1 ; drop TOS, set condition codes diff --git a/libsrc/runtime/popa.s b/libsrc/runtime/popa.s index bb74df0ca..c1700071d 100644 --- a/libsrc/runtime/popa.s +++ b/libsrc/runtime/popa.s @@ -5,23 +5,23 @@ ; .export popa - .importzp sp + .importzp c_sp .macpack cpu .proc popa .if (.cpu .bitand ::CPU_ISET_65SC02) - lda (sp) + lda (c_sp) .else ldy #0 ; (2) - lda (sp),y ; (7) Read byte + lda (c_sp),y ; (7) Read byte .endif - inc sp ; (12) + inc c_sp ; (12) beq @L1 ; (14) rts ; (20) -@L1: inc sp+1 +@L1: inc c_sp+1 rts .endproc diff --git a/libsrc/runtime/popptr1.s b/libsrc/runtime/popptr1.s index b54bb9eb3..45043dd27 100644 --- a/libsrc/runtime/popptr1.s +++ b/libsrc/runtime/popptr1.s @@ -6,19 +6,19 @@ .export popptr1 .import incsp2 - .importzp sp, ptr1 + .importzp c_sp, ptr1 .macpack cpu .proc popptr1 ; 14 bytes (four usages = at least 2 bytes saved) ldy #1 - lda (sp),y ; get hi byte + 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) - lda (sp) ; get lo byte + lda (c_sp) ; get lo byte .else - lda (sp),y ; get lo byte + lda (c_sp),y ; get lo byte .endif sta ptr1 ; to ptr lo jmp incsp2 diff --git a/libsrc/runtime/popsreg.s b/libsrc/runtime/popsreg.s index 47d67503a..c7f667246 100644 --- a/libsrc/runtime/popsreg.s +++ b/libsrc/runtime/popsreg.s @@ -6,20 +6,20 @@ .export popsreg .import incsp2 - .importzp sp, sreg + .importzp c_sp, sreg .macpack cpu popsreg: pha ; save A ldy #1 - lda (sp),y ; get hi byte + lda (c_sp),y ; get hi byte sta sreg+1 ; store it .if (.cpu .bitand ::CPU_ISET_65SC02) - lda (sp) ; get lo byte + lda (c_sp) ; get lo byte .else dey - lda (sp),y ; get lo byte + lda (c_sp),y ; get lo byte .endif sta sreg ; store it pla ; get A back diff --git a/libsrc/runtime/pusha.s b/libsrc/runtime/pusha.s index 04233282e..399423077 100644 --- a/libsrc/runtime/pusha.s +++ b/libsrc/runtime/pusha.s @@ -5,7 +5,7 @@ ; .export pusha0sp, pushaysp, pusha - .importzp sp + .importzp c_sp .macpack cpu @@ -14,16 +14,16 @@ pusha0sp: ldy #$00 pushaysp: - lda (sp),y -pusha: ldy sp ; (3) + lda (c_sp),y +pusha: ldy c_sp ; (3) beq @L1 ; (6) - dec sp ; (11) + dec c_sp ; (11) ldy #0 ; (13) - sta (sp),y ; (19) + sta (c_sp),y ; (19) rts ; (25) -@L1: dec sp+1 ; (11) - dec sp ; (16) - sta (sp),y ; (22) +@L1: dec c_sp+1 ; (11) + dec c_sp ; (16) + sta (c_sp),y ; (22) rts ; (28) diff --git a/libsrc/runtime/pushax.s b/libsrc/runtime/pushax.s index 27ddf641d..f77a9bcc3 100644 --- a/libsrc/runtime/pushax.s +++ b/libsrc/runtime/pushax.s @@ -5,7 +5,7 @@ ; .export push0, pusha0, pushax - .importzp sp + .importzp c_sp .macpack cpu @@ -20,21 +20,21 @@ pusha0: ldx #0 .proc pushax pha ; (3) - lda sp ; (6) + lda c_sp ; (6) sec ; (8) sbc #2 ; (10) - sta sp ; (13) + sta c_sp ; (13) bcs @L1 ; (17) - dec sp+1 ; (+5) + dec c_sp+1 ; (+5) @L1: ldy #1 ; (19) txa ; (21) - sta (sp),y ; (27) + sta (c_sp),y ; (27) pla ; (31) dey ; (33) .if (.cpu .bitand ::CPU_ISET_65SC02) - sta (sp) ; (37) + sta (c_sp) ; (37) .else - sta (sp),y ; (38) + sta (c_sp),y ; (38) .endif rts ; (44/43) diff --git a/libsrc/runtime/pushbsp.s b/libsrc/runtime/pushbsp.s index 0b5cbe854..45ad93b12 100644 --- a/libsrc/runtime/pushbsp.s +++ b/libsrc/runtime/pushbsp.s @@ -6,12 +6,12 @@ .export pushbsp, pushbysp .import pusha0 - .importzp sp + .importzp c_sp pushbsp: ldy #0 pushbysp: - lda (sp),y ; get lo byte + lda (c_sp),y ; get lo byte jmp pusha0 ; promote to unsigned and push diff --git a/libsrc/runtime/pushlysp.s b/libsrc/runtime/pushlysp.s index ca1834265..86bb87dbd 100644 --- a/libsrc/runtime/pushlysp.s +++ b/libsrc/runtime/pushlysp.s @@ -7,23 +7,23 @@ .export pushlysp .import pusheax - .importzp sreg, sp + .importzp sreg, c_sp .proc pushlysp iny iny - lda (sp),y + lda (c_sp),y iny sta sreg - lda (sp),y + lda (c_sp),y sta sreg+1 dey dey - lda (sp),y + lda (c_sp),y dey tax - lda (sp),y + lda (c_sp),y jmp pusheax .endproc diff --git a/libsrc/runtime/pushwsp.s b/libsrc/runtime/pushwsp.s index f5ebe0d7e..31c08d624 100644 --- a/libsrc/runtime/pushwsp.s +++ b/libsrc/runtime/pushwsp.s @@ -5,27 +5,27 @@ ; .export pushwysp, pushw0sp - .importzp sp + .importzp c_sp .macpack generic pushw0sp: ldy #3 pushwysp: - lda sp ; 3 + lda c_sp ; 3 sub #2 ; 4 - sta sp ; 3 + sta c_sp ; 3 bcs @L1 ; 3(+1) - dec sp+1 ; (5) -@L1: lda (sp),y ; 5 =16 + dec c_sp+1 ; (5) +@L1: lda (c_sp),y ; 5 =16 tax ; 2 dey ; 2 - lda (sp),y ; 5 + lda (c_sp),y ; 5 ldy #$00 ; 2 - sta (sp),y ; 5 + sta (c_sp),y ; 5 iny ; 2 txa ; 2 - sta (sp),y ; 5 + sta (c_sp),y ; 5 rts diff --git a/libsrc/runtime/regswap.s b/libsrc/runtime/regswap.s index 689d8d12a..17db9ee27 100644 --- a/libsrc/runtime/regswap.s +++ b/libsrc/runtime/regswap.s @@ -5,17 +5,17 @@ ; .export regswap - .importzp sp, regbank, tmp1 + .importzp c_sp, regbank, tmp1 .proc regswap sta tmp1 ; Store count @L1: lda regbank,x ; Get old value pha ; Save it - lda (sp),y ; Get stack loc + lda (c_sp),y ; Get stack loc sta regbank,x ; Store new value pla - sta (sp),y ; Store old value + sta (c_sp),y ; Store old value inx iny dec tmp1 diff --git a/libsrc/runtime/regswap1.s b/libsrc/runtime/regswap1.s index 753020acb..22cf170dc 100644 --- a/libsrc/runtime/regswap1.s +++ b/libsrc/runtime/regswap1.s @@ -5,16 +5,16 @@ ; .export regswap1 - .importzp sp, regbank + .importzp c_sp, regbank .proc regswap1 lda regbank,x ; Get old value pha ; Save it - lda (sp),y ; Get stack loc + lda (c_sp),y ; Get stack loc sta regbank,x ; Store new value pla - sta (sp),y ; Store old value + sta (c_sp),y ; Store old value rts .endproc diff --git a/libsrc/runtime/regswap2.s b/libsrc/runtime/regswap2.s index df5109dc6..07bc7c196 100644 --- a/libsrc/runtime/regswap2.s +++ b/libsrc/runtime/regswap2.s @@ -5,7 +5,7 @@ ; .export regswap2 - .importzp sp, regbank + .importzp c_sp, regbank .proc regswap2 @@ -13,20 +13,20 @@ lda regbank,x ; Get old value pha ; Save it - lda (sp),y ; Get stack loc + lda (c_sp),y ; Get stack loc sta regbank,x ; Store new value pla - sta (sp),y ; Store old value + sta (c_sp),y ; Store old value ; Second byte iny lda regbank+1,x ; Get old value pha ; Save it - lda (sp),y ; Get stack loc + lda (c_sp),y ; Get stack loc sta regbank+1,x ; Store new value pla - sta (sp),y ; Store old value + sta (c_sp),y ; Store old value rts diff --git a/libsrc/runtime/rsub.s b/libsrc/runtime/rsub.s index 69ee6da22..bacb3c7fc 100644 --- a/libsrc/runtime/rsub.s +++ b/libsrc/runtime/rsub.s @@ -7,7 +7,7 @@ .export tosrsuba0, tosrsubax .import addysp1 - .importzp sp, tmp1 + .importzp c_sp, tmp1 .macpack cpu @@ -20,16 +20,16 @@ tosrsuba0: tosrsubax: sec .if (.cpu .bitand CPU_ISET_65SC02) - sbc (sp) + sbc (c_sp) ldy #1 .else ldy #0 - sbc (sp),y ; lo byte + sbc (c_sp),y ; lo byte iny .endif sta tmp1 ; save lo byte txa - sbc (sp),y ; hi byte + sbc (c_sp),y ; hi byte tax lda tmp1 jmp addysp1 ; drop TOS, set condition codes diff --git a/libsrc/runtime/staspidx.s b/libsrc/runtime/staspidx.s index c8d42f34c..bd9b0c79d 100644 --- a/libsrc/runtime/staspidx.s +++ b/libsrc/runtime/staspidx.s @@ -6,17 +6,17 @@ .export staspidx .import incsp2 - .importzp sp, tmp1, ptr1 + .importzp c_sp, tmp1, ptr1 .proc staspidx pha sty tmp1 ; Save Index ldy #1 - lda (sp),y + lda (c_sp),y sta ptr1+1 dey - lda (sp),y + lda (c_sp),y sta ptr1 ; Pointer now in ptr1 ldy tmp1 ; Restore offset pla ; Restore value diff --git a/libsrc/runtime/staxsp.s b/libsrc/runtime/staxsp.s index 599e92a32..15bec22ee 100644 --- a/libsrc/runtime/staxsp.s +++ b/libsrc/runtime/staxsp.s @@ -1,20 +1,20 @@ ; ; Ullrich von Bassewitz, 31.08.1998 ; -; CC65 runtime: Store ax at (sp),y +; CC65 runtime: Store ax at (c_sp),y ; .export staxysp, stax0sp - .importzp sp + .importzp c_sp stax0sp: ldy #0 staxysp: - sta (sp),y + sta (c_sp),y iny pha txa - sta (sp),y + sta (c_sp),y pla rts diff --git a/libsrc/runtime/staxspi.s b/libsrc/runtime/staxspi.s index 3114f449c..aefed428f 100644 --- a/libsrc/runtime/staxspi.s +++ b/libsrc/runtime/staxspi.s @@ -7,7 +7,7 @@ .export staxspidx .import incsp2 - .importzp sp, tmp1, ptr1 + .importzp c_sp, tmp1, ptr1 .macpack cpu @@ -16,13 +16,13 @@ sty tmp1 ; Save Y pha ; Save A ldy #1 - lda (sp),y + lda (c_sp),y sta ptr1+1 .if (.cpu .bitand ::CPU_ISET_65SC02) - lda (sp) + lda (c_sp) .else dey - lda (sp),y + lda (c_sp),y .endif sta ptr1 ; Address now in ptr1 ldy tmp1 ; Restore Y diff --git a/libsrc/runtime/steaxsp.s b/libsrc/runtime/steaxsp.s index 6ac3891c9..33dbc04d7 100644 --- a/libsrc/runtime/steaxsp.s +++ b/libsrc/runtime/steaxsp.s @@ -1,26 +1,26 @@ ; ; Ullrich von Bassewitz, 31.08.1998 ; -; CC65 runtime: Store eax at (sp),y +; CC65 runtime: Store eax at (c_sp),y ; .export steaxysp, steax0sp - .importzp sp, sreg + .importzp c_sp, sreg steax0sp: ldy #0 steaxysp: - sta (sp),y + sta (c_sp),y iny pha txa - sta (sp),y + sta (c_sp),y iny lda sreg - sta (sp),y + sta (c_sp),y iny lda sreg+1 - sta (sp),y + sta (c_sp),y pla rts diff --git a/libsrc/runtime/stkchk.s b/libsrc/runtime/stkchk.s index ceab4c703..a7ca39f21 100644 --- a/libsrc/runtime/stkchk.s +++ b/libsrc/runtime/stkchk.s @@ -17,7 +17,7 @@ .constructor initstkchk, 25 .import __STACKSIZE__ ; Linker defined .import pusha0, _exit - .importzp sp + .importzp c_sp ; Use macros for better readability .macpack generic @@ -32,11 +32,11 @@ .proc initstkchk - lda sp + lda c_sp sta initialsp sub #<__STACKSIZE__ sta lowwater - lda sp+1 + lda c_sp+1 sta initialsp+1 sbc #>__STACKSIZE__ .if (.cpu .bitand ::CPU_ISET_65SC02) @@ -70,7 +70,7 @@ cstkchk: ; Check the high byte of the software stack @L0: lda lowwater+1 - cmp sp+1 + cmp c_sp+1 bcs @L1 rts @@ -78,7 +78,7 @@ cstkchk: @L1: bne CStackOverflow lda lowwater - cmp sp + cmp c_sp bcs CStackOverflow Done: rts @@ -87,9 +87,9 @@ Done: rts CStackOverflow: lda initialsp - sta sp + sta c_sp lda initialsp+1 - sta sp+1 + sta c_sp+1 ; Generic abort entry. We should output a diagnostic here, but this is ; difficult, since we're operating at a lower level here. diff --git a/libsrc/runtime/sub.s b/libsrc/runtime/sub.s index b41df3d91..58ffb4c91 100644 --- a/libsrc/runtime/sub.s +++ b/libsrc/runtime/sub.s @@ -6,7 +6,7 @@ .export tossuba0, tossubax .import addysp1 - .importzp sp + .importzp c_sp .macpack cpu @@ -18,17 +18,17 @@ tossubax: sec eor #$FF .if (.cpu .bitand CPU_ISET_65SC02) - adc (sp) + adc (c_sp) ldy #1 .else ldy #0 - adc (sp),y ; Subtract low byte + adc (c_sp),y ; Subtract low byte iny .endif pha ; Save high byte txa eor #$FF - adc (sp),y ; Subtract high byte + adc (c_sp),y ; Subtract high byte tax ; High byte into X pla ; Restore low byte jmp addysp1 ; drop TOS diff --git a/libsrc/runtime/subeqsp.s b/libsrc/runtime/subeqsp.s index 24080d97d..880e5f2fc 100644 --- a/libsrc/runtime/subeqsp.s +++ b/libsrc/runtime/subeqsp.s @@ -5,21 +5,21 @@ ; .export subeq0sp, subeqysp - .importzp sp + .importzp c_sp subeq0sp: ldy #0 subeqysp: sec eor #$FF - adc (sp),y - sta (sp),y + adc (c_sp),y + sta (c_sp),y pha ; Save low byte iny txa eor #$FF - adc (sp),y - sta (sp),y + adc (c_sp),y + sta (c_sp),y tax pla ; Restore low byte rts diff --git a/libsrc/runtime/subysp.s b/libsrc/runtime/subysp.s index 9fae44222..8f5bea806 100644 --- a/libsrc/runtime/subysp.s +++ b/libsrc/runtime/subysp.s @@ -6,17 +6,17 @@ ; .export subysp - .importzp sp + .importzp c_sp .proc subysp tya eor #$ff sec - adc sp - sta sp + adc c_sp + sta c_sp bcs @L1 - dec sp+1 + dec c_sp+1 @L1: rts .endproc diff --git a/libsrc/runtime/swap.s b/libsrc/runtime/swap.s index 5358e08d3..3796b0a97 100644 --- a/libsrc/runtime/swap.s +++ b/libsrc/runtime/swap.s @@ -6,7 +6,7 @@ ; .export swapstk - .importzp sp, ptr4 + .importzp c_sp, ptr4 .macpack cpu @@ -14,22 +14,22 @@ swapstk: sta ptr4 stx ptr4+1 ldy #1 ; index - lda (sp),y + lda (c_sp),y tax lda ptr4+1 - sta (sp),y + sta (c_sp),y .if (.cpu .bitand ::CPU_ISET_65SC02) - lda (sp) + lda (c_sp) tay lda ptr4 - sta (sp) + sta (c_sp) tya .else dey - lda (sp),y + lda (c_sp),y pha lda ptr4 - sta (sp),y + sta (c_sp),y pla .endif rts ; whew! diff --git a/libsrc/runtime/tosint.s b/libsrc/runtime/tosint.s index ed32298bd..2aaa19ccc 100644 --- a/libsrc/runtime/tosint.s +++ b/libsrc/runtime/tosint.s @@ -6,7 +6,7 @@ .export tosint .import incsp2 - .importzp sp + .importzp c_sp .macpack cpu @@ -16,17 +16,17 @@ pha .if (.cpu .bitand ::CPU_ISET_65SC02) - lda (sp) + lda (c_sp) .else ldy #0 - lda (sp),y ; sp+1 + lda (c_sp),y ; c_sp+1 .endif ldy #2 - sta (sp),y + sta (c_sp),y dey - lda (sp),y + lda (c_sp),y ldy #3 - sta (sp),y + sta (c_sp),y pla jmp incsp2 ; Drop 16 bit diff --git a/libsrc/runtime/toslong.s b/libsrc/runtime/toslong.s index 9065d3e6c..cf8eff031 100644 --- a/libsrc/runtime/toslong.s +++ b/libsrc/runtime/toslong.s @@ -6,7 +6,7 @@ .export tosulong, toslong .import decsp2 - .importzp sp + .importzp c_sp .macpack cpu @@ -16,25 +16,25 @@ tosulong: pha jsr decsp2 ; Make room ldy #2 - lda (sp),y + lda (c_sp),y .if (.cpu .bitand CPU_ISET_65SC02) - sta (sp) ; 65C02 version + sta (c_sp) ; 65C02 version iny ; Y = 3 .else ldy #0 - sta (sp),y + sta (c_sp),y ldy #3 .endif - lda (sp),y + lda (c_sp),y toslong1: ldy #1 - sta (sp),y + sta (c_sp),y lda #0 ; Zero extend toslong2: iny - sta (sp),y + sta (c_sp),y iny - sta (sp),y + sta (c_sp),y pla rts @@ -42,19 +42,19 @@ toslong: pha jsr decsp2 ; Make room ldy #2 - lda (sp),y + lda (c_sp),y .if (.cpu .bitand CPU_ISET_65SC02) - sta (sp) ; 65C02 version + sta (c_sp) ; 65C02 version iny ; Y = 3 .else ldy #0 - sta (sp),y + sta (c_sp),y ldy #3 .endif - lda (sp),y + lda (c_sp),y bpl toslong1 ; Jump if positive, high word is zero ldy #1 - sta (sp),y + sta (c_sp),y lda #$FF bne toslong2 ; Branch always diff --git a/libsrc/runtime/xor.s b/libsrc/runtime/xor.s index e03922926..15394413c 100644 --- a/libsrc/runtime/xor.s +++ b/libsrc/runtime/xor.s @@ -7,7 +7,7 @@ .export tosxora0, tosxorax .import addysp1 - .importzp sp, tmp1 + .importzp c_sp, tmp1 .macpack cpu @@ -15,16 +15,16 @@ tosxora0: ldx #$00 tosxorax: .if (.cpu .bitand CPU_ISET_65SC02) - eor (sp) + eor (c_sp) ldy #1 .else ldy #0 - eor (sp),y + eor (c_sp),y iny .endif sta tmp1 txa - eor (sp),y + eor (c_sp),y tax lda tmp1 jmp addysp1 ; drop TOS, set condition codes diff --git a/libsrc/runtime/zeropage.s b/libsrc/runtime/zeropage.s index 2bbe7ceee..75856f751 100644 --- a/libsrc/runtime/zeropage.s +++ b/libsrc/runtime/zeropage.s @@ -10,7 +10,7 @@ .zeropage -sp: .res 2 ; Stack pointer +c_sp: .res 2 ; Stack pointer sreg: .res 2 ; Secondary register/high 16 bit for longs regsave: .res 4 ; Slot to save/restore (E)AX into ptr1: .res 2 diff --git a/libsrc/sim6502/crt0.s b/libsrc/sim6502/crt0.s index c04a2b8a6..26be7888b 100644 --- a/libsrc/sim6502/crt0.s +++ b/libsrc/sim6502/crt0.s @@ -22,8 +22,8 @@ startup:cld txs lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__) ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__) - sta sp - stx sp+1 + sta c_sp + stx c_sp+1 jsr zerobss jsr initlib jsr callmain diff --git a/libsrc/sim6502/exehdr.s b/libsrc/sim6502/exehdr.s index 6487e5b0c..224b2af2d 100644 --- a/libsrc/sim6502/exehdr.s +++ b/libsrc/sim6502/exehdr.s @@ -5,7 +5,7 @@ ; .export __EXEHDR__ : absolute = 1 ; Linker referenced - .importzp sp + .importzp c_sp .import __MAIN_START__ .import startup @@ -24,6 +24,6 @@ .else .error Unknown CPU type. .endif - .byte sp ; sp address + .byte c_sp ; c_sp address .addr __MAIN_START__ ; load address .addr startup ; reset address diff --git a/libsrc/supervision/crt0.s b/libsrc/supervision/crt0.s index fbae1fc46..1cfba1845 100644 --- a/libsrc/supervision/crt0.s +++ b/libsrc/supervision/crt0.s @@ -33,8 +33,8 @@ reset: lda #<(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) ldx #>(__RAM_START__ + __RAM_SIZE__ + __STACKSIZE__) - sta sp - stx sp+1 ; Set argument stack ptr + sta c_sp + stx c_sp+1 ; Set argument stack ptr jsr initlib jsr _main _exit: jsr donelib diff --git a/libsrc/sym1/crt0.s b/libsrc/sym1/crt0.s index 5d4e0449b..d20b4cf6c 100644 --- a/libsrc/sym1/crt0.s +++ b/libsrc/sym1/crt0.s @@ -33,9 +33,9 @@ _init: jsr ACCESS ; Unlock System RAM ; Set cc65 argument stack pointer lda #<(__RAM_START__ + __RAM_SIZE__) - sta sp + sta c_sp lda #>(__RAM_START__ + __RAM_SIZE__) - sta sp+1 + sta c_sp+1 ; Initialize memory storage diff --git a/libsrc/telestrat/crt0.s b/libsrc/telestrat/crt0.s index df75520ce..aa32ed0d0 100644 --- a/libsrc/telestrat/crt0.s +++ b/libsrc/telestrat/crt0.s @@ -47,7 +47,7 @@ _exit: jsr donelib ldx #zpspace - 1 L2: lda zpsave,x - sta sp,x + sta c_sp,x dex bpl L2 @@ -64,7 +64,7 @@ L2: lda zpsave,x ; Save the zero-page area that we're about to use. init: ldx #zpspace - 1 -L1: lda sp,x +L1: lda c_sp,x sta zpsave,x dex bpl L1 @@ -74,8 +74,8 @@ L1: lda sp,x lda #<(__MAIN_START__ + __MAIN_SIZE__) ldx #>(__MAIN_START__ + __MAIN_SIZE__) - sta sp - stx sp+1 ; Set argument stack ptr + sta c_sp + stx c_sp+1 ; Set argument stack ptr ; Call the module constructors. diff --git a/libsrc/telestrat/open.s b/libsrc/telestrat/open.s index f59d3d31a..08c572e23 100644 --- a/libsrc/telestrat/open.s +++ b/libsrc/telestrat/open.s @@ -2,7 +2,7 @@ .import addysp,popax - .importzp sp,tmp2,tmp3,tmp1 + .importzp c_sp,tmp2,tmp3,tmp1 .include "telestrat.inc" diff --git a/libsrc/telestrat/wherex.s b/libsrc/telestrat/wherex.s index 8616003c8..256b967c3 100644 --- a/libsrc/telestrat/wherex.s +++ b/libsrc/telestrat/wherex.s @@ -3,7 +3,7 @@ ; .export _wherex - .importzp sp + .importzp c_sp .include "telestrat.inc" diff --git a/libsrc/tgi/tgi_outtextxy.s b/libsrc/tgi/tgi_outtextxy.s index 3934df871..24183396f 100644 --- a/libsrc/tgi/tgi_outtextxy.s +++ b/libsrc/tgi/tgi_outtextxy.s @@ -8,7 +8,7 @@ .include "tgi-kernel.inc" .import addysp1 - .importzp sp + .importzp c_sp .proc _tgi_outtextxy @@ -17,16 +17,16 @@ pha ; ldy #0 - lda (sp),y + lda (c_sp),y sta _tgi_cury iny - lda (sp),y + lda (c_sp),y sta _tgi_cury+1 iny - lda (sp),y + lda (c_sp),y sta _tgi_curx iny - lda (sp),y + lda (c_sp),y sta _tgi_curx+1 pla jsr addysp1 ; Drop arguments from stack diff --git a/libsrc/vic20/crt0.s b/libsrc/vic20/crt0.s index c5486063b..189114f5d 100644 --- a/libsrc/vic20/crt0.s +++ b/libsrc/vic20/crt0.s @@ -24,7 +24,7 @@ Start: ; Save the zero-page locations that we need. ldx #zpspace-1 -L1: lda sp,x +L1: lda c_sp,x sta zpsave,x dex bpl L1 @@ -45,8 +45,8 @@ L1: lda sp,x lda #<(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__) ldx #>(__MAIN_START__ + __MAIN_SIZE__ + __STACKSIZE__) - sta sp - stx sp+1 ; Set argument stack ptr + sta c_sp + stx c_sp+1 ; Set argument stack ptr ; Call the module constructors. @@ -65,7 +65,7 @@ _exit: pha ; Save the return code on stack ldx #zpspace-1 L2: lda zpsave,x - sta sp,x + sta c_sp,x dex bpl L2 diff --git a/libsrc/zlib/inflatemem.s b/libsrc/zlib/inflatemem.s index 80c19f223..2f2a1b295 100644 --- a/libsrc/zlib/inflatemem.s +++ b/libsrc/zlib/inflatemem.s @@ -12,7 +12,7 @@ .export _inflatemem .import incsp2 - .importzp sp, sreg, ptr1, ptr2, ptr3, ptr4 + .importzp c_sp, sreg, ptr1, ptr2, ptr3, ptr4 ; -------------------------------------------------------------------------- ; @@ -79,10 +79,10 @@ _inflatemem: stx inputPointer+1 ; outputPointer = dest ldy #1 - lda (sp),y + lda (c_sp),y sta outputPointer+1 dey - lda (sp),y + lda (c_sp),y sta outputPointer ; ldy #0 @@ -129,11 +129,11 @@ inflate_nextBlock: lda outputPointer ; ldy #0 ; sec - sbc (sp),y + sbc (c_sp),y iny pha lda outputPointer+1 - sbc (sp),y + sbc (c_sp),y tax pla ; pop dest diff --git a/samples/getsp.s b/samples/getsp.s index 9f169dc0b..95db689f4 100644 --- a/samples/getsp.s +++ b/samples/getsp.s @@ -1,11 +1,11 @@ .export _getsp - .importzp sp + .importzp c_sp .proc _getsp - ldx sp+1 - lda sp + ldx c_sp+1 + lda c_sp rts .endproc diff --git a/samples/tinyshell.c b/samples/tinyshell.c index 71e9b56e3..a8d5340d9 100644 --- a/samples/tinyshell.c +++ b/samples/tinyshell.c @@ -112,17 +112,17 @@ static void get_command(void) #ifdef CHECK_SP static char firstcall = 1; static unsigned int good_sp; - unsigned int sp; + unsigned int c_sp; if (firstcall) - sp = good_sp = getsp(); + c_sp = good_sp = getsp(); else - sp = getsp(); + c_sp = getsp(); - if (sp != good_sp) { - printf("SP: 0x%04X ***MISMATCH*** 0x%04X\n", sp, good_sp); + if (c_sp != good_sp) { + printf("SP: 0x%04X ***MISMATCH*** 0x%04X\n", c_sp, good_sp); } else if (verbose) - printf("SP: 0x%04X\n", sp); + printf("SP: 0x%04X\n", c_sp); #endif arg1 = arg2 = arg3 = NULL; diff --git a/src/cc65/codegen.c b/src/cc65/codegen.c index 17618e5ff..42be0099a 100644 --- a/src/cc65/codegen.c +++ b/src/cc65/codegen.c @@ -220,7 +220,10 @@ void g_preamble (void) AddTextLine ("\t.debuginfo\t%s", (DebugInfo != 0)? "on" : "off"); /* Import zero page variables */ - AddTextLine ("\t.importzp\tsp, sreg, regsave, regbank"); + AddTextLine ("\t.importzp\t" "c_sp, sreg, regsave, regbank"); + /* The space above is intentional, to ease replacement of the name of + ** the stack pointer. Don't worry, the preprocessor will concatenate them. + */ AddTextLine ("\t.importzp\ttmp1, tmp2, tmp3, tmp4, ptr1, ptr2, ptr3, ptr4"); /* Define long branch macros */ @@ -571,11 +574,11 @@ void g_swap_regvars (int StackOffs, int RegOffs, unsigned Bytes) AddCodeLine ("ldx #$%02X", RegOffs & 0xFF); AddCodeLine ("jsr regswap1"); } else { - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("ldx regbank%+d", RegOffs); AddCodeLine ("sta regbank%+d", RegOffs); AddCodeLine ("txa"); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("sta (c_sp),y"); } } else if (Bytes == 2) { @@ -617,7 +620,7 @@ void g_save_regvars (int RegOffs, unsigned Bytes) AddCodeLine ("ldx #$%02X", (unsigned char) Bytes); g_defcodelabel (Label); AddCodeLine ("lda regbank%+d,x", RegOffs-1); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("sta (c_sp),y"); AddCodeLine ("dey"); AddCodeLine ("dex"); AddCodeLine ("bne %s", LocalLabelName (Label)); @@ -641,28 +644,28 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes) if (Bytes == 1) { AddCodeLine ("ldy #$%02X", StackOffs); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sta regbank%+d", RegOffs); } else if (Bytes == 2) { AddCodeLine ("ldy #$%02X", StackOffs); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sta regbank%+d", RegOffs); AddCodeLine ("iny"); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sta regbank%+d", RegOffs+1); } else if (Bytes == 3 && IS_Get (&CodeSizeFactor) >= 133) { AddCodeLine ("ldy #$%02X", StackOffs); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sta regbank%+d", RegOffs); AddCodeLine ("iny"); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sta regbank%+d", RegOffs+1); AddCodeLine ("iny"); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sta regbank%+d", RegOffs+2); } else if (StackOffs <= RegOffs) { @@ -674,7 +677,7 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes) unsigned Label = GetLocalLabel (); AddCodeLine ("ldy #$%02X", StackOffs); g_defcodelabel (Label); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sta regbank%+d,y", RegOffs - StackOffs); AddCodeLine ("iny"); AddCodeLine ("cpy #$%02X", StackOffs + Bytes); @@ -690,7 +693,7 @@ void g_restore_regvars (int StackOffs, int RegOffs, unsigned Bytes) AddCodeLine ("ldy #$%02X", (unsigned char) (StackOffs + Bytes - 1)); AddCodeLine ("ldx #$%02X", (unsigned char) (Bytes - 1)); g_defcodelabel (Label); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sta regbank%+d,x", RegOffs); AddCodeLine ("dey"); AddCodeLine ("dex"); @@ -836,11 +839,11 @@ void g_getlocal (unsigned Flags, int Offs) CheckLocalOffs (Offs); if ((Flags & CF_FORCECHAR) || (Flags & CF_TEST)) { AddCodeLine ("ldy #$%02X", Offs); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); } else { AddCodeLine ("ldy #$%02X", Offs); AddCodeLine ("ldx #$00"); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); if ((Flags & CF_UNSIGNED) == 0) { unsigned L = GetLocalLabel(); AddCodeLine ("bpl %s", LocalLabelName (L)); @@ -854,9 +857,9 @@ void g_getlocal (unsigned Flags, int Offs) CheckLocalOffs (Offs + 1); AddCodeLine ("ldy #$%02X", (unsigned char) (Offs+1)); if (Flags & CF_TEST) { - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("dey"); - AddCodeLine ("ora (sp),y"); + AddCodeLine ("ora (c_sp),y"); } else { AddCodeLine ("jsr ldaxysp"); } @@ -937,7 +940,7 @@ void g_leasp (int Offs) { unsigned char Lo, Hi; - /* Calculate the offset relative to sp */ + /* Calculate the offset relative to c_sp */ Offs -= StackPtr; /* Get low and high byte */ @@ -947,17 +950,17 @@ void g_leasp (int Offs) /* Generate code */ if (Lo == 0) { if (Hi <= 3) { - AddCodeLine ("lda sp"); - AddCodeLine ("ldx sp+1"); + AddCodeLine ("lda c_sp"); + AddCodeLine ("ldx c_sp+1"); while (Hi--) { AddCodeLine ("inx"); } } else { - AddCodeLine ("lda sp+1"); + AddCodeLine ("lda c_sp+1"); AddCodeLine ("clc"); AddCodeLine ("adc #$%02X", Hi); AddCodeLine ("tax"); - AddCodeLine ("lda sp"); + AddCodeLine ("lda c_sp"); } } else if (Hi == 0) { /* 8 bit offset */ @@ -968,8 +971,8 @@ void g_leasp (int Offs) } else { /* 8 bit offset inlined */ unsigned L = GetLocalLabel (); - AddCodeLine ("lda sp"); - AddCodeLine ("ldx sp+1"); + AddCodeLine ("lda c_sp"); + AddCodeLine ("ldx c_sp+1"); AddCodeLine ("clc"); AddCodeLine ("adc #$%02X", Lo); AddCodeLine ("bcc %s", LocalLabelName (L)); @@ -983,11 +986,11 @@ void g_leasp (int Offs) AddCodeLine ("jsr leaaxsp"); } else { /* Full 16 bit offset inlined */ - AddCodeLine ("lda sp"); + AddCodeLine ("lda c_sp"); AddCodeLine ("clc"); AddCodeLine ("adc #$%02X", Lo); AddCodeLine ("pha"); - AddCodeLine ("lda sp+1"); + AddCodeLine ("lda c_sp+1"); AddCodeLine ("adc #$%02X", Hi); AddCodeLine ("tax"); AddCodeLine ("pla"); @@ -1003,10 +1006,10 @@ void g_leavariadic (int Offs) { unsigned ArgSizeOffs; - /* Calculate the offset relative to sp */ + /* Calculate the offset relative to c_sp */ Offs -= StackPtr; - /* Get the offset of the parameter which is stored at sp+0 on function + /* Get the offset of the parameter which is stored at c_sp+0 on function ** entry and check if this offset is reachable with a byte offset. */ CHECK (StackPtr <= 0); @@ -1015,14 +1018,14 @@ void g_leavariadic (int Offs) /* Get the size of all parameters. */ AddCodeLine ("ldy #$%02X", ArgSizeOffs); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); /* Add the value of the stackpointer */ if (IS_Get (&CodeSizeFactor) > 250) { unsigned L = GetLocalLabel(); - AddCodeLine ("ldx sp+1"); + AddCodeLine ("ldx c_sp+1"); AddCodeLine ("clc"); - AddCodeLine ("adc sp"); + AddCodeLine ("adc c_sp"); AddCodeLine ("bcc %s", LocalLabelName (L)); AddCodeLine ("inx"); g_defcodelabel (L); @@ -1094,14 +1097,14 @@ void g_putlocal (unsigned Flags, int Offs, long Val) AddCodeLine ("lda #$%02X", (unsigned char) Val); } AddCodeLine ("ldy #$%02X", Offs); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("sta (c_sp),y"); break; case CF_INT: if (Flags & CF_CONST) { AddCodeLine ("ldy #$%02X", Offs+1); AddCodeLine ("lda #$%02X", (unsigned char) (Val >> 8)); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("sta (c_sp),y"); if ((Flags & CF_NOKEEP) == 0) { /* Place high byte into X */ AddCodeLine ("tax"); @@ -1114,16 +1117,16 @@ void g_putlocal (unsigned Flags, int Offs, long Val) AddCodeLine ("dey"); AddCodeLine ("lda #$%02X", (unsigned char) Val); } - AddCodeLine ("sta (sp),y"); + AddCodeLine ("sta (c_sp),y"); } else { AddCodeLine ("ldy #$%02X", Offs); if ((Flags & CF_NOKEEP) == 0 || IS_Get (&CodeSizeFactor) < 160) { AddCodeLine ("jsr staxysp"); } else { - AddCodeLine ("sta (sp),y"); + AddCodeLine ("sta (c_sp),y"); AddCodeLine ("iny"); AddCodeLine ("txa"); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("sta (c_sp),y"); } } break; @@ -1163,12 +1166,12 @@ void g_putind (unsigned Flags, unsigned Offs) AddCodeLine ("pha"); } AddCodeLine ("lda #$%02X", Offs & 0xFF); - AddCodeLine ("adc (sp),y"); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("adc (c_sp),y"); + AddCodeLine ("sta (c_sp),y"); AddCodeLine ("iny"); AddCodeLine ("lda #$%02X", (Offs >> 8) & 0xFF); - AddCodeLine ("adc (sp),y"); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("adc (c_sp),y"); + AddCodeLine ("sta (c_sp),y"); if ((Flags & CF_NOKEEP) == 0) { AddCodeLine ("pla"); } @@ -1185,8 +1188,8 @@ void g_putind (unsigned Flags, unsigned Offs) AddCodeLine ("pha"); } AddCodeLine ("lda #$%02X", (Offs >> 8) & 0xFF); - AddCodeLine ("adc (sp),y"); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("adc (c_sp),y"); + AddCodeLine ("sta (c_sp),y"); if ((Flags & CF_NOKEEP) == 0) { AddCodeLine ("pla"); } @@ -1620,7 +1623,7 @@ void g_addlocal (unsigned flags, int offs) L = GetLocalLabel(); AddCodeLine ("ldy #$%02X", NewOff & 0xFF); AddCodeLine ("clc"); - AddCodeLine ("adc (sp),y"); + AddCodeLine ("adc (c_sp),y"); AddCodeLine ("bcc %s", LocalLabelName (L)); AddCodeLine ("inx"); g_defcodelabel (L); @@ -1629,11 +1632,11 @@ void g_addlocal (unsigned flags, int offs) case CF_INT: AddCodeLine ("ldy #$%02X", NewOff & 0xFF); AddCodeLine ("clc"); - AddCodeLine ("adc (sp),y"); + AddCodeLine ("adc (c_sp),y"); AddCodeLine ("pha"); AddCodeLine ("txa"); AddCodeLine ("iny"); - AddCodeLine ("adc (sp),y"); + AddCodeLine ("adc (c_sp),y"); AddCodeLine ("tax"); AddCodeLine ("pla"); break; @@ -1841,12 +1844,12 @@ void g_addeqlocal (unsigned flags, int Offs, unsigned long val) if (flags & CF_CONST) { AddCodeLine ("clc"); AddCodeLine ("lda #$%02X", (int)(val & 0xFF)); - AddCodeLine ("adc (sp),y"); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("adc (c_sp),y"); + AddCodeLine ("sta (c_sp),y"); } else { AddCodeLine ("clc"); - AddCodeLine ("adc (sp),y"); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("adc (c_sp),y"); + AddCodeLine ("sta (c_sp),y"); } if ((flags & CF_UNSIGNED) == 0) { unsigned L = GetLocalLabel(); @@ -1864,16 +1867,16 @@ void g_addeqlocal (unsigned flags, int Offs, unsigned long val) if (IS_Get (&CodeSizeFactor) >= 400) { AddCodeLine ("clc"); AddCodeLine ("lda #$%02X", (int)(val & 0xFF)); - AddCodeLine ("adc (sp),y"); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("adc (c_sp),y"); + AddCodeLine ("sta (c_sp),y"); AddCodeLine ("iny"); AddCodeLine ("lda #$%02X", (int) ((val >> 8) & 0xFF)); - AddCodeLine ("adc (sp),y"); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("adc (c_sp),y"); + AddCodeLine ("sta (c_sp),y"); if ((flags & CF_NOKEEP) == 0) { AddCodeLine ("tax"); AddCodeLine ("dey"); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); } } else { g_getimmed (flags, val, 0); @@ -1925,7 +1928,7 @@ void g_addeqind (unsigned flags, unsigned offs, unsigned long val) case CF_INT: case CF_LONG: AddCodeLine ("jsr pushax"); /* Push the address */ - push (CF_PTR); /* Correct the internal sp */ + push (CF_PTR); /* Correct the internal c_sp */ g_getind (flags, offs); /* Fetch the value */ g_inc (flags, val); /* Increment value in primary */ g_putind (flags, offs); /* Store the value back */ @@ -2091,15 +2094,15 @@ void g_subeqlocal (unsigned flags, int Offs, unsigned long val) AddCodeLine ("ldy #$%02X", Offs); AddCodeLine ("ldx #$00"); if (flags & CF_CONST) { - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sec"); AddCodeLine ("sbc #$%02X", (unsigned char)val); } else { AddCodeLine ("eor #$FF"); AddCodeLine ("sec"); - AddCodeLine ("adc (sp),y"); + AddCodeLine ("adc (c_sp),y"); } - AddCodeLine ("sta (sp),y"); + AddCodeLine ("sta (c_sp),y"); if ((flags & CF_UNSIGNED) == 0) { unsigned L = GetLocalLabel(); AddCodeLine ("bpl %s", LocalLabelName (L)); @@ -2159,7 +2162,7 @@ void g_subeqind (unsigned flags, unsigned offs, unsigned long val) case CF_INT: case CF_LONG: AddCodeLine ("jsr pushax"); /* Push the address */ - push (CF_PTR); /* Correct the internal sp */ + push (CF_PTR); /* Correct the internal c_sp */ g_getind (flags, offs); /* Fetch the value */ g_dec (flags, val); /* Increment value in primary */ g_putind (flags, offs); /* Store the value back */ @@ -2210,10 +2213,10 @@ void g_addaddr_local (unsigned flags attribute ((unused)), int offs) /* Label was used above */ g_defcodelabel (L); } - AddCodeLine ("adc sp"); + AddCodeLine ("adc c_sp"); AddCodeLine ("tay"); AddCodeLine ("txa"); - AddCodeLine ("adc sp+1"); + AddCodeLine ("adc c_sp+1"); AddCodeLine ("tax"); AddCodeLine ("tya"); } @@ -2514,10 +2517,10 @@ void g_callind (unsigned Flags, unsigned ArgSize, int Offs) CheckLocalOffs (Offs); AddCodeLine ("pha"); AddCodeLine ("ldy #$%02X", Offs); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sta jmpvec+1"); AddCodeLine ("iny"); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sta jmpvec+2"); AddCodeLine ("pla"); AddCodeLine ("jsr jmpvec"); @@ -2575,11 +2578,11 @@ void g_lateadjustSP (unsigned label) AddCodeLine ("pha"); AddCodeLine ("lda %s", LocalDataLabelName (label)); AddCodeLine ("clc"); - AddCodeLine ("adc sp"); - AddCodeLine ("sta sp"); + AddCodeLine ("adc c_sp"); + AddCodeLine ("sta c_sp"); AddCodeLine ("lda %s+1", LocalDataLabelName (label)); - AddCodeLine ("adc sp+1"); - AddCodeLine ("sta sp+1"); + AddCodeLine ("adc c_sp+1"); + AddCodeLine ("sta c_sp+1"); AddCodeLine ("pla"); } @@ -2593,11 +2596,11 @@ void g_drop (unsigned Space) AddCodeLine ("pha"); AddCodeLine ("lda #$%02X", (unsigned char) Space); AddCodeLine ("clc"); - AddCodeLine ("adc sp"); - AddCodeLine ("sta sp"); + AddCodeLine ("adc c_sp"); + AddCodeLine ("sta c_sp"); AddCodeLine ("lda #$%02X", (unsigned char) (Space >> 8)); - AddCodeLine ("adc sp+1"); - AddCodeLine ("sta sp+1"); + AddCodeLine ("adc c_sp+1"); + AddCodeLine ("sta c_sp+1"); AddCodeLine ("pla"); } else if (Space > 8) { AddCodeLine ("ldy #$%02X", Space); @@ -2620,13 +2623,13 @@ void g_space (int Space) ** overhead. */ AddCodeLine ("pha"); - AddCodeLine ("lda sp"); + AddCodeLine ("lda c_sp"); AddCodeLine ("sec"); AddCodeLine ("sbc #$%02X", (unsigned char) Space); - AddCodeLine ("sta sp"); - AddCodeLine ("lda sp+1"); + AddCodeLine ("sta c_sp"); + AddCodeLine ("lda c_sp+1"); AddCodeLine ("sbc #$%02X", (unsigned char) (Space >> 8)); - AddCodeLine ("sta sp+1"); + AddCodeLine ("sta c_sp+1"); AddCodeLine ("pla"); } else if (Space > 8) { AddCodeLine ("ldy #$%02X", Space); @@ -4586,14 +4589,14 @@ void g_initauto (unsigned Label, unsigned Size) AddCodeLine ("ldy #$%02X", Size-1); g_defcodelabel (CodeLabel); AddCodeLine ("lda %s,y", GetLabelName (CF_STATIC, Label, 0)); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("sta (c_sp),y"); AddCodeLine ("dey"); AddCodeLine ("bpl %s", LocalLabelName (CodeLabel)); } else if (Size <= 256) { AddCodeLine ("ldy #$00"); g_defcodelabel (CodeLabel); AddCodeLine ("lda %s,y", GetLabelName (CF_STATIC, Label, 0)); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("sta (c_sp),y"); AddCodeLine ("iny"); AddCmpCodeIfSizeNot256 ("cpy #$%02X", Size); AddCodeLine ("bne %s", LocalLabelName (CodeLabel)); diff --git a/src/cc65/codeinfo.c b/src/cc65/codeinfo.c index 29f18cb78..25712d546 100644 --- a/src/cc65/codeinfo.c +++ b/src/cc65/codeinfo.c @@ -386,6 +386,8 @@ static const FuncInfo FuncInfoTable[] = { /* CAUTION: table must be sorted for bsearch */ static const ZPInfo ZPInfoTable[] = { /* BEGIN SORTED.SH */ + { 0, "c_sp", 2, REG_SP_LO, REG_SP }, + { 0, "c_sp+1", 1, REG_SP_HI, REG_SP }, { 0, "ptr1", 2, REG_PTR1_LO, REG_PTR1 }, { 0, "ptr1+1", 1, REG_PTR1_HI, REG_PTR1 }, { 0, "ptr2", 2, REG_PTR2_LO, REG_PTR2 }, @@ -395,8 +397,6 @@ static const ZPInfo ZPInfoTable[] = { { 7, "regbank", 6, REG_NONE, REG_NONE }, { 0, "regsave", 4, REG_SAVE_LO, REG_SAVE }, { 0, "regsave+1", 3, REG_SAVE_HI, REG_SAVE }, - { 0, "sp", 2, REG_SP_LO, REG_SP }, - { 0, "sp+1", 1, REG_SP_HI, REG_SP }, { 0, "sreg", 2, REG_SREG_LO, REG_SREG }, { 0, "sreg+1", 1, REG_SREG_HI, REG_SREG }, { 0, "tmp1", 1, REG_TMP1, REG_TMP1 }, diff --git a/src/cc65/codeinfo.h b/src/cc65/codeinfo.h index c57908dad..d03962343 100644 --- a/src/cc65/codeinfo.h +++ b/src/cc65/codeinfo.h @@ -75,8 +75,8 @@ struct RegContents; #define REG_SP_HI 0x2000U /* Defines for some special register usage */ -#define SLV_IND 0x00010000U /* Accesses (sp),y */ -#define SLV_TOP 0x00020000U /* Accesses (sp),0 */ +#define SLV_IND 0x00010000U /* Accesses (c_sp),y */ +#define SLV_TOP 0x00020000U /* Accesses (c_sp),0 */ #define SLV_SP65 0x00200000U /* Accesses 6502 stack pointer */ #define SLV_PH65 0x00400000U /* Pushes onto 6502 stack */ #define SLV_PL65 0x00800000U /* Pops from 6502 stack */ @@ -122,7 +122,7 @@ struct RegContents; typedef struct ZPInfo ZPInfo; struct ZPInfo { unsigned char Len; /* Length of the following string */ - char Name[10]; /* Name of zero page symbol */ + char Name[64]; /* Name of zero page symbol */ unsigned char Size; /* Maximum buffer size of this register */ unsigned short ByteUse; /* Register info for this symbol */ unsigned short WordUse; /* Register info for 16 bit access */ diff --git a/src/cc65/codeopt.c b/src/cc65/codeopt.c index 19acfde74..e3869d786 100644 --- a/src/cc65/codeopt.c +++ b/src/cc65/codeopt.c @@ -825,7 +825,7 @@ static unsigned RunOptGroup5 (CodeSeg* S) static unsigned RunOptGroup6 (CodeSeg* S) -/* This one is quite special. It tries to replace "lda (sp),y" by "lda (sp,x)". +/* This one is quite special. It tries to replace "lda (c_sp),y" by "lda (c_sp,x)". ** The latter is ony cycle slower, but if we're able to remove the necessary ** load of the Y register, because X is zero anyway, we gain 1 cycle and ** shorten the code by one (transfer) or two bytes (load). So what we do is diff --git a/src/cc65/codeoptutil.c b/src/cc65/codeoptutil.c index 7547ef5ba..0d3dba95c 100644 --- a/src/cc65/codeoptutil.c +++ b/src/cc65/codeoptutil.c @@ -333,14 +333,14 @@ static int Affected (LoadRegInfo* LRI, const CodeEntry* E) */ if (E->AM == AM65_ABS || E->AM == AM65_ZP || - (E->AM == AM65_ZP_INDY && strcmp (E->ArgBase, "sp") == 0) + (E->AM == AM65_ZP_INDY && strcmp (E->ArgBase, "c_sp") == 0) ) { if ((LRI->Flags & LI_CHECK_ARG) != 0) { if (AE == 0 || (AE->AM != AM65_ABS && AE->AM != AM65_ZP && (AE->AM != AM65_ZP_INDY || - strcmp (AE->ArgBase, "sp") != 0)) || + strcmp (AE->ArgBase, "c_sp") != 0)) || (AE->ArgOff == E->ArgOff && strcmp (AE->ArgBase, E->ArgBase) == 0)) { @@ -445,7 +445,7 @@ void PrepairLoadRegInfoForArgCheck (CodeSeg* S, LoadRegInfo* LRI, CodeEntry* E) /* These insns are replaceable only if they are not modified later */ LRI->Flags |= LI_CHECK_ARG | LI_CHECK_Y; } else if ((E->AM == AM65_ZP_INDY) && - strcmp (E->Arg, "sp") == 0) { + strcmp (E->Arg, "c_sp") == 0) { /* A load from the stack with known offset is also ok, but in this ** case we must reload the index register later. Please note that ** a load indirect via other zero page locations is not ok, since @@ -556,7 +556,7 @@ unsigned int TrackLoads (LoadInfo* LI, CodeSeg* S, int I) /* These insns are replaceable only if they are not modified later */ LRI->Flags |= LI_CHECK_ARG | LI_CHECK_Y; } else if (E->AM == AM65_ZP_INDY && - strcmp (E->Arg, "sp") == 0) { + strcmp (E->Arg, "c_sp") == 0) { /* A load from the stack with known offset is also ok, but in this ** case we must reload the index register later. Please note that ** a load indirect via other zero page locations is not ok, since @@ -839,7 +839,7 @@ void AdjustStackOffset (StackOpData* D, unsigned Offs) if (E->OPC != OP65_JSR) { /* Check against some things that should not happen */ CHECK (E->AM == AM65_ZP_INDY && E->RI->In.RegY >= (short) Offs); - CHECK (strcmp (E->Arg, "sp") == 0); + CHECK (strcmp (E->Arg, "c_sp") == 0); /* We need to correct this one */ Correction = 2; @@ -1056,8 +1056,8 @@ void AddOpLow (StackOpData* D, opc_t OPC, LoadInfo* LI) InsertEntry (D, X, D->IP++); if (LI->A.LoadEntry->OPC == OP65_JSR) { - /* opc (sp),y */ - X = NewCodeEntry (OPC, AM65_ZP_INDY, "sp", 0, D->OpEntry->LI); + /* opc (c_sp),y */ + X = NewCodeEntry (OPC, AM65_ZP_INDY, "c_sp", 0, D->OpEntry->LI); } else { /* opc src,y */ X = NewCodeEntry (OPC, LI->A.LoadEntry->AM, LI->A.LoadEntry->Arg, 0, D->OpEntry->LI); @@ -1119,8 +1119,8 @@ void AddOpHigh (StackOpData* D, opc_t OPC, LoadInfo* LI, int KeepResult) InsertEntry (D, X, D->IP++); if (LI->X.LoadEntry->OPC == OP65_JSR) { - /* opc (sp),y */ - X = NewCodeEntry (OPC, AM65_ZP_INDY, "sp", 0, D->OpEntry->LI); + /* opc (c_sp),y */ + X = NewCodeEntry (OPC, AM65_ZP_INDY, "c_sp", 0, D->OpEntry->LI); } else { /* opc src,y */ X = NewCodeEntry (OPC, LI->X.LoadEntry->AM, LI->X.LoadEntry->Arg, 0, D->OpEntry->LI); @@ -1312,10 +1312,10 @@ const char* GetZPName (unsigned ZPLoc) return "save+1"; } if ((ZPLoc & REG_SP_LO) != 0) { - return "sp"; + return "c_sp"; } if ((ZPLoc & REG_SP_HI) != 0) { - return "sp+1"; + return "c_sp+1"; } return 0; diff --git a/src/cc65/coptadd.c b/src/cc65/coptadd.c index bc67f7a74..3636e0e20 100644 --- a/src/cc65/coptadd.c +++ b/src/cc65/coptadd.c @@ -62,15 +62,15 @@ unsigned OptAdd1 (CodeSeg* S) ** and replace it by: ** ** ldy #xx-1 -** lda (sp),y +** lda (c_sp),y ** ldy #yy-3 ** clc -** adc (sp),y +** adc (c_sp),y ** pha ** ldy #xx -** lda (sp),y +** lda (c_sp),y ** ldy #yy-2 -** adc (sp),y +** adc (c_sp),y ** tax ** pla */ @@ -104,8 +104,8 @@ unsigned OptAdd1 (CodeSeg* S) /* Correct the stack of the first Y register load */ CE_SetNumArg (L[0], L[0]->Num - 1); - /* lda (sp),y */ - X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "sp", 0, L[1]->LI); + /* lda (c_sp),y */ + X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "c_sp", 0, L[1]->LI); CS_InsertEntry (S, X, I+1); /* ldy #yy-3 */ @@ -117,8 +117,8 @@ unsigned OptAdd1 (CodeSeg* S) X = NewCodeEntry (OP65_CLC, AM65_IMP, 0, 0, L[5]->LI); CS_InsertEntry (S, X, I+3); - /* adc (sp),y */ - X = NewCodeEntry (OP65_ADC, AM65_ZP_INDY, "sp", 0, L[5]->LI); + /* adc (c_sp),y */ + X = NewCodeEntry (OP65_ADC, AM65_ZP_INDY, "c_sp", 0, L[5]->LI); CS_InsertEntry (S, X, I+4); /* pha */ @@ -130,8 +130,8 @@ unsigned OptAdd1 (CodeSeg* S) X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, L[1]->LI); CS_InsertEntry (S, X, I+6); - /* lda (sp),y */ - X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "sp", 0, L[1]->LI); + /* lda (c_sp),y */ + X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "c_sp", 0, L[1]->LI); CS_InsertEntry (S, X, I+7); /* ldy #yy-2 */ @@ -139,8 +139,8 @@ unsigned OptAdd1 (CodeSeg* S) X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, L[4]->LI); CS_InsertEntry (S, X, I+8); - /* adc (sp),y */ - X = NewCodeEntry (OP65_ADC, AM65_ZP_INDY, "sp", 0, L[5]->LI); + /* adc (c_sp),y */ + X = NewCodeEntry (OP65_ADC, AM65_ZP_INDY, "c_sp", 0, L[5]->LI); CS_InsertEntry (S, X, I+9); /* tax */ @@ -181,16 +181,16 @@ unsigned OptAdd2 (CodeSeg* S) ** and replace it by: ** ** ldy #xx-1 -** lda (sp),y +** lda (c_sp),y ** ldy #yy ** clc -** adc (sp),y -** sta (sp),y +** adc (c_sp),y +** sta (c_sp),y ** ldy #xx -** lda (sp),y +** lda (c_sp),y ** ldy #yy+1 -** adc (sp),y -** sta (sp),y +** adc (c_sp),y +** sta (c_sp),y ** ** provided that a/x is not used later. */ @@ -226,8 +226,8 @@ unsigned OptAdd2 (CodeSeg* S) X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, L[0]->LI); CS_InsertEntry (S, X, I+4); - /* lda (sp),y */ - X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "sp", 0, L[1]->LI); + /* lda (c_sp),y */ + X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "c_sp", 0, L[1]->LI); CS_InsertEntry (S, X, I+5); /* ldy #yy */ @@ -238,20 +238,20 @@ unsigned OptAdd2 (CodeSeg* S) X = NewCodeEntry (OP65_CLC, AM65_IMP, 0, 0, L[3]->LI); CS_InsertEntry (S, X, I+7); - /* adc (sp),y */ - X = NewCodeEntry (OP65_ADC, AM65_ZP_INDY, "sp", 0, L[3]->LI); + /* adc (c_sp),y */ + X = NewCodeEntry (OP65_ADC, AM65_ZP_INDY, "c_sp", 0, L[3]->LI); CS_InsertEntry (S, X, I+8); - /* sta (sp),y */ - X = NewCodeEntry (OP65_STA, AM65_ZP_INDY, "sp", 0, L[3]->LI); + /* sta (c_sp),y */ + X = NewCodeEntry (OP65_STA, AM65_ZP_INDY, "c_sp", 0, L[3]->LI); CS_InsertEntry (S, X, I+9); /* ldy #xx */ X = NewCodeEntry (OP65_LDY, AM65_IMM, L[0]->Arg, 0, L[0]->LI); CS_InsertEntry (S, X, I+10); - /* lda (sp),y */ - X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "sp", 0, L[1]->LI); + /* lda (c_sp),y */ + X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "c_sp", 0, L[1]->LI); CS_InsertEntry (S, X, I+11); /* ldy #yy+1 */ @@ -259,12 +259,12 @@ unsigned OptAdd2 (CodeSeg* S) X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, L[2]->LI); CS_InsertEntry (S, X, I+12); - /* adc (sp),y */ - X = NewCodeEntry (OP65_ADC, AM65_ZP_INDY, "sp", 0, L[3]->LI); + /* adc (c_sp),y */ + X = NewCodeEntry (OP65_ADC, AM65_ZP_INDY, "c_sp", 0, L[3]->LI); CS_InsertEntry (S, X, I+13); - /* sta (sp),y */ - X = NewCodeEntry (OP65_STA, AM65_ZP_INDY, "sp", 0, L[3]->LI); + /* sta (c_sp),y */ + X = NewCodeEntry (OP65_STA, AM65_ZP_INDY, "c_sp", 0, L[3]->LI); CS_InsertEntry (S, X, I+14); /* Delete the old code */ diff --git a/src/cc65/coptadd.h b/src/cc65/coptadd.h index e4df3b304..d29783305 100644 --- a/src/cc65/coptadd.h +++ b/src/cc65/coptadd.h @@ -55,14 +55,14 @@ unsigned OptAdd1 (CodeSeg* S); ** jsr pushax ** ldy xxx ** ldx #$00 -** lda (sp),y +** lda (c_sp),y ** jsr tosaddax ** ** and replace it by: ** ** ldy xxx-2 ** clc -** adc (sp),y +** adc (c_sp),y ** bcc L ** inx ** L: @@ -72,26 +72,26 @@ unsigned OptAdd2 (CodeSeg* S); /* Search for the sequence ** ** ldy #xx -** lda (sp),y +** lda (c_sp),y ** tax ** dey -** lda (sp),y +** lda (c_sp),y ** ldy #$yy ** jsr addeqysp ** ** and replace it by: ** ** ldy #xx-1 -** lda (sp),y +** lda (c_sp),y ** ldy #yy ** clc -** adc (sp),y -** sta (sp),y +** adc (c_sp),y +** sta (c_sp),y ** ldy #xx -** lda (sp),y +** lda (c_sp),y ** ldy #yy+1 -** adc (sp),y -** sta (sp),y +** adc (c_sp),y +** sta (c_sp),y ** ** provided that a/x is not used later. */ diff --git a/src/cc65/coptbool.c b/src/cc65/coptbool.c index 3a3b3fa7c..e0a79238e 100644 --- a/src/cc65/coptbool.c +++ b/src/cc65/coptbool.c @@ -743,9 +743,9 @@ unsigned OptBNegAX2 (CodeSeg* S) ** and replace it by ** ** ldy #xx -** lda (sp),y +** lda (c_sp),y ** dey -** ora (sp),y +** ora (c_sp),y ** jeq/jne ... */ { @@ -772,16 +772,16 @@ unsigned OptBNegAX2 (CodeSeg* S) CodeEntry* X; - /* lda (sp),y */ - X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "sp", 0, L[1]->LI); + /* lda (c_sp),y */ + X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "c_sp", 0, L[1]->LI); CS_InsertEntry (S, X, I+1); /* dey */ X = NewCodeEntry (OP65_DEY, AM65_IMP, 0, 0, L[1]->LI); CS_InsertEntry (S, X, I+2); - /* ora (sp),y */ - X = NewCodeEntry (OP65_ORA, AM65_ZP_INDY, "sp", 0, L[1]->LI); + /* ora (c_sp),y */ + X = NewCodeEntry (OP65_ORA, AM65_ZP_INDY, "c_sp", 0, L[1]->LI); CS_InsertEntry (S, X, I+3); /* Invert the branch */ diff --git a/src/cc65/coptcmp.c b/src/cc65/coptcmp.c index 2970b363b..eb138e78d 100644 --- a/src/cc65/coptcmp.c +++ b/src/cc65/coptcmp.c @@ -431,22 +431,22 @@ unsigned OptCmp5 (CodeSeg* S) /* The value is zero, we may use the simple code version: ** ldy #o-1 - ** lda (sp),y + ** lda (c_sp),y ** ldy #o - ** ora (sp),y + ** ora (c_sp),y ** jne/jeq ... */ sprintf (Buf, "$%02X", (int)(L[0]->Num-1)); X = NewCodeEntry (OP65_LDY, AM65_IMM, Buf, 0, L[0]->LI); CS_InsertEntry (S, X, I+1); - X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "sp", 0, L[1]->LI); + X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "c_sp", 0, L[1]->LI); CS_InsertEntry (S, X, I+2); X = NewCodeEntry (OP65_LDY, AM65_IMM, L[0]->Arg, 0, L[0]->LI); CS_InsertEntry (S, X, I+3); - X = NewCodeEntry (OP65_ORA, AM65_ZP_INDY, "sp", 0, L[1]->LI); + X = NewCodeEntry (OP65_ORA, AM65_ZP_INDY, "c_sp", 0, L[1]->LI); CS_InsertEntry (S, X, I+4); CS_DelEntries (S, I+5, 3); /* cpx/bne/cmp */ @@ -461,18 +461,18 @@ unsigned OptCmp5 (CodeSeg* S) ** of the low byte after the first branch if possible: ** ** ldy #o - ** lda (sp),y + ** lda (c_sp),y ** cmp #a ** bne L1 ** ldy #o-1 - ** lda (sp),y + ** lda (c_sp),y ** cmp #b ** jne/jeq ... */ X = NewCodeEntry (OP65_LDY, AM65_IMM, L[0]->Arg, 0, L[0]->LI); CS_InsertEntry (S, X, I+3); - X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "sp", 0, L[1]->LI); + X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "c_sp", 0, L[1]->LI); CS_InsertEntry (S, X, I+4); X = NewCodeEntry (OP65_CMP, L[2]->AM, L[2]->Arg, 0, L[2]->LI); @@ -482,7 +482,7 @@ unsigned OptCmp5 (CodeSeg* S) X = NewCodeEntry (OP65_LDY, AM65_IMM, Buf, 0, L[0]->LI); CS_InsertEntry (S, X, I+7); - X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "sp", 0, L[1]->LI); + X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "c_sp", 0, L[1]->LI); CS_InsertEntry (S, X, I+8); CS_DelEntries (S, I, 3); /* ldy/jsr/cpx */ diff --git a/src/cc65/coptcmp.h b/src/cc65/coptcmp.h index dd188f7fc..98e75715b 100644 --- a/src/cc65/coptcmp.h +++ b/src/cc65/coptcmp.h @@ -113,10 +113,10 @@ unsigned OptCmp5 (CodeSeg* S); /* Optimize compares of local variables: ** ** ldy #o -** lda (sp),y +** lda (c_sp),y ** tax ** dey -** lda (sp),y +** lda (c_sp),y ** cpx #a ** bne L1 ** cmp #b diff --git a/src/cc65/coptmisc.c b/src/cc65/coptmisc.c index b23ee6e0a..a2cda7495 100644 --- a/src/cc65/coptmisc.c +++ b/src/cc65/coptmisc.c @@ -492,9 +492,9 @@ unsigned OptGotoSPAdj (CodeSeg* S) L[1]->AM == AM65_ABS && L[2]->OPC == OP65_CLC && L[3]->OPC == OP65_ADC && - strcmp (L[3]->Arg, "sp") == 0 && + strcmp (L[3]->Arg, "c_sp") == 0 && L[6]->OPC == OP65_ADC && - strcmp (L[6]->Arg, "sp+1") == 0 && + strcmp (L[6]->Arg, "c_sp+1") == 0 && L[9]->OPC == OP65_JMP) { adjustment = FindSPAdjustment (L[1]->Arg); @@ -663,7 +663,7 @@ unsigned OptLoad1 (CodeSeg* S) CS_InsertEntry (S, X, I+1); /* Load from stack */ - X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "sp", 0, E->LI); + X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "c_sp", 0, E->LI); CS_InsertEntry (S, X, I+2); /* Now remove the call to the subroutine */ @@ -719,8 +719,8 @@ unsigned OptLoad2 (CodeSeg* S) ** later */ - /* lda (sp),y */ - X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "sp", 0, L[0]->LI); + /* lda (c_sp),y */ + X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "c_sp", 0, L[0]->LI); CS_InsertEntry (S, X, I+3); /* sta abs */ @@ -731,8 +731,8 @@ unsigned OptLoad2 (CodeSeg* S) X = NewCodeEntry (OP65_DEY, AM65_IMP, 0, 0, L[0]->LI); CS_InsertEntry (S, X, I+5); - /* lda (sp),y */ - X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "sp", 0, L[0]->LI); + /* lda (c_sp),y */ + X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "c_sp", 0, L[0]->LI); CS_InsertEntry (S, X, I+6); /* sta abs */ @@ -746,8 +746,8 @@ unsigned OptLoad2 (CodeSeg* S) /* Standard replacement */ - /* lda (sp),y */ - X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "sp", 0, L[0]->LI); + /* lda (c_sp),y */ + X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "c_sp", 0, L[0]->LI); CS_InsertEntry (S, X, I+1); /* tax */ @@ -758,8 +758,8 @@ unsigned OptLoad2 (CodeSeg* S) X = NewCodeEntry (OP65_DEY, AM65_IMP, 0, 0, L[0]->LI); CS_InsertEntry (S, X, I+3); - /* lda (sp),y */ - X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "sp", 0, L[0]->LI); + /* lda (c_sp),y */ + X = NewCodeEntry (OP65_LDA, AM65_ZP_INDY, "c_sp", 0, L[0]->LI); CS_InsertEntry (S, X, I+4); /* Now remove the call to the subroutine */ diff --git a/src/cc65/coptptrload.c b/src/cc65/coptptrload.c index 046e65d79..e28bf5d39 100644 --- a/src/cc65/coptptrload.c +++ b/src/cc65/coptptrload.c @@ -359,7 +359,7 @@ unsigned OptPtrLoad4 (CodeSeg* S) ** ldx #>(label+0) ** ldy #$xx ** clc -** adc (sp),y +** adc (c_sp),y ** bcc L ** inx ** L: ldy #$00 @@ -368,7 +368,7 @@ unsigned OptPtrLoad4 (CodeSeg* S) ** and replace it by: ** ** ldy #$xx -** lda (sp),y +** lda (c_sp),y ** tay ** ldx #$00 ** lda label,y @@ -553,7 +553,7 @@ unsigned OptPtrLoad6 (CodeSeg* S) ** jsr pushax ** ldy #xxx ** ldx #$00 -** lda (sp),y +** lda (c_sp),y ** jsr tosaddax ** ldy #$00 ** jsr ldauidx @@ -563,7 +563,7 @@ unsigned OptPtrLoad6 (CodeSeg* S) ** sta ptr1 ** stx ptr1+1 ** ldy #xxx-2 -** lda (sp),y +** lda (c_sp),y ** tay ** ldx #$00 ** lda (ptr1),y @@ -613,7 +613,7 @@ unsigned OptPtrLoad6 (CodeSeg* S) X = NewCodeEntry (OP65_LDY, AM65_IMM, Arg, 0, L[1]->LI); CS_InsertEntry (S, X, I+9); - /* lda (sp),y */ + /* lda (c_sp),y */ X = NewCodeEntry (OP65_LDA, L[3]->AM, L[3]->Arg, 0, L[3]->LI); CS_InsertEntry (S, X, I+10); diff --git a/src/cc65/coptptrload.h b/src/cc65/coptptrload.h index d4e0e2ed4..259d1587b 100644 --- a/src/cc65/coptptrload.h +++ b/src/cc65/coptptrload.h @@ -127,7 +127,7 @@ unsigned OptPtrLoad4 (CodeSeg* S); ** ldx #>(label+0) ** ldy #$xx ** clc -** adc (sp),y +** adc (c_sp),y ** bcc L ** inx ** L: ldy #$00 @@ -136,7 +136,7 @@ unsigned OptPtrLoad4 (CodeSeg* S); ** and replace it by: ** ** ldy #$xx -** lda (sp),y +** lda (c_sp),y ** tay ** ldx #$00 ** lda label,y @@ -166,7 +166,7 @@ unsigned OptPtrLoad6 (CodeSeg* S); ** jsr pushax ** ldy xxx ** ldx #$00 -** lda (sp),y +** lda (c_sp),y ** jsr tosaddax ** ldy #$00 ** jsr ldauidx @@ -176,7 +176,7 @@ unsigned OptPtrLoad6 (CodeSeg* S); ** sta ptr1 ** stx ptr1+1 ** ldy xxx -** lda (sp),y +** lda (c_sp),y ** tay ** lda (ptr1),y */ diff --git a/src/cc65/coptptrstore.c b/src/cc65/coptptrstore.c index 11832910f..6891d8353 100644 --- a/src/cc65/coptptrstore.c +++ b/src/cc65/coptptrstore.c @@ -396,7 +396,7 @@ unsigned OptPtrStore2 (CodeSeg* S) ** L: jsr pushax ** ldy yyy ** ldx #$00 -** lda (sp),y +** lda (c_sp),y ** ldy #$00 ** jsr staspidx ** @@ -406,7 +406,7 @@ unsigned OptPtrStore2 (CodeSeg* S) ** stx ptr1+1 ** ldy yyy-2 ** ldx #$00 -** lda (sp),y +** lda (c_sp),y ** ldy xxx ** sta (ptr1),y ** @@ -414,7 +414,7 @@ unsigned OptPtrStore2 (CodeSeg* S) ** ** ldy yyy-2 ** ldx #$00 -** lda (sp),y +** lda (c_sp),y ** ldy xxx ** sta (zp),y ** @@ -422,7 +422,7 @@ unsigned OptPtrStore2 (CodeSeg* S) ** ** ldy yyy-2 ** ldx #$00 -** lda (sp),y +** lda (c_sp),y ** ldy xxx ** sta label,y ** @@ -430,7 +430,7 @@ unsigned OptPtrStore2 (CodeSeg* S) ** ** ldy yyy-2 ** ldx #$00 -** lda (sp),y +** lda (c_sp),y ** ldy xxx ** sta $xxxx,y ** @@ -468,7 +468,7 @@ unsigned OptPtrStore2 (CodeSeg* S) L[6]->OPC == OP65_LDX && L[7]->OPC == OP65_LDA && L[7]->AM == AM65_ZP_INDY && - strcmp (L[7]->Arg, "sp") == 0 && + strcmp (L[7]->Arg, "c_sp") == 0 && L[8]->OPC == OP65_LDY && (L[8]->AM == AM65_ABS || L[8]->AM == AM65_ZP || diff --git a/src/cc65/coptptrstore.h b/src/cc65/coptptrstore.h index 3f8fc91f9..fd36eddba 100644 --- a/src/cc65/coptptrstore.h +++ b/src/cc65/coptptrstore.h @@ -105,7 +105,7 @@ unsigned OptPtrStore2 (CodeSeg* S); ** L: jsr pushax ** ldy yyy ** ldx #$00 -** lda (sp),y +** lda (c_sp),y ** ldy #$00 ** jsr staspidx ** @@ -115,7 +115,7 @@ unsigned OptPtrStore2 (CodeSeg* S); ** stx ptr1+1 ** ldy yyy-2 ** ldx #$00 -** lda (sp),y +** lda (c_sp),y ** ldy xxx ** sta (ptr1),y ** @@ -123,7 +123,7 @@ unsigned OptPtrStore2 (CodeSeg* S); ** ** ldy yyy-2 ** ldx #$00 -** lda (sp),y +** lda (c_sp),y ** ldy xxx ** sta (zp),y ** @@ -131,7 +131,7 @@ unsigned OptPtrStore2 (CodeSeg* S); ** ** ldy yyy-2 ** ldx #$00 -** lda (sp),y +** lda (c_sp),y ** ldy xxx ** sta label,y ** @@ -139,7 +139,7 @@ unsigned OptPtrStore2 (CodeSeg* S); ** ** ldy yyy-2 ** ldx #$00 -** lda (sp),y +** lda (c_sp),y ** ldy xxx ** sta $xxxx,y ** diff --git a/src/cc65/coptstop.c b/src/cc65/coptstop.c index e5d686d1a..7a9416b51 100644 --- a/src/cc65/coptstop.c +++ b/src/cc65/coptstop.c @@ -1292,10 +1292,10 @@ static unsigned Opt_a_tosicmp (StackOpData* D) } InsertEntry (D, X, D->IP++); - /* cmp src,y OR cmp (sp),y */ + /* cmp src,y OR cmp (c_sp),y */ if (D->Rhs.A.LoadEntry->OPC == OP65_JSR) { - /* opc (sp),y */ - X = NewCodeEntry (OP65_CMP, AM65_ZP_INDY, "sp", 0, D->OpEntry->LI); + /* opc (c_sp),y */ + X = NewCodeEntry (OP65_CMP, AM65_ZP_INDY, "c_sp", 0, D->OpEntry->LI); } else { /* opc src,y */ X = NewCodeEntry (OP65_CMP, D->Rhs.A.LoadEntry->AM, D->Rhs.A.LoadEntry->Arg, 0, D->OpEntry->LI); diff --git a/src/cc65/coptstore.c b/src/cc65/coptstore.c index b0dfe3b6d..2fc83b5fb 100644 --- a/src/cc65/coptstore.c +++ b/src/cc65/coptstore.c @@ -48,7 +48,7 @@ static void InsertStore (CodeSeg* S, unsigned* IP, LineInfo* LI) { - CodeEntry* X = NewCodeEntry (OP65_STA, AM65_ZP_INDY, "sp", 0, LI); + CodeEntry* X = NewCodeEntry (OP65_STA, AM65_ZP_INDY, "c_sp", 0, LI); CS_InsertEntry (S, X, (*IP)++); } diff --git a/src/cc65/locals.c b/src/cc65/locals.c index 08e41918e..08fe83b75 100644 --- a/src/cc65/locals.c +++ b/src/cc65/locals.c @@ -269,7 +269,7 @@ static void ParseAutoDecl (Declarator* Decl) Sym->V.Offs = F_ReserveLocalSpace (CurrentFunc, Size); /* Next, allocate the space on the stack. This means that the - ** variable is now located at offset 0 from the current sp. + ** variable is now located at offset 0 from the current c_sp. */ F_AllocLocalSpace (CurrentFunc); diff --git a/src/cc65/stdfunc.c b/src/cc65/stdfunc.c index 3f33cdcce..1597380e8 100644 --- a/src/cc65/stdfunc.c +++ b/src/cc65/stdfunc.c @@ -371,7 +371,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr) AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal - 1)); g_defcodelabel (Label); AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, -Offs)); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("sta (c_sp),y"); AddCodeLine ("dey"); AddCodeLine ("bpl %s", LocalLabelName (Label)); } else { @@ -379,7 +379,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr) AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal - 1)); g_defcodelabel (Label); AddCodeLine ("lda %s,x", ED_GetLabelName (&Arg2.Expr, 0)); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("sta (c_sp),y"); AddCodeLine ("dey"); AddCodeLine ("dex"); AddCodeLine ("bpl %s", LocalLabelName (Label)); @@ -391,7 +391,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr) AddCodeLine ("ldy #$%02X", (unsigned char) Offs); g_defcodelabel (Label); AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, -Offs)); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("sta (c_sp),y"); AddCodeLine ("iny"); AddCmpCodeIfSizeNot256 ("cpy #$%02X", Offs + Arg3.Expr.IVal); AddCodeLine ("bne %s", LocalLabelName (Label)); @@ -400,7 +400,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr) AddCodeLine ("ldy #$%02X", (unsigned char) Offs); g_defcodelabel (Label); AddCodeLine ("lda %s,x", ED_GetLabelName (&Arg2.Expr, 0)); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("sta (c_sp),y"); AddCodeLine ("iny"); AddCodeLine ("inx"); AddCmpCodeIfSizeNot256 ("cpx #$%02X", Arg3.Expr.IVal); @@ -448,7 +448,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr) if (Offs == 0) { AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.IVal - 1)); g_defcodelabel (Label); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, 0)); AddCodeLine ("dey"); AddCodeLine ("bpl %s", LocalLabelName (Label)); @@ -456,7 +456,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr) AddCodeLine ("ldx #$%02X", (unsigned char) (Arg3.Expr.IVal-1)); AddCodeLine ("ldy #$%02X", (unsigned char) (Offs + Arg3.Expr.IVal - 1)); g_defcodelabel (Label); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sta %s,x", ED_GetLabelName (&Arg1.Expr, 0)); AddCodeLine ("dey"); AddCodeLine ("dex"); @@ -468,7 +468,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr) if (Offs == 0 || AllowOneIndex) { AddCodeLine ("ldy #$%02X", (unsigned char) Offs); g_defcodelabel (Label); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, -Offs)); AddCodeLine ("iny"); AddCmpCodeIfSizeNot256 ("cpy #$%02X", Offs + Arg3.Expr.IVal); @@ -477,7 +477,7 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr) AddCodeLine ("ldx #$00"); AddCodeLine ("ldy #$%02X", (unsigned char) Offs); g_defcodelabel (Label); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sta %s,x", ED_GetLabelName (&Arg1.Expr, 0)); AddCodeLine ("iny"); AddCodeLine ("inx"); @@ -512,14 +512,14 @@ static void StdFunc_memcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr) if (Arg3.Expr.IVal <= 129) { AddCodeLine ("ldy #$%02X", (unsigned char) (Arg3.Expr.IVal - 1)); g_defcodelabel (Label); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sta (ptr1),y"); AddCodeLine ("dey"); AddCodeLine ("bpl %s", LocalLabelName (Label)); } else { AddCodeLine ("ldy #$00"); g_defcodelabel (Label); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sta (ptr1),y"); AddCodeLine ("iny"); AddCmpCodeIfSizeNot256 ("cpy #$%02X", Arg3.Expr.IVal); @@ -703,7 +703,7 @@ static void StdFunc_memset (FuncDesc* F attribute ((unused)), ExprDesc* Expr) AddCodeLine ("ldy #$%02X", (unsigned char) Offs); AddCodeLine ("lda #$%02X", (unsigned char) Arg2.Expr.IVal); g_defcodelabel (Label); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("sta (c_sp),y"); AddCodeLine ("iny"); AddCmpCodeIfSizeNot256 ("cpy #$%02X", Offs + Arg3.Expr.IVal); AddCodeLine ("bne %s", LocalLabelName (Label)); @@ -857,7 +857,7 @@ static void StdFunc_strcmp (FuncDesc* F attribute ((unused)), ExprDesc* Expr) /* Generate code */ AddCodeLine ("ldy #$%02X", Offs); AddCodeLine ("ldx #$00"); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); } else if (IsArray && ED_IsLocConst (&Arg1.Expr)) { /* Drop the generated code */ RemoveCode (&Arg1.Load); @@ -1090,14 +1090,14 @@ static void StdFunc_strcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr) if (Offs == 0 || AllowOneIndex) { g_defcodelabel (L1); AddCodeLine ("iny"); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sta %s,y", ED_GetLabelName (&Arg1.Expr, -Offs)); } else { AddCodeLine ("ldx #$FF"); g_defcodelabel (L1); AddCodeLine ("iny"); AddCodeLine ("inx"); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("sta %s,x", ED_GetLabelName (&Arg1.Expr, 0)); } AddCodeLine ("bne %s", LocalLabelName (L1)); @@ -1138,14 +1138,14 @@ static void StdFunc_strcpy (FuncDesc* F attribute ((unused)), ExprDesc* Expr) g_defcodelabel (L1); AddCodeLine ("iny"); AddCodeLine ("lda %s,y", ED_GetLabelName (&Arg2.Expr, -Offs)); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("sta (c_sp),y"); } else { AddCodeLine ("ldx #$FF"); g_defcodelabel (L1); AddCodeLine ("iny"); AddCodeLine ("inx"); AddCodeLine ("lda %s,x", ED_GetLabelName (&Arg2.Expr, 0)); - AddCodeLine ("sta (sp),y"); + AddCodeLine ("sta (c_sp),y"); } AddCodeLine ("bne %s", LocalLabelName (L1)); @@ -1285,7 +1285,7 @@ static void StdFunc_strlen (FuncDesc* F attribute ((unused)), ExprDesc* Expr) g_defcodelabel (L); AddCodeLine ("inx"); AddCodeLine ("iny"); - AddCodeLine ("lda (sp),y"); + AddCodeLine ("lda (c_sp),y"); AddCodeLine ("bne %s", LocalLabelName (L)); AddCodeLine ("txa"); AddCodeLine ("ldx #$00"); diff --git a/src/dbginfo/dbgsh.c b/src/dbginfo/dbgsh.c index 6a95db2af..280221fc9 100644 --- a/src/dbginfo/dbgsh.c +++ b/src/dbginfo/dbgsh.c @@ -458,7 +458,7 @@ static unsigned FindIdType (const char* TypeName) { "segment", SegmentId }, { "source", SourceId }, { "src", SourceId }, - { "sp", SpanId }, + { "c_sp", SpanId }, { "span", SpanId }, { "sym", SymbolId }, { "symbol", SymbolId }, diff --git a/src/sim65/main.c b/src/sim65/main.c index 828ea498e..3cc9581b5 100644 --- a/src/sim65/main.c +++ b/src/sim65/main.c @@ -230,7 +230,7 @@ static unsigned char ReadProgramFile (void) } } - /* Get the address of sp from the file header */ + /* Get the address of c_sp from the file header */ if ((Val = fgetc(F)) != EOF) { SPAddr = Val; } diff --git a/targettest/atari/mem.c b/targettest/atari/mem.c index b15b215ed..f063d1e46 100644 --- a/targettest/atari/mem.c +++ b/targettest/atari/mem.c @@ -41,7 +41,7 @@ int main(void) printf(" data: $%04X (data)\n", &data); printf(" _dos_type: $%04X (bss)\n", &_dos_type); printf(" allocmem: $%04X (dyn. data)\n", allocmem); - printf(" sp: $%04X (stack ptr)\n", getsp()); + printf(" c_sp: $%04X (stack ptr)\n", getsp()); if (allocmem) free(allocmem); if (doesclrscrafterexit()) cgetc(); diff --git a/targettest/ft.c b/targettest/ft.c index 3dfa0e37b..a28795f2b 100644 --- a/targettest/ft.c +++ b/targettest/ft.c @@ -10,7 +10,7 @@ ** got one from argv). I then opens the file, ** reads the first 16 bytes and displays them ** (as hex values). -** The values of sp (cc65 runtime stack pointer) +** The values of c_sp (cc65 runtime stack pointer) ** are displayed at some places. The displayed ** value should always be the same. */ @@ -64,16 +64,16 @@ int main(int argc,char **argv) } printf("using filename \"%s\"\n",filename); csp = getsp(); - printf("now opening file... sp = %d\n",csp); + printf("now opening file... c_sp = %d\n",csp); fd = open(filename,O_RDONLY); csp = getsp(); if (fd == -1) { char x1 = _oserror; - printf("open failed: os: %d,\n\terrno: %d, sp = %d\n",x1,errno,csp); + printf("open failed: os: %d,\n\terrno: %d, c_sp = %d\n",x1,errno,csp); cgetc(); return(0); } - printf("open success -- handle = $%x, sp = %d\n",fd,csp); + printf("open success -- handle = $%x, c_sp = %d\n",fd,csp); #ifdef __ATARI__ printf("fd_index:\n "); for (i=0; i<12; i++) printf("%02X ",__fd_index[i]); @@ -88,7 +88,7 @@ int main(int argc,char **argv) lr = read(fd,buf,16); /* read first 16 bytes */ csp = getsp(); if (lr == -1) { - printf("read failed: %d (sp = %d)\n",errno,csp); + printf("read failed: %d (c_sp = %d)\n",errno,csp); cgetc(); return(0); } @@ -99,7 +99,7 @@ int main(int argc,char **argv) return(0); } csp = getsp(); - printf("\n\nThe data read: (%d bytes, sp = %d)\n",lr,csp); + printf("\n\nThe data read: (%d bytes, c_sp = %d)\n",lr,csp); for (i=0; i Date: Tue, 24 Jun 2025 19:33:49 +0200 Subject: [PATCH 02/27] initial asm includes for c65 and mega65 --- asminc/c65.inc | 235 ++++++++++++++++++++++++++++++++++++++++++ asminc/cbm_kernal.inc | 57 +++++++++- asminc/cpu.mac | 15 ++- asminc/mega65.inc | 235 ++++++++++++++++++++++++++++++++++++++++++ 4 files changed, 532 insertions(+), 10 deletions(-) create mode 100644 asminc/c65.inc create mode 100644 asminc/mega65.inc diff --git a/asminc/c65.inc b/asminc/c65.inc new file mode 100644 index 000000000..4c10431ab --- /dev/null +++ b/asminc/c65.inc @@ -0,0 +1,235 @@ + +; --------------------------------------------------------------------------- +; Zero page, Commodore stuff + +TXTPTR := $3C ; Pointer into BASIC source code +STATUS := $90 ; Kernal I/O completion status +FNAM_LEN := $B7 ; Length of filename +SECADR := $B9 ; Secondary address +DEVNUM := $BA ; Device number +FNAM := $BB ; Address of filename +FNAM_BANK := $BE ; Bank for filename +KEY_COUNT := $D0 ; Number of keys in input buffer +FKEY_COUNT := $D1 ; Characters for function key +MODE := $D7 ; 40-/80-column mode (bit 7: 80 columns) +GRAPHM := $D8 ; Graphics mode flags (bits 5-7) +CHARDIS := $D9 ; Bit 2 shadow for location $01 +CURS_X := $EC ; Cursor column +CURS_Y := $EB ; Cursor row +SCREEN_PTR := $E0 ; Pointer to current char in text screen +CRAM_PTR := $E2 ; Pointer to current char in color RAM +CHARCOLOR := $F1 +RVS := $F3 ; Reverse output flag +SCROLL := $F8 ; Disable scrolling flag + +BASIC_BUF := $0200 ; Location of command-line +BASIC_BUF_LEN = 161 ; Maximum length of command-line + +FKEY_LEN := $1000 ; Function key lengths +FKEY_TEXT := $100A ; Function key texts + +PALFLAG := $1103 ; $FF=PAL, $00=NTSC +INIT_STATUS := $1104 ; Flags: Reset/Restore initiation status +TIME := $110C ; 60HZ clock + +KBDREPEAT := $111a +KBDREPEATRATE := $111b +KBDREPEATDELAY := $111c + +; --------------------------------------------------------------------------- +; Vectors + +IRQVec := $0314 +BRKVec := $0316 +NMIVec := $0318 + +; --------------------------------------------------------------------------- +; I/O: VIC + +VIC := $D000 +VIC_SPR0_X := $D000 +VIC_SPR0_Y := $D001 +VIC_SPR1_X := $D002 +VIC_SPR1_Y := $D003 +VIC_SPR2_X := $D004 +VIC_SPR2_Y := $D005 +VIC_SPR3_X := $D006 +VIC_SPR3_Y := $D007 +VIC_SPR4_X := $D008 +VIC_SPR4_Y := $D009 +VIC_SPR5_X := $D00A +VIC_SPR5_Y := $D00B +VIC_SPR6_X := $D00C +VIC_SPR6_Y := $D00D +VIC_SPR7_X := $D00E +VIC_SPR7_Y := $D00F +VIC_SPR_HI_X := $D010 +VIC_SPR_ENA := $D015 +VIC_SPR_EXP_Y := $D017 +VIC_SPR_EXP_X := $D01D +VIC_SPR_MCOLOR := $D01C +VIC_SPR_BG_PRIO := $D01B +VIC_SPR_COLL := $D01E +VIC_SPR_BG_COLL := $D01F + +VIC_SPR_MCOLOR0 := $D025 +VIC_SPR_MCOLOR1 := $D026 + +VIC_SPR0_COLOR := $D027 +VIC_SPR1_COLOR := $D028 +VIC_SPR2_COLOR := $D029 +VIC_SPR3_COLOR := $D02A +VIC_SPR4_COLOR := $D02B +VIC_SPR5_COLOR := $D02C +VIC_SPR6_COLOR := $D02D +VIC_SPR7_COLOR := $D02E + +VIC_CTRL1 := $D011 +VIC_CTRL2 := $D016 + +VIC_HLINE := $D012 + +VIC_LPEN_X := $D013 +VIC_LPEN_Y := $D014 + +VIC_VIDEO_ADR := $D018 + +VIC_IRR := $D019 ; Interrupt request register +VIC_IMR := $D01A ; Interrupt mask register + +VIC_BORDERCOLOR := $D020 +VIC_BG_COLOR0 := $D021 +VIC_BG_COLOR1 := $D022 +VIC_BG_COLOR2 := $D023 +VIC_BG_COLOR3 := $D024 + + +; --------------------------------------------------------------------------- +; I/O: FDC + +FDC := $D080 + +; --------------------------------------------------------------------------- +; I/O: SID + +SID0 := $D400 +SID0_S1Lo := $D400 +SID0_S1Hi := $D401 +SID0_PB1Lo := $D402 +SID0_PB1Hi := $D403 +SID0_Ctl1 := $D404 +SID0_AD1 := $D405 +SID0_SUR1 := $D406 + +SID0_S2Lo := $D407 +SID0_S2Hi := $D408 +SID0_PB2Lo := $D409 +SID0_PB2Hi := $D40A +SID0_Ctl2 := $D40B +SID0_AD2 := $D40C +SID0_SUR2 := $D40D + +SID0_S3Lo := $D40E +SID0_S3Hi := $D40F +SID0_PB3Lo := $D410 +SID0_PB3Hi := $D411 +SID0_Ctl3 := $D412 +SID0_AD3 := $D413 +SID0_SUR3 := $D414 + +SID0_FltLo := $D415 +SID0_FltHi := $D416 +SID0_FltCtl := $D417 +SID0_Amp := $D418 +SID0_ADConv1 := $D419 +SID0_ADConv2 := $D41A +SID0_Noise := $D41B +SID0_Read3 := $D41C + +SID1 := $D420 +SID1_S1Lo := $D420 +SID1_S1Hi := $D421 +SID1_PB1Lo := $D422 +SID1_PB1Hi := $D423 +SID1_Ctl1 := $D424 +SID1_AD1 := $D425 +SID1_SUR1 := $D426 + +SID1_S2Lo := $D427 +SID1_S2Hi := $D428 +SID1_PB2Lo := $D429 +SID1_PB2Hi := $D42A +SID1_Ctl2 := $D42B +SID1_AD2 := $D42C +SID1_SUR2 := $D42D + +SID1_S3Lo := $D42E +SID1_S3Hi := $D42F +SID1_PB3Lo := $D430 +SID1_PB3Hi := $D431 +SID1_Ctl3 := $D432 +SID1_AD3 := $D433 +SID1_SUR3 := $D434 + +SID1_FltLo := $D435 +SID1_FltHi := $D436 +SID1_FltCtl := $D437 +SID1_Amp := $D438 +SID1_ADConv1 := $D439 +SID1_ADConv2 := $D43A +SID1_Noise := $D43B +SID1_Read3 := $D43C + +; --------------------------------------------------------------------------- +; I/O: Complex Interface Adapters + +CIA1 := $DC00 +CIA1_PRA := $DC00 ; Port A +CIA1_PRB := $DC01 ; Port B +CIA1_DDRA := $DC02 ; Data direction register for port A +CIA1_DDRB := $DC03 ; Data direction register for port B +CIA1_TA := $DC04 ; 16-bit timer A +CIA1_TB := $DC06 ; 16-bit timer B +CIA1_TOD10 := $DC08 ; Time-of-day tenths of a second +CIA1_TODSEC := $DC09 ; Time-of-day seconds +CIA1_TODMIN := $DC0A ; Time-of-day minutes +CIA1_TODHR := $DC0B ; Time-of-day hours +CIA1_SDR := $DC0C ; Serial data register +CIA1_ICR := $DC0D ; Interrupt control register +CIA1_CRA := $DC0E ; Control register for timer A +CIA1_CRB := $DC0F ; Control register for timer B + +CIA2 := $DD00 +CIA2_PRA := $DD00 +CIA2_PRB := $DD01 +CIA2_DDRA := $DD02 +CIA2_DDRB := $DD03 +CIA2_TA := $DD04 +CIA2_TB := $DD06 +CIA2_TOD10 := $DD08 +CIA2_TODSEC := $DD09 +CIA2_TODMIN := $DD0A +CIA2_TODHR := $DD0B +CIA2_SDR := $DD0C +CIA2_ICR := $DD0D +CIA2_CRA := $DD0E +CIA2_CRB := $DD0F + +; --------------------------------------------------------------------------- +; I/O: DMA + +DMA := $D700 + + +; --------------------------------------------------------------------------- +; Processor Port at $01 + +LORAM = $01 ; Enable the basic rom +HIRAM = $02 ; Enable the kernal rom +IOEN = $04 ; Enable I/O +CASSDATA = $08 ; Cassette data +CASSPLAY = $10 ; Cassette: Play +CASSMOT = $20 ; Cassette motor on +TP_FAST = $80 ; Switch Rossmoeller TurboProcess to fast mode + +RAMONLY = $F8 ; (~(LORAM | HIRAM | IOEN)) & $FF diff --git a/asminc/cbm_kernal.inc b/asminc/cbm_kernal.inc index 4d78cf93f..e38131ab4 100644 --- a/asminc/cbm_kernal.inc +++ b/asminc/cbm_kernal.inc @@ -63,6 +63,35 @@ MOUSE_GET := $FF6B .endif +.if .def(__C65__) || .def (__MEGA65__) + ; extended C65 jump table + VERSIONQ := $FF2F + RESET_RUN := $FF32 + CURSOR := $FF35 + SAVEFL := $FF3B + GETIO := $FF41 + GETLFS := $FF44 + KEYLOCKS := $FF47 + ADDKEY := $FF4A + SPIN_SPOUT := $FF4D + CLSALL := $FF50 + C64MODE := $FF53 + MonitorCall := $FF56 + BOOT_SYS := $FF59 + PHOENIX := $FF5C + LKUPLA := $FF5F + LKUPSA := $FF62 + SWAPPER := $FF65 + PFKEY := $FF68 + SETBNK := $FF6B + JSRFAR := $FF6E + JMPFAR := $FF71 + LDA_FAR := $FF74 + STA_FAR := $FF77 + CMP_FAR := $FF7A + PRIMM := $FF7D +.endif + .if .def(__C128__) ; C128 extended jump table C64MODE := $FF4D @@ -83,7 +112,7 @@ PRIMM := $FF7D .endif -.if .def(__C64__) || .def(__C128__) || .def(__C16__) || .def(__CX16__) +.if .def(__C64__) || .def(__C128__) || .def(__C16__) || .def(__CX16__) || .def(__C65__) || .def (__MEGA65__) CINT := $FF81 IOINIT := $FF84 RAMTAS := $FF87 @@ -96,7 +125,7 @@ CINT := $FF7E .endif -.if .def(__VIC20__) || .def(__C64__) || .def(__C128__) || .def(__C16__) || .def(__CX16__) +.if .def(__VIC20__) || .def(__C64__) || .def(__C128__) || .def(__C16__) || .def(__CX16__) || .def(__C65__) || .def (__MEGA65__) RESTOR := $FF8A VECTOR := $FF8D .elseif .def(__CBM510__) || .def(__CBM610__) @@ -112,6 +141,17 @@ MEMBOT := $FF9C SCNKEY := $FF9F SETTMO := $FFA2 +.elseif .def(__C65__) || .def (__MEGA65__) + SETMSG := $FF90 + SECOND := $FF93 + TKSA := $FF96 + MEMTOP := $FF99 + MEMBOT := $FF9C + SCNKEY := $FF9F + MONEXIT := $FFA2 +.endif + +.if .def(__CBM510__) || .def(__CBM610__) || .def(__VIC20__) || .def(__C64__) || .def(__C128__) || .def(__C16__) || .def(__CX16__) || .def(__C65__) || .def(__MEGA65__) ACPTR := $FFA5 CIOUT := $FFA8 UNTLK := $FFAB @@ -136,7 +176,7 @@ CHRIN := $FFCF BSOUT := $FFD2 CHROUT := $FFD2 -.if .def(__CBM510__) || .def(__CBM610__) || .def(__VIC20__) || .def(__C64__) || .def(__C128__) || .def(__C16__) || .def(__CX16__) +.if .def(__CBM510__) || .def(__CBM610__) || .def(__VIC20__) || .def(__C64__) || .def(__C128__) || .def(__C16__) || .def(__CX16__) || .def(__C65__) || .def(__MEGA65__) LOAD := $FFD5 SAVE := $FFD8 SETTIM := $FFDB @@ -147,9 +187,14 @@ CHROUT := $FFD2 STOP := $FFE1 GETIN := $FFE4 CLALL := $FFE7 -UDTIM := $FFEA -.if .def(__CBM510__) || .def(__CBM610__) || .def(__VIC20__) || .def(__C64__) || .def(__C128__) || .def(__C16__) || .def(__CX16__) +.if .def(__C65__) || .def(__MEGA65__) +ScanStopKey := $FFEA +.else +UDTIM := $FFEA +.endif + +.if .def(__CBM510__) || .def(__CBM610__) || .def(__VIC20__) || .def(__C64__) || .def(__C128__) || .def(__C16__) || .def(__CX16__) || .def(__C65__) || .def(__MEGA65__) SCREEN := $FFED PLOT := $FFF0 IOBASE := $FFF3 @@ -189,4 +234,6 @@ UDTIM := $FFEA .elseif .def(__C16__) CLRSCR := $D88B KBDREAD := $D8C1 +.elseif .def(__C65__) || .def(__MEGA65__) +; CLRSCR := $E0EC ; ??? .endif diff --git a/asminc/cpu.mac b/asminc/cpu.mac index e3ab49014..be35265b7 100644 --- a/asminc/cpu.mac +++ b/asminc/cpu.mac @@ -1,12 +1,15 @@ -; CPU bitmask constants +; CPU bitmask constants (make sure this matches src/common/cpu.h) + CPU_ISET_NONE = $0001 CPU_ISET_6502 = $0002 CPU_ISET_6502X = $0004 CPU_ISET_6502DTV = $0008 + CPU_ISET_65SC02 = $0010 CPU_ISET_65C02 = $0020 CPU_ISET_65816 = $0040 CPU_ISET_SWEET16 = $0080 + CPU_ISET_HUC6280 = $0100 CPU_ISET_M740 = $0200 CPU_ISET_4510 = $0400 @@ -21,9 +24,11 @@ CPU_65SC02 = CPU_ISET_6502|CPU_ISET_65SC02 CPU_65C02 = CPU_ISET_6502|CPU_ISET_65SC02|CPU_ISET_65C02 CPU_65816 = CPU_ISET_6502|CPU_ISET_65SC02|CPU_ISET_65816 CPU_SWEET16 = CPU_ISET_SWEET16 +; FIXME: CPU_ISET_65SC02 does not apply to the following, because the zp-indirect +; addressing was replaced with zp-indirect,z-indexed in 652SCE02 ; NOTE: HUC6280 removes "wai" ($cb) and "stp" ($db) from the 65C02 instruction set -CPU_HUC6280 = CPU_ISET_6502|CPU_ISET_65SC02|CPU_ISET_65C02|CPU_ISET_HUC6280 -; NOTE: 45100 replaces "wai" ($cb) and "stp" ($db) of the 65C02 instruction set -CPU_4510 = CPU_ISET_6502|CPU_ISET_65SC02|CPU_ISET_65C02|CPU_ISET_4510 -CPU_45GS02 = CPU_ISET_6502|CPU_ISET_65SC02|CPU_ISET_65C02|CPU_ISET_4510|CPU_ISET_45GS02 +CPU_HUC6280 = CPU_ISET_6502|CPU_ISET_65C02|CPU_ISET_HUC6280 +; NOTE: 4510 replaces "wai" ($cb) and "stp" ($db) of the 65C02 instruction set +CPU_4510 = CPU_ISET_6502|CPU_ISET_65C02|CPU_ISET_4510 +CPU_45GS02 = CPU_ISET_6502|CPU_ISET_65C02|CPU_ISET_4510|CPU_ISET_45GS02 CPU_M740 = CPU_ISET_6502|CPU_ISET_M740 diff --git a/asminc/mega65.inc b/asminc/mega65.inc new file mode 100644 index 000000000..4c10431ab --- /dev/null +++ b/asminc/mega65.inc @@ -0,0 +1,235 @@ + +; --------------------------------------------------------------------------- +; Zero page, Commodore stuff + +TXTPTR := $3C ; Pointer into BASIC source code +STATUS := $90 ; Kernal I/O completion status +FNAM_LEN := $B7 ; Length of filename +SECADR := $B9 ; Secondary address +DEVNUM := $BA ; Device number +FNAM := $BB ; Address of filename +FNAM_BANK := $BE ; Bank for filename +KEY_COUNT := $D0 ; Number of keys in input buffer +FKEY_COUNT := $D1 ; Characters for function key +MODE := $D7 ; 40-/80-column mode (bit 7: 80 columns) +GRAPHM := $D8 ; Graphics mode flags (bits 5-7) +CHARDIS := $D9 ; Bit 2 shadow for location $01 +CURS_X := $EC ; Cursor column +CURS_Y := $EB ; Cursor row +SCREEN_PTR := $E0 ; Pointer to current char in text screen +CRAM_PTR := $E2 ; Pointer to current char in color RAM +CHARCOLOR := $F1 +RVS := $F3 ; Reverse output flag +SCROLL := $F8 ; Disable scrolling flag + +BASIC_BUF := $0200 ; Location of command-line +BASIC_BUF_LEN = 161 ; Maximum length of command-line + +FKEY_LEN := $1000 ; Function key lengths +FKEY_TEXT := $100A ; Function key texts + +PALFLAG := $1103 ; $FF=PAL, $00=NTSC +INIT_STATUS := $1104 ; Flags: Reset/Restore initiation status +TIME := $110C ; 60HZ clock + +KBDREPEAT := $111a +KBDREPEATRATE := $111b +KBDREPEATDELAY := $111c + +; --------------------------------------------------------------------------- +; Vectors + +IRQVec := $0314 +BRKVec := $0316 +NMIVec := $0318 + +; --------------------------------------------------------------------------- +; I/O: VIC + +VIC := $D000 +VIC_SPR0_X := $D000 +VIC_SPR0_Y := $D001 +VIC_SPR1_X := $D002 +VIC_SPR1_Y := $D003 +VIC_SPR2_X := $D004 +VIC_SPR2_Y := $D005 +VIC_SPR3_X := $D006 +VIC_SPR3_Y := $D007 +VIC_SPR4_X := $D008 +VIC_SPR4_Y := $D009 +VIC_SPR5_X := $D00A +VIC_SPR5_Y := $D00B +VIC_SPR6_X := $D00C +VIC_SPR6_Y := $D00D +VIC_SPR7_X := $D00E +VIC_SPR7_Y := $D00F +VIC_SPR_HI_X := $D010 +VIC_SPR_ENA := $D015 +VIC_SPR_EXP_Y := $D017 +VIC_SPR_EXP_X := $D01D +VIC_SPR_MCOLOR := $D01C +VIC_SPR_BG_PRIO := $D01B +VIC_SPR_COLL := $D01E +VIC_SPR_BG_COLL := $D01F + +VIC_SPR_MCOLOR0 := $D025 +VIC_SPR_MCOLOR1 := $D026 + +VIC_SPR0_COLOR := $D027 +VIC_SPR1_COLOR := $D028 +VIC_SPR2_COLOR := $D029 +VIC_SPR3_COLOR := $D02A +VIC_SPR4_COLOR := $D02B +VIC_SPR5_COLOR := $D02C +VIC_SPR6_COLOR := $D02D +VIC_SPR7_COLOR := $D02E + +VIC_CTRL1 := $D011 +VIC_CTRL2 := $D016 + +VIC_HLINE := $D012 + +VIC_LPEN_X := $D013 +VIC_LPEN_Y := $D014 + +VIC_VIDEO_ADR := $D018 + +VIC_IRR := $D019 ; Interrupt request register +VIC_IMR := $D01A ; Interrupt mask register + +VIC_BORDERCOLOR := $D020 +VIC_BG_COLOR0 := $D021 +VIC_BG_COLOR1 := $D022 +VIC_BG_COLOR2 := $D023 +VIC_BG_COLOR3 := $D024 + + +; --------------------------------------------------------------------------- +; I/O: FDC + +FDC := $D080 + +; --------------------------------------------------------------------------- +; I/O: SID + +SID0 := $D400 +SID0_S1Lo := $D400 +SID0_S1Hi := $D401 +SID0_PB1Lo := $D402 +SID0_PB1Hi := $D403 +SID0_Ctl1 := $D404 +SID0_AD1 := $D405 +SID0_SUR1 := $D406 + +SID0_S2Lo := $D407 +SID0_S2Hi := $D408 +SID0_PB2Lo := $D409 +SID0_PB2Hi := $D40A +SID0_Ctl2 := $D40B +SID0_AD2 := $D40C +SID0_SUR2 := $D40D + +SID0_S3Lo := $D40E +SID0_S3Hi := $D40F +SID0_PB3Lo := $D410 +SID0_PB3Hi := $D411 +SID0_Ctl3 := $D412 +SID0_AD3 := $D413 +SID0_SUR3 := $D414 + +SID0_FltLo := $D415 +SID0_FltHi := $D416 +SID0_FltCtl := $D417 +SID0_Amp := $D418 +SID0_ADConv1 := $D419 +SID0_ADConv2 := $D41A +SID0_Noise := $D41B +SID0_Read3 := $D41C + +SID1 := $D420 +SID1_S1Lo := $D420 +SID1_S1Hi := $D421 +SID1_PB1Lo := $D422 +SID1_PB1Hi := $D423 +SID1_Ctl1 := $D424 +SID1_AD1 := $D425 +SID1_SUR1 := $D426 + +SID1_S2Lo := $D427 +SID1_S2Hi := $D428 +SID1_PB2Lo := $D429 +SID1_PB2Hi := $D42A +SID1_Ctl2 := $D42B +SID1_AD2 := $D42C +SID1_SUR2 := $D42D + +SID1_S3Lo := $D42E +SID1_S3Hi := $D42F +SID1_PB3Lo := $D430 +SID1_PB3Hi := $D431 +SID1_Ctl3 := $D432 +SID1_AD3 := $D433 +SID1_SUR3 := $D434 + +SID1_FltLo := $D435 +SID1_FltHi := $D436 +SID1_FltCtl := $D437 +SID1_Amp := $D438 +SID1_ADConv1 := $D439 +SID1_ADConv2 := $D43A +SID1_Noise := $D43B +SID1_Read3 := $D43C + +; --------------------------------------------------------------------------- +; I/O: Complex Interface Adapters + +CIA1 := $DC00 +CIA1_PRA := $DC00 ; Port A +CIA1_PRB := $DC01 ; Port B +CIA1_DDRA := $DC02 ; Data direction register for port A +CIA1_DDRB := $DC03 ; Data direction register for port B +CIA1_TA := $DC04 ; 16-bit timer A +CIA1_TB := $DC06 ; 16-bit timer B +CIA1_TOD10 := $DC08 ; Time-of-day tenths of a second +CIA1_TODSEC := $DC09 ; Time-of-day seconds +CIA1_TODMIN := $DC0A ; Time-of-day minutes +CIA1_TODHR := $DC0B ; Time-of-day hours +CIA1_SDR := $DC0C ; Serial data register +CIA1_ICR := $DC0D ; Interrupt control register +CIA1_CRA := $DC0E ; Control register for timer A +CIA1_CRB := $DC0F ; Control register for timer B + +CIA2 := $DD00 +CIA2_PRA := $DD00 +CIA2_PRB := $DD01 +CIA2_DDRA := $DD02 +CIA2_DDRB := $DD03 +CIA2_TA := $DD04 +CIA2_TB := $DD06 +CIA2_TOD10 := $DD08 +CIA2_TODSEC := $DD09 +CIA2_TODMIN := $DD0A +CIA2_TODHR := $DD0B +CIA2_SDR := $DD0C +CIA2_ICR := $DD0D +CIA2_CRA := $DD0E +CIA2_CRB := $DD0F + +; --------------------------------------------------------------------------- +; I/O: DMA + +DMA := $D700 + + +; --------------------------------------------------------------------------- +; Processor Port at $01 + +LORAM = $01 ; Enable the basic rom +HIRAM = $02 ; Enable the kernal rom +IOEN = $04 ; Enable I/O +CASSDATA = $08 ; Cassette data +CASSPLAY = $10 ; Cassette: Play +CASSMOT = $20 ; Cassette motor on +TP_FAST = $80 ; Switch Rossmoeller TurboProcess to fast mode + +RAMONLY = $F8 ; (~(LORAM | HIRAM | IOEN)) & $FF From 681b49a1119e9539250da723e208ef963684bfbd Mon Sep 17 00:00:00 2001 From: mrdudz Date: Tue, 24 Jun 2025 19:55:28 +0200 Subject: [PATCH 03/27] initial target header files for c65 and mega65 --- include/c65.h | 102 +++++++++++++++++++++++++++++++++++++++++++++++ include/cbm.h | 4 ++ include/mega65.h | 102 +++++++++++++++++++++++++++++++++++++++++++++++ 3 files changed, 208 insertions(+) create mode 100644 include/c65.h create mode 100644 include/mega65.h diff --git a/include/c65.h b/include/c65.h new file mode 100644 index 000000000..35ddadc3d --- /dev/null +++ b/include/c65.h @@ -0,0 +1,102 @@ +/*****************************************************************************/ +/* */ +/* c65.h */ +/* */ +/* C65 system specific definitions */ +/* */ +/* */ +/* */ +/* (C) 1998-2013, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#ifndef _C65_H +#define _C65_H + + + +/* Check for errors */ +#if !defined(__C65__) +# error This module may only be used when compiling for the MEGA65! +#endif + + + +/* Additional key defines */ +#define CH_F1 133 +#define CH_F2 137 +#define CH_F3 134 +#define CH_F4 138 +#define CH_F5 135 +#define CH_F6 139 +#define CH_F7 136 +#define CH_F8 140 + +/* Color defines */ +#define COLOR_BLACK 0x00 +#define COLOR_WHITE 0x01 +#define COLOR_RED 0x02 +#define COLOR_CYAN 0x03 +#define COLOR_PURPLE 0x04 +#define COLOR_GREEN 0x05 +#define COLOR_BLUE 0x06 +#define COLOR_YELLOW 0x07 +#define COLOR_ORANGE 0x08 +#define COLOR_BROWN 0x09 +#define COLOR_LIGHTRED 0x0A +#define COLOR_GRAY1 0x0B +#define COLOR_GRAY2 0x0C +#define COLOR_LIGHTGREEN 0x0D +#define COLOR_LIGHTBLUE 0x0E +#define COLOR_GRAY3 0x0F + +/* Masks for joy_read */ +#define JOY_UP_MASK 0x01 +#define JOY_DOWN_MASK 0x02 +#define JOY_LEFT_MASK 0x04 +#define JOY_RIGHT_MASK 0x08 +#define JOY_BTN_1_MASK 0x10 + + +/* Define hardware */ +#include <_vic2.h> +#define VIC (*(struct __vic2*)0xD000) + +#include <_sid.h> +#define SID1 (*(struct __sid*)0xD400) +#define SID2 (*(struct __sid*)0xD420) + +#include <_6526.h> +#define CIA1 (*(struct __6526*)0xDC00) +#define CIA2 (*(struct __6526*)0xDD00) + + +/* Define special memory areas */ +#define COLOR_RAM ((unsigned char*)0xD800) + + +/* End of c65.h */ +#endif diff --git a/include/cbm.h b/include/cbm.h index 0679b2d65..89c01ffc0 100644 --- a/include/cbm.h +++ b/include/cbm.h @@ -67,6 +67,10 @@ # include #elif defined(__CX16__) && !defined(_CX16_H) # include +#elif defined(__C65__) && !defined(_C65_H) +# include +#elif defined(__MEGA65__) && !defined(_MEGA65_H) +# include #endif /* Include definitions for CBM file types */ diff --git a/include/mega65.h b/include/mega65.h new file mode 100644 index 000000000..260ab5e5f --- /dev/null +++ b/include/mega65.h @@ -0,0 +1,102 @@ +/*****************************************************************************/ +/* */ +/* mega65.h */ +/* */ +/* MEGA65 system specific definitions */ +/* */ +/* */ +/* */ +/* (C) 1998-2013, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#ifndef _MEGA65_H +#define _MEGA65_H + + + +/* Check for errors */ +#if !defined(__MEGA65__) +# error This module may only be used when compiling for the MEGA65! +#endif + + + +/* Additional key defines */ +#define CH_F1 133 +#define CH_F2 137 +#define CH_F3 134 +#define CH_F4 138 +#define CH_F5 135 +#define CH_F6 139 +#define CH_F7 136 +#define CH_F8 140 + +/* Color defines */ +#define COLOR_BLACK 0x00 +#define COLOR_WHITE 0x01 +#define COLOR_RED 0x02 +#define COLOR_CYAN 0x03 +#define COLOR_PURPLE 0x04 +#define COLOR_GREEN 0x05 +#define COLOR_BLUE 0x06 +#define COLOR_YELLOW 0x07 +#define COLOR_ORANGE 0x08 +#define COLOR_BROWN 0x09 +#define COLOR_LIGHTRED 0x0A +#define COLOR_GRAY1 0x0B +#define COLOR_GRAY2 0x0C +#define COLOR_LIGHTGREEN 0x0D +#define COLOR_LIGHTBLUE 0x0E +#define COLOR_GRAY3 0x0F + +/* Masks for joy_read */ +#define JOY_UP_MASK 0x01 +#define JOY_DOWN_MASK 0x02 +#define JOY_LEFT_MASK 0x04 +#define JOY_RIGHT_MASK 0x08 +#define JOY_BTN_1_MASK 0x10 + + +/* Define hardware */ +#include <_vic2.h> +#define VIC (*(struct __vic2*)0xD000) + +#include <_sid.h> +#define SID1 (*(struct __sid*)0xD400) +#define SID2 (*(struct __sid*)0xD420) + +#include <_6526.h> +#define CIA1 (*(struct __6526*)0xDC00) +#define CIA2 (*(struct __6526*)0xDD00) + + +/* Define special memory areas */ +#define COLOR_RAM ((unsigned char*)0xD800) + + +/* End of mega65.h */ +#endif From a37a88d5bf7c5a0a7856e680e8a295c8f72f75a2 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Tue, 24 Jun 2025 21:19:38 +0200 Subject: [PATCH 04/27] std cbm tgi colors --- include/c65.h | 18 ++++++++++++++++++ include/mega65.h | 18 ++++++++++++++++++ 2 files changed, 36 insertions(+) diff --git a/include/c65.h b/include/c65.h index 35ddadc3d..5ba485978 100644 --- a/include/c65.h +++ b/include/c65.h @@ -73,6 +73,24 @@ #define COLOR_LIGHTBLUE 0x0E #define COLOR_GRAY3 0x0F +/* TGI color defines */ +#define TGI_COLOR_BLACK COLOR_BLACK +#define TGI_COLOR_WHITE COLOR_WHITE +#define TGI_COLOR_RED COLOR_RED +#define TGI_COLOR_CYAN COLOR_CYAN +#define TGI_COLOR_PURPLE COLOR_PURPLE +#define TGI_COLOR_GREEN COLOR_GREEN +#define TGI_COLOR_BLUE COLOR_BLUE +#define TGI_COLOR_YELLOW COLOR_YELLOW +#define TGI_COLOR_ORANGE COLOR_ORANGE +#define TGI_COLOR_BROWN COLOR_BROWN +#define TGI_COLOR_LIGHTRED COLOR_LIGHTRED +#define TGI_COLOR_GRAY1 COLOR_GRAY1 +#define TGI_COLOR_GRAY2 COLOR_GRAY2 +#define TGI_COLOR_LIGHTGREEN COLOR_LIGHTGREEN +#define TGI_COLOR_LIGHTBLUE COLOR_LIGHTBLUE +#define TGI_COLOR_GRAY3 COLOR_GRAY3 + /* Masks for joy_read */ #define JOY_UP_MASK 0x01 #define JOY_DOWN_MASK 0x02 diff --git a/include/mega65.h b/include/mega65.h index 260ab5e5f..9f13d2e6c 100644 --- a/include/mega65.h +++ b/include/mega65.h @@ -73,6 +73,24 @@ #define COLOR_LIGHTBLUE 0x0E #define COLOR_GRAY3 0x0F +/* TGI color defines */ +#define TGI_COLOR_BLACK COLOR_BLACK +#define TGI_COLOR_WHITE COLOR_WHITE +#define TGI_COLOR_RED COLOR_RED +#define TGI_COLOR_CYAN COLOR_CYAN +#define TGI_COLOR_PURPLE COLOR_PURPLE +#define TGI_COLOR_GREEN COLOR_GREEN +#define TGI_COLOR_BLUE COLOR_BLUE +#define TGI_COLOR_YELLOW COLOR_YELLOW +#define TGI_COLOR_ORANGE COLOR_ORANGE +#define TGI_COLOR_BROWN COLOR_BROWN +#define TGI_COLOR_LIGHTRED COLOR_LIGHTRED +#define TGI_COLOR_GRAY1 COLOR_GRAY1 +#define TGI_COLOR_GRAY2 COLOR_GRAY2 +#define TGI_COLOR_LIGHTGREEN COLOR_LIGHTGREEN +#define TGI_COLOR_LIGHTBLUE COLOR_LIGHTBLUE +#define TGI_COLOR_GRAY3 COLOR_GRAY3 + /* Masks for joy_read */ #define JOY_UP_MASK 0x01 #define JOY_DOWN_MASK 0x02 From bfb16888d142dcefce054c307d74a82ccd0673fc Mon Sep 17 00:00:00 2001 From: mrdudz Date: Tue, 24 Jun 2025 21:20:31 +0200 Subject: [PATCH 05/27] simple linker config for c65 and mega65 --- cfg/c65.cfg | 44 ++++++++++++++++++++++++++++++++++++++++++++ cfg/mega65.cfg | 44 ++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 88 insertions(+) create mode 100644 cfg/c65.cfg create mode 100644 cfg/mega65.cfg diff --git a/cfg/c65.cfg b/cfg/c65.cfg new file mode 100644 index 000000000..914f84f3c --- /dev/null +++ b/cfg/c65.cfg @@ -0,0 +1,44 @@ +FEATURES { + STARTADDRESS: default = $2001; +} +SYMBOLS { + __LOADADDR__: type = import; + __EXEHDR__: type = import; + __STACKSIZE__: type = weak, value = $0800; # 2k stack + __HIMEM__: type = weak, value = $8000; +} +MEMORY { + ZP: file = "", define = yes, start = $0002, size = $001A; + LOADADDR: file = %O, start = %S - 2, size = $0002; + HEADER: file = %O, define = yes, start = %S, size = $0010; + MAIN: file = %O, define = yes, start = __HEADER_LAST__, size = __HIMEM__ - __HEADER_LAST__; + BSS: file = "", start = __ONCE_RUN__, size = __HIMEM__ - __STACKSIZE__ - __ONCE_RUN__; +} +SEGMENTS { + ZEROPAGE: load = ZP, type = zp; + LOADADDR: load = LOADADDR, type = ro; + EXEHDR: load = HEADER, type = ro; + STARTUP: load = MAIN, type = ro; + LOWCODE: load = MAIN, type = ro, optional = yes; + CODE: load = MAIN, type = ro; + RODATA: load = MAIN, type = ro; + DATA: load = MAIN, type = rw; + INIT: load = MAIN, type = rw; # uninitialized, but reserves output space + ONCE: load = MAIN, type = ro, define = yes; + BSS: load = BSS, type = bss, define = yes; +} +FEATURES { + CONDES: type = constructor, + label = __CONSTRUCTOR_TABLE__, + count = __CONSTRUCTOR_COUNT__, + segment = ONCE; + CONDES: type = destructor, + label = __DESTRUCTOR_TABLE__, + count = __DESTRUCTOR_COUNT__, + segment = RODATA; + CONDES: type = interruptor, + label = __INTERRUPTOR_TABLE__, + count = __INTERRUPTOR_COUNT__, + segment = RODATA, + import = __CALLIRQ__; +} diff --git a/cfg/mega65.cfg b/cfg/mega65.cfg new file mode 100644 index 000000000..914f84f3c --- /dev/null +++ b/cfg/mega65.cfg @@ -0,0 +1,44 @@ +FEATURES { + STARTADDRESS: default = $2001; +} +SYMBOLS { + __LOADADDR__: type = import; + __EXEHDR__: type = import; + __STACKSIZE__: type = weak, value = $0800; # 2k stack + __HIMEM__: type = weak, value = $8000; +} +MEMORY { + ZP: file = "", define = yes, start = $0002, size = $001A; + LOADADDR: file = %O, start = %S - 2, size = $0002; + HEADER: file = %O, define = yes, start = %S, size = $0010; + MAIN: file = %O, define = yes, start = __HEADER_LAST__, size = __HIMEM__ - __HEADER_LAST__; + BSS: file = "", start = __ONCE_RUN__, size = __HIMEM__ - __STACKSIZE__ - __ONCE_RUN__; +} +SEGMENTS { + ZEROPAGE: load = ZP, type = zp; + LOADADDR: load = LOADADDR, type = ro; + EXEHDR: load = HEADER, type = ro; + STARTUP: load = MAIN, type = ro; + LOWCODE: load = MAIN, type = ro, optional = yes; + CODE: load = MAIN, type = ro; + RODATA: load = MAIN, type = ro; + DATA: load = MAIN, type = rw; + INIT: load = MAIN, type = rw; # uninitialized, but reserves output space + ONCE: load = MAIN, type = ro, define = yes; + BSS: load = BSS, type = bss, define = yes; +} +FEATURES { + CONDES: type = constructor, + label = __CONSTRUCTOR_TABLE__, + count = __CONSTRUCTOR_COUNT__, + segment = ONCE; + CONDES: type = destructor, + label = __DESTRUCTOR_TABLE__, + count = __DESTRUCTOR_COUNT__, + segment = RODATA; + CONDES: type = interruptor, + label = __INTERRUPTOR_TABLE__, + count = __INTERRUPTOR_COUNT__, + segment = RODATA, + import = __CALLIRQ__; +} From 450c8f7c558cd74bd9c5b1e4c77bb8914e1a1d1e Mon Sep 17 00:00:00 2001 From: mrdudz Date: Tue, 24 Jun 2025 21:23:04 +0200 Subject: [PATCH 06/27] startup code and minimalist kernal support for c65 and mega65 --- asminc/cbm_kernal.inc | 6 +- libsrc/c65/crt0.s | 124 +++++++++++++++++++++++++++++++++++++++++ libsrc/c65/kernal.s | 48 ++++++++++++++++ libsrc/mega65/crt0.s | 124 +++++++++++++++++++++++++++++++++++++++++ libsrc/mega65/kernal.s | 48 ++++++++++++++++ 5 files changed, 347 insertions(+), 3 deletions(-) create mode 100644 libsrc/c65/crt0.s create mode 100644 libsrc/c65/kernal.s create mode 100644 libsrc/mega65/crt0.s create mode 100644 libsrc/mega65/kernal.s diff --git a/asminc/cbm_kernal.inc b/asminc/cbm_kernal.inc index e38131ab4..a2fb05cb0 100644 --- a/asminc/cbm_kernal.inc +++ b/asminc/cbm_kernal.inc @@ -218,10 +218,10 @@ UDTIM := $FFEA KBDREAD := $E5CF UPDCRAMPTR := $EAB2 .elseif .def(__C64__) - CLRSCR := $E544 - KBDREAD := $E5B4 + CLRSCR := $E544 ; Clear the screen + KBDREAD := $E5B4 ; Get Character From Keyboard Buffer NMIEXIT := $FEBC - UPDCRAMPTR := $EA24 + UPDCRAMPTR := $EA24 ; Update color ram pointer .elseif .def(__C128__) CLRSCR := $C142 KBDREAD := $C006 diff --git a/libsrc/c65/crt0.s b/libsrc/c65/crt0.s new file mode 100644 index 000000000..855b4ccf6 --- /dev/null +++ b/libsrc/c65/crt0.s @@ -0,0 +1,124 @@ +; +; Startup code for cc65 (C65 version) +; + + .export _exit + .export __STARTUP__ : absolute = 1 ; Mark as startup + + .import initlib, donelib + .import zerobss, callmain + .import BSOUT + .import __MAIN_START__, __MAIN_SIZE__ ; Linker generated + .import __STACKSIZE__ ; from configure file + + .include "zeropage.inc" + .include "c65.inc" + + +; ------------------------------------------------------------------------ +; Startup code + +.segment "STARTUP" + +Start: + +; Switch off the BASIC ROM. + +; FIXME +; lda $01 +; sta mmusave ; Save the memory configuration +; and #$F8 +; ora #$06 ; Enable Kernal+I/O, disable BASIC +; sta $01 +; sei +; lda #%00000000 ; lower offset 15-8 +; ldx #%00000000 ; map blk3-1 | lower offset 19-6 +; ldy #%00000000 ; upper offset 15-8 +; ldz #%00000000 ; map blk7-4 | upper offset 19-6 +; map +; eom + + tsx + stx spsave ; Save the system stack ptr + +; Save space by putting some of the start-up code in the ONCE segment, +; which can be re-used by the BSS segment, the heap and the C stack. + + jsr init + +; Clear the BSS data. + + jsr zerobss + +; Push the command-line arguments; and, call main(). + + jsr callmain + +; Back from main() [this is also the exit() entry]. Run the module destructors. + +_exit: pha ; Save the return code on stack + jsr donelib + +; Copy back the zero-page stuff. + + ldx #zpspace-1 +L2: lda zpsave,x + sta c_sp,x + dex + bpl L2 + +; Place the program return code into BASIC's status variable. + + pla + sta STATUS + +; Restore the system stuff. + + ldx spsave + txs ; Restore stack pointer + +; Back to BASIC. + + rts + + +; ------------------------------------------------------------------------ + +.segment "ONCE" + +init: + +; Save the zero-page locations that we need. + + ldx #zpspace-1 +L1: lda c_sp,x + sta zpsave,x + dex + bpl L1 + +; Set up the stack. + + lda #<(__MAIN_START__ + __MAIN_SIZE__) + ldx #>(__MAIN_START__ + __MAIN_SIZE__) + sta c_sp + stx c_sp+1 ; Set argument stack ptr + +; Switch to the second charset. + +; FIXME + lda #14 + jsr BSOUT + +; Call the module constructors. + + jmp initlib + + +; ------------------------------------------------------------------------ +; Data + +.segment "INIT" + +mmusave:.res 1 +spsave: .res 1 +zpsave: .res zpspace diff --git a/libsrc/c65/kernal.s b/libsrc/c65/kernal.s new file mode 100644 index 000000000..ea07f9ce6 --- /dev/null +++ b/libsrc/c65/kernal.s @@ -0,0 +1,48 @@ +; +; Ullrich von Bassewitz, 19.11.2002 +; +; C65 Kernal functions +; + + .include "cbm_kernal.inc" + + .export CINT + .export IOINIT + .export RAMTAS + .export RESTOR + .export VECTOR + .export SETMSG + .export SECOND + .export TKSA + .export MEMTOP + .export MEMBOT + .export SCNKEY + .export ACPTR + .export CIOUT + .export UNTLK + .export UNLSN + .export LISTEN + .export TALK + .export READST + .export SETLFS + .export SETNAM + .export OPEN + .export CLOSE + .export CHKIN + .export CKOUT + .export CLRCH + .export BASIN + .export CHRIN + .export BSOUT + .export CHROUT + .export LOAD + .export SAVE + .export SETTIM + .export RDTIM + .export STOP + .export GETIN + .export CLALL + .export UDTIM + .export SCREEN + .export IOBASE + .export PLOT diff --git a/libsrc/mega65/crt0.s b/libsrc/mega65/crt0.s new file mode 100644 index 000000000..401095c55 --- /dev/null +++ b/libsrc/mega65/crt0.s @@ -0,0 +1,124 @@ +; +; Startup code for cc65 (MEGA65 version) +; + + .export _exit + .export __STARTUP__ : absolute = 1 ; Mark as startup + + .import initlib, donelib + .import zerobss, callmain + .import BSOUT + .import __MAIN_START__, __MAIN_SIZE__ ; Linker generated + .import __STACKSIZE__ ; from configure file + + .include "zeropage.inc" + .include "mega65.inc" + + +; ------------------------------------------------------------------------ +; Startup code + +.segment "STARTUP" + +Start: + +; Switch off the BASIC ROM. + +; FIXME +; lda $01 +; sta mmusave ; Save the memory configuration +; and #$F8 +; ora #$06 ; Enable Kernal+I/O, disable BASIC +; sta $01 +; sei +; lda #%00000000 ; lower offset 15-8 +; ldx #%00000000 ; map blk3-1 | lower offset 19-6 +; ldy #%00000000 ; upper offset 15-8 +; ldz #%00000000 ; map blk7-4 | upper offset 19-6 +; map +; eom + + tsx + stx spsave ; Save the system stack ptr + +; Save space by putting some of the start-up code in the ONCE segment, +; which can be re-used by the BSS segment, the heap and the C stack. + + jsr init + +; Clear the BSS data. + + jsr zerobss + +; Push the command-line arguments; and, call main(). + + jsr callmain + +; Back from main() [this is also the exit() entry]. Run the module destructors. + +_exit: pha ; Save the return code on stack + jsr donelib + +; Copy back the zero-page stuff. + + ldx #zpspace-1 +L2: lda zpsave,x + sta c_sp,x + dex + bpl L2 + +; Place the program return code into BASIC's status variable. + + pla + sta STATUS + +; Restore the system stuff. + + ldx spsave + txs ; Restore stack pointer + +; Back to BASIC. + + rts + + +; ------------------------------------------------------------------------ + +.segment "ONCE" + +init: + +; Save the zero-page locations that we need. + + ldx #zpspace-1 +L1: lda c_sp,x + sta zpsave,x + dex + bpl L1 + +; Set up the stack. + + lda #<(__MAIN_START__ + __MAIN_SIZE__) + ldx #>(__MAIN_START__ + __MAIN_SIZE__) + sta c_sp + stx c_sp+1 ; Set argument stack ptr + +; Switch to the second charset. + +; FIXME + lda #14 + jsr BSOUT + +; Call the module constructors. + + jmp initlib + + +; ------------------------------------------------------------------------ +; Data + +.segment "INIT" + +mmusave:.res 1 +spsave: .res 1 +zpsave: .res zpspace diff --git a/libsrc/mega65/kernal.s b/libsrc/mega65/kernal.s new file mode 100644 index 000000000..45f4c4d02 --- /dev/null +++ b/libsrc/mega65/kernal.s @@ -0,0 +1,48 @@ +; +; Ullrich von Bassewitz, 19.11.2002 +; +; MEGA65 Kernal functions +; + + .include "cbm_kernal.inc" + + .export CINT + .export IOINIT + .export RAMTAS + .export RESTOR + .export VECTOR + .export SETMSG + .export SECOND + .export TKSA + .export MEMTOP + .export MEMBOT + .export SCNKEY + .export ACPTR + .export CIOUT + .export UNTLK + .export UNLSN + .export LISTEN + .export TALK + .export READST + .export SETLFS + .export SETNAM + .export OPEN + .export CLOSE + .export CHKIN + .export CKOUT + .export CLRCH + .export BASIN + .export CHRIN + .export BSOUT + .export CHROUT + .export LOAD + .export SAVE + .export SETTIM + .export RDTIM + .export STOP + .export GETIN + .export CLALL + .export UDTIM + .export SCREEN + .export IOBASE + .export PLOT From d374ea2cde07f6dbfc3cfe09d4857e2fcc387c67 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Tue, 24 Jun 2025 21:30:53 +0200 Subject: [PATCH 07/27] include target header to allow lib to build --- libsrc/cbm/cpeekc.s | 4 ++++ libsrc/cbm/cpeekcolor.s | 4 ++++ libsrc/cbm/cpeekrevers.s | 4 ++++ libsrc/cbm/cpeeks.s | 4 ++++ 4 files changed, 16 insertions(+) diff --git a/libsrc/cbm/cpeekc.s b/libsrc/cbm/cpeekc.s index 05c7fc718..32dc0456e 100644 --- a/libsrc/cbm/cpeekc.s +++ b/libsrc/cbm/cpeekc.s @@ -22,6 +22,10 @@ .include "pet.inc" .elseif .def(__VIC20__) .include "vic20.inc" +.elseif .def(__C65__) + .include "c65.inc" +.elseif .def(__MEGA65__) + .include "mega65.inc" .endif diff --git a/libsrc/cbm/cpeekcolor.s b/libsrc/cbm/cpeekcolor.s index 9c961b771..a0d7efe6c 100644 --- a/libsrc/cbm/cpeekcolor.s +++ b/libsrc/cbm/cpeekcolor.s @@ -17,6 +17,10 @@ .include "c64.inc" .elseif .def(__VIC20__) .include "vic20.inc" +.elseif .def(__C65__) + .include "c65.inc" +.elseif .def(__MEGA65__) + .include "mega65.inc" .endif diff --git a/libsrc/cbm/cpeekrevers.s b/libsrc/cbm/cpeekrevers.s index e8e210167..0e500605d 100644 --- a/libsrc/cbm/cpeekrevers.s +++ b/libsrc/cbm/cpeekrevers.s @@ -22,6 +22,10 @@ .include "pet.inc" .elseif .def(__VIC20__) .include "vic20.inc" +.elseif .def(__C65__) + .include "c65.inc" +.elseif .def(__MEGA65__) + .include "mega65.inc" .endif diff --git a/libsrc/cbm/cpeeks.s b/libsrc/cbm/cpeeks.s index 215998e37..d73192d73 100644 --- a/libsrc/cbm/cpeeks.s +++ b/libsrc/cbm/cpeeks.s @@ -26,6 +26,10 @@ .include "pet.inc" .elseif .def(__VIC20__) .include "vic20.inc" +.elseif .def(__C65__) + .include "c65.inc" +.elseif .def(__MEGA65__) + .include "mega65.inc" .endif From d6cc8939404b1bbba68efd893dd140b6f9f2a623 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Tue, 24 Jun 2025 21:39:39 +0200 Subject: [PATCH 08/27] fix instruction set bits set by the compiler. in particular do not set the 65SC02 bit for 4510/45GS02, else we get clashes with sta(zp) --- src/common/cpu.c | 26 ++++++++++++++++---------- src/common/cpu.h | 4 ++-- 2 files changed, 18 insertions(+), 12 deletions(-) diff --git a/src/common/cpu.c b/src/common/cpu.c index 2c29eb1c4..54bb8a3fb 100644 --- a/src/common/cpu.c +++ b/src/common/cpu.c @@ -66,20 +66,26 @@ const char* CPUNames[CPU_COUNT] = { "45GS02" }; -/* Tables with CPU instruction sets */ +/* Tables with CPU instruction sets + * NOTE: make sure to only combine the instruction sets that are 100% compatible + */ const unsigned CPUIsets[CPU_COUNT] = { CPU_ISET_NONE, CPU_ISET_6502, - CPU_ISET_6502 | CPU_ISET_6502X, - CPU_ISET_6502 | CPU_ISET_6502DTV, - CPU_ISET_6502 | CPU_ISET_65SC02, - CPU_ISET_6502 | CPU_ISET_65SC02 | CPU_ISET_65C02, - CPU_ISET_6502 | CPU_ISET_65SC02 | CPU_ISET_65C02 | CPU_ISET_65816, + CPU_ISET_6502X | CPU_ISET_6502, + CPU_ISET_6502DTV | CPU_ISET_6502, + CPU_ISET_65SC02 | CPU_ISET_6502, + CPU_ISET_65C02 | CPU_ISET_6502 | CPU_ISET_65SC02, + /* FIXME: does 65816 have both wai/stp and indirect-zp (without z)? */ + CPU_ISET_65816 | CPU_ISET_6502 | CPU_ISET_65SC02 | CPU_ISET_65C02, CPU_ISET_SWEET16, - CPU_ISET_6502 | CPU_ISET_65SC02 | CPU_ISET_65C02 | CPU_ISET_HUC6280, - CPU_ISET_6502 | CPU_ISET_M740, - CPU_ISET_6502 | CPU_ISET_65SC02 | CPU_ISET_65C02 | CPU_ISET_4510, - CPU_ISET_6502 | CPU_ISET_65SC02 | CPU_ISET_65C02 | CPU_ISET_4510 | CPU_ISET_45GS02, + /* FIXME: HUC6280 does not have wai/stp */ + CPU_ISET_HUC6280 | CPU_ISET_6502 | CPU_ISET_65SC02 | CPU_ISET_65C02, + CPU_ISET_M740 | CPU_ISET_6502, + /* 4510 does NOT have indirect-zp (without z), so we can not use 65SC02 */ + /* FIXME: 4510 does not have wai/stp */ + CPU_ISET_4510 | CPU_ISET_6502 | CPU_ISET_65C02, + CPU_ISET_45GS02 | CPU_ISET_6502 | CPU_ISET_65C02 | CPU_ISET_4510, }; diff --git a/src/common/cpu.h b/src/common/cpu.h index 6d8b72469..81795e146 100644 --- a/src/common/cpu.h +++ b/src/common/cpu.h @@ -47,7 +47,7 @@ /* CPUs */ typedef enum { CPU_UNKNOWN = -1, /* Not specified or invalid target */ - CPU_NONE, /* No CPU - for assembler */ + CPU_NONE = 0, /* No CPU - for assembler */ CPU_6502, CPU_6502X, /* "Extended", that is: with illegal opcodes */ CPU_6502DTV, /* CPU_6502 + DTV extra and illegal opcodes */ @@ -62,7 +62,7 @@ typedef enum { CPU_COUNT /* Number of different CPUs */ } cpu_t; -/* CPU instruction sets */ +/* CPU instruction sets (make sure this matches asminc/cpu.mac) */ enum { CPU_ISET_NONE = 1 << CPU_NONE, CPU_ISET_6502 = 1 << CPU_6502, From faa287f57888540bd7c50caf693acd787dbed085 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Tue, 24 Jun 2025 21:40:59 +0200 Subject: [PATCH 09/27] enable building library and samples --- libsrc/Makefile | 13 +++---------- samples/Makefile | 8 ++++++++ 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/libsrc/Makefile b/libsrc/Makefile index 9bbb0aadb..9e1592dd3 100644 --- a/libsrc/Makefile +++ b/libsrc/Makefile @@ -11,9 +11,11 @@ endif CBMS = c128 \ c16 \ c64 \ + c65 \ cbm510 \ cbm610 \ cx16 \ + mega65 \ pet \ plus4 \ vic20 @@ -21,7 +23,6 @@ CBMS = c128 \ GEOS = geos-apple \ geos-cbm -# FIXME: c65 (and perhaps mega65?) should be moved up to CBMS maybe TARGETS = agat \ apple2 \ apple2enh \ @@ -31,7 +32,6 @@ TARGETS = agat \ atari5200 \ atari7800 \ atmos \ - c65 \ creativision \ $(CBMS) \ $(GEOS) \ @@ -47,8 +47,7 @@ TARGETS = agat \ sim65c02 \ supervision \ sym1 \ - telestrat \ - mega65 + telestrat TARGETTEST = none \ sim6502 \ @@ -196,11 +195,6 @@ ifeq ($(TARGET),$(filter $(TARGET),$(GEOS))) SRCDIRS += $(addprefix geos-common/,$(GEOSDIRS)) endif -ifeq ($(TARGET),c65) -# FIXME: this does not work because of the SP vs C_SP clash -else ifeq ($(TARGET),mega65) -# FIXME: this does not work because of the SP vs C_SP clash -else SRCDIRS += common \ conio \ dbg \ @@ -211,7 +205,6 @@ SRCDIRS += common \ serial \ tgi \ zlib -endif vpath %.s $(SRCDIRS) vpath %.c $(SRCDIRS) diff --git a/samples/Makefile b/samples/Makefile index 0a56af3c1..8974ce1b6 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -240,6 +240,9 @@ EXELIST_c64 = \ tinyshell \ tgidemo +EXELIST_c65 = \ + checkversion + EXELIST_c128 = \ ascii \ checkversion \ @@ -312,6 +315,9 @@ EXELIST_lunix = \ EXELIST_lynx = \ notavailable +EXELIST_mega65 = \ + checkversion + EXELIST_nes = \ hello @@ -418,6 +424,7 @@ TARGETS := \ c128 \ c16 \ c64 \ + c65 \ cbm510 \ cbm610 \ creativision \ @@ -426,6 +433,7 @@ TARGETS := \ kim1 \ lunix \ lynx \ + mega65 \ nes \ osic1p \ pce \ From f787e0857aa9396cece5b534d6971e7aeba0bb89 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Tue, 24 Jun 2025 21:52:48 +0200 Subject: [PATCH 10/27] remove non existing kernal export --- asminc/cpu.mac | 21 ++++++++++----------- libsrc/c65/kernal.s | 1 - libsrc/mega65/kernal.s | 1 - 3 files changed, 10 insertions(+), 13 deletions(-) diff --git a/asminc/cpu.mac b/asminc/cpu.mac index be35265b7..c66641078 100644 --- a/asminc/cpu.mac +++ b/asminc/cpu.mac @@ -4,31 +4,30 @@ CPU_ISET_NONE = $0001 CPU_ISET_6502 = $0002 CPU_ISET_6502X = $0004 CPU_ISET_6502DTV = $0008 - CPU_ISET_65SC02 = $0010 CPU_ISET_65C02 = $0020 CPU_ISET_65816 = $0040 CPU_ISET_SWEET16 = $0080 - CPU_ISET_HUC6280 = $0100 CPU_ISET_M740 = $0200 CPU_ISET_4510 = $0400 CPU_ISET_45GS02 = $0800 ; CPU capabilities +; make sure to only combine the instruction sets that are 100% compatible CPU_NONE = CPU_ISET_NONE CPU_6502 = CPU_ISET_6502 -CPU_6502X = CPU_ISET_6502|CPU_ISET_6502X -CPU_6502DTV = CPU_ISET_6502|CPU_ISET_6502DTV -CPU_65SC02 = CPU_ISET_6502|CPU_ISET_65SC02 -CPU_65C02 = CPU_ISET_6502|CPU_ISET_65SC02|CPU_ISET_65C02 -CPU_65816 = CPU_ISET_6502|CPU_ISET_65SC02|CPU_ISET_65816 +CPU_6502X = CPU_ISET_6502X | CPU_ISET_6502 +CPU_6502DTV = CPU_ISET_6502DTV | CPU_ISET_6502 +CPU_65SC02 = CPU_ISET_65SC02 | CPU_ISET_6502 +CPU_65C02 = CPU_ISET_65C02 | CPU_ISET_6502 | CPU_ISET_65SC02 +CPU_65816 = CPU_ISET_65816 | CPU_ISET_6502 | CPU_ISET_65SC02 CPU_SWEET16 = CPU_ISET_SWEET16 ; FIXME: CPU_ISET_65SC02 does not apply to the following, because the zp-indirect ; addressing was replaced with zp-indirect,z-indexed in 652SCE02 ; NOTE: HUC6280 removes "wai" ($cb) and "stp" ($db) from the 65C02 instruction set -CPU_HUC6280 = CPU_ISET_6502|CPU_ISET_65C02|CPU_ISET_HUC6280 +CPU_HUC6280 = CPU_ISET_HUC6280 | CPU_ISET_6502 | CPU_ISET_65C02 ; NOTE: 4510 replaces "wai" ($cb) and "stp" ($db) of the 65C02 instruction set -CPU_4510 = CPU_ISET_6502|CPU_ISET_65C02|CPU_ISET_4510 -CPU_45GS02 = CPU_ISET_6502|CPU_ISET_65C02|CPU_ISET_4510|CPU_ISET_45GS02 -CPU_M740 = CPU_ISET_6502|CPU_ISET_M740 +CPU_4510 = CPU_ISET_4510 | CPU_ISET_6502 | CPU_ISET_65C02 +CPU_45GS02 = CPU_ISET_45GS02 | CPU_ISET_6502 | CPU_ISET_65C02 | CPU_ISET_4510 +CPU_M740 = CPU_ISET_M740 | CPU_ISET_6502 diff --git a/libsrc/c65/kernal.s b/libsrc/c65/kernal.s index ea07f9ce6..fac8be514 100644 --- a/libsrc/c65/kernal.s +++ b/libsrc/c65/kernal.s @@ -42,7 +42,6 @@ .export STOP .export GETIN .export CLALL - .export UDTIM .export SCREEN .export IOBASE .export PLOT diff --git a/libsrc/mega65/kernal.s b/libsrc/mega65/kernal.s index 45f4c4d02..198e8fbb4 100644 --- a/libsrc/mega65/kernal.s +++ b/libsrc/mega65/kernal.s @@ -42,7 +42,6 @@ .export STOP .export GETIN .export CLALL - .export UDTIM .export SCREEN .export IOBASE .export PLOT From 4d1fbe3f908ae12f7c6718eb995ffef7ea3f3f36 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Tue, 24 Jun 2025 21:59:35 +0200 Subject: [PATCH 11/27] fix refs (remove 652SC02) --- test/asm/cpudetect/4510-cpudetect.ref | Bin 60 -> 44 bytes test/asm/cpudetect/45GS02-cpudetect.ref | Bin 80 -> 64 bytes 2 files changed, 0 insertions(+), 0 deletions(-) diff --git a/test/asm/cpudetect/4510-cpudetect.ref b/test/asm/cpudetect/4510-cpudetect.ref index 515557c854d36f3bc8310b6c2a9cc0b2b0a98ade..484469a79bf38aa6e631fc1f0bc96cdb0ccf61bc 100644 GIT binary patch delta 7 OcmcD~nIJt;TMz&U2?5~% delta 10 RcmdO~nIO#+>^zZI9smu#0%-sM diff --git a/test/asm/cpudetect/45GS02-cpudetect.ref b/test/asm/cpudetect/45GS02-cpudetect.ref index e9aa843cda2fb487e49b4380205f4b31d1ffb805..b6e8e797fe3a85e410b0b3ceee7db2a06acebc2c 100644 GIT binary patch delta 7 OcmWG=m>@q|y->^xCW9{>+-0;vE1 From fa6d72cae5de6e275813b0ba6d227b2280148bb5 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 25 Jun 2025 00:14:19 +0200 Subject: [PATCH 12/27] move zp range to a somewhat safer place --- cfg/c65.cfg | 2 +- cfg/mega65.cfg | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/cfg/c65.cfg b/cfg/c65.cfg index 914f84f3c..2d78d26d2 100644 --- a/cfg/c65.cfg +++ b/cfg/c65.cfg @@ -8,7 +8,7 @@ SYMBOLS { __HIMEM__: type = weak, value = $8000; } MEMORY { - ZP: file = "", define = yes, start = $0002, size = $001A; + ZP: file = "", define = yes, start = $0018, size = $001A; LOADADDR: file = %O, start = %S - 2, size = $0002; HEADER: file = %O, define = yes, start = %S, size = $0010; MAIN: file = %O, define = yes, start = __HEADER_LAST__, size = __HIMEM__ - __HEADER_LAST__; diff --git a/cfg/mega65.cfg b/cfg/mega65.cfg index 914f84f3c..2d78d26d2 100644 --- a/cfg/mega65.cfg +++ b/cfg/mega65.cfg @@ -8,7 +8,7 @@ SYMBOLS { __HIMEM__: type = weak, value = $8000; } MEMORY { - ZP: file = "", define = yes, start = $0002, size = $001A; + ZP: file = "", define = yes, start = $0018, size = $001A; LOADADDR: file = %O, start = %S - 2, size = $0002; HEADER: file = %O, define = yes, start = %S, size = $0010; MAIN: file = %O, define = yes, start = __HEADER_LAST__, size = __HIMEM__ - __HEADER_LAST__; From 23336420b16dc32a68dd4a97515a6493fb2e0178 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 25 Jun 2025 00:23:58 +0200 Subject: [PATCH 13/27] a bunch of simple conio fixes, makes a few more samples work --- asminc/c65.inc | 4 ++ asminc/mega65.inc | 4 ++ libsrc/c65/_scrsize.s | 12 ++++ libsrc/c65/bordercolor.s | 17 ++++++ libsrc/c65/clrscr.s | 15 +++++ libsrc/c65/color.s | 24 ++++++++ libsrc/c65/conio.s | 10 +++ libsrc/c65/cputc.s | 118 ++++++++++++++++++++++++++++++++++++ libsrc/c65/devnum.s | 7 +++ libsrc/c65/kbhit.s | 24 ++++++++ libsrc/c65/status.s | 5 ++ libsrc/mega65/_scrsize.s | 12 ++++ libsrc/mega65/bordercolor.s | 17 ++++++ libsrc/mega65/clrscr.s | 15 +++++ libsrc/mega65/color.s | 24 ++++++++ libsrc/mega65/conio.s | 10 +++ libsrc/mega65/cputc.s | 118 ++++++++++++++++++++++++++++++++++++ libsrc/mega65/devnum.s | 7 +++ libsrc/mega65/kbhit.s | 24 ++++++++ libsrc/mega65/status.s | 5 ++ samples/Makefile | 14 ++++- 21 files changed, 484 insertions(+), 2 deletions(-) create mode 100644 libsrc/c65/_scrsize.s create mode 100644 libsrc/c65/bordercolor.s create mode 100644 libsrc/c65/clrscr.s create mode 100644 libsrc/c65/color.s create mode 100644 libsrc/c65/conio.s create mode 100644 libsrc/c65/cputc.s create mode 100644 libsrc/c65/devnum.s create mode 100644 libsrc/c65/kbhit.s create mode 100644 libsrc/c65/status.s create mode 100644 libsrc/mega65/_scrsize.s create mode 100644 libsrc/mega65/bordercolor.s create mode 100644 libsrc/mega65/clrscr.s create mode 100644 libsrc/mega65/color.s create mode 100644 libsrc/mega65/conio.s create mode 100644 libsrc/mega65/cputc.s create mode 100644 libsrc/mega65/devnum.s create mode 100644 libsrc/mega65/kbhit.s create mode 100644 libsrc/mega65/status.s diff --git a/asminc/c65.inc b/asminc/c65.inc index 4c10431ab..79a4e7b03 100644 --- a/asminc/c65.inc +++ b/asminc/c65.inc @@ -233,3 +233,7 @@ CASSMOT = $20 ; Cassette motor on TP_FAST = $80 ; Switch Rossmoeller TurboProcess to fast mode RAMONLY = $F8 ; (~(LORAM | HIRAM | IOEN)) & $FF + +; temporary, to get conio working +XSIZE = 80 +YSIZE = 50 diff --git a/asminc/mega65.inc b/asminc/mega65.inc index 4c10431ab..79a4e7b03 100644 --- a/asminc/mega65.inc +++ b/asminc/mega65.inc @@ -233,3 +233,7 @@ CASSMOT = $20 ; Cassette motor on TP_FAST = $80 ; Switch Rossmoeller TurboProcess to fast mode RAMONLY = $F8 ; (~(LORAM | HIRAM | IOEN)) & $FF + +; temporary, to get conio working +XSIZE = 80 +YSIZE = 50 diff --git a/libsrc/c65/_scrsize.s b/libsrc/c65/_scrsize.s new file mode 100644 index 000000000..57ad4f30f --- /dev/null +++ b/libsrc/c65/_scrsize.s @@ -0,0 +1,12 @@ +; +; Ullrich von Bassewitz, 26.10.2000 +; +; Screen size variables +; + + .export screensize + .import SCREEN + +screensize = SCREEN + + diff --git a/libsrc/c65/bordercolor.s b/libsrc/c65/bordercolor.s new file mode 100644 index 000000000..6b3c7f86c --- /dev/null +++ b/libsrc/c65/bordercolor.s @@ -0,0 +1,17 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; unsigned char __fastcall__ bordercolor (unsigned char color); +; + + + .export _bordercolor + + .include "c65.inc" + +_bordercolor: + ldx VIC_BORDERCOLOR ; get old value + sta VIC_BORDERCOLOR ; set new value + txa + rts + diff --git a/libsrc/c65/clrscr.s b/libsrc/c65/clrscr.s new file mode 100644 index 000000000..84fef5eac --- /dev/null +++ b/libsrc/c65/clrscr.s @@ -0,0 +1,15 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; void clrscr (void); +; + + .export _clrscr + + .include "cbm_kernal.inc" + +;_clrscr = CLRSCR + +_clrscr: + lda #$93 + jmp CHROUT diff --git a/libsrc/c65/color.s b/libsrc/c65/color.s new file mode 100644 index 000000000..b80ba2367 --- /dev/null +++ b/libsrc/c65/color.s @@ -0,0 +1,24 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; unsigned char __fastcall__ textcolor (unsigned char color); +; unsigned char __fastcall__ bgcolor (unsigned char color); +; + + + .export _textcolor, _bgcolor + + .include "c65.inc" + +_textcolor: + ldx CHARCOLOR ; get old value + sta CHARCOLOR ; set new value + txa + rts + + +_bgcolor: + ldx VIC_BG_COLOR0 ; get old value + sta VIC_BG_COLOR0 ; set new value + txa + rts diff --git a/libsrc/c65/conio.s b/libsrc/c65/conio.s new file mode 100644 index 000000000..6c90a6d2e --- /dev/null +++ b/libsrc/c65/conio.s @@ -0,0 +1,10 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; Low level stuff for screen output/console input +; + + .exportzp CURS_X, CURS_Y + + .include "c65.inc" + diff --git a/libsrc/c65/cputc.s b/libsrc/c65/cputc.s new file mode 100644 index 000000000..a34262437 --- /dev/null +++ b/libsrc/c65/cputc.s @@ -0,0 +1,118 @@ +; +; Ullrich von Bassewitz, 1998-08-06, 2009-09-26 +; +; void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c); +; void __fastcall__ cputc (char c); +; + + .export _cputcxy, _cputc, cputdirect, putchar + .export newline, plot + .import gotoxy + .import PLOT + + .include "c65.inc" + + +_cputcxy: + pha ; Save C + jsr gotoxy ; Set cursor, drop x and y + pla ; Restore C + +; Plot a character - also used as internal function + +_cputc: cmp #$0A ; CR? + bne L1 + lda #0 + sta CURS_X + beq plot ; Recalculate pointers + +L1: cmp #$0D ; LF? + beq newline ; Recalculate pointers + +; Printable char of some sort + + cmp #' ' + bcc cputdirect ; Other control char + tay + bmi L10 + cmp #$60 + bcc L2 + and #$DF + bne cputdirect ; Branch always +L2: and #$3F + +cputdirect: + jsr putchar ; Write the character to the screen + +; Advance cursor position + +advance: + iny + cpy #XSIZE + bne L3 + jsr newline ; new line + ldy #0 ; + cr +L3: sty CURS_X + rts + +newline: + clc + lda #XSIZE + adc SCREEN_PTR + sta SCREEN_PTR + bcc L4 + inc SCREEN_PTR+1 + clc +L4: lda #XSIZE + adc CRAM_PTR + sta CRAM_PTR + bcc L5 + inc CRAM_PTR+1 +L5: inc CURS_Y + rts + +; Handle character if high bit set + +L10: and #$7F + cmp #$7F ; PI? + bne L11 + lda #$5E ; Load screen code for PI +L11: ora #$40 + bne cputdirect + + + +; Set cursor position, calculate RAM pointers. + +plot: ldy CURS_X + ldx CURS_Y + clc + jmp PLOT ; Set the new cursor + + + +; Write one character to the screen without doing anything else, return X +; position in Y + +putchar: + ora RVS ; Set revers bit + ldy CURS_X + + pha + lda SCREEN_PTR + 1 + clc + adc #>$0800 + sta SCREEN_PTR + 1 + pla + + sta (SCREEN_PTR),y ; Set char + + lda SCREEN_PTR + 1 + sec + sbc #>$0800 + sta SCREEN_PTR + 1 + + lda CHARCOLOR +; lda #$88 +; sta (CRAM_PTR),y ; Set color + rts diff --git a/libsrc/c65/devnum.s b/libsrc/c65/devnum.s new file mode 100644 index 000000000..412b63fd7 --- /dev/null +++ b/libsrc/c65/devnum.s @@ -0,0 +1,7 @@ +; +; Oliver Schmidt, 2010-02-14 +; + + .include "c65.inc" + + .exportzp devnum := DEVNUM diff --git a/libsrc/c65/kbhit.s b/libsrc/c65/kbhit.s new file mode 100644 index 000000000..63b34629b --- /dev/null +++ b/libsrc/c65/kbhit.s @@ -0,0 +1,24 @@ + + + ; FIXME: is $d610 mega65 specific? + ; FIXME: this should rather use the kernal (with keyboard buffer etc) + + .export _cgetc +_cgetc: + +: lda $d610 + beq :- + ldx #0 + stx $d610 + rts + + .export _kbhit +_kbhit: + lda $d610 + beq :+ + + lda #1 +: + ldx #0 + rts + diff --git a/libsrc/c65/status.s b/libsrc/c65/status.s new file mode 100644 index 000000000..c6f279230 --- /dev/null +++ b/libsrc/c65/status.s @@ -0,0 +1,5 @@ +; +; Oliver Schmidt, 2012-09-30 +; + + .exportzp ST := $90 ; IEC status byte diff --git a/libsrc/mega65/_scrsize.s b/libsrc/mega65/_scrsize.s new file mode 100644 index 000000000..57ad4f30f --- /dev/null +++ b/libsrc/mega65/_scrsize.s @@ -0,0 +1,12 @@ +; +; Ullrich von Bassewitz, 26.10.2000 +; +; Screen size variables +; + + .export screensize + .import SCREEN + +screensize = SCREEN + + diff --git a/libsrc/mega65/bordercolor.s b/libsrc/mega65/bordercolor.s new file mode 100644 index 000000000..2ebf83766 --- /dev/null +++ b/libsrc/mega65/bordercolor.s @@ -0,0 +1,17 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; unsigned char __fastcall__ bordercolor (unsigned char color); +; + + + .export _bordercolor + + .include "mega65.inc" + +_bordercolor: + ldx VIC_BORDERCOLOR ; get old value + sta VIC_BORDERCOLOR ; set new value + txa + rts + diff --git a/libsrc/mega65/clrscr.s b/libsrc/mega65/clrscr.s new file mode 100644 index 000000000..84fef5eac --- /dev/null +++ b/libsrc/mega65/clrscr.s @@ -0,0 +1,15 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; void clrscr (void); +; + + .export _clrscr + + .include "cbm_kernal.inc" + +;_clrscr = CLRSCR + +_clrscr: + lda #$93 + jmp CHROUT diff --git a/libsrc/mega65/color.s b/libsrc/mega65/color.s new file mode 100644 index 000000000..094bf9ed8 --- /dev/null +++ b/libsrc/mega65/color.s @@ -0,0 +1,24 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; unsigned char __fastcall__ textcolor (unsigned char color); +; unsigned char __fastcall__ bgcolor (unsigned char color); +; + + + .export _textcolor, _bgcolor + + .include "mega65.inc" + +_textcolor: + ldx CHARCOLOR ; get old value + sta CHARCOLOR ; set new value + txa + rts + + +_bgcolor: + ldx VIC_BG_COLOR0 ; get old value + sta VIC_BG_COLOR0 ; set new value + txa + rts diff --git a/libsrc/mega65/conio.s b/libsrc/mega65/conio.s new file mode 100644 index 000000000..14052c5a1 --- /dev/null +++ b/libsrc/mega65/conio.s @@ -0,0 +1,10 @@ +; +; Ullrich von Bassewitz, 06.08.1998 +; +; Low level stuff for screen output/console input +; + + .exportzp CURS_X, CURS_Y + + .include "mega65.inc" + diff --git a/libsrc/mega65/cputc.s b/libsrc/mega65/cputc.s new file mode 100644 index 000000000..ad93ba7e5 --- /dev/null +++ b/libsrc/mega65/cputc.s @@ -0,0 +1,118 @@ +; +; Ullrich von Bassewitz, 1998-08-06, 2009-09-26 +; +; void __fastcall__ cputcxy (unsigned char x, unsigned char y, char c); +; void __fastcall__ cputc (char c); +; + + .export _cputcxy, _cputc, cputdirect, putchar + .export newline, plot + .import gotoxy + .import PLOT + + .include "mega65.inc" + + +_cputcxy: + pha ; Save C + jsr gotoxy ; Set cursor, drop x and y + pla ; Restore C + +; Plot a character - also used as internal function + +_cputc: cmp #$0A ; CR? + bne L1 + lda #0 + sta CURS_X + beq plot ; Recalculate pointers + +L1: cmp #$0D ; LF? + beq newline ; Recalculate pointers + +; Printable char of some sort + + cmp #' ' + bcc cputdirect ; Other control char + tay + bmi L10 + cmp #$60 + bcc L2 + and #$DF + bne cputdirect ; Branch always +L2: and #$3F + +cputdirect: + jsr putchar ; Write the character to the screen + +; Advance cursor position + +advance: + iny + cpy #XSIZE + bne L3 + jsr newline ; new line + ldy #0 ; + cr +L3: sty CURS_X + rts + +newline: + clc + lda #XSIZE + adc SCREEN_PTR + sta SCREEN_PTR + bcc L4 + inc SCREEN_PTR+1 + clc +L4: lda #XSIZE + adc CRAM_PTR + sta CRAM_PTR + bcc L5 + inc CRAM_PTR+1 +L5: inc CURS_Y + rts + +; Handle character if high bit set + +L10: and #$7F + cmp #$7F ; PI? + bne L11 + lda #$5E ; Load screen code for PI +L11: ora #$40 + bne cputdirect + + + +; Set cursor position, calculate RAM pointers. + +plot: ldy CURS_X + ldx CURS_Y + clc + jmp PLOT ; Set the new cursor + + + +; Write one character to the screen without doing anything else, return X +; position in Y + +putchar: + ora RVS ; Set revers bit + ldy CURS_X + + pha + lda SCREEN_PTR + 1 + clc + adc #>$0800 + sta SCREEN_PTR + 1 + pla + + sta (SCREEN_PTR),y ; Set char + + lda SCREEN_PTR + 1 + sec + sbc #>$0800 + sta SCREEN_PTR + 1 + + lda CHARCOLOR +; lda #$88 +; sta (CRAM_PTR),y ; Set color + rts diff --git a/libsrc/mega65/devnum.s b/libsrc/mega65/devnum.s new file mode 100644 index 000000000..898989766 --- /dev/null +++ b/libsrc/mega65/devnum.s @@ -0,0 +1,7 @@ +; +; Oliver Schmidt, 2010-02-14 +; + + .include "mega65.inc" + + .exportzp devnum := DEVNUM diff --git a/libsrc/mega65/kbhit.s b/libsrc/mega65/kbhit.s new file mode 100644 index 000000000..63b34629b --- /dev/null +++ b/libsrc/mega65/kbhit.s @@ -0,0 +1,24 @@ + + + ; FIXME: is $d610 mega65 specific? + ; FIXME: this should rather use the kernal (with keyboard buffer etc) + + .export _cgetc +_cgetc: + +: lda $d610 + beq :- + ldx #0 + stx $d610 + rts + + .export _kbhit +_kbhit: + lda $d610 + beq :+ + + lda #1 +: + ldx #0 + rts + diff --git a/libsrc/mega65/status.s b/libsrc/mega65/status.s new file mode 100644 index 000000000..c6f279230 --- /dev/null +++ b/libsrc/mega65/status.s @@ -0,0 +1,5 @@ +; +; Oliver Schmidt, 2012-09-30 +; + + .exportzp ST := $90 ; IEC status byte diff --git a/samples/Makefile b/samples/Makefile index 8974ce1b6..7d506e135 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -241,7 +241,12 @@ EXELIST_c64 = \ tgidemo EXELIST_c65 = \ - checkversion + ascii \ + checkversion \ + enumdevdir \ + hello \ + sieve \ + tinyshell EXELIST_c128 = \ ascii \ @@ -316,7 +321,12 @@ EXELIST_lynx = \ notavailable EXELIST_mega65 = \ - checkversion + ascii \ + checkversion \ + enumdevdir \ + hello \ + sieve \ + tinyshell EXELIST_nes = \ hello From 79b2d25840656d5b2beb36f18e56b79eaf2fff0f Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 25 Jun 2025 02:32:46 +0200 Subject: [PATCH 14/27] name the SIDs 1 and 2 just like the CIAs --- asminc/c65.inc | 120 ++++++++++++++++++++++++------------------------- 1 file changed, 60 insertions(+), 60 deletions(-) diff --git a/asminc/c65.inc b/asminc/c65.inc index 79a4e7b03..ff3572f1f 100644 --- a/asminc/c65.inc +++ b/asminc/c65.inc @@ -112,73 +112,73 @@ FDC := $D080 ; --------------------------------------------------------------------------- ; I/O: SID -SID0 := $D400 -SID0_S1Lo := $D400 -SID0_S1Hi := $D401 -SID0_PB1Lo := $D402 -SID0_PB1Hi := $D403 -SID0_Ctl1 := $D404 -SID0_AD1 := $D405 -SID0_SUR1 := $D406 +SID1 := $D400 +SID1_S1Lo := $D400 +SID1_S1Hi := $D401 +SID1_PB1Lo := $D402 +SID1_PB1Hi := $D403 +SID1_Ctl1 := $D404 +SID1_AD1 := $D405 +SID1_SUR1 := $D406 -SID0_S2Lo := $D407 -SID0_S2Hi := $D408 -SID0_PB2Lo := $D409 -SID0_PB2Hi := $D40A -SID0_Ctl2 := $D40B -SID0_AD2 := $D40C -SID0_SUR2 := $D40D +SID1_S2Lo := $D407 +SID1_S2Hi := $D408 +SID1_PB2Lo := $D409 +SID1_PB2Hi := $D40A +SID1_Ctl2 := $D40B +SID1_AD2 := $D40C +SID1_SUR2 := $D40D -SID0_S3Lo := $D40E -SID0_S3Hi := $D40F -SID0_PB3Lo := $D410 -SID0_PB3Hi := $D411 -SID0_Ctl3 := $D412 -SID0_AD3 := $D413 -SID0_SUR3 := $D414 +SID1_S3Lo := $D40E +SID1_S3Hi := $D40F +SID1_PB3Lo := $D410 +SID1_PB3Hi := $D411 +SID1_Ctl3 := $D412 +SID1_AD3 := $D413 +SID1_SUR3 := $D414 -SID0_FltLo := $D415 -SID0_FltHi := $D416 -SID0_FltCtl := $D417 -SID0_Amp := $D418 -SID0_ADConv1 := $D419 -SID0_ADConv2 := $D41A -SID0_Noise := $D41B -SID0_Read3 := $D41C +SID1_FltLo := $D415 +SID1_FltHi := $D416 +SID1_FltCtl := $D417 +SID1_Amp := $D418 +SID1_ADConv1 := $D419 +SID1_ADConv2 := $D41A +SID1_Noise := $D41B +SID1_Read3 := $D41C -SID1 := $D420 -SID1_S1Lo := $D420 -SID1_S1Hi := $D421 -SID1_PB1Lo := $D422 -SID1_PB1Hi := $D423 -SID1_Ctl1 := $D424 -SID1_AD1 := $D425 -SID1_SUR1 := $D426 +SID2 := $D420 +SID2_S1Lo := $D420 +SID2_S1Hi := $D421 +SID2_PB1Lo := $D422 +SID2_PB1Hi := $D423 +SID2_Ctl1 := $D424 +SID2_AD1 := $D425 +SID2_SUR1 := $D426 -SID1_S2Lo := $D427 -SID1_S2Hi := $D428 -SID1_PB2Lo := $D429 -SID1_PB2Hi := $D42A -SID1_Ctl2 := $D42B -SID1_AD2 := $D42C -SID1_SUR2 := $D42D +SID2_S2Lo := $D427 +SID2_S2Hi := $D428 +SID2_PB2Lo := $D429 +SID2_PB2Hi := $D42A +SID2_Ctl2 := $D42B +SID2_AD2 := $D42C +SID2_SUR2 := $D42D -SID1_S3Lo := $D42E -SID1_S3Hi := $D42F -SID1_PB3Lo := $D430 -SID1_PB3Hi := $D431 -SID1_Ctl3 := $D432 -SID1_AD3 := $D433 -SID1_SUR3 := $D434 +SID2_S3Lo := $D42E +SID2_S3Hi := $D42F +SID2_PB3Lo := $D430 +SID2_PB3Hi := $D431 +SID2_Ctl3 := $D432 +SID2_AD3 := $D433 +SID2_SUR3 := $D434 -SID1_FltLo := $D435 -SID1_FltHi := $D436 -SID1_FltCtl := $D437 -SID1_Amp := $D438 -SID1_ADConv1 := $D439 -SID1_ADConv2 := $D43A -SID1_Noise := $D43B -SID1_Read3 := $D43C +SID2_FltLo := $D435 +SID2_FltHi := $D436 +SID2_FltCtl := $D437 +SID2_Amp := $D438 +SID2_ADConv1 := $D439 +SID2_ADConv2 := $D43A +SID2_Noise := $D43B +SID2_Read3 := $D43C ; --------------------------------------------------------------------------- ; I/O: Complex Interface Adapters From db494325615910fb9f5136e02bed8ff5091cdec8 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 25 Jun 2025 02:38:40 +0200 Subject: [PATCH 15/27] some more simple fixes, make targettest(s) work --- libsrc/c65/crt0.s | 1 - libsrc/c65/get_tv.s | 25 +++++++ libsrc/c65/gettime.s | 83 +++++++++++++++++++++++ libsrc/c65/mainargs.s | 137 ++++++++++++++++++++++++++++++++++++++ libsrc/c65/randomize.s | 18 +++++ libsrc/c65/revers.s | 27 ++++++++ libsrc/c65/settime.s | 84 +++++++++++++++++++++++ libsrc/c65/sysuname.s | 37 ++++++++++ libsrc/c65/tmcommon.s | 64 ++++++++++++++++++ libsrc/mega65/crt0.s | 1 - libsrc/mega65/get_tv.s | 25 +++++++ libsrc/mega65/gettime.s | 83 +++++++++++++++++++++++ libsrc/mega65/mainargs.s | 137 ++++++++++++++++++++++++++++++++++++++ libsrc/mega65/randomize.s | 18 +++++ libsrc/mega65/revers.s | 27 ++++++++ libsrc/mega65/sysuname.s | 37 ++++++++++ libsrc/mega65/tmcommon.s | 64 ++++++++++++++++++ targettest/Makefile | 60 +++++++++++++++++ targettest/cpeek-test.c | 4 ++ 19 files changed, 930 insertions(+), 2 deletions(-) create mode 100644 libsrc/c65/get_tv.s create mode 100644 libsrc/c65/gettime.s create mode 100644 libsrc/c65/mainargs.s create mode 100644 libsrc/c65/randomize.s create mode 100644 libsrc/c65/revers.s create mode 100644 libsrc/c65/settime.s create mode 100644 libsrc/c65/sysuname.s create mode 100644 libsrc/c65/tmcommon.s create mode 100644 libsrc/mega65/get_tv.s create mode 100644 libsrc/mega65/gettime.s create mode 100644 libsrc/mega65/mainargs.s create mode 100644 libsrc/mega65/randomize.s create mode 100644 libsrc/mega65/revers.s create mode 100644 libsrc/mega65/sysuname.s create mode 100644 libsrc/mega65/tmcommon.s diff --git a/libsrc/c65/crt0.s b/libsrc/c65/crt0.s index 855b4ccf6..380d04e2e 100644 --- a/libsrc/c65/crt0.s +++ b/libsrc/c65/crt0.s @@ -105,7 +105,6 @@ L1: lda c_sp,x ; Switch to the second charset. -; FIXME lda #14 jsr BSOUT diff --git a/libsrc/c65/get_tv.s b/libsrc/c65/get_tv.s new file mode 100644 index 000000000..2093e45fd --- /dev/null +++ b/libsrc/c65/get_tv.s @@ -0,0 +1,25 @@ +; +; Ullrich von Bassewitz, 2002-12-03 +; +; unsigned char get_tv (void); +; /* Return the video mode the machine is using */ +; + + .include "get_tv.inc" + .include "c65.inc" + + +;-------------------------------------------------------------------------- +; _get_tv + +.proc _get_tv + + ldx #TV::PAL ; Assume PAL + lda PALFLAG + bne pal + dex ; NTSC +pal: txa + ldx #0 + rts + +.endproc diff --git a/libsrc/c65/gettime.s b/libsrc/c65/gettime.s new file mode 100644 index 000000000..c4b200a5d --- /dev/null +++ b/libsrc/c65/gettime.s @@ -0,0 +1,83 @@ +; +; Stefan Haubenthal, 27.7.2009 +; Oliver Schmidt, 14.8.2018 +; +; int __fastcall__ clock_gettime (clockid_t clk_id, struct timespec *tp); +; + + .include "time.inc" + .include "c65.inc" + + .importzp sreg, tmp1, tmp2 + .import pushax, pusheax, tosmul0ax, steaxspidx, incsp1, return0 + .import TM, load_tenth + + +;---------------------------------------------------------------------------- +.code + +.proc _clock_gettime + + jsr pushax + jsr pushax + + lda CIA1_TODHR + sed + tax ; Save PM flag + and #%01111111 + cmp #$12 ; 12 AM/PM + bcc @L1 + sbc #$12 +@L1: inx ; Get PM flag + bpl @L2 + clc + adc #$12 +@L2: cld + jsr BCD2dec + sta TM + tm::tm_hour + lda CIA1_TODMIN + jsr BCD2dec + sta TM + tm::tm_min + lda CIA1_TODSEC + jsr BCD2dec + sta TM + tm::tm_sec + lda #TM + jsr _mktime + + ldy #timespec::tv_sec + jsr steaxspidx ; Pops address pushed by 2. pushax + + jsr load_tenth + jsr pusheax + lda CIA1_TOD10 + ldx #>$0000 + jsr tosmul0ax + + ldy #timespec::tv_nsec + jsr steaxspidx ; Pops address pushed by 1. pushax + + jsr incsp1 + jmp return0 + +.endproc + +;---------------------------------------------------------------------------- +; dec = (((BCD>>4)*10) + (BCD&0xf)) + +.proc BCD2dec + + tax + and #%00001111 + sta tmp1 + txa + and #%11110000 ; *16 + lsr ; *8 + sta tmp2 + lsr + lsr ; *2 + adc tmp2 ; = *10 + adc tmp1 + rts + +.endproc diff --git a/libsrc/c65/mainargs.s b/libsrc/c65/mainargs.s new file mode 100644 index 000000000..e2249819f --- /dev/null +++ b/libsrc/c65/mainargs.s @@ -0,0 +1,137 @@ +; mainargs.s +; +; Ullrich von Bassewitz, 2003-03-07 +; Based on code from Stefan A. Haubenthal, +; 2003-05-18, Greg King +; 2004-04-28, 2005-02-26, Ullrich von Bassewitz +; +; Scan a group of arguments that are in BASIC's input-buffer. +; Build an array that points to the beginning of each argument. +; Send, to main(), that array and the count of the arguments. +; +; Command-lines look like these lines: +; +; run +; run : rem +; run:rem arg1 " arg 2 is quoted " arg3 "" arg5 +; +; "run" and "rem" are entokenned; the args. are not. Leading and trailing +; spaces outside of quotes are ignored. +; +; TO-DO: +; - The "file-name" might be a path-name; don't copy the directory-components. +; - Add a control-character quoting mechanism. + + .constructor initmainargs, 24 + .import __argc, __argv + + .include "c65.inc" + + +MAXARGS = 10 ; Maximum number of arguments allowed +REM = $8f ; BASIC token-code +NAME_LEN = 16 ; Maximum length of command-name + +; Get possible command-line arguments. Goes into the special ONCE segment, +; which may be reused after the startup code is run + +.segment "ONCE" + +initmainargs: + +; Assume that the program was loaded, a moment ago, by the traditional LOAD +; statement. Save the "most-recent filename" as argument #0. + + lda #0 ; The terminating NUL character + ldy FNAM_LEN + cpy #NAME_LEN + 1 + bcc L1 + ldy #NAME_LEN ; Limit the length + bne L1 ; Branch always +L0: lda (FNAM),y +L1: sta name,y + dey + bpl L0 + inc __argc ; argc always is equal to, at least, 1 + +; Find the "rem" token. + + ldx #0 +L2: lda BASIC_BUF,x + beq done ; No "rem," no args. + inx + cmp #REM + bne L2 + ldy #1 * 2 + +; Find the next argument + +next: lda BASIC_BUF,x + beq done ; End of line reached + inx + cmp #' ' ; Skip leading spaces + beq next + +; Found start of next argument. We've incremented the pointer in X already, so +; it points to the second character of the argument. This is useful since we +; will check now for a quoted argument, in which case we will have to skip this +; first character. + +found: cmp #'"' ; Is the argument quoted? + beq setterm ; Jump if so + dex ; Reset pointer to first argument character + lda #' ' ; A space ends the argument +setterm:sta term ; Set end of argument marker + +; Now store a pointer to the argument into the next slot. Since the BASIC +; input buffer is located at the start of a RAM page, no calculations are +; necessary. + + txa ; Get low byte + sta argv,y ; argv[y]= &arg + iny + lda #>BASIC_BUF + sta argv,y + iny + inc __argc ; Found another arg + +; Search for the end of the argument + +argloop:lda BASIC_BUF,x + beq done + inx + cmp term + bne argloop + +; We've found the end of the argument. X points one character behind it, and +; A contains the terminating character. To make the argument a valid C string, +; replace the terminating character by a zero. + + lda #0 + sta BASIC_BUF-1,x + +; Check if the maximum number of command line arguments is reached. If not, +; parse the next one. + + lda __argc ; Get low byte of argument count + cmp #MAXARGS ; Maximum number of arguments reached? + bcc next ; Parse next one if not + +; (The last vector in argv[] already is NULL.) + +done: lda #argv + sta __argv + stx __argv + 1 + rts + +.segment "INIT" + +term: .res 1 +name: .res NAME_LEN + 1 + +.data + +; char* argv[MAXARGS+1]={name}; +argv: .addr name + .res MAXARGS * 2 diff --git a/libsrc/c65/randomize.s b/libsrc/c65/randomize.s new file mode 100644 index 000000000..8ee5d1381 --- /dev/null +++ b/libsrc/c65/randomize.s @@ -0,0 +1,18 @@ +; +; 2002-11-05, Ullrich von Bassewitz +; 2015-09-11, Greg King +; +; void __randomize (void); +; /* Initialize the random number generator */ +; + + .export ___randomize + .import _srand + + .include "c65.inc" + +___randomize: + ldx VIC_HLINE ; Use VIC rasterline as high byte + lda TIME+2 ; Use 60HZ clock as low byte + jmp _srand ; Initialize generator + diff --git a/libsrc/c65/revers.s b/libsrc/c65/revers.s new file mode 100644 index 000000000..f6bd88688 --- /dev/null +++ b/libsrc/c65/revers.s @@ -0,0 +1,27 @@ +; +; Ullrich von Bassewitz, 07.08.1998 +; +; unsigned char revers (unsigned char onoff); +; + + .export _revers + + .include "c65.inc" + +.proc _revers + + ldx #$00 ; Assume revers off + tay ; Test onoff + beq L1 ; Jump if off + ldx #$80 ; Load on value + ldy #$00 ; Assume old value is zero +L1: lda RVS ; Load old value + stx RVS ; Set new value + beq L2 ; Jump if old value zero + iny ; Make old value = 1 +L2: ldx #$00 ; Load high byte of result + tya ; Load low byte, set CC + rts + +.endproc + diff --git a/libsrc/c65/settime.s b/libsrc/c65/settime.s new file mode 100644 index 000000000..8b376e089 --- /dev/null +++ b/libsrc/c65/settime.s @@ -0,0 +1,84 @@ +; +; Oliver Schmidt, 16.8.2018 +; +; int __fastcall__ clock_settime (clockid_t clk_id, const struct timespec *tp); +; + + .include "time.inc" + .include "c65.inc" + + .importzp sreg, ptr1 + .import pushax, pusheax, ldax0sp, ldeaxidx + .import tosdiveax, incsp3, return0 + .import TM, load_tenth + + +;---------------------------------------------------------------------------- +.code + +.proc _clock_settime + + jsr pushax + + .assert timespec::tv_sec = 0, error + jsr _localtime + sta ptr1 + stx ptr1+1 + ldy #.sizeof(tm)-1 +@L1: lda (ptr1),y + sta TM,y + dey + bpl @L1 + + lda TM + tm::tm_hour + jsr dec2BCD + tax ; Force flags + bne @L2 + lda #$92 ; 12 AM + bne @L3 +@L2: cmp #$13 ; 1 PM + bcc @L3 + sed + sbc #$12 + cld + ora #%10000000 +@L3: sta CIA1_TODHR + lda TM + tm::tm_min + jsr dec2BCD + sta CIA1_TODMIN + lda TM + tm::tm_sec + jsr dec2BCD + sta CIA1_TODSEC + + jsr ldax0sp + ldy #3+timespec::tv_nsec + jsr ldeaxidx + jsr pusheax + jsr load_tenth + jsr tosdiveax + sta CIA1_TOD10 + + jsr incsp3 + jmp return0 + +.endproc + +;---------------------------------------------------------------------------- +; Just sum up the value in BCD mode. +; http://forum.6502.org/viewtopic.php?p=7629#p7629 + +.proc dec2BCD + + tax + dex + bmi @L9 + lda #0 + clc + sed +@L1: adc #1 + dex + bpl @L1 + cld +@L9: rts + +.endproc diff --git a/libsrc/c65/sysuname.s b/libsrc/c65/sysuname.s new file mode 100644 index 000000000..b0a24a236 --- /dev/null +++ b/libsrc/c65/sysuname.s @@ -0,0 +1,37 @@ +; +; Ullrich von Bassewitz, 2003-08-12 +; +; unsigned char __fastcall__ _sysuname (struct utsname* buf); +; + + .export __sysuname, utsdata + + .import utscopy + + __sysuname = utscopy + +;-------------------------------------------------------------------------- +; Data. We define a fixed utsname struct here and just copy it. + +.rodata + +utsdata: + ; sysname + .asciiz "cc65" + + ; nodename + .asciiz "" + + ; release + .byte .string (>.version) + .byte '.' + .byte .string (<.version) + .byte $00 + + ; version + .byte '0' ; unused + .byte $00 + + ; machine + .asciiz "Commodore 65" + diff --git a/libsrc/c65/tmcommon.s b/libsrc/c65/tmcommon.s new file mode 100644 index 000000000..52094b68e --- /dev/null +++ b/libsrc/c65/tmcommon.s @@ -0,0 +1,64 @@ +; +; Oliver Schmidt, 16.8.2018 +; +; Common stuff for the clock routines +; + + .include "c65.inc" + .include "get_tv.inc" + + .export TM, load_tenth + + .constructor inittime + .importzp sreg + .import _get_tv + + +;---------------------------------------------------------------------------- +.code + +.proc load_tenth + + lda #<(100 * 1000 * 1000 / $10000) + ldx #>(100 * 1000 * 1000 / $10000) + sta sreg + stx sreg+1 + lda #<(100 * 1000 * 1000) + ldx #>(100 * 1000 * 1000) + rts + +.endproc + +;---------------------------------------------------------------------------- +; Constructor that writes to the 1/10 sec register of the TOD to kick it +; into action. If this is not done, the clock hangs. We will read the register +; and write it again, ignoring a possible change in between. +.segment "ONCE" + +.proc inittime + + lda CIA1_TOD10 + sta CIA1_TOD10 + jsr _get_tv + cmp #TV::PAL + bne @60Hz + lda CIA1_CRA + ora #$80 + sta CIA1_CRA +@60Hz: rts + +.endproc + +;---------------------------------------------------------------------------- +; TM struct with date set to 1970-01-01 +.data + +TM: .word 0 ; tm_sec + .word 0 ; tm_min + .word 0 ; tm_hour + .word 1 ; tm_mday + .word 0 ; tm_mon + .word 70 ; tm_year + .word 0 ; tm_wday + .word 0 ; tm_yday + .word 0 ; tm_isdst diff --git a/libsrc/mega65/crt0.s b/libsrc/mega65/crt0.s index 401095c55..c7be6b7ee 100644 --- a/libsrc/mega65/crt0.s +++ b/libsrc/mega65/crt0.s @@ -105,7 +105,6 @@ L1: lda c_sp,x ; Switch to the second charset. -; FIXME lda #14 jsr BSOUT diff --git a/libsrc/mega65/get_tv.s b/libsrc/mega65/get_tv.s new file mode 100644 index 000000000..eb2dafd1d --- /dev/null +++ b/libsrc/mega65/get_tv.s @@ -0,0 +1,25 @@ +; +; Ullrich von Bassewitz, 2002-12-03 +; +; unsigned char get_tv (void); +; /* Return the video mode the machine is using */ +; + + .include "get_tv.inc" + .include "mega65.inc" + + +;-------------------------------------------------------------------------- +; _get_tv + +.proc _get_tv + + ldx #TV::PAL ; Assume PAL + lda PALFLAG + bne pal + dex ; NTSC +pal: txa + ldx #0 + rts + +.endproc diff --git a/libsrc/mega65/gettime.s b/libsrc/mega65/gettime.s new file mode 100644 index 000000000..34c5054d5 --- /dev/null +++ b/libsrc/mega65/gettime.s @@ -0,0 +1,83 @@ +; +; Stefan Haubenthal, 27.7.2009 +; Oliver Schmidt, 14.8.2018 +; +; int __fastcall__ clock_gettime (clockid_t clk_id, struct timespec *tp); +; + + .include "time.inc" + .include "mega65.inc" + + .importzp sreg, tmp1, tmp2 + .import pushax, pusheax, tosmul0ax, steaxspidx, incsp1, return0 + .import TM, load_tenth + + +;---------------------------------------------------------------------------- +.code + +.proc _clock_gettime + + jsr pushax + jsr pushax + + lda CIA1_TODHR + sed + tax ; Save PM flag + and #%01111111 + cmp #$12 ; 12 AM/PM + bcc @L1 + sbc #$12 +@L1: inx ; Get PM flag + bpl @L2 + clc + adc #$12 +@L2: cld + jsr BCD2dec + sta TM + tm::tm_hour + lda CIA1_TODMIN + jsr BCD2dec + sta TM + tm::tm_min + lda CIA1_TODSEC + jsr BCD2dec + sta TM + tm::tm_sec + lda #TM + jsr _mktime + + ldy #timespec::tv_sec + jsr steaxspidx ; Pops address pushed by 2. pushax + + jsr load_tenth + jsr pusheax + lda CIA1_TOD10 + ldx #>$0000 + jsr tosmul0ax + + ldy #timespec::tv_nsec + jsr steaxspidx ; Pops address pushed by 1. pushax + + jsr incsp1 + jmp return0 + +.endproc + +;---------------------------------------------------------------------------- +; dec = (((BCD>>4)*10) + (BCD&0xf)) + +.proc BCD2dec + + tax + and #%00001111 + sta tmp1 + txa + and #%11110000 ; *16 + lsr ; *8 + sta tmp2 + lsr + lsr ; *2 + adc tmp2 ; = *10 + adc tmp1 + rts + +.endproc diff --git a/libsrc/mega65/mainargs.s b/libsrc/mega65/mainargs.s new file mode 100644 index 000000000..b4063b93c --- /dev/null +++ b/libsrc/mega65/mainargs.s @@ -0,0 +1,137 @@ +; mainargs.s +; +; Ullrich von Bassewitz, 2003-03-07 +; Based on code from Stefan A. Haubenthal, +; 2003-05-18, Greg King +; 2004-04-28, 2005-02-26, Ullrich von Bassewitz +; +; Scan a group of arguments that are in BASIC's input-buffer. +; Build an array that points to the beginning of each argument. +; Send, to main(), that array and the count of the arguments. +; +; Command-lines look like these lines: +; +; run +; run : rem +; run:rem arg1 " arg 2 is quoted " arg3 "" arg5 +; +; "run" and "rem" are entokenned; the args. are not. Leading and trailing +; spaces outside of quotes are ignored. +; +; TO-DO: +; - The "file-name" might be a path-name; don't copy the directory-components. +; - Add a control-character quoting mechanism. + + .constructor initmainargs, 24 + .import __argc, __argv + + .include "mega65.inc" + + +MAXARGS = 10 ; Maximum number of arguments allowed +REM = $8f ; BASIC token-code +NAME_LEN = 16 ; Maximum length of command-name + +; Get possible command-line arguments. Goes into the special ONCE segment, +; which may be reused after the startup code is run + +.segment "ONCE" + +initmainargs: + +; Assume that the program was loaded, a moment ago, by the traditional LOAD +; statement. Save the "most-recent filename" as argument #0. + + lda #0 ; The terminating NUL character + ldy FNAM_LEN + cpy #NAME_LEN + 1 + bcc L1 + ldy #NAME_LEN ; Limit the length + bne L1 ; Branch always +L0: lda (FNAM),y +L1: sta name,y + dey + bpl L0 + inc __argc ; argc always is equal to, at least, 1 + +; Find the "rem" token. + + ldx #0 +L2: lda BASIC_BUF,x + beq done ; No "rem," no args. + inx + cmp #REM + bne L2 + ldy #1 * 2 + +; Find the next argument + +next: lda BASIC_BUF,x + beq done ; End of line reached + inx + cmp #' ' ; Skip leading spaces + beq next + +; Found start of next argument. We've incremented the pointer in X already, so +; it points to the second character of the argument. This is useful since we +; will check now for a quoted argument, in which case we will have to skip this +; first character. + +found: cmp #'"' ; Is the argument quoted? + beq setterm ; Jump if so + dex ; Reset pointer to first argument character + lda #' ' ; A space ends the argument +setterm:sta term ; Set end of argument marker + +; Now store a pointer to the argument into the next slot. Since the BASIC +; input buffer is located at the start of a RAM page, no calculations are +; necessary. + + txa ; Get low byte + sta argv,y ; argv[y]= &arg + iny + lda #>BASIC_BUF + sta argv,y + iny + inc __argc ; Found another arg + +; Search for the end of the argument + +argloop:lda BASIC_BUF,x + beq done + inx + cmp term + bne argloop + +; We've found the end of the argument. X points one character behind it, and +; A contains the terminating character. To make the argument a valid C string, +; replace the terminating character by a zero. + + lda #0 + sta BASIC_BUF-1,x + +; Check if the maximum number of command line arguments is reached. If not, +; parse the next one. + + lda __argc ; Get low byte of argument count + cmp #MAXARGS ; Maximum number of arguments reached? + bcc next ; Parse next one if not + +; (The last vector in argv[] already is NULL.) + +done: lda #argv + sta __argv + stx __argv + 1 + rts + +.segment "INIT" + +term: .res 1 +name: .res NAME_LEN + 1 + +.data + +; char* argv[MAXARGS+1]={name}; +argv: .addr name + .res MAXARGS * 2 diff --git a/libsrc/mega65/randomize.s b/libsrc/mega65/randomize.s new file mode 100644 index 000000000..89feebe11 --- /dev/null +++ b/libsrc/mega65/randomize.s @@ -0,0 +1,18 @@ +; +; 2002-11-05, Ullrich von Bassewitz +; 2015-09-11, Greg King +; +; void __randomize (void); +; /* Initialize the random number generator */ +; + + .export ___randomize + .import _srand + + .include "mega65.inc" + +___randomize: + ldx VIC_HLINE ; Use VIC rasterline as high byte + lda TIME+2 ; Use 60HZ clock as low byte + jmp _srand ; Initialize generator + diff --git a/libsrc/mega65/revers.s b/libsrc/mega65/revers.s new file mode 100644 index 000000000..3dc508f79 --- /dev/null +++ b/libsrc/mega65/revers.s @@ -0,0 +1,27 @@ +; +; Ullrich von Bassewitz, 07.08.1998 +; +; unsigned char revers (unsigned char onoff); +; + + .export _revers + + .include "mega65.inc" + +.proc _revers + + ldx #$00 ; Assume revers off + tay ; Test onoff + beq L1 ; Jump if off + ldx #$80 ; Load on value + ldy #$00 ; Assume old value is zero +L1: lda RVS ; Load old value + stx RVS ; Set new value + beq L2 ; Jump if old value zero + iny ; Make old value = 1 +L2: ldx #$00 ; Load high byte of result + tya ; Load low byte, set CC + rts + +.endproc + diff --git a/libsrc/mega65/sysuname.s b/libsrc/mega65/sysuname.s new file mode 100644 index 000000000..2feab6fb1 --- /dev/null +++ b/libsrc/mega65/sysuname.s @@ -0,0 +1,37 @@ +; +; Ullrich von Bassewitz, 2003-08-12 +; +; unsigned char __fastcall__ _sysuname (struct utsname* buf); +; + + .export __sysuname, utsdata + + .import utscopy + + __sysuname = utscopy + +;-------------------------------------------------------------------------- +; Data. We define a fixed utsname struct here and just copy it. + +.rodata + +utsdata: + ; sysname + .asciiz "cc65" + + ; nodename + .asciiz "" + + ; release + .byte .string (>.version) + .byte '.' + .byte .string (<.version) + .byte $00 + + ; version + .byte '0' ; unused + .byte $00 + + ; machine + .asciiz "MEGA65" + diff --git a/libsrc/mega65/tmcommon.s b/libsrc/mega65/tmcommon.s new file mode 100644 index 000000000..52094b68e --- /dev/null +++ b/libsrc/mega65/tmcommon.s @@ -0,0 +1,64 @@ +; +; Oliver Schmidt, 16.8.2018 +; +; Common stuff for the clock routines +; + + .include "c65.inc" + .include "get_tv.inc" + + .export TM, load_tenth + + .constructor inittime + .importzp sreg + .import _get_tv + + +;---------------------------------------------------------------------------- +.code + +.proc load_tenth + + lda #<(100 * 1000 * 1000 / $10000) + ldx #>(100 * 1000 * 1000 / $10000) + sta sreg + stx sreg+1 + lda #<(100 * 1000 * 1000) + ldx #>(100 * 1000 * 1000) + rts + +.endproc + +;---------------------------------------------------------------------------- +; Constructor that writes to the 1/10 sec register of the TOD to kick it +; into action. If this is not done, the clock hangs. We will read the register +; and write it again, ignoring a possible change in between. +.segment "ONCE" + +.proc inittime + + lda CIA1_TOD10 + sta CIA1_TOD10 + jsr _get_tv + cmp #TV::PAL + bne @60Hz + lda CIA1_CRA + ora #$80 + sta CIA1_CRA +@60Hz: rts + +.endproc + +;---------------------------------------------------------------------------- +; TM struct with date set to 1970-01-01 +.data + +TM: .word 0 ; tm_sec + .word 0 ; tm_min + .word 0 ; tm_hour + .word 1 ; tm_mday + .word 0 ; tm_mon + .word 70 ; tm_year + .word 0 ; tm_wday + .word 0 ; tm_yday + .word 0 ; tm_isdst diff --git a/targettest/Makefile b/targettest/Makefile index 56b5df446..a9a7ef77d 100644 --- a/targettest/Makefile +++ b/targettest/Makefile @@ -608,6 +608,64 @@ EXELIST_cx16 = \ strqtok-test \ uname-test +# omitted: deb em-test joy-test mouse-test ser-test seek +EXELIST_c65 = \ + arg-test \ + clock \ + clock-test \ + conio \ + cpeek-test \ + cprintf \ + cursor \ + dir-test \ + div-test \ + exec-test1 \ + exec-test2 \ + fileio-test \ + ft \ + getopt-test \ + heaptest \ + moddiv-test \ + mul-test \ + posixio-test \ + rename-test \ + scanf-test \ + strdup-test \ + strnlen \ + stroserror-test \ + strqtok-test \ + uname-test \ + minimal + +# omitted: deb em-test joy-test mouse-test ser-test seek +EXELIST_mega65 = \ + arg-test \ + clock \ + clock-test \ + conio \ + cpeek-test \ + cprintf \ + cursor \ + dir-test \ + div-test \ + exec-test1 \ + exec-test2 \ + fileio-test \ + ft \ + getopt-test \ + heaptest \ + moddiv-test \ + mul-test \ + posixio-test \ + rename-test \ + scanf-test \ + strdup-test \ + strnlen \ + stroserror-test \ + strqtok-test \ + uname-test \ + minimal + # omitted: arg-test clock-test clock cpeek-test cprintf cursor deb dir-test div-test # em-test exec-test1 exec-test2 fileio-test ft getopt-test heaptest joy-test moddiv-test # mouse-test mul-test posixio-test rename-test scanf-test seek ser-test strdup-test @@ -756,6 +814,7 @@ TARGETS := \ c128 \ c16 \ c64 \ + c65 \ cbm510 \ cbm610 \ creativision \ @@ -764,6 +823,7 @@ TARGETS := \ kim1 \ lunix \ lynx \ + mega65 \ nes \ osic1p \ pce \ diff --git a/targettest/cpeek-test.c b/targettest/cpeek-test.c index 4c1aadcb2..6f6556935 100644 --- a/targettest/cpeek-test.c +++ b/targettest/cpeek-test.c @@ -24,6 +24,10 @@ # define SCREEN_RAM ((unsigned char*)0x8000) #elif defined(__VIC20__) # define SCREEN_RAM ((unsigned char*)0x1000) +#elif defined(__C65__) +# define SCREEN_RAM ((unsigned char*)0x0800) +#elif defined(__MEGA65__) +# define SCREEN_RAM ((unsigned char*)0x0800) #else # error This program cannot test that target. # define SCREEN_RAM ((unsigned char*)0) From 955c6627c0dc94d38e14e228e1ace6637b0e2671 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 25 Jun 2025 02:47:33 +0200 Subject: [PATCH 16/27] forgot settime... --- libsrc/mega65/settime.s | 84 +++++++++++++++++++++++++++++++++++++++++ 1 file changed, 84 insertions(+) create mode 100644 libsrc/mega65/settime.s diff --git a/libsrc/mega65/settime.s b/libsrc/mega65/settime.s new file mode 100644 index 000000000..22a17fb61 --- /dev/null +++ b/libsrc/mega65/settime.s @@ -0,0 +1,84 @@ +; +; Oliver Schmidt, 16.8.2018 +; +; int __fastcall__ clock_settime (clockid_t clk_id, const struct timespec *tp); +; + + .include "time.inc" + .include "mega65.inc" + + .importzp sreg, ptr1 + .import pushax, pusheax, ldax0sp, ldeaxidx + .import tosdiveax, incsp3, return0 + .import TM, load_tenth + + +;---------------------------------------------------------------------------- +.code + +.proc _clock_settime + + jsr pushax + + .assert timespec::tv_sec = 0, error + jsr _localtime + sta ptr1 + stx ptr1+1 + ldy #.sizeof(tm)-1 +@L1: lda (ptr1),y + sta TM,y + dey + bpl @L1 + + lda TM + tm::tm_hour + jsr dec2BCD + tax ; Force flags + bne @L2 + lda #$92 ; 12 AM + bne @L3 +@L2: cmp #$13 ; 1 PM + bcc @L3 + sed + sbc #$12 + cld + ora #%10000000 +@L3: sta CIA1_TODHR + lda TM + tm::tm_min + jsr dec2BCD + sta CIA1_TODMIN + lda TM + tm::tm_sec + jsr dec2BCD + sta CIA1_TODSEC + + jsr ldax0sp + ldy #3+timespec::tv_nsec + jsr ldeaxidx + jsr pusheax + jsr load_tenth + jsr tosdiveax + sta CIA1_TOD10 + + jsr incsp3 + jmp return0 + +.endproc + +;---------------------------------------------------------------------------- +; Just sum up the value in BCD mode. +; http://forum.6502.org/viewtopic.php?p=7629#p7629 + +.proc dec2BCD + + tax + dex + bmi @L9 + lda #0 + clc + sed +@L1: adc #1 + dex + bpl @L1 + cld +@L9: rts + +.endproc From 4db5ac6c142479ec92f4bc09cd19e7aa98184209 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 25 Jun 2025 05:13:09 +0200 Subject: [PATCH 17/27] SCREEN_PTR does only contain the offset apparently (unlike on other cbm systems), so we need extra handling --- libsrc/c65/cpeekc.s | 45 +++++++++++++++++++++ libsrc/c65/cpeekcolor.s | 25 ++++++++++++ libsrc/c65/cpeeks.s | 80 +++++++++++++++++++++++++++++++++++++ libsrc/c65/cputc.s | 24 ++++++----- libsrc/cbm/cpeekc.s | 4 -- libsrc/cbm/cpeekcolor.s | 4 -- libsrc/cbm/cpeeks.s | 4 -- libsrc/mega65/cpeekc.s | 45 +++++++++++++++++++++ libsrc/mega65/cpeekcolor.s | 25 ++++++++++++ libsrc/mega65/cpeekrevers.s | 28 +++++++++++++ libsrc/mega65/cpeeks.s | 80 +++++++++++++++++++++++++++++++++++++ libsrc/mega65/cputc.s | 26 ++++++------ libsrc/mega65/kbhit.s | 2 +- 13 files changed, 356 insertions(+), 36 deletions(-) create mode 100644 libsrc/c65/cpeekc.s create mode 100644 libsrc/c65/cpeekcolor.s create mode 100644 libsrc/c65/cpeeks.s create mode 100644 libsrc/mega65/cpeekc.s create mode 100644 libsrc/mega65/cpeekcolor.s create mode 100644 libsrc/mega65/cpeekrevers.s create mode 100644 libsrc/mega65/cpeeks.s diff --git a/libsrc/c65/cpeekc.s b/libsrc/c65/cpeekc.s new file mode 100644 index 000000000..a64e13cfd --- /dev/null +++ b/libsrc/c65/cpeekc.s @@ -0,0 +1,45 @@ +; +; 2016-02-28, Groepaz +; 2017-06-22, Greg King +; +; char cpeekc (void); +; + + .include "c65.inc" + + .export _cpeekc + .importzp ptr1 + +_cpeekc: + lda SCREEN_PTR + 1 + clc + adc #>$0800 + sta ptr1 + 1 + lda SCREEN_PTR + sta ptr1 + + ldy CURS_X + lda (ptr1),y ; get screen code + ldx #>$0000 + and #<~$80 ; remove reverse bit + +; Convert the screen code into a PetSCII code. +; $00 - $1F: +$40 +; $20 - $3F +; $40 - $5f: +$20 +; $60 - $7F: +$40 + + cmp #$20 + bcs @sk1 ;(bge) + ora #$40 + rts + +@sk1: cmp #$40 + bcc @end ;(blt) + cmp #$60 + bcc @sk2 ;(blt) + ;sec + adc #$20 - $01 +@sk2: ;clc ; both above cmp and adc clear carry flag + adc #$20 +@end: rts diff --git a/libsrc/c65/cpeekcolor.s b/libsrc/c65/cpeekcolor.s new file mode 100644 index 000000000..f4b4a5573 --- /dev/null +++ b/libsrc/c65/cpeekcolor.s @@ -0,0 +1,25 @@ +; +; 2016-02-28, Groepaz +; 2017-06-22, Greg King +; +; unsigned char cpeekcolor (void); +; + + .include "c65.inc" + + .export _cpeekcolor + .importzp ptr1 + +_cpeekcolor: + lda SCREEN_PTR + 1 + clc + adc #>$D800 + sta ptr1 + 1 + lda SCREEN_PTR + sta ptr1 + + ldy #0 + lda (ptr1),y + + ldx #>$0000 + rts diff --git a/libsrc/c65/cpeeks.s b/libsrc/c65/cpeeks.s new file mode 100644 index 000000000..9c33831f1 --- /dev/null +++ b/libsrc/c65/cpeeks.s @@ -0,0 +1,80 @@ +; +; 2017-07-05, Greg King +; +; void cpeeks (char* s, unsigned length); +; + + .include "c65.inc" + + .export _cpeeks + + .import popax + .importzp ptr1, ptr2, ptr3, tmp1, tmp2 + + .macpack generic + +_cpeeks: + eor #<$FFFF ; counting a word upward is faster + sta ptr3 ; so, we use -(length + 1) + txa + eor #>$FFFF + sta ptr3+1 + + lda SCREEN_PTR + sta ptr2 + lda SCREEN_PTR+1 + clc + adc #>$0800 + sta ptr2+1 + + ldy CURS_X + sty tmp2 + + jsr popax + sta tmp1 ; (will be a .Y index) + stx ptr1+1 + ldx #<$0000 + stx ptr1 + bze L3 ; branch always + +L4: ldy tmp2 + lda (ptr2),y ; get char + iny + bnz L2 + inc ptr2+1 +L2: sty tmp2 + and #<~$80 ; remove reverse bit + +; Convert the screen code into a PetSCII code. +; $00 - $1F: +$40 +; $20 - $3F +; $40 - $5f: +$20 +; $60 - $7F: +$40 + + cmp #$20 + blt @sk1 ;(bcc) + cmp #$40 + blt L5 + cmp #$60 + blt @sk2 ;(bcc) + clc +@sk1: adc #$20 +@sk2: ;clc ; both above cmp and adc clear carry flag + adc #$20 + +L5: ldy tmp1 + sta (ptr1),y + iny + bnz L1 + inc ptr1+1 +L1: sty tmp1 + +L3: inc ptr3 ; count length + bnz L4 + inc ptr3+1 + bnz L4 + + txa ; terminate the string + ldy tmp1 + sta (ptr1),y + rts diff --git a/libsrc/c65/cputc.s b/libsrc/c65/cputc.s index a34262437..99a81b67d 100644 --- a/libsrc/c65/cputc.s +++ b/libsrc/c65/cputc.s @@ -96,23 +96,25 @@ plot: ldy CURS_X putchar: ora RVS ; Set revers bit - ldy CURS_X - pha + tay lda SCREEN_PTR + 1 clc adc #>$0800 - sta SCREEN_PTR + 1 - pla + sta ptr4 + 1 + lda SCREEN_PTR + sta ptr4 + tya - sta (SCREEN_PTR),y ; Set char + ldy CURS_X + sta (ptr4),y ; Set char - lda SCREEN_PTR + 1 - sec - sbc #>$0800 - sta SCREEN_PTR + 1 + lda ptr4 + 1 + clc + adc #>$d000 + sta ptr4 + 1 lda CHARCOLOR -; lda #$88 -; sta (CRAM_PTR),y ; Set color + sta (ptr4),y ; Set color + rts diff --git a/libsrc/cbm/cpeekc.s b/libsrc/cbm/cpeekc.s index 32dc0456e..05c7fc718 100644 --- a/libsrc/cbm/cpeekc.s +++ b/libsrc/cbm/cpeekc.s @@ -22,10 +22,6 @@ .include "pet.inc" .elseif .def(__VIC20__) .include "vic20.inc" -.elseif .def(__C65__) - .include "c65.inc" -.elseif .def(__MEGA65__) - .include "mega65.inc" .endif diff --git a/libsrc/cbm/cpeekcolor.s b/libsrc/cbm/cpeekcolor.s index a0d7efe6c..9c961b771 100644 --- a/libsrc/cbm/cpeekcolor.s +++ b/libsrc/cbm/cpeekcolor.s @@ -17,10 +17,6 @@ .include "c64.inc" .elseif .def(__VIC20__) .include "vic20.inc" -.elseif .def(__C65__) - .include "c65.inc" -.elseif .def(__MEGA65__) - .include "mega65.inc" .endif diff --git a/libsrc/cbm/cpeeks.s b/libsrc/cbm/cpeeks.s index d73192d73..215998e37 100644 --- a/libsrc/cbm/cpeeks.s +++ b/libsrc/cbm/cpeeks.s @@ -26,10 +26,6 @@ .include "pet.inc" .elseif .def(__VIC20__) .include "vic20.inc" -.elseif .def(__C65__) - .include "c65.inc" -.elseif .def(__MEGA65__) - .include "mega65.inc" .endif diff --git a/libsrc/mega65/cpeekc.s b/libsrc/mega65/cpeekc.s new file mode 100644 index 000000000..f75926d3e --- /dev/null +++ b/libsrc/mega65/cpeekc.s @@ -0,0 +1,45 @@ +; +; 2016-02-28, Groepaz +; 2017-06-22, Greg King +; +; char cpeekc (void); +; + + .include "mega65.inc" + + .export _cpeekc + .importzp ptr1 + +_cpeekc: + lda SCREEN_PTR + 1 + clc + adc #>$0800 + sta ptr1 + 1 + lda SCREEN_PTR + sta ptr1 + + ldy CURS_X + lda (ptr1),y ; get screen code + ldx #>$0000 + and #<~$80 ; remove reverse bit + +; Convert the screen code into a PetSCII code. +; $00 - $1F: +$40 +; $20 - $3F +; $40 - $5f: +$20 +; $60 - $7F: +$40 + + cmp #$20 + bcs @sk1 ;(bge) + ora #$40 + rts + +@sk1: cmp #$40 + bcc @end ;(blt) + cmp #$60 + bcc @sk2 ;(blt) + ;sec + adc #$20 - $01 +@sk2: ;clc ; both above cmp and adc clear carry flag + adc #$20 +@end: rts diff --git a/libsrc/mega65/cpeekcolor.s b/libsrc/mega65/cpeekcolor.s new file mode 100644 index 000000000..45a59f3cb --- /dev/null +++ b/libsrc/mega65/cpeekcolor.s @@ -0,0 +1,25 @@ +; +; 2016-02-28, Groepaz +; 2017-06-22, Greg King +; +; unsigned char cpeekcolor (void); +; + + .include "mega65.inc" + + .export _cpeekcolor + .importzp ptr1 + +_cpeekcolor: + lda SCREEN_PTR + 1 + clc + adc #>$d800 + sta ptr1 + 1 + lda SCREEN_PTR + sta ptr1 + + ldy CURS_X + lda (ptr1),y + + ldx #>$0000 + rts diff --git a/libsrc/mega65/cpeekrevers.s b/libsrc/mega65/cpeekrevers.s new file mode 100644 index 000000000..a8e03e91e --- /dev/null +++ b/libsrc/mega65/cpeekrevers.s @@ -0,0 +1,28 @@ +; +; 2016-02-28, Groepaz +; 2017-06-15, Greg King +; +; unsigned char cpeekrevers (void); +; + + .include "mega65.inc" + + .export _cpeekrevers + .importzp ptr1 + +_cpeekrevers: + lda SCREEN_PTR + 1 + clc + adc #>$0800 + sta ptr1 + 1 + lda SCREEN_PTR + sta ptr1 + + ldy CURS_X + lda (ptr1),y ; get screen code + and #$80 ; get reverse bit + asl a + tax ; ldx #>$0000 + rol a ; return boolean value + + rts diff --git a/libsrc/mega65/cpeeks.s b/libsrc/mega65/cpeeks.s new file mode 100644 index 000000000..9c33831f1 --- /dev/null +++ b/libsrc/mega65/cpeeks.s @@ -0,0 +1,80 @@ +; +; 2017-07-05, Greg King +; +; void cpeeks (char* s, unsigned length); +; + + .include "c65.inc" + + .export _cpeeks + + .import popax + .importzp ptr1, ptr2, ptr3, tmp1, tmp2 + + .macpack generic + +_cpeeks: + eor #<$FFFF ; counting a word upward is faster + sta ptr3 ; so, we use -(length + 1) + txa + eor #>$FFFF + sta ptr3+1 + + lda SCREEN_PTR + sta ptr2 + lda SCREEN_PTR+1 + clc + adc #>$0800 + sta ptr2+1 + + ldy CURS_X + sty tmp2 + + jsr popax + sta tmp1 ; (will be a .Y index) + stx ptr1+1 + ldx #<$0000 + stx ptr1 + bze L3 ; branch always + +L4: ldy tmp2 + lda (ptr2),y ; get char + iny + bnz L2 + inc ptr2+1 +L2: sty tmp2 + and #<~$80 ; remove reverse bit + +; Convert the screen code into a PetSCII code. +; $00 - $1F: +$40 +; $20 - $3F +; $40 - $5f: +$20 +; $60 - $7F: +$40 + + cmp #$20 + blt @sk1 ;(bcc) + cmp #$40 + blt L5 + cmp #$60 + blt @sk2 ;(bcc) + clc +@sk1: adc #$20 +@sk2: ;clc ; both above cmp and adc clear carry flag + adc #$20 + +L5: ldy tmp1 + sta (ptr1),y + iny + bnz L1 + inc ptr1+1 +L1: sty tmp1 + +L3: inc ptr3 ; count length + bnz L4 + inc ptr3+1 + bnz L4 + + txa ; terminate the string + ldy tmp1 + sta (ptr1),y + rts diff --git a/libsrc/mega65/cputc.s b/libsrc/mega65/cputc.s index ad93ba7e5..df44f5bdd 100644 --- a/libsrc/mega65/cputc.s +++ b/libsrc/mega65/cputc.s @@ -9,10 +9,10 @@ .export newline, plot .import gotoxy .import PLOT + .importzp ptr4 .include "mega65.inc" - _cputcxy: pha ; Save C jsr gotoxy ; Set cursor, drop x and y @@ -96,23 +96,25 @@ plot: ldy CURS_X putchar: ora RVS ; Set revers bit - ldy CURS_X - pha + tay lda SCREEN_PTR + 1 clc adc #>$0800 - sta SCREEN_PTR + 1 - pla + sta ptr4 + 1 + lda SCREEN_PTR + sta ptr4 + tya - sta (SCREEN_PTR),y ; Set char + ldy CURS_X + sta (ptr4),y ; Set char - lda SCREEN_PTR + 1 - sec - sbc #>$0800 - sta SCREEN_PTR + 1 + lda ptr4 + 1 + clc + adc #>$d000 + sta ptr4 + 1 lda CHARCOLOR -; lda #$88 -; sta (CRAM_PTR),y ; Set color + sta (ptr4),y ; Set color + rts diff --git a/libsrc/mega65/kbhit.s b/libsrc/mega65/kbhit.s index 63b34629b..b88b0f48a 100644 --- a/libsrc/mega65/kbhit.s +++ b/libsrc/mega65/kbhit.s @@ -19,6 +19,6 @@ _kbhit: lda #1 : - ldx #0 + ldx #>$0000 rts From 1e209b1f150c681c208c28ebd0f7641f9e6d0683 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 25 Jun 2025 05:14:26 +0200 Subject: [PATCH 18/27] forgot, need sleep --- libsrc/c65/cputc.s | 1 + 1 file changed, 1 insertion(+) diff --git a/libsrc/c65/cputc.s b/libsrc/c65/cputc.s index 99a81b67d..d9f63c1dd 100644 --- a/libsrc/c65/cputc.s +++ b/libsrc/c65/cputc.s @@ -9,6 +9,7 @@ .export newline, plot .import gotoxy .import PLOT + .importzp ptr4 .include "c65.inc" From 2206b8d1998b35bdad3248cb9fb57f5df54a36f2 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 25 Jun 2025 18:52:36 +0200 Subject: [PATCH 19/27] fix getscreensize --- libsrc/c65/_scrsize.s | 9 +++++++-- libsrc/mega65/_scrsize.s | 9 +++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/libsrc/c65/_scrsize.s b/libsrc/c65/_scrsize.s index 57ad4f30f..3fc955657 100644 --- a/libsrc/c65/_scrsize.s +++ b/libsrc/c65/_scrsize.s @@ -5,8 +5,13 @@ ; .export screensize - .import SCREEN + .include "cbm_kernal.inc" -screensize = SCREEN +.proc screensize + jsr SCREEN + inx + iny + rts +.endproc diff --git a/libsrc/mega65/_scrsize.s b/libsrc/mega65/_scrsize.s index 57ad4f30f..3fc955657 100644 --- a/libsrc/mega65/_scrsize.s +++ b/libsrc/mega65/_scrsize.s @@ -5,8 +5,13 @@ ; .export screensize - .import SCREEN + .include "cbm_kernal.inc" -screensize = SCREEN +.proc screensize + jsr SCREEN + inx + iny + rts +.endproc From ef1b1015385cb9df6e894ffc64b8d84150d371b4 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 25 Jun 2025 20:38:58 +0200 Subject: [PATCH 20/27] fix cursor() --- asminc/cbm_kernal.inc | 16 ++++++++++++---- libsrc/c65/cursor.s | 26 ++++++++++++++++++++++++++ libsrc/mega65/cursor.s | 26 ++++++++++++++++++++++++++ 3 files changed, 64 insertions(+), 4 deletions(-) create mode 100644 libsrc/c65/cursor.s create mode 100644 libsrc/mega65/cursor.s diff --git a/asminc/cbm_kernal.inc b/asminc/cbm_kernal.inc index a2fb05cb0..963ab1985 100644 --- a/asminc/cbm_kernal.inc +++ b/asminc/cbm_kernal.inc @@ -63,16 +63,24 @@ MOUSE_GET := $FF6B .endif -.if .def(__C65__) || .def (__MEGA65__) +.if .def (__MEGA65__) ; extended C65 jump table - VERSIONQ := $FF2F - RESET_RUN := $FF32 - CURSOR := $FF35 + +; memory before $ff3b is all $ff in mega65 ROM? +; VERSIONQ := $FF2F +; RESET_RUN := $FF32 +; CURSOR := $FF35 + SAVEFL := $FF3B GETIO := $FF41 GETLFS := $FF44 KEYLOCKS := $FF47 ADDKEY := $FF4A +.endif + +.if .def(__C65__) || .def (__MEGA65__) + CURSOR := $E030 ; in editor ROM + SPIN_SPOUT := $FF4D CLSALL := $FF50 C64MODE := $FF53 diff --git a/libsrc/c65/cursor.s b/libsrc/c65/cursor.s new file mode 100644 index 000000000..8c36a7a32 --- /dev/null +++ b/libsrc/c65/cursor.s @@ -0,0 +1,26 @@ +; +; unsigned char cursor (unsigned char onoff); +; + + .include "cbm_kernal.inc" + + .export _cursor + .import cursor + +.proc _cursor + pha + ; A != 0 to enable, 0 to disable + cmp #0 + beq disable ; C = 1 + clc +disable: + ; C = 0 to enable, 1 to disable + jsr CURSOR + + ply ; onoff into Y + ldx #0 ; High byte of result + lda cursor ; Get old value + sty cursor ; Set new value + rts +.endproc + diff --git a/libsrc/mega65/cursor.s b/libsrc/mega65/cursor.s new file mode 100644 index 000000000..8c36a7a32 --- /dev/null +++ b/libsrc/mega65/cursor.s @@ -0,0 +1,26 @@ +; +; unsigned char cursor (unsigned char onoff); +; + + .include "cbm_kernal.inc" + + .export _cursor + .import cursor + +.proc _cursor + pha + ; A != 0 to enable, 0 to disable + cmp #0 + beq disable ; C = 1 + clc +disable: + ; C = 0 to enable, 1 to disable + jsr CURSOR + + ply ; onoff into Y + ldx #0 ; High byte of result + lda cursor ; Get old value + sty cursor ; Set new value + rts +.endproc + From a7e509cd43f4ff54a11873757615f8bf68d49940 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 25 Jun 2025 21:39:03 +0200 Subject: [PATCH 21/27] better handling of the cursor, use kernal function to read key, not the UART directly --- asminc/cbm_kernal.inc | 1 + libsrc/c65/cgetc.s | 32 ++++++++++++++++++++++++++++++++ libsrc/c65/cursor.s | 26 -------------------------- libsrc/c65/kbhit.s | 12 +----------- libsrc/mega65/cgetc.s | 32 ++++++++++++++++++++++++++++++++ libsrc/mega65/cursor.s | 26 -------------------------- libsrc/mega65/kbhit.s | 10 ---------- 7 files changed, 66 insertions(+), 73 deletions(-) create mode 100644 libsrc/c65/cgetc.s delete mode 100644 libsrc/c65/cursor.s create mode 100644 libsrc/mega65/cgetc.s delete mode 100644 libsrc/mega65/cursor.s diff --git a/asminc/cbm_kernal.inc b/asminc/cbm_kernal.inc index 963ab1985..f06483a47 100644 --- a/asminc/cbm_kernal.inc +++ b/asminc/cbm_kernal.inc @@ -244,4 +244,5 @@ UDTIM := $FFEA KBDREAD := $D8C1 .elseif .def(__C65__) || .def(__MEGA65__) ; CLRSCR := $E0EC ; ??? + KBDREAD := $E006 .endif diff --git a/libsrc/c65/cgetc.s b/libsrc/c65/cgetc.s new file mode 100644 index 000000000..3b2d5934d --- /dev/null +++ b/libsrc/c65/cgetc.s @@ -0,0 +1,32 @@ + + + .include "cbm_kernal.inc" + .import cursor + .export _cgetc +_cgetc: + + lda cursor + beq nocursor + + ; enable the cursor + clc + jsr CURSOR + +nocursor: + ; wait for a key + ; FIXME: is $d610 mega65 specific? +: + lda $d610 + beq :- + + jsr KBDREAD + + pha + ; disable the cursor + sec + jsr CURSOR + + pla + ldx #0 + rts + diff --git a/libsrc/c65/cursor.s b/libsrc/c65/cursor.s deleted file mode 100644 index 8c36a7a32..000000000 --- a/libsrc/c65/cursor.s +++ /dev/null @@ -1,26 +0,0 @@ -; -; unsigned char cursor (unsigned char onoff); -; - - .include "cbm_kernal.inc" - - .export _cursor - .import cursor - -.proc _cursor - pha - ; A != 0 to enable, 0 to disable - cmp #0 - beq disable ; C = 1 - clc -disable: - ; C = 0 to enable, 1 to disable - jsr CURSOR - - ply ; onoff into Y - ldx #0 ; High byte of result - lda cursor ; Get old value - sty cursor ; Set new value - rts -.endproc - diff --git a/libsrc/c65/kbhit.s b/libsrc/c65/kbhit.s index 63b34629b..683451b03 100644 --- a/libsrc/c65/kbhit.s +++ b/libsrc/c65/kbhit.s @@ -1,17 +1,7 @@ - ; FIXME: is $d610 mega65 specific? ; FIXME: this should rather use the kernal (with keyboard buffer etc) - .export _cgetc -_cgetc: - -: lda $d610 - beq :- - ldx #0 - stx $d610 - rts - .export _kbhit _kbhit: lda $d610 @@ -19,6 +9,6 @@ _kbhit: lda #1 : - ldx #0 + ldx #>$0000 rts diff --git a/libsrc/mega65/cgetc.s b/libsrc/mega65/cgetc.s new file mode 100644 index 000000000..3b2d5934d --- /dev/null +++ b/libsrc/mega65/cgetc.s @@ -0,0 +1,32 @@ + + + .include "cbm_kernal.inc" + .import cursor + .export _cgetc +_cgetc: + + lda cursor + beq nocursor + + ; enable the cursor + clc + jsr CURSOR + +nocursor: + ; wait for a key + ; FIXME: is $d610 mega65 specific? +: + lda $d610 + beq :- + + jsr KBDREAD + + pha + ; disable the cursor + sec + jsr CURSOR + + pla + ldx #0 + rts + diff --git a/libsrc/mega65/cursor.s b/libsrc/mega65/cursor.s deleted file mode 100644 index 8c36a7a32..000000000 --- a/libsrc/mega65/cursor.s +++ /dev/null @@ -1,26 +0,0 @@ -; -; unsigned char cursor (unsigned char onoff); -; - - .include "cbm_kernal.inc" - - .export _cursor - .import cursor - -.proc _cursor - pha - ; A != 0 to enable, 0 to disable - cmp #0 - beq disable ; C = 1 - clc -disable: - ; C = 0 to enable, 1 to disable - jsr CURSOR - - ply ; onoff into Y - ldx #0 ; High byte of result - lda cursor ; Get old value - sty cursor ; Set new value - rts -.endproc - diff --git a/libsrc/mega65/kbhit.s b/libsrc/mega65/kbhit.s index b88b0f48a..683451b03 100644 --- a/libsrc/mega65/kbhit.s +++ b/libsrc/mega65/kbhit.s @@ -1,17 +1,7 @@ - ; FIXME: is $d610 mega65 specific? ; FIXME: this should rather use the kernal (with keyboard buffer etc) - .export _cgetc -_cgetc: - -: lda $d610 - beq :- - ldx #0 - stx $d610 - rts - .export _kbhit _kbhit: lda $d610 From f8b1691effefb9492720b03ffd4fe7784d13a6a9 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 25 Jun 2025 21:48:25 +0200 Subject: [PATCH 22/27] prepare vic3 header --- include/_vic3.h | 188 +++++++++++++++++++++++++++++++++++++++++++++++ include/c65.h | 2 +- include/mega65.h | 2 +- 3 files changed, 190 insertions(+), 2 deletions(-) create mode 100644 include/_vic3.h diff --git a/include/_vic3.h b/include/_vic3.h new file mode 100644 index 000000000..820591656 --- /dev/null +++ b/include/_vic3.h @@ -0,0 +1,188 @@ +/*****************************************************************************/ +/* */ +/* _vic3.h */ +/* */ +/* Internal include file, do not use directly */ +/* */ +/* */ +/* */ +/* (C) 1998-2012, Ullrich von Bassewitz */ +/* Roemerstrasse 52 */ +/* D-70794 Filderstadt */ +/* EMail: uz@cc65.org */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + + + +#ifndef __VIC3_H +#define __VIC3_H + +/* FIXME: only VIC2 registers right now */ + +/* Define a structure with the vic register offsets. In cc65 mode, there +** are aliases for the field accessible as arrays. +*/ +#if __CC65_STD__ == __CC65_STD_CC65__ +struct __vic3 { + union { + struct { + unsigned char spr0_x; /* Sprite 0, X coordinate */ + unsigned char spr0_y; /* Sprite 0, Y coordinate */ + unsigned char spr1_x; /* Sprite 1, X coordinate */ + unsigned char spr1_y; /* Sprite 1, Y coordinate */ + unsigned char spr2_x; /* Sprite 2, X coordinate */ + unsigned char spr2_y; /* Sprite 2, Y coordinate */ + unsigned char spr3_x; /* Sprite 3, X coordinate */ + unsigned char spr3_y; /* Sprite 3, Y coordinate */ + unsigned char spr4_x; /* Sprite 4, X coordinate */ + unsigned char spr4_y; /* Sprite 4, Y coordinate */ + unsigned char spr5_x; /* Sprite 5, X coordinate */ + unsigned char spr5_y; /* Sprite 5, Y coordinate */ + unsigned char spr6_x; /* Sprite 6, X coordinate */ + unsigned char spr6_y; /* Sprite 6, Y coordinate */ + unsigned char spr7_x; /* Sprite 7, X coordinate */ + unsigned char spr7_y; /* Sprite 7, Y coordinate */ + }; + struct { + unsigned char x; /* X coordinate */ + unsigned char y; /* Y coordinate */ + } spr_pos[8]; + }; + unsigned char spr_hi_x; /* High bits of X coordinate */ + unsigned char ctrl1; /* Control register 1 */ + unsigned char rasterline; /* Current raster line */ + union { + struct { + unsigned char strobe_x; /* Light pen, X position */ + unsigned char strobe_y; /* Light pen, Y position */ + }; + struct { + unsigned char x; /* Light pen, X position */ + unsigned char y; /* Light pen, Y position */ + } strobe; + }; + unsigned char spr_ena; /* Enable sprites */ + unsigned char ctrl2; /* Control register 2 */ + unsigned char spr_exp_y; /* Expand sprites in Y dir */ + unsigned char addr; /* Address of chargen and video ram */ + unsigned char irr; /* Interrupt request register */ + unsigned char imr; /* Interrupt mask register */ + unsigned char spr_bg_prio; /* Priority to background */ + unsigned char spr_mcolor; /* Sprite multicolor bits */ + unsigned char spr_exp_x; /* Expand sprites in X dir */ + unsigned char spr_coll; /* Sprite/sprite collision reg */ + unsigned char spr_bg_coll; /* Sprite/background collision reg */ + unsigned char bordercolor; /* Border color */ + union { + struct { + unsigned char bgcolor0; /* Background color 0 */ + unsigned char bgcolor1; /* Background color 1 */ + unsigned char bgcolor2; /* Background color 2 */ + unsigned char bgcolor3; /* Background color 3 */ + }; + unsigned char bgcolor[4]; /* Background colors */ + }; + union { + struct { + unsigned char spr_mcolor0; /* Color 0 for multicolor sprites */ + unsigned char spr_mcolor1; /* Color 1 for multicolor sprites */ + }; + /* spr_color is already used ... */ + unsigned char spr_mcolors[2]; /* Color for multicolor sprites */ + }; + union { + struct { + unsigned char spr0_color; /* Color sprite 0 */ + unsigned char spr1_color; /* Color sprite 1 */ + unsigned char spr2_color; /* Color sprite 2 */ + unsigned char spr3_color; /* Color sprite 3 */ + unsigned char spr4_color; /* Color sprite 4 */ + unsigned char spr5_color; /* Color sprite 5 */ + unsigned char spr6_color; /* Color sprite 6 */ + unsigned char spr7_color; /* Color sprite 7 */ + }; + unsigned char spr_color[8]; /* Colors for the sprites */ + }; + + /* The following ones are only valid in the C128: */ + unsigned char x_kbd; /* Additional keyboard lines */ + unsigned char clock; /* Clock switch bit */ +}; +#else +struct __vic3 { + unsigned char spr0_x; /* Sprite 0, X coordinate */ + unsigned char spr0_y; /* Sprite 0, Y coordinate */ + unsigned char spr1_x; /* Sprite 1, X coordinate */ + unsigned char spr1_y; /* Sprite 1, Y coordinate */ + unsigned char spr2_x; /* Sprite 2, X coordinate */ + unsigned char spr2_y; /* Sprite 2, Y coordinate */ + unsigned char spr3_x; /* Sprite 3, X coordinate */ + unsigned char spr3_y; /* Sprite 3, Y coordinate */ + unsigned char spr4_x; /* Sprite 4, X coordinate */ + unsigned char spr4_y; /* Sprite 4, Y coordinate */ + unsigned char spr5_x; /* Sprite 5, X coordinate */ + unsigned char spr5_y; /* Sprite 5, Y coordinate */ + unsigned char spr6_x; /* Sprite 6, X coordinate */ + unsigned char spr6_y; /* Sprite 6, Y coordinate */ + unsigned char spr7_x; /* Sprite 7, X coordinate */ + unsigned char spr7_y; /* Sprite 7, Y coordinate */ + unsigned char spr_hi_x; /* High bits of X coordinate */ + unsigned char ctrl1; /* Control register 1 */ + unsigned char rasterline; /* Current raster line */ + unsigned char strobe_x; /* Light pen, X position */ + unsigned char strobe_y; /* Light pen, Y position */ + unsigned char spr_ena; /* Enable sprites */ + unsigned char ctrl2; /* Control register 2 */ + unsigned char spr_exp_y; /* Expand sprites in Y dir */ + unsigned char addr; /* Address of chargen and video ram */ + unsigned char irr; /* Interrupt request register */ + unsigned char imr; /* Interrupt mask register */ + unsigned char spr_bg_prio; /* Priority to background */ + unsigned char spr_mcolor; /* Sprite multicolor bits */ + unsigned char spr_exp_x; /* Expand sprites in X dir */ + unsigned char spr_coll; /* Sprite/sprite collision reg */ + unsigned char spr_bg_coll; /* Sprite/background collision reg */ + unsigned char bordercolor; /* Border color */ + unsigned char bgcolor0; /* Background color 0 */ + unsigned char bgcolor1; /* Background color 1 */ + unsigned char bgcolor2; /* Background color 2 */ + unsigned char bgcolor3; /* Background color 3 */ + unsigned char spr_mcolor0; /* Color 0 for multicolor sprites */ + unsigned char spr_mcolor1; /* Color 1 for multicolor sprites */ + unsigned char spr0_color; /* Color sprite 0 */ + unsigned char spr1_color; /* Color sprite 1 */ + unsigned char spr2_color; /* Color sprite 2 */ + unsigned char spr3_color; /* Color sprite 3 */ + unsigned char spr4_color; /* Color sprite 4 */ + unsigned char spr5_color; /* Color sprite 5 */ + unsigned char spr6_color; /* Color sprite 6 */ + unsigned char spr7_color; /* Color sprite 7 */ +}; +#endif + + + +/* End of _vic3.h */ +#endif + + + diff --git a/include/c65.h b/include/c65.h index 5ba485978..34270be03 100644 --- a/include/c65.h +++ b/include/c65.h @@ -100,7 +100,7 @@ /* Define hardware */ -#include <_vic2.h> +#include <_vic3.h> #define VIC (*(struct __vic2*)0xD000) #include <_sid.h> diff --git a/include/mega65.h b/include/mega65.h index 9f13d2e6c..83d48606d 100644 --- a/include/mega65.h +++ b/include/mega65.h @@ -100,7 +100,7 @@ /* Define hardware */ -#include <_vic2.h> +#include <_vic3.h> #define VIC (*(struct __vic2*)0xD000) #include <_sid.h> From 38bdb2326bddc8e8baf20596e6a487de0d675f4e Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 25 Jun 2025 23:14:08 +0200 Subject: [PATCH 23/27] added a simple joystick api example, since we didn't have one. --- samples/Makefile | 31 ++++++++++++---- samples/joydemo.c | 91 +++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 samples/joydemo.c diff --git a/samples/Makefile b/samples/Makefile index 7d506e135..6c00c97a4 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -84,10 +84,12 @@ ifneq ($(filter disk samples.%,$(MAKECMDGOALS)),) EMD := $(wildcard $(TARGET_PATH)/$(SYS)/drv/emd/*) MOU := $(wildcard $(TARGET_PATH)/$(SYS)/drv/mou/*) TGI := $(wildcard $(TARGET_PATH)/$(SYS)/drv/tgi/*) + JOY := $(wildcard $(TARGET_PATH)/$(SYS)/drv/joy/*) EMD := $(addprefix $(SUBST_TARGET_PATH)/$(SYS)/drv/emd/,$(notdir $(filter %.emd,$(EMD)))) MOU := $(addprefix $(SUBST_TARGET_PATH)/$(SYS)/drv/mou/,$(notdir $(filter %.mou,$(MOU)))) TGI := $(addprefix $(SUBST_TARGET_PATH)/$(SYS)/drv/tgi/,$(notdir $(filter %.tgi,$(TGI)))) + JOY := $(addprefix $(SUBST_TARGET_PATH)/$(SYS)/drv/joy/,$(notdir $(filter %.joy,$(JOY)))) # This one comes with the VICE emulator. # See http://vice-emu.sourceforge.net/ @@ -180,6 +182,7 @@ EXELIST_apple2 = \ enumdevdir \ gunzip65 \ hello \ + joydemo \ mandelbrot \ mousedemo \ multdemo \ @@ -213,10 +216,14 @@ EXELIST_atari2600 = \ EXELIST_atari5200 = \ notavailable +EXELIST_atari7800 = \ + notavailable + EXELIST_atmos = \ ascii \ checkversion \ hello \ + joydemo \ mandelbrot \ sieve \ terminal \ @@ -231,6 +238,7 @@ EXELIST_c64 = \ enumdevdir \ gunzip65 \ hello \ + joydemo \ mandelbrot \ mousedemo \ multdemo \ @@ -254,6 +262,7 @@ EXELIST_c128 = \ enumdevdir \ gunzip65 \ hello \ + joydemo \ mandelbrot \ mousedemo \ sieve \ @@ -266,13 +275,15 @@ EXELIST_c16 = \ checkversion \ enumdevdir \ tinyshell \ - hello + hello \ + joydemo EXELIST_cbm510 = \ ascii \ checkversion \ gunzip65 \ hello \ + joydemo \ mousedemo \ terminal \ tinyshell \ @@ -297,6 +308,7 @@ EXELIST_cx16 = \ enumdevdir \ gunzip65 \ hello \ + joydemo \ mandelbrot \ mousedemo \ sieve \ @@ -308,7 +320,6 @@ EXELIST_gamate = \ EXELIST_geos-cbm = \ ascii \ - checkversion \ diodemo EXELIST_geos-apple = \ @@ -329,19 +340,22 @@ EXELIST_mega65 = \ tinyshell EXELIST_nes = \ - hello + hello \ + joydemo EXELIST_osic1p = \ notavailable EXELIST_pce = \ - hello + hello \ + joydemo EXELIST_pet = \ ascii \ checkversion \ enumdevdir \ hello \ + joydemo \ tinyshell \ sieve @@ -351,6 +365,7 @@ EXELIST_plus4 = \ enumdevdir \ gunzip65 \ hello \ + joydemo \ mandelbrot \ terminal \ tinyshell \ @@ -377,6 +392,7 @@ EXELIST_telestrat = \ checkversion \ gunzip65 \ hello \ + joydemo \ mandelbrot \ sieve \ tgidemo @@ -386,6 +402,7 @@ EXELIST_vic20 = \ checkversion \ enumdevdir \ hello \ + joydemo \ mandelbrot \ sieve \ tgidemo @@ -541,7 +558,7 @@ samples.d64: samples @$(C1541) -format "samples,00" d64 $@ >$(NULLDEV) $(foreach file,$(EXELIST_$(SYS)),$(D64_WRITE_PRG_recipe)) $(foreach file,$(OVERLAYLIST),$(D64_WRITE_PRG_recipe)) - $(foreach file,$(EMD) $(MOU) $(TGI),$(D64_WRITE_SEQ_recipe)) + $(foreach file,$(EMD) $(MOU) $(JOY) $(TGI),$(D64_WRITE_SEQ_recipe)) # -------------------------------------------------------------------------- # Rule to make an Apple II disk with all samples. Needs the AppleCommander @@ -566,7 +583,7 @@ samples.dsk: samples cp prodos.dsk $@ $(foreach file,$(EXELIST_$(SYS)),$(DSK_WRITE_BIN_recipe)) $(foreach file,$(OVERLAYLIST),$(DSK_WRITE_REL_recipe)) - $(foreach file,$(EMD) $(MOU) $(TGI),$(DSK_WRITE_REL_recipe)) + $(foreach file,$(EMD) $(MOU) $(JOY) $(TGI),$(DSK_WRITE_REL_recipe)) # -------------------------------------------------------------------------- # Rule to make an Atari disk with all samples. Needs the dir2atr program @@ -585,7 +602,7 @@ samples.atr: samples cp "dup.sys" atr/dup.sys @$(foreach file,$(EXELIST_$(SYS)),$(ATR_WRITE_recipe)) @$(foreach file,$(OVERLAYLIST),$(ATR_WRITE_recipe)) - @$(foreach file,$(EMD) $(MOU) $(TGI),$(ATR_WRITE_recipe)) + @$(foreach file,$(EMD) $(MOU) $(JOY) $(TGI),$(ATR_WRITE_recipe)) $(DIR2ATR) -d -b MyDos4534 3200 $@ atr @$(RMDIR) atr diff --git a/samples/joydemo.c b/samples/joydemo.c new file mode 100644 index 000000000..807c16a08 --- /dev/null +++ b/samples/joydemo.c @@ -0,0 +1,91 @@ + +#include +#include +#include + +#ifndef DYN_DRV +# define DYN_DRV 1 +#endif + +#define USECONIO + +#ifdef USECONIO +#include +#define PRINTF cprintf +#define CR "\n\r" +#else +#define PRINTF printf +#define CR "\n" +#endif + +int main (void) +{ + unsigned char num_joy; + unsigned char raw_value; + unsigned char i; + unsigned char err; + unsigned char y; +#ifdef USECONIO + clrscr(); +#endif + PRINTF("Driver init..." CR); + +#if DYN_DRV + /* Load and initialize the driver */ + if ((err = joy_load_driver (joy_stddrv))) { + PRINTF ("Driver load error (code %d)." CR + "Warning: This program needs the JOY" CR + "driver on disk!" CR, err); + exit (EXIT_FAILURE); + } + PRINTF("Driver loaded OK" CR); +#else + /* Install the driver */ + joy_install (joy_static_stddrv); +#endif + + num_joy = joy_count(); + + PRINTF("Driver reported %d joysticks." CR "waiting for input..." CR, num_joy); + + /* wait for something to happen on any joystick input */ + { + unsigned char wait = 1; + while (wait) { + for (i = 0; i < num_joy; ++i) { + raw_value = joy_read(i); + if (raw_value) { + wait = 0; + break; + } + } + } + } + + /* read all joysticks and print the raw value(s) */ +#ifdef USECONIO + y = wherey(); +#endif + while (1) { +#ifdef USECONIO + gotoxy(0, y); +#endif + for (i = 0; i < num_joy; ++i) { + raw_value = joy_read(i); + PRINTF("%02x ", raw_value); + } + PRINTF(CR); + } + +#if DYN_DRV + /* Unload the driver */ + joy_unload (); +#else + /* Uninstall the driver */ + joy_uninstall (); +#endif + + /* Done */ + PRINTF ("Done" CR); + return EXIT_SUCCESS; +} From ad4d86bbf29476c191ad243b3361c3f3720d9dc4 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 25 Jun 2025 23:44:07 +0200 Subject: [PATCH 24/27] add a standard joystick driver, adapted from the c64 one --- libsrc/c65/joy/c65-stdjoy.s | 111 ++++++++++++++++++++++++++++++++ libsrc/c65/joy_stat_stddrv.s | 14 ++++ libsrc/c65/joy_stddrv.s | 14 ++++ libsrc/c65/libref.s | 8 +++ libsrc/mega65/joy/m65-stdjoy.s | 111 ++++++++++++++++++++++++++++++++ libsrc/mega65/joy_stat_stddrv.s | 14 ++++ libsrc/mega65/joy_stddrv.s | 14 ++++ libsrc/mega65/libref.s | 8 +++ 8 files changed, 294 insertions(+) create mode 100644 libsrc/c65/joy/c65-stdjoy.s create mode 100644 libsrc/c65/joy_stat_stddrv.s create mode 100644 libsrc/c65/joy_stddrv.s create mode 100644 libsrc/c65/libref.s create mode 100644 libsrc/mega65/joy/m65-stdjoy.s create mode 100644 libsrc/mega65/joy_stat_stddrv.s create mode 100644 libsrc/mega65/joy_stddrv.s create mode 100644 libsrc/mega65/libref.s diff --git a/libsrc/c65/joy/c65-stdjoy.s b/libsrc/c65/joy/c65-stdjoy.s new file mode 100644 index 000000000..1723c916a --- /dev/null +++ b/libsrc/c65/joy/c65-stdjoy.s @@ -0,0 +1,111 @@ +; +; Standard joystick driver for the C65. May be used multiple times when linked +; to the statically application. +; +; Ullrich von Bassewitz, 2002-12-20 +; + + .include "zeropage.inc" + + .include "joy-kernel.inc" + .include "joy-error.inc" + .include "c65.inc" + + .macpack generic + .macpack module + + +; ------------------------------------------------------------------------ +; Header. Includes jump table + + module_header _c65_stdjoy_joy + +; Driver signature + + .byte $6A, $6F, $79 ; "joy" + .byte JOY_API_VERSION ; Driver API version number + +; Library reference + + .addr $0000 + +; Jump table. + + .addr INSTALL + .addr UNINSTALL + .addr COUNT + .addr READ + +; ------------------------------------------------------------------------ +; Constants + +JOY_COUNT = 2 ; Number of joysticks we support + + +; ------------------------------------------------------------------------ +; Data. + + +.code + +; ------------------------------------------------------------------------ +; INSTALL routine. Is called after the driver is loaded into memory. If +; possible, check if the hardware is present and determine the amount of +; memory available. +; Must return an JOY_ERR_xx code in a/x. +; + +INSTALL: + lda #JOY_ERR_OK + .assert JOY_ERR_OK = 0, error + tax + +; rts ; Run into UNINSTALL instead + +; ------------------------------------------------------------------------ +; UNINSTALL routine. Is called before the driver is removed from memory. +; Can do cleanup or whatever. Must not return anything. +; + +UNINSTALL: + rts + + +; ------------------------------------------------------------------------ +; COUNT: Return the total number of available joysticks in a/x. +; + +COUNT: + lda #JOY_COUNT + rts + +; ------------------------------------------------------------------------ +; READ: Read a particular joystick passed in A. +; + +READ: tax ; Joystick number into X + bne joy2 + +; Read joystick 1 + +joy1: lda #$7F + sei + sta CIA1_PRA + lda CIA1_PRB + cli + jmp end + +; Read joystick 2 + +joy2: ldx #0 + lda #$E0 + ldy #$FF + sei + sta CIA1_DDRA + lda CIA1_PRA + sty CIA1_DDRA + cli +end: and #$1F + eor #$1F + rts diff --git a/libsrc/c65/joy_stat_stddrv.s b/libsrc/c65/joy_stat_stddrv.s new file mode 100644 index 000000000..3a4deffcd --- /dev/null +++ b/libsrc/c65/joy_stat_stddrv.s @@ -0,0 +1,14 @@ +; +; Address of the static standard joystick driver +; +; Oliver Schmidt, 2012-11-01 +; +; const void joy_static_stddrv[]; +; + + .export _joy_static_stddrv + .import _c65_stdjoy_joy + +.rodata + +_joy_static_stddrv := _c65_stdjoy_joy diff --git a/libsrc/c65/joy_stddrv.s b/libsrc/c65/joy_stddrv.s new file mode 100644 index 000000000..4232d9647 --- /dev/null +++ b/libsrc/c65/joy_stddrv.s @@ -0,0 +1,14 @@ +; +; Name of the standard joystick driver +; +; Ullrich von Bassewitz, 2002-12-21 +; +; const char joy_stddrv[]; +; + + .export _joy_stddrv + +.rodata + +_joy_stddrv: .asciiz "c65-stdjoy.joy" + diff --git a/libsrc/c65/libref.s b/libsrc/c65/libref.s new file mode 100644 index 000000000..e4afa7eb1 --- /dev/null +++ b/libsrc/c65/libref.s @@ -0,0 +1,8 @@ +; +; Oliver Schmidt, 2013-05-31 +; + + .export joy_libref + .import _exit + +joy_libref := _exit diff --git a/libsrc/mega65/joy/m65-stdjoy.s b/libsrc/mega65/joy/m65-stdjoy.s new file mode 100644 index 000000000..d266745d9 --- /dev/null +++ b/libsrc/mega65/joy/m65-stdjoy.s @@ -0,0 +1,111 @@ +; +; Standard joystick driver for the C64. May be used multiple times when linked +; to the statically application. +; +; Ullrich von Bassewitz, 2002-12-20 +; + + .include "zeropage.inc" + + .include "joy-kernel.inc" + .include "joy-error.inc" + .include "mega65.inc" + + .macpack generic + .macpack module + + +; ------------------------------------------------------------------------ +; Header. Includes jump table + + module_header _mega65_stdjoy_joy + +; Driver signature + + .byte $6A, $6F, $79 ; "joy" + .byte JOY_API_VERSION ; Driver API version number + +; Library reference + + .addr $0000 + +; Jump table. + + .addr INSTALL + .addr UNINSTALL + .addr COUNT + .addr READ + +; ------------------------------------------------------------------------ +; Constants + +JOY_COUNT = 2 ; Number of joysticks we support + + +; ------------------------------------------------------------------------ +; Data. + + +.code + +; ------------------------------------------------------------------------ +; INSTALL routine. Is called after the driver is loaded into memory. If +; possible, check if the hardware is present and determine the amount of +; memory available. +; Must return an JOY_ERR_xx code in a/x. +; + +INSTALL: + lda #JOY_ERR_OK + .assert JOY_ERR_OK = 0, error + tax + +; rts ; Run into UNINSTALL instead + +; ------------------------------------------------------------------------ +; UNINSTALL routine. Is called before the driver is removed from memory. +; Can do cleanup or whatever. Must not return anything. +; + +UNINSTALL: + rts + + +; ------------------------------------------------------------------------ +; COUNT: Return the total number of available joysticks in a/x. +; + +COUNT: + lda #JOY_COUNT + rts + +; ------------------------------------------------------------------------ +; READ: Read a particular joystick passed in A. +; + +READ: tax ; Joystick number into X + bne joy2 + +; Read joystick 1 + +joy1: lda #$7F + sei + sta CIA1_PRA + lda CIA1_PRB + cli + jmp end + +; Read joystick 2 + +joy2: ldx #0 + lda #$E0 + ldy #$FF + sei + sta CIA1_DDRA + lda CIA1_PRA + sty CIA1_DDRA + cli +end: and #$1F + eor #$1F + rts diff --git a/libsrc/mega65/joy_stat_stddrv.s b/libsrc/mega65/joy_stat_stddrv.s new file mode 100644 index 000000000..492d84eb0 --- /dev/null +++ b/libsrc/mega65/joy_stat_stddrv.s @@ -0,0 +1,14 @@ +; +; Address of the static standard joystick driver +; +; Oliver Schmidt, 2012-11-01 +; +; const void joy_static_stddrv[]; +; + + .export _joy_static_stddrv + .import _mega65_stdjoy_joy + +.rodata + +_joy_static_stddrv := _mega65_stdjoy_joy diff --git a/libsrc/mega65/joy_stddrv.s b/libsrc/mega65/joy_stddrv.s new file mode 100644 index 000000000..97c7c7501 --- /dev/null +++ b/libsrc/mega65/joy_stddrv.s @@ -0,0 +1,14 @@ +; +; Name of the standard joystick driver +; +; Ullrich von Bassewitz, 2002-12-21 +; +; const char joy_stddrv[]; +; + + .export _joy_stddrv + +.rodata + +_joy_stddrv: .asciiz "m65-stdjoy.joy" + diff --git a/libsrc/mega65/libref.s b/libsrc/mega65/libref.s new file mode 100644 index 000000000..e4afa7eb1 --- /dev/null +++ b/libsrc/mega65/libref.s @@ -0,0 +1,8 @@ +; +; Oliver Schmidt, 2013-05-31 +; + + .export joy_libref + .import _exit + +joy_libref := _exit From 1b815d4148e084600513c7de2a359682e8285f79 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Wed, 25 Jun 2025 23:52:59 +0200 Subject: [PATCH 25/27] add joydemo to c65/mega65 samples, it works when driver is statically linked --- samples/Makefile | 10 ++++++++++ samples/joydemo.c | 7 +++++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/samples/Makefile b/samples/Makefile index 6c00c97a4..267e253ff 100644 --- a/samples/Makefile +++ b/samples/Makefile @@ -108,6 +108,8 @@ DISK_apple2enh = samples.dsk DISK_atari = samples.atr DISK_atarixl = samples.atr DISK_plus4 = samples.d64 +DISK_c65 = samples.d81 +DISK_mega65 = samples.d81 # -------------------------------------------------------------------------- # System-dependent settings @@ -253,6 +255,7 @@ EXELIST_c65 = \ checkversion \ enumdevdir \ hello \ + joydemo \ sieve \ tinyshell @@ -336,6 +339,7 @@ EXELIST_mega65 = \ checkversion \ enumdevdir \ hello \ + joydemo \ sieve \ tinyshell @@ -560,6 +564,12 @@ samples.d64: samples $(foreach file,$(OVERLAYLIST),$(D64_WRITE_PRG_recipe)) $(foreach file,$(EMD) $(MOU) $(JOY) $(TGI),$(D64_WRITE_SEQ_recipe)) +samples.d81: samples + @$(C1541) -format "samples,00" d81 $@ >$(NULLDEV) + $(foreach file,$(EXELIST_$(SYS)),$(D64_WRITE_PRG_recipe)) + $(foreach file,$(OVERLAYLIST),$(D64_WRITE_PRG_recipe)) + $(foreach file,$(EMD) $(MOU) $(JOY) $(TGI),$(D64_WRITE_SEQ_recipe)) + # -------------------------------------------------------------------------- # Rule to make an Apple II disk with all samples. Needs the AppleCommander # program, available at https://applecommander.github.io/, and a template disk diff --git a/samples/joydemo.c b/samples/joydemo.c index 807c16a08..56e825541 100644 --- a/samples/joydemo.c +++ b/samples/joydemo.c @@ -3,6 +3,9 @@ #include #include +/* define 0 to link the standard driver statically */ +/* #define DYN_DRV 0 */ + #ifndef DYN_DRV # define DYN_DRV 1 #endif @@ -31,7 +34,7 @@ int main (void) PRINTF("Driver init..." CR); #if DYN_DRV - /* Load and initialize the driver */ + /* Load and initialize the standard driver driver */ if ((err = joy_load_driver (joy_stddrv))) { PRINTF ("Driver load error (code %d)." CR "Warning: This program needs the JOY" CR @@ -40,7 +43,7 @@ int main (void) } PRINTF("Driver loaded OK" CR); #else - /* Install the driver */ + /* Install the standard driver */ joy_install (joy_static_stddrv); #endif From b1a123b601a6ac42d7c0c7754101b876d072a35d Mon Sep 17 00:00:00 2001 From: mrdudz Date: Thu, 26 Jun 2025 02:10:15 +0200 Subject: [PATCH 26/27] fix c65 lib, remove includes from cbm generic lib --- libsrc/c65/cpeekrevers.s | 28 ++++++++++++++++++++++++++++ libsrc/c65/cputc.s | 1 - libsrc/cbm/cpeekrevers.s | 4 ---- 3 files changed, 28 insertions(+), 5 deletions(-) create mode 100644 libsrc/c65/cpeekrevers.s diff --git a/libsrc/c65/cpeekrevers.s b/libsrc/c65/cpeekrevers.s new file mode 100644 index 000000000..4fef17340 --- /dev/null +++ b/libsrc/c65/cpeekrevers.s @@ -0,0 +1,28 @@ +; +; 2016-02-28, Groepaz +; 2017-06-15, Greg King +; +; unsigned char cpeekrevers (void); +; + + .include "c65.inc" + + .export _cpeekrevers + .importzp ptr1 + +_cpeekrevers: + lda SCREEN_PTR + 1 + clc + adc #>$0800 + sta ptr1 + 1 + lda SCREEN_PTR + sta ptr1 + + ldy CURS_X + lda (ptr1),y ; get screen code + and #$80 ; get reverse bit + asl a + tax ; ldx #>$0000 + rol a ; return boolean value + + rts diff --git a/libsrc/c65/cputc.s b/libsrc/c65/cputc.s index d9f63c1dd..1a8dd1fee 100644 --- a/libsrc/c65/cputc.s +++ b/libsrc/c65/cputc.s @@ -13,7 +13,6 @@ .include "c65.inc" - _cputcxy: pha ; Save C jsr gotoxy ; Set cursor, drop x and y diff --git a/libsrc/cbm/cpeekrevers.s b/libsrc/cbm/cpeekrevers.s index 0e500605d..e8e210167 100644 --- a/libsrc/cbm/cpeekrevers.s +++ b/libsrc/cbm/cpeekrevers.s @@ -22,10 +22,6 @@ .include "pet.inc" .elseif .def(__VIC20__) .include "vic20.inc" -.elseif .def(__C65__) - .include "c65.inc" -.elseif .def(__MEGA65__) - .include "mega65.inc" .endif From 2de056167a8e0935a8b64e7819821951343344c3 Mon Sep 17 00:00:00 2001 From: mrdudz Date: Thu, 26 Jun 2025 02:16:05 +0200 Subject: [PATCH 27/27] fix warnings --- samples/checkversion.c | 2 ++ samples/joydemo.c | 4 +++- 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/samples/checkversion.c b/samples/checkversion.c index 9d88cecd3..0e2359f91 100644 --- a/samples/checkversion.c +++ b/samples/checkversion.c @@ -43,10 +43,12 @@ int main(void) printf("__CC65__ defined as %04x\n", __CC65__); printf("compiler version is %u.%u\n", VER_MAJOR, VER_MINOR); +#pragma warn (const-comparison, push, off) if (__CC65__ == VERSION) { printf("__CC65__ is defined correctly as (VER_MAJOR * 0x100) + VER_MINOR\n"); return EXIT_SUCCESS; } +#pragma warn (const-comparison, pop) printf("__CC65__ is incorrectly defined as (VER_MAJOR * 0x100) + (VER_MINOR * 0x10)\n"); return EXIT_FAILURE; } diff --git a/samples/joydemo.c b/samples/joydemo.c index 56e825541..7375f23d3 100644 --- a/samples/joydemo.c +++ b/samples/joydemo.c @@ -26,9 +26,11 @@ int main (void) unsigned char num_joy; unsigned char raw_value; unsigned char i; +#if DYN_DRV unsigned char err; - unsigned char y; +#endif #ifdef USECONIO + unsigned char y; clrscr(); #endif PRINTF("Driver init..." CR);