rename expr.cpp.h to expr.c.h
[rofl0r-VisualBoyAdvance.git] / src / agbprint.c
blob301c67188444a73a51057f607a21b90894484140
1 // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
2 // Copyright (C) 1999-2003 Forgotten
3 // Copyright (C) 2004 Forgotten and the VBA development team
5 // This program is free software; you can redistribute it and/or modify
6 // it under the terms of the GNU General Public License as published by
7 // the Free Software Foundation; either version 2, or(at your option)
8 // any later version.
9 //
10 // This program is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 // GNU General Public License for more details.
15 // You should have received a copy of the GNU General Public License
16 // along with this program; if not, write to the Free Software Foundation,
17 // Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
19 #include <stdio.h>
20 #include <string.h>
22 #include "GBA.h"
23 #include "Globals.h"
24 #include "Port.h"
26 #define debuggerWriteHalfWord(addr, value) \
27 WRITE16LE((u16*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask], (value))
29 #define debuggerReadHalfWord(addr) \
30 READ16LE(((u16*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
32 static bool agbPrintEnabled = false;
33 static bool agbPrintProtect = false;
35 bool agbPrintWrite(u32 address, u16 value)
37 if(agbPrintEnabled) {
38 if(address == 0x9fe2ffe) { // protect
39 agbPrintProtect = (value != 0);
40 debuggerWriteHalfWord(address, value);
41 return true;
42 } else {
43 if(agbPrintProtect &&
44 ((address >= 0x9fe20f8 && address <= 0x9fe20ff) // control structure
45 || (address >= 0x8fd0000 && address <= 0x8fdffff)
46 || (address >= 0x9fd0000 && address <= 0x9fdffff))) {
47 debuggerWriteHalfWord(address, value);
48 return true;
52 return false;
55 void agbPrintReset()
57 agbPrintProtect = false;
60 void agbPrintEnable(bool enable)
62 agbPrintEnabled = enable;
65 bool agbPrintIsEnabled()
67 return agbPrintEnabled;
70 extern void (*dbgOutput)(char *, u32);
72 void agbPrintFlush()
74 u16 get = debuggerReadHalfWord(0x9fe20fc);
75 u16 put = debuggerReadHalfWord(0x9fe20fe);
77 u32 address = (debuggerReadHalfWord(0x9fe20fa) << 16);
78 if(address != 0xfd0000 && address != 0x1fd0000) {
79 dbgOutput("Did you forget to call AGBPrintInit?\n", 0);
80 // get rid of the text otherwise we will continue to be called
81 debuggerWriteHalfWord(0x9fe20fc, put);
82 return;
85 u8 *data = &rom[address];
87 while(get != put) {
88 char c = data[get++];
89 char s[2];
90 s[0] = c;
91 s[1] = 0;
93 if(systemVerbose & VERBOSE_AGBPRINT)
94 dbgOutput(s, 0);
95 if(c == '\n')
96 break;
98 debuggerWriteHalfWord(0x9fe20fc, get);