home *** CD-ROM | disk | FTP | other *** search
/ FreeWare Collection 2 / FreeSoftwareCollection2pd199x-jp.img / demo / demo.c < prev    next >
Text File  |  1990-06-14  |  22KB  |  1,001 lines

  1. #include "demo.h"
  2.  
  3. #define PTN_CNT 30
  4.  
  5. char GWork[1536];
  6.  
  7. char para[128];
  8.  
  9. int Myx = 1;
  10. int Myy = 3;
  11. int SpriteCnt = 22;
  12. int door = 0;
  13.  
  14. short int PartsBuf[PARTS_MAX][16*2] = {
  15. 0x3333,0x3333,0x3333,0x3333,0x3333,0x3333,0x3333,0x3333,
  16. 0x3333,0x3333,0x3333,0x3333,0x3333,0x3333,0x3333,0x3333,
  17. 0x3333,0x3333,0x3333,0x3333,0x3333,0x3333,0x3333,0x3333,
  18. 0x3333,0x3333,0x3333,0x3333,0x3333,0x3333,0x3333,0x3333,
  19.  
  20. 0x1112,0x2222,0x2112,0x2122,0x2111,0x2112,0x2212,0x2112,
  21. 0x1112,0x2212,0x2111,0x2122,0x2221,0x2122,0x2122,0x1122,
  22. 0x2211,0x2221,0x1221,0x2121,0x1222,0x1122,0x2222,0x1122,
  23. 0x1122,0x2121,0x1122,0x2121,0x3321,0x3311,0x3313,0x3313,
  24.  
  25. 0x1113,0x1111,0x1113,0x2221,0x1313,0x2212,0x2333,0x1111,
  26. 0x2133,0x1211,0x3133,0x1211,0x3333,0x1112,0x3333,0x2132,
  27. 0x3333,0x2131,0x3333,0x2233,0x3333,0x1213,0x3333,0x1313,
  28. 0x3333,0x1313,0x3333,0x3333,0x3333,0x3333,0x3333,0x3333,
  29.  
  30. 0x2111,0x3121,0x2221,0x3211,0x2221,0x3231,0x1111,0x3133,
  31. 0x1121,0x3333,0x1122,0x3333,0x2111,0x3331,0x1221,0x3332,
  32. 0x3111,0x3332,0x3311,0x3331,0x3311,0x3333,0x3311,0x3333,
  33. 0x3113,0x3333,0x3133,0x3333,0x3333,0x3333,0x3333,0x3333,
  34.  
  35. 0x1112,0x2222,0x2112,0x2122,0x2111,0x2112,0x2212,0x2112,
  36. 0x1112,0x2212,0x2111,0x2122,0x2221,0x2122,0x2122,0x1122,
  37. 0x2211,0x2221,0x1221,0x2121,0x1222,0x1122,0x2222,0x1122,
  38. 0x1122,0x2121,0x1122,0x2121,0x2121,0x1112,0x2111,0x1211,
  39.  
  40. 0x6665,0x6666,0x4445,0x6444,0x4445,0x6444,0x4445,0x6444,
  41. 0x4445,0x6444,0x4445,0x6444,0x4445,0x6444,0x4445,0x6444,
  42. 0x4445,0x6444,0x4445,0x6444,0x4445,0x6444,0x4445,0x6444,
  43. 0x4445,0x6444,0x4445,0x6444,0x4445,0x6444,0x5555,0x6555,
  44.  
  45. 0x4445,0x6444,0x4445,0x6444,0x4445,0x6444,0x4445,0x6444,
  46. 0x4445,0x6444,0x4445,0x6444,0x4445,0x6444,0x4445,0x6444,
  47. 0x4445,0x6444,0x4445,0x6444,0x4445,0x6444,0x4445,0x6444,
  48. 0x4445,0x6444,0x4445,0x6444,0x4445,0x6444,0x4445,0x6444,
  49.  
  50. 0x8888,0x8888,0x8888,0x8888,0x7777,0x7777,0x7777,0x7777,
  51. 0x7777,0x7777,0x7777,0x7777,0x7777,0x7777,0x7777,0x7777,
  52. 0x7777,0x7777,0x7777,0x7777,0x7777,0x7777,0x7777,0x7777,
  53. 0x7777,0x7777,0x7777,0x7777,0x7777,0x7777,0xffff,0xffff,
  54.  
  55. 0x1112,0x2222,0x2112,0x2122,0x2111,0x2112,0x2212,0x2112,
  56. 0x1112,0x2212,0x2111,0x2122,0x2221,0x2122,0x2122,0x1122,
  57. 0x2211,0x2221,0x1221,0x2121,0x1222,0x1122,0x2222,0x1122,
  58. 0x1122,0x2121,0x1122,0x2121,0x4421,0x4411,0x4414,0x4414,
  59.  
  60. 0x1114,0x1111,0x1114,0x2221,0x1414,0x2212,0x2444,0x1111,
  61. 0x2144,0x1211,0x4144,0x1211,0x4444,0x1112,0x4444,0x2142,
  62. 0x4444,0x2141,0x4444,0x2244,0x4444,0x1214,0x4444,0x1414,
  63. 0x4444,0x1414,0x4444,0x4444,0x4444,0x4444,0x4444,0x4444,
  64.  
  65. 0x2111,0x4121,0x2221,0x4211,0x2221,0x4241,0x1111,0x4144,
  66. 0x1121,0x4444,0x1122,0x4444,0x2111,0x4441,0x1221,0x4442,
  67. 0x4111,0x4442,0x4411,0x4441,0x4411,0x4444,0x4411,0x4444,
  68. 0x4114,0x4444,0x4144,0x4444,0x4444,0x4444,0x4444,0x4444,
  69.  
  70. 0x1333,0x3311,0x1322,0x3112,0x1322,0x3211,0x2233,0x2222,
  71. 0x2211,0x3332,0x2112,0x3332,0x2111,0x3322,0x3222,0x2222,
  72. 0x2222,0x1122,0x1332,0x1111,0x1332,0x2211,0x1322,0x2221,
  73. 0x2222,0x2233,0x2222,0x3332,0x2111,0x1133,0x2111,0x1113,
  74.  
  75. 0x5455,0x5566,0x5455,0x5566,0x5445,0x5464,0x5466,0x4464,
  76. 0x6666,0x6655,0x5455,0x6654,0x5445,0x6545,0x4664,0x6546,
  77. 0x6655,0x6565,0x4466,0x4554,0x6456,0x6455,0x4455,0x6645,
  78. 0x6655,0x6645,0x4665,0x5566,0x6455,0x5555,0x6455,0x5555
  79. };
  80.  
  81. MAP regionmap[41]={
  82. /* 0.森の広場                        */ 99,1,
  83. /* 1.猟師のいる家                    */ 0,3,
  84. /* 2.猟師の部屋の中                    */ 99,99,
  85. /* 3.屋根裏部屋のある家                */ 1,6,
  86. /* 4.その家の中                        */ 99,99,
  87. /* 5.屋根裏部屋                        */ 99,99,
  88. /* 6.美術館                            */ 3,8,
  89. /* 7.美術館の中                        */ 99,99,
  90. /* 8.地下迷宮の入口(井戸)            */ 6,9,
  91. /* 9.長老の家                        */ 8,11,
  92. /* 10.長老の家の中                    */ 99,99,
  93. /* 11.真実の石を持った人がいる家    */ 9,13,
  94. /* 12.その家の中                    */ 99,99,
  95. /* 13.道具屋                        */ 11,15,
  96. /* 14.道具屋の中                    */ 99,99,
  97. /* 15.神殿の入口                    */ 13,17,
  98. /* 16.神殿                            */ 99,99,
  99. /* 17.工場                            */ 15,19,
  100. /* 18.工場の中                        */ 99,99,
  101. /* 19.洞窟の入口                    */ 17,99,
  102.  
  103. /* 20.地下迷宮 */ 21,22,
  104. /* 21.地下迷宮 */ 99,20,
  105. /* 22.地下迷宮 */ 20,99,
  106. /* 23.地下迷宮 */ 99,24,
  107. /* 24.地下迷宮 */ 23,99,
  108. /* 25.地下迷宮 */ 26,99,
  109. /* 26.地下迷宮 */ 99,25,
  110. /* 27.地下迷宮 */ 28,99,
  111. /* 28.地下迷宮 */ 29,27,
  112. /* 29.地下迷宮 */ 99,28,
  113.  
  114. /* 30.洞窟 */ 99,31,
  115. /* 31.洞窟 */ 30,99,
  116. /* 32.洞窟 */ 99,99,
  117. /* 33.洞窟 */ 99,99,
  118. /* 34.洞窟 */ 99,99,
  119. /* 35.洞窟 */ 99,99,
  120. /* 36.洞窟 */ 99,99,
  121. /* 37.洞窟 */ 99,38,
  122. /* 38.洞窟 */ 37,39,
  123. /* 39.洞窟 */ 38,99
  124. };
  125.  
  126. PTNINFO PtnInfo[PTN_CNT] = {
  127. /* 0 */ "door1.esp",1,2,128+22,256+0,
  128. /* 1 */ "door2.esp",1,2,128+24,256+0,
  129. /* 2 */ "cdoor1.esp",1,2,128+26,256+1,
  130. /* 3 */ "cdoor2.esp",1,2,128+28,256+1,
  131. /* 4 */ "takara.esp",1,2,128+30,256+0,
  132. /* 5 */ "ido.esp",1,2,128+32,256+2,
  133. /* 6 */ "saidan.esp",1,2,128+34,256+4,
  134. /* 7 */ "man1.esp",1,2,128+36,256+2,
  135. /* 8 */ "man2.esp",1,2,128+38,256+2,
  136. /* 9 */ "man3.esp",1,2,128+40,256+5,
  137. /* 10 */ "man4.esp",1,2,128+42,256+6,
  138. /* 11 */ "man5.esp",1,2,128+44,256+7,
  139. /* 12 */ "man6.esp",1,2,128+46,256+8,
  140. /* 13 */ "man7.esp",1,2,128+48,256+9,
  141. /* 14 */ "man8.esp",1,2,128+50,256+10,
  142. /* 15 */ "man9.esp",1,2,128+52,256+11,
  143. /* 16 */ "man10.esp",1,2,128+54,256+12,
  144. /* 17 */ "man11.esp",1,2,128+56,256+13,
  145.  
  146. /* 18 */ "end3.esp",6,3,128+58,256+0,
  147. /* 19 */ "end4.esp",6,3,128+76,256+0,
  148. /* 20 */ "end1.esp",6,3,128+94,256+0,
  149. /* 21 */ "end2.esp",6,3,128+112,256+0,
  150. /* 22 */ "end5.esp",6,3,128+130,256+0,
  151. /* 23 */ "end6.esp",6,3,128+148,256+0,
  152. /* 26 */ "end11.esp",6,3,128+166,256+0,
  153. /* 27 */ "end12.esp",6,3,128+184,256+0,
  154. /* 24 */ "end7.esp",6,3,128+202,256+0,
  155. /* 25 */ "end8.esp",6,3,128+220,256+0,
  156. /* 28 */ "end9.esp",6,3,128+238,256+0,
  157. /* 29 */ "end10.esp",6,3,128+256,256+0,
  158. };
  159.  
  160. int MusicTable[42] = {
  161.     MUS_TOWN,MUS_TOWN,MUS_TOWN,MUS_TOWN,MUS_TOWN,MUS_TOWN,MUS_TOWN,MUS_TOWN,MUS_TOWN,MUS_TOWN,
  162.     MUS_TOWN,MUS_TOWN,MUS_TOWN,MUS_TOWN,MUS_TOWN,MUS_TOWN,MUS_TOWN,MUS_TOWN,MUS_TOWN,MUS_TOWN,
  163.     MUS_CAVE,MUS_CAVE,MUS_CAVE,MUS_CAVE,MUS_CAVE,MUS_CAVE,MUS_CAVE,MUS_CAVE,MUS_CAVE,MUS_CAVE,
  164.     MUS_CAVE,MUS_CAVE,MUS_CAVE,MUS_CAVE,MUS_CAVE,MUS_CAVE,MUS_CAVE,MUS_CAVE,MUS_CAVE,MUS_CAVE,
  165.     MUS_OPEN,MUS_END
  166. };
  167.  
  168. int NowMusic = MUS_OPEN;
  169.  
  170. INFO CharInfo[2][6];
  171.  
  172. OBJECT objlist[LEVELMAX][OBJMAX];
  173.  
  174. int region = 0;
  175. int level = 0;
  176.  
  177. int WaitCnt;
  178.  
  179. void
  180. DrawFrame(mode)
  181. int mode;
  182. {
  183.     FILE *fp;
  184.     static char *buf;
  185.     GETPUT put;
  186.     
  187.     if (mode) {
  188.         buf=malloc(153734);
  189.         fp=fopen("frame.p16","rb");
  190.         fread(buf,1,153734,fp);
  191.         fclose(fp);
  192.     } else {
  193.         put.addr = buf+134;
  194.         put.select = 0x14;
  195.         put.x1 = 0;
  196.         put.y1 = 0;
  197.         put.x2 = 639;
  198.         put.y2 = 479;
  199.         EGB_putBlock(GWork,0,(char *)&put);
  200.         
  201.         free(buf);
  202.     }
  203.     
  204. }
  205. void
  206. PalLoad(from,to)
  207. int from,to;
  208. {
  209.     int cnt;
  210.     PALETTE pal;
  211.     
  212.     pal.no = to-from+1;
  213.     for (cnt=from;cnt<=to;cnt++) {
  214.         pal.color[cnt-from].seqno = cnt;
  215.         pal.color[cnt-from].blue = (PalBuf[region][cnt] & 0xf00) >> 4;
  216.         pal.color[cnt-from].red = (PalBuf[region][cnt] & 0x0f0);
  217.         pal.color[cnt-from].green = (PalBuf[region][cnt] & 0x00f) << 4;
  218.         pal.color[cnt-from].dummy = 0;
  219.     }
  220.     EGB_palette(GWork,1,(char *)&pal);
  221. }
  222. void
  223. PalSave(from,to)
  224. int from,to;
  225. {
  226.     int cnt;
  227.     PALETTE pal;
  228.     
  229.     pal.no = to-from+1;
  230.     for (cnt=from;cnt<=to;cnt++) {
  231.         pal.color[cnt-from].seqno = cnt;
  232.         pal.color[cnt-from].blue = 0;
  233.         pal.color[cnt-from].red = 0;
  234.         pal.color[cnt-from].green = 0;
  235.         pal.color[cnt-from].dummy = 0;
  236.     }
  237.     EGB_palette(GWork,1,(char *)&pal);
  238. }
  239.  
  240. void
  241. mapedit()
  242. {
  243.     int cnt1,cnt2;
  244.     
  245.     BOX para;
  246.     
  247.     para.x1 = 64;
  248.     para.y1 = 64;
  249.     para.x2 = 512+64-1;
  250.     para.y2 = 480-64;
  251.     EGB_color(GWork,0,0);
  252.     EGB_color(GWork,2,0);
  253.     EGB_paintMode(GWork,0x22);
  254.     EGB_rectangle(GWork,(char *)¶);
  255.     
  256.     PalSave(1,8);
  257.     
  258.     EGB_writeMode(GWork,6);
  259.     EGB_color(GWork,3,0);
  260.  
  261.     
  262.     for (cnt1=0;cnt1<22;cnt1++) {
  263.         for (cnt2=0;cnt2<64;cnt2++) {
  264.             if ((*(ScreenMap[region]+64 * cnt1 + cnt2)) != 0xff) {
  265.                 TransData(64+cnt2*8,416-(cnt1+1)*16,(char *)PartsBuf[((*(ScreenMap[region]+64 * cnt1 + cnt2)) & 0x7f)]);
  266.             }
  267.         }
  268.     }
  269.     
  270.     PalLoad(1,8);
  271.     
  272.     EGB_writeMode(GWork,0);
  273. }
  274.  
  275. void
  276. ReadData(mode)
  277. int mode;
  278. {
  279.     FILE *fp;
  280.     static char *temp[PTN_CNT+2];
  281.     int ptn_cnt,cnt;
  282.     
  283.     if (mode) {
  284.         fp = fopen("palette.32k","rb");
  285.         fread((char *)Palette,8192,1,fp);
  286.         fclose(fp);
  287.         
  288.         for (cnt=0;cnt<PTN_CNT+2;cnt++) {
  289.             temp[cnt] = malloc(128*6*4);
  290.         }
  291.         
  292.         fp = fopen("man1.esp","rb");
  293.         fread(temp[0],128*11+18,1,fp);
  294.         fclose(fp);
  295.         
  296.         fp = fopen("man2.esp","rb");
  297.         fread(temp[1],128*11+18,1,fp);
  298.         fclose(fp);
  299.         
  300.         for(cnt=0;cnt<PTN_CNT;cnt++) {
  301.             fp = fopen(PtnInfo[cnt].fname,"rb");
  302.             fread(temp[cnt+2],128*PtnInfo[cnt].xsize*PtnInfo[cnt].ysize+18,1,fp);
  303.             fclose(fp);
  304.         }
  305.         
  306.     } else {
  307.         SPR_init();
  308.         SPR_setPaletteBlock(256,256,(char *)Palette);
  309.         
  310.         /*  マイキャラの読み込み・定義  */
  311.         
  312.         SPR_define(0,128,1,11,temp[0]+18);
  313.         SPR_define(0,128+11,1,11,temp[1]+18);
  314.         free(temp[0]);
  315.         free(temp[1]);
  316.         
  317.         ptn_cnt = 22;
  318.         
  319.         /* オブジェクトの読み込み・定義  */
  320.         for(cnt=0;cnt<PTN_CNT;cnt++) {
  321.             SPR_define(0,128+ptn_cnt,PtnInfo[cnt].xsize,PtnInfo[cnt].ysize,temp[cnt+2]+18);
  322.             ptn_cnt += PtnInfo[cnt].xsize*PtnInfo[cnt].ysize;
  323.             free(temp[cnt+2]);
  324.         }
  325.     }
  326. }
  327.  
  328. void
  329. GInit()
  330. {
  331.     EGB_init(GWork,1536);
  332.     EGB_resolution(GWork,1,5);
  333.     EGB_resolution(GWork,0,3);
  334.     
  335.     EGB_writePage(GWork,1);
  336.     EGB_displayStart(GWork,0,64,0);
  337.     EGB_displayStart(GWork,1,0,0);
  338.     EGB_displayStart(GWork,2,2,2);
  339.     EGB_displayStart(GWork,3,256,256);
  340.     EGB_displayPage(GWork,1,3);
  341.     
  342.     EGB_writePage(GWork,0);
  343.     EGB_paintMode(GWork,0x22);
  344.     EGB_color(GWork,0,7);
  345.     EGB_color(GWork,1,0);
  346.     EGB_color(GWork,2,8);
  347.     
  348.     EGB_writePage(GWork,1);
  349.     ReadData(0);
  350.     
  351.     EGB_writePage(GWork,0);
  352.     
  353.     PalSave(0,15);
  354.     DrawFrame(0);
  355.     PalLoad(0,15);
  356.     
  357.     mapedit();
  358. }
  359.  
  360. void
  361. CharSet()
  362. {
  363.     int cnt0,cnt1,pat,spr;
  364.     
  365.     pat = 128;
  366.     spr = 1024;
  367.     
  368.     for (cnt0=0;cnt0<2;cnt0++) {
  369.         for (cnt1=0;cnt1<6;cnt1++) {
  370.             CharInfo[cnt0][cnt1].xsize = 1;
  371.             if (cnt1 == 5) {
  372.                 CharInfo[cnt0][cnt1].ysize = 1;
  373.             } else {
  374.                 CharInfo[cnt0][cnt1].ysize = 2;
  375.             }
  376.             spr -= CharInfo[cnt0][cnt1].xsize*CharInfo[cnt0][cnt1].ysize;
  377.             CharInfo[cnt0][cnt1].pattern = pat;
  378.             CharInfo[cnt0][cnt1].sprite = spr;
  379.             pat += CharInfo[cnt0][cnt1].xsize*CharInfo[cnt0][cnt1].ysize;
  380.             
  381.             SPR_setAttribute(CharInfo[cnt0][cnt1].sprite,CharInfo[cnt0][cnt1].xsize,CharInfo[cnt0][cnt1].ysize,CharInfo[cnt0][cnt1].pattern,257 | 0x8000 | 0x2000);
  382.         }
  383.     }
  384.     
  385.     SPR_display(1,SpriteCnt);
  386. }
  387.  
  388. void
  389. ClrObject()
  390. {
  391.     int cnt;
  392.     
  393.     SPR_display(2,SpriteCnt);
  394.     for (cnt=23;cnt<=SpriteCnt;cnt++) {
  395.         SPR_setAttribute(1024-cnt,1,1,128,256 | 0x8000 | 0x2000);
  396.     }
  397.     SPR_display(1,SpriteCnt);
  398. }
  399.  
  400. void
  401. DispObject()
  402. {
  403.     int cnt,x,y,pat;
  404.     
  405.     SpriteCnt = 22;
  406.     
  407.     SPR_display(2,SpriteCnt);
  408.     for (cnt=0;cnt<OBJMAX;cnt++) {
  409.         if (objlist[level][cnt].region == region && region != 0) {
  410.             pat = objlist[level][cnt].ptn_no;
  411.             SpriteCnt += PtnInfo[pat].xsize*PtnInfo[pat].ysize;
  412.             SPR_setAttribute(1024-SpriteCnt,PtnInfo[pat].xsize,PtnInfo[pat].ysize,PtnInfo[pat].ptn_no,PtnInfo[pat].pal | 0x8000 );
  413.             x = objlist[level][cnt].x*4-PtnInfo[pat].xsize*8;
  414.             y = 207-(PtnInfo[pat].ysize*16-1)-objlist[level][cnt].y*8;
  415.             SPR_setPosition(0,1024-SpriteCnt,PtnInfo[pat].xsize,PtnInfo[pat].ysize,x,y);
  416.         }
  417.     }
  418.     SPR_display(1,SpriteCnt);
  419. }
  420.  
  421. void
  422. EndProc()
  423. {
  424.     if (MusicFlag) {
  425.         MusicStop();
  426.     }
  427.     SPR_display(0,8);
  428. }
  429.  
  430. int
  431. JoyStatus(joy,button)
  432. int joy,button;
  433. {
  434.     if ((joy & (0x01 << button)) == 0) {
  435.         return(1);
  436.     }
  437.     return(0);
  438. }
  439.  
  440. void
  441. MoveChar(dir,phase,x,y)
  442. int dir,phase,x,y;
  443. {
  444.     static int dirb = -1;
  445.     static int phaseb = -1;
  446.     
  447.     x = x*4-8;
  448.     y = 207-(CharInfo[dir][phase].ysize*16-1)-y*8;
  449.     
  450.     SPR_display(2,SpriteCnt);
  451.     SPR_setPosition(0,CharInfo[dir][phase].sprite,CharInfo[dir][phase].xsize,CharInfo[dir][phase].ysize,x,y);
  452.     
  453.     if (dirb == dir && phaseb == phase) {
  454.         SPR_display(1,SpriteCnt);
  455.         return;
  456.     }
  457.     
  458.     SPR_setAttribute(CharInfo[dirb][phaseb].sprite,CharInfo[dirb][phaseb].xsize,CharInfo[dirb][phaseb].ysize,CharInfo[dirb][phaseb].pattern,259 | 0x8000 | 0x2000);
  459.     SPR_setAttribute(CharInfo[dir][phase].sprite,CharInfo[dir][phase].xsize,CharInfo[dir][phase].ysize,CharInfo[dir][phase].pattern,259 | 0x8000);
  460.     
  461.     SPR_display(1,SpriteCnt);
  462.     
  463.     dirb = dir;
  464.     phaseb = phase;
  465. }
  466.  
  467. int
  468. LowerY(x,y)
  469. int x,y;
  470. {
  471.     int ret,cnt1,cnt2;
  472.     
  473.     ret = 0;
  474.     for (cnt1=x-2;cnt1<x+2;cnt1++) {
  475.         if (0 <= cnt1 && cnt1 < 64) {
  476.             for (cnt2=y+2;cnt2!=0;cnt2--) {
  477.                 if (((int)(*(ScreenMap[region]+64*cnt2+cnt1))) & 0x80) {
  478.                     break;
  479.                 }
  480.             }
  481.             if (((int)(*(ScreenMap[region]+64*cnt2+cnt1))) & 0x80) {
  482.                 if (ret < cnt2+1) {
  483.                     ret = cnt2+1;
  484.                 }
  485.             }
  486.         }
  487.     }
  488.     return(ret);
  489. }
  490. int
  491. UpperY(x,y)
  492. int x,y;
  493. {
  494.     int ret,cnt1,cnt2;
  495.     
  496.     ret = 22;
  497.     for (cnt1=x-2;cnt1<x+2;cnt1++) {
  498.         if (0 <= cnt1 && cnt1 < 64) {
  499.             for (cnt2=y+2;cnt2!=22;cnt2++) {
  500.                 if (((int)(*(ScreenMap[region]+64 * cnt2 + cnt1))) & 0x80) {
  501.                     break;
  502.                 }
  503.             }
  504.             if (((int)(*(ScreenMap[region]+64 * cnt2 + cnt1))) & 0x80) {
  505.                 if (ret > cnt2) {
  506.                     ret = cnt2;
  507.                 }
  508.             }
  509.         }
  510.     }
  511.     return(ret);
  512. }
  513.  
  514. void
  515. UpdateStatus(joy)
  516. int joy;
  517. {
  518.     static int wait = 100;
  519.     static int jump_phase = 0;
  520.     static int phase = WALK1;
  521.     static int dir = DIR_RIGHT;
  522.     static int chartall = HIGH_TALL;
  523.     int landy,wally;
  524.     
  525.     if (JoyStatus(joy,DOWN)) {
  526.         chartall = LOW_TALL;
  527.     } else {
  528.         chartall = HIGH_TALL;
  529.     }
  530.     
  531.     if (JoyStatus(joy,LEFT)) {
  532.         dir = DIR_LEFT;
  533.         
  534.         landy = LowerY(Myx-1,Myy);
  535.         wally = UpperY(Myx-1,Myy)-landy;
  536.         if ((landy <= Myy+1) && (chartall <= wally) && (Myy <= landy+wally-chartall)) {
  537.             Myx --;
  538.             if (Myx < 0) {
  539.                 Myx = 0;
  540.             } else if (phase != LOW){
  541.                 phase++;
  542.             }
  543.         }
  544.     }
  545.     if (JoyStatus(joy,RIGHT)) {
  546.         dir = DIR_RIGHT;
  547.         
  548.         landy = LowerY(Myx+1,Myy);
  549.         wally = UpperY(Myx+1,Myy)-landy;
  550.         if ((landy <= Myy+1) && (chartall <= wally) && (Myy <= landy+wally-chartall)) {
  551.             Myx ++;
  552.             if (Myx > 64) {
  553.                 Myx = 64;
  554.             } else if (phase != LOW){
  555.                 phase++;
  556.             }
  557.         }
  558.     }
  559.     if (phase > 3) {
  560.         phase = 0;
  561.     }
  562.     landy = LowerY(Myx,Myy);
  563.     wally = UpperY(Myx,Myy)-landy;
  564.     if (JoyStatus(joy,TR_A) && wally > chartall) {
  565.         chartall = HIGH_TALL;
  566.         if (jump_phase < 4) {
  567.             jump_phase++;
  568.             Myy += JUMP_HIGHT;
  569.             if (Myy > wally+landy-chartall) {
  570.                 Myy = wally+landy-chartall;
  571.                 jump_phase = 10;
  572.             }
  573.             if (landy > Myy) {
  574.                 Myy = landy;
  575.                 jump_phase = 0;
  576.             }
  577.         } else if (jump_phase < 6) {
  578.             jump_phase++;
  579.         } else if (jump_phase >= 6) {
  580.             jump_phase++;
  581.             Myy -= JUMP_HIGHT;
  582.             if (landy > Myy) {
  583.                 Myy = landy;
  584.                 jump_phase = 0;
  585.             }
  586.         }
  587.     } else {
  588.         Myy -= JUMP_HIGHT;
  589.         jump_phase = 10;
  590.         if (landy >= Myy) {
  591.             Myy = landy;
  592.             jump_phase = 0;
  593.         }
  594.     }
  595.     if(jump_phase) {
  596.         phase = JUMP;
  597.         chartall = HIGH_TALL;
  598.     } else if (phase > LOW) {
  599.         phase = WALK1;
  600.     }
  601.     if (chartall == LOW_TALL) {
  602.         phase = LOW;
  603.     }
  604.     
  605.     MoveChar(dir,phase,Myx,Myy);
  606.     
  607. }
  608. void
  609. regionchg()
  610. {
  611.     int joy;
  612.  
  613.     if (NowMusic != MusicTable[region]) {
  614.         MusicStart(MusicTable[region]);
  615.     }
  616.     ClrObject();
  617.     mapedit();
  618.     DispObject();
  619.     do {
  620.         SND_joy_in_2(0,&joy);
  621.     }while(JoyStatus(joy,TR_B));
  622.     
  623. }
  624. void
  625. MessageBox(len)
  626. int len;
  627. {
  628.     CIRCLE circle;
  629.     BOX box;
  630.     LINE line;
  631.     ARC arc;
  632.     
  633.     EGB_color(GWork,0,MES_FRAME);
  634.     EGB_color(GWork,2,MES_BACK);
  635.     EGB_paintMode(GWork,0x20);
  636.     
  637.     circle.x = 75+9;
  638.     circle.y = 25+9;
  639.     circle.r = 9;
  640.     EGB_circle(GWork,(char *)&circle);
  641.     circle.x = 565-9;
  642.     circle.y = 25+9;
  643.     EGB_circle(GWork,(char *)&circle);
  644.     
  645.     box.x1 = 75+9;
  646.     box.y1 = 25;
  647.     box.x2 = 565-9;
  648.     box.y2 = 25+9;
  649.     EGB_rectangle(GWork,(char *)&box);
  650.     
  651.     circle.x = 75+9;
  652.     circle.y = 25+9+16*(len+1);
  653.     circle.r = 9;
  654.     EGB_circle(GWork,(char *)&circle);
  655.     circle.x = 565-9;
  656.     circle.y = 25+9+16*(len+1);
  657.     EGB_circle(GWork,(char *)&circle);
  658.     
  659.     box.x1 = 75+9;
  660.     box.y1 = 25+9+16*(len+1);
  661.     box.x2 = 565-9;
  662.     box.y2 = 25+9+16*(len+1)+9;
  663.     EGB_rectangle(GWork,(char *)&box);
  664.     
  665.     box.x1 = 75;
  666.     box.y1 = 25+9;
  667.     box.x2 = 565;
  668.     box.y2 = 25+9+16*(len+1);
  669.     EGB_rectangle(GWork,(char *)&box);
  670.     
  671.     EGB_paintMode(GWork,0x02);
  672.     
  673.     line.no = 2;
  674.     line.x1 = 75+9;
  675.     line.y1 = 25;
  676.     line.x2 = 565-9;
  677.     line.y2 = 25;
  678.     EGB_unConnect(GWork,(char *)&line);
  679.     
  680.     arc.x = 75+9;
  681.     arc.y = 25+9;
  682.     arc.x1 = -9;
  683.     arc.y1 = 0;
  684.     arc.x2 = 0;
  685.     arc.y2 = -9;
  686.     arc.r = 9;
  687.     EGB_arc(GWork,(char *)&arc);
  688.     
  689.     arc.x = 565-9;
  690.     arc.y = 25+9;
  691.     arc.x1 = 0;
  692.     arc.y1 = -9;
  693.     arc.x2 = 9;
  694.     arc.y2 = 0;
  695.     EGB_arc(GWork,(char *)&arc);
  696.     
  697.     line.x1 = 75;
  698.     line.y1 = 25+9;
  699.     line.x2 = 75;
  700.     line.y2 = 25+9+(len+1)*16;
  701.     EGB_unConnect(GWork,(char *)&line);
  702.     
  703.     line.x1 = 565;
  704.     line.x2 = 565;
  705.     EGB_unConnect(GWork,(char *)&line);
  706.     
  707.     arc.x = 75+9;
  708.     arc.y = 25+9+(len+1)*16;
  709.     arc.x1 = 0;
  710.     arc.y1 = 9;
  711.     arc.x2 = -9;
  712.     arc.y2 = 0;
  713.     EGB_arc(GWork,(char *)&arc);
  714.     
  715.     arc.x = 565-9;
  716.     arc.y = 25+9+(len+1)*16;
  717.     arc.x1 = 9;
  718.     arc.y1 = 0;
  719.     arc.x2 = 0;
  720.     arc.y2 = 9;
  721.     EGB_arc(GWork,(char *)&arc);
  722.     
  723.     line.no = 2;
  724.     line.x1 = 75+9;
  725.     line.y1 = 25+9+(len+1)*16+9;
  726.     line.x2 = 565-9;
  727.     line.y2 = 25+9+(len+1)*16+9;
  728.     EGB_unConnect(GWork,(char *)&line);
  729.     
  730. }
  731. void
  732. window(object)
  733. int object;
  734. {
  735.     int len; /* 文字列の長さ */
  736.     int loop; /* ウィンドウ中での行数 */
  737.     int cpylen; /* 1行でコピーする長さ */
  738.     int i,j,k;
  739.     int stat;
  740.     int *windbuf;
  741.     
  742.     /* windowサイズの背景のget */
  743.     windbuf=malloc(Windowbuf);
  744.     DWORD(para+0) = (unsigned int)windbuf;
  745.     WORD(para+4) = 0x14;
  746.     WORD(para+6) = 75;
  747.     WORD(para+8) = 25;
  748.     WORD(para+10) = 565;
  749.     WORD(para+12) = 130;
  750.     EGB_getBlock(GWork,para);
  751.  
  752.     do {
  753.         SND_joy_in_2(0,&stat);
  754.     } while((stat & 0x20) == 0);
  755.  
  756.     for(k=0;k<objlist[level][object].mes_no;k++) {
  757.         EGB_color(GWork,0,0);
  758.         len = strlen(objlist[level][object].message[k]);
  759.         loop = len/60;
  760.         if (len % 60) {
  761.             loop++;
  762.         }
  763.         MessageBox(loop-1);
  764.         EGB_color(GWork,0,objlist[level][object].mes_col[k]);
  765.         for(i=0;i<loop;i++) {
  766.             if(((len % 60) != 0) && (i == loop-1)) {
  767.                 cpylen=len % 60;
  768.             } else {
  769.                 cpylen=60;
  770.             }
  771.             WORD(para+0)=80;
  772.             WORD(para+2)=i*16+50;
  773.             WORD(para+4)=cpylen;
  774.             for(j=0;j<cpylen;j++)
  775.                 BYTE(para+6+j)=*(objlist[level][object].message[k]+i*60+j);
  776.             EGB_sjisString(GWork,para);
  777.         }
  778.         SND_joy_in_2(0,&stat);
  779.         while((stat & 0x20) != 0)
  780.             SND_joy_in_2(0,&stat);
  781.         while((stat & 0x20) == 0)
  782.             SND_joy_in_2(0,&stat);
  783.     }
  784.     DWORD(para+0) = (unsigned int)windbuf;
  785.     WORD(para+4) = 0x14;
  786.     WORD(para+6) = 75;
  787.     WORD(para+8) = 25;
  788.     WORD(para+10) = 565;
  789.     WORD(para+12) = 130;
  790.     EGB_putBlock(GWork,0,para);
  791.     free(windbuf);
  792. }
  793. void
  794. LevelUp()
  795. {
  796.     int joy;
  797.     
  798. /*
  799.     ClrObject();
  800. */
  801.     level++;
  802.     if (level == 20) {
  803.         if (MusicFlag) {
  804.             MusicStart(MUS_END);
  805.         }
  806.         Ending();
  807.         return;
  808.     }
  809.     
  810.     DispObject();
  811.     do {
  812.         SND_joy_in_2(0,&joy);
  813.     }while(JoyStatus(joy,TR_B));
  814. }
  815.  
  816. int
  817. Event(joy)
  818. int joy;
  819. {
  820.     int cnt,change;
  821.     
  822.     change = 0;
  823.     if (JoyStatus(joy,TR_B)) {
  824.         /* オブジェクトの数だけチェック */
  825.         for(cnt=0;cnt<OBJMAX;cnt++) {
  826.             /* オブジェクトとマイキャラのX座標,Y座標が同じか */
  827.             if((region == objlist[level][cnt].region) && (Myx > ((objlist[level][cnt].x)-5)) && (Myx < (objlist[level][cnt].x)+5) && (Myy > (objlist[level][cnt].y)-5) && (Myy < (objlist[level][cnt].y)+5) && region != 0) {
  828.                 window(cnt);
  829.                 if (objlist[level][cnt].level_up != 0) {
  830.                     LevelUp();
  831.                     if (level >= 20) {
  832.                         return(1);
  833.                     }
  834.                     change = 1;
  835.                 }
  836.                 /* リージョンチェンジが発生したか */
  837.                 if( objlist[level][cnt].reg_chg != 99 ) {
  838.                 /* マイキャラの移動 */
  839.                     if((cnt==12)&&(level<11)) {
  840.                         Myx=25;
  841.                         Myy=13;
  842.                     }
  843.                     if((cnt==32)&&(level<11)) {
  844.                         Myx=30;
  845.                         Myy=1;
  846.                     }
  847.  
  848.                     if((level==17)&&(cnt==36)) {
  849.                         if(door==0) door=1;
  850.                         else door=0;
  851.                     }
  852.                     if((level==17)&&(cnt==38)) {
  853.                         if(door==1) door=2;
  854.                         else door=0;
  855.                     }
  856.                     if((level==17)&&(cnt==35)) {
  857.                         if(door==2) door=3;
  858.                         else door=0;
  859.                     }
  860.                     if((level==17)&&(cnt==37)) {
  861.                         if(door==3) door=4;
  862.                         else door=0;
  863.                     }
  864.                     if(door==4) objlist[17][36].reg_chg=37;
  865.  
  866.  
  867.                     region=objlist[level][cnt].reg_chg;
  868.                     regionchg();
  869.                     change = 1;
  870.                 }
  871.                 if (change) {
  872.                     return(0);
  873.                 }
  874.             }
  875.         }
  876.     }
  877.  
  878.     /* 画面左端からのリージョンチェンジ */
  879.     if((JoyStatus(joy,LEFT)) && (Myx == 0) && (regionmap[region].LeftRegion != 99)) {
  880.         region=regionmap[region].LeftRegion;
  881.         regionchg();
  882.         Myx=63;
  883.     }
  884.  
  885.     /* 画面右端からのリージョンチェンジ */
  886.     if((JoyStatus(joy,RIGHT)) && (Myx == 64) && (regionmap[region].RightRegion != 99)) {
  887.         region=regionmap[region].RightRegion;
  888.         regionchg();
  889.         Myx=1;
  890.     }
  891.     return(0);
  892. }
  893.  
  894. void
  895. main(argc,argv)
  896. int argc;
  897. char *argv[];
  898. {
  899.     int joy,wait,end;
  900.     wait=0;
  901.     
  902.     if (argc == 1) {
  903.         WaitCnt = 0;
  904.     } else if (argc == 2) {
  905.         WaitCnt = atoi(argv[1]);
  906.     } else {
  907.         WaitCnt = atoi(argv[1]);
  908.         level = atoi(argv[2]);
  909.     }
  910.  
  911.     mesinit1();
  912.     mesinit2();
  913.     mesinit3();
  914.     mesinit4();
  915.     mapset00();
  916.     mapset01();
  917.     mapset02();
  918.     mapset03();
  919.     mapset04();
  920.     mapset05();
  921.     mapset06();
  922.     mapset07();
  923.     mapset08();
  924.     mapset09();
  925.     mapset10();
  926.     mapset11();
  927.     mapset12();
  928.     mapset13();
  929.     mapset14();
  930.     mapset15();
  931.     mapset16();
  932.     mapset17();
  933.     mapset18();
  934.     mapset19();
  935.     mapset20();
  936.     mapset21();
  937.     mapset22();
  938.     mapset23();
  939.     mapset24();
  940.     mapset25();
  941.     mapset26();
  942.     mapset27();
  943.     mapset28();
  944.     mapset29();
  945.     mapset30();
  946.     mapset31();
  947.     mapset32();
  948.     mapset33();
  949.     mapset34();
  950.     mapset35();
  951.     mapset36();
  952.     mapset37();
  953.     mapset38();
  954.     mapset39();
  955.     
  956.     
  957.     ReadData(1);
  958.     DrawFrame(1);
  959.     
  960.     MusicInit();
  961.     if (level == 0) {
  962.         MusicStart(MUS_OPEN);
  963.         Opening();
  964.     }
  965.     
  966.     if (MusicFlag) {
  967.         MusicStart(MUS_TOWN);
  968.     }
  969.     
  970.     GInit();
  971.     
  972.     CharSet();
  973.     DispObject();
  974.     
  975.     joy = 0xff;
  976.     end = 0;
  977.     
  978.     do {
  979.         
  980.         SND_joy_in_2(0,&joy);
  981.         
  982.         if (JoyStatus(joy,SELECT)) {
  983.             end = Help();
  984.         }
  985.         if (wait >= WaitCnt) {
  986.             
  987.             UpdateStatus(joy);
  988.             
  989.             if (Event(joy)) {
  990.                 end++;
  991.             }
  992.             wait = 0;
  993.         } else {
  994.             wait++;
  995.         }
  996.     } while(!end);
  997.     
  998.     EndProc();
  999.  
  1000. }
  1001.