Move constructor code into the INIT segment

git-svn-id: svn://svn.cc65.org/cc65/trunk@3405 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2005-02-26 09:28:46 +00:00
parent 6ec87c5dd9
commit d0bee35728
23 changed files with 166 additions and 59 deletions

View File

@@ -49,7 +49,10 @@
.endproc .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: initcgetc:
lda STATUS lda STATUS

View File

@@ -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 .proc initmainargs

View File

@@ -40,32 +40,31 @@ L2: lda KEY_COUNT ; Check characters again
.bss .bss
keyvec: .res 2 keyvec: .res 2
.code .segment "INIT"
initcgetc: initcgetc:
; Save the old vector ; Save the old vector
lda KeyStoreVec lda KeyStoreVec
sta keyvec sta keyvec
lda KeyStoreVec+1 lda KeyStoreVec+1
sta keyvec+1 sta keyvec+1
; Set the new vector. I can only hope that this works for other C128 ; Set the new vector. I can only hope that this works for other C128
; versions... ; versions...
lda #<$C6B7 lda #<$C6B7
ldx #>$C6B7 ldx #>$C6B7
jmp SetVec
SetVec: sei
sta KeyStoreVec
stx KeyStoreVec+1
cli
rts
.code
donecgetc: donecgetc:
lda #$00
sta SCROLL
lda keyvec lda keyvec
ldx keyvec+1 ldx keyvec+1
bne SetVec SetVec: sei
sta KeyStoreVec
stx KeyStoreVec+1
cli
rts

View File

@@ -18,6 +18,9 @@
cputdirect = PRINT cputdirect = PRINT
newline = NEWLINE newline = NEWLINE
;--------------------------------------------------------------------------
.code
_cputcxy: _cputcxy:
pha ; Save C pha ; Save C
@@ -75,7 +78,8 @@ plot: ldy CURS_X
putchar = $CC2F 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: initcputc:
lda #$C0 lda #$C0

View File

@@ -3,7 +3,7 @@
; Ullrich von Bassewitz, 2003-03-07 ; Ullrich von Bassewitz, 2003-03-07
; Based on code from Stefan A. Haubenthal, <polluks@web.de> ; Based on code from Stefan A. Haubenthal, <polluks@web.de>
; 2003-05-18, Greg King ; 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. ; Scan a group of arguments that are in BASIC's input-buffer.
; Build an array that points to the beginning of each argument. ; 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 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: initmainargs:
; Assume that the program was loaded, a moment ago, by the traditional LOAD ; Assume that the program was loaded, a moment ago, by the traditional LOAD

View File

@@ -56,6 +56,8 @@ L2: jsr KBDREAD ; Read char and return in A
.constructor initkbd .constructor initkbd
.destructor donekbd .destructor donekbd
.segment "INIT"
.proc initkbd .proc initkbd
ldy #15 ldy #15
@@ -68,6 +70,8 @@ L2: jsr KBDREAD ; Read char and return in A
.endproc .endproc
.code
.proc donekbd .proc donekbd
ldx #$39 ; Copy the original function keys ldx #$39 ; Copy the original function keys

View File

@@ -3,7 +3,7 @@
; Ullrich von Bassewitz, 2003-03-07 ; Ullrich von Bassewitz, 2003-03-07
; Based on code from Stefan A. Haubenthal, <polluks@web.de> ; Based on code from Stefan A. Haubenthal, <polluks@web.de>
; 2003-05-18, Greg King ; 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. ; Scan a group of arguments that are in BASIC's input-buffer.
; Build an array that points to the beginning of each argument. ; Build an array that points to the beginning of each argument.
@@ -30,11 +30,14 @@
MAXARGS = 10 ; Maximum number of arguments allowed MAXARGS = 10 ; Maximum number of arguments allowed
REM = $8f ; BASIC token-code REM = $8f ; BASIC token-code
NAME_LEN = 16 ; maximum length of command-name 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: initmainargs:
; Assume that the program was loaded, a moment ago, by the traditional LOAD ; Assume that the program was loaded, a moment ago, by the traditional LOAD

View File

@@ -3,7 +3,7 @@
; Ullrich von Bassewitz, 2003-03-07 ; Ullrich von Bassewitz, 2003-03-07
; Based on code from Stefan A. Haubenthal, <polluks@web.de> ; Based on code from Stefan A. Haubenthal, <polluks@web.de>
; 2003-05-18, Greg King ; 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. ; Scan a group of arguments that are in BASIC's input-buffer.
; Build an array that points to the beginning of each argument. ; 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 REM = $8f ; BASIC token-code
NAME_LEN = 16 ; maximum length of command-name 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: initmainargs:
; Assume that the program was loaded, a moment ago, by the traditional LOAD ; Assume that the program was loaded, a moment ago, by the traditional LOAD

View File

@@ -20,6 +20,8 @@
;-------------------------------------------------------------------------- ;--------------------------------------------------------------------------
; initstdin: Open the stdin file descriptors for the keyboard ; initstdin: Open the stdin file descriptors for the keyboard
.segment "INIT"
.proc initstdin .proc initstdin
@@ -37,6 +39,7 @@
;-------------------------------------------------------------------------- ;--------------------------------------------------------------------------
; _read ; _read
.code
.proc _read .proc _read

View File

@@ -20,6 +20,8 @@
;-------------------------------------------------------------------------- ;--------------------------------------------------------------------------
; initstdout: Open the stdout and stderr file descriptors for the screen. ; initstdout: Open the stdout and stderr file descriptors for the screen.
.segment "INIT"
.proc initstdout .proc initstdout
lda #LFN_WRITE lda #LFN_WRITE
@@ -40,7 +42,8 @@
;-------------------------------------------------------------------------- ;--------------------------------------------------------------------------
; _write ; _write
.code
.proc _write .proc _write

View File

@@ -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 .proc initmainargs

View File

@@ -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 .proc initmainargs

View File

@@ -6,7 +6,7 @@
; ;
; 6.3.2001, 17.4.2003 ; 6.3.2001, 17.4.2003
.include "../inc/geossym.inc" .include "../inc/geossym.inc"
.export xsize, ysize .export xsize, ysize
@@ -14,8 +14,8 @@
.importzp cursor_r, cursor_c .importzp cursor_r, cursor_c
.import _cursor .import _cursor
.constructor initscrsize .constructor initscrsize
.code .segment "INIT"
initscrsize: initscrsize:
lda graphMode lda graphMode

View File

@@ -21,6 +21,8 @@
;--------------------------------------------------------------------------- ;---------------------------------------------------------------------------
; Setup arguments for main ; Setup arguments for main
.segment "INIT"
.proc initmainargs .proc initmainargs
; Setup a pointer to our argv vector ; Setup a pointer to our argv vector

View File

@@ -45,7 +45,8 @@ CFLAGS = -Osir -g -T -t $(SYS) --forget-inc-paths -I . -I ../../include
#-------------------------------------------------------------------------- #--------------------------------------------------------------------------
# Object files # Object files
OBJS = cgetc.o \ OBJS = cartread.o \
cgetc.o \
crt0.o \ crt0.o \
ctype.o \ ctype.o \
eeprom.o \ eeprom.o \

49
libsrc/lynx/cartread.s Normal file
View File

@@ -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

View File

@@ -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 .proc initmainargs

View File

@@ -7,7 +7,7 @@
; ;
.export _cputcxy, _cputc, cputdirect, putchar .export _cputcxy, _cputc, cputdirect, putchar
.export newline .export newline
.constructor conioinit .constructor conioinit
.import popa, _gotoxy .import popa, _gotoxy
.import ppuinit, paletteinit, ppubuf_put .import ppuinit, paletteinit, ppubuf_put
@@ -18,12 +18,14 @@
.include "nes.inc" .include "nes.inc"
;----------------------------------------------------------------------------- ;-----------------------------------------------------------------------------
.code
_cputcxy: _cputcxy:
pha ; Save C pha ; Save C
jsr popa ; Get Y jsr popa ; Get Y
jsr _gotoxy ; Set cursor, drop x jsr _gotoxy ; Set cursor, drop x
pla ; Restore C pla ; Restore C
; Plot a character - also used as internal function ; Plot a character - also used as internal function
@@ -67,13 +69,16 @@ plot: ldy CURS_X
; position in Y ; position in Y
putchar: putchar:
ora RVS ; Set revers bit ora RVS ; Set revers bit
ldy SCREEN_PTR+1 ldy SCREEN_PTR+1
ldx SCREEN_PTR ldx SCREEN_PTR
jmp ppubuf_put 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: conioinit:
jsr ppuinit jsr ppuinit

View File

@@ -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 .proc initmainargs

View File

@@ -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 .proc initmainargs

View File

@@ -59,7 +59,7 @@ L2: sta ENABLE_ROM ; Bank in the ROM
.constructor initkbd .constructor initkbd
.destructor donekbd .destructor donekbd
.code ; Can go into the normal code segment .segment "INIT" ; Special init code segment may get overwritten
.proc initkbd .proc initkbd

View File

@@ -3,7 +3,7 @@
; Ullrich von Bassewitz, 2003-03-07 ; Ullrich von Bassewitz, 2003-03-07
; Based on code from Stefan A. Haubenthal, <polluks@web.de> ; Based on code from Stefan A. Haubenthal, <polluks@web.de>
; 2003-05-18, Greg King ; 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. ; Scan a group of arguments that are in BASIC's input-buffer.
; Build an array that points to the beginning of each argument. ; Build an array that points to the beginning of each argument.
@@ -26,15 +26,18 @@
.import __argc, __argv .import __argc, __argv
.include "plus4.inc" .include "plus4.inc"
MAXARGS = 10 ; Maximum number of arguments allowed MAXARGS = 10 ; Maximum number of arguments allowed
REM = $8f ; BASIC token-code REM = $8f ; BASIC token-code
NAME_LEN = 16 ; maximum length of command-name 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: initmainargs:
; Assume that the program was loaded, a moment ago, by the traditional LOAD ; 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.) ; (The last vector in argv[] already is NULL.)
done: lda #<argv done: lda #<argv
ldx #>argv ldx #>argv
sta __argv sta __argv
stx __argv + 1 stx __argv + 1
rts rts
; --------------------------------------------------------------------------
; These arrays are zeroed before initmainargs is called. ; These arrays are zeroed before initmainargs is called.
; char name[16+1]; ; char name[16+1];
; char* argv[MAXARGS+1]={name}; ; char* argv[MAXARGS+1]={name};

View File

@@ -3,7 +3,7 @@
; Ullrich von Bassewitz, 2003-03-07 ; Ullrich von Bassewitz, 2003-03-07
; Based on code from Stefan A. Haubenthal, <polluks@web.de> ; Based on code from Stefan A. Haubenthal, <polluks@web.de>
; 2003-05-18, Greg King ; 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. ; Scan a group of arguments that are in BASIC's input-buffer.
; Build an array that points to the beginning of each argument. ; 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 REM = $8f ; BASIC token-code
NAME_LEN = 16 ; maximum length of command-name 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: initmainargs:
; Assume that the program was loaded, a moment ago, by the traditional LOAD ; Assume that the program was loaded, a moment ago, by the traditional LOAD
@@ -100,7 +103,7 @@ argloop:lda BASIC_BUF,x
inx inx
cmp term cmp term
bne argloop bne argloop
; We've found the end of the argument. X points one character behind it, and ; 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, ; A contains the terminating character. To make the argument a valid C string,
; replace the terminating character by a zero. ; replace the terminating character by a zero.