/* For free support for VSIDE, please visit www.vsdsp-forum.com */

// Starting point template for creating VSOS3 applications.
// This will create a <projectname>.AP3 file, which you can copy to 
// your VS1005 Developer Board and run it from there.

// AP3 files require VSOS3 kernel 0.3x to run.

// If you rename your application to INIT.AP3, then the kernel will
// load it automatically after booting.

#include <vo_stdio.h>
#include <volink.h>     // Linker directives like DLLENTRY
#include <apploader.h>  // RunLibraryFunction etc
#include <consolestate.h>
#include <string.h>
#include <kernel.h>
#include <mutex.h>
#include <imem.h>

#if 1
#define NEVER_EXITS
#endif

#define CMD_LINE_CHARS 256

struct ShellEnv {
  char cmd[CMD_LINE_CHARS];
} shellEnv;



#if 0
void init(void) {
}
#endif

/*
  Note!
  If taking control of main with shellAsm.s, rename this shell_main()
*/
ioresult shell_main(char *parameters) {
  printf("\nVSOS SHELL\n");

  shellEnv.cmd[0] = CMD_LINE_CHARS;
  appFlags = APP_FLAG_ECHO;	

#if 0
  /* 2024-02-14: with shellAsm.s i6=0x30, without i6=0x77 */
  printf("i6=0x%x\n", GetI6());
#endif

  while (1) {
    char *params;
    int errCode;
#if 0
    printf("#1 currentDirectory = %04x = \"%s\"\n",
	   currentDirectory, currentDirectory);
#endif
    RunProgram("GETCMD", shellEnv.cmd);
    params = strchr(shellEnv.cmd+1, ' ');
    while (*params == ' ') {
      *params++ = '\0';
    }
    if ((errCode = RunProgram(shellEnv.cmd+1, params))) {
      Delay(10);
      SysError("%s Returned %d / 0x%x", shellEnv.cmd+1, errCode, errCode);
    }
  }

  return S_OK;
}


#if 0
void fini(void) {
}
#endif
