Advertisement
ZoriaRPG

Debug Cheat Shell (v1.13, Sequence Scripts)

Nov 1st, 2018
247
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 50.96 KB | None | 0 0
  1. /////////////////////////////////
  2. /// Debug Shell for ZC Quests ///
  3. /// Alpha Version 1.13.2      ///
  4. /// 1st November, 2018        ///
  5. /// By: ZoriaRPG              ///
  6. /// Requires: ZC Necromancer  ///
  7. /////////////////////////////////
  8. //
  9. // v1.2   : Finished working code. now it all functions as I intend.
  10. // v1.2.1 : Added a code comment block with examples on how to add more instructions to match_instruction().
  11. // v1.2.1 : Added a sanity check to setting Link->Item[]. It now only works on inventory items.
  12. // v1.3.0 : Added the SAVE instruction.
  13. // v1.4.0 : Added CREATEITEM ( cri,id,x,y )
  14. // v1.4.0 : Added CREATENPC ( crn,id,x,y )
  15. // v1.4.0 : Fixed bug where buffer persists through saves.
  16. // v1.5.0 : Added LX and LY as literal args for Link's X and Y positions.
  17. // v1.6.0 : Added LX and LY tracing.
  18. // v1.6.0 : Added PALETTE as pal,n1,n2 -- POS now requires more than 'p' -- to change DMap Palette. -1 for current DMap.
  19. // v1.6.0 :       This sets Game->DmapPalette[n1] = n2
  20. // v1.6.0 : Added MONOCHROME as mon,n to set Graphics->Monochrome(n1)
  21. // v1.6.1 : Added break instructiosn to fix invalid rval and other invalid returns in switch statements.
  22. // v1.6.2 : Added clear instructions to case for NONE in switch(instr).
  23. // v1.7.0 : Added LTRIFORCE to set if Link has the triforce for a given level as 'lt,id,true|false'
  24. // v1.7.0 : Added LCOMPASS to set if Link has the compass for a given level as 'lc,id,true|false'
  25. // v1.7.0 : Added LMAP to set if Link has the map for a given level as 'lm,id,true|false'
  26. // v1.7.0 : Added LBOSSKEY to set if Link has the boss key for a given level as 'lb,id,true|false'
  27. // v1.7.0 : Added LKEYS to set the current number of LEVEL KEYS for a given level ID as 'lk,levelid,number'
  28. // v1.7.0 : Added BOMBS to set the current number of bombs as 'b,number'
  29. // v1.7.0 : Added MBOMBS to set the current number of max bombs as 'b,number'
  30. // v1.7.0 : Added ARROWS to set the current number of arrows as 'a,number'
  31. // v1.7.0 : Added MARROWS to set the current number of max arrows as 'a,number'
  32. // v1.7.0 : Added RUPEES to set the current number of rupees as 'r,number'
  33. // v1.7.0 : Added MRUPEES to set the current number of max rupees as 'r,number'
  34. // v1.7.0 : Added KEYS to set the current number of keys as 'k,number'
  35. // v1.7.0 : Added BIGHITBOX to set the if Link's hitbox is large (full tile collision), or small, as 'h,t|f'
  36. // v1.7.0 : Added LINKDIAGONAL to set the if Link may move diagonally, as 'd,t|f'
  37. // v1.7.1 : orrected a bug where RUPEES was using Game->Counter[RUPEES} insead of CR_RUPEES.
  38. // 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.
  39. // v1.8.0 : Added SETFFSCRIPT as 'fs,ffc_id,script_id'
  40. // v1.8.0 : Added SETFFCDATA as 'fs,ffc_id,combo_id'
  41. // v1.8.0 : Added RUNFFCSCRIPTID as 'run,script_id'
  42. // v1.8.0 : Fixed missing break statements in execute(stack) switch(instr).
  43. // v1.9.0 : Added HUE as 'hu,r,g,b,t|f'
  44. // v1.9.0 : Added TINT as 't,r,g,b'
  45. // v1.9.0 : Added CLEARTINT as 'cl'
  46. /* v1.10.0 :
  47.     Added all FFC vars:
  48.     fc FCSET; fx FX; fy FY; fvx FVX; fvy FVY; fax FAX ; fay FAY; ffl FFLAGS; fth FTHEIGHT; ftw FTWIDTH ; feh FEHEIGHT ; few FEWIDTH
  49.     fl FLINK; fm FMISC
  50.     Added PLAYSOUND as 'pls,sound_id'
  51.     Added PLAYMIDI as 'plm,midi_id'
  52.     Added DMAPMIDI as 'dmm,dmap_id,midi_id'
  53. */
  54. // v1.10.1 : Added KEY_STOP (period) to the list of legal keys, to permit floating point values.
  55. // v1.10.1 : Fixed a bug where instructions missing params would not abort, and clear Start presses on abort().
  56. /* v1.11.0 :
  57.     The key used to open the shell is now a config option, with a base setting of F7.
  58.     Added an instruction QUEUE. You can now store up to 20 instructions.
  59.     Press the DOWN ARROW KEY to store an instruction.
  60.     Press the ENTER key on an empty line to process all stored instructions.
  61. */
  62. /* v1.11.1 :
  63.     Fixed some issues with the number of ENQUEUED instructions being offset based on whether the user tried
  64.     to press the ENTER key on an empty line, or on a line with an instruction.
  65. */
  66. /* v1.11.2 : Further patches to enqueued counts and behaviour.
  67.     Both of these now work properly, without any error codes.
  68.     I converted 'bool type()' into 'int type()' and now I return three possible conditions:
  69.         NONE: The user escaped out of the shell, or there were no instructions to process on pressing ENTER.
  70.         ENQUEUE: There are instructions in the queue.
  71.         RAW : This is when there is only one instruction, and no prior instructions entered,
  72.             and the user presses ENTER.
  73. */
  74.  
  75. // v1.12.0 : Added 'h,value' for SETLIFE.
  76. // v1.12.0 : Added 'm,value' for SETMAGIC.
  77. // v1.12.0 : Added 'co,counter_id,value' for SETCOUNTER.
  78. // v1.12.0 : Changed BIGHITBOX from 'h,t|f' to 'hb,t|f'.
  79.  
  80. // v1.13.0 : Begin adding SEQUENCES to save a sequence of instructions. Added ten sequence slots.
  81. // v1.13.0 : To save a sequence, hold CONTROL and press a main row number from 1 through 0.
  82. // v1.13.0 : That number will be the SEQUENCE SLOT that you are using. Sequences can be saved!
  83. // v1.13.0 : To run a sequence, open the shell and type RunSequence,id : This command is CaSe-SeNsItIvE!
  84. // v1.13.1 : WTF? I found a parser bug. Scan the file for 'parser' to read more.
  85. // v1.13.2 : Created a temporary work-around for the parser bug and fixed the save/read SEQUENCE functions.
  86. // v1.13.2 : Sequences now seem to work.
  87.  
  88.  
  89.  
  90. import "std.zh"
  91.  
  92. /*
  93. DEFINED INSTRUCTION VALUES
  94.     w WARP: return 2;   //dmap,screen
  95.     p POS: return 2;        //x,y
  96.     mx MOVEX: return 1;     //pixels (+/-)
  97.     my MOVEY: return 1;     //pixels (+/-)
  98.     rh REFILLHP: return 0;  //aNONE
  99.     rm REFILLMP: return 0;  //NONE
  100.     rc REFILLCTR: return 1; //counter
  101.     mh MAXHP: return 1; //amount
  102.     mm MAXMP: return 1; //amount
  103.     mc MAXCTR: return 2;    //counter, amount
  104.     save SAVE: return 0;   
  105.     cri CREATEITEM: return 3;   //id, x, y
  106.     crn CREATENPC: return 3;    //id, x, y
  107.    
  108.     inv INVINCIBLE: return 1;   //(BOOL) on / off
  109.     itm LINKITEM: return 2; //item, (BOOL), on / off
  110.     pal PALETTE return 2
  111.     mon MONOCHROME return 1
  112.    
  113.     h BIGHITBOX
  114.     d LINKDIAGONAL
  115.    
  116.     a ARROWS
  117.     b BOMBS
  118.     r RUPEES
  119.     mb MAXBOMBS
  120.     ma MAXARROWS
  121.     mr MAXRUPEES
  122.     k KEYS
  123.     lk LKEYS
  124.     lm LMAP
  125.     lc LCOMPASS
  126.     lt LTRIFORCE
  127.    
  128.     hu HUE
  129.     t TINT
  130.     cl CLEARTINT
  131.    
  132.     fc FCSET
  133.     fx FX
  134.     fy FY
  135.     fvx FVX
  136.     fvy FVY
  137.     fax FAX
  138.     fay FAY
  139.     ffl FFLAGS
  140.     fth FTHEIGHT
  141.     ftw FTWIDTH
  142.     feh FEHEIGHT
  143.     few FEWIDTH
  144.     fl FLINK
  145.     fm FMISC
  146.    
  147.     pls PLAYSOUND
  148.     plm PLAYMIDI
  149.     dmm DMAPMIDI
  150.  
  151. //COMMAND LIST
  152.     w: Warp Link to a specific dmap and screen
  153.     p: Reposition Link on the screen.
  154.     mx: Move link by +/-n pixels on the X axis.
  155.     my: Move link by +/-n pixels on the Y axis.
  156.     rh: Refill Link's HP to Max.
  157.     rm: Refill Link's HP to Max.
  158.     rc: Refill a specific counter to Max.
  159.     mh: Set Link's Max HP.
  160.     mm: Set Link's Max MP
  161.     mc: Set the maximum value of a specific counter.
  162.     inv: Set Link's Invisible state.
  163.     itm: Set the state of a specific item in Link's inventory.
  164.     save: Save the game.
  165.     cri: Create an item.
  166.     crn: Create an npc.
  167.     pal: Change a DMap palette; -1 for current dmap.
  168.     mono: Set monochrome effect.
  169.    
  170.     h: Set if Link uses a full tile hitbox. (hitbox)
  171.     d: Set if Link can move diagonally.
  172.    
  173.     a: Set the current number of Arrows
  174.     b: Set the current number of Bombs
  175.     r: Set the current number of Rupees
  176.     mb: Set the current number of Max Bombs
  177.     ma: Set the current number of Max Arrows
  178.     mr: Set the current number of Max Rupees
  179.     k: Set the current number of Keys
  180.     lk: Set the current number of Level Keys for a specific level ID.
  181.     lm: Set if the MAP item for a specific Level is in inventory.
  182.     lc: Set if the COMPASS item for a specific Level is in inventory.
  183.     lt: Set if the TRIFORCE item for a specific Level is in inventory.
  184.     lb: Set if the BOSS KEy item for a specific Level is in inventory.
  185.    
  186.     fd: Set the Data value of one ffc.
  187.     fs: Set the Script value of one ffc.
  188.     run: Attempt to run an ffc script.
  189.    
  190.     hu: Set a specific hue effect.
  191.     t: Set a specific tint effect.
  192.     cl: Clear hue/tint.
  193.    
  194.     fc: Set the CSet of an ffc.
  195.     fx: Set the X component of an ffc.
  196.     fy: Set the Y component of an ffc.
  197.     fvx: Set the X Velocity Component of an ffc.
  198.     fvy: Set the Y Velocity Component of an ffc.
  199.     fax: Set the X Accel. Component of an ffc.
  200.     fay: Set the XYAccel. Component of an ffc.
  201.    
  202.     ffl: Set an ffc flag state true or false.
  203.     fth: Set the TileHeight of an ffc.
  204.     ftw: Set the TileWidth of an ffc.
  205.     feh: Set the EffectHeight of an ffc.
  206.     few: Set the EffectWidth of an ffc.
  207.     fl: Link an ffc to another, or clear a link.
  208.     fm: Write to the Misc[] values of an ffc.
  209.    
  210.     pls: Play a sound effect.
  211.     plm: Play a MIDI.
  212.     dmm: Set the MIDI for a specific DMap to a desired ID.
  213.    
  214. //SYNTAX
  215. //command,args
  216.     w,1,2
  217.     p,1,2
  218.     mx,1
  219.     mx,-1
  220.     my,1
  221.     my,-1
  222.     rh
  223.     rm
  224.     rc,1
  225.     mh,1
  226.     mm,1
  227.     mc,1,2
  228.     inv,true
  229.     inv,false
  230.     itm,1,true
  231.     itm,1,false
  232.     save
  233.     cri,1,2,3 //id,x,y
  234.     crn,1,2,3 //id,x,y
  235.     pal,1,2 //dmap (-1 for current), palette
  236.     mono,1 : mono,type
  237.     h,true|false
  238.     d,true|false
  239.    
  240.     a,1
  241.     b,1
  242.     r,1
  243.     mb,1
  244.     ma,1
  245.     mr,1
  246.     k,1
  247.     lk,1,2 (level id, number)
  248.     lm,1,t|f (level id, true|false)
  249.     lc,1,t|f (level id, true|false)
  250.     lt,1,t|f (level id, true|false)
  251.     lb,1,t|f (level id, true|false)
  252.    
  253.     fd,1,2 (fs,ffc_id,combo_id)
  254.     fs,1,2 (fs,ffc_id,script_id)
  255.     run,1 (run,ffc_script_id)
  256.    
  257.     hu,1,2,3,t|f (hu,red,green,blue,true|false)
  258.     t,1,2,3 (t,red,green,blue)
  259.     cl
  260.    
  261.     fc,1,2 (fs,ffc_id,cset)
  262.     fx,1,2 (fs,ffc_id,x)
  263.     fy,1,2 (fs,ffc_id,y)
  264.     fvx,1,2 (fs,ffc_id,vx)
  265.     fvy,1,2 (fs,ffc_id,vy)
  266.     fax,1,2 (fs,ffc_id,ax)
  267.     fay,1,2 (fs,ffc_id,ay)
  268.    
  269.     ffl,1,2,t|f  (fs,ffc_id,flag,true|false)
  270.     fth,1,2 (fs,ffc_id,tileheight)
  271.     ftw,1,2 (fs,ffc_id,tilewidth)
  272.     feh,1,2 (fs,ffc_id,effectheight)
  273.     few,1,2 (fs,ffc_id,effectwidth)
  274.     fl,1,2 (fs,ffc_id,link_id)
  275.     fm,1,2,3 (fs,ffc_id,index,value)
  276.    
  277.     pls,1 (pls,sound_id)
  278.     plm,1 (pls,midi_id)
  279.     dmm,1,2 (dmm,dmap_id,midi_id)
  280.    
  281.        
  282.  
  283. */
  284.  
  285. script typedef ffc namespace;
  286. typedef const int define;
  287. typedef const int CFG;
  288.  
  289.  
  290.  
  291. namespace script debugshell
  292. {
  293.     CFG INVISIBLE_COMBO = 1;
  294.    
  295.     define INSTRUCTION_SIZE = 1; //The number of stack registers that any given *instruction* requires.
  296.     define MAX_INSTR_QUEUE = 20; //The number of instructions that can be enqueued.
  297.     define MAX_ARGS     = 4; //The maximum number of args that any instruction can use/require.
  298.     define STACK_SIZE   = 2 + ((INSTRUCTION_SIZE+MAX_ARGS)*MAX_INSTR_QUEUE);  //+2 now includes TOP
  299.     define MAX_TOKEN_LENGTH = 16;
  300.     define BUFFER_LENGTH    = 42;
  301.     int stack[STACK_SIZE];
  302.     int SP;
  303.     int ENQUEUED;
  304.     define TOP = ((INSTRUCTION_SIZE+MAX_ARGS)*MAX_INSTR_QUEUE)+1;
  305.     int debug_buffer[BUFFER_LENGTH];
  306.     define rERROR = 0;
  307.     define rRAW = 1;
  308.     define rENQUEUED = 2;
  309.     define SEQUENCES = 10;
  310.     int sequences[(STACK_SIZE+1)*SEQUENCES];
  311.    
  312.    
  313.     void runsequence(int id)
  314.     {
  315.         int seq[STACK_SIZE+1];
  316.         ENQUEUED = sequences[(id*STACK_SIZE)+STACK_SIZE]-1; //the last value is the number of instructions that were enqueued.
  317.         TraceError("Sequence ENQUEUED is: ",ENQUEUED);
  318.         //int seq_max = (id*STACK_SIZE)+STACK_SIZE;
  319.         for ( int q = 0; q < STACK_SIZE; ++q ) seq[q] = sequences[id*(STACK_SIZE+1)+q]; //copy the sequence set to the temp stack.
  320.         TraceErrorS("Tracing sequence stack.", " ");
  321.         TraceStack(seq);
  322.         execute(seq); //run the temp stack.
  323.     }
  324.     int savesequence(int id)
  325.     {
  326.         TraceError("Saving sequence, ID: ",id);
  327.         //int seq_max = (id*STACK_SIZE)+STACK_SIZE;
  328.         for ( int q = 0; q < STACK_SIZE; ++q )
  329.         {
  330.             sequences[(id*(STACK_SIZE+1))+q] = stack[q];
  331.         }
  332.         sequences[(id*STACK_SIZE)+STACK_SIZE] = ENQUEUED;
  333.         ENQUEUED = 0;
  334.         clearstack();
  335.         abort();
  336.         return id;
  337.     }
  338.     int sizeof(int p) { return SizeOfArray(p); }
  339.    
  340.     define YES = 1;
  341.     define NO = 0;
  342.    
  343.     CFG log_actions = YES;
  344.     CFG WINDOW_F_KEY = 53; //We use F7 to open the debug window.
  345.    
  346.    
  347.     define FONT = FONT_APPLE2; //Apple II
  348.     define F_COLOUR = 0x01; //font colour, white
  349.     define F_BCOLOUR = -1; //font background colour, translucent
  350.     define W_COLOUR = 0x03; //window colour (background), black
  351.     define W_S_COLOUR = 0xC5; //window colour (background), black
  352.     define CHAR_WIDTH = 6; //5 + one space
  353.     define CHAR_HEIGHT = 9; //8 + one space
  354.     define WINDOW_X = 15; //window indent over screen
  355.     define WINDOW_Y = 19; //window indent over screen
  356.     define WINDOW_H = 50;//CHAR_WIDTH * BUFFER_LENGTH;
  357.     define WINDOW_W = 180; //CHAR_HEIGHT * 3;
  358.     define WINDOW_S_X = 12; //window indent over screen
  359.     define WINDOW_S_Y = 16; //window indent over screen
  360.     define WINDOW_S_H = 50; //CHAR_WIDTH * BUFFER_LENGTH;
  361.     define WINDOW_S_W = 180; //CHAR_HEIGHT * 3;
  362.     define CHAR_X = 2; //Initial x indent
  363.     define CHAR_Y = 2; //Initial y indent
  364.     define W_OPACITY = OP_OPAQUE; //Window translucency.
  365.     define F_OPACITY = OP_OPAQUE; //Font translucency.
  366.     define W_LAYER = 6; //window draw layer
  367.     define F_LAYER = 6; //font draw layer
  368.    
  369.     CFG KEY_DELAY = 6; //frames between keystrokes
  370.    
  371.     define TYPESFX = 63;
  372.    
  373.     void process()
  374.     {
  375.         if ( Input->ReadKey[WINDOW_F_KEY] ) //46+WINDOW_F_KEY] )
  376.         {
  377.             TraceS("Enabled Deb ug Shell");
  378.             int typeval = type();
  379.             if ( typeval == rRAW ) //maybe type should be int with 0 being no return, 1 being enqueued, and 2 being raw?
  380.             {
  381.                 TraceS("process() evaluated type() true");
  382.                 if ( !ENQUEUED )
  383.                 {
  384.                     int r = read(debug_buffer,false);
  385.                     if ( r ) execute(stack);
  386.                 }
  387.                 else execute(stack);
  388.             }
  389.             else if ( typeval == rENQUEUED ) //maybe type should be int with 0 being no return, 1 being enqueued, and 2 being raw?
  390.             {
  391.                 TraceS("process() evaluated type() true");
  392.                 --ENQUEUED;
  393.                 execute(stack);
  394.             }
  395.             else
  396.             {
  397.                 TraceErrorS("type() returned: ", "false");
  398.                 Link->PressStart = false;
  399.                 Link->InputStart = false;
  400.             }
  401.         }
  402.     }
  403.    
  404.     //if ( type() execute(stack) )
  405.     //returns true if the user presses enter
  406.     int type()
  407.     {
  408.         int frame = 0;
  409.         if ( !frame ) TraceS("Starting type()");
  410.         ++frame;
  411.         Game->TypingMode = true;
  412.         int key_timer; int buffer_pos = 0;
  413.         bool typing = true; int e;
  414.         //while(!Input->ReadKey[KEY_ENTER] || Input->ReadKey[KEY_ENTER_PAD])
  415.         while(typing)
  416.         {
  417.             if ( key_timer <= 0 )
  418.             {
  419.                 if ( Input->ReadKey[KEY_BACKSPACE] ) //backspace
  420.                 {
  421.                    
  422.                     if ( buffer_pos > 0 )
  423.                     {
  424.                         debug_buffer[buffer_pos] = 0;
  425.                         --buffer_pos;
  426.                         debug_buffer[buffer_pos] = 0;
  427.                     }
  428.                     key_timer = KEY_DELAY;
  429.                     continue;
  430.                 }
  431.                 else if ( Input->ReadKey[KEY_DOWN] )
  432.                 {
  433.                     e = enqueue();
  434.                     TraceError("type() enqueued an instruction, queue ID: ", e);
  435.                    
  436.                 }
  437.                 else if ( Input->ReadKey[KEY_ENTER] || Input->ReadKey[KEY_ENTER_PAD] )
  438.                 {
  439.                     Game->TypingMode = false;
  440.                     TraceNL(); TraceS("Read enter key, and buffer position is: "); Trace(buffer_pos); TraceNL();
  441.                     if ( !buffer_pos )
  442.                     {
  443.                         if ( !ENQUEUED ) return 0; //do not execute if there are no commands
  444.                         else return rENQUEUED;
  445.                     }
  446.                     else //we've typed something
  447.                     {
  448.                         if ( ENQUEUED )
  449.                         {
  450.                             e = enqueue(); return rENQUEUED; //also enqueue this line
  451.                         }
  452.                         else return rRAW;
  453.                     }
  454.                 }
  455.                 else if ( Input->Key[KEY_LCONTROL] || Input->Key[KEY_RCONTROL] )
  456.                 {
  457.                     if ( Input->ReadKey[KEY_0] ) { savesequence(0); return 0; }
  458.                     else if ( Input->ReadKey[KEY_1] ) { savesequence(1); return 0; }
  459.                     else if ( Input->ReadKey[KEY_2] ) { savesequence(2); return 0; }
  460.                     else if ( Input->ReadKey[KEY_3] ) { savesequence(3); return 0; }
  461.                     else if ( Input->ReadKey[KEY_4] ) { savesequence(4); return 0; }
  462.                     else if ( Input->ReadKey[KEY_5] ) { savesequence(5); return 0; }
  463.                     else if ( Input->ReadKey[KEY_6] ) { savesequence(6); return 0; }
  464.                     else if ( Input->ReadKey[KEY_7] ) { savesequence(7); return 0; }
  465.                     else if ( Input->ReadKey[KEY_8] ) { savesequence(8); return 0; }
  466.                     else if ( Input->ReadKey[KEY_9] ) { savesequence(9); return 0; }
  467.                 }
  468.                 else if ( EscKey() )
  469.                 {
  470.                     for ( int q = 0; q < BUFFER_LENGTH; ++q ) debug_buffer[q] = 0;
  471.                     clearstack();
  472.                    
  473.                     Game->TypingMode = false;
  474.                     return 0; //exit and do not process.
  475.                 }
  476.                
  477.                 else
  478.                 {
  479.                     //else normal key
  480.                     int k;
  481.                     int LegalKeys[]=
  482.                     {
  483.                         KEY_A, KEY_B, KEY_C, KEY_D, KEY_E, KEY_F, KEY_G, KEY_H,
  484.                         KEY_I, KEY_J, KEY_K, KEY_L, KEY_M, KEY_N, KEY_O, KEY_P,
  485.                         KEY_Q, KEY_R, KEY_S, KEY_T, KEY_U, KEY_V, KEY_W, KEY_X,
  486.                         KEY_Y, KEY_Z, KEY_0, KEY_1, KEY_2, KEY_3, KEY_4, KEY_5,
  487.                         KEY_6, KEY_7, KEY_8, KEY_9, KEY_0_PAD, KEY_1_PAD, KEY_2_PAD,
  488.                         KEY_3_PAD, KEY_4_PAD, KEY_5_PAD,
  489.                         KEY_6_PAD, KEY_7_PAD, KEY_8_PAD, KEY_9_PAD, KEY_STOP, //period
  490.                         //KEY_TILDE,
  491.                         KEY_MINUS,
  492.                         //KEY_EQUALS, KEY_OPENBRACE, KEY_CLOSEBRACE,
  493.                         //KEY_COLON, KEY_QUOTE, KEY_BACKSLASH, KEY_BACKSLASH2,
  494.                         KEY_COMMA,
  495.                         //KEY_SEMICOLON, KEY_SLASH, KEY_SPACE, KEY_SLASH_PAD,
  496.                         //KEY_ASTERISK,
  497.                         KEY_MINUS_PAD
  498.                         //KEY_PLUS_PAD, KEY_CIRCUMFLEX, KEY_COLON2, KEY_EQUALS_PAD, KEY_STOP
  499.                     };
  500.  
  501.                    
  502.                     for ( int kk = SizeOfArray(LegalKeys)-1; kk >= 0; --kk )
  503.                     {
  504.                         k = LegalKeys[kk];
  505.                         if ( Input->ReadKey[k] )
  506.                         {
  507.                             TraceS("Read a key: "); Trace(k); TraceNL();
  508.                             debug_buffer[buffer_pos] = KeyToChar(k,(Input->ReadKey[KEY_LSHIFT])||(Input->ReadKey[KEY_RSHIFT])); //Warning!: Some masking may occur. :P
  509.                             TraceNL(); TraceS(debug_buffer); TraceNL();
  510.                             ++buffer_pos;
  511.                             key_timer = KEY_DELAY;
  512.                             break;
  513.                         }
  514.                     }
  515.                    
  516.                     //continue;
  517.                 }
  518.             }
  519.             else { --key_timer; }
  520.             if ( e )
  521.             {
  522.                 clearbuffer();
  523.                 buffer_pos = 0;
  524.                 e = 0;
  525.             }
  526.             draw();
  527.             Waitframe();
  528.         }
  529.        
  530.     }
  531.    
  532.     void draw()
  533.     {
  534.         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);
  535.         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);
  536.         Screen->DrawString(F_LAYER,WINDOW_X+CHAR_X,WINDOW_Y+CHAR_Y,FONT,F_COLOUR,F_BCOLOUR,0,debug_buffer,F_OPACITY);
  537.     }
  538.    
  539.     void TraceErrorS(int s, int s2)
  540.     {
  541.         TraceS(s); TraceS(": "); TraceS(s2); TraceNL();
  542.     }
  543.    
  544.     void TraceError(int s, float v, float v2)
  545.     {
  546.         int buf[12]; int buf2[12];
  547.         ftoa(buf,v);
  548.         ftoa(buf2,v2);
  549.         TraceS(s); TraceS(": "); TraceS(buf); TraceS(", "); TraceS(buf2); TraceNL();
  550.     }
  551.    
  552.     void TraceErrorVS(int s, float v, int s2)
  553.     {
  554.         int buf[12];
  555.         ftoa(buf,v);
  556.         TraceS(s); TraceS(": "); TraceS(buf); TraceS(", "); TraceS(s2); TraceNL();
  557.     }
  558.    
  559.     //instruction       //variables
  560.     define NONE =   0;  //NONE
  561.     define WARP     =   1;  //dmap,screen
  562.     define POS  =   2;  //x,y
  563.     define MOVEX    =   3;  //pixels (+/-)
  564.     define MOVEY    =   4;  //pixels (+/-)
  565.     define REFILLHP =   5;  //aNONE
  566.     define REFILLMP =   6;  //NONE
  567.     define REFILLCTR =  7;  //counter
  568.     define MAXHP    =   8;  //amount
  569.     define MAXMP    =   9;  //amount
  570.     define MAXCTR   =   10; //counter, amount
  571.    
  572.     define INVINCIBLE =     11; //(BOOL) on / off
  573.     define LINKITEM =   12; //item, (BOOL), on / off
  574.     define SAVE =       13; //item, (BOOL), on / off
  575.     define CREATEITEM =     14; //item, (BOOL), on / off
  576.     define CREATENPC =  15; //item, (BOOL), on / off
  577.     define PALETTE =    16; //item, (BOOL), on / off
  578.     define MONOCHROME =     17; //item, (BOOL), on / off
  579.     define BOMBS =      18; //item, (BOOL), on / off
  580.     define MBOMBS =     19; //item, (BOOL), on / off
  581.     define ARROWS =     20; //item, (BOOL), on / off
  582.     define MARROWS =    21; //item, (BOOL), on / off
  583.     define KEYS =       22; //item, (BOOL), on / off
  584.     define LKEYS =      23; //item, (BOOL), on / off
  585.     define RUPEES =     24; //item, (BOOL), on / off
  586.     define MRUPEES =    25; //item, (BOOL), on / off
  587.     define LMAP =       26; //level map, level id, true|false
  588.     define LBOSSKEY =   27; //level map, level id, true|false
  589.     define BIGHITBOX =  28; //level map, level id, true|false
  590.     define LINKDIAGONAL =   29; //level map, level id, true|false
  591.     define LTRIFORCE =  30; //level map, level id, true|false
  592.     define LCOMPASS =   31; //level map, level id, true|false
  593.     define RUNFFCSCRIPTID = 32;
  594.     define SETFFSCRIPT =    33;
  595.     define SETFFDATA =  34;
  596.    
  597.     define TINT =       35;
  598.     define HUE =        36;
  599.     define CLEARTINT =  37;
  600.    
  601.     define FCSET =      38;
  602.     define FX =     39;
  603.     define FY =     40;
  604.     define FVX =        41;
  605.     define FVY =        42;
  606.     define FAX =        43;
  607.     define FAY =        44;
  608.     define FFLAGS =     45; //ffc flags
  609.     define FTHEIGHT =   46;
  610.     define FTWIDTH =    47;
  611.     define FEHEIGHT =   48;
  612.     define FEWIDTH =    49;
  613.     define FLINK =      50;
  614.     define FMISC =      51;
  615.    
  616.     define PLAYSOUND =  52;
  617.     define PLAYMIDI =   53;
  618.     define DMAPMIDI =   54;
  619.    
  620.     define SETLIFE =    55;
  621.     define SETMAGIC =   56;
  622.     define SETCOUNTER = 57;
  623.    
  624.     define SAVESEQUENCE =   58;
  625.     define RUNSEQUENCE =    59;
  626.    
  627.    
  628.    
  629.    
  630.    
  631.     int num_instruction_params(int instr)
  632.     {
  633.         switch(instr)
  634.         {
  635.             //instruction       //variables
  636.             case NONE: return 0;
  637.             case WARP: return 2;    //dmap,screen
  638.             case POS: return 2;     //x,y
  639.             case MOVEX: return 1;   //pixels (+/-)
  640.             case MOVEY: return 1;   //pixels (+/-)
  641.             case REFILLHP: return 0;    //aNONE
  642.             case REFILLMP: return 0;    //NONE
  643.             case REFILLCTR: return 1;   //counter
  644.             case MAXHP: return 1;   //amount
  645.             case MAXMP: return 1;   //amount
  646.             case MAXCTR: return 2;  //counter, amount
  647.            
  648.             case INVINCIBLE: return 1;  //(BOOL) on / off
  649.             case LINKITEM: return 2;    //item, (BOOL), on / off
  650.             case SAVE: return 0;    //item, (BOOL), on / off
  651.             case CREATEITEM: return 3;  //item, (BOOL), on / off
  652.             case CREATENPC: return 3;   //item, (BOOL), on / off
  653.             case PALETTE: return 2; //item, (BOOL), on / off
  654.             case MONOCHROME: return 1;  //item, (BOOL), on / off
  655.            
  656.             case BOMBS: return 1;
  657.             case MBOMBS: return 1;
  658.             case ARROWS: return 1;
  659.             case MARROWS: return 1;
  660.             case KEYS: return 1;
  661.             case LKEYS: return 2; //level, number
  662.             case RUPEES: return 1;
  663.             case MRUPEES: return 1;
  664.             case LMAP: return 2;    //level map, level id, true|false
  665.             case LBOSSKEY: return 2;    //level bosskey, level id, true|false
  666.             case LTRIFORCE: return 2;   //level bosskey, level id, true|false
  667.             case LCOMPASS: return 2;    //level bosskey, level id, true|false
  668.             case BIGHITBOX: return 1;   //true|false
  669.             case LINKDIAGONAL: return 1;    //true|false
  670.             case RUNFFCSCRIPTID: return 1;
  671.             case SETFFSCRIPT: return 2;
  672.             case SETFFDATA: return 2;
  673.            
  674.             case TINT: return 3;
  675.             case HUE: return 4;
  676.             case CLEARTINT: return 0;
  677.            
  678.             case FCSET: return 2;
  679.             case FX: return 2;
  680.             case FCSET: return 2;
  681.             case FX: return 2;
  682.             case FY: return 2;
  683.             case FVX: return 2;
  684.             case FVY: return 2;
  685.             case FAX: return 2;
  686.             case FAY: return 2;
  687.             case FFLAGS: return 3;
  688.             case FTHEIGHT: return 2;
  689.             case FTWIDTH: return 2;
  690.             case FEHEIGHT: return 2;
  691.             case FEWIDTH: return 2;
  692.             case FLINK: return 2;
  693.             case FMISC: return 3;
  694.            
  695.             case PLAYSOUND: return 1;
  696.             case PLAYMIDI: return 1;
  697.             case DMAPMIDI: return 3;
  698.            
  699.             case SETLIFE: return 1;
  700.             case SETMAGIC: return 1;
  701.             case SETCOUNTER: return 2;
  702.            
  703.             case SAVESEQUENCE: return 1;
  704.             case RUNSEQUENCE: return 1;
  705.    
  706.             default:
  707.             {
  708.                
  709.                 TraceError("Invalid instruction passed to stack",instr);
  710.                 clearbuffer();
  711.                 return 0;
  712.             }
  713.         }
  714.     }
  715.    
  716.    
  717.    
  718.     int match_instruction(int token)
  719.     {
  720.         TraceNL(); TraceS("Input token into match_instruction is: "); TraceS(token); TraceNL();
  721.        
  722.         TraceNL(); TraceErrorS("match_instruction() token is: ",token); TraceNL();
  723.         TraceNL(); TraceError("Matching string with strcmp to 'w': ", strcmp(token,"w")); TraceNL();
  724.        
  725.         /* ONE WAY TO DO THIS. I did this with individual characters, and switches, to minimise the checks down
  726.         to the absolute minimum. -Z
  727.        
  728.         You could add specific instructions this way, if you wish.
  729.        
  730.         if ( !(strcmp(token,"w") ) ) TraceErrorS("Token in match_instruction() matched to WARP. Token: ", token);
  731.         if ( !(strcmp(token,"W") ) ) TraceErrorS("Token in match_instruction() matched to WARP. Token: ", token);
  732.         if ( !(strcmp(token,"p") ) ) TraceErrorS("Token in match_instruction() matched to POS. Token: ", token);
  733.         if ( !(strcmp(token,"P") ) ) TraceErrorS("Token in match_instruction() matched to POS. Token: ", token);
  734.         if ( !(strcmp(token,"rh") ) ) TraceErrorS("Token in match_instruction() matched to REFILLHP. Token: ", token);
  735.         if ( !(strcmp(token,"RH") ) ) TraceErrorS("Token in match_instruction() matched to REFILLHP. Token: ", token);
  736.         if ( !(strcmp(token,"Rh") ) ) TraceErrorS("Token in match_instruction() matched to REFILLHP. Token: ", token);
  737.         if ( !(strcmp(token,"rH") ) ) TraceErrorS("Token in match_instruction() matched to REFILLHP. Token: ", token);
  738.         if ( !(strcmp(token,"rH") ) ) TraceErrorS("Token in match_instruction() matched to REFILLHP. Token: ", token);
  739.         */
  740.        
  741.         /* Putting BRACES here causes Invalid pointer errors?! PARSER BUG!!
  742.         it works just find without the braces!!
  743.         if ( !(strcmp(token,"RunSequence") ) )
  744.         {
  745.             TraceErrorS("Found token RunSequence", token); // return RUNSEQUENCE; }//TraceErrorS("Token in match_instruction() matched to POS. Token: ", token);
  746.         }
  747.         */
  748.             //if ( !(strcmp(token,"RunSequence") ) ) { TraceError("Found token RunSequence", " "); return RUNSEQUENCE; }
  749.         //if ( !(strcmp(token,"SaveSequence") ) ) return SAVESEQUENCE;
  750.        
  751.         int sc;
  752.         if ( !(strcmp(token,"RunSequence") ) ) sc = RUNSEQUENCE;
  753.         if ( sc == RUNSEQUENCE ) { TraceError("Found token RunSequence", " "); return RUNSEQUENCE;}
  754.        
  755.         switch(token[0])
  756.         {
  757.             //A
  758.             case 'a':
  759.             case 'A':
  760.                 return ARROWS;
  761.             //B
  762.             case 'b':
  763.             case 'B':
  764.             {
  765.                 return BOMBS;
  766.                 /*
  767.                 switch(token[1])
  768.                 {
  769.                     case 'i':
  770.                     case 'I':
  771.                         return BIGHITBOX;
  772.                     case 'o':
  773.                     case 'O':
  774.                         return BOMBS;
  775.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  776.                 }
  777.                 */
  778.             }
  779.             case 'c':
  780.             case 'C':
  781.             {
  782.                 switch(token[1])
  783.                 {
  784.                     case NULL:
  785.                     case 'o':
  786.                     case 'O':
  787.                         return SETCOUNTER;
  788.                     case 'l':
  789.                     case 'L':
  790.                         return CLEARTINT;
  791.                     case 'r':
  792.                     case 'R':
  793.                     {
  794.                         switch(token[2])
  795.                         {
  796.                             case 'i':
  797.                             case 'I':
  798.                             {
  799.                                 TraceNL(); TraceS("instr() found token 'cri'"); TraceNL(); return CREATEITEM;
  800.                             }
  801.                            
  802.                             case 'n':
  803.                             case 'N':
  804.                             {
  805.                                 TraceNL(); TraceS("instr() found token 'cri'"); TraceNL(); return CREATENPC;
  806.                             }
  807.                
  808.                             default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  809.                         }
  810.                     }
  811.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  812.                 }
  813.                 break;
  814.             }
  815.             //D
  816.             case 'd':
  817.             case 'D':
  818.             {
  819.                 switch(token[1])
  820.                 {
  821.                     case NULL:
  822.                     case 'i':
  823.                     case 'I':
  824.                         return LINKDIAGONAL;
  825.                     case 'm':
  826.                     case 'M': //dmap stuff
  827.                     {
  828.                         switch(token[2])
  829.                         {
  830.                            
  831.                             case NULL:
  832.                             case 'm':
  833.                             case 'M':
  834.                                 return DMAPMIDI;
  835.                             default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  836.                
  837.                         }
  838.                     }  
  839.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  840.                
  841.                 }
  842.                 break;
  843.             }
  844.             //E
  845.             //F
  846.             case 'f':
  847.             case 'F':
  848.             {
  849.                 switch(token[1])
  850.                 {
  851.                     case 'a':
  852.                     case 'A':
  853.                     {
  854.                         switch(token[2])
  855.                         {
  856.                             case 'x':
  857.                             case 'X':
  858.                                 return FAX;
  859.                             case 'Y':
  860.                             case 'y':
  861.                                 return FAY;
  862.                             default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  863.                
  864.                         }
  865.                         break;
  866.                        
  867.                     }
  868.                     case 'c':
  869.                     case 'C':
  870.                         return FCSET;
  871.                     case 'd':
  872.                     case 'D':
  873.                         return SETFFDATA;
  874.                     case 'e':
  875.                     case 'E':
  876.                     {
  877.                         switch(token[2])
  878.                         {
  879.                             case 'h':
  880.                             case 'H':
  881.                                 return FEHEIGHT;
  882.                             case 'w':
  883.                             case 'W':
  884.                                 return FEWIDTH;
  885.                             default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  886.                         }
  887.                         break;
  888.                     }
  889.                     case 'f':
  890.                     case 'F':
  891.                     {
  892.                         switch(token[2])
  893.                         {
  894.                             case NULL:
  895.                             case 'l':
  896.                             case 'L':
  897.                                 return FFLAGS;
  898.                            
  899.                                
  900.                             default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  901.                         }
  902.                         break;
  903.                        
  904.                     }
  905.                     case 'l':
  906.                     case 'L':
  907.                         return FLINK;
  908.                     case 'M':
  909.                     case 'm':
  910.                         return FMISC;
  911.                     case 'S':
  912.                     case 's':
  913.                         return SETFFSCRIPT;
  914.                     case 't':
  915.                     case 'T':
  916.                     {
  917.                         switch(token[2])
  918.                         {
  919.                             case 'H':
  920.                             case 'h':
  921.                                 return FTHEIGHT;
  922.                             case 'w':
  923.                             case 'W':
  924.                                 return FTWIDTH;
  925.                             default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  926.                         }
  927.                         break;
  928.                        
  929.                     }
  930.                     case 'v':
  931.                     case 'V':
  932.                     {
  933.                         switch(token[2])
  934.                         {
  935.                             case 'x':
  936.                             case 'X':
  937.                                 return FVX;
  938.                             case 'y':
  939.                             case 'Y':
  940.                                 return FVY;
  941.                             default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  942.                         }
  943.                         break;
  944.                        
  945.                     }
  946.                     case 'x':
  947.                     case 'X':
  948.                         return FX;
  949.                     case 'y':
  950.                     case 'Y':
  951.                         return FY;
  952.                    
  953.                    
  954.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  955.                 }
  956.                 break;
  957.             }
  958.             //G
  959.             //H
  960.             case 'h':
  961.             case 'H':
  962.             {
  963.                 switch(token[1])
  964.                 {
  965.                     case NULL:
  966.                         return SETLIFE;
  967.                     case 'b':
  968.                     case 'B':
  969.                         return BIGHITBOX;
  970.                     case 'u':
  971.                     case 'U':
  972.                         return HUE;
  973.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  974.                 }
  975.             }
  976.             //I
  977.             case 'i':
  978.             case 'I':
  979.             {
  980.                 switch(token[1])
  981.                 {
  982.                     case 'n':
  983.                     case 'N':
  984.                         return INVINCIBLE;
  985.                     case 't':
  986.                     case 'T':
  987.                         return LINKITEM;
  988.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  989.                 }
  990.                 break;
  991.             }
  992.             //J
  993.             //K
  994.             case 'k':
  995.             case 'K':
  996.                 return KEYS;
  997.             //L
  998.             case 'l':
  999.             case 'L':
  1000.             {
  1001.                 switch(token[1])
  1002.                 {
  1003.                     case 'b':
  1004.                     case 'B':
  1005.                         return LBOSSKEY;
  1006.                     case 'c':
  1007.                     case 'C':
  1008.                         return LCOMPASS;
  1009.                     case 'K':
  1010.                     case 'k':
  1011.                         return LKEYS;
  1012.                     case 'M':
  1013.                     case 'm':
  1014.                         return LMAP;
  1015.                     case 't':
  1016.                     case 'T':
  1017.                         return LTRIFORCE;
  1018.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  1019.                 }
  1020.                
  1021.             }
  1022.             //M
  1023.             case 'm':
  1024.             case 'M':
  1025.             {
  1026.                 switch(token[1])
  1027.                 {
  1028.                     case NULL:
  1029.                         return SETMAGIC;
  1030.                     case 'x':
  1031.                     case 'X':
  1032.                         TraceNL(); TraceS("instr() found token 'mx'"); return MOVEX;
  1033.                     case 'y':
  1034.                     case 'Y':
  1035.                         TraceNL(); TraceS("instr() found token 'my'"); return MOVEY;
  1036.                     case 'h':
  1037.                     case 'H':
  1038.                         return MAXHP;
  1039.                     case 'm':
  1040.                     case 'M':
  1041.                         return MAXMP;
  1042.                     case 'c':
  1043.                     case 'C':
  1044.                         return MAXCTR;
  1045.                     case 'o':
  1046.                     case 'O':
  1047.                         return MONOCHROME;
  1048.                     case 'b':
  1049.                     case 'B':
  1050.                         return MBOMBS;
  1051.                    
  1052.                     case 'a':
  1053.                     case 'A':
  1054.                         return MARROWS;
  1055.                     case 'R':
  1056.                     case 'r':
  1057.                         return MRUPEES;
  1058.                    
  1059.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  1060.                 }
  1061.                 break;
  1062.             }
  1063.            
  1064.             //P
  1065.             case 'p':
  1066.             case 'P':
  1067.             {
  1068.                 switch(token[1])
  1069.                 {
  1070.                    
  1071.                     case 'a':
  1072.                     case 'A':
  1073.                         TraceNL(); TraceS("instr() found token 'p'"); TraceNL(); return PALETTE;
  1074.                    
  1075.                     case 'l':
  1076.                     case 'L':
  1077.                     {
  1078.                         switch(token[2])
  1079.                         {
  1080.                             case 'm':
  1081.                             case 'M':
  1082.                                 return PLAYMIDI;
  1083.                             case 's':
  1084.                             case 'S':
  1085.                                 return PLAYSOUND;
  1086.                            
  1087.                             default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  1088.                         }
  1089.                     }
  1090.                     case 'o':
  1091.                     case 'O':
  1092.                         TraceNL(); TraceS("instr() found token 'p'"); TraceNL(); return POS;
  1093.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  1094.                 }
  1095.                 break;
  1096.             }
  1097.             //Q
  1098.             //R
  1099.             case 'r':
  1100.             case 'R':
  1101.             {
  1102.                 switch(token[1])
  1103.                 {
  1104.                     case NULL:
  1105.                         return RUPEES;
  1106.                     case 'h':
  1107.                     case 'H':
  1108.                         return REFILLHP;
  1109.                     case 'm':
  1110.                     case 'M':
  1111.                         return REFILLMP;
  1112.                     case 'c':
  1113.                     case 'C':
  1114.                         return REFILLCTR;
  1115.                     case 'U':
  1116.                     case 'u':
  1117.                     {
  1118.                         switch(token[2])
  1119.                         {
  1120.                             case NULL:
  1121.                                 return RUPEES;
  1122.                             case 'n':
  1123.                             case 'N':
  1124.                                 return RUNFFCSCRIPTID;
  1125.                             default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  1126.                         }
  1127.                     }
  1128.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  1129.                 }
  1130.                 break;
  1131.             }
  1132.             //S
  1133.             case 's':
  1134.             case 'S':
  1135.             {
  1136.                 switch(token[1])
  1137.                 {
  1138.                     case 'a':
  1139.                     case 'A':
  1140.                     case 'V':
  1141.                     case 'v':
  1142.                     {
  1143.                         TraceNL(); TraceS("instr() found token 'save'"); return SAVE;
  1144.                     }
  1145.                     default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  1146.                 }
  1147.                 break;
  1148.             }
  1149.             //T
  1150.             case 't':
  1151.             case 'T':
  1152.                 return TINT;
  1153.             //U
  1154.             //V
  1155.             //W
  1156.             case 'w':
  1157.             case 'W':
  1158.                 TraceNL(); TraceS("instr() found token 'w'"); TraceNL(); return WARP;
  1159.            
  1160.             default: TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token); abort(); return 0;
  1161.         }
  1162.        
  1163.         //if ( strcmp(token,"w") == 0) { TraceNL(); TraceS("instr() found token 'w'"); return WARP; }
  1164.         //else if ( strcmp(token,"p") == 0) { TraceNL(); TraceS("instr() found token 'p'"); return POS; }
  1165.         //else if ( strcmp(token,"mx") == 0) { TraceNL(); TraceS("instr() found token 'mx'"); return MOVEX; }
  1166.         //else if ( strcmp(token,"my") == 0) return MOVEY;
  1167.         //else if ( strcmp(token,"rh") == 0) return REFILLHP;
  1168.         //else if ( strcmp(token,"rm") == 0) return REFILLMP;
  1169.         //else if ( strcmp(token,"rc") == 0) return REFILLCTR;
  1170.         //else if ( strcmp(token,"mh") == 0) return MAXHP;
  1171.         //else if ( strcmp(token,"mm") == 0) return MAXMP;
  1172.         //else if ( strcmp(token,"mc") == 0) return MAXCTR;
  1173.         //else if ( strcmp(token,"inv") == 0) return INVINCIBLE;
  1174.         //else// if ( strcmp(token,"itm") == 0) return LINKITEM;
  1175.         //else
  1176.         //{
  1177.         //  TraceErrorS("match_instruction(TOKEN) could not evaluate the instruction:",token);
  1178.         //  return 0;
  1179.         //}
  1180.     }
  1181.     void clearstack()
  1182.     {
  1183.         for ( int q = 0; q <= stack[TOP]; ++q ) stack[q] = 0;
  1184.         SP = 0;
  1185.         stack[TOP] = 0;
  1186.     }
  1187.     int enqueue()
  1188.     {
  1189.         TraceErrorS("enqueue() is pushing a string.", " ");
  1190.         int r = read(debug_buffer,true);
  1191.         //clearbuffer();
  1192.         ++ENQUEUED;
  1193.         TraceError("Enqueued is: ", ENQUEUED);
  1194.         TraceStack();
  1195.         TraceError("SP is now: ",SP);
  1196.         return ENQUEUED;
  1197.     }
  1198.     void TraceStack()
  1199.     {
  1200.         for ( int q = stack[TOP]; q >= 0; --q )
  1201.         TraceError("Stack register and value: ", q, stack[q]);
  1202.     }
  1203.     void TraceStack(int s)
  1204.     {
  1205.         for ( int q = s[TOP]; q >= 0; --q )
  1206.         TraceError("Stack register and value: ", q, s[q]);
  1207.     }
  1208.     void abort()
  1209.     {
  1210.         clearbuffer();
  1211.         Game->TypingMode = false;
  1212.         Link->PressStart = false;
  1213.         Link->InputStart = false;
  1214.     }
  1215.     void clearbuffer()
  1216.     {
  1217.         for ( int q = 0; q < BUFFER_LENGTH; ++q ) debug_buffer[q] = 0;
  1218.     }
  1219.     int read(int str, bool enqueued)
  1220.     {
  1221.         //debug
  1222.         if ( !enqueued ) {TraceNL(); TraceS("Starting read() with an initial buffer of: "); TraceS(str); TraceNL();}
  1223.         else {TraceNL(); TraceS("read() is running from enqueue() with an initial buffer of: "); TraceS(str); TraceNL();}
  1224.         int token[16]; int input_string_pos;
  1225.         int e; int token_pos = 0; int current_param;
  1226.         for ( input_string_pos = 0; input_string_pos < MAX_TOKEN_LENGTH; ++input_string_pos )
  1227.         {
  1228.             if (str[input_string_pos] == ',' ) { ++input_string_pos; break; }
  1229.             if (str[input_string_pos] == NULL ) break;
  1230.            
  1231.             token[token_pos] = str[input_string_pos];
  1232.             ++token_pos;
  1233.            
  1234.            
  1235.             //debug
  1236.            
  1237.             //++input_string_pos; //skip the comma now. If there are no params, we'll be on NULL.
  1238.         }
  1239.         //debug
  1240.         TraceNL(); TraceS("read() token: "); TraceS(token); TraceNL();
  1241.        
  1242.         //put the instruction onto the stack.
  1243.         //Right now, we are only allowing one instruction at a time.
  1244.         //This allows for future expansion.
  1245.         stack[SP] = match_instruction(token);
  1246.         TraceNL(); TraceS("SP is: "); Trace(stack[SP]); TraceNL();
  1247.         int num_params = num_instruction_params(stack[SP]);
  1248.         TraceNL(); TraceS("Number of expected params "); Trace(num_params); TraceNL();
  1249.        
  1250.         if ( num_params )
  1251.         {
  1252.             if ( str[input_string_pos] == NULL )
  1253.             {
  1254.                 //no params.
  1255.                 TraceErrorS("Input string is missing params. Token was:", token);
  1256.                 return 0;
  1257.             }
  1258.         }
  1259.        
  1260.         ++SP; //get the stack ready for the next instruction.
  1261.         stack[TOP] = SP+1;
  1262.         //push the variables onto the stack.
  1263.         while ( current_param < num_params )  //repeat this until we are out of params
  1264.             //NOT a Do loop, because some instructions have no params!
  1265.         {
  1266.             for ( token_pos = MAX_TOKEN_LENGTH-1; token_pos >= 0; --token_pos ) token[token_pos] = 0; //clear the token
  1267.            
  1268.             //copy over new token
  1269.             token_pos = 0;
  1270.             TraceNL(); TraceS("read() is seeking for params."); TraceNL();
  1271.             int temp_max = input_string_pos+MAX_TOKEN_LENGTH;
  1272.             for ( ; input_string_pos < temp_max; ++input_string_pos )
  1273.             {
  1274.                 if (str[input_string_pos] == ',' ) { ++input_string_pos; break; }
  1275.                 if (str[input_string_pos] == NULL ) break;
  1276.                
  1277.                 token[token_pos] = str[input_string_pos];
  1278.                 ++token_pos;
  1279.                
  1280.                
  1281.                 //debug
  1282.                
  1283.                 //++input_string_pos; //skip the comma now. If there are no params, we'll be on NULL.
  1284.             }
  1285.             /*
  1286.             while( str[input_string_pos] != ',' || str[input_string_pos] != NULL ) //|| current_param >= num_params ) //token terminates on a comma, or the end of the string
  1287.             {
  1288.                 token[token_pos] = str[input_string_pos]; //store the variable into a new token
  1289.                 ++token_pos;
  1290.             }
  1291.             */
  1292.             TraceNL(); TraceS("read() is getting tval"); TraceNL();
  1293.             int tval; //value of the param
  1294.             //first check the boolean types:
  1295.             TraceNL(); TraceS("The arg token is: "); TraceS(token); TraceNL();
  1296.             if ( !isNumber(token[0]) )
  1297.             {
  1298.                 switch(token[0])
  1299.                 {
  1300.                    
  1301.                     case '-': tval = atof(token); break;
  1302.                     case '.': tval = atof(token); break;
  1303.                    
  1304.                     case 't':
  1305.                     case 'T':
  1306.                         tval = 1; break;
  1307.                     case 'f':
  1308.                     case 'F':
  1309.                         tval = 0; break;
  1310.                    
  1311.                     case 'l':
  1312.                     case 'L':
  1313.                     {
  1314.                         switch(token[1])
  1315.                         {
  1316.                             case 'x':
  1317.                             case 'X':
  1318.                             {
  1319.                                 TraceError("tval set to Link->X: ", Link->X);
  1320.                                 tval = Link->X; break;
  1321.                             }
  1322.                             case 'y':
  1323.                             case 'Y':
  1324.                             {
  1325.                                 TraceError("tval set to Link->Y: ", Link->Y);
  1326.                                 tval = Link->Y; break;
  1327.                             }
  1328.                             default: TraceErrorS("Invalid token passed as an argument for instruction: ", token); tval = 0; break;
  1329.                         }
  1330.                         break;
  1331.                     }
  1332.                    
  1333.                     default: TraceErrorS("Invalid token passed as an argument for instruction: ", token); tval = 0; break;
  1334.                 }
  1335.                 //if ( strcmp(token,"true") ) tval = 1;
  1336.                 //else if ( strcmp(token,"T") ) tval = 1;
  1337.                 //else if ( strcmp(token,"false") ) tval = 0;
  1338.                 //else if ( strcmp(token,"F") ) tval = 0;
  1339.                
  1340.             }
  1341.             else //literals
  1342.             {
  1343.                
  1344.                 tval = atof(token);
  1345.                 TraceNL(); TraceS("found a literal var of: "); Trace(tval); TraceNL();
  1346.                
  1347.             }
  1348.             //push the token value onto the stack
  1349.             stack[SP] = tval;
  1350.        
  1351.             //now out stack looks like:
  1352.            
  1353.             //: PARAMn where n is the loop iteration
  1354.             //: PARAMn where n is the loop iteration
  1355.             //: PARAMn where n is the loop iteration
  1356.             //: INSTRUCTION
  1357.            
  1358.             ++SP; //this is why the stack size must be +1 larger than the3 total number of instructions and
  1359.             //params that it can hold.
  1360.             ++current_param;
  1361.            
  1362.         } //repeat this until we are out of params
  1363.         return 1;
  1364.        
  1365.     }
  1366.    
  1367.     //void getVarValue(int str)
  1368.     //{
  1369.     //  variables[VP] = atof(str);
  1370.     //  ++VP;
  1371.     //}
  1372.    
  1373.     void execute(int s)
  1374.     {
  1375.        
  1376.         TraceNL(); TraceS("Stack Trace");
  1377.         for ( int q = stack[TOP]; q >= 0; --q )
  1378.         {
  1379.             TraceNL(); Trace(stack[q]);
  1380.         }
  1381.        
  1382.        
  1383.         TraceNL(); TraceS("Running execute(stack)"); TraceNL();
  1384.         int reg_ptr = 0; //read the stack starting here, until we reach TOP.
  1385.         int args[MAX_ARGS];
  1386.         //evaluate the instruction:
  1387.         int instr;
  1388.         int current_arg = 0;
  1389.         int num_of_params = 0;
  1390.         for ( ; ENQUEUED >= 0; --ENQUEUED )
  1391.         {
  1392.             current_arg = 0; //we clear this for each enqueued instruction, so that we properly place args
  1393.                     //into their positions. Otherwise, we'd be trying to store args[5] instead of [2]!
  1394.             instr = s[reg_ptr];
  1395.             ++reg_ptr;
  1396.             num_of_params = num_instruction_params(instr);
  1397.             TraceNL(); TraceS("execute(stack) expects number of args to be: "); Trace(num_of_params); TraceNL();
  1398.             for ( ; num_of_params > 0; --num_of_params )
  1399.             {
  1400.                 args[current_arg] = s[reg_ptr];
  1401.                 TraceNL(); TraceS("Putting an arg on the heap. Arg value: "); Trace(args[current_arg]); TraceNL();
  1402.                 ++current_arg;
  1403.                 ++reg_ptr;
  1404.                
  1405.             }
  1406.            
  1407.             TraceNL(); TraceS("execute believes that the present instruction is: "); Trace(instr); TraceNL();
  1408.             TraceNL(); TraceS("args[0] is: "); Trace(args[0]); TraceNL();
  1409.             TraceNL(); TraceS("args[1] is: "); Trace(args[1]); TraceNL();
  1410.            
  1411.             switch(instr)
  1412.             {
  1413.                 case NONE:
  1414.                 TraceError("STACK INSTRUCTION IS INVALID: ", instr);
  1415.                 Game->TypingMode = false;
  1416.                 clearbuffer();
  1417.                 break;
  1418.                 case WARP:
  1419.                 {
  1420.                     Link->Warp(args[0],args[1]);
  1421.                     if ( log_actions ) TraceError("Cheat System Warped Link to dmap,screen:",args[0],args[1]);
  1422.                     break;
  1423.                 }
  1424.                 case POS:
  1425.                 {
  1426.                     Link->X = args[0];
  1427.                     Link->Y = args[1];
  1428.                     if ( log_actions ) TraceError("Cheat System repositioned Link to X,Y:",args[0],args[1]);
  1429.                     break;
  1430.                 }
  1431.                
  1432.                 case MOVEX:
  1433.                 {
  1434.                     Link->X += args[0];
  1435.                     if ( log_actions ) TraceError("Cheat system moved Link on his X axis by: ", args[0]);
  1436.                     break;
  1437.                 }
  1438.                 case MOVEY:
  1439.                 {
  1440.                     Link->Y += args[0];
  1441.                     if ( log_actions ) TraceError("Cheat system moved Link on his Y axis by", args[0]);
  1442.                     break;
  1443.                 }
  1444.                 case REFILLHP:
  1445.                 {
  1446.                     Link->HP =  Link->MaxHP;
  1447.                     if ( log_actions ) TraceError("Cheat system refilled Link's HP to", Link->MaxHP);
  1448.                     break;
  1449.                 }
  1450.                 case REFILLMP:
  1451.                 {
  1452.                     Link->MP =  Link->MaxMP;
  1453.                     if ( log_actions ) TraceError("Cheat system refilled Link's MP to", Link->MaxHP);
  1454.                     break;
  1455.                 }
  1456.                 case REFILLCTR:
  1457.                 {
  1458.                     Game->Counter[args[0]] =  Game->MCounter[args[0]];
  1459.                     if ( log_actions ) TraceError("Cheat system refilled Counter", args[0]);
  1460.                     break;
  1461.                 }
  1462.                 case MAXHP:
  1463.                 {
  1464.                     Game->MCounter[CR_LIFE] = args[0];
  1465.                     if ( log_actions ) TraceError("Cheat system set Link's Max HP to:",args[0]);
  1466.                     break;
  1467.                 }
  1468.                 case MAXMP:
  1469.                 {
  1470.                     Game->MCounter[CR_MAGIC] = args[0];
  1471.                     if ( log_actions ) TraceError("Cheat system set Link's Max MP to:",args[0]);
  1472.                     break;
  1473.                 }
  1474.                 case MAXCTR:
  1475.                 {
  1476.                     Game->Counter[args[0]] = args[1];
  1477.                     if ( log_actions ) TraceError("Cheat system refilled Counter (id, amount):",args[0],args[1]);
  1478.                     break;
  1479.                 }
  1480.                
  1481.                 case INVINCIBLE:
  1482.                 {
  1483.                     if ( args[0] )
  1484.                     {
  1485.                         Link->Invisible = true;
  1486.                         if ( log_actions ) TraceErrorS("Cheat system set Link's Invisibility state to ","true");
  1487.                         break;
  1488.                     }
  1489.                     else
  1490.                     {
  1491.                         Link->Invisible = false;
  1492.                         if ( log_actions ) TraceErrorS("Cheat system set Link's Invisibility state to ","false");
  1493.                         break;
  1494.                        
  1495.                     }
  1496.                    
  1497.                 }
  1498.                 case LINKITEM:
  1499.                 {
  1500.                     itemdata id = Game->LoadItemData(args[0]);
  1501.                     if ( id->Keep )
  1502.                     {
  1503.                         if ( args[1] )
  1504.                         {
  1505.                            
  1506.                             Link->Item[args[0]] = true;
  1507.                             if ( log_actions ) TraceErrorS("Cheat system set Link's Inventory Item to (item, state)","true");
  1508.                             break;
  1509.                         }
  1510.                         else
  1511.                         {
  1512.                             Link->Item[args[0]] = false;
  1513.                             if ( log_actions ) TraceErrorS("Cheat system set Link's Inventory Item to (item, state)","false");
  1514.                             break;
  1515.                            
  1516.                         }
  1517.                     }
  1518.                     else break;
  1519.                 }
  1520.                 case SAVE:
  1521.                 {
  1522.                     TraceNL(); TraceS("Cheat system is saving the game.");
  1523.                     clearbuffer();
  1524.                     Game->Save();
  1525.                     break;
  1526.                 }
  1527.                 case CREATEITEM:
  1528.                 {
  1529.                     if ( log_actions ) TraceError("Cheat system is creating item ID: ", args[0]);
  1530.                     if ( log_actions ) TraceError("Cheat system is creating item at X Position: ", args[1]);
  1531.                     if ( log_actions ) TraceError("Cheat system is creating item at Y Position: ", args[2]);
  1532.                     item cci = Screen->CreateItem(args[0]);
  1533.                     cci->X = args[1];
  1534.                     cci->Y = args[2];
  1535.                     break;
  1536.                 }
  1537.                 case CREATENPC:
  1538.                 {
  1539.                     if ( log_actions ) TraceError("Cheat system is creating npc ID: ", args[0]);
  1540.                     if ( log_actions ) TraceError("Cheat system is creating npc at X Position: ", args[1]);
  1541.                     if ( log_actions ) TraceError("Cheat system is creating npc at Y Position: ", args[2]);
  1542.                     npc ccn = Screen->CreateNPC(args[0]);
  1543.                     ccn->X = args[1];
  1544.                     ccn->Y = args[2];
  1545.                     break;
  1546.                 }
  1547.                 case PALETTE:
  1548.                 {
  1549.                     if ( args[0] < 0 )
  1550.                     {
  1551.                         Game->DMapPalette[Game->GetCurDMap()] = args[1];
  1552.                     }
  1553.                     else Game->DMapPalette[args[0]] = args[1];
  1554.                     break;
  1555.                 }
  1556.                 case MONOCHROME:
  1557.                 {
  1558.                     Graphics->Monochrome(args[0]); break;
  1559.                 }
  1560.                 case MBOMBS: Game->MCounter[CR_BOMBS] = args[0]; break;
  1561.                 case BOMBS: Game->Counter[CR_BOMBS] = args[0]; break;
  1562.                 case MARROWS: Game->MCounter[CR_ARROWS] = args[0]; break;
  1563.                 case ARROWS: Game->Counter[CR_ARROWS] = args[0]; break;
  1564.                 case KEYS: Game->Counter[CR_KEYS] = args[0]; break;
  1565.                 case RUPEES: Game->Counter[CR_RUPEES] = args[0]; break;
  1566.                 case MRUPEES: Game->MCounter[CR_RUPEES] = args[0]; break;
  1567.                
  1568.                 case LKEYS: Game->LKeys[args[0]] = args[1]; break;
  1569.                 case LINKDIAGONAL: Link->Diagonal = Cond(args[0],true,false); break;
  1570.                 case BIGHITBOX: Link->BigHitbox = Cond(args[0],true,false); break;
  1571.                
  1572.                 case LMAP:
  1573.                 {
  1574.                     if ( args[1] ) //true
  1575.                     {  
  1576.                         Game->LItems[args[0]] |= LI_MAP;
  1577.                     }
  1578.                     else Game->LItems[args[0]] &= ~LI_MAP;
  1579.                     break;
  1580.                 }
  1581.                 case LBOSSKEY:
  1582.                 {
  1583.                     if ( args[1] ) //true
  1584.                     {  
  1585.                         Game->LItems[args[0]] |= LI_BOSSKEY;
  1586.                     }
  1587.                     else Game->LItems[args[0]] &= ~LI_BOSSKEY;
  1588.                     break;
  1589.                 }
  1590.                 case LCOMPASS:
  1591.                 {
  1592.                     if ( args[1] ) //true
  1593.                     {  
  1594.                         Game->LItems[args[0]] |= LI_COMPASS;
  1595.                     }
  1596.                     else Game->LItems[args[0]] &= ~LI_COMPASS;
  1597.                     break;
  1598.                 }
  1599.                 case LTRIFORCE:
  1600.                 {
  1601.                     if ( args[1] ) //true
  1602.                     {  
  1603.                         Game->LItems[args[0]] |= LI_TRIFORCE;
  1604.                     }
  1605.                     else Game->LItems[args[0]] &= ~LI_TRIFORCE;
  1606.                     break;
  1607.                 }
  1608.                 case SETFFDATA:
  1609.                 {
  1610.                     ffc f = Screen->LoadFFC(args[0]);
  1611.                     f->Data = args[1];
  1612.                     break;
  1613.                 }
  1614.                 case SETFFSCRIPT:
  1615.                 {
  1616.                     ffc f = Screen->LoadFFC(args[0]);
  1617.                     f->Script = args[1];
  1618.                     break;
  1619.                 }
  1620.                 case RUNFFCSCRIPTID:
  1621.                 {
  1622.                     ffc f; bool running;
  1623.                     for ( int q = 1; q < 33; ++q )
  1624.                     {  
  1625.                         f = Screen->LoadFFC(args[0]);
  1626.                         if ( !f->Script )
  1627.                         {
  1628.                             if ( !f->Data ) f->Data = INVISIBLE_COMBO;
  1629.                             f->Script = args[1];
  1630.                             running = true;
  1631.                             break;
  1632.                         }
  1633.                     }
  1634.                     if ( !running ) TraceError("Cheat system could not find a free ffc for command RUN. Try FS,id,scriptid instead.",NULL);
  1635.                     break;
  1636.                 }
  1637.                 case CLEARTINT:
  1638.                 {
  1639.                     TraceError("Cheat shell is clearing all Tint().",NULL);
  1640.                     Graphics->ClearTint();
  1641.                     break;
  1642.                 }
  1643.                 case TINT:
  1644.                 {
  1645.                     TraceError("Cheat shell is setting Tint().",NULL);
  1646.                     TraceError("Tint(red) is: ",args[0]);
  1647.                     TraceError("Tint(green) is: ",args[1]);
  1648.                     TraceError("Tint(blue) is: ",args[2]);
  1649.                    
  1650.                     Graphics->Tint(args[0],args[1],args[2]);
  1651.                     break;
  1652.                 }
  1653.                 case HUE:
  1654.                 {
  1655.                     TraceError("Cheat shell is setting Hue().",NULL);
  1656.                     TraceError("Hue(red) is: ",args[0]);
  1657.                     TraceError("Hue(green) is: ",args[1]);
  1658.                     TraceError("Hue(blue) is: ",args[2]);
  1659.                     if ( args[3] ) TraceErrorS("Hue(distribution) is: ","true");
  1660.                     else TraceErrorS("Hue(distribution) is: ","false");
  1661.                    
  1662.                     Graphics->MonochromeHue(args[0],args[1],args[2],Cond(args[3],true,false));
  1663.                     break;
  1664.                 }
  1665.                 case FCSET:
  1666.                 {
  1667.                     ffc f = Screen->LoadFFC(args[0]);
  1668.                     f->CSet = args[1];
  1669.                     break;
  1670.                 }
  1671.                 case FX:
  1672.                 {
  1673.                     ffc f = Screen->LoadFFC(args[0]);
  1674.                     f->X = args[1];
  1675.                     break;
  1676.                 }  
  1677.                 case FY:
  1678.                 {
  1679.                     ffc f = Screen->LoadFFC(args[0]);
  1680.                     f->Y = args[1];
  1681.                     break;
  1682.                 }
  1683.                 case FVX:
  1684.                 {
  1685.                     ffc f = Screen->LoadFFC(args[0]);
  1686.                     f->Vx = args[1];
  1687.                     break;
  1688.                 }  
  1689.                 case FVY:
  1690.                 {
  1691.                     ffc f = Screen->LoadFFC(args[0]);
  1692.                     f->Vy = args[1];
  1693.                     break;
  1694.                 }  
  1695.                 case FAX:
  1696.                 {
  1697.                     ffc f = Screen->LoadFFC(args[0]);
  1698.                     f->Ax = args[1];
  1699.                     break;
  1700.                 }  
  1701.                 case FAY:
  1702.                 {
  1703.                     ffc f = Screen->LoadFFC(args[0]);
  1704.                     f->Ay = args[1];
  1705.                     break;
  1706.                 }  
  1707.                 case FFLAGS:
  1708.                 {
  1709.                     ffc f = Screen->LoadFFC(args[0]);
  1710.                     f->Flags[args[1]] = (args[2]);
  1711.                     break;
  1712.                 }  
  1713.                 case FTHEIGHT:
  1714.                 {
  1715.                     ffc f = Screen->LoadFFC(args[0]);
  1716.                     f->TileHeight = args[1];
  1717.                     break;
  1718.                 }  
  1719.                 case FTWIDTH:
  1720.                 {
  1721.                     ffc f = Screen->LoadFFC(args[0]);
  1722.                     f->TileWidth = args[1];
  1723.                     break;
  1724.                 }  
  1725.                 case FEHEIGHT:
  1726.                 {
  1727.                     ffc f = Screen->LoadFFC(args[0]);
  1728.                     f->EffectHeight = args[1];
  1729.                     break;
  1730.                 }  
  1731.                 case FEWIDTH:
  1732.                 {
  1733.                     ffc f = Screen->LoadFFC(args[0]);
  1734.                     f->EffectWidth = args[1];
  1735.                     break;
  1736.                 }  
  1737.                 case FLINK:
  1738.                 {
  1739.                     ffc f = Screen->LoadFFC(args[0]);
  1740.                     f->Link = args[1];
  1741.                     break;
  1742.                 }  
  1743.                 case FMISC:
  1744.                 {
  1745.                     ffc f = Screen->LoadFFC(args[0]);
  1746.                     f->Misc[args[1]] = args[2];
  1747.                     break;
  1748.                 }  
  1749.                
  1750.                 case PLAYSOUND: Game->PlaySound(args[0]); break;
  1751.                 case PLAYMIDI: Game->PlayMIDI(args[0]); break;
  1752.                 case DMAPMIDI:
  1753.                 {
  1754.                     if ( args[0] < 0 )
  1755.                     {
  1756.                         TraceError("Cheat system is setting the DMap MIDI for the current DMap to: ",args[1]);
  1757.                         Game->DMapMIDI[Game->GetCurDMap()] = args[1];
  1758.                     }
  1759.                    
  1760.                     else
  1761.                     {
  1762.                         TraceError("Cheat system is setting the DMap MIDI for the DMap: ",args[0]);
  1763.                         TraceError("...to MIDI ID: ",args[1]);
  1764.                         Game->DMapMIDI[args[0]] = args[1];
  1765.                     }
  1766.                     break;
  1767.                 }
  1768.                
  1769.                 case SETLIFE: Game->Counter[CR_LIFE] = args[0]; break;
  1770.                 case SETMAGIC: Game->Counter[CR_MAGIC] = args[0]; break;
  1771.                 case SETCOUNTER: Game->Counter[args[0]] = args[1]; break;
  1772.                    
  1773.                
  1774.                 case RUNSEQUENCE: { TraceError("Running Saved Sequence", args[0]); runsequence(args[0]); break; }
  1775.                 case SAVESEQUENCE: TraceError("Saveing Sequence", savesequence(args[0])); break;
  1776.                 default:
  1777.                 {
  1778.                    
  1779.                     TraceError("Invalid instruction passed to stack",instr);
  1780.                     break;
  1781.                 }
  1782.                
  1783.             }
  1784.         }
  1785.         ///-----later, we'll add this: //pop everything off of the stack
  1786.         //just wipe the stack for now, as we only support one command at this time
  1787.         for ( int q = 0; q <= s[TOP]; ++q ) s[q] = 0;
  1788.         SP = 0;
  1789.        
  1790.         //clear the main buffer, too!
  1791.         for ( int cl = 0; cl < BUFFER_LENGTH; ++cl ) debug_buffer[cl] = 0;
  1792.         Game->TypingMode = false; //insurance clear
  1793.         Link->PressStart = false;
  1794.         Link->InputStart = false;
  1795.         ENQUEUED = 0;
  1796.        
  1797.        
  1798.     }
  1799.        
  1800.     void run()
  1801.     {
  1802.    
  1803.        
  1804.        
  1805.     }
  1806. }
  1807.  
  1808. global script test
  1809. {
  1810.     void run()
  1811.     {
  1812.         debugshell.SP = 0;
  1813.         debugshell.clearbuffer();
  1814.         while(1)
  1815.         {
  1816.             debugshell.process();
  1817.             Waitdraw();
  1818.             Waitframe();
  1819.         }
  1820.        
  1821.     }
  1822. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement