Mercurial > vba-linux
comparison 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 |
comparison
equal
deleted
inserted
replaced
0:8ced16adf2e1 | 1:f9f4f1b99eed |
---|---|
1 #include <cstdio> | |
2 #include <cstring> | |
3 | |
4 #include "GBAGlobals.h" | |
5 | |
6 extern void (*dbgOutput)(char *, u32); | |
7 extern int systemVerbose; | |
8 | |
9 static bool agbPrintEnabled = false; | |
10 static bool agbPrintProtect = false; | |
11 | |
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 } | |
36 | |
37 void agbPrintReset() | |
38 { | |
39 agbPrintProtect = false; | |
40 } | |
41 | |
42 void agbPrintEnable(bool enable) | |
43 { | |
44 agbPrintEnabled = enable; | |
45 } | |
46 | |
47 bool agbPrintIsEnabled() | |
48 { | |
49 return agbPrintEnabled; | |
50 } | |
51 | |
52 void agbPrintFlush() | |
53 { | |
54 u16 get = debuggerReadHalfWord(0x9fe20fc); | |
55 u16 put = debuggerReadHalfWord(0x9fe20fe); | |
56 | |
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 } | |
65 | |
66 u8 *data = &rom[address]; | |
67 | |
68 while (get != put) | |
69 { | |
70 char c = data[get++]; | |
71 char s[2]; | |
72 s[0] = c; | |
73 s[1] = 0; | |
74 | |
75 if (systemVerbose & VERBOSE_AGBPRINT) | |
76 dbgOutput(s, 0); | |
77 if (c == '\n') | |
78 break; | |
79 } | |
80 debuggerWriteHalfWord(0x9fe20fc, get); | |
81 } | |
82 |