📄 vgadraw.c
字号:
/* write to all planes */ port_out(0x02, SEQ_I); port_out(0x0F, SEQ_D);#if defined(CONFIG_ALPHA_JENSEN) MEMCPY(SM + ((y * CI.xdim + x) << 4), colors, length);#else MEMCPY(GM + (y * CI.xdim + x) / 8, colors, length);#endif /* restore map mask register */ port_out(0x02, SEQ_I); /* Yeah, ATI */ port_out(0x0F, SEQ_D); /* enable Set/Reset Register */ port_out(0x01, GRA_I); port_out(0x0F, GRA_D); } break; case 256: { switch (CM) { case G320x200x256: /* linear addressing - easy and fast */#if defined(CONFIG_ALPHA_JENSEN) MEMCPY(SM + ((y * CI.xdim + x) << 7), colors, length);#else MEMCPY(GM + (y * CI.xdim + x), colors, length);#endif#ifdef BACKGROUND __svgalib_is_vt_switching_needed();#endif return 0; case G320x240x256: case G320x400x256: case G360x480x256: modeX: { int first, offset, pixel, plane; for (plane = 0; plane < 4; plane++) { /* select plane */ port_out(0x02, SEQ_I); /* ATI needs to set it */ port_out(1 << plane, SEQ_D); pixel = ((4 - (x & 3) + plane) & 3); first = (y * CI.xdim + x) / 4; if((x & 3) + pixel > 3) first++; for (offset = first; pixel < length; offset++) { gr_writeb(colors[pixel], offset); pixel += 4; } } }#ifdef BACKGROUND __svgalib_is_vt_switching_needed();#endif return 0; } { unsigned long offset; int segment, free; SegmentedCopy: offset = y * CI.xbytes + x; segment = offset >> 16; free = ((segment + 1) << 16) - offset; offset &= 0xFFFF; if (free < length) { vga_setpage(segment);#if defined(CONFIG_ALPHA_JENSEN) MEMCPY(SM + (offset << 7), colors, free);#else MEMCPY(GM + offset, colors, free);#endif vga_setpage(segment + 1); MEMCPY(VM, colors + free, length - free); } else { vga_setpage(segment);#if defined(CONFIG_ALPHA_JENSEN) MEMCPY(SM + (offset << 7), colors, length);#else MEMCPY(GM + offset, colors, length);#endif } } } break; case 32768: case 65536: x *= 2; goto SegmentedCopy; case 1 << 24: if (__svgalib_cur_info.bytesperpixel == 4) { x <<= 2; if (MODEFLAGS & RGB_MISORDERED) { unsigned long offset; int segment, free; offset = y * CI.xbytes + x; segment = offset >> 16; free = ((segment + 1) << 16) - offset; offset &= 0xFFFF; if (free < length) { vga_setpage(segment); shifted_memcpy(GM + offset, colors, free); vga_setpage(segment + 1); shifted_memcpy(GM, colors + free, length - free); } else { vga_setpage(segment); shifted_memcpy(GM + offset, colors, length); } } else { goto SegmentedCopy; } break; } x *= 3; if (MODEFLAGS & RGB_MISORDERED) { unsigned long offset; int segment, free; offset = y * CI.xbytes + x; segment = offset >> 16; free = ((segment + 1) << 16) - offset; offset &= 0xFFFF; if (free < length) { int i; vga_setpage(segment); i = RGB_swapped_memcpy(GM + offset, colors, free); colors += (free - i); switch (i) { case 2: gr_writeb(colors[2], 0xfffe); gr_writeb(colors[2], 0xffff); break; case 1: gr_writeb(colors[2], 0xffff); break; } vga_setpage(segment + 1); switch (i) { case 1: gr_writeb(colors[1], 0); gr_writeb(colors[0], 1); i = 3 - i; free += i; colors += 3; break; case 2: gr_writeb(colors[0], 0); i = 3 - i; free += i; colors += 3; break; } RGB_swapped_memcpy(GM + i, colors, length - free); } else { vga_setpage(segment); RGB_swapped_memcpy(GM + offset, colors, length); } } else { goto SegmentedCopy; } }#ifdef BACKGROUND __svgalib_is_vt_switching_needed();#endif return 0;}#ifdef BACKGROUNDstatic int _vga_getscansegment_bg(unsigned char *colors, int x, int y, int length){ /* The easy way */ int count=0; while(count<length) { vga_setcolor(*colors); *colors=__svgalib_fast_getpixel(x+count,y); colors++; count++; } return(0);}#endifint vga_getscansegment(unsigned char *colors, int x, int y, int length){#ifdef BACKGROUND __svgalib_dont_switch_vt_yet(); if (!vga_oktowrite()) { /*__svgalib_is_vt_switching_needed(); */ _vga_getscansegment_bg(colors,x,y,length); __svgalib_is_vt_switching_needed(); return(0); }#endif if (MODEX) goto modeX2; switch (CI.colors) { case 16: { int i, k, page, l1, l2; int offset, eoffs, soffs, nbytes, bit; unsigned char *address; unsigned char color; k = 0; soffs = (x & 0x7); /* starting offset into first byte */ eoffs = (x + length) & 0x7; /* ending offset into last byte */ offset = (y * CI.xdim + x) / 8; vga_setpage((page = offset >> 16)); l1 = 0x10000 - (offset &= 0xffff); if (soffs) nbytes = (length - (8 - soffs)) / 8 + 1; else nbytes = length / 8; if (eoffs) nbytes++; if (l1 > nbytes) l1 = nbytes; l2 = nbytes - l1; address = GM + offset; /* disable Set/Reset Register */ port_out(0x01, GRA_I); port_out(0x00, GRA_D); /* read plane 0 */ port_out(0x04, GRA_I); port_out(0x00, GRA_D); memcpy(plane0, address, l1); /* read plane 1 */ port_out(0x04, GRA_I); port_out(0x01, GRA_D); memcpy(plane1, address, l1); /* read plane 2 */ port_out(0x04, GRA_I); port_out(0x02, GRA_D); memcpy(plane2, address, l1); /* read plane 3 */ port_out(0x04, GRA_I); port_out(0x03, GRA_D); memcpy(plane3, address, l1); if (l2 > 0) { vga_setpage(page + 1); /* read plane 0 */ port_out(0x04, GRA_I); port_out(0x00, GRA_D); memcpy(&plane0[l1], GM, l2); /* read plane 1 */ port_out(0x04, GRA_I); port_out(0x01, GRA_D); memcpy(&plane1[l1], GM, l2); /* read plane 2 */ port_out(0x04, GRA_I); port_out(0x02, GRA_D); memcpy(&plane2[l1], GM, l2); /* read plane 3 */ port_out(0x04, GRA_I); port_out(0x03, GRA_D); memcpy(&plane3[l1], GM, l2); } /* enable Set/Reset Register */ port_out(0x01, GRA_I); port_out(0x0F, GRA_D); k = 0; for (i = 0; i < length;) { for (bit = 7 - soffs; bit >= 0 && i < length; bit--, i++) { color = (plane0[k] & (1 << bit) ? 1 : 0); color |= (plane1[k] & (1 << bit) ? 1 : 0) << 1; color |= (plane2[k] & (1 << bit) ? 1 : 0) << 2; color |= (plane3[k] & (1 << bit) ? 1 : 0) << 3; colors[i] = color; } k++; soffs = 0; } } break; case 2: { /* disable Set/Reset Register */ port_out(0x01, GRA_I); port_out(0x00, GRA_D); /* read from plane 0 */ port_out(0x04, SEQ_I); port_out(0x00, SEQ_D); memcpy(colors, GM + (y * CI.xdim + x) / 8, length); /* enable Set/Reset Register */ port_out(0x01, GRA_I); port_out(0x0F, GRA_D); } break; case 256: { switch (CM) { case G320x200x256: /* linear addressing - easy and fast */ memcpy(colors, GM + y * CI.xdim + x, length);#ifdef BACKGROUND __svgalib_is_vt_switching_needed();#endif return 0; case G320x240x256: case G320x400x256: case G360x480x256: modeX2: { int first, offset, pixel, plane; for (plane = 0; plane < 4; plane++) { /* select plane */ port_out(0x04, GRA_I); /* feel the wrath of the ATI */ port_out(plane, GRA_D); pixel = ((4 - (x & 3) + plane) & 3); first = (y * CI.xdim + x) / 4; if((x & 3) + pixel > 3) first++; for (offset = first; pixel < length; offset++) { colors[pixel] = gr_readb(offset); pixel += 4; } } }#ifdef BACKGROUND __svgalib_is_vt_switching_needed();#endif return 0; } { unsigned long offset; int segment, free; SegmentedCopy2: offset = y * CI.xbytes + x; segment = offset >> 16; free = ((segment + 1) << 16) - offset; offset &= 0xFFFF; if (free < length) { vga_setpage(segment); memcpy(colors, GM + offset, free); vga_setpage(segment + 1); memcpy(colors + free, GM, length - free); } else { vga_setpage(segment); memcpy(colors, GM + offset, length); } } } break; case 32768: case 65536: x *= 2; goto SegmentedCopy2; case 1 << 24:#ifdef BACKGROUND __svgalib_is_vt_switching_needed();#endif return -1; /* not supported */ }#ifdef BACKGROUND __svgalib_is_vt_switching_needed();#endif return 0;}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -