void flush_line(int offset, char *buffer, int width) { int tmp; if (lbuf_len <= screen_size) { // Banked memory tmp = offset >> 16; if (tmp != screen_page) vga_setpage(screen_page = tmp); offset &= 0xffff; tmp = 0x10000 - offset; if (tmp > width) tmp = width; }
/* ** SWimp_InitGraphics ** ** This initializes the software refresh's implementation specific ** graphics subsystem. In the case of Windows it creates DIB or ** DDRAW surfaces. ** ** The necessary width and height parameters are grabbed from ** vid.width and vid.height. */ static qboolean SWimp_InitGraphics( qboolean fullscreen ) { int bsize, zsize, tsize; SWimp_Shutdown(); current_mode = get_mode(vid.width, vid.height); if (current_mode < 0) { ri.Con_Printf (PRINT_ALL, "Mode %d %d not found\n", vid.width, vid.height); return false; // mode not found } // let the sound and input subsystems know about the new window ri.Vid_NewWindow (vid.width, vid.height); ri.Con_Printf (PRINT_ALL, "Setting VGAMode: %d\n", current_mode ); // Cvar_SetValue ("vid_mode", (float)modenum); VGA_width = modes[current_mode].width; VGA_height = modes[current_mode].height; VGA_planar = modes[current_mode].bytesperpixel == 0; VGA_rowbytes = modes[current_mode].linewidth; vid.rowbytes = modes[current_mode].linewidth; if (VGA_planar) { VGA_bufferrowbytes = modes[current_mode].linewidth * 4; vid.rowbytes = modes[current_mode].linewidth*4; } // get goin' vga_setmode(current_mode); VGA_pagebase = framebuffer_ptr = (char *) vga_getgraphmem(); // if (vga_setlinearaddressing()>0) // framebuffer_ptr = (char *) vga_getgraphmem(); if (!framebuffer_ptr) Sys_Error("This mode isn't hapnin'\n"); vga_setpage(0); vid.buffer = malloc(vid.rowbytes * vid.height); if (!vid.buffer) Sys_Error("Unabled to alloc vid.buffer!\n"); return true; }
static void colhline_pos_paged32 (void) #endif { int count, y = py + dy0, x1 = px1 + dx0, x2 = px2 + dx0; unsigned short offst; int pg; declarevp; long vp = 0; if (__clip) { if (y < __clipy1 || y > __clipy2) return; if (x1 < __clipx1) { #ifdef WRAP xd += (__clipx1 - x1) * xd_x; yd += (__clipx1 - x1) * yd_x; #endif #ifdef INTERP c += (__clipx1 - x1) * c_x; #endif x1 = __clipx1; } if (x2 > __clipx2 + 1) { x2 = __clipx2 + 1; } } count = x2 - x1; assignvpoffset (x1, y, vp); pg = vp >> 16; vga_setpage (pg); offst = vp; if (count > 0) { do { incvpoffset; #ifdef WRAP yd += yd_x; xd += xd_x; #endif #ifdef INTERP c += c_x; #endif } while (--count); } }
/* ** SWimp_EndFrame ** ** This does an implementation specific copy from the backbuffer to the ** front buffer. In the Win32 case it uses BitBlt or BltFast depending ** on whether we're using DIB sections/GDI or DDRAW. */ void SWimp_EndFrame (void) { if (!vga_oktowrite()) return; // can't update screen if it's not active // if (vid_waitforrefresh.value) // vga_waitretrace(); if (VGA_planar) VGA_UpdatePlanarScreen (vid.buffer); else { int total = vid.rowbytes * vid.height; int offset; for (offset=0;offset<total;offset+=0x10000) { vga_setpage(offset/0x10000); memcpy(framebuffer_ptr, vid.buffer + offset, ((total-offset>0x10000)?0x10000:(total-offset))); } } }
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 */ }
SDL_Surface *SVGA_SetVideoMode(_THIS, SDL_Surface *current, int width, int height, int bpp, Uint32 flags) { int mode; int vgamode; vga_modeinfo *modeinfo; int screenpage_len; /* Try to set the requested linear video mode */ bpp = (bpp+7)/8-1; for ( mode=0; SDL_modelist[bpp][mode]; ++mode ) { if ( (SDL_modelist[bpp][mode]->w == width) && (SDL_modelist[bpp][mode]->h == height) ) { break; } } if ( SDL_modelist[bpp][mode] == NULL ) { SDL_SetError("Couldn't find requested mode in list"); return(NULL); } vga_setmode(SDL_vgamode[bpp][mode]); vga_setpage(0); vgamode=SDL_vgamode[bpp][mode]; if ((vga_setlinearaddressing()<0) && (vgamode!=G320x200x256)) { SDL_SetError("Unable to set linear addressing"); return(NULL); } modeinfo = vga_getmodeinfo(SDL_vgamode[bpp][mode]); /* Update hardware acceleration info */ SVGA_UpdateVideoInfo(this); /* Allocate the new pixel format for the screen */ bpp = (bpp+1)*8; if ( (bpp == 16) && (modeinfo->colors == 32768) ) { bpp = 15; } if ( ! SDL_ReallocFormat(current, bpp, 0, 0, 0, 0) ) { return(NULL); } /* Set up the new mode framebuffer */ current->flags = (SDL_FULLSCREEN|SDL_HWSURFACE); if ( bpp == 8 ) { /* FIXME: What about DirectColor? */ current->flags |= SDL_HWPALETTE; } current->w = width; current->h = height; current->pitch = modeinfo->linewidth; current->pixels = vga_getgraphmem(); /* set double-buffering */ if ( flags & SDL_DOUBLEBUF ) { /* length of one screen page in bytes */ screenpage_len=current->h*modeinfo->linewidth; /* if start address should be aligned */ if ( modeinfo->linewidth_unit ) { if ( screenpage_len % modeinfo->linewidth_unit ) { screenpage_len += modeinfo->linewidth_unit - ( screenpage_len % modeinfo->linewidth_unit ); } } /* if we heve enough videomemory = ak je dost videopamete */ if ( modeinfo->memory > ( screenpage_len * 2 / 1024 ) ) { current->flags |= SDL_DOUBLEBUF; flip_page = 0; flip_offset[0] = 0; flip_offset[1] = screenpage_len; flip_address[0] = vga_getgraphmem(); flip_address[1] = flip_address[0]+screenpage_len; SVGA_FlipHWSurface(this,current); } } /* Set the blit function */ this->UpdateRects = SVGA_DirectUpdate; /* Set up the mouse handler again (buggy SVGAlib 1.40) */ mouse_seteventhandler(SVGA_mousecallback); /* We're done */ return(current); }
int main(int argc, char *argv[]) { int i,j; if (!(argc == 2 && strcmp(argv[1], "--force") == 0)) if (!(vga_getmodeinfo(vga_getdefaultmode())->flags & CAPABLE_LINEAR)) { printf("Linear addressing not supported for this chipset.\n"); exit(1); } vga_init(); vga_setmode(vga_getdefaultmode()); vga_setpage(0); #ifdef USE_LINEAR_ADDRESSING if (vga_setlinearaddressing() == -1) { vga_setmode(TEXT); printf("Could not set linear addressing.\n"); exit(-1); } #endif /* Should not mess with bank register after this. */ vbuf = vga_getgraphmem(); printf("vbuf mapped at %08lx.\n", (unsigned long) vbuf); getchar(); #ifdef USE_LINEAR_ADDRESSING memset(vbuf, 0x88, 640 * 480); sleep(1); memset(vbuf, 0, 640 * 480); for (i = 0; i < 100000; i++) *(vbuf + (rand() & 0xfffff)) = rand(); #endif #if 0 if (vga_getcurrentchipset() == CIRRUS) /* Show the bandwidth of the extended write modes of the */ /* Cirrus chip. */ by8test(); #endif getchar(); for(i = 0;i < 44;i++){ *(vbuf + i) = 0x1c; *(vbuf + 640*17 + i) = 0x1c; *(vbuf + 640*480 - i) = 0x1c; *(vbuf + 640*480 - 1 - 640*17 - i) = 0x1c; for(j = 1;j < 17;j++){ *(vbuf + 640*j + i) = (i == 0 || i == 43)? 0x1c:0; *(vbuf + 640*480 - 1 - 640*j - i) = (i == 0 || i == 43)? 0x1c:0; } } for(i = 3;i < 10;i++) for(j = 4;j < 10;j++){ *(vbuf + i + 640*j) = 0x3f; *(vbuf + 640*480 -1 -640*j - i) = 0x3f; } getchar(); vga_setmode(TEXT); return 0; }
int vga_clear(void) { vga_screenoff(); #ifdef BACKGROUND __svgalib_dont_switch_vt_yet(); #endif if (MODEX) goto modeX; switch (CM) { case G320x200x256: case G320x240x256: case G320x400x256: case G360x480x256: modeX: #ifdef BACKGROUND if (vga_oktowrite()) { #endif /* write to all planes */ port_out(0x02, SEQ_I); port_out(0x0F, SEQ_D); /* clear video memory */ memset(GM, 0, 65536); #ifdef BACKGROUND } else { int i; for (i = 0; i < 4; i++) { /* save plane i */ __svgalib_fast_setpage(i); memset(GM, 0, GRAPH_SIZE); } } #endif break; default: switch (CI.colors) { case 2: case 16: vga_setcolor(0); #ifdef BACKGROUND if (vga_oktowrite()) { #endif /* write to all bits */ port_out(0x08, GRA_I); port_out(0xFF, GRA_D); #ifdef BACKGROUND } #endif default: { int i; int pages = (CI.ydim * CI.xbytes + 65535) >> 16; #if defined(CONFIG_ALPHA_JENSEN) int j; #endif #ifdef BACKGROUND if (!vga_oktowrite()) { switch (CI.colors) { case 2: case 16: pages*=4; } } #endif for (i = 0; i < pages; ++i) { vga_setpage(i); #if defined(CONFIG_ALPHA_JENSEN) for (j = 0; j < 65536; j += 2) gr_writew(0, j); #else /* clear video memory */ memset(GM, 0, 65536); #endif } } break; } break; } vga_setcolor(15); #ifdef BACKGROUND __svgalib_is_vt_switching_needed(); #endif vga_screenon(); return 0; }
int graph_init_video(void) { int rc = 0; int screen_colours; vga_modeinfo *vminfo; if (tcgetpgrp(STDIN_FILENO) != getpid()) { fprintf(stderr, "Sorry, this application cannot start in background\n"); return 0; } pltf = PLTF_SVGA; /*-----------------------------------------------------------*/ /* Checking libvga version, 1.4.0 and prior will return (-1) */ /* Currently you need IOPERM for 1.9.x to run as a non-priv */ /* user, however set IOPERM upsets upsets previous versions */ /*-----------------------------------------------------------*/ if (vga_setmode(-1) >= 0x1900) setenv("IOPERM", "1", 0); rc = vga_init(); if (rc != 0) { fprintf(stderr, "Can't initialise SVGA library. \n" "Possible solution: log as root, and enter:\n" "\tchown 0 ifrac\n" "\tchmod 4755 ifrac\n"); return 0; } #ifdef SVGALIB_BACKGROUND_SUPPORT set_background_routines(); #else run_background = 0; #endif if (!set_video_mode()) { fprintf(stderr, "Sorry, unable to set video mode. \n"); return 0; } vminfo = vga_getmodeinfo(vga_getcurrentmode()); WndWidth = ScrWidth = vminfo->width; WndHeight = ScrHeight = vminfo->height; screen_colours = vminfo->colors; if (screen_colours < 16) { fprintf (stderr, "This application requires at least 16-colour mode\n"); return 0; } ScrDepth = 0; while((screen_colours>>=1) != 0) ScrDepth++; if (ScrDepth <= 8) { BytesPerPixel = 1; stored_colours = 1; } else { BytesPerPixel = vminfo->bytesperpixel; stored_colours = 0; } scan_line_width = vminfo->linewidth; screen_size = scan_line_width * ScrHeight; if (ScrDepth < 8) DirVideo = 0; else { vga_setpage(screen_page=0); if (DirVideo == 2 && (vminfo->flags & CAPABLE_LINEAR)) lbuf_len = vga_setlinearaddressing(); if (DirVideo > 0) lbuf_addr = vga_getgraphmem(); } return 1; }