Noble Ape
The Central Directories of the Noble Ape Simulation.
 All Data Structures Files Functions Variables Typedefs Enumerations Enumerator Macros
noble.h
Go to the documentation of this file.
1 /****************************************************************
2 
3  noble.h
4 
5  =============================================================
6 
7  Copyright 1996-2014 Tom Barbalet. All rights reserved.
8 
9  Permission is hereby granted, free of charge, to any person
10  obtaining a copy of this software and associated documentation
11  files (the "Software"), to deal in the Software without
12  restriction, including without limitation the rights to use,
13  copy, modify, merge, publish, distribute, sublicense, and/or
14  sell copies of the Software, and to permit persons to whom the
15  Software is furnished to do so, subject to the following
16  conditions:
17 
18  The above copyright notice and this permission notice shall be
19  included in all copies or substantial portions of the Software.
20 
21  THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
22  EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
23  OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
24  NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
25  HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
26  WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
27  FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
28  OTHER DEALINGS IN THE SOFTWARE.
29 
30  This software and Noble Ape are a continuing work of Tom Barbalet,
31  begun on 13 June 1996. No apes or cats were harmed in the writing
32  of this software.
33 
34  ****************************************************************/
35 
41 #ifndef _NOBLEAPE_NOBLE_H_
42 #define _NOBLEAPE_NOBLE_H_
43 /* Variable Definitions */
44 
45 #define SCRIPT_DEBUG /* Add all the runtime debug */
46 #undef COMMAND_LINE_DEBUG /* Sends the debug output as printf output - added through command line build */
47 #undef ROUGH_CODE_OUT /* printf outputs the interpret stream in character number format */
48 
49 #ifdef OVERWRITE_THREADED
50 
51 #else
52 
53 #ifdef NOBLE_IOS
54  #undef EXECUTE_THREADED
55 #else
56  #define EXECUTE_THREADED
57 #endif
58 
59 #endif
60 
61 #ifdef COMMAND_LINE_EXPLICIT
62 
63 #define NOBLE_APE_ASSERT
64 
65 #else
66 
67 #undef NOBLE_APE_ASSERT
68 
69 #endif
70 
72 #define SHORT_VERSION_NAME "Noble Ape 0.699 "
73 #define FULL_DATE __DATE__
74 
76 #define VERSION_NUMBER 699
77 #define COPYRIGHT_DATE "Copyright 1996 - 2014 "
78 
79 #define FULL_VERSION_COPYRIGHT "Copyright Tom Barbalet, 1996-2014."
80 
82 #define NOBLE_APE_SIGNATURE (('N'<< 8) | 'A')
83 #define NOBLE_WARFARE_SIGNATURE (('N'<< 8) | 'W')
84 
85 #define COPYRIGHT_NAME "Tom Barbalet. "
86 #define COPYRIGHT_FOLLOW "All rights reserved."
87 
88 #define PACKED_DATA_BLOCK (32*32*32*2)
89 
90 typedef double n_double;
91 
92 #define TWO_PI ((n_double)(6.2831853071795864769252867665590057683943))
93 
94 #define SINE_MAXIMUM (26880)
95 
98 typedef char * n_string;
99 
100 typedef const char * n_constant_string;
101 
102 #define STRING_BLOCK_SIZE (2048)
103 
105 
108 typedef unsigned char n_byte;
112 typedef unsigned short n_byte2;
113 
114 typedef unsigned int n_byte4;
115 typedef int n_c_int;
116 
117 #ifndef _WIN64
118 
122 typedef unsigned long n_uint;
123 
127 typedef long n_int;
128 
129 #else
130 
131 typedef unsigned long long n_uint;
132 typedef long long n_int;
133 
134 #endif
135 
136 typedef short n_audio;
137 
138 
139 #ifdef NOBLE_APE_ASSERT
140 
141 #define NA_ASSERT(test, message) if(!(test))io_assert(message, __FILE__, __LINE__)
142 
143 void io_assert(n_string message, n_string file_loc, n_int line);
144 
145 #else
146 
147 #define NA_ASSERT(test, message) /* test message */
148 
149 #endif
150 
151 #define AUDIO_FFT_MAX_BITS (15)
152 #define AUDIO_FFT_MAX_BUFFER (1<<AUDIO_FFT_MAX_BITS)
153 
154 void audio_fft(n_byte inverse, n_uint power_sample);
155 void audio_clear_buffers(n_uint length);
156 void audio_clear_output(n_audio * audio, n_uint length);
157 
158 void audio_equal_output(n_audio * audio, n_uint length);
159 
160 void audio_multiply_output(n_audio * audio, n_uint length);
161 void audio_set_frequency(n_uint entry, n_uint value);
162 
174 typedef struct
175 {
178 } n_version;
179 
185 typedef struct
186 {
189 } n_vect2;
190 
191 typedef struct
192 {
194  n_byte2 location[2];
196 }
198 
207 typedef struct
208 {
209  n_byte characters[7];
215 
216 #define POPULATED(ch) ((ch[0] != 0) || (ch[1] != 0) || (ch[2] != 0) || (ch[3] != 0) || (ch[4] != 0) || (ch[5] != 0))
217 
218 /* include externally, if needed */
219 
220 #define FILE_COPYRIGHT 0x00
221 
223 {
229 };
230 
231 #define FILE_INCL(num) ((num) & 0xf0)
232 #define FILE_KIND(num) ((num) & 0x0f)
233 
234 #define FILE_EOF 0x0100
235 
236 #define ASCII_NUMBER(val) (((val) >= '0') && ((val) <= '9'))
237 #define ASCII_LOWERCASE(val) (((val) >= 'a') && ((val) <= 'z'))
238 #define ASCII_UPPERCASE(val) (((val) >= 'A') && ((val) <= 'Z'))
239 
240 #define FILE_OKAY 0x0000
241 #define FILE_ERROR (-1)
242 
243 typedef n_string (n_console_input)(n_string value, n_int length);
244 
245 typedef void (n_console_output)(n_constant_string value);
246 
247 typedef n_byte (n_pixel)(n_int px, n_int py, n_int dx, n_int dy, void * information);
248 
249 typedef n_int (n_memory_location)(n_int px, n_int py);
250 
251 typedef n_byte2 (n_patch)(n_byte2 * local);
252 
253 typedef n_int (n_console)(void * ptr, n_string response, n_console_output output_function);
254 
255 typedef n_int (n_file_in)(n_byte * buff, n_uint len);
256 
257 typedef n_byte * (n_file_out)(n_uint * len);
258 
259 typedef struct
260 {
261  n_console * function;
266 
281 typedef struct
282 {
284  void * information;
285 } n_join;
286 
287 typedef struct
288 {
291 } n_background8;
292 
293 typedef struct
294 {
297 } n_color8;
298 
309 typedef struct
310 {
314 } n_file;
315 
316 typedef void (n_file_specific)(n_string string, n_byte * reference);
317 
318 typedef struct
319 {
320  void * data;
323  void * next;
324 } n_file_chain;
325 
327 #define NEW_SD_MULTIPLE 26880
328 
330 {
331  NUM_VIEW = (0),
333 #ifndef GRAPHLESS_GUI
334  ,NUM_GRAPH = (2)
335 #endif
336 };
337 
338 /* maximum bytes in a braincode program */
339 #define BRAINCODE_SIZE 128
340 
341 /* number of probes which can be applied to the brain */
342 #define BRAINCODE_PROBES (BRAINCODE_SIZE>>3)
343 
344 #define BRAINCODE_PSPACE_REGISTERS 3
345 /* maximum frequency of a brain probe */
346 #define BRAINCODE_MAX_FREQUENCY 16
347 
348 /* number of bytes per instruction */
349 #define BRAINCODE_BYTES_PER_INSTRUCTION 3
350 
351 /* number of instructions which a MVB copies */
352 #define BRAINCODE_BLOCK_COPY 16
353 
354 #define BRAINCODE_MAX_ADDRESS (BRAINCODE_SIZE*2)
355 #define BRAINCODE_ADDRESS(i) ((i) % BRAINCODE_MAX_ADDRESS)
356 
358 {
361 };
362 
363 /* instruction codes */
364 
366 {
367  /* data */
370 
371  /* operators */
385 
386  /* conditionals */
395 
396  /* sensors */
400 
401  /* actuators */
406 
408 };
409 
410 #ifndef GRAPHLESS_GUI
411 
413 {
415 
427 };
428 
429 #endif
430 
431 typedef enum
432 {
442 
444 {
448 #ifndef GRAPHLESS_GUI
453 #endif
454 };
455 
456 typedef enum
457 {
462 } KIND_OF_USE;
463 
464 typedef enum
465 {
467 
473 
477 
479 
482 
490 
509 
511 } AE_ENUM;
512 
513 typedef struct
514 {
518 } n_ae_error;
519 
521 static const n_ae_error apescript_errors[]=
522 {
523  {AE_UNKNOWN_ERROR, "Unknown error", "Please contact tom at nobleape dot com"},
524  {AE_NUMBER_EXPECTED, "Number expected", "A non-numeric character is included in a number string."},
525  {AE_NUMBER_OUT_OF_RANGE, "Number out of range", "Number does not fit in the range"},
526  {AE_MAXIMUM_NUMBERS_REACHED, "Maximum numbers reached", "Please contact tom at nobleape dot com"},
527  {AE_MAXIMUM_SCRIPT_SIZE_REACHED, "Maximum script size reached", "Please contact tom at nobleape dot com"},
528  {AE_MAXIMUM_VARIABLES_REACHED, "Maximum variables reached", "Please contact tom at nobleape dot com"},
529  {AE_UNKNOWN_SYNTAX_PARSER_BUFFER, "Unknown syntax (parser buffer)", "Syntax is incorrect"},
530  {AE_UNKNOWN_SYNTAX_PARSER_CONVERT, "Unknown syntax (parser convert)", "Syntax is incorrect"},
531 
532  {AE_SELECTED_ENTITY_OUT_OF_RANGE, "Selected entity out of range", "Selected entity is outside the bounds of the number of entities."},
533  {AE_COORDINATES_OUT_OF_RANGE, "Coordinates out of range", "Coordinates outside the prescribed range."},
534  {AE_VALUE_OUT_OF_RANGE, "Value out of range", "Value outside the presecribed range."},
535 
536  {AE_TOO_MANY_CLOSE_BRACES, "Too many }", "You have closed too many braces. Go back to the code and see if there is an erroneous additional } in the code."},
537  {AE_MAXIMUM_BRACES_REACHED, "Maximum braces reached", "Please contact tom at nobleape dot com"},
538  {AE_FIRST_VALUE_FAILED, "First value failed", "Something is wrong with the first value of an equality, if or while operation. It could be the first and only value in this function."},
539  {AE_SECOND_VALUE_FAILED, "Second value failed", "Something is wrong with the second number/variable value of an equality, if or while operation."},
540  {AE_UNKNOWN_SYNTAX_MISSING_EQUALS, "Unknown syntax (missing =)", "Syntax is incorrect"},
541  {AE_UNKNOWN_SYNTAX_NO_COMMAND, "Unknown syntax (no command)", "Syntax is incorrect"},
542  {AE_WRONG_END, "Wrong end", "A bracket or colon was expected but not found."},
543 
544  {AE_LINE_START_INCORRECT, "Line start incorrect", "A line of code begins incorrectly. It could start with a number or an operator when if/while or a variable was expected."},
545  {AE_OUTPUT_SET_AS_INPUT_VARIABLE, "Output set as input variable", "An output only variable is attempting to be set."},
546  {AE_IF_WHILE_NOT_FOLLOWED_BY_BRACKET, "if/while not followed by {", "All if/while statements require a bracket following the if/while (allowing for any amount of whitespace too)."},
547  {AE_FUNCTION_ISNT_VARIABLE, "Function isn't variable", "Function must not be a special term."},
548  {AE_NON_FUNCTION_APPLIED, "Non-function applied", "Expecting a function."},
549  {AE_FUNCTION_DEFINED_PRIOR, "Function defined prior", "Single function definition only."},
550  {AE_FUNCTION_OUT_OF_RANGE, "Function out of range", "Function defined outside the range of the code presented."},
551  {AE_WITHOUT_SEMICOLON, "Without ;", "Semi-colon required."},
552  {AE_WITHOUT_OPEN_BRACE, "Without {", "All if/while statements expect what is executed through the bracket enclosed statement being correct to be followed by inclusive braces { }. There is no single line if or while statements without { } in ApeScript."},
553 
554  {AE_FUNCTION_SETTING_FAILED, "Function setting failed", "Function could not be set."},
555  {AE_ERROR_STARTING_MAIN, "Error starting main", "Main could not be started."},
556  {AE_CODE_AFTER_MAIN, "Code after main", "All the code in ApeScript must exist before the end of main."},
557  {AE_NO_CLOSE_BRACE_TO_END_OF_FILE, "No } to end of file", "Based on the final main function it is expected that the last meaningful character will be }."},
558  {AE_CODE_OUTSIDE_FUNCTION, "Code outside function", "All code in ApeScript needs to exist within functions."},
559  {AE_INPUT_VARIABLE_WITHOUT_EQUALS, "Input variable without equals", "All variables set require an equals following the variable."},
560  {AE_ASSIGN_VALUE_FAILED, "Assign value failed", "Something is wrong with the variable set by an equality."},
561  {AE_UNKNOWN_SYNTAX_FROM_INTERPRET, "Unknown syntax (from interpret)", "Syntax is incorrect"},
562  {AE_NO_MAIN_CODE, "No main code", "ApeScript requires a main function."},
563 
564  {AE_NO_ERROR, 0L, 0L}
565 };
566 
567 extern n_int draw_error(n_constant_string error_text, n_constant_string location, n_int line_number);
568 
569 /* "---1---2---3---4---5---6---7--" */ /* length of the errors */
570 
571 #define SHOW_ERROR(val) (draw_error(val, __FILE__, __LINE__))
572 
573 #define IO_LOWER_CHAR(value) if(ASCII_UPPERCASE(value)) (value) += 'a' - 'A'
574 
575 
576 typedef n_int (execute_function)(void * general_data, void * read_data, void * write_data);
577 
578 void execute_add(execute_function function, void * general_data, void * read_data, void * write_data);
579 
580 void execute_group(execute_function * function, void * general_data, void * read_data, n_int count, n_int size);
581 
582 void execute_init(void);
583 
584 void execute_close(void);
585 
586 void execute_complete_added(void);
587 
588 void execute_threads(n_int value);
590 n_int execute_toggle(n_int toggle);
591 
592 void vect2_byte2(n_vect2 * converter, n_byte2 * input);
593 void vect2_add(n_vect2 * equals, n_vect2 * initial, n_vect2 * second);
594 void vect2_center(n_vect2 * center, n_vect2 * initial, n_vect2 * second);
595 
596 void vect2_subtract(n_vect2 * equals, n_vect2 * initial, n_vect2 * second);
597 void vect2_multiplier(
598  n_vect2 * equals, n_vect2 * initial,
599  n_vect2 * second, n_int multiplier, n_int divisor);
600 void vect2_d(
601  n_vect2 * initial, n_vect2 * second,
602  n_int multiplier, n_int divisor);
604  n_vect2 * initial, n_vect2 * second,
605  n_int multiplier, n_int divisor);
606 void vect2_rotate90(n_vect2 * rotation);
607 void vect2_direction(n_vect2 * initial, n_int direction, n_int divisor);
608 void vect2_offset(n_vect2 * initial, n_int dx, n_int dy);
609 void vect2_back_byte2(n_vect2 * converter, n_byte2 * output);
610 void vect2_copy(n_vect2 * to, n_vect2 * from);
611 void vect2_populate(n_vect2 * value, n_int x, n_int y);
612 
613 void vect2_rotation(n_vect2 * location, n_vect2 * rotation);
614 
615 n_int vect2_nonzero(n_vect2 * nonzero);
616 
618 void vect2_min_max(n_vect2 * points, n_int number, n_vect2 * maxmin);
619 
621 
622 void math_general_execution(n_int instruction, n_int is_constant0, n_int is_constant1,
623  n_byte * addr0, n_byte * addr1, n_int value0, n_int * i,
624  n_int is_const0, n_int is_const1,
625  n_byte * pspace,
626  n_byte **maddr0, n_byte **maddr1,
627  n_byte *bc0, n_byte *bc1,
628  n_int braincode_min_loop);
629 
631 n_uint math_hash(n_byte * values, n_uint length);
632 
633 void math_bilinear_8_times(n_byte * side512, n_byte * data, n_byte double_spread);
634 
635 n_uint math_root(n_uint squ);
637 n_byte2 math_random(n_byte2 * local);
638 void math_random3(n_byte2 * local);
639 n_byte math_join(n_int sx, n_int sy, n_int dx, n_int dy, n_join * draw);
641 void math_pack(n_int size, n_byte value, n_byte * alloc1, n_byte *alloc2);
643 void math_patch(n_byte * local_map,
644  n_memory_location * mem_func,
645  n_patch * func, n_byte2 * arg,
646  n_int refine);
647 void math_round(n_byte * local_map, n_byte * scratch,
648  n_memory_location * mem_func);
649 
650 void math_round_smarter(n_byte * local_map, n_byte * scratch,
651  n_memory_location * mem_func);
652 
653 n_int math_sine(n_int direction, n_int divisor);
654 
655 n_byte math_join_vect2(n_int sx, n_int sy, n_vect2 * vect, n_join * draw);
656 n_byte math_line_vect(n_vect2 * point1, n_vect2 * point2, n_join * draw);
657 n_byte math_line(n_int x1, n_int y1, n_int x2, n_int y2, n_join * draw);
658 
659 void io_entry_execution(n_int argc, n_string * argv);
662 
663 void io_lower(n_string value, n_int length);
664 void io_whitespace(n_file * input);
665 void io_audit_file(const noble_file_entry * format, n_byte section_to_audit);
666 void io_search_file_format(const noble_file_entry * format, n_string compare);
667 void io_string_write(n_string dest, n_string insert, n_int * pos);
668 n_int io_read_bin(n_file * fil, n_byte * local_byte);
669 n_int io_file_write(n_file * fil, n_byte byte);
670 void io_file_reused(n_file * fil);
671 n_int io_write(n_file * fil, n_constant_string ch, n_byte new_line);
672 n_int io_writenumber(n_file * fil, n_int loc_val, n_uint numer, n_uint denom);
673 n_int io_length(n_string value, n_int max);
674 n_int io_find(n_string check, n_int from, n_int max, n_string value_find, n_int value_find_length);
675 n_int io_read_buff(n_file * fil, n_byte * data, const noble_file_entry * commands);
676 n_int io_write_buff(n_file * fil, void * data, const noble_file_entry * commands, n_byte command_num, n_file_specific * func);
677 n_int io_write_csv(n_file * fil, n_byte * data, const noble_file_entry * commands, n_byte command_num, n_byte initial) ;
678 void io_copy(n_byte * from, n_byte * to, n_uint number);
679 void * io_new(n_uint bytes);
680 void io_free(void ** ptr);
681 void * io_new_range(n_uint memory_min, n_uint *memory_allocated);
682 n_file * io_file_new(void);
683 void io_file_free(n_file ** file);
684 
685 n_int io_number(n_string number_string, n_int * actual_value, n_int * decimal_divisor);
686 
687 void audio_aiff_header(void * fptr, n_uint total_samples);
688 
689 void audio_aiff_body(void * fptr, n_audio *samples, n_uint number_samples);
690 
691 n_int io_quit(void * ptr, n_string response, n_console_output output_function);
692 n_int io_help(void * ptr, n_string response, n_console_output output_function);
694 n_string io_console_entry(n_string string, n_int length);
696 n_int io_console(void * ptr, noble_console_command * commands, n_console_input input_function, n_console_output output_function);
697 void io_erase(n_byte * buf_offscr, n_uint nestop);
698 n_int io_disk_read(n_file * local_file, n_string file_name);
699 n_int io_disk_write(n_file * local_file, n_string file_name);
701 n_string * io_tab_delimit_to_n_string_ptr(n_file * tab_file, n_int * size_value, n_int * row_value);
702 
703 void io_three_string_combination(n_string output, n_string first, n_string second, n_string third, n_int count);
704 void io_time_to_string(n_string value, n_int minutes, n_int days);
705 n_int io_read_byte4(n_file * fil, n_uint * actual_value, n_byte * final_char);
706 n_int io_writenum(n_file * fil, n_int loc_val, n_byte ekind, n_byte new_line);
707 n_int io_command(n_file * fil, const noble_file_entry * commands);
708 n_int io_read_data(n_file * fil, n_byte2 command, n_byte * data_read);
709 void io_help_line(noble_console_command * specific, n_console_output output_function);
710 
711 void io_console_quit(void);
712 
713 void io_output_contents(n_file * file);
714 
715 n_file * io_file_ready(n_int entry, n_file * file);
716 
717 void io_file_cleanup(n_int * entry, n_file ** file);
718 
719 void io_file_writeon(n_int * entry, n_file ** file, n_byte blocked_write);
720 
721 void io_file_writeoff(n_int * entry, n_file * file);
722 
723 void io_file_string(n_int entry, n_file * file, n_constant_string string);
724 
725 void io_offset(n_byte * start, n_byte * point, n_string text);
726 
728 
729 void compress_compress(n_file *input, n_file *output);
730 void compress_expand(n_file *input, n_file *output);
731 
732 #ifdef NOBLE_IOS
733 
734 #define MAP_BITS (8)
735 
736 #else
737 
738 #define MAP_BITS (9)
739 
740 #endif
741 
742 #define MAP_DIMENSION (1<<(MAP_BITS))
743 #define MAP_AREA (1<<(2*MAP_BITS))
744 
745 #define APESPACE_TO_MAPSPACE(num) ((num)>>6)
746 
747 #define HI_RES_MAP_BITS (MAP_BITS+3)
748 
749 #define HI_RES_MAP_DIMENSION (1<<(HI_RES_MAP_BITS))
750 #define HI_RES_MAP_AREA (1<<(2*HI_RES_MAP_BITS))
751 
752 #define APESPACE_TO_HR_MAPSPACE(num) ((num)>>3)
753 
754 #define MAPSPACE_TO_APESPACE(num) ((num)<<6)
755 
756 #define MAP_APE_RESOLUTION_SIZE (MAPSPACE_TO_APESPACE(MAP_DIMENSION))
757 #define APESPACE_BOUNDS ((MAP_APE_RESOLUTION_SIZE)-1)
758 
759 #define APESPACE_CONFINED(num) (n_byte2)((num)>APESPACE_BOUNDS ? APESPACE_BOUNDS : ((num)<0 ? 0 : (num)))
760 #define APESPACE_WRAP(num) (n_byte2)((num + APESPACE_BOUNDS)&(APESPACE_BOUNDS-1))
761 
762 #define LAND_TILE_EDGE (256)
763 #define POSITIVE_LAND_COORD(num) ((num+(3*MAP_DIMENSION))&(MAP_DIMENSION-1))
764 #define POSITIVE_LAND_COORD_HIRES(num) ((num+(3*HI_RES_MAP_DIMENSION))&(HI_RES_MAP_DIMENSION-1))
765 #define NUMBER_LAND_TILES (MAP_DIMENSION/LAND_TILE_EDGE)
766 #define WEATHER_TO_MAPSPACE(num) ((num)*2)
767 
768 #define LAND_DITHER(x,y,z) (((x+y+z)&15)-(((x&y)|z)&7)-((x|(y&z))&7))
769 
770 #ifdef GRAPHLESS_GUI
771 
772 #define OFFSCREENSIZE (MAP_AREA + TERRAIN_WINDOW_AREA)
773 
774 #else
775 
776 #define OFFSCREENSIZE (MAP_AREA + TERRAIN_WINDOW_AREA + GRAPH_WINDOW_AREA)
777 
778 #endif
779 
780 #define WEATHER_CLOUD (32768)
781 #define WEATHER_RAIN (98304)
782 
783 #define TIME_HOUR_MINUTES (60)
784 #define TIME_DAY_MINUTES (TIME_HOUR_MINUTES * 24)
785 #define TIME_MONTH_MINUTES (TIME_DAY_MINUTES * 28)
786 #define TIME_YEAR_MINUTES (TIME_MONTH_MINUTES * 13)
787 #define TIME_YEAR_DAYS (7 * 52) /*364 also = 13 * 28 */
788 #define TIME_CENTURY_DAYS (TIME_YEAR_DAYS * 100)
789 
790 #define LUNAR_ORBIT_MINS 39312
791 
792 #define WATER_TEST(pz,w) ((pz)<(w))
793 
794 #define WATER_MAP 128
795 
796 #define TIDE_AMPLITUDE_LUNAR 8
797 #define TIDE_AMPLITUDE_SOLAR 2
798 
799 #define TIDE_MAX (WATER_MAP + TIDE_AMPLITUDE_LUNAR + TIDE_AMPLITUDE_SOLAR)
800 
801 /* Night/Day definitions */
802 #define IS_NIGHT(num) ((((num)>>5) < (11))||(((num)>>5) > (36)))
803 #define IS_DAWNDUSK(num) ((((num)>>5) == (11))||(((num)>>5) == (36)))
804 
805 #define NIGHT_END_POINT (256)
806 #define DAWN_END_POINT (384)
807 #define DAY_END_POINT (1152)
808 #define DUSK_END_POINT (1184)
809 
810 #define MAX_MODIFIED_TIME (238)
811 
812 #define NIGHT_TIME_DIVISION(time) ((time)>>4)
813 #define DAWN_DUSK_TIME_DIVISION(time) ((time)>>3)
814 #define DAY_TIME_DIVISION(time) ((time)>>2)
815 
816 /*
817  Night 1184 - 1439
818  Night 0 - 351
819  Dawn 352 - 383
820  Day 384 - 1151
821  Dusk 1152 - 1183
822  */
823 
824 typedef struct
825 {
826  n_byte4 date; /* save-able */
827  n_byte2 genetics[2]; /* save-able */
828  n_byte2 time; /* save-able */
829 
830  n_byte topology[MAP_AREA]; /* generated */
831  n_byte topology_highdef[HI_RES_MAP_AREA * 2]; /* generated */
832  n_byte4 highres_tide[HI_RES_MAP_AREA/32]; /* generated */
833  n_byte2 delta_pressure[ MAP_AREA / 4]; /* generated */
834  n_c_int atmosphere[ MAP_AREA / 4]; /* save-able and generate-able */
835  n_byte tide_level; /* generated */
836 }
837 n_land;
838 
839 void weather_init(n_land * local_land);
840 void weather_wind_vector(n_land * local_land, n_vect2 * pos, n_vect2 * wind);
841 n_int weather_pressure(n_land * local_land, n_int px, n_int py);
842 void weather_cycle(n_land * local_land);
844 
845 void land_init(n_land * local_land, n_byte * scratch, n_byte double_spread);
846 void land_clear(n_land * local, KIND_OF_USE kind, n_byte4 start);
847 void land_cycle(n_land * local_land);
848 void land_vect2(n_vect2 * output, n_int * actual_z, n_land * local, n_vect2 * location);
849 n_int land_operator_interpolated(n_land * local_land, n_int locx, n_int locy, n_byte * kind);
850 
852 n_int land_map_bits(n_land * land);
853 
854 void land_tide(n_land * local_land);
855 n_int land_location(n_land * land, n_int px, n_int py);
856 
857 
858 /*0*/
859 
861 {
866 };
867 
869 {
876 
884 
886 
889 
892 
894 };
895 
897 {
902 };
903 
905 {
912  APESCRIPT_TEXT = ('t'),
916  APESCRIPT_RUN = ('r'),
918 };
919 
920 #define ASCII_QUOTE(num) ((num) == '"')
921 
922 #define ASCII_TEXT(num) ((ASCII_UPPERCASE(num) || ASCII_LOWERCASE(num)) || ((num) == '_'))
923 
924 #define ASCII_SEMICOLON(num) ((num) == ';')
925 
926 #define ASCII_EQUAL(num) ((num) == '=')
927 
928 #define ASCII_BRACKET(num) (((num) == '(')||((num) == ')'))
929 #define ASCII_BRACES(num) (((num) == '{')||((num) == '}'))
930 
931 #define ASCII_LOGICAL(num) ((((num) == '&')||((num) == '|'))||(((num) == '^')||((num) == '!')))
932 #define ASCII_ARITHMETIC(num) ((((num) == '+')||((num) == '-'))||(((num) == '*')||((num) == '/')))
933 
934 #define ASCII_DIRECTIONAL(num) (((num)=='<')||((num)=='>'))
935 
936 #define CODE_VALUE_REQUIRED(num) (((num) == APESCRIPT_OPERATOR || (num) == APESCRIPT_NUMBER) || ((num) == APESCRIPT_TEXT))
937 
938 #define SIZEOF_NUMBER_WRITE (sizeof(n_int))
939 
940 void io_int_to_bytes(n_int value, n_byte * bytes);
941 n_int io_bytes_to_int(n_byte * bytes);
942 
943 #define VARIABLE_INPUT(num,code) ((num)>((code)->input_greater))
944 #define VARIABLE_SPECIAL(num,code) ((num)<((code)->special_less))
945 
946 #ifndef ABS
947 #define ABS(a) (((a) < 0) ? -(a) : (a))
948 #endif
949 
950 #define NUMBER_MAX 256
951 #define VARIABLE_MAX 256
952 
953 #define BRACES_MAX 16
954 #define SIZE_OF_EVALUATE (SIZEOF_NUMBER_WRITE+SIZEOF_NUMBER_WRITE+1) /* (tA=XtB) */
955 
956 #define CYCLE_COUNT_RESET 4096
957 
958 #define MAIN_NOT_RUN 0
959 #define MAIN_RUN 1
960 
970 typedef n_int (script_input )(void * individual, n_byte kind, n_int value);
971 
980 typedef n_int (script_output)(void * code, void * individual, n_byte * kind, n_int * number);
981 
982 typedef void (script_external)(void * individual, void * structure, void * data);
983 
984 #define VARIABLE_WIDTH 32
985 
987 
995 typedef struct
996 {
999 } n_brace;
1000 
1001 
1002 typedef struct
1003 {
1005  n_int number_buffer[NUMBER_MAX]; /* per entry */
1006  variable_string *variable_strings;
1012 } n_interpret;
1013 
1014 typedef struct
1015 {
1016  n_int interpret_location; /* per entry */
1017  n_int leave; /* per entry */
1018  n_int localized_leave; /* per entry */
1019  void * interpret_data; /* per entry */
1020  n_int variable_references[VARIABLE_MAX]; /* per entry */
1021  n_int braces_count; /* per entry */
1022  n_brace braces[BRACES_MAX]; /* per entry */
1023  n_byte main_status; /* per entry */
1025 
1026 
1027 /* used for stripping ApeScript errors for documentation */
1028 
1029 n_int io_apescript_error(void * ptr, AE_ENUM value);
1030 
1031 n_interpret * parse_convert(n_file * input, n_int main_entry, variable_string * variables);
1032 
1033 void interpret_individual(n_individual_interpret * individual);
1034 
1035 void interpret_cleanup(n_interpret ** to_clean);
1036 n_int interpret_cycle(n_interpret * code, n_individual_interpret * individual, n_int exit_offset,
1037  void * structure, void * data,
1038  script_external * start, script_external * end);
1039 
1040 #ifdef SCRIPT_DEBUG
1041 
1042 n_file * scdebug_file_ready(void);
1043 void scdebug_file_cleanup(void);
1044 
1045 void scdebug_string(void * ptr, n_constant_string string);
1046 void scdebug_int(void * ptr, n_int number);
1047 void scdebug_newline(void * ptr);
1048 void scdebug_tabstep(void * ptr, n_int steps);
1049 n_string scdebug_variable(n_int variable);
1050 
1051 void scdebug_writeon(void * ptr);
1052 void scdebug_writeoff(void * ptr);
1053 
1054 n_int spacetime_after(n_spacetime * initial, n_spacetime * second);
1055 void spacetime_copy(n_spacetime * to, n_spacetime * from);
1056 n_int spacetime_before_now(n_spacetime * initial, n_land * now);
1057 void spacetime_set(n_spacetime * set, n_land * local, n_byte2 * location);
1058 
1059 
1060 #define SC_DEBUG_STRING(ptr, string) scdebug_string(ptr, string)
1061 #define SC_DEBUG_NUMBER(ptr, number) scdebug_int(ptr, number)
1062 #define SC_DEBUG_NEWLINE(ptr) scdebug_newline(ptr)
1063 #define SC_DEBUG_UP(ptr) scdebug_tabstep(ptr,1)
1064 #define SC_DEBUG_DOWN(ptr) scdebug_tabstep(ptr,-1)
1065 #define SC_DEBUG_ON(ptr) scdebug_writeon(ptr)
1066 #define SC_DEBUG_OFF(ptr) scdebug_writeoff(ptr)
1067 
1068 #else
1069 
1070 #define SC_DEBUG_STRING(string) /* string */
1071 #define SC_DEBUG_NUMBER(number) /* number */
1072 #define SC_DEBUG_NEWLINE /* */
1073 #define SC_DEBUG_UP /* */
1074 #define SC_DEBUG_DOWN /* */
1075 #define SC_DEBUG_ON(ptr) /* ptr */
1076 #define SC_DEBUG_OFF /* */
1077 
1078 #endif
1079 
1080 #endif /* _NOBLEAPE_NOBLE_H_ */
1081