?? video.c
字號:
*((char *)addr) = (char) ch; video_col++; if (video_col > (VGA_MAXCOLS-1)) { video_row++; video_col=0; } } /* If we're on the bottom of the secreen, wrap one row */ if (video_row > (VGA_MAXROWS-1)) video_scroll(1); video_cursor(video_col, video_row);}unsigned char video_set_attr(unsigned char attr){ unsigned char saved_attr = video_attr; video_attr = attr; return saved_attr;}unsigned char video_set_attr_xy(unsigned char attr, int x, int y){ unsigned char *addr = video_fb + (x * 80 + y) * 2 + 1; unsigned char saved_attr = *addr; *addr = attr; return saved_attr;}/* put char at xy */void video_putc_xy(char ch, int x, int y){ video_col = x; video_row = y; video_putc(ch);}/* put char at xy relative to the position */void video_putc_rxy(char ch, int x, int y){ video_col += x; video_row += y; video_putc(ch);}/* put char with attribute at xy */void video_putc_axy(char ch, char attr, int x, int y){ unsigned char saved_attr = video_set_attr(attr); video_col = x; video_row = y; video_putc(ch); video_set_attr(saved_attr);}void video_puts(const char *s){ while(*s) { video_putc(*s); s++; }}void video_puts_a(const char *s, char attr){ unsigned char saved_attr = video_set_attr(attr); video_puts(s); video_set_attr(saved_attr);}void video_puts_xy(const char *s, int x, int y){ video_cursor(x,y); video_puts(s);}void video_puts_axy(const char *s, char attr, int x, int y){ unsigned char saved_attr = video_set_attr(attr); video_puts_xy(s, x, y); video_set_attr(saved_attr);}void video_wipe_ca_area(unsigned char ch, char attr, int x, int y, int w, int h){ int r, c; /* better to do this as word writes */ unsigned short * addr16 = (unsigned short *)video_fb + (y * 80 + x); unsigned short charattr = (unsigned short)ch << 8 | attr; charattr=vga_swap_short(charattr); for (r = 0 ; r < h ; r++, addr16 += 80) { for (c = 0 ; c < w ; c++) { addr16[c] = charattr; } }}void video_wipe_a_area(unsigned char attr, int x, int y, int w, int h){ int r, c; /* better to do this as word writes */ unsigned short * addr16 = (unsigned short *)video_fb + (y * 80 + x); for (r = 0 ; r < h ; r++, addr16 += 80) { for (c = 0 ; c < w ; c++) { ((char*)addr16)[c*2+1] = attr; } }}void video_wipe_c_area(unsigned char ch, int x, int y, int w, int h){ int r, c; /* better to do this as word writes */ unsigned short * addr16 = (unsigned short *)video_fb + (y * 80 + x); for (r = 0 ; r < h ; r++, addr16 += 80) { for (c = 0 ; c < w ; c++) { ((char*)addr16)[c*2] = ch; } }}/*tl t trl lbl b br*/typedef struct { unsigned char tl; /* top left corner */ unsigned char t; /* top edge */ unsigned char tr; /* top right corner */ unsigned char l; /* left edge */ unsigned char r; /* right edge */ unsigned char bl; /* bottom left corner */ unsigned char b; /* bottom edge */ unsigned char br; /* bottom right corner */} box_chars_t;box_chars_t sbox_chars = { 0xDA, 0xC4, 0xBF, 0xB3, 0xB3, 0xC0, 0xC4, 0xD9};box_chars_t dbox_chars = { 0xC9, 0xCD, 0xBB, 0xBA, 0xBA, 0xC8, 0xCD, 0xBC};static char cmap[] = "0123456789ABCDEF";void video_putchex(char c){ video_putc(cmap[(c >> 4 ) & 0xF]); video_putc(cmap[c & 0xF]);}void video_putchexl(char c){ video_putc(cmap[c & 0xF]);}void video_putchexh(char c){ video_putc(cmap[(c >> 4) & 0xF]);}#define VGA_CELL_CA(a,c) (((unsigned short)c<<8)|a) /* for BIG endians */void video_gbox_area(box_chars_t *box_chars_p, int x, int y, int w, int h){ int r, c; /* better to do this as word writes */ unsigned short* addr16 = (unsigned short *)video_fb + (y * VGA_MAXCOLS + x); for (r = 0 ; r < h ; r++, addr16 += VGA_MAXCOLS) { if (r == 0) { addr16[0] = VGA_CELL_CA(video_attr, box_chars_p->tl); addr16[w-1] = VGA_CELL_CA(video_attr, box_chars_p->tr); for (c = 1 ; c < w - 1 ; c++) addr16[c] = VGA_CELL_CA(video_attr, box_chars_p->t); } else if (r == h - 1) { addr16[0] = VGA_CELL_CA(video_attr, box_chars_p->bl); addr16[w-1] = VGA_CELL_CA(video_attr, box_chars_p->br); for (c = 1 ; c < w - 1 ; c++) addr16[c] = VGA_CELL_CA(video_attr, box_chars_p->b); } else { addr16[0] = VGA_CELL_CA(video_attr, box_chars_p->l); addr16[w-1] = VGA_CELL_CA(video_attr, box_chars_p->r); } }}/* Writes a box on the screen */void video_box_area(int x, int y, int w, int h) { video_gbox_area(&sbox_chars, x, y, w, h);}/*writes a box with double lines on the screen */void video_dbox_area(int x, int y, int w, int h) { video_gbox_area(&dbox_chars, x, y, w, h);}/* routines to set the VGA registers *//* set attributes */void vga_set_attrib(void){ int i; unsigned char status; status=in8(STATUS_REG1); i=0; while(attr[i].reg!=0xFF) { out8(ATTRI_INDEX,attr[i].reg); out8(ATTRI_INDEX,attr[i].val); /* Attribute uses index for index and data */ i++; } out8(ATTRI_INDEX,0x20); /* unblank the screen */}/* set CRT Controller Registers */void vga_set_crt(void){ int i; i=0; while(crtc[i].reg!=0xFF) { out8(CRT_INDEX,crtc[i].reg); out8(CRT_DATA,crtc[i].val); i++; }}/* Set Palette Registers (DAC) */void vga_set_dac(void){ int i; for(i=0;i<256;i++) { out8(COL_PAL_IND_W,(unsigned char)i); out8(COL_PAL_DATA,dac[i][0]); /* red */ out8(COL_PAL_DATA,dac[i][1]); /* green */ out8(COL_PAL_DATA,dac[i][2]); /* blue */ } out8(COL_PAL_MASK,0xff); /* set mask */}/* set Graphic Controller Register */void vga_set_gr(void){ int i; i=0; while(grmr[i].reg!=0xFF) { out8(GR_INDEX,grmr[i].reg); out8(GR_DATA,grmr[i].val); i++; }}/* Set Sequencer Registers */void vga_set_seq(void){ int i; i=0; while(seq[i].reg!=0xFF) { out8(SEQ_INDEX,seq[i].reg); out8(SEQ_DATA,seq[i].val); i++; }}/* Set Extension Registers */void vga_set_xreg(void){ int i; i=0; while(xreg[i].reg!=0xFF) { out8(XREG_INDEX,xreg[i].reg); out8(XREG_DATA,xreg[i].val); i++; }}/************************************************************ * some helping routines */void vga_write_sr(unsigned char reg,unsigned char val){ out8(SEQ_INDEX,reg); out8(SEQ_DATA,val);}void vga_write_gr(unsigned char reg,unsigned char val){ out8(GR_INDEX,reg); out8(GR_DATA,val);}void vga_write_cr(unsigned char reg,unsigned char val){ out8(CRT_INDEX,reg); out8(CRT_DATA,val);}#if 0void video_dump_reg(void){ /* first dump attributes */ int i; unsigned char status; printf("Extended Regs:\n"); i=0; while(xreg[i].reg!=0xFF) { out8(XREG_INDEX,xreg[i].reg); status=in8(XREG_DATA); printf("XR%02X is %02X, should be %02X\n",xreg[i].reg,status,xreg[i].val); i++; } printf("Sequencer Regs:\n"); i=0; while(seq[i].reg!=0xFF) { out8(SEQ_INDEX,seq[i].reg); status=in8(SEQ_DATA); printf("SR%02X is %02X, should be %02X\n",seq[i].reg,status,seq[i].val); i++; } printf("Graphic Regs:\n"); i=0; while(grmr[i].reg!=0xFF) { out8(GR_INDEX,grmr[i].reg); status=in8(GR_DATA); printf("GR%02X is %02X, should be %02X\n",grmr[i].reg,status,grmr[i].val); i++; } printf("CRT Regs:\n"); i=0; while(crtc[i].reg!=0xFF) { out8(CRT_INDEX,crtc[i].reg); status=in8(CRT_DATA); printf("CR%02X is %02X, should be %02X\n",crtc[i].reg,status,crtc[i].val); i++; } printf("Attributes:\n"); status=in8(STATUS_REG1); i=0; while(attr[i].reg!=0xFF) { out8(ATTRI_INDEX,attr[i].reg); status=in8(ATTRI_DATA); out8(ATTRI_INDEX,attr[i].val); /* Attribute uses index for index and data */ printf("AR%02X is %02X, should be %02X\n",attr[i].reg,status,attr[i].val); i++; }}#endif#endif /* CONFIG_VIDEO */
?? 快捷鍵說明
復(fù)制代碼
Ctrl + C
搜索代碼
Ctrl + F
全屏模式
F11
切換主題
Ctrl + Shift + D
顯示快捷鍵
?
增大字號
Ctrl + =
減小字號
Ctrl + -