Annotation of generator/src/uip-svgalib.c, revision 1.1.1.2

1.1.1.2 ! root        1: /* Generator is (c) James Ponder, 1997-2001 http://www.squish.net/generator/ */
        !             2: 
        !             3: /* user interface for svgalib (15/16 bit) */
1.1       root        4: 
                      5: #include <stdio.h>
                      6: #include <unistd.h>
                      7: 
                      8: #include "generator.h"
                      9: #include <vga.h>
                     10: #include <vgakeyboard.h>
                     11: 
                     12: #include "uip.h"
                     13: #include "ui.h"
                     14: #include "ui-console.h"
                     15: #include "vdp.h"
                     16: #include "mem68k.h"
                     17: 
                     18: #define BANKSIZE 640*480*2
                     19: 
                     20: /*** forward reference declarations ***/
                     21: 
1.1.1.2 ! root       22: static int uip_getshifts(t_uipinfo *uipinfo);
        !            23: 
1.1       root       24: /*** static variables ***/
                     25: 
                     26: static uint8 uip_vga = 0;             /* flag for whether in VGA more or not */
                     27: static uint8 uip_displaybanknum = 0;  /* view this one, write to other one */
                     28: static t_uipinfo *uip_uipinfo = NULL; /* uipinfo */
                     29: static uint8 uip_key[256];            /* keyboard state */
1.1.1.2 ! root       30: static int uip_forceredshift = -1;    /* if set, forces red shift position */
        !            31: static int uip_forcegreenshift = -1;  /* if set, forces green shift position */
        !            32: static int uip_forceblueshift = -1;   /* if set, forces blue shift position */
1.1       root       33: 
                     34: /*** Code ***/
                     35: 
                     36: static void uip_keyboardhandler(int scancode, int press) {
                     37:   if (scancode >= 256)
                     38:     return;
                     39:   if (uip_key[scancode] == press)
                     40:     return;
                     41:   uip_key[scancode] = press;
                     42:   if (press) {
1.1.1.2 ! root       43:     if (scancode == SCANCODE_F1) {
        !            44:       ui_fkeys|= 1<<1;
        !            45:     } else if (scancode == SCANCODE_F2) {
        !            46:       ui_fkeys|= 1<<2;
        !            47:     } else if (scancode == SCANCODE_F3) {
        !            48:       ui_fkeys|= 1<<3;
        !            49:     } else if (scancode == SCANCODE_F4) {
        !            50:       ui_fkeys|= 1<<4;
        !            51:     } else if (scancode == SCANCODE_F5) {
        !            52:       ui_fkeys|= 1<<5;
1.1       root       53:     } else if (scancode == SCANCODE_F6) {
1.1.1.2 ! root       54:       ui_fkeys|= 1<<6;
1.1       root       55:     } else if (scancode == SCANCODE_F7) {
1.1.1.2 ! root       56:       ui_fkeys|= 1<<7;
1.1       root       57:     } else if (scancode == SCANCODE_F8) {
1.1.1.2 ! root       58:       ui_fkeys|= 1<<8;
1.1       root       59:     } else if (scancode == SCANCODE_F9) {
1.1.1.2 ! root       60:       ui_fkeys|= 1<<9;
        !            61:     } else if (scancode == SCANCODE_F10) {
        !            62:       ui_fkeys|= 1<<10;
        !            63:     } else if (scancode == SCANCODE_F11) {
        !            64:       ui_fkeys|= 1<<11;
        !            65:     } else if (scancode == SCANCODE_F12) {
        !            66:       ui_fkeys|= 1<<12;
1.1       root       67:     }
                     68:   }
                     69: }
                     70: 
                     71: int uip_init(t_uipinfo *uipinfo)
                     72: {
                     73:   uip_uipinfo = uipinfo;
                     74:   printf("Initialising svgalib...\n");
                     75:   sleep(1);
                     76:   if (vga_init()) {
                     77:     LOG_CRITICAL(("Failed to initialise SVGALib"));
                     78:     return 1;
                     79:   }
                     80:   return 0;
                     81: }
                     82: 
                     83: int uip_vgamode(void)
                     84: {
                     85:   vga_modeinfo *modeinfo;
                     86:   int cardmemory;
                     87: 
                     88:   uip_vga = 1;
                     89:   if (vga_setmode(G640x480x32K) == -1) {
1.1.1.2 ! root       90:     LOG_CRITICAL(("640x480 @ 32K colours not supported by hardware"));
        !            91:     LOG_CRITICAL(("Trying 640x480 @ 64K colours..."));
        !            92:     if (vga_setmode(G640x480x64K) == -1) {
        !            93:       LOG_CRITICAL(("640x480 @ 64K colours not supported by hardware"));
        !            94:       uip_textmode();
        !            95:       LOG_CRITICAL(("Unable to change SVGA mode, mode not supported by "
        !            96:                    "hardware?"));
        !            97:       LOG_CRITICAL(("Check /etc/vga/libvga.config to ensure your card "
        !            98:                    "is not commented out"));
        !            99:       return 1;
        !           100:     }
1.1       root      101:   }
                    102:   if (vga_claimvideomemory(2*BANKSIZE) == -1) {
                    103:     uip_textmode();
                    104:     LOG_CRITICAL(("Unable to allocated video memory - 2MB video card "
                    105:                  "required."));
                    106:     return 1;
                    107:   }
                    108:   if ((modeinfo = vga_getmodeinfo(vga_getcurrentmode())) == NULL) {
                    109:     uip_textmode();
                    110:     LOG_CRITICAL(("Unable to get current mode information"));
                    111:     return 1;
                    112:   }
                    113:   LOG_VERBOSE(("Resolution %dx%d bytesperpixel %d linewidth %d",
                    114:               modeinfo->width, modeinfo->height, modeinfo->bytesperpixel,
                    115:               modeinfo->linewidth));
                    116:   if (modeinfo->width != 640 || modeinfo->height != 480 ||
                    117:       modeinfo->bytesperpixel != 2 || modeinfo->linewidth*480 > BANKSIZE ||
                    118:       (modeinfo->startaddressrange & BANKSIZE) != BANKSIZE) {
                    119:     uip_textmode();
                    120:     LOG_CRITICAL(("Unexpected mode settings"));
                    121:     return 1;
                    122:   }
                    123:   uip_uipinfo->linewidth = modeinfo->linewidth;
                    124:   if (vga_setlinearaddressing() == -1) {
                    125:     uip_textmode();
                    126:     LOG_CRITICAL(("Linear addressing mode not supported by hardware"));
                    127:     return 1;
                    128:   }
                    129:   if ((uip_uipinfo->screenmem0 = vga_getgraphmem()) == NULL) {
                    130:     uip_textmode();
                    131:     LOG_CRITICAL(("Failed to find start of screen memory"));
                    132:     return 1;
                    133:   }
                    134:   uip_uipinfo->screenmem1 = uip_uipinfo->screenmem0+BANKSIZE;
1.1.1.2 ! root      135:   if (uip_forceredshift != -1 && uip_forcegreenshift != -1 &&
        !           136:       uip_forceblueshift != -1) {
        !           137:     uip_uipinfo->redshift = uip_forceredshift;
        !           138:     uip_uipinfo->greenshift = uip_forcegreenshift;
        !           139:     uip_uipinfo->blueshift = uip_forceblueshift;
        !           140:   } else {
        !           141:     switch (modeinfo->colors) {
        !           142:     case 32768:
        !           143:       LOG_VERBOSE(("Assuming colour bit positions 10,5,0 for 32k colour mode"));
        !           144:       uip_uipinfo->blueshift = 0;
        !           145:       uip_uipinfo->greenshift = 5;
        !           146:       uip_uipinfo->redshift = 10;
        !           147:       break;
        !           148:     case 65536:
        !           149:       LOG_VERBOSE(("Assuming colour bit positions 11,6,0 for 64k colour mode"));
        !           150:       uip_uipinfo->blueshift = 0;
        !           151:       uip_uipinfo->greenshift = 6;
        !           152:       uip_uipinfo->redshift = 11;
        !           153:       break;
        !           154:     default:
        !           155:       LOG_CRITICAL(("Unknown mode - %d colours?? use -c", modeinfo->colors));
        !           156:       return 1;
        !           157:     }
        !           158:   }
1.1       root      159:   uip_displaybank(0); /* set current to 0th bank */
                    160:   uip_clearscreen(); /* clear bank */
                    161:   ui_setupscreen(); /* setup bank */
                    162:   uip_displaybank(-1); /* toggle bank */
                    163:   uip_clearscreen(); /* clear bank */
                    164:   ui_setupscreen(); /* setup bank */
                    165:   if (keyboard_init() == -1) {
                    166:     uip_textmode();
                    167:     LOG_CRITICAL(("Unable to initialise keyboard"));
                    168:     return 1;
                    169:   }
                    170:   memset(uip_key, 0, sizeof(uip_key));
                    171:   keyboard_seteventhandler(uip_keyboardhandler);
                    172:   return 0;
                    173: }
                    174: 
1.1.1.2 ! root      175: int uip_setcolourbits(int red, int green, int blue)
        !           176: {
        !           177:   uip_forceredshift = red;
        !           178:   uip_forcegreenshift = green;
        !           179:   uip_forceblueshift = blue;
        !           180:   return 0;
        !           181: }
        !           182: 
1.1       root      183: void uip_displaybank(int bank) {
                    184:   if (bank == -1)
                    185:     bank = uip_displaybanknum ^ 1;
                    186:   vga_setdisplaystart(bank ? BANKSIZE : 0);
                    187:   uip_uipinfo->screenmem_w = bank ? uip_uipinfo->screenmem0 :
                    188:     uip_uipinfo->screenmem1;
                    189:   uip_displaybanknum = bank;
                    190: }
                    191: 
                    192: void uip_clearscreen(void) {
                    193:   memset(uip_uipinfo->screenmem_w, 0, BANKSIZE);
                    194: }
                    195: 
1.1.1.2 ! root      196: void uip_clearmiddle(void) {
        !           197:   int i;
        !           198: 
        !           199:   for (i = 0; i < 240; i++) {
        !           200:     memset(uip_uipinfo->screenmem_w+(uip_uipinfo->linewidth)*(120+i)+
        !           201:         160*2, 0, 2*320);
        !           202:   }
        !           203: }
        !           204: 
        !           205: /* uip_singlebank sets write address to the current display screen */
        !           206: 
        !           207: void uip_singlebank(void) {
        !           208:   uip_uipinfo->screenmem_w = uip_displaybanknum ? uip_uipinfo->screenmem1 :
        !           209:     uip_uipinfo->screenmem0;
        !           210: }
        !           211: 
        !           212: /* uip_doublebank sets write address to hidden display screen */
        !           213: 
        !           214: void uip_doublebank(void) {
        !           215:   uip_uipinfo->screenmem_w = uip_displaybanknum ? uip_uipinfo->screenmem0 :
        !           216:     uip_uipinfo->screenmem1;
        !           217: }
        !           218: 
1.1       root      219: void uip_textmode(void)
                    220: {
                    221:   if (uip_vga) {
                    222:     keyboard_setdefaulteventhandler();
                    223:     vga_setmode(0);
                    224:   }
                    225:   uip_vga = 0;
                    226: }
                    227: 
                    228: int uip_checkkeyboard(void)
                    229: {
                    230:   keyboard_update();
                    231:   mem68k_cont1_a = uip_key[SCANCODE_A] ? 1 : 0;
                    232:   mem68k_cont1_b = (uip_key[SCANCODE_B] ||
                    233:                    uip_key[SCANCODE_S]) ? 1 : 0;
                    234:   mem68k_cont1_c = (uip_key[SCANCODE_C] ||
                    235:                    uip_key[SCANCODE_D]) ? 1 : 0;
                    236:   mem68k_cont1_left = uip_key[SCANCODE_CURSORBLOCKLEFT] ? 1 : 0;
                    237:   mem68k_cont1_up = uip_key[SCANCODE_CURSORBLOCKUP] ? 1 : 0;
                    238:   mem68k_cont1_right = uip_key[SCANCODE_CURSORBLOCKRIGHT] ? 1 : 0;
                    239:   mem68k_cont1_down = uip_key[SCANCODE_CURSORBLOCKDOWN] ? 1 : 0;
                    240:   mem68k_cont1_start = uip_key[SCANCODE_ENTER] ? 1 : 0;
                    241:   return (uip_key[SCANCODE_ESCAPE] ? 1 : 0);
                    242: }
                    243: 
                    244: void uip_vsync(void)
                    245: {
                    246:   vga_waitretrace();
                    247: }
1.1.1.2 ! root      248: 
        !           249: unsigned int uip_whichbank(void)
        !           250: {
        !           251:   /* returns 0 or 1 - the bank being VIEWED */
        !           252:   return uip_displaybanknum;
        !           253: }
        !           254: 
        !           255: uint8 uip_getchar(void)
        !           256: {
        !           257:   char c;
        !           258: 
        !           259:   keyboard_setdefaulteventhandler();
        !           260:   keyboard_close();
        !           261:   c = getchar();
        !           262:   keyboard_init();
        !           263:   memset(uip_key, 0, sizeof(uip_key));
        !           264:   keyboard_seteventhandler(uip_keyboardhandler);
        !           265:   return c;
        !           266: }

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.