/* * Svga.c - a Driver for Linux SVGALib in MasterGear * * Heavily derived from code by Marat Fayzullin, and useless * without the MasterGear sources. */ #if( defined(LINUX) && defined(SVGA) ) /* Standard and SVGALib includes */ #include #include #include #include #include /* Private includes */ #include "SMS.h" #ifdef SOUND #include "DSP.h" #endif /* Sound related stuff */ #ifdef SOUND int UseSound = 0; int SndSwitch = 0x0F; int SndVolume = 200; #endif /* SVGALib variables */ char* ScreenMem = NULL; /* Miscellaneous variables/functions */ #define WIDTH 320 #define HEIGHT 200 int Black = 0; char* Title = "MasterGear for SVGALib"; byte *XBuf; byte XPal[16], SPal[16]; int SaveCPU = 1; void OnBreak(int Arg){ vga_setmode(TEXT); keyboard_close; CPURunning=0; } void PutImage(int X, int Y, int W, int H) { /* Hmm... This code requires a Linear Framebuffer. As I don't manually * initialise a linear framebuffer, that means that this code depends on a * 320x200 video mode... I do it this way for speed. */ byte* dest, *source; int i, xcent, ycent; xcent = (WIDTH-W)/2; ycent = (HEIGHT-H)/2; dest = ScreenMem + ycent * WIDTH; source = XBuf + Y * WIDTH; for( i = 0; i < (H-1); i++ ) { memcpy(dest + xcent, source + X, W); dest += WIDTH; source += WIDTH; } /* And there you have it - a fast and buggy update routine */ } /* SetColor - Sets a color from the pre-allocated table */ void SetColor(byte N, byte R, byte G, byte B) { byte* P; if( N>15 ) { N -= 16; P = SPal; } else P = XPal; P[N] = ((R&0xC0)>>2)|((G&0xC0)>>4)|((B&0xC0)>>6); } /* TrashMachine - Uninitialise everything */ void TrashMachine(void) { if( Verbose ) printf("Shutting down...\n"); free(XBuf); keyboard_close(); vga_setmode(TEXT); #ifdef SOUND TrashSound(); #endif } /* InitMachine - Starts up all the Unix/SVGA related stuff */ int InitMachine(void) { int i, j; if( Verbose ) printf("Initialising Unix/SVGA driver:\n Allocating buffers...\n"); XBuf = (byte*) malloc(sizeof(byte) * WIDTH * HEIGHT); if( !XBuf ) { if( Verbose ) printf("FAILED\n"); return (0); } if( Verbose ) printf("OK\n Initing sound...\n"); #ifdef SOUND InitSound(UseSound,Verbose); SetChannels(SndVolume,SndSwitch); SetSound(3,SND_NOISE); #endif SOUND signal(SIGHUP,OnBreak);signal(SIGINT,OnBreak); signal(SIGQUIT,OnBreak);signal(SIGTERM,OnBreak); vga_init(); vga_setmode(G320x200x256); ScreenMem = vga_getgraphmem(); if( Verbose ) printf("OK\n Allocating colors...\n"); for( j = 0; j < 64; j++ ) { vga_setpalette(j, (j & 0x3F), (j << 2) & 0x3F, (j << 4) & 0x3F); } keyboard_init(); keyboard_translatekeys(TRANSLATE_CURSORKEYS | TRANSLATE_DIAGONAL); return(1); } /* Josticks - Handles input. Due to differences between SVGAlib and X, this * may be a bit bonkers. You have been warned. Due to SVGAlib, and my * laziness, only a select few keys are supported. But anyway, the key * mappings I have dropped are nasty, horrid ones. So don't worry. */ int Joysticks(void) { static int JS = 0x0000; static byte N = 0; char* keys; if( keyboard_update() == 0 ) return JS; JS = 0; keys = keyboard_getstate(); #define KEY(__a) keys[SCANCODE_##__a] if( KEY(ESCAPE) || KEY(F12) ) CPURunning = 0; #ifdef DEBUG if( KEY(F1) ) Trace = !Trace; if( KEY(F2) ) { int J; printf("***** SprTab = %04Xh *****\n",SprTab-VRAM); for(J=0;J<64;J++) printf("SPRITE#%02d: %d,%d %02Xh %02Xh\n", J,SprX(J),SprY(J),SprP(J),SprA(J)); } #endif #ifdef SOUND if( KEY(1) ) SetChannels(SndVolume, SndSwitch ^= 0x01); if( KEY(2) ) SetChannels(SndVolume, SndSwitch ^= 0x02); if( KEY(3) ) SetChannels(SndVolume, SndSwitch ^= 0x04); if( KEY(4) ) SetChannels(SndVolume, SndSwitch ^= 0x08); if( KEY(0) ) SetChannels(SndVolume, SndSwitch = (SndSwitch ? 0x00 : 0x0F)); if( KEY(MINUS) || KEY(KEYPADMINUS) ) { if(SndVolume>0) SndVolume-=10; SetChannels(SndVolume,SndSwitch); } if( KEY(EQUAL) || KEY(KEYPADPLUS) ) { if(SndVolume<250) SndVolume+=10; SetChannels(SndVolume,SndSwitch); } #endif if( KEY(LEFTCONTROL) ) JS|=N? 0x0800:0x0020; if( KEY(LEFTALT) || KEY(SPACE) ) JS|=N? 0x0400:0x0010; if( KEY(ENTER) ) JS |= 0x2000; if( KEY(TAB) ) JS |= 0x1000; if( KEY(CURSORDOWN) ) JS |= N ? 0x0080 : 0x0002; if( KEY(CURSORUP) ) JS |= N ? 0x0040 : 0x0001; if( KEY(CURSORLEFT) ) JS |= N ? 0x0100 : 0x0004; if( KEY(CURSORRIGHT) ) JS |= N ? 0x0200 : 0x0008; if( KEY(BACKSPACE) ) JS |= 0x10000; if( KEY(CAPSLOCK) ) { JS = 0x0000; N = 1; } return JS; } #include "Common.h" #endif