VolksForth

Atari8bit-spartados
Login

Extension word sfor Sparta-DOS

( Sparta DOS routines )

DECIMAL

: ?SPARTA ( -- f )
  ( returns 1 if this is Sparta DOS )
  $700 C@ $53 = ;

: COMTAB ( -- addr )
  ( gets COMTAB base address )
  10 @ ;

: BUFOFS ( -- addr )
  ( adress of bufferoffset )
  COMTAB 10 + ;

: ZCRNAME ( -- )
  ( gets next cmd-line parm to COMFNAME )
  COMTAB 3 + CALL DROP ;

: GETPARM ( addr -- addr n )
  ( gets current parameter, needs address  )
  DUP DUP DUP 28 + SWAP
  DO
    I C@ 155 =
         IF I LEAVE THEN
  LOOP SWAP - ;

: FNAME ( -- addr n )
  ( get next param as filename )
  COMTAB 33 + GETPARM ;

: PARM ( -- addr n )
  ( get next param without Dx: )
  COMTAB 36 + GETPARM ;

: RESETBUF ( -- )
  ( Resets buffer offset )
  0 BUFOFS C! ZCRNAME ;

: PARAMS ( -- n )
  ( number of parameters on the cmd-line )
  RESETBUF
  0 BEGIN
     ZCRNAME PARM SWAP DROP
     DUP IF
          SWAP 1+ SWAP
         THEN
    0= UNTIL
    RESETBUF ;

: (TIME) ( n -- time )
  ( internal routine to access time )
  COMTAB + C@ ;

: HOUR ( -- hh )
  ( get the current hour )
  16 (TIME) ;

: MINUTE ( -- mm )
  ( get the current minute )
  17 (TIME) ;

: SECOND ( -- ss )
  ( get the current seconds )
  18 (TIME) ;

CR .( Sparta DOS Extensions loaded... ) CR

Examples:

Querying the clock:

: TIME 
  ?SPARTA IF 
     HOUR . $3A EMIT
   MINUTE . $3A EMIT
   SECOND . CR ELSE
     ." No Sparta DOS!" THEN ;

Loading Forth source by specifying the source file on the DOS command line:

( LAUNCH FORTH Source from Sparta DOS )
( Command line                        )

: LAUNCH ( -- )
  PARAMS ( do we have cmdline params? )
  IF     ( yes )
    CR ZCRNAME  ( get next filename )
    FNAME INCLUDED ( and include )
  THEN ;