TESTIMG.C 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183
  1. // Test image generator for more advanced color tests
  2. #define word char
  3. #include "LIB/MATH.C"
  4. #include "LIB/STDLIB.C"
  5. #include "LIB/SYS.C"
  6. #include "LIB/GFX.C"
  7. #include "DATA/TESTIMGD.C"
  8. #define DATA_OFFSET 3
  9. void testCard()
  10. {
  11. GFX_initVram(); // clear all VRAM
  12. GFX_copyPaletteTable((word)DATA_PALETTE_COLOR);
  13. GFX_copyPatternTable((word)DATA_PATTERN_COLOR);
  14. word y;
  15. for (y = 0; y < 25; y++)
  16. {
  17. GFX_printWindowColored(((word)tileColor0) + DATA_OFFSET, 5, GFX_WindowPosFromXY(0, y), 1);
  18. GFX_printWindowColored(((word)tileColor1) + DATA_OFFSET, 5, GFX_WindowPosFromXY(5, y), 1);
  19. GFX_printWindowColored(((word)tileColor2) + DATA_OFFSET, 5, GFX_WindowPosFromXY(10, y), 1);
  20. GFX_printWindowColored(((word)tileColor3) + DATA_OFFSET, 5, GFX_WindowPosFromXY(15, y), 1);
  21. GFX_printWindowColored(((word)tileColor0) + DATA_OFFSET, 5, GFX_WindowPosFromXY(20, y), 2);
  22. GFX_printWindowColored(((word)tileColor1) + DATA_OFFSET, 5, GFX_WindowPosFromXY(25, y), 2);
  23. GFX_printWindowColored(((word)tileColor2) + DATA_OFFSET, 5, GFX_WindowPosFromXY(30, y), 2);
  24. GFX_printWindowColored(((word)tileColor3) + DATA_OFFSET, 5, GFX_WindowPosFromXY(35, y), 2);
  25. }
  26. }
  27. void writePattern()
  28. {
  29. asm(
  30. "; backup registers\n"
  31. "push r1\n"
  32. "push r2\n"
  33. "push r3\n"
  34. "push r4\n"
  35. "push r5\n"
  36. "push r6\n"
  37. "push r7\n"
  38. "; 128 tiles in Window layer to id 252-255\n"
  39. "; vram address\n"
  40. "load32 0xC01420 r1 ; vram addr 1056+2048 0xC01420\n"
  41. "add r1 412 r1 ; add starting offset\n"
  42. "; loop variables\n"
  43. "load 0 r3 ; loopvar\n"
  44. "load 128 r4 ; loopmax\n"
  45. "or r1 r0 r5 ; vram addr with offset\n"
  46. "load 252 r1 ; initial tile ID\n"
  47. "load 0 r2 ; counter for next line\n"
  48. "load 15 r6 ; compare for next line (-1)\n"
  49. "; loop\n"
  50. "Test_colors_write_tile_id_loop:\n"
  51. "write 0 r5 r1 ; set tile\n"
  52. "; check if tile id is 255, then set back to 252, else increase by one\n"
  53. "load 255 r7\n"
  54. "bne r7 r1 2\n"
  55. "load 252 r1\n"
  56. "add r1 1 r1\n"
  57. "shiftr r3 2 r7 ; only increase color id every 4 tiles\n"
  58. "write 2048 r5 r7 ; set color (2048 offset, 0x800 in hex)\n"
  59. "; if drawn 16 tiles on this line\n"
  60. "bne r2 r6 4\n"
  61. "add r5 25 r5\n"
  62. "load 0 r2\n"
  63. "jumpo 3 ; skip the other clause\n"
  64. "; else\n"
  65. "add r2 1 r2\n"
  66. "add r5 1 r5 ; incr vram address\n"
  67. "add r3 1 r3 ; incr counter\n"
  68. "beq r3 r4 2 ; keep looping until all tiles are set\n"
  69. "jump Test_colors_write_tile_id_loop\n"
  70. "; restore registers\n"
  71. "pop r7\n"
  72. "pop r6\n"
  73. "pop r5\n"
  74. "pop r4\n"
  75. "pop r3\n"
  76. "pop r2\n"
  77. "pop r1\n"
  78. );
  79. }
  80. void testPalette1()
  81. {
  82. GFX_initVram(); // clear all VRAM
  83. GFX_copyPaletteTable((word)TEST_COLOR_PALETTETABLE_1);
  84. GFX_copyPatternTable((word)DATA_ASCII_DEFAULT);
  85. writePattern();
  86. }
  87. void testPalette2()
  88. {
  89. GFX_initVram(); // clear all VRAM
  90. GFX_copyPaletteTable((word)TEST_COLOR_PALETTETABLE_2);
  91. GFX_copyPatternTable((word)DATA_ASCII_DEFAULT);
  92. writePattern();
  93. }
  94. int main()
  95. {
  96. GFX_clearConsole();
  97. GFX_PrintConsole("Image test tool\n");
  98. GFX_PrintConsole("Press one of the following keys:\n");
  99. GFX_PrintConsole("q: quit\n");
  100. GFX_PrintConsole("1: test card\n");
  101. GFX_PrintConsole("2: color palette 1/2\n");
  102. GFX_PrintConsole("3: color palette 2/2\n");
  103. while (1)
  104. {
  105. if (HID_FifoAvailable())
  106. {
  107. word c = HID_FifoRead();
  108. if (c == 'q') // escape
  109. {
  110. return 'q';
  111. }
  112. if (c == '1')
  113. {
  114. testCard();
  115. }
  116. if (c == '2')
  117. {
  118. testPalette1();
  119. }
  120. if (c == '3')
  121. {
  122. testPalette2();
  123. }
  124. }
  125. }
  126. return 'q';
  127. }
  128. void interrupt()
  129. {
  130. // handle all interrupts
  131. word i = getIntID();
  132. switch(i)
  133. {
  134. case INTID_TIMER1:
  135. timer1Value = 1; // notify ending of timer1
  136. break;
  137. case INTID_TIMER2:
  138. break;
  139. case INTID_UART0:
  140. break;
  141. case INTID_GPU:
  142. break;
  143. case INTID_TIMER3:
  144. break;
  145. case INTID_PS2:
  146. break;
  147. case INTID_UART1:
  148. break;
  149. case INTID_UART2:
  150. break;
  151. }
  152. }