X-Git-Url: https://notaz.gp2x.de/cgi-bin/gitweb.cgi?p=pcsx_rearmed.git;a=blobdiff_plain;f=plugins%2Fgpu_neon%2Fpsx_gpu%2Fpsx_gpu_parse.c;h=920c6388381a07554b088e862ef620af7658586f;hp=2ef823d7a312067b6b7e471deae3e111c69adfc5;hb=c8eaa363acbafb84840b8d29b532ae1225d6d61c;hpb=b7ed06327bf625bdc1aa55899665f544757e9b76 diff --git a/plugins/gpu_neon/psx_gpu/psx_gpu_parse.c b/plugins/gpu_neon/psx_gpu/psx_gpu_parse.c index 2ef823d7..920c6388 100644 --- a/plugins/gpu_neon/psx_gpu/psx_gpu_parse.c +++ b/plugins/gpu_neon/psx_gpu/psx_gpu_parse.c @@ -16,6 +16,7 @@ #include "common.h" +#ifndef command_lengths const u8 command_lengths[256] = { 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 00 @@ -24,7 +25,7 @@ const u8 command_lengths[256] = 5, 5, 5, 5, 8, 8, 8, 8, 7, 7, 7, 7, 11, 11, 11, 11, // 30 2, 2, 2, 2, 2, 2, 2, 2, 3, 3, 3, 3, 3, 3, 3, 3, // 40 3, 3, 3, 3, 3, 3, 3, 3, 4, 4, 4, 4, 4, 4, 4, 4, // 50 - 2, 2, 2, 2, 3, 3, 3, 3, 1, 1, 1, 1, 1, 1, 1, 1, // 60 + 2, 2, 2, 2, 3, 3, 3, 3, 1, 1, 1, 1, 0, 0, 0, 0, // 60 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, // 70 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 80 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 90 @@ -35,6 +36,7 @@ const u8 command_lengths[256] = 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // e0 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 // f0 }; +#endif void update_texture_ptr(psx_gpu_struct *psx_gpu) { @@ -153,6 +155,13 @@ void set_triangle_color(psx_gpu_struct *psx_gpu, u32 triangle_color) #define sign_extend_12bit(value) \ (((s32)((value) << 20)) >> 20) \ +#define sign_extend_11bit(value) \ + (((s32)((value) << 21)) >> 21) \ + +#define sign_extend_10bit(value) \ + (((s32)((value) << 22)) >> 22) \ + + #define get_vertex_data_xy(vertex_number, offset16) \ vertexes[vertex_number].x = \ sign_extend_12bit(list_s16[offset16]) + psx_gpu->offset_x; \ @@ -190,12 +199,17 @@ void set_triangle_color(psx_gpu_struct *psx_gpu, u32 triangle_color) get_vertex_data_xy(vertex_number, offset16); \ set_vertex_color_constant(vertex_number, color) \ +#ifndef SET_Ex +#define SET_Ex(r, v) +#endif + vertex_struct vertexes[4] __attribute__((aligned(32))); -void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) +u32 gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size, u32 *last_command) { - u32 current_command, command_length; - + u32 current_command = 0, command_length; + + u32 *list_start = list; u32 *list_end = list + (size / 4); for(; list < list_end; list += 1 + command_length) @@ -203,16 +217,65 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) s16 *list_s16 = (void *)list; current_command = *list >> 24; command_length = command_lengths[current_command]; - + if (list + 1 + command_length > list_end) { + current_command = (u32)-1; + break; + } + switch(current_command) { case 0x00: break; case 0x02: - render_block_fill(psx_gpu, list[0] & 0xFFFFFF, list_s16[2], list_s16[3], - list_s16[4] & 0x3FF, list_s16[5] & 0x3FF); + { + u32 x = list_s16[2] & 0x3FF; + u32 y = list_s16[3] & 0x1FF; + u32 width = list_s16[4] & 0x3FF; + u32 height = list_s16[5] & 0x1FF; + u32 color = list[0] & 0xFFFFFF; + + x &= ~0xF; + width = ((width + 0xF) & ~0xF); + + if((x + width) > 1024) + { + u32 width_a = 1024 - x; + u32 width_b = width - width_a; + + if((y + height) > 512) + { + u32 height_a = 512 - y; + u32 height_b = height - height_a; + + render_block_fill(psx_gpu, color, x, y, width_a, height_a); + render_block_fill(psx_gpu, color, 0, y, width_b, height_a); + render_block_fill(psx_gpu, color, x, 0, width_a, height_b); + render_block_fill(psx_gpu, color, 0, 0, width_b, height_b); + } + else + { + render_block_fill(psx_gpu, color, x, y, width_a, height); + render_block_fill(psx_gpu, color, 0, y, width_b, height); + } + } + else + { + if((y + height) > 512) + { + u32 height_a = 512 - y; + u32 height_b = height - height_a; + + render_block_fill(psx_gpu, color, x, y, width, height_a); + render_block_fill(psx_gpu, color, x, 0, width, height_b); + } + else + { + render_block_fill(psx_gpu, color, x, y, width, height); + } + } break; + } case 0x20 ... 0x23: { @@ -221,7 +284,7 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) get_vertex_data_xy(0, 2); get_vertex_data_xy(1, 4); get_vertex_data_xy(2, 6); - + render_triangle(psx_gpu, vertexes, current_command); break; } @@ -349,27 +412,29 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) vertexes[1].x = (xy & 0xFFFF) + psx_gpu->offset_x; vertexes[1].y = (xy >> 16) + psx_gpu->offset_y; + xy = *list_position; while(1) { - xy = *list_position; - if(xy == 0x55555555) - break; - vertexes[0] = vertexes[1]; vertexes[1].x = (xy & 0xFFFF) + psx_gpu->offset_x; vertexes[1].y = (xy >> 16) + psx_gpu->offset_y; + render_line(psx_gpu, vertexes, current_command, list[0]); + list_position++; num_vertexes++; - render_line(psx_gpu, vertexes, current_command, list[0]); - } + if(list_position >= list_end) + break; - if(num_vertexes > 2) - command_length += (num_vertexes - 2); + xy = *list_position; + if((xy & 0xF000F000) == 0x50005000) + break; + } - break; + command_length += (num_vertexes - 2); + break; } case 0x50 ... 0x57: @@ -403,12 +468,9 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) vertexes[1].x = (xy & 0xFFFF) + psx_gpu->offset_x; vertexes[1].y = (xy >> 16) + psx_gpu->offset_y; + color = list_position[0]; while(1) { - color = list_position[0]; - if(color == 0x55555555) - break; - xy = list_position[1]; vertexes[0] = vertexes[1]; @@ -419,22 +481,27 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) vertexes[1].x = (xy & 0xFFFF) + psx_gpu->offset_x; vertexes[1].y = (xy >> 16) + psx_gpu->offset_y; + render_line(psx_gpu, vertexes, current_command, 0); + list_position += 2; num_vertexes++; - render_line(psx_gpu, vertexes, current_command, 0); - } + if(list_position >= list_end) + break; - if(num_vertexes > 2) - command_length += ((num_vertexes * 2) - 2); + color = list_position[0]; + if((color & 0xF000F000) == 0x50005000) + break; + } - break; + command_length += ((num_vertexes - 2) * 2); + break; } case 0x60 ... 0x63: { - u32 x = list_s16[2] + psx_gpu->offset_x; - u32 y = list_s16[3] + psx_gpu->offset_y; + u32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x); + u32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y); u32 width = list_s16[4] & 0x3FF; u32 height = list_s16[5] & 0x1FF; @@ -444,8 +511,8 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) case 0x64 ... 0x67: { - u32 x = list_s16[2] + psx_gpu->offset_x; - u32 y = list_s16[3] + psx_gpu->offset_y; + u32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x); + u32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y); u32 uv = list_s16[4]; u32 width = list_s16[6] & 0x3FF; u32 height = list_s16[7] & 0x1FF; @@ -462,8 +529,8 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) case 0x6A: case 0x6B: { - s32 x = list_s16[2] + psx_gpu->offset_x; - s32 y = list_s16[3] + psx_gpu->offset_y; + s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x); + s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y); render_sprite(psx_gpu, x, y, 0, 0, 1, 1, current_command, list[0]); break; @@ -474,8 +541,8 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) case 0x72: case 0x73: { - s32 x = list_s16[2] + psx_gpu->offset_x; - s32 y = list_s16[3] + psx_gpu->offset_y; + s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x); + s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y); render_sprite(psx_gpu, x, y, 0, 0, 8, 8, current_command, list[0]); break; @@ -486,8 +553,8 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) case 0x76: case 0x77: { - s32 x = list_s16[2] + psx_gpu->offset_x; - s32 y = list_s16[3] + psx_gpu->offset_y; + s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x); + s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y); u32 uv = list_s16[4]; set_clut(psx_gpu, list_s16[5]); @@ -502,8 +569,8 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) case 0x7A: case 0x7B: { - s32 x = list_s16[2] + psx_gpu->offset_x; - s32 y = list_s16[3] + psx_gpu->offset_y; + s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x); + s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y); render_sprite(psx_gpu, x, y, 0, 0, 16, 16, current_command, list[0]); break; @@ -514,8 +581,8 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) case 0x7E: case 0x7F: { - s32 x = list_s16[2] + psx_gpu->offset_x; - s32 y = list_s16[3] + psx_gpu->offset_y; + s32 x = sign_extend_11bit(list_s16[2] + psx_gpu->offset_x); + s32 y = sign_extend_11bit(list_s16[3] + psx_gpu->offset_y); u32 uv = list_s16[4]; set_clut(psx_gpu, list_s16[5]); @@ -527,35 +594,47 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) case 0x80: // vid -> vid render_block_move(psx_gpu, list_s16[2] & 0x3FF, list_s16[3] & 0x1FF, - list_s16[4] & 0x3FF, list_s16[5] & 0x1FF, list_s16[6], list_s16[7]); + list_s16[4] & 0x3FF, list_s16[5] & 0x1FF, + ((list_s16[6] - 1) & 0x3FF) + 1, ((list_s16[7] - 1) & 0x1FF) + 1); break; - + +#ifdef PCSX + case 0xA0: // sys -> vid + case 0xC0: // vid -> sys + goto breakloop; +#else case 0xA0: // sys -> vid { - u32 load_x = list_s16[2]; - u32 load_y = list_s16[3]; - u32 load_width = list_s16[4]; - u32 load_height = list_s16[5]; + u32 load_x = list_s16[2] & 0x3FF; + u32 load_y = list_s16[3] & 0x1FF; + u32 load_width = list_s16[4] & 0x3FF; + u32 load_height = list_s16[5] & 0x1FF; u32 load_size = load_width * load_height; command_length += load_size / 2; - + + if(load_size & 1) + command_length++; + render_block_copy(psx_gpu, (u16 *)&(list_s16[6]), load_x, load_y, load_width, load_height, load_width); break; } - + case 0xC0: // vid -> sys break; - +#endif + case 0xE1: set_texture(psx_gpu, list[0] & 0x1FF); + if(list[0] & (1 << 9)) psx_gpu->render_state_base |= RENDER_STATE_DITHER; else psx_gpu->render_state_base &= ~RENDER_STATE_DITHER; psx_gpu->display_area_draw_enable = (list[0] >> 10) & 0x1; + SET_Ex(1, list[0]); break; case 0xE2: @@ -588,6 +667,7 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) update_texture_ptr(psx_gpu); } + SET_Ex(2, list[0]); break; } @@ -601,6 +681,7 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) psx_gpu->viewport_start_y, psx_gpu->viewport_end_x, psx_gpu->viewport_end_y); #endif + SET_Ex(3, list[0]); break; case 0xE4: @@ -613,6 +694,7 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) psx_gpu->viewport_start_y, psx_gpu->viewport_end_x, psx_gpu->viewport_end_y); #endif + SET_Ex(4, list[0]); break; case 0xE5: @@ -622,6 +704,7 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) psx_gpu->offset_x = offset_x >> 21; psx_gpu->offset_y = offset_y >> 21; + SET_Ex(5, list[0]); break; } @@ -641,6 +724,7 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) psx_gpu->mask_msb = mask_msb; } + SET_Ex(6, list[0]); break; } @@ -648,5 +732,12 @@ void gpu_parse(psx_gpu_struct *psx_gpu, u32 *list, u32 size) break; } } + +#ifdef PCSX +breakloop: +#endif + if (last_command != NULL) + *last_command = current_command; + return list - list_start; }