X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Fbakapi.c;h=6d04e5470eba75baabc399d6e44b9099e8d51218;hb=25b9bc83026e8a72be55c8ba9ad73496e8654e50;hp=28faa99d7c53c9663811565cf58873b06fd7e277;hpb=07346f616e3fe792fd34aba5e80afaddb8cf47e7;p=16.git diff --git a/src/bakapi.c b/src/bakapi.c index 28faa99d..6d04e547 100755 --- a/src/bakapi.c +++ b/src/bakapi.c @@ -28,11 +28,65 @@ global_game_variables_t gvar; static bakapee_t bakapee; word key,d,xpos,ypos,xdir,ydir; +sword vgamodex_mode = 1; // 320x240 default int ch=0x0; void main(int argc, char *argvar[]) { + char *a; + int i; + word panq=1, pand=0; + boolean panswitch=0; + + // allow changing default mode from command line + for (i=1;i < argc;) { + a = argvar[i++]; + + if (*a == '-') { + do { a++; } while (*a == '-'); + + if (!strcmp(a,"mx")) { + // (based on src/lib/modex16.c) + // 1 = 320x240 + // 2 = 160x120 + // 3 = 320x200 + // 4 = 192x144 + // 5 = 256x192 + vgamodex_mode = (sword)strtoul(argvar[i++],NULL,0); + } + else { + fprintf(stderr,"Unknown switch %s\n",a); + return; + } + } + else { + fprintf(stderr,"Unknown command arg %s\n",a); + return; + } + } + + // DOSLIB: check our environment + probe_dos(); + + // DOSLIB: what CPU are we using? + // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS. + // So this code by itself shouldn't care too much what CPU it's running on. Except that other + // parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for + // the CPU to carry out tasks. --J.C. + cpu_probe(); + + // DOSLIB: check for VGA + if (!probe_vga()) { + printf("VGA probe failed\n"); + return; + } + // hardware must be VGA or higher! + if (!(vga_state.vga_flags & VGA_IS_VGA)) { + printf("This program requires VGA or higher graphics hardware\n"); + return; + } + // main variables values d=4; // switch variable key=2; // default screensaver number @@ -41,39 +95,10 @@ main(int argc, char *argvar[]) xdir=1; ydir=1; -#ifdef MXLIB - VGAmodeX(1, &gvar); -#else - probe_dos(); - if (!probe_vga()) { - printf("VGA probe failed\n"); - return 1; - } - int10_setmode(19); - update_state_from_vga(); - vga_enable_256color_modex(); // VGA mode X - vga_state.vga_width = 320; // VGA lib currently does not update this - vga_state.vga_height = 240; // VGA lib currently does not update this - -//#if 1 // 320x240 test mode: this is how Project 16 is using our code, enable for test case - { - struct vga_mode_params cm; + VGAmodeX(vgamodex_mode, 1, &gvar); // TODO: Suggestion: Instead of magic numbers for the first param, might I suggest defining an enum or some #define constants that are easier to remember? --J.C. + // this code is written around modex16 which so far is a better fit than using DOSLIB vga directly, so leave MXLIB code in. + // we'll integrate DOSLIB vga into that part of the code instead for less disruption. -- J.C. - vga_read_crtc_mode(&cm); - - // 320x240 mode 60Hz - cm.vertical_total = 525; - cm.vertical_start_retrace = 0x1EA; - cm.vertical_end_retrace = 0x1EC; - cm.vertical_display_end = 480; - cm.vertical_blank_start = 489; - cm.vertical_blank_end = 517; - - vga_write_crtc_mode(&cm,0); - } - vga_state.vga_height = 240; // VGA lib currently does not update this -//#endif -#endif bakapee.xx = rand()&0%gvar.video.page[0].width; bakapee.yy = rand()&0%gvar.video.page[0].height; bakapee.gq = 0; @@ -100,33 +125,123 @@ main(int argc, char *argvar[]) #ifdef BOINK while(d>0) // on! { - if(!kbhit()) - { // conditions of screen saver - ding(&gvar.video.page[0], &bakapee, key); + int c; + /* run screensaver routine until keyboard input */ + while (key > 0) { + if (kbhit()) { + if(!panswitch) + { + getch(); // eat keyboard input + break; + }else c=getch(); + } + + if(!panswitch) ding(&gvar.video.page[0], &bakapee, key); + else ding(&gvar.video.page[0], &bakapee, 2); + if(panswitch!=0) + { + //right movement + if((c==0x4d && pand == 0) || pand == 2) + { + if(pand == 0){ pand = 2; } + if(panq<=(TILEWH/(4))) + { + gvar.video.page[0].dx++; + modexShowPage(&gvar.video.page[0]); + panq++; + } else { panq = 1; pand = 0; } + } + //left movement + if((c==0x4b && pand == 0) || pand == 4) + { + if(pand == 0){ pand = 4; } + if(panq<=(TILEWH/(4))) + { + gvar.video.page[0].dx--; + modexShowPage(&gvar.video.page[0]); + panq++; + } else { panq = 1; pand = 0; } + } + //down movement + if((c==0x50 && pand == 0) || pand == 3) + { + if(pand == 0){ pand = 3; } + if(panq<=(TILEWH/(4))) + { + gvar.video.page[0].dy++; + modexShowPage(&gvar.video.page[0]); + panq++; + } else { panq = 1; pand = 0; } + } + //up movement + if((c==0x48 && pand == 0) || pand == 1) + { + if(pand == 0){ pand = 1; } + if(panq<=(TILEWH/(4))) + { + gvar.video.page[0].dy--; + modexShowPage(&gvar.video.page[0]); + panq++; + } else { panq = 1; pand = 0; } + } + if(c==0x71 || c==0xb1 || c=='p') + { + //getch(); // eat keyboard input + panswitch=0; + break; // 'q' or 'ESC' or 'p' + } + } } - else + { -#ifndef MXLIB - int10_setmode(3); -#else - VGAmodeX(0, &gvar); -#endif + + // this code is written around modex16 which so far is a better fit than using DOSLIB vga directly, so leave MXLIB code in. + // we'll integrate DOSLIB vga into that part of the code instead for less disruption. -- J.C. + VGAmodeX(0, 0, &gvar); // user imput switch - fprintf(stderr, "xx=%d yy=%d tile=%d\n", bakapee.xx, bakapee.yy, bakapee.tile); - printf("Enter 1, 2, 3, 4, or 6 to run a screensaver, or enter 0 to quit.\n", getch()); // prompt the user - //scanf("%d", &key); - if(scanf("%d", &key) != 1) + //fprintf(stderr, "xx=%d yy=%d tile=%d\n", bakapee.xx, bakapee.yy, bakapee.tile); + printf("Tiled mode is "); + switch (bakapee.tile) { - printf("%d\n", key); + case 0: + printf("off. "); + break; + case 1: + printf("on. "); + break; } - getch(); - //if(key==3){xx=yy=0;} // crazy screen saver wwww - switch (key) + //printf("\n"); + printf("Pan mode is "); + switch (panswitch) { case 0: + printf("off.\n"); + break; + case 1: + printf("on.\n"); + break; + } + printf("Enter 1, 2, 3, 4, 5, 6, 8, or 9 to run a screensaver, or enter 0 to quit.\n"); +pee: + c = getch(); + switch (c) { + case 27: /* Escape key */ + case '0': d=0; + break; + case 'p': // test pan + switch (panswitch) + { + case 0: + panswitch=1; + break; + case 1: + panswitch=0; + break; + } + goto pee; break; - case 65536: + case 'b': // test tile change switch (bakapee.tile) { case 0: @@ -136,124 +251,66 @@ main(int argc, char *argvar[]) bakapee.tile=0; break; } - d=2; - default: -#ifdef MXLIB + key=0; + break; + case '8': + c+=8; + case '1': + case '2': + case '3': + case '4': + case '5': + case '6': + case '9': + key = c - '0'; gvar.video.page[0] = modexDefaultPage(&gvar.video.page[0]); gvar.video.page[0].width += (TILEWH*2); gvar.video.page[0].height += (TILEWH*2); - VGAmodeX(1, &gvar); -#else - probe_dos(); - if (!probe_vga()) { - printf("VGA probe failed\n"); - return 1; - } - int10_setmode(19); - update_state_from_vga(); - vga_enable_256color_modex(); // VGA mode X - vga_state.vga_width = 320; // VGA lib currently does not update this - vga_state.vga_height = 240; // VGA lib currently does not update this - -//#if 1 // 320x240 test mode: this is how Project 16 is using our code, enable for test case - { - struct vga_mode_params cm; - - vga_read_crtc_mode(&cm); - - // 320x240 mode 60Hz - cm.vertical_total = 525; - cm.vertical_start_retrace = 0x1EA; - cm.vertical_end_retrace = 0x1EC; - cm.vertical_display_end = 480; - cm.vertical_blank_start = 489; - cm.vertical_blank_end = 517; - - vga_write_crtc_mode(&cm,0); - } - vga_state.vga_height = 240; // VGA lib currently does not update this -//#endif -#endif + VGAmodeX(vgamodex_mode, 0, &gvar); + // this code is written around modex16 which so far is a better fit than using DOSLIB vga directly, so leave MXLIB code in. + // we'll integrate DOSLIB vga into that part of the code instead for less disruption. -- J.C. modexShowPage(&gvar.video.page[0]); - break; + break; + default: + key=0; + break; } } } -#else +#else // !defined(BOINK) +// FIXME: Does not compile. Do you want to remove this? +// TODO: This is a testing sextion for textrendering and panning for project 16 --sparky4 while(1) { // conditions of screen saver - while(!kbhit()) - { - ding(&gvar.video.page[0], &bakapee, key); - } +// while(!kbhit()) +// { +// ding(&gvar.video.page[0], &bakapee, key); +// } //end of screen savers - /*for(int x = 0; x < gvar.video.page[0].width; ++x) - { - modexputPixel(&page, x, 0, 15); - mxPutPixel(x, gvar.video.page[0].height-1, 15); - } - for (int y = 0; y < VH; ++y) - { - mxPutPixel(0, y, 15); - mxPutPixel(gvar.video.page[0].width-1, y, 15); - } - for (int x = 0; x < VW; ++x) - { - mxPutPixel(x, 0, 15); - mxPutPixel(x, VH-1, 15); - } - for (int y = 240; y < VH; ++y) - { - mxPutPixel(0, y, 15); - mxPutPixel(VW-1, y, 15); - }*/ - pdump(&gvar.video.page[0]); - getch(); - //text box - /*++++mxBitBlt(xpos, ypos+(TILEWH*12), gvar.video.page[0].width, TILEWH*BUFFMX, 0, BS); //copy background - mxFillBox(xpos, ypos+(TILEWH*12), gvar.video.page[0].width, TILEWH*BUFFMX, 0, OP_SET); // background for text box - //+(QUADWH*6) - mxOutText(xpos+1, ypos+gvar.video.page[0].height-48, "========================================"); - mxOutText(xpos+1, ypos+gvar.video.page[0].height-40, "| |Chikyuu:$line1"); - mxOutText(xpos+1, ypos+gvar.video.page[0].height-32, "| |$line2"); - mxOutText(xpos+1, ypos+gvar.video.page[0].height-24, "| |$line3"); - mxOutText(xpos+1, ypos+gvar.video.page[0].height-16, "| |$line4"); - mxOutText(xpos+1, ypos+gvar.video.page[0].height-8, "========================================"); - mxFillBox(xpos+QUADWH, ypos+QUADWH+(TILEWH*12), TILEWH*2, TILEWH*2, 9, OP_SET); //portriat~ - getch(); - mxBitBlt(0, BS, gvar.video.page[0].width, TILEWH*BUFFMX, xpos, ypos+(TILEWH*12)); //copy background - getch();++++*/ - while(!kbhit()) - { - //for(int i=0;i(VW-gvar.video.page[0].width-1)) || (xpos<1))delay(500); - //mxWaitRetrace(); -//mxBitBlt(32, (gvar.video.page[0].height+32), gvar.video.page[0].width, gvar.video.page[0].height, xpos, ypos); -//++++mxBitBlt(TILEWH*2, (gvar.video.page[0].height+64+32), gvar.video.page[0].width, gvar.video.page[0].height, TILEWH*2, TILEWH*2); -//xpos=ypos=TILEWH*2; - //????modexPanPage(&gvar.video.page[0], 32, 32); - //} - if( (xpos>(VW-gvar.video.page[0].width-1)) || (xpos<1)){xdir=-xdir;} - if( (ypos>(BH-gvar.video.page[0].height-1)) || (ypos<1)){ydir=-ydir;} // { Hit a boundry, change - //}// direction! -//mxBitBlt(32, (gvar.video.page[0].height+64+32), gvar.video.page[0].width, gvar.video.page[0].height, xpos, ypos); -//mxBitBlt(TILEWH*2, (gvar.video.page[0].height+64+32), gvar.video.page[0].width, gvar.video.page[0].height, TILEWH*2, TILEWH*2); - } - ch=getch(); + //pdump(&gvar.video.page[0]); + +// mxOutText(xpos+1, ypos+gvar.video.page[0].height-48, "========================================"); +// mxOutText(xpos+1, ypos+gvar.video.page[0].height-40, "| |Chikyuu:$line1"); +// mxOutText(xpos+1, ypos+gvar.video.page[0].height-32, "| |$line2"); +// mxOutText(xpos+1, ypos+gvar.video.page[0].height-24, "| |$line3"); +// mxOutText(xpos+1, ypos+gvar.video.page[0].height-16, "| |$line4"); +// mxOutText(xpos+1, ypos+gvar.video.page[0].height-8, "========================================"); + + ding(&gvar.video.page[0], &bakapee, key); + modexPanPage(&gvar.video.page[0], xpos, ypos); + c = getch(); + +// xpos+=xdir; +// ypos+=ydir; +// if( (xpos>(VW-gvar.video.page[0].width-1)) || (xpos<1)){xdir=-xdir;} +// if( (ypos>(BH-gvar.video.page[0].height-1)) || (ypos<1)){ydir=-ydir;} +// ch=getch(); if(ch==0x71)break; // 'q' if(ch==0x1b)break; // 'ESC' } -// VGAmodeX(0, &gvar); -#endif - printf("bakapi ver. 1.04.13.04\nis made by sparky4i†ƒÖ…j feel free to use it ^^\nLicence: GPL v3\n"); + VGAmodeX(0, 1, &gvar); +#endif // defined(BOINK) + printf("bakapi ver. 1.04.16.04\nis made by sparky4i†ƒÖ…j feel free to use it ^^\nLicence: GPL v3\n"); + printf("compiled on 2016/04/04\n"); } //pee!