debug.c 1.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051
  1. #include "data.h"
  2. #include "pad.h"
  3. #include "PPU.h"
  4. #include "ressource.h"
  5. word debugMap[0x400];
  6. void initDebugMap(void) {
  7. word i;
  8. for(i=0; i<0x400; i++) {
  9. debugMap[i] = 0x00;
  10. }
  11. }
  12. char hex_chars[] = {'0', '1', '2', '3', '4', '5', '6', '7', '8', '9', 'A', 'B', 'C', 'D', 'E', 'F'};
  13. void int2hex(unsigned long number, char *buf,word size)
  14. {
  15. unsigned long n;
  16. unsigned char i;
  17. //unsigned char x;
  18. for (i = 0; i < size; i++) {
  19. n = number >> 4;
  20. //x = (number - (n << 4));
  21. buf[size-i-1] = hex_chars[(number - (n << 4))];
  22. number = n;
  23. }
  24. }
  25. void printDebugScreen(char *buffer,word y){
  26. char i;
  27. waitForVBlank();
  28. for(i=0; i<32; i++) {
  29. waitForVBlank();
  30. VRAMByteWrite((byte) (buffer[i]-32), (word) (0x4000+i+(y*0x20)));
  31. }
  32. }
  33. void printf(char *buffer){
  34. while(*buffer)
  35. *(byte*) 0x3000=*buffer++;
  36. }
  37. void enableDebugScreen(void){
  38. VRAMLoad((word) debugFont_pic, 0x5000, 2048);
  39. CGRAMLoad((word) debugFont_pal, (byte) 0x00, (word) 16);
  40. VRAMLoad((word) debugMap, 0x4000, 0x0800);
  41. setTileMapLocation(0x4000, (byte) 0x00, (byte) 0);
  42. setCharacterLocation(0x5000, (byte) 0);
  43. *(byte*) 0x2100 = 0x0f; // enable background
  44. }