view src/gba/agbprint.cpp @ 296:659a9c84c785

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