Advertisement
ZoriaRPG

Debug Cheat Shell (v1.10.2)

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