Annotation of msdos-player/source/msdos.h, revision 1.1.1.14

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       root       34: 
1.1.1.9   root       35: // variable scope of 'for' loop for Microsoft Visual C++ 6.0
                     36: #if defined(_MSC_VER) && (_MSC_VER == 1200)
1.1       root       37: #define for if(0);else for
                     38: #endif
1.1.1.9   root       39: 
                     40: // disable warnings for Microsoft Visual C++ 2005 or later
1.1       root       41: #if defined(_MSC_VER) && (_MSC_VER >= 1400)
                     42: #pragma warning( disable : 4819 )
                     43: #pragma warning( disable : 4995 )
                     44: #pragma warning( disable : 4996 )
1.1.1.9   root       45: // for MAME i86/i386
                     46: #pragma warning( disable : 4018 )
                     47: #pragma warning( disable : 4065 )
                     48: #pragma warning( disable : 4146 )
                     49: #pragma warning( disable : 4244 )
                     50: #pragma warning( disable : 4267 )
                     51: #endif
                     52: 
                     53: // endian
                     54: #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
                     55:        #if defined(__BYTE_ORDER) && (defined(__LITTLE_ENDIAN) || defined(__BIG_ENDIAN))
                     56:                #if __BYTE_ORDER == __LITTLE_ENDIAN
                     57:                        #define __LITTLE_ENDIAN__
                     58:                #elif __BYTE_ORDER == __BIG_ENDIAN
                     59:                        #define __BIG_ENDIAN__
                     60:                #endif
                     61:        #elif defined(WORDS_LITTLEENDIAN)
                     62:                #define __LITTLE_ENDIAN__
                     63:        #elif defined(WORDS_BIGENDIAN)
                     64:                #define __BIG_ENDIAN__
                     65:        #endif
                     66: #endif
                     67: #if !defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)
                     68:        // Microsoft Visual C++
                     69:        #define __LITTLE_ENDIAN__
1.1       root       70: #endif
1.1.1.9   root       71: 
1.1       root       72: // compat for mingw32 headers
                     73: #ifndef COMMON_LVB_UNDERSCORE
                     74: #define COMMON_LVB_UNDERSCORE 0x8000
                     75: #endif
                     76: 
                     77: // type definition
                     78: #ifndef UINT8
                     79: typedef unsigned char UINT8;
                     80: #endif
                     81: #ifndef UINT16
                     82: typedef unsigned short UINT16;
                     83: #endif
                     84: #ifndef UINT32
                     85: typedef unsigned int UINT32;
                     86: #endif
                     87: #ifndef INT8
                     88: typedef signed char INT8;
                     89: #endif
                     90: #ifndef INT16
                     91: typedef signed short INT16;
                     92: #endif
                     93: #ifndef INT32
                     94: typedef signed int INT32;
                     95: #endif
                     96: 
                     97: #pragma pack(1)
                     98: typedef union {
                     99:        UINT32 dw;
                    100:        struct {
1.1.1.9   root      101: #ifdef __BIG_ENDIAN__
                    102:                UINT16 h, l;
                    103: #else
1.1       root      104:                UINT16 l, h;
1.1.1.9   root      105: #endif
1.1       root      106:        } w;
                    107: } PAIR32;
                    108: #pragma pack()
                    109: 
                    110: /* ----------------------------------------------------------------------------
                    111:        FIFO buffer
                    112: ---------------------------------------------------------------------------- */
                    113: 
                    114: #define MAX_FIFO       256
                    115: 
                    116: class FIFO
                    117: {
                    118: private:
                    119:        int buf[MAX_FIFO];
                    120:        int cnt, rpt, wpt, stored[3];
                    121: public:
                    122:        FIFO() {
                    123:                cnt = rpt = wpt = 0;
                    124:        }
                    125:        void write(int val) {
                    126:                if(cnt < MAX_FIFO) {
                    127:                        buf[wpt++] = val;
                    128:                        if(wpt >= MAX_FIFO) {
                    129:                                wpt = 0;
                    130:                        }
                    131:                        cnt++;
                    132:                }
                    133:        }
                    134:        int read() {
                    135:                int val = 0;
                    136:                if(cnt) {
                    137:                        val = buf[rpt++];
                    138:                        if(rpt >= MAX_FIFO) {
                    139:                                rpt = 0;
                    140:                        }
                    141:                        cnt--;
                    142:                }
                    143:                return val;
                    144:        }
                    145:        int count() {
                    146:                return cnt;
                    147:        }
                    148:        void store_buffer() {
                    149:                stored[0] = cnt;
                    150:                stored[1] = rpt;
                    151:                stored[2] = wpt;
                    152:        }
                    153:        void restore_buffer() {
                    154:                cnt = stored[0];
                    155:                rpt = stored[1];
                    156:                wpt = stored[2];
                    157:        }
                    158: };
                    159: 
                    160: /* ----------------------------------------------------------------------------
1.1.1.14! root      161:        MAME i86/i386
        !           162: ---------------------------------------------------------------------------- */
        !           163: 
        !           164: #if defined(HAS_I86)
        !           165:        #define CPU_MODEL i8086
        !           166: #elif defined(HAS_I186)
        !           167:        #define CPU_MODEL i80186
        !           168: #elif defined(HAS_V30)
        !           169:        #define CPU_MODEL v30
        !           170: #elif defined(HAS_I286)
        !           171:        #define CPU_MODEL i80286
        !           172: #elif defined(HAS_I386)
        !           173:        #define CPU_MODEL i386
        !           174: #else
        !           175: //     #if defined(HAS_I386SX)
        !           176: //             #define CPU_MODEL i386SX
        !           177: //     #else
        !           178:                #if defined(HAS_I486)
        !           179:                        #define CPU_MODEL i486
        !           180:                #else
        !           181:                        #if defined(HAS_PENTIUM)
        !           182:                                #define CPU_MODEL pentium
        !           183:                        #elif defined(HAS_MEDIAGX)
        !           184:                                #define CPU_MODEL mediagx
        !           185:                        #elif defined(HAS_PENTIUM_PRO)
        !           186:                                #define CPU_MODEL pentium_pro
        !           187:                        #elif defined(HAS_PENTIUM_MMX)
        !           188:                                #define CPU_MODEL pentium_mmx
        !           189:                        #elif defined(HAS_PENTIUM2)
        !           190:                                #define CPU_MODEL pentium2
        !           191:                        #elif defined(HAS_PENTIUM3)
        !           192:                                #define CPU_MODEL pentium3
        !           193:                        #elif defined(HAS_PENTIUM4)
        !           194:                                #define CPU_MODEL pentium4
        !           195:                        #endif
        !           196:                        #define SUPPORT_RDTSC
        !           197:                #endif
        !           198:                #define SUPPORT_FPU
        !           199: //     #endif
        !           200:        #define HAS_I386
        !           201: #endif
        !           202: 
        !           203: /* ----------------------------------------------------------------------------
        !           204:        PC/AT hardware emulation
        !           205: ---------------------------------------------------------------------------- */
        !           206: 
        !           207: void hardware_init();
        !           208: void hardware_finish();
        !           209: void hardware_run();
        !           210: void hardware_update();
        !           211: 
        !           212: // memory
        !           213: 
        !           214: #if defined(HAS_I386)
        !           215: #define MAX_MEM 0x2000000      /* 32MB */
        !           216: #elif defined(HAS_I286)
        !           217: #define MAX_MEM 0x1000000      /* 16MB */
        !           218: #else
        !           219: #define MAX_MEM 0x100000       /* 1MB */
        !           220: #endif
        !           221: UINT8 mem[MAX_MEM + 3];
        !           222: 
        !           223: // ems
        !           224: 
        !           225: #define MAX_EMS_HANDLES 16
        !           226: #define MAX_EMS_PAGES 2048     /* 32MB */
        !           227: 
        !           228: struct {
        !           229:        char name[8];
        !           230:        UINT8* buffer;
        !           231:        int pages;
        !           232:        bool allocated;
        !           233: } ems_handles[MAX_EMS_HANDLES];
        !           234: 
        !           235: struct {
        !           236:        UINT16 handle;
        !           237:        UINT16 page;
        !           238:        bool mapped;
        !           239: } ems_pages[4];
        !           240: 
        !           241: int free_ems_pages;
        !           242: 
        !           243: void ems_init();
        !           244: void ems_finish();
        !           245: void ems_allocate_pages(int handle, int pages);
        !           246: void ems_reallocate_pages(int handle, int pages);
        !           247: void ems_release_pages(int handle);
        !           248: void ems_map_page(int physical, int handle, int logical);
        !           249: void ems_unmap_page(int physical);
        !           250: 
        !           251: // xms
        !           252: 
        !           253: #if defined(HAS_I286) || defined(HAS_I386)
        !           254: #define SUPPORT_XMS
        !           255: #endif
        !           256: 
        !           257: #ifdef SUPPORT_XMS
        !           258: #define MAX_XMS_HANDLES 16
        !           259: #define MAX_XMS_SIZE_KB 0x8000 // 32MB
        !           260: 
        !           261: struct {
        !           262:        int seg;
        !           263:        int size_kb;
        !           264:        int lock;
        !           265:        bool allocated;
        !           266: } xms_handles[MAX_XMS_HANDLES + 1];
        !           267: #endif
        !           268: 
        !           269: // pic
        !           270: 
        !           271: typedef struct {
        !           272:        UINT8 imr, isr, irr, prio;
        !           273:        UINT8 icw1, icw2, icw3, icw4;
        !           274:        UINT8 ocw3;
        !           275:        UINT8 icw2_r, icw3_r, icw4_r;
        !           276: } pic_t;
        !           277: 
        !           278: pic_t pic[2];
        !           279: int pic_req_chip, pic_req_level;
        !           280: UINT8 pic_req_bit;
        !           281: 
        !           282: void pic_init();
        !           283: void pic_write(int c, UINT32 addr, UINT8 data);
        !           284: UINT8 pic_read(int c, UINT32 addr);
        !           285: void pic_req(int c, int level, int signal);
        !           286: int pic_ack();
        !           287: void pic_update();
        !           288: 
        !           289: // pit
        !           290: 
        !           291: #define PIT_ALWAYS_RUNNING
        !           292: 
        !           293: typedef struct {
        !           294:        INT32 count;
        !           295:        UINT16 latch;
        !           296:        UINT16 count_reg;
        !           297:        UINT8 ctrl_reg;
        !           298:        int count_latched;
        !           299:        int low_read, high_read;
        !           300:        int low_write, high_write;
        !           301:        int mode;
        !           302:        int status_latched;
        !           303:        UINT8 status;
        !           304:        // constant clock
        !           305:        UINT32 expired_time;
        !           306:        UINT32 prev_time;
        !           307: } pit_t;
        !           308: 
        !           309: pit_t pit[3];
        !           310: #ifndef PIT_ALWAYS_RUNNING
        !           311: int pit_active;
        !           312: #endif
        !           313: 
        !           314: void pit_init();
        !           315: void pit_write(int ch, UINT8 val);
        !           316: UINT8 pit_read(int ch);
        !           317: int pit_run(int ch, UINT32 cur_time);
        !           318: void pit_latch_count(int ch);
        !           319: int pit_get_expired_time(int ch);
        !           320: 
        !           321: UINT8 system_port = 0;
        !           322: 
        !           323: // cmos
        !           324: 
        !           325: UINT8 cmos[128];
        !           326: UINT8 cmos_addr;
        !           327: 
        !           328: void cmos_init();
        !           329: void cmos_write(int addr, UINT8 val);
        !           330: UINT8 cmos_read(int addr);
        !           331: 
        !           332: // kbd (a20)
        !           333: 
        !           334: UINT8 kbd_data;
        !           335: UINT8 kbd_status;
        !           336: UINT8 kbd_command;
        !           337: 
        !           338: void kbd_init();
        !           339: UINT8 kbd_read_data();
        !           340: void kbd_write_data(UINT8 val);
        !           341: UINT8 kbd_read_status();
        !           342: void kbd_write_command(UINT8 val);
        !           343: 
        !           344: /* ----------------------------------------------------------------------------
1.1       root      345:        MS-DOS virtual machine
                    346: ---------------------------------------------------------------------------- */
                    347: 
                    348: #define VECTOR_TOP     0
                    349: #define VECTOR_SIZE    0x400
                    350: #define BIOS_TOP       (VECTOR_TOP + VECTOR_SIZE)
                    351: #define BIOS_SIZE      0x100
                    352: #define WORK_TOP       (BIOS_TOP + BIOS_SIZE)
1.1.1.14! root      353: #define WORK_SIZE      0x200
        !           354: #define DOS_INFO_TOP   (WORK_TOP + WORK_SIZE)
        !           355: #define DOS_INFO_BASE  (DOS_INFO_TOP + 38)
1.1       root      356: #define DOS_INFO_SIZE  0x100
                    357: #define DPB_TOP                (DOS_INFO_TOP + DOS_INFO_SIZE)
                    358: #define DPB_SIZE       0x400
                    359: #define FILE_TABLE_TOP (DPB_TOP + DPB_SIZE)
                    360: #define FILE_TABLE_SIZE        0x10
1.1.1.14! root      361: #define DISK_BUF_TOP   (FILE_TABLE_TOP + FILE_TABLE_SIZE)
        !           362: #define DISK_BUF_SIZE  0x20
        !           363: #define CDS_TOP                (DISK_BUF_TOP + DISK_BUF_SIZE)
1.1       root      364: #define CDS_SIZE       0x80
                    365: #define FCB_TABLE_TOP  (CDS_TOP + CDS_SIZE)
                    366: #define FCB_TABLE_SIZE 0x10
1.1.1.13  root      367: // nls tables
                    368: #define UPPERTABLE_TOP (FCB_TABLE_TOP + FCB_TABLE_SIZE)
                    369: #define UPPERTABLE_SIZE        0x82
                    370: #define FILENAME_UPPERTABLE_TOP (UPPERTABLE_TOP + UPPERTABLE_SIZE)
                    371: #define FILENAME_UPPERTABLE_SIZE 0x82
                    372: #define FILENAME_TERMINATOR_TOP (FILENAME_UPPERTABLE_TOP + FILENAME_UPPERTABLE_SIZE)
                    373: #define FILENAME_TERMINATOR_SIZE 0x20  /* requirement: 10 + 14(terminate chars) */
                    374: #define COLLATING_TABLE_TOP (FILENAME_TERMINATOR_TOP + FILENAME_TERMINATOR_SIZE)
                    375: #define COLLATING_TABLE_SIZE 0x102
                    376: #define DBCS_TOP       (COLLATING_TABLE_TOP + COLLATING_TABLE_SIZE)
1.1       root      377: #define DBCS_TABLE     (DBCS_TOP + 2)
                    378: #define DBCS_SIZE      0x10
1.1.1.13  root      379: #define MSDOS_SYSTEM_DATA_END (DBCS_TOP + DBCS_SIZE)
                    380: #define MEMORY_TOP     ((MSDOS_SYSTEM_DATA_END + 15) & ~15U)
1.1.1.7   root      381: #define MEMORY_END     0xb8000
                    382: #define TEXT_VRAM_TOP  0xb8000
1.1.1.14! root      383: #define EMS_TOP                0xc0000
        !           384: #define EMS_SIZE       0x10000
        !           385: UINT32 UMB_TOP = EMS_TOP; // EMS is disabled
1.1.1.7   root      386: #define UMB_END                0xf8000
                    387: #define SHADOW_BUF_TOP 0xf8000
1.1.1.14! root      388: #define EMB_TOP                0x10fff0
        !           389: #define EMB_END                MAX_MEM
        !           390: 
        !           391: UINT32 IRET_TOP = 0;
        !           392: #define IRET_SIZE      0x100
        !           393: UINT32 XMS_TOP = 0;
        !           394: #define XMS_OFFSET     0x04
        !           395: #define XMS_SIZE       0x20
1.1       root      396: 
                    397: //#define ENV_SIZE     0x800
                    398: #define ENV_SIZE       0x2000
                    399: #define PSP_SIZE       0x100
                    400: 
                    401: #define MAX_FILES      128
                    402: #define MAX_PROCESS    16
1.1.1.12  root      403: #define MAX_DTAINFO    128
1.1.1.11  root      404: #define LFN_DTA_LADDR  0x10FFF0
1.1.1.12  root      405: #define FIND_MAGIC     0x46696e64
1.1       root      406: 
                    407: #define DUP_STDIN      29
                    408: #define DUP_STDOUT     30
                    409: #define DUP_STDERR     31
                    410: 
                    411: //#define SUPPORT_AUX_PRN
                    412: 
                    413: #pragma pack(1)
                    414: typedef struct {
                    415:        UINT8 mz;
                    416:        UINT16 psp;
1.1.1.14! root      417:        union {
        !           418:                UINT8 reserved[5];
        !           419:                UINT16 paragraphs16;
        !           420:                UINT32 paragraphs32;
        !           421:        };
1.1.1.3   root      422:        char prog_name[8];
1.1.1.14! root      423:        // use 32bit paragraphs for emb
        !           424:        UINT32 paragraphs()
        !           425:        {
        !           426:                UINT32 offset = &(this->mz) - mem;
        !           427:                return (offset >= EMB_TOP) ? paragraphs32 : paragraphs16;
        !           428:        }
        !           429:        UINT32 size_kb()
        !           430:        {
        !           431:                return paragraphs() >> 6;
        !           432:        }
1.1       root      433: } mcb_t;
                    434: #pragma pack()
                    435: 
                    436: #pragma pack(1)
                    437: typedef struct {
                    438:        UINT16 env_seg;
                    439:        PAIR32 cmd_line;
                    440:        PAIR32 fcb1;
                    441:        PAIR32 fcb2;
                    442:        UINT16 sp;
                    443:        UINT16 ss;
                    444:        UINT16 ip;
                    445:        UINT16 cs;
                    446: } param_block_t;
                    447: #pragma pack()
                    448: 
                    449: #pragma pack(1)
                    450: typedef struct {
                    451:        UINT8 len;
                    452:        char cmd[127];
                    453: } cmd_line_t;
                    454: #pragma pack()
                    455: 
                    456: #pragma pack(1)
                    457: typedef struct {
                    458:        UINT8 exit[2];
                    459:        UINT16 first_mcb;
                    460:        UINT8 reserved_1;
                    461:        UINT8 far_call;
                    462:        PAIR32 cpm_entry;
                    463:        PAIR32 int_22h;
                    464:        PAIR32 int_23h;
                    465:        PAIR32 int_24h;
                    466:        UINT16 parent_psp;
                    467:        UINT8 file_table[20];
                    468:        UINT16 env_seg;
                    469:        PAIR32 stack;
1.1.1.12  root      470:        UINT16 file_table_size;
                    471:        PAIR32 file_table_ptr;
                    472:        UINT8 reserved_2[24];
1.1       root      473:        UINT8 service[3];
                    474:        UINT8 reserved_3[2];
                    475:        UINT8 ex_fcb[7];
                    476:        UINT8 fcb1[16];
                    477:        UINT8 fcb2[20];
                    478:        UINT8 buffer[128];
                    479: } psp_t;
                    480: #pragma pack()
                    481: 
                    482: #pragma pack(1)
                    483: typedef struct {
                    484:        UINT16 mz;
                    485:        UINT16 extra_bytes;
                    486:        UINT16 pages;
                    487:        UINT16 relocations;
                    488:        UINT16 header_size;
                    489:        UINT16 min_alloc;
                    490:        UINT16 max_alloc;
                    491:        UINT16 init_ss;
                    492:        UINT16 init_sp;
                    493:        UINT16 check_sum;
                    494:        UINT16 init_ip;
                    495:        UINT16 init_cs;
                    496:        UINT16 relocation_table;
                    497:        UINT16 overlay;
                    498: } exe_header_t;
                    499: #pragma pack()
                    500: 
                    501: #pragma pack(1)
                    502: typedef struct {
                    503:        UINT8 flag;
                    504:        UINT8 reserved[5];
                    505:        UINT8 attribute;
                    506: } ext_fcb_t;
                    507: #pragma pack()
                    508: 
                    509: #pragma pack(1)
                    510: typedef struct {
                    511:        UINT8 drive;
                    512:        UINT8 file_name[8 + 3];
                    513:        UINT16 current_block;
                    514:        UINT16 record_size;
                    515:        UINT32 file_size;
                    516:        UINT16 date;
                    517:        UINT16 time;
1.1.1.12  root      518:        union {
                    519:                UINT8 reserved[8];
                    520:                HANDLE handle;
                    521:        };
1.1       root      522:        UINT8 cur_record;
                    523:        UINT32 rand_record;
                    524: } fcb_t;
                    525: #pragma pack()
                    526: 
                    527: #pragma pack(1)
                    528: typedef struct {
                    529:        UINT8 drive;
                    530:        UINT8 file_name[8 + 3];
                    531:        UINT8 attribute;
                    532:        UINT8 nt_res;
                    533:        UINT8 create_time_ms;
                    534:        UINT16 creation_time;
                    535:        UINT16 creation_date;
                    536:        UINT16 last_access_date;
                    537:        UINT16 cluster_hi;
                    538:        UINT16 last_write_time;
                    539:        UINT16 last_write_date;
                    540:        UINT16 cluster_lo;
                    541:        UINT32 file_size;
                    542: } find_fcb_t;
                    543: #pragma pack()
                    544: 
                    545: #pragma pack(1)
                    546: typedef struct {
1.1.1.12  root      547:        union {
                    548:                UINT8 reserved[21];
                    549:                struct {
                    550:                        UINT32 find_magic;
                    551:                        UINT32 dta_index;
                    552:                };
                    553:        };
1.1       root      554:        UINT8 attrib;
                    555:        UINT16 time;
                    556:        UINT16 date;
                    557:        UINT32 size;
                    558:        char name[13];
                    559: } find_t;
                    560: #pragma pack()
                    561: 
                    562: #pragma pack(1)
                    563: typedef struct {
                    564:        UINT32 attrib;
                    565:        PAIR32 ctime_lo;
                    566:        PAIR32 ctime_hi;
                    567:        PAIR32 atime_lo;
                    568:        PAIR32 atime_hi;
                    569:        PAIR32 mtime_lo;
                    570:        PAIR32 mtime_hi;
                    571:        UINT32 size_hi;
                    572:        UINT32 size_lo;
                    573:        UINT8 reserved[8];
                    574:        char full_name[260];
                    575:        char short_name[14];
                    576: } find_lfn_t;
                    577: #pragma pack()
                    578: 
                    579: #pragma pack(1)
                    580: typedef struct {
                    581:        UINT16 info_level;
                    582:        UINT32 serial_number;
                    583:        char volume_label[11];
                    584:        char file_system[8];
                    585: } drive_info_t;
                    586: #pragma pack()
                    587: 
                    588: #pragma pack(1)
                    589: typedef struct {
                    590:        UINT16 size_of_structure;
                    591:        UINT16 structure_version;
                    592:        UINT32 sectors_per_cluster;
                    593:        UINT32 bytes_per_sector;
                    594:        UINT32 available_clusters_on_drive;
                    595:        UINT32 total_clusters_on_drive;
                    596:        UINT32 available_sectors_on_drive;
                    597:        UINT32 total_sectors_on_drive;
                    598:        UINT32 available_allocation_units;
                    599:        UINT32 total_allocation_units;
                    600:        UINT8 reserved[8];
                    601: } ext_space_info_t;
                    602: #pragma pack()
                    603: 
                    604: #pragma pack(1)
                    605: typedef struct {
                    606:        UINT8 drive_num;
                    607:        UINT8 unit_num;
                    608:        UINT16 bytes_per_sector;
                    609:        UINT8 highest_sector_num;
                    610:        UINT8 shift_count;
                    611:        UINT16 reserved_sectors;
                    612:        UINT8 fat_num;
                    613:        UINT16 root_entries;
                    614:        UINT16 first_data_sector;
                    615:        UINT16 highest_cluster_num;
                    616:        UINT16 sectors_per_fat;
                    617:        UINT16 first_dir_sector;
                    618:        UINT32 device_driver_header;
                    619:        UINT8 media_type;
                    620:        UINT8 drive_accessed;
                    621:        UINT16 next_dpb_ofs;
                    622:        UINT16 next_dpb_seg;
                    623:        UINT16 first_free_cluster;
                    624:        UINT16 free_clusters;
1.1.1.12  root      625:        // extended
                    626:        UINT16 fat_mirroring;
                    627:        UINT16 info_sector;
                    628:        UINT16 backup_boot_sector;
                    629:        UINT32 first_cluster_sector;
                    630:        UINT32 maximum_cluster_num;
                    631:        UINT32 fat_sectors;
                    632:        UINT32 root_cluster;
                    633:        UINT32 free_search_cluster;
1.1       root      634: } dpb_t;
                    635: #pragma pack()
                    636: 
                    637: #pragma pack(1)
                    638: typedef struct {
                    639:        char path_name[67];
                    640:        UINT16 drive_attrib;
                    641:        UINT8 physical_drive_number;
                    642: } cds_t;
                    643: #pragma pack()
                    644: 
                    645: #pragma pack(1)
                    646: typedef struct {
1.1.1.14! root      647:        UINT8 reserved_0[4];    // -38
        !           648:        UINT16 magic_word;      // -34 from DOSBox
        !           649:        UINT8 reserved_1[30];   // -32
1.1       root      650:        UINT16 first_mcb;       // -2
                    651:        PAIR32 first_dpb;       // +0
1.1.1.14! root      652:        PAIR32 first_sft;       // +4
        !           653:        UINT8 reserved_2[8];    // +8
        !           654:        UINT16 max_sector_len;  // +16
        !           655:        PAIR32 disk_buf_info;   // +18 from DOSBox
1.1       root      656:        PAIR32 cds;             // +22
                    657:        PAIR32 fcb_table;       // +26
1.1.1.14! root      658:        UINT8 reserved_3[3];    // +30
1.1       root      659:        UINT8 last_drive;       // +33
1.1.1.14! root      660:        struct {
        !           661:                UINT32 next_driver;     // +34
        !           662:                UINT16 attributes;      // +38
        !           663:                UINT16 strategy;        // +40
        !           664:                UINT16 interrupt;       // +42
        !           665:                char dev_name[8];       // +44
        !           666:        } nul_device;
        !           667:        UINT8 reserved_4[11];   // +52
1.1       root      668:        UINT16 buffers_x;       // +63
                    669:        UINT16 buffers_y;       // +65
                    670:        UINT8 boot_drive;       // +67
                    671:        UINT8 i386_or_later;    // +68
                    672:        UINT16 ext_mem_size;    // +69
1.1.1.14! root      673:        PAIR32 disk_buf_heads;  // +71 from DOSBox
        !           674:        UINT8 reserved_5[21];   // +75
1.1.1.5   root      675:        UINT8 dos_flag;         // +96
1.1       root      676: } dos_info_t;
                    677: #pragma pack()
                    678: 
1.1.1.14! root      679: #pragma pack(1)
        !           680: typedef struct {
        !           681:        UINT16 date_format;
        !           682:        char currency_symbol[5];
        !           683:        char thou_sep[2];
        !           684:        char dec_sep[2];
        !           685:        char date_sep[2];
        !           686:        char time_sep[2];
        !           687:        char currency_format;
        !           688:        char currency_dec_digits;
        !           689:        char time_format;
        !           690:        PAIR32 case_map;
        !           691:        char list_sep[2];
        !           692:        char reserved[10];
        !           693: } country_info_t;
        !           694: #pragma pack()
        !           695: 
1.1       root      696: typedef struct {
                    697:        char path[MAX_PATH];
                    698:        int valid;
                    699:        int id;
                    700:        int atty;
                    701:        int mode;
                    702:        UINT16 info;
                    703:        UINT16 psp;
                    704: } file_handler_t;
                    705: 
                    706: static const struct {
                    707:        int mode;
                    708:        int in;
                    709:        int out;
                    710: } file_mode[] = {
1.1.1.11  root      711:        { _O_RDONLY | _O_BINARY, 1, 0 },
1.1       root      712:        { _O_WRONLY | _O_BINARY, 0, 1 },
                    713:        { _O_RDWR   | _O_BINARY, 1, 1 },
                    714: };
                    715: 
                    716: typedef struct {
                    717:        UINT16 psp;
                    718:        char module_dir[MAX_PATH];
                    719:        PAIR32 dta;
                    720:        UINT8 switchar;
                    721:        UINT8 verify;
                    722:        int max_files;
                    723:        char volume_label[MAX_PATH];
                    724:        bool parent_int_10h_feh_called;
                    725:        bool parent_int_10h_ffh_called;
1.1.1.12  root      726:        UINT16 parent_ds;
1.1.1.14! root      727:        struct {
        !           728:                UINT16 handle;
        !           729:                UINT16 page;
        !           730:                bool mapped;
        !           731:        } ems_pages[4];
        !           732:        bool ems_pages_stored;
1.1       root      733: } process_t;
                    734: 
1.1.1.11  root      735: typedef struct {
                    736:        UINT16 psp;
                    737:        UINT32 dta;
1.1.1.12  root      738:        UINT8 allowable_mask;
                    739:        UINT8 required_mask;
1.1.1.11  root      740:        HANDLE find_handle;
                    741: } dtainfo_t;
                    742: 
1.1.1.8   root      743: UINT8 major_version = 7;
                    744: UINT8 minor_version = 10;
                    745: 
1.1.1.7   root      746: UINT16 first_mcb;
1.1       root      747: UINT16 current_psp;
                    748: 
                    749: int retval = 0;
                    750: UINT16 error_code = 0;
                    751: 
                    752: file_handler_t file_handler[MAX_FILES];
                    753: UINT8 file_buffer[0x100000];
                    754: 
                    755: process_t process[MAX_PROCESS];
1.1.1.11  root      756: dtainfo_t dtalist[MAX_DTAINFO];
1.1       root      757: 
1.1.1.6   root      758: UINT16 malloc_strategy = 0;
                    759: 
1.1.1.12  root      760: char comspec_path[MAX_PATH] = "C:\\COMMAND.COM";
                    761: 
1.1       root      762: void msdos_syscall(unsigned num);
                    763: int msdos_init(int argc, char *argv[], char *envp[], int standard_env);
                    764: void msdos_finish();
                    765: 
                    766: // console
                    767: 
1.1.1.12  root      768: #define SCR_BUF_WIDTH  256
                    769: #define SCR_BUF_HEIGHT 128
1.1       root      770: 
                    771: #define SET_RECT(rect, l, t, r, b) { \
                    772:        rect.Left = l; \
                    773:        rect.Top = t; \
                    774:        rect.Right = r; \
                    775:        rect.Bottom = b; \
                    776: }
                    777: 
                    778: HANDLE hStdin;
                    779: HANDLE hStdout;
1.1.1.12  root      780: CHAR_INFO scr_buf[SCR_BUF_WIDTH * SCR_BUF_HEIGHT];
                    781: char scr_char[SCR_BUF_WIDTH * SCR_BUF_HEIGHT];
                    782: WORD scr_attr[SCR_BUF_WIDTH * SCR_BUF_HEIGHT];
1.1       root      783: COORD scr_buf_size;
                    784: COORD scr_buf_pos;
                    785: int scr_width, scr_height;
1.1.1.12  root      786: int scr_top;
1.1.1.10  root      787: bool restore_console_on_exit = false;
1.1       root      788: bool cursor_moved;
                    789: 
                    790: FIFO *key_buf_char;
                    791: FIFO *key_buf_scan;
1.1.1.7   root      792: int key_input = 0;
1.1.1.4   root      793: UINT32 key_code = 0;
1.1       root      794: 
                    795: int active_code_page;
                    796: int system_code_page;
                    797: 
1.1.1.12  root      798: UINT32 text_vram_top_address;
                    799: UINT32 text_vram_end_address;
                    800: UINT32 shadow_buffer_top_address;
                    801: UINT32 shadow_buffer_end_address;
                    802: int vram_pages;
1.1       root      803: bool int_10h_feh_called = false;
                    804: bool int_10h_ffh_called = false;
                    805: 
                    806: #endif

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.