initial commit
[dosdemo] / src / dos / dpmi.c
1 /*
2 colcycle - color cycling image viewer
3 Copyright (C) 2016  John Tsiombikas <nuclear@member.fsf.org>
4
5 This program is free software: you can redistribute it and/or modify
6 it under the terms of the GNU General Public License as published by
7 the Free Software Foundation, either version 3 of the License, or
8 (at your option) any later version.
9
10 This program is distributed in the hope that it will be useful,
11 but WITHOUT ANY WARRANTY; without even the implied warranty of
12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
13 GNU General Public License for more details.
14
15 You should have received a copy of the GNU General Public License
16 along with this program.  If not, see <http://www.gnu.org/licenses/>.
17 */
18 #include "dpmi.h"
19
20 void dpmi_real_int(int inum, struct dpmi_real_regs *regs)
21 {
22         unsigned char int_num = (unsigned char)inum;
23         __asm {
24                 mov eax, 0x300
25                 mov edi, regs
26                 mov bl, int_num
27                 mov bh, 0
28                 xor ecx, ecx
29                 int 0x31
30         }
31 }
32
33 void *dpmi_mmap(uint32_t phys_addr, unsigned int size)
34 {
35         uint16_t mem_high, mem_low;
36         uint16_t phys_high = phys_addr >> 16;
37         uint16_t phys_low = phys_addr & 0xffff;
38         uint16_t size_high = size >> 16;
39         uint16_t size_low = size & 0xffff;
40         unsigned int err, res = 0;
41
42         __asm {
43                 mov eax, 0x800
44                 mov bx, phys_high
45                 mov cx, phys_low
46                 mov si, size_high
47                 mov di, size_low
48                 int 0x31
49                 add res, 1
50                 mov err, eax
51                 mov mem_high, bx
52                 mov mem_low, cx
53         }
54
55         if(res == 2) {
56                 return 0;
57         }
58         return (void*)(((uint32_t)mem_high << 16) | ((uint32_t)mem_low));
59 }
60
61 void dpmi_munmap(void *addr)
62 {
63         uint16_t mem_high = (uint32_t)addr >> 16;
64         uint16_t mem_low = (uint16_t)addr;
65
66         __asm {
67                 mov eax, 0x801
68                 mov bx, mem_high
69                 mov cx, mem_low
70                 int 0x31
71         }
72 }