diff src/gba/agbprint.cpp @ 1:f9f4f1b99eed

importing src directory
author Robert McIntyre <rlm@mit.edu>
date Sat, 03 Mar 2012 10:31:27 -0600
parents
children
line wrap: on
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/gba/agbprint.cpp	Sat Mar 03 10:31:27 2012 -0600
     1.3 @@ -0,0 +1,82 @@
     1.4 +#include <cstdio>
     1.5 +#include <cstring>
     1.6 +
     1.7 +#include "GBAGlobals.h"
     1.8 +
     1.9 +extern void (*dbgOutput)(char *, u32);
    1.10 +extern int systemVerbose;
    1.11 +
    1.12 +static bool agbPrintEnabled = false;
    1.13 +static bool agbPrintProtect = false;
    1.14 +
    1.15 +bool agbPrintWrite(u32 address, u16 value)
    1.16 +{
    1.17 +	if (agbPrintEnabled)
    1.18 +	{
    1.19 +		if (address == 0x9fe2ffe) // protect
    1.20 +		{
    1.21 +			agbPrintProtect = (value != 0);
    1.22 +			debuggerWriteHalfWord(address, value);
    1.23 +			return true;
    1.24 +		}
    1.25 +		else
    1.26 +		{
    1.27 +			if (agbPrintProtect &&
    1.28 +			    ((address >= 0x9fe20f8 && address <= 0x9fe20ff) // control structure
    1.29 +			     || (address >= 0x8fd0000 && address <= 0x8fdffff)
    1.30 +			     || (address >= 0x9fd0000 && address <= 0x9fdffff)))
    1.31 +			{
    1.32 +				debuggerWriteHalfWord(address, value);
    1.33 +				return true;
    1.34 +			}
    1.35 +		}
    1.36 +	}
    1.37 +	return false;
    1.38 +}
    1.39 +
    1.40 +void agbPrintReset()
    1.41 +{
    1.42 +	agbPrintProtect = false;
    1.43 +}
    1.44 +
    1.45 +void agbPrintEnable(bool enable)
    1.46 +{
    1.47 +	agbPrintEnabled = enable;
    1.48 +}
    1.49 +
    1.50 +bool agbPrintIsEnabled()
    1.51 +{
    1.52 +	return agbPrintEnabled;
    1.53 +}
    1.54 +
    1.55 +void agbPrintFlush()
    1.56 +{
    1.57 +	u16 get = debuggerReadHalfWord(0x9fe20fc);
    1.58 +	u16 put = debuggerReadHalfWord(0x9fe20fe);
    1.59 +
    1.60 +	u32 address = (debuggerReadHalfWord(0x9fe20fa) << 16);
    1.61 +	if (address != 0xfd0000 && address != 0x1fd0000)
    1.62 +	{
    1.63 +		dbgOutput("Did you forget to call AGBPrintInit?\n", 0);
    1.64 +		// get rid of the text otherwise we will continue to be called
    1.65 +		debuggerWriteHalfWord(0x9fe20fc, put);
    1.66 +		return;
    1.67 +	}
    1.68 +
    1.69 +	u8 *data = &rom[address];
    1.70 +
    1.71 +	while (get != put)
    1.72 +	{
    1.73 +		char c = data[get++];
    1.74 +		char s[2];
    1.75 +		s[0] = c;
    1.76 +		s[1] = 0;
    1.77 +
    1.78 +		if (systemVerbose & VERBOSE_AGBPRINT)
    1.79 +			dbgOutput(s, 0);
    1.80 +		if (c == '\n')
    1.81 +			break;
    1.82 +	}
    1.83 +	debuggerWriteHalfWord(0x9fe20fc, get);
    1.84 +}
    1.85 +