]> 4ch.mooo.com Git - 16.git/blob - src/lib/16_tail.c
scroll.exe works again but the fps thingy dose not work because of MM
[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         start_timer(gvar);\r
42 \r
43         // DOSLIB: check our environment\r
44         probe_dos();\r
45 \r
46         // DOSLIB: what CPU are we using?\r
47         // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.\r
48         //      So this code by itself shouldn't care too much what CPU it's running on. Except that other\r
49         //      parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for\r
50         //      the CPU to carry out tasks. --J.C.\r
51         cpu_probe();\r
52 \r
53         // DOSLIB: check for VGA\r
54         if (!probe_vga()) {\r
55                 printf("VGA probe failed\n");\r
56                 return;\r
57         }\r
58         // hardware must be VGA or higher!\r
59         if (!(vga_state.vga_flags & VGA_IS_VGA)) {\r
60                 printf("This program requires VGA or higher graphics hardware\n");\r
61                 return;\r
62         }\r
63 \r
64         if (_DEBUG_INIT() == 0) {\r
65 #ifdef DEBUGSERIAL\r
66                 printf("WARNING: Failed to initialize DEBUG output\n");\r
67 #endif\r
68         }\r
69         _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
70         _DEBUGF("Serial debug output printf test %u %u %u\n",1U,2U,3U);\r
71 #endif\r
72         gvar->mm.mmstarted=0;\r
73         gvar->pm.PMStarted=0;\r
74 #ifdef __DEBUG__\r
75         if(!dbg_nommpmca)\r
76 #endif\r
77         MM_Startup(gvar);\r
78 if(!dbg_noplayerinpu)\r
79         IN_Startup(gvar);\r
80 #ifdef __DEBUG__\r
81         if(!dbg_nommpmca){\r
82 #endif\r
83         PM_Startup(gvar);\r
84         PM_UnlockMainMem(gvar);\r
85         CA_Startup(gvar);\r
86 #ifdef __DEBUG__\r
87         }\r
88 #endif\r
89 }\r
90 \r
91 //===========================================================================\r
92 \r
93 /*\r
94 ==========================\r
95 =\r
96 = Shutdown16\r
97 =\r
98 = Shuts down all ID_?? managers\r
99 =\r
100 ==========================\r
101 */\r
102 \r
103 void Shutdown16(global_game_variables_t *gvar)\r
104 {\r
105 #ifdef __DEBUG__\r
106         if(!dbg_nommpmca)\r
107 #endif\r
108         PM_Shutdown(gvar);\r
109 if(!dbg_noplayerinpu)\r
110         IN_Shutdown(gvar);\r
111 #ifdef __DEBUG__\r
112         if(!dbg_nommpmca){\r
113 #endif\r
114         CA_Shutdown(gvar);\r
115         MM_Shutdown(gvar);\r
116 #ifdef __DEBUG__\r
117         }\r
118 #endif\r
119 }\r
120 \r
121 \r
122 //===========================================================================\r
123 \r
124 /*\r
125 ==================\r
126 =\r
127 = DebugMemory\r
128 =\r
129 ==================\r
130 */\r
131 \r
132 void DebugMemory_(global_game_variables_t *gvar, boolean q)\r
133 {\r
134         /*VW_FixRefreshBuffer ();\r
135         US_CenterWindow (16,7);\r
136 \r
137         US_CPrint ("Memory Usage");\r
138         US_CPrint ("------------");\r
139         US_Print ("Total     :");\r
140         US_PrintUnsigned (mminfo.mainmem/1024);\r
141         US_Print ("k\nFree      :");\r
142         US_PrintUnsigned (MM_UnusedMemory()/1024);\r
143         US_Print ("k\nWith purge:");\r
144         US_PrintUnsigned (MM_TotalFree()/1024);\r
145         US_Print ("k\n");\r
146         VW_UpdateScreen();*/\r
147         if(q){\r
148         printf("========================================\n");\r
149         printf("                DebugMemory_\n");\r
150         printf("========================================\n");}\r
151         if(q) { printf("Memory Usage\n");\r
152         printf("------------\n"); }else printf("        %c%c", 0xD3, 0xC4);\r
153         printf("Total:  "); if(q) printf("      "); printf("%uk", gvar->mmi.mainmem/1024);\r
154         if(q) printf("\n"); else printf("       ");\r
155         printf("Free:   "); if(q) printf("      "); printf("%uk", MM_UnusedMemory(gvar)/1024);\r
156         if(q) printf("\n"); else printf("       ");\r
157         printf("With purge:"); if(q) printf("   "); printf("%uk\n", MM_TotalFree(gvar)/1024);\r
158         if(q) printf("------------\n");\r
159 #ifdef __WATCOMC__\r
160         IN_Ack ();\r
161 #endif\r
162         if(q) MM_ShowMemory (gvar);\r
163 }\r
164 #ifdef __WATCOMC__\r
165 /*\r
166 ==========================\r
167 =\r
168 = Quit\r
169 =\r
170 ==========================\r
171 */\r
172 \r
173 void Quit (char *error)\r
174 {\r
175         //unsigned        finscreen;\r
176         memptr  screen=0;\r
177         union REGS in, out;\r
178 \r
179         //ClearMemory ();\r
180         if (!*error)\r
181         {\r
182          //WriteConfig ();\r
183         }\r
184         else\r
185         {\r
186          //CA_CacheGrChunk (ERRORSCREEN);\r
187          //screen = grsegs[ERRORSCREEN];\r
188         }\r
189 \r
190         //ShutdownId ();\r
191         IN_Shutdown();\r
192         //modexLeave();\r
193         in.h.ah = 0x00;\r
194         in.h.al = 0x3;\r
195         int86(0x10, &in, &out);\r
196 \r
197         if (error && *error)\r
198         {\r
199           //movedata ((unsigned)screen,7,0xb800,0,7*160);\r
200           //gotoxy (10,4);\r
201           fprintf(stderr, "%s\n", error);\r
202           //gotoxy (1,8);\r
203           exit(1);\r
204         }\r
205         else\r
206         if (!error || !(*error))\r
207         {\r
208                 //clrscr();\r
209                 //#ifndef JAPAN\r
210                 movedata ((unsigned)screen,7,0xb800,0,4000);\r
211                 //gotoxy(1,24);\r
212                 //#endif\r
213 //asm   mov     bh,0\r
214 //asm   mov     dh,23   // row\r
215 //asm   mov     dl,0    // collumn\r
216 //asm   mov ah,2\r
217 //asm   int     0x10\r
218         }\r
219 \r
220         exit(0);\r
221 }\r
222 #endif\r
223 \r
224 //===========================================================================\r
225 \r
226 const char *nibble_to_binary(nibble x)\r
227 {\r
228         static char b[9];\r
229         int z;\r
230 \r
231         b[0] = '\0';\r
232         for (z = 8; z > 0; z >>= 1)\r
233         {\r
234                 strcat(b, ((x & z) == z) ? "1" : "0");\r
235         }\r
236         return b;\r
237 }\r
238 \r
239 const char *boolean_to_binary(boolean x)\r
240 {\r
241         static char b[9];\r
242         int z;\r
243 \r
244         b[0] = '\0';\r
245         for (z = 1; z > 0; z >>= 1)\r
246         {\r
247                 strcat(b, ((x & z) == z) ? "1" : "0");\r
248         }\r
249         return b;\r
250 }\r
251 \r
252 void nibbletest()\r
253 {\r
254         nibble pee;\r
255         printf("nibbletest\n");\r
256         /* nibble to binary string */\r
257         for(pee=0;pee<18;pee++)\r
258                 printf("        %u %s\n", pee, nibble_to_binary(pee));\r
259         printf("        sizeof(nibble)=%s\n", nibble_to_binary(sizeof(nibble)));\r
260         printf("end of nibble test\n");\r
261 }\r
262 \r
263 void booleantest()\r
264 {\r
265         boolean pee;\r
266         printf("booleantest\n");\r
267         /* boolean to binary string */\r
268         for(pee=0;pee<4;pee++)\r
269                 printf("        %u %s\n", pee, boolean_to_binary(pee));\r
270         printf("        sizeof(boolean)=%s\n", boolean_to_binary(sizeof(boolean)));\r
271         printf("end of boolean test\n");\r
272 }\r