debug.c 3.0 KB

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