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

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

unix.superglobalmegacorp.com

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