Advertisement
uaa

parrot_code.c double-buffering edition (for test)

uaa
Aug 12th, 2021
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.20 KB | None | 0 0
  1. // CC-BY-SA
  2. // original code: SASANO Takayoshi
  3.  
  4. #include <msx/gfx.h>
  5.  
  6. extern const unsigned char *parrot_data[];
  7. extern const unsigned char parrot_palette[];
  8.  
  9. #define DATA_SIZE 768
  10. #define PLANE 10
  11.  
  12. #define DELAY 500
  13.  
  14. #define PATTERN_GEN 0x0000 // pattern generator table
  15. #define PATTERN_NAME0 0x1800 // pattern name table #0
  16. #define PATTERN_NAME1 0x1c00 // pattern name table #1
  17. #define COLOR_TABLE 0x2000 // color table
  18.  
  19. #define PALETTE_MAX 16
  20.  
  21. #define VDP_PORT_R 0x0006 // VDP I/O port (read) stored address
  22. #define VDP_PORT_W 0x0007 // VDP I/O port (write) stored address
  23. #define MSX_VERSION 0x002d // MSX-BASIC version stored address
  24. #define NEWKEY 0xfbe5 // keyboard matrix status
  25.  
  26. static void init_screen(void)
  27. {
  28. int i;
  29.  
  30. set_mode(mode_1);
  31. set_color(15, 0, 0);
  32.  
  33. for (i = 0; i < 16; i++) {
  34. fill(PATTERN_GEN + i * 128, 0, 8); // blank pattern
  35. vpoke(COLOR_TABLE + i * 2, i); // color (as background)
  36. }
  37.  
  38. fill(PATTERN_NAME0, 0, DATA_SIZE);
  39. fill(PATTERN_NAME1, 0, DATA_SIZE);
  40. }
  41.  
  42. static void dummy_loop(int ticks)
  43. {
  44. int i;
  45.  
  46. for (i = 0; i < ticks; i++) {
  47. #asm
  48. nop
  49. #endasm
  50. }
  51. }
  52.  
  53. static void set_palette(const unsigned char *palette)
  54. {
  55. int i;
  56. unsigned int port = *(unsigned int *)VDP_PORT_W;
  57.  
  58. #asm
  59. di
  60. #endasm
  61.  
  62. /* set palette index to 0 */
  63. outp(port + 1, 0x00);
  64. outp(port + 1, 0x90);
  65.  
  66. /* send palette data */
  67. for (i = 0; i < PALETTE_MAX; i++) {
  68. outp(port + 2, *palette++);
  69. outp(port + 2, *palette++);
  70. }
  71. #asm
  72. ei
  73. #endasm
  74. }
  75.  
  76. static void do_disp(void)
  77. {
  78. unsigned char i, n;
  79. unsigned int port = *(unsigned int *)VDP_PORT_W;
  80. const unsigned int naddr[] = {PATTERN_NAME0, PATTERN_NAME1};
  81.  
  82. n = 0;
  83. for (i = 0; ; i++) {
  84. // set display page
  85. #asm
  86. di
  87. #endasm
  88. outp(port + 1, naddr[i & 1] >> 10);
  89. outp(port + 1, 0x82);
  90. #asm
  91. ei
  92. #endasm
  93. // fill next page
  94. vwrite(parrot_data[n], naddr[(i + 1) & 1], DATA_SIZE);
  95. dummy_loop(DELAY);
  96.  
  97. if (++n >= PLANE)
  98. n = 0;
  99. }
  100. }
  101.  
  102. int main(int argc, char *argv[])
  103. {
  104. init_screen();
  105.  
  106. /* MSX1 or press "1"; no palette setting */
  107. if ((*((unsigned char *)NEWKEY) & 2) && *((unsigned char *)MSX_VERSION))
  108. set_palette(parrot_palette);
  109.  
  110. do_disp();
  111.  
  112. /* NOTREACHED */
  113. return 0;
  114. }
  115.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement