免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2570 | 回复: 7
打印 上一主题 下一主题

关于DOS下扩展内存的使用(涉及WIN2000) [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2003-02-15 10:41 |只看该作者 |倒序浏览
我现在由于工作需要,编写一个将运行于DOS上的通讯程序,期间要把收到的数据作为坐标画在屏幕上并不断更新显示。由于需要重画的区域太大,所以使用缓冲方式来实现动画。由此需要使用到扩展内存甚至扩充内存。
   我遇到的问题是,工作电脑上装的是WIN2000,找半天没找到DOS下的两个内存管理程序himem .sys和 emm386 .exe, XMS和EMS都需要对这两个程序设置后才能使用,怎办?
    如若不然,有什么办法能在WIN2000下继续写我的程序吗?请知道的朋友不吝赐教,小妹万分感激!

论坛徽章:
0
2 [报告]
发表于 2003-02-15 17:08 |只看该作者

关于DOS下扩展内存的使用(涉及WIN2000)

你自己先试看能不能运行

一般如果是使用TC的话
还要设置内存模式为large模式

论坛徽章:
0
3 [报告]
发表于 2003-02-15 17:10 |只看该作者

关于DOS下扩展内存的使用(涉及WIN2000)

我以前做过相似的一个项目
使用TC开发
也是在dos下写屏幕
刷新时要先保留旧屏幕的内容
然后再把它画回去

开始时写整个屏幕是不成功
(内存不够)
后来把屏幕分成几块
每次一块一块画
成功了

论坛徽章:
0
4 [报告]
发表于 2003-02-15 19:23 |只看该作者

关于DOS下扩展内存的使用(涉及WIN2000)

分辨率多少?颜色多少bit?

用 watcom c++ 比较简单,他在dos下提供保护模式的大量内存。
免去自己管理内存的麻烦。

himem.sys windowsXP在 c:\windows\system32这个目录下。
估计2000也一样。emm386.exe没有。其实这两个用一个就可以了。

论坛徽章:
0
5 [报告]
发表于 2003-02-16 15:17 |只看该作者

关于DOS下扩展内存的使用(涉及WIN2000)

  1. 遥远的年代编的程序,不知道是否有帮助。

  2. /* ems.h

  3. Definitions for EMS input/output.

  4. Meng Wenguang 1993-1994
  5. */
  6. #include <dos.h>;
  7. #include <stdio.h>;
  8. #include <stdlib.h>;
  9. #include <graph.h>;
  10. #include <conio.h>;
  11. typedef struct {
  12. unsigned int handle;
  13. int pagenum;
  14. long int size;
  15. int firstphypage;
  16. int firstlogpage;
  17. long int address;
  18. long int mapaddress;
  19. unsigned char far *base;
  20. long int top;
  21. int activenum;
  22. int active;
  23. } EMSFILE;


  24. struct EMSinfo{
  25. unsigned char far *BASE;
  26. int MAXPAGENUM;
  27. int RESTNUM;
  28. int EXIST;
  29. int PAGENUM;
  30. int TURN[4];
  31. EMSFILE * FILE[4];
  32. int PAGEUSED[4];
  33. } extern EMS;

  34. EMSFILE * EMSopen(long int size);
  35. void EMSclose(EMSFILE *stream);

  36. void EMSactive(EMSFILE *stream);
  37. void EMSdeactive(EMSFILE *stream);

  38. void EMSlocation(EMSFILE *stream);
  39. long int EMStell(EMSFILE *stream);
  40. void EMSseek(EMSFILE *stream,long address,int way);

  41. void EMSread(unsigned char *buffer,unsigned int size,int num,EMSFILE *stream);
  42. void EMSwrite(unsigned char *buffer,unsigned int size,int num,EMSFILE *stream);

  43. unsigned char EMSgetc(EMSFILE *stream);
  44. void EMSputc(unsigned char a,EMSFILE *stream);

  45. EMSFILE * putfiletoEMS(char *name);
  46. void saveEMSfile(EMSFILE *EMSfp,char *name);

  47. EMSFILE * qputfiletoEMS(char *name);
  48. void qsaveEMSfile(EMSFILE *EMSfp,char *name);

  49. unsigned int EMSalloc(int);
  50. void EMSshell(void);
  51. void EMSexit(unsigned int handle);
  52. int EMSini(void);
  53. void EMSmap(unsigned int handle,int phys,int page);


  54. EMSFILE * EMSopen(long int size)
  55. {
  56. int i;
  57. EMSFILE *EMSfp;
  58. if(!EMS.EXIST) return NULL;
  59. i=(int) ((size+16383)/16384);
  60. if(i>;EMS.RESTNUM) {
  61. puts(" No enough Expanded memory detected !\n");
  62. puts(" System halted !\n");
  63. exit(0);
  64. return NULL;
  65. };
  66. EMSfp=(EMSFILE *)malloc(sizeof(EMSFILE));

  67. EMSfp->;handle=EMSalloc(i);
  68. EMSfp->;pagenum=i;
  69. EMSfp->;size=size;
  70. EMSfp->;firstlogpage=0;
  71. EMSfp->;address=0;
  72. EMSfp->;mapaddress=0;
  73. EMSfp->;active=0;
  74. EMSfp->;top=0;

  75. EMS.RESTNUM-=i;

  76. return EMSfp;
  77. }

  78. void EMSlocation(EMSFILE *stream)
  79. {
  80. int i;
  81. stream->;firstlogpage=(int)(stream->;mapaddress/stream->;top)*stream->;activenum;
  82. if(stream->;firstlogpage+stream->;activenum>;stream->;pagenum)
  83. stream->;firstlogpage=stream->;pagenum-stream->;activenum;
  84. stream->;address=(unsigned int)(stream->;mapaddress-stream->;firstlogpage*16384);
  85. for(i=0;i<stream->;activenum;i++)
  86. EMSmap(stream->;handle,stream->;firstphypage+i,stream->;firstlogpage+i);
  87. }


  88. void EMSactive(EMSFILE *stream)
  89. {
  90. int i,j,k;
  91. if(stream->;active==1) return;
  92. for(i=0;i<4;i++) if(EMS.PAGEUSED==0) break;
  93. if(i<4){

  94. k=i;

  95. j=0;

  96. while((EMS.PAGEUSED[k]==0)&&(k<4)){ j++;k++;};
  97. if(j>;stream->;pagenum) j=stream->;pagenum;

  98. stream->;activenum=j;
  99. stream->;top=0;
  100. for(k=0;k<j;k++) stream->;top+=16384;
  101. stream->;base=EMS.BASE+i*16384;
  102. stream->;firstphypage=i;

  103. EMSlocation(stream);

  104. for(k=0;k<j;k++){
  105. EMS.TURN[EMS.PAGENUM]=i+k;
  106. EMS.PAGENUM++;
  107. EMS.PAGEUSED[i+k]=1;
  108. EMS.FILE[i+k]=stream;
  109. };

  110. }
  111. else{
  112. for(i=4;i>;0;i--) if(EMS.FILE->;handle==EMS.FILE[i-1]->;handle) break;
  113. if(i>;0){
  114. for(j=i;j<3;j++) EMS.TURN[j]=EMS.TURN[j+1];
  115. EMS.TURN[3]=i;

  116. EMS.FILE->;top-=16384;
  117. EMS.FILE->;activenum--;

  118. EMSlocation(EMS.FILE);

  119. stream->;firstphypage=i;
  120. stream->;activenum=1;
  121. stream->;base=EMS.BASE+i*16384;
  122. stream->;top=16384;
  123. EMSlocation(stream);
  124. EMS.FILE=stream;
  125. }
  126. else{
  127. i=EMS.TURN[0];

  128. EMS.FILE->;top=0;
  129. EMS.FILE->;active=0;
  130. EMS.FILE->;activenum--;

  131. stream->;base=EMS.BASE+i*16384;
  132. stream->;firstphypage=i;
  133. stream->;top=16384;
  134. stream->;activenum=1;
  135. EMSlocation(stream);

  136. EMS.FILE=stream;
  137. for(j=0;j<3;j++) EMS.TURN[j]=EMS.TURN[j+1];
  138. EMS.TURN[3]=i;
  139. };
  140. };
  141. stream->;active=1;
  142. }

  143. void EMSshell(void)
  144. {
  145. // int i;
  146. // for(i=4;i>;0;i--)
  147. // if(EMS.PAGEUSED==1)
  148. // {
  149. // EMS.FILE->;active=0;
  150. // EMS.PAGEUSED=0;
  151. // };

  152. }

  153. void EMSdeactive(EMSFILE *stream)
  154. {
  155. int i,j,k;
  156. for(i=0;i<stream->;activenum;i++){
  157. for(j=0;j<4;j++) if(EMS.TURN[j]==(i+stream->;firstphypage)) break;
  158. for(k=j;k<3;k++) EMS.TURN[k]=EMS.TURN[k+1];
  159. EMS.PAGEUSED[stream->;firstphypage+i]=0;
  160. EMS.PAGENUM--;
  161. };
  162. }

  163. void EMSclose(EMSFILE *stream)
  164. {
  165. union REGS regs;
  166. if(stream->;active) EMSdeactive(stream);
  167. regs.h.ah=0x45;
  168. regs.x.dx=stream->;handle;
  169. int86(0x67 ,&reg;s,&reg;s);
  170. EMS.RESTNUM+=stream->;pagenum;
  171. free(stream);
  172. }


  173. void EMSread(unsigned char *buffer,unsigned int size,int num, EMSFILE *stream)
  174. {
  175. unsigned char far *source;
  176. unsigned int j;
  177. size*=num;
  178. if(!stream->;active) EMSactive(stream);
  179. source=stream->;base+(unsigned int)stream->;address;
  180. if(stream->;address<(stream->;top-size)){
  181. stream->;mapaddress+=size;
  182. stream->;address+=size;
  183. while(size-->;0) *buffer++=*source++;
  184. return;
  185. }
  186. else{
  187. j=(unsigned int)(stream->;top-stream->;address);
  188. stream->;mapaddress+=j;
  189. size-=j;
  190. while(j-->;0) *buffer++= *source++;
  191. while(size>;=stream->;top){
  192. EMSseek(stream,stream->;mapaddress,0);
  193. j=stream->;top;
  194. stream->;mapaddress+=j;
  195. size-=j;
  196. source=stream->;base+(unsigned int)stream->;address;
  197. while(j-->;0) *buffer++= *source++;
  198. };
  199. EMSseek(stream,stream->;mapaddress,0);
  200. j=size;
  201. stream->;mapaddress+=j;
  202. source=stream->;base+(unsigned int)stream->;address;
  203. stream->;address+=j;
  204. // source-=j;
  205. while(j-->;0) *buffer++= *source++;
  206. }
  207. }
  208. void EMSwrite(unsigned char *buffer,unsigned int size,int num,EMSFILE *stream)
  209. {
  210. unsigned char far *targe;
  211. unsigned int j;
  212. size*=num;
  213. if(!stream->;active) EMSactive(stream);
  214. targe=stream->;base+(unsigned int)stream->;address;
  215. if(stream->;address<=(stream->;top-size)){
  216. stream->;address+=size;
  217. stream->;mapaddress+=size;
  218. while(size-->;0) *targe++=*buffer++;
  219. return;
  220. }
  221. else{
  222. j=(unsigned int) (stream->;top-stream->;address);
  223. stream->;mapaddress+=j;
  224. size-=j;
  225. while(j-->;0) *targe++=*buffer++;

  226. while(size>;=stream->;top){
  227. EMSseek(stream,stream->;mapaddress,0);
  228. j=stream->;top;
  229. stream->;mapaddress+=j;
  230. size-=j;
  231. targe=stream->;base+(unsigned int)stream->;address;
  232. while(j-->;0) *targe++=*buffer++;
  233. };
  234. EMSseek(stream,stream->;mapaddress,0);
  235. j=size;
  236. targe=stream->;base+(unsigned int)stream->;address;
  237. stream->;mapaddress+=j;
  238. stream->;address+=j;
  239. while(j-->;0) *targe++=*buffer++;
  240. }
  241. }

  242. unsigned char EMSgetc(EMSFILE *stream)
  243. {
  244. unsigned char far *source;
  245. if(!stream->;active) EMSactive(stream);
  246. if(stream->;address>;=stream->;top)
  247. EMSlocation(stream);
  248. source=stream->;base+(unsigned int)stream->;address;
  249. stream->;mapaddress++;
  250. stream->;address++;
  251. return(*source);
  252. }

  253. void EMSputc(unsigned char a,EMSFILE *stream)
  254. {
  255. unsigned char far *targe;
  256. if(!stream->;active) EMSactive(stream);
  257. if(stream->;address>;=stream->;top)
  258. EMSlocation(stream);
  259. targe=stream->;base+(unsigned int)stream->;address;
  260. *targe=a;
  261. stream->;mapaddress++;
  262. stream->;address++;
  263. }

  264. long int EMStell(EMSFILE *stream)
  265. {
  266. return stream->;mapaddress;
  267. }


  268. void EMSseek(EMSFILE *stream,long int address,int way)
  269. {
  270. int i;
  271. if(way==0)
  272. stream->;mapaddress=address;
  273. else if(way==1) stream->;mapaddress+=address;
  274. else if(way==2) stream->;mapaddress=(stream->;size-address);
  275. if(stream->;mapaddress<0) stream->;mapaddress=0;
  276. if(stream->;mapaddress>;(stream->;size))
  277. stream->;mapaddress=stream->;size;
  278. if(!stream->;active){ EMSactive(stream); EMSlocation(stream);};
  279. i=stream->;firstlogpage;
  280. stream->;firstlogpage=(int)((stream->;mapaddress/stream->;top)*stream->;activenum);
  281. if(stream->;firstlogpage+stream->;activenum>;stream->;pagenum)
  282. stream->;firstlogpage=stream->;pagenum-stream->;activenum;
  283. // if(stream->;firstlogpage==i) return;
  284. stream->;address=(unsigned int)(stream->;mapaddress-stream->;firstlogpage*16384l);
  285. for(i=0;i<stream->;activenum;i++)
  286. EMSmap(stream->;handle,stream->;firstphypage+i,stream->;firstlogpage+i);

  287. // EMSlocation(stream);

  288. }

  289. int EMSini()
  290. {
  291. union REGS regs;
  292. void far *p;
  293. regs.h.ah=0x40;
  294. int86(0x67,&reg;s,&reg;s);
  295. if(regs.h.ah!=0)
  296. {
  297. EMS.EXIST=0;
  298. return 0;
  299. };
  300. regs.h.ah=0x41;
  301. int86(0x67,&reg;s,&reg;s);
  302. p=MK_FP(regs.x.bx,0);
  303. EMS.BASE=(unsigned char far *) p;
  304. regs.h.ah=0x42;
  305. int86(0x67,&reg;s,&reg;s);
  306. EMS.EXIST=1;
  307. EMS.PAGENUM=0;
  308. EMS.PAGEUSED[0]=(EMS.PAGEUSED[1]=0);
  309. EMS.PAGEUSED[2]=(EMS.PAGEUSED[3]=0);
  310. EMS.RESTNUM=(EMS.MAXPAGENUM=regs.x.bx);
  311. return 1;
  312. }

  313. unsigned int EMSalloc(int n)
  314. {
  315. union REGS regs;
  316. regs.h.ah=0x43;
  317. regs.x.bx=n;
  318. int86(0x67 ,&reg;s,&reg;s);
  319. if(regs.h.ah!=0) return -1;
  320. return regs.x.dx;
  321. }

  322. void EMSmap(unsigned int handle,int phys,int page)
  323. {
  324. union REGS regs;
  325. regs.h.ah=0x44;
  326. regs.h.al=phys;
  327. regs.x.bx=page;
  328. regs.x.dx=handle;
  329. int86(0x67 ,&reg;s,&reg;s);
  330. }

  331. void EMSexit(unsigned int handle)
  332. {
  333. union REGS regs;
  334. regs.h.ah=0x45;
  335. regs.x.dx=handle;
  336. int86(0x67 ,&reg;s,&reg;s);
  337. }

  338. EMSFILE *putfiletoEMS(char *name)
  339. {
  340. FILE *fp;
  341. long int size;
  342. EMSFILE *EMSfp;

  343. fp=fopen(name,"rb");
  344. fseek(fp,0,2);
  345. size=ftell(fp);
  346. fseek(fp,0,0);
  347. EMSfp=EMSopen(size);
  348. EMSactive(EMSfp);
  349. EMSseek(EMSfp,0,0);
  350. while(size-->;0)
  351. EMSputc(fgetc(fp),EMSfp);
  352. fclose(fp);
  353. EMSseek(EMSfp,0,0);
  354. return EMSfp;
  355. }

  356. void saveEMSfile(EMSFILE *EMSfp,char *name)
  357. {
  358. FILE *fp;
  359. long int size;

  360. fp=fopen(name,"wb");
  361. size=EMSfp->;size;
  362. EMSseek(EMSfp,0,0);
  363. while(size-->;0) fputc(EMSgetc(EMSfp),fp);
  364. fclose(fp);
  365. EMSseek(EMSfp,0,0);
  366. }

  367. EMSFILE *qputfiletoEMS(char *name)
  368. {
  369. FILE *fp;
  370. long int size;
  371. EMSFILE *EMSfp;
  372. unsigned char *b;
  373. if((b=(unsigned char *)malloc(16384))==NULL) return NULL;
  374. fp=fopen(name,"rb");
  375. fseek(fp,0,2);
  376. size=ftell(fp);
  377. fseek(fp,0,0);
  378. EMSfp=EMSopen(size);
  379. EMSactive(EMSfp);
  380. while(size>;=16384){
  381. fread(b,16384,1,fp);
  382. EMSwrite(b,16384,1,EMSfp);
  383. size-=16384;
  384. };
  385. fread(b,(int)size,1,fp);
  386. EMSwrite(b,(int)size,1,EMSfp);
  387. fclose(fp);
  388. EMSseek(EMSfp,0,0);
  389. free(b);
  390. return EMSfp;
  391. }

  392. void qsaveEMSfile(EMSFILE *EMSfp,char *name)
  393. {
  394. FILE *fp;
  395. long int size;
  396. unsigned char *b;
  397. if((b=(unsigned char *)malloc(16384))==NULL) return;
  398. fp=fopen(name,"wb");
  399. size=EMSfp->;size;
  400. EMSseek(EMSfp,0,0);
  401. while(size>;=16384){
  402. EMSread(b,16384,1,EMSfp);
  403. fwrite(b,16384,1,fp);
  404. size-=16384;
  405. };
  406. EMSread(b,(int)size,1,EMSfp);
  407. fwrite(b,(int)size,1,fp);
  408. fclose(fp);
  409. free(b);
  410. EMSseek(EMSfp,0,0);
  411. }

复制代码

论坛徽章:
0
6 [报告]
发表于 2003-02-18 11:38 |只看该作者

关于DOS下扩展内存的使用(涉及WIN2000)

这是个接收声纳上传数据实时显示海底情况的鱼探程序,因为要添加在几年前别人已写完的程序上才用DOS,不然谁用这玩意!传由于要同时高速读串口(115200),重画的区域也相当大,620×340,所以我尽量不想分块画。
    现在我刚把XMS的himem.sys搞上去,可是检测结果xms可用空间为0,如此怎办?

论坛徽章:
0
7 [报告]
发表于 2003-02-18 13:11 |只看该作者

关于DOS下扩展内存的使用(涉及WIN2000)


www.google.com
上查找
dos 扩展内存 编程
看看

论坛徽章:
0
8 [报告]
发表于 2003-02-18 22:11 |只看该作者

关于DOS下扩展内存的使用(涉及WIN2000)

我去找了一下。这里有篇不错的文章,有兴趣的朋友也可以看下。
http://www.powerba.com/develop/c&amp;c++/article/20001205002.htm
《DOS实方式下直接访问4GB内存》
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP