2 * Copyright (C) 2011 Gilead Kutnick "Exophase" <exophase@gmail.com>
4 * This program is free software; you can redistribute it and/or
5 * modify it under the terms of the GNU General Public License as
6 * published by the Free Software Foundation; either version 2 of
7 * the License, or (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12 * General Public License for more details.
19 #ifndef command_lengths
20 const u8 command_lengths[256] =
22 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00
23 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 10
24 3, 3, 3, 3, 6, 6, 6, 6, 4, 4, 4, 4, 8, 8, 8, 8, // 20
25 5, 5, 5, 5, 8, 8, 8, 8, 7, 7, 7, 7, 11, 11, 11, 11, // 30
26 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, // 40
27 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, // 50
28 2, 2, 2, 2, 3, 3, 3, 3, 1, 1, 1, 1, 0, 0, 0, 0, // 60
29 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, // 70
30 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 80
31 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 90
32 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // a0
33 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // b0
34 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // c0
35 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // d0
36 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // e0
37 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // f0
41 void update_texture_ptr(psx_gpu_struct *psx_gpu)
46 switch((psx_gpu->render_state_base >> 8) & 0x3)
48 case TEXTURE_MODE_4BPP:
49 texture_base = psx_gpu->texture_4bpp_cache[psx_gpu->current_texture_page];
51 texture_ptr = texture_base;
52 texture_ptr += psx_gpu->texture_window_x & 0xF;
53 texture_ptr += (psx_gpu->texture_window_y & 0xF) << 4;
54 texture_ptr += (psx_gpu->texture_window_x >> 4) << 8;
55 texture_ptr += (psx_gpu->texture_window_y >> 4) << 12;
58 case TEXTURE_MODE_8BPP:
59 if(psx_gpu->current_texture_page & 0x1)
62 psx_gpu->texture_8bpp_odd_cache[psx_gpu->current_texture_page >> 1];
67 psx_gpu->texture_8bpp_even_cache[psx_gpu->current_texture_page >> 1];
70 texture_ptr = texture_base;
71 texture_ptr += psx_gpu->texture_window_x & 0xF;
72 texture_ptr += (psx_gpu->texture_window_y & 0xF) << 4;
73 texture_ptr += (psx_gpu->texture_window_x >> 4) << 8;
74 texture_ptr += (psx_gpu->texture_window_y >> 4) << 12;
78 case TEXTURE_MODE_16BPP:
79 texture_base = (u8 *)(psx_gpu->vram_ptr);
80 texture_base += (psx_gpu->current_texture_page & 0xF) * 128;
81 texture_base += ((psx_gpu->current_texture_page >> 4) * 256) * 2048;
83 texture_ptr = texture_base;
84 texture_ptr += psx_gpu->texture_window_x * 2;
85 texture_ptr += (psx_gpu->texture_window_y) * 2048;
89 psx_gpu->texture_page_base = texture_base;
90 psx_gpu->texture_page_ptr = texture_ptr;
93 void set_texture(psx_gpu_struct *psx_gpu, u32 texture_settings)
95 texture_settings &= 0x1FF;
96 if(psx_gpu->texture_settings != texture_settings)
98 u32 new_texture_page = texture_settings & 0x1F;
99 u32 texture_mode = (texture_settings >> 7) & 0x3;
100 u32 render_state_base = psx_gpu->render_state_base;
102 flush_render_block_buffer(psx_gpu);
104 render_state_base &= ~(0xF << 6);
105 render_state_base |= ((texture_settings >> 5) & 0xF) << 6;
107 psx_gpu->render_state_base = render_state_base;
109 psx_gpu->current_texture_mask = 0x1 << new_texture_page;
111 if(texture_mode == TEXTURE_MODE_8BPP)
113 // In 8bpp mode 256x256 takes up two pages. If it's on the right edge it
114 // wraps back around to the left edge.
115 u32 adjacent_texture_page = ((texture_settings + 1) & 0xF) | (texture_settings & 0x10);
116 psx_gpu->current_texture_mask |= 0x1 << adjacent_texture_page;
118 if((psx_gpu->last_8bpp_texture_page ^ new_texture_page) & 0x1)
120 u32 dirty_textures_8bpp_alternate_mask =
121 psx_gpu->dirty_textures_8bpp_alternate_mask;
122 psx_gpu->dirty_textures_8bpp_alternate_mask =
123 psx_gpu->dirty_textures_8bpp_mask;
124 psx_gpu->dirty_textures_8bpp_mask = dirty_textures_8bpp_alternate_mask;
127 psx_gpu->last_8bpp_texture_page = new_texture_page;
130 psx_gpu->current_texture_page = new_texture_page;
131 psx_gpu->texture_settings = texture_settings;
133 update_texture_ptr(psx_gpu);
137 void set_clut(psx_gpu_struct *psx_gpu, u32 clut_settings)
139 if(psx_gpu->clut_settings != clut_settings)
141 flush_render_block_buffer(psx_gpu);
142 psx_gpu->clut_settings = clut_settings;
143 psx_gpu->clut_ptr = psx_gpu->vram_ptr + ((clut_settings & 0x7FFF) * 16);
147 void set_triangle_color(psx_gpu_struct *psx_gpu, u32 triangle_color)
149 if(psx_gpu->triangle_color != triangle_color)
151 flush_render_block_buffer(psx_gpu);
152 psx_gpu->triangle_color = triangle_color;
156 static void do_fill(psx_gpu_struct *psx_gpu, u32 x, u32 y,
157 u32 width, u32 height, u32 color)
160 width = ((width + 0xF) & ~0xF);
162 flush_render_block_buffer(psx_gpu);
164 if(unlikely((x + width) > 1024))
166 u32 width_a = 1024 - x;
167 u32 width_b = width - width_a;
169 if(unlikely((y + height) > 512))
171 u32 height_a = 512 - y;
172 u32 height_b = height - height_a;
174 render_block_fill(psx_gpu, color, x, y, width_a, height_a);
175 render_block_fill(psx_gpu, color, 0, y, width_b, height_a);
176 render_block_fill(psx_gpu, color, x, 0, width_a, height_b);
177 render_block_fill(psx_gpu, color, 0, 0, width_b, height_b);
181 render_block_fill(psx_gpu, color, x, y, width_a, height);
182 render_block_fill(psx_gpu, color, 0, y, width_b, height);
187 if(unlikely((y + height) > 512))
189 u32 height_a = 512 - y;
190 u32 height_b = height - height_a;
192 render_block_fill(psx_gpu, color, x, y, width, height_a);
193 render_block_fill(psx_gpu, color, x, 0, width, height_b);
197 render_block_fill(psx_gpu, color, x, y, width, height);
202 #define sign_extend_12bit(value) \
203 (((s32)((value) << 20)) >> 20) \
205 #define sign_extend_11bit(value) \
206 (((s32)((value) << 21)) >> 21) \
208 #define sign_extend_10bit(value) \
209 (((s32)((value) << 22)) >> 22) \
212 #define get_vertex_data_xy(vertex_number, offset16) \
213 vertexes[vertex_number].x = \
214 sign_extend_12bit(list_s16[offset16]) + psx_gpu->offset_x; \
215 vertexes[vertex_number].y = \
216 sign_extend_12bit(list_s16[(offset16) + 1]) + psx_gpu->offset_y; \
218 #define get_vertex_data_uv(vertex_number, offset16) \
219 vertexes[vertex_number].u = list_s16[offset16] & 0xFF; \
220 vertexes[vertex_number].v = (list_s16[offset16] >> 8) & 0xFF \
222 #define get_vertex_data_rgb(vertex_number, offset32) \
223 vertexes[vertex_number].r = list[offset32] & 0xFF; \
224 vertexes[vertex_number].g = (list[offset32] >> 8) & 0xFF; \
225 vertexes[vertex_number].b = (list[offset32] >> 16) & 0xFF \
227 #define get_vertex_data_xy_uv(vertex_number, offset16) \
228 get_vertex_data_xy(vertex_number, offset16); \
229 get_vertex_data_uv(vertex_number, (offset16) + 2) \
231 #define get_vertex_data_xy_rgb(vertex_number, offset16) \
232 get_vertex_data_rgb(vertex_number, (offset16) / 2); \
233 get_vertex_data_xy(vertex_number, (offset16) + 2); \
235 #define get_vertex_data_xy_uv_rgb(vertex_number, offset16) \
236 get_vertex_data_rgb(vertex_number, (offset16) / 2); \
237 get_vertex_data_xy(vertex_number, (offset16) + 2); \
238 get_vertex_data_uv(vertex_number, (offset16) + 4); \
240 #define set_vertex_color_constant(vertex_number, color) \
241 vertexes[vertex_number].r = color & 0xFF; \
242 vertexes[vertex_number].g = (color >> 8) & 0xFF; \
243 vertexes[vertex_number].b = (color >> 16) & 0xFF \
245 #define get_vertex_data_xy_rgb_constant(vertex_number, offset16, color) \
246 get_vertex_data_xy(vertex_number, offset16); \
247 set_vertex_color_constant(vertex_number, color) \
253 u32 gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size, u32 *last_command)
255 vertex_struct vertexes[4] __attribute__((aligned(16))) = {};
256 u32 current_command = 0, command_length;
258 u32 *list_start = list;
259 u32 *list_end = list + (size / 4);
261 for(; list < list_end; list += 1 + command_length)
263 s16 *list_s16 = (void *)list;
264 current_command = *list >> 24;
265 command_length = command_lengths[current_command];
266 if (list + 1 + command_length > list_end) {
267 current_command = (u32)-1;
271 switch(current_command)
278 u32 x = list_s16[2] & 0x3FF;
279 u32 y = list_s16[3] & 0x1FF;
280 u32 width = list_s16[4] & 0x3FF;
281 u32 height = list_s16[5] & 0x1FF;
282 u32 color = list[0] & 0xFFFFFF;
284 do_fill(psx_gpu, x, y, width, height, color);
290 set_triangle_color(psx_gpu, list[0] & 0xFFFFFF);
292 get_vertex_data_xy(0, 2);
293 get_vertex_data_xy(1, 4);
294 get_vertex_data_xy(2, 6);
296 render_triangle(psx_gpu, vertexes, current_command);
302 set_clut(psx_gpu, list_s16[5]);
303 set_texture(psx_gpu, list_s16[9]);
304 set_triangle_color(psx_gpu, list[0] & 0xFFFFFF);
306 get_vertex_data_xy_uv(0, 2);
307 get_vertex_data_xy_uv(1, 6);
308 get_vertex_data_xy_uv(2, 10);
310 render_triangle(psx_gpu, vertexes, current_command);
316 set_triangle_color(psx_gpu, list[0] & 0xFFFFFF);
318 get_vertex_data_xy(0, 2);
319 get_vertex_data_xy(1, 4);
320 get_vertex_data_xy(2, 6);
321 get_vertex_data_xy(3, 8);
323 render_triangle(psx_gpu, vertexes, current_command);
324 render_triangle(psx_gpu, &(vertexes[1]), current_command);
330 set_clut(psx_gpu, list_s16[5]);
331 set_texture(psx_gpu, list_s16[9]);
332 set_triangle_color(psx_gpu, list[0] & 0xFFFFFF);
334 get_vertex_data_xy_uv(0, 2);
335 get_vertex_data_xy_uv(1, 6);
336 get_vertex_data_xy_uv(2, 10);
337 get_vertex_data_xy_uv(3, 14);
339 render_triangle(psx_gpu, vertexes, current_command);
340 render_triangle(psx_gpu, &(vertexes[1]), current_command);
346 get_vertex_data_xy_rgb(0, 0);
347 get_vertex_data_xy_rgb(1, 4);
348 get_vertex_data_xy_rgb(2, 8);
350 render_triangle(psx_gpu, vertexes, current_command);
359 set_clut(psx_gpu, list_s16[5]);
360 set_texture(psx_gpu, list_s16[11]);
362 get_vertex_data_xy_uv_rgb(0, 0);
363 get_vertex_data_xy_uv_rgb(1, 6);
364 get_vertex_data_xy_uv_rgb(2, 12);
366 render_triangle(psx_gpu, vertexes, current_command);
375 get_vertex_data_xy_rgb(0, 0);
376 get_vertex_data_xy_rgb(1, 4);
377 get_vertex_data_xy_rgb(2, 8);
378 get_vertex_data_xy_rgb(3, 12);
380 render_triangle(psx_gpu, vertexes, current_command);
381 render_triangle(psx_gpu, &(vertexes[1]), current_command);
390 set_clut(psx_gpu, list_s16[5]);
391 set_texture(psx_gpu, list_s16[11]);
393 get_vertex_data_xy_uv_rgb(0, 0);
394 get_vertex_data_xy_uv_rgb(1, 6);
395 get_vertex_data_xy_uv_rgb(2, 12);
396 get_vertex_data_xy_uv_rgb(3, 18);
398 render_triangle(psx_gpu, vertexes, current_command);
399 render_triangle(psx_gpu, &(vertexes[1]), current_command);
405 vertexes[0].x = list_s16[2] + psx_gpu->offset_x;
406 vertexes[0].y = list_s16[3] + psx_gpu->offset_y;
407 vertexes[1].x = list_s16[4] + psx_gpu->offset_x;
408 vertexes[1].y = list_s16[5] + psx_gpu->offset_y;
410 render_line(psx_gpu, vertexes, current_command, list[0], 0);
416 u32 num_vertexes = 1;
417 u32 *list_position = &(list[2]);
420 vertexes[1].x = (xy & 0xFFFF) + psx_gpu->offset_x;
421 vertexes[1].y = (xy >> 16) + psx_gpu->offset_y;
426 vertexes[0] = vertexes[1];
428 vertexes[1].x = (xy & 0xFFFF) + psx_gpu->offset_x;
429 vertexes[1].y = (xy >> 16) + psx_gpu->offset_y;
431 render_line(psx_gpu, vertexes, current_command, list[0], 0);
436 if(list_position >= list_end)
438 current_command = (u32)-1;
443 if((xy & 0xF000F000) == 0x50005000)
447 command_length += (num_vertexes - 2);
453 vertexes[0].r = list[0] & 0xFF;
454 vertexes[0].g = (list[0] >> 8) & 0xFF;
455 vertexes[0].b = (list[0] >> 16) & 0xFF;
456 vertexes[0].x = list_s16[2] + psx_gpu->offset_x;
457 vertexes[0].y = list_s16[3] + psx_gpu->offset_y;
459 vertexes[1].r = list[2] & 0xFF;
460 vertexes[1].g = (list[2] >> 8) & 0xFF;
461 vertexes[1].b = (list[2] >> 16) & 0xFF;
462 vertexes[1].x = list_s16[6] + psx_gpu->offset_x;
463 vertexes[1].y = list_s16[7] + psx_gpu->offset_y;
465 render_line(psx_gpu, vertexes, current_command, 0, 0);
471 u32 num_vertexes = 1;
472 u32 *list_position = &(list[2]);
476 vertexes[1].r = color & 0xFF;
477 vertexes[1].g = (color >> 8) & 0xFF;
478 vertexes[1].b = (color >> 16) & 0xFF;
479 vertexes[1].x = (xy & 0xFFFF) + psx_gpu->offset_x;
480 vertexes[1].y = (xy >> 16) + psx_gpu->offset_y;
482 color = list_position[0];
485 xy = list_position[1];
487 vertexes[0] = vertexes[1];
489 vertexes[1].r = color & 0xFF;
490 vertexes[1].g = (color >> 8) & 0xFF;
491 vertexes[1].b = (color >> 16) & 0xFF;
492 vertexes[1].x = (xy & 0xFFFF) + psx_gpu->offset_x;
493 vertexes[1].y = (xy >> 16) + psx_gpu->offset_y;
495 render_line(psx_gpu, vertexes, current_command, 0, 0);
500 if(list_position >= list_end)
502 current_command = (u32)-1;
506 color = list_position[0];
507 if((color & 0xF000F000) == 0x50005000)
511 command_length += ((num_vertexes - 2) * 2);
517 u32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
518 u32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
519 u32 width = list_s16[4] & 0x3FF;
520 u32 height = list_s16[5] & 0x1FF;
522 render_sprite(psx_gpu, x, y, 0, 0, width, height, current_command, list[0]);
528 u32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
529 u32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
530 u32 uv = list_s16[4];
531 u32 width = list_s16[6] & 0x3FF;
532 u32 height = list_s16[7] & 0x1FF;
534 set_clut(psx_gpu, list_s16[5]);
536 render_sprite(psx_gpu, x, y, uv & 0xFF, (uv >> 8) & 0xFF, width, height,
537 current_command, list[0]);
546 s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
547 s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
549 render_sprite(psx_gpu, x, y, 0, 0, 1, 1, current_command, list[0]);
558 s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
559 s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
561 render_sprite(psx_gpu, x, y, 0, 0, 8, 8, current_command, list[0]);
570 s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
571 s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
572 u32 uv = list_s16[4];
574 set_clut(psx_gpu, list_s16[5]);
576 render_sprite(psx_gpu, x, y, uv & 0xFF, (uv >> 8) & 0xFF, 8, 8,
577 current_command, list[0]);
586 s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
587 s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
589 render_sprite(psx_gpu, x, y, 0, 0, 16, 16, current_command, list[0]);
598 s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
599 s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
600 u32 uv = list_s16[4];
602 set_clut(psx_gpu, list_s16[5]);
604 render_sprite(psx_gpu, x, y, uv & 0xFF, (uv >> 8) & 0xFF, 16, 16,
605 current_command, list[0]);
609 case 0x80: // vid -> vid
611 u32 sx = list_s16[2] & 0x3FF;
612 u32 sy = list_s16[3] & 0x1FF;
613 u32 dx = list_s16[4] & 0x3FF;
614 u32 dy = list_s16[5] & 0x1FF;
615 u32 w = ((list_s16[6] - 1) & 0x3FF) + 1;
616 u32 h = ((list_s16[7] - 1) & 0x1FF) + 1;
618 if (sx == dx && sy == dy && psx_gpu->mask_msb == 0)
621 render_block_move(psx_gpu, sx, sy, dx, dy, w, h);
626 case 0xA0: // sys -> vid
627 case 0xC0: // vid -> sys
630 case 0xA0: // sys -> vid
632 u32 load_x = list_s16[2] & 0x3FF;
633 u32 load_y = list_s16[3] & 0x1FF;
634 u32 load_width = list_s16[4] & 0x3FF;
635 u32 load_height = list_s16[5] & 0x1FF;
636 u32 load_size = load_width * load_height;
638 command_length += load_size / 2;
643 render_block_copy(psx_gpu, (u16 *)&(list_s16[6]), load_x, load_y,
644 load_width, load_height, load_width);
648 case 0xC0: // vid -> sys
653 set_texture(psx_gpu, list[0]);
655 if(list[0] & (1 << 9))
656 psx_gpu->render_state_base |= RENDER_STATE_DITHER;
658 psx_gpu->render_state_base &= ~RENDER_STATE_DITHER;
660 psx_gpu->display_area_draw_enable = (list[0] >> 10) & 0x1;
667 u32 texture_window_settings = list[0];
670 if(texture_window_settings != psx_gpu->texture_window_settings)
672 tmp = (texture_window_settings & 0x1F) | 0x20;
673 for(w = 8; (tmp & 1) == 0; tmp >>= 1, w <<= 1);
675 tmp = ((texture_window_settings >> 5) & 0x1f) | 0x20;
676 for (h = 8; (tmp & 1) == 0; tmp >>= 1, h <<= 1);
679 x = ((texture_window_settings >> 10) & tmp) << 3;
682 y = ((texture_window_settings >> 15) & tmp) << 3;
684 flush_render_block_buffer(psx_gpu);
686 psx_gpu->texture_window_settings = texture_window_settings;
687 psx_gpu->texture_window_x = x;
688 psx_gpu->texture_window_y = y;
689 psx_gpu->texture_mask_width = w - 1;
690 psx_gpu->texture_mask_height = h - 1;
692 update_texture_ptr(psx_gpu);
700 s16 viewport_start_x = list[0] & 0x3FF;
701 s16 viewport_start_y = (list[0] >> 10) & 0x1FF;
703 if(viewport_start_x == psx_gpu->viewport_start_x &&
704 viewport_start_y == psx_gpu->viewport_start_y)
709 psx_gpu->viewport_start_x = viewport_start_x;
710 psx_gpu->viewport_start_y = viewport_start_y;
712 #ifdef TEXTURE_CACHE_4BPP
713 psx_gpu->viewport_mask =
714 texture_region_mask(psx_gpu->viewport_start_x,
715 psx_gpu->viewport_start_y, psx_gpu->viewport_end_x,
716 psx_gpu->viewport_end_y);
724 s16 viewport_end_x = list[0] & 0x3FF;
725 s16 viewport_end_y = (list[0] >> 10) & 0x1FF;
727 if(viewport_end_x == psx_gpu->viewport_end_x &&
728 viewport_end_y == psx_gpu->viewport_end_y)
733 psx_gpu->viewport_end_x = viewport_end_x;
734 psx_gpu->viewport_end_y = viewport_end_y;
736 #ifdef TEXTURE_CACHE_4BPP
737 psx_gpu->viewport_mask =
738 texture_region_mask(psx_gpu->viewport_start_x,
739 psx_gpu->viewport_start_y, psx_gpu->viewport_end_x,
740 psx_gpu->viewport_end_y);
748 s32 offset_x = list[0] << 21;
749 s32 offset_y = list[0] << 10;
750 psx_gpu->offset_x = offset_x >> 21;
751 psx_gpu->offset_y = offset_y >> 21;
759 u32 mask_settings = list[0];
760 u16 mask_msb = mask_settings << 15;
763 psx_gpu->render_state_base |= RENDER_STATE_MASK_EVALUATE;
765 psx_gpu->render_state_base &= ~RENDER_STATE_MASK_EVALUATE;
767 if(mask_msb != psx_gpu->mask_msb)
769 flush_render_block_buffer(psx_gpu);
770 psx_gpu->mask_msb = mask_msb;
783 if (last_command != NULL)
784 *last_command = current_command;
785 return list - list_start;
790 #define ENH_BUF_TABLE_STEP (1024 / sizeof(psx_gpu->enhancement_buf_by_x16))
792 static int is_new_scanout(psx_gpu_struct *psx_gpu, int x)
795 for (i = 0; i < ARRAY_SIZE(psx_gpu->enhancement_scanout_x); i++)
797 scanout_x = psx_gpu->enhancement_scanout_x[i];
798 if (x <= scanout_x && scanout_x < x + ENH_BUF_TABLE_STEP)
801 log_anomaly("unaligned scanout x: %d,%d\n", scanout_x, x);
808 static void update_enhancement_buf_table_from_hres(psx_gpu_struct *psx_gpu)
813 psx_gpu->enhancement_buf_by_x16[0] = b;
814 psx_gpu->enhancement_buf_start[0] = 0;
815 for (x = 1; x < sizeof(psx_gpu->enhancement_buf_by_x16); x++)
817 if (b < 3 && is_new_scanout(psx_gpu, x * ENH_BUF_TABLE_STEP)) {
819 psx_gpu->enhancement_buf_start[b] = x * ENH_BUF_TABLE_STEP;
822 psx_gpu->enhancement_buf_by_x16[x] = b;
825 printf("buf_by_x16:\n");
826 for (b = 0; b < 3; b++) {
827 int first = -1, count = 0;
828 for (x = 0; x < sizeof(psx_gpu->enhancement_buf_by_x16); x++) {
829 if (psx_gpu->enhancement_buf_by_x16[x] == b) {
830 if (first < 0) first = x;
835 assert(first * ENH_BUF_TABLE_STEP == psx_gpu->enhancement_buf_start[b]);
836 printf("%d: %3zd-%zd\n", b, first * ENH_BUF_TABLE_STEP,
837 (first + count) * ENH_BUF_TABLE_STEP);
843 static void update_enhancement_buf_table_from_x(psx_gpu_struct *psx_gpu,
849 for (x = x0, b = 0; x >= len; b++)
854 memset(psx_gpu->enhancement_buf_by_x16 + x0 / ENH_BUF_TABLE_STEP,
855 b, (len + ENH_BUF_TABLE_STEP - 1) / ENH_BUF_TABLE_STEP);
859 #define select_enhancement_buf(psx_gpu) \
860 psx_gpu->enhancement_current_buf_ptr = \
861 select_enhancement_buf_ptr(psx_gpu, psx_gpu->saved_viewport_start_x)
863 #define enhancement_disable() { \
864 psx_gpu->vram_out_ptr = psx_gpu->vram_ptr; \
865 psx_gpu->viewport_start_x = psx_gpu->saved_viewport_start_x; \
866 psx_gpu->viewport_start_y = psx_gpu->saved_viewport_start_y; \
867 psx_gpu->viewport_end_x = psx_gpu->saved_viewport_end_x; \
868 psx_gpu->viewport_end_y = psx_gpu->saved_viewport_end_y; \
869 psx_gpu->uvrgb_phase = 0x8000; \
872 #define enhancement_enable() { \
873 psx_gpu->vram_out_ptr = psx_gpu->enhancement_current_buf_ptr; \
874 psx_gpu->viewport_start_x = psx_gpu->saved_viewport_start_x * 2; \
875 psx_gpu->viewport_start_y = psx_gpu->saved_viewport_start_y * 2; \
876 psx_gpu->viewport_end_x = psx_gpu->saved_viewport_end_x * 2 + 1; \
877 psx_gpu->viewport_end_y = psx_gpu->saved_viewport_end_y * 2 + 1; \
878 psx_gpu->uvrgb_phase = 0x7fff; \
881 #define shift_vertices3(v) { \
890 #define unshift_vertices3(v) { \
899 #define shift_triangle_area() \
900 psx_gpu->triangle_area *= 4
903 void scale2x_tiles8(void *dst, const void *src, int w8, int h)
905 uint16_t* d = (uint16_t*)dst;
906 const uint16_t* s = (const uint16_t*)src;
910 uint16_t* d_save = d;
911 const uint16_t* s_save = s;
966 s = s_save + 1024; /* or 512? */
971 static int disable_main_render;
973 static int check_enhanced_range(psx_gpu_struct *psx_gpu, int x, int x_end)
975 // simple reject to avoid oveflowing the 1024 width
976 // (assume some offscreen render-to-texture thing)
977 if (x >= (int)(psx_gpu->saved_viewport_start_x + 512))
983 static int is_in_array(int val, int array[], int len)
986 for (i = 0; i < len; i++)
992 static int make_members_unique(int array[], int len)
995 for (i = j = 1; i < len; i++)
996 if (!is_in_array(array[i], array, j))
997 array[j++] = array[i];
999 if (array[0] > array[1]) {
1000 i = array[0]; array[0] = array[1]; array[1] = i;
1005 static void patch_u(vertex_struct *vertex_ptrs, int count, int old, int new)
1008 for (i = 0; i < count; i++)
1009 if (vertex_ptrs[i].u == old)
1010 vertex_ptrs[i].u = new;
1013 static void patch_v(vertex_struct *vertex_ptrs, int count, int old, int new)
1016 for (i = 0; i < count; i++)
1017 if (vertex_ptrs[i].v == old)
1018 vertex_ptrs[i].v = new;
1021 static void uv_hack(vertex_struct *vertex_ptrs, int vertex_count)
1025 for (i = 0; i < vertex_count; i++) {
1026 u[i] = vertex_ptrs[i].u;
1027 v[i] = vertex_ptrs[i].v;
1029 if (make_members_unique(u, vertex_count) == 2 && u[1] - u[0] >= 8) {
1030 if ((u[0] & 7) == 7) {
1031 patch_u(vertex_ptrs, vertex_count, u[0], u[0] + 1);
1032 //printf("u hack: %3u-%3u -> %3u-%3u\n", u[0], u[1], u[0]+1, u[1]);
1034 else if ((u[1] & 7) == 0 || u[1] - u[0] > 128) {
1035 patch_u(vertex_ptrs, vertex_count, u[1], u[1] - 1);
1036 //printf("u hack: %3u-%3u -> %3u-%3u\n", u[0], u[1], u[0], u[1]-1);
1039 if (make_members_unique(v, vertex_count) == 2 && ((v[0] - v[1]) & 7) == 0) {
1040 if ((v[0] & 7) == 7) {
1041 patch_v(vertex_ptrs, vertex_count, v[0], v[0] + 1);
1042 //printf("v hack: %3u-%3u -> %3u-%3u\n", v[0], v[1], v[0]+1, v[1]);
1044 else if ((v[1] & 7) == 0) {
1045 patch_v(vertex_ptrs, vertex_count, v[1], v[1] - 1);
1046 //printf("v hack: %3u-%3u -> %3u-%3u\n", v[0], v[1], v[0], v[1]-1);
1051 static void do_triangle_enhanced(psx_gpu_struct *psx_gpu,
1052 vertex_struct *vertexes, u32 current_command)
1054 vertex_struct *vertex_ptrs[3];
1056 if (!prepare_triangle(psx_gpu, vertexes, vertex_ptrs))
1059 if (!disable_main_render)
1060 render_triangle_p(psx_gpu, vertex_ptrs, current_command);
1062 if (!check_enhanced_range(psx_gpu, vertex_ptrs[0]->x, vertex_ptrs[2]->x))
1065 enhancement_enable();
1066 shift_vertices3(vertex_ptrs);
1067 shift_triangle_area();
1068 render_triangle_p(psx_gpu, vertex_ptrs, current_command);
1069 unshift_vertices3(vertex_ptrs);
1072 static void do_quad_enhanced(psx_gpu_struct *psx_gpu, vertex_struct *vertexes,
1073 u32 current_command)
1075 do_triangle_enhanced(psx_gpu, vertexes, current_command);
1076 enhancement_disable();
1077 do_triangle_enhanced(psx_gpu, &vertexes[1], current_command);
1082 #define fill_vertex(i, x_, y_, u_, v_, rgb_) \
1083 vertexes[i].x = x_; \
1084 vertexes[i].y = y_; \
1085 vertexes[i].u = u_; \
1086 vertexes[i].v = v_; \
1087 vertexes[i].r = rgb_; \
1088 vertexes[i].g = (rgb_) >> 8; \
1089 vertexes[i].b = (rgb_) >> 16
1091 static void do_sprite_enhanced(psx_gpu_struct *psx_gpu, int x, int y,
1092 u32 u, u32 v, u32 w, u32 h, u32 cmd_rgb)
1094 vertex_struct *vertex_ptrs[3];
1095 u32 flags = (cmd_rgb >> 24);
1096 u32 color = cmd_rgb & 0xffffff;
1097 u32 render_state_base_saved = psx_gpu->render_state_base;
1102 (RENDER_FLAGS_MODULATE_TEXELS | RENDER_FLAGS_BLEND |
1103 RENDER_FLAGS_TEXTURE_MAP);
1105 set_triangle_color(psx_gpu, color);
1106 if(color == 0x808080)
1107 flags |= RENDER_FLAGS_MODULATE_TEXELS;
1109 psx_gpu->render_state_base &= ~RENDER_STATE_DITHER;
1110 enhancement_enable();
1117 if (u1 < u) u1 = 0xff;
1118 if (v1 < v) v1 = 0xff;
1123 fill_vertex(0, x, y, u, v, color);
1124 fill_vertex(1, x, y1, u, v1, color);
1125 fill_vertex(2, x1, y, u1, v, color);
1126 if (prepare_triangle(psx_gpu, vertexes, vertex_ptrs)) {
1127 shift_vertices3(vertex_ptrs);
1128 shift_triangle_area();
1129 render_triangle_p(psx_gpu, vertex_ptrs, flags);
1135 fill_vertex(0, x1, y, u1, v, color);
1136 fill_vertex(1, x, y1, u, v1, color);
1137 fill_vertex(2, x1, y1, u1, v1, color);
1138 if (prepare_triangle(psx_gpu, vertexes, vertex_ptrs)) {
1139 shift_vertices3(vertex_ptrs);
1140 shift_triangle_area();
1141 render_triangle_p(psx_gpu, vertex_ptrs, flags);
1144 psx_gpu->render_state_base = render_state_base_saved;
1147 static void do_sprite_enhanced(psx_gpu_struct *psx_gpu, int x, int y,
1148 u32 u, u32 v, u32 w, u32 h, u32 cmd_rgb)
1150 u32 flags = (cmd_rgb >> 24);
1151 u32 color = cmd_rgb & 0xffffff;
1153 render_sprite_4x(psx_gpu, x, y, u, v, w, h, flags, color);
1157 u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size,
1160 vertex_struct vertexes[4] __attribute__((aligned(16))) = {};
1161 u32 current_command = 0, command_length;
1163 u32 *list_start = list;
1164 u32 *list_end = list + (size / 4);
1166 psx_gpu->saved_viewport_start_x = psx_gpu->viewport_start_x;
1167 psx_gpu->saved_viewport_start_y = psx_gpu->viewport_start_y;
1168 psx_gpu->saved_viewport_end_x = psx_gpu->viewport_end_x;
1169 psx_gpu->saved_viewport_end_y = psx_gpu->viewport_end_y;
1170 select_enhancement_buf(psx_gpu);
1172 for(; list < list_end; list += 1 + command_length)
1174 s16 *list_s16 = (void *)list;
1175 current_command = *list >> 24;
1176 command_length = command_lengths[current_command];
1177 if (list + 1 + command_length > list_end) {
1178 current_command = (u32)-1;
1182 enhancement_disable();
1184 switch(current_command)
1191 u32 x = list_s16[2] & 0x3FF;
1192 u32 y = list_s16[3] & 0x1FF;
1193 u32 width = list_s16[4] & 0x3FF;
1194 u32 height = list_s16[5] & 0x1FF;
1195 u32 color = list[0] & 0xFFFFFF;
1199 width = ((width + 0xF) & ~0xF);
1200 if (width == 0 || height == 0)
1203 do_fill(psx_gpu, x, y, width, height, color);
1205 i1 = select_enhancement_buf_index(psx_gpu, x);
1206 i2 = select_enhancement_buf_index(psx_gpu, x + width - 1);
1208 sync_enhancement_buffers(x, y, width, height);
1211 if (x >= psx_gpu->enhancement_buf_start[i1] + psx_gpu->saved_hres)
1214 psx_gpu->vram_out_ptr = select_enhancement_buf_ptr(psx_gpu, x);
1219 render_block_fill_enh(psx_gpu, color, x, y, width, height);
1225 set_triangle_color(psx_gpu, list[0] & 0xFFFFFF);
1227 get_vertex_data_xy(0, 2);
1228 get_vertex_data_xy(1, 4);
1229 get_vertex_data_xy(2, 6);
1231 do_triangle_enhanced(psx_gpu, vertexes, current_command);
1237 set_clut(psx_gpu, list_s16[5]);
1238 set_texture(psx_gpu, list_s16[9]);
1239 set_triangle_color(psx_gpu, list[0] & 0xFFFFFF);
1241 get_vertex_data_xy_uv(0, 2);
1242 get_vertex_data_xy_uv(1, 6);
1243 get_vertex_data_xy_uv(2, 10);
1245 do_triangle_enhanced(psx_gpu, vertexes, current_command);
1251 set_triangle_color(psx_gpu, list[0] & 0xFFFFFF);
1253 get_vertex_data_xy(0, 2);
1254 get_vertex_data_xy(1, 4);
1255 get_vertex_data_xy(2, 6);
1256 get_vertex_data_xy(3, 8);
1258 do_quad_enhanced(psx_gpu, vertexes, current_command);
1264 set_clut(psx_gpu, list_s16[5]);
1265 set_texture(psx_gpu, list_s16[9]);
1266 set_triangle_color(psx_gpu, list[0] & 0xFFFFFF);
1268 get_vertex_data_xy_uv(0, 2);
1269 get_vertex_data_xy_uv(1, 6);
1270 get_vertex_data_xy_uv(2, 10);
1271 get_vertex_data_xy_uv(3, 14);
1273 uv_hack(vertexes, 4);
1274 do_quad_enhanced(psx_gpu, vertexes, current_command);
1280 get_vertex_data_xy_rgb(0, 0);
1281 get_vertex_data_xy_rgb(1, 4);
1282 get_vertex_data_xy_rgb(2, 8);
1284 do_triangle_enhanced(psx_gpu, vertexes, current_command);
1293 set_clut(psx_gpu, list_s16[5]);
1294 set_texture(psx_gpu, list_s16[11]);
1296 get_vertex_data_xy_uv_rgb(0, 0);
1297 get_vertex_data_xy_uv_rgb(1, 6);
1298 get_vertex_data_xy_uv_rgb(2, 12);
1300 do_triangle_enhanced(psx_gpu, vertexes, current_command);
1309 get_vertex_data_xy_rgb(0, 0);
1310 get_vertex_data_xy_rgb(1, 4);
1311 get_vertex_data_xy_rgb(2, 8);
1312 get_vertex_data_xy_rgb(3, 12);
1314 do_quad_enhanced(psx_gpu, vertexes, current_command);
1323 set_clut(psx_gpu, list_s16[5]);
1324 set_texture(psx_gpu, list_s16[11]);
1326 get_vertex_data_xy_uv_rgb(0, 0);
1327 get_vertex_data_xy_uv_rgb(1, 6);
1328 get_vertex_data_xy_uv_rgb(2, 12);
1329 get_vertex_data_xy_uv_rgb(3, 18);
1331 uv_hack(vertexes, 4);
1332 do_quad_enhanced(psx_gpu, vertexes, current_command);
1338 vertexes[0].x = list_s16[2] + psx_gpu->offset_x;
1339 vertexes[0].y = list_s16[3] + psx_gpu->offset_y;
1340 vertexes[1].x = list_s16[4] + psx_gpu->offset_x;
1341 vertexes[1].y = list_s16[5] + psx_gpu->offset_y;
1343 render_line(psx_gpu, vertexes, current_command, list[0], 0);
1344 enhancement_enable();
1345 render_line(psx_gpu, vertexes, current_command, list[0], 1);
1351 u32 num_vertexes = 1;
1352 u32 *list_position = &(list[2]);
1355 vertexes[1].x = (xy & 0xFFFF) + psx_gpu->offset_x;
1356 vertexes[1].y = (xy >> 16) + psx_gpu->offset_y;
1358 xy = *list_position;
1361 vertexes[0] = vertexes[1];
1363 vertexes[1].x = (xy & 0xFFFF) + psx_gpu->offset_x;
1364 vertexes[1].y = (xy >> 16) + psx_gpu->offset_y;
1366 enhancement_disable();
1367 render_line(psx_gpu, vertexes, current_command, list[0], 0);
1368 enhancement_enable();
1369 render_line(psx_gpu, vertexes, current_command, list[0], 1);
1374 if(list_position >= list_end)
1376 current_command = (u32)-1;
1380 xy = *list_position;
1381 if((xy & 0xF000F000) == 0x50005000)
1385 command_length += (num_vertexes - 2);
1391 vertexes[0].r = list[0] & 0xFF;
1392 vertexes[0].g = (list[0] >> 8) & 0xFF;
1393 vertexes[0].b = (list[0] >> 16) & 0xFF;
1394 vertexes[0].x = list_s16[2] + psx_gpu->offset_x;
1395 vertexes[0].y = list_s16[3] + psx_gpu->offset_y;
1397 vertexes[1].r = list[2] & 0xFF;
1398 vertexes[1].g = (list[2] >> 8) & 0xFF;
1399 vertexes[1].b = (list[2] >> 16) & 0xFF;
1400 vertexes[1].x = list_s16[6] + psx_gpu->offset_x;
1401 vertexes[1].y = list_s16[7] + psx_gpu->offset_y;
1403 render_line(psx_gpu, vertexes, current_command, 0, 0);
1404 enhancement_enable();
1405 render_line(psx_gpu, vertexes, current_command, 0, 1);
1411 u32 num_vertexes = 1;
1412 u32 *list_position = &(list[2]);
1413 u32 color = list[0];
1416 vertexes[1].r = color & 0xFF;
1417 vertexes[1].g = (color >> 8) & 0xFF;
1418 vertexes[1].b = (color >> 16) & 0xFF;
1419 vertexes[1].x = (xy & 0xFFFF) + psx_gpu->offset_x;
1420 vertexes[1].y = (xy >> 16) + psx_gpu->offset_y;
1422 color = list_position[0];
1425 xy = list_position[1];
1427 vertexes[0] = vertexes[1];
1429 vertexes[1].r = color & 0xFF;
1430 vertexes[1].g = (color >> 8) & 0xFF;
1431 vertexes[1].b = (color >> 16) & 0xFF;
1432 vertexes[1].x = (xy & 0xFFFF) + psx_gpu->offset_x;
1433 vertexes[1].y = (xy >> 16) + psx_gpu->offset_y;
1435 enhancement_disable();
1436 render_line(psx_gpu, vertexes, current_command, 0, 0);
1437 enhancement_enable();
1438 render_line(psx_gpu, vertexes, current_command, 0, 1);
1443 if(list_position >= list_end)
1445 current_command = (u32)-1;
1449 color = list_position[0];
1450 if((color & 0xF000F000) == 0x50005000)
1454 command_length += ((num_vertexes - 2) * 2);
1460 u32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
1461 u32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
1462 u32 width = list_s16[4] & 0x3FF;
1463 u32 height = list_s16[5] & 0x1FF;
1465 render_sprite(psx_gpu, x, y, 0, 0, width, height, current_command, list[0]);
1467 if (check_enhanced_range(psx_gpu, x, x + width))
1468 do_sprite_enhanced(psx_gpu, x, y, 0, 0, width, height, list[0]);
1474 u32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
1475 u32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
1477 u8 v = list_s16[4] >> 8;
1478 u32 width = list_s16[6] & 0x3FF;
1479 u32 height = list_s16[7] & 0x1FF;
1481 set_clut(psx_gpu, list_s16[5]);
1483 render_sprite(psx_gpu, x, y, u, v, width, height,
1484 current_command, list[0]);
1486 if (check_enhanced_range(psx_gpu, x, x + width))
1487 do_sprite_enhanced(psx_gpu, x, y, u, v, width, height, list[0]);
1496 s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
1497 s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
1499 render_sprite(psx_gpu, x, y, 0, 0, 1, 1, current_command, list[0]);
1501 if (check_enhanced_range(psx_gpu, x, x + 1))
1502 do_sprite_enhanced(psx_gpu, x, y, 0, 0, 1, 1, list[0]);
1511 s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
1512 s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
1514 render_sprite(psx_gpu, x, y, 0, 0, 8, 8, current_command, list[0]);
1516 if (check_enhanced_range(psx_gpu, x, x + 8))
1517 do_sprite_enhanced(psx_gpu, x, y, 0, 0, 8, 8, list[0]);
1526 s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
1527 s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
1529 u8 v = list_s16[4] >> 8;
1531 set_clut(psx_gpu, list_s16[5]);
1533 render_sprite(psx_gpu, x, y, u, v, 8, 8,
1534 current_command, list[0]);
1536 if (check_enhanced_range(psx_gpu, x, x + 8))
1537 do_sprite_enhanced(psx_gpu, x, y, u, v, 8, 8, list[0]);
1546 s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
1547 s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
1549 render_sprite(psx_gpu, x, y, 0, 0, 16, 16, current_command, list[0]);
1551 if (check_enhanced_range(psx_gpu, x, x + 16))
1552 do_sprite_enhanced(psx_gpu, x, y, 0, 0, 16, 16, list[0]);
1561 s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
1562 s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
1564 u8 v = list_s16[4] >> 8;
1566 set_clut(psx_gpu, list_s16[5]);
1568 render_sprite(psx_gpu, x, y, u, v, 16, 16, current_command, list[0]);
1570 if (check_enhanced_range(psx_gpu, x, x + 16))
1571 do_sprite_enhanced(psx_gpu, x, y, u, v, 16, 16, list[0]);
1575 case 0x80: // vid -> vid
1577 u32 sx = list_s16[2] & 0x3FF;
1578 u32 sy = list_s16[3] & 0x1FF;
1579 u32 dx = list_s16[4] & 0x3FF;
1580 u32 dy = list_s16[5] & 0x1FF;
1581 u32 w = ((list_s16[6] - 1) & 0x3FF) + 1;
1582 u32 h = ((list_s16[7] - 1) & 0x1FF) + 1;
1584 if (sx == dx && sy == dy && psx_gpu->mask_msb == 0)
1587 render_block_move(psx_gpu, sx, sy, dx, dy, w, h);
1588 sync_enhancement_buffers(dx, dy, w, h);
1592 case 0xA0: // sys -> vid
1593 case 0xC0: // vid -> sys
1597 set_texture(psx_gpu, list[0]);
1599 if(list[0] & (1 << 9))
1600 psx_gpu->render_state_base |= RENDER_STATE_DITHER;
1602 psx_gpu->render_state_base &= ~RENDER_STATE_DITHER;
1604 psx_gpu->display_area_draw_enable = (list[0] >> 10) & 0x1;
1611 u32 texture_window_settings = list[0];
1612 u32 tmp, x, y, w, h;
1614 if(texture_window_settings != psx_gpu->texture_window_settings)
1616 tmp = (texture_window_settings & 0x1F) | 0x20;
1617 for(w = 8; (tmp & 1) == 0; tmp >>= 1, w <<= 1);
1619 tmp = ((texture_window_settings >> 5) & 0x1f) | 0x20;
1620 for (h = 8; (tmp & 1) == 0; tmp >>= 1, h <<= 1);
1622 tmp = 32 - (w >> 3);
1623 x = ((texture_window_settings >> 10) & tmp) << 3;
1625 tmp = 32 - (h >> 3);
1626 y = ((texture_window_settings >> 15) & tmp) << 3;
1628 flush_render_block_buffer(psx_gpu);
1630 psx_gpu->texture_window_settings = texture_window_settings;
1631 psx_gpu->texture_window_x = x;
1632 psx_gpu->texture_window_y = y;
1633 psx_gpu->texture_mask_width = w - 1;
1634 psx_gpu->texture_mask_height = h - 1;
1636 update_texture_ptr(psx_gpu);
1644 s16 viewport_start_x = list[0] & 0x3FF;
1645 s16 viewport_start_y = (list[0] >> 10) & 0x1FF;
1649 if(viewport_start_x == psx_gpu->viewport_start_x &&
1650 viewport_start_y == psx_gpu->viewport_start_y)
1654 psx_gpu->viewport_start_x = viewport_start_x;
1655 psx_gpu->viewport_start_y = viewport_start_y;
1656 psx_gpu->saved_viewport_start_x = viewport_start_x;
1657 psx_gpu->saved_viewport_start_y = viewport_start_y;
1659 w = (u32)psx_gpu->viewport_end_x - (u32)viewport_start_x + 1;
1660 d = psx_gpu->saved_hres - w;
1661 if(-16 <= d && d <= 16)
1663 update_enhancement_buf_table_from_x(psx_gpu,
1664 viewport_start_x, w);
1666 select_enhancement_buf(psx_gpu);
1668 #ifdef TEXTURE_CACHE_4BPP
1669 psx_gpu->viewport_mask =
1670 texture_region_mask(psx_gpu->viewport_start_x,
1671 psx_gpu->viewport_start_y, psx_gpu->viewport_end_x,
1672 psx_gpu->viewport_end_y);
1680 s16 viewport_end_x = list[0] & 0x3FF;
1681 s16 viewport_end_y = (list[0] >> 10) & 0x1FF;
1685 if(viewport_end_x == psx_gpu->viewport_end_x &&
1686 viewport_end_y == psx_gpu->viewport_end_y)
1691 psx_gpu->viewport_end_x = viewport_end_x;
1692 psx_gpu->viewport_end_y = viewport_end_y;
1693 psx_gpu->saved_viewport_end_x = viewport_end_x;
1694 psx_gpu->saved_viewport_end_y = viewport_end_y;
1696 w = (u32)viewport_end_x - (u32)psx_gpu->viewport_start_x + 1;
1697 d = psx_gpu->saved_hres - w;
1698 if(-16 <= d && d <= 16)
1700 update_enhancement_buf_table_from_x(psx_gpu,
1701 psx_gpu->viewport_start_x, w);
1703 select_enhancement_buf(psx_gpu);
1705 #ifdef TEXTURE_CACHE_4BPP
1706 psx_gpu->viewport_mask =
1707 texture_region_mask(psx_gpu->viewport_start_x,
1708 psx_gpu->viewport_start_y, psx_gpu->viewport_end_x,
1709 psx_gpu->viewport_end_y);
1717 s32 offset_x = list[0] << 21;
1718 s32 offset_y = list[0] << 10;
1719 psx_gpu->offset_x = offset_x >> 21;
1720 psx_gpu->offset_y = offset_y >> 21;
1728 u32 mask_settings = list[0];
1729 u16 mask_msb = mask_settings << 15;
1732 psx_gpu->render_state_base |= RENDER_STATE_MASK_EVALUATE;
1734 psx_gpu->render_state_base &= ~RENDER_STATE_MASK_EVALUATE;
1736 if(mask_msb != psx_gpu->mask_msb)
1738 flush_render_block_buffer(psx_gpu);
1739 psx_gpu->mask_msb = mask_msb;
1751 enhancement_disable();
1754 if (last_command != NULL)
1755 *last_command = current_command;
1756 return list - list_start;
1761 // vim:ts=2:shiftwidth=2:expandtab