-
Notifications
You must be signed in to change notification settings - Fork 20
/
debug.c
3470 lines (2957 loc) · 84 KB
/
debug.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/* MegaZeux
*
* Copyright (C) 2004 Gilead Kutnick <exophase@adelphia.net>
* Copyright (C) 2008 Alistair John Strachan <alistair@devzero.co.uk>
* Copyright (C) 2012 Alice Rowan <petrifiedrowan@gmail.com>
*
* This program is free software; you can redistribute it and/or
* modify it under the terms of the GNU General Public License as
* published by the Free Software Foundation; either version 2 of
* the License, or (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "debug.h"
#include "char_ed.h"
#include "pal_ed.h"
#include "robo_debug.h"
#include "stringsearch.h"
#include "window.h"
#include "../core.h"
#include "../counter.h"
#include "../event.h"
#include "../extmem.h"
#include "../graphics.h"
#include "../intake.h"
#include "../memcasecmp.h"
#include "../scrdisp.h"
#include "../sprite.h"
#include "../str.h"
#include "../util.h"
#include "../window.h"
#include "../world.h"
#include "../io/vio.h"
#include "../audio/audio.h"
#include <ctype.h>
#include <stdint.h>
#include <string.h>
#define TREE_LIST_X 62
#define TREE_LIST_Y 2
#define TREE_LIST_WIDTH 16
#define TREE_LIST_HEIGHT 15
#define VAR_LIST_X 2
#define VAR_LIST_Y 2
#define VAR_LIST_WIDTH 58
#define VAR_LIST_HEIGHT 21
#define BUTTONS_X 62
#define BUTTONS_Y 18
#define CVALUE_SIZE 11
#define LVALUE_SIZE 21
#define SVALUE_SIZE 40
#define CVALUE_COL_OFFSET (VAR_LIST_WIDTH - CVALUE_SIZE - 1)
#define LVALUE_COL_OFFSET (VAR_LIST_WIDTH - LVALUE_SIZE - 1)
#define SVALUE_COL_OFFSET (VAR_LIST_WIDTH - SVALUE_SIZE - 1)
#define VAR_SEARCH_DIALOG_X 4
#define VAR_SEARCH_DIALOG_Y 9
#define VAR_SEARCH_DIALOG_W 71
#define VAR_SEARCH_DIALOG_H 5
#define VAR_SEARCH_MAX 48
#define VAR_SEARCH_NAMES 1
#define VAR_SEARCH_VALUES 2
#define VAR_SEARCH_CASESENS 4
#define VAR_SEARCH_REVERSE 8
#define VAR_SEARCH_WRAP 16
#define VAR_SEARCH_LOCAL 32
#define VAR_SEARCH_EXACT 64
#define VAR_ADD_DIALOG_X 20
#define VAR_ADD_DIALOG_Y 8
#define VAR_ADD_DIALOG_W 40
#define VAR_ADD_DIALOG_H 6
#define VAR_ADD_MAX 30
static const char asc[17] = "0123456789ABCDEF";
// Escape \n. Use for most debug var name/text fields. This is intended for
// display only and doesn't escape \. For anything that needs to be edited
// or unescaped, use copy_substring_escaped instead. FIXME it'd be nice if
// list box elements could print these chars instead of making this necessary.
static void copy_name_escaped(char *dest, size_t dest_len, const char *src,
size_t src_len)
{
unsigned int i, j, left;
for(i = 0, j = 0; j < src_len; i++, j++)
{
left = dest_len - i;
if(src[j] == '\n')
{
if(left < 3)
break;
dest[i++] = '\\';
dest[i] = 'n';
}
else
{
if(left < 2)
break;
dest[i] = src[j];
}
}
dest[i] = 0;
}
// Escape all non-ASCII chars. Use for string values.
static void copy_substring_escaped(char *dest, size_t dest_len, const char *src,
size_t src_len)
{
unsigned int i, j, left;
for(i = 0, j = 0; j < src_len; i++, j++)
{
left = dest_len - i;
if(src[j] == '\\')
{
if(left < 3)
break;
dest[i++] = '\\';
dest[i] = '\\';
}
else
if(src[j] == '\n')
{
if(left < 3)
break;
dest[i++] = '\\';
dest[i] = 'n';
}
else
if(src[j] == '\r')
{
if(left < 3)
break;
dest[i++] = '\\';
dest[i] = 'r';
}
else
if(src[j] == '\t')
{
if(left < 3)
break;
dest[i++] = '\\';
dest[i] = 't';
}
else
if(src[j] < 32 || src[j] > 126)
{
if(left < 5)
break;
dest[i++] = '\\';
dest[i++] = 'x';
dest[i++] = asc[src[j] >> 4];
dest[i] = asc[src[j] & 15];
}
else
{
if(left < 2)
break;
dest[i] = src[j];
}
}
dest[i] = 0;
}
// Unescape a string escaped by copy_substring_escaped.
static void unescape_string(char *buf, int *len)
{
size_t i = 0, j, old_len = strlen(buf);
char tmp[3];
for(j = 0; j < old_len; i++, j++)
{
if(buf[j] != '\\')
{
buf[i] = buf[j];
continue;
}
j++;
if(j == old_len)
break;
switch(buf[j])
{
case 'n':
buf[i] = '\n';
break;
case 'r':
buf[i] = '\r';
break;
case 't':
buf[i] = '\t';
break;
case '\\':
buf[i] = '\\';
break;
case 'x':
if(j + 2 >= old_len)
{
j = old_len;
break;
}
tmp[0] = buf[j + 1];
tmp[1] = buf[j + 2];
tmp[2] = '\0';
buf[i] = strtol(tmp, NULL, 16);
j += 2;
break;
default:
buf[i] = buf[j];
break;
}
}
(*len) = i;
}
/***********************
* Var reading/setting *
***********************/
enum virtual_var
{
VIR_RAM_COUNTER_LIST,
VIR_RAM_COUNTER_TABLE,
VIR_RAM_COUNTERS,
VIR_RAM_STRING_LIST,
VIR_RAM_STRING_TABLE,
VIR_RAM_STRINGS,
VIR_RAM_SPRITES,
VIR_RAM_VLAYER,
VIR_RAM_BOARD_INFO,
VIR_RAM_BOARD_DATA,
VIR_RAM_BOARD_OVERLAY,
VIR_RAM_ROBOT_INFO,
VIR_RAM_ROBOT_STACK,
VIR_RAM_ROBOT_SOURCE,
VIR_RAM_ROBOT_PROGRAMS,
VIR_RAM_ROBOT_PROGRAM_LABELS,
VIR_RAM_SCROLLS_SENSORS,
VIR_RAM_VIDEO_LAYERS,
VIR_RAM_DEBUGGER_ROBOTS,
VIR_RAM_DEBUGGER_VARIABLES,
VIR_RAM_EXTRAM_DELTA,
VIR_RAM_VIRTUAL_FILESYSTEM,
VIR_RAM_VIRTUAL_FILESYSTEM_CACHED_ONLY,
};
static const char * const virtual_var_names[] =
{
"Counter list*",
"Counter table*",
"Counters*",
"String list*",
"String table*",
"Strings*",
"Sprites*",
"Vlayer*",
"Board info*",
"Board data*",
"Board overlay*",
"Robot info*",
"Robot stack*",
"Robot program source*",
"Robot program bytecode*",
"Robot program labels*",
"Scrolls and sensors*",
"Video layers*",
"Debug (robots)*",
"Debug (variables)*",
"ExtRAM compression delta*",
"Virtual filesystem (total)*",
"Virtual filesystem (cached only)*",
};
// We'll read off of these when we construct the tree
static const char *universal_var_list[] =
{
"random_seed0",
"random_seed1",
"date_year*",
"date_month*",
"date_day*",
"time_hours*",
"time_minutes*",
"time_seconds*",
"time_millis*",
};
static const char *world_var_list[] =
{
"bimesg", //no read
"c_divisions",
"commands",
"commands_stop",
"divider",
"fread_delimiter", //no read
"fwrite_delimiter", //no read
"joy_simulate_keys", //no read
"max_samples",
"mod_frequency",
"mod_length*",
"mod_loopend",
"mod_loopstart",
"mod_name*",
"mod_order",
"mod_position",
"multiplier",
"mzx_speed",
"smzx_message",
"smzx_mode*",
"spacelock", //no read
"vlayer_size*",
"vlayer_width*",
"vlayer_height*",
};
static const enum virtual_var world_ram_var_list[] =
{
VIR_RAM_COUNTER_LIST,
VIR_RAM_COUNTER_TABLE,
VIR_RAM_COUNTERS,
VIR_RAM_STRING_LIST,
VIR_RAM_STRING_TABLE,
VIR_RAM_STRINGS,
VIR_RAM_SPRITES,
VIR_RAM_VLAYER,
VIR_RAM_BOARD_INFO,
VIR_RAM_BOARD_DATA,
VIR_RAM_BOARD_OVERLAY,
VIR_RAM_ROBOT_INFO,
VIR_RAM_ROBOT_STACK,
#ifdef CONFIG_DEBYTECODE
VIR_RAM_ROBOT_SOURCE,
#endif
VIR_RAM_ROBOT_PROGRAMS,
VIR_RAM_ROBOT_PROGRAM_LABELS,
VIR_RAM_SCROLLS_SENSORS,
VIR_RAM_VIDEO_LAYERS,
VIR_RAM_DEBUGGER_ROBOTS,
VIR_RAM_DEBUGGER_VARIABLES,
#ifdef CONFIG_EXTRAM
VIR_RAM_EXTRAM_DELTA,
#endif
VIR_RAM_VIRTUAL_FILESYSTEM,
VIR_RAM_VIRTUAL_FILESYSTEM_CACHED_ONLY,
};
static const char *board_var_list[] =
{
"board_name*",
"board_mod*", //no read
"board_w*",
"board_h*",
"input", // as a counter
"input*", // as a string (no read function; handled in interpolation code)
"inputsize",
"key",
"overlay_mode*",
"playerfacedir",
"playerlastdir",
"playerx*",
"playery*",
"scrolledx*",
"scrolledy*",
"timereset",
"volume", //no read or write
};
// Locals are added onto the end later.
static const char *robot_var_list[] =
{
"robot_name*",
"commands_total", //no read or write
"commands_cycle*", //no read
"bullettype",
"lava_walk",
"goop_walk",
"lockself", //no read or write
"loopcount",
"thisx*",
"thisy*",
"this_char*",
"this_color*",
"playerdist*",
"horizpld*",
"vertpld*",
};
// Sprite parent list (note: clist# added to end)
static const char *sprite_parent_var_list[] =
{
"Active sprites*", // no read/write
"spr_num",
"spr_yorder",
"spr_collisions*",
};
// The following will all be added to the end of 'sprN_'
static const char *sprite_var_list[] =
{
"x",
"y",
"z",
"refx",
"refy",
"width",
"height",
"cx",
"cy",
"cwidth",
"cheight",
"ccheck", // no read
"off",
"offset",
"overlay", // no read
"static", // no read
"tcol",
"unbound",
"vlayer", // no read
};
static const char *sensor_var_list[] =
{
"Sensor name*", // no read/write
"Robot to mesg*", // no read/write
};
static const char *scroll_text_var = "Scroll text*";
static const int num_universal_vars = ARRAY_SIZE(universal_var_list);
static const int num_world_vars = ARRAY_SIZE(world_var_list);
static const int num_world_ram_vars = ARRAY_SIZE(world_ram_var_list);
static const int num_board_vars = ARRAY_SIZE(board_var_list);
static const int num_robot_vars = ARRAY_SIZE(robot_var_list);
static const int num_sprite_parent_vars = ARRAY_SIZE(sprite_parent_var_list);
static const int num_sprite_vars = ARRAY_SIZE(sprite_var_list);
static const int num_sensor_vars = ARRAY_SIZE(sensor_var_list);
enum debug_var_type
{
V_COUNTER,
V_STRING,
V_VAR,
V_VIRTUAL_VAR,
V_SPRITE_VAR,
V_SPRITE_CLIST,
V_LOCAL_VAR,
V_SCROLL_TEXT,
};
struct debug_var
{
// This goes first so this struct can act like a char * for the dialog.
char text[VAR_LIST_WIDTH + 1];
// Internal data
unsigned char type;
unsigned char id;
boolean is_empty;
union
{
struct counter *counter;
struct string *string;
const char *var_name;
enum virtual_var virtual_var;
int clist_num;
int local_num;
}
data;
};
struct debug_ram_data
{
size_t counter_list_size;
size_t counter_table_size;
size_t counter_struct_size;
size_t string_list_size;
size_t string_table_size;
size_t string_struct_size;
size_t sprites_size;
size_t vlayer_size;
size_t board_list_and_struct_size;
size_t board_data_size;
size_t board_overlay_size;
size_t robot_list_and_struct_size;
size_t robot_stack_size;
size_t robot_source_size;
size_t robot_program_size;
size_t robot_program_labels_size;
size_t scroll_sensor_total_size;
size_t video_layer_size;
size_t debug_robot_total_size;
size_t debug_variables_total_size;
size_t extram_uncompressed_size;
size_t extram_compressed_size;
size_t virtual_filesystem_size;
size_t virtual_filesystem_cached_size;
};
static struct debug_ram_data ram_data;
static void robot_ram_usage(struct robot *robot, struct debug_ram_data *ram_data)
{
if(robot->stack)
ram_data->robot_stack_size += robot->stack_size * sizeof(robot->stack[0]);
#ifdef CONFIG_DEBYTECODE
if(robot->program_source)
ram_data->robot_source_size += robot->program_source_length;
#else
// Count this in debug since it's only used for that...
if(robot->program_source)
ram_data->debug_robot_total_size += robot->program_source_length;
#endif /* !CONFIG_DEBYTECODE */
if(robot->program_bytecode)
ram_data->robot_program_size += robot->program_bytecode_length;
if(robot->command_map)
{
ram_data->debug_robot_total_size +=
robot->command_map_length * sizeof(struct command_mapping);
}
if(robot->label_list)
{
ram_data->robot_program_labels_size +=
robot->num_labels * (sizeof(struct label *) + sizeof(struct label));
}
}
static void update_ram_usage_data(struct world *mzx_world,
size_t var_debug_usage)
{
int i, j;
size_t u;
memset(&ram_data, 0, sizeof(struct debug_ram_data));
counter_list_size(&mzx_world->counter_list, &ram_data.counter_list_size,
&ram_data.counter_table_size, &ram_data.counter_struct_size);
string_list_size(&mzx_world->string_list, &ram_data.string_list_size,
&ram_data.string_table_size, &ram_data.string_struct_size);
ram_data.sprites_size =
mzx_world->num_sprites_allocated * sizeof(struct sprite *) +
mzx_world->num_sprites * sizeof(struct sprite);
ram_data.vlayer_size = mzx_world->vlayer_size * 2;
ram_data.board_list_and_struct_size =
mzx_world->num_boards_allocated * sizeof(struct board *) +
mzx_world->num_boards * sizeof(struct board);
robot_ram_usage(&mzx_world->global_robot, &ram_data);
for(i = 0; i < mzx_world->num_boards; i++)
{
struct board *b = mzx_world->board_list[i];
// Board data.
ram_data.board_data_size += b->board_width * b->board_height * 6;
if(b->overlay_mode)
ram_data.board_overlay_size += b->board_width * b->board_height * 2;
// Buffers (split off the board struct).
ram_data.board_list_and_struct_size +=
b->input_allocated + b->charset_path_allocated + b->palette_path_allocated;
// Robot list (+1) and robot name sorted list.
ram_data.robot_list_and_struct_size +=
((b->num_robots_allocated + 1) + b->num_robots_active) * sizeof(struct robot *);
// Scroll and sensor lists (both +1).
ram_data.scroll_sensor_total_size +=
(b->num_scrolls_allocated + 1) * sizeof(struct scroll *) +
(b->num_sensors_allocated + 1) * sizeof(struct sensor *);
for(j = 1; j <= b->num_robots; j++)
{
if(b->robot_list[j])
{
ram_data.robot_list_and_struct_size += sizeof(struct robot);
robot_ram_usage(b->robot_list[j], &ram_data);
}
}
for(j = 1; j <= b->num_scrolls; j++)
if(b->scroll_list[j])
ram_data.scroll_sensor_total_size +=
sizeof(struct scroll) + b->scroll_list[j]->mesg_size;
for(j = 1; j <= b->num_sensors; j++)
if(b->sensor_list[j])
ram_data.scroll_sensor_total_size += sizeof(struct sensor);
#ifdef CONFIG_EXTRAM
{
size_t c;
size_t u;
if(board_extram_usage(b, &c, &u))
{
ram_data.extram_compressed_size += c;
ram_data.extram_uncompressed_size += u;
}
}
#endif
}
for(u = 0; u < graphics.layer_count; u++)
{
struct video_layer *layer = &(graphics.video_layers[u]);
if(layer->data)
ram_data.video_layer_size +=
layer->w * layer->h * sizeof(struct char_element);
}
ram_data.debug_variables_total_size = var_debug_usage;
ram_data.virtual_filesystem_size = vio_filesystem_total_memory_usage();
ram_data.virtual_filesystem_cached_size = vio_filesystem_total_cached_usage();
}
#define match_counter(_name) (strlen(_name) == len && !strcasecmp(name, _name))
int get_counter_safe(struct world *mzx_world, const char *name, int id)
{
// This is a safe wrapper for get_counter(). Some counters, when read,
// could alter world data in a way we don't want to happen here.
// So detect and block them.
size_t len = strlen(name);
if(match_counter("fread")) return -1;
if(match_counter("fread_counter")) return -1;
return get_counter(mzx_world, name, id);
}
static void get_var_name(struct debug_var *v, const char **name, int *len,
char buffer[VAR_LIST_WIDTH + 1])
{
switch((enum debug_var_type)v->type)
{
case V_COUNTER:
if(name) *name = v->data.counter->name;
if(len) *len = v->data.counter->name_length;
return;
case V_STRING:
if(name) *name = v->data.string->name;
if(len) *len = v->data.string->name_length;
return;
case V_VAR:
case V_SCROLL_TEXT:
if(name) *name = (char *)v->data.var_name;
if(len) *len = strlen(*name);
return;
case V_VIRTUAL_VAR:
if(name) *name = (char *)virtual_var_names[v->data.virtual_var];
if(len) *len = strlen(*name);
return;
case V_SPRITE_VAR:
snprintf(buffer, 32, "spr%d_%s", v->id, v->data.var_name);
if(name) *name = buffer;
if(len) *len = strlen(buffer);
return;
case V_SPRITE_CLIST:
snprintf(buffer, 32, "spr_clist%d*", v->data.clist_num);
if(name) *name = buffer;
if(len) *len = strlen(buffer);
return;
case V_LOCAL_VAR:
snprintf(buffer, 32, "local%d", v->data.local_num);
if(name) *name = buffer;
if(len) *len = strlen(buffer);
return;
}
}
#define match_var(_name) (strlen(_name) == len && !memcmp(var, _name, len))
// The buffer param is used for any vars that need to generate char values.
static void get_var_value(struct world *mzx_world, struct debug_var *v,
const char **char_value, int *int_value, int64_t *long_value,
char buffer[VAR_LIST_WIDTH + 1])
{
struct board *cur_board = mzx_world->current_board;
char real_var[32];
*char_value = NULL;
switch((enum debug_var_type)v->type)
{
case V_COUNTER:
{
v->is_empty = false;
if(v->data.counter->value == 0)
v->is_empty = true;
*int_value = v->data.counter->value;
break;
}
case V_STRING:
{
v->is_empty = false;
if(!v->data.string->length)
v->is_empty = true;
*char_value = v->data.string->value;
*int_value = v->data.string->length;
break;
}
// It's a built-in var. Since some of these don't have
// read functions, we have to map several manually.
case V_VAR:
{
const char *var = v->data.var_name;
size_t len = strlen(var);
int index = v->id;
if(match_var("bimesg"))
{
*int_value = mzx_world->bi_mesg_status;
}
else
if(match_var("spacelock"))
{
*int_value = mzx_world->bi_shoot_status;
}
else
if(match_var("fread_delimiter"))
{
*int_value = mzx_world->fread_delimiter;
}
else
if(match_var("fwrite_delimiter"))
{
*int_value = mzx_world->fwrite_delimiter;
}
else
if(match_var("Active sprites*"))
{
*int_value = mzx_world->active_sprites;
}
else
if(match_var("spr_yorder"))
{
*int_value = mzx_world->sprite_y_order;
}
else
if(match_var("mod_name*"))
{
*char_value = mzx_world->real_mod_playing;
*int_value = strlen(*char_value);
}
else
if(match_var("board_name*"))
{
*char_value = cur_board->board_name;
*int_value = strlen(*char_value);
}
else
if(match_var("board_mod*"))
{
*char_value = cur_board->mod_playing;
*int_value = strlen(*char_value);
}
else
if(match_var("input*"))
{
// the starred version of input is the input string!
*char_value = cur_board->input_string ? cur_board->input_string : "";
*int_value = strlen(*char_value);
}
else
if(match_var("volume"))
{
*int_value = cur_board->volume;
}
else
if(match_var("robot_name*"))
{
*char_value = cur_board->robot_list[index]->robot_name;
*int_value = strlen(*char_value);
}
else
if(match_var("commands_total"))
{
*int_value = cur_board->robot_list[index]->commands_total;
}
else
if(match_var("commands_cycle*"))
{
*int_value = cur_board->robot_list[index]->commands_cycle;
}
else
if(match_var("lockself"))
{
*int_value = cur_board->robot_list[index]->is_locked;
}
else
if(match_var("Sensor name*"))
{
*char_value = cur_board->sensor_list[index]->sensor_name;
*int_value = strlen(*char_value);
}
else
if(match_var("Robot to mesg*"))
{
*char_value = cur_board->sensor_list[index]->robot_to_mesg;
*int_value = strlen(*char_value);
}
else
if(match_var("joy_simulate_keys"))
{
*int_value = mzx_world->joystick_simulate_keys;
}
else
{
// All other vars try to use a regular counter lookup.
memcpy(real_var, var, len + 1);
if(real_var[len - 1] == '*')
real_var[len - 1] = 0;
*int_value = get_counter_safe(mzx_world, real_var, index);
}
break;
}
// Subset of builtin vars that represent aggregate data or other info that
// doesn't actually exist in the world.
case V_VIRTUAL_VAR:
{
enum virtual_var vvar = v->data.virtual_var;
int64_t value = 0;
switch(vvar)
{
case VIR_RAM_COUNTER_LIST:
value = ram_data.counter_list_size;
break;
case VIR_RAM_COUNTER_TABLE:
value = ram_data.counter_table_size;
break;
case VIR_RAM_COUNTERS:
value = ram_data.counter_struct_size;
break;
case VIR_RAM_STRING_LIST:
value = ram_data.string_list_size;
break;
case VIR_RAM_STRING_TABLE:
value = ram_data.string_table_size;
break;
case VIR_RAM_STRINGS:
value = ram_data.string_struct_size;
break;
case VIR_RAM_VLAYER:
value = ram_data.vlayer_size;
break;
case VIR_RAM_SPRITES:
value = ram_data.sprites_size;
break;
case VIR_RAM_BOARD_INFO:
value = ram_data.board_list_and_struct_size;
break;
case VIR_RAM_BOARD_DATA:
value = ram_data.board_data_size;
break;
case VIR_RAM_BOARD_OVERLAY:
value = ram_data.board_overlay_size;
break;
case VIR_RAM_ROBOT_INFO:
value = ram_data.robot_list_and_struct_size;
break;
case VIR_RAM_ROBOT_STACK:
value = ram_data.robot_stack_size;
break;
case VIR_RAM_ROBOT_SOURCE:
value = ram_data.robot_source_size;
break;
case VIR_RAM_ROBOT_PROGRAMS:
value = ram_data.robot_program_size;
break;
case VIR_RAM_ROBOT_PROGRAM_LABELS:
value = ram_data.robot_program_labels_size;
break;
case VIR_RAM_SCROLLS_SENSORS:
value = ram_data.scroll_sensor_total_size;
break;
case VIR_RAM_VIDEO_LAYERS:
value = ram_data.video_layer_size;
break;
case VIR_RAM_DEBUGGER_ROBOTS:
value = ram_data.debug_robot_total_size;
break;
case VIR_RAM_DEBUGGER_VARIABLES:
value = ram_data.debug_variables_total_size;
break;
case VIR_RAM_EXTRAM_DELTA:
value = (int64_t)ram_data.extram_compressed_size -
(int64_t)ram_data.extram_uncompressed_size;
break;
case VIR_RAM_VIRTUAL_FILESYSTEM:
value = ram_data.virtual_filesystem_size;
break;
case VIR_RAM_VIRTUAL_FILESYSTEM_CACHED_ONLY:
value = ram_data.virtual_filesystem_cached_size;
break;
}
*long_value = value;
break;
}
case V_SPRITE_VAR:
{
const char *var = v->data.var_name;
size_t len = strlen(var);
int sprite_num = v->id;
if(match_var("overlay"))
{
if(mzx_world->sprite_list[sprite_num]->flags & SPRITE_OVER_OVERLAY)
*int_value = 1;
}
else
if(match_var("static"))
{
if(mzx_world->sprite_list[sprite_num]->flags & SPRITE_STATIC)
*int_value = 1;
}
else
if(match_var("vlayer"))
{
if(mzx_world->sprite_list[sprite_num]->flags & SPRITE_VLAYER)
*int_value = 1;
}
else
if(match_var("ccheck"))
{