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