home *** CD-ROM | disk | FTP | other *** search
- // Copyright 1993, Mark T. Pflaging
- // Interface for a class for handling the LIM EMS version 4.0.
- // Portions borrowed from:
- // "LOTUS(R)/INTEL(R)/MICROSOFT(R)
- // EXPANDED MEMORY SPECIFICATION
- // Version 4.0
- // 300275-005
- // October, 1987"
-
- #ifndef __EMM_HPP
- #define __EMM_HPP
-
- #include "standard.hpp"
- #include <iostream.h>
- #include <stdlib.h>
-
- #define EMM_INT 0x67 // EMM interrupt number
- #define GET_PAGE_FRAME 0x41 // EMM get page frame
- // function number
- #define GET_UNALLOC_PAGE_COUNT 0x42 // EMM get unallocated
- // page count
- // function number
- #define ALLOCATE_PAGES 0x43 // EMM allocate pages
- // function number
- #define MAP_PAGES 0x44 // EMM map pages
- // function number
- #define DEALLOCATE_PAGES 0x45 // EMM deallocate pages
- // function number
- #define DEVICE_NAME_LENGTH 8 // length of a device
- // name string
- #define GET_PHYSICAL_PAGES 0x58 // EMM get mappable physical pages
- // function number
- #define MAP_MULTIPLE_PAGES 0x50 // EMM map multiple pages
- // function number
- #define REALLOCATE_PAGES 0x51 // EMM reallocate pages
- // function number
-
- // Structure used in determining mappable physical pages:
- typedef struct _mappable_phys_page {
- unsigned int phys_page_segment;
- unsigned int phys_page_number;
- } mappable_phys_page;
-
- typedef struct _log_to_phys_map {
- unsigned int log_page_number;
- unsigned int phys_page_number;
- } log_to_phys_map, *log_to_phys_map_ptr;
-
- class LIMEMS {
- static union REGS input_regs, output_regs;
- static struct SREGS segment_regs;
- static int emm_handle;
- static char * page_frame;
- static int pages_needed;
-
- static Boolean emm_installed();
- static Boolean enough_unallocated_pages (int pages_needed);
- static Boolean allocate_expanded_memory_pages (int pages_needed);
- static Boolean reallocate_expanded_memory_pages (int pages_needed);
- static Boolean map_expanded_memory_pages (int physical_page,
- int logical_page);
- static Boolean get_page_frame_address();
- static Boolean deallocate_expanded_memory_pages ();
- static Boolean get_mappable_physical_pages();
- static Boolean map_multiple_pages(log_to_phys_map * mapping, int num_maps);
-
- void Create();
- void MemoryExists(int num_pages) {
- //--------------------------------------------------------//
- // Determine if enough expanded memory pages exist for //
- // application. //
- //--------------------------------------------------------//
- if (!enough_unallocated_pages (num_pages)) {
- cout << "Not enough EMM!" << endl;
- exit(1);
- }
- }
- void Allocate() {
- //--------------------------------------------------------//
- // Allocate expanded memory pages. //
- //--------------------------------------------------------//
- if (!allocate_expanded_memory_pages (pages_needed)) {
- cout << "Could not allocate EMM!" << endl;
- exit(1);
- }
- }
- void ReAllocate() {
- //--------------------------------------------------------//
- // Allocate expanded memory pages. //
- //--------------------------------------------------------//
- if (!reallocate_expanded_memory_pages (pages_needed)) {
- cout << "Could not REallocate EMM!" << endl;
- exit(1);
- }
- }
- void PageFrame() {
- //--------------------------------------------------------//
- // Get expanded memory page frame address. //
- //--------------------------------------------------------//
- if (!get_page_frame_address ()) {
- cout << "Could not get page frame address!" << endl;
- exit(1);
- }
- }
-
- public:
- LIMEMS() { Create(); }
- LIMEMS(int num_pages) {
- Create();
- Init(num_pages);
- }
- void Init(int num_pages) {
- pages_needed = num_pages;
- MemoryExists(pages_needed);
- Allocate();
- PageFrame();
- }
- ~LIMEMS() {
- //--------------------------------------------------------//
- // Return expanded memory pages before exiting. //
- //--------------------------------------------------------//
- if (page_frame) {
- if (!deallocate_expanded_memory_pages()) {
- cout << "Could not deallocate EMM!" << endl;
- exit(1);
- }
- page_frame = NULL;
- }
- }
- void MoreMemory(int num_pages) {
- pages_needed += num_pages;
- MemoryExists(num_pages);
- ReAllocate();
- }
- Boolean isValidYet() {
- // returns True when Allocate has been called.
- return (page_frame ? True : False);
- }
- void Allocate(int num_pages) {
- if (isValidYet()) MoreMemory(num_pages);
- else Init(num_pages);
- }
- void MappablePhysical() {
- // Determine mappable physical pages.
- if (!get_mappable_physical_pages()) {
- cout << "Could not get mappable physical pages!" << endl;
- exit(1);
- }
- }
- void Map(int physical_page, int logical_page) {
- //--------------------------------------------------------//
- // Map in the required pages. //
- //--------------------------------------------------------//
- if (!map_expanded_memory_pages (physical_page, logical_page)) {
- cout << "Could not map EMM!" << endl;
- exit(1);
- }
- }
- char * getPageFrame() { return page_frame; }
- void MapMultiple(log_to_phys_map * mapping, int num_maps) {
- //--------------------------------------------------------//
- // Map in some pages. //
- //--------------------------------------------------------//
- if (!map_multiple_pages(mapping, num_maps)) {
- cout << "Could not multiple map EMM!" << endl;
- exit(1);
- }
- }
- int CurrentlyAllocated() { return pages_needed; }
- };
-
- #endif
-