// // This function is called to init the video driver for specific mode // static int config(uint32_t width, uint32_t height, uint32_t d_width, uint32_t d_height, uint32_t flags, char *title, uint32_t format) { int32_t req_w = width;// (d_width > 0 ? d_width : width); int32_t req_h = height;// (d_height > 0 ? d_height : height); uint16_t vid_mode = 0; int32_t req_bpp; uint32_t accflags; mp_msg(MSGT_VO,MSGL_V, "vo_svga: config(%i, %i, %i, %i, %08x, %s, %08x)\n", width, height, d_width, d_height, flags, title, format); //Only RGB modes supported if (!IMGFMT_IS_RGB(format) && !IMGFMT_IS_BGR(format)) { assert(0); return -1; } req_bpp = IMGFMT_BGR_DEPTH(format); if( vo_dbpp!=0 && vo_dbpp!=req_bpp) { assert(0); return-1; } if(!force_vm) { mp_msg(MSGT_VO,MSGL_V, "vo_svga: Looking for the best resolution...\n"); mp_msg(MSGT_VO,MSGL_V, "vo_svga: req_w: %d, req_h: %d, bpp: %d\n",req_w,req_h,req_bpp); vid_mode=find_best_svga_mode(req_w,req_h,req_bpp); if(vid_mode==0) return 1; modeinfo=vga_getmodeinfo(vid_mode); } else { //force_vm vid_mode=force_vm; if(vga_hasmode(vid_mode) == 0) { mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SVGA_ForcedVidmodeNotAvailable, vid_mode,vga_getmodename(vid_mode)); return 1; //error; } modeinfo=vga_getmodeinfo(vid_mode); if( (modeinfo->width < req_w) || (modeinfo->height < req_h) ) { mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SVGA_ForcedVidmodeTooSmall, vid_mode,vga_getmodename(vid_mode)); return 1; } } mode_bpp=bpp_from_vminfo(modeinfo); mp_msg(MSGT_VO,MSGL_INFO, MSGTR_LIBVO_SVGA_Vidmode, vid_mode,modeinfo->width,modeinfo->height,mode_bpp); if (vga_setmode(vid_mode) == -1) { mp_msg(MSGT_VO,MSGL_ERR, MSGTR_LIBVO_SVGA_VgasetmodeFailed,vid_mode); uninit(); return 1; // error } /* set 332 palette for 8 bpp */ if(mode_bpp==8) { int i; for(i=0; i<256; i++) vga_setpalette(i, ((i>>5)&7)*9, ((i>>2)&7)*9, (i&3)*21); }
void VID_InitModes(void) { int i; // get complete information on all modes num_modes = vga_lastmodenumber()+1; modes = malloc(num_modes * sizeof(vga_modeinfo)); for (i=0 ; i<num_modes ; i++) { if (vga_hasmode(i)) memcpy(&modes[i], vga_getmodeinfo(i), sizeof (vga_modeinfo)); else modes[i].width = 0; // means not available } // filter for modes i don't support for (i=0 ; i<num_modes ; i++) { if (modes[i].bytesperpixel != 1 && modes[i].colors != 256) modes[i].width = 0; } for (i = 0; i < num_modes; i++) if (modes[i].width) ri.Con_Printf(PRINT_ALL, "mode %d: %d %d\n", modes[i].width, modes[i].height); }
d_rasterdescription_t *d_raster_getmodes(int *nmodes) { d_rasterdescription_t *modes; vga_modeinfo *minf; int i; modes = NULL; *nmodes = 0; for(i = 1; i < vga_lastmodenumber(); i++) { if(vga_hasmode(i) == 0) continue; (*nmodes)++; modes = d_memory_resize(modes, *nmodes*sizeof(d_rasterdescription_t)); if(modes == NULL) { d_error_push("d_raster_getmodes: d_memory_resize failed."); return NULL; } minf = vga_getmodeinfo(i); modes[*nmodes-1].w = minf->width; modes[*nmodes-1].h = minf->height; modes[*nmodes-1].bpp = log2(minf->colors); modes[*nmodes-1].alpha = 0; if(modes[*nmodes-1].bpp == 8) modes[*nmodes-1].paletted = true; else modes[*nmodes-1].paletted = false; modes[*nmodes-1].cspace = RGB; } return modes; }
static int find_best_svga_mode(int req_w,int req_h, int req_bpp){ int badness,prev_badness; int bestmode,lastmode; int i; vga_modeinfo *vminfo; //int best aspect mode // best linear mode // best normal mode (no modeX) prev_badness = 0;//take care of special case below bestmode = 0; //0 is the TEXT mode lastmode = vga_lastmodenumber(); for(i=1;i<=lastmode;i++){ vminfo = vga_getmodeinfo(i); if( vminfo == NULL ) continue; if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: testing mode %d (%s)\n",i,vga_getmodename(i)); if( vga_hasmode(i) == 0 ) continue; if( req_bpp != bpp_from_vminfo(vminfo) )continue; if( (vminfo->width < req_w) || (vminfo->height < req_h) ) continue; badness=(vminfo->width * vminfo->height) - (req_h * req_w); //put here aspect calculations if(squarepix) if( vminfo->width*3 != vminfo->height*4 ) continue; if( bestmode==0 || prev_badness >= badness ){//modeX etc... prev_badness=badness; bestmode=i; if( mp_msg_test(MSGT_VO,MSGL_DBG4) ) mp_msg(MSGT_VO,MSGL_DBG4, "vo_svga: found good mode %d with badness %d\n",i,badness); } } return bestmode; }
void VL_Startup() { myint mode; vga_init(); /* TODO: maybe move into main or such? */ if (MS_CheckParm("x2")) { mode = G640x400x256; vwidth = 640; vheight = 400; } else { mode = G320x200x256; vwidth = 320; vheight = 200; } if (gfxbuf == NULL) gfxbuf = malloc(vwidth * vheight * 1); if (vga_hasmode(mode) == 0) Quit("vga_hasmode failed!"); if (vga_setmode(mode) != 0) Quit("vga_setmode failed!"); if ((mode != G320x200x256) && (vga_setlinearaddressing() == -1)) Quit("vga_setlinearaddressing failed!"); graphmem = vga_getgraphmem(); keyboard_init(); keyboard_seteventhandler(keyboard_handlerx); }
int main(int argc, char *argv[]) { vga_init(); if(argc>=2) { timescale=atoi(argv[1]); if(timescale<1)timescale=1; } VGAMODE = vga_getdefaultmode(); if (VGAMODE == -1) VGAMODE = G320x200x256; /* Default mode. */ if (!vga_hasmode(VGAMODE)) { printf("Mode not available.\n"); exit(-1); } VIRTUAL = 0; /* No virtual screen. */ if (vga_getmodeinfo(VGAMODE)->colors == 16 || (vga_getmodeinfo(VGAMODE)->flags & IS_MODEX)) /* These modes are supported indirectly by vgagl. */ VIRTUAL = 1; if (VIRTUAL) { /* Create virtual screen. */ gl_setcontextvgavirtual(VGAMODE); backscreen = gl_allocatecontext(); gl_getcontext(backscreen); } vga_setmode(VGAMODE); gl_setcontextvga(VGAMODE); /* Physical screen context. */ physicalscreen = gl_allocatecontext(); gl_getcontext(physicalscreen); if (COLORS == 256) gl_setrgbpalette(); if(argc==3)sleep(2); test(); /* Now do the same with clipping enabled. */ gl_clearscreen(0); gl_setclippingwindow(WIDTH / 4, HEIGHT / 4, WIDTH - WIDTH / 4 - 1, HEIGHT - HEIGHT / 4 - 1); test(); gl_disableclipping(); if (COLORS == 256) /* Show the logo if using 256 color mode. */ logotest(); getchar(); if (VIRTUAL) gl_freecontext(backscreen); vga_setmode(TEXT); exit(0); }
int main(int argc, char *argv[]) { int i; int oldmode; int mode = G320x200x256; int width, height, colors; //获得当前的模式 oldmode = vga_getcurrentmode(); //初始化 vga_init(); //判断是否支持该模式 if(vga_hasmode(mode)) vga_setmode(mode); else { printf("No such mode\n"); exit(1); } //取得信息 width = vga_getxdim(); height = vga_getydim(); colors = vga_getcolors(); //绘图 for(i=0; i<colors; i++){ vga_setcolor(i); vga_drawline(0, i, width-1, i); } vga_setcolor(3); for(i=0; i<50; i++) vga_drawpixel(i*4, 20); vga_setcolor(4); vga_drawline(100, 100, 300, 200); vga_setcolor(5); vga_drawline(0, 0, width-1, 0); vga_drawline(0, height-1, width-1, height-1); vga_drawline(0, 0, 0, height-1); vga_drawline(width-1, 0, width-1, height-1); //等待按键 while(!vga_getkey()); //恢复原来的模式 vga_setmode(oldmode); return 0; }
void find_mode( int exact ) { vga_modeinfo *inf; int i, j, w, h; for( i = 0; i <= vga_lastmodenumber(); i++ ) { if( vga_hasmode( i ) ) { inf = vga_getmodeinfo( i ); if( inf->colors >= 16 && !( inf->flags & IS_MODEX ) && inf->width >= 320 && inf->height >= 240 && inf->width <= 1280 && inf->height <= 1024 ) { /* try exact match */ for( j = 0; j < 3; j++ ) { w = DISPLAY_ASPECT_WIDTH * ( j + 1 ); h = DISPLAY_SCREEN_HEIGHT * ( j + 1 ); if( exact == 0 && inf->width == w && inf->height == h && ( modes[j].n == -1 || ( ( modes[j].width != w || modes[j].height != h || modes[j].depth != 16 ) && ( inf->colors == 65536 || inf->colors > modes[j].colors ) ) ) ) { set_mode( j, i, inf ); } if( exact == 1 && inf->width >= w && inf->height >= h && inf->width < w * 5 / 4 && inf->height < h * 5 / 4 && ( modes[j].n == -1 || ( ( modes[j].width > inf->width || modes[j].height > inf->height || modes[j].depth != 16 ) && ( inf->colors == 65536 || inf->colors > modes[j].colors ) ) ) ) { set_mode( j, i, inf ); } if( exact == -1 && inf->width <= w && inf->height <= h && inf->width > w * 3 / 4 && inf->height > h * 3 / 4 && ( modes[j].n == -1 || ( ( modes[j].width < inf->width || modes[j].height < inf->height || modes[j].depth != 16 ) && ( inf->colors == 65536 || inf->colors > modes[j].colors ) ) ) ) { set_mode( j, i, inf ); } } } } } }
int svgadisplay_init( void ) { size_t i; int found_mode = 0; vga_init(); /* First, see if our preferred mode exists */ for( i=0; i<mode_count && !found_mode; i++ ) { if( available_modes[i].fuse_id == settings_current.svga_mode || settings_current.doublescan_mode == 0 ) { if( vga_hasmode( available_modes[i].svgalib_id ) ) { vga_setmode( available_modes[i].svgalib_id ); hires = available_modes[i].hires; found_mode = 1; } } } /* If we haven't found a mode yet, try each in order */ for( i=0; i<mode_count && !found_mode; i++ ) { if( vga_hasmode( available_modes[i].svgalib_id ) ) { vga_setmode( available_modes[i].svgalib_id ); hires = available_modes[i].hires; found_mode = 1; } } /* Error out if we couldn't find a VGA mode */ if( !found_mode ) { ui_error( UI_ERROR_ERROR, "couldn't find a mode to start in" ); return 1; } svgadisplay_allocate_colours( 16 ); return 0; }
int graphics_setup (void) { int i,j, count = 1; vga_init(); current_vgamode = TEXT; for (i = 0; i < MAX_SCREEN_MODES; i++) { /* Ignore the larger modes which only make sense for Picasso screens. */ if (x_size_table[i] > 800 || y_size_table[i] > 600) continue; for (j = 0; j < MAX_COLOR_MODES+1; j++) { /* Delete modes which are not available on this card. */ if (!vga_hasmode (vga_mode_table[i][j])) { vga_mode_table[i][j] = -1; } if (vga_mode_table[i][j] != -1) count++; } } video_mode_menu = (struct bstring *)malloc (sizeof (struct bstring)*count); memset (video_mode_menu, 0, sizeof (struct bstring)*count); count = 0; for (i = 0; i < MAX_SCREEN_MODES; i++) { /* Ignore the larger modes which only make sense for Picasso screens. */ if (x_size_table[i] > 800 || y_size_table[i] > 600) continue; for (j = 0; j < MAX_COLOR_MODES+1; j++) { char buf[80]; if (vga_mode_table[i][j] == -1) continue; sprintf (buf, "%3dx%d, %s", x_size_table[i], y_size_table[i], colormodes[j]); video_mode_menu[count].val = -1; video_mode_menu[count++].data = strdup(buf); } } video_mode_menu[count].val = -3; video_mode_menu[count++].data = NULL; return 1; }
void SetVideoMode(short mode) { _mode_ = mode; vga_init (); if (!(vga_ext_set(VGA_EXT_AVAILABLE, VGA_AVAIL_SET) & (1 << VGA_EXT_PAGE_OFFSET))) { puts("You need at least svgalib 1.2.10 to run this program!\n"); exit(1); } if (!vga_hasmode (_mode_)) { fprintf (stderr, "Mode not available.\n"); exit (-1); } vga_setmode (_mode_); _ginfo_ = vga_getmodeinfo (_mode_); dX = _ginfo_->width; dY = _ginfo_->height; }
static int init_vidmode () { int err, i; fprintf (stderr, "svgalib: SVGAlib support by XoXus\n"); err = vga_init (); if (err) { fprintf (stderr, "svgalib: can't initialize svgalib\n"); return err_Unk; } err = vga_hasmode (G320x200x256); if (err == 0) { fprintf (stderr, "svgalib: video mode unavailable (320x200x256)\n"); return err_Unk; } vga_setmode (G320x200x256); svgalib_framebuffer = vga_getgraphmem (); /* Set up EGA colors */ for (i = 0; i < 32; i++) { vga_setpalette (i, palette[i * 3], palette[i * 3 + 1], palette[i * 3 + 2]); } /* Allocate framebuffer */ video_buffer = (UINT8 *) malloc (320 * 200); if (!video_buffer) { fprintf (stderr, "svgalib: can't alloc framebuffer\n"); deinit_vidmode (); return err_Unk; } /* XoXus: This is a semantics issue, but the keyboard init * probably shouldn't be done in 'init_vidmode' */ err = svgalib_key_init (); if (err != err_OK) { deinit_vidmode (); return err_Unk; } return err_OK; }
bool d_raster_setmode(d_rasterdescription_t mode) { vga_modeinfo *minf; int i, ret; if(mode.cspace == grayscale) { d_error_push(__FUNCTION__": grayscale modes are not supported " "with this driver."); return failure; } for(i = 1; i < vga_lastmodenumber(); i++) { if(vga_hasmode(i) == 0) continue; minf = vga_getmodeinfo(i); if(minf->width == mode.w && minf->height == mode.h && minf->colors == 1<<mode.bpp) { ret = vga_setmode(i); if(ret != 0) { d_error_push(__FUNCTION__": vga_setmode failed."); return failure; } raster_curmode = mode; if(raster_vbuf != NULL) d_memory_delete(raster_vbuf); raster_vbuf = d_memory_new((mode.w*mode.h*mode.bpp+7)/8); if(raster_vbuf == NULL) { d_error_push(__FUNCTION__": memory allocation failed for " "raster_vbuf."); return failure; } return success; } } d_error_push(__FUNCTION__": no such mode available."); return failure; }
void configure(void) { int allowed[GLASTMODE + 1]; for (;;) { int i; int m; for (i = G320x200x16; i <= GLASTMODE; i++) { allowed[i] = 0; if (vga_hasmode(i)) { printf("%2d %s\n", i, vga_getmodename(i)); allowed[i] = 1; } } printf("\nWhich mode? "); scanf("%d", &m); getchar(); printf("\n"); if (m >= G320x200x16 && m <= GLASTMODE) { VGAMODE = m; if (vga_getmodeinfo(m)->bytesperpixel >= 1) USEGL = 1; else USEGL = 0; break; } } vga_setmode(VGAMODE); #ifdef LINEAR_ADDRESSING vga_setlinearaddressing(); #endif if (USEGL) { gl_setcontextvga(VGAMODE); physicalscreen = gl_allocatecontext(); gl_getcontext(physicalscreen); } }
static void VID_InitModes (void) { int i; /* get complete information on all modes */ num_modes = vga_lastmodenumber() + 1; modes = (vga_modeinfo *) Z_Malloc(num_modes * sizeof(vga_modeinfo), Z_MAINZONE); for (i = 0; i < num_modes; i++) { if (vga_hasmode(i)) memcpy(&modes[i], vga_getmodeinfo(i), sizeof(vga_modeinfo)); else modes[i].width = 0; /* means not available */ } /* filter for modes i don't support */ for (i = 0; i < num_modes; i++) { if (modes[i].bytesperpixel != 1 && modes[i].colors != 256) modes[i].width = 0; } }
void initscreen(void) { int vgamode; vga_init(); vgamode = G640x480x16; if (!vga_hasmode(vgamode)) { printf("Mode not available.\n"); exit(-1); } vga_setmode(vgamode); /* Create virtual screen. */ gl_setcontextvgavirtual(vgamode); backscreen = gl_allocatecontext(); gl_getcontext(backscreen); /* Physical screen context. */ vga_setmode(vgamode); gl_setcontextvga(vgamode); physicalscreen = gl_allocatecontext(); gl_getcontext(physicalscreen); gl_setcontext(backscreen); /*drawgraypalette(); */ gl_clearscreen(0); // gl_setcontextvga(vgamode); gl_enableclipping(); gl_setclippingwindow(0, 0, 639, 479); gl_setwritemode(WRITEMODE_OVERWRITE | FONT_COMPRESSED); gl_setfont(8, 8, gl_font8x8); gl_setfontcolors(0, 1); }
void main(void) { struct timeval timeout; fd_set inputs; char bitmap[16 * 16 * 4]; /* big enough for 10x10 bitmap in any mode */ int vgamode, color, pipefd[2], x, y, button, event, cursorsize = 5; char loop = 1, drawcursor = 1; #ifdef USE_RAWKEYBOARD char space_pressed = 0; #endif puts("This is a demo showing the abilities of the new vga_waitevent() function\n" "If something goes wrong it might hang your machine. Thus hit <ctrl>-C now\n" "to bailout if in doubt.\n" "Use mouse to move cursor. 1-9,0 to set the cursor size. Space to change the\n" "cursor color. Left button to draw. Right button or 'Q' to bailout.\n" "The cursor goes on/off every half second by usage of a timeout passed to\n" "vga_waitevent. Every 5 secs a string from a child process (the time) arrives\n" "asynchronously and is displayed by the frontend."); #ifdef USE_RAWKEYBOARD puts("\nBEWARE! This has been compiled to use the raw keyboard. A crash might\n" "render the console unusable. (but shouldn't)."); #endif fputs("\nHit <Enter> if brave enough, else ^C to bailout: ", stdout); fflush(stdout); getchar(); fflush(stdin); /* clear I/O buffer */ pipe(pipefd); if (fork() == 0) { /* fork off b4 touching graphix to avoid side effects */ close(pipefd[0]); /* Important: close reading side, else it remains */ /* opened by child when parent exits and we don't get */ /* a SIGPIPE! */ child(pipefd[1]); } vga_init(); vgamode = vga_getdefaultmode(); if (vgamode == -1) vgamode = G320x200x256; if (!vga_hasmode(vgamode)) { printf("Mode not available.\n"); exit(-1); } /* Enable automatic mouse setup at mode set. */ vga_setmousesupport(1); vga_setmode(vgamode); /* Disable wrapping (default). */ /* mouse_setwrap(MOUSE_NOWRAP); */ gl_setcontextvga(vgamode); gl_enableclipping(); /* There might be some scrap data in the serial buffer from the mouse. It will make vga_waitevent block because it thinks the mouse wants to send data but then no mouse packet arrives. */ color = newcolor(); x = 0; y = 0; gl_setwritemode(WRITEMODE_OVERWRITE | FONT_COMPRESSED); gl_setfont(8, 8, gl_font8x8); gl_setfontcolors(0, newcolor()); #ifdef USE_RAWKEYBOARD if (keyboard_init()) { printf("Could not initialize keyboard.\n"); exit(1); } #endif while (loop) { gl_getbox(x, y, 10, 10, bitmap); if (drawcursor) { gl_hline(x, y, x + cursorsize, color); gl_hline(x, y + cursorsize, x + cursorsize, color); gl_line(x, y, x, y + cursorsize, color); gl_line(x + cursorsize, y, x + cursorsize, y + cursorsize, color); } FD_ZERO(&inputs); FD_SET(pipefd[0], &inputs); timeout.tv_sec = 0; timeout.tv_usec = 500000; /* 0.5 second time out */ event = vga_waitevent(VGA_MOUSEEVENT | VGA_KEYEVENT, &inputs, NULL, NULL, &timeout); gl_putbox(x, y, 10, 10, bitmap); if (timeout.tv_sec || timeout.tv_usec) { /* No timeout. An actual event occured. Reset to visible cursor. Note: This is actually a bug as the cursor will get visible on time updates. However, it's better this way for demo/test purposes. */ drawcursor = 1; } else { drawcursor ^= 1; } if (FD_ISSET(pipefd[0], &inputs)) process_input(pipefd[0]); if (event & VGA_MOUSEEVENT) { x = mouse_getx(); y = mouse_gety(); button = mouse_getbutton(); if (button & MOUSE_LEFTBUTTON) gl_fillbox(x, y, cursorsize + 1, cursorsize + 1, color); if (button & MOUSE_RIGHTBUTTON) loop = 0; } if (event & VGA_KEYEVENT) { #ifdef USE_RAWKEYBOARD if (keyboard_keypressed(SCANCODE_1)) cursorsize = 0; if (keyboard_keypressed(SCANCODE_2)) cursorsize = 1; if (keyboard_keypressed(SCANCODE_3)) cursorsize = 2; if (keyboard_keypressed(SCANCODE_4)) cursorsize = 3; if (keyboard_keypressed(SCANCODE_5)) cursorsize = 4; if (keyboard_keypressed(SCANCODE_6)) cursorsize = 5; if (keyboard_keypressed(SCANCODE_7)) cursorsize = 6; if (keyboard_keypressed(SCANCODE_8)) cursorsize = 7; if (keyboard_keypressed(SCANCODE_9)) cursorsize = 8; if (keyboard_keypressed(SCANCODE_0)) cursorsize = 9; if (keyboard_keypressed(SCANCODE_Q)) loop = 0; if (keyboard_keypressed(SCANCODE_SPACE)) { if (!space_pressed) { color = newcolor(); space_pressed = 1; } } else { space_pressed = 0; } #else switch (vga_getch()) { case '1': cursorsize = 0; break; case '2': cursorsize = 1; break; case '3': cursorsize = 2; break; case '4': cursorsize = 3; break; case '5': cursorsize = 4; break; case '6': cursorsize = 5; break; case '7': cursorsize = 6; break; case '8': cursorsize = 7; break; case '9': cursorsize = 8; break; case '0': cursorsize = 9; break; case ' ': color = newcolor(); break; case 'q': case 'Q': loop = 0; break; default: ping(); break; } #endif } } #ifdef USE_RAWKEYBOARD keyboard_close(); /* Don't forget this! */ #endif vga_setmode(TEXT); exit(0); }
void main(void) { int vgamode, color, leftpressed; int x, y; vga_init(); vgamode = vga_getdefaultmode(); if ((vgamode == -1) || (vga_getmodeinfo(vgamode)->bytesperpixel != 1)) vgamode = G320x200x256; if (!vga_hasmode(vgamode)) { printf("Mode not available.\n"); exit(1); } printf("\nWARNING: This program will set the keyboard to RAW mode.\n" "The keyboard routines in svgalib have not been tested\n" "very much. There may be no recovery if something goes\n" "wrong.\n\n" "Press ctrl-c now to bail out, enter to continue.\n" "In the test itself, use 'q' or Escape to quit.\n" "It will also terminate after 60 seconds.\n" "Use any cursor keys to move, keypad 0 or enter to change color.\n"); getchar(); vga_setmode(vgamode); gl_setcontextvga(vgamode); gl_enableclipping(); signal(SIGALRM, timeout); /* This installs the default handler, which is good enough for most */ /* purposes. */ if (keyboard_init()) { printf("Could not initialize keyboard.\n"); exit(1); } /* Translate to 4 keypad cursor keys, and unify enter key. */ keyboard_translatekeys(TRANSLATE_CURSORKEYS | TRANSLATE_KEYPADENTER | TRANSLATE_DIAGONAL); /* (TRANSLATE_DIAGONAL seems to give problems.) Michael: No doesn't... but might not do what you expect.. */ alarm(60); /* Terminate after 60 seconds for safety. */ x = WIDTH / 2; y = HEIGHT / 2; color = newcolor(); leftpressed = 0; for (;;) { /* Draw moving box. */ gl_fillbox(x, y, 5, 5, color); /* Draw key status bar at top of screen. */ gl_putbox(0, 0, 128, 1, keyboard_getstate()); /* Wait about 1/100th of a second. */ /* Note that use of this function makes things less */ /* smooth because of timer latency. */ usleep(10000); keyboard_update(); /* Move. */ if (keyboard_keypressed(SCANCODE_CURSORLEFT)) x--; if (keyboard_keypressed(SCANCODE_CURSORRIGHT)) x++; if (keyboard_keypressed(SCANCODE_CURSORUP)) y--; if (keyboard_keypressed(SCANCODE_CURSORDOWN)) y++; /* Boundary checks. */ if (x < 0) x = 0; if (x >= WIDTH) x = WIDTH - 1; if (y < 1) y = 1; if (y >= HEIGHT) y = HEIGHT - 1; /* Check for color change. */ if (keyboard_keypressed(SCANCODE_KEYPAD0) || keyboard_keypressed(SCANCODE_ENTER)) { if (!leftpressed) { color = newcolor(); leftpressed = 1; } } else leftpressed = 0; if (keyboard_keypressed(SCANCODE_Q) || keyboard_keypressed(SCANCODE_ESCAPE)) break; } keyboard_close(); /* Don't forget this! */ vga_setmode(TEXT); exit(0); }
int main(int argc, char *argv[]) { int mode, mode2; int i, high; vga_init(); /* Initialize. */ mode = -1; mode2= -1; if(argc==2) { mode = atoi(argv[1]); } else if(argc==3) { mode = atoi(argv[1]); mode2= atoi(argv[2]); } if (mode == -1) { printf("Choose one of the following video modes: \n"); high = 0; for (i = 1; i <= vga_lastmodenumber(); i++) if (vga_hasmode(i)) { vga_modeinfo *info; char expl[100]; const char *cols = NULL; *expl = '\0'; info = vga_getmodeinfo(i); switch (info->colors) { case 2: cols = "2"; strcpy(expl, "1 bitplane, monochrome"); break; case 16: cols = "16"; strcpy(expl, "4 bitplanes"); break; case 256: if (i == G320x200x256) strcpy(expl, "packed-pixel"); else if (i == G320x240x256 || i == G320x400x256 || i == G360x480x256) strcpy(expl, "Mode X"); else strcpy(expl, "packed-pixel, banked"); break; case 1 << 15: cols = "32K"; strcpy(expl, "5-5-5 RGB, blue at LSB, banked"); break; case 1 << 16: cols = "64K"; strcpy(expl, "5-6-5 RGB, blue at LSB, banked"); break; case 1 << 24: cols = "16M"; if (info->bytesperpixel == 3) { if (info->flags & RGB_MISORDERED) strcpy(expl, "8-8-8 BGR, red byte first, banked"); else strcpy(expl, "8-8-8 RGB, blue byte first, banked"); } else if (info->flags & RGB_MISORDERED) strcpy(expl, "8-8-8 RGBX, 32-bit pixels, X byte first, banked"); else strcpy(expl, "8-8-8 XRGB, 32-bit pixels, blue byte first, banked"); break; } if (info->flags & IS_INTERLACED) { if (*expl != '\0') strcat(expl, ", "); strcat(expl, "interlaced"); } if (info->flags & IS_DYNAMICMODE) { if (*expl != '\0') strcat(expl, ", "); strcat(expl, "dynamically loaded"); } high = i; printf("%5d: %dx%d, ", i, info->width, info->height); if (cols == NULL) printf("%d", info->colors); else printf("%s", cols); printf(" colors "); if (*expl != '\0') printf("(%s)", expl); printf("\n"); } printf("Enter mode number (1-%d): ", high); scanf("%d", &mode); getchar(); printf("\n"); if (mode < 1 || mode > GLASTMODE) { printf("Error: Mode number out of range \n"); exit(-1); } } if (vga_hasmode(mode)) { testmode(mode); if(mode2!=-1 && vga_hasmode(mode2)) { testmode(mode2); } } else { printf("Error: Video mode not supported by driver\n"); exit(-1); } vga_setmode(TEXT); return 0; }
/* This name doesn't really cover this function, since it also sets up mouse and keyboard. This is done over here, since on most display targets the mouse and keyboard can't be setup before the display has. */ int sysdep_display_driver_open(int reopen) { int i; int best_mode = -1; int depth, score, best_score = 0; vga_modeinfo *my_modeinfo; unsigned char *video_start; static int firsttime = 1; if (reopen) { sysdep_display_effect_close(); if (doublebuffer_buffer) { free(doublebuffer_buffer); doublebuffer_buffer = NULL; } } /* Find a suitable mode, also determine the max size of the display */ sysdep_display_properties.max_width = 0; sysdep_display_properties.max_height = 0; for (i=1; (my_modeinfo=vga_getmodeinfo(i)); i++) { if (!vga_hasmode(i)) continue; switch(my_modeinfo->colors) { case 32768: depth = 15; break; case 65536: depth = 16; break; case 16777216: depth = 24; break; default: continue; } score = mode_match(my_modeinfo->width, my_modeinfo->height, my_modeinfo->linewidth/my_modeinfo->bytesperpixel, depth, my_modeinfo->bytesperpixel*8); if (score > best_score) { best_score = score; best_mode = i; video_modeinfo = *my_modeinfo; } /* also determine the max size of the display */ if (my_modeinfo->width > sysdep_display_properties.max_width) sysdep_display_properties.max_width = my_modeinfo->width; if (my_modeinfo->height > sysdep_display_properties.max_height) sysdep_display_properties.max_height = my_modeinfo->height; if (firsttime) fprintf(stderr, "SVGAlib: Info: Found videomode %dx%dx%d\n", my_modeinfo->width, my_modeinfo->height, (depth==24)? my_modeinfo->bytesperpixel*8:depth); } firsttime = 0; if (best_score == 0) { fprintf(stderr, "SVGAlib: Couldn't find a suitable mode\n"); return 1; } mode_set_aspect_ratio((double)(video_modeinfo.width)/video_modeinfo.height); scaled_width = ((sysdep_display_params.width+3)&~3) * sysdep_display_params.widthscale; scaled_height = sysdep_display_params.yarbsize? sysdep_display_params.yarbsize: sysdep_display_params.height * sysdep_display_params.heightscale; startx = ((video_modeinfo.width - scaled_width ) / 2) & ~3; starty = (video_modeinfo.height - scaled_height) / 2; fprintf(stderr, "Using video mode %dx%dx%d, starting at %dx%d\n", video_modeinfo.width, video_modeinfo.height, video_modeinfo.colors, startx, starty); /* fill the sysdep_display_properties struct */ memset(&sysdep_display_properties.palette_info, 0, sizeof(struct sysdep_palette_info)); switch(video_modeinfo.colors) { case 32768: sysdep_display_properties.palette_info.red_mask = 0x001F; sysdep_display_properties.palette_info.green_mask = 0x03E0; sysdep_display_properties.palette_info.blue_mask = 0xEC00; sysdep_display_properties.palette_info.depth = 15; break; case 65536: sysdep_display_properties.palette_info.red_mask = 0xF800; sysdep_display_properties.palette_info.green_mask = 0x07E0; sysdep_display_properties.palette_info.blue_mask = 0x001F; sysdep_display_properties.palette_info.depth = 16; break; case 16777216: sysdep_display_properties.palette_info.red_mask = 0xFF0000; sysdep_display_properties.palette_info.green_mask = 0x00FF00; sysdep_display_properties.palette_info.blue_mask = 0x0000FF; sysdep_display_properties.palette_info.depth = 24; break; } sysdep_display_properties.palette_info.bpp = video_modeinfo.bytesperpixel*8; sysdep_display_properties.vector_renderer = NULL; if(best_mode != video_mode) { vga_setmode(best_mode); video_mode = best_mode; } /* do we have a linear framebuffer ? */ i = video_modeinfo.width * video_modeinfo.height * video_modeinfo.bytesperpixel; if ((video_modeinfo.flags & IS_LINEAR) || (use_linear && (video_modeinfo.flags && CAPABLE_LINEAR) && vga_setlinearaddressing() >= i)) { video_mem = vga_getgraphmem(); video_mem += startx * video_modeinfo.bytesperpixel; video_mem += starty * video_modeinfo.linewidth; video_update_type=0; sysdep_display_properties.mode_info[0] |= SYSDEP_DISPLAY_DIRECT_FB; fprintf(stderr, "SVGAlib: Info: Using a linear framebuffer to speed up\n"); } else /* use gl funcs todo the updating */ { gl_setcontextvga(best_mode); /* do we need to blit to a doublebuffer buffer because using effects, scaling etc. */ if (!sysdep_display_blit_dest_bitmap_equals_src_bitmap()) { doublebuffer_buffer = malloc(scaled_width*scaled_height* video_modeinfo.bytesperpixel); if (!doublebuffer_buffer) { fprintf(stderr, "SVGAlib: Error: Couldn't allocate doublebuffer buffer\n"); return 1; } video_update_type=2; } else video_update_type=1; sysdep_display_properties.mode_info[0] &= ~SYSDEP_DISPLAY_DIRECT_FB; } /* clear the unused area of the screen */ switch(video_update_type) { case 0: /* linear */ video_start = vga_getgraphmem(); /* top */ memset(video_start, 0, starty*video_modeinfo.linewidth); /* left and right */ for (i=starty; i<(scaled_height+starty); i++) { /* left */ memset(video_start + i*video_modeinfo.linewidth, 0, startx * video_modeinfo.bytesperpixel); /* right */ memset(video_start + i*video_modeinfo.linewidth + (startx + scaled_width) * video_modeinfo.bytesperpixel, 0, (video_modeinfo.width - (startx + scaled_width)) * video_modeinfo.bytesperpixel); } /* bottom */ memset(video_start + (starty + scaled_height) * video_modeinfo.linewidth, 0, (video_modeinfo.height - (starty + scaled_height)) * video_modeinfo.linewidth); break; case 1: /* gl bitmap equals framebuffer */ case 2: /* gl bitmap needs conversion before it can be blitted */ /* top */ gl_fillbox(0, 0, video_modeinfo.width, starty, 0); /* left */ gl_fillbox(0, starty, startx, scaled_height, 0); /* right */ gl_fillbox(startx + scaled_width, starty, video_modeinfo.width - (startx + scaled_width), scaled_height, 0); /* bottom */ gl_fillbox(0, starty + scaled_height, video_modeinfo.width, video_modeinfo.height - (starty + scaled_height), 0); break; } /* init input */ if (!reopen) { if(svga_input_open(NULL, NULL)) return 1; } /* get a blit function */ return !(blit_func=sysdep_display_effect_open()); }
static void screen(int mode) { int bpp,bott,endp,linlen,i,j,bii,col,p; vga_modeinfo *minf; unsigned char *vbuf; int mem; if(mode == 0) { printf("Usage:lineart [mode mode ...]\n\nwhere mode is an integer.\n"); return; } if(! vga_hasmode(mode)) { printf("Invalid mode %d\n",mode); return; } vga_setmode(mode); minf = vga_getmodeinfo(mode); if(! (minf->flags & CAPABLE_LINEAR)){ vga_setmode(TEXT); printf("The mode %d is not capable of linear\n",mode); return; } vga_setpage(0); if(vga_setlinearaddressing() == -1) { vga_setmode(TEXT); printf("Could not set linear addressing for mode %d\n",mode); return; } bpp = minf->bytesperpixel; linlen = minf->width*bpp; bott = linlen*17; /* pointer 17 pixels wide. */ endp = linlen*minf->height; mem = minf->linewidth*minf->height; /* Do random pixels */ vbuf = vga_getgraphmem(); printf("Memory mapped to %08x. Mode = %d.\n",(int) vbuf,mode); memset(vbuf,0,mem); /* Clear out 2 megabytes of memory, */ for(i = 0;i < 100000;i++) { p = rand() % mem-2; *(vbuf + p) = rand() & 0xff; if(bpp > 1) *(vbuf + p + 1) = rand() & 0xff; if(bpp == 3) *(vbuf + p + 2) = rand() & 0xff; } /* Place marker at top left and bottem right. */ for(i = 0;i < 44;i += bpp) { *(vbuf + i) = 0x60; *(vbuf + bott + i) = 0x60; *(vbuf + endp - i) = 0x60; bii = endp -1 -bott; *(vbuf + bii -i) = 0x60; if(bpp > 1) { *(vbuf + i + 1) = 0x60; *(vbuf + i + 1 + bott) = 0x60; *(vbuf - i - 1 + endp) = 0x60; *(vbuf - i - 1 + bii) = 0x60; } if(bpp == 3) { *(vbuf + i + 2) = 0x60; *(vbuf + i + 2 + bott) = 0x60; *(vbuf - i - 2 + endp) = 0x60; *(vbuf - i - 2 + bii) = 0x60; } col = (i == 0 || i >= 42)? 0x60:0; for(j = 1;j < 17;j++) { *(vbuf + i + linlen*j) = col; *(vbuf - i + endp -1 - linlen*j) = col; if(bpp > 1) { *(vbuf + i + 1 + linlen*j) = col; *(vbuf - i - 2 + endp - linlen*j) = col; } if(bpp == 3) { *(vbuf + i + 2 + linlen*j) = col; *(vbuf - i - 3 + endp - linlen*j) = col; } } } for(i = 5;i < 12;i += bpp) for(j = 4;j < 12;j++) { *(vbuf + i + linlen*j) = 0x3f; *(vbuf + endp - i - bpp - linlen*j) = 0x3f; } getchar(); /* Wait for a key punch */ }
int SVGA_VideoInit(_THIS, SDL_PixelFormat *vformat) { int keyboard; int i, j; int mode, total_modes; /* Initialize all variables that we clean on shutdown */ for ( i=0; i<NUM_MODELISTS; ++i ) { SDL_nummodes[i] = 0; SDL_modelist[i] = NULL; SDL_vgamode[i] = NULL; } /* Initialize the library */ vga_disabledriverreport(); if ( vga_init() < 0 ) { SDL_SetError("Unable to initialize SVGAlib"); return(-1); } vga_setmode(TEXT); /* Enable mouse and keyboard support */ vga_setmousesupport(1); keyboard = keyboard_init_return_fd(); if ( keyboard < 0 ) { SDL_SetError("Unable to initialize keyboard"); return(-1); } if ( SVGA_initkeymaps(keyboard) < 0 ) { return(-1); } keyboard_seteventhandler(SVGA_keyboardcallback); /* Determine the screen depth (use default 8-bit depth) */ vformat->BitsPerPixel = 8; /* Enumerate the available fullscreen modes */ total_modes = 0; for ( mode=vga_lastmodenumber(); mode; --mode ) { if ( vga_hasmode(mode) ) { if ( SVGA_AddMode(this, mode, 0, 0) ) { ++total_modes; } } } if ( SVGA_AddMode(this, G320x200x256, 0, 1) ) ++total_modes; if ( total_modes == 0 ) { SDL_SetError("No linear video modes available"); return(-1); } for ( i=0; i<NUM_MODELISTS; ++i ) { SDL_vgamode[i] = (int *)malloc(SDL_nummodes[i]*sizeof(int)); if ( SDL_vgamode[i] == NULL ) { SDL_OutOfMemory(); return(-1); } SDL_modelist[i] = (SDL_Rect **) malloc((SDL_nummodes[i]+1)*sizeof(SDL_Rect *)); if ( SDL_modelist[i] == NULL ) { SDL_OutOfMemory(); return(-1); } for ( j=0; j<SDL_nummodes[i]; ++j ) { SDL_modelist[i][j]=(SDL_Rect *)malloc(sizeof(SDL_Rect)); if ( SDL_modelist[i][j] == NULL ) { SDL_OutOfMemory(); return(-1); } memset(SDL_modelist[i][j], 0, sizeof(SDL_Rect)); } SDL_modelist[i][j] = NULL; } for ( mode=vga_lastmodenumber(); mode; --mode ) { if ( vga_hasmode(mode) ) { SVGA_AddMode(this, mode, 1, 0); } } SVGA_AddMode(this, G320x200x256, 1, 1); /* Free extra (duplicated) modes */ for ( i=0; i<NUM_MODELISTS; ++i ) { j = 0; while ( SDL_modelist[i][j] && SDL_modelist[i][j]->w ) { j++; } while ( SDL_modelist[i][j] ) { free(SDL_modelist[i][j]); SDL_modelist[i][j] = NULL; j++; } } /* Fill in our hardware acceleration capabilities */ SVGA_UpdateVideoInfo(this); /* We're done! */ return(0); }