• R/O
  • SSH
  • HTTPS

haribote: Commit


Commit MetaInfo

Revision183 (tree)
Time2007-08-04 15:13:43
Authorbayside

Log Message

refactoring

Change Summary

Incremental Difference

--- haribote/trunk/bayos_exp/dsctbl.cpp (revision 182)
+++ haribote/trunk/bayos_exp/dsctbl.cpp (nonexistent)
@@ -1,61 +0,0 @@
1-/* GDTやIDTなどの、 descriptor table 関係 */
2-
3-#include "bootpack.h"
4-
5-void Descriptor::init(void)
6-{
7- SegmentDescriptor *gdt = (SegmentDescriptor *) ADR_GDT;
8- GateDescriptor *idt = (GateDescriptor *) ADR_IDT;
9- int i;
10-
11- /* GDTの初期化 */
12- for (i = 0; i <= LIMIT_GDT / 8; i++) {
13- SegmentDescriptor::set(gdt + i, 0, 0, 0);
14- }
15- SegmentDescriptor::set(gdt + 1, 0xffffffff, 0x00000000, AR_DATA32_RW);
16- SegmentDescriptor::set(gdt + 2, LIMIT_BOTPAK, ADR_BOTPAK, AR_CODE32_ER);
17- load_gdtr(LIMIT_GDT, ADR_GDT);
18-
19- /* IDTの初期化 */
20- for (i = 0; i <= LIMIT_IDT / 8; i++) {
21- GateDescriptor::set(idt + i, 0, 0, 0);
22- }
23- load_idtr(LIMIT_IDT, ADR_IDT);
24-
25- /* IDTの設定 */
26- GateDescriptor::set(idt + 0x07, (int) asm_inthandler07, 2 * 8, AR_INTGATE32);
27- GateDescriptor::set(idt + 0x0c, (int) asm_inthandler0c, 2 * 8, AR_INTGATE32);
28- GateDescriptor::set(idt + 0x0d, (int) asm_inthandler0d, 2 * 8, AR_INTGATE32);
29- GateDescriptor::set(idt + 0x20, (int) asm_inthandler20, 2 * 8, AR_INTGATE32);
30- GateDescriptor::set(idt + 0x21, (int) asm_inthandler21, 2 * 8, AR_INTGATE32);
31- GateDescriptor::set(idt + 0x27, (int) asm_inthandler27, 2 * 8, AR_INTGATE32);
32- GateDescriptor::set(idt + 0x2c, (int) asm_inthandler2c, 2 * 8, AR_INTGATE32);
33- GateDescriptor::set(idt + 0x40, (int) asm_hrb_api, 2 * 8, AR_INTGATE32 + 0x60);
34-
35- return;
36-}
37-
38-void SegmentDescriptor::set(SegmentDescriptor *sd, unsigned int limit, int base, int ar)
39-{
40- if (limit > 0xfffff) {
41- ar |= 0x8000; /* G_bit = 1 */
42- limit /= 0x1000;
43- }
44- sd->limit_low = limit & 0xffff;
45- sd->base_low = base & 0xffff;
46- sd->base_mid = (base >> 16) & 0xff;
47- sd->access_right = ar & 0xff;
48- sd->limit_high = ((limit >> 16) & 0x0f) | ((ar >> 8) & 0xf0);
49- sd->base_high = (base >> 24) & 0xff;
50- return;
51-}
52-
53-void GateDescriptor::set(GateDescriptor *gd, int offset, int selector, int ar)
54-{
55- gd->offset_low = offset & 0xffff;
56- gd->selector = selector;
57- gd->dw_count = (ar >> 8) & 0xff;
58- gd->access_right = ar & 0xff;
59- gd->offset_high = (offset >> 16) & 0xffff;
60- return;
61-}
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
--- haribote/trunk/bayos_exp/fifo.cpp (revision 182)
+++ haribote/trunk/bayos_exp/fifo.cpp (nonexistent)
@@ -1,63 +0,0 @@
1-/* FIFOライブラリ */
2-
3-#include "bootpack.h"
4-
5-#define FLAGS_OVERRUN 0x0001
6-
7-void Queue::init(Queue *fifo, int size, int *buf, Task *task)
8-/* FIFOバッファの初期化 */
9-{
10- fifo->size = size;
11- fifo->buf = buf;
12- fifo->free = size; /* 空き */
13- fifo->flags = 0;
14- fifo->p = 0; /* 書き込み位置 */
15- fifo->q = 0; /* 読み込み位置 */
16- fifo->task = task; /* データが入ったときに起こすタスク */
17- return;
18-}
19-
20-int Queue::push(Queue *fifo, int data)
21-/* FIFOへデータを送り込んで蓄える */
22-{
23- if (fifo->free == 0) {
24- /* 空きがなくてあふれた */
25- fifo->flags |= FLAGS_OVERRUN;
26- return -1;
27- }
28- fifo->buf[fifo->p] = data;
29- fifo->p++;
30- if (fifo->p == fifo->size) {
31- fifo->p = 0;
32- }
33- fifo->free--;
34- if (fifo->task != 0) {
35- if (fifo->task->flags != 2) { /* タスクが寝ていたら */
36- Task::run(fifo->task, -1, 0); /* 起こしてあげる */
37- }
38- }
39- return 0;
40-}
41-
42-int Queue::pop(Queue *fifo)
43-/* FIFOからデータを一つとってくる */
44-{
45- int data;
46- if (fifo->free == fifo->size) {
47- /* バッファが空っぽのときは、とりあえず-1が返される */
48- return -1;
49- }
50- data = fifo->buf[fifo->q];
51- fifo->q++;
52- if (fifo->q == fifo->size) {
53- fifo->q = 0;
54- }
55- fifo->free++;
56- return data;
57-}
58-
59-int Queue::status(Queue *fifo)
60-/* どのくらいデータが溜まっているかを報告する */
61-{
62- return fifo->size - fifo->free;
63-}
Deleted: svn:executable
## -1 +0,0 ##
-*
\ No newline at end of property
--- haribote/trunk/bayos_exp/gui.cpp (nonexistent)
+++ haribote/trunk/bayos_exp/gui.cpp (revision 183)
@@ -0,0 +1,239 @@
1+#include "bootpack.h"
2+
3+#define BLACK 0x0000
4+#define LIGHT_RED 0xf800
5+#define LIGHT_GREEN 0x07e0
6+#define LIGHT_YELLOW 0xffe0
7+#define LIGHT_BLUE 0x001f
8+#define LIGHT_PURPLE 0xf81f
9+#define LIGHT_AQUA 0x07ff
10+#define WHITE 0xffff
11+#define LIGHT_GRAY 0xc618
12+#define DARK_RED 0x8000
13+#define DARK_GREEN 0x0420
14+#define DARK_YELLOW 0x8420
15+#define DARK_BLUE 0x0010
16+#define DARK_PURPLE 0x8010
17+#define DARK_AQUA 0x0410
18+#define DARK_GRAY 0x8410
19+
20+#define FONT_W 6
21+#define FONT_H 12
22+
23+extern unsigned short table_8_565[256];
24+
25+void Gui::drawPixel(Sheet* sheet, int x, int y, unsigned short col)
26+/* 点を打つ */
27+{
28+ int tx = 0;
29+ int ty = 0;
30+ int cw = sheet->bxsize;
31+
32+ sheet->buf[(tx + x) + cw * (ty + y)] = col;
33+}
34+
35+void Gui::drawLine(Sheet* sheet, int x0, int y0, int x1, int y1, unsigned short col)
36+/* 線を引く */
37+{
38+ int tx = 0;
39+ int ty = 0;
40+ int cw = sheet->bxsize;
41+ int dx = (x0 > x1) ? (x0 - x1) : (x1 - x0);
42+ int dy = (y0 > y1) ? (y0 - y1) : (y1 - y0);
43+
44+ if (dx == 0 && dy == 0) {
45+ sheet->buf[(tx + x0) + cw * (ty + y0)] = col;
46+ } else if (dx >= dy) {
47+ if (x0 > x1) {
48+ int tx = x0;
49+ x0 = x1;
50+ x1 = tx;
51+ int ty = y0;
52+ y0 = y1;
53+ y1 = ty;
54+ }
55+ for (int x = x0; x <= x1; x++) {
56+ sheet->buf[(tx + x) + cw * (ty + ((2 * y0 + 2 * (y1 - y0) * (x - x0) / (x1 - x0)) + 1) / 2)] = col;
57+ }
58+ } else {
59+ if (y0 > y1) {
60+ int tx = x0;
61+ x0 = x1;
62+ x1 = tx;
63+ int ty = y0;
64+ y0 = y1;
65+ y1 = ty;
66+ }
67+ for (int y = y0; y <= y1; y++) {
68+ sheet->buf[(tx + (2 * x0 + 2 * (x1 - x0) * (y - y0) / (y1 - y0) + 1) / 2) + cw * (ty + y)] = col;
69+ }
70+ }
71+}
72+
73+void Gui::drawRect(Sheet* sheet, int x, int y, int width, int height, unsigned short col)
74+/* 矩形を描く */
75+{
76+ int tx = 0;
77+ int ty = 0;
78+ int cw = sheet->bxsize;
79+ int xw = x + width - 1;
80+ int yh = y + height - 1;
81+
82+ for (int xx = x; xx <= xw; xx++) {
83+ sheet->buf[(tx + xx) + cw * (ty + y)] = col;
84+ sheet->buf[(tx + xx) + cw * (ty + yh)] = col;
85+ }
86+ for (int yy = y + 1; yy <= yh - 1; yy++) {
87+ sheet->buf[(tx + x) + cw * (ty + yy)] = col;
88+ sheet->buf[(tx + xw) + cw * (ty + yy)] = col;
89+ }
90+}
91+
92+void Gui::fillRect(Sheet* sheet, int x0, int y0, int x1, int y1, unsigned short col)
93+/* 矩形を塗りつぶす */
94+{
95+ int tx = 0;
96+ int ty = 0;
97+ int cw = sheet->bxsize;
98+
99+ for (int y = y0; y < y0 + y1; y++) {
100+ for (int x = x0; x < x0 + x1; x++) {
101+ sheet->buf[(tx + x) + cw * (ty + y)] = col;
102+ }
103+ }
104+}
105+
106+void Gui::drawString(Sheet* sheet, char* title, int x0, int y0, unsigned short col)
107+/* 文字列を描画する */
108+{
109+#if 0
110+ int bw = 0, bh = FONT_H, length = 0;
111+ int sw = sheet != NULL ? sheet->bxsize : 0;
112+ int I = strlen(title);
113+
114+ for (int i = 0; i < I;) {
115+ unsigned short ucs2 = 0;
116+ byte c = title[i] & 0xe0;
117+ if (c < 0x80) {
118+ ucs2 = (unsigned short) title[i];
119+ i++;
120+ } else if (c < 0xe0) {
121+ ucs2 = (unsigned short) title[i] & 0x1f;
122+ i++;
123+ ucs2 = ucs2 << 6;
124+ ucs2 = ucs2 | ((unsigned short) title[i] & 0x3f);
125+ i++;
126+ } else if (c < 0xf0) {
127+ ucs2 = (unsigned short) title[i] & 0x0f;
128+ i++;
129+ ucs2 = ucs2 << 6;
130+ ucs2 = ucs2 | ((unsigned short) title[i] & 0x3f);
131+ i++;
132+ ucs2 = ucs2 << 6;
133+ ucs2 = ucs2 | ((unsigned short) title[i] & 0x3f);
134+ i++;
135+ }
136+
137+ int offset = offsets[ucs2] + 4;
138+ if (offset != 0) {
139+ byte fw = SheetCtl::zenkaku[offset++];
140+ byte fh = SheetCtl::zenkaku[offset++];
141+ if (sw > 0) {
142+ int bit = 1;
143+ for (int y = 0; y < fh; y++) {
144+ for (int x = 0; x < fw; x++) {
145+ if ((SheetCtl::zenkaku[offset] & bit) != 0) {
146+ sheet->buf[(x0 + x + bw) + sw * (y0 + y)] = col;
147+ }
148+ bit <<= 1;
149+ if (bit == 256) {
150+ offset++;
151+ bit = 1;
152+ }
153+ }
154+ }
155+ }
156+ bw += fw;
157+ length++;
158+ }
159+ }
160+#endif
161+}
162+
163+void Gui::drawFrame(Sheet* sheet, char* title)
164+/* 枠を描く */
165+{
166+ int w = sheet->bxsize;
167+ int h = sheet->bysize;
168+
169+ /* 背景塗りつぶし */
170+ fillRect(sheet, 0, 0, w, h, LIGHT_GRAY);
171+
172+ /* 閉じるボタン */
173+ static unsigned char icon_close_data [] = {
174+ 0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x2,
175+ 0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x8,
176+ 0x1,0x0,0x8,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x2,0x0,0x8,
177+ 0x1,0x0,0x2,0x5,0x5,0x3,0x3,0x7,0x7,0x2,0x1,0x0,0x8,
178+ 0x1,0x0,0x2,0x5,0x3,0x3,0x7,0x7,0x2,0x2,0x1,0x0,0x8,
179+ 0x1,0x0,0x2,0x3,0x3,0x7,0x7,0x2,0x2,0x6,0x1,0x0,0x8,
180+ 0x1,0x0,0x2,0x3,0x7,0x7,0x2,0x2,0x6,0x6,0x1,0x0,0x8,
181+ 0x1,0x0,0x2,0x7,0x7,0x2,0x2,0x6,0x6,0x4,0x1,0x0,0x8,
182+ 0x1,0x0,0x2,0x7,0x2,0x2,0x6,0x6,0x4,0x4,0x1,0x0,0x8,
183+ 0x1,0x0,0x2,0x2,0x2,0x6,0x6,0x4,0x4,0x8,0x1,0x0,0x8,
184+ 0x1,0x0,0x2,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x1,0x0,0x8,
185+ 0x1,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x0,0x8,
186+ 0x2,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,0x8,
187+ };
188+ static unsigned short icon_close_pallete [] = {
189+ 0x18c3,
190+ 0x8c71,
191+ 0xce79,
192+ 0xad75,
193+ 0xef7d,
194+ 0x9cf3,
195+ 0xdefb,
196+ 0xbdf7,
197+ 0xffff,
198+ };
199+
200+ for (int y = 0; y < 13; y++) {
201+ for (int x = 0; x < 13; x++) {
202+ sheet->buf[(y + 4) * w + (x + 4)] =
203+ icon_close_pallete[icon_close_data[y * 13 + x]];
204+ }
205+ }
206+
207+ /* 外枠 */
208+ Gui::drawRect(sheet, 0, 0, w, h, BLACK);
209+
210+ /* 内枠 */
211+ Gui::drawRect(sheet, 5, 21, w - 10, h - 26, BLACK);
212+
213+ /* 縁線 */
214+ Gui::drawLine(sheet, 4, 20, 4, h - 6, DARK_GRAY);
215+ Gui::drawLine(sheet, 4, 20, w - 6, 20, DARK_GRAY);
216+ Gui::drawLine(sheet, w - 5, 21, w - 5, h - 6, WHITE);
217+ Gui::drawLine(sheet, 4, h - 5, w - 5, h - 5, WHITE);
218+ Gui::drawLine(sheet, 1, 1, 1, h - 3, WHITE);
219+ Gui::drawLine(sheet, 1, 1, w - 3, 1, WHITE);
220+ Gui::drawLine(sheet, w - 2, 2, w - 2, h - 2, DARK_GRAY);
221+ Gui::drawLine(sheet, 2, h - 2, w - 3, h - 2, DARK_GRAY);
222+
223+ /* タイトル幅 */
224+ Gui::drawString(0, title, 0, 0, 0);
225+ int L = 100;//SheetCtl::wstrinfo->width + FONT_W;
226+ int W = (w - L) / 2;
227+
228+ /* タイトル線 */
229+ for (int y = 4; y <= 14; y += 2) {
230+ Gui::drawLine(sheet, 21, y, W - 1, y, WHITE);
231+ Gui::drawLine(sheet, 22, y + 1, W, y + 1, DARK_GRAY);
232+ Gui::drawLine(sheet, W + L, y, w - 6, y, WHITE);
233+ Gui::drawLine(sheet, W + L + 1, y + 1, w - 5, y + 1, DARK_GRAY);
234+ }
235+
236+ /* タイトル */
237+ Gui::drawString(sheet, title, W + FONT_W / 2, ((22 - FONT_H) / 2), BLACK);
238+ Gui::drawString(sheet, title, W + FONT_W / 2 + 1, ((22 - FONT_H) / 2), BLACK);
239+}
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
--- haribote/trunk/bayos_exp/queue.cpp (nonexistent)
+++ haribote/trunk/bayos_exp/queue.cpp (revision 183)
@@ -0,0 +1,63 @@
1+/* FIFOライブラリ */
2+
3+#include "bootpack.h"
4+
5+#define FLAGS_OVERRUN 0x0001
6+
7+void Queue::init(Queue *queue, int size, int *buf, Task *task)
8+/* FIFOバッファの初期化 */
9+{
10+ queue->size = size;
11+ queue->buf = buf;
12+ queue->free = size; /* 空き */
13+ queue->flags = 0;
14+ queue->p = 0; /* 書き込み位置 */
15+ queue->q = 0; /* 読み込み位置 */
16+ queue->task = task; /* データが入ったときに起こすタスク */
17+ return;
18+}
19+
20+int Queue::push(Queue *queue, int data)
21+/* FIFOへデータを送り込んで蓄える */
22+{
23+ if (queue->free == 0) {
24+ /* 空きがなくてあふれた */
25+ queue->flags |= FLAGS_OVERRUN;
26+ return -1;
27+ }
28+ queue->buf[queue->p] = data;
29+ queue->p++;
30+ if (queue->p == queue->size) {
31+ queue->p = 0;
32+ }
33+ queue->free--;
34+ if (queue->task != 0) {
35+ if (queue->task->flags != 2) { /* タスクが寝ていたら */
36+ Task::run(queue->task, -1, 0); /* 起こしてあげる */
37+ }
38+ }
39+ return 0;
40+}
41+
42+int Queue::pop(Queue *queue)
43+/* FIFOからデータを一つとってくる */
44+{
45+ int data;
46+ if (queue->free == queue->size) {
47+ /* バッファが空っぽのときは、とりあえず-1が返される */
48+ return -1;
49+ }
50+ data = queue->buf[queue->q];
51+ queue->q++;
52+ if (queue->q == queue->size) {
53+ queue->q = 0;
54+ }
55+ queue->free++;
56+ return data;
57+}
58+
59+int Queue::status(Queue *queue)
60+/* どのくらいデータが溜まっているかを報告する */
61+{
62+ return queue->size - queue->free;
63+}
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
--- haribote/trunk/bayos_exp/descriptor.cpp (nonexistent)
+++ haribote/trunk/bayos_exp/descriptor.cpp (revision 183)
@@ -0,0 +1,61 @@
1+/* GDTやIDTなどの、 descriptor table 関係 */
2+
3+#include "bootpack.h"
4+
5+void Descriptor::init(void)
6+{
7+ SegmentDescriptor *gdt = (SegmentDescriptor *) ADR_GDT;
8+ GateDescriptor *idt = (GateDescriptor *) ADR_IDT;
9+ int i;
10+
11+ /* GDTの初期化 */
12+ for (i = 0; i <= LIMIT_GDT / 8; i++) {
13+ SegmentDescriptor::set(gdt + i, 0, 0, 0);
14+ }
15+ SegmentDescriptor::set(gdt + 1, 0xffffffff, 0x00000000, AR_DATA32_RW);
16+ SegmentDescriptor::set(gdt + 2, LIMIT_BOTPAK, ADR_BOTPAK, AR_CODE32_ER);
17+ load_gdtr(LIMIT_GDT, ADR_GDT);
18+
19+ /* IDTの初期化 */
20+ for (i = 0; i <= LIMIT_IDT / 8; i++) {
21+ GateDescriptor::set(idt + i, 0, 0, 0);
22+ }
23+ load_idtr(LIMIT_IDT, ADR_IDT);
24+
25+ /* IDTの設定 */
26+ GateDescriptor::set(idt + 0x07, (int) asm_inthandler07, 2 * 8, AR_INTGATE32);
27+ GateDescriptor::set(idt + 0x0c, (int) asm_inthandler0c, 2 * 8, AR_INTGATE32);
28+ GateDescriptor::set(idt + 0x0d, (int) asm_inthandler0d, 2 * 8, AR_INTGATE32);
29+ GateDescriptor::set(idt + 0x20, (int) asm_inthandler20, 2 * 8, AR_INTGATE32);
30+ GateDescriptor::set(idt + 0x21, (int) asm_inthandler21, 2 * 8, AR_INTGATE32);
31+ GateDescriptor::set(idt + 0x27, (int) asm_inthandler27, 2 * 8, AR_INTGATE32);
32+ GateDescriptor::set(idt + 0x2c, (int) asm_inthandler2c, 2 * 8, AR_INTGATE32);
33+ GateDescriptor::set(idt + 0x40, (int) asm_hrb_api, 2 * 8, AR_INTGATE32 + 0x60);
34+
35+ return;
36+}
37+
38+void SegmentDescriptor::set(SegmentDescriptor *sd, unsigned int limit, int base, int ar)
39+{
40+ if (limit > 0xfffff) {
41+ ar |= 0x8000; /* G_bit = 1 */
42+ limit /= 0x1000;
43+ }
44+ sd->limit_low = limit & 0xffff;
45+ sd->base_low = base & 0xffff;
46+ sd->base_mid = (base >> 16) & 0xff;
47+ sd->access_right = ar & 0xff;
48+ sd->limit_high = ((limit >> 16) & 0x0f) | ((ar >> 8) & 0xf0);
49+ sd->base_high = (base >> 24) & 0xff;
50+ return;
51+}
52+
53+void GateDescriptor::set(GateDescriptor *gd, int offset, int selector, int ar)
54+{
55+ gd->offset_low = offset & 0xffff;
56+ gd->selector = selector;
57+ gd->dw_count = (ar >> 8) & 0xff;
58+ gd->access_right = ar & 0xff;
59+ gd->offset_high = (offset >> 16) & 0xffff;
60+ return;
61+}
Added: svn:executable
## -0,0 +1 ##
+*
\ No newline at end of property
Show on old repository browser