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 u16 GPU_FrameBuffer[FRAME_BUFFER_SIZE/2] __attribute__((aligned(16))); // FRAME_BUFFER_SIZE is defined in bytes
100 ///////////////////////////////////////////////////////////////////////////////
101 // Inner loop driver instanciation file
102 #include "gpu_inner.h"
104 ///////////////////////////////////////////////////////////////////////////////
106 #define GPU_RGB16(rgb) ((((rgb)&0xF80000)>>9)|(((rgb)&0xF800)>>6)|(((rgb)&0xF8)>>3))
108 #define GPU_EXPANDSIGN_POLY(x) (((s32)(x)<<20)>>20)
109 //#define GPU_EXPANDSIGN_POLY(x) (((s32)(x)<<21)>>21)
110 #define GPU_EXPANDSIGN_SPRT(x) (((s32)(x)<<21)>>21)
112 //#define GPU_TESTRANGE(x) { if((u32)(x+1024) > 2047) return; }
113 #define GPU_TESTRANGE(x) { if ((x<-1023) || (x>1023)) return; }
115 #define GPU_SWAP(a,b,t) {(t)=(a);(a)=(b);(b)=(t);}
117 ///////////////////////////////////////////////////////////////////////////////
118 // GPU internal image drawing functions
119 #include "gpu_raster_image.h"
121 ///////////////////////////////////////////////////////////////////////////////
122 // GPU internal line drawing functions
123 #include "gpu_raster_line.h"
125 ///////////////////////////////////////////////////////////////////////////////
126 // GPU internal polygon drawing functions
127 #include "gpu_raster_polygon.h"
129 ///////////////////////////////////////////////////////////////////////////////
130 // GPU internal sprite drawing functions
131 #include "gpu_raster_sprite.h"
133 ///////////////////////////////////////////////////////////////////////////////
134 // GPU command buffer execution/store
135 #include "gpu_command.h"
137 ///////////////////////////////////////////////////////////////////////////////
138 INLINE void gpuReset(void)
140 GPU_GP1 = 0x14802000;
141 TextureWindow[0] = 0;
142 TextureWindow[1] = 0;
143 TextureWindow[2] = 255;
144 TextureWindow[3] = 255;
145 DrawingArea[2] = 256;
146 DrawingArea[3] = 240;
147 DisplayArea[2] = 256;
148 DisplayArea[3] = 240;
149 DisplayArea[5] = 240;
152 ///////////////////////////////////////////////////////////////////////////////
158 for(int i=1;i<=(1<<TABLE_BITS);++i)
160 double v = 1.0 / double(i);
161 #ifdef GPU_TABLE_10_BITS
162 v *= double(0xffffffff>>1);
164 v *= double(0x80000000);
166 s_invTable[i-1]=s32(v);
171 ///////////////////////////////////////////////////////////////////////////////
172 void GPU_shutdown(void)
176 ///////////////////////////////////////////////////////////////////////////////
177 long GPU_freeze(unsigned int bWrite, GPUFreeze_t* p2)
180 if (p2->Version != 1) return (0);
184 p2->GPU_gp1 = GPU_GP1;
185 memset(p2->Control, 0, sizeof(p2->Control));
186 p2->Control[5] = DisplayArea[0] | (DisplayArea[1] << 10);
187 p2->Control[7] = DisplayArea[4] | (DisplayArea[5] << 10);
188 p2->Control[8] = ((GPU_GP1 >> 17) & 0x3f) | ((GPU_GP1 >> 10) & 0x40);
189 memcpy(p2->FrameBuffer, (u16*)GPU_FrameBuffer, FRAME_BUFFER_SIZE);
194 GPU_GP1 = p2->GPU_gp1;
195 memcpy((u16*)GPU_FrameBuffer, p2->FrameBuffer, FRAME_BUFFER_SIZE);
196 GPU_writeStatus((5 << 24) | p2->Control[5]);
197 GPU_writeStatus((7 << 24) | p2->Control[7]);
198 GPU_writeStatus((8 << 24) | p2->Control[8]);
199 gpuSetTexture(GPU_GP1);
205 ///////////////////////////////////////////////////////////////////////////////
206 // GPU DMA comunication
208 ///////////////////////////////////////////////////////////////////////////////
211 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0-15
212 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16-31
213 3, 3, 3, 3, 6, 6, 6, 6, 4, 4, 4, 4, 8, 8, 8, 8, // 32-47
214 5, 5, 5, 5, 8, 8, 8, 8, 7, 7, 7, 7, 11, 11, 11, 11, // 48-63
215 2, 2, 2, 2, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, // 64-79
216 3, 3, 3, 3, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, // 80-95
217 2, 2, 2, 2, 3, 3, 3, 3, 1, 1, 1, 1, 2, 2, 2, 2, // 96-111
218 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, // 112-127
219 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 128-
220 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 144
221 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 160
222 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
223 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
224 0, 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 //
229 ///////////////////////////////////////////////////////////////////////////////
230 INLINE void gpuSendPacket()
232 #ifdef DEBUG_ANALYSIS
233 dbg_anacnt_GPU_sendPacket++;
235 gpuSendPacketFunction(PacketBuffer.U4[0]>>24);
238 ///////////////////////////////////////////////////////////////////////////////
239 INLINE void gpuCheckPacket(u32 uData)
243 PacketBuffer.U4[PacketIndex++] = uData;
248 PacketBuffer.U4[0] = uData;
249 PacketCount = PacketSize[uData >> 24];
252 if (!PacketCount) gpuSendPacket();
255 ///////////////////////////////////////////////////////////////////////////////
256 void GPU_writeDataMem(u32* dmaAddress, s32 dmaCount)
258 #ifdef DEBUG_ANALYSIS
259 dbg_anacnt_GPU_writeDataMem++;
261 pcsx4all_prof_pause(PCSX4ALL_PROF_CPU);
262 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
264 const u16 *VIDEO_END=(GPU_FrameBuffer+(FRAME_BUFFER_SIZE/2)-1);
265 GPU_GP1 &= ~0x14000000;
273 data = *dmaAddress++;
274 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
283 GPU_GP1 &= ~0x08000000;
287 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
288 pvram[px] = data>>16;
296 GPU_GP1 &= ~0x08000000;
304 data = *dmaAddress++;
306 gpuCheckPacket(data);
310 GPU_GP1 = (GPU_GP1 | 0x14000000) & ~0x60000000;
312 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
313 pcsx4all_prof_resume(PCSX4ALL_PROF_CPU);
317 INLINE int CheckForEndlessLoop(u32 *laddr)
319 if(laddr==lUsedAddr[1]) return 1;
320 if(laddr==lUsedAddr[2]) return 1;
322 if(laddr<lUsedAddr[0]) lUsedAddr[1]=laddr;
323 else lUsedAddr[2]=laddr;
328 ///////////////////////////////////////////////////////////////////////////////
329 void GPU_dmaChain(u32* baseAddr, u32 dmaVAddr)
331 #ifdef DEBUG_ANALYSIS
332 dbg_anacnt_GPU_dmaChain++;
334 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
335 u32 data, *address, count, offset;
336 unsigned int DMACommandCounter = 0;
338 GPU_GP1 &= ~0x14000000;
339 lUsedAddr[0]=lUsedAddr[1]=lUsedAddr[2]=(u32*)0x1fffff;
340 dmaVAddr &= 0x001FFFFF;
341 while (dmaVAddr != 0x1FFFFF)
343 address = (baseAddr + (dmaVAddr >> 2));
344 if(DMACommandCounter++ > 2000000) break;
345 if(CheckForEndlessLoop(address)) break;
347 count = (data >> 24);
348 offset = data & 0x001FFFFF;
349 if (dmaVAddr != offset) dmaVAddr = offset;
350 else dmaVAddr = 0x1FFFFF;
352 if(count>0) GPU_writeDataMem(address,count);
354 GPU_GP1 = (GPU_GP1 | 0x14000000) & ~0x60000000;
355 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
358 ///////////////////////////////////////////////////////////////////////////////
359 void GPU_writeData(u32 data)
361 const u16 *VIDEO_END=(GPU_FrameBuffer+(FRAME_BUFFER_SIZE/2)-1);
362 #ifdef DEBUG_ANALYSIS
363 dbg_anacnt_GPU_writeData++;
365 pcsx4all_prof_pause(PCSX4ALL_PROF_CPU);
366 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
367 GPU_GP1 &= ~0x14000000;
371 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
380 GPU_GP1 &= ~0x08000000;
385 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
394 GPU_GP1 &= ~0x08000000;
401 gpuCheckPacket(data);
403 GPU_GP1 |= 0x14000000;
405 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
406 pcsx4all_prof_resume(PCSX4ALL_PROF_CPU);
411 ///////////////////////////////////////////////////////////////////////////////
412 void GPU_readDataMem(u32* dmaAddress, s32 dmaCount)
414 const u16 *VIDEO_END=(GPU_FrameBuffer+(FRAME_BUFFER_SIZE/2)-1);
415 #ifdef DEBUG_ANALYSIS
416 dbg_anacnt_GPU_readDataMem++;
418 if(!FrameToRead) return;
420 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
421 GPU_GP1 &= ~0x14000000;
424 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
426 u32 data = (unsigned long)pvram[px];
434 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
435 // higher 16 bit (always, even if it's an odd width)
436 data |= (unsigned long)(pvram[px])<<16;
438 *dmaAddress++ = data;
447 GPU_GP1 &= ~0x08000000;
451 } while (--dmaCount);
453 GPU_GP1 = (GPU_GP1 | 0x14000000) & ~0x60000000;
454 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
459 ///////////////////////////////////////////////////////////////////////////////
460 u32 GPU_readData(void)
462 const u16 *VIDEO_END=(GPU_FrameBuffer+(FRAME_BUFFER_SIZE/2)-1);
463 #ifdef DEBUG_ANALYSIS
464 dbg_anacnt_GPU_readData++;
466 pcsx4all_prof_pause(PCSX4ALL_PROF_CPU);
467 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_READ);
468 GPU_GP1 &= ~0x14000000;
471 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
480 GPU_GP1 &= ~0x08000000;
483 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
484 GP0 |= pvram[px]<<16;
492 GPU_GP1 &= ~0x08000000;
497 GPU_GP1 |= 0x14000000;
499 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_READ);
500 pcsx4all_prof_resume(PCSX4ALL_PROF_CPU);
504 ///////////////////////////////////////////////////////////////////////////////
505 u32 GPU_readStatus(void)
507 #ifdef DEBUG_ANALYSIS
508 dbg_anacnt_GPU_readStatus++;
513 ///////////////////////////////////////////////////////////////////////////////
514 void GPU_writeStatus(u32 data)
516 #ifdef DEBUG_ANALYSIS
517 dbg_anacnt_GPU_writeStatus++;
519 pcsx4all_prof_pause(PCSX4ALL_PROF_CPU);
520 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
521 switch (data >> 24) {
526 GPU_GP1 &= ~0x08000000;
527 PacketCount = FrameToRead = FrameToWrite = 0;
530 GPU_GP1 &= ~0x08000000;
531 PacketCount = FrameToRead = FrameToWrite = 0;
534 GPU_GP1 = (GPU_GP1 & ~0x00800000) | ((data & 1) << 23);
537 if (data == 0x04000000)
539 GPU_GP1 = (GPU_GP1 & ~0x60000000) | ((data & 3) << 29);
542 DisplayArea[0] = (data & 0x000003FF); //(short)(data & 0x3ff);
543 DisplayArea[1] = ((data & 0x0007FC00)>>10); //(data & 0x000FFC00) >> 10; //(short)((data>>10)&0x1ff);
547 DisplayArea[4] = data & 0x000003FF; //(short)(data & 0x3ff);
548 DisplayArea[5] = (data & 0x000FFC00) >> 10; //(short)((data>>10) & 0x3ff);
553 GPU_GP1 = (GPU_GP1 & ~0x007F0000) | ((data & 0x3F) << 17) | ((data & 0x40) << 10);
554 static u32 HorizontalResolution[8] = { 256, 368, 320, 384, 512, 512, 640, 640 };
555 DisplayArea[2] = HorizontalResolution[(GPU_GP1 >> 16) & 7];
556 static u32 VerticalResolution[4] = { 240, 480, 256, 480 };
557 DisplayArea[3] = VerticalResolution[(GPU_GP1 >> 19) & 3];
558 isPAL = (data & 0x08) ? true : false; // if 1 - PAL mode, else NTSC
563 switch (data & 0xffff) {
567 GP0 = (DrawingArea[1] << 10) | DrawingArea[0];
570 GP0 = ((DrawingArea[3]-1) << 10) | (DrawingArea[2]-1);
574 GP0 = (DrawingOffset[1] << 11) | DrawingOffset[0];
584 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
585 pcsx4all_prof_resume(PCSX4ALL_PROF_CPU);
590 // Blitting functions
591 #include "gpu_blit.h"
593 INLINE void gpuVideoOutput(void)
595 static s16 old_res_horz, old_res_vert, old_rgb24;
596 s16 h0, x0, y0, w0, h1;
602 h0 = DisplayArea[3]; // video mode
604 h1 = DisplayArea[5] - DisplayArea[4]; // display needed
605 if (h0 == 480) h1 = Min2(h1*2,480);
607 u16* dest_screen16 = SCREEN;
608 u16* src_screen16 = &((u16*)GPU_FrameBuffer)[FRAME_OFFSET(x0,y0)];
609 u32 isRGB24 = (GPU_GP1 & 0x00200000 ? 32 : 0);
611 /* Clear the screen if resolution changed to prevent interlacing and clipping to clash */
612 if( (w0 != old_res_horz || h1 != old_res_vert || (s16)isRGB24 != old_rgb24) )
614 // Update old resolution
617 old_rgb24 = (s16)isRGB24;
618 // Finally, clear the screen for this special case
624 if(h0==256) h0 = 240; else if(h0==480) sizeShift = 2;
625 if(h1>h0) { src_screen16 += ((h1-h0)>>sizeShift)*1024; h1 = h0; }
626 else if(h1<h0) dest_screen16 += ((h0-h1)>>sizeShift)*VIDEO_WIDTH;
629 int incY = (h0==480) ? 2 : 1;
630 h0=(h0==480 ? 2048 : 1024);
632 if (!progressInterlace)
634 const int li=linesInterlace;
638 for(int y1=y0+h1; y0<y1; y0+=incY)
640 if( 0 == (y0&li) ) GPU_BlitWWDWW( src_screen16, dest_screen16, isRGB24);
641 dest_screen16 += VIDEO_WIDTH;
646 for(int y1=y0+h1; y0<y1; y0+=incY)
648 if( 0 == (y0&li) ) GPU_BlitWWWWWWWWS( src_screen16, dest_screen16, isRGB24, 4);
649 dest_screen16 += VIDEO_WIDTH;
654 for(int y1=y0+h1; y0<y1; y0+=incY)
656 if( 0 == (y0&li) ) GPU_BlitWW( src_screen16, dest_screen16, isRGB24);
657 dest_screen16 += VIDEO_WIDTH;
662 for(int y1=y0+h1; y0<y1; y0+=incY)
664 if( 0 == (y0&li) ) GPU_BlitWWWWWS( src_screen16, dest_screen16, isRGB24);
665 dest_screen16 += VIDEO_WIDTH;
670 for(int y1=y0+h1; y0<y1; y0+=incY)
672 if( 0 == (y0&li) ) GPU_BlitWWSWWSWS( src_screen16, dest_screen16, isRGB24);
673 dest_screen16 += VIDEO_WIDTH;
678 for(int y1=y0+h1; y0<y1; y0+=incY)
680 if( 0 == (y0&li) ) GPU_BlitWS( src_screen16, dest_screen16, isRGB24);
681 dest_screen16 += VIDEO_WIDTH;
689 const int li=linesInterlace;
690 bool flag=progressInterlace_flag; /* progressive interlace */
694 for(int y1=y0+h1; y0<y1; y0+=incY)
696 if(( 0 == (y0&li) ) && (flag=!flag)) GPU_BlitWWDWW( src_screen16, dest_screen16, isRGB24);
697 dest_screen16 += VIDEO_WIDTH;
702 for(int y1=y0+h1; y0<y1; y0+=incY)
704 if(( 0 == (y0&li) ) && (flag=!flag)) GPU_BlitWWWWWWWWS( src_screen16, dest_screen16, isRGB24, 4);
705 dest_screen16 += VIDEO_WIDTH;
710 for(int y1=y0+h1; y0<y1; y0+=incY)
712 if(( 0 == (y0&li) ) && (flag=!flag)) GPU_BlitWW( src_screen16, dest_screen16, isRGB24);
713 dest_screen16 += VIDEO_WIDTH;
718 for(int y1=y0+h1; y0<y1; y0+=incY)
720 if(( 0 == (y0&li) ) && (flag=!flag)) GPU_BlitWWWWWS( src_screen16, dest_screen16, isRGB24);
721 dest_screen16 += VIDEO_WIDTH;
726 for(int y1=y0+h1; y0<y1; y0+=incY)
728 if(( 0 == (y0&li) ) && (flag=!flag)) GPU_BlitWWSWWSWS( src_screen16, dest_screen16, isRGB24);
729 dest_screen16 += VIDEO_WIDTH;
734 for(int y1=y0+h1; y0<y1; y0+=incY)
736 if(( 0 == (y0&li) ) && (flag=!flag)) GPU_BlitWS( src_screen16, dest_screen16, isRGB24);
737 dest_screen16 += VIDEO_WIDTH;
742 progressInterlace_flag=!flag;
747 ///////////////////////////////////////////////////////////////////////////////
748 void GPU_updateLace(void)
750 #ifdef ENABLE_GPU_LOG_SUPPORT
751 fprintf(stdout,"GPU_updateLace()\n");
753 #ifdef DEBUG_ANALYSIS
754 dbg_anacnt_GPU_updateLace++;
756 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_COUNTERS);
757 #ifdef PROFILER_PCSX4ALL
758 pcsx4all_prof_frames++;
764 if (!passed) dbg_enable();
765 else pcsx4all_exit();
771 static const unsigned char skipTable[12][12] =
773 { 0,0,0,0,0,0,0,0,0,0,0,0 },
774 { 0,0,0,0,0,0,0,0,0,0,0,1 },
775 { 0,0,0,0,0,1,0,0,0,0,0,1 },
776 { 0,0,0,1,0,0,0,1,0,0,0,1 },
777 { 0,0,1,0,0,1,0,0,1,0,0,1 },
778 { 0,1,0,0,1,0,1,0,0,1,0,1 },
779 { 0,1,0,1,0,1,0,1,0,1,0,1 },
780 { 0,1,0,1,1,0,1,0,1,1,0,1 },
781 { 0,1,1,0,1,1,0,1,1,0,1,1 },
782 { 0,1,1,1,0,1,1,1,0,1,1,1 },
783 { 0,1,1,1,1,1,0,1,1,1,1,1 },
784 { 0,1,1,1,1,1,1,1,1,1,1,1 }
787 // Interlace bit toggle
788 GPU_GP1 ^= 0x80000000;
791 if ((!skipFrame) && (!isSkip) && (!(((GPU_GP1&0x08000000))||((GPU_GP1&0x00800000)))))
793 gpuVideoOutput(); // Display updated
795 if (DisplayArea[3] == 480)
797 if (linesInterlace_user) linesInterlace = 3; // 1/4 of lines
798 else linesInterlace = 1; // if 480 we only need half of lines
800 else if (linesInterlace != linesInterlace_user)
802 linesInterlace = linesInterlace_user; // resolution changed from 480 to lower one
809 static unsigned next=get_ticks();
810 unsigned now=get_ticks();
813 if (now<next) wait_ticks(next-now);
815 next+=(isPAL?(1000000/50):((unsigned)(1000000.0/59.94)));
819 // Show FPS statistics
822 static u32 real_fps=0;
823 static u32 prev=get_ticks();
824 static char msg[24]="FPS=000/00 SPD=000%";
827 if ((now-prev)>=1000000)
829 u32 expected_fps=(isPAL?50:60);
830 sprintf(msg,"FPS=%3d/%2d SPD=%3d%%",((real_fps*(12-skipCount))/12),((expected_fps*(12-skipCount))/12),((real_fps*100)/expected_fps));
834 port_printf(5,5,msg);
841 skipFrame=skipTable[skipCount][skCount];
842 skCount--; if (skCount<0) skCount=11;
850 skipFrame=skipTable[skipCount][skCount];
851 skCount--; if (skCount<0) skCount=11;
856 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_COUNTERS);
861 #include "../../frontend/plugin_lib.h"
865 extern void bgr555_to_rgb565(void *dst, void *src, int bytes);
866 extern void bgr888_to_rgb888(void *dst, void *src, int bytes);
867 static const struct rearmed_cbs *cbs;
868 static void *screen_buf;
870 static void blit(void)
872 static s16 old_res_horz, old_res_vert, old_rgb24;
873 s16 isRGB24 = (GPU_GP1 & 0x00200000) ? 1 : 0;
874 s16 h0, x0, y0, w0, h1;
878 x0 = DisplayArea[0] & ~3; // alignment needed by blitter
880 srcs = &((u16*)GPU_FrameBuffer)[FRAME_OFFSET(x0,y0)];
883 h0 = DisplayArea[3]; // video mode
885 h1 = DisplayArea[5] - DisplayArea[4]; // display needed
886 if (h0 == 480) h1 = Min2(h1*2,480);
891 if (w0 != old_res_horz || h1 != old_res_vert || isRGB24 != old_rgb24)
895 old_rgb24 = (s16)isRGB24;
896 screen_buf = cbs->pl_fbdev_set_mode(w0, h1, isRGB24 ? 24 : 16);
898 dest = (u8 *)screen_buf;
902 for (; h1-- > 0; dest += w0 * 3, srcs += 1024)
904 bgr888_to_rgb888(dest, srcs, w0 * 3);
909 for (; h1-- > 0; dest += w0 * 2, srcs += 1024)
911 bgr555_to_rgb565(dest, srcs, w0 * 2);
915 screen_buf = cbs->pl_fbdev_flip();
918 void GPU_updateLace(void)
920 // Interlace bit toggle
921 GPU_GP1 ^= 0x80000000;
923 if (!fb_dirty || (GPU_GP1&0x08800000))
930 if (*cbs->fskip_option)
937 long GPUopen(unsigned long *, char *, char *)
939 cbs->pl_fbdev_open();
940 screen_buf = cbs->pl_fbdev_flip();
946 cbs->pl_fbdev_close();
950 long GPUfreeze(unsigned int ulGetFreezeData, GPUFreeze_t* p2)
952 if (ulGetFreezeData > 1)
955 return GPU_freeze(ulGetFreezeData, p2);
958 void GPUrearmedCallbacks(const struct rearmed_cbs *cbs_)