render_gx.c 30 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973
  1. /* MegaZeux
  2. *
  3. * Copyright (C) 2008 Alan Williams <mralert@gmail.com>
  4. * Copyright (C) 2018 Alice Rowan <petrifiedrowan@gmail.com>
  5. *
  6. * This program is free software; you can redistribute it and/or
  7. * modify it under the terms of the GNU General Public License as
  8. * published by the Free Software Foundation; either version 2 of
  9. * the License, or (at your option) any later version.
  10. *
  11. * This program is distributed in the hope that it will be useful,
  12. * but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
  14. * General Public License for more details.
  15. *
  16. * You should have received a copy of the GNU General Public License
  17. * along with this program; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #include "../../src/graphics.h"
  21. #include "../../src/platform.h"
  22. #include "../../src/render.h"
  23. #include "../../src/renderers.h"
  24. #include <stdlib.h>
  25. #include <string.h>
  26. #include <malloc.h>
  27. #define BOOL _BOOL
  28. #include <ogc/system.h>
  29. #include <ogc/conf.h>
  30. #include <ogc/cache.h>
  31. #include <ogc/video.h>
  32. #include <ogc/gx.h>
  33. #include <ogc/gu.h>
  34. #undef BOOL
  35. #define DEFAULT_FIFO_SIZE (1024 * 1024)
  36. #define TEX_SCALE_W 1024
  37. #define TEX_SCALE_H 512
  38. #define SCALE_TEX_SIZE (sizeof(u32) * TEX_SCALE_W * TEX_SCALE_H)
  39. #define SCALE_TEX_X0 (0.0 / TEX_SCALE_W)
  40. #define SCALE_TEX_Y0 (1.0 / TEX_SCALE_H)
  41. #define SCALE_TEX_X1 (640.0 / TEX_SCALE_W)
  42. #define SCALE_TEX_Y1 (351.0 / TEX_SCALE_H)
  43. /**
  44. * Char packing format (I4)
  45. *
  46. * 1) Two versions of each char are stored in the texture (MZX and SMZX).
  47. * 2) Chars are packed into 8x8 tiles, meaning they need to be split into
  48. * two tiles when drawn to the charset texture. This also means that in
  49. * this texture they occupy 8x16 pixels rather than the usual 8x14 pixels.
  50. */
  51. #define CHAR_VARIANTS 2
  52. #define CHAR_VAR_W (CHAR_VARIANTS * 8)
  53. #define CHAR_VAR_H 16
  54. #define SMZX_OFFSET CHAR_W
  55. #define CHARSET_COLS 64
  56. #define CHARSET_ROWS (FULL_CHARSET_SIZE / CHARSET_COLS)
  57. #define TEX_DATA_W (CHARSET_COLS * CHAR_VAR_W)
  58. #define TEX_DATA_H (CHARSET_ROWS * CHAR_VAR_H)
  59. #define TEX_DATA_W_F (TEX_DATA_W * 1.0f)
  60. #define TEX_DATA_H_F (TEX_DATA_H * 1.0f)
  61. #define TEX_DATA_SIZE \
  62. (sizeof(u32) * CHAR_VAR_H * CHAR_VARIANTS * FULL_CHARSET_SIZE)
  63. // (likely wasteful) tlut breakdown:
  64. #define TLUT_MZX_OFFSET (256 * 0) // Standard MZX
  65. #define TLUT_SMZX_OFFSET (256 * 1) // SMZX (separate because of SMZX_MESSAGE)
  66. #define TLUT_T0_OFFSET (256 * 2) // MZX/UI/SMZX tcol is idx 0
  67. #define TLUT_T1_OFFSET (256 * 3) // MZX/UI/SMZX tcol is idx 1
  68. #define TLUT_T2_OFFSET (256 * 4) // SMZX tcol is idx 2 / MZX fg + UI bg
  69. #define TLUT_T3_OFFSET (256 * 5) // SMZX tcol is idx 3 / MZX bg + UI fg
  70. #define TLUT_UI_OFFSET (256 * 6) // UI
  71. #define NUM_TLUT (256 * 7)
  72. // RGB5A3 transparent color for layer rendering.
  73. #define NO_COLOR 0x0000
  74. // Must be multiple of 32 bytes
  75. struct ci4tlut
  76. {
  77. u16 pal[16];
  78. };
  79. struct gx_render_data
  80. {
  81. void *xfb[2];
  82. void *fifo;
  83. GXRModeObj *rmode;
  84. struct ci4tlut *mzxtlut;
  85. void *charimg;
  86. void *scaleimg;
  87. GXTlutObj mzxtlutobj[NUM_TLUT];
  88. GXTexObj chartex;
  89. GXTexObj scaletex;
  90. GXColor palette[FULL_PAL_SIZE];
  91. u16 tlutpal[FULL_PAL_SIZE];
  92. u8 chrdirty[FULL_CHARSET_SIZE];
  93. int chrdirty_all;
  94. int chrdirty_set;
  95. int paldirty;
  96. boolean invalidate;
  97. int current_xfb;
  98. s16 sx0, sy0, sx1, sy1;
  99. };
  100. // Lookup table for generating CI4 charset textures
  101. static u32 mzxtexline[256] =
  102. {
  103. 0x00000000, 0x0000000F, 0x000000F0, 0x000000FF,
  104. 0x00000F00, 0x00000F0F, 0x00000FF0, 0x00000FFF,
  105. 0x0000F000, 0x0000F00F, 0x0000F0F0, 0x0000F0FF,
  106. 0x0000FF00, 0x0000FF0F, 0x0000FFF0, 0x0000FFFF,
  107. 0x000F0000, 0x000F000F, 0x000F00F0, 0x000F00FF,
  108. 0x000F0F00, 0x000F0F0F, 0x000F0FF0, 0x000F0FFF,
  109. 0x000FF000, 0x000FF00F, 0x000FF0F0, 0x000FF0FF,
  110. 0x000FFF00, 0x000FFF0F, 0x000FFFF0, 0x000FFFFF,
  111. 0x00F00000, 0x00F0000F, 0x00F000F0, 0x00F000FF,
  112. 0x00F00F00, 0x00F00F0F, 0x00F00FF0, 0x00F00FFF,
  113. 0x00F0F000, 0x00F0F00F, 0x00F0F0F0, 0x00F0F0FF,
  114. 0x00F0FF00, 0x00F0FF0F, 0x00F0FFF0, 0x00F0FFFF,
  115. 0x00FF0000, 0x00FF000F, 0x00FF00F0, 0x00FF00FF,
  116. 0x00FF0F00, 0x00FF0F0F, 0x00FF0FF0, 0x00FF0FFF,
  117. 0x00FFF000, 0x00FFF00F, 0x00FFF0F0, 0x00FFF0FF,
  118. 0x00FFFF00, 0x00FFFF0F, 0x00FFFFF0, 0x00FFFFFF,
  119. 0x0F000000, 0x0F00000F, 0x0F0000F0, 0x0F0000FF,
  120. 0x0F000F00, 0x0F000F0F, 0x0F000FF0, 0x0F000FFF,
  121. 0x0F00F000, 0x0F00F00F, 0x0F00F0F0, 0x0F00F0FF,
  122. 0x0F00FF00, 0x0F00FF0F, 0x0F00FFF0, 0x0F00FFFF,
  123. 0x0F0F0000, 0x0F0F000F, 0x0F0F00F0, 0x0F0F00FF,
  124. 0x0F0F0F00, 0x0F0F0F0F, 0x0F0F0FF0, 0x0F0F0FFF,
  125. 0x0F0FF000, 0x0F0FF00F, 0x0F0FF0F0, 0x0F0FF0FF,
  126. 0x0F0FFF00, 0x0F0FFF0F, 0x0F0FFFF0, 0x0F0FFFFF,
  127. 0x0FF00000, 0x0FF0000F, 0x0FF000F0, 0x0FF000FF,
  128. 0x0FF00F00, 0x0FF00F0F, 0x0FF00FF0, 0x0FF00FFF,
  129. 0x0FF0F000, 0x0FF0F00F, 0x0FF0F0F0, 0x0FF0F0FF,
  130. 0x0FF0FF00, 0x0FF0FF0F, 0x0FF0FFF0, 0x0FF0FFFF,
  131. 0x0FFF0000, 0x0FFF000F, 0x0FFF00F0, 0x0FFF00FF,
  132. 0x0FFF0F00, 0x0FFF0F0F, 0x0FFF0FF0, 0x0FFF0FFF,
  133. 0x0FFFF000, 0x0FFFF00F, 0x0FFFF0F0, 0x0FFFF0FF,
  134. 0x0FFFFF00, 0x0FFFFF0F, 0x0FFFFFF0, 0x0FFFFFFF,
  135. 0xF0000000, 0xF000000F, 0xF00000F0, 0xF00000FF,
  136. 0xF0000F00, 0xF0000F0F, 0xF0000FF0, 0xF0000FFF,
  137. 0xF000F000, 0xF000F00F, 0xF000F0F0, 0xF000F0FF,
  138. 0xF000FF00, 0xF000FF0F, 0xF000FFF0, 0xF000FFFF,
  139. 0xF00F0000, 0xF00F000F, 0xF00F00F0, 0xF00F00FF,
  140. 0xF00F0F00, 0xF00F0F0F, 0xF00F0FF0, 0xF00F0FFF,
  141. 0xF00FF000, 0xF00FF00F, 0xF00FF0F0, 0xF00FF0FF,
  142. 0xF00FFF00, 0xF00FFF0F, 0xF00FFFF0, 0xF00FFFFF,
  143. 0xF0F00000, 0xF0F0000F, 0xF0F000F0, 0xF0F000FF,
  144. 0xF0F00F00, 0xF0F00F0F, 0xF0F00FF0, 0xF0F00FFF,
  145. 0xF0F0F000, 0xF0F0F00F, 0xF0F0F0F0, 0xF0F0F0FF,
  146. 0xF0F0FF00, 0xF0F0FF0F, 0xF0F0FFF0, 0xF0F0FFFF,
  147. 0xF0FF0000, 0xF0FF000F, 0xF0FF00F0, 0xF0FF00FF,
  148. 0xF0FF0F00, 0xF0FF0F0F, 0xF0FF0FF0, 0xF0FF0FFF,
  149. 0xF0FFF000, 0xF0FFF00F, 0xF0FFF0F0, 0xF0FFF0FF,
  150. 0xF0FFFF00, 0xF0FFFF0F, 0xF0FFFFF0, 0xF0FFFFFF,
  151. 0xFF000000, 0xFF00000F, 0xFF0000F0, 0xFF0000FF,
  152. 0xFF000F00, 0xFF000F0F, 0xFF000FF0, 0xFF000FFF,
  153. 0xFF00F000, 0xFF00F00F, 0xFF00F0F0, 0xFF00F0FF,
  154. 0xFF00FF00, 0xFF00FF0F, 0xFF00FFF0, 0xFF00FFFF,
  155. 0xFF0F0000, 0xFF0F000F, 0xFF0F00F0, 0xFF0F00FF,
  156. 0xFF0F0F00, 0xFF0F0F0F, 0xFF0F0FF0, 0xFF0F0FFF,
  157. 0xFF0FF000, 0xFF0FF00F, 0xFF0FF0F0, 0xFF0FF0FF,
  158. 0xFF0FFF00, 0xFF0FFF0F, 0xFF0FFFF0, 0xFF0FFFFF,
  159. 0xFFF00000, 0xFFF0000F, 0xFFF000F0, 0xFFF000FF,
  160. 0xFFF00F00, 0xFFF00F0F, 0xFFF00FF0, 0xFFF00FFF,
  161. 0xFFF0F000, 0xFFF0F00F, 0xFFF0F0F0, 0xFFF0F0FF,
  162. 0xFFF0FF00, 0xFFF0FF0F, 0xFFF0FFF0, 0xFFF0FFFF,
  163. 0xFFFF0000, 0xFFFF000F, 0xFFFF00F0, 0xFFFF00FF,
  164. 0xFFFF0F00, 0xFFFF0F0F, 0xFFFF0FF0, 0xFFFF0FFF,
  165. 0xFFFFF000, 0xFFFFF00F, 0xFFFFF0F0, 0xFFFFF0FF,
  166. 0xFFFFFF00, 0xFFFFFF0F, 0xFFFFFFF0, 0xFFFFFFFF
  167. };
  168. // Lookup table for generating CI4 SMZX charset textures
  169. static u32 smzxtexline[256] =
  170. {
  171. 0x00000000, 0x00000055, 0x000000AA, 0x000000FF,
  172. 0x00005500, 0x00005555, 0x000055AA, 0x000055FF,
  173. 0x0000AA00, 0x0000AA55, 0x0000AAAA, 0x0000AAFF,
  174. 0x0000FF00, 0x0000FF55, 0x0000FFAA, 0x0000FFFF,
  175. 0x00550000, 0x00550055, 0x005500AA, 0x005500FF,
  176. 0x00555500, 0x00555555, 0x005555AA, 0x005555FF,
  177. 0x0055AA00, 0x0055AA55, 0x0055AAAA, 0x0055AAFF,
  178. 0x0055FF00, 0x0055FF55, 0x0055FFAA, 0x0055FFFF,
  179. 0x00AA0000, 0x00AA0055, 0x00AA00AA, 0x00AA00FF,
  180. 0x00AA5500, 0x00AA5555, 0x00AA55AA, 0x00AA55FF,
  181. 0x00AAAA00, 0x00AAAA55, 0x00AAAAAA, 0x00AAAAFF,
  182. 0x00AAFF00, 0x00AAFF55, 0x00AAFFAA, 0x00AAFFFF,
  183. 0x00FF0000, 0x00FF0055, 0x00FF00AA, 0x00FF00FF,
  184. 0x00FF5500, 0x00FF5555, 0x00FF55AA, 0x00FF55FF,
  185. 0x00FFAA00, 0x00FFAA55, 0x00FFAAAA, 0x00FFAAFF,
  186. 0x00FFFF00, 0x00FFFF55, 0x00FFFFAA, 0x00FFFFFF,
  187. 0x55000000, 0x55000055, 0x550000AA, 0x550000FF,
  188. 0x55005500, 0x55005555, 0x550055AA, 0x550055FF,
  189. 0x5500AA00, 0x5500AA55, 0x5500AAAA, 0x5500AAFF,
  190. 0x5500FF00, 0x5500FF55, 0x5500FFAA, 0x5500FFFF,
  191. 0x55550000, 0x55550055, 0x555500AA, 0x555500FF,
  192. 0x55555500, 0x55555555, 0x555555AA, 0x555555FF,
  193. 0x5555AA00, 0x5555AA55, 0x5555AAAA, 0x5555AAFF,
  194. 0x5555FF00, 0x5555FF55, 0x5555FFAA, 0x5555FFFF,
  195. 0x55AA0000, 0x55AA0055, 0x55AA00AA, 0x55AA00FF,
  196. 0x55AA5500, 0x55AA5555, 0x55AA55AA, 0x55AA55FF,
  197. 0x55AAAA00, 0x55AAAA55, 0x55AAAAAA, 0x55AAAAFF,
  198. 0x55AAFF00, 0x55AAFF55, 0x55AAFFAA, 0x55AAFFFF,
  199. 0x55FF0000, 0x55FF0055, 0x55FF00AA, 0x55FF00FF,
  200. 0x55FF5500, 0x55FF5555, 0x55FF55AA, 0x55FF55FF,
  201. 0x55FFAA00, 0x55FFAA55, 0x55FFAAAA, 0x55FFAAFF,
  202. 0x55FFFF00, 0x55FFFF55, 0x55FFFFAA, 0x55FFFFFF,
  203. 0xAA000000, 0xAA000055, 0xAA0000AA, 0xAA0000FF,
  204. 0xAA005500, 0xAA005555, 0xAA0055AA, 0xAA0055FF,
  205. 0xAA00AA00, 0xAA00AA55, 0xAA00AAAA, 0xAA00AAFF,
  206. 0xAA00FF00, 0xAA00FF55, 0xAA00FFAA, 0xAA00FFFF,
  207. 0xAA550000, 0xAA550055, 0xAA5500AA, 0xAA5500FF,
  208. 0xAA555500, 0xAA555555, 0xAA5555AA, 0xAA5555FF,
  209. 0xAA55AA00, 0xAA55AA55, 0xAA55AAAA, 0xAA55AAFF,
  210. 0xAA55FF00, 0xAA55FF55, 0xAA55FFAA, 0xAA55FFFF,
  211. 0xAAAA0000, 0xAAAA0055, 0xAAAA00AA, 0xAAAA00FF,
  212. 0xAAAA5500, 0xAAAA5555, 0xAAAA55AA, 0xAAAA55FF,
  213. 0xAAAAAA00, 0xAAAAAA55, 0xAAAAAAAA, 0xAAAAAAFF,
  214. 0xAAAAFF00, 0xAAAAFF55, 0xAAAAFFAA, 0xAAAAFFFF,
  215. 0xAAFF0000, 0xAAFF0055, 0xAAFF00AA, 0xAAFF00FF,
  216. 0xAAFF5500, 0xAAFF5555, 0xAAFF55AA, 0xAAFF55FF,
  217. 0xAAFFAA00, 0xAAFFAA55, 0xAAFFAAAA, 0xAAFFAAFF,
  218. 0xAAFFFF00, 0xAAFFFF55, 0xAAFFFFAA, 0xAAFFFFFF,
  219. 0xFF000000, 0xFF000055, 0xFF0000AA, 0xFF0000FF,
  220. 0xFF005500, 0xFF005555, 0xFF0055AA, 0xFF0055FF,
  221. 0xFF00AA00, 0xFF00AA55, 0xFF00AAAA, 0xFF00AAFF,
  222. 0xFF00FF00, 0xFF00FF55, 0xFF00FFAA, 0xFF00FFFF,
  223. 0xFF550000, 0xFF550055, 0xFF5500AA, 0xFF5500FF,
  224. 0xFF555500, 0xFF555555, 0xFF5555AA, 0xFF5555FF,
  225. 0xFF55AA00, 0xFF55AA55, 0xFF55AAAA, 0xFF55AAFF,
  226. 0xFF55FF00, 0xFF55FF55, 0xFF55FFAA, 0xFF55FFFF,
  227. 0xFFAA0000, 0xFFAA0055, 0xFFAA00AA, 0xFFAA00FF,
  228. 0xFFAA5500, 0xFFAA5555, 0xFFAA55AA, 0xFFAA55FF,
  229. 0xFFAAAA00, 0xFFAAAA55, 0xFFAAAAAA, 0xFFAAAAFF,
  230. 0xFFAAFF00, 0xFFAAFF55, 0xFFAAFFAA, 0xFFAAFFFF,
  231. 0xFFFF0000, 0xFFFF0055, 0xFFFF00AA, 0xFFFF00FF,
  232. 0xFFFF5500, 0xFFFF5555, 0xFFFF55AA, 0xFFFF55FF,
  233. 0xFFFFAA00, 0xFFFFAA55, 0xFFFFAAAA, 0xFFFFAAFF,
  234. 0xFFFFFF00, 0xFFFFFF55, 0xFFFFFFAA, 0xFFFFFFFF
  235. };
  236. static boolean gx_init_video(struct graphics_data *graphics,
  237. struct config_info *conf)
  238. {
  239. const GXColor black = {0, 0, 0, 255};
  240. struct gx_render_data *render_data;
  241. f32 yscale;
  242. u32 xfbHeight;
  243. Mtx identmtx;
  244. GXRModeObj *rmode;
  245. Mtx44 projmtx;
  246. u16 sw, sh;
  247. int i;
  248. graphics->resolution_width = 640;
  249. graphics->resolution_height = 350;
  250. graphics->window_width = 640;
  251. graphics->window_height = 350;
  252. render_data = cmalloc(sizeof(struct gx_render_data));
  253. graphics->render_data = render_data;
  254. graphics->ratio = conf->video_ratio;
  255. graphics->gl_vsync = conf->gl_vsync;
  256. VIDEO_Init();
  257. rmode = render_data->rmode = VIDEO_GetPreferredMode(NULL);
  258. render_data->xfb[0] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
  259. render_data->xfb[1] = MEM_K0_TO_K1(SYS_AllocateFramebuffer(rmode));
  260. render_data->current_xfb = 0;
  261. render_data->charimg = memalign(32, TEX_DATA_SIZE);
  262. memset(render_data->charimg, 0, TEX_DATA_SIZE);
  263. render_data->scaleimg = memalign(32, SCALE_TEX_SIZE);
  264. memset(render_data->scaleimg, 0, SCALE_TEX_SIZE);
  265. render_data->mzxtlut = memalign(32, sizeof(struct ci4tlut) * NUM_TLUT);
  266. memset(render_data->mzxtlut, 0, sizeof(struct ci4tlut) * NUM_TLUT);
  267. for(i = 0; i < NUM_TLUT; i++)
  268. GX_InitTlutObj(render_data->mzxtlutobj + i, render_data->mzxtlut + i,
  269. GX_TL_RGB5A3, 16);
  270. GX_InitTexObjCI(&render_data->chartex,
  271. render_data->charimg, TEX_DATA_W, TEX_DATA_H,
  272. GX_TF_CI4, GX_REPEAT, GX_REPEAT, GX_FALSE, GX_TLUT0);
  273. GX_InitTexObjLOD(&render_data->chartex, GX_NEAR, GX_NEAR, 0, 0, 0, GX_FALSE,
  274. GX_TRUE, GX_ANISO_1);
  275. GX_InitTexObj(&render_data->scaletex,
  276. render_data->scaleimg, TEX_SCALE_W, TEX_SCALE_H,
  277. GX_TF_RGBA8, GX_REPEAT, GX_REPEAT, GX_FALSE);
  278. VIDEO_Configure(rmode);
  279. VIDEO_SetNextFramebuffer(render_data->xfb[0]);
  280. VIDEO_SetBlack(FALSE);
  281. VIDEO_Flush();
  282. VIDEO_WaitVSync();
  283. if(rmode->viTVMode & VI_NON_INTERLACE)
  284. VIDEO_WaitVSync();
  285. render_data->fifo = memalign(32, DEFAULT_FIFO_SIZE);
  286. memset(render_data->fifo, 0, DEFAULT_FIFO_SIZE);
  287. GX_Init(render_data->fifo, DEFAULT_FIFO_SIZE);
  288. yscale = GX_GetYScaleFactor(rmode->efbHeight, rmode->xfbHeight);
  289. xfbHeight = GX_SetDispCopyYScale(yscale);
  290. sw = ((rmode->fbWidth > 640) ? rmode->fbWidth : 640);
  291. sh = ((rmode->efbHeight > 352) ? rmode->efbHeight : 352);
  292. GX_SetScissor(0, 0, sw, sh);
  293. GX_SetDispCopySrc(0, 0, rmode->fbWidth, rmode->efbHeight);
  294. GX_SetDispCopyDst(rmode->fbWidth, xfbHeight);
  295. GX_SetCopyFilter(rmode->aa, rmode->sample_pattern, GX_TRUE, rmode->vfilter);
  296. GX_SetFieldMode(rmode->field_rendering,
  297. ((rmode->viHeight == 2 * rmode->xfbHeight) ? GX_ENABLE : GX_DISABLE));
  298. if(rmode->aa)
  299. GX_SetPixelFmt(GX_PF_RGB565_Z16, GX_ZC_LINEAR);
  300. else
  301. GX_SetPixelFmt(GX_PF_RGB8_Z24, GX_ZC_LINEAR);
  302. GX_SetDispCopyGamma(GX_GM_1_0);
  303. GX_SetCopyClear(black, GX_MAX_Z24);
  304. GX_SetTexCopySrc(0, 0, 640, 352);
  305. GX_SetTexCopyDst(1024, 512, GX_TF_RGBA8, GX_FALSE);
  306. GX_ClearVtxDesc();
  307. GX_SetVtxDesc(GX_VA_POS, GX_DIRECT);
  308. GX_SetVtxDesc(GX_VA_TEX0, GX_DIRECT);
  309. GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_POS, GX_POS_XY, GX_S16, 0);
  310. GX_SetVtxAttrFmt(GX_VTXFMT0, GX_VA_TEX0, GX_TEX_ST, GX_F32, 0);
  311. GX_SetNumChans(1);
  312. GX_SetNumTexGens(1);
  313. GX_SetChanCtrl(GX_COLOR0A0, GX_DISABLE, GX_SRC_REG, GX_SRC_REG, GX_LIGHTNULL,
  314. GX_DF_NONE, GX_AF_NONE);
  315. GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
  316. GX_SetTevOrder(GX_TEVSTAGE0, GX_TEXCOORD0, GX_TEXMAP0, GX_COLOR0A0);
  317. GX_SetTexCoordGen(GX_TEXCOORD0, GX_TG_MTX2x4, GX_TG_TEX0, GX_IDENTITY);
  318. guMtxIdentity(identmtx);
  319. GX_LoadPosMtxImm(identmtx, GX_PNMTX0);
  320. GX_SetViewport(0, 0, sw, sh, 0, 1);
  321. GX_SetAlphaUpdate(GX_TRUE);
  322. GX_SetCullMode(GX_CULL_NONE);
  323. GX_CopyDisp(render_data->xfb[1], GX_TRUE);
  324. GX_CopyDisp(render_data->xfb[0], GX_FALSE);
  325. GX_Flush();
  326. render_data->chrdirty_set = 1;
  327. render_data->chrdirty_all = 1;
  328. render_data->paldirty = 1;
  329. guOrtho(projmtx, -1, sh - 1, 0, sw, -1.0, 1.0);
  330. GX_LoadProjectionMtx(projmtx, GX_ORTHOGRAPHIC);
  331. return set_video_mode();
  332. }
  333. static void gx_free_video(struct graphics_data *graphics)
  334. {
  335. free(graphics->render_data);
  336. graphics->render_data = NULL;
  337. }
  338. static boolean gx_check_video_mode(struct graphics_data *graphics,
  339. int width, int height, int depth, boolean fullscreen, boolean resize)
  340. {
  341. return true;
  342. }
  343. static boolean gx_set_video_mode(struct graphics_data *graphics,
  344. int width, int height, int depth, boolean fullscreen, boolean resize)
  345. {
  346. struct gx_render_data *render_data = graphics->render_data;
  347. float x, y, w, h, scale, xscale, yscale;
  348. int fh, fs, sw, sh, dw, dh;
  349. if(fullscreen)
  350. scale = 8.0 / 9.0;
  351. else
  352. scale = 8.0 / 10.0;
  353. if(render_data->rmode->viTVMode == VI_TVMODE_PAL_INT)
  354. fh = 574;
  355. else
  356. fh = 480;
  357. fs = fh * 720;
  358. if(CONF_GetAspectRatio() == CONF_ASPECT_16_9)
  359. {
  360. sw = fs * 16;
  361. sh = fs * 9;
  362. }
  363. else
  364. {
  365. sw = fs * 4;
  366. sh = fs * 3;
  367. }
  368. fix_viewport_ratio(sw, sh, &dw, &dh, graphics->ratio);
  369. if(render_data->rmode->viWidth > render_data->rmode->fbWidth)
  370. xscale = (float)render_data->rmode->fbWidth / render_data->rmode->viWidth;
  371. else
  372. xscale = 1.0;
  373. yscale = (float)render_data->rmode->efbHeight / render_data->rmode->viHeight;
  374. w = (float)dw * 720 / sw * scale;
  375. h = (float)dh * fh / sh * scale;
  376. x = (720 - w) / 2 - render_data->rmode->viXOrigin;
  377. y = (fh - h) / 2 - render_data->rmode->viYOrigin;
  378. w *= xscale; h *= yscale; x *= xscale; y *= yscale;
  379. render_data->sx0 = x;
  380. render_data->sy0 = y + 1;
  381. render_data->sx1 = x + w;
  382. render_data->sy1 = y + h + 1;
  383. return true;
  384. }
  385. static void gx_update_colors(struct graphics_data *graphics,
  386. struct rgb_color *palette, Uint32 count)
  387. {
  388. struct gx_render_data *render_data = graphics->render_data;
  389. Uint32 i;
  390. render_data->paldirty = 1;
  391. for(i = 0; i < count; i++)
  392. {
  393. // 32-bit color palette (used for cursor)
  394. render_data->palette[i].r = palette[i].r;
  395. render_data->palette[i].g = palette[i].g;
  396. render_data->palette[i].b = palette[i].b;
  397. render_data->palette[i].a = 255;
  398. // RGB5A3 (1 RRRRR GGGGG BBBBB) or (0 RRRR GGGG BBBB AAA)
  399. render_data->tlutpal[i] = 0x8000 |
  400. (palette[i].b >> 3) |
  401. ((palette[i].g & 0xF8) << 2) |
  402. ((palette[i].r & 0xF8) << 7);
  403. }
  404. }
  405. static void gx_remap_char_range(struct graphics_data *graphics, Uint16 first,
  406. Uint16 count)
  407. {
  408. struct gx_render_data *render_data = graphics->render_data;
  409. if(first + count > FULL_CHARSET_SIZE)
  410. count = FULL_CHARSET_SIZE - first;
  411. if(count <= 256)
  412. memset(render_data->chrdirty + first, 1, count);
  413. else
  414. render_data->chrdirty_all = 1;
  415. render_data->chrdirty_set = 1;
  416. }
  417. static void gx_remap_char(struct graphics_data *graphics, Uint16 chr)
  418. {
  419. struct gx_render_data *render_data = graphics->render_data;
  420. render_data->chrdirty[chr] = 1;
  421. render_data->chrdirty_set = 1;
  422. }
  423. static void gx_remap_charbyte(struct graphics_data *graphics,
  424. Uint16 chr, Uint8 byte)
  425. {
  426. struct gx_render_data *render_data = graphics->render_data;
  427. render_data->chrdirty[chr] = 1;
  428. render_data->chrdirty_set = 1;
  429. }
  430. /**
  431. * Draw a single char (MZX and SMZX) to the charset texture.
  432. * Because the texture is stored in 8x8 blocks, we need to draw the first
  433. * eight lines of the char, then skip ahead to the next row in the texture.
  434. */
  435. static void gx_draw_char(struct graphics_data *graphics, Uint16 chr)
  436. {
  437. struct gx_render_data *render_data = graphics->render_data;
  438. Uint8 *src = graphics->charset;
  439. u32 *dest = render_data->charimg;
  440. int byte;
  441. src += chr * CHAR_SIZE;
  442. dest += (chr / CHARSET_COLS) * CHAR_VAR_W * CHARSET_COLS * 2;
  443. dest += (chr % CHARSET_COLS) * CHAR_VAR_W;
  444. for(byte = 0; byte < 8; byte++, src++, dest++)
  445. *dest = mzxtexline[*src];
  446. src -= 8;
  447. for(byte = 0; byte < 8; byte++, src++, dest++)
  448. *dest = smzxtexline[*src];
  449. dest += (CHARSET_COLS - 1) * CHAR_VAR_W;
  450. for(byte = 0; byte < 6; byte++, src++, dest++)
  451. *dest = mzxtexline[*src];
  452. src -= 6;
  453. dest += 2;
  454. for(byte = 0; byte < 6; byte++, src++, dest++)
  455. *dest = smzxtexline[*src];
  456. }
  457. /**
  458. * Redraw the entire charset texture.
  459. * Because chars are stored in 8x8 blocks, the first 8 lines of each char in
  460. * a row need to be drawn and then the last 6 lines need to be drawn in the
  461. * next row of 8x8 blocks.
  462. */
  463. static void gx_draw_charsets(struct graphics_data *graphics)
  464. {
  465. struct gx_render_data *render_data = graphics->render_data;
  466. Uint8 *src = graphics->charset;
  467. u32 *dest = render_data->charimg;
  468. int x;
  469. int y;
  470. int byte;
  471. for(y = 0; y < CHARSET_ROWS; y++)
  472. {
  473. for(x = 0; x < CHARSET_COLS; x++)
  474. {
  475. for(byte = 0; byte < 8; byte++, src++, dest++)
  476. *dest = mzxtexline[*src];
  477. src -= 8;
  478. for(byte = 0; byte < 8; byte++, src++, dest++)
  479. *dest = smzxtexline[*src];
  480. src += 6;
  481. }
  482. src -= CHARSET_COLS * CHAR_SIZE;
  483. for(x = 0; x < CHARSET_COLS; x++)
  484. {
  485. src += 8;
  486. for(byte = 0; byte < 6; byte++, src++, dest++)
  487. *dest = mzxtexline[*src];
  488. src -= 6;
  489. dest += 2;
  490. for(byte = 0; byte < 6; byte++, src++, dest++)
  491. *dest = smzxtexline[*src];
  492. dest += 2;
  493. }
  494. }
  495. }
  496. static void gx_check_remap_chars(struct graphics_data *graphics)
  497. {
  498. struct gx_render_data *render_data = graphics->render_data;
  499. int i;
  500. if(!render_data->chrdirty_set)
  501. return;
  502. if(render_data->chrdirty_all)
  503. {
  504. gx_draw_charsets(graphics);
  505. render_data->chrdirty_all = false;
  506. memset(render_data->chrdirty, 0, FULL_CHARSET_SIZE);
  507. render_data->invalidate = true;
  508. }
  509. else
  510. {
  511. for(i = 0; i < FULL_CHARSET_SIZE; i++)
  512. {
  513. if(render_data->chrdirty[i])
  514. {
  515. gx_draw_char(graphics, i);
  516. render_data->chrdirty[i] = 0;
  517. render_data->invalidate = true;
  518. }
  519. }
  520. }
  521. render_data->chrdirty_set = 0;
  522. }
  523. static void gx_check_remap_palettes(struct graphics_data *graphics)
  524. {
  525. struct gx_render_data *render_data = graphics->render_data;
  526. int i;
  527. if(render_data->paldirty)
  528. {
  529. for(i = 0; i < NUM_TLUT; i++)
  530. render_data->mzxtlut[i].pal[1] = 0;
  531. render_data->paldirty = 0;
  532. render_data->invalidate = true;
  533. }
  534. }
  535. static int gx_get_tlut_id_mzx(struct graphics_data *graphics,
  536. struct video_layer *layer, Uint8 bg_color, Uint8 fg_color)
  537. {
  538. int tcol = layer->transparent_col;
  539. int tlut_id;
  540. if(tcol == (int)bg_color)
  541. return fg_color + TLUT_T0_OFFSET;
  542. if(tcol == (int)fg_color)
  543. return bg_color + TLUT_T1_OFFSET;
  544. tlut_id = ((bg_color & 0xF) << 4) | (fg_color & 0xF);
  545. if(bg_color >= 16 && fg_color >= 16)
  546. return tlut_id + TLUT_UI_OFFSET;
  547. // Mixed UI/game colors only occur during normal MZX mode, so it should
  548. // be safe to reuse the SMZX TCOL mappings for these.
  549. else
  550. if(bg_color >= 16)
  551. return tlut_id + TLUT_T2_OFFSET;
  552. else
  553. if(fg_color >= 16)
  554. return tlut_id + TLUT_T3_OFFSET;
  555. return tlut_id + TLUT_MZX_OFFSET;
  556. }
  557. static int gx_get_tlut_id_smzx(struct graphics_data *graphics,
  558. struct video_layer *layer, Uint8 bg_color, Uint8 fg_color)
  559. {
  560. int palette_id = ((bg_color & 0xF) << 4) | (fg_color & 0xF);
  561. int idx0 = graphics->smzx_indices[palette_id * 4 + 0];
  562. int idx1 = graphics->smzx_indices[palette_id * 4 + 1];
  563. int idx2 = graphics->smzx_indices[palette_id * 4 + 2];
  564. int idx3 = graphics->smzx_indices[palette_id * 4 + 3];
  565. int tcol = layer->transparent_col;
  566. if(tcol == idx0)
  567. return palette_id + TLUT_T0_OFFSET;
  568. if(tcol == idx1)
  569. return palette_id + TLUT_T1_OFFSET;
  570. if(tcol == idx2)
  571. return palette_id + TLUT_T2_OFFSET;
  572. if(tcol == idx3)
  573. return palette_id + TLUT_T3_OFFSET;
  574. return palette_id + TLUT_SMZX_OFFSET;
  575. }
  576. static void gx_set_tlut_mzx(struct graphics_data *graphics,
  577. struct video_layer *layer, struct ci4tlut *tlut, int bg_color, int fg_color)
  578. {
  579. struct gx_render_data *render_data = graphics->render_data;
  580. int tcol = layer->transparent_col;
  581. if(bg_color >= 16)
  582. bg_color = graphics->protected_pal_position + (bg_color & 0xF);
  583. else
  584. bg_color &= 0xF;
  585. if(fg_color >= 16)
  586. fg_color = graphics->protected_pal_position + (fg_color & 0xF);
  587. else
  588. fg_color &= 0xF;
  589. tlut->pal[0] = bg_color != tcol ? render_data->tlutpal[bg_color] : NO_COLOR;
  590. tlut->pal[15] = fg_color != tcol ? render_data->tlutpal[fg_color] : NO_COLOR;
  591. tlut->pal[1] = 0xFFFF;
  592. }
  593. static void gx_set_tlut_smzx(struct graphics_data *graphics,
  594. struct video_layer *layer, struct ci4tlut *tlut, int bg_color, int fg_color)
  595. {
  596. struct gx_render_data *render_data = graphics->render_data;
  597. int palette_id = ((bg_color & 0xF) << 4) | (fg_color & 0xF);
  598. int idx0 = graphics->smzx_indices[palette_id * 4 + 0];
  599. int idx1 = graphics->smzx_indices[palette_id * 4 + 1];
  600. int idx2 = graphics->smzx_indices[palette_id * 4 + 2];
  601. int idx3 = graphics->smzx_indices[palette_id * 4 + 3];
  602. int tcol = layer->transparent_col;
  603. tlut->pal[0] = idx0 != tcol ? render_data->tlutpal[idx0] : NO_COLOR;
  604. tlut->pal[5] = idx1 != tcol ? render_data->tlutpal[idx1] : NO_COLOR;
  605. tlut->pal[10] = idx2 != tcol ? render_data->tlutpal[idx2] : NO_COLOR;
  606. tlut->pal[15] = idx3 != tcol ? render_data->tlutpal[idx3] : NO_COLOR;
  607. tlut->pal[1] = 0xFFFF;
  608. }
  609. static Uint16 gx_get_char_value(struct video_layer *layer, Uint16 char_value)
  610. {
  611. if(char_value == INVISIBLE_CHAR)
  612. return INVISIBLE_CHAR;
  613. if(char_value > 0xFF)
  614. return (char_value & 0xFF) + PROTECTED_CHARSET_POSITION;
  615. return (layer->offset + char_value) % PROTECTED_CHARSET_POSITION;
  616. }
  617. static void gx_render_layer(struct graphics_data *graphics,
  618. struct video_layer *layer)
  619. {
  620. struct gx_render_data *render_data = graphics->render_data;
  621. struct char_element *src = layer->data;
  622. struct ci4tlut *tlut;
  623. int last_tlut_id;
  624. int cur_tlut_id;
  625. Uint16 char_value;
  626. Uint8 bg_color;
  627. Uint8 fg_color;
  628. Uint32 x, y;
  629. int x1, x2, y1, y2;
  630. float u, v;
  631. float u2, v2;
  632. render_data->invalidate = false;
  633. gx_check_remap_chars(graphics);
  634. if(render_data->invalidate)
  635. {
  636. DCFlushRange(render_data->charimg, TEX_DATA_SIZE);
  637. GX_InvalidateTexAll();
  638. render_data->invalidate = false;
  639. }
  640. gx_check_remap_palettes(graphics);
  641. if(render_data->invalidate)
  642. GX_InvalidateTexAll();
  643. GX_SetBlendMode(GX_BM_BLEND, GX_BL_SRCALPHA, GX_BL_INVSRCALPHA, GX_LO_CLEAR);
  644. GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);
  645. last_tlut_id = -1;
  646. if(!layer->mode)
  647. {
  648. for(y = 0; y < layer->h; y++)
  649. {
  650. for(x = 0; x < layer->w; x++, src++)
  651. {
  652. char_value = gx_get_char_value(layer, src->char_value);
  653. if(char_value == INVISIBLE_CHAR)
  654. continue;
  655. bg_color = src->bg_color;
  656. fg_color = src->fg_color;
  657. cur_tlut_id = gx_get_tlut_id_mzx(graphics, layer, bg_color, fg_color);
  658. if(cur_tlut_id != last_tlut_id)
  659. {
  660. tlut = &(render_data->mzxtlut[cur_tlut_id]);
  661. if(!tlut->pal[1])
  662. {
  663. gx_set_tlut_mzx(graphics, layer, tlut, bg_color, fg_color);
  664. DCFlushRange(tlut, sizeof(struct ci4tlut));
  665. }
  666. GX_LoadTlut(&render_data->mzxtlutobj[cur_tlut_id], GX_TLUT0);
  667. GX_LoadTexObj(&render_data->chartex, GX_TEXMAP0);
  668. last_tlut_id = cur_tlut_id;
  669. }
  670. u = (char_value % CHARSET_COLS) * CHAR_VAR_W / TEX_DATA_W_F;
  671. v = (char_value / CHARSET_COLS) * CHAR_VAR_H / TEX_DATA_H_F;
  672. u2 = u + CHAR_W / TEX_DATA_W_F;
  673. v2 = v + CHAR_H / TEX_DATA_H_F;
  674. x1 = (int)x * CHAR_W + layer->x;
  675. y1 = (int)y * CHAR_H + layer->y;
  676. x2 = ((int)x + 1) * CHAR_W + layer->x;
  677. y2 = ((int)y + 1) * CHAR_H + layer->y;
  678. GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
  679. GX_Position2s16(x1, y1);
  680. GX_TexCoord2f32(u, v );
  681. GX_Position2s16(x2, y1);
  682. GX_TexCoord2f32(u2, v );
  683. GX_Position2s16(x2, y2);
  684. GX_TexCoord2f32(u2, v2);
  685. GX_Position2s16(x1, y2);
  686. GX_TexCoord2f32(u, v2);
  687. GX_End();
  688. }
  689. }
  690. }
  691. else
  692. {
  693. for(y = 0; y < layer->h; y++)
  694. {
  695. for(x = 0; x < layer->w; x++, src++)
  696. {
  697. char_value = gx_get_char_value(layer, src->char_value);
  698. if(char_value == INVISIBLE_CHAR)
  699. continue;
  700. bg_color = src->bg_color;
  701. fg_color = src->fg_color;
  702. cur_tlut_id = gx_get_tlut_id_smzx(graphics, layer, bg_color, fg_color);
  703. if(cur_tlut_id != last_tlut_id)
  704. {
  705. tlut = &(render_data->mzxtlut[cur_tlut_id]);
  706. if(!tlut->pal[1])
  707. {
  708. gx_set_tlut_smzx(graphics, layer, tlut, bg_color, fg_color);
  709. DCFlushRange(tlut, sizeof(struct ci4tlut));
  710. }
  711. GX_LoadTlut(&render_data->mzxtlutobj[cur_tlut_id], GX_TLUT0);
  712. GX_LoadTexObj(&render_data->chartex, GX_TEXMAP0);
  713. last_tlut_id = cur_tlut_id;
  714. }
  715. u = (char_value % CHARSET_COLS) * CHAR_VAR_W / TEX_DATA_W_F;
  716. v = (char_value / CHARSET_COLS) * CHAR_VAR_H / TEX_DATA_H_F;
  717. u += SMZX_OFFSET / TEX_DATA_W_F;
  718. u2 = u + CHAR_W / TEX_DATA_W_F;
  719. v2 = v + CHAR_H / TEX_DATA_H_F;
  720. x1 = (int)x * CHAR_W + layer->x;
  721. y1 = (int)y * CHAR_H + layer->y;
  722. x2 = ((int)x + 1) * CHAR_W + layer->x;
  723. y2 = ((int)y + 1) * CHAR_H + layer->y;
  724. GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
  725. GX_Position2s16(x1, y1);
  726. GX_TexCoord2f32(u, v );
  727. GX_Position2s16(x2, y1);
  728. GX_TexCoord2f32(u2, v );
  729. GX_Position2s16(x2, y2);
  730. GX_TexCoord2f32(u2, v2);
  731. GX_Position2s16(x1, y2);
  732. GX_TexCoord2f32(u, v2);
  733. GX_End();
  734. }
  735. }
  736. }
  737. GX_SetTevOp(GX_TEVSTAGE0, GX_PASSCLR);
  738. }
  739. static void gx_render_cursor(struct graphics_data *graphics,
  740. Uint32 x, Uint32 y, Uint16 color, Uint8 lines, Uint8 offset)
  741. {
  742. struct gx_render_data *render_data = graphics->render_data;
  743. GXColor *pal = render_data->palette;
  744. GX_SetChanMatColor(GX_COLOR0A0, pal[color & 0xFF]);
  745. GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
  746. GX_Position2s16(x * 8, y * 14 + offset);
  747. GX_TexCoord2f32(0, 0);
  748. GX_Position2s16(x * 8 + 8, y * 14 + offset);
  749. GX_TexCoord2f32(0, 0);
  750. GX_Position2s16(x * 8 + 8, y * 14 + offset + lines);
  751. GX_TexCoord2f32(0, 0);
  752. GX_Position2s16(x * 8, y * 14 + offset + lines);
  753. GX_TexCoord2f32(0, 0);
  754. GX_End();
  755. }
  756. static void gx_render_mouse(struct graphics_data *graphics,
  757. Uint32 x, Uint32 y, Uint8 w, Uint8 h)
  758. {
  759. const GXColor white = {255, 255, 255, 255};
  760. GX_SetBlendMode(GX_BM_BLEND, GX_BL_INVDSTCLR, GX_BL_ZERO, GX_LO_CLEAR);
  761. GX_SetChanMatColor(GX_COLOR0A0, white);
  762. GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
  763. GX_Position2s16(x, y);
  764. GX_TexCoord2f32(0, 0);
  765. GX_Position2s16(x + w, y);
  766. GX_TexCoord2f32(0, 0);
  767. GX_Position2s16(x + w, y + h);
  768. GX_TexCoord2f32(0, 0);
  769. GX_Position2s16(x, y + h);
  770. GX_TexCoord2f32(0, 0);
  771. GX_End();
  772. }
  773. static void gx_sync_screen(struct graphics_data *graphics)
  774. {
  775. struct gx_render_data *render_data = graphics->render_data;
  776. static u8 tex_ptn[12][2] = {
  777. {6, 6}, {6, 6}, {6, 6},
  778. {6, 6}, {6, 6}, {6, 6},
  779. {6, 6}, {6, 6}, {6, 6},
  780. {6, 6}, {6, 6}, {6, 6},
  781. };
  782. static u8 tex_vf[7] = {0, 0, 21, 22, 21, 0, 0};
  783. GX_SetCopyFilter(GX_FALSE, tex_ptn, GX_FALSE, tex_vf);
  784. GX_CopyTex(render_data->scaleimg, GX_TRUE);
  785. GX_Flush();
  786. GX_PixModeSync();
  787. GX_SetTevOp(GX_TEVSTAGE0, GX_REPLACE);
  788. GX_LoadTexObj(&render_data->scaletex, GX_TEXMAP0);
  789. GX_Begin(GX_QUADS, GX_VTXFMT0, 4);
  790. GX_Position2s16(render_data->sx0, render_data->sy0);
  791. GX_TexCoord2f32(SCALE_TEX_X0, SCALE_TEX_Y0);
  792. GX_Position2s16(render_data->sx1, render_data->sy0);
  793. GX_TexCoord2f32(SCALE_TEX_X1, SCALE_TEX_Y0);
  794. GX_Position2s16(render_data->sx1, render_data->sy1);
  795. GX_TexCoord2f32(SCALE_TEX_X1, SCALE_TEX_Y1);
  796. GX_Position2s16(render_data->sx0, render_data->sy1);
  797. GX_TexCoord2f32(SCALE_TEX_X0, SCALE_TEX_Y1);
  798. GX_End();
  799. GX_DrawDone();
  800. GX_SetZMode(GX_FALSE, GX_ALWAYS, GX_FALSE);
  801. GX_SetColorUpdate(GX_TRUE);
  802. GX_SetCopyFilter(render_data->rmode->aa, render_data->rmode->sample_pattern,
  803. GX_TRUE, render_data->rmode->vfilter);
  804. GX_CopyDisp(render_data->xfb[render_data->current_xfb], GX_TRUE);
  805. GX_Flush();
  806. VIDEO_SetNextFramebuffer(render_data->xfb[render_data->current_xfb]);
  807. VIDEO_Flush();
  808. if(graphics->gl_vsync)
  809. VIDEO_WaitVSync();
  810. render_data->current_xfb ^= 1;
  811. }
  812. void render_gx_register(struct renderer *renderer)
  813. {
  814. memset(renderer, 0, sizeof(struct renderer));
  815. renderer->init_video = gx_init_video;
  816. renderer->free_video = gx_free_video;
  817. renderer->check_video_mode = gx_check_video_mode;
  818. renderer->set_video_mode = gx_set_video_mode;
  819. renderer->update_colors = gx_update_colors;
  820. renderer->resize_screen = resize_screen_standard;
  821. renderer->remap_char_range = gx_remap_char_range;
  822. renderer->remap_char = gx_remap_char;
  823. renderer->remap_charbyte = gx_remap_charbyte;
  824. renderer->get_screen_coords = get_screen_coords_centered;
  825. renderer->set_screen_coords = set_screen_coords_centered;
  826. renderer->render_layer = gx_render_layer;
  827. renderer->render_cursor = gx_render_cursor;
  828. renderer->render_mouse = gx_render_mouse;
  829. renderer->sync_screen = gx_sync_screen;
  830. }