3 * Test program: HIMEM.SYS functions
\r
4 * (C) 2010-2012 Jonathan Campbell.
\r
5 * Hackipedia DOS library.
\r
7 * This code is licensed under the LGPL.
\r
8 * <insert LGPL legal text here>
\r
18 //#include "src/lib/doslib/cpu.h"
\r
19 #include "src/lib/doslib/dos.h"
\r
20 //#include doswin.h>
\r
21 #include "src/lib/doslib/himemsys.h"
\r
25 printf("DOS version %x.%02u\n",dos_version>>8,dos_version&0xFF);
\r
26 /*if (detect_windows()) {
\r
27 printf("I am running under Windows.\n");
\r
28 printf(" Mode: %s\n",windows_mode_str(windows_mode));
\r
29 printf(" Ver: %x.%02u\n",windows_version>>8,windows_version&0xFF);
\r
32 printf("Not running under Windows or OS/2\n");
\r
35 if (probe_himem_sys()) {
\r
38 printf("HIMEM.SYS detected. Entry point %04x:%04x. v%x.%02x\n",
\r
39 (unsigned int)((himem_sys_entry >> 16) & 0xFFFFUL),
\r
40 (unsigned int)(himem_sys_entry & 0xFFFFUL),
\r
41 (unsigned int)(himem_sys_version >> 8),
\r
42 (unsigned int)(himem_sys_version & 0xFF));
\r
44 if (himem_sys_flags & HIMEM_F_HMA)
\r
45 printf(" - HMA is present\n");
\r
46 if (himem_sys_flags & HIMEM_F_4GB)
\r
47 printf(" - Extensions are present to address up to 4GB of memory\n");
\r
49 printf("A20 status: %u\n",himem_sys_query_a20());
\r
50 printf("Global A20 line: "); fflush(stdout);
\r
51 printf("en=%d ",himem_sys_global_a20(1)); fflush(stdout);
\r
52 printf("query=%d ",himem_sys_query_a20(1)); fflush(stdout);
\r
53 printf("dis=%d ",himem_sys_global_a20(0)); fflush(stdout);
\r
54 printf("query=%d ",himem_sys_query_a20(1)); fflush(stdout);
\r
57 printf("Local A20 line: "); fflush(stdout);
\r
58 printf("en=%d ",himem_sys_local_a20(1)); fflush(stdout);
\r
59 printf("query=%d ",himem_sys_query_a20(1)); fflush(stdout);
\r
60 printf("dis=%d ",himem_sys_local_a20(0)); fflush(stdout);
\r
61 printf("query=%d ",himem_sys_query_a20(1)); fflush(stdout);
\r
64 himem_sys_update_free_memory_status();
\r
65 printf("Free memory: %luKB (largest block %luKB)\n",
\r
66 (unsigned long)himem_sys_total_free,
\r
67 (unsigned long)himem_sys_largest_free);
\r
69 printf("Attempting to alloc 4KB: ");
\r
70 h1 = himem_sys_alloc(4); /* NTS: This is in KB, not bytes */
\r
71 if (h1 != -1) printf("ok, handle %u\n",h1);
\r
72 else printf("failed\n");
\r
74 printf("Attempting to alloc 64KB: ");
\r
75 h2 = himem_sys_alloc(46); /* NTS: This is in KB, not bytes */
\r
76 if (h2 != -1) printf("ok, handle %u\n",h2);
\r
77 else printf("failed\n");
\r
79 printf("Attempting to alloc 1MB: ");
\r
80 h3 = himem_sys_alloc(1024); /* NTS: This is in KB, not bytes */
\r
81 if (h3 != -1) printf("ok, handle %u\n",h3);
\r
82 else printf("failed\n");
\r
85 if (!himem_sys_free(h1)) printf(" - Free failed\n");
\r
88 if (!himem_sys_free(h2)) printf(" - Free failed\n");
\r
91 if (!himem_sys_free(h3)) printf(" - Free failed\n");
\r
94 printf("Attempting to alloc 1MB (for writing to): ");
\r
95 h3 = himem_sys_alloc(1024); /* NTS: This is in KB, not bytes */
\r
99 struct himem_block_info binf;
\r
100 #if TARGET_MSDOS == 32
\r
102 unsigned char *tmp;
\r
103 uint16_t tmpsel=0,msgsel=0;
\r
104 const char *msgref = "Testing 123 hello";
\r
106 unsigned char tmp[16];
\r
107 const char *msg = "Testing 123 hello";
\r
110 #if TARGET_MSDOS == 32
\r
111 tmp = dpmi_alloc_dos(16,&tmpsel);
\r
112 if (tmp == NULL) abort();
\r
113 msg = dpmi_alloc_dos(strlen(msgref)+16,&msgsel);
\r
114 if (msg == NULL) abort();
\r
115 memcpy(msg,msgref,strlen(msgref)+1);
\r
118 printf("ok, handle %u\n",h3);
\r
120 if (himem_sys_get_handle_info(h3,&binf)) {
\r
121 printf("Handle info:\n");
\r
122 printf(" Lock count=%u Free handles=%u Size=%luKB\n",
\r
123 (unsigned int)binf.lock_count,
\r
124 (unsigned int)binf.free_handles,
\r
125 (unsigned long)binf.block_length_kb);
\r
128 printf("Cannot get handle info\n");
\r
131 #if TARGET_MSDOS == 32
\r
132 if (!himem_sys_move(h3,0,0/*conventional memory*/,(unsigned long)(msg),16))
\r
134 if (!himem_sys_move(h3,0,0/*conventional memory*/,((unsigned long)FP_SEG(msg) << 4UL) + (unsigned long)FP_OFF(msg),sizeof(tmp)))
\r
136 printf("Copy didn't work\n");
\r
138 for (i=0;i < 16;i += 2) {
\r
143 #if TARGET_MSDOS == 32
\r
144 if (!himem_sys_move(0/*conventional memory*/,(unsigned long)(tmp),h3,0,16))
\r
146 if (!himem_sys_move(0/*conventional memory*/,((unsigned long)FP_SEG(tmp) << 4UL) + (unsigned long)FP_OFF(tmp),h3,0,sizeof(tmp)))
\r
148 printf("Copy didn't work\n");
\r
150 for (i=0;i < 16;i++) printf("%02x ",tmp[i]);
\r
153 ofs = himem_sys_lock(h3);
\r
155 printf(" - Locked: Physical memory address 0x%08lX\n",(unsigned long)ofs);
\r
156 if (!himem_sys_unlock(h3)) printf(" - Cannot unlock\n");
\r
159 printf(" - Cannot lock\n");
\r
162 printf("now resizing to 2MB\n");
\r
163 if (himem_sys_realloc(h3,2048)) {
\r
164 #if TARGET_MSDOS == 32
\r
165 if (!himem_sys_move(0/*conventional memory*/,(unsigned long)(tmp),h3,0,16))
\r
167 if (!himem_sys_move(0/*conventional memory*/,((unsigned long)FP_SEG(tmp) << 4UL) + (unsigned long)FP_OFF(tmp),h3,0,sizeof(tmp)))
\r
169 printf("Copy didn't work\n");
\r
171 for (i=0;i < 16;i++) printf("%02x ",tmp[i]);
\r
174 ofs = himem_sys_lock(h3);
\r
176 printf(" - Locked: Physical memory address 0x%08lX\n",(unsigned long)ofs);
\r
177 if (!himem_sys_unlock(h3)) printf(" - Cannot unlock\n");
\r
180 printf(" - Cannot lock\n");
\r
184 printf(" - Cannot realloc\n");
\r
187 if (!himem_sys_free(h3)) printf(" - Free failed\n");
\r
189 #if TARGET_MSDOS == 32
\r
190 dpmi_free_dos(tmpsel); tmp=NULL;
\r
191 dpmi_free_dos(msgsel); msg=NULL;
\r
194 else printf("failed\n");
\r
196 printf("Attempting to alloc 129MB (for writing to): ");
\r
197 h3 = himem_sys_alloc(129UL * 1024UL); /* NTS: This is in KB, not bytes */
\r
201 unsigned char tmp[16];
\r
202 struct himem_block_info binf;
\r
203 const char *msg = "Testing 123 hello";
\r
205 printf("ok, handle %u\n",h3);
\r
207 if (himem_sys_get_handle_info(h3,&binf)) {
\r
208 printf("Handle info:\n");
\r
209 printf(" Lock count=%u Free handles=%u Size=%luKB\n",
\r
210 (unsigned int)binf.lock_count,
\r
211 (unsigned int)binf.free_handles,
\r
212 (unsigned long)binf.block_length_kb);
\r
215 printf("Cannot get handle info\n");
\r
218 #if TARGET_MSDOS == 32
\r
219 if (!himem_sys_move(h3,0,0/*conventional memory*/,(unsigned long)(msg),16))
\r
221 if (!himem_sys_move(h3,0,0/*conventional memory*/,((unsigned long)FP_SEG(msg) << 4UL) + (unsigned long)FP_OFF(msg),sizeof(tmp)))
\r
223 printf("Copy didn't work\n");
\r
225 for (i=0;i < 16;i += 2) {
\r
230 #if TARGET_MSDOS == 32
\r
231 if (!himem_sys_move(0/*conventional memory*/,(unsigned long)(tmp),h3,0,16))
\r
233 if (!himem_sys_move(0/*conventional memory*/,((unsigned long)FP_SEG(tmp) << 4UL) + (unsigned long)FP_OFF(tmp),h3,0,sizeof(tmp)))
\r
235 printf("Copy didn't work\n");
\r
237 for (i=0;i < 16;i++) printf("%02x ",tmp[i]);
\r
240 ofs = himem_sys_lock(h3);
\r
242 printf(" - Locked: Physical memory address 0x%08lX\n",(unsigned long)ofs);
\r
243 if (!himem_sys_unlock(h3)) printf(" - Cannot unlock\n");
\r
246 printf(" - Cannot lock\n");
\r
249 printf("now resizing to 144MB\n");
\r
250 if (himem_sys_realloc(h3,144UL*1024UL)) {
\r
251 if (himem_sys_get_handle_info(h3,&binf)) {
\r
252 printf("Handle info:\n");
\r
253 printf(" Lock count=%u Free handles=%u Size=%luKB\n",
\r
254 (unsigned int)binf.lock_count,
\r
255 (unsigned int)binf.free_handles,
\r
256 (unsigned long)binf.block_length_kb);
\r
259 printf("Cannot get handle info\n");
\r
262 #if TARGET_MSDOS == 32
\r
263 if (!himem_sys_move(0/*conventional memory*/,(unsigned long)(tmp),h3,0,16))
\r
265 if (!himem_sys_move(0/*conventional memory*/,((unsigned long)FP_SEG(tmp) << 4UL) + (unsigned long)FP_OFF(tmp),h3,0,sizeof(tmp)))
\r
267 printf("Copy didn't work\n");
\r
269 for (i=0;i < 16;i++) printf("%02x ",tmp[i]);
\r
272 ofs = himem_sys_lock(h3);
\r
274 printf(" - Locked: Physical memory address 0x%08lX\n",(unsigned long)ofs);
\r
275 if (!himem_sys_unlock(h3)) printf(" - Cannot unlock\n");
\r
278 printf(" - Cannot lock\n");
\r
282 printf(" - Cannot realloc\n");
\r
285 if (!himem_sys_free(h3)) printf(" - Free failed\n");
\r
287 else printf("failed\n");
\r
290 printf("HIMEM.SYS not found\n");
\r