OSDN Git Service

API comment added
[heavyosecpu/HeavyOSECPU.git] / function.c
index c87b381..3c96cdb 100644 (file)
@@ -1,137 +1,6 @@
-#include "osecpu.h"
+#include "osecpu.h"
 
-static struct {
-       unsigned stat[4], mat1, mat2, tmat;
-} randStat;
-
-static unsigned char fontdata[] = {
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x00, 0x00, 0x10, 0x10, 0x00, 0x00,
-       0x28, 0x28, 0x28, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x44, 0x44, 0x44, 0xfe, 0x44, 0x44, 0x44, 0x44, 0x44, 0xfe, 0x44, 0x44, 0x44, 0x00, 0x00,
-       0x10, 0x3a, 0x56, 0x92, 0x92, 0x90, 0x50, 0x38, 0x14, 0x12, 0x92, 0x92, 0xd4, 0xb8, 0x10, 0x10,
-       0x62, 0x92, 0x94, 0x94, 0x68, 0x08, 0x10, 0x10, 0x20, 0x2c, 0x52, 0x52, 0x92, 0x8c, 0x00, 0x00,
-       0x00, 0x70, 0x88, 0x88, 0x88, 0x90, 0x60, 0x47, 0xa2, 0x92, 0x8a, 0x84, 0x46, 0x39, 0x00, 0x00,
-       0x04, 0x08, 0x10, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x02, 0x04, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x08, 0x08, 0x04, 0x02, 0x00,
-       0x80, 0x40, 0x20, 0x20, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x20, 0x20, 0x40, 0x80, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x92, 0x54, 0x38, 0x54, 0x92, 0x10, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x10, 0x10, 0xfe, 0x10, 0x10, 0x10, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x08, 0x08, 0x10,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00,
-       0x02, 0x02, 0x04, 0x04, 0x08, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x40, 0x40, 0x40, 0x80, 0x80,
-       0x00, 0x18, 0x24, 0x24, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x24, 0x18, 0x00, 0x00,
-       0x00, 0x08, 0x18, 0x28, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x08, 0x3e, 0x00, 0x00,
-       0x00, 0x18, 0x24, 0x42, 0x42, 0x02, 0x04, 0x08, 0x10, 0x20, 0x20, 0x40, 0x40, 0x7e, 0x00, 0x00,
-       0x00, 0x18, 0x24, 0x42, 0x02, 0x02, 0x04, 0x18, 0x04, 0x02, 0x02, 0x42, 0x24, 0x18, 0x00, 0x00,
-       0x00, 0x0c, 0x0c, 0x0c, 0x14, 0x14, 0x14, 0x24, 0x24, 0x44, 0x7e, 0x04, 0x04, 0x1e, 0x00, 0x00,
-       0x00, 0x7c, 0x40, 0x40, 0x40, 0x58, 0x64, 0x02, 0x02, 0x02, 0x02, 0x42, 0x24, 0x18, 0x00, 0x00,
-       0x00, 0x18, 0x24, 0x42, 0x40, 0x58, 0x64, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00, 0x00,
-       0x00, 0x7e, 0x42, 0x42, 0x04, 0x04, 0x08, 0x08, 0x08, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00,
-       0x00, 0x18, 0x24, 0x42, 0x42, 0x42, 0x24, 0x18, 0x24, 0x42, 0x42, 0x42, 0x24, 0x18, 0x00, 0x00,
-       0x00, 0x18, 0x24, 0x42, 0x42, 0x42, 0x42, 0x42, 0x26, 0x1a, 0x02, 0x42, 0x24, 0x18, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00, 0x00, 0x00, 0x18, 0x18, 0x08, 0x08, 0x10,
-       0x00, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00, 0x00, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x80, 0x40, 0x20, 0x10, 0x08, 0x04, 0x02, 0x02, 0x04, 0x08, 0x10, 0x20, 0x40, 0x80, 0x00,
-       0x00, 0x38, 0x44, 0x82, 0x82, 0x82, 0x04, 0x08, 0x10, 0x10, 0x00, 0x00, 0x18, 0x18, 0x00, 0x00,
-       0x00, 0x38, 0x44, 0x82, 0x9a, 0xaa, 0xaa, 0xaa, 0xaa, 0xaa, 0x9c, 0x80, 0x46, 0x38, 0x00, 0x00,
-       0x00, 0x18, 0x18, 0x18, 0x18, 0x24, 0x24, 0x24, 0x24, 0x7e, 0x42, 0x42, 0x42, 0xe7, 0x00, 0x00,
-       0x00, 0xf0, 0x48, 0x44, 0x44, 0x44, 0x48, 0x78, 0x44, 0x42, 0x42, 0x42, 0x44, 0xf8, 0x00, 0x00,
-       0x00, 0x3a, 0x46, 0x42, 0x82, 0x80, 0x80, 0x80, 0x80, 0x80, 0x82, 0x42, 0x44, 0x38, 0x00, 0x00,
-       0x00, 0xf8, 0x44, 0x44, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x44, 0x44, 0xf8, 0x00, 0x00,
-       0x00, 0xfe, 0x42, 0x42, 0x40, 0x40, 0x44, 0x7c, 0x44, 0x40, 0x40, 0x42, 0x42, 0xfe, 0x00, 0x00,
-       0x00, 0xfe, 0x42, 0x42, 0x40, 0x40, 0x44, 0x7c, 0x44, 0x44, 0x40, 0x40, 0x40, 0xf0, 0x00, 0x00,
-       0x00, 0x3a, 0x46, 0x42, 0x82, 0x80, 0x80, 0x9e, 0x82, 0x82, 0x82, 0x42, 0x46, 0x38, 0x00, 0x00,
-       0x00, 0xe7, 0x42, 0x42, 0x42, 0x42, 0x42, 0x7e, 0x42, 0x42, 0x42, 0x42, 0x42, 0xe7, 0x00, 0x00,
-       0x00, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x7c, 0x00, 0x00,
-       0x00, 0x1f, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x84, 0x48, 0x30, 0x00,
-       0x00, 0xe7, 0x42, 0x44, 0x48, 0x50, 0x50, 0x60, 0x50, 0x50, 0x48, 0x44, 0x42, 0xe7, 0x00, 0x00,
-       0x00, 0xf0, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x40, 0x42, 0x42, 0xfe, 0x00, 0x00,
-       0x00, 0xc3, 0x42, 0x66, 0x66, 0x66, 0x5a, 0x5a, 0x5a, 0x42, 0x42, 0x42, 0x42, 0xe7, 0x00, 0x00,
-       0x00, 0xc7, 0x42, 0x62, 0x62, 0x52, 0x52, 0x52, 0x4a, 0x4a, 0x4a, 0x46, 0x46, 0xe2, 0x00, 0x00,
-       0x00, 0x38, 0x44, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x44, 0x38, 0x00, 0x00,
-       0x00, 0xf8, 0x44, 0x42, 0x42, 0x42, 0x44, 0x78, 0x40, 0x40, 0x40, 0x40, 0x40, 0xf0, 0x00, 0x00,
-       0x00, 0x38, 0x44, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x82, 0x92, 0x8a, 0x44, 0x3a, 0x00, 0x00,
-       0x00, 0xfc, 0x42, 0x42, 0x42, 0x42, 0x7c, 0x44, 0x42, 0x42, 0x42, 0x42, 0x42, 0xe7, 0x00, 0x00,
-       0x00, 0x3a, 0x46, 0x82, 0x82, 0x80, 0x40, 0x38, 0x04, 0x02, 0x82, 0x82, 0xc4, 0xb8, 0x00, 0x00,
-       0x00, 0xfe, 0x92, 0x92, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x7c, 0x00, 0x00,
-       0x00, 0xe7, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x24, 0x3c, 0x00, 0x00,
-       0x00, 0xe7, 0x42, 0x42, 0x42, 0x42, 0x24, 0x24, 0x24, 0x24, 0x18, 0x18, 0x18, 0x18, 0x00, 0x00,
-       0x00, 0xe7, 0x42, 0x42, 0x42, 0x5a, 0x5a, 0x5a, 0x5a, 0x24, 0x24, 0x24, 0x24, 0x24, 0x00, 0x00,
-       0x00, 0xe7, 0x42, 0x42, 0x24, 0x24, 0x24, 0x18, 0x24, 0x24, 0x24, 0x42, 0x42, 0xe7, 0x00, 0x00,
-       0x00, 0xee, 0x44, 0x44, 0x44, 0x28, 0x28, 0x28, 0x10, 0x10, 0x10, 0x10, 0x10, 0x7c, 0x00, 0x00,
-       0x00, 0xfe, 0x84, 0x84, 0x08, 0x08, 0x10, 0x10, 0x20, 0x20, 0x40, 0x42, 0x82, 0xfe, 0x00, 0x00,
-       0x00, 0x3e, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x3e, 0x00,
-       0x80, 0x80, 0x40, 0x40, 0x20, 0x20, 0x20, 0x10, 0x10, 0x08, 0x08, 0x04, 0x04, 0x04, 0x02, 0x02,
-       0x00, 0x7c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x7c, 0x00,
-       0x00, 0x10, 0x28, 0x44, 0x82, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x00,
-       0x10, 0x08, 0x04, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x70, 0x08, 0x04, 0x3c, 0x44, 0x84, 0x84, 0x8c, 0x76, 0x00, 0x00,
-       0xc0, 0x40, 0x40, 0x40, 0x40, 0x58, 0x64, 0x42, 0x42, 0x42, 0x42, 0x42, 0x64, 0x58, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x30, 0x4c, 0x84, 0x84, 0x80, 0x80, 0x82, 0x44, 0x38, 0x00, 0x00,
-       0x0c, 0x04, 0x04, 0x04, 0x04, 0x34, 0x4c, 0x84, 0x84, 0x84, 0x84, 0x84, 0x4c, 0x36, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x82, 0x82, 0xfc, 0x80, 0x82, 0x42, 0x3c, 0x00, 0x00,
-       0x0e, 0x10, 0x10, 0x10, 0x10, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x7c, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x36, 0x4c, 0x84, 0x84, 0x84, 0x84, 0x4c, 0x34, 0x04, 0x04, 0x78,
-       0xc0, 0x40, 0x40, 0x40, 0x40, 0x58, 0x64, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0xe3, 0x00, 0x00,
-       0x00, 0x10, 0x10, 0x00, 0x00, 0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00,
-       0x00, 0x04, 0x04, 0x00, 0x00, 0x0c, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x04, 0x08, 0x08, 0x30,
-       0xc0, 0x40, 0x40, 0x40, 0x40, 0x4e, 0x44, 0x48, 0x50, 0x60, 0x50, 0x48, 0x44, 0xe6, 0x00, 0x00,
-       0x30, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x38, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xf6, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0x49, 0xdb, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x64, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0xe3, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x38, 0x44, 0x82, 0x82, 0x82, 0x82, 0x82, 0x44, 0x38, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xd8, 0x64, 0x42, 0x42, 0x42, 0x42, 0x42, 0x64, 0x58, 0x40, 0xe0,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x34, 0x4c, 0x84, 0x84, 0x84, 0x84, 0x84, 0x4c, 0x34, 0x04, 0x0e,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xdc, 0x62, 0x42, 0x40, 0x40, 0x40, 0x40, 0x40, 0xe0, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0x7a, 0x86, 0x82, 0xc0, 0x38, 0x06, 0x82, 0xc2, 0xbc, 0x00, 0x00,
-       0x00, 0x00, 0x10, 0x10, 0x10, 0x7c, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x0e, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x42, 0x42, 0x42, 0x42, 0x42, 0x42, 0x46, 0x3b, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xe7, 0x42, 0x42, 0x42, 0x24, 0x24, 0x24, 0x18, 0x18, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xe7, 0x42, 0x42, 0x5a, 0x5a, 0x5a, 0x24, 0x24, 0x24, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xc6, 0x44, 0x28, 0x28, 0x10, 0x28, 0x28, 0x44, 0xc6, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xe7, 0x42, 0x42, 0x24, 0x24, 0x24, 0x18, 0x18, 0x10, 0x10, 0x60,
-       0x00, 0x00, 0x00, 0x00, 0x00, 0xfe, 0x82, 0x84, 0x08, 0x10, 0x20, 0x42, 0x82, 0xfe, 0x00, 0x00,
-       0x00, 0x06, 0x08, 0x10, 0x10, 0x10, 0x10, 0x60, 0x10, 0x10, 0x10, 0x10, 0x08, 0x06, 0x00, 0x00,
-       0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10, 0x10,
-       0x00, 0x60, 0x10, 0x08, 0x08, 0x08, 0x08, 0x06, 0x08, 0x08, 0x08, 0x08, 0x10, 0x60, 0x00, 0x00,
-       0x00, 0x72, 0x8c, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
-       0x00, 0x00, 0x00, 0x00, 0x10, 0x28, 0x44, 0x82, 0xfe, 0x82, 0xfe, 0x00, 0x00, 0x00, 0x00, 0x00
-};
-
-
-
-// tinyMTの32bit版のアルゴリズムを使っています : http://www.math.sci.hiroshima-u.ac.jp/~m-mat/MT/TINYMT/index-jp.html
-void randStatNext()
-{
-       unsigned x, y;
-       x = (randStat.stat[0] & 0x7fffffff) ^ randStat.stat[1] ^ randStat.stat[2];
-       y = randStat.stat[3];
-       x ^= x << 1;
-       y ^= (y >> 1) ^ x;
-       randStat.stat[1] = randStat.stat[2] ^ (-((int)(y & 1)) & randStat.mat1);
-       randStat.stat[2] = x ^ (y << 10) ^ (-((int)(y & 1)) & randStat.mat2);
-       randStat.stat[3] = y;
-       return;
-}
-
-void randStatInit(unsigned seed)
-{
-       int i;
-       randStat.stat[0] = seed;
-       randStat.stat[1] = randStat.mat1 = 0x8f7011ee;
-       randStat.stat[2] = randStat.mat2 = 0xfc78ff1f;
-       randStat.stat[3] = randStat.tmat = 0x3793fdff;
-       for (i = 1; i < 8; i++)
-               randStat.stat[i & 3] ^= i + ((unsigned)1812433253) * (randStat.stat[(i - 1) & 3] ^ (randStat.stat[(i - 1) & 3] >> 30));
-       for (i = 0; i < 8; i++)
-               randStatNext();
-       return;
-}
+extern unsigned char fontdata[];    // @fontdata.c
 
 const char *searchArg(int argc, const char **argv, const char *tag, int i)
 {
@@ -142,7 +11,9 @@ const char *searchArg(int argc, const char **argv, const char *tag, int i)
                for (j = 1; j < argc; j++) {
                        if (strncmp(argv[j], tag, l) == 0) {
                                r = argv[j] + l;
-                               if (i == 0)     break;
+                               if (i == 0){
+                                       break;
+                               }
                                i--;
                        }
                }
@@ -151,12 +22,16 @@ const char *searchArg(int argc, const char **argv, const char *tag, int i)
                for (j = 1; j < argc; j++) {
                        if (strchr(argv[j], ':') == NULL) {
                                r = argv[j];
-                               if (i == 0)     break;
+                               if (i == 0){
+                                       break;
+                               }
                                i--;
                        }
                }
        }
-       if (i != 0) r = NULL;
+       if (i != 0){
+               r = NULL;
+       }
        return r;
 }
 
@@ -169,17 +44,26 @@ void devFunc0001(int len, unsigned char *puc, HOSECPU_RuntimeEnvironment *r)
        return;
 }
 
+// drawString
 void devFunc0006(int mod, int sx, int sy, int x, int y, int c, int len, unsigned char *puc, HOSECPU_RuntimeEnvironment *r)
 {
-       if (sy == 0) sy = sx;
-       int xx = x + sx * 8;
-       int yy = y + sy * 16;
-       if (xx <= 0 || xx > v_xsiz || yy <= 0 || yy > v_ysiz)
+       int xx;
+       int yy;
+       int i, ddx, ddy, j, ch, dx, dy;
+       
+       if (sy == 0){
+               sy = sx;
+       }
+       xx = x + sx * 8;
+       yy = y + sy * 16;
+       if (xx <= 0 || xx > mainWindow.xsize || yy <= 0 || yy > mainWindow.ysize){
                (*(r->errHndl))(r);
-       if (x < 0 || x >= v_xsiz || y < 0 || y >= v_ysiz)
+       }
+       if (x < 0 || x >= mainWindow.xsize || y < 0 || y >= mainWindow.ysize){
                (*(r->errHndl))(r);
-       int i, ddx, ddy, j, ch, dx, dy;
-
+       }
+       
+       
        if ((mod & 3) == 0 && sx == 1 && sy == 1) {
                // メジャーケースを高速化.
                for (i = 0; i < len; i++) {
@@ -189,7 +73,9 @@ void devFunc0006(int mod, int sx, int sy, int x, int y, int c, int len, unsigned
                        for (dy = 0; dy < 16; dy++) {
                                j = fontdata[(ch - ' ') * 16 + dy];
                                for (dx = 0; dx < 8; dx++) {
-                                       if ((j & (0x80 >> dx)) != 0) vram[(x + dx) + (y + dy) * v_xsiz] = c;
+                                       if ((j & (0x80 >> dx)) != 0){
+                                               mainWindow.vram[(x + dx) + (y + dy) * mainWindow.xsize] = c;
+                                       }
                                }
                        }
                        x += 8;
@@ -206,15 +92,25 @@ void devFunc0006(int mod, int sx, int sy, int x, int y, int c, int len, unsigned
                                for (dx = 0; dx < 8; dx++) {
                                        if ((j & (0x80 >> dx)) != 0) {
                                                for (ddx = 0; ddx < sx; ddx++) {
-                                                       if ((mod & 3) == 0) vram[x + y * v_xsiz] = c;
-                                                       if ((mod & 3) == 1) vram[x + y * v_xsiz] |= c;
-                                                       if ((mod & 3) == 2) vram[x + y * v_xsiz] ^= c;
-                                                       if ((mod & 3) == 3) vram[x + y * v_xsiz] &= c;
+                                                       switch (mod & 3) {
+                                                               case 0:
+                                                                       mainWindow.vram[x + y * mainWindow.xsize] = c;
+                                                                       break;
+                                                               case 1:
+                                                                       mainWindow.vram[x + y * mainWindow.xsize] |= c;
+                                                                       break;
+                                                               case 2:
+                                                                       mainWindow.vram[x + y * mainWindow.xsize] ^= c;
+                                                                       break;
+                                                               case 3:
+                                                                       mainWindow.vram[x + y * mainWindow.xsize] &= c;
+                                                                       break;
+                                                       }
                                                        x++;
                                                }
-                                       }
-                                       else
+                                       } else{
                                                x += sx;
+                                       }
                                }
                                x -= sx * 8;
                                y++;
@@ -232,16 +128,24 @@ void devFunc0004(int mod, int x0, int y0, int x1, int y1, int c)
        if (mod == 0) {
                for (y = y0; y <= y1; y++) {
                        for (x = x0; x <= x1; x++) {
-                               vram[x + y * v_xsiz] = c;
+                               mainWindow.vram[x + y * mainWindow.xsize] = c;
                        }
                }
        }
        else {
                for (y = y0; y <= y1; y++) {
                        for (x = x0; x <= x1; x++) {
-                               if (mod == 1) vram[x + y * v_xsiz] |= c;
-                               if (mod == 2) vram[x + y * v_xsiz] ^= c;
-                               if (mod == 3) vram[x + y * v_xsiz] &= c;
+                               switch (mod) {
+                                       case 1:
+                                               mainWindow.vram[x + y * mainWindow.xsize] |= c;
+                                               break;
+                                       case 2:
+                                               mainWindow.vram[x + y * mainWindow.xsize] ^= c;
+                                               break;
+                                       case 3:
+                                               mainWindow.vram[x + y * mainWindow.xsize] &= c;
+                                               break;
+                               }
                        }
                }
        }
@@ -252,9 +156,11 @@ int devFunc0016(int buflen, unsigned char *buf, int plen, unsigned char *p, int
 {
        int i = 0, base, j, k;
        char sign;
+       
        while (plen > 0) {
-               if (i >= buflen)
+               if (i >= buflen){
                        (*(r->errHndl))(r);
+               }
                if (*p != 0x01) {
                        buf[i++] = *p++;
                        plen--;
@@ -262,28 +168,42 @@ int devFunc0016(int buflen, unsigned char *buf, int plen, unsigned char *p, int
                }
                p++;
                plen--;
-               if (qlen < 4)
+               if (qlen < 4){
                        (*(r->errHndl))(r);
+               }
                base = q[0];
                sign = 0;
-               if (base == 0) base = 16;
+               if (base == 0){
+                       base = 16;
+               }
 #if (REVISION == 1)
-               if (base == -3) base = 10;
+               if (base == -3){
+                       base = 10;
+               }
 #endif
-               if (base == -1) base = 10;
-               if (base < 0 || base > 16)
+               if (base == -1){
+                       base = 10;
+               }
+               if (base < 0 || base > 16){
                        (*(r->errHndl))(r);
-               if (q[1] + i > buflen)
+               }
+               if (q[1] + i > buflen){
                        (*(r->errHndl))(r);
+               }
                j = q[3];
                if ((q[2] & 4) == 0) {
                        // jは符号付き整数.
-                       if ((q[2] & 8) != 0 && j > 0) sign = '+';
-                       if (j < 0) { sign = '-'; j *= -1; }
-               }
-               else {
+                       if ((q[2] & 8) != 0 && j > 0){
+                               sign = '+';
+                       }
+                       if (j < 0) {
+                               sign = '-'; j *= -1;
+                       }
+               } else{
                        // jは符号無し整数.
-                       if ((q[2] & 8) != 0 && j != 0) sign = '+';
+                       if ((q[2] & 8) != 0 && j != 0){
+                               sign = '+';
+                       }
                }
                for (k = q[1] - 1; k >= 0; k--) {
                        buf[i + k] = (j % base) + 0x10;
@@ -292,21 +212,26 @@ int devFunc0016(int buflen, unsigned char *buf, int plen, unsigned char *p, int
                k = 0;
                if ((q[2] & 2) == 0 && j == 0) {
                        for (k = 0; k < q[1] - 1; k++) {
-                               if (buf[i + k] != 0x10) break;
+                               if (buf[i + k] != 0x10){
+                                       break;
+                               }
                                buf[i + k] = ' ';
                        }
                }
                if (sign != 0) {
-                       if (k > 0) k--;
+                       if (k > 0){
+                               k--;
+                       }
                        buf[i + k] = sign;
                }
                if ((q[2] & 1) != 0 && buf[i] == ' ') {
-                       for (j = 0; k < q[1]; k++, j++)
+                       for (j = 0; k < q[1]; k++, j++){
                                buf[i + j] = buf[i + k];
+                       }
                        i += j;
-               }
-               else
+               } else{
                        i += q[1];
+               }
                qlen -= 4;
                q += 4;
        }
@@ -316,382 +241,476 @@ int devFunc0016(int buflen, unsigned char *buf, int plen, unsigned char *p, int
 void devFunc(HOSECPU_RuntimeEnvironment *r)
 {
        FILE *fp;
-       r = (HOSECPU_RuntimeEnvironment *) (((char *)r) - 128); /* サイズを節約するためにEBPを128バイトずらしているのを元に戻す */
        int i, c;
        int x, y, len, dx, dy;
        unsigned char *puc;
        unsigned char pucbuf[256];
-       if (r->winClosed != 0)
+       
+       //サイズを節約するためにEBPを128バイトずらしているのを元に戻す
+       r = (HOSECPU_RuntimeEnvironment *) (((char *)r) - 128);
+       
+       if (r->winClosed != 0){
                longjmp(*(r->setjmpEnv), 1);
+       }
        if (0xff44 <= r->ireg[0x30] && r->ireg[0x30] <= 0xff48) {
-               if (vram == NULL) {
-                       v_xsiz = 640;
-                       v_ysiz = 480;
-                       vram = malloc(640 * 480 * 4);
-                       drv_openWin(640, 480, (void *)vram, &r->winClosed);
+               if (mainWindow.vram == NULL) {
+                       mainWindow.xsize = 640;
+                       mainWindow.ysize = 480;
+                       mainWindow.vram = malloc(640 * 480 * 4);
+                       drv_openWin(640, 480, (void *)mainWindow.vram, &r->winClosed);
                        r->autoSleep = 1;
-                       for (i = 640 * 480 - 1; i >= 0; i--)
-                               vram[i] = 0;
+                       for (i = 640 * 480 - 1; i >= 0; i--){
+                               mainWindow.vram[i] = 0;
+                       }
                }
        }
-
-       switch (r->ireg[0x30]) {
-       case 0xff00:
-               printf("R31=%d(dec)\n", r->ireg[0x31]);
-               break;
-
-       case 0xff01:
-               /* return: R30, P31 */
-               if (r->buf0 == NULL)
-                       r->buf0 = malloc(1024 * 1024);
-               if (r->mainArgc <= r->ireg[0x31]) {
-                       fprintf(stderr, "devFunc: error: R30=ff01: argc error: R31=%08X\n", r->ireg[0x31]);
-                       exit(1);
-               }
-               fp = fopen(r->mainArgv[r->ireg[0x31]], "rb");
-               if (fp == NULL) {
-                       fprintf(stderr, "devFunc: error: R30=ff01: fopen error: '%s'\n", r->mainArgv[r->ireg[0x31]]);
-                       exit(1);
-               }
-               i = (int)fread(r->buf0, 1, 1024 * 1024 - 4, fp);
-               if (i >= 1024 * 1024 - 4 || i < 0) {
-                       fprintf(stderr, "devFunc: error: R30=ff01: fread error: '%s'\n", r->mainArgv[r->ireg[0x31]]);
-                       exit(1);
-               }
-               fclose(fp);
-               r->preg[0x31].p = r->buf0;
-               r->preg[0x31].p0 = r->buf0;
-               r->preg[0x31].p1 = r->buf0 + i;
-               r->preg[0x31].typ = 3; // T_UINT8
-               r->ireg[0x30] = i;
-               break;
-
-       case 0xff02:
-               /* return: none */
-               if (r->mainArgc <= r->ireg[0x31]) {
-                       fprintf(stderr, "devFunc: error: R30=ff02: argc error: R31=%08X\n", r->ireg[0x31]);
-                       exit(1);
-               }
-               fp = fopen(r->mainArgv[r->ireg[0x31]], "wb");
-               if (fp == NULL) {
-                       fprintf(stderr, "devFunc: error: R30=ff02: fopen error: '%s'\n", r->mainArgv[r->ireg[0x31]]);
-                       exit(1);
-               }
-               if (r->ireg[0x32] >= 1024 * 1024 || r->ireg[0x32] < 0){
-                       fprintf(stderr, "devFunc: error: R30=ff02: fwrite error: R02=%08X\n", r->ireg[0x32]);
-                       exit(1);
-               }
-               fwrite(r->preg[0x31].p, 1, r->ireg[0x32], fp);
-               fclose(fp);
-               break;
-
-       case 0xff03:
-               /* return: P31 */
-               if (r->buf1 == NULL)
-                       r->buf1 = malloc(1024 * 1024);
-               r->preg[0x31].p = r->buf1;
-               r->preg[0x31].p0 = r->buf1;
-               r->preg[0x31].p1 = r->buf1 + 1024 * 1024;
-               break;
-
-       case 0xff04:
-               printf("P31.(p-p0)=%d(dec)\n", (int)(r->preg[0x31].p - r->preg[0x31].p0));
-               break;
-
-       case 0xff05:
-               fwrite(r->preg[0x31].p, 1, r->ireg[0x31], stdout);
-               break;
-
-       case 0xff06:
-               // R31はリターンコード.
-               // これを反映すべきだが、現状は手抜きでいつも正常終了.
-               longjmp(*(r->setjmpEnv), 1);
-               break;
-
-       case 0xff07:
-               // マシになった文字列表示.OSASK文字列に対応.offにすれば通常の文字列処理もできる.現状はonのみサポート.
-               checkString(r, 0x31, 0x31);
-               devFunc0001(r->ireg[0x31], r->preg[0x31].p, r);
-               break;
-
-       case 0xff08:
-               // JITC on JITC
-               // R31: 言語(back-end, front-end, ...
-               // R32: level
-               // R33: debugInfo1
-               checkString(r, 0x34, 0x31);
-               if (r->ireg[0x33] < 0 || r->ireg[0x33] > 15 || r->debugInfo1 > 15)
-                       (*(r->errHndl))(r);
-               for (i = 0; i < r->maxLabels; i++)
-                       r->label[i].opt = 0;
-               puc = r->preg[0x31].p;
-               i = jitCompiler(r->jitbuf, r->jitbuf1, puc, puc + r->ireg[0x34], puc, r->label, r->maxLabels, r->ireg[0x32], di1_serial, JITC_NOSTARTUP + 0);
-               if (i == 0) {
-                       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);
-                       if (i >= 0) {
-                               r->mapDi1s[r->debugInfo1][r->ireg[0x33]] = di1_serial;
-                               di1_serial++;
-                               r->ireg[0x30] = 0;
-                               r->preg[0x31].p = r->jitbuf;
-                               r->preg[0x31].typ = 0; // TYP_CODE
-                               r->preg[0x31].p0 = r->jitbuf;
-                               r->preg[0x31].p1 = r->jitbuf + 1;
-                               //int j; for (j = 0; j < i; j++) printf("%02X ", r->jitbuf[j]); putchar('\n');
-                               r->jitbuf += i;
-                               static unsigned char ff08_ret[3] = { 0x1e, 0x3f, 0x30 };
-                               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);
-                               r->jitbuf += i;
-                               break;
+       
+       switch (r->ireg[0x30]){
+               case 0xff00:
+                       printf("R31=%d(dec)\n", r->ireg[0x31]);
+                       break;
+                       
+               case 0xff01:    // junkApi_fopenRead(_filesize, _p, arg) R31=arg; PCALL(P28); _filesize=R30; _p=P31
+                       
+                       /* return: R30, P31 */
+                       if (r->buf0 == NULL){
+                               r->buf0 = malloc(1024 * 1024);
                        }
-               }
-               r->ireg[0x30] = -1;
-               break;
-
-       case 0xff09:
-               // たぶんbit7を使ったテキストはうまく処理できない(これはもはや仕様にしても問題ないかも).
-               checkString(r, 0x31, 0x31);
-               len = devFunc0016(sizeof pucbuf, pucbuf, r->ireg[0x31], r->preg[0x31].p, r->ireg[0x32], (int *)r->preg[0x32].p, r);
-               devFunc0001(len, pucbuf, r);
-               break;
-
-       case 0xff40:
-               /* R31とR32でサイズを指定 */
-               v_xsiz = r->ireg[0x31];
-               v_ysiz = r->ireg[0x32];
-               if (v_xsiz <= 0 || v_ysiz <= 0)
-                       (*(r->errHndl))(r);
-               r->preg[0x31].p = (void *)(vram = malloc(v_xsiz * v_ysiz * 4));
-               r->preg[0x31].p0 = r->preg[0x31].p;
-               r->preg[0x31].p1 = r->preg[0x31].p + v_xsiz * v_ysiz * 4;
-               drv_openWin(r->ireg[0x31], r->ireg[0x32], r->preg[0x31].p, &r->winClosed);
-               //      drv_flshWin(r->ireg[1], r->ireg[2], 0, 0);
-               r->autoSleep = 1;
-               for (i = v_xsiz * v_ysiz - 1; i >= 0; i--)
-                       vram[i] = 0;
-               break;
-
-       case 0xff41:
-               /* R31とR32でサイズを指定、R33とR34でx0,y0指定 */
-               if (r->ireg[0x31] == -1) { r->ireg[0x31] = v_xsiz; r->ireg[0x33] &= 0; }
-               if (r->ireg[0x32] == -1) { r->ireg[0x32] = v_ysiz; r->ireg[0x34] &= 0; }
-               checkRect(r, 0x31);
-               drv_flshWin(r->ireg[0x31], r->ireg[0x32], r->ireg[0x33], r->ireg[0x34]);
-               break;
-
-       case 0xff42:
-               if (r->ireg[0x32] == -1) {
-                       r->autoSleep = 1;
+                       if (r->mainArgc <= r->ireg[0x31]) {
+                               fprintf(stderr, "devFunc: error: R30=ff01: argc error: R31=%08X\n", r->ireg[0x31]);
+                               exit(1);
+                       }
+                       fp = fopen(r->mainArgv[r->ireg[0x31]], "rb");
+                       if (fp == NULL) {
+                               fprintf(stderr, "devFunc: error: R30=ff01: fopen error: '%s'\n", r->mainArgv[r->ireg[0x31]]);
+                               exit(1);
+                       }
+                       i = (int)fread(r->buf0, 1, 1024 * 1024 - 4, fp);
+                       if (i >= 1024 * 1024 - 4 || i < 0) {
+                               fprintf(stderr, "devFunc: error: R30=ff01: fread error: '%s'\n", r->mainArgv[r->ireg[0x31]]);
+                               exit(1);
+                       }
+                       fclose(fp);
+                       r->preg[0x31].p = r->buf0;
+                       r->preg[0x31].p0 = r->buf0;
+                       r->preg[0x31].p1 = r->buf0 + i;
+                       r->preg[0x31].typ = 3; // T_UINT8
+                       r->ireg[0x30] = i;
+                       break;
+                       
+               case 0xff02:    // junkApi_fopenWrite(arg, filesize, p) R31=arg; R32=filesize; P31=p;
+                       /* return: none */
+                       if (r->mainArgc <= r->ireg[0x31]) {
+                               fprintf(stderr, "devFunc: error: R30=ff02: argc error: R31=%08X\n", r->ireg[0x31]);
+                               exit(1);
+                       }
+                       fp = fopen(r->mainArgv[r->ireg[0x31]], "wb");
+                       if (fp == NULL) {
+                               fprintf(stderr, "devFunc: error: R30=ff02: fopen error: '%s'\n", r->mainArgv[r->ireg[0x31]]);
+                               exit(1);
+                       }
+                       if (r->ireg[0x32] >= 1024 * 1024 || r->ireg[0x32] < 0){
+                               fprintf(stderr, "devFunc: error: R30=ff02: fwrite error: R02=%08X\n", r->ireg[0x32]);
+                               exit(1);
+                       }
+                       fwrite(r->preg[0x31].p, 1, r->ireg[0x32], fp);
+                       fclose(fp);
+                       break;
+                       
+               case 0xff03:    // junkApi_allocBuf(_p) _p=P31
+                       /* return: P31 */
+                       if (r->buf1 == NULL){
+                               r->buf1 = malloc(1024 * 1024);
+                       }
+                       r->preg[0x31].p = r->buf1;
+                       r->preg[0x31].p0 = r->buf1;
+                       r->preg[0x31].p1 = r->buf1 + 1024 * 1024;
+                       break;
+                       
+               case 0xff04:
+                       printf("P31.(p-p0)=%d(dec)\n", (int)(r->preg[0x31].p - r->preg[0x31].p0));
+                       break;
+                       
+               case 0xff05:    // junkApi_writeStdout(len, p) R31=len; P31=p;
+                       fwrite(r->preg[0x31].p, 1, r->ireg[0x31], stdout);
+                       break;
+                       
+               case 0xff06:    // jnukApi_exit(i) R31=i;
+                       // R31はリターンコード.
+                       // これを反映すべきだが、現状は手抜きでいつも正常終了.
                        longjmp(*(r->setjmpEnv), 1);
-               }
-               if (r->ireg[0x32] < 0)
-                       (*(r->errHndl))(r);
-               r->autoSleep = 0;
-               if ((r->ireg[0x31] & 1) == 0 && vram != NULL)
-                       drv_flshWin(v_xsiz, v_ysiz, 0, 0);
-               for (;;) {
-                       if (r->winClosed != 0)
+                       break;
+                       
+               case 0xff07:    // junkApi_putConstString0(s) DB(0xff,0x00,0x00); DB%(s,0x00);
+                       // マシになった文字列表示.OSASK文字列に対応.offにすれば通常の文字列処理もできる.現状はonのみサポート.
+                       checkString(r, 0x31, 0x31);
+                       devFunc0001(r->ireg[0x31], r->preg[0x31].p, r);
+                       break;
+                       
+               case 0xff08:    // junkApi_jitc2(_rc, _p, mod, lev, di1, len, s) R31=mod; R32=lev; R33=di1; R34=len; P31=s; _rc=R30; _p=P31
+                       // JITC on JITC
+                       // R31: 言語(back-end, front-end, ...
+                       // R32: level
+                       // R33: debugInfo1
+                       checkString(r, 0x34, 0x31);
+                       if (r->ireg[0x33] < 0 || r->ireg[0x33] > 15 || r->debugInfo1 > 15){
+                               (*(r->errHndl))(r);
+                       }
+                       for (i = 0; i < r->maxLabels; i++){
+                               r->label[i].opt = 0;
+                       }
+                       puc = r->preg[0x31].p;
+                       i = jitCompiler(r->jitbuf, r->jitbuf1, puc, puc + r->ireg[0x34], puc, r->label, r->maxLabels, r->ireg[0x32], di1_serial, JITC_NOSTARTUP + 0);
+                       if (i == 0) {
+                               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);
+                               if (i >= 0) {
+                                       r->mapDi1s[r->debugInfo1][r->ireg[0x33]] = di1_serial;
+                                       di1_serial++;
+                                       r->ireg[0x30] = 0;
+                                       r->preg[0x31].p = r->jitbuf;
+                                       r->preg[0x31].typ = 0; // TYP_CODE
+                                       r->preg[0x31].p0 = r->jitbuf;
+                                       r->preg[0x31].p1 = r->jitbuf + 1;
+                                       //int j; for (j = 0; j < i; j++) printf("%02X ", r->jitbuf[j]); putchar('\n');
+                                       r->jitbuf += i;
+                                       static unsigned char ff08_ret[3] = { 0x1e, 0x3f, 0x30 };
+                                       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);
+                                       r->jitbuf += i;
+                                       break;
+                               }
+                       }
+                       r->ireg[0x30] = -1;
+                       break;
+                       
+               case 0xff09:    //putStringDec
+                       // たぶんbit7を使ったテキストはうまく処理できない(これはもはや仕様にしても問題ないかも).
+                       checkString(r, 0x31, 0x31);
+                       len = devFunc0016(sizeof pucbuf, pucbuf, r->ireg[0x31], r->preg[0x31].p, r->ireg[0x32], (int *)r->preg[0x32].p, r);
+                       devFunc0001(len, pucbuf, r);
+                       break;
+                       
+               case 0xff40:    // junkApi_openWin(xsiz, ysiz) R31=xsiz; R32=ysiz;
+                       /* R31とR32でサイズを指定 */
+                       mainWindow.xsize = r->ireg[0x31];
+                       mainWindow.ysize = r->ireg[0x32];
+                       if (mainWindow.xsize <= 0 || mainWindow.ysize <= 0){
+                               (*(r->errHndl))(r);
+                       }
+                       r->preg[0x31].p = (void *)(mainWindow.vram = malloc(mainWindow.xsize * mainWindow.ysize * 4));
+                       r->preg[0x31].p0 = r->preg[0x31].p;
+                       r->preg[0x31].p1 = r->preg[0x31].p + mainWindow.xsize * mainWindow.ysize * 4;
+                       drv_openWin(r->ireg[0x31], r->ireg[0x32], r->preg[0x31].p, &r->winClosed);
+                       //      drv_flshWin(r->ireg[1], r->ireg[2], 0, 0);
+                       r->autoSleep = 1;
+                       for (i = mainWindow.xsize * mainWindow.ysize - 1; i >= 0; i--){
+                               mainWindow.vram[i] = 0;
+                       }
+                       break;
+                       
+               case 0xff41:    // junkApi_flushWin(xsiz, ysiz, x0, y0) R31=xsiz; R32=ysiz; R33=x0; R34=y0
+                       /* R31とR32でサイズを指定、R33とR34でx0,y0指定 */
+                       if (r->ireg[0x31] == -1) {
+                               r->ireg[0x31] = mainWindow.xsize; r->ireg[0x33] &= 0;
+                       }
+                       if (r->ireg[0x32] == -1) {
+                               r->ireg[0x32] = mainWindow.ysize; r->ireg[0x34] &= 0;
+                       }
+                       checkRect(r, 0x31);
+                       drv_flshWin(r->ireg[0x31], r->ireg[0x32], r->ireg[0x33], r->ireg[0x34]);
+                       break;
+                       
+               case 0xff42:    // junkApi_sleep(opt, msec) R31=opt; R32=msec
+                       if (r->ireg[0x32] == -1) {
+                               r->autoSleep = 1;
                                longjmp(*(r->setjmpEnv), 1);
-                       drv_sleep(r->ireg[0x32]);
-                       if ((r->ireg[0x31] & 2) != 0 && keybuf_c <= 0) continue;
+                       }
+                       if (r->ireg[0x32] < 0){
+                               (*(r->errHndl))(r);
+                       }
+                       r->autoSleep = 0;
+                       if ((r->ireg[0x31] & 1) == 0 && mainWindow.vram != NULL){
+                               drv_flshWin(mainWindow.xsize, mainWindow.ysize, 0, 0);
+                       }
+                       for (;;) {
+                               if (r->winClosed != 0){
+                                       longjmp(*(r->setjmpEnv), 1);
+                               }
+                               drv_sleep(r->ireg[0x32]);
+                               if ((r->ireg[0x31] & 2) != 0 && keybuf_c <= 0){
+                                       continue;
+                               }
+                               break;
+                       }
                        break;
-               }
-               break;
-
-       case 0xff43:
-               //  1:peek
-               //  2:stdin
-               //      4,8: ソース指定.
-               //      16: shift, lock系を有効化.
-               //      32: 左右のshift系を区別する.
-               if (r->ireg[0x31] == 2) {       // なぜ3にしなかったのか...
-                       r->ireg[0x30] = fgetc(stdin);
-                       if (r->ireg[0x30] == EOF)
-                               r->ireg[0x30] = -1;
+                       
+               case 0xff43:    // junkApi_inkey(_i, mod) R31=mod; _i=R30 
+                       //  1:peek
+                       //  2:stdin
+                       //      4,8: ソース指定.
+                       //      16: shift, lock系を有効化.
+                       //      32: 左右のshift系を区別する.
+                       if (r->ireg[0x31] == 2) {       // なぜ3にしなかったのか...
+                               r->ireg[0x30] = fgetc(stdin);
+                               if (r->ireg[0x30] == EOF){
+                                       r->ireg[0x30] = -1;
+                               }
+                               break;
+                       }
+                       r->ireg[0x30] |= -1;
+                       if (keybuf_c > 0) {
+                               r->ireg[0x30] = keybuf[keybuf_r];
+                               if ((r->ireg[0x31] & 16) == 0){
+                                       r->ireg[0x30] &= 0x3e3effff;
+                               }
+                               if ((r->ireg[0x31] & 32) == 0){
+                                       r->ireg[0x30] |= (r->ireg[0x30] >> 8) & 0xff0000;
+                               }
+                               if ((r->ireg[0x31] & 1) != 0) {
+                                       keybuf_c--;
+                                       keybuf_r = (keybuf_r + 1) & (KEYBUFSIZ - 1);
+                               }
+                       }
+                       r->ireg[0x32] = r->ireg[0x33] = 0;
+                       if (r->ireg[0x30] == 4132) r->ireg[0x32]--;
+                       if (r->ireg[0x30] == 4133) r->ireg[0x33]--;
+                       if (r->ireg[0x30] == 4134) r->ireg[0x32]++;
+                       if (r->ireg[0x30] == 4135) r->ireg[0x33]++;
                        break;
-               }
-               r->ireg[0x30] |= -1;
-               if (keybuf_c > 0) {
-                       r->ireg[0x30] = keybuf[keybuf_r];
-                       if ((r->ireg[0x31] & 16) == 0) r->ireg[0x30] &= 0x3e3effff;
-                       if ((r->ireg[0x31] & 32) == 0) r->ireg[0x30] |= (r->ireg[0x30] >> 8) & 0xff0000;
-                       if ((r->ireg[0x31] & 1) != 0) {
-                               keybuf_c--;
-                               keybuf_r = (keybuf_r + 1) & (KEYBUFSIZ - 1);
+                       
+               case 0xff44:    // junkApi_drawPoint(mod, x, y, c) R31=mod; R32=x; R33=y; R34=c
+                       c = loadColor(r, 0x34);
+                       if (r->ireg[0x32] < 0 || r->ireg[0x32] >= mainWindow.xsize ||
+                               r->ireg[0x33] < 0 || r->ireg[0x33] >= mainWindow.ysize){
+                               (*(r->errHndl))(r);
+                       }
+                       
+                       switch ((r->ireg[0x31] & 3)) {
+                               case 0:
+                                       mainWindow.vram[r->ireg[0x32] + r->ireg[0x33] * mainWindow.xsize] = c;
+                                       break;
+                               case 1:
+                                       mainWindow.vram[r->ireg[0x32] + r->ireg[0x33] * mainWindow.xsize] |= c;
+                                       break;
+                               case 2:
+                                       mainWindow.vram[r->ireg[0x32] + r->ireg[0x33] * mainWindow.xsize] ^= c;
+                                       break;
+                               case 3:
+                                       mainWindow.vram[r->ireg[0x32] + r->ireg[0x33] * mainWindow.xsize] &= c;
+                                       break;
+                       }
+                       break;
+                       
+               case 0xff45:    // junkApi_drawLine(mod, x0, y0, x1, y1, c)     DB(0xfe,0x05,0x01); DDBE(0x0003); R30=0xff45; R31=mod; R32=x0; R33=y0; R34=x1; R35=y1; R36=c
+                       //drawLine
+                       c = loadColor(r, 0x36);
+                       if (r->ireg[0x32] < 0 || r->ireg[0x32] >= mainWindow.xsize ||
+                               r->ireg[0x33] < 0 || r->ireg[0x33] >= mainWindow.ysize){
+                               (*(r->errHndl))(r);
+                       }
+                       if (r->ireg[0x34] < 0 || r->ireg[0x34] >= mainWindow.xsize ||
+                               r->ireg[0x35] < 0 || r->ireg[0x35] >= mainWindow.ysize){
+                               (*(r->errHndl))(r);
+                       }
+                       dx = r->ireg[0x34] - r->ireg[0x32];
+                       dy = r->ireg[0x35] - r->ireg[0x33];
+                       x = r->ireg[0x32] << 10;
+                       y = r->ireg[0x33] << 10;
+                       if (dx < 0){
+                               dx = -dx;
+                       }
+                       if (dy < 0){
+                               dy = -dy;
+                       }
+                       if (dx >= dy) {
+                               len = dx + 1; dx = 1024;
+                               if (r->ireg[0x32] > r->ireg[0x34]){
+                                       dx *= -1;
+                               }
+                               if (r->ireg[0x33] > r->ireg[0x35]){
+                                       dy *= -1;
+                               }
+                               dy = (dy << 10) / len;
+                       } else {
+                               len = dy + 1; dy = 1024;
+                               if (r->ireg[0x33] > r->ireg[0x35]){
+                                       dy *= -1;
+                               }
+                               if (r->ireg[0x32] > r->ireg[0x34]){
+                                       dx *= -1;
+                               }
+                               dx = (dx << 10) / len;
+                       }
+                       if ((r->ireg[0x31] & 3) == 0) {
+                               for (i = 0; i < len; i++) {
+                                       mainWindow.vram[(x >> 10) + (y >> 10) * mainWindow.xsize] = c;
+                                       x += dx;
+                                       y += dy;
+                               }
+                               break;
                        }
-               }
-               r->ireg[0x32] = r->ireg[0x33] = 0;
-               if (r->ireg[0x30] == 4132) r->ireg[0x32]--;
-               if (r->ireg[0x30] == 4133) r->ireg[0x33]--;
-               if (r->ireg[0x30] == 4134) r->ireg[0x32]++;
-               if (r->ireg[0x30] == 4135) r->ireg[0x33]++;
-               break;
-
-       case 0xff44:
-               c = loadColor(r, 0x34);
-               if (r->ireg[0x32] < 0 || r->ireg[0x32] >= v_xsiz || r->ireg[0x33] < 0 || r->ireg[0x33] >= v_ysiz)
-                       (*(r->errHndl))(r);
-               if ((r->ireg[0x31] & 3) == 0) vram[r->ireg[0x32] + r->ireg[0x33] * v_xsiz] = c;
-               if ((r->ireg[0x31] & 3) == 1) vram[r->ireg[0x32] + r->ireg[0x33] * v_xsiz] |= c;
-               if ((r->ireg[0x31] & 3) == 2) vram[r->ireg[0x32] + r->ireg[0x33] * v_xsiz] ^= c;
-               if ((r->ireg[0x31] & 3) == 3) vram[r->ireg[0x32] + r->ireg[0x33] * v_xsiz] &= c;
-               break;
-
-       case 0xff45:
-               c = loadColor(r, 0x36);
-               if (r->ireg[0x32] < 0 || r->ireg[0x32] >= v_xsiz || r->ireg[0x33] < 0 || r->ireg[0x33] >= v_ysiz)
-                       (*(r->errHndl))(r);
-               if (r->ireg[0x34] < 0 || r->ireg[0x34] >= v_xsiz || r->ireg[0x35] < 0 || r->ireg[0x35] >= v_ysiz)
-                       (*(r->errHndl))(r);
-               dx = r->ireg[0x34] - r->ireg[0x32];
-               dy = r->ireg[0x35] - r->ireg[0x33];
-               x = r->ireg[0x32] << 10;
-               y = r->ireg[0x33] << 10;
-               if (dx < 0) dx = -dx;
-               if (dy < 0) dy = -dy;
-               if (dx >= dy) {
-                       len = dx + 1; dx = 1024;
-                       if (r->ireg[0x32] > r->ireg[0x34]) dx *= -1;
-                       if (r->ireg[0x33] > r->ireg[0x35]) dy *= -1;
-                       dy = (dy << 10) / len;
-               }
-               else {
-                       len = dy + 1; dy = 1024;
-                       if (r->ireg[0x33] > r->ireg[0x35]) dy *= -1;
-                       if (r->ireg[0x32] > r->ireg[0x34]) dx *= -1;
-                       dx = (dx << 10) / len;
-               }
-               if ((r->ireg[0x31] & 3) == 0) {
                        for (i = 0; i < len; i++) {
-                               vram[(x >> 10) + (y >> 10) * v_xsiz] = c;
+                               //      if ((r->ireg[0x31] & 3) == 0) vram[(x >> 10) + (y >> 10) * v_xsiz] =  c;
+                               switch ((r->ireg[0x31] & 3)) {
+                                       case 1:
+                                               mainWindow.vram[(x >> 10) + (y >> 10) * mainWindow.xsize] |= c;
+                                               break;
+                                       case 2:
+                                               mainWindow.vram[(x >> 10) + (y >> 10) * mainWindow.xsize] ^= c;
+                                               break;
+                                       case 3:
+                                               mainWindow.vram[(x >> 10) + (y >> 10) * mainWindow.xsize] &= c;
+                                               break;
+                                       default:
+                                               break;
+                               }
                                x += dx;
                                y += dy;
                        }
                        break;
-               }
-               for (i = 0; i < len; i++) {
-                       //      if ((r->ireg[0x31] & 3) == 0) vram[(x >> 10) + (y >> 10) * v_xsiz] =  c;
-                       if ((r->ireg[0x31] & 3) == 1) vram[(x >> 10) + (y >> 10) * v_xsiz] |= c;
-                       if ((r->ireg[0x31] & 3) == 2) vram[(x >> 10) + (y >> 10) * v_xsiz] ^= c;
-                       if ((r->ireg[0x31] & 3) == 3) vram[(x >> 10) + (y >> 10) * v_xsiz] &= c;
-                       x += dx;
-                       y += dy;
-               }
-               break;
-
-       case 0xff46:    // fillRect(opt:R31, xsiz:R32, ysiz:R33, x0:R34, y0:R35, c:R36)
-               c = loadColor(r, 0x36);
-               if (r->ireg[0x32] == -1) { r->ireg[0x32] = v_xsiz; r->ireg[0x34] &= 0; }
-               if (r->ireg[0x33] == -1) { r->ireg[0x33] = v_ysiz; r->ireg[0x35] &= 0; }
-               checkRect(r, 0x32);
-               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;
-               if ((r->ireg[0x31] & 0x20) == 0) {
-                       devFunc0004(mod3, x0, y0, x1, y1, c);
-               }
-               else {  // drawRect
-                       devFunc0004(mod3, x0, y0, x1, y0, c);
-                       devFunc0004(mod3, x0, y1, x1, y1, c);
-                       devFunc0004(mod3, x0, y0, x0, y1, c);
-                       devFunc0004(mod3, x1, y0, x1, y1, c);
-               }
-               break;
-
-       case 0xff47:    // fillOval(opt:R31, xsiz:R32, ysiz:R33, x0:R34, y0:R35, c:R36)
-               // これの計算精度はアーキテクチャに依存する.
-               c = loadColor(r, 0x36);
-               if (r->ireg[0x32] == -1) { r->ireg[0x32] = v_xsiz; r->ireg[0x34] &= 0; }
-               if (r->ireg[0x33] == -1) { r->ireg[0x33] = v_ysiz; r->ireg[0x35] &= 0; }
-               checkRect(r, 0x32);
-               double dcx = 0.5 * (r->ireg[0x32] - 1), dcy = 0.5 * (r->ireg[0x33] - 1), dcxy = (dcx + 0.5) * (dcy + 0.5) - 0.1;
-               dcxy *= dcxy;
-               mod3 = r->ireg[0x31] & 3;
-               x1 = r->ireg[0x32];
-               y1 = r->ireg[0x33];
-               if (mod3 == 0 && (r->ireg[0x31] & 0x20) == 0) {
-                       for (y = 0; y < y1; y++) {
-                               double dty = (y - dcy) * dcx;
-                               for (x = 0; x < x1; x++) {
-                                       double dtx = (x - dcx) * dcy;
-                                       if (dtx * dtx + dty * dty > dcxy) continue;
-                                       vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * v_xsiz] = c;
-                               }
+                       
+               case 0xff46:    // fillRect(opt:R31, xsiz:R32, ysiz:R33, x0:R34, y0:R35, c:R36)
+                       c = loadColor(r, 0x36);
+                       if (r->ireg[0x32] == -1) { r->ireg[0x32] = mainWindow.xsize; r->ireg[0x34] &= 0; }
+                       if (r->ireg[0x33] == -1) { r->ireg[0x33] = mainWindow.ysize; r->ireg[0x35] &= 0; }
+                       checkRect(r, 0x32);
+                       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;
+                       if ((r->ireg[0x31] & 0x20) == 0) {
+                               devFunc0004(mod3, x0, y0, x1, y1, c);
+                       } else {        // drawRect
+                               devFunc0004(mod3, x0, y0, x1, y0, c);
+                               devFunc0004(mod3, x0, y1, x1, y1, c);
+                               devFunc0004(mod3, x0, y0, x0, y1, c);
+                               devFunc0004(mod3, x1, y0, x1, y1, c);
                        }
-               }
-               else {
+                       break;
+                       
+               case 0xff47:    // fillOval(opt:R31, xsiz:R32, ysiz:R33, x0:R34, y0:R35, c:R36)
+                       // これの計算精度はアーキテクチャに依存する.
+                       c = loadColor(r, 0x36);
+                       if (r->ireg[0x32] == -1) {
+                               r->ireg[0x32] = mainWindow.xsize; r->ireg[0x34] &= 0;
+                       }
+                       if (r->ireg[0x33] == -1) {
+                               r->ireg[0x33] = mainWindow.ysize; r->ireg[0x35] &= 0;
+                       }
+                       checkRect(r, 0x32);
+                       double dcx = 0.5 * (r->ireg[0x32] - 1);
+                       double dcy = 0.5 * (r->ireg[0x33] - 1);
+                       double dcxy = (dcx + 0.5) * (dcy + 0.5) - 0.1;
+                       dcxy *= dcxy;
+                       mod3 = r->ireg[0x31] & 3;
+                       x1 = r->ireg[0x32];
+                       y1 = r->ireg[0x33];
+                       if (mod3 == 0 && (r->ireg[0x31] & 0x20) == 0) {
+                               for (y = 0; y < y1; y++) {
+                                       double dty = (y - dcy) * dcx;
+                                       for (x = 0; x < x1; x++) {
+                                               double dtx = (x - dcx) * dcy;
+                                               if (dtx * dtx + dty * dty > dcxy){
+                                                       continue;
+                                               }
+                                               mainWindow.vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * mainWindow.xsize] = c;
+                                       }
+                               }
+                       } else {
 #define DRAWOVALPARAM  1
-                       double dcx1 = 0.5 * (r->ireg[0x32] - (1 + DRAWOVALPARAM * 2)), dcy1 = 0.5 * (r->ireg[0x33] - (1 + DRAWOVALPARAM * 2)), dcxy1 = (dcx1 + 0.5) * (dcy1 + 0.5) - 0.1;
-                       dcxy1 *= dcxy1;
-                       for (y = 0; y < y1; y++) {
-                               double dty = (y - dcy) * dcx;
-                               double dty1 = (y - dcy) * dcx1;
-                               for (x = 0; x < x1; x++) {
-                                       double dtx = (x - dcx) * dcy;
-                                       double dtx1 = (x - dcx) * dcy1;
-                                       if (dtx * dtx + dty * dty > dcxy) continue;
-                                       if (DRAWOVALPARAM <= x && x < x1 - DRAWOVALPARAM && DRAWOVALPARAM <= y && y < y1 - DRAWOVALPARAM) {
-                                               if (dtx1 * dtx1 + dty1 * dty1 < dcxy1) continue;
+                               double dcx1 = 0.5 * (r->ireg[0x32] - (1 + DRAWOVALPARAM * 2));
+                               double dcy1 = 0.5 * (r->ireg[0x33] - (1 + DRAWOVALPARAM * 2));
+                               double dcxy1 = (dcx1 + 0.5) * (dcy1 + 0.5) - 0.1;
+                               dcxy1 *= dcxy1;
+                               for (y = 0; y < y1; y++) {
+                                       double dty = (y - dcy) * dcx;
+                                       double dty1 = (y - dcy) * dcx1;
+                                       for (x = 0; x < x1; x++) {
+                                               double dtx = (x - dcx) * dcy;
+                                               double dtx1 = (x - dcx) * dcy1;
+                                               if (dtx * dtx + dty * dty > dcxy){
+                                                       continue;
+                                               }
+                                               if (DRAWOVALPARAM <= x && x < x1 - DRAWOVALPARAM && DRAWOVALPARAM <= y && y < y1 - DRAWOVALPARAM) {
+                                                       if (dtx1 * dtx1 + dty1 * dty1 < dcxy1){
+                                                               continue;
+                                                       }
+                                               }
+                                               switch (mod3) {
+                                                       case 0:
+                                                               mainWindow.vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * mainWindow.xsize] = c;
+                                                               break;
+                                                       case 1:
+                                                               mainWindow.vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * mainWindow.xsize] |= c;
+                                                               break;
+                                                       case 2:
+                                                               mainWindow.vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * mainWindow.xsize] ^= c;
+                                                               break;
+                                                       case 3:
+                                                               mainWindow.vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * mainWindow.xsize] &= c;
+                                                               break;
+                                               }
                                        }
-                                       if (mod3 == 0) vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * v_xsiz] = c;
-                                       if (mod3 == 1) vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * v_xsiz] |= c;
-                                       if (mod3 == 2) vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * v_xsiz] ^= c;
-                                       if (mod3 == 3) vram[(x + r->ireg[0x34]) + (y + r->ireg[0x35]) * v_xsiz] &= c;
                                }
                        }
-               }
-               break;
-
-       case 0xff48:    // drawString(opt:R31, xsiz:R32, ysiz:R33, x0:R34, y0:R35, c:R36, s.len:R37, s.p:P31)
-               checkString(r, 0x37, 0x31);
-               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);
-               break;
-
-       case 0xff49:    /* 適当な乱数を返す */
-               randStatNext();
-               unsigned u32t;
-               u32t = randStat.stat[0] + (randStat.stat[2] >> 8);
-               r->ireg[0x30] = randStat.stat[3] ^ u32t ^ (-((int)(u32t & 1)) & randStat.tmat);
-               if (r->ireg[0x31] > 0)
-                       r->ireg[0x30] = (r->ireg[0x30] & 0x7fffffff) % (r->ireg[0x31] + 1);
-               break;
-
-       case 0xff4a:    /* seedの指定 */
-               randStatInit(r->ireg[0x31]);
-               break;
-
-       case 0xff4b:    /* 適当なseedを提供 */
-               r->ireg[0x30] = (int)(time(NULL) ^ (long)0x55555555);
-               break;
-
-       case 0xff4c:
-               checkString(r, 0x37, 0x31);
-               len = devFunc0016(sizeof pucbuf, pucbuf, r->ireg[0x37], r->preg[0x31].p, r->ireg[0x38], (int *)r->preg[0x32].p, r);
-               devFunc0006(r->ireg[0x31], r->ireg[0x32], r->ireg[0x33], r->ireg[0x34], r->ireg[0x35], loadColor(r, 0x36), len, pucbuf, r);
-               break;
-
-       case 0xff4d:
-               // bitblt(mod, xsiz, ysiz, xscale, yscale, x0, y0, lineskip, inv, p_buf, typ0, p_table, typ1); 
-               // mod: 0x20:use_table, 0x40:inv_is_visible & typ1_is_color
-               puc = r->preg[0x31].p;
-               mod3 = r->ireg[0x31] & 3;
-               dx = r->ireg[0x34];
-               dy = r->ireg[0x35];
-               if (dy == 0) dy = dx;
-               if (r->ireg[0x32] == -1) { r->ireg[0x32] = v_xsiz / dx; r->ireg[0x36] &= 0; }
-               if (r->ireg[0x33] == -1) { r->ireg[0x33] = v_ysiz / dy; r->ireg[0x37] &= 0; }
-               for (y = 0; y < r->ireg[0x33]; y++) {
-                       y0 = y * dy + r->ireg[0x37];
-                       for (x = 0; x < r->ireg[0x32]; x++) {
-                               x0 = x * dx + r->ireg[0x36];
-                               c = iColor1[*puc++];
-                               devFunc0004(mod3, x0, y0, x0 + dx, y0 + dy, c);
-                       }
-                       puc += r->ireg[0x38];
-               }
-               break;
-
-       default:
-               printf("devFunc: error: R30=%08X\n", r->ireg[0x30]);
-               exit(1);
-
+                       break;
+                       
+               case 0xff48:    // drawString(opt:R31, xsiz:R32, ysiz:R33, x0:R34, y0:R35, c:R36, s.len:R37, s.p:P31)
+                       checkString(r, 0x37, 0x31);
+                       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);
+                       break;
+                       
+               case 0xff49:    // junkApi_rand(_r, range) R31=range; _r=R30
+                       // **** junkApi_rand(i, max) ****
+                       // 0 <= i <= maxとなるiを返す。
+                       // max==0のとき、iはSINT32全体を範囲とする乱数となる。
+                       r->ireg[0x30] = randGetNextUInt32();
+                       if (r->ireg[0x31] > 0){
+                               r->ireg[0x30] = (r->ireg[0x30] & 0x7fffffff) % (r->ireg[0x31] + 1);
+                       }
+                       break;
+                       
+               case 0xff4a:    /* seedの指定 */
+                       randStatInit(r->ireg[0x31]);
+                       break;
+                       
+               case 0xff4b:    /* 適当なseedを提供 */
+                       r->ireg[0x30] = (int)(time(NULL) ^ (long)0x55555555);
+                       break;
+                       
+               case 0xff4c:    // drawStringDec
+                       checkString(r, 0x37, 0x31);
+                       len = devFunc0016(sizeof pucbuf, pucbuf, r->ireg[0x37], r->preg[0x31].p, r->ireg[0x38], (int *)r->preg[0x32].p, r);
+                       devFunc0006(r->ireg[0x31], r->ireg[0x32], r->ireg[0x33], r->ireg[0x34], r->ireg[0x35], loadColor(r, 0x36), len, pucbuf, r);
+                       break;
+                       
+               case 0xff4d:
+                       // bitblt(mod, xsiz, ysiz, xscale, yscale, x0, y0, lineskip, inv, p_buf, typ0, p_table, typ1); 
+                       // mod: 0x20:use_table, 0x40:inv_is_visible & typ1_is_color
+                       puc = r->preg[0x31].p;
+                       mod3 = r->ireg[0x31] & 3;
+                       dx = r->ireg[0x34];
+                       dy = r->ireg[0x35];
+                       if (dy == 0){
+                               dy = dx;
+                       }
+                       if (r->ireg[0x32] == -1) {
+                               r->ireg[0x32] = mainWindow.xsize / dx; r->ireg[0x36] &= 0;
+                       }
+                       if (r->ireg[0x33] == -1) {
+                               r->ireg[0x33] = mainWindow.ysize / dy; r->ireg[0x37] &= 0;
+                       }
+                       for (y = 0; y < r->ireg[0x33]; y++) {
+                               y0 = y * dy + r->ireg[0x37];
+                               for (x = 0; x < r->ireg[0x32]; x++) {
+                                       x0 = x * dx + r->ireg[0x36];
+                                       c = iColor1[*puc++];
+                                       devFunc0004(mod3, x0, y0, x0 + dx, y0 + dy, c);
+                               }
+                               puc += r->ireg[0x38];
+                       }
+                       break;
+                       
+               default:
+                       printf("devFunc: error: R30=%08X\n", r->ireg[0x30]);
+                       exit(EXIT_FAILURE);
+                       
        }
        return;
 }