Help out

xiaoxiao2021-03-06  41

#include #include #include #include #include #include #include # Include #include #include #include

#define VGA256 0x13 # define TEXT_MODE 0x03 # define SCREEN_WIDTH 320 # define SCREEN_HEIGHT 200 # define PALETTE_MASK 0x3c6 # define PALETTE_REGISTER_RD 0x3c7 # define PALETTE_REGISTER_WR 0x3c8 # define PALETTE_DATA 0x3c9

Typedef struct rgb_color_typ {unsigned char red; unsigned char green; unsigned char blue;} RGB_COLOR, * RGB_COLOR_PTR;

Unsigned char far * video_buffer = (char far *) 0xA0000000L; float sin_look [361]; float cos_look [361];

Void delay (int ClickS) {unsigned int far * clock = (unsigned int far *) 0x0000046cl; unsigned int now; now = * clock; while (abs (* clock-now) {}}

Void create_tables (void) {int index; for (INDEX = 0; index <= 360; index ) {cos_look [index] = (float) COS ((Double) (Index * 3.14159 / 180); sin_look [index] = (FLOAT) SIN ((Double) (Index * 3.14159 / 180));}}

void Set_Palette_Register (int index, RGB_color_ptr color) {outp (PALETTE_MASK, 0xff); outp (PALETTE_REGISTER_WR, index); outp (PALETTE_DATA, color-> red); outp (PALETTE_DATA, color-> green); outp (PALETTE_DATA, color- > blue);} void Get_Palette_Register (int index, RGB_color_ptr color) {outp (PALETTE_MASK, 0xff); outp (PALETTE_REGISTER_RD, index); color-> red = inp (PALETTE_DATA); color-> green = inp (PALETTE_DATA); color -> Blue = INP (Palette_data);

}

Void set_video_mode (int mode) {Union Regs INREGS, OUTREGS; INREGS.H.AH = 0; INREGS.H.AL = (unsigned char) mode; int86 (0x10, & inregs, & outregs);}

Void Plot_pixel_fast (int X, int y, char color) {video_buffer [(Y << 8) (Y << 6)) x] = color;} void bplot_pixel_fast (int x, int y, char color) { Video_buffer [(Y << 8) (Y << 6)) x] = color; video_buffer [(Y << 8) (Y << 6)) x-1] = color; video_buffer [ ((Y << 8) (Y << 6)) X-320] = Color; Video_Buffer [(Y << 8) (Y << 6)) X-321] = Color;}

Void Bline (int X0, int y0, int x1, int y1, unsigned char color) / * Sao miao qu * / {Int DX, DY, X_INC, Y_INC, ERROR = 0, Index; Unsigned Char Far * VB_Start = Video_Buffer; VB_START = VB_START (unsigned int) y0 << 6) (unsigned int) x0; dx = x1-x0; DY = Y1-Y0; if (dx> = 0) {x_inc = 1; / * Sao miao quhip xiao zhi zuo ce zhi you ce * /} else {x_inc = -1; / * tong smang * / dx = -dx;} if (dy> = 0) {y_inc = 320;} else {y_inc = -320; DY = -dy;} if (dx> DY) {for (index = 0; index <= dx; index ) {* vb_start = color; error = DY; if (Error> DX) {Error- = DX; vb_start = y_inc;} vb_start = x_inc;}} else {for (index = 0; index <= DY; index ) {* vb_start = color; error = dx; if (error> 0) {Error- = DY; VB_START = X_INC;} VB_Start = Y_INC;}}}

Void H_Line (int X1, int x2, int y, unsigned int color) {MEMSET ((Char Far *) ("Y << 8) (Y << 6)) x1), Color, X2- X1 1);

Void v_Line (int y1, int y2, int x, unsigned int color) {INT i; for (i = y1; i

Void Circle (int X, int y, int R, int color) {INT X0, Y0, X1, Y1, Index; X0 = Y0 = R / SQRT (2); for (INDEX = 0; index <= 360; index ) {X1 = x0 * cos_look [index] -y0 * sin_look [index]; y1 = x0 * sin_look [index] y0 * cos_look [index]; plot_pixel_fast (x x1, y y1, color);}} void Bcircle (int X, int y, int R, int color) {INT X0, Y0, X1, Y1, Index; X0 = Y0 = R / SQRT (2); for (INDEX = 0; index <= 360; index ) {X1 = x0 * cos_look [index] -y0 * sin_look [index]; y1 = x0 * sin_look [index] y0 * cos_look [index]; plot_pixel_fast (x x1, y y1, color); plot_pixel_fast (x X1-1, Y Y1, Color; Plot_Pixel_fast (x x1, y y1-1, color); plot_pixel_fast (x x1 1, y y1, color); plot_pixel_fast (x x1, y Y1 1, color); Plot_Pixel_fast (x x1-1, y y1-1, color); plot_pixel_fast (x x1 1, y y1-1, color); plot_pixel_fast (x x1 1, y Y1 1, color); Plot_Pixel_fast (x x1-1, y y1 1, color);}

}

Void Fill_Circle (int X, int y, int r, int color) {int index; for (index = r; index> 0; index - {bcircle (x, y, index, color);}}

Void main (void) {int index, x0 = 160, y0 = 100, x1 = 50, y1 = 50, x2, y2, curr_color = 1, I, flag = 0, SON = 0; RGB_COLOR Color, Color_1, Color_2; Create_Tables (); set_video_mode (vga256); color.red = 0; color.green = 0; color.blue = 5; set_palette_register (0, (RGB_COLOR_PTR) & color);

For (index = 1; index <= 255; index ) {color.red = 0; color.green = 10; color.blue = 0; set_palette_register (index, (rgb_color_ptr) & color);} color.red = 0; color .green = 30; color.blue = 0; set_palette_register (182, (rgb_color_ptr) & color); color.red = 0; color.green = 10; color.blue = 0; set_palette_register (183, (RGB_COLOR_PTR) & color); for (index = 184; index <= 188; index ) {color.Red = 0; color.green = 30 (index-184) * 10; color.blue = 0; set_palette_register (index, (rgb_color_ptr) & color);} Fill_circle (160, 100, 73, 183); for (index = 0; index <= 360; index ) {x2 = x1 * cos_look [index] -y1 * sin_look [index]; y2 = x1 * sin_look [index] Y1 * COS_LOOK [ Index]; Bline (X0, Y0, X0 X2, Y0 Y2, Index / 2 1); / * Sao Miao Xian Cu Xi * /} v_line (22, 178, 160, 182); / * xian zuo biao * / h_line (82, 238, 100, 182) For (index = 0; index <4; index ) bcircle (160, 100, 73 index, 184 index);

For (index = 0; index <4; index ) bcircle (160, 100, 76 index, 187-index);

For (index = 1; index <= 158; index = index 5) {plot_pixel_fast (81 index, 99,182); Plot_pixel_fast (161, 21 index, 182);} for (index = 0; index <10; index ) ) {BPlot_Pixel_Fast (143 index * 8,140-index * 2,190 index); Plot_Pixel_Fast (116-index * 2,72 index * 5,190 index); Plot_Pixel_Fast (122 index * 2,145-index * 3,190 index); BPlot_Pixel_Fast (190-index * 8,150-index * 2,190 index); Plot_Pixel_Fast (136 index * 2,152-index * 5,190 index); Plot_Pixel_Fast (172-index * 2,145-index * 3,190 index);} color_1.red = 0 ; Color_1.blue = 0; color_2.red = 255; color_2.green = 0; color_2.blue = 0; color.Red = 0; color.blue = 0;

While (! kbhit ()) for (index = 1; index <= 181; index ) {for (i = 0; i <15; i ) {color.green = 20 i * 2; if (INDEX I> 181) Set_Palette_Register (index i-181, (RGB_color_ptr) & color); else Set_Palette_Register (index i, (RGB_color_ptr) & color);} color.green = 255; if (index i> 181) Set_Palette_Register (index i- 181, (RGB_COLOR_PTR) & color); Else Set_palette_register (INDEX I, (RGB_COLOR_PTR) & color);

SET_PALETTE_REGISTER (INDEX, (RGB_COLOR_PTR) & Color_1);

转载请注明原文地址:https://www.9cbs.com/read-70789.html

New Post(0)