FreeBSD/sys/dev/fb/vga.c
/*
 * save_state():
 * Read video register values.
 * NOTE: this function only reads the standard EGA/VGA registers.
 * any extra/extended registers of SVGA adapters are not saved.
 *
 * VGA
 */
Read video register values.
NOTE: this function only reads the standard EGA/VGA registers.
any extra/extended registers of SVGA adapters are not saved.

VGA
Read video register values . NOTE : this function only reads the standard EGA / VGA registers . any extra / extended registers of SVGA adapters are not saved . VGA
static int
vga_save_state(video_adapter_t *adp, void *p, size_t size)
{
    video_info_t info;
    u_char *buf;
    int crtc_addr;
    int i, j;
    int s;
    if (size == 0) {
	prologue(adp, V_ADP_STATESAVE, 0);
	return sizeof(adp_state_t);
    } else {
	prologue(adp, V_ADP_STATESAVE, ENODEV);
	if (size < sizeof(adp_state_t))
	    return EINVAL;
    }
    ((adp_state_t *)p)->sig = V_STATE_SIG;
    buf = ((adp_state_t *)p)->regs;
    bzero(buf, V_MODE_PARAM_SIZE);
    crtc_addr = adp->va_crtc_addr;
    s = splhigh();
    outb(TSIDX, 0x00); outb(TSREG, 0x01);	
    for (i = 0, j = 5; i < 4; i++) {           
	outb(TSIDX, i + 1);
	buf[j++]  =  inb(TSREG);
    }
    buf[9]  =  inb(MISC + 10);			
    outb(TSIDX, 0x00); outb(TSREG, 0x03);	
    for (i = 0, j = 10; i < 25; i++) {		
	outb(crtc_addr, i);
	buf[j++]  =  inb(crtc_addr + 1);
    }
    for (i = 0, j = 35; i < 20; i++) {		
        inb(crtc_addr + 6);			
	outb(ATC, i);
	buf[j++]  =  inb(ATC + 1);
    }
    for (i = 0, j = 55; i < 9; i++) {		
	outb(GDCIDX, i);
	buf[j++]  =  inb(GDCREG);
    }
    inb(crtc_addr + 6);				
    outb(ATC, 0x20);				
    splx(s);
#if 1
    if (vga_get_info(adp, adp->va_mode, &info) == 0) {
	if (info.vi_flags & V_INFO_GRAPHICS) {
	    buf[0] = info.vi_width/info.vi_cwidth; 
	    buf[1] = info.vi_height/info.vi_cheight - 1; 
	} else {
	    buf[0] = info.vi_width;		
	    buf[1] = info.vi_height - 1;	
	}
	buf[2] = info.vi_cheight;		
    }
#else
    buf[0] = readb(BIOS_PADDRTOVADDR(0x44a));	
    buf[1] = readb(BIOS_PADDRTOVADDR(0x484));	
    buf[2] = readb(BIOS_PADDRTOVADDR(0x485));	
    buf[3] = readb(BIOS_PADDRTOVADDR(0x44c));
    buf[4] = readb(BIOS_PADDRTOVADDR(0x44d));
#endif
    return 0;
}
static int vga_save_state ( video_adapter_t * adp , void * p , size_t size ) { video_info_t info ; u_char * buf ; int crtc_addr ; int i , j ; int s ; if ( size == 0 ) { prologue ( adp , V_ADP_STATESAVE , 0 ) ; return sizeof ( adp_state_t ) ; } else { prologue ( adp , V_ADP_STATESAVE , ENODEV ) ; if ( size < sizeof ( adp_state_t ) ) return EINVAL ; } ( ( adp_state_t * ) p ) -> sig = V_STATE_SIG ; buf = ( ( adp_state_t * ) p ) -> regs ; bzero ( buf , V_MODE_PARAM_SIZE ) ; crtc_addr = adp -> va_crtc_addr ; s = splhigh ( ) ; outb ( TSIDX , 0x00 ) ; outb ( TSREG , 0x01 ) ; for ( i = 0 , j = 5 ; i < 4 ; i ++ ) { outb ( TSIDX , i + 1 ) ; buf [ j ++ ] = inb ( TSREG ) ; } buf [ 9 ] = inb ( MISC + 10 ) ; outb ( TSIDX , 0x00 ) ; outb ( TSREG , 0x03 ) ; for ( i = 0 , j = 10 ; i < 25 ; i ++ ) { outb ( crtc_addr , i ) ; buf [ j ++ ] = inb ( crtc_addr + 1 ) ; } for ( i = 0 , j = 35 ; i < 20 ; i ++ ) { inb ( crtc_addr + 6 ) ; outb ( ATC , i ) ; buf [ j ++ ] = inb ( ATC + 1 ) ; } for ( i = 0 , j = 55 ; i < 9 ; i ++ ) { outb ( GDCIDX , i ) ; buf [ j ++ ] = inb ( GDCREG ) ; } inb ( crtc_addr + 6 ) ; outb ( ATC , 0x20 ) ; splx ( s ) ; #if 1 if ( vga_get_info ( adp , adp -> va_mode , & info ) == 0 ) { if ( info . vi_flags & V_INFO_GRAPHICS ) { buf [ 0 ] = info . vi_width / info . vi_cwidth ; buf [ 1 ] = info . vi_height / info . vi_cheight - 1 ; } else { buf [ 0 ] = info . vi_width ; buf [ 1 ] = info . vi_height - 1 ; } buf [ 2 ] = info . vi_cheight ; } #else buf [ 0 ] = readb ( BIOS_PADDRTOVADDR ( 0x44a ) ) ; buf [ 1 ] = readb ( BIOS_PADDRTOVADDR ( 0x484 ) ) ; buf [ 2 ] = readb ( BIOS_PADDRTOVADDR ( 0x485 ) ) ; buf [ 3 ] = readb ( BIOS_PADDRTOVADDR ( 0x44c ) ) ; buf [ 4 ] = readb ( BIOS_PADDRTOVADDR ( 0x44d ) ) ; #endif return 0 ; }
save_state():
 Read video register values.
save_state () : Read video register values .
/* return the required buffer size */ /* stop sequencer */ /* dot-clock */ /* start sequencer */ /* crtc */ /* attribute ctrl */ /* reset flip-flop */ /* graph data ctrl */ /* reset flip-flop */ /* enable palette */ /* COLS */ /* ROWS */ /* COLS */ /* ROWS */ /* POINTS */ /* COLS */ /* ROWS */ /* POINTS */