From: cuz Date: Mon, 10 Mar 2003 21:21:46 +0000 (+0000) Subject: Added routines to handle command line params X-Git-Tag: V2.12.0~1680 X-Git-Url: https://git.sur5r.net/?a=commitdiff_plain;h=467d8ad9c5c870aa83dd8c801a2f9e7dde0d0c79;p=cc65 Added routines to handle command line params git-svn-id: svn://svn.cc65.org/cc65/trunk@2012 b7a2c559-68d2-44c3-8de9-860c34a00d81 --- diff --git a/libsrc/apple2/Makefile b/libsrc/apple2/Makefile index be8fe57e8..88372e21b 100644 --- a/libsrc/apple2/Makefile +++ b/libsrc/apple2/Makefile @@ -29,6 +29,7 @@ OBJS= _scrsize.o \ ctype.o \ cvline.o \ kbhit.o \ + mainargs.o \ randomize.o \ read.o \ revers.o \ diff --git a/libsrc/apple2/crt0.s b/libsrc/apple2/crt0.s index b3cfb55c9..5b9edce22 100644 --- a/libsrc/apple2/crt0.s +++ b/libsrc/apple2/crt0.s @@ -8,7 +8,7 @@ .import initlib, donelib .import zerobss, push0 .import __STARTUP_LOAD__, __BSS_LOAD__ ; Linker generated - .import _main + .import callmain .include "zeropage.inc" .include "apple2.inc" @@ -33,7 +33,7 @@ ldx #zpspace-1 L1: lda sp,x - sta zpsave,x ; Save the zero page locations we need + sta zpsave,x ; Save the zero page locations we need dex bpl L1 @@ -44,12 +44,12 @@ L1: lda sp,x ; Save system stuff and setup the stack tsx - stx spsave ; Save the system stack ptr + stx spsave ; Save the system stack ptr lda MEMSIZE sta sp lda MEMSIZE+1 - sta sp+1 ; Set argument stack ptr + sta sp+1 ; Set argument stack ptr ; Call module constructors @@ -64,13 +64,9 @@ L1: lda sp,x ;; sta USEROM -; 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. @@ -78,7 +74,7 @@ _exit: jsr donelib ; Restore system stuff - lda #$ff ; Reset text mode + lda #$ff ; Reset text mode sta TEXTTYP ldx spsave diff --git a/libsrc/apple2/mainargs.s b/libsrc/apple2/mainargs.s new file mode 100644 index 000000000..ebe6d0348 --- /dev/null +++ b/libsrc/apple2/mainargs.s @@ -0,0 +1,21 @@ +; +; Ullrich von Bassewitz, 2003-03-07 +; +; Setup arguments for main +; + + + .constructor initmainargs, 24 + .import __argc, __argv + + +;--------------------------------------------------------------------------- +; Setup arguments for main + +.proc initmainargs + + rts + +.endproc + + diff --git a/libsrc/atmos/Makefile b/libsrc/atmos/Makefile index 893278937..7a07b6c52 100644 --- a/libsrc/atmos/Makefile +++ b/libsrc/atmos/Makefile @@ -20,6 +20,7 @@ C_OBJS = S_OBJS = crt0.o \ + mainargs.o \ systime.o #-------------------------------------------------------------------------- diff --git a/libsrc/atmos/crt0.s b/libsrc/atmos/crt0.s index c386b9c4b..cb1b5a14e 100644 --- a/libsrc/atmos/crt0.s +++ b/libsrc/atmos/crt0.s @@ -8,7 +8,7 @@ .export _exit .import initlib, donelib - .import push0, _main, zerobss + .import push0, callmain, zerobss .import __RAM_START__, __RAM_SIZE__ ; Linker generated .importzp sp @@ -41,13 +41,9 @@ 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. diff --git a/libsrc/atmos/mainargs.s b/libsrc/atmos/mainargs.s new file mode 100644 index 000000000..ebe6d0348 --- /dev/null +++ b/libsrc/atmos/mainargs.s @@ -0,0 +1,21 @@ +; +; Ullrich von Bassewitz, 2003-03-07 +; +; Setup arguments for main +; + + + .constructor initmainargs, 24 + .import __argc, __argv + + +;--------------------------------------------------------------------------- +; Setup arguments for main + +.proc initmainargs + + rts + +.endproc + + diff --git a/libsrc/c128/Makefile b/libsrc/c128/Makefile index 36310200b..ee0741469 100644 --- a/libsrc/c128/Makefile +++ b/libsrc/c128/Makefile @@ -40,6 +40,7 @@ OBJS = _scrsize.o \ joy_stddrv.o \ kbhit.o \ kernal.o \ + mainargs.o \ mouse.o \ randomize.o \ revers.o \ diff --git a/libsrc/c128/crt0.s b/libsrc/c128/crt0.s index 2e09a3f73..324e1a5de 100644 --- a/libsrc/c128/crt0.s +++ b/libsrc/c128/crt0.s @@ -7,7 +7,7 @@ .export _exit .import condes, initlib, donelib .import zerobss - .import push0, _main + .import push0, callmain .import RESTOR, BSOUT, CLRCH .import __IRQFUNC_TABLE__, __IRQFUNC_COUNT__ .import __RAM_START__, __RAM_SIZE__ @@ -108,13 +108,9 @@ L1: lda sp,x stx IRQVec+1 cli -; Pass an empty command line +; Push arguments and call main() -NoIRQ1: jsr push0 ; argc - jsr push0 ; argv - - ldy #4 ; Argument size - jsr _main ; call the users code +NoIRQ1: jsr callmain ; Back from main (this is also the _exit entry). Reset the IRQ vector if ; we chained it. diff --git a/libsrc/c128/mainargs.s b/libsrc/c128/mainargs.s new file mode 100644 index 000000000..ebe6d0348 --- /dev/null +++ b/libsrc/c128/mainargs.s @@ -0,0 +1,21 @@ +; +; Ullrich von Bassewitz, 2003-03-07 +; +; Setup arguments for main +; + + + .constructor initmainargs, 24 + .import __argc, __argv + + +;--------------------------------------------------------------------------- +; Setup arguments for main + +.proc initmainargs + + rts + +.endproc + + diff --git a/libsrc/c16/Makefile b/libsrc/c16/Makefile index 3fa69d4c4..45645c96d 100644 --- a/libsrc/c16/Makefile +++ b/libsrc/c16/Makefile @@ -38,6 +38,7 @@ OBJS = _scrsize.o \ joy_stddrv.o \ kbhit.o \ kernal.o \ + mainargs.o \ randomize.o \ revers.o diff --git a/libsrc/c16/crt0.s b/libsrc/c16/crt0.s index d040f4e53..8a63537b0 100644 --- a/libsrc/c16/crt0.s +++ b/libsrc/c16/crt0.s @@ -9,7 +9,7 @@ .export _exit .import initlib, donelib - .import push0, _main, zerobss + .import push0, callmain, zerobss .import MEMTOP, RESTOR, BSOUT, CLRCH .include "zeropage.inc" @@ -75,13 +75,9 @@ MemOk: stx sp 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. diff --git a/libsrc/c16/mainargs.s b/libsrc/c16/mainargs.s new file mode 100644 index 000000000..ebe6d0348 --- /dev/null +++ b/libsrc/c16/mainargs.s @@ -0,0 +1,21 @@ +; +; Ullrich von Bassewitz, 2003-03-07 +; +; Setup arguments for main +; + + + .constructor initmainargs, 24 + .import __argc, __argv + + +;--------------------------------------------------------------------------- +; Setup arguments for main + +.proc initmainargs + + rts + +.endproc + + diff --git a/libsrc/c64/Makefile b/libsrc/c64/Makefile index 30cceb14b..5e8d1bcfe 100644 --- a/libsrc/c64/Makefile +++ b/libsrc/c64/Makefile @@ -39,6 +39,7 @@ OBJS = _scrsize.o \ joy_stddrv.o \ kbhit.o \ kernal.o \ + mainargs.o \ mouse.o \ randomize.o \ revers.o \ diff --git a/libsrc/c64/c64.inc b/libsrc/c64/c64.inc index 913842fa3..e93872f93 100644 --- a/libsrc/c64/c64.inc +++ b/libsrc/c64/c64.inc @@ -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 diff --git a/libsrc/c64/crt0.s b/libsrc/c64/crt0.s index 4c441d513..17166f4d2 100644 --- a/libsrc/c64/crt0.s +++ b/libsrc/c64/crt0.s @@ -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. diff --git a/libsrc/c64/mainargs.s b/libsrc/c64/mainargs.s new file mode 100644 index 000000000..4a34e4196 --- /dev/null +++ b/libsrc/c64/mainargs.s @@ -0,0 +1,72 @@ +; +; Ullrich von Bassewitz, 2003-03-07 +; +; Setup arguments for main. +; Based on code from Stefan A. Haubenthal, +; + + + .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+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 + + diff --git a/libsrc/cbm510/Makefile b/libsrc/cbm510/Makefile index 60cb8f6c4..4609aeb6a 100644 --- a/libsrc/cbm510/Makefile +++ b/libsrc/cbm510/Makefile @@ -48,6 +48,7 @@ OBJS = _scrsize.o \ kplot.o \ kscnkey.o \ kudtim.o \ + mainargs.o \ mouse.o \ peeksys.o \ pokesys.o \ diff --git a/libsrc/cbm510/crt0.s b/libsrc/cbm510/crt0.s index 6b6ca1676..2296106a0 100644 --- a/libsrc/cbm510/crt0.s +++ b/libsrc/cbm510/crt0.s @@ -7,7 +7,7 @@ .export _exit .import _clrscr, initlib, donelib - .import push0, _main + .import push0, callmain .import __CHARRAM_START__, __CHARRAM_SIZE__, __VIDRAM_START__ .import __EXTZP_RUN__, __EXTZP_SIZE__ .import __BSS_RUN__, __BSS_SIZE__ @@ -282,11 +282,6 @@ ccopy2: lda __VIDRAM_START__,y jsr initlib -; Create the (empty) command line for the program - - jsr push0 ; argc - jsr push0 ; argv - ; Execute the program code jmp Start @@ -378,10 +373,9 @@ Start: cli -; Call the user code +; Push arguments and call main() - ldy #4 ; Argument size - jsr _main ; call the users code + jsr callmain ; Call module destructors. This is also the _exit entry. diff --git a/libsrc/cbm510/mainargs.s b/libsrc/cbm510/mainargs.s new file mode 100644 index 000000000..ebe6d0348 --- /dev/null +++ b/libsrc/cbm510/mainargs.s @@ -0,0 +1,21 @@ +; +; Ullrich von Bassewitz, 2003-03-07 +; +; Setup arguments for main +; + + + .constructor initmainargs, 24 + .import __argc, __argv + + +;--------------------------------------------------------------------------- +; Setup arguments for main + +.proc initmainargs + + rts + +.endproc + + diff --git a/libsrc/cbm610/Makefile b/libsrc/cbm610/Makefile index 3facda076..6856f764a 100644 --- a/libsrc/cbm610/Makefile +++ b/libsrc/cbm610/Makefile @@ -37,6 +37,7 @@ OBJS = _scrsize.o \ kplot.o \ kscnkey.o \ kudtim.o \ + mainargs.o \ peeksys.o \ pokesys.o \ randomize.o \ diff --git a/libsrc/cbm610/crt0.s b/libsrc/cbm610/crt0.s index f2298bcd9..65fdf81e3 100644 --- a/libsrc/cbm610/crt0.s +++ b/libsrc/cbm610/crt0.s @@ -9,7 +9,7 @@ .exportzp ktab2, ktab3, ktab4, time, RecvBuf, SendBuf .import initlib, donelib - .import push0, _main + .import push0, callmain .import __BSS_RUN__, __BSS_SIZE__ .import irq, nmi .import k_irq, k_nmi, PLOT, UDTIM, SCNKEY @@ -214,11 +214,6 @@ Z4: jsr initlib -; Create the (empty) command line for the program - - jsr push0 ; argc - jsr push0 ; argv - ; Execute the program code jmp Start @@ -293,10 +288,9 @@ Start: cli -; Call the user code +; Push arguments and call main() - ldy #4 ; Argument size - jsr _main ; call the users code + jsr callmain ; Call module destructors. This is also the _exit entry. diff --git a/libsrc/cbm610/mainargs.s b/libsrc/cbm610/mainargs.s new file mode 100644 index 000000000..ebe6d0348 --- /dev/null +++ b/libsrc/cbm610/mainargs.s @@ -0,0 +1,21 @@ +; +; Ullrich von Bassewitz, 2003-03-07 +; +; Setup arguments for main +; + + + .constructor initmainargs, 24 + .import __argc, __argv + + +;--------------------------------------------------------------------------- +; Setup arguments for main + +.proc initmainargs + + rts + +.endproc + + diff --git a/libsrc/geos/devel/Makefile b/libsrc/geos/devel/Makefile index b763ac5eb..a5287174c 100644 --- a/libsrc/geos/devel/Makefile +++ b/libsrc/geos/devel/Makefile @@ -16,7 +16,14 @@ %.tgi: %.o ../../runtime/zeropage.o @$(LD) -t module -o $@ $^ -S_OBJS = crt0.o extzp.o oserror.o oserrlist.o randomize.o fio_module.o tgi_mode_table.o +S_OBJS = crt0.o \ + extzp.o \ + fio_module.o \ + mainargs.o \ + oserror.o \ + oserrlist.o \ + randomize.o \ + tgi_mode_table.o #-------------------------------------------------------------------------- # Drivers diff --git a/libsrc/geos/devel/crt0.s b/libsrc/geos/devel/crt0.s index 75ad670d3..76e9c8ef6 100644 --- a/libsrc/geos/devel/crt0.s +++ b/libsrc/geos/devel/crt0.s @@ -8,7 +8,7 @@ .import __RAM_START__, __RAM_SIZE__ ; Linker generated .import initlib, donelib .import pushax - .import _main + .import callmain .import _MainLoop, _EnterDeskTop .import zerobss .importzp sp @@ -39,16 +39,10 @@ jsr initlib -; Pass an empty command line - - lda #0 - tax - jsr pushax ; argc - jsr pushax ; argv +; Push arguments and call main() cli - ldy #4 ; Argument size - jsr _main ; call the users code + jsr callmain ; Call module destructors. This is also the _exit entry which must be called ; explicitly by the code. diff --git a/libsrc/geos/devel/mainargs.s b/libsrc/geos/devel/mainargs.s new file mode 100644 index 000000000..ebe6d0348 --- /dev/null +++ b/libsrc/geos/devel/mainargs.s @@ -0,0 +1,21 @@ +; +; Ullrich von Bassewitz, 2003-03-07 +; +; Setup arguments for main +; + + + .constructor initmainargs, 24 + .import __argc, __argv + + +;--------------------------------------------------------------------------- +; Setup arguments for main + +.proc initmainargs + + rts + +.endproc + + diff --git a/libsrc/pet/Makefile b/libsrc/pet/Makefile index bcfb680d3..a09bde862 100644 --- a/libsrc/pet/Makefile +++ b/libsrc/pet/Makefile @@ -38,6 +38,7 @@ OBJS = _scrsize.o \ kreadst.o \ ksetlfs.o \ ksetnam.o \ + mainargs.o \ randomize.o \ revers.o diff --git a/libsrc/pet/crt0.s b/libsrc/pet/crt0.s index fb65973ec..c3cebc774 100644 --- a/libsrc/pet/crt0.s +++ b/libsrc/pet/crt0.s @@ -7,7 +7,7 @@ .export _exit .import initlib, donelib .import zerobss, push0 - .import _main + .import callmain .import CLRCH, BSOUT .include "zeropage.inc" @@ -70,13 +70,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. diff --git a/libsrc/pet/mainargs.s b/libsrc/pet/mainargs.s new file mode 100644 index 000000000..ebe6d0348 --- /dev/null +++ b/libsrc/pet/mainargs.s @@ -0,0 +1,21 @@ +; +; Ullrich von Bassewitz, 2003-03-07 +; +; Setup arguments for main +; + + + .constructor initmainargs, 24 + .import __argc, __argv + + +;--------------------------------------------------------------------------- +; Setup arguments for main + +.proc initmainargs + + rts + +.endproc + + diff --git a/libsrc/plus4/Makefile b/libsrc/plus4/Makefile index df257b1e8..e453c9e4b 100644 --- a/libsrc/plus4/Makefile +++ b/libsrc/plus4/Makefile @@ -60,6 +60,7 @@ OBJS = _scrsize.o \ ktalk.o \ kunlsn.o \ kuntlk.o \ + mainargs.o \ randomize.o \ revers.o \ tgi_mode_table.o diff --git a/libsrc/plus4/crt0.s b/libsrc/plus4/crt0.s index a2e33413d..3146e3674 100644 --- a/libsrc/plus4/crt0.s +++ b/libsrc/plus4/crt0.s @@ -8,7 +8,7 @@ .export brk_jmp .import condes, initlib, donelib - .import push0, _main, zerobss + .import push0, callmain, zerobss .import __IRQFUNC_TABLE__, __IRQFUNC_COUNT__ .include "zeropage.inc" @@ -99,13 +99,9 @@ L1: lda sp,x stx IRQVec+1 cli -; Pass an empty command line +; Push arguments and call main() -NoIRQ1: jsr push0 ; argc - jsr push0 ; argv - - ldy #4 ; Argument size - jsr _main ; call the users code +NoIRQ1: jsr callmain ; Back from main (this is also the _exit entry). Reset the IRQ vector if ; we chained it. diff --git a/libsrc/plus4/mainargs.s b/libsrc/plus4/mainargs.s new file mode 100644 index 000000000..ebe6d0348 --- /dev/null +++ b/libsrc/plus4/mainargs.s @@ -0,0 +1,21 @@ +; +; Ullrich von Bassewitz, 2003-03-07 +; +; Setup arguments for main +; + + + .constructor initmainargs, 24 + .import __argc, __argv + + +;--------------------------------------------------------------------------- +; Setup arguments for main + +.proc initmainargs + + rts + +.endproc + + diff --git a/libsrc/vic20/Makefile b/libsrc/vic20/Makefile index 7baf2b69c..1be2fae72 100644 --- a/libsrc/vic20/Makefile +++ b/libsrc/vic20/Makefile @@ -38,6 +38,7 @@ OBJS = _scrsize.o \ kbhit.o \ kernal.o \ kplot.o \ + mainargs.o \ randomize.o \ revers.o @@ -66,4 +67,4 @@ clean: zap: clean @rm -f $(EMDS) $(JOYS) $(TGIS) - + diff --git a/libsrc/vic20/crt0.s b/libsrc/vic20/crt0.s index ca3ff2f49..03a3bbc92 100644 --- a/libsrc/vic20/crt0.s +++ b/libsrc/vic20/crt0.s @@ -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 @@ -75,13 +75,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. diff --git a/libsrc/vic20/mainargs.s b/libsrc/vic20/mainargs.s new file mode 100644 index 000000000..ebe6d0348 --- /dev/null +++ b/libsrc/vic20/mainargs.s @@ -0,0 +1,21 @@ +; +; Ullrich von Bassewitz, 2003-03-07 +; +; Setup arguments for main +; + + + .constructor initmainargs, 24 + .import __argc, __argv + + +;--------------------------------------------------------------------------- +; Setup arguments for main + +.proc initmainargs + + rts + +.endproc + +