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

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];
1.1.1.16  root      275: 
                    276: int xms_a20_local_enb_count = 0;
1.1.1.14  root      277: #endif
                    278: 
                    279: // pic
                    280: 
                    281: typedef struct {
                    282:        UINT8 imr, isr, irr, prio;
                    283:        UINT8 icw1, icw2, icw3, icw4;
                    284:        UINT8 ocw3;
                    285:        UINT8 icw2_r, icw3_r, icw4_r;
                    286: } pic_t;
                    287: 
                    288: pic_t pic[2];
                    289: int pic_req_chip, pic_req_level;
                    290: UINT8 pic_req_bit;
                    291: 
                    292: void pic_init();
                    293: void pic_write(int c, UINT32 addr, UINT8 data);
                    294: UINT8 pic_read(int c, UINT32 addr);
                    295: void pic_req(int c, int level, int signal);
                    296: int pic_ack();
                    297: void pic_update();
                    298: 
                    299: // pit
                    300: 
                    301: #define PIT_ALWAYS_RUNNING
                    302: 
                    303: typedef struct {
                    304:        INT32 count;
                    305:        UINT16 latch;
                    306:        UINT16 count_reg;
                    307:        UINT8 ctrl_reg;
                    308:        int count_latched;
                    309:        int low_read, high_read;
                    310:        int low_write, high_write;
                    311:        int mode;
                    312:        int status_latched;
                    313:        UINT8 status;
                    314:        // constant clock
                    315:        UINT32 expired_time;
                    316:        UINT32 prev_time;
1.1.1.17! root      317:        UINT64 accum;
1.1.1.14  root      318: } pit_t;
                    319: 
                    320: pit_t pit[3];
                    321: #ifndef PIT_ALWAYS_RUNNING
                    322: int pit_active;
                    323: #endif
                    324: 
                    325: void pit_init();
                    326: void pit_write(int ch, UINT8 val);
                    327: UINT8 pit_read(int ch);
                    328: int pit_run(int ch, UINT32 cur_time);
                    329: void pit_latch_count(int ch);
                    330: int pit_get_expired_time(int ch);
                    331: 
                    332: UINT8 system_port = 0;
                    333: 
                    334: // cmos
                    335: 
                    336: UINT8 cmos[128];
                    337: UINT8 cmos_addr;
                    338: 
                    339: void cmos_init();
                    340: void cmos_write(int addr, UINT8 val);
                    341: UINT8 cmos_read(int addr);
                    342: 
                    343: // kbd (a20)
                    344: 
                    345: UINT8 kbd_data;
                    346: UINT8 kbd_status;
                    347: UINT8 kbd_command;
                    348: 
                    349: void kbd_init();
                    350: UINT8 kbd_read_data();
                    351: void kbd_write_data(UINT8 val);
                    352: UINT8 kbd_read_status();
                    353: void kbd_write_command(UINT8 val);
                    354: 
                    355: /* ----------------------------------------------------------------------------
1.1       root      356:        MS-DOS virtual machine
                    357: ---------------------------------------------------------------------------- */
                    358: 
                    359: #define VECTOR_TOP     0
                    360: #define VECTOR_SIZE    0x400
                    361: #define BIOS_TOP       (VECTOR_TOP + VECTOR_SIZE)
                    362: #define BIOS_SIZE      0x100
                    363: #define WORK_TOP       (BIOS_TOP + BIOS_SIZE)
1.1.1.14  root      364: #define WORK_SIZE      0x200
                    365: #define DOS_INFO_TOP   (WORK_TOP + WORK_SIZE)
                    366: #define DOS_INFO_BASE  (DOS_INFO_TOP + 38)
1.1       root      367: #define DOS_INFO_SIZE  0x100
                    368: #define DPB_TOP                (DOS_INFO_TOP + DOS_INFO_SIZE)
                    369: #define DPB_SIZE       0x400
1.1.1.16  root      370: #define SFT_TOP                (DPB_TOP + DPB_SIZE)
                    371: #define SFT_SIZE       0x4b0   /* 6 + 0x3b * 20 */
                    372: #define DISK_BUF_TOP   (SFT_TOP + SFT_SIZE)
1.1.1.14  root      373: #define DISK_BUF_SIZE  0x20
                    374: #define CDS_TOP                (DISK_BUF_TOP + DISK_BUF_SIZE)
1.1       root      375: #define CDS_SIZE       0x80
                    376: #define FCB_TABLE_TOP  (CDS_TOP + CDS_SIZE)
                    377: #define FCB_TABLE_SIZE 0x10
1.1.1.17! root      378: #define ERR_TABLE_TOP  (FCB_TABLE_TOP + FCB_TABLE_SIZE)
        !           379: #define ERR_TABLE_SIZE 0x10
1.1.1.13  root      380: // nls tables
1.1.1.17! root      381: #define UPPERTABLE_TOP (ERR_TABLE_TOP + ERR_TABLE_SIZE)
1.1.1.13  root      382: #define UPPERTABLE_SIZE        0x82
                    383: #define FILENAME_UPPERTABLE_TOP (UPPERTABLE_TOP + UPPERTABLE_SIZE)
                    384: #define FILENAME_UPPERTABLE_SIZE 0x82
                    385: #define FILENAME_TERMINATOR_TOP (FILENAME_UPPERTABLE_TOP + FILENAME_UPPERTABLE_SIZE)
                    386: #define FILENAME_TERMINATOR_SIZE 0x20  /* requirement: 10 + 14(terminate chars) */
                    387: #define COLLATING_TABLE_TOP (FILENAME_TERMINATOR_TOP + FILENAME_TERMINATOR_SIZE)
                    388: #define COLLATING_TABLE_SIZE 0x102
                    389: #define DBCS_TOP       (COLLATING_TABLE_TOP + COLLATING_TABLE_SIZE)
1.1       root      390: #define DBCS_TABLE     (DBCS_TOP + 2)
                    391: #define DBCS_SIZE      0x10
1.1.1.13  root      392: #define MSDOS_SYSTEM_DATA_END (DBCS_TOP + DBCS_SIZE)
                    393: #define MEMORY_TOP     ((MSDOS_SYSTEM_DATA_END + 15) & ~15U)
1.1.1.7   root      394: #define MEMORY_END     0xb8000
                    395: #define TEXT_VRAM_TOP  0xb8000
1.1.1.14  root      396: #define EMS_TOP                0xc0000
                    397: #define EMS_SIZE       0x10000
                    398: UINT32 UMB_TOP = EMS_TOP; // EMS is disabled
1.1.1.7   root      399: #define UMB_END                0xf8000
                    400: #define SHADOW_BUF_TOP 0xf8000
1.1.1.14  root      401: #define EMB_TOP                0x10fff0
                    402: #define EMB_END                MAX_MEM
                    403: 
                    404: UINT32 IRET_TOP = 0;
                    405: #define IRET_SIZE      0x100
                    406: UINT32 XMS_TOP = 0;
                    407: #define XMS_OFFSET     0x04
                    408: #define XMS_SIZE       0x20
1.1       root      409: 
                    410: //#define ENV_SIZE     0x800
                    411: #define ENV_SIZE       0x2000
                    412: #define PSP_SIZE       0x100
                    413: 
                    414: #define MAX_FILES      128
                    415: #define MAX_PROCESS    16
1.1.1.12  root      416: #define MAX_DTAINFO    128
1.1.1.11  root      417: #define LFN_DTA_LADDR  0x10FFF0
1.1.1.12  root      418: #define FIND_MAGIC     0x46696e64
1.1       root      419: 
1.1.1.16  root      420: #define DUP_STDIN      27
                    421: #define DUP_STDOUT     28
                    422: #define DUP_STDERR     29
                    423: #define DUP_STDAUX     30
                    424: #define DUP_STDPRN     31
1.1       root      425: 
1.1.1.16  root      426: //#define MAP_AUX_DEVICE_TO_FILE
                    427: //#define MAP_PRN_DEVICE_TO_FILE
1.1       root      428: 
                    429: #pragma pack(1)
                    430: typedef struct {
                    431:        UINT8 mz;
                    432:        UINT16 psp;
1.1.1.14  root      433:        union {
                    434:                UINT8 reserved[5];
                    435:                UINT16 paragraphs16;
                    436:                UINT32 paragraphs32;
                    437:        };
1.1.1.3   root      438:        char prog_name[8];
1.1.1.14  root      439:        // use 32bit paragraphs for emb
                    440:        UINT32 paragraphs()
                    441:        {
                    442:                UINT32 offset = &(this->mz) - mem;
                    443:                return (offset >= EMB_TOP) ? paragraphs32 : paragraphs16;
                    444:        }
                    445:        UINT32 size_kb()
                    446:        {
                    447:                return paragraphs() >> 6;
                    448:        }
1.1       root      449: } mcb_t;
                    450: #pragma pack()
                    451: 
                    452: #pragma pack(1)
                    453: typedef struct {
                    454:        UINT16 env_seg;
                    455:        PAIR32 cmd_line;
                    456:        PAIR32 fcb1;
                    457:        PAIR32 fcb2;
                    458:        UINT16 sp;
                    459:        UINT16 ss;
                    460:        UINT16 ip;
                    461:        UINT16 cs;
                    462: } param_block_t;
                    463: #pragma pack()
                    464: 
                    465: #pragma pack(1)
                    466: typedef struct {
                    467:        UINT8 len;
                    468:        char cmd[127];
                    469: } cmd_line_t;
                    470: #pragma pack()
                    471: 
                    472: #pragma pack(1)
                    473: typedef struct {
                    474:        UINT8 exit[2];
                    475:        UINT16 first_mcb;
                    476:        UINT8 reserved_1;
                    477:        UINT8 far_call;
                    478:        PAIR32 cpm_entry;
                    479:        PAIR32 int_22h;
                    480:        PAIR32 int_23h;
                    481:        PAIR32 int_24h;
                    482:        UINT16 parent_psp;
                    483:        UINT8 file_table[20];
                    484:        UINT16 env_seg;
                    485:        PAIR32 stack;
1.1.1.12  root      486:        UINT16 file_table_size;
                    487:        PAIR32 file_table_ptr;
                    488:        UINT8 reserved_2[24];
1.1       root      489:        UINT8 service[3];
                    490:        UINT8 reserved_3[2];
                    491:        UINT8 ex_fcb[7];
                    492:        UINT8 fcb1[16];
                    493:        UINT8 fcb2[20];
                    494:        UINT8 buffer[128];
                    495: } psp_t;
                    496: #pragma pack()
                    497: 
                    498: #pragma pack(1)
                    499: typedef struct {
                    500:        UINT16 mz;
                    501:        UINT16 extra_bytes;
                    502:        UINT16 pages;
                    503:        UINT16 relocations;
                    504:        UINT16 header_size;
                    505:        UINT16 min_alloc;
                    506:        UINT16 max_alloc;
                    507:        UINT16 init_ss;
                    508:        UINT16 init_sp;
                    509:        UINT16 check_sum;
                    510:        UINT16 init_ip;
                    511:        UINT16 init_cs;
                    512:        UINT16 relocation_table;
                    513:        UINT16 overlay;
                    514: } exe_header_t;
                    515: #pragma pack()
                    516: 
                    517: #pragma pack(1)
                    518: typedef struct {
                    519:        UINT8 flag;
                    520:        UINT8 reserved[5];
                    521:        UINT8 attribute;
                    522: } ext_fcb_t;
                    523: #pragma pack()
                    524: 
                    525: #pragma pack(1)
                    526: typedef struct {
                    527:        UINT8 drive;
                    528:        UINT8 file_name[8 + 3];
                    529:        UINT16 current_block;
                    530:        UINT16 record_size;
                    531:        UINT32 file_size;
                    532:        UINT16 date;
                    533:        UINT16 time;
1.1.1.12  root      534:        union {
                    535:                UINT8 reserved[8];
                    536:                HANDLE handle;
                    537:        };
1.1       root      538:        UINT8 cur_record;
                    539:        UINT32 rand_record;
                    540: } fcb_t;
                    541: #pragma pack()
                    542: 
                    543: #pragma pack(1)
                    544: typedef struct {
                    545:        UINT8 drive;
                    546:        UINT8 file_name[8 + 3];
                    547:        UINT8 attribute;
                    548:        UINT8 nt_res;
                    549:        UINT8 create_time_ms;
                    550:        UINT16 creation_time;
                    551:        UINT16 creation_date;
                    552:        UINT16 last_access_date;
                    553:        UINT16 cluster_hi;
                    554:        UINT16 last_write_time;
                    555:        UINT16 last_write_date;
                    556:        UINT16 cluster_lo;
                    557:        UINT32 file_size;
                    558: } find_fcb_t;
                    559: #pragma pack()
                    560: 
                    561: #pragma pack(1)
                    562: typedef struct {
1.1.1.12  root      563:        union {
                    564:                UINT8 reserved[21];
                    565:                struct {
                    566:                        UINT32 find_magic;
                    567:                        UINT32 dta_index;
                    568:                };
                    569:        };
1.1       root      570:        UINT8 attrib;
                    571:        UINT16 time;
                    572:        UINT16 date;
                    573:        UINT32 size;
                    574:        char name[13];
                    575: } find_t;
                    576: #pragma pack()
                    577: 
                    578: #pragma pack(1)
                    579: typedef struct {
                    580:        UINT32 attrib;
                    581:        PAIR32 ctime_lo;
                    582:        PAIR32 ctime_hi;
                    583:        PAIR32 atime_lo;
                    584:        PAIR32 atime_hi;
                    585:        PAIR32 mtime_lo;
                    586:        PAIR32 mtime_hi;
                    587:        UINT32 size_hi;
                    588:        UINT32 size_lo;
                    589:        UINT8 reserved[8];
                    590:        char full_name[260];
                    591:        char short_name[14];
                    592: } find_lfn_t;
                    593: #pragma pack()
                    594: 
                    595: #pragma pack(1)
                    596: typedef struct {
                    597:        UINT16 info_level;
                    598:        UINT32 serial_number;
                    599:        char volume_label[11];
                    600:        char file_system[8];
                    601: } drive_info_t;
                    602: #pragma pack()
                    603: 
                    604: #pragma pack(1)
                    605: typedef struct {
                    606:        UINT16 size_of_structure;
                    607:        UINT16 structure_version;
                    608:        UINT32 sectors_per_cluster;
                    609:        UINT32 bytes_per_sector;
                    610:        UINT32 available_clusters_on_drive;
                    611:        UINT32 total_clusters_on_drive;
                    612:        UINT32 available_sectors_on_drive;
                    613:        UINT32 total_sectors_on_drive;
                    614:        UINT32 available_allocation_units;
                    615:        UINT32 total_allocation_units;
                    616:        UINT8 reserved[8];
                    617: } ext_space_info_t;
                    618: #pragma pack()
                    619: 
                    620: #pragma pack(1)
                    621: typedef struct {
                    622:        UINT8 drive_num;
                    623:        UINT8 unit_num;
                    624:        UINT16 bytes_per_sector;
                    625:        UINT8 highest_sector_num;
                    626:        UINT8 shift_count;
                    627:        UINT16 reserved_sectors;
                    628:        UINT8 fat_num;
                    629:        UINT16 root_entries;
                    630:        UINT16 first_data_sector;
                    631:        UINT16 highest_cluster_num;
                    632:        UINT16 sectors_per_fat;
                    633:        UINT16 first_dir_sector;
                    634:        UINT32 device_driver_header;
                    635:        UINT8 media_type;
                    636:        UINT8 drive_accessed;
                    637:        UINT16 next_dpb_ofs;
                    638:        UINT16 next_dpb_seg;
                    639:        UINT16 first_free_cluster;
                    640:        UINT16 free_clusters;
1.1.1.12  root      641:        // extended
                    642:        UINT16 fat_mirroring;
                    643:        UINT16 info_sector;
                    644:        UINT16 backup_boot_sector;
                    645:        UINT32 first_cluster_sector;
                    646:        UINT32 maximum_cluster_num;
                    647:        UINT32 fat_sectors;
                    648:        UINT32 root_cluster;
                    649:        UINT32 free_search_cluster;
1.1       root      650: } dpb_t;
                    651: #pragma pack()
                    652: 
                    653: #pragma pack(1)
                    654: typedef struct {
                    655:        char path_name[67];
                    656:        UINT16 drive_attrib;
                    657:        UINT8 physical_drive_number;
                    658: } cds_t;
                    659: #pragma pack()
                    660: 
                    661: #pragma pack(1)
                    662: typedef struct {
1.1.1.14  root      663:        UINT8 reserved_0[4];    // -38
                    664:        UINT16 magic_word;      // -34 from DOSBox
                    665:        UINT8 reserved_1[30];   // -32
1.1       root      666:        UINT16 first_mcb;       // -2
                    667:        PAIR32 first_dpb;       // +0
1.1.1.14  root      668:        PAIR32 first_sft;       // +4
                    669:        UINT8 reserved_2[8];    // +8
                    670:        UINT16 max_sector_len;  // +16
                    671:        PAIR32 disk_buf_info;   // +18 from DOSBox
1.1       root      672:        PAIR32 cds;             // +22
                    673:        PAIR32 fcb_table;       // +26
1.1.1.14  root      674:        UINT8 reserved_3[3];    // +30
1.1       root      675:        UINT8 last_drive;       // +33
1.1.1.14  root      676:        struct {
                    677:                UINT32 next_driver;     // +34
                    678:                UINT16 attributes;      // +38
                    679:                UINT16 strategy;        // +40
                    680:                UINT16 interrupt;       // +42
                    681:                char dev_name[8];       // +44
                    682:        } nul_device;
                    683:        UINT8 reserved_4[11];   // +52
1.1       root      684:        UINT16 buffers_x;       // +63
                    685:        UINT16 buffers_y;       // +65
                    686:        UINT8 boot_drive;       // +67
                    687:        UINT8 i386_or_later;    // +68
                    688:        UINT16 ext_mem_size;    // +69
1.1.1.14  root      689:        PAIR32 disk_buf_heads;  // +71 from DOSBox
                    690:        UINT8 reserved_5[21];   // +75
1.1.1.5   root      691:        UINT8 dos_flag;         // +96
1.1.1.15  root      692:        UINT8 reserved_6[2];    // +97
                    693:        UINT8 umb_linked;       // +99 from DOSBox
                    694:        UINT8 reserved_7[2];    // +100
                    695:        UINT16 first_umb_fcb;   // +102 from DOSBox
                    696:        UINT16 first_mcb_2;     // +104 from DOSBox
1.1       root      697: } dos_info_t;
                    698: #pragma pack()
                    699: 
1.1.1.14  root      700: #pragma pack(1)
                    701: typedef struct {
                    702:        UINT16 date_format;
                    703:        char currency_symbol[5];
                    704:        char thou_sep[2];
                    705:        char dec_sep[2];
                    706:        char date_sep[2];
                    707:        char time_sep[2];
                    708:        char currency_format;
                    709:        char currency_dec_digits;
                    710:        char time_format;
                    711:        PAIR32 case_map;
                    712:        char list_sep[2];
                    713:        char reserved[10];
                    714: } country_info_t;
                    715: #pragma pack()
                    716: 
1.1       root      717: typedef struct {
                    718:        char path[MAX_PATH];
                    719:        int valid;
                    720:        int id;
                    721:        int atty;
                    722:        int mode;
                    723:        UINT16 info;
                    724:        UINT16 psp;
                    725: } file_handler_t;
                    726: 
                    727: static const struct {
                    728:        int mode;
                    729:        int in;
                    730:        int out;
                    731: } file_mode[] = {
1.1.1.11  root      732:        { _O_RDONLY | _O_BINARY, 1, 0 },
1.1       root      733:        { _O_WRONLY | _O_BINARY, 0, 1 },
                    734:        { _O_RDWR   | _O_BINARY, 1, 1 },
                    735: };
                    736: 
                    737: typedef struct {
                    738:        UINT16 psp;
                    739:        char module_dir[MAX_PATH];
                    740:        PAIR32 dta;
                    741:        UINT8 switchar;
                    742:        UINT8 verify;
                    743:        int max_files;
                    744:        char volume_label[MAX_PATH];
                    745:        bool parent_int_10h_feh_called;
                    746:        bool parent_int_10h_ffh_called;
1.1.1.12  root      747:        UINT16 parent_ds;
1.1.1.14  root      748:        struct {
                    749:                UINT16 handle;
                    750:                UINT16 page;
                    751:                bool mapped;
                    752:        } ems_pages[4];
                    753:        bool ems_pages_stored;
1.1       root      754: } process_t;
                    755: 
1.1.1.11  root      756: typedef struct {
                    757:        UINT16 psp;
                    758:        UINT32 dta;
1.1.1.12  root      759:        UINT8 allowable_mask;
                    760:        UINT8 required_mask;
1.1.1.11  root      761:        HANDLE find_handle;
                    762: } dtainfo_t;
                    763: 
1.1.1.8   root      764: UINT8 major_version = 7;
                    765: UINT8 minor_version = 10;
                    766: 
1.1.1.7   root      767: UINT16 first_mcb;
1.1       root      768: UINT16 current_psp;
                    769: 
                    770: int retval = 0;
                    771: UINT16 error_code = 0;
                    772: 
                    773: file_handler_t file_handler[MAX_FILES];
                    774: UINT8 file_buffer[0x100000];
                    775: 
                    776: process_t process[MAX_PROCESS];
1.1.1.11  root      777: dtainfo_t dtalist[MAX_DTAINFO];
1.1       root      778: 
1.1.1.6   root      779: UINT16 malloc_strategy = 0;
                    780: 
1.1.1.12  root      781: char comspec_path[MAX_PATH] = "C:\\COMMAND.COM";
                    782: 
1.1       root      783: void msdos_syscall(unsigned num);
                    784: int msdos_init(int argc, char *argv[], char *envp[], int standard_env);
                    785: void msdos_finish();
                    786: 
                    787: // console
                    788: 
1.1.1.12  root      789: #define SCR_BUF_WIDTH  256
                    790: #define SCR_BUF_HEIGHT 128
1.1       root      791: 
                    792: #define SET_RECT(rect, l, t, r, b) { \
                    793:        rect.Left = l; \
                    794:        rect.Top = t; \
                    795:        rect.Right = r; \
                    796:        rect.Bottom = b; \
                    797: }
                    798: 
                    799: HANDLE hStdin;
                    800: HANDLE hStdout;
1.1.1.12  root      801: CHAR_INFO scr_buf[SCR_BUF_WIDTH * SCR_BUF_HEIGHT];
                    802: char scr_char[SCR_BUF_WIDTH * SCR_BUF_HEIGHT];
                    803: WORD scr_attr[SCR_BUF_WIDTH * SCR_BUF_HEIGHT];
1.1       root      804: COORD scr_buf_size;
                    805: COORD scr_buf_pos;
                    806: int scr_width, scr_height;
1.1.1.12  root      807: int scr_top;
1.1.1.10  root      808: bool restore_console_on_exit = false;
1.1       root      809: bool cursor_moved;
                    810: 
                    811: FIFO *key_buf_char;
                    812: FIFO *key_buf_scan;
1.1.1.7   root      813: int key_input = 0;
1.1.1.4   root      814: UINT32 key_code = 0;
1.1       root      815: 
                    816: int active_code_page;
                    817: int system_code_page;
                    818: 
1.1.1.12  root      819: UINT32 text_vram_top_address;
                    820: UINT32 text_vram_end_address;
                    821: UINT32 shadow_buffer_top_address;
                    822: UINT32 shadow_buffer_end_address;
                    823: int vram_pages;
1.1       root      824: bool int_10h_feh_called = false;
                    825: bool int_10h_ffh_called = false;
                    826: 
                    827: #endif

unix.superglobalmegacorp.com

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