home *** CD-ROM | disk | FTP | other *** search
/ Chip 2004 July / CMCD0704.ISO / Software / Freeware / Utilitare / VisualBoyAdvance-1.7.2 / src / agbprint.cpp < prev    next >
Encoding:
C/C++ Source or Header  |  2004-05-13  |  2.7 KB  |  100 lines

  1. // VisualBoyAdvance - Nintendo Gameboy/GameboyAdvance (TM) emulator.
  2. // Copyright (C) 1999-2003 Forgotten
  3. // Copyright (C) 2004 Forgotten and the VBA development team
  4.  
  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.
  14. //
  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.
  18.  
  19. #include <stdio.h>
  20. #include <string.h>
  21.  
  22. #include "GBA.h"
  23. #include "Globals.h"
  24. #include "Port.h"
  25.  
  26. #define debuggerWriteHalfWord(addr, value) \
  27.   WRITE16LE((u16*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask], (value))
  28.  
  29. #define debuggerReadHalfWord(addr) \
  30.   READ16LE(((u16*)&map[(addr)>>24].address[(addr) & map[(addr)>>24].mask]))
  31.  
  32. static bool agbPrintEnabled = false;
  33. static bool agbPrintProtect = false;
  34.  
  35. bool agbPrintWrite(u32 address, u16 value)
  36. {
  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;
  49.       }
  50.     }
  51.   }
  52.   return false;
  53. }
  54.  
  55. void agbPrintReset()
  56. {
  57.   agbPrintProtect = false;
  58. }
  59.  
  60. void agbPrintEnable(bool enable)
  61. {
  62.   agbPrintEnabled = enable;
  63. }
  64.  
  65. bool agbPrintIsEnabled()
  66. {
  67.   return agbPrintEnabled;
  68. }
  69.  
  70. extern void (*dbgOutput)(char *, u32);
  71.  
  72. void agbPrintFlush()
  73. {
  74.   u16 get = debuggerReadHalfWord(0x9fe20fc);
  75.   u16 put = debuggerReadHalfWord(0x9fe20fe);
  76.  
  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;
  83.   }
  84.  
  85.   u8 *data = &rom[address];
  86.  
  87.   while(get != put) {
  88.     char c = data[get++];
  89.     char s[2];
  90.     s[0] = c;
  91.     s[1] = 0;
  92.  
  93.     if(systemVerbose & VERBOSE_AGBPRINT)
  94.       dbgOutput(s, 0);
  95.     if(c == '\n')
  96.       break;
  97.   }
  98.   debuggerWriteHalfWord(0x9fe20fc, get);
  99. }
  100.