XMAINARGS (argmains)
ID primitive : $2C
Description
Return argc and argv or a ptr with a content of the command line
Input
A => mode
mode 0 : return a struct of args
mode 1 : return the string of the command line (ptr)
Output
Mode 0 :
- A & Y :contains ptr to XMAINARGS Struct
- X: number of args
Mode 1 :
- A & Y : a ptr to a new malloc which contains commandline
Example
Mode 0 : parse command line and build argc/argv
.include "telestrat.inc"
lda #$00 ; Mode 0
BRK_TELEMON XMAINARGS
stx save_argc
sta save_argv
sty save_argv+1
rts
Mode 1 : return command line
.include "telestrat.inc"
lda #$01 ; Mode 0
BRK_TELEMON XMAINARGS
sta ptr_cmd
sty ptr_cmd+1 ; ptr_cmd contains the ptr to the command line. It allocates a string, it needs to be free when the program does not need it anymore
rts
See initmainargs macro from orix-sdk to use it
XMAINARGS allocates a chunk in memory, it must be free at the end of the use of the parameters
Mode 0 is available since v2022.4
Since cc65 last version (2024 release), XMAINARGS does not need to declare anymore
XGETARGV does not handle "" yet and " in parameters