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