OSDN Git Service

okies~
[proj16/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         // DOSLIB: check our environment\r
41         probe_dos();\r
42 \r
43         // DOSLIB: what CPU are we using?\r
44         // NTS: I can see from the makefile Sparky4 intends this to run on 8088 by the -0 switch in CFLAGS.\r
45         //      So this code by itself shouldn't care too much what CPU it's running on. Except that other\r
46         //      parts of this project (DOSLIB itself) rely on CPU detection to know what is appropriate for\r
47         //      the CPU to carry out tasks. --J.C.\r
48         cpu_probe();\r
49 \r
50         // DOSLIB: check for VGA\r
51         if (!probe_vga()) {\r
52                 printf("VGA probe failed\n");\r
53                 return;\r
54         }\r
55         // hardware must be VGA or higher!\r
56         if (!(vga_state.vga_flags & VGA_IS_VGA)) {\r
57                 printf("This program requires VGA or higher graphics hardware\n");\r
58                 return;\r
59         }\r
60 \r
61         gvar->mm.mmstarted=0;\r
62         gvar->pm.PMStarted=0;\r
63         MM_Startup(gvar);\r
64         IN_Startup(gvar);\r
65         PM_Startup(gvar);\r
66         PM_UnlockMainMem(gvar);\r
67         CA_Startup(gvar);\r
68 \r
69 }\r
70 \r
71 //===========================================================================\r
72 \r
73 /*\r
74 ==========================\r
75 =\r
76 = Shutdown16\r
77 =\r
78 = Shuts down all ID_?? managers\r
79 =\r
80 ==========================\r
81 */\r
82 \r
83 void Shutdown16(global_game_variables_t *gvar)\r
84 {\r
85         PM_Shutdown(gvar);\r
86         IN_Shutdown(gvar);\r
87         CA_Shutdown(gvar);\r
88         MM_Shutdown(gvar);\r
89 }\r
90 \r
91 \r
92 //===========================================================================\r
93 \r
94 /*\r
95 ==================\r
96 =\r
97 = DebugMemory\r
98 =\r
99 ==================\r
100 */\r
101 \r
102 void DebugMemory_(global_game_variables_t *gvar, boolean q)\r
103 {\r
104         /*VW_FixRefreshBuffer ();\r
105         US_CenterWindow (16,7);\r
106 \r
107         US_CPrint ("Memory Usage");\r
108         US_CPrint ("------------");\r
109         US_Print ("Total     :");\r
110         US_PrintUnsigned (mminfo.mainmem/1024);\r
111         US_Print ("k\nFree      :");\r
112         US_PrintUnsigned (MM_UnusedMemory()/1024);\r
113         US_Print ("k\nWith purge:");\r
114         US_PrintUnsigned (MM_TotalFree()/1024);\r
115         US_Print ("k\n");\r
116         VW_UpdateScreen();*/\r
117         if(q){\r
118         printf("========================================\n");\r
119         printf("                DebugMemory_\n");\r
120         printf("========================================\n");}\r
121         if(q) { printf("Memory Usage\n");\r
122         printf("------------\n"); }else printf("        %c%c", 0xD3, 0xC4);\r
123         printf("Total:  "); if(q) printf("      "); printf("%uk", gvar->mmi.mainmem/1024);\r
124         if(q) printf("\n"); else printf("       ");\r
125         printf("Free:   "); if(q) printf("      "); printf("%uk", MM_UnusedMemory(gvar)/1024);\r
126         if(q) printf("\n"); else printf("       ");\r
127         printf("With purge:"); if(q) printf("   "); printf("%uk\n", MM_TotalFree(gvar)/1024);\r
128         if(q) printf("------------\n");\r
129 #ifdef __WATCOMC__\r
130         IN_Ack ();\r
131 #endif\r
132         if(q) MM_ShowMemory (gvar);\r
133 }\r
134 #ifdef __WATCOMC__\r
135 /*\r
136 ==========================\r
137 =\r
138 = Quit\r
139 =\r
140 ==========================\r
141 */\r
142 \r
143 void Quit (char *error)\r
144 {\r
145         unsigned        finscreen;\r
146         memptr  screen;\r
147         union REGS in, out;\r
148 \r
149         //ClearMemory ();\r
150         if (!*error)\r
151         {\r
152          //WriteConfig ();\r
153         }\r
154         else\r
155         {\r
156          //CA_CacheGrChunk (ERRORSCREEN);\r
157          //screen = grsegs[ERRORSCREEN];\r
158         }\r
159 \r
160         //ShutdownId ();\r
161         IN_Shutdown();\r
162         //modexLeave();\r
163         in.h.ah = 0x00;\r
164         in.h.al = 0x3;\r
165         int86(0x10, &in, &out);\r
166 \r
167         if (error && *error)\r
168         {\r
169           //movedata ((unsigned)screen,7,0xb800,0,7*160);\r
170           //gotoxy (10,4);\r
171           fprintf(stderr, "%s\n", error);\r
172           //gotoxy (1,8);\r
173           exit(1);\r
174         }\r
175         else\r
176         if (!error || !(*error))\r
177         {\r
178                 //clrscr();\r
179                 //#ifndef JAPAN\r
180                 movedata ((unsigned)screen,7,0xb800,0,4000);\r
181                 //gotoxy(1,24);\r
182                 //#endif\r
183 //asm   mov     bh,0\r
184 //asm   mov     dh,23   // row\r
185 //asm   mov     dl,0    // collumn\r
186 //asm   mov ah,2\r
187 //asm   int     0x10\r
188         }\r
189 \r
190         exit(0);\r
191 }\r
192 #endif\r
193 \r
194 //===========================================================================\r