include "malloc.h"; include "tokeniser.h"; include "store.h"; include "string.h"; include "interpreter.h"; include "utils.h"; include "script.h"; constant HEAP_SIZE $7FFF; array heap -> HEAP_SIZE; array parsebuffer -> 256; ! Draw the status line. [ draw_status; @split_window 1; @set_window 1; @set_cursor 1 1; style reverse; spaces (0->33)-1; @set_cursor 1 2; print "baZic 0.1 (C) 2001 David Given. "; ! We add on some stuff in the next line, because we don't want to ! include the input buffer in the memory count. print (mem_countfree()+255+AB__SIZE), " bytes free."; @set_cursor 1 1; style roman; @set_window 0; ]; ! Read in a command from the user into the parse buffer. [ read_interactive_command buf in; buf = mem_alloc(255); if (buf == 0) return -2; ! Prompt the user for input. buf->0 = 255; print "> "; read buf 0 draw_status; ! Ensure the string is zero-terminated. in = buf+2; in->(buf->1) = 0; ! Tokenise the stream. in = tokenise_stream(in, parsebuffer); mem_free(buf); return in; ]; ! Clear all variables and reinit the heap. [ cmd_clear; mem_init(store_eop+1, heap+HEAP_SIZE); store_heapclean(); return ESTATE_NORMAL; ]; ! Invoke a command loop. [ command_loop func i; cmd_clear(); do { string_gc(); i = indirect(func); switch (i) { -1: ! success !detokenise_stream(parsebuffer+1); i = execute_command(parsebuffer); break; -2: ! out of memory print "Insufficient memory for interactive prompt!^"; print "Dumping variables and trying again.^"; i = ESTATE_DANGEROUS; break; -3: ! end of program or script or whatever i = ESTATE_ERROR; break; default: ! parse error print "Parse error at offset ", i, ".^"; i = ESTATE_ERROR; break; } } until (i < 0); return i; ]; [ Main i; print "^^^^^^^^baZic v0.1^(C) 2001 David Given^^"; print "To play ~Hunt the Wumpus~, type ~script 2~ to load "; print "the program, and then ~run~ to start it. Try ~script~ on its "; print "own to see what else is available.^^"; do { store_init(heap, heap+HEAP_SIZE); do { i = command_loop(read_interactive_command); } until ((i == ESTATE_QUIT) || (i == ESTATE_NEW)); } until (i == ESTATE_QUIT); ];