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) */
33 bool skipFrame = false; /* skip frame (according to frame skip) */
34 bool alt_fps = false; /* Alternative FPS algorithm */
35 bool show_fps = false; /* Show FPS statistics */
37 bool isPAL = false; /* PAL video timing */
38 bool progressInterlace_flag = false; /* Progressive interlace flag */
39 bool progressInterlace = false; /* Progressive interlace option*/
40 bool frameLimit = false; /* frames to wait */
42 bool light = true; /* lighting */
43 bool blend = true; /* blending */
44 bool FrameToRead = false; /* load image in progress */
45 bool FrameToWrite = false; /* store image in progress */
46 bool fb_dirty = false;
48 bool enableAbbeyHack = false; /* Abe's Odyssey hack */
57 ///////////////////////////////////////////////////////////////////////////////
59 ///////////////////////////////////////////////////////////////////////////////
61 ///////////////////////////////////////////////////////////////////////////////
71 ///////////////////////////////////////////////////////////////////////////////
75 ///////////////////////////////////////////////////////////////////////////////
77 u32 TextureWindow [4];
79 u32 DrawingOffset [2];
81 ///////////////////////////////////////////////////////////////////////////////
87 ///////////////////////////////////////////////////////////////////////////////
97 GPUPacket PacketBuffer;
98 // FRAME_BUFFER_SIZE is defined in bytes; 512K is guard memory for out of range reads
99 u16 GPU_FrameBuffer[(FRAME_BUFFER_SIZE+512*1024)/2] __attribute__((aligned(2048)));
102 ///////////////////////////////////////////////////////////////////////////////
103 // Inner loop driver instanciation file
104 #include "gpu_inner.h"
106 ///////////////////////////////////////////////////////////////////////////////
108 #define GPU_RGB16(rgb) ((((rgb)&0xF80000)>>9)|(((rgb)&0xF800)>>6)|(((rgb)&0xF8)>>3))
110 #define GPU_EXPANDSIGN_POLY(x) (((s32)(x)<<20)>>20)
111 //#define GPU_EXPANDSIGN_POLY(x) (((s32)(x)<<21)>>21)
112 #define GPU_EXPANDSIGN_SPRT(x) (((s32)(x)<<21)>>21)
114 //#define GPU_TESTRANGE(x) { if((u32)(x+1024) > 2047) return; }
115 #define GPU_TESTRANGE(x) { if ((x<-1023) || (x>1023)) return; }
117 #define GPU_SWAP(a,b,t) {(t)=(a);(a)=(b);(b)=(t);}
119 ///////////////////////////////////////////////////////////////////////////////
120 // GPU internal image drawing functions
121 #include "gpu_raster_image.h"
123 ///////////////////////////////////////////////////////////////////////////////
124 // GPU internal line drawing functions
125 #include "gpu_raster_line.h"
127 ///////////////////////////////////////////////////////////////////////////////
128 // GPU internal polygon drawing functions
129 #include "gpu_raster_polygon.h"
131 ///////////////////////////////////////////////////////////////////////////////
132 // GPU internal sprite drawing functions
133 #include "gpu_raster_sprite.h"
135 ///////////////////////////////////////////////////////////////////////////////
136 // GPU command buffer execution/store
137 #include "gpu_command.h"
139 ///////////////////////////////////////////////////////////////////////////////
140 INLINE void gpuReset(void)
142 GPU_GP1 = 0x14802000;
143 TextureWindow[0] = 0;
144 TextureWindow[1] = 0;
145 TextureWindow[2] = 255;
146 TextureWindow[3] = 255;
147 DrawingArea[2] = 256;
148 DrawingArea[3] = 240;
149 DisplayArea[2] = 256;
150 DisplayArea[3] = 240;
151 DisplayArea[5] = 240;
154 ///////////////////////////////////////////////////////////////////////////////
160 for(int i=1;i<=(1<<TABLE_BITS);++i)
162 double v = 1.0 / double(i);
163 #ifdef GPU_TABLE_10_BITS
164 v *= double(0xffffffff>>1);
166 v *= double(0x80000000);
168 s_invTable[i-1]=s32(v);
173 ///////////////////////////////////////////////////////////////////////////////
174 void GPU_shutdown(void)
178 ///////////////////////////////////////////////////////////////////////////////
179 long GPU_freeze(unsigned int bWrite, GPUFreeze_t* p2)
182 if (p2->Version != 1) return (0);
186 p2->GPU_gp1 = GPU_GP1;
187 memset(p2->Control, 0, sizeof(p2->Control));
188 // save resolution and registers for P.E.Op.S. compatibility
189 p2->Control[3] = (3 << 24) | ((GPU_GP1 >> 23) & 1);
190 p2->Control[4] = (4 << 24) | ((GPU_GP1 >> 29) & 3);
191 p2->Control[5] = (5 << 24) | (DisplayArea[0] | (DisplayArea[1] << 10));
192 p2->Control[6] = (6 << 24) | (2560 << 12);
193 p2->Control[7] = (7 << 24) | (DisplayArea[4] | (DisplayArea[5] << 10));
194 p2->Control[8] = (8 << 24) | ((GPU_GP1 >> 17) & 0x3f) | ((GPU_GP1 >> 10) & 0x40);
195 memcpy(p2->FrameBuffer, (u16*)GPU_FrameBuffer, FRAME_BUFFER_SIZE);
200 GPU_GP1 = p2->GPU_gp1;
201 memcpy((u16*)GPU_FrameBuffer, p2->FrameBuffer, FRAME_BUFFER_SIZE);
202 GPU_writeStatus((5 << 24) | p2->Control[5]);
203 GPU_writeStatus((7 << 24) | p2->Control[7]);
204 GPU_writeStatus((8 << 24) | p2->Control[8]);
205 gpuSetTexture(GPU_GP1);
211 ///////////////////////////////////////////////////////////////////////////////
212 // GPU DMA comunication
214 ///////////////////////////////////////////////////////////////////////////////
217 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 0-15
218 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 16-31
219 3, 3, 3, 3, 6, 6, 6, 6, 4, 4, 4, 4, 8, 8, 8, 8, // 32-47
220 5, 5, 5, 5, 8, 8, 8, 8, 7, 7, 7, 7, 11, 11, 11, 11, // 48-63
221 2, 2, 2, 2, 0, 0, 0, 0, 3, 3, 3, 3, 3, 3, 3, 3, // 64-79
222 3, 3, 3, 3, 0, 0, 0, 0, 4, 4, 4, 4, 4, 4, 4, 4, // 80-95
223 2, 2, 2, 2, 3, 3, 3, 3, 1, 1, 1, 1, 2, 2, 2, 2, // 96-111
224 1, 1, 1, 1, 2, 2, 2, 2, 1, 1, 1, 1, 2, 2, 2, 2, // 112-127
225 3, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 128-
226 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 144
227 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, // 160
228 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
229 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
230 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
231 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, //
232 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 //
235 ///////////////////////////////////////////////////////////////////////////////
236 INLINE void gpuSendPacket()
238 #ifdef DEBUG_ANALYSIS
239 dbg_anacnt_GPU_sendPacket++;
241 gpuSendPacketFunction(PacketBuffer.U4[0]>>24);
244 ///////////////////////////////////////////////////////////////////////////////
245 INLINE void gpuCheckPacket(u32 uData)
249 PacketBuffer.U4[PacketIndex++] = uData;
254 PacketBuffer.U4[0] = uData;
255 PacketCount = PacketSize[uData >> 24];
258 if (!PacketCount) gpuSendPacket();
261 ///////////////////////////////////////////////////////////////////////////////
262 void GPU_writeDataMem(u32* dmaAddress, s32 dmaCount)
264 #ifdef DEBUG_ANALYSIS
265 dbg_anacnt_GPU_writeDataMem++;
267 pcsx4all_prof_pause(PCSX4ALL_PROF_CPU);
268 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
270 const u16 *VIDEO_END=(GPU_FrameBuffer+(FRAME_BUFFER_SIZE/2)-1);
271 GPU_GP1 &= ~0x14000000;
280 data = *dmaAddress++;
281 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
289 FrameToWrite = false;
290 GPU_GP1 &= ~0x08000000;
294 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
295 pvram[px] = data>>16;
302 FrameToWrite = false;
303 GPU_GP1 &= ~0x08000000;
311 data = *dmaAddress++;
313 gpuCheckPacket(data);
317 GPU_GP1 = (GPU_GP1 | 0x14000000) & ~0x60000000;
319 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
320 pcsx4all_prof_resume(PCSX4ALL_PROF_CPU);
324 INLINE int CheckForEndlessLoop(u32 *laddr)
326 if(laddr==lUsedAddr[1]) return 1;
327 if(laddr==lUsedAddr[2]) return 1;
329 if(laddr<lUsedAddr[0]) lUsedAddr[1]=laddr;
330 else lUsedAddr[2]=laddr;
335 ///////////////////////////////////////////////////////////////////////////////
336 long GPU_dmaChain(u32* baseAddr, u32 dmaVAddr)
338 #ifdef DEBUG_ANALYSIS
339 dbg_anacnt_GPU_dmaChain++;
341 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
342 u32 data, *address, count, offset;
343 unsigned int DMACommandCounter = 0;
346 GPU_GP1 &= ~0x14000000;
347 lUsedAddr[0]=lUsedAddr[1]=lUsedAddr[2]=(u32*)0x1fffff;
348 dmaVAddr &= 0x001FFFFF;
349 while (dmaVAddr != 0x1FFFFF)
351 address = (baseAddr + (dmaVAddr >> 2));
352 if(DMACommandCounter++ > 2000000) break;
353 if(CheckForEndlessLoop(address)) break;
355 count = (data >> 24);
356 offset = data & 0x001FFFFF;
357 if (dmaVAddr != offset) dmaVAddr = offset;
358 else dmaVAddr = 0x1FFFFF;
360 if(count>0) GPU_writeDataMem(address,count);
361 dma_words += 1 + count;
363 GPU_GP1 = (GPU_GP1 | 0x14000000) & ~0x60000000;
364 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
369 ///////////////////////////////////////////////////////////////////////////////
370 void GPU_writeData(u32 data)
372 const u16 *VIDEO_END=(GPU_FrameBuffer+(FRAME_BUFFER_SIZE/2)-1);
373 #ifdef DEBUG_ANALYSIS
374 dbg_anacnt_GPU_writeData++;
376 pcsx4all_prof_pause(PCSX4ALL_PROF_CPU);
377 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
378 GPU_GP1 &= ~0x14000000;
382 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
390 FrameToWrite = false;
391 GPU_GP1 &= ~0x08000000;
396 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
404 FrameToWrite = false;
405 GPU_GP1 &= ~0x08000000;
412 gpuCheckPacket(data);
414 GPU_GP1 |= 0x14000000;
416 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
417 pcsx4all_prof_resume(PCSX4ALL_PROF_CPU);
422 ///////////////////////////////////////////////////////////////////////////////
423 void GPU_readDataMem(u32* dmaAddress, s32 dmaCount)
425 const u16 *VIDEO_END=(GPU_FrameBuffer+(FRAME_BUFFER_SIZE/2)-1);
426 #ifdef DEBUG_ANALYSIS
427 dbg_anacnt_GPU_readDataMem++;
429 if(!FrameToRead) return;
431 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
432 GPU_GP1 &= ~0x14000000;
435 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
437 u32 data = (unsigned long)pvram[px];
445 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
446 // higher 16 bit (always, even if it's an odd width)
447 data |= (unsigned long)(pvram[px])<<16;
449 *dmaAddress++ = data;
458 GPU_GP1 &= ~0x08000000;
462 } while (--dmaCount);
464 GPU_GP1 = (GPU_GP1 | 0x14000000) & ~0x60000000;
465 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
470 ///////////////////////////////////////////////////////////////////////////////
471 u32 GPU_readData(void)
473 const u16 *VIDEO_END=(GPU_FrameBuffer+(FRAME_BUFFER_SIZE/2)-1);
474 #ifdef DEBUG_ANALYSIS
475 dbg_anacnt_GPU_readData++;
477 pcsx4all_prof_pause(PCSX4ALL_PROF_CPU);
478 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_READ);
479 GPU_GP1 &= ~0x14000000;
482 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
491 GPU_GP1 &= ~0x08000000;
494 if ((&pvram[px])>(VIDEO_END)) pvram-=512*1024;
495 GP0 |= pvram[px]<<16;
503 GPU_GP1 &= ~0x08000000;
508 GPU_GP1 |= 0x14000000;
510 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_READ);
511 pcsx4all_prof_resume(PCSX4ALL_PROF_CPU);
515 ///////////////////////////////////////////////////////////////////////////////
516 u32 GPU_readStatus(void)
518 #ifdef DEBUG_ANALYSIS
519 dbg_anacnt_GPU_readStatus++;
524 ///////////////////////////////////////////////////////////////////////////////
525 void GPU_writeStatus(u32 data)
527 #ifdef DEBUG_ANALYSIS
528 dbg_anacnt_GPU_writeStatus++;
530 pcsx4all_prof_pause(PCSX4ALL_PROF_CPU);
531 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
532 switch (data >> 24) {
537 GPU_GP1 &= ~0x08000000;
538 PacketCount = 0; FrameToRead = FrameToWrite = false;
541 GPU_GP1 &= ~0x08000000;
542 PacketCount = 0; FrameToRead = FrameToWrite = false;
545 GPU_GP1 = (GPU_GP1 & ~0x00800000) | ((data & 1) << 23);
548 if (data == 0x04000000)
550 GPU_GP1 = (GPU_GP1 & ~0x60000000) | ((data & 3) << 29);
553 DisplayArea[0] = (data & 0x000003FF); //(short)(data & 0x3ff);
554 DisplayArea[1] = ((data & 0x0007FC00)>>10); //(data & 0x000FFC00) >> 10; //(short)((data>>10)&0x1ff);
563 DisplayArea[4] = data & 0x000003FF; //(short)(data & 0x3ff);
564 DisplayArea[5] = (data & 0x000FFC00) >> 10; //(short)((data>>10) & 0x3ff);
569 GPU_GP1 = (GPU_GP1 & ~0x007F0000) | ((data & 0x3F) << 17) | ((data & 0x40) << 10);
570 static u32 HorizontalResolution[8] = { 256, 368, 320, 384, 512, 512, 640, 640 };
571 DisplayArea[2] = HorizontalResolution[(GPU_GP1 >> 16) & 7];
572 static u32 VerticalResolution[4] = { 240, 480, 256, 480 };
573 DisplayArea[3] = VerticalResolution[(GPU_GP1 >> 19) & 3];
574 isPAL = (data & 0x08) ? true : false; // if 1 - PAL mode, else NTSC
579 switch (data & 0xffff) {
583 GP0 = (DrawingArea[1] << 10) | DrawingArea[0];
586 GP0 = ((DrawingArea[3]-1) << 10) | (DrawingArea[2]-1);
590 GP0 = (DrawingOffset[1] << 11) | DrawingOffset[0];
600 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_HW_WRITE);
601 pcsx4all_prof_resume(PCSX4ALL_PROF_CPU);
606 // Blitting functions
607 #include "gpu_blit.h"
609 INLINE void gpuVideoOutput(void)
611 static s16 old_res_horz, old_res_vert, old_rgb24;
612 s16 h0, x0, y0, w0, h1;
618 h0 = DisplayArea[3]; // video mode
620 h1 = DisplayArea[5] - DisplayArea[4]; // display needed
621 if (h0 == 480) h1 = Min2(h1*2,480);
623 u16* dest_screen16 = SCREEN;
624 u16* src_screen16 = &((u16*)GPU_FrameBuffer)[FRAME_OFFSET(x0,y0)];
625 u32 isRGB24 = (GPU_GP1 & 0x00200000 ? 32 : 0);
627 /* Clear the screen if resolution changed to prevent interlacing and clipping to clash */
628 if( (w0 != old_res_horz || h1 != old_res_vert || (s16)isRGB24 != old_rgb24) )
630 // Update old resolution
633 old_rgb24 = (s16)isRGB24;
634 // Finally, clear the screen for this special case
640 if(h0==256) h0 = 240; else if(h0==480) sizeShift = 2;
641 if(h1>h0) { src_screen16 += ((h1-h0)>>sizeShift)*1024; h1 = h0; }
642 else if(h1<h0) dest_screen16 += ((h0-h1)>>sizeShift)*VIDEO_WIDTH;
645 int incY = (h0==480) ? 2 : 1;
646 h0=(h0==480 ? 2048 : 1024);
649 const int li=linesInterlace;
650 bool pi=progressInterlace;
651 bool pif=progressInterlace_flag;
655 for(int y1=y0+h1; y0<y1; y0+=incY)
657 if(( 0 == (y0&li) ) && ((!pi) || (pif=!pif))) GPU_BlitWWDWW( 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) ) && ((!pi) || (pif=!pif))) GPU_BlitWWWWWWWWS( src_screen16, dest_screen16, isRGB24, 4);
666 dest_screen16 += VIDEO_WIDTH;
671 for(int y1=y0+h1; y0<y1; y0+=incY)
673 if(( 0 == (y0&li) ) && ((!pi) || (pif=!pif))) GPU_BlitWW( 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) ) && ((!pi) || (pif=!pif))) GPU_BlitWWWWWS( 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) ) && ((!pi) || (pif=!pif))) GPU_BlitWWSWWSWS( src_screen16, dest_screen16, isRGB24);
690 dest_screen16 += VIDEO_WIDTH;
695 for(int y1=y0+h1; y0<y1; y0+=incY)
697 if(( 0 == (y0&li) ) && ((!pi) || (pif=!pif))) GPU_BlitWS( src_screen16, dest_screen16, isRGB24);
698 dest_screen16 += VIDEO_WIDTH;
703 progressInterlace_flag=!progressInterlace_flag;
708 ///////////////////////////////////////////////////////////////////////////////
709 void GPU_updateLace(void)
711 #ifdef ENABLE_GPU_LOG_SUPPORT
712 fprintf(stdout,"GPU_updateLace()\n");
714 #ifdef DEBUG_ANALYSIS
715 dbg_anacnt_GPU_updateLace++;
717 pcsx4all_prof_start_with_pause(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_COUNTERS);
718 #ifdef PROFILER_PCSX4ALL
719 pcsx4all_prof_frames++;
725 if (!passed) dbg_enable();
726 else pcsx4all_exit();
732 static const unsigned char skipTable[12][12] =
734 { 0,0,0,0,0,0,0,0,0,0,0,0 },
735 { 0,0,0,0,0,0,0,0,0,0,0,1 },
736 { 0,0,0,0,0,1,0,0,0,0,0,1 },
737 { 0,0,0,1,0,0,0,1,0,0,0,1 },
738 { 0,0,1,0,0,1,0,0,1,0,0,1 },
739 { 0,1,0,0,1,0,1,0,0,1,0,1 },
740 { 0,1,0,1,0,1,0,1,0,1,0,1 },
741 { 0,1,0,1,1,0,1,0,1,1,0,1 },
742 { 0,1,1,0,1,1,0,1,1,0,1,1 },
743 { 0,1,1,1,0,1,1,1,0,1,1,1 },
744 { 0,1,1,1,1,1,0,1,1,1,1,1 },
745 { 0,1,1,1,1,1,1,1,1,1,1,1 }
748 // Interlace bit toggle
749 GPU_GP1 ^= 0x80000000;
752 if ((!skipFrame) && (!isSkip) && (fb_dirty) && (!(((GPU_GP1&0x08000000))||((GPU_GP1&0x00800000)))))
754 gpuVideoOutput(); // Display updated
756 if (DisplayArea[3] == 480)
758 if (linesInterlace_user) linesInterlace = 3; // 1/4 of lines
759 else linesInterlace = 1; // if 480 we only need half of lines
761 else if (linesInterlace != linesInterlace_user)
763 linesInterlace = linesInterlace_user; // resolution changed from 480 to lower one
771 static unsigned next=get_ticks();
774 unsigned now=get_ticks();
775 if (now<next) wait_ticks(next-now);
777 next+=(isPAL?(1000000/50):((unsigned)(1000000.0/59.94)));
780 // Show FPS statistics
783 static u32 real_fps=0;
784 static u32 prev=get_ticks();
785 static char msg[32]="FPS=000/00 SPD=000%";
788 if ((now-prev)>=1000000)
790 u32 expected_fps=(isPAL?50:60);
791 sprintf(msg,"FPS=%3d/%2d SPD=%3d%%",((real_fps*(12-skipCount))/12),((expected_fps*(12-skipCount))/12),((real_fps*100)/expected_fps));
795 port_printf(5,5,msg);
802 skipFrame=skipTable[skipCount][skCount];
803 skCount--; if (skCount<0) skCount=11;
811 skipFrame=skipTable[skipCount][skCount];
812 skCount--; if (skCount<0) skCount=11;
818 pcsx4all_prof_end_with_resume(PCSX4ALL_PROF_GPU,PCSX4ALL_PROF_COUNTERS);
823 #include "../../frontend/plugin_lib.h"
824 #include "../../frontend/cspace.h"
828 static const struct rearmed_cbs *cbs;
829 static void *screen_buf;
830 static s16 old_res_horz, old_res_vert, old_rgb24;
832 static void blit(void)
834 u16 *base = (u16 *)GPU_FrameBuffer;
835 s16 isRGB24 = (GPU_GP1 & 0x00200000) ? 1 : 0;
836 s16 h0, x0, y0, w0, h1;
840 x0 = DisplayArea[0] & ~1; // alignment needed by blitter
842 fb_offs = FRAME_OFFSET(x0, y0);
845 h0 = DisplayArea[3]; // video mode
847 h1 = DisplayArea[5] - DisplayArea[4]; // display needed
848 if (h0 == 480) h1 = Min2(h1*2,480);
853 if (w0 != old_res_horz || h1 != old_res_vert || isRGB24 != old_rgb24)
857 old_rgb24 = (s16)isRGB24;
858 screen_buf = cbs->pl_vout_set_mode(w0, h1, isRGB24 ? 24 : 16);
860 dest = (u8 *)screen_buf;
865 for (; h1-- > 0; dest += w0 * 3, fb_offs += 1024)
867 fb_offs &= 1024*512-1;
868 bgr888_to_rgb888(dest, base + fb_offs, w0 * 3);
871 for (; h1-- > 0; dest += w0 * 2, fb_offs += 1024)
873 fb_offs &= 1024*512-1;
874 bgr888_to_rgb565(dest, base + fb_offs, w0 * 3);
880 for (; h1-- > 0; dest += w0 * 2, fb_offs += 1024)
882 fb_offs &= 1024*512-1;
883 bgr555_to_rgb565(dest, base + fb_offs, w0 * 2);
887 screen_buf = cbs->pl_vout_flip();
890 static void blit_raw(void)
892 s16 isRGB24 = (GPU_GP1 & 0x00200000) ? 1 : 0;
896 h0 = DisplayArea[3]; // video mode
897 h1 = DisplayArea[5] - DisplayArea[4]; // display needed
898 if (h0 == 480) h1 = Min2(h1*2,480);
903 if (w0 != old_res_horz || h1 != old_res_vert || isRGB24 != old_rgb24)
907 old_rgb24 = (s16)isRGB24;
908 screen_buf = cbs->pl_vout_set_mode(w0, h1, isRGB24 ? 24 : 16);
910 cbs->pl_vout_raw_flip(DisplayArea[0], DisplayArea[1]);
913 void GPU_updateLace(void)
915 // Interlace bit toggle
916 GPU_GP1 ^= 0x80000000;
918 if (!fb_dirty || (GPU_GP1&0x08800000))
922 if (cbs->pl_vout_raw_flip != NULL)
932 wasSkip = isSkip = 0;
935 skipFrame = cbs->fskip_advice || cbs->frameskip == 1;
938 long GPUopen(unsigned long *, char *, char *)
941 screen_buf = cbs->pl_vout_flip();
947 cbs->pl_vout_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_)
961 enableAbbeyHack = cbs_->gpu_unai.abe_hack;
962 light = !cbs_->gpu_unai.no_light;
963 blend = !cbs_->gpu_unai.no_blend;
964 if (cbs_->pl_vout_set_raw_vram)
965 cbs_->pl_vout_set_raw_vram((void *)GPU_FrameBuffer);