u/AppledogHu

▲ 6 r/Forth

Using Forth to run the OS and execute BASIC

Has anyone used Forth as a serious OS before? I need to cut something out of my KERNAL and I thought, I could remove Forth (7.5k), but I could also remove BASIC (~20k). Most of the OS commands are written into the BASIC interpreter. What if I move the OS commands to forth instead? So after some experimentation I found a way to make forth run commands that look like BASIC and/or shell commands. Currently, BASIC handles all the OS commands like DIR, COPY, etc.

I'm not sure if this would work but I can't see why not:

    : STRIP, DUP
      BEGIN
        DUP C@ 0= IF DROP EXIT THEN
        DUP C@ 44 = IF 0 OVER C! THEN
        1 +
      AGAIN ;
    
    : ARG WORD STRIP, NUMBER ;
    
    : POKE ARG ARG SWAP C! ;
    
    POKE 49152, 10  \\ example command

or this

    : SPLITARG
      WORD DUP
      BEGIN
        DUP C@ 0= IF DROP NUMBER EXIT THEN
        DUP C@ 44 = IF
          0 OVER C!            \ null-terminate first part
          1 +                  \ pointer to second part
          SWAP NUMBER          \ convert first part
          SWAP NUMBER          \ convert second part
          EXIT
        THEN
        1 +
      AGAIN ;
  
    : POKE SPLITARG SWAP C! ;

    POKE 49152,10  \\ example command

I could make commands like MKDIR dirname, COPY file1 file2 and so on. If this works, the OS prompt will feel exactly the same except it will have the power of FORTH inside. And I can clear up 20k of space in the kernal by removing BASIC. I will have to investigate this further.

reddit.com
u/AppledogHu — 3 days ago