• R/O
  • HTTP
  • SSH
  • HTTPS

HeavyOSECPU: Commit


Commit MetaInfo

Revisióndc219dc26bb29772407f674143fe486ab0d2e844 (tree)
Tiempo2014-03-12 18:22:08
Autorttwilb <ttwilb@user...>
Commiterttwilb

Log Message

インデントをタブに統一

Cambiar Resumen

Diferencia incremental

--- a/comlib.c
+++ b/comlib.c
@@ -8,8 +8,8 @@ struct ComLib_Str {
88
99 int ComLib_getBit(struct ComLib_Str *s)
1010 {
11- //ビットを一つずつ取り出す
12- if (s->bitBufLen == 0) {
11+ //ビットを一つずつ取り出す
12+ if (s->bitBufLen == 0) {
1313 s->bitBuf = s->p[0] | s->p[1] << 8;
1414 s->p += 2;
1515 s->bitBufLen = 16;
@@ -20,14 +20,14 @@ int ComLib_getBit(struct ComLib_Str *s)
2020
2121 int ComLib_getTmpBit(struct ComLib_Str *s)
2222 {
23- //次のビットをtmpの一番下のビットに押し込んで、その次のビットを返す
23+ //次のビットをtmpの一番下のビットに押し込んで、その次のビットを返す
2424 s->tmp = (s->tmp << 1 | ComLib_getBit(s)) & 0xffff;
2525 return ComLib_getBit(s);
2626 }
2727
2828 unsigned char *ComLib_main(const unsigned char *p, unsigned char *q)
2929 {
30- //hh4デコーダー?
30+ //hh4デコーダー?
3131 struct ComLib_Str s;
3232 int i, dis = 0;
3333 dis |= -1;
@@ -39,19 +39,19 @@ l0:
3939 l1:
4040 i = ComLib_getBit(&s);
4141 if (i != 0){
42- //4bit?
43- goto l0;
44- }
42+ //4bit?
43+ goto l0;
44+ }
4545 s.tmp = 1;
4646 do {
4747 i = ComLib_getTmpBit(&s);
4848 if (s.tmp == 0){
49- goto fin;
50- }
49+ goto fin;
50+ }
5151 } while (i == 0);
5252 if (s.tmp >= 3){
5353 dis = ~((s.tmp - 3) << 8 | *s.p++);
54- }
54+ }
5555 s.tmp &= 0;
5656 i = ComLib_getTmpBit(&s);
5757 s.tmp = s.tmp << 1 | i;
@@ -64,11 +64,11 @@ l1:
6464 }
6565 s.tmp++;
6666 if (dis < -0xd00){
67- s.tmp++;
68- }
67+ s.tmp++;
68+ }
6969 for (i = 0; i < s.tmp; i++){
7070 q[i] = q[i + dis];
71- }
71+ }
7272 q += s.tmp;
7373 goto l1;
7474 fin:
--- a/dpndenv.c
+++ b/dpndenv.c
@@ -19,9 +19,9 @@ NSApplication* app;
1919
2020 @interface OSECPUView : NSView
2121 {
22- unsigned char *_buf;
23- int _sx;
24- int _sy;
22+ unsigned char *_buf;
23+ int _sx;
24+ int _sy;
2525 CGContextRef _context;
2626 }
2727
@@ -32,34 +32,34 @@ NSApplication* app;
3232 @implementation OSECPUView
3333 - (id)initWithFrame:(NSRect)frameRect buf:(unsigned char *)buf sx:(int)sx sy:(int)sy
3434 {
35- self = [super initWithFrame:frameRect];
36- if (self) {
37- _buf = buf;
38- _sx = sx;
39- _sy = sy;
40- }
41- return self;
35+ self = [super initWithFrame:frameRect];
36+ if (self) {
37+ _buf = buf;
38+ _sx = sx;
39+ _sy = sy;
40+ }
41+ return self;
4242 }
4343
4444 - (void)drawRect:(NSRect)rect {
45- CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
46- _context = CGBitmapContextCreate (_buf, _sx, _sy, 8, 4 * _sx, colorSpace, (kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst));
47- CGImageRef image = CGBitmapContextCreateImage(_context);
48- CGContextRef currentContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
49- CGContextDrawImage(currentContext, NSRectToCGRect(rect), image);
50-
51- CFRelease(colorSpace);
52- CFRelease(image);
45+ CGColorSpaceRef colorSpace = CGColorSpaceCreateDeviceRGB();
46+ _context = CGBitmapContextCreate (_buf, _sx, _sy, 8, 4 * _sx, colorSpace, (kCGBitmapByteOrder32Little | kCGImageAlphaNoneSkipFirst));
47+ CGImageRef image = CGBitmapContextCreateImage(_context);
48+ CGContextRef currentContext = (CGContextRef)[[NSGraphicsContext currentContext] graphicsPort];
49+ CGContextDrawImage(currentContext, NSRectToCGRect(rect), image);
50+
51+ CFRelease(colorSpace);
52+ CFRelease(image);
5353 }
5454
5555 @end
5656
5757 @interface Main : NSObject<NSWindowDelegate>
5858 {
59- int argc;
60- const unsigned char **argv;
61- char *winClosed;
62- OSECPUView *_view;
59+ int argc;
60+ const unsigned char **argv;
61+ char *winClosed;
62+ OSECPUView *_view;
6363 }
6464
6565 - (void)runApp;
@@ -72,29 +72,29 @@ NSApplication* app;
7272 @implementation Main
7373 - (void)runApp
7474 {
75- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
76- HeavyOSECPUMain(argc, (char **)argv);
77- [NSApp terminate:self];
75+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
76+ HeavyOSECPUMain(argc, (char **)argv);
77+ [NSApp terminate:self];
7878 [pool release];
7979 }
8080
8181 - (void)createThread : (int)_argc args:(const unsigned char **)_argv
8282 {
83- argc = _argc;
84- argv = _argv;
85- NSThread *thread = [[[NSThread alloc] initWithTarget:self selector:@selector(runApp) object:nil] autorelease];
86- [thread start];
83+ argc = _argc;
84+ argv = _argv;
85+ NSThread *thread = [[[NSThread alloc] initWithTarget:self selector:@selector(runApp) object:nil] autorelease];
86+ [thread start];
8787 }
8888
8989 - (BOOL)windowShouldClose:(id)sender
9090 {
91- *winClosed = 1;
92- return YES;
91+ *winClosed = 1;
92+ return YES;
9393 }
9494
9595 - (void)openWin:(unsigned char *)buf sx:(int)sx sy:(int) sy winClosed:(char *)_winClosed
9696 {
97-
97+
9898 NSWindow* window = [[NSWindow alloc] initWithContentRect: NSMakeRect(0, 0, sx, sy) styleMask: NSTitledWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask backing: NSBackingStoreBuffered defer: NO];
9999 [window setTitle: @"osecpu"];
100100 [window center];
@@ -102,14 +102,14 @@ NSApplication* app;
102102 [window setReleasedWhenClosed:YES];
103103 window.delegate = self;
104104 winClosed = _winClosed;
105-
105+
106106 _view = [[OSECPUView alloc] initWithFrame:NSMakeRect(0,0,sx,sy) buf:buf sx:sx sy:sy];
107107 [window.contentView addSubview:_view];
108108 }
109109
110110 - (void)flushWin : (NSRect)rect
111111 {
112- [_view drawRect:rect];
112+ [_view drawRect:rect];
113113 }
114114
115115 @end
@@ -118,30 +118,30 @@ id objc_main;
118118
119119 int main(int argc, char **argv)
120120 {
121- objc_main = [[Main alloc] init];
122-
123- NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
124- app = [[NSApplication alloc] init];
125- [objc_main createThread:argc args:(const unsigned char **)argv];
126- [app run];
121+ objc_main = [[Main alloc] init];
122+
123+ NSAutoreleasePool* pool = [[NSAutoreleasePool alloc] init];
124+ app = [[NSApplication alloc] init];
125+ [objc_main createThread:argc args:(const unsigned char **)argv];
126+ [app run];
127127 [pool release];
128- return 0;
128+ return 0;
129129 }
130130
131131 void drv_openWin(int sx, int sy, unsigned char *buf, char *winClosed)
132132 {
133- [objc_main openWin:buf sx:sx sy:sy winClosed:winClosed];
133+ [objc_main openWin:buf sx:sx sy:sy winClosed:winClosed];
134134 }
135135
136136 void drv_flshWin(int sx, int sy, int x0, int y0)
137137 {
138- [objc_main flushWin:NSMakeRect(x0,y0,sx,sy)];
138+ [objc_main flushWin:NSMakeRect(x0,y0,sx,sy)];
139139 }
140140
141141 void drv_sleep(int msec)
142142 {
143- [NSThread sleepForTimeInterval:0.001*msec];
144- return;
143+ [NSThread sleepForTimeInterval:0.001*msec];
144+ return;
145145 }
146146
147147
@@ -230,10 +230,10 @@ static int winthread(void *dmy)
230230 RECT r;
231231 int i, x, y;
232232 MSG msg;
233-
233+
234234 x = dw.bmi.bmiHeader.biWidth;
235235 y = -dw.bmi.bmiHeader.biHeight;
236-
236+
237237 wc.cbSize = sizeof (WNDCLASSEX);
238238 wc.style = CS_HREDRAW | CS_VREDRAW;
239239 wc.lpfnWndProc = WndProc;
@@ -241,10 +241,10 @@ static int winthread(void *dmy)
241241 wc.cbWndExtra = 0;
242242 wc.hInstance = dw.hi;
243243 wc.hIcon = (HICON)LoadImage(NULL, MAKEINTRESOURCE(IDI_APPLICATION),
244- IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
244+ IMAGE_ICON, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
245245 wc.hIconSm = wc.hIcon;
246246 wc.hCursor = (HCURSOR)LoadImage(NULL, MAKEINTRESOURCE(IDC_ARROW),
247- IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
247+ IMAGE_CURSOR, 0, 0, LR_DEFAULTSIZE | LR_SHARED);
248248 wc.hbrBackground = (HBRUSH)COLOR_APPWORKSPACE;
249249 wc.lpszMenuName = NULL;
250250 wc.lpszClassName = L"WinClass";
@@ -257,11 +257,11 @@ static int winthread(void *dmy)
257257 AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, FALSE);
258258 x = r.right - r.left;
259259 y = r.bottom - r.top;
260-
260+
261261 char *t = "osecpu";
262-
262+
263263 dw.hw = CreateWindowA("WinClass", t, WS_OVERLAPPEDWINDOW,
264- CW_USEDEFAULT, CW_USEDEFAULT, x, y, NULL, NULL, dw.hi, NULL);
264+ CW_USEDEFAULT, CW_USEDEFAULT, x, y, NULL, NULL, dw.hi, NULL);
265265 if (dw.hw == NULL)
266266 return 1;
267267 ShowWindow(dw.hw, SW_SHOW);
@@ -270,7 +270,7 @@ static int winthread(void *dmy)
270270 SetTimer(dw.hw, TIMER_ID + 1, TIMER_INTERVAL * 10, NULL);
271271 SetTimer(dw.hw, TIMER_ID + 2, TIMER_INTERVAL * 100, NULL);
272272 dw.flags |= 2 | 4;
273-
273+
274274 for (;;) {
275275 i = GetMessage(&msg, NULL, 0, 0);
276276 if (i == 0 || i == -1) /* エラーもしくは終了メッセージ */
@@ -289,7 +289,7 @@ static int winthread(void *dmy)
289289 void bld_openWin(int sx, int sy, char *winClosed)
290290 {
291291 static int i;
292-
292+
293293 dw.bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER);
294294 dw.bmi.bmiHeader.biWidth = sx;
295295 dw.bmi.bmiHeader.biHeight = -sy;
@@ -297,9 +297,9 @@ void bld_openWin(int sx, int sy, char *winClosed)
297297 dw.bmi.bmiHeader.biBitCount = 32;
298298 dw.bmi.bmiHeader.biCompression = BI_RGB;
299299 dw.winClosed = winClosed;
300-
300+
301301 threadhandle = CreateThread(NULL, 0, (void *)&winthread, NULL, 0, (void *)&i);
302-
302+
303303 return;
304304 }
305305
@@ -317,7 +317,7 @@ LRESULT CALLBACK WndProc(HWND hw, unsigned int msg, WPARAM wp, LPARAM lp)
317317 PAINTSTRUCT ps;
318318 HDC hdc = BeginPaint(dw.hw, &ps);
319319 SetDIBitsToDevice(hdc, 0, 0, w.win.xsiz, w.win.ysiz,
320- 0, 0, 0, w.win.ysiz, w.win.buf, &dw.bmi, DIB_RGB_COLORS);
320+ 0, 0, 0, w.win.ysiz, w.win.buf, &dw.bmi, DIB_RGB_COLORS);
321321 EndPaint(dw.hw, &ps);
322322 }
323323 if (msg == WM_DESTROY) {
@@ -340,7 +340,7 @@ LRESULT CALLBACK WndProc(HWND hw, unsigned int msg, WPARAM wp, LPARAM lp)
340340 }
341341 if (msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) {
342342 i = -1;
343-
343+
344344 if (wp == VK_RETURN) i = KEY_ENTER;
345345 if (wp == VK_ESCAPE) i = KEY_ESC;
346346 if (wp == VK_BACK) i = KEY_BACKSPACE;
--- a/function.c
+++ b/function.c
@@ -12,8 +12,8 @@ const char *searchArg(int argc, const char **argv, const char *tag, int i)
1212 if (strncmp(argv[j], tag, l) == 0) {
1313 r = argv[j] + l;
1414 if (i == 0){
15- break;
16- }
15+ break;
16+ }
1717 i--;
1818 }
1919 }
@@ -23,15 +23,15 @@ const char *searchArg(int argc, const char **argv, const char *tag, int i)
2323 if (strchr(argv[j], ':') == NULL) {
2424 r = argv[j];
2525 if (i == 0){
26- break;
27- }
26+ break;
27+ }
2828 i--;
2929 }
3030 }
3131 }
3232 if (i != 0){
33- r = NULL;
34- }
33+ r = NULL;
34+ }
3535 return r;
3636 }
3737
@@ -46,23 +46,23 @@ void devFunc0001(int len, unsigned char *puc, HOSECPU_RuntimeEnvironment *r)
4646
4747 void devFunc0006(int mod, int sx, int sy, int x, int y, int c, int len, unsigned char *puc, HOSECPU_RuntimeEnvironment *r)
4848 {
49- int xx;
50- int yy;
51- int i, ddx, ddy, j, ch, dx, dy;
52-
49+ int xx;
50+ int yy;
51+ int i, ddx, ddy, j, ch, dx, dy;
52+
5353 if (sy == 0){
54- sy = sx;
55- }
54+ sy = sx;
55+ }
5656 xx = x + sx * 8;
5757 yy = y + sy * 16;
5858 if (xx <= 0 || xx > mainWindow.xsize || yy <= 0 || yy > mainWindow.ysize){
5959 (*(r->errHndl))(r);
60- }
60+ }
6161 if (x < 0 || x >= mainWindow.xsize || y < 0 || y >= mainWindow.ysize){
6262 (*(r->errHndl))(r);
63- }
63+ }
64+
6465
65-
6666 if ((mod & 3) == 0 && sx == 1 && sy == 1) {
6767 // メジャーケースを高速化.
6868 for (i = 0; i < len; i++) {
@@ -73,8 +73,8 @@ void devFunc0006(int mod, int sx, int sy, int x, int y, int c, int len, unsigned
7373 j = fontdata[(ch - ' ') * 16 + dy];
7474 for (dx = 0; dx < 8; dx++) {
7575 if ((j & (0x80 >> dx)) != 0){
76- mainWindow.vram[(x + dx) + (y + dy) * mainWindow.xsize] = c;
77- }
76+ mainWindow.vram[(x + dx) + (y + dy) * mainWindow.xsize] = c;
77+ }
7878 }
7979 }
8080 x += 8;
@@ -91,25 +91,25 @@ void devFunc0006(int mod, int sx, int sy, int x, int y, int c, int len, unsigned
9191 for (dx = 0; dx < 8; dx++) {
9292 if ((j & (0x80 >> dx)) != 0) {
9393 for (ddx = 0; ddx < sx; ddx++) {
94- switch (mod & 3) {
95- case 0:
96- mainWindow.vram[x + y * mainWindow.xsize] = c;
97- break;
98- case 1:
99- mainWindow.vram[x + y * mainWindow.xsize] |= c;
100- break;
101- case 2:
102- mainWindow.vram[x + y * mainWindow.xsize] ^= c;
103- break;
104- case 3:
105- mainWindow.vram[x + y * mainWindow.xsize] &= c;
106- break;
107- }
94+ switch (mod & 3) {
95+ case 0:
96+ mainWindow.vram[x + y * mainWindow.xsize] = c;
97+ break;
98+ case 1:
99+ mainWindow.vram[x + y * mainWindow.xsize] |= c;
100+ break;
101+ case 2:
102+ mainWindow.vram[x + y * mainWindow.xsize] ^= c;
103+ break;
104+ case 3:
105+ mainWindow.vram[x + y * mainWindow.xsize] &= c;
106+ break;
107+ }
108108 x++;
109109 }
110110 } else{
111111 x += sx;
112- }
112+ }
113113 }
114114 x -= sx * 8;
115115 y++;
@@ -134,18 +134,18 @@ void devFunc0004(int mod, int x0, int y0, int x1, int y1, int c)
134134 else {
135135 for (y = y0; y <= y1; y++) {
136136 for (x = x0; x <= x1; x++) {
137- switch (mod) {
138- case 1:
139- mainWindow.vram[x + y * mainWindow.xsize] |= c;
140- break;
141- case 2:
142- mainWindow.vram[x + y * mainWindow.xsize] ^= c;
143- break;
144- case 3:
145- mainWindow.vram[x + y * mainWindow.xsize] &= c;
146- break;
147- }
148- }
137+ switch (mod) {
138+ case 1:
139+ mainWindow.vram[x + y * mainWindow.xsize] |= c;
140+ break;
141+ case 2:
142+ mainWindow.vram[x + y * mainWindow.xsize] ^= c;
143+ break;
144+ case 3:
145+ mainWindow.vram[x + y * mainWindow.xsize] &= c;
146+ break;
147+ }
148+ }
149149 }
150150 }
151151 return;
@@ -155,11 +155,11 @@ int devFunc0016(int buflen, unsigned char *buf, int plen, unsigned char *p, int
155155 {
156156 int i = 0, base, j, k;
157157 char sign;
158-
158+
159159 while (plen > 0) {
160160 if (i >= buflen){
161161 (*(r->errHndl))(r);
162- }
162+ }
163163 if (*p != 0x01) {
164164 buf[i++] = *p++;
165165 plen--;
@@ -169,40 +169,40 @@ int devFunc0016(int buflen, unsigned char *buf, int plen, unsigned char *p, int
169169 plen--;
170170 if (qlen < 4){
171171 (*(r->errHndl))(r);
172- }
172+ }
173173 base = q[0];
174174 sign = 0;
175175 if (base == 0){
176- base = 16;
177- }
176+ base = 16;
177+ }
178178 #if (REVISION == 1)
179179 if (base == -3){
180- base = 10;
181- }
180+ base = 10;
181+ }
182182 #endif
183183 if (base == -1){
184- base = 10;
185- }
184+ base = 10;
185+ }
186186 if (base < 0 || base > 16){
187187 (*(r->errHndl))(r);
188- }
188+ }
189189 if (q[1] + i > buflen){
190190 (*(r->errHndl))(r);
191- }
191+ }
192192 j = q[3];
193193 if ((q[2] & 4) == 0) {
194194 // jは符号付き整数.
195195 if ((q[2] & 8) != 0 && j > 0){
196- sign = '+';
197- }
196+ sign = '+';
197+ }
198198 if (j < 0) {
199- sign = '-'; j *= -1;
200- }
199+ sign = '-'; j *= -1;
200+ }
201201 } else{
202202 // jは符号無し整数.
203203 if ((q[2] & 8) != 0 && j != 0){
204- sign = '+';
205- }
204+ sign = '+';
205+ }
206206 }
207207 for (k = q[1] - 1; k >= 0; k--) {
208208 buf[i + k] = (j % base) + 0x10;
@@ -212,25 +212,25 @@ int devFunc0016(int buflen, unsigned char *buf, int plen, unsigned char *p, int
212212 if ((q[2] & 2) == 0 && j == 0) {
213213 for (k = 0; k < q[1] - 1; k++) {
214214 if (buf[i + k] != 0x10){
215- break;
216- }
215+ break;
216+ }
217217 buf[i + k] = ' ';
218218 }
219219 }
220220 if (sign != 0) {
221221 if (k > 0){
222- k--;
223- }
222+ k--;
223+ }
224224 buf[i + k] = sign;
225225 }
226226 if ((q[2] & 1) != 0 && buf[i] == ' ') {
227227 for (j = 0; k < q[1]; k++, j++){
228228 buf[i + j] = buf[i + k];
229- }
229+ }
230230 i += j;
231231 } else{
232232 i += q[1];
233- }
233+ }
234234 qlen -= 4;
235235 q += 4;
236236 }
@@ -240,17 +240,17 @@ int devFunc0016(int buflen, unsigned char *buf, int plen, unsigned char *p, int
240240 void devFunc(HOSECPU_RuntimeEnvironment *r)
241241 {
242242 FILE *fp;
243- int i, c;
243+ int i, c;
244244 int x, y, len, dx, dy;
245245 unsigned char *puc;
246246 unsigned char pucbuf[256];
247-
248- //サイズを節約するためにEBPを128バイトずらしているのを元に戻す
247+
248+ //サイズを節約するためにEBPを128バイトずらしているのを元に戻す
249249 r = (HOSECPU_RuntimeEnvironment *) (((char *)r) - 128);
250250
251251 if (r->winClosed != 0){
252252 longjmp(*(r->setjmpEnv), 1);
253- }
253+ }
254254 if (0xff44 <= r->ireg[0x30] && r->ireg[0x30] <= 0xff48) {
255255 if (mainWindow.vram == NULL) {
256256 mainWindow.xsize = 640;
@@ -260,455 +260,455 @@ void devFunc(HOSECPU_RuntimeEnvironment *r)
260260 r->autoSleep = 1;
261261 for (i = 640 * 480 - 1; i >= 0; i--){
262262 mainWindow.vram[i] = 0;
263- }
263+ }
264264 }
265265 }
266-
266+
267267 switch (r->ireg[0x30]){
268- case 0xff00:
269- printf("R31=%d(dec)\n", r->ireg[0x31]);
270- break;
271-
272- case 0xff01:
273- /* return: R30, P31 */
274- if (r->buf0 == NULL){
275- r->buf0 = malloc(1024 * 1024);
276- }
277- if (r->mainArgc <= r->ireg[0x31]) {
278- fprintf(stderr, "devFunc: error: R30=ff01: argc error: R31=%08X\n", r->ireg[0x31]);
279- exit(1);
280- }
281- fp = fopen(r->mainArgv[r->ireg[0x31]], "rb");
282- if (fp == NULL) {
283- fprintf(stderr, "devFunc: error: R30=ff01: fopen error: '%s'\n", r->mainArgv[r->ireg[0x31]]);
284- exit(1);
285- }
286- i = (int)fread(r->buf0, 1, 1024 * 1024 - 4, fp);
287- if (i >= 1024 * 1024 - 4 || i < 0) {
288- fprintf(stderr, "devFunc: error: R30=ff01: fread error: '%s'\n", r->mainArgv[r->ireg[0x31]]);
289- exit(1);
290- }
291- fclose(fp);
292- r->preg[0x31].p = r->buf0;
293- r->preg[0x31].p0 = r->buf0;
294- r->preg[0x31].p1 = r->buf0 + i;
295- r->preg[0x31].typ = 3; // T_UINT8
296- r->ireg[0x30] = i;
297- break;
298-
299- case 0xff02:
300- /* return: none */
301- if (r->mainArgc <= r->ireg[0x31]) {
302- fprintf(stderr, "devFunc: error: R30=ff02: argc error: R31=%08X\n", r->ireg[0x31]);
303- exit(1);
304- }
305- fp = fopen(r->mainArgv[r->ireg[0x31]], "wb");
306- if (fp == NULL) {
307- fprintf(stderr, "devFunc: error: R30=ff02: fopen error: '%s'\n", r->mainArgv[r->ireg[0x31]]);
308- exit(1);
309- }
310- if (r->ireg[0x32] >= 1024 * 1024 || r->ireg[0x32] < 0){
311- fprintf(stderr, "devFunc: error: R30=ff02: fwrite error: R02=%08X\n", r->ireg[0x32]);
312- exit(1);
313- }
314- fwrite(r->preg[0x31].p, 1, r->ireg[0x32], fp);
315- fclose(fp);
316- break;
317-
318- case 0xff03:
319- /* return: P31 */
320- if (r->buf1 == NULL){
321- r->buf1 = malloc(1024 * 1024);
322- }
323- r->preg[0x31].p = r->buf1;
324- r->preg[0x31].p0 = r->buf1;
325- r->preg[0x31].p1 = r->buf1 + 1024 * 1024;
326- break;
327-
328- case 0xff04:
329- printf("P31.(p-p0)=%d(dec)\n", (int)(r->preg[0x31].p - r->preg[0x31].p0));
330- break;
331-
332- case 0xff05:
333- fwrite(r->preg[0x31].p, 1, r->ireg[0x31], stdout);
334- break;
335-
336- case 0xff06:
337- // R31はリターンコード.
338- // これを反映すべきだが、現状は手抜きでいつも正常終了.
339- longjmp(*(r->setjmpEnv), 1);
340- break;
341-
342- case 0xff07:
343- // マシになった文字列表示.OSASK文字列に対応.offにすれば通常の文字列処理もできる.現状はonのみサポート.
344- checkString(r, 0x31, 0x31);
345- devFunc0001(r->ireg[0x31], r->preg[0x31].p, r);
346- break;
347-
348- case 0xff08:
349- // JITC on JITC
350- // R31: 言語(back-end, front-end, ...
351- // R32: level
352- // R33: debugInfo1
353- checkString(r, 0x34, 0x31);
354- if (r->ireg[0x33] < 0 || r->ireg[0x33] > 15 || r->debugInfo1 > 15){
355- (*(r->errHndl))(r);
356- }
357- for (i = 0; i < r->maxLabels; i++){
358- r->label[i].opt = 0;
359- }
360- puc = r->preg[0x31].p;
361- i = jitCompiler(r->jitbuf, r->jitbuf1, puc, puc + r->ireg[0x34], puc, r->label, r->maxLabels, r->ireg[0x32], di1_serial, JITC_NOSTARTUP + 0);
362- if (i == 0) {
363- i = jitCompiler(r->jitbuf, r->jitbuf1, puc, puc + r->ireg[0x34], puc, r->label, r->maxLabels, r->ireg[0x32], di1_serial, JITC_NOSTARTUP + JITC_PHASE1 + 0);
364- if (i >= 0) {
365- r->mapDi1s[r->debugInfo1][r->ireg[0x33]] = di1_serial;
366- di1_serial++;
367- r->ireg[0x30] = 0;
368- r->preg[0x31].p = r->jitbuf;
369- r->preg[0x31].typ = 0; // TYP_CODE
370- r->preg[0x31].p0 = r->jitbuf;
371- r->preg[0x31].p1 = r->jitbuf + 1;
372- //int j; for (j = 0; j < i; j++) printf("%02X ", r->jitbuf[j]); putchar('\n');
373- r->jitbuf += i;
374- static unsigned char ff08_ret[3] = { 0x1e, 0x3f, 0x30 };
375- i = jitCompiler(r->jitbuf, r->jitbuf1, ff08_ret, ff08_ret + 3, puc, r->label, r->maxLabels, r->ireg[0x32], -1, JITC_NOSTARTUP + JITC_PHASE1 + 0);
376- r->jitbuf += i;
377- break;
378- }
379- }
380- r->ireg[0x30] = -1;
381- break;
382-
383- case 0xff09:
384- // たぶんbit7を使ったテキストはうまく処理できない(これはもはや仕様にしても問題ないかも).
385- checkString(r, 0x31, 0x31);
386- len = devFunc0016(sizeof pucbuf, pucbuf, r->ireg[0x31], r->preg[0x31].p, r->ireg[0x32], (int *)r->preg[0x32].p, r);
387- devFunc0001(len, pucbuf, r);
388- break;
389-
390- case 0xff40:
391- /* R31とR32でサイズを指定 */
392- mainWindow.xsize = r->ireg[0x31];
393- mainWindow.ysize = r->ireg[0x32];
394- if (mainWindow.xsize <= 0 || mainWindow.ysize <= 0){
395- (*(r->errHndl))(r);
396- }
397- r->preg[0x31].p = (void *)(mainWindow.vram = malloc(mainWindow.xsize * mainWindow.ysize * 4));
398- r->preg[0x31].p0 = r->preg[0x31].p;
399- r->preg[0x31].p1 = r->preg[0x31].p + mainWindow.xsize * mainWindow.ysize * 4;
400- drv_openWin(r->ireg[0x31], r->ireg[0x32], r->preg[0x31].p, &r->winClosed);
401- // drv_flshWin(r->ireg[1], r->ireg[2], 0, 0);
402- r->autoSleep = 1;
403- for (i = mainWindow.xsize * mainWindow.ysize - 1; i >= 0; i--){
404- mainWindow.vram[i] = 0;
405- }
406- break;
407-
408- case 0xff41:
409- /* R31とR32でサイズを指定、R33とR34でx0,y0指定 */
410- if (r->ireg[0x31] == -1) {
411- r->ireg[0x31] = mainWindow.xsize; r->ireg[0x33] &= 0;
412- }
413- if (r->ireg[0x32] == -1) {
414- r->ireg[0x32] = mainWindow.ysize; r->ireg[0x34] &= 0;
415- }
416- checkRect(r, 0x31);
417- drv_flshWin(r->ireg[0x31], r->ireg[0x32], r->ireg[0x33], r->ireg[0x34]);
418- break;
419-
420- case 0xff42:
421- if (r->ireg[0x32] == -1) {
422- r->autoSleep = 1;
423- longjmp(*(r->setjmpEnv), 1);
424- }
425- if (r->ireg[0x32] < 0){
426- (*(r->errHndl))(r);
427- }
428- r->autoSleep = 0;
429- if ((r->ireg[0x31] & 1) == 0 && mainWindow.vram != NULL){
430- drv_flshWin(mainWindow.xsize, mainWindow.ysize, 0, 0);
431- }
432- for (;;) {
433- if (r->winClosed != 0){
434- longjmp(*(r->setjmpEnv), 1);
435- }
436- drv_sleep(r->ireg[0x32]);
437- if ((r->ireg[0x31] & 2) != 0 && keybuf_c <= 0){
438- continue;
439- }
440- break;
441- }
442- break;
443-
444- case 0xff43:
445- // 1:peek
446- // 2:stdin
447- // 4,8: ソース指定.
448- // 16: shift, lock系を有効化.
449- // 32: 左右のshift系を区別する.
450- if (r->ireg[0x31] == 2) { // なぜ3にしなかったのか...
451- r->ireg[0x30] = fgetc(stdin);
452- if (r->ireg[0x30] == EOF){
453- r->ireg[0x30] = -1;
454- }
455- break;
456- }
457- r->ireg[0x30] |= -1;
458- if (keybuf_c > 0) {
459- r->ireg[0x30] = keybuf[keybuf_r];
460- if ((r->ireg[0x31] & 16) == 0){
461- r->ireg[0x30] &= 0x3e3effff;
462- }
463- if ((r->ireg[0x31] & 32) == 0){
464- r->ireg[0x30] |= (r->ireg[0x30] >> 8) & 0xff0000;
465- }
466- if ((r->ireg[0x31] & 1) != 0) {
467- keybuf_c--;
468- keybuf_r = (keybuf_r + 1) & (KEYBUFSIZ - 1);
469- }
470- }
471- r->ireg[0x32] = r->ireg[0x33] = 0;
472- if (r->ireg[0x30] == 4132) r->ireg[0x32]--;
473- if (r->ireg[0x30] == 4133) r->ireg[0x33]--;
474- if (r->ireg[0x30] == 4134) r->ireg[0x32]++;
475- if (r->ireg[0x30] == 4135) r->ireg[0x33]++;
476- break;
477-
478- case 0xff44:
479- c = loadColor(r, 0x34);
480- if (r->ireg[0x32] < 0 || r->ireg[0x32] >= mainWindow.xsize ||
481- r->ireg[0x33] < 0 || r->ireg[0x33] >= mainWindow.ysize){
482- (*(r->errHndl))(r);
483- }
484-
485- switch ((r->ireg[0x31] & 3)) {
486- case 0:
487- mainWindow.vram[r->ireg[0x32] + r->ireg[0x33] * mainWindow.xsize] = c;
488- break;
489- case 1:
490- mainWindow.vram[r->ireg[0x32] + r->ireg[0x33] * mainWindow.xsize] |= c;
491- break;
492- case 2:
493- mainWindow.vram[r->ireg[0x32] + r->ireg[0x33] * mainWindow.xsize] ^= c;
494- break;
495- case 3:
496- mainWindow.vram[r->ireg[0x32] + r->ireg[0x33] * mainWindow.xsize] &= c;
497- break;
498- }
499- break;
500-
501- case 0xff45:
502- //drawLine
503- c = loadColor(r, 0x36);
504- if (r->ireg[0x32] < 0 || r->ireg[0x32] >= mainWindow.xsize ||
505- r->ireg[0x33] < 0 || r->ireg[0x33] >= mainWindow.ysize){
506- (*(r->errHndl))(r);
507- }
508- if (r->ireg[0x34] < 0 || r->ireg[0x34] >= mainWindow.xsize ||
509- r->ireg[0x35] < 0 || r->ireg[0x35] >= mainWindow.ysize){
510- (*(r->errHndl))(r);
511- }
512- dx = r->ireg[0x34] - r->ireg[0x32];
513- dy = r->ireg[0x35] - r->ireg[0x33];
514- x = r->ireg[0x32] << 10;
515- y = r->ireg[0x33] << 10;
516- if (dx < 0){
517- dx = -dx;
518- }
519- if (dy < 0){
520- dy = -dy;
521- }
522- if (dx >= dy) {
523- len = dx + 1; dx = 1024;
524- if (r->ireg[0x32] > r->ireg[0x34]){
525- dx *= -1;
526- }
527- if (r->ireg[0x33] > r->ireg[0x35]){
528- dy *= -1;
529- }
530- dy = (dy << 10) / len;
531- } else {
532- len = dy + 1; dy = 1024;
533- if (r->ireg[0x33] > r->ireg[0x35]){
534- dy *= -1;
535- }
536- if (r->ireg[0x32] > r->ireg[0x34]){
537- dx *= -1;
538- }
539- dx = (dx << 10) / len;
540- }
541- if ((r->ireg[0x31] & 3) == 0) {
542- for (i = 0; i < len; i++) {
543- mainWindow.vram[(x >> 10) + (y >> 10) * mainWindow.xsize] = c;
544- x += dx;
545- y += dy;
546- }
547- break;
548- }
549- for (i = 0; i < len; i++) {
550- // if ((r->ireg[0x31] & 3) == 0) vram[(x >> 10) + (y >> 10) * v_xsiz] = c;
551- switch ((r->ireg[0x31] & 3)) {
552- case 1:
553- mainWindow.vram[(x >> 10) + (y >> 10) * mainWindow.xsize] |= c;
554- break;
555- case 2:
556- mainWindow.vram[(x >> 10) + (y >> 10) * mainWindow.xsize] ^= c;
557- break;
558- case 3:
559- mainWindow.vram[(x >> 10) + (y >> 10) * mainWindow.xsize] &= c;
560- break;
561- default:
562- break;
563- }
564- x += dx;
565- y += dy;
566- }
567- break;
568-
569- case 0xff46: // fillRect(opt:R31, xsiz:R32, ysiz:R33, x0:R34, y0:R35, c:R36)
570- c = loadColor(r, 0x36);
571- if (r->ireg[0x32] == -1) { r->ireg[0x32] = mainWindow.xsize; r->ireg[0x34] &= 0; }
572- if (r->ireg[0x33] == -1) { r->ireg[0x33] = mainWindow.ysize; r->ireg[0x35] &= 0; }
573- checkRect(r, 0x32);
574- int mod3 = r->ireg[0x31] & 3, x0 = r->ireg[0x34], y0 = r->ireg[0x35], x1 = r->ireg[0x34] + r->ireg[0x32] - 1, y1 = r->ireg[0x35] + r->ireg[0x33] - 1;
575- if ((r->ireg[0x31] & 0x20) == 0) {
576- devFunc0004(mod3, x0, y0, x1, y1, c);
577- } else { // drawRect
578- devFunc0004(mod3, x0, y0, x1, y0, c);
579- devFunc0004(mod3, x0, y1, x1, y1, c);
580- devFunc0004(mod3, x0, y0, x0, y1, c);
581- devFunc0004(mod3, x1, y0, x1, y1, c);
582- }
583- break;
584-
585- case 0xff47: // fillOval(opt:R31, xsiz:R32, ysiz:R33, x0:R34, y0:R35, c:R36)
586- // これの計算精度はアーキテクチャに依存する.
587- c = loadColor(r, 0x36);
588- if (r->ireg[0x32] == -1) {
589- r->ireg[0x32] = mainWindow.xsize; r->ireg[0x34] &= 0;
590- }
591- if (r->ireg[0x33] == -1) {
592- r->ireg[0x33] = mainWindow.ysize; r->ireg[0x35] &= 0;
593- }
594- checkRect(r, 0x32);
595- double dcx = 0.5 * (r->ireg[0x32] - 1);
596- double dcy = 0.5 * (r->ireg[0x33] - 1);
597- double dcxy = (dcx + 0.5) * (dcy + 0.5) - 0.1;
598- dcxy *= dcxy;
599- mod3 = r->ireg[0x31] & 3;
600- x1 = r->ireg[0x32];
601- y1 = r->ireg[0x33];
602- if (mod3 == 0 && (r->ireg[0x31] & 0x20) == 0) {
603- for (y = 0; y < y1; y++) {
604- double dty = (y - dcy) * dcx;
605- for (x = 0; x < x1; x++) {
606- double dtx = (x - dcx) * dcy;
607- if (dtx * dtx + dty * dty > dcxy){
608- continue;
609- }
610- mainWindow.vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * mainWindow.xsize] = c;
611- }
612- }
613- } else {
268+ case 0xff00:
269+ printf("R31=%d(dec)\n", r->ireg[0x31]);
270+ break;
271+
272+ case 0xff01:
273+ /* return: R30, P31 */
274+ if (r->buf0 == NULL){
275+ r->buf0 = malloc(1024 * 1024);
276+ }
277+ if (r->mainArgc <= r->ireg[0x31]) {
278+ fprintf(stderr, "devFunc: error: R30=ff01: argc error: R31=%08X\n", r->ireg[0x31]);
279+ exit(1);
280+ }
281+ fp = fopen(r->mainArgv[r->ireg[0x31]], "rb");
282+ if (fp == NULL) {
283+ fprintf(stderr, "devFunc: error: R30=ff01: fopen error: '%s'\n", r->mainArgv[r->ireg[0x31]]);
284+ exit(1);
285+ }
286+ i = (int)fread(r->buf0, 1, 1024 * 1024 - 4, fp);
287+ if (i >= 1024 * 1024 - 4 || i < 0) {
288+ fprintf(stderr, "devFunc: error: R30=ff01: fread error: '%s'\n", r->mainArgv[r->ireg[0x31]]);
289+ exit(1);
290+ }
291+ fclose(fp);
292+ r->preg[0x31].p = r->buf0;
293+ r->preg[0x31].p0 = r->buf0;
294+ r->preg[0x31].p1 = r->buf0 + i;
295+ r->preg[0x31].typ = 3; // T_UINT8
296+ r->ireg[0x30] = i;
297+ break;
298+
299+ case 0xff02:
300+ /* return: none */
301+ if (r->mainArgc <= r->ireg[0x31]) {
302+ fprintf(stderr, "devFunc: error: R30=ff02: argc error: R31=%08X\n", r->ireg[0x31]);
303+ exit(1);
304+ }
305+ fp = fopen(r->mainArgv[r->ireg[0x31]], "wb");
306+ if (fp == NULL) {
307+ fprintf(stderr, "devFunc: error: R30=ff02: fopen error: '%s'\n", r->mainArgv[r->ireg[0x31]]);
308+ exit(1);
309+ }
310+ if (r->ireg[0x32] >= 1024 * 1024 || r->ireg[0x32] < 0){
311+ fprintf(stderr, "devFunc: error: R30=ff02: fwrite error: R02=%08X\n", r->ireg[0x32]);
312+ exit(1);
313+ }
314+ fwrite(r->preg[0x31].p, 1, r->ireg[0x32], fp);
315+ fclose(fp);
316+ break;
317+
318+ case 0xff03:
319+ /* return: P31 */
320+ if (r->buf1 == NULL){
321+ r->buf1 = malloc(1024 * 1024);
322+ }
323+ r->preg[0x31].p = r->buf1;
324+ r->preg[0x31].p0 = r->buf1;
325+ r->preg[0x31].p1 = r->buf1 + 1024 * 1024;
326+ break;
327+
328+ case 0xff04:
329+ printf("P31.(p-p0)=%d(dec)\n", (int)(r->preg[0x31].p - r->preg[0x31].p0));
330+ break;
331+
332+ case 0xff05:
333+ fwrite(r->preg[0x31].p, 1, r->ireg[0x31], stdout);
334+ break;
335+
336+ case 0xff06:
337+ // R31はリターンコード.
338+ // これを反映すべきだが、現状は手抜きでいつも正常終了.
339+ longjmp(*(r->setjmpEnv), 1);
340+ break;
341+
342+ case 0xff07:
343+ // マシになった文字列表示.OSASK文字列に対応.offにすれば通常の文字列処理もできる.現状はonのみサポート.
344+ checkString(r, 0x31, 0x31);
345+ devFunc0001(r->ireg[0x31], r->preg[0x31].p, r);
346+ break;
347+
348+ case 0xff08:
349+ // JITC on JITC
350+ // R31: 言語(back-end, front-end, ...
351+ // R32: level
352+ // R33: debugInfo1
353+ checkString(r, 0x34, 0x31);
354+ if (r->ireg[0x33] < 0 || r->ireg[0x33] > 15 || r->debugInfo1 > 15){
355+ (*(r->errHndl))(r);
356+ }
357+ for (i = 0; i < r->maxLabels; i++){
358+ r->label[i].opt = 0;
359+ }
360+ puc = r->preg[0x31].p;
361+ i = jitCompiler(r->jitbuf, r->jitbuf1, puc, puc + r->ireg[0x34], puc, r->label, r->maxLabels, r->ireg[0x32], di1_serial, JITC_NOSTARTUP + 0);
362+ if (i == 0) {
363+ i = jitCompiler(r->jitbuf, r->jitbuf1, puc, puc + r->ireg[0x34], puc, r->label, r->maxLabels, r->ireg[0x32], di1_serial, JITC_NOSTARTUP + JITC_PHASE1 + 0);
364+ if (i >= 0) {
365+ r->mapDi1s[r->debugInfo1][r->ireg[0x33]] = di1_serial;
366+ di1_serial++;
367+ r->ireg[0x30] = 0;
368+ r->preg[0x31].p = r->jitbuf;
369+ r->preg[0x31].typ = 0; // TYP_CODE
370+ r->preg[0x31].p0 = r->jitbuf;
371+ r->preg[0x31].p1 = r->jitbuf + 1;
372+ //int j; for (j = 0; j < i; j++) printf("%02X ", r->jitbuf[j]); putchar('\n');
373+ r->jitbuf += i;
374+ static unsigned char ff08_ret[3] = { 0x1e, 0x3f, 0x30 };
375+ i = jitCompiler(r->jitbuf, r->jitbuf1, ff08_ret, ff08_ret + 3, puc, r->label, r->maxLabels, r->ireg[0x32], -1, JITC_NOSTARTUP + JITC_PHASE1 + 0);
376+ r->jitbuf += i;
377+ break;
378+ }
379+ }
380+ r->ireg[0x30] = -1;
381+ break;
382+
383+ case 0xff09:
384+ // たぶんbit7を使ったテキストはうまく処理できない(これはもはや仕様にしても問題ないかも).
385+ checkString(r, 0x31, 0x31);
386+ len = devFunc0016(sizeof pucbuf, pucbuf, r->ireg[0x31], r->preg[0x31].p, r->ireg[0x32], (int *)r->preg[0x32].p, r);
387+ devFunc0001(len, pucbuf, r);
388+ break;
389+
390+ case 0xff40:
391+ /* R31とR32でサイズを指定 */
392+ mainWindow.xsize = r->ireg[0x31];
393+ mainWindow.ysize = r->ireg[0x32];
394+ if (mainWindow.xsize <= 0 || mainWindow.ysize <= 0){
395+ (*(r->errHndl))(r);
396+ }
397+ r->preg[0x31].p = (void *)(mainWindow.vram = malloc(mainWindow.xsize * mainWindow.ysize * 4));
398+ r->preg[0x31].p0 = r->preg[0x31].p;
399+ r->preg[0x31].p1 = r->preg[0x31].p + mainWindow.xsize * mainWindow.ysize * 4;
400+ drv_openWin(r->ireg[0x31], r->ireg[0x32], r->preg[0x31].p, &r->winClosed);
401+ // drv_flshWin(r->ireg[1], r->ireg[2], 0, 0);
402+ r->autoSleep = 1;
403+ for (i = mainWindow.xsize * mainWindow.ysize - 1; i >= 0; i--){
404+ mainWindow.vram[i] = 0;
405+ }
406+ break;
407+
408+ case 0xff41:
409+ /* R31とR32でサイズを指定、R33とR34でx0,y0指定 */
410+ if (r->ireg[0x31] == -1) {
411+ r->ireg[0x31] = mainWindow.xsize; r->ireg[0x33] &= 0;
412+ }
413+ if (r->ireg[0x32] == -1) {
414+ r->ireg[0x32] = mainWindow.ysize; r->ireg[0x34] &= 0;
415+ }
416+ checkRect(r, 0x31);
417+ drv_flshWin(r->ireg[0x31], r->ireg[0x32], r->ireg[0x33], r->ireg[0x34]);
418+ break;
419+
420+ case 0xff42:
421+ if (r->ireg[0x32] == -1) {
422+ r->autoSleep = 1;
423+ longjmp(*(r->setjmpEnv), 1);
424+ }
425+ if (r->ireg[0x32] < 0){
426+ (*(r->errHndl))(r);
427+ }
428+ r->autoSleep = 0;
429+ if ((r->ireg[0x31] & 1) == 0 && mainWindow.vram != NULL){
430+ drv_flshWin(mainWindow.xsize, mainWindow.ysize, 0, 0);
431+ }
432+ for (;;) {
433+ if (r->winClosed != 0){
434+ longjmp(*(r->setjmpEnv), 1);
435+ }
436+ drv_sleep(r->ireg[0x32]);
437+ if ((r->ireg[0x31] & 2) != 0 && keybuf_c <= 0){
438+ continue;
439+ }
440+ break;
441+ }
442+ break;
443+
444+ case 0xff43:
445+ // 1:peek
446+ // 2:stdin
447+ // 4,8: ソース指定.
448+ // 16: shift, lock系を有効化.
449+ // 32: 左右のshift系を区別する.
450+ if (r->ireg[0x31] == 2) { // なぜ3にしなかったのか...
451+ r->ireg[0x30] = fgetc(stdin);
452+ if (r->ireg[0x30] == EOF){
453+ r->ireg[0x30] = -1;
454+ }
455+ break;
456+ }
457+ r->ireg[0x30] |= -1;
458+ if (keybuf_c > 0) {
459+ r->ireg[0x30] = keybuf[keybuf_r];
460+ if ((r->ireg[0x31] & 16) == 0){
461+ r->ireg[0x30] &= 0x3e3effff;
462+ }
463+ if ((r->ireg[0x31] & 32) == 0){
464+ r->ireg[0x30] |= (r->ireg[0x30] >> 8) & 0xff0000;
465+ }
466+ if ((r->ireg[0x31] & 1) != 0) {
467+ keybuf_c--;
468+ keybuf_r = (keybuf_r + 1) & (KEYBUFSIZ - 1);
469+ }
470+ }
471+ r->ireg[0x32] = r->ireg[0x33] = 0;
472+ if (r->ireg[0x30] == 4132) r->ireg[0x32]--;
473+ if (r->ireg[0x30] == 4133) r->ireg[0x33]--;
474+ if (r->ireg[0x30] == 4134) r->ireg[0x32]++;
475+ if (r->ireg[0x30] == 4135) r->ireg[0x33]++;
476+ break;
477+
478+ case 0xff44:
479+ c = loadColor(r, 0x34);
480+ if (r->ireg[0x32] < 0 || r->ireg[0x32] >= mainWindow.xsize ||
481+ r->ireg[0x33] < 0 || r->ireg[0x33] >= mainWindow.ysize){
482+ (*(r->errHndl))(r);
483+ }
484+
485+ switch ((r->ireg[0x31] & 3)) {
486+ case 0:
487+ mainWindow.vram[r->ireg[0x32] + r->ireg[0x33] * mainWindow.xsize] = c;
488+ break;
489+ case 1:
490+ mainWindow.vram[r->ireg[0x32] + r->ireg[0x33] * mainWindow.xsize] |= c;
491+ break;
492+ case 2:
493+ mainWindow.vram[r->ireg[0x32] + r->ireg[0x33] * mainWindow.xsize] ^= c;
494+ break;
495+ case 3:
496+ mainWindow.vram[r->ireg[0x32] + r->ireg[0x33] * mainWindow.xsize] &= c;
497+ break;
498+ }
499+ break;
500+
501+ case 0xff45:
502+ //drawLine
503+ c = loadColor(r, 0x36);
504+ if (r->ireg[0x32] < 0 || r->ireg[0x32] >= mainWindow.xsize ||
505+ r->ireg[0x33] < 0 || r->ireg[0x33] >= mainWindow.ysize){
506+ (*(r->errHndl))(r);
507+ }
508+ if (r->ireg[0x34] < 0 || r->ireg[0x34] >= mainWindow.xsize ||
509+ r->ireg[0x35] < 0 || r->ireg[0x35] >= mainWindow.ysize){
510+ (*(r->errHndl))(r);
511+ }
512+ dx = r->ireg[0x34] - r->ireg[0x32];
513+ dy = r->ireg[0x35] - r->ireg[0x33];
514+ x = r->ireg[0x32] << 10;
515+ y = r->ireg[0x33] << 10;
516+ if (dx < 0){
517+ dx = -dx;
518+ }
519+ if (dy < 0){
520+ dy = -dy;
521+ }
522+ if (dx >= dy) {
523+ len = dx + 1; dx = 1024;
524+ if (r->ireg[0x32] > r->ireg[0x34]){
525+ dx *= -1;
526+ }
527+ if (r->ireg[0x33] > r->ireg[0x35]){
528+ dy *= -1;
529+ }
530+ dy = (dy << 10) / len;
531+ } else {
532+ len = dy + 1; dy = 1024;
533+ if (r->ireg[0x33] > r->ireg[0x35]){
534+ dy *= -1;
535+ }
536+ if (r->ireg[0x32] > r->ireg[0x34]){
537+ dx *= -1;
538+ }
539+ dx = (dx << 10) / len;
540+ }
541+ if ((r->ireg[0x31] & 3) == 0) {
542+ for (i = 0; i < len; i++) {
543+ mainWindow.vram[(x >> 10) + (y >> 10) * mainWindow.xsize] = c;
544+ x += dx;
545+ y += dy;
546+ }
547+ break;
548+ }
549+ for (i = 0; i < len; i++) {
550+ // if ((r->ireg[0x31] & 3) == 0) vram[(x >> 10) + (y >> 10) * v_xsiz] = c;
551+ switch ((r->ireg[0x31] & 3)) {
552+ case 1:
553+ mainWindow.vram[(x >> 10) + (y >> 10) * mainWindow.xsize] |= c;
554+ break;
555+ case 2:
556+ mainWindow.vram[(x >> 10) + (y >> 10) * mainWindow.xsize] ^= c;
557+ break;
558+ case 3:
559+ mainWindow.vram[(x >> 10) + (y >> 10) * mainWindow.xsize] &= c;
560+ break;
561+ default:
562+ break;
563+ }
564+ x += dx;
565+ y += dy;
566+ }
567+ break;
568+
569+ case 0xff46: // fillRect(opt:R31, xsiz:R32, ysiz:R33, x0:R34, y0:R35, c:R36)
570+ c = loadColor(r, 0x36);
571+ if (r->ireg[0x32] == -1) { r->ireg[0x32] = mainWindow.xsize; r->ireg[0x34] &= 0; }
572+ if (r->ireg[0x33] == -1) { r->ireg[0x33] = mainWindow.ysize; r->ireg[0x35] &= 0; }
573+ checkRect(r, 0x32);
574+ int mod3 = r->ireg[0x31] & 3, x0 = r->ireg[0x34], y0 = r->ireg[0x35], x1 = r->ireg[0x34] + r->ireg[0x32] - 1, y1 = r->ireg[0x35] + r->ireg[0x33] - 1;
575+ if ((r->ireg[0x31] & 0x20) == 0) {
576+ devFunc0004(mod3, x0, y0, x1, y1, c);
577+ } else { // drawRect
578+ devFunc0004(mod3, x0, y0, x1, y0, c);
579+ devFunc0004(mod3, x0, y1, x1, y1, c);
580+ devFunc0004(mod3, x0, y0, x0, y1, c);
581+ devFunc0004(mod3, x1, y0, x1, y1, c);
582+ }
583+ break;
584+
585+ case 0xff47: // fillOval(opt:R31, xsiz:R32, ysiz:R33, x0:R34, y0:R35, c:R36)
586+ // これの計算精度はアーキテクチャに依存する.
587+ c = loadColor(r, 0x36);
588+ if (r->ireg[0x32] == -1) {
589+ r->ireg[0x32] = mainWindow.xsize; r->ireg[0x34] &= 0;
590+ }
591+ if (r->ireg[0x33] == -1) {
592+ r->ireg[0x33] = mainWindow.ysize; r->ireg[0x35] &= 0;
593+ }
594+ checkRect(r, 0x32);
595+ double dcx = 0.5 * (r->ireg[0x32] - 1);
596+ double dcy = 0.5 * (r->ireg[0x33] - 1);
597+ double dcxy = (dcx + 0.5) * (dcy + 0.5) - 0.1;
598+ dcxy *= dcxy;
599+ mod3 = r->ireg[0x31] & 3;
600+ x1 = r->ireg[0x32];
601+ y1 = r->ireg[0x33];
602+ if (mod3 == 0 && (r->ireg[0x31] & 0x20) == 0) {
603+ for (y = 0; y < y1; y++) {
604+ double dty = (y - dcy) * dcx;
605+ for (x = 0; x < x1; x++) {
606+ double dtx = (x - dcx) * dcy;
607+ if (dtx * dtx + dty * dty > dcxy){
608+ continue;
609+ }
610+ mainWindow.vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * mainWindow.xsize] = c;
611+ }
612+ }
613+ } else {
614614 #define DRAWOVALPARAM 1
615- double dcx1 = 0.5 * (r->ireg[0x32] - (1 + DRAWOVALPARAM * 2));
616- double dcy1 = 0.5 * (r->ireg[0x33] - (1 + DRAWOVALPARAM * 2));
617- double dcxy1 = (dcx1 + 0.5) * (dcy1 + 0.5) - 0.1;
618- dcxy1 *= dcxy1;
619- for (y = 0; y < y1; y++) {
620- double dty = (y - dcy) * dcx;
621- double dty1 = (y - dcy) * dcx1;
622- for (x = 0; x < x1; x++) {
623- double dtx = (x - dcx) * dcy;
624- double dtx1 = (x - dcx) * dcy1;
625- if (dtx * dtx + dty * dty > dcxy){
626- continue;
627- }
628- if (DRAWOVALPARAM <= x && x < x1 - DRAWOVALPARAM && DRAWOVALPARAM <= y && y < y1 - DRAWOVALPARAM) {
629- if (dtx1 * dtx1 + dty1 * dty1 < dcxy1){
630- continue;
631- }
632- }
633- switch (mod3) {
634- case 0:
635- mainWindow.vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * mainWindow.xsize] = c;
636- break;
637- case 1:
638- mainWindow.vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * mainWindow.xsize] |= c;
639- break;
640- case 2:
641- mainWindow.vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * mainWindow.xsize] ^= c;
642- break;
643- case 3:
644- mainWindow.vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * mainWindow.xsize] &= c;
645- break;
646- }
647- }
648- }
649- }
650- break;
651-
652- case 0xff48: // drawString(opt:R31, xsiz:R32, ysiz:R33, x0:R34, y0:R35, c:R36, s.len:R37, s.p:P31)
653- checkString(r, 0x37, 0x31);
654- devFunc0006(r->ireg[0x31], r->ireg[0x32], r->ireg[0x33], r->ireg[0x34], r->ireg[0x35], loadColor(r, 0x36), r->ireg[0x37], r->preg[0x31].p, r);
655- break;
656-
657- case 0xff49:
658- // **** junkApi_rand(i, max) ****
659- // 0 <= i <= maxとなるiを返す。
660- // max==0のとき、iはSINT32全体を範囲とする乱数となる。
661- r->ireg[0x30] = randGetNextUInt32();
662- if (r->ireg[0x31] > 0){
663- r->ireg[0x30] = (r->ireg[0x30] & 0x7fffffff) % (r->ireg[0x31] + 1);
664- }
665- break;
666-
667- case 0xff4a: /* seedの指定 */
668- randStatInit(r->ireg[0x31]);
669- break;
670-
671- case 0xff4b: /* 適当なseedを提供 */
672- r->ireg[0x30] = (int)(time(NULL) ^ (long)0x55555555);
673- break;
674-
675- case 0xff4c:
676- checkString(r, 0x37, 0x31);
677- len = devFunc0016(sizeof pucbuf, pucbuf, r->ireg[0x37], r->preg[0x31].p, r->ireg[0x38], (int *)r->preg[0x32].p, r);
678- devFunc0006(r->ireg[0x31], r->ireg[0x32], r->ireg[0x33], r->ireg[0x34], r->ireg[0x35], loadColor(r, 0x36), len, pucbuf, r);
679- break;
680-
681- case 0xff4d:
682- // bitblt(mod, xsiz, ysiz, xscale, yscale, x0, y0, lineskip, inv, p_buf, typ0, p_table, typ1);
683- // mod: 0x20:use_table, 0x40:inv_is_visible & typ1_is_color
684- puc = r->preg[0x31].p;
685- mod3 = r->ireg[0x31] & 3;
686- dx = r->ireg[0x34];
687- dy = r->ireg[0x35];
688- if (dy == 0){
689- dy = dx;
690- }
691- if (r->ireg[0x32] == -1) {
692- r->ireg[0x32] = mainWindow.xsize / dx; r->ireg[0x36] &= 0;
693- }
694- if (r->ireg[0x33] == -1) {
695- r->ireg[0x33] = mainWindow.ysize / dy; r->ireg[0x37] &= 0;
696- }
697- for (y = 0; y < r->ireg[0x33]; y++) {
698- y0 = y * dy + r->ireg[0x37];
699- for (x = 0; x < r->ireg[0x32]; x++) {
700- x0 = x * dx + r->ireg[0x36];
701- c = iColor1[*puc++];
702- devFunc0004(mod3, x0, y0, x0 + dx, y0 + dy, c);
703- }
704- puc += r->ireg[0x38];
705- }
706- break;
707-
708- default:
709- printf("devFunc: error: R30=%08X\n", r->ireg[0x30]);
710- exit(EXIT_FAILURE);
711-
615+ double dcx1 = 0.5 * (r->ireg[0x32] - (1 + DRAWOVALPARAM * 2));
616+ double dcy1 = 0.5 * (r->ireg[0x33] - (1 + DRAWOVALPARAM * 2));
617+ double dcxy1 = (dcx1 + 0.5) * (dcy1 + 0.5) - 0.1;
618+ dcxy1 *= dcxy1;
619+ for (y = 0; y < y1; y++) {
620+ double dty = (y - dcy) * dcx;
621+ double dty1 = (y - dcy) * dcx1;
622+ for (x = 0; x < x1; x++) {
623+ double dtx = (x - dcx) * dcy;
624+ double dtx1 = (x - dcx) * dcy1;
625+ if (dtx * dtx + dty * dty > dcxy){
626+ continue;
627+ }
628+ if (DRAWOVALPARAM <= x && x < x1 - DRAWOVALPARAM && DRAWOVALPARAM <= y && y < y1 - DRAWOVALPARAM) {
629+ if (dtx1 * dtx1 + dty1 * dty1 < dcxy1){
630+ continue;
631+ }
632+ }
633+ switch (mod3) {
634+ case 0:
635+ mainWindow.vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * mainWindow.xsize] = c;
636+ break;
637+ case 1:
638+ mainWindow.vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * mainWindow.xsize] |= c;
639+ break;
640+ case 2:
641+ mainWindow.vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * mainWindow.xsize] ^= c;
642+ break;
643+ case 3:
644+ mainWindow.vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * mainWindow.xsize] &= c;
645+ break;
646+ }
647+ }
648+ }
649+ }
650+ break;
651+
652+ case 0xff48: // drawString(opt:R31, xsiz:R32, ysiz:R33, x0:R34, y0:R35, c:R36, s.len:R37, s.p:P31)
653+ checkString(r, 0x37, 0x31);
654+ devFunc0006(r->ireg[0x31], r->ireg[0x32], r->ireg[0x33], r->ireg[0x34], r->ireg[0x35], loadColor(r, 0x36), r->ireg[0x37], r->preg[0x31].p, r);
655+ break;
656+
657+ case 0xff49:
658+ // **** junkApi_rand(i, max) ****
659+ // 0 <= i <= maxとなるiを返す。
660+ // max==0のとき、iはSINT32全体を範囲とする乱数となる。
661+ r->ireg[0x30] = randGetNextUInt32();
662+ if (r->ireg[0x31] > 0){
663+ r->ireg[0x30] = (r->ireg[0x30] & 0x7fffffff) % (r->ireg[0x31] + 1);
664+ }
665+ break;
666+
667+ case 0xff4a: /* seedの指定 */
668+ randStatInit(r->ireg[0x31]);
669+ break;
670+
671+ case 0xff4b: /* 適当なseedを提供 */
672+ r->ireg[0x30] = (int)(time(NULL) ^ (long)0x55555555);
673+ break;
674+
675+ case 0xff4c:
676+ checkString(r, 0x37, 0x31);
677+ len = devFunc0016(sizeof pucbuf, pucbuf, r->ireg[0x37], r->preg[0x31].p, r->ireg[0x38], (int *)r->preg[0x32].p, r);
678+ devFunc0006(r->ireg[0x31], r->ireg[0x32], r->ireg[0x33], r->ireg[0x34], r->ireg[0x35], loadColor(r, 0x36), len, pucbuf, r);
679+ break;
680+
681+ case 0xff4d:
682+ // bitblt(mod, xsiz, ysiz, xscale, yscale, x0, y0, lineskip, inv, p_buf, typ0, p_table, typ1);
683+ // mod: 0x20:use_table, 0x40:inv_is_visible & typ1_is_color
684+ puc = r->preg[0x31].p;
685+ mod3 = r->ireg[0x31] & 3;
686+ dx = r->ireg[0x34];
687+ dy = r->ireg[0x35];
688+ if (dy == 0){
689+ dy = dx;
690+ }
691+ if (r->ireg[0x32] == -1) {
692+ r->ireg[0x32] = mainWindow.xsize / dx; r->ireg[0x36] &= 0;
693+ }
694+ if (r->ireg[0x33] == -1) {
695+ r->ireg[0x33] = mainWindow.ysize / dy; r->ireg[0x37] &= 0;
696+ }
697+ for (y = 0; y < r->ireg[0x33]; y++) {
698+ y0 = y * dy + r->ireg[0x37];
699+ for (x = 0; x < r->ireg[0x32]; x++) {
700+ x0 = x * dx + r->ireg[0x36];
701+ c = iColor1[*puc++];
702+ devFunc0004(mod3, x0, y0, x0 + dx, y0 + dy, c);
703+ }
704+ puc += r->ireg[0x38];
705+ }
706+ break;
707+
708+ default:
709+ printf("devFunc: error: R30=%08X\n", r->ireg[0x30]);
710+ exit(EXIT_FAILURE);
711+
712712 }
713713 return;
714714 }
--- a/main.c
+++ b/main.c
@@ -22,82 +22,82 @@ void putKeybuf(int i)
2222
2323 int HeavyOSECPUMain(int argc, char **argv)
2424 {
25- FILE *fp;
26- unsigned char *jitbuf, *sysjit00, *sysjit;
27- unsigned char *systmp0, *systmp1, *systmp2;
28- unsigned char *opTbl;
29- HOSECPU_LabelListTag *label;
30- int tmpsiz, i;
31- jmp_buf setjmpEnv;
25+ FILE *fp;
26+ unsigned char *jitbuf, *sysjit00, *sysjit;
27+ unsigned char *systmp0, *systmp1, *systmp2;
28+ unsigned char *opTbl;
29+ HOSECPU_LabelListTag *label;
30+ int tmpsiz, i;
31+ jmp_buf setjmpEnv;
3232 double tm0, tm1, tm2;
3333 HOSECPU_PointerControlTag *ptrCtrl;
34- unsigned char *syslib;
35- int argDebug = 0, stacksiz = 1;
36- const char *cp;
37- HOSECPU_RuntimeEnvironment env;
34+ unsigned char *syslib;
35+ int argDebug = 0, stacksiz = 1;
36+ const char *cp;
37+ HOSECPU_RuntimeEnvironment env;
3838 void(*jitfunc)(char *);
39- unsigned char *jp;
40-
41- //Initialize mainWindow
42- mainWindow.vram = NULL;
43- mainWindow.xsize = 0;
44- mainWindow.ysize = 0;
45- di1_serial = 0;
46-
47- //実行環境初期化
48- env.mainArgc = argc;
49- env.mainArgv = (const char **)argv;
50- env.appBin = malloc(APPSIZ1);
51- env.executionLevel = JITC_LV_SLOWEST;
39+ unsigned char *jp;
40+
41+ //Initialize mainWindow
42+ mainWindow.vram = NULL;
43+ mainWindow.xsize = 0;
44+ mainWindow.ysize = 0;
45+ di1_serial = 0;
46+
47+ //実行環境初期化
48+ env.mainArgc = argc;
49+ env.mainArgv = (const char **)argv;
50+ env.appBin = malloc(APPSIZ1);
51+ env.executionLevel = JITC_LV_SLOWEST;
5252 jitbuf = mallocRWE(1024 * 1024); /* とりあえず1MBで */
5353 //unsigned char *sysjit0 = mallocRWE(SJITSIZ1), *sysjit1 = sysjit0, *sysjit00 = sysjit0;
5454 // syslib.oseのjitc結果を格納する領域を確保。
5555 sysjit00 = mallocRWE(SJITSIZ1);
56- sysjit = sysjit00;
56+ sysjit = sysjit00;
5757 // 現在の、jitc結果を格納するメモリへの書き込み位置のアドレス
58- // sysjit: 現在のjitc書き込み位置
59- // sysjit00: jitc結果の先頭
60- //ワークメモリを三つくらいもらう
58+ // sysjit: 現在のjitc書き込み位置
59+ // sysjit00: jitc結果の先頭
60+ //ワークメモリを三つくらいもらう
6161 systmp0 = malloc(SYSTMP0SIZ); /* syslibのjitc用 */
6262 systmp1 = malloc(SYSTMP1SIZ);
6363 systmp2 = malloc(1024 * 1024);
64-
65- opTbl = malloc(256);
64+
65+ opTbl = malloc(256);
6666 label = malloc(JITC_MAXLABELS * sizeof (HOSECPU_LabelListTag));
6767 keybuf = malloc(KEYBUFSIZ * sizeof (int));
6868 keybuf_r = keybuf_w = keybuf_c = 0;
6969 ptrCtrl = malloc(PTRCTRLSIZ * sizeof (HOSECPU_PointerControlTag));
70-
70+
7171 randStatInit((unsigned int)time(NULL));
7272 for (i = 0; i < PTRCTRLSIZ; i++) {
7373 ptrCtrl[i].liveSign = 0;
7474 ptrCtrl[i].size = -1;
7575 }
7676 ptrCtrl[0].size = -2;
77-
78- /* syslibの読み込み */
79- syslib = Init_LoadSysLib(argv[0], systmp0);
80-
81- sysjit = jitCompInit(sysjit);
82- sysjit00 = sysjit;
77+
78+ /* syslibの読み込み */
79+ syslib = Init_LoadSysLib(argv[0], systmp0);
80+
81+ sysjit = jitCompInit(sysjit);
82+ sysjit00 = sysjit;
8383 // labelはjitc0()内で初期化される。
8484 i = jitc0(&sysjit, sysjit00 + SJITSIZ1, syslib + 32, syslib + SYSLIBSIZ1, JITC_LV_SLOWEST+9, label);
8585 if (i != 0){
8686 fputs("syslib-file JITC error.\n", stderr);
8787 return 1;
8888 }
89-
89+
9090 // エラー時にデバッグ用に表示する変数を加算
9191 di1_serial++;
92-
93- /* アプリバイナリの読み込み */
94- LoadAppBin(&env);
95-
96- /* クロック初期化 */
92+
93+ /* アプリバイナリの読み込み */
94+ LoadAppBin(&env);
95+
96+ /* クロック初期化 */
9797 tm0 = clock() / (double)CLOCKS_PER_SEC;
98-
98+
9999 if (env.appBin[2] == 0xf0) {
100- // tek5圧縮がかかっている
100+ // tek5圧縮がかかっている
101101 #if (USE_TEK5 != 0)
102102 env.appSize1 = tek5Decomp(env.appBin + 2, env.appBin + env.appSize0, systmp0) + 2;
103103 #else
@@ -108,18 +108,18 @@ int HeavyOSECPUMain(int argc, char **argv)
108108 return 1;
109109 }
110110 }
111- //デバッグモード指定
111+ //デバッグモード指定
112112 cp = searchArg(argc, (const char **)argv, "debug:", 0);
113113 if (cp != NULL){
114- argDebug = *cp - '0';
115- }
116- //スタックサイズ指定(MiB単位)
114+ argDebug = *cp - '0';
115+ }
116+ //スタックサイズ指定(MiB単位)
117117 cp = searchArg(argc, (const char **)argv, "stack:", 0);
118118 if (cp != NULL){
119- stacksiz = strtol(cp, NULL, 0);
120- }
119+ stacksiz = strtol(cp, NULL, 0);
120+ }
121121 jp = jitbuf; /* JIT-pointer */
122-
122+
123123 /* フロントエンドコードをバックエンドコードに変換する */
124124 if ((env.appBin[2] & 0xf0) != 0) {
125125 systmp0[0] = env.appBin[0];
@@ -152,43 +152,43 @@ int HeavyOSECPUMain(int argc, char **argv)
152152 memcpy(systmp0, env.appBin, env.appSize1);
153153 tmpsiz = env.appSize1;
154154 }
155-
155+
156156 if ((argDebug & 2) != 0) {
157- /*変換後のバックエンドコードをファイルへ保存*/
157+ /*変換後のバックエンドコードをファイルへ保存*/
158158 fp = fopen("debug2.bin", "wb");
159159 fwrite(systmp0, 1, tmpsiz, fp);
160160 fclose(fp);
161161 }
162-
163- //JITコンパイル
162+
163+ //JITコンパイル
164164 i = jitc0(&jp, jitbuf + 1024 * 1024, systmp0, systmp0 + tmpsiz, env.executionLevel, label);
165165 if (i == 1){
166- fputs("app-file header error.\n", stderr);
166+ fputs("app-file header error.\n", stderr);
167167 return 1;
168- }
168+ }
169169 if (i != 0){
170- return 1;
171- }
170+ return 1;
171+ }
172172 di1_serial++;
173-
173+
174174 int appsiz2 = jp - jitbuf;
175-
175+
176176 unsigned char *p28 = jp;
177177 jp = jitCompCallFunc(jp, &devFunc);
178-
178+
179179 tm1 = clock() / (double)CLOCKS_PER_SEC;
180-
180+
181181 /* レジスタ初期化 */
182182 for (i = 0; i < 64; i++){
183183 env.ireg[i] = 0;
184- }
184+ }
185185 for (i = 0; i < 64; i++) {
186186 env.preg[i].p = NULL;
187187 env.preg[i].typ = -1;
188188 env.preg[i].p0 = NULL;
189189 env.preg[i].p1 = NULL;
190190 }
191-
191+
192192 env.buf0 = env.buf1 = NULL;
193193 env.preg[0x28].p = p28;
194194 env.preg[0x28].typ = 0; // TYP_CODE
@@ -201,43 +201,43 @@ int HeavyOSECPUMain(int argc, char **argv)
201201 env.autoSleep = 0;
202202 env.setjmpEnv = &setjmpEnv;
203203 env.lastConsoleChar = '\n';
204-
204+
205205 env.label = label;
206206 env.maxLabels = JITC_MAXLABELS;
207207 env.jitbuf = jp;
208208 env.jitbuf1 = jitbuf + 1024 * 1024;
209209 env.errHndl = &errorHandler;
210-
210+
211211 env.dbgr = 0;
212212 if (searchArg(argc, (const char **)argv, "dbgr:1", 0) != NULL){
213- env.dbgr = 1;
214- }
215-
213+ env.dbgr = 1;
214+ }
215+
216216 if ((argDebug & 1) != 0) {
217217 fp = fopen("debug1.bin", "wb");
218218 fwrite(jitbuf, 1, jp - jitbuf, fp);
219219 fclose(fp);
220220 }
221-
221+
222222 /* JITコード実行 */
223223 jitfunc = (void *)jitbuf;
224224 if (setjmp(setjmpEnv) == 0){
225225 (*jitfunc)(((char *)&env) + 128); /* サイズを節約するためにEBPを128バイトずらす */
226- }
226+ }
227227 if (env.autoSleep != 0) {
228228 if (mainWindow.vram != NULL){
229229 drv_flshWin(mainWindow.xsize, mainWindow.ysize, 0, 0);
230- }
230+ }
231231 while (env.winClosed == 0){
232232 drv_sleep(100);
233- }
233+ }
234234 }
235235 if (env.lastConsoleChar != '\n'){
236236 putchar('\n');
237- }
238-
237+ }
238+
239239 tm2 = clock() / (double)CLOCKS_PER_SEC;
240-
240+
241241 /* 実行結果確認のためのレジスタダンプ */
242242 if (searchArg(argc, (const char **)argv, "verbose:1", 0) != NULL) {
243243 printf("time: JITC=%.3f[sec], exec=%.3f[sec]\n", tm1 - tm0, tm2 - tm1);
@@ -253,12 +253,12 @@ int HeavyOSECPUMain(int argc, char **argv)
253253
254254 unsigned char *Init_LoadSysLib(char argv0[], unsigned char *tmpWorkMemory)
255255 {
256- unsigned char *syslib;
257- FILE *fp;
258- unsigned char *up;
259- int appsize;
260-
261- /* syslibの読み込み */
256+ unsigned char *syslib;
257+ FILE *fp;
258+ unsigned char *up;
259+ int appsize;
260+
261+ /* syslibの読み込み */
262262 syslib = malloc(SYSLIBSIZ1);
263263 fp = fopen(SYSLIB_OSE, "rb");
264264 if (fp == NULL) {
@@ -266,18 +266,18 @@ unsigned char *Init_LoadSysLib(char argv0[], unsigned char *tmpWorkMemory)
266266 strcpy((char *)syslib + 1, argv0);
267267 up = syslib + 1;
268268 while (*up != '\0'){
269- up++;
270- }
269+ up++;
270+ }
271271 while (*up != '/' && *up != 0x5c){
272- up--;
273- }
272+ up--;
273+ }
274274 up++;
275275 strcpy((char *)up, SYSLIB_OSE);
276276 fp = fopen((char *)syslib + 1, "rb");
277277 }
278278 if (fp == NULL) {
279279 fputs("syslib-file fopen error.\n", stderr);
280- exit(EXIT_FAILURE);
280+ exit(EXIT_FAILURE);
281281 }
282282 appsize = fread(syslib, 1, SYSLIBSIZ1 - 4, fp);
283283 fclose(fp);
@@ -292,41 +292,41 @@ unsigned char *Init_LoadSysLib(char argv0[], unsigned char *tmpWorkMemory)
292292 syslib[0] = 0x05;
293293 syslib[1] = 0x1b;
294294 }
295-
295+
296296 fp = fopen("syslib_dbg.ose", "wb");
297297 fwrite(syslib, 1, SYSLIBSIZ1, fp);
298298 fclose(fp);
299- return syslib;
299+ return syslib;
300300 }
301301
302302 void LoadAppBin(HOSECPU_RuntimeEnvironment *env)
303303 {
304- FILE *fp;
305- const char *fileName;
304+ FILE *fp;
305+ const char *fileName;
306306 /* アプリバイナリの読み込み */
307307 if (env->mainArgc <= 1) {
308- //アプリ名未指定なので何事もなく終了
309- exit(EXIT_SUCCESS);
310- }
308+ //アプリ名未指定なので何事もなく終了
309+ exit(EXIT_SUCCESS);
310+ }
311311 fileName = env->mainArgv[1];
312- //アプリ名先頭に:n:をつけることでレベルnでの実行が可能?
312+ //アプリ名先頭に:n:をつけることでレベルnでの実行が可能?
313313 if (fileName[0] == ':' && fileName[2] == ':') {
314314 env->executionLevel = fileName[1] - '0';
315315 if (env->executionLevel < 0 || env->executionLevel > 9){
316316 env->executionLevel = JITC_LV_SLOWEST;
317- }
317+ }
318318 fileName += 3;
319319 }
320-
320+
321321 fp = fopen(fileName, "rb");
322322 if (fp == NULL) {
323323 fputs("app-file load error.\n", stderr);
324324 exit(EXIT_FAILURE);
325325 }
326326 env->appSize0 = fread(env->appBin, 1, APPSIZ1 - 4, fp);
327- env->appSize1 = env->appSize0;
327+ env->appSize1 = env->appSize0;
328328 fclose(fp);
329-
329+
330330 if (env->appSize0 >= APPSIZ1 - 4) {
331331 fputs("app-file too large.\n", stderr);
332332 exit(EXIT_FAILURE);
--- a/randmt.c
+++ b/randmt.c
@@ -28,19 +28,19 @@ void randStatInit(unsigned seed)
2828 randStat.stat[3] = randStat.tmat = 0x3793fdff;
2929 for (i = 1; i < 8; i++){
3030 randStat.stat[i & 3] ^= i + ((unsigned)1812433253) * (randStat.stat[(i - 1) & 3] ^ (randStat.stat[(i - 1) & 3] >> 30));
31- }
31+ }
3232 for (i = 0; i < 8; i++){
3333 randStatNext();
34- }
34+ }
3535 return;
3636 }
3737
3838 unsigned int randGetNextUInt32(void)
3939 {
40- //次の乱数を取得する。
41- unsigned int u32t;
42-
43- randStatNext();
44- u32t = randStat.stat[0] + (randStat.stat[2] >> 8);
45- return (randStat.stat[3] ^ u32t ^ (-((int)(u32t & 1)) & randStat.tmat));
40+ //次の乱数を取得する。
41+ unsigned int u32t;
42+
43+ randStatNext();
44+ u32t = randStat.stat[0] + (randStat.stat[2] >> 8);
45+ return (randStat.stat[3] ^ u32t ^ (-((int)(u32t & 1)) & randStat.tmat));
4646 }
--- a/screen.c
+++ b/screen.c
@@ -4,9 +4,9 @@ void putOsaskChar(int c, HOSECPU_RuntimeEnvironment *r)
44 {
55 if (0x10 <= c && c <= 0x1f){
66 c = "0123456789ABCDEF"[c & 0x0f];
7- }
7+ }
88 putchar(c);
9- r->lastConsoleChar = c;
9+ r->lastConsoleChar = c;
1010 return;
1111 }
1212
@@ -14,39 +14,39 @@ void checkString(HOSECPU_RuntimeEnvironment *r, int rxx, int pxx)
1414 {
1515 char c = 0;
1616 if (r->preg[pxx].typ != 0x03){
17- c = 1;
18- }
17+ c = 1;
18+ }
1919 if (r->preg[pxx].p < r->preg[pxx].p0){
20- c = 1;
21- }
20+ c = 1;
21+ }
2222 if (r->ireg[rxx] < 0){
23- c = 1;
24- }
23+ c = 1;
24+ }
2525 if (r->preg[pxx].p + r->ireg[rxx] > r->preg[pxx].p1){
26- c = 1;
27- }
26+ c = 1;
27+ }
2828 if (c != 0){
2929 (*(r->errHndl))(r);
30- }
30+ }
3131 return;
3232 }
3333
3434 int loadColor(HOSECPU_RuntimeEnvironment *r, int rxx)
3535 {
3636 int c, m, rr, gg, bb;
37- c = r->ireg[rxx];
38- m = r->ireg[0x31] & 0x0c;
37+ c = r->ireg[rxx];
38+ m = r->ireg[0x31] & 0x0c;
3939 if (m == 0x04) {
4040 if (c < -1 || c > 7){
4141 (*(r->errHndl))(r);
42- }
42+ }
4343 c = iColor1[c & 0x07];
4444 }
4545 if (m == 0x08) {
4646 // 00, 24, 48, 6d, 91, b6, da, ff
4747 if (c < 0 || c >= (1 << 9)){
4848 (*(r->errHndl))(r);
49- }
49+ }
5050 rr = (c >> 6) & 0x07;
5151 gg = (c >> 3) & 0x07;
5252 bb = c & 0x07;
@@ -62,7 +62,7 @@ int loadColor(HOSECPU_RuntimeEnvironment *r, int rxx)
6262 // c5, cd, d5, de, e6, ee, f6, ff
6363 if (c < 0 || c >= (1 << 15)){
6464 (*(r->errHndl))(r);
65- }
65+ }
6666 rr = (c >> 10) & 0x1f;
6767 gg = (c >> 5) & 0x1f;
6868 bb = c & 0x1f;
@@ -79,27 +79,27 @@ void checkRect(HOSECPU_RuntimeEnvironment *r, int rxx)
7979 char c = 0;
8080 int i;
8181 if (r->ireg[rxx + 0] <= 0 || r->ireg[rxx + 0] > mainWindow.xsize){
82- c = 1;
83- }
82+ c = 1;
83+ }
8484 if (r->ireg[rxx + 1] <= 0 || r->ireg[rxx + 1] > mainWindow.ysize){
85- c = 1;
86- }
85+ c = 1;
86+ }
8787 if (r->ireg[rxx + 2] < 0 || r->ireg[rxx + 2] >= mainWindow.xsize){
88- c = 1;
89- }
88+ c = 1;
89+ }
9090 if (r->ireg[rxx + 3] < 0 || r->ireg[rxx + 3] >= mainWindow.ysize){
91- c = 1;
92- }
91+ c = 1;
92+ }
9393 i = r->ireg[rxx + 2] + r->ireg[rxx + 0];
94- if (i <= 0 || i > mainWindow.xsize){
95- c = 1;
96- }
94+ if (i <= 0 || i > mainWindow.xsize){
95+ c = 1;
96+ }
9797 i = r->ireg[rxx + 1] + r->ireg[rxx + 3];
98- if (i <= 0 || i > mainWindow.ysize){
99- c = 1;
100- }
98+ if (i <= 0 || i > mainWindow.ysize){
99+ c = 1;
100+ }
101101 if (c != 0){
102102 (*(r->errHndl))(r);
103- }
103+ }
104104 return;
105105 }
\ No newline at end of file
Show on old repository browser