From d0bee35728a55148fea9bd8d90bfef36b7e7de86 Mon Sep 17 00:00:00 2001 From: cuz Date: Sat, 26 Feb 2005 09:28:46 +0000 Subject: [PATCH] Move constructor code into the INIT segment git-svn-id: svn://svn.cc65.org/cc65/trunk@3405 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- libsrc/atmos/cgetc.s | 5 +++- libsrc/atmos/mainargs.s | 5 +++- libsrc/c128/cgetc.s | 31 +++++++++++------------ libsrc/c128/cputc.s | 6 ++++- libsrc/c128/mainargs.s | 9 ++++--- libsrc/c16/cgetc.s | 4 +++ libsrc/c16/mainargs.s | 13 ++++++---- libsrc/c64/mainargs.s | 9 ++++--- libsrc/cbm/read.s | 3 +++ libsrc/cbm/write.s | 5 +++- libsrc/cbm510/mainargs.s | 5 +++- libsrc/cbm610/mainargs.s | 5 +++- libsrc/geos/conio/_scrsize.s | 6 ++--- libsrc/geos/devel/mainargs.s | 2 ++ libsrc/lynx/Makefile | 3 ++- libsrc/lynx/cartread.s | 49 ++++++++++++++++++++++++++++++++++++ libsrc/lynx/mainargs.s | 5 +++- libsrc/nes/cputc.s | 17 ++++++++----- libsrc/nes/mainargs.s | 5 +++- libsrc/pet/mainargs.s | 5 +++- libsrc/plus4/cgetc.s | 2 +- libsrc/plus4/mainargs.s | 20 +++++++++------ libsrc/vic20/mainargs.s | 11 +++++--- 23 files changed, 166 insertions(+), 59 deletions(-) create mode 100644 libsrc/lynx/cartread.s diff --git a/libsrc/atmos/cgetc.s b/libsrc/atmos/cgetc.s index e8f96abb3..988302138 100644 --- a/libsrc/atmos/cgetc.s +++ b/libsrc/atmos/cgetc.s @@ -49,7 +49,10 @@ .endproc ; ------------------------------------------------------------------------ -; Switch the cursor off, disable capslock +; Switch the cursor off, disable capslock. Code goes into the INIT segment +; which may be reused after it is run. + +.segment "INIT" initcgetc: lda STATUS diff --git a/libsrc/atmos/mainargs.s b/libsrc/atmos/mainargs.s index ebe6d0348..a9233382f 100644 --- a/libsrc/atmos/mainargs.s +++ b/libsrc/atmos/mainargs.s @@ -10,7 +10,10 @@ ;--------------------------------------------------------------------------- -; Setup arguments for main +; Get possible command-line arguments. Goes into the special INIT segment, +; which may be reused after the startup code is run + +.segment "INIT" .proc initmainargs diff --git a/libsrc/c128/cgetc.s b/libsrc/c128/cgetc.s index 01a5ff0e0..f3f62ff53 100644 --- a/libsrc/c128/cgetc.s +++ b/libsrc/c128/cgetc.s @@ -40,32 +40,31 @@ L2: lda KEY_COUNT ; Check characters again .bss keyvec: .res 2 -.code +.segment "INIT" initcgetc: ; Save the old vector - lda KeyStoreVec - sta keyvec - lda KeyStoreVec+1 - sta keyvec+1 + lda KeyStoreVec + sta keyvec + lda KeyStoreVec+1 + sta keyvec+1 ; Set the new vector. I can only hope that this works for other C128 ; versions... - lda #<$C6B7 - ldx #>$C6B7 - -SetVec: sei - sta KeyStoreVec - stx KeyStoreVec+1 - cli - rts + lda #<$C6B7 + ldx #>$C6B7 + jmp SetVec +.code donecgetc: - lda #$00 - sta SCROLL lda keyvec ldx keyvec+1 - bne SetVec +SetVec: sei + sta KeyStoreVec + stx KeyStoreVec+1 + cli + rts + diff --git a/libsrc/c128/cputc.s b/libsrc/c128/cputc.s index 5c761118f..5442e9f57 100644 --- a/libsrc/c128/cputc.s +++ b/libsrc/c128/cputc.s @@ -18,6 +18,9 @@ cputdirect = PRINT newline = NEWLINE +;-------------------------------------------------------------------------- + +.code _cputcxy: pha ; Save C @@ -75,7 +78,8 @@ plot: ldy CURS_X putchar = $CC2F ;-------------------------------------------------------------------------- -; Module constructor/destructor +; Module constructor/destructor. Don't move the constructor into the INIT +; segment, because it shares most of the code with the destructor. initcputc: lda #$C0 diff --git a/libsrc/c128/mainargs.s b/libsrc/c128/mainargs.s index a3e33e936..3bacd2934 100644 --- a/libsrc/c128/mainargs.s +++ b/libsrc/c128/mainargs.s @@ -3,7 +3,7 @@ ; Ullrich von Bassewitz, 2003-03-07 ; Based on code from Stefan A. Haubenthal, ; 2003-05-18, Greg King -; 2004-04-28, Ullrich von Bassewitz +; 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. @@ -33,8 +33,11 @@ REM = $8f ; BASIC token-code NAME_LEN = 16 ; maximum length of command-name -; Get possible command-line arguments. -; +; Get possible command-line arguments. Goes into the special INIT segment, +; which may be reused after the startup code is run + +.segment "INIT" + initmainargs: ; Assume that the program was loaded, a moment ago, by the traditional LOAD diff --git a/libsrc/c16/cgetc.s b/libsrc/c16/cgetc.s index 8d10bba52..dc6e1e811 100644 --- a/libsrc/c16/cgetc.s +++ b/libsrc/c16/cgetc.s @@ -56,6 +56,8 @@ L2: jsr KBDREAD ; Read char and return in A .constructor initkbd .destructor donekbd +.segment "INIT" + .proc initkbd ldy #15 @@ -68,6 +70,8 @@ L2: jsr KBDREAD ; Read char and return in A .endproc +.code + .proc donekbd ldx #$39 ; Copy the original function keys diff --git a/libsrc/c16/mainargs.s b/libsrc/c16/mainargs.s index c567b8ceb..863c8e473 100644 --- a/libsrc/c16/mainargs.s +++ b/libsrc/c16/mainargs.s @@ -3,7 +3,7 @@ ; Ullrich von Bassewitz, 2003-03-07 ; Based on code from Stefan A. Haubenthal, ; 2003-05-18, Greg King -; 2004-04-28, Ullrich von Bassewitz +; 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. @@ -30,11 +30,14 @@ MAXARGS = 10 ; Maximum number of arguments allowed -REM = $8f ; BASIC token-code -NAME_LEN = 16 ; maximum length of command-name +REM = $8f ; BASIC token-code +NAME_LEN = 16 ; maximum length of command-name + +; Get possible command-line arguments. Goes into the special INIT segment, +; which may be reused after the startup code is run + +.segment "INIT" -; Get possible command-line arguments. -; initmainargs: ; Assume that the program was loaded, a moment ago, by the traditional LOAD diff --git a/libsrc/c64/mainargs.s b/libsrc/c64/mainargs.s index 1bee04249..6b2f624bf 100644 --- a/libsrc/c64/mainargs.s +++ b/libsrc/c64/mainargs.s @@ -3,7 +3,7 @@ ; Ullrich von Bassewitz, 2003-03-07 ; Based on code from Stefan A. Haubenthal, ; 2003-05-18, Greg King -; 2004-04-28, Ullrich von Bassewitz +; 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. @@ -33,8 +33,11 @@ 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. -; +; Get possible command-line arguments. Goes into the special INIT segment, +; which may be reused after the startup code is run + +.segment "INIT" + initmainargs: ; Assume that the program was loaded, a moment ago, by the traditional LOAD diff --git a/libsrc/cbm/read.s b/libsrc/cbm/read.s index 1e9fdbd5c..2a139bde7 100644 --- a/libsrc/cbm/read.s +++ b/libsrc/cbm/read.s @@ -20,6 +20,8 @@ ;-------------------------------------------------------------------------- ; initstdin: Open the stdin file descriptors for the keyboard + +.segment "INIT" .proc initstdin @@ -37,6 +39,7 @@ ;-------------------------------------------------------------------------- ; _read +.code .proc _read diff --git a/libsrc/cbm/write.s b/libsrc/cbm/write.s index dbdc7d8d9..46bcfe407 100644 --- a/libsrc/cbm/write.s +++ b/libsrc/cbm/write.s @@ -20,6 +20,8 @@ ;-------------------------------------------------------------------------- ; initstdout: Open the stdout and stderr file descriptors for the screen. +.segment "INIT" + .proc initstdout lda #LFN_WRITE @@ -40,7 +42,8 @@ ;-------------------------------------------------------------------------- ; _write - + +.code .proc _write diff --git a/libsrc/cbm510/mainargs.s b/libsrc/cbm510/mainargs.s index ebe6d0348..a9233382f 100644 --- a/libsrc/cbm510/mainargs.s +++ b/libsrc/cbm510/mainargs.s @@ -10,7 +10,10 @@ ;--------------------------------------------------------------------------- -; Setup arguments for main +; Get possible command-line arguments. Goes into the special INIT segment, +; which may be reused after the startup code is run + +.segment "INIT" .proc initmainargs diff --git a/libsrc/cbm610/mainargs.s b/libsrc/cbm610/mainargs.s index ebe6d0348..a9233382f 100644 --- a/libsrc/cbm610/mainargs.s +++ b/libsrc/cbm610/mainargs.s @@ -10,7 +10,10 @@ ;--------------------------------------------------------------------------- -; Setup arguments for main +; Get possible command-line arguments. Goes into the special INIT segment, +; which may be reused after the startup code is run + +.segment "INIT" .proc initmainargs diff --git a/libsrc/geos/conio/_scrsize.s b/libsrc/geos/conio/_scrsize.s index 29616c86f..b469d2a9d 100644 --- a/libsrc/geos/conio/_scrsize.s +++ b/libsrc/geos/conio/_scrsize.s @@ -6,7 +6,7 @@ ; ; 6.3.2001, 17.4.2003 - + .include "../inc/geossym.inc" .export xsize, ysize @@ -14,8 +14,8 @@ .importzp cursor_r, cursor_c .import _cursor .constructor initscrsize - -.code + +.segment "INIT" initscrsize: lda graphMode diff --git a/libsrc/geos/devel/mainargs.s b/libsrc/geos/devel/mainargs.s index 255c48807..d5ffbf3e5 100644 --- a/libsrc/geos/devel/mainargs.s +++ b/libsrc/geos/devel/mainargs.s @@ -21,6 +21,8 @@ ;--------------------------------------------------------------------------- ; Setup arguments for main +.segment "INIT" + .proc initmainargs ; Setup a pointer to our argv vector diff --git a/libsrc/lynx/Makefile b/libsrc/lynx/Makefile index b4196b8fc..62336e1d1 100644 --- a/libsrc/lynx/Makefile +++ b/libsrc/lynx/Makefile @@ -45,7 +45,8 @@ CFLAGS = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include #-------------------------------------------------------------------------- # Object files -OBJS = cgetc.o \ +OBJS = cartread.o \ + cgetc.o \ crt0.o \ ctype.o \ eeprom.o \ diff --git a/libsrc/lynx/cartread.s b/libsrc/lynx/cartread.s new file mode 100644 index 000000000..9330a0851 --- /dev/null +++ b/libsrc/lynx/cartread.s @@ -0,0 +1,49 @@ +; *** +; CC65 Lynx Library +; +; Originally by Bastian Schick +; http://www.geocities.com/SiliconValley/Byte/4242/lynx/ +; +; Ported to cc65 (http://www.cc65.org) by +; Shawn Jefferson, June 2004 +; +; *** +; +; void __fastcall__ read_cart_block(unsigned char block, char *dest) +; +; Reads an entire block (1024 bytes) from the cartridge into the buffer +; pointed to by dest. + + + .export _read_cart_block + .import FileSelectBlock, FileReadBytes + .import popa + + .include "extzp.inc" + + +.code + +;******************************************* +; void read_cart_block (unsigned char block, char *dest); +; loads one Block (1024 bytes) to pDest + +_read_cart_block: + sta _FileDestPtr ; lo + stx _FileDestPtr+1 ; hi + + jsr popa ; bBlock + + sta _FileCurrBlock + jsr FileSelectBlock ; select block# (Accu) + + lda #<1024 ; load a whole block (1024 bytes) + eor #$ff + tax + lda #>1024 + eor #$ff + tay + + jmp FileReadBytes + + diff --git a/libsrc/lynx/mainargs.s b/libsrc/lynx/mainargs.s index d6bae50d6..8b6808051 100644 --- a/libsrc/lynx/mainargs.s +++ b/libsrc/lynx/mainargs.s @@ -10,7 +10,10 @@ ;--------------------------------------------------------------------------- -; Setup arguments for main +; Get possible command-line arguments. Goes into the special INIT segment, +; which may be reused after the startup code is run + +.segment "INIT" .proc initmainargs diff --git a/libsrc/nes/cputc.s b/libsrc/nes/cputc.s index 0fcbe5d77..255b5f403 100644 --- a/libsrc/nes/cputc.s +++ b/libsrc/nes/cputc.s @@ -7,7 +7,7 @@ ; .export _cputcxy, _cputc, cputdirect, putchar - .export newline + .export newline .constructor conioinit .import popa, _gotoxy .import ppuinit, paletteinit, ppubuf_put @@ -18,12 +18,14 @@ .include "nes.inc" ;----------------------------------------------------------------------------- + +.code _cputcxy: - pha ; Save C - jsr popa ; Get Y + pha ; Save C + jsr popa ; Get Y jsr _gotoxy ; Set cursor, drop x - pla ; Restore C + pla ; Restore C ; Plot a character - also used as internal function @@ -67,13 +69,16 @@ plot: ldy CURS_X ; position in Y putchar: - ora RVS ; Set revers bit + ora RVS ; Set revers bit ldy SCREEN_PTR+1 ldx SCREEN_PTR jmp ppubuf_put ;----------------------------------------------------------------------------- -; Initialize the conio subsystem +; Initialize the conio subsystem. Code goes into the INIT segment, which may +; be reused after startup. + +.segment "INIT" conioinit: jsr ppuinit diff --git a/libsrc/nes/mainargs.s b/libsrc/nes/mainargs.s index ebe6d0348..a9233382f 100644 --- a/libsrc/nes/mainargs.s +++ b/libsrc/nes/mainargs.s @@ -10,7 +10,10 @@ ;--------------------------------------------------------------------------- -; Setup arguments for main +; Get possible command-line arguments. Goes into the special INIT segment, +; which may be reused after the startup code is run + +.segment "INIT" .proc initmainargs diff --git a/libsrc/pet/mainargs.s b/libsrc/pet/mainargs.s index ebe6d0348..a9233382f 100644 --- a/libsrc/pet/mainargs.s +++ b/libsrc/pet/mainargs.s @@ -10,7 +10,10 @@ ;--------------------------------------------------------------------------- -; Setup arguments for main +; Get possible command-line arguments. Goes into the special INIT segment, +; which may be reused after the startup code is run + +.segment "INIT" .proc initmainargs diff --git a/libsrc/plus4/cgetc.s b/libsrc/plus4/cgetc.s index 65bf26628..0a4403127 100644 --- a/libsrc/plus4/cgetc.s +++ b/libsrc/plus4/cgetc.s @@ -59,7 +59,7 @@ L2: sta ENABLE_ROM ; Bank in the ROM .constructor initkbd .destructor donekbd -.code ; Can go into the normal code segment +.segment "INIT" ; Special init code segment may get overwritten .proc initkbd diff --git a/libsrc/plus4/mainargs.s b/libsrc/plus4/mainargs.s index 7ad231a2f..7365b1478 100644 --- a/libsrc/plus4/mainargs.s +++ b/libsrc/plus4/mainargs.s @@ -3,7 +3,7 @@ ; Ullrich von Bassewitz, 2003-03-07 ; Based on code from Stefan A. Haubenthal, ; 2003-05-18, Greg King -; 2004-04-28, Ullrich von Bassewitz +; 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. @@ -26,15 +26,18 @@ .import __argc, __argv .include "plus4.inc" - + MAXARGS = 10 ; Maximum number of arguments allowed -REM = $8f ; BASIC token-code -NAME_LEN = 16 ; maximum length of command-name +REM = $8f ; BASIC token-code +NAME_LEN = 16 ; maximum length of command-name + +; Get possible command-line arguments. Goes into the special INIT segment, +; which may be reused after the startup code is run + +.segment "INIT" -; Get possible command-line arguments. -; initmainargs: ; Assume that the program was loaded, a moment ago, by the traditional LOAD @@ -117,12 +120,13 @@ argloop:lda BASIC_BUF,x ; (The last vector in argv[] already is NULL.) -done: lda #argv sta __argv stx __argv + 1 rts - + +; -------------------------------------------------------------------------- ; These arrays are zeroed before initmainargs is called. ; char name[16+1]; ; char* argv[MAXARGS+1]={name}; diff --git a/libsrc/vic20/mainargs.s b/libsrc/vic20/mainargs.s index 5857843fc..3cc1dc286 100644 --- a/libsrc/vic20/mainargs.s +++ b/libsrc/vic20/mainargs.s @@ -3,7 +3,7 @@ ; Ullrich von Bassewitz, 2003-03-07 ; Based on code from Stefan A. Haubenthal, ; 2003-05-18, Greg King -; 2004-04-28, Ullrich von Bassewitz +; 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. @@ -33,8 +33,11 @@ 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. -; +; Get possible command-line arguments. Goes into the special INIT segment, +; which may be reused after the startup code is run + +.segment "INIT" + initmainargs: ; Assume that the program was loaded, a moment ago, by the traditional LOAD @@ -100,7 +103,7 @@ argloop:lda BASIC_BUF,x 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. -- 2.39.5