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 // reject to avoid oveflowing the 1024 width
976 // (assume some offscreen render-to-texture thing)
980 fb_index = select_enhancement_buf_index(psx_gpu, x);
981 if (x >= psx_gpu->enhancement_buf_start[fb_index] + 512)
987 static int is_in_array(int val, int array[], int len)
990 for (i = 0; i < len; i++)
996 static int make_members_unique(int array[], int len)
999 for (i = j = 1; i < len; i++)
1000 if (!is_in_array(array[i], array, j))
1001 array[j++] = array[i];
1003 if (array[0] > array[1]) {
1004 i = array[0]; array[0] = array[1]; array[1] = i;
1009 static void patch_u(vertex_struct *vertex_ptrs, int count, int old, int new)
1012 for (i = 0; i < count; i++)
1013 if (vertex_ptrs[i].u == old)
1014 vertex_ptrs[i].u = new;
1017 static void patch_v(vertex_struct *vertex_ptrs, int count, int old, int new)
1020 for (i = 0; i < count; i++)
1021 if (vertex_ptrs[i].v == old)
1022 vertex_ptrs[i].v = new;
1025 static void uv_hack(vertex_struct *vertex_ptrs, int vertex_count)
1029 for (i = 0; i < vertex_count; i++) {
1030 u[i] = vertex_ptrs[i].u;
1031 v[i] = vertex_ptrs[i].v;
1033 if (make_members_unique(u, vertex_count) == 2 && u[1] - u[0] >= 8) {
1034 if ((u[0] & 7) == 7) {
1035 patch_u(vertex_ptrs, vertex_count, u[0], u[0] + 1);
1036 //printf("u hack: %3u-%3u -> %3u-%3u\n", u[0], u[1], u[0]+1, u[1]);
1038 else if ((u[1] & 7) == 0 || u[1] - u[0] > 128) {
1039 patch_u(vertex_ptrs, vertex_count, u[1], u[1] - 1);
1040 //printf("u hack: %3u-%3u -> %3u-%3u\n", u[0], u[1], u[0], u[1]-1);
1043 if (make_members_unique(v, vertex_count) == 2 && ((v[0] - v[1]) & 7) == 0) {
1044 if ((v[0] & 7) == 7) {
1045 patch_v(vertex_ptrs, vertex_count, v[0], v[0] + 1);
1046 //printf("v hack: %3u-%3u -> %3u-%3u\n", v[0], v[1], v[0]+1, v[1]);
1048 else if ((v[1] & 7) == 0) {
1049 patch_v(vertex_ptrs, vertex_count, v[1], v[1] - 1);
1050 //printf("v hack: %3u-%3u -> %3u-%3u\n", v[0], v[1], v[0], v[1]-1);
1055 static void do_triangle_enhanced(psx_gpu_struct *psx_gpu,
1056 vertex_struct *vertexes, u32 current_command)
1058 vertex_struct *vertex_ptrs[3];
1060 if (!prepare_triangle(psx_gpu, vertexes, vertex_ptrs))
1063 if (!disable_main_render)
1064 render_triangle_p(psx_gpu, vertex_ptrs, current_command);
1066 if (!check_enhanced_range(psx_gpu, vertex_ptrs[0]->x, vertex_ptrs[2]->x))
1069 enhancement_enable();
1070 shift_vertices3(vertex_ptrs);
1071 shift_triangle_area();
1072 render_triangle_p(psx_gpu, vertex_ptrs, current_command);
1073 unshift_vertices3(vertex_ptrs);
1076 static void do_quad_enhanced(psx_gpu_struct *psx_gpu, vertex_struct *vertexes,
1077 u32 current_command)
1079 do_triangle_enhanced(psx_gpu, vertexes, current_command);
1080 enhancement_disable();
1081 do_triangle_enhanced(psx_gpu, &vertexes[1], current_command);
1086 #define fill_vertex(i, x_, y_, u_, v_, rgb_) \
1087 vertexes[i].x = x_; \
1088 vertexes[i].y = y_; \
1089 vertexes[i].u = u_; \
1090 vertexes[i].v = v_; \
1091 vertexes[i].r = rgb_; \
1092 vertexes[i].g = (rgb_) >> 8; \
1093 vertexes[i].b = (rgb_) >> 16
1095 static void do_sprite_enhanced(psx_gpu_struct *psx_gpu, int x, int y,
1096 u32 u, u32 v, u32 w, u32 h, u32 cmd_rgb)
1098 vertex_struct *vertex_ptrs[3];
1099 u32 flags = (cmd_rgb >> 24);
1100 u32 color = cmd_rgb & 0xffffff;
1101 u32 render_state_base_saved = psx_gpu->render_state_base;
1106 (RENDER_FLAGS_MODULATE_TEXELS | RENDER_FLAGS_BLEND |
1107 RENDER_FLAGS_TEXTURE_MAP);
1109 set_triangle_color(psx_gpu, color);
1110 if(color == 0x808080)
1111 flags |= RENDER_FLAGS_MODULATE_TEXELS;
1113 psx_gpu->render_state_base &= ~RENDER_STATE_DITHER;
1114 enhancement_enable();
1121 if (u1 < u) u1 = 0xff;
1122 if (v1 < v) v1 = 0xff;
1127 fill_vertex(0, x, y, u, v, color);
1128 fill_vertex(1, x, y1, u, v1, color);
1129 fill_vertex(2, x1, y, u1, v, color);
1130 if (prepare_triangle(psx_gpu, vertexes, vertex_ptrs)) {
1131 shift_vertices3(vertex_ptrs);
1132 shift_triangle_area();
1133 render_triangle_p(psx_gpu, vertex_ptrs, flags);
1139 fill_vertex(0, x1, y, u1, v, color);
1140 fill_vertex(1, x, y1, u, v1, color);
1141 fill_vertex(2, x1, y1, u1, v1, color);
1142 if (prepare_triangle(psx_gpu, vertexes, vertex_ptrs)) {
1143 shift_vertices3(vertex_ptrs);
1144 shift_triangle_area();
1145 render_triangle_p(psx_gpu, vertex_ptrs, flags);
1148 psx_gpu->render_state_base = render_state_base_saved;
1151 static void do_sprite_enhanced(psx_gpu_struct *psx_gpu, int x, int y,
1152 u32 u, u32 v, u32 w, u32 h, u32 cmd_rgb)
1154 u32 flags = (cmd_rgb >> 24);
1155 u32 color = cmd_rgb & 0xffffff;
1157 render_sprite_4x(psx_gpu, x, y, u, v, w, h, flags, color);
1161 u32 gpu_parse_enhanced(psx_gpu_struct *psx_gpu, u32 *list, u32 size,
1164 vertex_struct vertexes[4] __attribute__((aligned(16))) = {};
1165 u32 current_command = 0, command_length;
1167 u32 *list_start = list;
1168 u32 *list_end = list + (size / 4);
1170 psx_gpu->saved_viewport_start_x = psx_gpu->viewport_start_x;
1171 psx_gpu->saved_viewport_start_y = psx_gpu->viewport_start_y;
1172 psx_gpu->saved_viewport_end_x = psx_gpu->viewport_end_x;
1173 psx_gpu->saved_viewport_end_y = psx_gpu->viewport_end_y;
1174 select_enhancement_buf(psx_gpu);
1176 for(; list < list_end; list += 1 + command_length)
1178 s16 *list_s16 = (void *)list;
1179 current_command = *list >> 24;
1180 command_length = command_lengths[current_command];
1181 if (list + 1 + command_length > list_end) {
1182 current_command = (u32)-1;
1186 enhancement_disable();
1188 switch(current_command)
1195 u32 x = list_s16[2] & 0x3FF;
1196 u32 y = list_s16[3] & 0x1FF;
1197 u32 width = list_s16[4] & 0x3FF;
1198 u32 height = list_s16[5] & 0x1FF;
1199 u32 color = list[0] & 0xFFFFFF;
1203 width = ((width + 0xF) & ~0xF);
1204 if (width == 0 || height == 0)
1207 do_fill(psx_gpu, x, y, width, height, color);
1209 i1 = select_enhancement_buf_index(psx_gpu, x);
1210 i2 = select_enhancement_buf_index(psx_gpu, x + width - 1);
1212 sync_enhancement_buffers(x, y, width, height);
1215 if (x >= psx_gpu->enhancement_buf_start[i1] + psx_gpu->saved_hres)
1218 psx_gpu->vram_out_ptr = select_enhancement_buf_ptr(psx_gpu, x);
1223 render_block_fill_enh(psx_gpu, color, x, y, width, height);
1229 set_triangle_color(psx_gpu, list[0] & 0xFFFFFF);
1231 get_vertex_data_xy(0, 2);
1232 get_vertex_data_xy(1, 4);
1233 get_vertex_data_xy(2, 6);
1235 do_triangle_enhanced(psx_gpu, vertexes, current_command);
1241 set_clut(psx_gpu, list_s16[5]);
1242 set_texture(psx_gpu, list_s16[9]);
1243 set_triangle_color(psx_gpu, list[0] & 0xFFFFFF);
1245 get_vertex_data_xy_uv(0, 2);
1246 get_vertex_data_xy_uv(1, 6);
1247 get_vertex_data_xy_uv(2, 10);
1249 do_triangle_enhanced(psx_gpu, vertexes, current_command);
1255 set_triangle_color(psx_gpu, list[0] & 0xFFFFFF);
1257 get_vertex_data_xy(0, 2);
1258 get_vertex_data_xy(1, 4);
1259 get_vertex_data_xy(2, 6);
1260 get_vertex_data_xy(3, 8);
1262 do_quad_enhanced(psx_gpu, vertexes, current_command);
1268 set_clut(psx_gpu, list_s16[5]);
1269 set_texture(psx_gpu, list_s16[9]);
1270 set_triangle_color(psx_gpu, list[0] & 0xFFFFFF);
1272 get_vertex_data_xy_uv(0, 2);
1273 get_vertex_data_xy_uv(1, 6);
1274 get_vertex_data_xy_uv(2, 10);
1275 get_vertex_data_xy_uv(3, 14);
1277 uv_hack(vertexes, 4);
1278 do_quad_enhanced(psx_gpu, vertexes, current_command);
1284 get_vertex_data_xy_rgb(0, 0);
1285 get_vertex_data_xy_rgb(1, 4);
1286 get_vertex_data_xy_rgb(2, 8);
1288 do_triangle_enhanced(psx_gpu, vertexes, current_command);
1297 set_clut(psx_gpu, list_s16[5]);
1298 set_texture(psx_gpu, list_s16[11]);
1300 get_vertex_data_xy_uv_rgb(0, 0);
1301 get_vertex_data_xy_uv_rgb(1, 6);
1302 get_vertex_data_xy_uv_rgb(2, 12);
1304 do_triangle_enhanced(psx_gpu, vertexes, current_command);
1313 get_vertex_data_xy_rgb(0, 0);
1314 get_vertex_data_xy_rgb(1, 4);
1315 get_vertex_data_xy_rgb(2, 8);
1316 get_vertex_data_xy_rgb(3, 12);
1318 do_quad_enhanced(psx_gpu, vertexes, current_command);
1327 set_clut(psx_gpu, list_s16[5]);
1328 set_texture(psx_gpu, list_s16[11]);
1330 get_vertex_data_xy_uv_rgb(0, 0);
1331 get_vertex_data_xy_uv_rgb(1, 6);
1332 get_vertex_data_xy_uv_rgb(2, 12);
1333 get_vertex_data_xy_uv_rgb(3, 18);
1335 uv_hack(vertexes, 4);
1336 do_quad_enhanced(psx_gpu, vertexes, current_command);
1342 vertexes[0].x = list_s16[2] + psx_gpu->offset_x;
1343 vertexes[0].y = list_s16[3] + psx_gpu->offset_y;
1344 vertexes[1].x = list_s16[4] + psx_gpu->offset_x;
1345 vertexes[1].y = list_s16[5] + psx_gpu->offset_y;
1347 render_line(psx_gpu, vertexes, current_command, list[0], 0);
1348 enhancement_enable();
1349 render_line(psx_gpu, vertexes, current_command, list[0], 1);
1355 u32 num_vertexes = 1;
1356 u32 *list_position = &(list[2]);
1359 vertexes[1].x = (xy & 0xFFFF) + psx_gpu->offset_x;
1360 vertexes[1].y = (xy >> 16) + psx_gpu->offset_y;
1362 xy = *list_position;
1365 vertexes[0] = vertexes[1];
1367 vertexes[1].x = (xy & 0xFFFF) + psx_gpu->offset_x;
1368 vertexes[1].y = (xy >> 16) + psx_gpu->offset_y;
1370 enhancement_disable();
1371 render_line(psx_gpu, vertexes, current_command, list[0], 0);
1372 enhancement_enable();
1373 render_line(psx_gpu, vertexes, current_command, list[0], 1);
1378 if(list_position >= list_end)
1380 current_command = (u32)-1;
1384 xy = *list_position;
1385 if((xy & 0xF000F000) == 0x50005000)
1389 command_length += (num_vertexes - 2);
1395 vertexes[0].r = list[0] & 0xFF;
1396 vertexes[0].g = (list[0] >> 8) & 0xFF;
1397 vertexes[0].b = (list[0] >> 16) & 0xFF;
1398 vertexes[0].x = list_s16[2] + psx_gpu->offset_x;
1399 vertexes[0].y = list_s16[3] + psx_gpu->offset_y;
1401 vertexes[1].r = list[2] & 0xFF;
1402 vertexes[1].g = (list[2] >> 8) & 0xFF;
1403 vertexes[1].b = (list[2] >> 16) & 0xFF;
1404 vertexes[1].x = list_s16[6] + psx_gpu->offset_x;
1405 vertexes[1].y = list_s16[7] + psx_gpu->offset_y;
1407 render_line(psx_gpu, vertexes, current_command, 0, 0);
1408 enhancement_enable();
1409 render_line(psx_gpu, vertexes, current_command, 0, 1);
1415 u32 num_vertexes = 1;
1416 u32 *list_position = &(list[2]);
1417 u32 color = list[0];
1420 vertexes[1].r = color & 0xFF;
1421 vertexes[1].g = (color >> 8) & 0xFF;
1422 vertexes[1].b = (color >> 16) & 0xFF;
1423 vertexes[1].x = (xy & 0xFFFF) + psx_gpu->offset_x;
1424 vertexes[1].y = (xy >> 16) + psx_gpu->offset_y;
1426 color = list_position[0];
1429 xy = list_position[1];
1431 vertexes[0] = vertexes[1];
1433 vertexes[1].r = color & 0xFF;
1434 vertexes[1].g = (color >> 8) & 0xFF;
1435 vertexes[1].b = (color >> 16) & 0xFF;
1436 vertexes[1].x = (xy & 0xFFFF) + psx_gpu->offset_x;
1437 vertexes[1].y = (xy >> 16) + psx_gpu->offset_y;
1439 enhancement_disable();
1440 render_line(psx_gpu, vertexes, current_command, 0, 0);
1441 enhancement_enable();
1442 render_line(psx_gpu, vertexes, current_command, 0, 1);
1447 if(list_position >= list_end)
1449 current_command = (u32)-1;
1453 color = list_position[0];
1454 if((color & 0xF000F000) == 0x50005000)
1458 command_length += ((num_vertexes - 2) * 2);
1464 u32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
1465 u32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
1466 u32 width = list_s16[4] & 0x3FF;
1467 u32 height = list_s16[5] & 0x1FF;
1469 render_sprite(psx_gpu, x, y, 0, 0, width, height, current_command, list[0]);
1471 if (check_enhanced_range(psx_gpu, x, x + width))
1472 do_sprite_enhanced(psx_gpu, x, y, 0, 0, width, height, list[0]);
1478 u32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
1479 u32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
1481 u8 v = list_s16[4] >> 8;
1482 u32 width = list_s16[6] & 0x3FF;
1483 u32 height = list_s16[7] & 0x1FF;
1485 set_clut(psx_gpu, list_s16[5]);
1487 render_sprite(psx_gpu, x, y, u, v, width, height,
1488 current_command, list[0]);
1490 if (check_enhanced_range(psx_gpu, x, x + width))
1491 do_sprite_enhanced(psx_gpu, x, y, u, v, width, height, list[0]);
1500 s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
1501 s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
1503 render_sprite(psx_gpu, x, y, 0, 0, 1, 1, current_command, list[0]);
1505 if (check_enhanced_range(psx_gpu, x, x + 1))
1506 do_sprite_enhanced(psx_gpu, x, y, 0, 0, 1, 1, list[0]);
1515 s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
1516 s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
1518 render_sprite(psx_gpu, x, y, 0, 0, 8, 8, current_command, list[0]);
1520 if (check_enhanced_range(psx_gpu, x, x + 8))
1521 do_sprite_enhanced(psx_gpu, x, y, 0, 0, 8, 8, list[0]);
1530 s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
1531 s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
1533 u8 v = list_s16[4] >> 8;
1535 set_clut(psx_gpu, list_s16[5]);
1537 render_sprite(psx_gpu, x, y, u, v, 8, 8,
1538 current_command, list[0]);
1540 if (check_enhanced_range(psx_gpu, x, x + 8))
1541 do_sprite_enhanced(psx_gpu, x, y, u, v, 8, 8, list[0]);
1550 s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
1551 s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
1553 render_sprite(psx_gpu, x, y, 0, 0, 16, 16, current_command, list[0]);
1555 if (check_enhanced_range(psx_gpu, x, x + 16))
1556 do_sprite_enhanced(psx_gpu, x, y, 0, 0, 16, 16, list[0]);
1565 s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x);
1566 s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y);
1568 u8 v = list_s16[4] >> 8;
1570 set_clut(psx_gpu, list_s16[5]);
1572 render_sprite(psx_gpu, x, y, u, v, 16, 16, current_command, list[0]);
1574 if (check_enhanced_range(psx_gpu, x, x + 16))
1575 do_sprite_enhanced(psx_gpu, x, y, u, v, 16, 16, list[0]);
1579 case 0x80: // vid -> vid
1581 u32 sx = list_s16[2] & 0x3FF;
1582 u32 sy = list_s16[3] & 0x1FF;
1583 u32 dx = list_s16[4] & 0x3FF;
1584 u32 dy = list_s16[5] & 0x1FF;
1585 u32 w = ((list_s16[6] - 1) & 0x3FF) + 1;
1586 u32 h = ((list_s16[7] - 1) & 0x1FF) + 1;
1588 if (sx == dx && sy == dy && psx_gpu->mask_msb == 0)
1591 render_block_move(psx_gpu, sx, sy, dx, dy, w, h);
1592 sync_enhancement_buffers(dx, dy, w, h);
1596 case 0xA0: // sys -> vid
1597 case 0xC0: // vid -> sys
1601 set_texture(psx_gpu, list[0]);
1603 if(list[0] & (1 << 9))
1604 psx_gpu->render_state_base |= RENDER_STATE_DITHER;
1606 psx_gpu->render_state_base &= ~RENDER_STATE_DITHER;
1608 psx_gpu->display_area_draw_enable = (list[0] >> 10) & 0x1;
1615 u32 texture_window_settings = list[0];
1616 u32 tmp, x, y, w, h;
1618 if(texture_window_settings != psx_gpu->texture_window_settings)
1620 tmp = (texture_window_settings & 0x1F) | 0x20;
1621 for(w = 8; (tmp & 1) == 0; tmp >>= 1, w <<= 1);
1623 tmp = ((texture_window_settings >> 5) & 0x1f) | 0x20;
1624 for (h = 8; (tmp & 1) == 0; tmp >>= 1, h <<= 1);
1626 tmp = 32 - (w >> 3);
1627 x = ((texture_window_settings >> 10) & tmp) << 3;
1629 tmp = 32 - (h >> 3);
1630 y = ((texture_window_settings >> 15) & tmp) << 3;
1632 flush_render_block_buffer(psx_gpu);
1634 psx_gpu->texture_window_settings = texture_window_settings;
1635 psx_gpu->texture_window_x = x;
1636 psx_gpu->texture_window_y = y;
1637 psx_gpu->texture_mask_width = w - 1;
1638 psx_gpu->texture_mask_height = h - 1;
1640 update_texture_ptr(psx_gpu);
1648 s16 viewport_start_x = list[0] & 0x3FF;
1649 s16 viewport_start_y = (list[0] >> 10) & 0x1FF;
1653 if(viewport_start_x == psx_gpu->viewport_start_x &&
1654 viewport_start_y == psx_gpu->viewport_start_y)
1658 psx_gpu->viewport_start_x = viewport_start_x;
1659 psx_gpu->viewport_start_y = viewport_start_y;
1660 psx_gpu->saved_viewport_start_x = viewport_start_x;
1661 psx_gpu->saved_viewport_start_y = viewport_start_y;
1663 w = (u32)psx_gpu->viewport_end_x - (u32)viewport_start_x + 1;
1664 d = psx_gpu->saved_hres - w;
1665 if(-16 <= d && d <= 16)
1667 update_enhancement_buf_table_from_x(psx_gpu,
1668 viewport_start_x, w);
1670 select_enhancement_buf(psx_gpu);
1672 #ifdef TEXTURE_CACHE_4BPP
1673 psx_gpu->viewport_mask =
1674 texture_region_mask(psx_gpu->viewport_start_x,
1675 psx_gpu->viewport_start_y, psx_gpu->viewport_end_x,
1676 psx_gpu->viewport_end_y);
1684 s16 viewport_end_x = list[0] & 0x3FF;
1685 s16 viewport_end_y = (list[0] >> 10) & 0x1FF;
1689 if(viewport_end_x == psx_gpu->viewport_end_x &&
1690 viewport_end_y == psx_gpu->viewport_end_y)
1695 psx_gpu->viewport_end_x = viewport_end_x;
1696 psx_gpu->viewport_end_y = viewport_end_y;
1697 psx_gpu->saved_viewport_end_x = viewport_end_x;
1698 psx_gpu->saved_viewport_end_y = viewport_end_y;
1700 w = (u32)viewport_end_x - (u32)psx_gpu->viewport_start_x + 1;
1701 d = psx_gpu->saved_hres - w;
1702 if(-16 <= d && d <= 16)
1704 update_enhancement_buf_table_from_x(psx_gpu,
1705 psx_gpu->viewport_start_x, w);
1707 select_enhancement_buf(psx_gpu);
1709 #ifdef TEXTURE_CACHE_4BPP
1710 psx_gpu->viewport_mask =
1711 texture_region_mask(psx_gpu->viewport_start_x,
1712 psx_gpu->viewport_start_y, psx_gpu->viewport_end_x,
1713 psx_gpu->viewport_end_y);
1721 s32 offset_x = list[0] << 21;
1722 s32 offset_y = list[0] << 10;
1723 psx_gpu->offset_x = offset_x >> 21;
1724 psx_gpu->offset_y = offset_y >> 21;
1732 u32 mask_settings = list[0];
1733 u16 mask_msb = mask_settings << 15;
1736 psx_gpu->render_state_base |= RENDER_STATE_MASK_EVALUATE;
1738 psx_gpu->render_state_base &= ~RENDER_STATE_MASK_EVALUATE;
1740 if(mask_msb != psx_gpu->mask_msb)
1742 flush_render_block_buffer(psx_gpu);
1743 psx_gpu->mask_msb = mask_msb;
1755 enhancement_disable();
1758 if (last_command != NULL)
1759 *last_command = current_command;
1760 return list - list_start;
1765 // vim:ts=2:shiftwidth=2:expandtab