Increase MAX_STATIC_DATA
[bazic.git] / bazic.inf
1 !% $MAX_STATIC_DATA=150000
2 include "malloc.h";
3 include "tokeniser.h";
4 include "store.h";
5 include "string.h";
6 include "interpreter.h";
7 include "utils.h";
8 include "script.h";
9
10 constant HEAP_SIZE $7FFF;
11 array heap -> HEAP_SIZE;
12 array parsebuffer -> 256;
13
14 ! Draw the status line.
15
16 [ draw_status;
17         @split_window 1;
18         @set_window 1;
19         @set_cursor 1 1;
20         style reverse;
21         spaces (0->33)-1;
22         @set_cursor 1 2;
23         print "baZic 0.1 (C) 2001 David Given.   ";
24         ! We add on some stuff in the next line, because we don't want to
25         ! include the input buffer in the memory count.
26         print (mem_countfree()+255+AB__SIZE), " bytes free.";
27         @set_cursor 1 1;
28         style roman;
29         @set_window 0;
30 ];
31
32 ! Read in a command from the user into the parse buffer.
33
34 [ read_interactive_command  buf in;
35         buf = mem_alloc(255);
36         if (buf == 0)
37                 return -2;
38
39         ! Prompt the user for input.
40
41         buf->0 = 255;
42         print "> ";
43         read buf 0 draw_status;
44
45         ! Ensure the string is zero-terminated.
46
47         in = buf+2;
48         in->(buf->1) = 0;
49
50         ! Tokenise the stream.
51
52         in = tokenise_stream(in, parsebuffer);
53
54         mem_free(buf);
55         return in;
56 ];
57         
58 ! Clear all variables and reinit the heap.
59
60 [ cmd_clear;
61         mem_init(store_eop+1, heap+HEAP_SIZE);
62         store_heapclean();
63         return ESTATE_NORMAL;
64 ];
65
66 ! Invoke a command loop.
67
68 [ command_loop func  i;
69         cmd_clear();
70         do {
71                 string_gc();
72                 i = indirect(func);
73                 switch (i)
74                 {
75                         -1: ! success
76                                 !detokenise_stream(parsebuffer+1);
77                                 i = execute_command(parsebuffer);
78                                 break;
79
80                         -2: ! out of memory
81                                 print "Insufficient memory for interactive prompt!^";
82                                 print "Dumping variables and trying again.^";
83                                 i = ESTATE_DANGEROUS;
84                                 break;
85
86                         -3: ! end of program or script or whatever
87                                 i = ESTATE_ERROR;
88                                 break;
89
90                         default: ! parse error
91                                 print "Parse error at offset ", i, ".^";
92                                 i = ESTATE_ERROR;
93                                 break;
94                 }
95         } until (i < 0);
96         return i;
97 ];
98
99 [ Main  i;
100         print "^^^^^^^^baZic v0.1^(C) 2001 David Given^^";
101         print "To play ~Hunt the Wumpus~, type ~script 2~ to load ";
102         print "the program, and then ~run~ to start it. Try ~script~ on its ";
103         print "own to see what else is available.^^";
104
105         do {
106                 store_init(heap, heap+HEAP_SIZE);
107                 do {
108                         i = command_loop(read_interactive_command);
109                 } until ((i == ESTATE_QUIT) || (i == ESTATE_NEW));
110         } until (i == ESTATE_QUIT);
111 ];
112