Advertisement
ZoriaRPG

Debug Cheat Shell (v1.14, WIP on TRACE)

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