.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
;---------------------------------------------------------------------------
-; 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
.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
+
cputdirect = PRINT
newline = NEWLINE
+;--------------------------------------------------------------------------
+
+.code
_cputcxy:
pha ; Save C
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
; Ullrich von Bassewitz, 2003-03-07
; Based on code from Stefan A. Haubenthal, <polluks@web.de>
; 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.
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
.constructor initkbd
.destructor donekbd
+.segment "INIT"
+
.proc initkbd
ldy #15
.endproc
+.code
+
.proc donekbd
ldx #$39 ; Copy the original function keys
; Ullrich von Bassewitz, 2003-03-07
; Based on code from Stefan A. Haubenthal, <polluks@web.de>
; 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.
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
; Ullrich von Bassewitz, 2003-03-07
; Based on code from Stefan A. Haubenthal, <polluks@web.de>
; 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.
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
;--------------------------------------------------------------------------
; initstdin: Open the stdin file descriptors for the keyboard
+
+.segment "INIT"
.proc initstdin
;--------------------------------------------------------------------------
; _read
+.code
.proc _read
;--------------------------------------------------------------------------
; initstdout: Open the stdout and stderr file descriptors for the screen.
+.segment "INIT"
+
.proc initstdout
lda #LFN_WRITE
;--------------------------------------------------------------------------
; _write
-
+
+.code
.proc _write
;---------------------------------------------------------------------------
-; 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
;---------------------------------------------------------------------------
-; 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
;
; 6.3.2001, 17.4.2003
-
+
.include "../inc/geossym.inc"
.export xsize, ysize
.importzp cursor_r, cursor_c
.import _cursor
.constructor initscrsize
-
-.code
+
+.segment "INIT"
initscrsize:
lda graphMode
;---------------------------------------------------------------------------
; Setup arguments for main
+.segment "INIT"
+
.proc initmainargs
; Setup a pointer to our argv vector
#--------------------------------------------------------------------------
# Object files
-OBJS = cgetc.o \
+OBJS = cartread.o \
+ cgetc.o \
crt0.o \
ctype.o \
eeprom.o \
--- /dev/null
+; ***
+; 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
+
+
;---------------------------------------------------------------------------
-; 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
;
.export _cputcxy, _cputc, cputdirect, putchar
- .export newline
+ .export newline
.constructor conioinit
.import popa, _gotoxy
.import ppuinit, paletteinit, ppubuf_put
.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
; 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
;---------------------------------------------------------------------------
-; 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
;---------------------------------------------------------------------------
-; 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
.constructor initkbd
.destructor donekbd
-.code ; Can go into the normal code segment
+.segment "INIT" ; Special init code segment may get overwritten
.proc initkbd
; Ullrich von Bassewitz, 2003-03-07
; Based on code from Stefan A. Haubenthal, <polluks@web.de>
; 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.
.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
; (The last vector in argv[] already is NULL.)
-done: lda #<argv
+done: lda #<argv
ldx #>argv
sta __argv
stx __argv + 1
rts
-
+
+; --------------------------------------------------------------------------
; These arrays are zeroed before initmainargs is called.
; char name[16+1];
; char* argv[MAXARGS+1]={name};
; Ullrich von Bassewitz, 2003-03-07
; Based on code from Stefan A. Haubenthal, <polluks@web.de>
; 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.
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
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.