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