Revisión | dc219dc26bb29772407f674143fe486ab0d2e844 (tree) |
---|---|
Tiempo | 2014-03-12 18:22:08 |
Autor | ttwilb <ttwilb@user...> |
Commiter | ttwilb |
インデントをタブに統一
@@ -8,8 +8,8 @@ struct ComLib_Str { | ||
8 | 8 | |
9 | 9 | int ComLib_getBit(struct ComLib_Str *s) |
10 | 10 | { |
11 | - //ビットを一つずつ取り出す | |
12 | - if (s->bitBufLen == 0) { | |
11 | + //ビットを一つずつ取り出す | |
12 | + if (s->bitBufLen == 0) { | |
13 | 13 | s->bitBuf = s->p[0] | s->p[1] << 8; |
14 | 14 | s->p += 2; |
15 | 15 | s->bitBufLen = 16; |
@@ -20,14 +20,14 @@ int ComLib_getBit(struct ComLib_Str *s) | ||
20 | 20 | |
21 | 21 | int ComLib_getTmpBit(struct ComLib_Str *s) |
22 | 22 | { |
23 | - //次のビットをtmpの一番下のビットに押し込んで、その次のビットを返す | |
23 | + //次のビットをtmpの一番下のビットに押し込んで、その次のビットを返す | |
24 | 24 | s->tmp = (s->tmp << 1 | ComLib_getBit(s)) & 0xffff; |
25 | 25 | return ComLib_getBit(s); |
26 | 26 | } |
27 | 27 | |
28 | 28 | unsigned char *ComLib_main(const unsigned char *p, unsigned char *q) |
29 | 29 | { |
30 | - //hh4デコーダー? | |
30 | + //hh4デコーダー? | |
31 | 31 | struct ComLib_Str s; |
32 | 32 | int i, dis = 0; |
33 | 33 | dis |= -1; |
@@ -39,19 +39,19 @@ l0: | ||
39 | 39 | l1: |
40 | 40 | i = ComLib_getBit(&s); |
41 | 41 | if (i != 0){ |
42 | - //4bit? | |
43 | - goto l0; | |
44 | - } | |
42 | + //4bit? | |
43 | + goto l0; | |
44 | + } | |
45 | 45 | s.tmp = 1; |
46 | 46 | do { |
47 | 47 | i = ComLib_getTmpBit(&s); |
48 | 48 | if (s.tmp == 0){ |
49 | - goto fin; | |
50 | - } | |
49 | + goto fin; | |
50 | + } | |
51 | 51 | } while (i == 0); |
52 | 52 | if (s.tmp >= 3){ |
53 | 53 | dis = ~((s.tmp - 3) << 8 | *s.p++); |
54 | - } | |
54 | + } | |
55 | 55 | s.tmp &= 0; |
56 | 56 | i = ComLib_getTmpBit(&s); |
57 | 57 | s.tmp = s.tmp << 1 | i; |
@@ -64,11 +64,11 @@ l1: | ||
64 | 64 | } |
65 | 65 | s.tmp++; |
66 | 66 | if (dis < -0xd00){ |
67 | - s.tmp++; | |
68 | - } | |
67 | + s.tmp++; | |
68 | + } | |
69 | 69 | for (i = 0; i < s.tmp; i++){ |
70 | 70 | q[i] = q[i + dis]; |
71 | - } | |
71 | + } | |
72 | 72 | q += s.tmp; |
73 | 73 | goto l1; |
74 | 74 | fin: |
@@ -19,9 +19,9 @@ NSApplication* app; | ||
19 | 19 | |
20 | 20 | @interface OSECPUView : NSView |
21 | 21 | { |
22 | - unsigned char *_buf; | |
23 | - int _sx; | |
24 | - int _sy; | |
22 | + unsigned char *_buf; | |
23 | + int _sx; | |
24 | + int _sy; | |
25 | 25 | CGContextRef _context; |
26 | 26 | } |
27 | 27 |
@@ -32,34 +32,34 @@ NSApplication* app; | ||
32 | 32 | @implementation OSECPUView |
33 | 33 | - (id)initWithFrame:(NSRect)frameRect buf:(unsigned char *)buf sx:(int)sx sy:(int)sy |
34 | 34 | { |
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; | |
42 | 42 | } |
43 | 43 | |
44 | 44 | - (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); | |
53 | 53 | } |
54 | 54 | |
55 | 55 | @end |
56 | 56 | |
57 | 57 | @interface Main : NSObject<NSWindowDelegate> |
58 | 58 | { |
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; | |
63 | 63 | } |
64 | 64 | |
65 | 65 | - (void)runApp; |
@@ -72,29 +72,29 @@ NSApplication* app; | ||
72 | 72 | @implementation Main |
73 | 73 | - (void)runApp |
74 | 74 | { |
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]; | |
78 | 78 | [pool release]; |
79 | 79 | } |
80 | 80 | |
81 | 81 | - (void)createThread : (int)_argc args:(const unsigned char **)_argv |
82 | 82 | { |
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]; | |
87 | 87 | } |
88 | 88 | |
89 | 89 | - (BOOL)windowShouldClose:(id)sender |
90 | 90 | { |
91 | - *winClosed = 1; | |
92 | - return YES; | |
91 | + *winClosed = 1; | |
92 | + return YES; | |
93 | 93 | } |
94 | 94 | |
95 | 95 | - (void)openWin:(unsigned char *)buf sx:(int)sx sy:(int) sy winClosed:(char *)_winClosed |
96 | 96 | { |
97 | - | |
97 | + | |
98 | 98 | NSWindow* window = [[NSWindow alloc] initWithContentRect: NSMakeRect(0, 0, sx, sy) styleMask: NSTitledWindowMask | NSMiniaturizableWindowMask | NSClosableWindowMask backing: NSBackingStoreBuffered defer: NO]; |
99 | 99 | [window setTitle: @"osecpu"]; |
100 | 100 | [window center]; |
@@ -102,14 +102,14 @@ NSApplication* app; | ||
102 | 102 | [window setReleasedWhenClosed:YES]; |
103 | 103 | window.delegate = self; |
104 | 104 | winClosed = _winClosed; |
105 | - | |
105 | + | |
106 | 106 | _view = [[OSECPUView alloc] initWithFrame:NSMakeRect(0,0,sx,sy) buf:buf sx:sx sy:sy]; |
107 | 107 | [window.contentView addSubview:_view]; |
108 | 108 | } |
109 | 109 | |
110 | 110 | - (void)flushWin : (NSRect)rect |
111 | 111 | { |
112 | - [_view drawRect:rect]; | |
112 | + [_view drawRect:rect]; | |
113 | 113 | } |
114 | 114 | |
115 | 115 | @end |
@@ -118,30 +118,30 @@ id objc_main; | ||
118 | 118 | |
119 | 119 | int main(int argc, char **argv) |
120 | 120 | { |
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]; | |
127 | 127 | [pool release]; |
128 | - return 0; | |
128 | + return 0; | |
129 | 129 | } |
130 | 130 | |
131 | 131 | void drv_openWin(int sx, int sy, unsigned char *buf, char *winClosed) |
132 | 132 | { |
133 | - [objc_main openWin:buf sx:sx sy:sy winClosed:winClosed]; | |
133 | + [objc_main openWin:buf sx:sx sy:sy winClosed:winClosed]; | |
134 | 134 | } |
135 | 135 | |
136 | 136 | void drv_flshWin(int sx, int sy, int x0, int y0) |
137 | 137 | { |
138 | - [objc_main flushWin:NSMakeRect(x0,y0,sx,sy)]; | |
138 | + [objc_main flushWin:NSMakeRect(x0,y0,sx,sy)]; | |
139 | 139 | } |
140 | 140 | |
141 | 141 | void drv_sleep(int msec) |
142 | 142 | { |
143 | - [NSThread sleepForTimeInterval:0.001*msec]; | |
144 | - return; | |
143 | + [NSThread sleepForTimeInterval:0.001*msec]; | |
144 | + return; | |
145 | 145 | } |
146 | 146 | |
147 | 147 |
@@ -230,10 +230,10 @@ static int winthread(void *dmy) | ||
230 | 230 | RECT r; |
231 | 231 | int i, x, y; |
232 | 232 | MSG msg; |
233 | - | |
233 | + | |
234 | 234 | x = dw.bmi.bmiHeader.biWidth; |
235 | 235 | y = -dw.bmi.bmiHeader.biHeight; |
236 | - | |
236 | + | |
237 | 237 | wc.cbSize = sizeof (WNDCLASSEX); |
238 | 238 | wc.style = CS_HREDRAW | CS_VREDRAW; |
239 | 239 | wc.lpfnWndProc = WndProc; |
@@ -241,10 +241,10 @@ static int winthread(void *dmy) | ||
241 | 241 | wc.cbWndExtra = 0; |
242 | 242 | wc.hInstance = dw.hi; |
243 | 243 | 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); | |
245 | 245 | wc.hIconSm = wc.hIcon; |
246 | 246 | 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); | |
248 | 248 | wc.hbrBackground = (HBRUSH)COLOR_APPWORKSPACE; |
249 | 249 | wc.lpszMenuName = NULL; |
250 | 250 | wc.lpszClassName = L"WinClass"; |
@@ -257,11 +257,11 @@ static int winthread(void *dmy) | ||
257 | 257 | AdjustWindowRect(&r, WS_OVERLAPPEDWINDOW, FALSE); |
258 | 258 | x = r.right - r.left; |
259 | 259 | y = r.bottom - r.top; |
260 | - | |
260 | + | |
261 | 261 | char *t = "osecpu"; |
262 | - | |
262 | + | |
263 | 263 | 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); | |
265 | 265 | if (dw.hw == NULL) |
266 | 266 | return 1; |
267 | 267 | ShowWindow(dw.hw, SW_SHOW); |
@@ -270,7 +270,7 @@ static int winthread(void *dmy) | ||
270 | 270 | SetTimer(dw.hw, TIMER_ID + 1, TIMER_INTERVAL * 10, NULL); |
271 | 271 | SetTimer(dw.hw, TIMER_ID + 2, TIMER_INTERVAL * 100, NULL); |
272 | 272 | dw.flags |= 2 | 4; |
273 | - | |
273 | + | |
274 | 274 | for (;;) { |
275 | 275 | i = GetMessage(&msg, NULL, 0, 0); |
276 | 276 | if (i == 0 || i == -1) /* エラーもしくは終了メッセージ */ |
@@ -289,7 +289,7 @@ static int winthread(void *dmy) | ||
289 | 289 | void bld_openWin(int sx, int sy, char *winClosed) |
290 | 290 | { |
291 | 291 | static int i; |
292 | - | |
292 | + | |
293 | 293 | dw.bmi.bmiHeader.biSize = sizeof (BITMAPINFOHEADER); |
294 | 294 | dw.bmi.bmiHeader.biWidth = sx; |
295 | 295 | dw.bmi.bmiHeader.biHeight = -sy; |
@@ -297,9 +297,9 @@ void bld_openWin(int sx, int sy, char *winClosed) | ||
297 | 297 | dw.bmi.bmiHeader.biBitCount = 32; |
298 | 298 | dw.bmi.bmiHeader.biCompression = BI_RGB; |
299 | 299 | dw.winClosed = winClosed; |
300 | - | |
300 | + | |
301 | 301 | threadhandle = CreateThread(NULL, 0, (void *)&winthread, NULL, 0, (void *)&i); |
302 | - | |
302 | + | |
303 | 303 | return; |
304 | 304 | } |
305 | 305 |
@@ -317,7 +317,7 @@ LRESULT CALLBACK WndProc(HWND hw, unsigned int msg, WPARAM wp, LPARAM lp) | ||
317 | 317 | PAINTSTRUCT ps; |
318 | 318 | HDC hdc = BeginPaint(dw.hw, &ps); |
319 | 319 | 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); | |
321 | 321 | EndPaint(dw.hw, &ps); |
322 | 322 | } |
323 | 323 | if (msg == WM_DESTROY) { |
@@ -340,7 +340,7 @@ LRESULT CALLBACK WndProc(HWND hw, unsigned int msg, WPARAM wp, LPARAM lp) | ||
340 | 340 | } |
341 | 341 | if (msg == WM_KEYDOWN || msg == WM_SYSKEYDOWN) { |
342 | 342 | i = -1; |
343 | - | |
343 | + | |
344 | 344 | if (wp == VK_RETURN) i = KEY_ENTER; |
345 | 345 | if (wp == VK_ESCAPE) i = KEY_ESC; |
346 | 346 | if (wp == VK_BACK) i = KEY_BACKSPACE; |
@@ -12,8 +12,8 @@ const char *searchArg(int argc, const char **argv, const char *tag, int i) | ||
12 | 12 | if (strncmp(argv[j], tag, l) == 0) { |
13 | 13 | r = argv[j] + l; |
14 | 14 | if (i == 0){ |
15 | - break; | |
16 | - } | |
15 | + break; | |
16 | + } | |
17 | 17 | i--; |
18 | 18 | } |
19 | 19 | } |
@@ -23,15 +23,15 @@ const char *searchArg(int argc, const char **argv, const char *tag, int i) | ||
23 | 23 | if (strchr(argv[j], ':') == NULL) { |
24 | 24 | r = argv[j]; |
25 | 25 | if (i == 0){ |
26 | - break; | |
27 | - } | |
26 | + break; | |
27 | + } | |
28 | 28 | i--; |
29 | 29 | } |
30 | 30 | } |
31 | 31 | } |
32 | 32 | if (i != 0){ |
33 | - r = NULL; | |
34 | - } | |
33 | + r = NULL; | |
34 | + } | |
35 | 35 | return r; |
36 | 36 | } |
37 | 37 |
@@ -46,23 +46,23 @@ void devFunc0001(int len, unsigned char *puc, HOSECPU_RuntimeEnvironment *r) | ||
46 | 46 | |
47 | 47 | void devFunc0006(int mod, int sx, int sy, int x, int y, int c, int len, unsigned char *puc, HOSECPU_RuntimeEnvironment *r) |
48 | 48 | { |
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 | + | |
53 | 53 | if (sy == 0){ |
54 | - sy = sx; | |
55 | - } | |
54 | + sy = sx; | |
55 | + } | |
56 | 56 | xx = x + sx * 8; |
57 | 57 | yy = y + sy * 16; |
58 | 58 | if (xx <= 0 || xx > mainWindow.xsize || yy <= 0 || yy > mainWindow.ysize){ |
59 | 59 | (*(r->errHndl))(r); |
60 | - } | |
60 | + } | |
61 | 61 | if (x < 0 || x >= mainWindow.xsize || y < 0 || y >= mainWindow.ysize){ |
62 | 62 | (*(r->errHndl))(r); |
63 | - } | |
63 | + } | |
64 | + | |
64 | 65 | |
65 | - | |
66 | 66 | if ((mod & 3) == 0 && sx == 1 && sy == 1) { |
67 | 67 | // メジャーケースを高速化. |
68 | 68 | 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 | ||
73 | 73 | j = fontdata[(ch - ' ') * 16 + dy]; |
74 | 74 | for (dx = 0; dx < 8; dx++) { |
75 | 75 | 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 | + } | |
78 | 78 | } |
79 | 79 | } |
80 | 80 | x += 8; |
@@ -91,25 +91,25 @@ void devFunc0006(int mod, int sx, int sy, int x, int y, int c, int len, unsigned | ||
91 | 91 | for (dx = 0; dx < 8; dx++) { |
92 | 92 | if ((j & (0x80 >> dx)) != 0) { |
93 | 93 | 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 | + } | |
108 | 108 | x++; |
109 | 109 | } |
110 | 110 | } else{ |
111 | 111 | x += sx; |
112 | - } | |
112 | + } | |
113 | 113 | } |
114 | 114 | x -= sx * 8; |
115 | 115 | y++; |
@@ -134,18 +134,18 @@ void devFunc0004(int mod, int x0, int y0, int x1, int y1, int c) | ||
134 | 134 | else { |
135 | 135 | for (y = y0; y <= y1; y++) { |
136 | 136 | 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 | + } | |
149 | 149 | } |
150 | 150 | } |
151 | 151 | return; |
@@ -155,11 +155,11 @@ int devFunc0016(int buflen, unsigned char *buf, int plen, unsigned char *p, int | ||
155 | 155 | { |
156 | 156 | int i = 0, base, j, k; |
157 | 157 | char sign; |
158 | - | |
158 | + | |
159 | 159 | while (plen > 0) { |
160 | 160 | if (i >= buflen){ |
161 | 161 | (*(r->errHndl))(r); |
162 | - } | |
162 | + } | |
163 | 163 | if (*p != 0x01) { |
164 | 164 | buf[i++] = *p++; |
165 | 165 | plen--; |
@@ -169,40 +169,40 @@ int devFunc0016(int buflen, unsigned char *buf, int plen, unsigned char *p, int | ||
169 | 169 | plen--; |
170 | 170 | if (qlen < 4){ |
171 | 171 | (*(r->errHndl))(r); |
172 | - } | |
172 | + } | |
173 | 173 | base = q[0]; |
174 | 174 | sign = 0; |
175 | 175 | if (base == 0){ |
176 | - base = 16; | |
177 | - } | |
176 | + base = 16; | |
177 | + } | |
178 | 178 | #if (REVISION == 1) |
179 | 179 | if (base == -3){ |
180 | - base = 10; | |
181 | - } | |
180 | + base = 10; | |
181 | + } | |
182 | 182 | #endif |
183 | 183 | if (base == -1){ |
184 | - base = 10; | |
185 | - } | |
184 | + base = 10; | |
185 | + } | |
186 | 186 | if (base < 0 || base > 16){ |
187 | 187 | (*(r->errHndl))(r); |
188 | - } | |
188 | + } | |
189 | 189 | if (q[1] + i > buflen){ |
190 | 190 | (*(r->errHndl))(r); |
191 | - } | |
191 | + } | |
192 | 192 | j = q[3]; |
193 | 193 | if ((q[2] & 4) == 0) { |
194 | 194 | // jは符号付き整数. |
195 | 195 | if ((q[2] & 8) != 0 && j > 0){ |
196 | - sign = '+'; | |
197 | - } | |
196 | + sign = '+'; | |
197 | + } | |
198 | 198 | if (j < 0) { |
199 | - sign = '-'; j *= -1; | |
200 | - } | |
199 | + sign = '-'; j *= -1; | |
200 | + } | |
201 | 201 | } else{ |
202 | 202 | // jは符号無し整数. |
203 | 203 | if ((q[2] & 8) != 0 && j != 0){ |
204 | - sign = '+'; | |
205 | - } | |
204 | + sign = '+'; | |
205 | + } | |
206 | 206 | } |
207 | 207 | for (k = q[1] - 1; k >= 0; k--) { |
208 | 208 | buf[i + k] = (j % base) + 0x10; |
@@ -212,25 +212,25 @@ int devFunc0016(int buflen, unsigned char *buf, int plen, unsigned char *p, int | ||
212 | 212 | if ((q[2] & 2) == 0 && j == 0) { |
213 | 213 | for (k = 0; k < q[1] - 1; k++) { |
214 | 214 | if (buf[i + k] != 0x10){ |
215 | - break; | |
216 | - } | |
215 | + break; | |
216 | + } | |
217 | 217 | buf[i + k] = ' '; |
218 | 218 | } |
219 | 219 | } |
220 | 220 | if (sign != 0) { |
221 | 221 | if (k > 0){ |
222 | - k--; | |
223 | - } | |
222 | + k--; | |
223 | + } | |
224 | 224 | buf[i + k] = sign; |
225 | 225 | } |
226 | 226 | if ((q[2] & 1) != 0 && buf[i] == ' ') { |
227 | 227 | for (j = 0; k < q[1]; k++, j++){ |
228 | 228 | buf[i + j] = buf[i + k]; |
229 | - } | |
229 | + } | |
230 | 230 | i += j; |
231 | 231 | } else{ |
232 | 232 | i += q[1]; |
233 | - } | |
233 | + } | |
234 | 234 | qlen -= 4; |
235 | 235 | q += 4; |
236 | 236 | } |
@@ -240,17 +240,17 @@ int devFunc0016(int buflen, unsigned char *buf, int plen, unsigned char *p, int | ||
240 | 240 | void devFunc(HOSECPU_RuntimeEnvironment *r) |
241 | 241 | { |
242 | 242 | FILE *fp; |
243 | - int i, c; | |
243 | + int i, c; | |
244 | 244 | int x, y, len, dx, dy; |
245 | 245 | unsigned char *puc; |
246 | 246 | unsigned char pucbuf[256]; |
247 | - | |
248 | - //サイズを節約するためにEBPを128バイトずらしているのを元に戻す | |
247 | + | |
248 | + //サイズを節約するためにEBPを128バイトずらしているのを元に戻す | |
249 | 249 | r = (HOSECPU_RuntimeEnvironment *) (((char *)r) - 128); |
250 | 250 | |
251 | 251 | if (r->winClosed != 0){ |
252 | 252 | longjmp(*(r->setjmpEnv), 1); |
253 | - } | |
253 | + } | |
254 | 254 | if (0xff44 <= r->ireg[0x30] && r->ireg[0x30] <= 0xff48) { |
255 | 255 | if (mainWindow.vram == NULL) { |
256 | 256 | mainWindow.xsize = 640; |
@@ -260,455 +260,455 @@ void devFunc(HOSECPU_RuntimeEnvironment *r) | ||
260 | 260 | r->autoSleep = 1; |
261 | 261 | for (i = 640 * 480 - 1; i >= 0; i--){ |
262 | 262 | mainWindow.vram[i] = 0; |
263 | - } | |
263 | + } | |
264 | 264 | } |
265 | 265 | } |
266 | - | |
266 | + | |
267 | 267 | 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 { | |
614 | 614 | #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 | + | |
712 | 712 | } |
713 | 713 | return; |
714 | 714 | } |
@@ -22,82 +22,82 @@ void putKeybuf(int i) | ||
22 | 22 | |
23 | 23 | int HeavyOSECPUMain(int argc, char **argv) |
24 | 24 | { |
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; | |
32 | 32 | double tm0, tm1, tm2; |
33 | 33 | 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; | |
38 | 38 | 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; | |
52 | 52 | jitbuf = mallocRWE(1024 * 1024); /* とりあえず1MBで */ |
53 | 53 | //unsigned char *sysjit0 = mallocRWE(SJITSIZ1), *sysjit1 = sysjit0, *sysjit00 = sysjit0; |
54 | 54 | // syslib.oseのjitc結果を格納する領域を確保。 |
55 | 55 | sysjit00 = mallocRWE(SJITSIZ1); |
56 | - sysjit = sysjit00; | |
56 | + sysjit = sysjit00; | |
57 | 57 | // 現在の、jitc結果を格納するメモリへの書き込み位置のアドレス |
58 | - // sysjit: 現在のjitc書き込み位置 | |
59 | - // sysjit00: jitc結果の先頭 | |
60 | - //ワークメモリを三つくらいもらう | |
58 | + // sysjit: 現在のjitc書き込み位置 | |
59 | + // sysjit00: jitc結果の先頭 | |
60 | + //ワークメモリを三つくらいもらう | |
61 | 61 | systmp0 = malloc(SYSTMP0SIZ); /* syslibのjitc用 */ |
62 | 62 | systmp1 = malloc(SYSTMP1SIZ); |
63 | 63 | systmp2 = malloc(1024 * 1024); |
64 | - | |
65 | - opTbl = malloc(256); | |
64 | + | |
65 | + opTbl = malloc(256); | |
66 | 66 | label = malloc(JITC_MAXLABELS * sizeof (HOSECPU_LabelListTag)); |
67 | 67 | keybuf = malloc(KEYBUFSIZ * sizeof (int)); |
68 | 68 | keybuf_r = keybuf_w = keybuf_c = 0; |
69 | 69 | ptrCtrl = malloc(PTRCTRLSIZ * sizeof (HOSECPU_PointerControlTag)); |
70 | - | |
70 | + | |
71 | 71 | randStatInit((unsigned int)time(NULL)); |
72 | 72 | for (i = 0; i < PTRCTRLSIZ; i++) { |
73 | 73 | ptrCtrl[i].liveSign = 0; |
74 | 74 | ptrCtrl[i].size = -1; |
75 | 75 | } |
76 | 76 | 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; | |
83 | 83 | // labelはjitc0()内で初期化される。 |
84 | 84 | i = jitc0(&sysjit, sysjit00 + SJITSIZ1, syslib + 32, syslib + SYSLIBSIZ1, JITC_LV_SLOWEST+9, label); |
85 | 85 | if (i != 0){ |
86 | 86 | fputs("syslib-file JITC error.\n", stderr); |
87 | 87 | return 1; |
88 | 88 | } |
89 | - | |
89 | + | |
90 | 90 | // エラー時にデバッグ用に表示する変数を加算 |
91 | 91 | di1_serial++; |
92 | - | |
93 | - /* アプリバイナリの読み込み */ | |
94 | - LoadAppBin(&env); | |
95 | - | |
96 | - /* クロック初期化 */ | |
92 | + | |
93 | + /* アプリバイナリの読み込み */ | |
94 | + LoadAppBin(&env); | |
95 | + | |
96 | + /* クロック初期化 */ | |
97 | 97 | tm0 = clock() / (double)CLOCKS_PER_SEC; |
98 | - | |
98 | + | |
99 | 99 | if (env.appBin[2] == 0xf0) { |
100 | - // tek5圧縮がかかっている | |
100 | + // tek5圧縮がかかっている | |
101 | 101 | #if (USE_TEK5 != 0) |
102 | 102 | env.appSize1 = tek5Decomp(env.appBin + 2, env.appBin + env.appSize0, systmp0) + 2; |
103 | 103 | #else |
@@ -108,18 +108,18 @@ int HeavyOSECPUMain(int argc, char **argv) | ||
108 | 108 | return 1; |
109 | 109 | } |
110 | 110 | } |
111 | - //デバッグモード指定 | |
111 | + //デバッグモード指定 | |
112 | 112 | cp = searchArg(argc, (const char **)argv, "debug:", 0); |
113 | 113 | if (cp != NULL){ |
114 | - argDebug = *cp - '0'; | |
115 | - } | |
116 | - //スタックサイズ指定(MiB単位) | |
114 | + argDebug = *cp - '0'; | |
115 | + } | |
116 | + //スタックサイズ指定(MiB単位) | |
117 | 117 | cp = searchArg(argc, (const char **)argv, "stack:", 0); |
118 | 118 | if (cp != NULL){ |
119 | - stacksiz = strtol(cp, NULL, 0); | |
120 | - } | |
119 | + stacksiz = strtol(cp, NULL, 0); | |
120 | + } | |
121 | 121 | jp = jitbuf; /* JIT-pointer */ |
122 | - | |
122 | + | |
123 | 123 | /* フロントエンドコードをバックエンドコードに変換する */ |
124 | 124 | if ((env.appBin[2] & 0xf0) != 0) { |
125 | 125 | systmp0[0] = env.appBin[0]; |
@@ -152,43 +152,43 @@ int HeavyOSECPUMain(int argc, char **argv) | ||
152 | 152 | memcpy(systmp0, env.appBin, env.appSize1); |
153 | 153 | tmpsiz = env.appSize1; |
154 | 154 | } |
155 | - | |
155 | + | |
156 | 156 | if ((argDebug & 2) != 0) { |
157 | - /*変換後のバックエンドコードをファイルへ保存*/ | |
157 | + /*変換後のバックエンドコードをファイルへ保存*/ | |
158 | 158 | fp = fopen("debug2.bin", "wb"); |
159 | 159 | fwrite(systmp0, 1, tmpsiz, fp); |
160 | 160 | fclose(fp); |
161 | 161 | } |
162 | - | |
163 | - //JITコンパイル | |
162 | + | |
163 | + //JITコンパイル | |
164 | 164 | i = jitc0(&jp, jitbuf + 1024 * 1024, systmp0, systmp0 + tmpsiz, env.executionLevel, label); |
165 | 165 | if (i == 1){ |
166 | - fputs("app-file header error.\n", stderr); | |
166 | + fputs("app-file header error.\n", stderr); | |
167 | 167 | return 1; |
168 | - } | |
168 | + } | |
169 | 169 | if (i != 0){ |
170 | - return 1; | |
171 | - } | |
170 | + return 1; | |
171 | + } | |
172 | 172 | di1_serial++; |
173 | - | |
173 | + | |
174 | 174 | int appsiz2 = jp - jitbuf; |
175 | - | |
175 | + | |
176 | 176 | unsigned char *p28 = jp; |
177 | 177 | jp = jitCompCallFunc(jp, &devFunc); |
178 | - | |
178 | + | |
179 | 179 | tm1 = clock() / (double)CLOCKS_PER_SEC; |
180 | - | |
180 | + | |
181 | 181 | /* レジスタ初期化 */ |
182 | 182 | for (i = 0; i < 64; i++){ |
183 | 183 | env.ireg[i] = 0; |
184 | - } | |
184 | + } | |
185 | 185 | for (i = 0; i < 64; i++) { |
186 | 186 | env.preg[i].p = NULL; |
187 | 187 | env.preg[i].typ = -1; |
188 | 188 | env.preg[i].p0 = NULL; |
189 | 189 | env.preg[i].p1 = NULL; |
190 | 190 | } |
191 | - | |
191 | + | |
192 | 192 | env.buf0 = env.buf1 = NULL; |
193 | 193 | env.preg[0x28].p = p28; |
194 | 194 | env.preg[0x28].typ = 0; // TYP_CODE |
@@ -201,43 +201,43 @@ int HeavyOSECPUMain(int argc, char **argv) | ||
201 | 201 | env.autoSleep = 0; |
202 | 202 | env.setjmpEnv = &setjmpEnv; |
203 | 203 | env.lastConsoleChar = '\n'; |
204 | - | |
204 | + | |
205 | 205 | env.label = label; |
206 | 206 | env.maxLabels = JITC_MAXLABELS; |
207 | 207 | env.jitbuf = jp; |
208 | 208 | env.jitbuf1 = jitbuf + 1024 * 1024; |
209 | 209 | env.errHndl = &errorHandler; |
210 | - | |
210 | + | |
211 | 211 | env.dbgr = 0; |
212 | 212 | if (searchArg(argc, (const char **)argv, "dbgr:1", 0) != NULL){ |
213 | - env.dbgr = 1; | |
214 | - } | |
215 | - | |
213 | + env.dbgr = 1; | |
214 | + } | |
215 | + | |
216 | 216 | if ((argDebug & 1) != 0) { |
217 | 217 | fp = fopen("debug1.bin", "wb"); |
218 | 218 | fwrite(jitbuf, 1, jp - jitbuf, fp); |
219 | 219 | fclose(fp); |
220 | 220 | } |
221 | - | |
221 | + | |
222 | 222 | /* JITコード実行 */ |
223 | 223 | jitfunc = (void *)jitbuf; |
224 | 224 | if (setjmp(setjmpEnv) == 0){ |
225 | 225 | (*jitfunc)(((char *)&env) + 128); /* サイズを節約するためにEBPを128バイトずらす */ |
226 | - } | |
226 | + } | |
227 | 227 | if (env.autoSleep != 0) { |
228 | 228 | if (mainWindow.vram != NULL){ |
229 | 229 | drv_flshWin(mainWindow.xsize, mainWindow.ysize, 0, 0); |
230 | - } | |
230 | + } | |
231 | 231 | while (env.winClosed == 0){ |
232 | 232 | drv_sleep(100); |
233 | - } | |
233 | + } | |
234 | 234 | } |
235 | 235 | if (env.lastConsoleChar != '\n'){ |
236 | 236 | putchar('\n'); |
237 | - } | |
238 | - | |
237 | + } | |
238 | + | |
239 | 239 | tm2 = clock() / (double)CLOCKS_PER_SEC; |
240 | - | |
240 | + | |
241 | 241 | /* 実行結果確認のためのレジスタダンプ */ |
242 | 242 | if (searchArg(argc, (const char **)argv, "verbose:1", 0) != NULL) { |
243 | 243 | printf("time: JITC=%.3f[sec], exec=%.3f[sec]\n", tm1 - tm0, tm2 - tm1); |
@@ -253,12 +253,12 @@ int HeavyOSECPUMain(int argc, char **argv) | ||
253 | 253 | |
254 | 254 | unsigned char *Init_LoadSysLib(char argv0[], unsigned char *tmpWorkMemory) |
255 | 255 | { |
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の読み込み */ | |
262 | 262 | syslib = malloc(SYSLIBSIZ1); |
263 | 263 | fp = fopen(SYSLIB_OSE, "rb"); |
264 | 264 | if (fp == NULL) { |
@@ -266,18 +266,18 @@ unsigned char *Init_LoadSysLib(char argv0[], unsigned char *tmpWorkMemory) | ||
266 | 266 | strcpy((char *)syslib + 1, argv0); |
267 | 267 | up = syslib + 1; |
268 | 268 | while (*up != '\0'){ |
269 | - up++; | |
270 | - } | |
269 | + up++; | |
270 | + } | |
271 | 271 | while (*up != '/' && *up != 0x5c){ |
272 | - up--; | |
273 | - } | |
272 | + up--; | |
273 | + } | |
274 | 274 | up++; |
275 | 275 | strcpy((char *)up, SYSLIB_OSE); |
276 | 276 | fp = fopen((char *)syslib + 1, "rb"); |
277 | 277 | } |
278 | 278 | if (fp == NULL) { |
279 | 279 | fputs("syslib-file fopen error.\n", stderr); |
280 | - exit(EXIT_FAILURE); | |
280 | + exit(EXIT_FAILURE); | |
281 | 281 | } |
282 | 282 | appsize = fread(syslib, 1, SYSLIBSIZ1 - 4, fp); |
283 | 283 | fclose(fp); |
@@ -292,41 +292,41 @@ unsigned char *Init_LoadSysLib(char argv0[], unsigned char *tmpWorkMemory) | ||
292 | 292 | syslib[0] = 0x05; |
293 | 293 | syslib[1] = 0x1b; |
294 | 294 | } |
295 | - | |
295 | + | |
296 | 296 | fp = fopen("syslib_dbg.ose", "wb"); |
297 | 297 | fwrite(syslib, 1, SYSLIBSIZ1, fp); |
298 | 298 | fclose(fp); |
299 | - return syslib; | |
299 | + return syslib; | |
300 | 300 | } |
301 | 301 | |
302 | 302 | void LoadAppBin(HOSECPU_RuntimeEnvironment *env) |
303 | 303 | { |
304 | - FILE *fp; | |
305 | - const char *fileName; | |
304 | + FILE *fp; | |
305 | + const char *fileName; | |
306 | 306 | /* アプリバイナリの読み込み */ |
307 | 307 | if (env->mainArgc <= 1) { |
308 | - //アプリ名未指定なので何事もなく終了 | |
309 | - exit(EXIT_SUCCESS); | |
310 | - } | |
308 | + //アプリ名未指定なので何事もなく終了 | |
309 | + exit(EXIT_SUCCESS); | |
310 | + } | |
311 | 311 | fileName = env->mainArgv[1]; |
312 | - //アプリ名先頭に:n:をつけることでレベルnでの実行が可能? | |
312 | + //アプリ名先頭に:n:をつけることでレベルnでの実行が可能? | |
313 | 313 | if (fileName[0] == ':' && fileName[2] == ':') { |
314 | 314 | env->executionLevel = fileName[1] - '0'; |
315 | 315 | if (env->executionLevel < 0 || env->executionLevel > 9){ |
316 | 316 | env->executionLevel = JITC_LV_SLOWEST; |
317 | - } | |
317 | + } | |
318 | 318 | fileName += 3; |
319 | 319 | } |
320 | - | |
320 | + | |
321 | 321 | fp = fopen(fileName, "rb"); |
322 | 322 | if (fp == NULL) { |
323 | 323 | fputs("app-file load error.\n", stderr); |
324 | 324 | exit(EXIT_FAILURE); |
325 | 325 | } |
326 | 326 | env->appSize0 = fread(env->appBin, 1, APPSIZ1 - 4, fp); |
327 | - env->appSize1 = env->appSize0; | |
327 | + env->appSize1 = env->appSize0; | |
328 | 328 | fclose(fp); |
329 | - | |
329 | + | |
330 | 330 | if (env->appSize0 >= APPSIZ1 - 4) { |
331 | 331 | fputs("app-file too large.\n", stderr); |
332 | 332 | exit(EXIT_FAILURE); |
@@ -28,19 +28,19 @@ void randStatInit(unsigned seed) | ||
28 | 28 | randStat.stat[3] = randStat.tmat = 0x3793fdff; |
29 | 29 | for (i = 1; i < 8; i++){ |
30 | 30 | randStat.stat[i & 3] ^= i + ((unsigned)1812433253) * (randStat.stat[(i - 1) & 3] ^ (randStat.stat[(i - 1) & 3] >> 30)); |
31 | - } | |
31 | + } | |
32 | 32 | for (i = 0; i < 8; i++){ |
33 | 33 | randStatNext(); |
34 | - } | |
34 | + } | |
35 | 35 | return; |
36 | 36 | } |
37 | 37 | |
38 | 38 | unsigned int randGetNextUInt32(void) |
39 | 39 | { |
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)); | |
46 | 46 | } |
@@ -4,9 +4,9 @@ void putOsaskChar(int c, HOSECPU_RuntimeEnvironment *r) | ||
4 | 4 | { |
5 | 5 | if (0x10 <= c && c <= 0x1f){ |
6 | 6 | c = "0123456789ABCDEF"[c & 0x0f]; |
7 | - } | |
7 | + } | |
8 | 8 | putchar(c); |
9 | - r->lastConsoleChar = c; | |
9 | + r->lastConsoleChar = c; | |
10 | 10 | return; |
11 | 11 | } |
12 | 12 |
@@ -14,39 +14,39 @@ void checkString(HOSECPU_RuntimeEnvironment *r, int rxx, int pxx) | ||
14 | 14 | { |
15 | 15 | char c = 0; |
16 | 16 | if (r->preg[pxx].typ != 0x03){ |
17 | - c = 1; | |
18 | - } | |
17 | + c = 1; | |
18 | + } | |
19 | 19 | if (r->preg[pxx].p < r->preg[pxx].p0){ |
20 | - c = 1; | |
21 | - } | |
20 | + c = 1; | |
21 | + } | |
22 | 22 | if (r->ireg[rxx] < 0){ |
23 | - c = 1; | |
24 | - } | |
23 | + c = 1; | |
24 | + } | |
25 | 25 | if (r->preg[pxx].p + r->ireg[rxx] > r->preg[pxx].p1){ |
26 | - c = 1; | |
27 | - } | |
26 | + c = 1; | |
27 | + } | |
28 | 28 | if (c != 0){ |
29 | 29 | (*(r->errHndl))(r); |
30 | - } | |
30 | + } | |
31 | 31 | return; |
32 | 32 | } |
33 | 33 | |
34 | 34 | int loadColor(HOSECPU_RuntimeEnvironment *r, int rxx) |
35 | 35 | { |
36 | 36 | 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; | |
39 | 39 | if (m == 0x04) { |
40 | 40 | if (c < -1 || c > 7){ |
41 | 41 | (*(r->errHndl))(r); |
42 | - } | |
42 | + } | |
43 | 43 | c = iColor1[c & 0x07]; |
44 | 44 | } |
45 | 45 | if (m == 0x08) { |
46 | 46 | // 00, 24, 48, 6d, 91, b6, da, ff |
47 | 47 | if (c < 0 || c >= (1 << 9)){ |
48 | 48 | (*(r->errHndl))(r); |
49 | - } | |
49 | + } | |
50 | 50 | rr = (c >> 6) & 0x07; |
51 | 51 | gg = (c >> 3) & 0x07; |
52 | 52 | bb = c & 0x07; |
@@ -62,7 +62,7 @@ int loadColor(HOSECPU_RuntimeEnvironment *r, int rxx) | ||
62 | 62 | // c5, cd, d5, de, e6, ee, f6, ff |
63 | 63 | if (c < 0 || c >= (1 << 15)){ |
64 | 64 | (*(r->errHndl))(r); |
65 | - } | |
65 | + } | |
66 | 66 | rr = (c >> 10) & 0x1f; |
67 | 67 | gg = (c >> 5) & 0x1f; |
68 | 68 | bb = c & 0x1f; |
@@ -79,27 +79,27 @@ void checkRect(HOSECPU_RuntimeEnvironment *r, int rxx) | ||
79 | 79 | char c = 0; |
80 | 80 | int i; |
81 | 81 | if (r->ireg[rxx + 0] <= 0 || r->ireg[rxx + 0] > mainWindow.xsize){ |
82 | - c = 1; | |
83 | - } | |
82 | + c = 1; | |
83 | + } | |
84 | 84 | if (r->ireg[rxx + 1] <= 0 || r->ireg[rxx + 1] > mainWindow.ysize){ |
85 | - c = 1; | |
86 | - } | |
85 | + c = 1; | |
86 | + } | |
87 | 87 | if (r->ireg[rxx + 2] < 0 || r->ireg[rxx + 2] >= mainWindow.xsize){ |
88 | - c = 1; | |
89 | - } | |
88 | + c = 1; | |
89 | + } | |
90 | 90 | if (r->ireg[rxx + 3] < 0 || r->ireg[rxx + 3] >= mainWindow.ysize){ |
91 | - c = 1; | |
92 | - } | |
91 | + c = 1; | |
92 | + } | |
93 | 93 | 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 | + } | |
97 | 97 | 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 | + } | |
101 | 101 | if (c != 0){ |
102 | 102 | (*(r->errHndl))(r); |
103 | - } | |
103 | + } | |
104 | 104 | return; |
105 | 105 | } |
\ No newline at end of file |