]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_tail.c
ok wwwww zscroll and scroll compile disabled due to me being too tired to whack at...
[16.git] / src / lib / 16_tail.c
1 /* Project 16 Source Code~\r
2  * Copyright (C) 2012-2016 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover\r
3  *\r
4  * This file is part of Project 16.\r
5  *\r
6  * Project 16 is free software; you can redistribute it and/or modify\r
7  * it under the terms of the GNU General Public License as published by\r
8  * the Free Software Foundation; either version 3 of the License, or\r
9  * (at your option) any later version.\r
10  *\r
11  * Project 16 is distributed in the hope that it will be useful,\r
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of\r
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
14  * GNU General Public License for more details.\r
15  *\r
16  * You should have received a copy of the GNU General Public License\r
17  * along with this program.  If not, see <http://www.gnu.org/licenses/>, or\r
18  * write to the Free Software Foundation, Inc., 51 Franklin Street,\r
19  * Fifth Floor, Boston, MA 02110-1301 USA.\r
20  *\r
21  */\r
22 /*\r
23  * 16 library\r
24  */\r
25 \r
26 #include "src/lib/16_tail.h"\r
27 \r
28 /*\r
29 ==========================\r
30 =\r
31 = Startup16\r
32 =\r
33 = Load a few things right away\r
34 =\r
35 ==========================\r
36 */\r
37 \r
38 void Startup16(global_game_variables_t *gvar)\r
39 {\r
40 #ifdef __WATCOMC__\r
41         // DOSLIB: check our environment\r
42         probe_dos();\r
43 \r
44         // DOSLIB: what CPU are we using?\r
45         // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.\r
46         //      So this code by itself shouldn't care too much what CPU it's running on. Except that other\r
47         //      parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for\r
48         //      the CPU to carry out tasks. --J.C.\r
49         cpu_probe();\r
50 \r
51         // DOSLIB: check for VGA\r
52         if (!probe_vga()) {\r
53                 printf("VGA probe failed\n");\r
54                 return;\r
55         }\r
56         // hardware must be VGA or higher!\r
57         if (!(vga_state.vga_flags & VGA_IS_VGA)) {\r
58                 printf("This program requires VGA or higher graphics hardware\n");\r
59                 return;\r
60         }\r
61 \r
62         if (_DEBUG_INIT() == 0) {\r
63 #ifdef DEBUGSERIAL\r
64                 printf("WARNING: Failed to initialize DEBUG output\n");\r
65 #endif\r
66         }\r
67         _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
68         _DEBUGF("Serial debug output printf test %u %u %u\n",1U,2U,3U);\r
69 #endif\r
70         gvar->mm.mmstarted=0;\r
71         gvar->pm.PMStarted=0;\r
72         MM_Startup(gvar);\r
73 if(!dbg_noplayerinpu)\r
74         IN_Startup(gvar);\r
75         PM_Startup(gvar);\r
76         PM_UnlockMainMem(gvar);\r
77         CA_Startup(gvar);\r
78 #ifdef __WATCOMC__\r
79         start_timer(gvar);\r
80 #endif\r
81 \r
82 }\r
83 \r
84 //===========================================================================\r
85 \r
86 /*\r
87 ==========================\r
88 =\r
89 = Shutdown16\r
90 =\r
91 = Shuts down all ID_?? managers\r
92 =\r
93 ==========================\r
94 */\r
95 \r
96 void Shutdown16(global_game_variables_t *gvar)\r
97 {\r
98         PM_Shutdown(gvar);\r
99 if(!dbg_noplayerinpu)\r
100         IN_Shutdown(gvar);\r
101         CA_Shutdown(gvar);\r
102         MM_Shutdown(gvar);\r
103 }\r
104 \r
105 \r
106 //===========================================================================\r
107 \r
108 /*\r
109 ==================\r
110 =\r
111 = DebugMemory\r
112 =\r
113 ==================\r
114 */\r
115 \r
116 void DebugMemory_(global_game_variables_t *gvar, boolean q)\r
117 {\r
118         /*VW_FixRefreshBuffer ();\r
119         US_CenterWindow (16,7);\r
120 \r
121         US_CPrint ("Memory Usage");\r
122         US_CPrint ("------------");\r
123         US_Print ("Total     :");\r
124         US_PrintUnsigned (mminfo.mainmem/1024);\r
125         US_Print ("k\nFree      :");\r
126         US_PrintUnsigned (MM_UnusedMemory()/1024);\r
127         US_Print ("k\nWith purge:");\r
128         US_PrintUnsigned (MM_TotalFree()/1024);\r
129         US_Print ("k\n");\r
130         VW_UpdateScreen();*/\r
131         if(q){\r
132         printf("========================================\n");\r
133         printf("                DebugMemory_\n");\r
134         printf("========================================\n");}\r
135         if(q) { printf("Memory Usage\n");\r
136         printf("------------\n"); }else printf("        %c%c", 0xD3, 0xC4);\r
137         printf("Total:  "); if(q) printf("      "); printf("%uk", gvar->mmi.mainmem/1024);\r
138         if(q) printf("\n"); else printf("       ");\r
139         printf("Free:   "); if(q) printf("      "); printf("%uk", MM_UnusedMemory(gvar)/1024);\r
140         if(q) printf("\n"); else printf("       ");\r
141         printf("With purge:"); if(q) printf("   "); printf("%uk\n", MM_TotalFree(gvar)/1024);\r
142         if(q) printf("------------\n");\r
143 #ifdef __WATCOMC__\r
144         IN_Ack ();\r
145 #endif\r
146         if(q) MM_ShowMemory (gvar);\r
147 }\r
148 #ifdef __WATCOMC__\r
149 /*\r
150 ==========================\r
151 =\r
152 = Quit\r
153 =\r
154 ==========================\r
155 */\r
156 \r
157 void Quit (char *error)\r
158 {\r
159         //unsigned        finscreen;\r
160         memptr  screen=0;\r
161         union REGS in, out;\r
162 \r
163         //ClearMemory ();\r
164         if (!*error)\r
165         {\r
166          //WriteConfig ();\r
167         }\r
168         else\r
169         {\r
170          //CA_CacheGrChunk (ERRORSCREEN);\r
171          //screen = grsegs[ERRORSCREEN];\r
172         }\r
173 \r
174         //ShutdownId ();\r
175         IN_Shutdown();\r
176         //modexLeave();\r
177         in.h.ah = 0x00;\r
178         in.h.al = 0x3;\r
179         int86(0x10, &in, &out);\r
180 \r
181         if (error && *error)\r
182         {\r
183           //movedata ((unsigned)screen,7,0xb800,0,7*160);\r
184           //gotoxy (10,4);\r
185           fprintf(stderr, "%s\n", error);\r
186           //gotoxy (1,8);\r
187           exit(1);\r
188         }\r
189         else\r
190         if (!error || !(*error))\r
191         {\r
192                 //clrscr();\r
193                 //#ifndef JAPAN\r
194                 movedata ((unsigned)screen,7,0xb800,0,4000);\r
195                 //gotoxy(1,24);\r
196                 //#endif\r
197 //asm   mov     bh,0\r
198 //asm   mov     dh,23   // row\r
199 //asm   mov     dl,0    // collumn\r
200 //asm   mov ah,2\r
201 //asm   int     0x10\r
202         }\r
203 \r
204         exit(0);\r
205 }\r
206 #endif\r
207 \r
208 //===========================================================================\r
209 \r
210 const char *nibble_to_binary(nibble x)\r
211 {\r
212         static char b[9];\r
213         int z;\r
214 \r
215         b[0] = '\0';\r
216         for (z = 8; z > 0; z >>= 1)\r
217         {\r
218                 strcat(b, ((x & z) == z) ? "1" : "0");\r
219         }\r
220         return b;\r
221 }\r
222 \r
223 const char *boolean_to_binary(boolean x)\r
224 {\r
225         static char b[9];\r
226         int z;\r
227 \r
228         b[0] = '\0';\r
229         for (z = 1; z > 0; z >>= 1)\r
230         {\r
231                 strcat(b, ((x & z) == z) ? "1" : "0");\r
232         }\r
233         return b;\r
234 }\r
235 \r
236 void nibbletest()\r
237 {\r
238         nibble pee;\r
239         printf("nibbletest\n");\r
240         /* nibble to binary string */\r
241         for(pee=0;pee<18;pee++)\r
242                 printf("        %u %s\n", pee, nibble_to_binary(pee));\r
243         printf("        sizeof(nibble)=%s\n", nibble_to_binary(sizeof(nibble)));\r
244         printf("end of nibble test\n");\r
245 }\r
246 \r
247 void booleantest()\r
248 {\r
249         boolean pee;\r
250         printf("booleantest\n");\r
251         /* boolean to binary string */\r
252         for(pee=0;pee<4;pee++)\r
253                 printf("        %u %s\n", pee, boolean_to_binary(pee));\r
254         printf("        sizeof(boolean)=%s\n", boolean_to_binary(sizeof(boolean)));\r
255         printf("end of boolean test\n");\r
256 }\r