X-Git-Url: http://4ch.mooo.com/gitweb/?a=blobdiff_plain;f=src%2Flib%2F16_tail.c;h=9cb0e76997507b1c8dbbb1eb3d7503c98a4877ee;hb=f888d29c0ceaa48568b15f3269df70e6498c9dbc;hp=414e51a17c3bb33a5ce82106c127d7a9a19d13b0;hpb=2e3fb239b58cf341ceb5b4e7b39b6542f5581cae;p=16.git diff --git a/src/lib/16_tail.c b/src/lib/16_tail.c index 414e51a1..9cb0e769 100755 --- a/src/lib/16_tail.c +++ b/src/lib/16_tail.c @@ -1,5 +1,5 @@ /* Project 16 Source Code~ - * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover + * Copyright (C) 2012-2018 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover * * This file is part of Project 16. * @@ -20,10 +20,11 @@ * */ /* - * 16 library + * 16 tail library */ #include "src/lib/16_tail.h" +#include "src/lib/16text.h" /* ========================== @@ -35,50 +36,80 @@ ========================== */ -void Startup16(global_game_variables_t *gvar) +void Startup16 (global_game_variables_t *gvar) { + gvar->video.VL_Started=0; + TL_VidInit(gvar); + gvar->mm.mmstarted=0; + gvar->pm.PMStarted=0; + StartupCAMMPM(gvar); #ifdef __WATCOMC__ - // 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; - } +#ifdef __DEBUG_InputMgr__ + if(!dbg_nointest) +#endif + IN_Startup(gvar); +#endif +} + +//=========================================================================== + +/* +========================== += += Shutdown16 += += Shuts down all ID_?? managers += +========================== +*/ - if (_DEBUG_INIT() == 0) { -#ifdef DEBUGSERIAL - printf("WARNING: Failed to initialize DEBUG output\n"); +void Shutdown16 (global_game_variables_t *gvar) +{ +#ifdef __WATCOMC__ +#ifdef __DEBUG_InputMgr__ + if(!dbg_nointest) #endif - } - _DEBUG("Serial debug output started\n"); // NTS: All serial output must end messages with newline, or DOSBox-X will not emit text to log - _DEBUGF("Serial debug output printf test %u %u %u\n",1U,2U,3U); + IN_Shutdown(gvar); #endif - gvar->mm.mmstarted=0; - gvar->pm.PMStarted=0; + ShutdownCAMMPM(gvar); +#ifdef __WATCOMC__ + if(gvar->video.VL_Started) + VL_Shutdown (gvar);//VGAmodeX(0, 1, gvar); +#endif +} + +//=========================================================================== + +/* +========================== += += StartupCAMMPM += +========================== +*/ + +void StartupCAMMPM (global_game_variables_t *gvar) +{ +/* + MM_Startup (); // so the signon screen can be freed + + SignonScreen (); + + VW_Startup (); + IN_Startup (); + PM_Startup (); + PM_UnlockMainMem (); + SD_Startup (); + CA_Startup (); + US_Startup (); +*/ MM_Startup(gvar); -if(!dbg_noplayerinpu) - IN_Startup(gvar); +#ifdef __16_PM__ PM_Startup(gvar); +//???? PM_CheckMainMem(gvar); PM_UnlockMainMem(gvar); - CA_Startup(gvar); -#ifdef __WATCOMC__ - start_timer(gvar); #endif - + CA_Startup(gvar); } //=========================================================================== @@ -86,22 +117,398 @@ if(!dbg_noplayerinpu) /* ========================== = -= Shutdown16 -= -= Shuts down all ID_?? managers += ShutdownCAMMPM = ========================== */ -void Shutdown16(global_game_variables_t *gvar) +void ShutdownCAMMPM (global_game_variables_t *gvar) { +/* + US_Shutdown (); + SD_Shutdown (); + PM_Shutdown (); + IN_Shutdown (); + VW_Shutdown (); + CA_Shutdown (); + MM_Shutdown () +*/ +#ifdef __16_PM__ PM_Shutdown(gvar); -if(!dbg_noplayerinpu) - IN_Shutdown(gvar); +#endif CA_Shutdown(gvar); MM_Shutdown(gvar); } +//=========================================================================== + +//////////////////////////////////////////////////////////////////// +// +// HANDLE INTRO SCREEN (SYSTEM CONFIG) +// +//////////////////////////////////////////////////////////////////// +void MU_IntroScreen(global_game_variables_t *gvar) +{ +#define MAINCOLOR 0x6c +#define EMSCOLOR 0x6c +#define XMSCOLOR 0x6c + +#define FILLCOLOR 14 + + long memory,emshere,xmshere; + int i,num,ems[10]={100,200,300,400,500,600,700,800,900,1000}, + xms[10]={100,200,300,400,500,600,700,800,900,1000}, + main[10]={32,64,96,128,160,192,224,256,288,320}; + + gvar->video.print.t=1; + gvar->video.print.tlsw=1; + gvar->video.print.bgcolor=8; + gvar->video.print.color=5; + + // + // DRAW MAIN MEMORY + // + num=32; + gvar->video.print.x=49-32; + + memory=(1023l+gvar->mmi.nearheap+gvar->mmi.farheap)/1024l; + for (i=0;i<10;i++) + if (memory>=main[i]) + { + gvar->video.print.y=163-8*i; + sprintf(global_temp_status_text, "% 4u", num); VL_print(global_temp_status_text, 0, gvar); + VL_Bar(49,163-8*i,6,5,MAINCOLOR-i,gvar); + num+=32; + } + gvar->video.print.y=171; + VL_print("MAIN", 0, gvar); + + + // + // DRAW EMS MEMORY + // + if (gvar->pm.emm.EMSPresent) + { + num=100; + gvar->video.print.x=89-32; + + emshere=4l*gvar->pm.emm.EMSPagesAvail; + for (i=0;i<10;i++) + if (emshere>=ems[i]) + { + gvar->video.print.y=163-8*i; + sprintf(global_temp_status_text, "% 4u", num); VL_print(global_temp_status_text, 0, gvar); + VL_Bar(89,163-8*i,6,5,EMSCOLOR-i,gvar); + num+=100; + } + gvar->video.print.y=171; + VL_print(" EMS", 0, gvar); + } + + // + // DRAW XMS MEMORY + // + if (gvar->pm.xmm.XMSPresent) + { + num=100; + gvar->video.print.x=129-32; + + xmshere=4l*gvar->pm.xmm.XMSPagesAvail; + for (i=0;i<10;i++) + if (xmshere>=xms[i]) + { + gvar->video.print.y=163-8*i; + sprintf(global_temp_status_text, "% 4u", num); VL_print(global_temp_status_text, 0, gvar); + VL_Bar(129,163-8*i,6,5,XMSCOLOR-i,gvar); + num+=100; + } + gvar->video.print.y=171; + VL_print(" XMS", 0, gvar); + } + + // + // FILL BOXES + // + if (gvar->in.MousePresent) + VL_Bar(164,82,12,2,FILLCOLOR,gvar); + + if (gvar->in.JoysPresent[0] || gvar->in.JoysPresent[1]) + VL_Bar(164,105,12,2,FILLCOLOR,gvar); + +//++++ if (gvar->sd.AdLibPresent)//SB && !SoundBlasterPresent) +//++++ VL_Bar(164,128,12,2,FILLCOLOR,gvar); + +//SB if (SoundBlasterPresent) +//SB VL_Bar(164,151,12,2,FILLCOLOR,gvar); + +//SS if (SoundSourcePresent) +//SS VL_Bar(164,174,12,2,FILLCOLOR,gvar); + IN_Ack (gvar); +} + +//=========================================================================== + +/* +==================== += += ReadConfig += +==================== +*/ +#if 0 +void ReadConfig(void) +{ + int file; +// SDMode sd; +// SMMode sm; +// SDSMode sds; + + + if ( (file = open(CONFIGNAME,O_BINARY | O_RDONLY)) != -1) + { + // + // valid config file + // +// read(file,Scores,sizeof(HighScore) * MaxScores); + +// read(file,&sd,sizeof(sd)); +// read(file,&sm,sizeof(sm)); +// read(file,&sds,sizeof(sds)); + + read(file,&mouseenabled,sizeof(mouseenabled)); + read(file,&joystickenabled,sizeof(joystickenabled)); + read(file,&joystickprogressive,sizeof(joystickprogressive)); + read(file,&joystickport,sizeof(joystickport)); + + read(file,&dirscan,sizeof(dirscan)); + read(file,&buttonscan,sizeof(buttonscan)); + read(file,&buttonmouse,sizeof(buttonmouse)); + read(file,&buttonjoy,sizeof(buttonjoy)); + + read(file,&viewsize,sizeof(viewsize)); + read(file,&mouseadjustment,sizeof(mouseadjustment)); + + close(file); + + /*if (sd == sdm_AdLib && !AdLibPresent && !SoundBlasterPresent) + { + sd = sdm_PC; + sd = smm_Off; + } + + if ((sds == sds_SoundBlaster && !SoundBlasterPresent) || + (sds == sds_SoundSource && !SoundSourcePresent)) + sds = sds_Off;*/ + + if (!MousePresent) + mouseenabled = false; + if (!JoysPresent[joystickport]) + joystickenabled = false; + + MainMenu[6].active=1; + MainItems.curpos=0; + } + else + { + // + // no config file, so select by hardware + // +/* if (SoundBlasterPresent || AdLibPresent) + { + sd = sdm_AdLib; + sm = smm_AdLib; + } + else + { + sd = sdm_PC; + sm = smm_Off; + } + + if (SoundBlasterPresent) + sds = sds_SoundBlaster; + else if (SoundSourcePresent) + sds = sds_SoundSource; + else + sds = sds_Off;*/ + + if (MousePresent) + mouseenabled = true; + + joystickenabled = false; + joystickport = 0; + joystickprogressive = false; + + viewsize = 15; + mouseadjustment=5; + } + + SD_SetMusicMode (sm); + SD_SetSoundMode (sd); + SD_SetDigiDevice (sds); +} + + +/* +==================== += += WriteConfig += +==================== +*/ + +void WriteConfig(void) +{ + int file; + + file = open(CONFIGNAME,O_CREAT | O_BINARY | O_WRONLY, + S_IREAD | S_IWRITE | S_IFREG); + + if (file != -1) + { +// write(file,Scores,sizeof(HighScore) * MaxScores); + +// write(file,&SoundMode,sizeof(SoundMode)); +// write(file,&MusicMode,sizeof(MusicMode)); +// write(file,&DigiMode,sizeof(DigiMode)); + + write(file,&mouseenabled,sizeof(mouseenabled)); + write(file,&joystickenabled,sizeof(joystickenabled)); + write(file,&joystickprogressive,sizeof(joystickprogressive)); + write(file,&joystickport,sizeof(joystickport)); + + write(file,&dirscan,sizeof(dirscan)); + write(file,&buttonscan,sizeof(buttonscan)); + write(file,&buttonmouse,sizeof(buttonmouse)); + write(file,&buttonjoy,sizeof(buttonjoy)); + +// write(file,&viewsize,sizeof(viewsize)); + write(file,&mouseadjustment,sizeof(mouseadjustment)); + + close(file); + } +} +#endif +//=========================================================================== + +/* +=================== += += FizzleFade += +=================== +*/ + +boolean FizzleFade (unsigned source, unsigned dest, unsigned width, unsigned height, unsigned frames, boolean abortable, global_game_variables_t *gvar) +{ + word p,pixperframe; + unsigned drawofs,pagedelta; + byte mask,maskb[8] = {1,2,4,8}; + unsigned x,y,frame; + long rndval; + word screenseg; +#ifdef __WATCOMC__ + unsigned esorig;//,q; +#endif + + pagedelta = dest-source; + rndval = 1; +#ifdef __WATCOMC__ + esorig = 0;// q = 16; +#endif + x = y = 0; + pixperframe = (dword)(gvar->video.page[0].width*gvar->video.page[0].height)/frames; + screenseg = SCREENSEG; + + IN_StartAck (gvar); + +// modexClearRegion(&(gvar->video.page[0]), 0, 0, gvar->video.page[0].width, gvar->video.page[0].height, 0); +// modexClearRegion(&(gvar->video.page[1]), 0, 0, gvar->video.page[0].width, gvar->video.page[0].height, 15); + +#ifdef __WATCOMC__ + __asm { + mov [esorig],es + } +#endif +// TimeCount= + frame=0; + do // while (1) + { + if (abortable && IN_CheckAck (gvar) ) + return true; + + __asm { + mov es,[screenseg] + } + + for (p=0;pwidth || y>height) +// if ((x>width || y>height) && (xvideo.ofs.ylookup[y]) + (x>>2); + drawofs = source+(y*gvar->video.page[0].stridew) + (x>>2); + + // + // copy one pixel + // + mask = x&3; + VGAREADMAP(mask); + mask = maskb[mask]; + VGAMAPMASK(mask); + + __asm { + mov di,[drawofs] + mov al,[es:di] + add di,[pagedelta] + mov [es:di],al + } + + if (rndval == 1) // entire sequence has been completed + return false; + } + frame++; +//-- while (TimeCount=STARTTILE8) + sprite = STARTTILE8-1; + else if (spritewidth);US_Print ("\n");PrintX=hx; + US_PrintUnsigned (spr->height);US_Print ("\n");PrintX=hx; + US_PrintSigned (spr->orgx);US_Print ("\n");PrintX=hx; + US_PrintSigned (spr->orgy);US_Print ("\n");PrintX=hx; + US_PrintSigned (spr->xl);US_Print ("\n");PrintX=hx; + US_PrintSigned (spr->yl);US_Print ("\n");PrintX=hx; + US_PrintSigned (spr->xh);US_Print ("\n");PrintX=hx; + US_PrintSigned (spr->yh);US_Print ("\n");PrintX=hx; + US_PrintSigned (spr->shifts);US_Print ("\n");PrintX=hx; + if (!block) + { + US_Print ("-----"); + } + else + { + mem = block->sourceoffset[3]+5*block->planesize[3]; + mem = (mem+15)&(~15); // round to paragraphs + US_PrintUnsigned (mem); + } + + oldsprite = sprite; + do + { + // + // draw the current shift, then wait for key + // + VL_Bar(topx,hy,DISPWIDTH,bottomy-hy,WHITE); + if (block) + { + PrintX = topx; + PrintY = hy; + US_Print ("Shift:"); + US_PrintUnsigned (shift); + US_Print ("\n"); + VWB_DrawSprite (topx+16+shift*2,PrintY,sprite); + } + + VW_UpdateScreen(); + + scan = IN_WaitForKey (); + + switch (scan) + { + case sc_UpArrow: + sprite++; + break; + case sc_DownArrow: + sprite--; + break; + case sc_LeftArrow: + if (--shift == -1) + shift = 3; + break; + case sc_RightArrow: + if (++shift == 4) + shift = 0; + break; + case sc_Escape: + return; + } + + } while (sprite == oldsprite); + + } while (1); + + +} + +#endif + +/* +========================== += += ClearMemory += +========================== +*/ + +void ClearMemory (global_game_variables_t *gvar) +{ +#ifdef __16_PM__ + PM_UnlockMainMem(gvar); +#endif + //sd + MM_SortMem (gvar); +} + /* ========================== = @@ -154,46 +700,43 @@ void DebugMemory_(global_game_variables_t *gvar, boolean q) ========================== */ -void Quit (char *error) +void Quit (global_game_variables_t *gvar, char *error) { - //unsigned finscreen; + //unsigned finscreen; memptr screen=0; - union REGS in, out; - //ClearMemory (); + ClearMemory (gvar); if (!*error) { - //WriteConfig (); +// #ifndef JAPAN +// CA_CacheGrChunk (ORDERSCREEN); +// screen = grsegs[ORDERSCREEN]; +// #endif +// WriteConfig (); } else { - //CA_CacheGrChunk (ERRORSCREEN); - //screen = grsegs[ERRORSCREEN]; +// CA_CacheGrChunk (ERRORSCREEN); +// screen = grsegs[ERRORSCREEN]; } - - //ShutdownId (); - IN_Shutdown(); - //modexLeave(); - in.h.ah = 0x00; - in.h.al = 0x3; - int86(0x10, &in, &out); + Shutdown16(gvar); if (error && *error) { - //movedata ((unsigned)screen,7,0xb800,0,7*160); - //gotoxy (10,4); - fprintf(stderr, "%s\n", error); - //gotoxy (1,8); - exit(1); + //movedata((unsigned)screen,7,0xb800,0,7*160); + gotoxy (10,4); + fprintf(stderr, "%s\n", error); + gotoxy (1,8); + exit(1); } else if (!error || !(*error)) { - //clrscr(); - //#ifndef JAPAN + clrscr(); +#ifndef JAPAN movedata ((unsigned)screen,7,0xb800,0,4000); - //gotoxy(1,24); - //#endif + gotoxy(1,24); +#endif //asm mov bh,0 //asm mov dh,23 // row //asm mov dl,0 // collumn @@ -203,54 +746,49 @@ void Quit (char *error) exit(0); } -#endif //=========================================================================== -const char *nibble_to_binary(nibble x) +#ifdef __WATCOMC__ +// +// for mary4 (XT) +// this is from my XT's BIOS +// http://www.phatcode.net/downloads.php?id=101 +// +void turboXT(byte bakapee) { - static char b[9]; - int z; + __asm { + push ax + push bx + push cx + in al, 61h //; Read equipment flags + xor al, bakapee //; toggle speed + out 61h, al //; Write new flags back - b[0] = '\0'; - for (z = 8; z > 0; z >>= 1) - { - strcat(b, ((x & z) == z) ? "1" : "0"); - } - return b; -} + mov bx, 0F89h //; low pitch blip + and al, 4 //; Is turbo mode set? + jz @@do_beep + mov bx, 52Eh //; high pitch blip -const char *boolean_to_binary(boolean x) -{ - static char b[9]; - int z; - - b[0] = '\0'; - for (z = 1; z > 0; z >>= 1) - { - strcat(b, ((x & z) == z) ? "1" : "0"); + @@do_beep: + mov al, 10110110b //; Timer IC 8253 square waves + out 43h, al //; channel 2, speaker + mov ax, bx + out 42h, al //; send low order + mov al, ah //; load high order + out 42h, al //; send high order + in al, 61h //; Read IC 8255 machine status + push ax + or al, 00000011b + out 61h, al //; Turn speaker on + mov cx, 2000h + @@delay: + loop @@delay + pop ax + out 61h, al //; Turn speaker off + pop cx + pop bx + pop ax } - return b; -} - -void nibbletest() -{ - nibble pee; - printf("nibbletest\n"); - /* nibble to binary string */ - for(pee=0;pee<18;pee++) - printf(" %u %s\n", pee, nibble_to_binary(pee)); - printf(" sizeof(nibble)=%s\n", nibble_to_binary(sizeof(nibble))); - printf("end of nibble test\n"); -} - -void booleantest() -{ - boolean pee; - printf("booleantest\n"); - /* boolean to binary string */ - for(pee=0;pee<4;pee++) - printf(" %u %s\n", pee, boolean_to_binary(pee)); - printf(" sizeof(boolean)=%s\n", boolean_to_binary(sizeof(boolean))); - printf("end of boolean test\n"); } +#endif