/
zshell-old-1.14.4-archival.zs
1899 lines (1724 loc) · 51.7 KB
/
zshell-old-1.14.4-archival.zs
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
/////////////////////////////////
/// Debug Shell for ZC Quests ///
/// Alpha Version 1.14.4 ///
/// 3rd November, 2018 ///
/// By: ZoriaRPG ///
/// Requires: ZC Necromancer ///
/////////////////////////////////
//
// v1.2 : Finished working code. now it all functions as I intend.
// v1.2.1 : Added a code comment block with examples on how to add more instructions to match_instruction().
// v1.2.1 : Added a sanity check to setting Link->Item[]. It now only works on inventory items.
// v1.3.0 : Added the SAVE instruction.
// v1.4.0 : Added CREATEITEM ( cri,id,x,y )
// v1.4.0 : Added CREATENPC ( crn,id,x,y )
// v1.4.0 : Fixed bug where buffer persists through saves.
// v1.5.0 : Added LX and LY as literal args for Link's X and Y positions.
// v1.6.0 : Added LX and LY tracing.
// v1.6.0 : Added PALETTE as pal,n1,n2 -- POS now requires more than 'p' -- to change DMap Palette. -1 for current DMap.
// v1.6.0 : This sets Game->DmapPalette[n1] = n2
// v1.6.0 : Added MONOCHROME as mon,n to set Graphics->Monochrome(n1)
// v1.6.1 : Added break instructiosn to fix invalid rval and other invalid returns in switch statements.
// v1.6.2 : Added clear instructions to case for NONE in switch(instr).
// v1.7.0 : Added LTRIFORCE to set if Link has the triforce for a given level as 'lt,id,true|false'
// v1.7.0 : Added LCOMPASS to set if Link has the compass for a given level as 'lc,id,true|false'
// v1.7.0 : Added LMAP to set if Link has the map for a given level as 'lm,id,true|false'
// v1.7.0 : Added LBOSSKEY to set if Link has the boss key for a given level as 'lb,id,true|false'
// v1.7.0 : Added LKEYS to set the current number of LEVEL KEYS for a given level ID as 'lk,levelid,number'
// v1.7.0 : Added BOMBS to set the current number of bombs as 'b,number'
// v1.7.0 : Added MBOMBS to set the current number of max bombs as 'b,number'
// v1.7.0 : Added ARROWS to set the current number of arrows as 'a,number'
// v1.7.0 : Added MARROWS to set the current number of max arrows as 'a,number'
// v1.7.0 : Added RUPEES to set the current number of rupees as 'r,number'
// v1.7.0 : Added MRUPEES to set the current number of max rupees as 'r,number'
// v1.7.0 : Added KEYS to set the current number of keys as 'k,number'
// v1.7.0 : Added BIGHITBOX to set the if Link's hitbox is large (full tile collision), or small, as 'h,t|f'
// v1.7.0 : Added LINKDIAGONAL to set the if Link may move diagonally, as 'd,t|f'
// v1.7.1 : orrected a bug where RUPEES was using Game->Counter[RUPEES} insead of CR_RUPEES.
// v1.7.1 : Added a NULL case for token[1] of command 'r', so that 'r' without any other legal char as the next token is RUPEES.
// v1.8.0 : Added SETFFSCRIPT as 'fs,ffc_id,script_id'
// v1.8.0 : Added SETFFCDATA as 'fs,ffc_id,combo_id'
// v1.8.0 : Added RUNFFCSCRIPTID as 'run,script_id'
// v1.8.0 : Fixed missing break statements in execute(stack) switch(instr).
// v1.9.0 : Added HUE as 'hu,r,g,b,t|f'
// v1.9.0 : Added TINT as 't,r,g,b'
// v1.9.0 : Added CLEARTINT as 'cl'
/* v1.10.0 :
Added all FFC vars:
fc FCSET; fx FX; fy FY; fvx FVX; fvy FVY; fax FAX ; fay FAY; ffl FFLAGS; fth FTHEIGHT; ftw FTWIDTH ; feh FEHEIGHT ; few FEWIDTH
fl FLINK; fm FMISC
Added PLAYSOUND as 'pls,sound_id'
Added PLAYMIDI as 'plm,midi_id'
Added DMAPMIDI as 'dmm,dmap_id,midi_id'
*/
// v1.10.1 : Added KEY_STOP (period) to the list of legal keys, to permit floating point values.
// v1.10.1 : Fixed a bug where instructions missing params would not abort, and clear Start presses on abort().
/* v1.11.0 :
The key used to open the shell is now a config option, with a base setting of F7.
Added an instruction QUEUE. You can now store up to 20 instructions.
Press the DOWN ARROW KEY to store an instruction.
Press the ENTER key on an empty line to process all stored instructions.
*/
/* v1.11.1 :
Fixed some issues with the number of ENQUEUED instructions being offset based on whether the user tried
to press the ENTER key on an empty line, or on a line with an instruction.
*/
/* v1.11.2 : Further patches to enqueued counts and behaviour.
Both of these now work properly, without any error codes.
I converted 'bool type()' into 'int type()' and now I return three possible conditions:
NONE: The user escaped out of the shell, or there were no instructions to process on pressing ENTER.
ENQUEUE: There are instructions in the queue.
RAW : This is when there is only one instruction, and no prior instructions entered,
and the user presses ENTER.
*/
// v1.12.0 : Added 'h,value' for SETLIFE.
// v1.12.0 : Added 'm,value' for SETMAGIC.
// v1.12.0 : Added 'co,counter_id,value' for SETCOUNTER.
// v1.12.0 : Changed BIGHITBOX from 'h,t|f' to 'hb,t|f'.
// v1.13.0 : Begin adding SEQUENCES to save a sequence of instructions. Added ten sequence slots.
// v1.13.0 : To save a sequence, hold CONTROL and press a main row number from 1 through 0.
// v1.13.0 : That number will be the SEQUENCE SLOT that you are using. Sequences can be saved!
// v1.13.0 : To run a sequence, open the shell and type RunSequence,id : This command is CaSe-SeNsItIvE!
// v1.13.1 : WTF? I found a parser bug. Scan the file for 'parser' to read more.
// v1.13.2 : Created a temporary work-around for the parser bug and fixed the save/read SEQUENCE functions.
// v1.13.2 : Sequences now seem to work.
// v1.14.0 : Added TRACE as an instruction to print to log. This uses the format of:
// v1.14.0 : %s:string -- traces 'string' to the log.
// v1.14.0 : %d:value -- traces value to the log.
// v1.14.1 : Patched error in the offset of TRACE copying into temp buffers.
// v1.14.1 : Increased size of MAX_TOKEN_LENGTH from 16 to 100, to allow for strings.
// v1.14.1 : Fixed call to atof() in TRACE for token %d
// v1.14.1 : Removed extraneous spaces and colons in strings inside calls to TrqaceError*()
// v1.14.2 : TRACE now eats all leading spaces and colons, instead of using a hardcoded offset.
// v1.14.3 : Moved a number of traces into 'if ( log_actions ) ' statements, and disabled others.
// v1.14.4 : Fixed a bug where holding down a shift key would only modify the very next character.
import "std.zh"
/*
DEFINED INSTRUCTION VALUES
w WARP: return 2; //dmap,screen
p POS: return 2; //x,y
mx MOVEX: return 1; //pixels (+/-)
my MOVEY: return 1; //pixels (+/-)
rh REFILLHP: return 0; //aNONE
rm REFILLMP: return 0; //NONE
rc REFILLCTR: return 1; //counter
mh MAXHP: return 1; //amount
mm MAXMP: return 1; //amount
mc MAXCTR: return 2; //counter, amount
save SAVE: return 0;
cri CREATEITEM: return 3; //id, x, y
crn CREATENPC: return 3; //id, x, y
inv INVINCIBLE: return 1; //(BOOL) on / off
itm LINKITEM: return 2; //item, (BOOL), on / off
pal PALETTE return 2
mon MONOCHROME return 1
h BIGHITBOX
d LINKDIAGONAL
a ARROWS
b BOMBS
r RUPEES
mb MAXBOMBS
ma MAXARROWS
mr MAXRUPEES
k KEYS
lk LKEYS
lm LMAP
lc LCOMPASS
lt LTRIFORCE
hu HUE
t TINT
cl CLEARTINT
fc FCSET
fx FX
fy FY
fvx FVX
fvy FVY
fax FAX
fay FAY
ffl FFLAGS
fth FTHEIGHT
ftw FTWIDTH
feh FEHEIGHT
few FEWIDTH
fl FLINK
fm FMISC
pls PLAYSOUND
plm PLAYMIDI
dmm DMAPMIDI
//COMMAND LIST
w: Warp Link to a specific dmap and screen
p: Reposition Link on the screen.
mx: Move link by +/-n pixels on the X axis.
my: Move link by +/-n pixels on the Y axis.
rh: Refill Link's HP to Max.
rm: Refill Link's HP to Max.
rc: Refill a specific counter to Max.
mh: Set Link's Max HP.
mm: Set Link's Max MP
mc: Set the maximum value of a specific counter.
inv: Set Link's Invisible state.
itm: Set the state of a specific item in Link's inventory.
save: Save the game.
cri: Create an item.
crn: Create an npc.
pal: Change a DMap palette; -1 for current dmap.
mono: Set monochrome effect.
h: Set if Link uses a full tile hitbox. (hitbox)
d: Set if Link can move diagonally.
a: Set the current number of Arrows
b: Set the current number of Bombs
r: Set the current number of Rupees
mb: Set the current number of Max Bombs
ma: Set the current number of Max Arrows
mr: Set the current number of Max Rupees
k: Set the current number of Keys
lk: Set the current number of Level Keys for a specific level ID.
lm: Set if the MAP item for a specific Level is in inventory.
lc: Set if the COMPASS item for a specific Level is in inventory.
lt: Set if the TRIFORCE item for a specific Level is in inventory.
lb: Set if the BOSS KEy item for a specific Level is in inventory.
fd: Set the Data value of one ffc.
fs: Set the Script value of one ffc.
run: Attempt to run an ffc script.
hu: Set a specific hue effect.
t: Set a specific tint effect.
cl: Clear hue/tint.
fc: Set the CSet of an ffc.
fx: Set the X component of an ffc.
fy: Set the Y component of an ffc.
fvx: Set the X Velocity Component of an ffc.
fvy: Set the Y Velocity Component of an ffc.
fax: Set the X Accel. Component of an ffc.
fay: Set the XYAccel. Component of an ffc.
ffl: Set an ffc flag state true or false.
fth: Set the TileHeight of an ffc.
ftw: Set the TileWidth of an ffc.
feh: Set the EffectHeight of an ffc.
few: Set the EffectWidth of an ffc.
fl: Link an ffc to another, or clear a link.
fm: Write to the Misc[] values of an ffc.
pls: Play a sound effect.
plm: Play a MIDI.
dmm: Set the MIDI for a specific DMap to a desired ID.
//SYNTAX
//command,args
w,1,2
p,1,2
mx,1
mx,-1
my,1
my,-1
rh
rm
rc,1
mh,1
mm,1
mc,1,2
inv,true
inv,false
itm,1,true
itm,1,false
save
cri,1,2,3 //id,x,y
crn,1,2,3 //id,x,y
pal,1,2 //dmap (-1 for current), palette
mono,1 : mono,type
h,true|false
d,true|false
a,1
b,1
r,1
mb,1
ma,1
mr,1
k,1
lk,1,2 (level id, number)
lm,1,t|f (level id, true|false)
lc,1,t|f (level id, true|false)
lt,1,t|f (level id, true|false)
lb,1,t|f (level id, true|false)
fd,1,2 (fs,ffc_id,combo_id)
fs,1,2 (fs,ffc_id,script_id)
run,1 (run,ffc_script_id)
hu,1,2,3,t|f (hu,red,green,blue,true|false)
t,1,2,3 (t,red,green,blue)
cl
fc,1,2 (fs,ffc_id,cset)
fx,1,2 (fs,ffc_id,x)
fy,1,2 (fs,ffc_id,y)
fvx,1,2 (fs,ffc_id,vx)
fvy,1,2 (fs,ffc_id,vy)
fax,1,2 (fs,ffc_id,ax)
fay,1,2 (fs,ffc_id,ay)
ffl,1,2,t|f (fs,ffc_id,flag,true|false)
fth,1,2 (fs,ffc_id,tileheight)
ftw,1,2 (fs,ffc_id,tilewidth)
feh,1,2 (fs,ffc_id,effectheight)
few,1,2 (fs,ffc_id,effectwidth)
fl,1,2 (fs,ffc_id,link_id)
fm,1,2,3 (fs,ffc_id,index,value)
pls,1 (pls,sound_id)
plm,1 (pls,midi_id)
dmm,1,2 (dmm,dmap_id,midi_id)
*/
script typedef ffc namespace;
typedef const int define;
typedef const int CFG;
namespace script debugshell
{
CFG INVISIBLE_COMBO = 1;
define INSTRUCTION_SIZE = 1; //The number of stack registers that any given *instruction* requires.
define MAX_INSTR_QUEUE = 20; //The number of instructions that can be enqueued.
define MAX_ARGS = 4; //The maximum number of args that any instruction can use/require.
define STACK_SIZE = 2 + ((INSTRUCTION_SIZE+MAX_ARGS)*MAX_INSTR_QUEUE); //+2 now includes TOP
define MAX_TOKEN_LENGTH = 100;
define BUFFER_LENGTH = 42;
int stack[STACK_SIZE];
int SP;
int ENQUEUED;
define TOP = ((INSTRUCTION_SIZE+MAX_ARGS)*MAX_INSTR_QUEUE)+1;
int debug_buffer[BUFFER_LENGTH];
define rERROR = 0;
define rRAW = 1;
define rENQUEUED = 2;
define SEQUENCES = 10;
int sequences[(STACK_SIZE+1)*SEQUENCES];
void runsequence(int id)
{
int seq[STACK_SIZE+1];
ENQUEUED = sequences[(id*STACK_SIZE)+STACK_SIZE]-1; //the last value is the number of instructions that were enqueued.
if ( log_actions ) TraceError("Sequence ENQUEUED is: ",ENQUEUED);
//int seq_max = (id*STACK_SIZE)+STACK_SIZE;
for ( int q = 0; q < STACK_SIZE; ++q ) seq[q] = sequences[id*(STACK_SIZE+1)+q]; //copy the sequence set to the temp stack.
if ( log_actions ) TraceErrorS("Tracing sequence stack.", " ");
if ( log_actions ) TraceStack(seq);
execute(seq); //run the temp stack.
}
int savesequence(int id)
{
if ( log_actions ) TraceError("Saving sequence, ID: ",id);
//int seq_max = (id*STACK_SIZE)+STACK_SIZE;
for ( int q = 0; q < STACK_SIZE; ++q )
{
sequences[(id*(STACK_SIZE+1))+q] = stack[q];
}
sequences[(id*STACK_SIZE)+STACK_SIZE] = ENQUEUED;
ENQUEUED = 0;
clearstack();
abort();
return id;
}
int sizeof(int p) { return SizeOfArray(p); }
define YES = 1;
define NO = 0;
CFG log_actions = NO;
CFG WINDOW_F_KEY = 53; //We use F7 to open the debug window.
define FONT = FONT_APPLE2; //Apple II
define F_COLOUR = 0x01; //font colour, white
define F_BCOLOUR = -1; //font background colour, translucent
define W_COLOUR = 0x03; //window colour (background), black
define W_S_COLOUR = 0xC5; //window colour (background), black
define CHAR_WIDTH = 6; //5 + one space
define CHAR_HEIGHT = 9; //8 + one space
define WINDOW_X = 15; //window indent over screen
define WINDOW_Y = 19; //window indent over screen
define WINDOW_H = 50;//CHAR_WIDTH * BUFFER_LENGTH;
define WINDOW_W = 180; //CHAR_HEIGHT * 3;
define WINDOW_S_X = 12; //window indent over screen
define WINDOW_S_Y = 16; //window indent over screen
define WINDOW_S_H = 50; //CHAR_WIDTH * BUFFER_LENGTH;
define WINDOW_S_W = 180; //CHAR_HEIGHT * 3;
define CHAR_X = 2; //Initial x indent
define CHAR_Y = 2; //Initial y indent
define W_OPACITY = OP_OPAQUE; //Window translucency.
define F_OPACITY = OP_OPAQUE; //Font translucency.
define W_LAYER = 6; //window draw layer
define F_LAYER = 6; //font draw layer
CFG KEY_DELAY = 6; //frames between keystrokes
define TYPESFX = 63;
void process()
{
if ( Input->ReadKey[WINDOW_F_KEY] ) //46+WINDOW_F_KEY] )
{
if ( log_actions ) TraceS("Enabled Debug Shell");
int typeval = type();
if ( typeval == rRAW ) //maybe type should be int with 0 being no return, 1 being enqueued, and 2 being raw?
{
if ( log_actions ) TraceS("process() evaluated type() true");
if ( !ENQUEUED )
{
int r = read(debug_buffer,false);
if ( r ) execute(stack);
}
else execute(stack);
}
else if ( typeval == rENQUEUED ) //maybe type should be int with 0 being no return, 1 being enqueued, and 2 being raw?
{
if ( log_actions ) TraceS("process() evaluated type() true");
--ENQUEUED;
execute(stack);
}
else
{
if ( log_actions ) TraceErrorS("type() returned: ", "false");
Link->PressStart = false;
Link->InputStart = false;
}
}
}
//if ( type() execute(stack) )
//returns true if the user presses enter
int type()
{
int frame = 0;
if ( !frame && log_actions ) TraceS("Starting type()");
++frame;
Game->TypingMode = true;
int key_timer; int buffer_pos = 0;
bool typing = true; int e;
//while(!Input->ReadKey[KEY_ENTER] || Input->ReadKey[KEY_ENTER_PAD])
while(typing)
{
//if ( key_timer <= 0 )
//{
if ( Input->ReadKey[KEY_BACKSPACE] ) //backspace
{
if ( buffer_pos > 0 )
{
debug_buffer[buffer_pos] = 0;
--buffer_pos;
debug_buffer[buffer_pos] = 0;
}
key_timer = KEY_DELAY;
continue;
}
else if ( Input->ReadKey[KEY_DOWN] )
{
e = enqueue();
if ( log_actions ) TraceError("type() enqueued an instruction, queue ID: ", e);
}
else if ( Input->ReadKey[KEY_ENTER] || Input->ReadKey[KEY_ENTER_PAD] )
{
Game->TypingMode = false;
//TraceNL(); TraceS("Read enter key, and buffer position is: "); Trace(buffer_pos); TraceNL();
if ( !buffer_pos )
{
if ( !ENQUEUED ) return 0; //do not execute if there are no commands
else return rENQUEUED;
}
else //we've typed something
{
if ( ENQUEUED )
{
e = enqueue(); return rENQUEUED; //also enqueue this line
}
else return rRAW;
}
}
else if ( Input->Key[KEY_LCONTROL] || Input->Key[KEY_RCONTROL] )
{
if ( Input->ReadKey[KEY_0] ) { savesequence(0); return 0; }
else if ( Input->ReadKey[KEY_1] ) { savesequence(1); return 0; }
else if ( Input->ReadKey[KEY_2] ) { savesequence(2); return 0; }
else if ( Input->ReadKey[KEY_3] ) { savesequence(3); return 0; }
else if ( Input->ReadKey[KEY_4] ) { savesequence(4); return 0; }
else if ( Input->ReadKey[KEY_5] ) { savesequence(5); return 0; }
else if ( Input->ReadKey[KEY_6] ) { savesequence(6); return 0; }
else if ( Input->ReadKey[KEY_7] ) { savesequence(7); return 0; }
else if ( Input->ReadKey[KEY_8] ) { savesequence(8); return 0; }
else if ( Input->ReadKey[KEY_9] ) { savesequence(9); return 0; }
}
else if ( EscKey() )
{
for ( int q = 0; q < BUFFER_LENGTH; ++q ) debug_buffer[q] = 0;
clearstack();
Game->TypingMode = false;
return 0; //exit and do not process.
}
else
{
//else normal key
int k;
int LegalKeys[]=
{
KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, KEY_H,
KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N, KEY_O, KEY_P,
KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, KEY_X,
KEY_Y, KEY_Z, KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5,
KEY_6, KEY_7, KEY_8, KEY_9, KEY_0_PAD, KEY_1_PAD, KEY_2_PAD,
KEY_3_PAD, KEY_4_PAD, KEY_5_PAD,
KEY_6_PAD, KEY_7_PAD, KEY_8_PAD, KEY_9_PAD, KEY_STOP, //period
KEY_TILDE,
KEY_MINUS,
KEY_EQUALS, KEY_OPENBRACE, KEY_CLOSEBRACE,
KEY_COLON, KEY_QUOTE, KEY_BACKSLASH, KEY_BACKSLASH2,
KEY_COMMA,
KEY_SEMICOLON, KEY_SLASH, KEY_SPACE, KEY_SLASH_PAD,
KEY_ASTERISK,
KEY_MINUS_PAD,
KEY_PLUS_PAD, KEY_CIRCUMFLEX, KEY_COLON2, KEY_EQUALS_PAD, KEY_STOP
};
for ( int kk = SizeOfArray(LegalKeys)-1; kk >= 0; --kk )
{
k = LegalKeys[kk];
if ( Input->ReadKey[k] )
{
//TraceS("Read a key: "); Trace(k); TraceNL();
debug_buffer[buffer_pos] = KeyToChar(k,(Input->Key[KEY_LSHIFT])||(Input->Key[KEY_RSHIFT])); //Warning!: Some masking may occur. :P
//TraceNL(); TraceS(debug_buffer); TraceNL();
++buffer_pos;
key_timer = KEY_DELAY;
break;
}
}
//continue;
}
//}
//else { --key_timer; }
if ( e )
{
clearbuffer();
buffer_pos = 0;
e = 0;
}
draw();
Waitframe();
}
}
void draw()
{
Screen->Rectangle(W_LAYER, WINDOW_S_X, WINDOW_S_Y, WINDOW_S_X+WINDOW_W, WINDOW_S_Y+WINDOW_H, W_S_COLOUR, 1, 0,0,0,true,W_OPACITY);
Screen->Rectangle(W_LAYER, WINDOW_X, WINDOW_Y, WINDOW_X+WINDOW_W, WINDOW_Y+WINDOW_H, W_COLOUR, 1, 0,0,0,true,W_OPACITY);
Screen->DrawString(F_LAYER,WINDOW_X+CHAR_X,WINDOW_Y+CHAR_Y,FONT,F_COLOUR,F_BCOLOUR,0,debug_buffer,F_OPACITY);
}
void TraceErrorS(int s, int s2)
{
TraceS(s); TraceS(": "); TraceS(s2); TraceNL();
}
void TraceError(int s, float v, float v2)
{
int buf[12]; int buf2[12];
ftoa(buf,v);
ftoa(buf2,v2);
TraceS(s); TraceS(": "); TraceS(buf); TraceS(", "); TraceS(buf2); TraceNL();
}
void TraceErrorVS(int s, float v, int s2)
{
int buf[12];
ftoa(buf,v);
TraceS(s); TraceS(": "); TraceS(buf); TraceS(", "); TraceS(s2); TraceNL();
}
//instruction //variables
define NONE = 0; //NONE
define WARP = 1; //dmap,screen
define POS = 2; //x,y
define MOVEX = 3; //pixels (+/-)
define MOVEY = 4; //pixels (+/-)
define REFILLHP = 5; //aNONE
define REFILLMP = 6; //NONE
define REFILLCTR = 7; //counter
define MAXHP = 8; //amount
define MAXMP = 9; //amount
define MAXCTR = 10; //counter, amount
define INVINCIBLE = 11; //(BOOL) on / off
define LINKITEM = 12; //item, (BOOL), on / off
define SAVE = 13; //item, (BOOL), on / off
define CREATEITEM = 14; //item, (BOOL), on / off
define CREATENPC = 15; //item, (BOOL), on / off
define PALETTE = 16; //item, (BOOL), on / off
define MONOCHROME = 17; //item, (BOOL), on / off
define BOMBS = 18; //item, (BOOL), on / off
define MBOMBS = 19; //item, (BOOL), on / off
define ARROWS = 20; //item, (BOOL), on / off
define MARROWS = 21; //item, (BOOL), on / off
define KEYS = 22; //item, (BOOL), on / off
define LKEYS = 23; //item, (BOOL), on / off
define RUPEES = 24; //item, (BOOL), on / off
define MRUPEES = 25; //item, (BOOL), on / off
define LMAP = 26; //level map, level id, true|false
define LBOSSKEY = 27; //level map, level id, true|false
define BIGHITBOX = 28; //level map, level id, true|false
define LINKDIAGONAL = 29; //level map, level id, true|false
define LTRIFORCE = 30; //level map, level id, true|false
define LCOMPASS = 31; //level map, level id, true|false
define RUNFFCSCRIPTID = 32;
define SETFFSCRIPT = 33;
define SETFFDATA = 34;
define TINT = 35;
define HUE = 36;
define CLEARTINT = 37;
define FCSET = 38;
define FX = 39;
define FY = 40;
define FVX = 41;
define FVY = 42;
define FAX = 43;
define FAY = 44;
define FFLAGS = 45; //ffc flags
define FTHEIGHT = 46;
define FTWIDTH = 47;
define FEHEIGHT = 48;
define FEWIDTH = 49;
define FLINK = 50;
define FMISC = 51;
define PLAYSOUND = 52;
define PLAYMIDI = 53;
define DMAPMIDI = 54;
define SETLIFE = 55;
define SETMAGIC = 56;
define SETCOUNTER = 57;
define SAVESEQUENCE = 58;
define RUNSEQUENCE = 59;
define TRACE = 60;
int num_instruction_params(int instr)
{
switch(instr)
{
//instruction //variables
case NONE: return 0;
case WARP: return 2; //dmap,screen
case POS: return 2; //x,y
case MOVEX: return 1; //pixels (+/-)
case MOVEY: return 1; //pixels (+/-)
case REFILLHP: return 0; //aNONE
case REFILLMP: return 0; //NONE
case REFILLCTR: return 1; //counter
case MAXHP: return 1; //amount
case MAXMP: return 1; //amount
case MAXCTR: return 2; //counter, amount
case INVINCIBLE: return 1; //(BOOL) on / off
case LINKITEM: return 2; //item, (BOOL), on / off
case SAVE: return 0; //item, (BOOL), on / off
case CREATEITEM: return 3; //item, (BOOL), on / off
case CREATENPC: return 3; //item, (BOOL), on / off
case PALETTE: return 2; //item, (BOOL), on / off
case MONOCHROME: return 1; //item, (BOOL), on / off
case BOMBS: return 1;
case MBOMBS: return 1;
case ARROWS: return 1;
case MARROWS: return 1;
case KEYS: return 1;
case LKEYS: return 2; //level, number
case RUPEES: return 1;
case MRUPEES: return 1;
case LMAP: return 2; //level map, level id, true|false
case LBOSSKEY: return 2; //level bosskey, level id, true|false
case LTRIFORCE: return 2; //level bosskey, level id, true|false
case LCOMPASS: return 2; //level bosskey, level id, true|false
case BIGHITBOX: return 1; //true|false
case LINKDIAGONAL: return 1; //true|false
case RUNFFCSCRIPTID: return 1;
case SETFFSCRIPT: return 2;
case SETFFDATA: return 2;
case TINT: return 3;
case HUE: return 4;
case CLEARTINT: return 0;
case FCSET: return 2;
case FX: return 2;
case FCSET: return 2;
case FX: return 2;
case FY: return 2;
case FVX: return 2;
case FVY: return 2;
case FAX: return 2;
case FAY: return 2;
case FFLAGS: return 3;
case FTHEIGHT: return 2;
case FTWIDTH: return 2;
case FEHEIGHT: return 2;
case FEWIDTH: return 2;
case FLINK: return 2;
case FMISC: return 3;
case PLAYSOUND: return 1;
case PLAYMIDI: return 1;
case DMAPMIDI: return 3;
case SETLIFE: return 1;
case SETMAGIC: return 1;
case SETCOUNTER: return 2;
case SAVESEQUENCE: return 1;
case RUNSEQUENCE: return 1;
case TRACE: return 0;
default:
{
TraceError("Invalid instruction passed to stack",instr);
clearbuffer();
return 0;
}
}
}
int match_instruction(int token)
{
if ( log_actions ) {TraceNL(); TraceS("Input token into match_instruction is: "); TraceS(token); TraceNL();}
if ( log_actions ) {TraceNL(); TraceErrorS("match_instruction() token is: ",token); TraceNL();}
if ( log_actions ) {TraceNL(); TraceError("Matching string with strcmp to 'w': ", strcmp(token,"w")); TraceNL();}
/* ONE WAY TO DO THIS. I did this with individual characters, and switches, to minimise the checks down
to the absolute minimum. -Z
You could add specific instructions this way, if you wish.
if ( !(strcmp(token,"w") ) ) TraceErrorS("Token in match_instruction() matched to WARP. Token: ", token);
if ( !(strcmp(token,"W") ) ) TraceErrorS("Token in match_instruction() matched to WARP. Token: ", token);
if ( !(strcmp(token,"p") ) ) TraceErrorS("Token in match_instruction() matched to POS. Token: ", token);
if ( !(strcmp(token,"P") ) ) TraceErrorS("Token in match_instruction() matched to POS. Token: ", token);
if ( !(strcmp(token,"rh") ) ) TraceErrorS("Token in match_instruction() matched to REFILLHP. Token: ", token);
if ( !(strcmp(token,"RH") ) ) TraceErrorS("Token in match_instruction() matched to REFILLHP. Token: ", token);
if ( !(strcmp(token,"Rh") ) ) TraceErrorS("Token in match_instruction() matched to REFILLHP. Token: ", token);
if ( !(strcmp(token,"rH") ) ) TraceErrorS("Token in match_instruction() matched to REFILLHP. Token: ", token);
if ( !(strcmp(token,"rH") ) ) TraceErrorS("Token in match_instruction() matched to REFILLHP. Token: ", token);
*/
/* Putting BRACES here causes Invalid pointer errors?! PARSER BUG!!
it works just find without the braces!!
if ( !(strcmp(token,"RunSequence") ) )
{
TraceErrorS("Found token RunSequence", token); // return RUNSEQUENCE; }//TraceErrorS("Token in match_instruction() matched to POS. Token: ", token);
}
*/
//if ( !(strcmp(token,"RunSequence") ) ) { TraceError("Found token RunSequence", " "); return RUNSEQUENCE; }
//if ( !(strcmp(token,"SaveSequence") ) ) return SAVESEQUENCE;
int sc;
if ( !(strcmp(token,"RunSequence") ) ) sc = RUNSEQUENCE;
if ( sc == RUNSEQUENCE ) { TraceError("Found token RunSequence", " "); return RUNSEQUENCE;}
switch(token[0])
{
case '%':
{
switch(token[1])
{
case 's':
case 'S':
{
//TraceS(token);
int buf[MAX_TOKEN_LENGTH];
//Trace(buf);
int offset = 2;
for ( ; (token[offset] == ' ' || token[offset] == ':'); ++offset ) continue; //destroy leading spaces
for ( int qq = offset; qq < MAX_TOKEN_LENGTH; ++qq )
{
buf[qq-offset] = token[qq];
}
TraceErrorS("Log",buf);
//TraceS(buf);
return TRACE;
}
case 'd':
case 'D':
{
int buf[MAX_TOKEN_LENGTH];
int offset = 2;
for ( ; (token[offset] == ' ' || token[offset] == ':'); ++offset ) continue; //destroy leading spaces
for ( int q = offset; q < MAX_TOKEN_LENGTH; ++q )
{
buf[q-offset] = token[q];
}
int tmp = atof(buf);
TraceError("Log",tmp);
return TRACE;
}
default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction",token); abort(); return 0;
}
break;
}
//A
case 'a':
case 'A':
return ARROWS;
//B
case 'b':
case 'B':
{
return BOMBS;
/*
switch(token[1])
{
case 'i':
case 'I':
return BIGHITBOX;
case 'o':
case 'O':
return BOMBS;
default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction",token); abort(); return 0;
}
*/
}
case 'c':
case 'C':
{
switch(token[1])
{
case NULL:
case 'o':
case 'O':
return SETCOUNTER;
case 'l':
case 'L':
return CLEARTINT;
case 'r':
case 'R':
{
switch(token[2])
{
case 'i':
case 'I':
{
//TraceNL(); TraceS("instr() found token 'cri'"); TraceNL();
return CREATEITEM;
}
case 'n':
case 'N':
{
//TraceNL(); TraceS("instr() found token 'cri'"); TraceNL();
return CREATENPC;
}
default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction",token); abort(); return 0;
}
}
default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction",token); abort(); return 0;
}
break;
}
//D
case 'd':
case 'D':
{
switch(token[1])
{
case NULL:
case 'i':
case 'I':
return LINKDIAGONAL;
case 'm':
case 'M': //dmap stuff
{
switch(token[2])
{
case NULL:
case 'm':
case 'M':
return DMAPMIDI;
default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction",token); abort(); return 0;
}
}
default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction",token); abort(); return 0;
}
break;
}
//E
//F
case 'f':
case 'F':
{
switch(token[1])
{
case 'a':
case 'A':
{
switch(token[2])
{
case 'x':
case 'X':
return FAX;
case 'Y':
case 'y':
return FAY;
default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction",token); abort(); return 0;
}
break;
}
case 'c':
case 'C':
return FCSET;
case 'd':
case 'D':
return SETFFDATA;
case 'e':
case 'E':
{
switch(token[2])
{
case 'h':
case 'H':
return FEHEIGHT;
case 'w':
case 'W':
return FEWIDTH;
default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction",token); abort(); return 0;
}
break;
}
case 'f':
case 'F':
{
switch(token[2])
{
case NULL:
case 'l':
case 'L':
return FFLAGS;
default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction",token); abort(); return 0;
}
break;
}
case 'l':
case 'L':
return FLINK;
case 'M':
case 'm':
return FMISC;
case 'S':
case 's':
return SETFFSCRIPT;
case 't':
case 'T':
{
switch(token[2])
{
case 'H':
case 'h':
return FTHEIGHT;
case 'w':
case 'W':
return FTWIDTH;
default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction",token); abort(); return 0;
}
break;
}
case 'v':
case 'V':
{
switch(token[2])
{
case 'x':
case 'X':
return FVX;
case 'y':
case 'Y':
return FVY;
default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction",token); abort(); return 0;
}