@@ -144,7 +144,50 @@ void hardware_init(void* udata, struct ps2_gs* gs, SDL_Window* window, SDL_GPUDe
144144void hardware_destroy (void * udata) {
145145 hardware_state* ctx = (hardware_state*)udata;
146146}
147- void hardware_set_size (void * udata, int width, int height) {}
147+ void hardware_set_size (void * udata, int width, int height) {
148+ hardware_state* ctx = (hardware_state*)udata;
149+
150+ int en1 = ctx->gs ->pmode & 1 ;
151+ int en2 = (ctx->gs ->pmode >> 1 ) & 1 ;
152+
153+ uint64_t display = 0 , dispfb = 0 ;
154+
155+ if (en1) {
156+ display = ctx->gs ->display1 ;
157+ dispfb = ctx->gs ->dispfb1 ;
158+ } else if (en2) {
159+ display = ctx->gs ->display2 ;
160+ dispfb = ctx->gs ->dispfb2 ;
161+ }
162+
163+ uint32_t tex_fmt = (dispfb >> 15 ) & 0x1f ;
164+
165+ int magh = ((display >> 23 ) & 0xf ) + 1 ;
166+ int magv = ((display >> 27 ) & 3 ) + 1 ;
167+
168+ if (((display >> 32 ) & 0xfff ) == 0 ) {
169+ ctx->tex_w = 0 ;
170+ ctx->tex_h = 0 ;
171+
172+ return ;
173+ }
174+
175+ if (((display >> 44 ) & 0x7ff ) == 0 ) {
176+ ctx->tex_w = 0 ;
177+ ctx->tex_h = 0 ;
178+
179+ return ;
180+ }
181+
182+ uint32_t tex_w = (((display >> 32 ) & 0xfff ) / magh) + 1 ;
183+ uint32_t tex_h = (((display >> 44 ) & 0x7ff ) / magv) + 1 ;
184+
185+ ctx->tex_w = tex_w;
186+ ctx->tex_h = tex_h;
187+
188+ if ((ctx->gs ->smode2 & 3 ) == 3 )
189+ ctx->tex_h /= 2 ;
190+ }
148191void hardware_set_scale (void * udata, float scale) {}
149192void hardware_set_aspect_mode (void * udata, int aspect_mode) {}
150193void hardware_set_integer_scaling (void * udata, bool integer_scaling) {}
@@ -176,6 +219,8 @@ extern "C" void hardware_render_triangle(struct ps2_gs* gs, void* udata) {
176219 // gs->vq[0].z, gs->vq[1].z, gs->vq[2].z
177220 // );
178221
222+ int interlace = ((gs->smode2 & 3 ) == 3 ) ? 2 : 1 ;
223+
179224 for (int i = 0 ; i < 3 ; i++) {
180225 hw_vertex hw_v;
181226
@@ -186,7 +231,7 @@ extern "C" void hardware_render_triangle(struct ps2_gs* gs, void* udata) {
186231 hw_v.u = gs->vq [i].u ;
187232 hw_v.v = gs->vq [i].v ;
188233 hw_v.x = gs->vq [i].x - ctx->gs ->ctx ->ofx ;
189- hw_v.y = (224 - (gs->vq [i].y - ctx->gs ->ctx ->ofy )) * 2 ;
234+ hw_v.y = (ctx-> tex_h - (gs->vq [i].y - ctx->gs ->ctx ->ofy )) * interlace ;
190235 hw_v.z = gs->vq [i].z ;
191236 hw_v.s = gs->vq [i].s ;
192237 hw_v.t = gs->vq [i].t ;
@@ -201,10 +246,12 @@ extern "C" void hardware_render_sprite(struct ps2_gs* gs, void* udata) {
201246 struct gs_vertex v0 = gs->vq [0 ];
202247 struct gs_vertex v1 = gs->vq [1 ];
203248
249+ int interlace = ((gs->smode2 & 3 ) == 3 ) ? 2 : 1 ;
250+
204251 uint32_t v0_x = v0.x - gs->ctx ->ofx ;
205- uint32_t v0_y = (224 - (v0.y - gs->ctx ->ofy )) * 2.0 ;
252+ uint32_t v0_y = (ctx-> tex_h - (v0.y - gs->ctx ->ofy )) * interlace ;
206253 uint32_t v1_x = v1.x - gs->ctx ->ofx ;
207- uint32_t v1_y = (224 - (v1.y - gs->ctx ->ofy )) * 2.0 ;
254+ uint32_t v1_y = (ctx-> tex_h - (v1.y - gs->ctx ->ofy )) * interlace ;
208255
209256 hw_vertex hw_v[6 ];
210257
0 commit comments