DOS中使用扩展内存与XMS操作库设计
作者:彭学周(Favory.Peng)
- {uxms.pas}
- {
- DOS XMS library is a DOS real mode and large memory model Pascal library.
- Because DOS is ran under real mode, programmer only can access RAM under 1MB.
- The memory user can use are 640 KB, Other 384 KB are reserved for ROM BIOS and other cards.
- XMS library provides DOS programmer a easy way to access RAM above 1 MB under DOS via XMS driver.
- For MS-DOS, add "DOS=HIGH" to you CONFIG.SYS will force MS-DOS to active XMS driver.
- ================================================================================
- 3F Medical Pascal XMS Library.
- Copyright (C) 2008 by Favory.Peng.
- This library is for 3F Medical product user only.
- }
- unit UXMS;
- interface
- uses DOS,CRT;
- type
- XMMS = record
- byte_count:LongInt; {bytes count}
- source_handle:word; {source handle}
- source_offset:Pointer;{source offset}
- dest_handle:word; {destination handle}
- dest_offset:Pointer; {destination offset}
- end;
- pXMMS = ^XMMS;
- pByte = ^Byte;
- pWord = ^Word;
- var
- XMS:Boolean;
- xms_func:LongInt;
- max_block,total_block:word;
- trans:XMMS;
- function XMS_Init:Boolean;
- function XMS_Allocate(len:word):word;
- function XMS_Free(handle:word):Boolean;
- function XMS_GetVer:word;
- function XMS_GetFree:Boolean;
- function XMS_Lock(handle:word):Boolean;
- function XMS_ULock(handle:word):Boolean;
- function XMS_Copy(PT:pXMMS):Boolean;
- function XMS_CopyToXMS(DstHandle:word;lDstOffset:Pointer;pSrc:Pointer;lLen:LongInt):Boolean;
- function XMS_CopyFromXMS(pDst:Pointer;SrcHandle:word;lSrcOffset:Pointer;lLen:LongInt):Boolean;
- implementation
- {Initialize XMS driver and get control function address}
- function XMS_Init:Boolean;
- var
- is_exist:byte;
- seg1,off1:word;
- ptr_xms_func:^word;
- begin
- asm
- mov ax,4300h
- int 2fh
- mov is_exist,al
- end;
- if is_exist<>$80 then
- begin
- XMS_Init:=False;
- end else
- begin
- asm
- mov ax,4310h
- Int 2fh
- mov seg1,ES
- mov off1,BX
- end;
- ptr_xms_func:=@xms_func;
- ptr_xms_func^:=off1;
- inc(ptr_xms_func);
- ptr_xms_func^:=seg1;
- XMS_Init:=True;
- end;
- end;
- {Allocate XMS memory}
- function XMS_Allocate(len:word):word;
- var
- result,handle:word;
- begin
- asm
- mov dx,len
- mov ah,9
- call xms_func
- mov result,ax
- mov handle,dx
- end;
- if result=0 then
- XMS_Allocate:=0
- else
- XMS_Allocate:=handle;
- end;
- {Free allocated XMS memory}
- function XMS_Free(handle:word):Boolean;
- var
- result:word;
- begin
- asm
- mov dx,handle
- mov ah,10
- call xms_func
- mov result,ax
- end;
- if result=0 then
- XMS_Free:=False
- else
- XMS_Free:=True;
- end;
- {Get XMS driver version}
- function XMS_GetVer:word;
- var
- version:word;
- begin
- asm
- mov ah,0
- call xms_func
- mov version,ax
- end;
- XMS_GetVer:=version;
- end;
- {Query free memory and maximum available space}
- function XMS_GetFree:Boolean;
- var
- error_code:byte;
- begin
- error_code:=$ff;
- if XMS then
- begin
- asm
- mov ah,8
- call xms_func
- mov max_block,ax
- mov total_block,dx
- mov error_code,bl
- end;
- end;
- if error_code=$ff then
- XMS_GetFree:=False
- else
- XMS_GetFree:=True;
- end;
- {Lock Block}
- function XMS_Lock(handle:word):Boolean;
- var
- result:word;
- begin
- if XMS then
- begin
- asm
- mov ah,0ch
- mov dx,handle
- call xms_func
- mov result,ax
- end;
- end;
- if result=0 then
- XMS_Lock:=false
- else
- XMS_Lock:=True;
- end;
- {UNLock Block}
- function XMS_ULock(handle:word):Boolean;
- var
- result:word;
- begin
- if XMS then
- begin
- asm
- mov ah,0dh
- mov dx,handle
- call xms_func
- mov result,ax
- end;
- end;
- if result=0 then
- XMS_ULock:=False
- else
- XMS_ULock:=True;
- end;
- {Copy XMS memory}
- function XMS_Copy(PT:pXMMS):Boolean;
- var
- xoff,result:word;
- begin
- result:=$ff;
- if XMS then
- begin
- xoff:=Ofs(PT^);
- asm
- mov ah,0bh
- mov si,xoff
- call xms_func
- mov result,ax
- end;
- end;
- if result=0 then
- begin
- XMS_Copy:=False;
- end else
- begin
- XMS_Copy:=True;
- end;
- end;
- {Copy memory buffer to XMS}
- function XMS_CopyToXMS(DstHandle:word;lDstOffset:Pointer;pSrc:Pointer;lLen:LongInt):Boolean;
- begin
- trans.byte_count:=llen;
- trans.source_handle:=0;
- trans.source_offset:=pByte(pSrc);
- trans.dest_handle:=DstHandle;
- trans.dest_offset:=lDstOffset;
- XMS_CopyToXMS:=XMS_Copy(@trans);
- end;
- {Copy XMS to memory buffer}
- function XMS_CopyFromXMS(pDst:Pointer;SrcHandle:word;lSrcOffset:Pointer;lLen:LongInt):Boolean;
- begin
- trans.byte_count:=llen;
- trans.source_handle:=SrcHandle;
- trans.source_offset:=lSrcOffset;
- trans.dest_handle:=0;
- trans.dest_offset:=pByte(pDst);
- XMS_CopyFromXMS:=XMS_Copy(@trans);
- end;
- {init_unit}
- begin
- XMS:=XMS_Init;
- XMS_GetFree;
- end.
- {UXMSTEST.pas}
- {
- XMS example for XMS library, copyright (C) 2008 by Favory.Peng,
- This example will show you how to XMS library.
- }
- program uxmstest;
- uses dos,crt,uxms;
- var
- szStr:array[0..99] of Byte;
- i,xms_handle:word;
- nStrLen:LongInt;
- {main}
- begin
- clrscr;
- for i:=0 to 99 do
- begin
- szStr[i]:=i;
- end;
- nStrLen:=100;
- if XMS_GetFree then writeln('Free memory: Max=',max_block,' KB, total=',total_block,' KB.');
- xms_handle:=XMS_Allocate(1);
- if xms_handle=0 then
- writeln('Allocate failed!')
- else begin
- writeln('Allocate 1KB memory: Handle=',xms_handle);
- end;
- if XMS_GetFree then writeln('Free memory: Max=',max_block,' KB, total=',total_block,' KB.');
- if XMS then writeln('XMS Version: ',XMS_GetVer);
- writeln('--------------------------------------------------------------------------');
- for i:=0 to 99 do
- begin
- write(szStr[i],',');
- end;
- writeln;
- writeln('1. Copy buffer to XMS..... buffer size=',nStrLen);
- XMS_CopyToXMS(xms_handle,Pointer(0),@szStr,nStrLen);
- writeln('2. Reset buffer....');
- for i:=0 to 99 do
- begin
- szStr[i]:=0;
- write(szStr[i],',');
- end;
- writeln;
- XMS_CopyFromXMS(@szStr,xms_handle,Pointer(0),nStrLen);
- writeln('3. Restore buffer....');
- for i:=0 to 99 do
- begin
- write(szStr[i],',');
- end;
- writeln;
- writeln('--------------------------------------------------------------------------');
- XMS_Free(xms_handle);
- if XMS_GetFree then writeln('Free memory: Max=',max_block,' KB, total=',total_block,' KB.');
- readkey;
- end.
XMS操作单元UXMS.PAS:
UXMS使用实例执行结果:
本文到此结束!
DOS中使用扩展内存与XMS操作库设计相关推荐
- java知识点8——垃圾回收原理和算法、通用的分代垃圾回收机制、 JVM调优和Full GC、开发中容易造成内存泄露的操作
垃圾回收原理和算法 内存管理 Java的内存管理很大程度指的就是对象的管理,其中包括对象空间的分配和释放. 对象空间的分配:使用new关键字创建对象即可 对象空间的释放:将对象赋值null即可 垃圾回 ...
- ORM映射框架总结--数据库操作库(精修版)
1. ORM数据库操作原理 前面已经介绍过了个人ORM映射框架中的三个核心库: 实体-数据库 映射特性关系: http://www.cnblogs.com/qingyuan/archive ...
- 什么是堆栈?内存中划分出按FIL0方式操作的特殊区域,叫做堆栈
内存中划分出按FIL0方式操作的特殊区域,叫做堆栈 有两个操作,分为压栈,出栈 每次压栈和出栈以字为单位. SS存放段基值,SP存放栈顶单元偏移量 SS:SP构成堆栈指针 物理地址SSx16+SP 常 ...
- 错误内存【读书笔记】C程序中常见的内存操作有关的典型编程错误
题记:写这篇博客要主是加深自己对错误内存的认识和总结实现算法时的一些验经和训教,如果有错误请指出,万分感谢. 对C/C++程序员来讲,内存管理是个不小的挑战,绝对值得慎之又慎,否则让由上万行代码构成的 ...
- c语言中指针往内存写值,C语言编程常见问题解答之指针和内存分配
指针为C语言编程提供了强大的支持--如果你能正确而灵活地利用指针,你就可以直接切入问题的核心,或者将程序分割成一个个片断.一个很好地利用了指针的程序会非常高效.简洁和精致. 利用指针你可以将数据写入内 ...
- 追踪JVM中的本地内存
点击蓝色"程序猿DD"关注我 回复"资源"获取独家整理的学习资料! 转载自公众号:锅外的大佬 1.概述 有没有想过为什么Java应用程序通过众所周知的-Xms和 ...
- group by 和 left join 哪个慢_手机自带内存和扩展内存一样吗?哪个更好?
前个月,无意中看到某手机的营销文案,运存4GB,总内存可达256GB.明眼人自然可以看到,这不过是通过TF卡扩展内存得到总256GB.因为还没有见过那个机器用4+256的组合的,常见都是4+32,4+ ...
- 使用jemalloc在Go中进行手动内存管理
目录 通过Cgo创建内存 jemalloc 在字节片上放置Go结构 用分配器摊销Calloc的成本 明智地参考 处理分配的GB 排序可变长度数据 捕捉内存泄漏 结论 推荐阅读 曼尼斯·赖·贾 因(Ma ...
- JVM中的本地内存追踪NMT(Native Memory Tracking)
JVM中的本地内存追踪NMT(Native Memory Tracking) 1 概述 每当想起为什么Java应用程序会消耗比设置-Xms和-Xmx多的内存的时候,心中总是会有个问号.因为一些理由和优 ...
最新文章
- watchOS 5 新特性:继续发力运动与健身
- python判断最后一行_python中如何判断文件的最后一行是空行?
- PlSql加入数据库链接
- 解释java程序中的异常机制_Java编程中的异常机制
- 東方 project 联机版开发日记(1)
- mediamind SyncAds
- 关于Jbulder2006的问题
- Spark DataFrameRDD案例实现
- win10命令行查看显卡驱动版本_Win10更新显卡驱动提示尝试重启GeForce Experience的解决方法...
- 安徽大学计算机基础知识答案,安徽大学大学计算机基础选择题
- 【Android系统源码修改】去掉开机时显示的正在优化应用对话框
- pwm占空比的c语言编程详解,灵动微MM32F003硬件最小系统 --- PWM占空比从0%到100%例程解析【18】...
- Python笔记之Django网页模板的继承block(挖坑填坑、HTML转义)
- Fast-Paced Multiplayer (Part I): Introduction
- 【Altium Designer 19使用教程】Part1 工程及原理图的创建
- MySQL数据库的主从同步和读写分离
- 手机Camera理论
- Macbook 开机黑屏
- SpringBoot利用ZXing工具来生成二维码(简单)
- 使用dnsmasq在本地将域名解析为CNAME别名
热门文章
- 什么是内存颗粒?内存条的构成!
- 安装java进度条不动了_提示安装过程出错怎么处理啊?安装offi – 手机爱问
- flag{e2f34a3a-9972-4ba5-bdeb-ff7d524d87cb} preg_match implode
- Datawhale 计算机视觉基础-图像处理(上)-Task01 OpenCV框架与图像插值算法
- iOS从相册选择图片并裁剪,可用于上传头像
- 微信小程序(uni-app)
- Android隐藏软件盘
- Arduino实现超声波测距
- 网络安全-靶机dvwa之sql注入Low到High详解(含代码分析)
- 常见的WebShell管理工具