\ VP
\ Main source file for JacksOrBetter
\ 
\ $Id: VP.txt,v 1.4 2000/10/25 00:17:43 kris_johnson Exp $

\ Copyright 2000
\ Kristopher D. Johnson
\ 
\ See LICENSE-JacksOrBetter for the
\ conditions under which you may
\ use, redistribute, or modify this 
\ code, or create derived works.

docneeds VP-globals
docneeds VP-stats
docneeds VP-game
docneeds VP-features
docneeds VP-ui
docneeds VP-events

.( VP... )

: bad-system-alert ( -- )
  altOSVersionError FrmAlert drop ;

: system-ok? ( -- f )
  2.0-feature-set?
  dup not if
    bad-system-alert
  then
;

: init-globals ( -- )
  restore-globals not if
    new-game
  then
;

: init-statistics ( -- )
  restore-stats not if
    init-stats
  then
;

\ Initialize global state
: initialize ( -- )
  init-globals
  init-statistics
;

: save-state ( -- )
  checks>hold save-globals
  save-stats
;

\ Thrown by Quartus event handler
\ when appStopEvent is received
-257 constant byeThrow

\ Handle appStopEvent
: appStop ( -- )
  save-state
  (bye)
;

\ Display main form and
\ handle events until exit or
\ until appStopEvent
: run ( -- )
  show-form
  ['] handle-events catch
  byeThrow = if
    appStop
  then
;

\ START is the entry point for
\ the standalone application
: start ( -- )
  system-ok? not if exit then
  initialize
  run
;

\ GO is for running inside
\ Quartus Forth
: go ( -- )
  start
  MainForm   \ Back to QF console
;

.( VP loaded! )

