]> 4ch.mooo.com Git - 16.git/blob - src/lib/doslib/dos/ddpmidos.c
added a bunch of things~ and midi stuff~
[16.git] / src / lib / doslib / dos / ddpmidos.c
1 /* dos.c
2  *
3  * Code to detect the surrounding DOS/Windows environment and support routines to work with it
4  * (C) 2009-2012 Jonathan Campbell.
5  * Hackipedia DOS library.
6  *
7  * This code is licensed under the LGPL.
8  * <insert LGPL legal text here>
9  */
10
11 #ifdef TARGET_WINDOWS
12 # include <windows.h>
13 #endif
14
15 #include <stdio.h>
16 #include <conio.h> /* this is where Open Watcom hides the outp() etc. functions */
17 #include <stdlib.h>
18 #include <string.h>
19 #include <stddef.h>
20 #include <unistd.h>
21 #include <malloc.h>
22 #include <assert.h>
23 #include <fcntl.h>
24 #include <dos.h>
25
26 #include <hw/cpu/cpu.h>
27 #include <hw/dos/dos.h>
28 #include <hw/dos/doswin.h>
29 #include <hw/dos/dosntvdm.h>
30
31 #if TARGET_MSDOS == 32
32 void *dpmi_alloc_dos(unsigned long len,uint16_t *selector) {
33         unsigned short rm=0,pm=0,fail=0;
34
35         /* convert len to paragraphs */
36         len = (len + 15) >> 4UL;
37         if (len >= 0xFF00UL) return NULL;
38
39         __asm {
40                 mov     bx,WORD PTR len
41                 mov     ax,0x100
42                 int     0x31
43
44                 mov     rm,ax
45                 mov     pm,dx
46                 sbb     ax,ax
47                 mov     fail,ax
48         }
49
50         if (fail) return NULL;
51
52         *selector = pm;
53         return (void*)((unsigned long)rm << 4UL);
54 }
55
56 void dpmi_free_dos(uint16_t selector) {
57         __asm {
58                 mov     ax,0x101
59                 mov     dx,selector
60                 int     0x31
61         }
62 }
63 #endif
64