|
|
1.1 root 1: /*
2: MS-DOS Player for Win32 console
3:
4: Author : Takeda.Toshiya
5: Date : 2009.11.09-
6: */
7:
8: #ifndef _MSDOS_H_
9: #define _MSDOS_H_
10:
1.1.1.12 root 11: #ifndef _WIN32_WINNT
12: #define _WIN32_WINNT 0x501
13: #endif
1.1 root 14: #include <windows.h>
15: #include <winioctl.h>
16: #include <tchar.h>
1.1.1.13 root 17: #include <stddef.h>
1.1 root 18: #include <stdlib.h>
19: #include <stdio.h>
1.1.1.2 root 20: #include <assert.h>
1.1 root 21: #include <conio.h>
1.1.1.2 root 22: #include <math.h>
1.1 root 23: #include <dos.h>
24: #include <fcntl.h>
25: #include <sys/types.h>
26: #include <sys/stat.h>
27: #include <io.h>
28: #include <sys/locking.h>
29: #include <mbctype.h>
30: #include <direct.h>
31: #include <errno.h>
1.1.1.9 root 32: #include <tlhelp32.h>
33: #include <psapi.h>
1.1.1.20! root 34: #include <setupapi.h>
1.1 root 35:
1.1.1.15 root 36: #ifdef _DEBUG
37: #define _CRTDBG_MAP_ALLOC
38: #include <crtdbg.h>
39: #define calloc(c, s) _calloc_dbg(c, s, _NORMAL_BLOCK, __FILE__, __LINE__)
40: #define malloc(s) _malloc_dbg(s, _NORMAL_BLOCK, __FILE__, __LINE__)
41: #define new new(_NORMAL_BLOCK, __FILE__, __LINE__)
42: #endif
43:
1.1.1.9 root 44: // variable scope of 'for' loop for Microsoft Visual C++ 6.0
45: #if defined(_MSC_VER) && (_MSC_VER == 1200)
1.1 root 46: #define for if(0);else for
47: #endif
1.1.1.9 root 48:
49: // disable warnings for Microsoft Visual C++ 2005 or later
1.1 root 50: #if defined(_MSC_VER) && (_MSC_VER >= 1400)
51: #pragma warning( disable : 4819 )
52: #pragma warning( disable : 4995 )
53: #pragma warning( disable : 4996 )
1.1.1.9 root 54: // for MAME i86/i386
55: #pragma warning( disable : 4018 )
56: #pragma warning( disable : 4065 )
57: #pragma warning( disable : 4146 )
58: #pragma warning( disable : 4244 )
59: #pragma warning( disable : 4267 )
60: #endif
61:
62: // endian
63: #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
64: #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
65: #if __BYTE_ORDER == __LITTLE_ENDIAN
66: #define __LITTLE_ENDIAN__
67: #elif __BYTE_ORDER == __BIG_ENDIAN
68: #define __BIG_ENDIAN__
69: #endif
70: #elif defined(WORDS_LITTLEENDIAN)
71: #define __LITTLE_ENDIAN__
72: #elif defined(WORDS_BIGENDIAN)
73: #define __BIG_ENDIAN__
74: #endif
75: #endif
76: #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
77: // Microsoft Visual C++
78: #define __LITTLE_ENDIAN__
1.1 root 79: #endif
1.1.1.9 root 80:
1.1 root 81: // compat for mingw32 headers
82: #ifndef COMMON_LVB_UNDERSCORE
83: #define COMMON_LVB_UNDERSCORE 0x8000
84: #endif
85:
86: // type definition
87: #ifndef UINT8
88: typedef unsigned char UINT8;
89: #endif
90: #ifndef UINT16
91: typedef unsigned short UINT16;
92: #endif
93: #ifndef UINT32
94: typedef unsigned int UINT32;
95: #endif
96: #ifndef INT8
97: typedef signed char INT8;
98: #endif
99: #ifndef INT16
100: typedef signed short INT16;
101: #endif
102: #ifndef INT32
103: typedef signed int INT32;
104: #endif
105:
106: #pragma pack(1)
107: typedef union {
108: UINT32 dw;
109: struct {
1.1.1.9 root 110: #ifdef __BIG_ENDIAN__
111: UINT16 h, l;
112: #else
1.1 root 113: UINT16 l, h;
1.1.1.9 root 114: #endif
1.1 root 115: } w;
116: } PAIR32;
117: #pragma pack()
118:
119: /* ----------------------------------------------------------------------------
120: FIFO buffer
121: ---------------------------------------------------------------------------- */
122:
123: class FIFO
124: {
125: private:
1.1.1.20! root 126: int size;
! 127: int *buf;
1.1 root 128: int cnt, rpt, wpt, stored[3];
129: public:
1.1.1.20! root 130: FIFO(int s) {
! 131: size = s;
! 132: buf = (int *)malloc(size * sizeof(int));
1.1 root 133: cnt = rpt = wpt = 0;
134: }
1.1.1.20! root 135: void release()
! 136: {
! 137: free(buf);
! 138: }
1.1 root 139: void write(int val) {
1.1.1.20! root 140: if(cnt < size) {
1.1 root 141: buf[wpt++] = val;
1.1.1.20! root 142: if(wpt >= size) {
1.1 root 143: wpt = 0;
144: }
145: cnt++;
146: }
147: }
148: int read() {
149: int val = 0;
150: if(cnt) {
151: val = buf[rpt++];
1.1.1.20! root 152: if(rpt >= size) {
1.1 root 153: rpt = 0;
154: }
155: cnt--;
156: }
1.1.1.20! root 157: return(val);
1.1 root 158: }
159: int count() {
1.1.1.20! root 160: return(cnt);
! 161: }
! 162: int remain() {
! 163: return(size - cnt);
! 164: }
! 165: bool full()
! 166: {
! 167: return(cnt == size);
! 168: }
! 169: bool empty()
! 170: {
! 171: return(cnt == 0);
1.1 root 172: }
173: void store_buffer() {
174: stored[0] = cnt;
175: stored[1] = rpt;
176: stored[2] = wpt;
177: }
178: void restore_buffer() {
179: cnt = stored[0];
180: rpt = stored[1];
181: wpt = stored[2];
182: }
183: };
184:
185: /* ----------------------------------------------------------------------------
1.1.1.14 root 186: MAME i86/i386
187: ---------------------------------------------------------------------------- */
188:
189: #if defined(HAS_I86)
190: #define CPU_MODEL i8086
191: #elif defined(HAS_I186)
192: #define CPU_MODEL i80186
193: #elif defined(HAS_V30)
194: #define CPU_MODEL v30
195: #elif defined(HAS_I286)
196: #define CPU_MODEL i80286
197: #elif defined(HAS_I386)
198: #define CPU_MODEL i386
199: #else
200: // #if defined(HAS_I386SX)
201: // #define CPU_MODEL i386SX
202: // #else
203: #if defined(HAS_I486)
204: #define CPU_MODEL i486
205: #else
206: #if defined(HAS_PENTIUM)
207: #define CPU_MODEL pentium
208: #elif defined(HAS_MEDIAGX)
209: #define CPU_MODEL mediagx
210: #elif defined(HAS_PENTIUM_PRO)
211: #define CPU_MODEL pentium_pro
212: #elif defined(HAS_PENTIUM_MMX)
213: #define CPU_MODEL pentium_mmx
214: #elif defined(HAS_PENTIUM2)
215: #define CPU_MODEL pentium2
216: #elif defined(HAS_PENTIUM3)
217: #define CPU_MODEL pentium3
218: #elif defined(HAS_PENTIUM4)
219: #define CPU_MODEL pentium4
220: #endif
221: #define SUPPORT_RDTSC
222: #endif
223: #define SUPPORT_FPU
224: // #endif
225: #define HAS_I386
226: #endif
227:
228: /* ----------------------------------------------------------------------------
229: PC/AT hardware emulation
230: ---------------------------------------------------------------------------- */
231:
232: void hardware_init();
233: void hardware_finish();
234: void hardware_run();
235: void hardware_update();
236:
237: // memory
238:
239: #if defined(HAS_I386)
240: #define MAX_MEM 0x2000000 /* 32MB */
241: #elif defined(HAS_I286)
242: #define MAX_MEM 0x1000000 /* 16MB */
243: #else
244: #define MAX_MEM 0x100000 /* 1MB */
245: #endif
246: UINT8 mem[MAX_MEM + 3];
247:
248: // ems
249:
250: #define MAX_EMS_HANDLES 16
251: #define MAX_EMS_PAGES 2048 /* 32MB */
252:
253: struct {
254: char name[8];
255: UINT8* buffer;
256: int pages;
257: bool allocated;
258: } ems_handles[MAX_EMS_HANDLES];
259:
260: struct {
261: UINT16 handle;
262: UINT16 page;
263: bool mapped;
264: } ems_pages[4];
265:
266: int free_ems_pages;
267:
268: void ems_init();
269: void ems_finish();
270: void ems_allocate_pages(int handle, int pages);
271: void ems_reallocate_pages(int handle, int pages);
272: void ems_release_pages(int handle);
273: void ems_map_page(int physical, int handle, int logical);
274: void ems_unmap_page(int physical);
275:
276: // xms
277:
278: #if defined(HAS_I286) || defined(HAS_I386)
279: #define SUPPORT_XMS
280: #endif
281:
282: #ifdef SUPPORT_XMS
283: #define MAX_XMS_HANDLES 16
284: #define MAX_XMS_SIZE_KB 0x8000 // 32MB
285:
286: struct {
287: int seg;
288: int size_kb;
289: int lock;
290: bool allocated;
291: } xms_handles[MAX_XMS_HANDLES + 1];
1.1.1.16 root 292:
293: int xms_a20_local_enb_count = 0;
1.1.1.14 root 294: #endif
295:
1.1.1.20! root 296: // dma
! 297:
! 298: typedef struct {
! 299: struct {
! 300: union {
! 301: UINT16 w;
! 302: struct {
! 303: #ifdef __BIG_ENDIAN__
! 304: UINT8 h, l;
! 305: #else
! 306: UINT8 l, h;
! 307: #endif
! 308: } b;
! 309: } areg, creg, bareg, bcreg;
! 310: UINT8 mode;
! 311: UINT8 pagereg;
! 312: UINT32 port;
! 313: } ch[4];
! 314:
! 315: bool low_high;
! 316: UINT8 cmd;
! 317: UINT8 req;
! 318: UINT8 mask;
! 319: UINT8 tc;
! 320: UINT16 tmp;
! 321: } dma_t;
! 322:
! 323: dma_t dma[2] = {0};
! 324:
! 325: void dma_init();
! 326: void dma_reset(int c);
! 327: void dma_write(int c, UINT32 addr, UINT8 data);
! 328: UINT8 dma_read(int c, UINT32 addr);
! 329: void dma_page_write(int c, int ch, UINT8 data);
! 330: UINT8 dma_page_read(int c, int ch);
! 331: void dma_run(int c, int ch);
! 332:
1.1.1.14 root 333: // pic
334:
335: typedef struct {
336: UINT8 imr, isr, irr, prio;
337: UINT8 icw1, icw2, icw3, icw4;
338: UINT8 ocw3;
339: UINT8 icw2_r, icw3_r, icw4_r;
340: } pic_t;
341:
342: pic_t pic[2];
343: int pic_req_chip, pic_req_level;
344: UINT8 pic_req_bit;
345:
346: void pic_init();
347: void pic_write(int c, UINT32 addr, UINT8 data);
348: UINT8 pic_read(int c, UINT32 addr);
349: void pic_req(int c, int level, int signal);
350: int pic_ack();
351: void pic_update();
352:
1.1.1.20! root 353: // pio
! 354:
! 355: typedef struct {
! 356: UINT8 data, stat, ctrl;
! 357: } pio_t;
! 358:
! 359: pio_t pio[2] = {0};;
! 360:
! 361: void pio_init();
! 362: void pio_write(int c, UINT32 addr, UINT8 data);
! 363: UINT8 pio_read(int c, UINT32 addr);
! 364:
1.1.1.14 root 365: // pit
366:
367: #define PIT_ALWAYS_RUNNING
368:
369: typedef struct {
370: INT32 count;
371: UINT16 latch;
372: UINT16 count_reg;
373: UINT8 ctrl_reg;
374: int count_latched;
375: int low_read, high_read;
376: int low_write, high_write;
377: int mode;
378: int status_latched;
379: UINT8 status;
380: // constant clock
381: UINT32 expired_time;
382: UINT32 prev_time;
1.1.1.17 root 383: UINT64 accum;
1.1.1.14 root 384: } pit_t;
385:
386: pit_t pit[3];
387: #ifndef PIT_ALWAYS_RUNNING
388: int pit_active;
389: #endif
390:
391: void pit_init();
392: void pit_write(int ch, UINT8 val);
393: UINT8 pit_read(int ch);
394: int pit_run(int ch, UINT32 cur_time);
395: void pit_latch_count(int ch);
396: int pit_get_expired_time(int ch);
397:
398: UINT8 system_port = 0;
399:
1.1.1.20! root 400: // sio
! 401:
! 402: #define SIO_BUFFER_SIZE 1024
! 403:
! 404: typedef struct {
! 405: int channel;
! 406: int port_number;
! 407:
! 408: FIFO *send_buffer;
! 409: FIFO *recv_buffer;
! 410:
! 411: union {
! 412: UINT16 w;
! 413: struct {
! 414: #ifdef __BIG_ENDIAN__
! 415: UINT8 h, l;
! 416: #else
! 417: UINT8 l, h;
! 418: #endif
! 419: } b;
! 420: } divisor;
! 421: UINT16 prev_divisor;
! 422: UINT8 line_ctrl, prev_line_ctrl;
! 423: UINT8 selector;
! 424:
! 425: UINT8 modem_ctrl;
! 426: bool set_brk, prev_set_brk;
! 427: bool set_rts, prev_set_rts;
! 428: bool set_dtr, prev_set_dtr;
! 429:
! 430: UINT8 line_stat_buf, line_stat_err;
! 431: UINT8 modem_stat, prev_modem_stat;
! 432:
! 433: UINT8 irq_enable;
! 434: UINT8 irq_identify;
! 435:
! 436: UINT8 scratch;
! 437: } sio_t;
! 438:
! 439: typedef struct {
! 440: HANDLE hThread;
! 441: CRITICAL_SECTION csSendData;
! 442: CRITICAL_SECTION csRecvData;
! 443: CRITICAL_SECTION csLineCtrl;
! 444: CRITICAL_SECTION csLineStat;
! 445: CRITICAL_SECTION csModemCtrl;
! 446: CRITICAL_SECTION csModemStat;
! 447: } sio_mt_t;
! 448:
! 449: sio_t sio[2] = {0};
! 450: sio_mt_t sio_mt[2] = {0};
! 451:
! 452: void sio_init();
! 453: void sio_finish();
! 454: void sio_write(int c, UINT32 addr, UINT8 data);
! 455: UINT8 sio_read(int c, UINT32 addr);
! 456: void sio_update(int c);
! 457: void sio_update_irq(int c);
! 458: DWORD WINAPI sio_thread(void *lpx);
! 459:
1.1.1.14 root 460: // cmos
461:
462: UINT8 cmos[128];
463: UINT8 cmos_addr;
464:
465: void cmos_init();
466: void cmos_write(int addr, UINT8 val);
467: UINT8 cmos_read(int addr);
468:
469: // kbd (a20)
470:
471: UINT8 kbd_data;
472: UINT8 kbd_status;
473: UINT8 kbd_command;
474:
475: void kbd_init();
476: UINT8 kbd_read_data();
477: void kbd_write_data(UINT8 val);
478: UINT8 kbd_read_status();
479: void kbd_write_command(UINT8 val);
480:
481: /* ----------------------------------------------------------------------------
1.1 root 482: MS-DOS virtual machine
483: ---------------------------------------------------------------------------- */
484:
485: #define VECTOR_TOP 0
486: #define VECTOR_SIZE 0x400
487: #define BIOS_TOP (VECTOR_TOP + VECTOR_SIZE)
488: #define BIOS_SIZE 0x100
489: #define WORK_TOP (BIOS_TOP + BIOS_SIZE)
1.1.1.14 root 490: #define WORK_SIZE 0x200
1.1.1.20! root 491: // IO.SYS 0070:0000
! 492: #define DEVICE_TOP (WORK_TOP + WORK_SIZE)
! 493: #define DEVICE_SIZE 0x40 /* 22 + 18 * 2 */
! 494: #define DOS_INFO_TOP (DEVICE_TOP + DEVICE_SIZE)
1.1 root 495: #define DOS_INFO_SIZE 0x100
1.1.1.20! root 496: #define EXT_BIOS_TOP (DOS_INFO_TOP + DOS_INFO_SIZE)
! 497: #define EXT_BIOS_SIZE 0x400
! 498: #define DPB_TOP (EXT_BIOS_TOP + EXT_BIOS_SIZE)
1.1 root 499: #define DPB_SIZE 0x400
1.1.1.16 root 500: #define SFT_TOP (DPB_TOP + DPB_SIZE)
501: #define SFT_SIZE 0x4b0 /* 6 + 0x3b * 20 */
502: #define DISK_BUF_TOP (SFT_TOP + SFT_SIZE)
1.1.1.14 root 503: #define DISK_BUF_SIZE 0x20
504: #define CDS_TOP (DISK_BUF_TOP + DISK_BUF_SIZE)
1.1 root 505: #define CDS_SIZE 0x80
506: #define FCB_TABLE_TOP (CDS_TOP + CDS_SIZE)
507: #define FCB_TABLE_SIZE 0x10
1.1.1.17 root 508: #define ERR_TABLE_TOP (FCB_TABLE_TOP + FCB_TABLE_SIZE)
509: #define ERR_TABLE_SIZE 0x10
1.1.1.18 root 510: #define SDA_TOP (ERR_TABLE_TOP + ERR_TABLE_SIZE)
511: #define SDA_SIZE 0xb0
1.1.1.13 root 512: // nls tables
1.1.1.18 root 513: #define UPPERTABLE_TOP (SDA_TOP + SDA_SIZE)
1.1.1.13 root 514: #define UPPERTABLE_SIZE 0x82
1.1.1.18 root 515: #define LOWERTABLE_TOP (UPPERTABLE_TOP + UPPERTABLE_SIZE)
516: #define LOWERTABLE_SIZE 0x82
517: #define FILENAME_UPPERTABLE_TOP (LOWERTABLE_TOP + LOWERTABLE_SIZE)
1.1.1.13 root 518: #define FILENAME_UPPERTABLE_SIZE 0x82
519: #define FILENAME_TERMINATOR_TOP (FILENAME_UPPERTABLE_TOP + FILENAME_UPPERTABLE_SIZE)
520: #define FILENAME_TERMINATOR_SIZE 0x20 /* requirement: 10 + 14(terminate chars) */
521: #define COLLATING_TABLE_TOP (FILENAME_TERMINATOR_TOP + FILENAME_TERMINATOR_SIZE)
522: #define COLLATING_TABLE_SIZE 0x102
523: #define DBCS_TOP (COLLATING_TABLE_TOP + COLLATING_TABLE_SIZE)
1.1 root 524: #define DBCS_TABLE (DBCS_TOP + 2)
525: #define DBCS_SIZE 0x10
1.1.1.13 root 526: #define MSDOS_SYSTEM_DATA_END (DBCS_TOP + DBCS_SIZE)
527: #define MEMORY_TOP ((MSDOS_SYSTEM_DATA_END + 15) & ~15U)
1.1.1.7 root 528: #define MEMORY_END 0xb8000
529: #define TEXT_VRAM_TOP 0xb8000
1.1.1.14 root 530: #define EMS_TOP 0xc0000
531: #define EMS_SIZE 0x10000
532: UINT32 UMB_TOP = EMS_TOP; // EMS is disabled
1.1.1.7 root 533: #define UMB_END 0xf8000
534: #define SHADOW_BUF_TOP 0xf8000
1.1.1.14 root 535: #define EMB_TOP 0x10fff0
536: #define EMB_END MAX_MEM
537:
538: UINT32 IRET_TOP = 0;
539: #define IRET_SIZE 0x100
540: UINT32 XMS_TOP = 0;
541: #define XMS_SIZE 0x20
1.1 root 542:
543: //#define ENV_SIZE 0x800
544: #define ENV_SIZE 0x2000
545: #define PSP_SIZE 0x100
546:
547: #define MAX_FILES 128
548: #define MAX_PROCESS 16
1.1.1.12 root 549: #define MAX_DTAINFO 128
1.1.1.11 root 550: #define LFN_DTA_LADDR 0x10FFF0
1.1.1.12 root 551: #define FIND_MAGIC 0x46696e64
1.1 root 552:
1.1.1.16 root 553: #define DUP_STDIN 27
554: #define DUP_STDOUT 28
555: #define DUP_STDERR 29
556: #define DUP_STDAUX 30
557: #define DUP_STDPRN 31
1.1 root 558:
1.1.1.16 root 559: //#define MAP_AUX_DEVICE_TO_FILE
560: //#define MAP_PRN_DEVICE_TO_FILE
1.1 root 561:
562: #pragma pack(1)
563: typedef struct {
564: UINT8 mz;
565: UINT16 psp;
1.1.1.14 root 566: union {
567: UINT8 reserved[5];
568: UINT16 paragraphs16;
569: UINT32 paragraphs32;
570: };
1.1.1.3 root 571: char prog_name[8];
1.1.1.14 root 572: // use 32bit paragraphs for emb
573: UINT32 paragraphs()
574: {
575: UINT32 offset = &(this->mz) - mem;
576: return (offset >= EMB_TOP) ? paragraphs32 : paragraphs16;
577: }
578: UINT32 size_kb()
579: {
580: return paragraphs() >> 6;
581: }
1.1 root 582: } mcb_t;
583: #pragma pack()
584:
585: #pragma pack(1)
586: typedef struct {
587: UINT16 env_seg;
588: PAIR32 cmd_line;
589: PAIR32 fcb1;
590: PAIR32 fcb2;
591: UINT16 sp;
592: UINT16 ss;
593: UINT16 ip;
594: UINT16 cs;
595: } param_block_t;
596: #pragma pack()
597:
598: #pragma pack(1)
599: typedef struct {
600: UINT8 len;
601: char cmd[127];
602: } cmd_line_t;
603: #pragma pack()
604:
605: #pragma pack(1)
606: typedef struct {
607: UINT8 exit[2];
608: UINT16 first_mcb;
609: UINT8 reserved_1;
610: UINT8 far_call;
611: PAIR32 cpm_entry;
612: PAIR32 int_22h;
613: PAIR32 int_23h;
614: PAIR32 int_24h;
615: UINT16 parent_psp;
616: UINT8 file_table[20];
617: UINT16 env_seg;
618: PAIR32 stack;
1.1.1.12 root 619: UINT16 file_table_size;
620: PAIR32 file_table_ptr;
621: UINT8 reserved_2[24];
1.1 root 622: UINT8 service[3];
623: UINT8 reserved_3[2];
624: UINT8 ex_fcb[7];
625: UINT8 fcb1[16];
626: UINT8 fcb2[20];
627: UINT8 buffer[128];
628: } psp_t;
629: #pragma pack()
630:
631: #pragma pack(1)
632: typedef struct {
633: UINT16 mz;
634: UINT16 extra_bytes;
635: UINT16 pages;
636: UINT16 relocations;
637: UINT16 header_size;
638: UINT16 min_alloc;
639: UINT16 max_alloc;
640: UINT16 init_ss;
641: UINT16 init_sp;
642: UINT16 check_sum;
643: UINT16 init_ip;
644: UINT16 init_cs;
645: UINT16 relocation_table;
646: UINT16 overlay;
647: } exe_header_t;
648: #pragma pack()
649:
650: #pragma pack(1)
651: typedef struct {
652: UINT8 flag;
653: UINT8 reserved[5];
654: UINT8 attribute;
655: } ext_fcb_t;
656: #pragma pack()
657:
658: #pragma pack(1)
659: typedef struct {
660: UINT8 drive;
661: UINT8 file_name[8 + 3];
662: UINT16 current_block;
663: UINT16 record_size;
664: UINT32 file_size;
665: UINT16 date;
666: UINT16 time;
1.1.1.12 root 667: union {
668: UINT8 reserved[8];
669: HANDLE handle;
670: };
1.1 root 671: UINT8 cur_record;
672: UINT32 rand_record;
673: } fcb_t;
674: #pragma pack()
675:
676: #pragma pack(1)
677: typedef struct {
678: UINT8 drive;
679: UINT8 file_name[8 + 3];
680: UINT8 attribute;
681: UINT8 nt_res;
682: UINT8 create_time_ms;
683: UINT16 creation_time;
684: UINT16 creation_date;
685: UINT16 last_access_date;
686: UINT16 cluster_hi;
687: UINT16 last_write_time;
688: UINT16 last_write_date;
689: UINT16 cluster_lo;
690: UINT32 file_size;
691: } find_fcb_t;
692: #pragma pack()
693:
694: #pragma pack(1)
695: typedef struct {
1.1.1.12 root 696: union {
697: UINT8 reserved[21];
698: struct {
699: UINT32 find_magic;
700: UINT32 dta_index;
701: };
702: };
1.1 root 703: UINT8 attrib;
704: UINT16 time;
705: UINT16 date;
706: UINT32 size;
707: char name[13];
708: } find_t;
709: #pragma pack()
710:
711: #pragma pack(1)
712: typedef struct {
713: UINT32 attrib;
714: PAIR32 ctime_lo;
715: PAIR32 ctime_hi;
716: PAIR32 atime_lo;
717: PAIR32 atime_hi;
718: PAIR32 mtime_lo;
719: PAIR32 mtime_hi;
720: UINT32 size_hi;
721: UINT32 size_lo;
722: UINT8 reserved[8];
723: char full_name[260];
724: char short_name[14];
725: } find_lfn_t;
726: #pragma pack()
727:
728: #pragma pack(1)
729: typedef struct {
730: UINT16 info_level;
731: UINT32 serial_number;
732: char volume_label[11];
733: char file_system[8];
734: } drive_info_t;
735: #pragma pack()
736:
737: #pragma pack(1)
738: typedef struct {
739: UINT16 size_of_structure;
740: UINT16 structure_version;
741: UINT32 sectors_per_cluster;
742: UINT32 bytes_per_sector;
743: UINT32 available_clusters_on_drive;
744: UINT32 total_clusters_on_drive;
745: UINT32 available_sectors_on_drive;
746: UINT32 total_sectors_on_drive;
747: UINT32 available_allocation_units;
748: UINT32 total_allocation_units;
749: UINT8 reserved[8];
750: } ext_space_info_t;
751: #pragma pack()
752:
753: #pragma pack(1)
754: typedef struct {
755: UINT8 drive_num;
756: UINT8 unit_num;
757: UINT16 bytes_per_sector;
758: UINT8 highest_sector_num;
759: UINT8 shift_count;
760: UINT16 reserved_sectors;
761: UINT8 fat_num;
762: UINT16 root_entries;
763: UINT16 first_data_sector;
764: UINT16 highest_cluster_num;
765: UINT16 sectors_per_fat;
766: UINT16 first_dir_sector;
767: UINT32 device_driver_header;
768: UINT8 media_type;
769: UINT8 drive_accessed;
770: UINT16 next_dpb_ofs;
771: UINT16 next_dpb_seg;
772: UINT16 first_free_cluster;
773: UINT16 free_clusters;
1.1.1.12 root 774: // extended
775: UINT16 fat_mirroring;
776: UINT16 info_sector;
777: UINT16 backup_boot_sector;
778: UINT32 first_cluster_sector;
779: UINT32 maximum_cluster_num;
780: UINT32 fat_sectors;
781: UINT32 root_cluster;
782: UINT32 free_search_cluster;
1.1 root 783: } dpb_t;
784: #pragma pack()
785:
786: #pragma pack(1)
787: typedef struct {
788: char path_name[67];
789: UINT16 drive_attrib;
790: UINT8 physical_drive_number;
791: } cds_t;
792: #pragma pack()
793:
794: #pragma pack(1)
795: typedef struct {
1.1.1.18 root 796: UINT8 reserved_1[3]; // -34
797: UINT8 switchar; // -31 current switch character
798: UINT8 malloc_strategy; // -30 current memory allocation strategy
799: UINT8 reserved_2[29]; // -29
800: // ----- from DOSBox -----
801: UINT8 crit_error_flag; // 0x00 Critical Error Flag
802: UINT8 indos_flag; // 0x01 InDOS flag (count of active INT 21 calls)
803: UINT8 drive_crit_error; // 0x02 Drive on which current critical error occurred or FFh
804: UINT8 locus_of_last_error; // 0x03 locus of last error
805: UINT16 extended_error_code; // 0x04 extended error code of last error
806: UINT8 suggested_action; // 0x06 suggested action for last error
807: UINT8 error_class; // 0x07 class of last error
808: PAIR32 last_error_pointer; // 0x08 ES:DI pointer for last error
809: PAIR32 current_dta; // 0x0C current DTA (Disk Transfer Address)
810: UINT16 current_psp; // 0x10 current PSP
811: UINT16 sp_int_23; // 0x12 stores SP across an INT 23
812: UINT16 return_code; // 0x14 return code from last process termination (zerod after reading with AH=4Dh)
813: UINT8 current_drive; // 0x16 current drive
814: UINT8 extended_break_flag; // 0x17 extended break flag
815: UINT8 fill[2]; // 0x18 flag: code page switching || flag: copy of previous byte in case of INT 24 Abort
816: } sda_t;
817: #pragma pack()
818:
819: #pragma pack(1)
820: typedef struct {
1.1.1.14 root 821: UINT8 reserved_0[4]; // -38
822: UINT16 magic_word; // -34 from DOSBox
823: UINT8 reserved_1[30]; // -32
1.1 root 824: UINT16 first_mcb; // -2
825: PAIR32 first_dpb; // +0
1.1.1.14 root 826: PAIR32 first_sft; // +4
1.1.1.20! root 827: PAIR32 clock_device; // +8
! 828: PAIR32 con_device; // +12
1.1.1.14 root 829: UINT16 max_sector_len; // +16
830: PAIR32 disk_buf_info; // +18 from DOSBox
1.1 root 831: PAIR32 cds; // +22
832: PAIR32 fcb_table; // +26
1.1.1.20! root 833: UINT8 reserved_2[3]; // +30
1.1 root 834: UINT8 last_drive; // +33
1.1.1.14 root 835: struct {
1.1.1.20! root 836: PAIR32 next_driver; // +34
1.1.1.14 root 837: UINT16 attributes; // +38
838: UINT16 strategy; // +40
839: UINT16 interrupt; // +42
840: char dev_name[8]; // +44
841: } nul_device;
1.1.1.20! root 842: UINT8 reserved_3[11]; // +52
1.1 root 843: UINT16 buffers_x; // +63
844: UINT16 buffers_y; // +65
845: UINT8 boot_drive; // +67
846: UINT8 i386_or_later; // +68
847: UINT16 ext_mem_size; // +69
1.1.1.14 root 848: PAIR32 disk_buf_heads; // +71 from DOSBox
1.1.1.20! root 849: UINT8 reserved_4[21]; // +75
1.1.1.5 root 850: UINT8 dos_flag; // +96
1.1.1.20! root 851: UINT8 reserved_5[2]; // +97
1.1.1.15 root 852: UINT8 umb_linked; // +99 from DOSBox
1.1.1.20! root 853: UINT8 reserved_6[2]; // +100
1.1.1.15 root 854: UINT16 first_umb_fcb; // +102 from DOSBox
855: UINT16 first_mcb_2; // +104 from DOSBox
1.1 root 856: } dos_info_t;
857: #pragma pack()
858:
1.1.1.14 root 859: #pragma pack(1)
860: typedef struct {
1.1.1.20! root 861: PAIR32 next_driver;
! 862: UINT16 attributes;
! 863: UINT16 strategy;
! 864: UINT16 interrupt;
! 865: char dev_name[8];
! 866: } device_t;
! 867: #pragma pack()
! 868:
! 869: #pragma pack(1)
! 870: typedef struct {
1.1.1.14 root 871: UINT16 date_format;
872: char currency_symbol[5];
873: char thou_sep[2];
874: char dec_sep[2];
875: char date_sep[2];
876: char time_sep[2];
877: char currency_format;
878: char currency_dec_digits;
879: char time_format;
880: PAIR32 case_map;
881: char list_sep[2];
882: char reserved[10];
883: } country_info_t;
884: #pragma pack()
885:
1.1 root 886: typedef struct {
887: char path[MAX_PATH];
888: int valid;
889: int id;
890: int atty;
891: int mode;
892: UINT16 info;
893: UINT16 psp;
894: } file_handler_t;
895:
896: static const struct {
897: int mode;
898: int in;
899: int out;
900: } file_mode[] = {
1.1.1.11 root 901: { _O_RDONLY | _O_BINARY, 1, 0 },
1.1 root 902: { _O_WRONLY | _O_BINARY, 0, 1 },
903: { _O_RDWR | _O_BINARY, 1, 1 },
904: };
905:
906: typedef struct {
907: UINT16 psp;
908: char module_dir[MAX_PATH];
909: PAIR32 dta;
910: UINT8 switchar;
911: UINT8 verify;
912: int max_files;
913: char volume_label[MAX_PATH];
914: bool parent_int_10h_feh_called;
915: bool parent_int_10h_ffh_called;
1.1.1.12 root 916: UINT16 parent_ds;
1.1.1.14 root 917: struct {
918: UINT16 handle;
919: UINT16 page;
920: bool mapped;
921: } ems_pages[4];
922: bool ems_pages_stored;
1.1 root 923: } process_t;
924:
1.1.1.11 root 925: typedef struct {
926: UINT16 psp;
927: UINT32 dta;
1.1.1.12 root 928: UINT8 allowable_mask;
929: UINT8 required_mask;
1.1.1.11 root 930: HANDLE find_handle;
931: } dtainfo_t;
932:
1.1.1.8 root 933: UINT8 major_version = 7;
934: UINT8 minor_version = 10;
935:
1.1.1.7 root 936: UINT16 first_mcb;
1.1 root 937: UINT16 current_psp;
938:
939: int retval = 0;
940: UINT16 error_code = 0;
941:
942: file_handler_t file_handler[MAX_FILES];
943: UINT8 file_buffer[0x100000];
944:
945: process_t process[MAX_PROCESS];
1.1.1.11 root 946: dtainfo_t dtalist[MAX_DTAINFO];
1.1 root 947:
1.1.1.6 root 948: UINT16 malloc_strategy = 0;
949:
1.1.1.12 root 950: char comspec_path[MAX_PATH] = "C:\\COMMAND.COM";
951:
1.1 root 952: void msdos_syscall(unsigned num);
953: int msdos_init(int argc, char *argv[], char *envp[], int standard_env);
954: void msdos_finish();
955:
956: // console
957:
1.1.1.12 root 958: #define SCR_BUF_WIDTH 256
959: #define SCR_BUF_HEIGHT 128
1.1 root 960:
961: #define SET_RECT(rect, l, t, r, b) { \
962: rect.Left = l; \
963: rect.Top = t; \
964: rect.Right = r; \
965: rect.Bottom = b; \
966: }
967:
1.1.1.19 root 968: DWORD dwConsoleMode = 0;
969:
1.1.1.12 root 970: CHAR_INFO scr_buf[SCR_BUF_WIDTH * SCR_BUF_HEIGHT];
971: char scr_char[SCR_BUF_WIDTH * SCR_BUF_HEIGHT];
972: WORD scr_attr[SCR_BUF_WIDTH * SCR_BUF_HEIGHT];
1.1 root 973: COORD scr_buf_size;
974: COORD scr_buf_pos;
975: int scr_width, scr_height;
1.1.1.12 root 976: int scr_top;
1.1.1.10 root 977: bool restore_console_on_exit = false;
1.1 root 978: bool cursor_moved;
979:
980: FIFO *key_buf_char;
981: FIFO *key_buf_scan;
1.1.1.19 root 982: bool key_changed = false;
1.1.1.4 root 983: UINT32 key_code = 0;
1.1 root 984:
985: int active_code_page;
986: int system_code_page;
987:
1.1.1.12 root 988: UINT32 text_vram_top_address;
989: UINT32 text_vram_end_address;
990: UINT32 shadow_buffer_top_address;
991: UINT32 shadow_buffer_end_address;
992: int vram_pages;
1.1 root 993: bool int_10h_feh_called = false;
994: bool int_10h_ffh_called = false;
995:
1.1.1.19 root 996: #define MAX_MOUSE_BUTTONS 3
997:
998: struct {
999: bool active;
1000: struct {
1001: int x, y;
1002: } position, prev_position, max_position, min_position, mickey;
1003: struct {
1004: bool status;
1005: int pressed_times;
1006: int released_times;
1007: struct {
1008: int x, y;
1009: } pressed_position;
1010: struct {
1011: int x, y;
1012: } released_position;
1013: } buttons[MAX_MOUSE_BUTTONS];
1014: int get_buttons()
1015: {
1016: int val = 0;
1017: for(int i = 0; i < MAX_MOUSE_BUTTONS; i++) {
1018: if(buttons[i].status) {
1019: val |= 1 << i;
1020: }
1021: }
1022: return(val);
1023: }
1024: UINT16 status;
1025: UINT16 status_irq;
1026: UINT16 call_mask;
1027: PAIR32 call_addr;
1028: // dummy
1029: UINT16 sensitivity[3];
1030: UINT16 display_page;
1031: UINT16 language;
1032: UINT16 hot_spot[2];
1033: } mouse = {0};
1034:
1035: UINT16 mouse_push_ax;
1036: UINT16 mouse_push_bx;
1037: UINT16 mouse_push_cx;
1038: UINT16 mouse_push_dx;
1039: UINT16 mouse_push_si;
1040: UINT16 mouse_push_di;
1041:
1.1 root 1042: #endif
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.