1 /* FCE Ultra - NES/Famicom Emulator
3 * Copyright notice for this file:
4 * Copyright (C) 1998 \Firebug\
5 * Copyright (C) 2002 Ben Parnell
7 * This program is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; either version 2 of the License, or
10 * (at your option) any later version.
12 * This program is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 * GNU General Public License for more details.
17 * You should have received a copy of the GNU General Public License
18 * along with this program; if not, write to the Free Software
19 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
28 #define outportb(port, value) outb(value, port)
29 #define outportw(port, value) outw(value, port)
33 #include "svga-video.h"
42 static int vidready=0;
45 void LockConsole(void)
51 FCEUI_DispMessage("Console locked.");
55 void UnlockConsole(void)
61 FCEUI_DispMessage("Console unlocked.");
70 outportb(0x3c0,(0x11|0x20));
78 void TweakVGA(int VGAMode)
86 for(I=0;I<768;I++) outportb(0x3C9,0x00);
89 I=inportb(0x3D5)&0x7F;
95 case 1: for(I=0;I<25;I++) VGAPortSet(v256x240[I]);break;
96 case 2: for(I=0;I<25;I++) VGAPortSet(v256x256[I]);break;
97 case 3: for(I=0;I<25;I++) VGAPortSet(v256x256S[I]);break;
98 case 6: for(I=0;I<25;I++) VGAPortSet(v256x224S[I]);break;
99 case 8: for(I=0;I<25;I++) VGAPortSet(v256x224_103[I]);break;
109 static uint8 palettedbr[256],palettedbg[256],palettedbb[256];
111 static void FlushPalette(void)
117 if(vmode==4 || vmode==5 || vmode==7) z^=0x80;
118 vga_setpalette(z,palettedbr[x]>>2,palettedbg[x]>>2,palettedbb[x]>>2);
122 void FCEUD_SetPalette(uint8 index, uint8 r, uint8 g, uint8 b)
130 if(vmode==4 || vmode==5 || vmode==7) index^=0x80;
131 vga_setpalette(index,r>>2,g>>2,b>>2);
136 void FCEUD_GetPalette(uint8 i, uint8 *r, uint8 *g, uint8 *b)
143 static void vcfix(void)
152 if(z!=0xe3 && z!=0xe7) // Common value in all tweaked video modes(and not in 320x200 mode).
160 static uint8 *ScreenLoc;
169 if(vmode<=3 || vmode==6 || vmode==8)
171 if(vga_getcurrentchipset()==FBDEV)
173 puts("Tweaked VGA video modes will not work. Using a 320x240 video mode instead...");
186 vga_setmode(G320x200x256);
188 ScreenLoc=vga_getgraphmem();
191 memset(ScreenLoc,128,256*256);
195 if(!(vga_getmodeinfo(G640x480x256)->flags & CAPABLE_LINEAR))
197 puts("Video: No linear addressing mode available!");
200 if(vga_setmode(G640x480x256)==-1)
202 puts("Video: Could not set 640x480x8bpp video mode!");
208 if(vga_setlinearaddressing()!=-1)
209 ScreenLoc=vga_getgraphmem();
212 puts("Video: Could not set linear addressing!");
215 memset(ScreenLoc,0,640*480);
218 if(!(vga_getmodeinfo(G320x240x256V)->flags & CAPABLE_LINEAR))
220 puts("Video: No linear addressing mode available!");
223 if(vga_setmode(G320x240x256V)==-1)
225 puts("Video: Could not set 320x240x8bpp video mode!");
231 if(vga_setlinearaddressing()!=-1)
232 ScreenLoc=vga_getgraphmem();
235 puts("Video: Could not set linear addressing!");
238 memset(ScreenLoc,0,320*240);
242 FlushPalette(); // Needed for cheat console code(and it isn't a bad thing to do anyway...).
256 void BlitScreen(uint8 *XBuf)
265 FCEUI_FrameSkip(FCEUDfskip);
268 if(doptions&DO_VSYNC && !NoWaiting)
273 tlines=erendline-srendline+1;
277 if(vmode!=4 && vmode!=5 && vmode!=7)
279 conto=(conto+1)&0x3F;
284 case 1:dest+=(((240-tlines)>>1)<<8);break;
286 case 3:dest+=(((256-tlines)>>1)<<8);break;
288 case 5:dest+=(((240-tlines)>>1)*640+((640-512)>>1));break;
290 case 6:if(tlines>224) tlines=224;dest+=(((224-tlines)>>1)<<8);break;
291 case 7:dest+=(((240-tlines)>>1)*320)+32;break;
294 XBuf+=(srendline<<8)+(srendline<<4);
296 if(eoptions&EO_CLIPSIDES)
301 "xorl %%edx, %%edx\n\t"
303 "movb $120,%%al \n\t"
305 "movb 1(%%esi),%%dl\n\t"
307 "movb (%%esi),%%dl\n\t"
308 "xorl $0x00800080,%%edx\n\t"
309 "movl %%edx,(%%edi)\n\t"
316 "addl $800,%%edi\n\t"
320 : "S" (XBuf+8), "D" (dest+8), "b" (tlines)
321 : "%al", "%edx", "%cc" );
327 "movb $120,%%al \n\t"
329 "movb 1(%%esi),%%dh\n\t"
332 "movb (%%esi),%%dl\n\t"
333 "movb %%dl,%%dh\n\t" // Ugh
334 "xorl $0x80808080,%%edx\n\t"
335 "movl %%edx,(%%edi)\n\t"
342 "addl $800,%%edi\n\t"
346 : "S" (XBuf+8), "D" (dest+8), "b" (tlines)
347 : "%al", "%edx", "%cc" );
355 "movl (%%esi),%%edx\n\t"
356 "movl 4(%%esi),%%ecx\n\t"
357 "xorl $0x80808080,%%edx\n\t"
358 "xorl $0x80808080,%%ecx\n\t"
359 "movl %%edx,(%%edi)\n\t"
360 "movl %%ecx,4(%%edi)\n\t"
370 : "S" (XBuf+8), "D" (dest+8), "b" (tlines)
371 : "%eax","%cc","%edx","%ecx" );
379 "movl (%%esi),%%edx\n\t"
380 "movl 4(%%esi),%%ecx\n\t"
381 "movl %%edx,(%%edi)\n\t"
382 "movl %%ecx,4(%%edi)\n\t"
392 : "S" (XBuf+8), "D" (dest+8), "b" (tlines)
393 : "%eax","%cc","%edx","%ecx" );
401 "xorl %%edx, %%edx\n\t"
403 "movb $128,%%al \n\t"
405 "movb 1(%%esi),%%dl\n\t"
407 "movb (%%esi),%%dl\n\t"
408 "xorl $0x00800080,%%edx\n\t"
409 "movl %%edx,(%%edi)\n\t"
416 "addl $768,%%edi\n\t"
420 : "S" (XBuf), "D" (dest), "b" (tlines)
421 : "%al", "%edx", "%cc" );
427 "movb $128,%%al \n\t"
429 "movb 1(%%esi),%%dh\n\t"
432 "movb (%%esi),%%dl\n\t"
433 "movb %%dl,%%dh\n\t" // Ugh
434 "xorl $0x80808080,%%edx\n\t"
435 "movl %%edx,(%%edi)\n\t"
442 "addl $768,%%edi\n\t"
446 : "S" (XBuf), "D" (dest), "b" (tlines)
447 : "%al", "%edx", "%cc" );
455 "movl (%%esi),%%edx\n\t"
456 "movl 4(%%esi),%%ecx\n\t"
457 "xorl $0x80808080,%%edx\n\t"
458 "xorl $0x80808080,%%ecx\n\t"
459 "movl %%edx,(%%edi)\n\t"
460 "movl %%ecx,4(%%edi)\n\t"
470 : "S" (XBuf), "D" (dest), "b" (tlines)
471 : "%eax","%cc","%edx","%ecx" );
479 "movl (%%esi),%%edx\n\t"
480 "movl 4(%%esi),%%ecx\n\t"
481 "movl %%edx,(%%edi)\n\t"
482 "movl %%ecx,4(%%edi)\n\t"
491 : "S" (XBuf), "D" (dest), "b" (tlines)
492 : "%eax","%cc","%edx","%ecx" );