; FreeWINdows - GUI MENU
; Copyright Christopher Evans
; email:   tekno1911@yahoo.com
; Website: http://nxdos.sourceforge.net/
;                                                                           ;
;       This program is copyrighted, but may be freely distributed          ;
;       under the terms of the Free Software Foundation's GNU General       ;
;       Public License v2 (or later.)  See the file COPYING for the         ;
;       legalities.  If you did not receive a copy of COPYING, you          ;
;       may request one from the Free Software Foundation, Inc.,            ;
;       59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.           ;
;       ABSOLUTELY NO WARRANTY -- use it at your own risk!                  ;
;                                                                           ;


_stack     segment word stack 'STACK'
                db      0100h DUP (05h)
_stack     ends

data segment    ; data things here

include \nxdos\src\tbx_data.inc

startmenu_msg db 'Menu',0
stm_6 db 'Run',0
stm_7 db 'Shutdown',0
filenotexist_msg db 'File does not exist.',0
advancedsnd dw 0

data ends

        code   segment
        assume cs:code, ds:data, es:data, ss:_stack

include \nxdos\src\tbx_code.inc
include \nxdos\src\kernel\gfx.asm
include \nxdos\src\window.inc

; include \nxdos\src\gui\gif.asm


        _compile


start:  mov     ax, data    ; Establish data and extra segment addressability
        mov     ds, ax      ; aka  setup the stack n' data segments
        mov     es, ax

        call cs:main
        call cs:closeup
exit:   call dosexit

; ===========================================================================
init proc far
; ===========================================================================
     ; initialize mouse etc...
     ; set video modes
     call savescreen
     ret
init endp

; ===========================================================================
playsoundfx proc far
; ===========================================================================
     mov  ax, advancedsnd
     or   ax, ax
     jnz  psfx_a
          ; if not on_floppy
          ;  spawn(externalplayer, soundefect(sndfx));
          jmp  psfx_x
psfx_a:
          ; playocwav
          ; if pos('.VOC',soundeffect(sndfx)) > 0 then
          ; if not(playvoc(soundeffect(sndfx)) then beep;
          call beep
psfx_x:
     ret
playsoundfx endp

; ===========================================================================
closeup proc far
; AL    = Errorlevel
; DS:SI = custom error string
; Returns AL = boolean
; ===========================================================================
        call showcursor
        call clrscr
        call restorescreen
        call dosexit
        ret
closeup endp

; ===========================================================================
drawscreen proc far
; ===========================================================================
     call clrscr
     mov  cx, 2000
@ii:
     _echo 178
     loop @ii   

     _gotoxy 1, 1, 0
     _textcolor 7, 1
     call clreol 

     _gotoxy 1, 24, 0
     _textcolor 7, 1
     call clreol 
     ret
drawscreen endp

; ===========================================================================
update_clock proc far
; ===========================================================================
     _gotoxy 75, 24, 0
     _textcolor 14, 1
     mov  ah, 02h
     int  1ah
     jc   noclk
     push cx
     xor  ax, ax
     mov  al, ch
     call puthex8
     pop  cx
     push cx
     mov  ah, 2ch
     int  21h
     mov  al, dl
     test al, 00000001b
     jz   nodiv
     mov  al, ':'
     jmp  short divshw
nodiv:
     mov  al, ' '
divshw:
     call teletype
     xor  ax, ax
     mov  al, cl
     call puthex8
     pop  cx
noclk:
     ret
update_clock endp

; ===========================================================================
testmenu proc far
; ===========================================================================

      _popbox 10, 5, 20, 10, 7, 1
      _readkey
      _popbox 11, 6, 21, 11, 7, 1
      _readkey
      _popbox 12, 7, 22, 12, 7, 1

   ;   _newline
   ;   _echo 'X'
   ;   _newline
   ;   _echo 'X'
   ;   _newline
   ;   _echo 'X'
   ;   _newline

      _readkey
     ret
testmenu endp

runmenu proc far
      _popbox 15, 15, 20, 3, 7, 1
      _gotoxy 16, 16, 0
      lea  di, _buffer
      mov  cx, 19
      call getdata
      lea  dx, _buffer
      xor  bx, bx
      _fileexist _buffer
      jnc  runne0
           call spawn
           jmp  runmnux
      runne0:
      _popbox 15, 15, 20, 3, 7, 1
      _gotoxy 16, 16, 0
      _print filenotexist_msg, 1
      _readkey
runmnux:
      ret
runmenu endp

startmenu proc far
      _popbox 2, 2, 15, 8, 7, 7
      _textcolor 8, 7
      _gotoxy 3, 8, 0
      _print stm_6, 1
      _gotoxy 3, 9, 0
      _print stm_7, 1
      _readkey
         call upcase
         cmp  al, 'R'
         je   run0
         cmp  al, 'S'
         je   shutdown0
         jmp  endcase_s
         run0:
              call runmenu
              jmp  endcase_s
         shutdown0:
              xor ax, ax
              call closeup
              jmp  endcase_s
         endcase_s:

        ret
startmenu endp

update_menu proc far
     _gotoxy 2, 1, 0
     _textcolor 15, 1
     _print startmenu_msg, 1
     _textcolor 7, 1
     _Echo ' '
     _Echo '³'
     ret
update_menu endp

; ===========================================================================
menu proc far
; ===========================================================================
whilem:
     call hidecursor
     ; Update our visable items
     call update_clock 
     call update_menu
     ; 
     kbhit
     or  ax, ax
     jz  no_user
         _readkey
         call upcase
         cmp  al, 27
         je   menux
         cmp  al, 'T'
         je   testmenu0
         cmp  al, ' '
         je   startmenu0
         jmp  endcase_m
         testmenu0:
              call testmenu
              jmp  endcase_m
         startmenu0:
              call startmenu
              jmp  endcase_m
         endcase_m:

no_user:
     jmp whilem
menux:
     ret
menu endp

; ===========================================================================
main proc far
; ===========================================================================
     call init
     call savescreen
     call drawscreen
     call menu
     call closeup
     ret
main endp

        code ends
        end  start   

