OSDN Git Service

first commit
[winexe-harib/winexe-harib.git] / haribote / graphic.c
1 /* \83O\83\89\83t\83B\83b\83N\8f\88\97\9d\8aÖ\8cW */
2
3 #include "bootpack.h"
4
5 void init_palette(void)
6 {
7         static unsigned char table_rgb[16 * 3] = {
8                 0x00, 0x00, 0x00,       /*  0:\8d\95 */
9                 0xff, 0x00, 0x00,       /*  1:\96¾\82é\82¢\90Ô */
10                 0x00, 0xff, 0x00,       /*  2:\96¾\82é\82¢\97Π*/
11                 0xff, 0xff, 0x00,       /*  3:\96¾\82é\82¢\89©\90F */
12                 0x00, 0x00, 0xff,       /*  4:\96¾\82é\82¢\90 */
13                 0xff, 0x00, 0xff,       /*  5:\96¾\82é\82¢\8e\87 */
14                 0x00, 0xff, 0xff,       /*  6:\96¾\82é\82¢\90\85\90F */
15                 0xff, 0xff, 0xff,       /*  7:\94\92 */
16                 0xc6, 0xc6, 0xc6,       /*  8:\96¾\82é\82¢\8aD\90F */
17                 0x84, 0x00, 0x00,       /*  9:\88Ã\82¢\90Ô */
18                 0x00, 0x84, 0x00,       /* 10:\88Ã\82¢\97Π*/
19                 0x84, 0x84, 0x00,       /* 11:\88Ã\82¢\89©\90F */
20                 0x00, 0x00, 0x84,       /* 12:\88Ã\82¢\90 */
21                 0x84, 0x00, 0x84,       /* 13:\88Ã\82¢\8e\87 */
22                 0x00, 0x84, 0x84,       /* 14:\88Ã\82¢\90\85\90F */
23                 0x84, 0x84, 0x84        /* 15:\88Ã\82¢\8aD\90F */
24         };
25         unsigned char table2[216 * 3];
26         int r, g, b;
27         set_palette(0, 15, table_rgb);
28         for (b = 0; b < 6; b++) {
29                 for (g = 0; g < 6; g++) {
30                         for (r = 0; r < 6; r++) {
31                                 table2[(r + g * 6 + b * 36) * 3 + 0] = r * 51;
32                                 table2[(r + g * 6 + b * 36) * 3 + 1] = g * 51;
33                                 table2[(r + g * 6 + b * 36) * 3 + 2] = b * 51;
34                         }
35                 }
36         }
37         set_palette(16, 231, table2);
38         return;
39 }
40
41 void set_palette(int start, int end, unsigned char *rgb)
42 {
43         int i, eflags;
44         eflags = io_load_eflags();      /* \8a\84\82è\8d\9e\82Ý\8b\96\89Â\83t\83\89\83O\82Ì\92l\82ð\8bL\98^\82·\82é */
45         io_cli();                                       /* \8b\96\89Â\83t\83\89\83O\82ð0\82É\82µ\82Ä\8a\84\82è\8d\9e\82Ý\8bÖ\8e~\82É\82·\82é */
46         io_out8(0x03c8, start);
47         for (i = start; i <= end; i++) {
48                 io_out8(0x03c9, rgb[0] / 4);
49                 io_out8(0x03c9, rgb[1] / 4);
50                 io_out8(0x03c9, rgb[2] / 4);
51                 rgb += 3;
52         }
53         io_store_eflags(eflags);        /* \8a\84\82è\8d\9e\82Ý\8b\96\89Â\83t\83\89\83O\82ð\8c³\82É\96ß\82· */
54         return;
55 }
56
57 void boxfill8(unsigned char *vram, int xsize, unsigned char c, int x0, int y0, int x1, int y1)
58 {
59         int x, y;
60         for (y = y0; y <= y1; y++) {
61                 for (x = x0; x <= x1; x++)
62                         vram[y * xsize + x] = c;
63         }
64         return;
65 }
66
67 void init_screen8(char *vram, int x, int y)
68 {
69         boxfill8(vram, x, COL8_008484,  0,     0,      x -  1, y - 29);
70         boxfill8(vram, x, COL8_C6C6C6,  0,     y - 28, x -  1, y - 28);
71         boxfill8(vram, x, COL8_FFFFFF,  0,     y - 27, x -  1, y - 27);
72         boxfill8(vram, x, COL8_C6C6C6,  0,     y - 26, x -  1, y -  1);
73
74         boxfill8(vram, x, COL8_FFFFFF,  3,     y - 24, 59,     y - 24);
75         boxfill8(vram, x, COL8_FFFFFF,  2,     y - 24,  2,     y -  4);
76         boxfill8(vram, x, COL8_848484,  3,     y -  4, 59,     y -  4);
77         boxfill8(vram, x, COL8_848484, 59,     y - 23, 59,     y -  5);
78         boxfill8(vram, x, COL8_000000,  2,     y -  3, 59,     y -  3);
79         boxfill8(vram, x, COL8_000000, 60,     y - 24, 60,     y -  3);
80
81         boxfill8(vram, x, COL8_848484, x - 47, y - 24, x -  4, y - 24);
82         boxfill8(vram, x, COL8_848484, x - 47, y - 23, x - 47, y -  4);
83         boxfill8(vram, x, COL8_FFFFFF, x - 47, y -  3, x -  4, y -  3);
84         boxfill8(vram, x, COL8_FFFFFF, x -  3, y - 24, x -  3, y -  3);
85         return;
86 }
87
88 void putfont8(char *vram, int xsize, int x, int y, char c, char *font)
89 {
90         int i;
91         char *p, d /* data */;
92         for (i = 0; i < 16; i++) {
93                 p = vram + (y + i) * xsize + x;
94                 d = font[i];
95                 if ((d & 0x80) != 0) { p[0] = c; }
96                 if ((d & 0x40) != 0) { p[1] = c; }
97                 if ((d & 0x20) != 0) { p[2] = c; }
98                 if ((d & 0x10) != 0) { p[3] = c; }
99                 if ((d & 0x08) != 0) { p[4] = c; }
100                 if ((d & 0x04) != 0) { p[5] = c; }
101                 if ((d & 0x02) != 0) { p[6] = c; }
102                 if ((d & 0x01) != 0) { p[7] = c; }
103         }
104         return;
105 }
106
107 void putfonts8_asc(char *vram, int xsize, int x, int y, char c, unsigned char *s)
108 {
109         extern char hankaku[4096];
110         struct TASK *task = task_now();
111         char *nihongo = (char *) *((int *) 0x0fe8), *font;
112         int k, t;
113
114         if (task->langmode == 0) {
115                 for (; *s != 0x00; s++) {
116                         putfont8(vram, xsize, x, y, c, hankaku + *s * 16);
117                         x += 8;
118                 }
119         }
120         if (task->langmode == 1) {
121                 for (; *s != 0x00; s++) {
122                         if (task->langbyte1 == 0) {
123                                 if ((0x81 <= *s && *s <= 0x9f) || (0xe0 <= *s && *s <= 0xfc)) {
124                                         task->langbyte1 = *s;
125                                 } else {
126                                         putfont8(vram, xsize, x, y, c, nihongo + *s * 16);
127                                 }
128                         } else {
129                                 if (0x81 <= task->langbyte1 && task->langbyte1 <= 0x9f) {
130                                         k = (task->langbyte1 - 0x81) * 2;
131                                 } else {
132                                         k = (task->langbyte1 - 0xe0) * 2 + 62;
133                                 }
134                                 if (0x40 <= *s && *s <= 0x7e) {
135                                         t = *s - 0x40;
136                                 } else if (0x80 <= *s && *s <= 0x9e) {
137                                         t = *s - 0x80 + 63;
138                                 } else {
139                                         t = *s - 0x9f;
140                                         k++;
141                                 }
142                                 task->langbyte1 = 0;
143                                 font = nihongo + 256 * 16 + (k * 94 + t) * 32;
144                                 putfont8(vram, xsize, x - 8, y, c, font     );  /* \8d\94¼\95ª */
145                                 putfont8(vram, xsize, x    , y, c, font + 16);  /* \89E\94¼\95ª */
146                         }
147                         x += 8;
148                 }
149         }
150         if (task->langmode == 2) {
151                 for (; *s != 0x00; s++) {
152                         if (task->langbyte1 == 0) {
153                                 if (0x81 <= *s && *s <= 0xfe) {
154                                         task->langbyte1 = *s;
155                                 } else {
156                                         putfont8(vram, xsize, x, y, c, nihongo + *s * 16);
157                                 }
158                         } else {
159                                 k = task->langbyte1 - 0xa1;
160                                 t = *s - 0xa1;
161                                 task->langbyte1 = 0;
162                                 font = nihongo + 256 * 16 + (k * 94 + t) * 32;
163                                 putfont8(vram, xsize, x - 8, y, c, font     );  /* \8d\94¼\95ª */
164                                 putfont8(vram, xsize, x    , y, c, font + 16);  /* \89E\94¼\95ª */
165                         }
166                         x += 8;
167                 }
168         }
169         return;
170 }
171
172 void init_mouse_cursor8(char *mouse, char bc)
173 /* \83}\83E\83X\83J\81[\83\\83\8b\82ð\8f\80\94õ\81i16x16\81j */
174 {
175         static char cursor[16][16] = {
176                 "**************..",
177                 "*OOOOOOOOOOO*...",
178                 "*OOOOOOOOOO*....",
179                 "*OOOOOOOOO*.....",
180                 "*OOOOOOOO*......",
181                 "*OOOOOOO*.......",
182                 "*OOOOOOO*.......",
183                 "*OOOOOOOO*......",
184                 "*OOOO**OOO*.....",
185                 "*OOO*..*OOO*....",
186                 "*OO*....*OOO*...",
187                 "*O*......*OOO*..",
188                 "**........*OOO*.",
189                 "*..........*OOO*",
190                 "............*OO*",
191                 ".............***"
192         };
193         int x, y;
194
195         for (y = 0; y < 16; y++) {
196                 for (x = 0; x < 16; x++) {
197                         if (cursor[y][x] == '*') {
198                                 mouse[y * 16 + x] = COL8_000000;
199                         }
200                         if (cursor[y][x] == 'O') {
201                                 mouse[y * 16 + x] = COL8_FFFFFF;
202                         }
203                         if (cursor[y][x] == '.') {
204                                 mouse[y * 16 + x] = bc;
205                         }
206                 }
207         }
208         return;
209 }
210
211 void putblock8_8(char *vram, int vxsize, int pxsize,
212         int pysize, int px0, int py0, char *buf, int bxsize)
213 {
214         int x, y;
215         for (y = 0; y < pysize; y++) {
216                 for (x = 0; x < pxsize; x++) {
217                         vram[(py0 + y) * vxsize + (px0 + x)] = buf[y * bxsize + x];
218                 }
219         }
220         return;
221 }