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

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

unix.superglobalmegacorp.com

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