OSDN Git Service

HeavyOSECPUMainの各変数名を適切なものへ変更。
[heavyosecpu/HeavyOSECPU.git] / screen.c
1 #include "osecpu.h"
2
3 void putOsaskChar(int c, HOSECPU_RuntimeEnvironment *r)
4 {
5         if (0x10 <= c && c <= 0x1f){
6                 c = "0123456789ABCDEF"[c & 0x0f];
7         }
8         putchar(c);
9         r->lastConsoleChar = c;
10         return;
11 }
12
13 void checkString(HOSECPU_RuntimeEnvironment *r, int rxx, int pxx)
14 {
15         char c = 0;
16         if (r->preg[pxx].typ != 0x03){
17                 c = 1;
18         }
19         if (r->preg[pxx].p < r->preg[pxx].p0){
20                 c = 1;
21         }
22         if (r->ireg[rxx] < 0){
23                 c = 1;
24         }
25         if (r->preg[pxx].p + r->ireg[rxx] > r->preg[pxx].p1){
26                 c = 1;
27         }
28         if (c != 0){
29                 (*(r->errHndl))(r);
30         }
31         return;
32 }
33
34 int loadColor(HOSECPU_RuntimeEnvironment *r, int rxx)
35 {
36         int c, m, rr, gg, bb;
37         c = r->ireg[rxx];
38         m = r->ireg[0x31] & 0x0c;
39         if (m == 0x04) {
40                 if (c < -1 || c > 7){
41                         (*(r->errHndl))(r);
42                 }
43                 c = iColor1[c & 0x07];
44         }
45         if (m == 0x08) {
46                 // 00, 24, 48, 6d, 91, b6, da, ff
47                 if (c < 0 || c >= (1 << 9)){
48                         (*(r->errHndl))(r);
49                 }
50                 rr = (c >> 6) & 0x07;
51                 gg = (c >> 3) & 0x07;
52                 bb = c & 0x07;
53                 rr = (rr * 255) / 7;
54                 gg = (gg * 255) / 7;
55                 bb = (bb * 255) / 7;
56                 c = rr << 16 | gg << 8 | bb;
57         }
58         if (m == 0x0c) {
59                 // 00, 08, 10, 18, 20, 29, 31, 39,
60                 // 41, 4a, 52, 5a, 62, 6a, 73, 7b,
61                 // 83, 8b, 94, 9c, a4, ac, b4, bd,
62                 // c5, cd, d5, de, e6, ee, f6, ff
63                 if (c < 0 || c >= (1 << 15)){
64                         (*(r->errHndl))(r);
65                 }
66                 rr = (c >> 10) & 0x1f;
67                 gg = (c >> 5) & 0x1f;
68                 bb = c & 0x1f;
69                 rr = (rr * 255) / 31;
70                 gg = (gg * 255) / 31;
71                 bb = (bb * 255) / 31;
72                 c = rr << 16 | gg << 8 | bb;
73         }
74         return c;
75 }
76
77 void checkRect(HOSECPU_RuntimeEnvironment *r, int rxx)
78 {
79         char c = 0;
80         int i;
81         if (r->ireg[rxx + 0] <= 0 || r->ireg[rxx + 0] > mainWindow.xsize){
82                 c = 1;
83         }
84         if (r->ireg[rxx + 1] <= 0 || r->ireg[rxx + 1] > mainWindow.ysize){
85                 c = 1;
86         }
87         if (r->ireg[rxx + 2] < 0 || r->ireg[rxx + 2] >= mainWindow.xsize){
88                 c = 1;
89         }
90         if (r->ireg[rxx + 3] < 0 || r->ireg[rxx + 3] >= mainWindow.ysize){
91                 c = 1;
92         }
93         i = r->ireg[rxx + 2] + r->ireg[rxx + 0];
94         if (i <= 0 || i > mainWindow.xsize){
95                 c = 1;
96         }
97         i = r->ireg[rxx + 1] + r->ireg[rxx + 3];
98         if (i <= 0 || i > mainWindow.ysize){
99                 c = 1;
100         }
101         if (c != 0){
102                 (*(r->errHndl))(r);
103         }
104         return;
105 }