debug.c 1.4 KB

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