]> 4ch.mooo.com Git - 16.git/blobdiff - src/lib/16_tail.c
p16 is being worked on a bunch by me wwww [16_ca needs huge amounts of work and I...
[16.git] / src / lib / 16_tail.c
index 08ad6244b6975a7e7e775efb07c7e7866198bf2e..2e045c58ebd2ae354972ec65347fa87308b1d7c6 100755 (executable)
@@ -1,5 +1,5 @@
 /* Project 16 Source Code~\r
- * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
+ * Copyright (C) 2012-2017 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
  *\r
  * This file is part of Project 16.\r
  *\r
  *\r
  */\r
 /*\r
- * 16 library\r
+ * 16 tail library\r
  */\r
 \r
 #include "src/lib/16_tail.h"\r
 #include "src/lib/16text.h"\r
 \r
+static word far* clockw= (word far*) 0x046C; /* 18.2hz clock */\r
+\r
 /*\r
 ==========================\r
 =\r
@@ -40,38 +42,9 @@ void Startup16(global_game_variables_t *gvar)
 {\r
 #ifdef __WATCOMC__\r
        start_timer(gvar);\r
-\r
-       // DOSLIB: check our environment\r
-       probe_dos();\r
-\r
-       // DOSLIB: what CPU are we using?\r
-       // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.\r
-       //      So this code by itself shouldn't care too much what CPU it's running on. Except that other\r
-       //      parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for\r
-       //      the CPU to carry out tasks. --J.C.\r
-       cpu_probe();\r
-\r
-       // DOSLIB: check for VGA\r
-       if (!probe_vga()) {\r
-               printf("VGA probe failed\n");\r
-               return;\r
-       }\r
-       // hardware must be VGA or higher!\r
-       if (!(vga_state.vga_flags & VGA_IS_VGA)) {\r
-               printf("This program requires VGA or higher graphics hardware\n");\r
-               return;\r
-       }\r
-\r
-       if (_DEBUG_INIT() == 0) {\r
-#ifdef DEBUGSERIAL\r
-               printf("WARNING: Failed to initialize DEBUG output\n");\r
-#endif\r
-       }\r
-       _DEBUG("Serial debug output started\n"); // NTS: All serial output must end messages with newline, or DOSBox-X will not emit text to log\r
-       _DEBUGF("Serial debug output printf test %u %u %u\n",1U,2U,3U);\r
-\r
-       textInit();\r
 #endif\r
+       gvar->video.VL_Started=0;\r
+       TL_VidInit(gvar);\r
        gvar->mm.mmstarted=0;\r
        gvar->pm.PMStarted=0;\r
        MM_Startup(gvar);\r
@@ -81,8 +54,11 @@ void Startup16(global_game_variables_t *gvar)
 #endif\r
        IN_Startup(gvar);\r
 #endif\r
+#ifdef __16_PM__\r
        PM_Startup(gvar);\r
+       PM_CheckMainMem(gvar);\r
        PM_UnlockMainMem(gvar);\r
+#endif\r
        CA_Startup(gvar);\r
 }\r
 \r
@@ -100,7 +76,9 @@ void Startup16(global_game_variables_t *gvar)
 \r
 void Shutdown16(global_game_variables_t *gvar)\r
 {\r
+#ifdef __16_PM__\r
        PM_Shutdown(gvar);\r
+#endif\r
 #ifdef __WATCOMC__\r
 #ifdef __DEBUG_InputMgr__\r
        if(!dbg_nointest)\r
@@ -109,6 +87,54 @@ void Shutdown16(global_game_variables_t *gvar)
 #endif\r
        CA_Shutdown(gvar);\r
        MM_Shutdown(gvar);\r
+#ifdef __WATCOMC__\r
+       if(gvar->video.VL_Started)\r
+               VGAmodeX(0, 1, gvar);\r
+#endif\r
+}\r
+\r
+void   TL_VidInit(global_game_variables_t *gvar)\r
+{\r
+#ifdef __WATCOMC__\r
+       // DOSLIB: check our environment\r
+       probe_dos();\r
+\r
+       // DOSLIB: what CPU are we using?\r
+       // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.\r
+       //        So this code by itself shouldn't care too much what CPU it's running on. Except that other\r
+       //        parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for\r
+       //        the CPU to carry out tasks. --J.C.\r
+       cpu_probe();\r
+\r
+       // DOSLIB: check for VGA\r
+       if (!probe_vga()) {\r
+               printf("VGA probe failed\n");\r
+               return;\r
+       }\r
+       // hardware must be VGA or higher!\r
+       if (!(vga_state.vga_flags & VGA_IS_VGA)) {\r
+               printf("This program requires VGA or higher graphics hardware\n");\r
+               return;\r
+       }\r
+\r
+       if (_DEBUG_INIT() == 0) {\r
+#ifdef DEBUGSERIAL\r
+               //printf("WARNING: Failed to initialize DEBUG output\n");\r
+#endif\r
+       }\r
+       _DEBUG("Serial debug output started\n"); // NTS: All serial output must end messages with newline, or DOSBox-X will not emit text to log\r
+       _DEBUGF("Serial debug output printf test %u %u %u\n",1U,2U,3U);\r
+\r
+       textInit();\r
+\r
+       // get old video mode\r
+       //in.h.ah = 0xf;\r
+       //int86(0x10, &in, &out);\r
+       if(!gvar->video.old_mode) gvar->video.old_mode = vgaGetMode();//out.h.al;\r
+#else\r
+       gvar->video.old_mode = 3;\r
+#endif\r
+       gvar->video.VL_Initiated = 1;\r
 }\r
 \r
 \r
@@ -124,10 +150,10 @@ void Shutdown16(global_game_variables_t *gvar)
 \r
 /*void ReadConfig(void)\r
 {\r
-       int                     file;\r
-       SDMode          sd;\r
-       SMMode          sm;\r
-       SDSMode         sds;\r
+       int                                      file;\r
+       SDMode            sd;\r
+       SMMode            sm;\r
+       SDSMode          sds;\r
 \r
 \r
        if ( (file = open(configname,O_BINARY | O_RDONLY)) != -1)\r
@@ -226,7 +252,7 @@ void Shutdown16(global_game_variables_t *gvar)
 \r
 /*void WriteConfig(void)\r
 {\r
-       int                     file;\r
+       int                                      file;\r
 \r
        file = open(configname,O_CREAT | O_BINARY | O_WRONLY,\r
                                S_IREAD | S_IWRITE | S_IFREG);\r
@@ -259,6 +285,176 @@ void Shutdown16(global_game_variables_t *gvar)
 \r
 //===========================================================================\r
 \r
+/*\r
+===================\r
+=\r
+= FizzleFade\r
+=\r
+===================\r
+*/\r
+\r
+#define PIXPERFRAME     1600\r
+\r
+void FizzleFade (unsigned source, unsigned dest,\r
+       unsigned width,unsigned height, boolean abortable, global_game_variables_t *gv)\r
+{\r
+       unsigned        drawofs,pagedelta;\r
+       unsigned        char maskb[8] = {1,2,4,8,16,32,64,128};\r
+       unsigned        x,y,p,frame;\r
+       long            rndval;\r
+       word TimeCount = *clockw;\r
+       word screenseg = SCREENSEG;\r
+\r
+       pagedelta = dest-source;\r
+//++++ VL_SetScreen (dest,0);\r
+       rndval = 1;\r
+       x = y = 0;\r
+\r
+       __asm {\r
+               mov     es,[screenseg]\r
+               mov     dx,SC_INDEX\r
+               mov     al,SC_MAPMASK\r
+               out     dx,al\r
+       }\r
+\r
+       TimeCount=frame=0;\r
+       do      // while (1)\r
+       {\r
+               if (abortable)\r
+               {\r
+                       IN_ReadControl(0,gv);\r
+                       if (gv->player[0].info.button0 || gv->player[0].info.button1 || gv->in.inst->Keyboard[sc_Space]\r
+                       || gv->in.inst->Keyboard[sc_Enter])\r
+                       {\r
+//++++                         VW_ScreenToScreen (source,dest,width/8,height);\r
+                               return;\r
+                       }\r
+               }\r
+\r
+               for (p=0;p<PIXPERFRAME;p++)\r
+               {\r
+                       //\r
+                       // seperate random value into x/y pair\r
+                       //\r
+                       __asm {\r
+                               mov     ax,[WORD PTR rndval]\r
+                               mov     dx,[WORD PTR rndval+2]\r
+                               mov     bx,ax\r
+                               dec     bl\r
+                               mov     [BYTE PTR y],bl                 // low 8 bits - 1 = y xoordinate\r
+                               mov     bx,ax\r
+                               mov     cx,dx\r
+                               shr     cx,1\r
+                               rcr     bx,1\r
+                               shr     bx,1\r
+                               shr     bx,1\r
+                               shr     bx,1\r
+                               shr     bx,1\r
+                               shr     bx,1\r
+                               shr     bx,1\r
+                               shr     bx,1\r
+                               mov     [x],bx                                  // next 9 bits = x xoordinate\r
+                       //\r
+                       // advance to next random element\r
+                       //\r
+                               shr     dx,1\r
+                               rcr     ax,1\r
+                               jnc     noxor\r
+                               xor     dx,0x0001\r
+                               xor     ax,0x2000\r
+#ifdef __BORLANDC__\r
+                       }\r
+#endif\r
+noxor:\r
+#ifdef __BORLANDC__\r
+                       __asm {\r
+#endif\r
+                               mov     [WORD PTR rndval],ax\r
+                               mov     [WORD PTR rndval+2],dx\r
+                       }\r
+\r
+                       if (x>width || y>height)\r
+                               continue;\r
+                       drawofs = source+gv->video.ofs.ylookup[y];\r
+\r
+                       __asm {\r
+                               mov     cx,[x]\r
+                               mov     si,cx\r
+                               and     si,7\r
+                               mov     dx,GC_INDEX\r
+                               mov     al,GC_BITMASK\r
+                               mov     ah,BYTE PTR [maskb+si]\r
+                               out     dx,ax\r
+\r
+                               mov     si,[drawofs]\r
+                               shr     cx,1\r
+                               shr     cx,1\r
+                               shr     cx,1\r
+                               add     si,cx\r
+                               mov     di,si\r
+                               add     di,[pagedelta]\r
+\r
+                               mov     dx,GC_INDEX\r
+                               mov     al,GC_READMAP                   // leave GC_INDEX set to READMAP\r
+                               out         dx,al\r
+\r
+                               mov     dx,SC_INDEX+1\r
+                               mov     al,1\r
+                               out         dx,al\r
+                               mov     dx,GC_INDEX+1\r
+                               mov     al,0\r
+                               out         dx,al\r
+\r
+                               mov     bl,[es:si]\r
+                               xchg    [es:di],bl\r
+\r
+                               mov     dx,SC_INDEX+1\r
+                               mov     al,2\r
+                               out         dx,al\r
+                               mov     dx,GC_INDEX+1\r
+                               mov     al,1\r
+                               out         dx,al\r
+\r
+                               mov     bl,[es:si]\r
+                               xchg    [es:di],bl\r
+\r
+                               mov     dx,SC_INDEX+1\r
+                               mov     al,4\r
+                               out         dx,al\r
+                               mov     dx,GC_INDEX+1\r
+                               mov     al,2\r
+                               out         dx,al\r
+\r
+                               mov     bl,[es:si]\r
+                               xchg    [es:di],bl\r
+\r
+                               mov     dx,SC_INDEX+1\r
+                               mov     al,8\r
+                               out         dx,al\r
+                               mov     dx,GC_INDEX+1\r
+                               mov     al,3\r
+                               out         dx,al\r
+\r
+                               mov     bl,[es:si]\r
+                               xchg    [es:di],bl\r
+                       }\r
+\r
+                       if (rndval == 1)                // entire sequence has been completed\r
+                       {\r
+//++++                         VGABITMASK(255);\r
+//++++                         VGAMAPMASK(15);\r
+                               return;\r
+                       }\r
+               }\r
+               frame++;\r
+//++++         while (TimeCount<frame){}       // don't go too fast\r
+       } while (1);\r
+\r
+\r
+}\r
+\r
+//===========================================================================\r
+\r
 /*\r
 ==================\r
 =\r
@@ -274,9 +470,9 @@ void DebugMemory_(global_game_variables_t *gvar, boolean q)
 \r
        US_CPrint ("Memory Usage");\r
        US_CPrint ("------------");\r
-       US_Print ("Total     :");\r
+       US_Print ("Total         :");\r
        US_PrintUnsigned (mminfo.mainmem/1024);\r
-       US_Print ("k\nFree      :");\r
+       US_Print ("k\nFree        :");\r
        US_PrintUnsigned (MM_UnusedMemory()/1024);\r
        US_Print ("k\nWith purge:");\r
        US_PrintUnsigned (MM_TotalFree()/1024);\r
@@ -297,7 +493,7 @@ void DebugMemory_(global_game_variables_t *gvar, boolean q)
 #ifdef __WATCOMC__\r
        //IN_Ack ();\r
 #endif\r
-       if(q) MM_ShowMemory (gvar);\r
+//     if(q) MM_ShowMemory (gvar);\r
 }\r
 \r
 /*\r
@@ -310,7 +506,9 @@ void DebugMemory_(global_game_variables_t *gvar, boolean q)
 \r
 void ClearMemory (global_game_variables_t *gvar)\r
 {\r
+#ifdef __16_PM__\r
        PM_UnlockMainMem(gvar);\r
+#endif\r
        //snd\r
        MM_SortMem (gvar);\r
 }\r
@@ -325,7 +523,7 @@ void ClearMemory (global_game_variables_t *gvar)
 \r
 void Quit (global_game_variables_t *gvar, char *error)\r
 {\r
-       //unsigned        finscreen;\r
+       //unsigned              finscreen;\r
        memptr  screen=0;\r
 \r
        ClearMemory (gvar);\r
@@ -346,7 +544,7 @@ void Quit (global_game_variables_t *gvar, char *error)
 \r
        if (error && *error)\r
        {\r
-               movedata((unsigned)screen,7,0xb800,0,7*160);\r
+               //movedata((unsigned)screen,7,0xb800,0,7*160);\r
                gotoxy (10,4);\r
                fprintf(stderr, "%s\n", error);\r
                gotoxy (1,8);\r
@@ -372,20 +570,64 @@ void Quit (global_game_variables_t *gvar, char *error)
 \r
 //===========================================================================\r
 \r
-void walktypeinfo(player_t *player, word pn)\r
+#ifndef __WATCOMC__\r
+char global_temp_status_text[512];\r
+char global_temp_status_text2[512];\r
+#else\r
+//\r
+// for mary4 (XT)\r
+// this is from my XT's BIOS\r
+// http://www.phatcode.net/downloads.php?id=101\r
+//\r
+void turboXT(byte bakapee)\r
 {\r
-       switch(player[pn].walktype)\r
+       __asm {\r
+               push    ax\r
+               push    bx\r
+               push    cx\r
+               in      al, 61h                         //; Read equipment flags\r
+               xor     al, bakapee                     //;   toggle speed\r
+               out     61h, al                         //; Write new flags back\r
+\r
+               mov     bx, 0F89h                       //; low pitch blip\r
+               and     al, 4                           //; Is turbo mode set?\r
+               jz      @@do_beep\r
+               mov     bx, 52Eh                        //; high pitch blip\r
+\r
+       @@do_beep:\r
+               mov     al, 10110110b           //; Timer IC 8253 square waves\r
+               out     43h, al                         //;   channel 2, speaker\r
+               mov     ax, bx\r
+               out     42h, al                         //;   send low order\r
+               mov     al, ah                          //;   load high order\r
+               out     42h, al                         //;   send high order\r
+               in      al, 61h                         //; Read IC 8255 machine status\r
+               push    ax\r
+               or      al, 00000011b\r
+               out     61h, al                         //; Turn speaker on\r
+               mov     cx, 2000h\r
+       @@delay:\r
+               loop    @@delay\r
+               pop     ax\r
+               out     61h, al                         //; Turn speaker off\r
+               pop     cx\r
+               pop     bx\r
+               pop     ax\r
+       }\r
+}\r
+#endif\r
+\r
+const char *word_to_binary(word x)\r
+{\r
+       static char b[17];\r
+       int z;\r
+\r
+       b[0] = '\0';\r
+       for (z = 16; z > 0; z >>= 1)\r
        {\r
-               case 0: //bump\r
-                       sprintf(global_temp_status_text, "%s", "b");\r
-               break;\r
-               case 1: //walk no scroll\r
-                       sprintf(global_temp_status_text, "%s", "w");\r
-               break;\r
-               case 2: //scrolling walk\r
-                       sprintf(global_temp_status_text, "%s", "s");\r
-               break;\r
+               strcat(b, ((x & z) == z) ? "1" : "0");\r
        }\r
+       return b;\r
 }\r
 \r
 const char *nibble_to_binary(nibble x)\r
@@ -435,3 +677,13 @@ void booleantest()
        printf("        sizeof(boolean)=%s\n", boolean_to_binary(sizeof(boolean)));\r
        printf("end of boolean test\n");\r
 }\r
+\r
+#ifdef __BORLANDC__\r
+word modexPalOverscan(word col)\r
+{\r
+       //modexWaitBorder();\r
+       outp(PAL_WRITE_REG, 0);  /* start at the beginning of palette */\r
+       outp(PAL_DATA_REG, col);\r
+       return col;\r
+}\r
+#endif\r