1 /* Project 16 Source Code~
\r
2 * Copyright (C) 2012-2020 sparky4 & pngwen & andrius4669 & joncampbell123 & yakui-lover
\r
4 * This file is part of Project 16.
\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
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
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
23 #include "src/lib/16_head.h"
\r
25 //cpu reg stuff for _AX, _BX, _CX, _DX
\r
30 // big global status text buffer
\r
31 char global_temp_status_text[512];
\r
32 char global_temp_status_text2[512];
\r
37 long int save_pos, size_of_file;
\r
39 save_pos = ftell(fp);
\r
40 fseek(fp, 0L, SEEK_END);
\r
41 size_of_file = ftell(fp);
\r
42 fseek(fp, save_pos, SEEK_SET);
\r
43 return(size_of_file);
\r
46 // clrstdin() clear any leftover chars tha may be in stdin stream //
\r
50 while( ( ch = getchar() ) != '\n' && ch != EOF );
\r
53 //from http://stackoverflow.com/questions/2736753/how-to-remove-extension-from-file-name
\r
54 // remove_ext: removes the "extension" from a file spec.
\r
55 // mystr is the string to process.
\r
56 // dot is the extension separator.
\r
57 // sep is the path separator (0 means to ignore).
\r
58 // Returns an allocated string identical to the original but
\r
59 // with the extension removed. It must be freed when you're
\r
60 // finished with it.
\r
61 // If you pass in NULL or the new string can't be allocated,
\r
64 char *remove_ext (char* mystr, char dot, char sep) {
\r
65 char *retstr, *lastdot, *lastsep;
\r
67 // Error checks and allocate string.
\r
70 if ((retstr = malloc(strlen (mystr) + 1)) == NULL)
\r
73 // Make a copy and find the relevant characters.
\r
75 strcpy (retstr, mystr);
\r
76 lastdot = strrchr (retstr, dot);
\r
77 lastsep = (sep == 0) ? NULL : strrchr (retstr, sep);
\r
79 // If it has an extension separator.
\r
81 if (lastdot != NULL) {
\r
82 // and it's before the extenstion separator.
\r
84 if (lastsep != NULL) {
\r
85 if (lastsep < lastdot) {
\r
91 // Has extension separator with no path separator.
\r
97 // Return the modified string.
\r
103 //from http://quiz.geeksforgeeks.org/c-program-cyclically-rotate-array-one/
\r
104 void rotateR(byte *arr, byte n)
\r
106 byte x = arr[n-1], i;
\r
107 for (i = n-1; i > 0; i--)
\r
112 void rotateL(byte *arr, byte n)
\r
114 byte x = arr[n+1], i;
\r
115 for (i = n+1; i > 0; i++)
\r
120 void printmeminfoline(byte *strc, const byte *pee, size_t h_total, size_t h_used, size_t h_free)
\r
123 strcat(strc,pee); strcat(strc," "); ultoa((dword)h_total,str,10); strcat(strc,str);
\r
124 if(strlen(str)<=4) strcat(strc," "); //printf("%u\n", strlen(str));
\r
125 strcat(strc," "); ultoa((dword)h_used,str,10); strcat(strc,str); strcat(strc," "); strcat(strc," ");
\r
126 ultoa((dword)h_free,str,10); strcat(strc,str);
\r
130 ///////////////////////////////////////////////////////////////////////////
\r
132 // US_CheckParm() - checks to see if a string matches one of a set of
\r
133 // strings. The check is case insensitive. The routine returns the
\r
134 // index of the string that matched, or -1 if no matches were found
\r
136 ///////////////////////////////////////////////////////////////////////////
\r
138 US_CheckParm(char *parm,char **strings)
\r
144 while (!isalpha(*parm)) // Skip non-alphas
\r
147 for (i = 0;*strings && **strings;i++)
\r
149 for (s = *strings++,p = parm,cs = cp = 0;cs == cp;)
\r
165 // for input test //
\r
166 byte dirchar(byte in)
\r
190 //from: http://stackoverflow.com/questions/5349896/print-a-struct-in-c
\r
191 void print_mem(void const *vp, size_t n)
\r
194 unsigned char const *p = vp;
\r
195 for (i=0; i<n; i++)
\r
197 printf("%02x", p[i]);
\r
198 //printf("%c", p[i]);
\r
199 if((!(i%16)) && i) printf("\n");
\r
201 //printf("%u%%40=%u\n", i, i%40);
\r
204 printf("\nstruct size is %zu bytes\n", n);
\r
207 //from: https://groups.google.com/forum/#!topic/comp.lang.asm.x86/QtuVXl43nDo
\r
219 //#define REGIDUMP_HEX
\r
220 #define REGIDUMP_DUMPFLAGS
\r
221 //#define REGIDUMP_USE_CAPS //uncomment to use the assembly
\r
226 unsigned short _ax,_bx,_cx,_dx;
\r
227 #ifndef __BORLANDC__
\r
228 unsigned short _cflag;
\r
230 unsigned char _al,_ah,_bl,_bh,_cl,_ch,_dl,_dh;
\r
232 unsigned short _bp,_si,_di,_sp;
\r
234 unsigned short _cs_,_ds_,_es_,_ss_; //SEGMENT
\r
235 // unsigned short _ip; //SPECIAL PURPOSE
\r
236 _ax=_bx=_cx=_dx=_si=_di=_bp=_sp=_cs_=_ds_=_es_=_ss_=0;
\r
237 #ifndef __BORLANDC__
\r
240 _ah=_al=_bh=_bl=_ch=_cl=_dh=_dl=0;
\r
242 #ifndef REGIDUMP_USE_CAPS
\r
290 #ifndef __BORLANDC__
\r
302 // printf("integer values: ax=%04d bx=%04d cx=%04d dx=%04d\n", a, b, c, d);
\r
303 // printf("unsigned values:ax=%04u bx=%04u cx=%04u dx=%04u\n", a, b, c, d);
\r
304 printf("================================================================================");
\r
305 printf("16 bit 8088 register values\n");
\r
306 printf("================================================================================");
\r
307 printf("general purpose:\n");
\r
308 #ifndef REGIDUMP_HEX
\r
309 printf(" ax=%04u\n bx=%04u\n cx=%04u\n dx=%04u\n\n", _ax, _bx, _cx, _dx);
\r
310 printf(" si=%04u\n di=%04u\n bp=%04u\n sp=%04u\n", _si, _di, _bp, _sp);
\r
312 printf(" ax=%04x\n bx=%04x\n cx=%04x\n dx=%04x\n\n", _ax, _bx, _cx, _dx);
\r
313 printf(" si=%04x\n di=%04x\n bp=%04x\n sp=%04x\n", _si, _di, _bp, _sp);
\r
315 printf(" ---------------------------------------\n");
\r
319 printf("segment:\n");
\r
320 #ifndef REGIDUMP_HEX
\r
321 //printf(" cs=%04u\n ds=%04u\n es=%04u\n ss=%04u\n", _cs_, _ds, _es_, _ss_);
\r
322 printf(" cs=%04u\n", _cs_); printf(" ds=%04u\n", _ds_); printf(" es=%04u\n", _es_); printf(" ss=%04u\n", _ss_);
\r
324 //printf(" cs=%04x\n ds=%04x\n es=%04x\n ss=%04x\n", _cs_, _ds_, _es_, _ss_);
\r
325 printf(" cs=%04x\n", _cs_); printf(" ds=%04x\n", _ds_); printf(" es=%04x\n", _es_); printf(" ss=%04x\n", _ss_);
\r
327 printf(" ---------------------------------------\n");
\r
330 #ifndef __BORLANDC__
\r
331 printf("cflags:\n");
\r
332 /* printf(" ip=%04u\n\n", _ip);
\r
333 printf(" cf=%04u\npf=%04u\naf=%04u\nzf=%04u\nsf=%04u\ntf=%04u\nif=%04u\ndf=%04u\nof=%04u\n", _cf, _pf, _af, _zf, _sf, _tf, _if, _df, _of);
\r
334 printf(" ---------------------------------------\n");*/
\r
335 #ifdef REGIDUMP_DUMPFLAGS
\r
336 #ifndef REGIDUMP_HEX
\r
337 // printf(" ip=%04u\n\n", _IP);
\r
338 // printf(" cf=%04u\npf=%04u\naf=%04u\nzf=%04u\nsf=%04u\ntf=%04u\nif=%04u\ndf=%04u\nof=%04u\n", _CF, _PF, _AF, _ZF, _SF, _TF, _IF, _DF, _OF);
\r
340 printf("cflag: "BYTE_TO_BINARY_PATTERN""BYTE_TO_BINARY_PATTERN"\n", BYTE_TO_BINARY(_cflag>>8), BYTE_TO_BINARY(_cflag));
\r
342 // printf(" ip=%04x\n\n", _IP);
\r
343 // printf(" cf=%04x\npf=%04x\naf=%04x\nzf=%04x\nsf=%04x\ntf=%04x\nif=%04x\ndf=%04x\nof=%04x\n", _CF, _PF, _AF, _ZF, _SF, _TF, _IF, _DF, _OF);
\r
344 printf("cflag: %016x\n",(_cflag));
\r
345 printf(" ahl=%016x", _al|(_ah<<4));
\r
347 printf("testing\n");
\r
348 // printf("dx: "NIBBLE_TO_BINARY_PATTERN""NIBBLE_TO_BINARY_PATTERN"\n", NIBBLE_TO_BINARY(_dx>>4), NIBBLE_TO_BINARY(_dx));
\r
349 // printf("dx: "BYTE_TO_BINARY_PATTERN""BYTE_TO_BINARY_PATTERN"\n", BYTE_TO_BINARY(_dx>>8), BYTE_TO_BINARY(_dx));
\r
350 printf("dx: "WORD_TO_BINARY_PATTERN"\n", WORD_TO_BINARY(_dx));
\r
351 printf(" ---------------------------------------\n");
\r
355 printf("for more info see\n http://stackoverflow.com/questions/9130349/how-many-registers-are-there-in-8086-8088\n");
\r
356 printf("================================================================================");
\r