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

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

unix.superglobalmegacorp.com

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