psx_gpu: switch to 1024 width again.
[pcsx_rearmed.git] / plugins / gpu_neon / psx_gpu_if.c
1 /*
2  * (C) GraÅžvydas "notaz" Ignotas, 2011
3  *
4  * This work is licensed under the terms of any of these licenses
5  * (at your option):
6  *  - GNU GPL, version 2 or later.
7  *  - GNU LGPL, version 2.1 or later.
8  * See the COPYING file in the top-level directory.
9  */
10
11 #include <stdio.h>
12
13 extern const unsigned char cmd_lengths[256];
14 #define command_lengths cmd_lengths
15
16 static unsigned int *ex_regs;
17
18 #define PCSX
19 #define SET_Ex(r, v) \
20   ex_regs[r] = v
21
22 #include "psx_gpu/psx_gpu.c"
23 #include "psx_gpu/psx_gpu_parse.c"
24 #include "../gpulib/gpu.h"
25
26 static psx_gpu_struct egpu __attribute__((aligned(256)));
27
28 int do_cmd_list(uint32_t *list, int count, int *last_cmd)
29 {
30   int ret;
31
32   if (gpu.state.enhancement_active)
33     ret = gpu_parse_enhanced(&egpu, list, count * 4, (u32 *)last_cmd);
34   else
35     ret = gpu_parse(&egpu, list, count * 4, (u32 *)last_cmd);
36
37   ex_regs[1] &= ~0x1ff;
38   ex_regs[1] |= egpu.texture_settings & 0x1ff;
39   return ret;
40 }
41
42 int renderer_init(void)
43 {
44   initialize_psx_gpu(&egpu, gpu.vram);
45   ex_regs = gpu.ex_regs;
46
47   if (gpu.enhancement_bufer == NULL) {
48     // currently we use 4x 1024*1024 buffers instead of single 2048*1024
49     // to be able to reuse 1024-width code better (triangle setup,
50     // dithering phase, lines).
51     gpu.enhancement_bufer = malloc(1024 * 1024 * 2 * 4);
52     if (gpu.enhancement_bufer == NULL)
53       printf("OOM for enhancement buffer\n");
54   }
55   egpu.enhancement_buf_ptr = gpu.enhancement_bufer;
56
57   return 0;
58 }
59
60 void renderer_finish(void)
61 {
62   free(gpu.enhancement_bufer);
63   gpu.enhancement_bufer = NULL;
64   egpu.enhancement_buf_ptr = NULL;
65 }
66
67 void renderer_sync_ecmds(uint32_t *ecmds)
68 {
69   gpu_parse(&egpu, ecmds + 1, 6 * 4, NULL);
70 }
71
72 void renderer_update_caches(int x, int y, int w, int h)
73 {
74   update_texture_cache_region(&egpu, x, y, x + w - 1, y + h - 1);
75 }
76
77 void renderer_flush_queues(void)
78 {
79   flush_render_block_buffer(&egpu);
80 }
81
82 void renderer_set_interlace(int enable, int is_odd)
83 {
84   egpu.render_mode &= ~(RENDER_INTERLACE_ENABLED|RENDER_INTERLACE_ODD);
85   if (enable)
86     egpu.render_mode |= RENDER_INTERLACE_ENABLED;
87   if (is_odd)
88     egpu.render_mode |= RENDER_INTERLACE_ODD;
89 }
90
91 void renderer_notify_res_change(void)
92 {
93   egpu.enhancement_x_threshold = gpu.screen.hres;
94 }
95
96 #include "../../frontend/plugin_lib.h"
97
98 void renderer_set_config(const struct rearmed_cbs *cbs)
99 {
100   disable_main_render = cbs->gpu_neon.enhancement_no_main;
101 }