1 /***************************************************************************
2 * Copyright (C) 2010 PCSX4ALL Team *
3 * Copyright (C) 2010 Unai *
5 * This program is free software; you can redistribute it and/or modify *
6 * it under the terms of the GNU General Public License as published by *
7 * the Free Software Foundation; either version 2 of the License, or *
8 * (at your option) any later version. *
10 * This program is distributed in the hope that it will be useful, *
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of *
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *
13 * GNU General Public License for more details. *
15 * You should have received a copy of the GNU General Public License *
16 * along with this program; if not, write to the *
17 * Free Software Foundation, Inc., *
18 * 51 Franklin Street, Fifth Floor, Boston, MA 02111-1307 USA. *
19 ***************************************************************************/
26 int skipCount = 2; /* frame skip (0,1,2,3...) */
27 int skCount=0; /* internal frame skip */
28 int linesInterlace = 0; /* internal lines interlace */
29 int linesInterlace_user = 0; /* Lines interlace */
31 bool isSkip=false; /* skip frame (info coming from GPU) */
32 bool skipFrame=false; /* skip frame (according to frame skip) */
33 bool alt_fps = false; /* Alternative FPS algorithm */
34 bool show_fps = false; /* Show FPS statistics */
36 bool isPAL=false; /* PAL video timing */
37 bool progressInterlace_flag = false; /* Progressive interlace flag */
38 bool progressInterlace = false; /* Progressive interlace option*/
39 bool frameLimit = false; /* frames to wait */
40 bool light = true; /* lighting */
41 bool blend = true; /* blending */
43 bool fb_dirty = false;
45 bool enableAbbeyHack = false; /* Abe's Odyssey hack */
53 ///////////////////////////////////////////////////////////////////////////////
55 ///////////////////////////////////////////////////////////////////////////////
57 ///////////////////////////////////////////////////////////////////////////////
70 ///////////////////////////////////////////////////////////////////////////////
74 ///////////////////////////////////////////////////////////////////////////////
76 u32 TextureWindow [4];
78 u32 DrawingOffset [2];
80 ///////////////////////////////////////////////////////////////////////////////
86 ///////////////////////////////////////////////////////////////////////////////
96 GPUPacket PacketBuffer;
97 // FRAME_BUFFER_SIZE is defined in bytes; 512K is guard memory for out of range reads
98 u16 GPU_FrameBuffer[(FRAME_BUFFER_SIZE+512*1024)/2] __attribute__((aligned(16)));
101 ///////////////////////////////////////////////////////////////////////////////
102 // Inner loop driver instanciation file
103 #include "gpu_inner.h"
105 ///////////////////////////////////////////////////////////////////////////////
107 #define GPU_RGB16(rgb) ((((rgb)&0xF80000)>>9)|(((rgb)&0xF800)>>6)|(((rgb)&0xF8)>>3))
109 #define GPU_EXPANDSIGN_POLY(x) (((s32)(x)<<20)>>20)
110 //#define GPU_EXPANDSIGN_POLY(x) (((s32)(x)<<21)>>21)
111 #define GPU_EXPANDSIGN_SPRT(x) (((s32)(x)<<21)>>21)
113 //#define GPU_TESTRANGE(x) { if((u32)(x+1024) > 2047) return; }
114 #define GPU_TESTRANGE(x) { if ((x<-1023) || (x>1023)) return; }
116 #define GPU_SWAP(a,b,t) {(t)=(a);(a)=(b);(b)=(t);}
118 ///////////////////////////////////////////////////////////////////////////////
119 // GPU internal image drawing functions
120 #include "gpu_raster_image.h"
122 ///////////////////////////////////////////////////////////////////////////////
123 // GPU internal line drawing functions
124 #include "gpu_raster_line.h"
126 ///////////////////////////////////////////////////////////////////////////////
127 // GPU internal polygon drawing functions
128 #include "gpu_raster_polygon.h"
130 ///////////////////////////////////////////////////////////////////////////////
131 // GPU internal sprite drawing functions
132 #include "gpu_raster_sprite.h"
134 ///////////////////////////////////////////////////////////////////////////////
135 // GPU command buffer execution/store
136 #include "gpu_command.h"
138 ///////////////////////////////////////////////////////////////////////////////
139 INLINE void gpuReset(void)
141 GPU_GP1 = 0x14802000;
142 TextureWindow[0] = 0;
143 TextureWindow[1] = 0;
144 TextureWindow[2] = 255;
145 TextureWindow[3] = 255;
146 DrawingArea[2] = 256;
147 DrawingArea[3] = 240;
148 DisplayArea[2] = 256;
149 DisplayArea[3] = 240;
150 DisplayArea[5] = 240;
153 ///////////////////////////////////////////////////////////////////////////////
159 for(int i=1;i<=(1<<TABLE_BITS);++i)
161 double v = 1.0 / double(i);
162 #ifdef GPU_TABLE_10_BITS
163 v *= double(0xffffffff>>1);
165 v *= double(0x80000000);
167 s_invTable[i-1]=s32(v);
172 ///////////////////////////////////////////////////////////////////////////////
173 void GPU_shutdown(void)
177 ///////////////////////////////////////////////////////////////////////////////
178 long GPU_freeze(unsigned int bWrite, GPUFreeze_t* p2)
181 if (p2->Version != 1) return (0);
185 p2->GPU_gp1 = GPU_GP1;
186 memset(p2->Control, 0, sizeof(p2->Control));
187 p2->Control[5] = DisplayArea[0] | (DisplayArea[1] << 10);
188 p2->Control[7] = DisplayArea[4] | (DisplayArea[5] << 10);
189 p2->Control[8] = ((GPU_GP1 >> 17) & 0x3f) | ((GPU_GP1 >> 10) & 0x40);
190 memcpy(p2->FrameBuffer, (u16*)GPU_FrameBuffer, FRAME_BUFFER_SIZE);
195 GPU_GP1 = p2->GPU_gp1;
196 memcpy((u16*)GPU_FrameBuffer, p2->FrameBuffer, FRAME_BUFFER_SIZE);
197 GPU_writeStatus((5 << 24) | p2->Control[5]);
198 GPU_writeStatus((7 << 24) | p2->Control[7]);
199 GPU_writeStatus((8 << 24) | p2->Control[8]);
200 gpuSetTexture(GPU_GP1);
206 ///////////////////////////////////////////////////////////////////////////////
207 // GPU DMA comunication
209 ///////////////////////////////////////////////////////////////////////////////
212 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0-15
213 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16-31
214 3, 3, 3, 3, 6, 6, 6, 6, 4, 4, 4, 4, 8, 8, 8, 8, // 32-47
215 5, 5, 5, 5, 8, 8, 8, 8, 7, 7, 7, 7, 11, 11, 11, 11, // 48-63
216 2, 2, 2, 2, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, // 64-79
217 3, 3, 3, 3, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, // 80-95
218 2, 2, 2, 2, 3, 3, 3, 3, 1, 1, 1, 1, 2, 2, 2, 2, // 96-111
219 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, // 112-127
220 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 128-
221 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 144
222 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 160
223 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
224 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
225 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
226 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
227 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 //
230 ///////////////////////////////////////////////////////////////////////////////
231 INLINE void gpuSendPacket()
233 #ifdef DEBUG_ANALYSIS
234 dbg_anacnt_GPU_sendPacket++;
236 gpuSendPacketFunction(PacketBuffer.U4[0]>>24);
239 ///////////////////////////////////////////////////////////////////////////////
240 INLINE void gpuCheckPacket(u32 uData)
244 PacketBuffer.U4[PacketIndex++] = uData;
249 PacketBuffer.U4[0] = uData;
250 PacketCount = PacketSize[uData >> 24];
253 if (!PacketCount) gpuSendPacket();
256 ///////////////////////////////////////////////////////////////////////////////
257 void GPU_writeDataMem(u32* dmaAddress, s32 dmaCount)
259 #ifdef DEBUG_ANALYSIS
260 dbg_anacnt_GPU_writeDataMem++;
262 pcsx4all_prof_pause(PCSX4ALL_PROF_CPU);
263 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
265 const u16 *VIDEO_END=(GPU_FrameBuffer+(FRAME_BUFFER_SIZE/2)-1);
266 GPU_GP1 &= ~0x14000000;
274 data = *dmaAddress++;
275 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
284 GPU_GP1 &= ~0x08000000;
288 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
289 pvram[px] = data>>16;
297 GPU_GP1 &= ~0x08000000;
305 data = *dmaAddress++;
307 gpuCheckPacket(data);
311 GPU_GP1 = (GPU_GP1 | 0x14000000) & ~0x60000000;
313 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
314 pcsx4all_prof_resume(PCSX4ALL_PROF_CPU);
318 INLINE int CheckForEndlessLoop(u32 *laddr)
320 if(laddr==lUsedAddr[1]) return 1;
321 if(laddr==lUsedAddr[2]) return 1;
323 if(laddr<lUsedAddr[0]) lUsedAddr[1]=laddr;
324 else lUsedAddr[2]=laddr;
329 ///////////////////////////////////////////////////////////////////////////////
330 void GPU_dmaChain(u32* baseAddr, u32 dmaVAddr)
332 #ifdef DEBUG_ANALYSIS
333 dbg_anacnt_GPU_dmaChain++;
335 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
336 u32 data, *address, count, offset;
337 unsigned int DMACommandCounter = 0;
339 GPU_GP1 &= ~0x14000000;
340 lUsedAddr[0]=lUsedAddr[1]=lUsedAddr[2]=(u32*)0x1fffff;
341 dmaVAddr &= 0x001FFFFF;
342 while (dmaVAddr != 0x1FFFFF)
344 address = (baseAddr + (dmaVAddr >> 2));
345 if(DMACommandCounter++ > 2000000) break;
346 if(CheckForEndlessLoop(address)) break;
348 count = (data >> 24);
349 offset = data & 0x001FFFFF;
350 if (dmaVAddr != offset) dmaVAddr = offset;
351 else dmaVAddr = 0x1FFFFF;
353 if(count>0) GPU_writeDataMem(address,count);
355 GPU_GP1 = (GPU_GP1 | 0x14000000) & ~0x60000000;
356 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
359 ///////////////////////////////////////////////////////////////////////////////
360 void GPU_writeData(u32 data)
362 const u16 *VIDEO_END=(GPU_FrameBuffer+(FRAME_BUFFER_SIZE/2)-1);
363 #ifdef DEBUG_ANALYSIS
364 dbg_anacnt_GPU_writeData++;
366 pcsx4all_prof_pause(PCSX4ALL_PROF_CPU);
367 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
368 GPU_GP1 &= ~0x14000000;
372 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
381 GPU_GP1 &= ~0x08000000;
386 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
395 GPU_GP1 &= ~0x08000000;
402 gpuCheckPacket(data);
404 GPU_GP1 |= 0x14000000;
406 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
407 pcsx4all_prof_resume(PCSX4ALL_PROF_CPU);
412 ///////////////////////////////////////////////////////////////////////////////
413 void GPU_readDataMem(u32* dmaAddress, s32 dmaCount)
415 const u16 *VIDEO_END=(GPU_FrameBuffer+(FRAME_BUFFER_SIZE/2)-1);
416 #ifdef DEBUG_ANALYSIS
417 dbg_anacnt_GPU_readDataMem++;
419 if(!FrameToRead) return;
421 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
422 GPU_GP1 &= ~0x14000000;
425 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
427 u32 data = (unsigned long)pvram[px];
435 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
436 // higher 16 bit (always, even if it's an odd width)
437 data |= (unsigned long)(pvram[px])<<16;
439 *dmaAddress++ = data;
448 GPU_GP1 &= ~0x08000000;
452 } while (--dmaCount);
454 GPU_GP1 = (GPU_GP1 | 0x14000000) & ~0x60000000;
455 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
460 ///////////////////////////////////////////////////////////////////////////////
461 u32 GPU_readData(void)
463 const u16 *VIDEO_END=(GPU_FrameBuffer+(FRAME_BUFFER_SIZE/2)-1);
464 #ifdef DEBUG_ANALYSIS
465 dbg_anacnt_GPU_readData++;
467 pcsx4all_prof_pause(PCSX4ALL_PROF_CPU);
468 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_READ);
469 GPU_GP1 &= ~0x14000000;
472 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
481 GPU_GP1 &= ~0x08000000;
484 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
485 GP0 |= pvram[px]<<16;
493 GPU_GP1 &= ~0x08000000;
498 GPU_GP1 |= 0x14000000;
500 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_READ);
501 pcsx4all_prof_resume(PCSX4ALL_PROF_CPU);
505 ///////////////////////////////////////////////////////////////////////////////
506 u32 GPU_readStatus(void)
508 #ifdef DEBUG_ANALYSIS
509 dbg_anacnt_GPU_readStatus++;
514 ///////////////////////////////////////////////////////////////////////////////
515 void GPU_writeStatus(u32 data)
517 #ifdef DEBUG_ANALYSIS
518 dbg_anacnt_GPU_writeStatus++;
520 pcsx4all_prof_pause(PCSX4ALL_PROF_CPU);
521 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
522 switch (data >> 24) {
527 GPU_GP1 &= ~0x08000000;
528 PacketCount = FrameToRead = FrameToWrite = 0;
531 GPU_GP1 &= ~0x08000000;
532 PacketCount = FrameToRead = FrameToWrite = 0;
535 GPU_GP1 = (GPU_GP1 & ~0x00800000) | ((data & 1) << 23);
538 if (data == 0x04000000)
540 GPU_GP1 = (GPU_GP1 & ~0x60000000) | ((data & 3) << 29);
543 DisplayArea[0] = (data & 0x000003FF); //(short)(data & 0x3ff);
544 DisplayArea[1] = ((data & 0x0007FC00)>>10); //(data & 0x000FFC00) >> 10; //(short)((data>>10)&0x1ff);
548 DisplayArea[4] = data & 0x000003FF; //(short)(data & 0x3ff);
549 DisplayArea[5] = (data & 0x000FFC00) >> 10; //(short)((data>>10) & 0x3ff);
554 GPU_GP1 = (GPU_GP1 & ~0x007F0000) | ((data & 0x3F) << 17) | ((data & 0x40) << 10);
555 static u32 HorizontalResolution[8] = { 256, 368, 320, 384, 512, 512, 640, 640 };
556 DisplayArea[2] = HorizontalResolution[(GPU_GP1 >> 16) & 7];
557 static u32 VerticalResolution[4] = { 240, 480, 256, 480 };
558 DisplayArea[3] = VerticalResolution[(GPU_GP1 >> 19) & 3];
559 isPAL = (data & 0x08) ? true : false; // if 1 - PAL mode, else NTSC
564 switch (data & 0xffff) {
568 GP0 = (DrawingArea[1] << 10) | DrawingArea[0];
571 GP0 = ((DrawingArea[3]-1) << 10) | (DrawingArea[2]-1);
575 GP0 = (DrawingOffset[1] << 11) | DrawingOffset[0];
585 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
586 pcsx4all_prof_resume(PCSX4ALL_PROF_CPU);
591 // Blitting functions
592 #include "gpu_blit.h"
594 INLINE void gpuVideoOutput(void)
596 static s16 old_res_horz, old_res_vert, old_rgb24;
597 s16 h0, x0, y0, w0, h1;
603 h0 = DisplayArea[3]; // video mode
605 h1 = DisplayArea[5] - DisplayArea[4]; // display needed
606 if (h0 == 480) h1 = Min2(h1*2,480);
608 u16* dest_screen16 = SCREEN;
609 u16* src_screen16 = &((u16*)GPU_FrameBuffer)[FRAME_OFFSET(x0,y0)];
610 u32 isRGB24 = (GPU_GP1 & 0x00200000 ? 32 : 0);
612 /* Clear the screen if resolution changed to prevent interlacing and clipping to clash */
613 if( (w0 != old_res_horz || h1 != old_res_vert || (s16)isRGB24 != old_rgb24) )
615 // Update old resolution
618 old_rgb24 = (s16)isRGB24;
619 // Finally, clear the screen for this special case
625 if(h0==256) h0 = 240; else if(h0==480) sizeShift = 2;
626 if(h1>h0) { src_screen16 += ((h1-h0)>>sizeShift)*1024; h1 = h0; }
627 else if(h1<h0) dest_screen16 += ((h0-h1)>>sizeShift)*VIDEO_WIDTH;
630 int incY = (h0==480) ? 2 : 1;
631 h0=(h0==480 ? 2048 : 1024);
633 if (!progressInterlace)
635 const int li=linesInterlace;
639 for(int y1=y0+h1; y0<y1; y0+=incY)
641 if( 0 == (y0&li) ) GPU_BlitWWDWW( src_screen16, dest_screen16, isRGB24);
642 dest_screen16 += VIDEO_WIDTH;
647 for(int y1=y0+h1; y0<y1; y0+=incY)
649 if( 0 == (y0&li) ) GPU_BlitWWWWWWWWS( src_screen16, dest_screen16, isRGB24, 4);
650 dest_screen16 += VIDEO_WIDTH;
655 for(int y1=y0+h1; y0<y1; y0+=incY)
657 if( 0 == (y0&li) ) GPU_BlitWW( src_screen16, dest_screen16, isRGB24);
658 dest_screen16 += VIDEO_WIDTH;
663 for(int y1=y0+h1; y0<y1; y0+=incY)
665 if( 0 == (y0&li) ) GPU_BlitWWWWWS( src_screen16, dest_screen16, isRGB24);
666 dest_screen16 += VIDEO_WIDTH;
671 for(int y1=y0+h1; y0<y1; y0+=incY)
673 if( 0 == (y0&li) ) GPU_BlitWWSWWSWS( src_screen16, dest_screen16, isRGB24);
674 dest_screen16 += VIDEO_WIDTH;
679 for(int y1=y0+h1; y0<y1; y0+=incY)
681 if( 0 == (y0&li) ) GPU_BlitWS( src_screen16, dest_screen16, isRGB24);
682 dest_screen16 += VIDEO_WIDTH;
690 const int li=linesInterlace;
691 bool flag=progressInterlace_flag; /* progressive interlace */
695 for(int y1=y0+h1; y0<y1; y0+=incY)
697 if(( 0 == (y0&li) ) && (flag=!flag)) GPU_BlitWWDWW( src_screen16, dest_screen16, isRGB24);
698 dest_screen16 += VIDEO_WIDTH;
703 for(int y1=y0+h1; y0<y1; y0+=incY)
705 if(( 0 == (y0&li) ) && (flag=!flag)) GPU_BlitWWWWWWWWS( src_screen16, dest_screen16, isRGB24, 4);
706 dest_screen16 += VIDEO_WIDTH;
711 for(int y1=y0+h1; y0<y1; y0+=incY)
713 if(( 0 == (y0&li) ) && (flag=!flag)) GPU_BlitWW( src_screen16, dest_screen16, isRGB24);
714 dest_screen16 += VIDEO_WIDTH;
719 for(int y1=y0+h1; y0<y1; y0+=incY)
721 if(( 0 == (y0&li) ) && (flag=!flag)) GPU_BlitWWWWWS( src_screen16, dest_screen16, isRGB24);
722 dest_screen16 += VIDEO_WIDTH;
727 for(int y1=y0+h1; y0<y1; y0+=incY)
729 if(( 0 == (y0&li) ) && (flag=!flag)) GPU_BlitWWSWWSWS( src_screen16, dest_screen16, isRGB24);
730 dest_screen16 += VIDEO_WIDTH;
735 for(int y1=y0+h1; y0<y1; y0+=incY)
737 if(( 0 == (y0&li) ) && (flag=!flag)) GPU_BlitWS( src_screen16, dest_screen16, isRGB24);
738 dest_screen16 += VIDEO_WIDTH;
743 progressInterlace_flag=!flag;
748 ///////////////////////////////////////////////////////////////////////////////
749 void GPU_updateLace(void)
751 #ifdef ENABLE_GPU_LOG_SUPPORT
752 fprintf(stdout,"GPU_updateLace()\n");
754 #ifdef DEBUG_ANALYSIS
755 dbg_anacnt_GPU_updateLace++;
757 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_COUNTERS);
758 #ifdef PROFILER_PCSX4ALL
759 pcsx4all_prof_frames++;
765 if (!passed) dbg_enable();
766 else pcsx4all_exit();
772 static const unsigned char skipTable[12][12] =
774 { 0,0,0,0,0,0,0,0,0,0,0,0 },
775 { 0,0,0,0,0,0,0,0,0,0,0,1 },
776 { 0,0,0,0,0,1,0,0,0,0,0,1 },
777 { 0,0,0,1,0,0,0,1,0,0,0,1 },
778 { 0,0,1,0,0,1,0,0,1,0,0,1 },
779 { 0,1,0,0,1,0,1,0,0,1,0,1 },
780 { 0,1,0,1,0,1,0,1,0,1,0,1 },
781 { 0,1,0,1,1,0,1,0,1,1,0,1 },
782 { 0,1,1,0,1,1,0,1,1,0,1,1 },
783 { 0,1,1,1,0,1,1,1,0,1,1,1 },
784 { 0,1,1,1,1,1,0,1,1,1,1,1 },
785 { 0,1,1,1,1,1,1,1,1,1,1,1 }
788 // Interlace bit toggle
789 GPU_GP1 ^= 0x80000000;
792 if ((!skipFrame) && (!isSkip) && (!(((GPU_GP1&0x08000000))||((GPU_GP1&0x00800000)))))
794 gpuVideoOutput(); // Display updated
796 if (DisplayArea[3] == 480)
798 if (linesInterlace_user) linesInterlace = 3; // 1/4 of lines
799 else linesInterlace = 1; // if 480 we only need half of lines
801 else if (linesInterlace != linesInterlace_user)
803 linesInterlace = linesInterlace_user; // resolution changed from 480 to lower one
810 static unsigned next=get_ticks();
811 unsigned now=get_ticks();
814 if (now<next) wait_ticks(next-now);
816 next+=(isPAL?(1000000/50):((unsigned)(1000000.0/59.94)));
820 // Show FPS statistics
823 static u32 real_fps=0;
824 static u32 prev=get_ticks();
825 static char msg[24]="FPS=000/00 SPD=000%";
828 if ((now-prev)>=1000000)
830 u32 expected_fps=(isPAL?50:60);
831 sprintf(msg,"FPS=%3d/%2d SPD=%3d%%",((real_fps*(12-skipCount))/12),((expected_fps*(12-skipCount))/12),((real_fps*100)/expected_fps));
835 port_printf(5,5,msg);
842 skipFrame=skipTable[skipCount][skCount];
843 skCount--; if (skCount<0) skCount=11;
851 skipFrame=skipTable[skipCount][skCount];
852 skCount--; if (skCount<0) skCount=11;
857 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_COUNTERS);
862 #include "../../frontend/plugin_lib.h"
866 extern void bgr555_to_rgb565(void *dst, void *src, int bytes);
867 extern void bgr888_to_rgb888(void *dst, void *src, int bytes);
868 static const struct rearmed_cbs *cbs;
869 static void *screen_buf;
871 static void blit(void)
873 static s16 old_res_horz, old_res_vert, old_rgb24;
874 s16 isRGB24 = (GPU_GP1 & 0x00200000) ? 1 : 0;
875 s16 h0, x0, y0, w0, h1;
879 x0 = DisplayArea[0] & ~3; // alignment needed by blitter
881 srcs = &((u16*)GPU_FrameBuffer)[FRAME_OFFSET(x0,y0)];
884 h0 = DisplayArea[3]; // video mode
886 h1 = DisplayArea[5] - DisplayArea[4]; // display needed
887 if (h0 == 480) h1 = Min2(h1*2,480);
892 if (w0 != old_res_horz || h1 != old_res_vert || isRGB24 != old_rgb24)
896 old_rgb24 = (s16)isRGB24;
897 screen_buf = cbs->pl_fbdev_set_mode(w0, h1, isRGB24 ? 24 : 16);
899 dest = (u8 *)screen_buf;
903 for (; h1-- > 0; dest += w0 * 3, srcs += 1024)
905 bgr888_to_rgb888(dest, srcs, w0 * 3);
910 for (; h1-- > 0; dest += w0 * 2, srcs += 1024)
912 bgr555_to_rgb565(dest, srcs, w0 * 2);
916 screen_buf = cbs->pl_fbdev_flip();
919 void GPU_updateLace(void)
921 // Interlace bit toggle
922 GPU_GP1 ^= 0x80000000;
924 if (!fb_dirty || (GPU_GP1&0x08800000))
931 if (*cbs->fskip_option)
938 long GPUopen(unsigned long *, char *, char *)
940 cbs->pl_fbdev_open();
941 screen_buf = cbs->pl_fbdev_flip();
947 cbs->pl_fbdev_close();
951 long GPUfreeze(unsigned int ulGetFreezeData, GPUFreeze_t* p2)
953 if (ulGetFreezeData > 1)
956 return GPU_freeze(ulGetFreezeData, p2);
959 void GPUrearmedCallbacks(const struct rearmed_cbs *cbs_)