OSDN Git Service

svn rev.329より移動。
[chnosproject/CHNOSProject.git] / CHNOSProject / chnos / tolset_chn_000 / chnos_008 / chnos / api.c
1 \r
2 #include "core.h"\r
3 \r
4 uint hrb_api(uint edi, uint esi, uint ebp, uint esp, uint ebx, uint edx, uint ecx, uint eax)\r
5 {\r
6         UI_Task *task = task_now();\r
7         UI_Console *cons;\r
8         UI_Window *win;\r
9         uchar s[64];\r
10         uchar *app_s;\r
11         uint i;\r
12 \r
13         uint *reg = &eax + 1;\r
14 \r
15         for(i = 0; i < MAX_CONSOLES; i++){\r
16                 if(system.ui.console.consoles[i].task == task)break;\r
17         }\r
18         cons = &system.ui.console.consoles[i];\r
19 \r
20         if(edx == 1){\r
21                 cons_put_char(cons, (uchar)(eax & 0xff));\r
22         } else if(edx == 2){\r
23                 cons_put_str(cons, (uchar *)(ebx + cons->app_ds_base));\r
24         } else if(edx == 4){\r
25                 return (uint)&(task->tss.esp0);\r
26         } else if(edx == 5){\r
27                 win = make_window_app_compatible_hrb((uchar *)(ecx + cons->app_ds_base), esi, edi, 200, 100, sheet_get_topheight(), true, sys_memman_alloc(esi * edi * (system.data.info.vesa.BitsPerPixel >> 3)), task);\r
28                 win->app_buf = (uchar *)(ebx + cons->app_ds_base);\r
29                 win->app_buf_bits = 8;\r
30                 boxfill8(win->app_buf, esi, COL8_FFFFFF, 0, 0, esi, edi);\r
31                 reg[7] = GetWindowNumber(win);\r
32                 sprintf(s, "winID = %u\n", reg[7]);\r
33                 cons_put_str(cons, s);\r
34         } else if(edx == 6){\r
35                 i = esi;\r
36                 app_s = (uchar *)(ebp + cons->app_ds_base);\r
37                 if(GetWindowInfo(ebx)->app_buf_bits == 8){\r
38                         for (; *app_s != 0x00; app_s++) {\r
39                                 putfont8(GetWindowInfo(ebx)->app_buf, GetWindowInfo(ebx)->winxsize, esi, edi, eax, hankaku + (*app_s * 16));\r
40                                 esi += 8;\r
41                         }\r
42                 } else if(GetWindowInfo(ebx)->app_buf_bits == 16){\r
43                         for (; *app_s != 0x00; app_s++) {\r
44                                 putfont16(GetWindowInfo(ebx)->app_buf, GetWindowInfo(ebx)->winxsize, esi, edi, eax, hankaku + (*app_s * 16));\r
45                                 esi += 8;\r
46                         }\r
47                 } else if(GetWindowInfo(ebx)->app_buf_bits == 32){\r
48                         for (; *app_s != 0x00; app_s++) {\r
49                                 putfont32(GetWindowInfo(ebx)->app_buf, GetWindowInfo(ebx)->winxsize, esi, edi, eax, hankaku + (*app_s * 16));\r
50                                 esi += 8;\r
51                         }\r
52                 }\r
53                 if((ebx & 1) == 0){\r
54                         putblock_i_convert(GetWindowInfo(ebx)->buf, GetWindowInfo(ebx)->winxsize, i, edi, esi, edi + 16, GetWindowInfo(ebx)->app_buf, system.data.info.vesa.BitsPerPixel, GetWindowInfo(ebx)->app_buf_bits);\r
55                         sheet_refresh(GetWindowInfo(ebx)->win, i, edi, esi, edi + 16);\r
56                 }\r
57         } else if(edx == 7){\r
58                 boxfill_bpp(GetWindowInfo(ebx)->app_buf, GetWindowInfo(ebx)->winxsize, ebp, eax, ecx, esi, edi, GetWindowInfo(ebx)->app_buf_bits);\r
59                 if((ebx & 1) == 0){\r
60                         putblock_i_convert(GetWindowInfo(ebx)->buf, GetWindowInfo(ebx)->winxsize, eax, ecx, esi, edi, GetWindowInfo(ebx)->app_buf, system.data.info.vesa.BitsPerPixel, GetWindowInfo(ebx)->app_buf_bits);\r
61                         sheet_refresh(GetWindowInfo(ebx)->win, eax, ecx, esi, edi);\r
62                 }\r
63         } else if(edx == 8){\r
64                 memman_init((IO_MemoryControl *)(ebx + cons->app_ds_base));\r
65                 ecx &= 0xfffffff0;\r
66                 memman_free((IO_MemoryControl *)(ebx + cons->app_ds_base), (uchar *)eax, ecx);\r
67         } else if(edx == 9){\r
68                 ecx = (ecx + 0x0f) & 0xfffffff0;\r
69                 reg[7] = (uint)memman_alloc((IO_MemoryControl *)(ebx + cons->app_ds_base), ecx);\r
70         } else if(edx == 10){\r
71                 ecx = (ecx + 0x0f) & 0xfffffff0;\r
72                 memman_free((IO_MemoryControl *)(ebx + cons->app_ds_base), (uchar *)eax, ecx);\r
73         } else if(edx == 11){\r
74                 point_bpp(GetWindowInfo(ebx)->app_buf, esi, edi, eax, GetWindowInfo(ebx)->winxsize, GetWindowInfo(ebx)->app_buf_bits);\r
75                 if((ebx & 1) == 0){\r
76                         putblock_i_convert(GetWindowInfo(ebx)->buf, GetWindowInfo(ebx)->winxsize, esi, edi, esi + 1, edi + 1, GetWindowInfo(ebx)->app_buf, system.data.info.vesa.BitsPerPixel, GetWindowInfo(ebx)->app_buf_bits);\r
77                         sheet_refresh(GetWindowInfo(ebx)->win, esi, edi, esi + 1, edi + 1);\r
78                 }\r
79         } else if(edx == 12){\r
80                 putblock_i_convert(GetWindowInfo(ebx)->buf, GetWindowInfo(ebx)->winxsize, eax, ecx, esi, edi, GetWindowInfo(ebx)->app_buf, system.data.info.vesa.BitsPerPixel, GetWindowInfo(ebx)->app_buf_bits);\r
81                 sheet_refresh(GetWindowInfo(ebx)->win, eax, ecx, esi, edi);\r
82         } else if(edx == 13){\r
83                 line_bpp(GetWindowInfo(ebx)->app_buf, GetWindowInfo(ebx)->winxsize, eax, ecx, esi, edi, ebp, GetWindowInfo(ebx)->app_buf_bits);\r
84                 if((ebx & 1) == 0){\r
85                         putblock_i_convert(GetWindowInfo(ebx)->buf, GetWindowInfo(ebx)->winxsize, eax, ecx, esi, edi, GetWindowInfo(ebx)->app_buf, system.data.info.vesa.BitsPerPixel, GetWindowInfo(ebx)->app_buf_bits);\r
86                         sheet_refresh(GetWindowInfo(ebx)->win, eax, ecx, esi, edi);\r
87                 }\r
88         } else if(edx == 14){\r
89                 sys_memman_free(GetWindowInfo(ebx)->buf, GetWindowInfo(ebx)->winxsize * GetWindowInfo(ebx)->winysize * (system.data.info.vesa.BitsPerPixel >> 3));\r
90                 free_window_app(GetWindowInfo(ebx));\r
91         } else if(edx == 15){\r
92                 for(;;){\r
93                         io_cli();\r
94                         if(fifo32_status(&cons->task->fifo) == 0){\r
95                                 if(eax == 0){\r
96                                         io_sti();\r
97                                         reg[7] = 0xFFFFFFFF;\r
98                                         return 0;\r
99                                 } else{\r
100                                         task_sleep(cons->task);\r
101                                 }\r
102                         } else {\r
103                                 i = fifo32_get(&cons->task->fifo);\r
104                                 io_sti();\r
105                                 if(i == 1){\r
106                                         if(cons->cursor_on){\r
107                                                 if(cons->cursor_state){\r
108                                                         cons->cursor_c = CONSOLE_COLOR_CHAR;\r
109                                                         cons->cursor_state = false;\r
110                                                 } else{\r
111                                                         cons->cursor_c = CONSOLE_COLOR_BACKGROUND;\r
112                                                         cons->cursor_state = true;\r
113                                                 }\r
114                                                 boxfill_win(cons->win, cons->cursor_c, cons->cursor.x, cons->cursor.y, cons->cursor.x + 8, cons->cursor.y +16);\r
115                                         }\r
116                                         timer_settime(cons->timer, 50);\r
117                                 } else if(i == CONSOLE_FIFO_CURSOR_START){\r
118                                         cons->cursor_on = true;\r
119                                 } else if(i == CONSOLE_FIFO_CURSOR_STOP){\r
120                                         cons->cursor_on = false;\r
121                                         boxfill_win(cons->win, CONSOLE_COLOR_BACKGROUND, cons->cursor.x, cons->cursor.y, cons->cursor.x + 8, cons->cursor.y +16);\r
122                                 } else if(CONSOLE_FIFO_START_KEYB <= i && i <= CONSOLE_FIFO_START_KEYB + DATA_BYTE){\r
123                                         i -= CONSOLE_FIFO_START_KEYB;\r
124                                                 reg[7] = i;\r
125                                                 return 0;\r
126                                 }\r
127                         }\r
128                 }\r
129         } else {\r
130                 cons_put_str(cons, "Unknown api number.");\r
131                 return (uint)&(task->tss.esp0);\r
132         }\r
133         return 0;\r
134 }\r
135 \r
136 uint GetWindowNumber(UI_Window *win)\r
137 {\r
138         return (uint)((win - system.ui.window.ctrl.winfos) << 1);\r
139 }\r
140 \r
141 UI_Window *GetWindowInfo(uint n)\r
142 {\r
143         return &system.ui.window.ctrl.winfos[n >> 1];\r
144 }\r