Advertisement
ZoriaRPG

Debug Cheat Shell (v1.14.2, TRACE Patches)

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