\*
 *   ZEN 1.10  Initialization
 *     C 1990  by Martin Tracy
 *             Last modified  12/17/89
 *
 *   Modified 03/19/90 by MAW to produce COM executable for ZEN2APP demo
 *
 *\
ASSEMBLER
;
; Machine-level coldstart
;
Coldstart:
        cld
        push  cs
        pop   bx
        mov   ds,bx
        cli
        mov   ss,bx
; BARE
;        mov   sp,OFFSET SP0
        sti
        mov   si,OFFSET COLD+3 ; skip code field
        NEXT
END-CODE

\ Push Coldstart address on stack.  Used by SAVING
CODE 'SAVE ( - code_addr stack_seg )
        push  bx
        mov   bx,OFFSET _TEXT: Coldstart
        NEXT
END-CODE

\ Return to MS-DOS
CODE BYE ( )
        mov   ax,4C00h
        int   21h
END-CODE

\ Application initialization
\ : READY ( )
\   CR ." ZEN 1.10      C 1986 1989 1990"
\   CR ." Martin Tracy  Fax 213 371-2499" CR ;
\
\ Forth-level coldstart
\ Must be the last word in the nucleus dictionary.
\ : COLD ( )
\    BARE RESET [
\  ASSEMBLER
\         dw    Lit, OFFSET  _TEXT: COLDq
\         dw    Lit, OFFSET  _TEXT: PREVIOUSq
\         dw    Lit, OFFSET DGROUP: TP0
\         dw    Lit, OFFSET DGROUP: VP0
\         dw    Lit, OFFSET  _TEXT: DP0
\ END-CODE
\    ] DP ! VP ! TP !
\ [ VOX? ]     \IF  ['] ROOT >BODY !  ['] FORTH >BODY !
\ [ VOX? ]     \IF  ONLY FORTH DEFINITIONS ALSO
\ [ VOX? NOT ] \IF  'FORTH !  'FORTH  DUP CONTEXT 2!
\ [ MUX? ]     \IF  ['] NOOP MX ! ( Multitasking off)
\      ['] (VAL?) 'VAL? !   ['] NOOP DUP 'WARN 2!
\      [']  NOOP  'MAIN !   ['] GRIPE 'ERR !
\      DECIMAL  DUMB  " READY" EVALUATE  ABORT ;

\ Forth-level coldstart
\ Must be the last word in the nucleus dictionary.
: COLD ( )
   BARE  RESET [
ASSEMBLER
; IFNDEF HEADS_OFF
;        dw    Lit, OFFSET  _TEXT: COLDq
;        dw    Lit, OFFSET  _TEXT: PREVIOUSq
; ELSE
        dw    Lit, 0 ; OFFSET  _TEXT: COLDq
;        dw    Lit, 0 ; OFFSET  _TEXT: PREVIOUSq
; ENDIF
        dw    Lit, OFFSET DGROUP: TP0
        dw    Lit, OFFSET DGROUP: VP0
        dw    Lit, OFFSET  _TEXT: DP0
END-CODE
   ] DP ! VP ! TP !
[ VOX? ]     \IF  ['] ROOT >BODY !  ['] FORTH >BODY !
[ VOX? ]     \IF  ONLY FORTH DEFINITIONS ALSO
\ [ VOX? NOT ] \IF  'FORTH !  'FORTH  DUP CONTEXT 2!
[ MUX? ]     \IF  ['] NOOP MX ! ( Multitasking off)
\     ['] (VAL?) 'VAL? !  \ do not include unless used ?
     ['] NOOP DUP 'WARN 2!
     ['] NOOP  'MAIN !
\     ['] ABORT2 'ERR !  \ must build own error handler
     DUMB MYAPP BYE ;
