Skip to content

XMAINARGS (argmains)

ID primitive : $2C


Return argc and argv or a ptr with a content of the command line


A => mode

mode 0 : return a struct of args

mode 1 : return the string of the command line (ptr)


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


Mode 0 : parse command line and build argc/argv


lda     #$00 ; Mode 0
brk_kernel XMAINARGS

stx save_argc
sta save_argv
sty save_argv+1

Mode 1 : return command line


lda     #$01 ; Mode 0
brk_kernel 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

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

XGETARGV does not handle "" yet and " in parameters

Last update: 2022-11-23