home *** CD-ROM | disk | FTP | other *** search
/ ST-Computer Leser 2002 January / STC_CD_01_2002.iso / JAGUAR / JAG_SRC / SOURCE / CMD.C < prev    next >
C/C++ Source or Header  |  2001-08-17  |  10KB  |  341 lines

  1. ////////////////////////////////////////////////////////////////////////////////
  2. // Jagulator: Atari Jaguar Console Emulation Project (cmd.c)
  3. // -----------------------------------------------------------------------------
  4. // Jagulator is the Copyright (c) RealityMan 1998-2001 and is provided "as is" 
  5. // without any expressed or implied warranty. I have no Trademarks, Legal or 
  6. // otherwise. Atari, Jaguar and the Atari Logo are copyright Hasbro Inc. All 
  7. // other Copyrights and Trademarks are acknowledged. This project is in no way 
  8. // linked to Atari/Hasbro or other associated Atari companies.                
  9. //
  10. // 07-07-2001 GH: New Source, Rewritten for Release 1.5.0
  11. // 00-00-0000 GH: All Previous Source Considered as Development Code Only
  12.  
  13. #include "core.h"
  14.  
  15. ////////////////////////////////////////////////////////////////////////////////
  16. // Debugger Function Keys
  17.  
  18.    void command_fkey( int a )
  19.    {
  20.       switch( a )
  21.       {
  22.          case KEY_F5:
  23.             command( "go" );
  24.             break;
  25.       }
  26.    }
  27.  
  28. ////////////////////////////////////////////////////////////////////////////////
  29. // Command Parameter Splitter
  30.  
  31.    char *param( char **tp )
  32.    {
  33.       static char buf[256];            // Returned Parameters
  34.       char *d = buf, *s = *tp;         // String Pointers
  35.  
  36.       *buf = 0;
  37.  
  38.       while( *s && *s <= 32 ) s++;     // Skip Space
  39.       while( *s && *s > 32 )           // Copy Non-space
  40.          *d++ = *s++;
  41.       *d = 0;
  42.       while( *s && *s <= 32 ) s++;     // Skip Space
  43.       *tp = s;                         // Set Parameter Pointer
  44.  
  45.       return( buf );                   // Return Buffer Contents
  46.    }
  47.  
  48. ////////////////////////////////////////////////////////////////////////////////
  49. // Command Help Screen
  50.  
  51.    void printhelp( void )
  52.    {
  53.       #ifndef RELEASE
  54.       print( "\n" );
  55.       print( "\x1\x3-- 68000 Debug Commands ----------------------------" );
  56.       print( "---------------------------\n" );
  57.       print( "b <addr>      - Run Continuously, Break at PC=<addr>\n" );
  58.       print( "t <hex>       - Trace Through <hex> Instructions\n" );
  59.       print( "j <addr>      - Jump Directly to <addr>\n" );
  60.       print( "i <num>       - Generate Hardware Interrupt <num>\n" );
  61.       print( "u <addr>      - Unassemble Code, Starting at <addr>\n" );
  62.       print( "d <addr>      - Dump Memory, Starting at <addr>\n" );
  63.       print( "r             - Show Register Dump and Next Instruction\n" );
  64.       print( "s <num>       - Switch to CPU <num>\n" );
  65.       print( "\x1\x3-- GPU Debug Commands ------------------------------" );
  66.       print( "---------------------------\n" );
  67.       print( "gu <addr>     - Unassemble GPU Code, Starting at <addr>\n" );
  68.       print( "\x1\x3-- DSP Debug Commands ------------------------------" );
  69.       print( "---------------------------\n" );
  70.       print( "du <addr>     - Unassemble DSP Code, Starting at <addr>\n" );
  71.       print( "\x1\x3-- Object Processor Debug Commands -----------------" );
  72.       print( "---------------------------\n" );
  73.       print( "eo            - Execute One Pass of Object List\n" );
  74.       print( "\x1\x3-- Basic Commands ----------------------------------" );
  75.       print( "---------------------------\n" );
  76.       print( "rla <ad> <fl> - Load Rom <fl> at Ram Address <ad>\n" );
  77.       print( "rom <file>    - Load a New Rom Image\n" );
  78.       print( "jagcd         - Load a CD Boot Rom Image\n" );
  79.       print( "g <num>       - Execute <num> Frames\n" );
  80.       print( "exit, x       - Exit\n" );
  81.       print( "\x1\x3----------------------------------------------------" );
  82.       print( "---------------------------\n\n" );
  83.       #endif
  84.    }
  85.  
  86. ////////////////////////////////////////////////////////////////////////////////
  87. // Main Command Activity
  88.  
  89.    int command_main( char *p, char *tp )
  90.    {
  91.       extern dword debugpc, hexaddr;
  92.       extern dword debuggpc, debugdpc;
  93.       #ifdef DEBUG
  94.        dword tmppc;                     // Temporary Program Counter
  95.       #endif
  96.       char *tpend;
  97.  
  98.       if( 0 ) { }
  99.       #ifdef DEBUG
  100.       else IFIS(p,"u")                 // Unassemble 68000
  101.       {
  102.          if( !st.readytogo ) return( 1 );
  103.          if((*tp)!=0){
  104.                 tmppc = strtoul( tp, &tpend, 16 );
  105.                 debugpc = tmppc;
  106.             }
  107.             cpudebug_disassemble( 16 );
  108.       }
  109.       else IFIS(p,"d")                 // Dump Memory
  110.       {
  111.          if( !st.readytogo ) return( 1 );
  112.             if((*tp)!=0){
  113.                 tmppc = strtoul( tp, &tpend, 16 );
  114.                 if( tpend != tp ) hexaddr = tmppc;
  115.             }
  116.             cpudebug_hexdump();
  117.       }
  118.       else IFIS(p,"r")                 // Register Dump
  119.       {
  120.          if( !st.readytogo ) return( 1 );
  121.          cpudebug_registerdump();
  122.       }
  123.       else IFIS(p,"b")                 // Run Continuously, Break at PC
  124.       {
  125.          static int c;
  126.  
  127.          if( !st.readytogo ) return( 1 );
  128.          if((*tp)!=0){
  129.                 tmppc = strtoul(tp,&tpend,16);
  130.                 if(tpend!=tp){
  131.                c = 1000000;
  132.                     while(s68000context.pc!=tmppc)
  133.                   s68000exec(1);
  134.                     cpudebug_registerdump();
  135.                 }else{
  136.                     error( "Invalid Address" );
  137.                 }
  138.             }else{
  139.             error( "Needs an Address" );
  140.             }
  141.       }
  142.       else IFIS(p,"t")                 // Trace Through [hex] Instructions
  143.       {
  144.          if( !st.readytogo ) return( 1 );
  145.          tmppc=1;
  146.             if((*tp)!=0){
  147.                 tmppc=strtoul(tp,&tpend,16);
  148.                 if(tpend==tp)tmppc=1;
  149.             }
  150.             if(tmppc>0){
  151.                 while(tmppc--)s68000exec(1);
  152.                 cpudebug_registerdump();
  153.             }
  154.       }
  155.       else IFIS(p,"s")                 // Switch to CPU [n]
  156.       {
  157.          if( !st.readytogo ) return( 1 );
  158.          if((*tp)!=0){
  159.                 tmppc=strtoul(tp,&tpend,10);
  160.                 if(tmppc>0)return tmppc;
  161.                 else error( "Invalid CPU Number" );
  162.             }else return 0;
  163.       }      
  164.       else IFIS(p,"j")                 // Jump Directly to [Address]
  165.       {
  166.          if( !st.readytogo ) return( 1 );
  167.          if((*tp)!=0){
  168.                 tmppc=strtoul(tp,&tpend,16);
  169.                 if(tpend!=tp){
  170.                     s68000context.pc=tmppc;
  171.                     print("PC Set to 0x%06X\n",s68000context.pc);
  172.                     debugpc=s68000context.pc;
  173.                     cpudebug_disassemble(1);
  174.                     debugpc=s68000context.pc;
  175.                 }else{
  176.                     error("Invalid Address");
  177.                 }
  178.             }else{
  179.                 error("Need an Address");
  180.             }
  181.       }      
  182.       else IFIS(p,"i")                 // Generate Hardware Interrupt [Number]
  183.       {
  184.          if( !st.readytogo ) return( 1 );
  185.          if((*tp)!=0){
  186.                 tmppc=strtoul(tp,&tpend,10);
  187.                 if(tpend!=tp){
  188.                     print("Interrupt %d Generated\n",tmppc);
  189.                     s68000interrupt(tmppc, -1);
  190.                s68000flushInterrupts();
  191.                     cpudebug_registerdump();
  192.                     debugpc=s68000context.pc;
  193.                 }else{
  194.                     error("Invalid Interrupt Number");
  195.                 }
  196.             }else{
  197.                 error("Need an Interrupt Number");
  198.             }
  199.       }      
  200.       else IFIS( p, "gu" )             // Unassemble GPU
  201.       {
  202.          if( !st.readytogo ) return( 1 );
  203.          if( (*tp) != 0 ) {
  204.                 tmppc = strtoul( tp, &tpend, 16 );
  205.                 debuggpc = tmppc;
  206.             }
  207.             gpudebug_disassemble( 16 );
  208.       }
  209.       else IFIS( p, "du" )             // Unassemble DSP
  210.       {
  211.          if( !st.readytogo ) return( 1 );
  212.          if( (*tp) != 0 ) {
  213.                 tmppc = strtoul( tp, &tpend, 16 );
  214.                 debugdpc = tmppc;
  215.             }
  216.             dspdebug_disassemble( 16 );
  217.       }
  218.       else IFIS(p,"help")
  219.       {
  220.          printhelp();                  // Command Help
  221.       }
  222.       #endif
  223.       else if( IS(p,"x") || IS(p,"exit") )
  224.       {
  225.          exitnow();                    // Exit
  226.       }
  227.       else IFIS(p,"rom")               // Load Rom
  228.       {
  229.          boot( tp );
  230.       }
  231.       #ifdef DEBUG
  232.       else IFIS(p,"jagcd")             // Load CD Boot Rom
  233.       {
  234.          bootcd();
  235.       }
  236.       #endif
  237.       else IFIS(p,"rla")               // Load Rom at Address
  238.       {
  239.          static int a;
  240.  
  241.          if( (*tp)!=0 )
  242.          {
  243.             p = param( &tp ); sscanf( p, "%X", &a );
  244.             p = param( &tp );
  245.             bootaddr( p, a );
  246.             s68000context.areg[7] = 0x0004000;     // Set Stack
  247.             s68000context.pc = a;                  // Set Program Counter
  248.          }
  249.          else
  250.          {
  251.             #ifdef DEBUG
  252.             print( YEL"Missing Parameters\n" );
  253.             #endif
  254.          }
  255.       }
  256.       else if( IS(p,"g") )
  257.       {
  258.          static dword c;
  259.          static dword fr;
  260.  
  261.          if( !st.readytogo ) return( 1 );
  262.            fr=strtoul(tp,&tpend,10);
  263.          for(c = 0; c < fr; c++ )
  264.          {
  265.             s68000exec(217714);
  266.             s68000releaseTimeslice();
  267.             s68000interrupt( 1, 64 );
  268.             object_exec();
  269.          }
  270.       }
  271.       else if( IS(p,"go") )
  272.       {/*
  273.          if( !st.readytogo ) return( 1 );
  274.          while( st.emulating )
  275.          {
  276.             s68000exec(217714);
  277.             //s68000exec(500000);
  278.             s68000releaseTimeslice();
  279.             s68000interrupt( 1, 64 );
  280.             exec_object();
  281.             if( GetAsyncKeyState( VK_ESCAPE ) ) st.emulating = FALSE;
  282.          }*/
  283.          cpu_exec();
  284.       }
  285.       else if( IS(p,"eo") )
  286.       {
  287.          object_exec();
  288.       }
  289.       else 
  290.          return( 0 );
  291.     
  292.       return( 1 );
  293.    }
  294.  
  295. ////////////////////////////////////////////////////////////////////////////////
  296. // Command Entry Point
  297.  
  298.    void command( char *cmd )
  299.    {
  300.       char *tp, *p, *cs, *cd;
  301.       int   a;
  302.       char  buf[256];
  303.  
  304.       #ifdef DEBUG
  305.       view_writeconsole( "\x01\x17\r" );
  306.       con_cursorxy( 0, 0, 0 );
  307.       view.consolecursor = -1;
  308.       #endif
  309.  
  310.       cs = cmd;
  311.       while( *cs )
  312.       {
  313.          // Copy Next Command (Until EOS or ;)
  314.          cd = buf;
  315.          while( *cs && *cs <= 32 ) cs++;
  316.          while( *cs && *cs != ';' )
  317.          {
  318.             *cd++ = *cs++;
  319.          }
  320.          *cd = 0;
  321.          if( *cs == ';' ) cs++;
  322.          while( *cs && *cs <= 32 ) cs++;
  323.  
  324.          // Get Command Name
  325.          tp = buf;
  326.          p = param( &tp );
  327.  
  328.          // Execute
  329.          a = 0;
  330.          if( !a ) a = command_main( p, tp );
  331.          #ifdef DEBUG
  332.          if( !a ) print( "Unknown Command '%s', Try Help.\n", p );
  333.          #endif
  334.       }
  335.  
  336.       #ifdef DEBUG
  337.       print( NULL );
  338.       #endif
  339.    }
  340.  
  341.