OSDN Git Service

quit works with input system now
[proj16/16.git] / src / lib / 16_head.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 #include "src/lib/16_head.h"\r
24 \r
25 /* Function: Wait **********************************************************\r
26 *\r
27 *     Parameters:    wait - time in microseconds\r
28 *\r
29 *     Description:    pauses for a specified number of microseconds.\r
30 *\r
31 */\r
32 void wait(clock_t wait){\r
33         clock_t goal;\r
34 \r
35         if(!wait) return;\r
36 \r
37         goal = wait + clock();\r
38         while((goal > clock()) && !kbhit()) ;\r
39 } /* End of wait */\r
40 \r
41 long int\r
42 filesize(FILE *fp)\r
43 {\r
44         long int save_pos, size_of_file;\r
45 \r
46         save_pos = ftell(fp);\r
47         fseek(fp, 0L, SEEK_END);\r
48         size_of_file = ftell(fp);\r
49         fseek(fp, save_pos, SEEK_SET);\r
50         return(size_of_file);\r
51 }\r
52 \r
53 void printmeminfoline(byte *strc, const byte *pee, size_t h_total, size_t h_used, size_t h_free)\r
54 {\r
55         byte str[64];\r
56         strcat(strc,pee); strcat(strc,"            "); ultoa((dword)h_total,str,10); strcat(strc,str);\r
57         if(strlen(str)<=4) strcat(strc,"        "); //printf("%u\n", strlen(str));\r
58         strcat(strc,"   "); ultoa((dword)h_used,str,10); strcat(strc,str); strcat(strc,"        "); strcat(strc,"  ");\r
59         ultoa((dword)h_free,str,10); strcat(strc,str);\r
60         strcat(strc,"\n");\r
61 }\r
62 \r
63 ///////////////////////////////////////////////////////////////////////////\r
64 //\r
65 //      US_CheckParm() - checks to see if a string matches one of a set of\r
66 //              strings. The check is case insensitive. The routine returns the\r
67 //              index of the string that matched, or -1 if no matches were found\r
68 //\r
69 ///////////////////////////////////////////////////////////////////////////\r
70 int\r
71 US_CheckParm(char *parm,char **strings)\r
72 {\r
73         char    cp,cs,\r
74                         *p,*s;\r
75         int             i;\r
76 \r
77         while (!isalpha(*parm)) // Skip non-alphas\r
78                 parm++;\r
79 \r
80         for (i = 0;*strings && **strings;i++)\r
81         {\r
82                 for (s = *strings++,p = parm,cs = cp = 0;cs == cp;)\r
83                 {\r
84                         cs = *s++;\r
85                         if (!cs)\r
86                                 return(i);\r
87                         cp = *p++;\r
88 \r
89                         if (isupper(cs))\r
90                                 cs = tolower(cs);\r
91                         if (isupper(cp))\r
92                                 cp = tolower(cp);\r
93                 }\r
94         }\r
95         return(-1);\r
96 }\r
97 #ifdef __BORLANDC__\r
98 //===========================================================================\r
99 \r
100 /*\r
101 ==========================\r
102 =\r
103 = Quit\r
104 =\r
105 ==========================\r
106 */\r
107 \r
108 void Quit (char *error)\r
109 {\r
110         unsigned        finscreen;\r
111         memptr  screen;\r
112         union REGS in, out;\r
113 \r
114         //ClearMemory ();\r
115         if (!*error)\r
116         {\r
117          //WriteConfig ();\r
118         }\r
119         else\r
120         {\r
121          //CA_CacheGrChunk (ERRORSCREEN);\r
122          //screen = grsegs[ERRORSCREEN];\r
123         }\r
124 \r
125         //ShutdownId ();\r
126         //IN_Shutdown();\r
127         //modexLeave();\r
128         in.h.ah = 0x00;\r
129         in.h.al = 0x3;\r
130         int86(0x10, &in, &out);\r
131 \r
132         if (error && *error)\r
133         {\r
134           movedata ((unsigned)screen,7,0xb800,0,7*160);\r
135           //gotoxy (10,4);\r
136           puts(error);\r
137           //gotoxy (1,8);\r
138           exit(1);\r
139         }\r
140         else\r
141         if (!error || !(*error))\r
142         {\r
143                 //clrscr();\r
144                 //#ifndef JAPAN\r
145                 movedata ((unsigned)screen,7,0xb800,0,4000);\r
146                 //gotoxy(1,24);\r
147                 //#endif\r
148 //asm   mov     bh,0\r
149 //asm   mov     dh,23   // row\r
150 //asm   mov     dl,0    // collumn\r
151 //asm   mov ah,2\r
152 //asm   int     0x10\r
153         }\r
154 \r
155         exit(0);\r
156 }\r
157 \r
158 //===========================================================================\r
159 #endif\r
160 \r
161 byte dirchar(byte in)\r
162 {\r
163         byte out;\r
164         switch(in)\r
165         {\r
166                 case 0: //up\r
167                         out = 0x1E;\r
168                 break;\r
169                 case 4: //down\r
170                         out = 0x1F;\r
171                 break;\r
172                 case 1: //left\r
173                         out = 0x11;\r
174                 break;\r
175                 case 3: //right\r
176                         out = 0x10;\r
177                 break;\r
178                 default: //null\r
179                         out = 0xB3;\r
180                 break;\r
181         }\r
182         return out;\r
183 }\r