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 enableAbbeyHack = false; /* Abe's Odyssey hack */
51 ///////////////////////////////////////////////////////////////////////////////
53 ///////////////////////////////////////////////////////////////////////////////
55 ///////////////////////////////////////////////////////////////////////////////
68 ///////////////////////////////////////////////////////////////////////////////
72 ///////////////////////////////////////////////////////////////////////////////
74 u32 TextureWindow [4];
76 u32 DrawingOffset [2];
78 ///////////////////////////////////////////////////////////////////////////////
84 ///////////////////////////////////////////////////////////////////////////////
94 GPUPacket PacketBuffer;
95 u16 GPU_FrameBuffer[FRAME_BUFFER_SIZE/2] __attribute__((aligned(16))); // FRAME_BUFFER_SIZE is defined in bytes
98 ///////////////////////////////////////////////////////////////////////////////
99 // Inner loop driver instanciation file
100 #include "gpu_inner.h"
102 ///////////////////////////////////////////////////////////////////////////////
104 #define GPU_RGB16(rgb) ((((rgb)&0xF80000)>>9)|(((rgb)&0xF800)>>6)|(((rgb)&0xF8)>>3))
106 #define GPU_EXPANDSIGN_POLY(x) (((s32)(x)<<20)>>20)
107 //#define GPU_EXPANDSIGN_POLY(x) (((s32)(x)<<21)>>21)
108 #define GPU_EXPANDSIGN_SPRT(x) (((s32)(x)<<21)>>21)
110 //#define GPU_TESTRANGE(x) { if((u32)(x+1024) > 2047) return; }
111 #define GPU_TESTRANGE(x) { if ((x<-1023) || (x>1023)) return; }
113 #define GPU_SWAP(a,b,t) {(t)=(a);(a)=(b);(b)=(t);}
115 ///////////////////////////////////////////////////////////////////////////////
116 // GPU internal image drawing functions
117 #include "gpu_raster_image.h"
119 ///////////////////////////////////////////////////////////////////////////////
120 // GPU internal line drawing functions
121 #include "gpu_raster_line.h"
123 ///////////////////////////////////////////////////////////////////////////////
124 // GPU internal polygon drawing functions
125 #include "gpu_raster_polygon.h"
127 ///////////////////////////////////////////////////////////////////////////////
128 // GPU internal sprite drawing functions
129 #include "gpu_raster_sprite.h"
131 ///////////////////////////////////////////////////////////////////////////////
132 // GPU command buffer execution/store
133 #include "gpu_command.h"
135 ///////////////////////////////////////////////////////////////////////////////
136 INLINE void gpuReset(void)
138 GPU_GP1 = 0x14802000;
139 TextureWindow[0] = 0;
140 TextureWindow[1] = 0;
141 TextureWindow[2] = 255;
142 TextureWindow[3] = 255;
143 DrawingArea[2] = 256;
144 DrawingArea[3] = 240;
145 DisplayArea[2] = 256;
146 DisplayArea[3] = 240;
147 DisplayArea[5] = 240;
150 ///////////////////////////////////////////////////////////////////////////////
156 for(int i=1;i<=(1<<TABLE_BITS);++i)
158 double v = 1.0 / double(i);
159 #ifdef GPU_TABLE_10_BITS
160 v *= double(0xffffffff>>1);
162 v *= double(0x80000000);
164 s_invTable[i-1]=s32(v);
169 ///////////////////////////////////////////////////////////////////////////////
170 void GPU_shutdown(void)
174 ///////////////////////////////////////////////////////////////////////////////
175 long GPU_freeze(unsigned int bWrite, GPUFreeze_t* p2)
178 if (p2->Version != 1) return (0);
182 p2->GPU_gp1 = GPU_GP1;
183 memcpy(p2->FrameBuffer, (u16*)GPU_FrameBuffer, FRAME_BUFFER_SIZE);
188 GPU_GP1 = p2->GPU_gp1;
189 memcpy((u16*)GPU_FrameBuffer, p2->FrameBuffer, FRAME_BUFFER_SIZE);
195 ///////////////////////////////////////////////////////////////////////////////
196 // GPU DMA comunication
198 ///////////////////////////////////////////////////////////////////////////////
201 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0-15
202 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16-31
203 3, 3, 3, 3, 6, 6, 6, 6, 4, 4, 4, 4, 8, 8, 8, 8, // 32-47
204 5, 5, 5, 5, 8, 8, 8, 8, 7, 7, 7, 7, 11, 11, 11, 11, // 48-63
205 2, 2, 2, 2, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, // 64-79
206 3, 3, 3, 3, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, // 80-95
207 2, 2, 2, 2, 3, 3, 3, 3, 1, 1, 1, 1, 2, 2, 2, 2, // 96-111
208 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, // 112-127
209 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 128-
210 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 144
211 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 160
212 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
213 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
214 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
215 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
216 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 //
219 ///////////////////////////////////////////////////////////////////////////////
220 INLINE void gpuSendPacket()
222 #ifdef DEBUG_ANALYSIS
223 dbg_anacnt_GPU_sendPacket++;
225 gpuSendPacketFunction(PacketBuffer.U4[0]>>24);
228 ///////////////////////////////////////////////////////////////////////////////
229 INLINE void gpuCheckPacket(u32 uData)
233 PacketBuffer.U4[PacketIndex++] = uData;
238 PacketBuffer.U4[0] = uData;
239 PacketCount = PacketSize[uData >> 24];
242 if (!PacketCount) gpuSendPacket();
245 ///////////////////////////////////////////////////////////////////////////////
246 void GPU_writeDataMem(u32* dmaAddress, s32 dmaCount)
248 #ifdef DEBUG_ANALYSIS
249 dbg_anacnt_GPU_writeDataMem++;
251 pcsx4all_prof_pause(PCSX4ALL_PROF_CPU);
252 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
254 const u16 *VIDEO_END=(GPU_FrameBuffer+(FRAME_BUFFER_SIZE/2)-1);
255 GPU_GP1 &= ~0x14000000;
263 data = *dmaAddress++;
264 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
273 GPU_GP1 &= ~0x08000000;
277 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
278 pvram[px] = data>>16;
286 GPU_GP1 &= ~0x08000000;
294 data = *dmaAddress++;
296 gpuCheckPacket(data);
300 GPU_GP1 = (GPU_GP1 | 0x14000000) & ~0x60000000;
301 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
302 pcsx4all_prof_resume(PCSX4ALL_PROF_CPU);
306 INLINE int CheckForEndlessLoop(u32 *laddr)
308 if(laddr==lUsedAddr[1]) return 1;
309 if(laddr==lUsedAddr[2]) return 1;
311 if(laddr<lUsedAddr[0]) lUsedAddr[1]=laddr;
312 else lUsedAddr[2]=laddr;
317 ///////////////////////////////////////////////////////////////////////////////
318 void GPU_dmaChain(u32* baseAddr, u32 dmaVAddr)
320 #ifdef DEBUG_ANALYSIS
321 dbg_anacnt_GPU_dmaChain++;
323 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
324 u32 data, *address, count, offset;
325 unsigned int DMACommandCounter = 0;
327 GPU_GP1 &= ~0x14000000;
328 lUsedAddr[0]=lUsedAddr[1]=lUsedAddr[2]=(u32*)0x1fffff;
329 dmaVAddr &= 0x001FFFFF;
330 while (dmaVAddr != 0x1FFFFF)
332 address = (baseAddr + (dmaVAddr >> 2));
333 if(DMACommandCounter++ > 2000000) break;
334 if(CheckForEndlessLoop(address)) break;
336 count = (data >> 24);
337 offset = data & 0x001FFFFF;
338 if (dmaVAddr != offset) dmaVAddr = offset;
339 else dmaVAddr = 0x1FFFFF;
341 if(count>0) GPU_writeDataMem(address,count);
343 GPU_GP1 = (GPU_GP1 | 0x14000000) & ~0x60000000;
344 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
347 ///////////////////////////////////////////////////////////////////////////////
348 void GPU_writeData(u32 data)
350 const u16 *VIDEO_END=(GPU_FrameBuffer+(FRAME_BUFFER_SIZE/2)-1);
351 #ifdef DEBUG_ANALYSIS
352 dbg_anacnt_GPU_writeData++;
354 pcsx4all_prof_pause(PCSX4ALL_PROF_CPU);
355 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
356 GPU_GP1 &= ~0x14000000;
360 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
369 GPU_GP1 &= ~0x08000000;
374 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
383 GPU_GP1 &= ~0x08000000;
390 gpuCheckPacket(data);
392 GPU_GP1 |= 0x14000000;
393 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
394 pcsx4all_prof_resume(PCSX4ALL_PROF_CPU);
399 ///////////////////////////////////////////////////////////////////////////////
400 void GPU_readDataMem(u32* dmaAddress, s32 dmaCount)
402 const u16 *VIDEO_END=(GPU_FrameBuffer+(FRAME_BUFFER_SIZE/2)-1);
403 #ifdef DEBUG_ANALYSIS
404 dbg_anacnt_GPU_readDataMem++;
406 if(!FrameToRead) return;
408 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
409 GPU_GP1 &= ~0x14000000;
412 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
414 u32 data = (unsigned long)pvram[px];
422 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
423 // higher 16 bit (always, even if it's an odd width)
424 data |= (unsigned long)(pvram[px])<<16;
426 *dmaAddress++ = data;
435 GPU_GP1 &= ~0x08000000;
439 } while (--dmaCount);
441 GPU_GP1 = (GPU_GP1 | 0x14000000) & ~0x60000000;
442 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
447 ///////////////////////////////////////////////////////////////////////////////
448 u32 GPU_readData(void)
450 const u16 *VIDEO_END=(GPU_FrameBuffer+(FRAME_BUFFER_SIZE/2)-1);
451 #ifdef DEBUG_ANALYSIS
452 dbg_anacnt_GPU_readData++;
454 pcsx4all_prof_pause(PCSX4ALL_PROF_CPU);
455 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_READ);
456 GPU_GP1 &= ~0x14000000;
459 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
468 GPU_GP1 &= ~0x08000000;
471 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
472 GP0 |= pvram[px]<<16;
480 GPU_GP1 &= ~0x08000000;
485 GPU_GP1 |= 0x14000000;
487 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_READ);
488 pcsx4all_prof_resume(PCSX4ALL_PROF_CPU);
492 ///////////////////////////////////////////////////////////////////////////////
493 u32 GPU_readStatus(void)
495 #ifdef DEBUG_ANALYSIS
496 dbg_anacnt_GPU_readStatus++;
501 ///////////////////////////////////////////////////////////////////////////////
502 void GPU_writeStatus(u32 data)
504 #ifdef DEBUG_ANALYSIS
505 dbg_anacnt_GPU_writeStatus++;
507 pcsx4all_prof_pause(PCSX4ALL_PROF_CPU);
508 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
509 switch (data >> 24) {
514 GPU_GP1 &= ~0x08000000;
515 PacketCount = FrameToRead = FrameToWrite = 0;
518 GPU_GP1 &= ~0x08000000;
519 PacketCount = FrameToRead = FrameToWrite = 0;
522 GPU_GP1 = (GPU_GP1 & ~0x00800000) | ((data & 1) << 23);
525 if (data == 0x04000000)
527 GPU_GP1 = (GPU_GP1 & ~0x60000000) | ((data & 3) << 29);
530 DisplayArea[0] = (data & 0x000003FF); //(short)(data & 0x3ff);
531 DisplayArea[1] = ((data & 0x0007FC00)>>10); //(data & 0x000FFC00) >> 10; //(short)((data>>10)&0x1ff);
534 DisplayArea[4] = data & 0x000003FF; //(short)(data & 0x3ff);
535 DisplayArea[5] = (data & 0x000FFC00) >> 10; //(short)((data>>10) & 0x3ff);
539 GPU_GP1 = (GPU_GP1 & ~0x007F0000) | ((data & 0x3F) << 17) | ((data & 0x40) << 10);
540 static u32 HorizontalResolution[8] = { 256, 368, 320, 384, 512, 512, 640, 640 };
541 DisplayArea[2] = HorizontalResolution[(GPU_GP1 >> 16) & 7];
542 static u32 VerticalResolution[4] = { 240, 480, 256, 480 };
543 DisplayArea[3] = VerticalResolution[(GPU_GP1 >> 19) & 3];
544 isPAL = (data & 0x08) ? true : false; // if 1 - PAL mode, else NTSC
548 switch (data & 0xffff) {
552 GP0 = (DrawingArea[1] << 10) | DrawingArea[0];
555 GP0 = ((DrawingArea[3]-1) << 10) | (DrawingArea[2]-1);
559 GP0 = (DrawingOffset[1] << 11) | DrawingOffset[0];
569 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
570 pcsx4all_prof_resume(PCSX4ALL_PROF_CPU);
575 // Blitting functions
576 #include "gpu_blit.h"
578 INLINE void gpuVideoOutput(void)
580 static s16 old_res_horz, old_res_vert, old_rgb24;
581 s16 h0, x0, y0, w0, h1;
587 h0 = DisplayArea[3]; // video mode
589 h1 = DisplayArea[5] - DisplayArea[4]; // display needed
590 if (h0 == 480) h1 = Min2(h1*2,480);
592 u16* dest_screen16 = SCREEN;
593 u16* src_screen16 = &((u16*)GPU_FrameBuffer)[FRAME_OFFSET(x0,y0)];
594 u32 isRGB24 = (GPU_GP1 & 0x00200000 ? 32 : 0);
596 /* Clear the screen if resolution changed to prevent interlacing and clipping to clash */
597 if( (w0 != old_res_horz || h1 != old_res_vert || (s16)isRGB24 != old_rgb24) )
599 // Update old resolution
602 old_rgb24 = (s16)isRGB24;
603 // Finally, clear the screen for this special case
609 if(h0==256) h0 = 240; else if(h0==480) sizeShift = 2;
610 if(h1>h0) { src_screen16 += ((h1-h0)>>sizeShift)*1024; h1 = h0; }
611 else if(h1<h0) dest_screen16 += ((h0-h1)>>sizeShift)*VIDEO_WIDTH;
614 int incY = (h0==480) ? 2 : 1;
615 h0=(h0==480 ? 2048 : 1024);
617 if (!progressInterlace)
619 const int li=linesInterlace;
623 for(int y1=y0+h1; y0<y1; y0+=incY)
625 if( 0 == (y0&li) ) GPU_BlitWWDWW( src_screen16, dest_screen16, isRGB24);
626 dest_screen16 += VIDEO_WIDTH;
631 for(int y1=y0+h1; y0<y1; y0+=incY)
633 if( 0 == (y0&li) ) GPU_BlitWWWWWWWWS( src_screen16, dest_screen16, isRGB24, 4);
634 dest_screen16 += VIDEO_WIDTH;
639 for(int y1=y0+h1; y0<y1; y0+=incY)
641 if( 0 == (y0&li) ) GPU_BlitWW( 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_BlitWWWWWS( src_screen16, dest_screen16, isRGB24);
650 dest_screen16 += VIDEO_WIDTH;
655 for(int y1=y0+h1; y0<y1; y0+=incY)
657 if( 0 == (y0&li) ) GPU_BlitWWSWWSWS( 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_BlitWS( src_screen16, dest_screen16, isRGB24);
666 dest_screen16 += VIDEO_WIDTH;
674 const int li=linesInterlace;
675 bool flag=progressInterlace_flag; /* progressive interlace */
679 for(int y1=y0+h1; y0<y1; y0+=incY)
681 if(( 0 == (y0&li) ) && (flag=!flag)) GPU_BlitWWDWW( src_screen16, dest_screen16, isRGB24);
682 dest_screen16 += VIDEO_WIDTH;
687 for(int y1=y0+h1; y0<y1; y0+=incY)
689 if(( 0 == (y0&li) ) && (flag=!flag)) GPU_BlitWWWWWWWWS( src_screen16, dest_screen16, isRGB24, 4);
690 dest_screen16 += VIDEO_WIDTH;
695 for(int y1=y0+h1; y0<y1; y0+=incY)
697 if(( 0 == (y0&li) ) && (flag=!flag)) GPU_BlitWW( 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_BlitWWWWWS( src_screen16, dest_screen16, isRGB24);
706 dest_screen16 += VIDEO_WIDTH;
711 for(int y1=y0+h1; y0<y1; y0+=incY)
713 if(( 0 == (y0&li) ) && (flag=!flag)) GPU_BlitWWSWWSWS( 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_BlitWS( src_screen16, dest_screen16, isRGB24);
722 dest_screen16 += VIDEO_WIDTH;
727 progressInterlace_flag=!flag;
732 ///////////////////////////////////////////////////////////////////////////////
733 void GPU_updateLace(void)
735 #ifdef ENABLE_GPU_LOG_SUPPORT
736 fprintf(stdout,"GPU_updateLace()\n");
738 #ifdef DEBUG_ANALYSIS
739 dbg_anacnt_GPU_updateLace++;
741 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_COUNTERS);
742 #ifdef PROFILER_PCSX4ALL
743 pcsx4all_prof_frames++;
749 if (!passed) dbg_enable();
750 else pcsx4all_exit();
756 static const unsigned char skipTable[12][12] =
758 { 0,0,0,0,0,0,0,0,0,0,0,0 },
759 { 0,0,0,0,0,0,0,0,0,0,0,1 },
760 { 0,0,0,0,0,1,0,0,0,0,0,1 },
761 { 0,0,0,1,0,0,0,1,0,0,0,1 },
762 { 0,0,1,0,0,1,0,0,1,0,0,1 },
763 { 0,1,0,0,1,0,1,0,0,1,0,1 },
764 { 0,1,0,1,0,1,0,1,0,1,0,1 },
765 { 0,1,0,1,1,0,1,0,1,1,0,1 },
766 { 0,1,1,0,1,1,0,1,1,0,1,1 },
767 { 0,1,1,1,0,1,1,1,0,1,1,1 },
768 { 0,1,1,1,1,1,0,1,1,1,1,1 },
769 { 0,1,1,1,1,1,1,1,1,1,1,1 }
772 // Interlace bit toggle
773 GPU_GP1 ^= 0x80000000;
776 if ((!skipFrame) && (!isSkip) && (!(((GPU_GP1&0x08000000))||((GPU_GP1&0x00800000)))))
778 gpuVideoOutput(); // Display updated
780 if (DisplayArea[3] == 480)
782 if (linesInterlace_user) linesInterlace = 3; // 1/4 of lines
783 else linesInterlace = 1; // if 480 we only need half of lines
785 else if (linesInterlace != linesInterlace_user)
787 linesInterlace = linesInterlace_user; // resolution changed from 480 to lower one
794 static unsigned next=get_ticks();
795 unsigned now=get_ticks();
798 if (now<next) wait_ticks(next-now);
800 next+=(isPAL?(1000000/50):((unsigned)(1000000.0/59.94)));
804 // Show FPS statistics
807 static u32 real_fps=0;
808 static u32 prev=get_ticks();
809 static char msg[24]="FPS=000/00 SPD=000%";
812 if ((now-prev)>=1000000)
814 u32 expected_fps=(isPAL?50:60);
815 sprintf(msg,"FPS=%3d/%2d SPD=%3d%%",((real_fps*(12-skipCount))/12),((expected_fps*(12-skipCount))/12),((real_fps*100)/expected_fps));
819 port_printf(5,5,msg);
826 skipFrame=skipTable[skipCount][skCount];
827 skCount--; if (skCount<0) skCount=11;
835 skipFrame=skipTable[skipCount][skCount];
836 skCount--; if (skCount<0) skCount=11;
841 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_COUNTERS);
846 #include "../../frontend/plugin_lib.h"
850 extern void bgr555_to_rgb565(void *dst, void *src, int bytes);
851 extern void bgr888_to_rgb888(void *dst, void *src, int bytes);
852 static const struct rearmed_cbs *cbs;
853 static void *screen_buf;
855 static void blit(void)
857 static s16 old_res_horz, old_res_vert, old_rgb24;
858 s16 isRGB24 = (GPU_GP1 & 0x00200000) ? 1 : 0;
859 s16 h0, x0, y0, w0, h1;
860 u8 *dest = (u8 *)screen_buf;
863 x0 = DisplayArea[0] & ~3; // alignment needed by blitter
865 srcs = &((u16*)GPU_FrameBuffer)[FRAME_OFFSET(x0,y0)];
868 h0 = DisplayArea[3]; // video mode
870 h1 = DisplayArea[5] - DisplayArea[4]; // display needed
871 if (h0 == 480) h1 = Min2(h1*2,480);
873 if (w0 != old_res_horz || h1 != old_res_vert || isRGB24 != old_rgb24)
877 old_rgb24 = (s16)isRGB24;
878 cbs->pl_fbdev_set_mode(w0, h1, isRGB24 ? 24 : 16);
883 for (; h1-- > 0; dest += w0 * 3, srcs += 1024)
885 bgr888_to_rgb888(dest, srcs, w0 * 3);
890 for (; h1-- > 0; dest += w0 * 2, srcs += 1024)
892 bgr555_to_rgb565(dest, srcs, w0 * 2);
896 screen_buf = cbs->pl_fbdev_flip();
899 void GPU_updateLace(void)
901 // Interlace bit toggle
902 GPU_GP1 ^= 0x80000000;
904 if (!((GPU_GP1&0x08000000) || (GPU_GP1&0x00800000)))
908 long GPUopen(unsigned long *, char *, char *)
910 cbs->pl_fbdev_open();
911 screen_buf = cbs->pl_fbdev_flip();
917 cbs->pl_fbdev_close();
921 long GPUfreeze(unsigned int ulGetFreezeData, GPUFreeze_t* p2)
923 if (ulGetFreezeData > 1)
926 return GPU_freeze(ulGetFreezeData, p2);
929 void GPUrearmedCallbacks(const struct rearmed_cbs *cbs_)