annotate src/gba/agbprint.cpp @ 397:9b0d79cad624

use E as scratch instead of C
author Robert McIntyre <rlm@mit.edu>
date Fri, 13 Apr 2012 04:56:01 -0500
parents f9f4f1b99eed
children
rev   line source
rlm@1 1 #include <cstdio>
rlm@1 2 #include <cstring>
rlm@1 3
rlm@1 4 #include "GBAGlobals.h"
rlm@1 5
rlm@1 6 extern void (*dbgOutput)(char *, u32);
rlm@1 7 extern int systemVerbose;
rlm@1 8
rlm@1 9 static bool agbPrintEnabled = false;
rlm@1 10 static bool agbPrintProtect = false;
rlm@1 11
rlm@1 12 bool agbPrintWrite(u32 address, u16 value)
rlm@1 13 {
rlm@1 14 if (agbPrintEnabled)
rlm@1 15 {
rlm@1 16 if (address == 0x9fe2ffe) // protect
rlm@1 17 {
rlm@1 18 agbPrintProtect = (value != 0);
rlm@1 19 debuggerWriteHalfWord(address, value);
rlm@1 20 return true;
rlm@1 21 }
rlm@1 22 else
rlm@1 23 {
rlm@1 24 if (agbPrintProtect &&
rlm@1 25 ((address >= 0x9fe20f8 && address <= 0x9fe20ff) // control structure
rlm@1 26 || (address >= 0x8fd0000 && address <= 0x8fdffff)
rlm@1 27 || (address >= 0x9fd0000 && address <= 0x9fdffff)))
rlm@1 28 {
rlm@1 29 debuggerWriteHalfWord(address, value);
rlm@1 30 return true;
rlm@1 31 }
rlm@1 32 }
rlm@1 33 }
rlm@1 34 return false;
rlm@1 35 }
rlm@1 36
rlm@1 37 void agbPrintReset()
rlm@1 38 {
rlm@1 39 agbPrintProtect = false;
rlm@1 40 }
rlm@1 41
rlm@1 42 void agbPrintEnable(bool enable)
rlm@1 43 {
rlm@1 44 agbPrintEnabled = enable;
rlm@1 45 }
rlm@1 46
rlm@1 47 bool agbPrintIsEnabled()
rlm@1 48 {
rlm@1 49 return agbPrintEnabled;
rlm@1 50 }
rlm@1 51
rlm@1 52 void agbPrintFlush()
rlm@1 53 {
rlm@1 54 u16 get = debuggerReadHalfWord(0x9fe20fc);
rlm@1 55 u16 put = debuggerReadHalfWord(0x9fe20fe);
rlm@1 56
rlm@1 57 u32 address = (debuggerReadHalfWord(0x9fe20fa) << 16);
rlm@1 58 if (address != 0xfd0000 && address != 0x1fd0000)
rlm@1 59 {
rlm@1 60 dbgOutput("Did you forget to call AGBPrintInit?\n", 0);
rlm@1 61 // get rid of the text otherwise we will continue to be called
rlm@1 62 debuggerWriteHalfWord(0x9fe20fc, put);
rlm@1 63 return;
rlm@1 64 }
rlm@1 65
rlm@1 66 u8 *data = &rom[address];
rlm@1 67
rlm@1 68 while (get != put)
rlm@1 69 {
rlm@1 70 char c = data[get++];
rlm@1 71 char s[2];
rlm@1 72 s[0] = c;
rlm@1 73 s[1] = 0;
rlm@1 74
rlm@1 75 if (systemVerbose & VERBOSE_AGBPRINT)
rlm@1 76 dbgOutput(s, 0);
rlm@1 77 if (c == '\n')
rlm@1 78 break;
rlm@1 79 }
rlm@1 80 debuggerWriteHalfWord(0x9fe20fc, get);
rlm@1 81 }
rlm@1 82