void vga_set_gmode (void) {
	u8 byte;

	byte = read_att_b(ATC_MODE) & ~0x0f;
	write_att(byte|0x1, ATC_MODE);
//
// display is off at this point

	byte = read_seq_b(SEQ_PLANE_WRITE) & ~0xf;
	write_seq(byte|0xf,SEQ_PLANE_WRITE); // all planes
	byte = read_seq_b(SEQ_MEMORY_MODE);
	write_seq(byte|4,SEQ_MEMORY_MODE);

	byte = read_gra_b(GDC_MODE) & ~0x10;
	write_gra(byte,GDC_MODE);
	write_gra(0x05, GDC_MISC);

	write_crtc(0x20, CRTC_CURSOR_START);
	write_crtc(0x00, CRTC_CURSOR_END);
	byte = read_crtc_b(CRTC_MODE) & ~0xe0;
	write_crtc(byte|0xe0, CRTC_MODE);
	byte = read_crtc_b(CRTC_MAX_SCAN) & ~0x01f;
	write_crtc(byte, CRTC_MAX_SCAN);

	byte = inb(MIS_R); // get 3c2 value by reading 3cc
	outb(byte & ~0xc,MIS_W); // clear last bits to set 25Mhz clock and low page


// turn on display, disable access to attr palette
	inb(IS1_RC);
	outb(0x20, ATT_IW);
}
void vga_set_amode (void) {
	u8 byte;
	write_att(0x0c, ATC_MODE);

	//reset palette to normal in the case it was changed
	write_att(0x0, ATC_COLOR_PAGE);
//
// display is off at this point

	write_seq(0x3,SEQ_PLANE_WRITE); // planes 0 & 1
	byte = read_seq_b(SEQ_MEMORY_MODE) & ~0x04;
	write_seq(byte,SEQ_MEMORY_MODE);

	byte = read_gra_b(GDC_MODE) & ~0x60;
	write_gra(byte|0x10,GDC_MODE);

	write_gra(0x0e, GDC_MISC);

	write_crtc(0x00, CRTC_CURSOR_START);
	write_crtc(CHAR_HEIGHT-1, CRTC_CURSOR_END);

	byte = read_crtc_b(CRTC_MODE) & ~0xe0;
	write_crtc(byte|0xa0, CRTC_MODE);
	byte = read_crtc_b(CRTC_MAX_SCAN) & ~0x01f;
	write_crtc(byte | (CHAR_HEIGHT-1), CRTC_MAX_SCAN);


// turn on display, disable access to attr palette
	inb(IS1_RC);
	outb(0x20, ATT_IW);
}
void vga_putc(unsigned char byte)
{
	if (byte == '\n') {
		video_line++;
		video_col = 0;

	} else if (byte == '\r') {
		video_col = 0;

	} else if (byte == '\b') {
		video_col--;

	} else if (byte == '\t') {
		video_col += 4;

	} else if (byte == '\a') {
		//beep
		//beep(500);

	} else {
		vidmem[((video_col + (video_line *COLS)) * 2)] = byte;
		vidmem[((video_col + (video_line *COLS)) * 2) +1] = VGA_ATTR_CLR_WHT;
		video_col++;
	}
	if (video_col < 0) {
		video_col = 0;
	}
	if (video_col >= COLS) {
		video_line++;
		video_col = 0;
	}
	if (video_line >= LINES) {
		video_scroll();
		video_line--;
	}
	// move the cursor
	write_crtc((video_col + (video_line *COLS)) >> 8, CRTC_CURSOR_HI);
	write_crtc((video_col + (video_line *COLS)) & 0x0ff, CRTC_CURSOR_LO);
}