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 >
Wrap
C/C++ Source or Header
|
2001-08-17
|
10KB
|
341 lines
////////////////////////////////////////////////////////////////////////////////
// Jagulator: Atari Jaguar Console Emulation Project (cmd.c)
// -----------------------------------------------------------------------------
// Jagulator is the Copyright (c) RealityMan 1998-2001 and is provided "as is"
// without any expressed or implied warranty. I have no Trademarks, Legal or
// otherwise. Atari, Jaguar and the Atari Logo are copyright Hasbro Inc. All
// other Copyrights and Trademarks are acknowledged. This project is in no way
// linked to Atari/Hasbro or other associated Atari companies.
//
// 07-07-2001 GH: New Source, Rewritten for Release 1.5.0
// 00-00-0000 GH: All Previous Source Considered as Development Code Only
#include "core.h"
////////////////////////////////////////////////////////////////////////////////
// Debugger Function Keys
void command_fkey( int a )
{
switch( a )
{
case KEY_F5:
command( "go" );
break;
}
}
////////////////////////////////////////////////////////////////////////////////
// Command Parameter Splitter
char *param( char **tp )
{
static char buf[256]; // Returned Parameters
char *d = buf, *s = *tp; // String Pointers
*buf = 0;
while( *s && *s <= 32 ) s++; // Skip Space
while( *s && *s > 32 ) // Copy Non-space
*d++ = *s++;
*d = 0;
while( *s && *s <= 32 ) s++; // Skip Space
*tp = s; // Set Parameter Pointer
return( buf ); // Return Buffer Contents
}
////////////////////////////////////////////////////////////////////////////////
// Command Help Screen
void printhelp( void )
{
#ifndef RELEASE
print( "\n" );
print( "\x1\x3-- 68000 Debug Commands ----------------------------" );
print( "---------------------------\n" );
print( "b <addr> - Run Continuously, Break at PC=<addr>\n" );
print( "t <hex> - Trace Through <hex> Instructions\n" );
print( "j <addr> - Jump Directly to <addr>\n" );
print( "i <num> - Generate Hardware Interrupt <num>\n" );
print( "u <addr> - Unassemble Code, Starting at <addr>\n" );
print( "d <addr> - Dump Memory, Starting at <addr>\n" );
print( "r - Show Register Dump and Next Instruction\n" );
print( "s <num> - Switch to CPU <num>\n" );
print( "\x1\x3-- GPU Debug Commands ------------------------------" );
print( "---------------------------\n" );
print( "gu <addr> - Unassemble GPU Code, Starting at <addr>\n" );
print( "\x1\x3-- DSP Debug Commands ------------------------------" );
print( "---------------------------\n" );
print( "du <addr> - Unassemble DSP Code, Starting at <addr>\n" );
print( "\x1\x3-- Object Processor Debug Commands -----------------" );
print( "---------------------------\n" );
print( "eo - Execute One Pass of Object List\n" );
print( "\x1\x3-- Basic Commands ----------------------------------" );
print( "---------------------------\n" );
print( "rla <ad> <fl> - Load Rom <fl> at Ram Address <ad>\n" );
print( "rom <file> - Load a New Rom Image\n" );
print( "jagcd - Load a CD Boot Rom Image\n" );
print( "g <num> - Execute <num> Frames\n" );
print( "exit, x - Exit\n" );
print( "\x1\x3----------------------------------------------------" );
print( "---------------------------\n\n" );
#endif
}
////////////////////////////////////////////////////////////////////////////////
// Main Command Activity
int command_main( char *p, char *tp )
{
extern dword debugpc, hexaddr;
extern dword debuggpc, debugdpc;
#ifdef DEBUG
dword tmppc; // Temporary Program Counter
#endif
char *tpend;
if( 0 ) { }
#ifdef DEBUG
else IFIS(p,"u") // Unassemble 68000
{
if( !st.readytogo ) return( 1 );
if((*tp)!=0){
tmppc = strtoul( tp, &tpend, 16 );
debugpc = tmppc;
}
cpudebug_disassemble( 16 );
}
else IFIS(p,"d") // Dump Memory
{
if( !st.readytogo ) return( 1 );
if((*tp)!=0){
tmppc = strtoul( tp, &tpend, 16 );
if( tpend != tp ) hexaddr = tmppc;
}
cpudebug_hexdump();
}
else IFIS(p,"r") // Register Dump
{
if( !st.readytogo ) return( 1 );
cpudebug_registerdump();
}
else IFIS(p,"b") // Run Continuously, Break at PC
{
static int c;
if( !st.readytogo ) return( 1 );
if((*tp)!=0){
tmppc = strtoul(tp,&tpend,16);
if(tpend!=tp){
c = 1000000;
while(s68000context.pc!=tmppc)
s68000exec(1);
cpudebug_registerdump();
}else{
error( "Invalid Address" );
}
}else{
error( "Needs an Address" );
}
}
else IFIS(p,"t") // Trace Through [hex] Instructions
{
if( !st.readytogo ) return( 1 );
tmppc=1;
if((*tp)!=0){
tmppc=strtoul(tp,&tpend,16);
if(tpend==tp)tmppc=1;
}
if(tmppc>0){
while(tmppc--)s68000exec(1);
cpudebug_registerdump();
}
}
else IFIS(p,"s") // Switch to CPU [n]
{
if( !st.readytogo ) return( 1 );
if((*tp)!=0){
tmppc=strtoul(tp,&tpend,10);
if(tmppc>0)return tmppc;
else error( "Invalid CPU Number" );
}else return 0;
}
else IFIS(p,"j") // Jump Directly to [Address]
{
if( !st.readytogo ) return( 1 );
if((*tp)!=0){
tmppc=strtoul(tp,&tpend,16);
if(tpend!=tp){
s68000context.pc=tmppc;
print("PC Set to 0x%06X\n",s68000context.pc);
debugpc=s68000context.pc;
cpudebug_disassemble(1);
debugpc=s68000context.pc;
}else{
error("Invalid Address");
}
}else{
error("Need an Address");
}
}
else IFIS(p,"i") // Generate Hardware Interrupt [Number]
{
if( !st.readytogo ) return( 1 );
if((*tp)!=0){
tmppc=strtoul(tp,&tpend,10);
if(tpend!=tp){
print("Interrupt %d Generated\n",tmppc);
s68000interrupt(tmppc, -1);
s68000flushInterrupts();
cpudebug_registerdump();
debugpc=s68000context.pc;
}else{
error("Invalid Interrupt Number");
}
}else{
error("Need an Interrupt Number");
}
}
else IFIS( p, "gu" ) // Unassemble GPU
{
if( !st.readytogo ) return( 1 );
if( (*tp) != 0 ) {
tmppc = strtoul( tp, &tpend, 16 );
debuggpc = tmppc;
}
gpudebug_disassemble( 16 );
}
else IFIS( p, "du" ) // Unassemble DSP
{
if( !st.readytogo ) return( 1 );
if( (*tp) != 0 ) {
tmppc = strtoul( tp, &tpend, 16 );
debugdpc = tmppc;
}
dspdebug_disassemble( 16 );
}
else IFIS(p,"help")
{
printhelp(); // Command Help
}
#endif
else if( IS(p,"x") || IS(p,"exit") )
{
exitnow(); // Exit
}
else IFIS(p,"rom") // Load Rom
{
boot( tp );
}
#ifdef DEBUG
else IFIS(p,"jagcd") // Load CD Boot Rom
{
bootcd();
}
#endif
else IFIS(p,"rla") // Load Rom at Address
{
static int a;
if( (*tp)!=0 )
{
p = param( &tp ); sscanf( p, "%X", &a );
p = param( &tp );
bootaddr( p, a );
s68000context.areg[7] = 0x0004000; // Set Stack
s68000context.pc = a; // Set Program Counter
}
else
{
#ifdef DEBUG
print( YEL"Missing Parameters\n" );
#endif
}
}
else if( IS(p,"g") )
{
static dword c;
static dword fr;
if( !st.readytogo ) return( 1 );
fr=strtoul(tp,&tpend,10);
for(c = 0; c < fr; c++ )
{
s68000exec(217714);
s68000releaseTimeslice();
s68000interrupt( 1, 64 );
object_exec();
}
}
else if( IS(p,"go") )
{/*
if( !st.readytogo ) return( 1 );
while( st.emulating )
{
s68000exec(217714);
//s68000exec(500000);
s68000releaseTimeslice();
s68000interrupt( 1, 64 );
exec_object();
if( GetAsyncKeyState( VK_ESCAPE ) ) st.emulating = FALSE;
}*/
cpu_exec();
}
else if( IS(p,"eo") )
{
object_exec();
}
else
return( 0 );
return( 1 );
}
////////////////////////////////////////////////////////////////////////////////
// Command Entry Point
void command( char *cmd )
{
char *tp, *p, *cs, *cd;
int a;
char buf[256];
#ifdef DEBUG
view_writeconsole( "\x01\x17\r" );
con_cursorxy( 0, 0, 0 );
view.consolecursor = -1;
#endif
cs = cmd;
while( *cs )
{
// Copy Next Command (Until EOS or ;)
cd = buf;
while( *cs && *cs <= 32 ) cs++;
while( *cs && *cs != ';' )
{
*cd++ = *cs++;
}
*cd = 0;
if( *cs == ';' ) cs++;
while( *cs && *cs <= 32 ) cs++;
// Get Command Name
tp = buf;
p = param( &tp );
// Execute
a = 0;
if( !a ) a = command_main( p, tp );
#ifdef DEBUG
if( !a ) print( "Unknown Command '%s', Try Help.\n", p );
#endif
}
#ifdef DEBUG
print( NULL );
#endif
}