source: abuse/tags/pd/imlib/port/dos4gw/vesatest.c @ 49

Last change on this file since 49 was 49, checked in by Sam Hocevar, 11 years ago
  • Imported original public domain release, for future reference.
  • Property svn:keywords set to Id
File size: 1.3 KB
Line 
1#include "doscall.hpp"
2#include <stdlib.h>
3#include <i86.h>
4#include <string.hpp>
5
6
7void RM_intr(int intr, struct rminfo *rm)      // do a real-mode interrupt
8{
9  union REGS regs;
10  struct SREGS sregs;
11  memset(&sregs,0,sizeof(sregs));
12  regs.w.ax=0x0300;
13  regs.w.bx=intr;
14  regs.w.cx=0;
15  sregs.es=FP_SEG(rm);
16  regs.x.edi=FP_OFF(rm);
17  int386x(0x31,&regs,&regs,&sregs); 
18} ;
19
20void *alloc_low_memory(long size)            // size in bytes
21{
22  rminfo rm;
23  memset(&rm,0,sizeof(rm));
24  rm.eax=0x4800;
25  rm.ebx=(size+15)/16;
26  RM_intr(0x21,&rm);
27  if (rm.flags&1)
28    return NULL;
29  else return (void *)((rm.eax&0xffff)<<4);
30}
31
32void free_low_memory(void *ptr)
33{
34  rminfo rm;
35  memset(&rm,0,sizeof(rm));
36  rm.eax=0x4900;
37  rm.es=((unsigned long)ptr)>>4;
38  RM_intr(0x21,&rm);
39  if (rm.flags&1)
40  {
41    printf("Error while freeing low memory block\n");
42    exit(0);
43  }
44}
45
46long low_memory_available()
47{
48  rminfo rm;
49  memset(&rm,0,sizeof(rm));
50  rm.eax=0x4800;
51  rm.ebx=0xffff;        // try to allocate the maximum size, dos while tells us how much is possible
52  RM_intr(0x21,&rm);
53  if (rm.flags&1) 
54    return rm.ebx*16;
55  else                  // this shouldn't succed, but just in case...
56  {
57    free_low_memory((void *)((rm.eax&0xffff)<<4));
58    return 0xffff*16;
59  }
60}
61
62
63
64
65
66
67
Note: See TracBrowser for help on using the repository browser.