"Fossies" - the Fresh Open Source Software Archive

Member "alec64-1.13/src/video_svga.c" (20 Jun 1996, 7704 Bytes) of package /linux/misc/old/alec64-1.13.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) C and C++ source code syntax highlighting (style: standard) with prefixed line numbers and code folding option. Alternatively you can here view or download the uninterpreted source code file.

    1 /*
    2  *  The C64 emulator
    3  *
    4  *  Copyright 1996 by ALE.
    5  *  written by Lutz Sammer.
    6  *
    7  *  Video driver for svgalib and linux.
    8  *------------------------------------------------------------------------------
    9  * $Id: video_svga.c,v 1.3 1996/06/13 00:00:16 ari Exp root $
   10  * $Log: video_svga.c,v $
   11  * Revision 1.3  1996/06/13 00:00:16  ari
   12  * Made svgalib quiet. Added volatile to VideoIsDisplayed!
   13  *
   14  * Revision 1.2  1996/06/12 23:33:12  johns
   15  * Added video sync support and overscan support.
   16  *
   17  * Revision 1.1  1996/04/26 23:08:44  johns
   18  * Initial revision
   19  *
   20  *------------------------------------------------------------------------------
   21  */
   22 
   23 #include "config.h"
   24 
   25 #ifdef SVGALIB  /* { */
   26 
   27 #include "c64.h"
   28 #include "vic.h"
   29 #include "sid.h"
   30 #include "video_svga.h"
   31 
   32 #include <stdio.h>
   33 #include <stdlib.h>
   34 #include <signal.h>
   35 #include <signal.h>
   36 #include <unistd.h>
   37 #include <sys/vt.h>
   38 #include <sys/kd.h>
   39 #include <sys/ioctl.h>
   40 
   41 volatile int VideoIsDisplayed;      /* GLOBAL Flag to indicate
   42                     ** VT-Screen active or switched away */
   43 
   44 /*---------------------------------------------------------------------------*/
   45 
   46 static struct {
   47     char Red,Green,Blue;
   48 } CONST Palette[16] = {
   49     { 0,  0,  0},           /* 00 Black */
   50     {63, 63, 63},           /* 01 White */
   51     {39,  0,  0},           /* 02 Red */
   52     { 0, 47, 47},           /* 03 Turquoise 08 48 48 */
   53     {47,  0, 47},           /* 04 Violet 48 0 48 */
   54     { 0, 39,  0},           /* 05 Green */
   55     { 0,  0, 39},           /* 06 Blue */
   56     {63, 63,  0},           /* 07 Yellow */
   57     {63, 22,  0},           /* 08 Orange 63 22 0 */
   58     {30, 14,  0},           /* 09 Brown  31 15 0 */
   59     {63,  0,  0},           /* 0A Lite Red */
   60     {15, 15, 15},           /* 0B Gray 1 */
   61     {31, 31, 31},           /* 0C Gray 2 */
   62     { 0, 63,  0},           /* 0D Lite Green */
   63     { 0,  0, 63},           /* 0E Lite Blue */
   64     {47, 47, 47}            /* 0F Gray 3 */
   65 };
   66 
   67 /*
   68 **  Load my own palette into DAC.
   69 */
   70 static void InitPalette()
   71 {
   72     int i;
   73 
   74     for( i=0; i<256; ++i ) {
   75     vga_setpalette(i,Palette[i&0xF].Red,
   76         Palette[i&0xF].Green,
   77         Palette[i&0xF].Blue);
   78     }
   79 }
   80 
   81 /*
   82 **  Set asyncron overscan color.
   83 */
   84 void SetOverscanColor(unsigned char c)
   85 {
   86     if( VideoIsDisplayed ) {
   87     /* HELPME: portable WAY for svgalib ?? */
   88     inb(0x3DA);
   89     outb(0x3C0,0x31);
   90     outb(0x3C0,c);
   91     }
   92 }
   93 
   94 /*---------------------------------------------------------------------------*/
   95 
   96 #ifdef VIDEOSYNC    /* { */
   97 
   98 #include <signal.h>
   99 #include <sys/time.h>
  100 
  101 volatile int VideoInterrupts;       /* be happy, were are quicker */
  102 
  103 /*
  104 **  Called from SIGALRM.
  105 */
  106 static void VideoSyncHandler(int unused)
  107 {
  108     ++VideoInterrupts;
  109 }
  110 
  111 /*
  112 **  Initialise video sync.
  113 */
  114 static void InitVideoSync(void)
  115 {
  116     struct sigaction sa;
  117     struct itimerval itv;
  118 
  119     if( !VideoSyncSpeed ) {
  120     return;
  121     }
  122 
  123     itv.it_interval.tv_sec=itv.it_value.tv_sec=
  124     (100/FRAMES_PER_SECOND)/VideoSyncSpeed;
  125     itv.it_interval.tv_usec=itv.it_value.tv_usec=
  126     (100000000/FRAMES_PER_SECOND)/VideoSyncSpeed-
  127     itv.it_value.tv_sec*100000;
  128     if( setitimer(ITIMER_REAL,&itv,NULL) ) {
  129     printf("Can't set itimer\n");
  130     }
  131     sa.sa_handler=VideoSyncHandler;
  132     sigemptyset(&sa.sa_mask);
  133     sa.sa_flags=SA_RESTART;
  134     if( sigaction(SIGALRM,&sa,NULL) ) {
  135     printf("Can't set signal\n");
  136     }
  137 }
  138 
  139 #else   /* }{ VIDEOSYNC */
  140 
  141 #define InitVideoSync()
  142 
  143 #endif  /* } !VIDEOSYNC */
  144 
  145 /*---------------------------------------------------------------------------*/
  146 
  147 /*
  148 **  Setup my vga-mode.
  149 */
  150 static void SVGA_SetupVideoMode(void)
  151 {
  152     vga_setmode(VGAMODE);
  153 #ifdef NEW_SVGA
  154     vga_setlogicalwidth(1024);
  155     {
  156     int i;
  157     for( i=0; i<8; ++i ) {
  158         vga_setpage(i);
  159         LongFill(VideoMemory,0x00000000,(64*1024)/4);
  160     }
  161     }
  162 #endif
  163 }
  164 
  165 /*---------------------------------------------------------------------------*/
  166 
  167 #define SIG_REL SIGUSR1
  168 #define SIG_ACQ SIGUSR2
  169 
  170 /*
  171 **  this is the signal handler for when the user screen flips
  172 **  away from us.
  173 */
  174 static void rel_screen(int sig)
  175 {
  176     signal(SIG_REL,rel_screen);
  177     vga_setlogicalwidth(640);
  178     vga_setpage(0);
  179     vga_setmode(TEXT);
  180     VideoIsDisplayed=0;
  181     SuspendSound();
  182     /*
  183     ** Tell the video driver that you have saved your state
  184     ** and it can now have the card to switch to the new screen.
  185     ** The video driver waits (forever) for this ioctl before
  186     ** it will complete the screen switch requested by the user.
  187     ** If you don't make this ioctl the screen switcher will
  188     ** be wedged until it gets one.  It is best to have a
  189     ** small one line reldisp.c program to unwedge your screen
  190     ** switcher when development programs screw up from time
  191     ** to time.
  192     */
  193     ioctl(0,VT_RELDISP,1);
  194 
  195     SuspendKeyboard();
  196 #ifdef NEW_SVGA
  197     pause();
  198 #endif
  199 }
  200 
  201 /*
  202 **  this is the signal handler for when the user screen flips
  203 **  back to us.
  204 */
  205 static void acq_screen(int sig)
  206 {
  207     signal(SIG_ACQ,acq_screen);
  208 
  209     SVGA_SetupVideoMode();
  210 
  211     InitPalette();
  212     VicOverscanColor=-1;
  213     VideoIsDisplayed=1;
  214     ResumeSound();
  215     /*
  216     **  Tell the video driver that you have restored your state
  217     **  and screen switching can now continue.
  218     */
  219     ioctl(0,VT_RELDISP,VT_ACKACQ);
  220 
  221     ResumeKeyboard();
  222 }
  223 
  224 /*
  225 **  Turn console switching on.
  226 */
  227 void SwitchingOn(void)
  228 {
  229     struct vt_mode smode;
  230 
  231     /*
  232     **  Set up to catch the screen switch signals.
  233     */
  234     signal(SIG_REL,rel_screen);
  235     signal(SIG_ACQ,acq_screen);
  236 
  237     /*
  238     ** Set up the data structure that asks the driver
  239     ** to send you signals when the screens are switched.
  240     ** mode == VT_PROCESS means send screen switch signals.
  241     ** mode == VT_AUTO means turn off screen switch signals (regular mode).
  242     ** relsig == the signal you want when the user switches away.
  243     ** acqsig == the signal you want when the user switches back to you.
  244     */
  245     smode.mode  =VT_PROCESS;
  246     smode.waitv =0;         /* not implemented, reserved */
  247     smode.relsig=SIG_REL;
  248     smode.acqsig=SIG_ACQ;
  249     smode.frsig =SIGINT;        /* not implemented, reserved */
  250 
  251     if( ioctl(0,VT_SETMODE,&smode)==-1 ) {
  252     perror("Screen switch signal ioctl VT_SETMODE");
  253     abort();
  254     }
  255 }
  256 
  257 /*
  258 **  Turn console switching off.
  259 */
  260 void SwitchingOff(void)
  261 {
  262     struct vt_mode smode;
  263 
  264     smode.mode  =VT_AUTO;
  265     smode.waitv =0;         /* not implemented, reserved */
  266     smode.relsig=0;
  267     smode.acqsig=0;
  268     smode.frsig =SIGINT;        /* not implemented, reserved */
  269 
  270     if( ioctl(0,VT_SETMODE,&smode)==-1 ) {
  271     perror("Screen switch signal ioctl VT_SETMODE");
  272     abort();
  273     }
  274 
  275     signal(SIG_REL,SIG_DFL);
  276     signal(SIG_ACQ,SIG_DFL);
  277 }
  278 
  279 /*---------------------------------------------------------------------------*/
  280 
  281 /*
  282 **  Setup video card for C64 emulator.
  283 */
  284 void EnterVideo(int argc,char** argv,char* geometry)
  285 {
  286     extern int __svgalib_driver_report;
  287 
  288     iopl(3);
  289 #ifndef AOUT
  290     // FIXME: MY OLD SGVALIB VERSION: didn't have it
  291     __svgalib_driver_report = 0;
  292 #endif
  293     vga_init();
  294     iopl(3);        /* SVGALIB BUGFIX:
  295             ** Stupid ET4000W32 detection does give up IOPL
  296             ** although it shouldn't touch it!
  297             */
  298     setuid(getuid());   /* finally give up SUSER priv */
  299 
  300     SVGA_SetupVideoMode();
  301 
  302     SwitchingOff(); /* turn off svgalib's switch handlers.. */
  303 
  304     SwitchingOn();  /* install our own instead */
  305     InitPalette();
  306     VideoIsDisplayed=1;
  307 
  308     InitVideoSync();
  309 }
  310 
  311 /*
  312 **  Restore video card.
  313 */
  314 void LeaveVideo(void)
  315 {
  316     if( VideoIsDisplayed ) {
  317     vga_setlogicalwidth(640);
  318     vga_setpage(0);
  319     vga_setmode(TEXT);
  320     SwitchingOff();
  321     VideoIsDisplayed=0;
  322     }
  323 }
  324 
  325 /*
  326 **  Suspend video.
  327 */
  328 void SuspendVideo(void)
  329 {
  330     LeaveVideo();
  331 }
  332 
  333 /*
  334 **  Resume video.
  335 */
  336 void ResumeVideo(void)
  337 {
  338     if( !VideoIsDisplayed ) {
  339     SwitchingOn();
  340     SVGA_SetupVideoMode();
  341 
  342     InitPalette();
  343     VideoIsDisplayed=1;
  344     }
  345     VicOverscanColor=-1;
  346     /*
  347     **  Contents automatic restored after 1/50s or 1/60s.
  348     */
  349 }
  350 
  351 #endif  /* } SVGALIB */