Using the C language and screen display
Add a write memory function
1 | ; add to naskfunc.nas |
Draw something via direct VRAM access in C
1 | void io_hlt(void); |
Use pointer
1 | void HariMain(void){ |
Configuring colors
we can define a mapping between the 8 bit color and 24 bit color
1 | //bootpack.c |
首先在一连串的访问中屏蔽中断(比如CLI)。
将想要设定的调色板号码写入0x03c8,紧接着,按R,G,B的顺序
写入0x03c9。如果还想继续设定下一个调色板,则省略调色板号
码,再按照RGB的顺序写入0x03c9就行了。
如果想要读出当前调色板的状态,首先要将调色板的号码写入
0x03c7,再从0x03c9读取3次。读出的顺序就是R,G,B。如果要继
续读出下一个调色板,同样也是省略调色板号码的设定,按RGB的
顺序读出。
如果最初执行了CLI,那么最后要执行STI。
为什么这里要除4?
VGA显示模式只支持6位的颜色,而我们是采用8位的16进制来表示颜色,为了更好的适配VGA显示,需要将8位的颜色右移2位,也就是除4。
Port 0x3C8
Port 0x3C8, 0x3C9 and 0x3C7 control the DAC. Each register in the DAC consists of 18 bits, 6 bits for each color component. To write a color, write the color index to port 0x3C8, then write 3 bytes to 0x3C9 in the order red, green, blue. If you want to write multiple consecutive DAC entries, you only need to write the first entry’s index to 0x3C8 then write all values to 0x3C9 in the order red, green, blue, red, green, blue, and so on. The accessed DAC entry will automatically increment after every three bytes written. To read the DAC entries, write the index to be read to 0x3C7, then read the bytes from port 0x3C9 in a similar fashion (as with writing, the index will increment after every three bytes read)
Implement low level functions in assembly
1 | [FORMAT "WCOFF"] |
Draw a rectangle
1 | void boxfill8(unsigned char * vram , int xsize , unsigned char c , int x0 , int y0, int x1 , int y1){ |
To use VMware, first add a floppy driver in hardware configuration(you can find an “add” button near the bottom of the window), then just boot from floppy, using the file haribote.img