@@ -355,11 +355,36 @@ void OpenGL::renderBlit(gpu::GPU* gpu, bool software) {
355355 y = static_cast <int >((height - h) / 2 .f );
356356 }
357357
358- float y2 = static_cast <float >(gpu->displayRangeY2 - gpu->displayRangeY1 );
359- if (gpu->gp1_08 .getVerticalResoulution () == 480 ) y2 *= 2 ;
360- // TODO: convert xy to screen space
361- blitShader->getUniform (" clipLeftTop" ).f (0 , 0 );
362- blitShader->getUniform (" clipRightBottom" ).f (1024 , gpu->displayAreaStartY + y2);
358+ {
359+ float yOffset = y / static_cast <float >(h); // Compensate for aspect ratio
360+ float xOffset = x / static_cast <float >(w);
361+
362+ float vResolution = gpu->isNtsc () ? 240 : 256 ;
363+
364+ float displayTop = 0 .f ;
365+ float displayBottom = (gpu->displayRangeY2 - gpu->displayRangeY1 ) / vResolution;
366+
367+ // V aligment disabled for now
368+ // int firstLine = gpu->isNtsc() ? (0x88 - 224/2) : (0xA3 - 264/2);
369+ // y -= ((gpu->displayRangeY1 - firstLine) / vResolution) * h;
370+
371+ float hres = gpu->gp1_08 .getHorizontalResoulution ();
372+ int cyclesPerPixel = ceilf (640 * 4 / hres);
373+
374+ float displayXOffset = (gpu->displayRangeX1 - 0x260 ) / cyclesPerPixel / hres;
375+
376+ float displayLeft = 0 .f ;
377+ float displayRight = (gpu->displayRangeX2 - gpu->displayRangeX1 ) / cyclesPerPixel / hres;
378+
379+ // Move display to right by offset
380+ x += displayXOffset * w;
381+
382+ blitShader->getUniform (" iResolution" ).f (w, h);
383+ blitShader->getUniform (" displayHorizontal" ).f (displayLeft + xOffset, displayRight + xOffset);
384+ blitShader->getUniform (" displayVertical" ).f (displayTop - yOffset, displayBottom - yOffset);
385+ }
386+
387+ blitShader->getUniform (" displayEnabled" ).i (!gpu->displayDisable );
363388
364389 glViewport (x, y, w, h);
365390 blitBuffer->update (bb.size () * sizeof (BlitStruct), bb.data ());
0 commit comments