debug.c 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186
  1. #include <string.h>
  2. #include <stdarg.h>
  3. #include <stdio.h>
  4. #include <fcntl.h>
  5. #include "debug.h"
  6. #include "data.h"
  7. #include "pad.h"
  8. #include "PPU.h"
  9. #include "ressource.h"
  10. word debugMap[0x400];
  11. static char debug_buffer[512];
  12. static char screen_buffer[512];
  13. void debug_init(void) {
  14. word i;
  15. for(i=0; i<0x400; i++) {
  16. debugMap[i] = 0x00;
  17. }
  18. memset(debug_buffer,0,255);
  19. }
  20. void debug_enable(void){
  21. VRAMLoad((word) debugFont_pic, 0x5000, 2048);
  22. VRAMLoad((word) debugMap, 0x4000, 0x0800);
  23. setTileMapLocation(0x4000, (byte) 0x00, (byte) 0);
  24. setCharacterLocation(0x5000, (byte) 0);
  25. *(byte*) 0x2100 = 0x0f; // enable background
  26. // hex(24 << 10 | 24 << 5 | 24 )
  27. // '0x6318'
  28. *(byte*) 0x2121 = 0x00;
  29. *(byte*) 0x2122 = 0x18;
  30. *(byte*) 0x2122 = 0x63;
  31. }
  32. void clears(void) {
  33. word i,y;
  34. for(y=0; y<20; y++){
  35. waitForVBlank();
  36. for(i=0; i<32; i++){
  37. *(byte*)0x2115 = 0x80;
  38. *(word*)0x2116 = 0x4000+i+(y*0x20);
  39. *(byte*)0x2118 = 0;
  40. }
  41. }
  42. }
  43. void _print_char(word y,word x, char c){
  44. waitForVBlank();
  45. VRAMByteWrite((byte) (c-32), (word) (0x4000+x+(y*0x20)));
  46. }
  47. void _print_screen(word y, char *buffer){
  48. char l;
  49. char x = 0;
  50. l = strlen(buffer);
  51. waitForVBlank();
  52. while(*buffer){
  53. if (*buffer == '\n' ) {
  54. while(x++<32){
  55. *(byte*)0x2115 = 0x80;
  56. *(word*)0x2116 = 0x4000+x+(y*0x20);
  57. *(byte*)0x2118 = 0;
  58. }
  59. x = 0;
  60. y++;
  61. buffer++;
  62. waitForVBlank();
  63. continue;
  64. }
  65. *(byte*)0x2115 = 0x80;
  66. *(word*)0x2116 = 0x4000+x+(y*0x20);
  67. *(byte*)0x2118 = *buffer-32;
  68. x++;
  69. buffer++;
  70. //waitForVBlank();
  71. }
  72. }
  73. void _print_console(const char *buffer){
  74. while(*buffer)
  75. *(byte*) 0x3000=*buffer++;
  76. }
  77. void printfc(const char *fmt,...){
  78. va_list ap;
  79. va_start(ap,fmt);
  80. vsprintf(debug_buffer,fmt,ap);
  81. va_end(ap);
  82. _print_console(debug_buffer);
  83. //memset(debug_buffer,0,255);
  84. }
  85. void printfs(word y,const char *fmt,...){
  86. va_list ap;
  87. va_start(ap,fmt);
  88. vsprintf(screen_buffer,fmt,ap);
  89. va_end(ap);
  90. _print_screen(y,screen_buffer);
  91. memset(screen_buffer,0,255);
  92. }
  93. void printc_packet(unsigned long addr,unsigned int len,byte *packet){
  94. unsigned int i,j;
  95. unsigned int sum = 0;
  96. unsigned int clear=0;
  97. for (i=0;i<len;i+=16) {
  98. sum = 0;
  99. for (j=0;j<16;j++) {
  100. sum +=packet[i+j];
  101. }
  102. if (!sum){
  103. clear=1;
  104. continue;
  105. }
  106. if (clear){
  107. printfc("*\n");
  108. clear = 0;
  109. }
  110. printfc("%lx:", addr + i);
  111. for (j=0;j<16;j++) {
  112. printfc(" %x", packet[i+j]);
  113. }
  114. printfc(" |");
  115. for (j=0;j<16;j++) {
  116. if (packet[i+j]>=33 && packet[i+j]<=126 )
  117. printfc("%c", packet[i+j]);
  118. else
  119. printfc(".");
  120. }
  121. printfc("|\n");
  122. }
  123. }
  124. /* keep the linker happy */
  125. int open(const char * _name, int _mode){
  126. _print_console("open called\n");
  127. return -1;
  128. }
  129. int close(int fd){
  130. _print_console("close called\n");
  131. return -1;
  132. }
  133. size_t read(int fd, void * buff, size_t len){
  134. _print_console("read called\n");
  135. return 0;
  136. }
  137. size_t write(int fd, void * buffer, size_t len){
  138. _print_console("write called\n");
  139. return 0;
  140. }
  141. long lseek(int fd, long off, int count){
  142. _print_console("lseek called\n");
  143. return 0;
  144. }
  145. int unlink(const char * name){
  146. _print_console("unlink called\n");
  147. return -1;
  148. }
  149. int isatty(){
  150. _print_console("isatty called\n");
  151. return 1;
  152. }