Added routines to handle command line params

git-svn-id: svn://svn.cc65.org/cc65/trunk@2012 b7a2c559-68d2-44c3-8de9-860c34a00d81
This commit is contained in:
cuz
2003-03-10 21:21:46 +00:00
parent 065b8f2596
commit 467d8ad9c5
34 changed files with 340 additions and 90 deletions

View File

@@ -39,6 +39,7 @@ OBJS = _scrsize.o \
joy_stddrv.o \
kbhit.o \
kernal.o \
mainargs.o \
mouse.o \
randomize.o \
revers.o \

View File

@@ -11,7 +11,8 @@ ST = $90 ; IEC status byte
TIME = $A0 ; 60 HZ clock
FNAM_LEN = $B7 ; Length of filename
SECADR = $B9 ; Secondary address
DEVNUM = $BA ; Device number
DEVNUM = $BA ; Device number
FNAM = $BB ; Pointer to filename
KEY_COUNT = $C6 ; Number of keys in input buffer
RVS = $C7 ; Reverse flag
CURS_FLAG = $CC ; 1 = cursor off

View File

@@ -7,7 +7,7 @@
.export _exit
.import initlib, donelib
.import zerobss, push0
.import _main
.import callmain
.import RESTOR, BSOUT, CLRCH
.import __RAM_START__, __RAM_SIZE__ ; Linker generated
@@ -81,13 +81,9 @@ L1: lda sp,x
jsr initlib
; Pass an empty command line
; Push arguments and call main
jsr push0 ; argc
jsr push0 ; argv
ldy #4 ; Argument size
jsr _main ; call the users code
jsr callmain
; Call module destructors. This is also the _exit entry.

72
libsrc/c64/mainargs.s Normal file
View File

@@ -0,0 +1,72 @@
;
; Ullrich von Bassewitz, 2003-03-07
;
; Setup arguments for main.
; Based on code from Stefan A. Haubenthal, <polluks@web.de>
;
.constructor initmainargs, 24
.import __argc, __argv
.include "c64.inc"
;---------------------------------------------------------------------------
; Setup arguments for main
.proc initmainargs
; Setup a pointer to our argv vector
lda #<argv
sta __argv
lda #>argv
sta __argv+1
; Save the last filename as argument #0. Since the buffer we're copying into
; is zeroed out, we don't need to add a NUL character.
ldy FNAM_LEN
cpy #16+1
bcc L0
ldy #16 ; Limit the length
L0: dey
L1: lda (FNAM),y
sta argv0,y
dey
bpl L1
inc __argc ; __argc = 1
; Find argument in BASIC buffer, if found, use it as arg #1
ldy #0
L2: lda $200,y
beq L9
iny
cmp #$8F ; REM token
bne L2
sty argv+2 ; Store offset
ldy #>$200
sty argv+3
inc __argc ; argc = 2
; Done
L9: rts
.endproc
;---------------------------------------------------------------------------
; Data
.data
argv: .word argv0 ; Pointer to program name
.word $0000 ; Optional second argument
.word $0000 ; Last vector must always be NULL
.bss
argv0: .res 17 ; Program name