-/* tsthimem.c
- *
- * Test program: HIMEM.SYS functions
- * (C) 2010-2012 Jonathan Campbell.
- * Hackipedia DOS library.
- *
- * This code is licensed under the LGPL.
- * <insert LGPL legal text here>
- */
-
-#include <stdlib.h>
-#include <string.h>
-#include <stdint.h>
-#include <stdio.h>
-#include <conio.h>
-#include <dos.h>
-
-//#include "src/lib/doslib/cpu.h"
-#include "src/lib/doslib/dos.h"
-//#include doswin.h>
-#include "src/lib/doslib/himemsys.h"
-
-int main() {
- probe_dos();
- printf("DOS version %x.%02u\n",dos_version>>8,dos_version&0xFF);
- /*if (detect_windows()) {
- printf("I am running under Windows.\n");
- printf(" Mode: %s\n",windows_mode_str(windows_mode));
- printf(" Ver: %x.%02u\n",windows_version>>8,windows_version&0xFF);
- }
- else {
- printf("Not running under Windows or OS/2\n");
- }*/
-
- if (probe_himem_sys()) {
- int h1,h2,h3;
-
- printf("HIMEM.SYS detected. Entry point %04x:%04x. v%x.%02x\n",
- (unsigned int)((himem_sys_entry >> 16) & 0xFFFFUL),
- (unsigned int)(himem_sys_entry & 0xFFFFUL),
- (unsigned int)(himem_sys_version >> 8),
- (unsigned int)(himem_sys_version & 0xFF));
-
- if (himem_sys_flags & HIMEM_F_HMA)
- printf(" - HMA is present\n");
- if (himem_sys_flags & HIMEM_F_4GB)
- printf(" - Extensions are present to address up to 4GB of memory\n");
-
- printf("A20 status: %u\n",himem_sys_query_a20());
- printf("Global A20 line: "); fflush(stdout);
- printf("en=%d ",himem_sys_global_a20(1)); fflush(stdout);
- printf("query=%d ",himem_sys_query_a20(1)); fflush(stdout);
- printf("dis=%d ",himem_sys_global_a20(0)); fflush(stdout);
- printf("query=%d ",himem_sys_query_a20(1)); fflush(stdout);
- printf("\n");
-
- printf("Local A20 line: "); fflush(stdout);
- printf("en=%d ",himem_sys_local_a20(1)); fflush(stdout);
- printf("query=%d ",himem_sys_query_a20(1)); fflush(stdout);
- printf("dis=%d ",himem_sys_local_a20(0)); fflush(stdout);
- printf("query=%d ",himem_sys_query_a20(1)); fflush(stdout);
- printf("\n");
-
- himem_sys_update_free_memory_status();
- printf("Free memory: %luKB (largest block %luKB)\n",
- (unsigned long)himem_sys_total_free,
- (unsigned long)himem_sys_largest_free);
-
- printf("Attempting to alloc 4KB: ");
- h1 = himem_sys_alloc(4); /* NTS: This is in KB, not bytes */
- if (h1 != -1) printf("ok, handle %u\n",h1);
- else printf("failed\n");
-
- printf("Attempting to alloc 64KB: ");
- h2 = himem_sys_alloc(46); /* NTS: This is in KB, not bytes */
- if (h2 != -1) printf("ok, handle %u\n",h2);
- else printf("failed\n");
-
- printf("Attempting to alloc 1MB: ");
- h3 = himem_sys_alloc(1024); /* NTS: This is in KB, not bytes */
- if (h3 != -1) printf("ok, handle %u\n",h3);
- else printf("failed\n");
-
- if (h1 != -1) {
- if (!himem_sys_free(h1)) printf(" - Free failed\n");
- }
- if (h2 != -1) {
- if (!himem_sys_free(h2)) printf(" - Free failed\n");
- }
- if (h3 != -1) {
- if (!himem_sys_free(h3)) printf(" - Free failed\n");
- }
-
- printf("Attempting to alloc 1MB (for writing to): ");
- h3 = himem_sys_alloc(1024); /* NTS: This is in KB, not bytes */
- if (h3 != -1) {
- uint32_t ofs;
- unsigned int i;
- struct himem_block_info binf;
-#if TARGET_MSDOS == 32
- char *msg;
- unsigned char *tmp;
- uint16_t tmpsel=0,msgsel=0;
- const char *msgref = "Testing 123 hello";
-#else
- unsigned char tmp[16];
- const char *msg = "Testing 123 hello";
-#endif
-
-#if TARGET_MSDOS == 32
- tmp = dpmi_alloc_dos(16,&tmpsel);
- if (tmp == NULL) abort();
- msg = dpmi_alloc_dos(strlen(msgref)+16,&msgsel);
- if (msg == NULL) abort();
- memcpy(msg,msgref,strlen(msgref)+1);
-#endif
-
- printf("ok, handle %u\n",h3);
-
- if (himem_sys_get_handle_info(h3,&binf)) {
- printf("Handle info:\n");
- printf(" Lock count=%u Free handles=%u Size=%luKB\n",
- (unsigned int)binf.lock_count,
- (unsigned int)binf.free_handles,
- (unsigned long)binf.block_length_kb);
- }
- else {
- printf("Cannot get handle info\n");
- }
-
-#if TARGET_MSDOS == 32
- if (!himem_sys_move(h3,0,0/*conventional memory*/,(unsigned long)(msg),16))
-#else
- if (!himem_sys_move(h3,0,0/*conventional memory*/,((unsigned long)FP_SEG(msg) << 4UL) + (unsigned long)FP_OFF(msg),sizeof(tmp)))
-#endif
- printf("Copy didn't work\n");
-
- for (i=0;i < 16;i += 2) {
- tmp[i+0] = 0x55;
- tmp[i+1] = 0xAA;
- }
-
-#if TARGET_MSDOS == 32
- if (!himem_sys_move(0/*conventional memory*/,(unsigned long)(tmp),h3,0,16))
-#else
- if (!himem_sys_move(0/*conventional memory*/,((unsigned long)FP_SEG(tmp) << 4UL) + (unsigned long)FP_OFF(tmp),h3,0,sizeof(tmp)))
-#endif
- printf("Copy didn't work\n");
-
- for (i=0;i < 16;i++) printf("%02x ",tmp[i]);
- printf("\n");
-
- ofs = himem_sys_lock(h3);
- if (ofs != 0UL) {
- printf(" - Locked: Physical memory address 0x%08lX\n",(unsigned long)ofs);
- if (!himem_sys_unlock(h3)) printf(" - Cannot unlock\n");
- }
- else {
- printf(" - Cannot lock\n");
- }
-
- printf("now resizing to 2MB\n");
- if (himem_sys_realloc(h3,2048)) {
-#if TARGET_MSDOS == 32
- if (!himem_sys_move(0/*conventional memory*/,(unsigned long)(tmp),h3,0,16))
-#else
- if (!himem_sys_move(0/*conventional memory*/,((unsigned long)FP_SEG(tmp) << 4UL) + (unsigned long)FP_OFF(tmp),h3,0,sizeof(tmp)))
-#endif
- printf("Copy didn't work\n");
-
- for (i=0;i < 16;i++) printf("%02x ",tmp[i]);
- printf("\n");
-
- ofs = himem_sys_lock(h3);
- if (ofs != 0UL) {
- printf(" - Locked: Physical memory address 0x%08lX\n",(unsigned long)ofs);
- if (!himem_sys_unlock(h3)) printf(" - Cannot unlock\n");
- }
- else {
- printf(" - Cannot lock\n");
- }
- }
- else {
- printf(" - Cannot realloc\n");
- }
-
- if (!himem_sys_free(h3)) printf(" - Free failed\n");
-
-#if TARGET_MSDOS == 32
- dpmi_free_dos(tmpsel); tmp=NULL;
- dpmi_free_dos(msgsel); msg=NULL;
-#endif
- }
- else printf("failed\n");
-
- printf("Attempting to alloc 129MB (for writing to): ");
- h3 = himem_sys_alloc(129UL * 1024UL); /* NTS: This is in KB, not bytes */
- if (h3 != -1) {
- uint32_t ofs;
- unsigned int i;
- unsigned char tmp[16];
- struct himem_block_info binf;
- const char *msg = "Testing 123 hello";
-
- printf("ok, handle %u\n",h3);
-
- if (himem_sys_get_handle_info(h3,&binf)) {
- printf("Handle info:\n");
- printf(" Lock count=%u Free handles=%u Size=%luKB\n",
- (unsigned int)binf.lock_count,
- (unsigned int)binf.free_handles,
- (unsigned long)binf.block_length_kb);
- }
- else {
- printf("Cannot get handle info\n");
- }
-
-#if TARGET_MSDOS == 32
- if (!himem_sys_move(h3,0,0/*conventional memory*/,(unsigned long)(msg),16))
-#else
- if (!himem_sys_move(h3,0,0/*conventional memory*/,((unsigned long)FP_SEG(msg) << 4UL) + (unsigned long)FP_OFF(msg),sizeof(tmp)))
-#endif
- printf("Copy didn't work\n");
-
- for (i=0;i < 16;i += 2) {
- tmp[i+0] = 0x55;
- tmp[i+1] = 0xAA;
- }
-
-#if TARGET_MSDOS == 32
- if (!himem_sys_move(0/*conventional memory*/,(unsigned long)(tmp),h3,0,16))
-#else
- if (!himem_sys_move(0/*conventional memory*/,((unsigned long)FP_SEG(tmp) << 4UL) + (unsigned long)FP_OFF(tmp),h3,0,sizeof(tmp)))
-#endif
- printf("Copy didn't work\n");
-
- for (i=0;i < 16;i++) printf("%02x ",tmp[i]);
- printf("\n");
-
- ofs = himem_sys_lock(h3);
- if (ofs != 0UL) {
- printf(" - Locked: Physical memory address 0x%08lX\n",(unsigned long)ofs);
- if (!himem_sys_unlock(h3)) printf(" - Cannot unlock\n");
- }
- else {
- printf(" - Cannot lock\n");
- }
-
- printf("now resizing to 144MB\n");
- if (himem_sys_realloc(h3,144UL*1024UL)) {
- if (himem_sys_get_handle_info(h3,&binf)) {
- printf("Handle info:\n");
- printf(" Lock count=%u Free handles=%u Size=%luKB\n",
- (unsigned int)binf.lock_count,
- (unsigned int)binf.free_handles,
- (unsigned long)binf.block_length_kb);
- }
- else {
- printf("Cannot get handle info\n");
- }
-
-#if TARGET_MSDOS == 32
- if (!himem_sys_move(0/*conventional memory*/,(unsigned long)(tmp),h3,0,16))
-#else
- if (!himem_sys_move(0/*conventional memory*/,((unsigned long)FP_SEG(tmp) << 4UL) + (unsigned long)FP_OFF(tmp),h3,0,sizeof(tmp)))
-#endif
- printf("Copy didn't work\n");
-
- for (i=0;i < 16;i++) printf("%02x ",tmp[i]);
- printf("\n");
-
- ofs = himem_sys_lock(h3);
- if (ofs != 0UL) {
- printf(" - Locked: Physical memory address 0x%08lX\n",(unsigned long)ofs);
- if (!himem_sys_unlock(h3)) printf(" - Cannot unlock\n");
- }
- else {
- printf(" - Cannot lock\n");
- }
- }
- else {
- printf(" - Cannot realloc\n");
- }
-
- if (!himem_sys_free(h3)) printf(" - Free failed\n");
- }
- else printf("failed\n");
- }
- else {
- printf("HIMEM.SYS not found\n");
- }
-
- return 0;
-}
-
+/* tsthimem.c\r
+ *\r
+ * Test program: HIMEM.SYS functions\r
+ * (C) 2010-2012 Jonathan Campbell.\r
+ * Hackipedia DOS library.\r
+ *\r
+ * This code is licensed under the LGPL.\r
+ * <insert LGPL legal text here>\r
+ */\r
+\r
+#include <stdlib.h>\r
+#include <string.h>\r
+#include <stdint.h>\r
+#include <stdio.h>\r
+#include <conio.h>\r
+#include <dos.h>\r
+\r
+//#include "src/lib/doslib/cpu.h"\r
+#include "src/lib/doslib/dos.h"\r
+//#include doswin.h>\r
+#include "src/lib/doslib/himemsys.h"\r
+\r
+int main() {\r
+ probe_dos();\r
+ printf("DOS version %x.%02u\n",dos_version>>8,dos_version&0xFF);\r
+ /*if (detect_windows()) {\r
+ printf("I am running under Windows.\n");\r
+ printf(" Mode: %s\n",windows_mode_str(windows_mode));\r
+ printf(" Ver: %x.%02u\n",windows_version>>8,windows_version&0xFF);\r
+ }\r
+ else {\r
+ printf("Not running under Windows or OS/2\n");\r
+ }*/\r
+\r
+ if (probe_himem_sys()) {\r
+ int h1,h2,h3;\r
+\r
+ printf("HIMEM.SYS detected. Entry point %04x:%04x. v%x.%02x\n",\r
+ (unsigned int)((himem_sys_entry >> 16) & 0xFFFFUL),\r
+ (unsigned int)(himem_sys_entry & 0xFFFFUL),\r
+ (unsigned int)(himem_sys_version >> 8),\r
+ (unsigned int)(himem_sys_version & 0xFF));\r
+\r
+ if (himem_sys_flags & HIMEM_F_HMA)\r
+ printf(" - HMA is present\n");\r
+ if (himem_sys_flags & HIMEM_F_4GB)\r
+ printf(" - Extensions are present to address up to 4GB of memory\n");\r
+\r
+ printf("A20 status: %u\n",himem_sys_query_a20());\r
+ printf("Global A20 line: "); fflush(stdout);\r
+ printf("en=%d ",himem_sys_global_a20(1)); fflush(stdout);\r
+ printf("query=%d ",himem_sys_query_a20(1)); fflush(stdout);\r
+ printf("dis=%d ",himem_sys_global_a20(0)); fflush(stdout);\r
+ printf("query=%d ",himem_sys_query_a20(1)); fflush(stdout);\r
+ printf("\n");\r
+\r
+ printf("Local A20 line: "); fflush(stdout);\r
+ printf("en=%d ",himem_sys_local_a20(1)); fflush(stdout);\r
+ printf("query=%d ",himem_sys_query_a20(1)); fflush(stdout);\r
+ printf("dis=%d ",himem_sys_local_a20(0)); fflush(stdout);\r
+ printf("query=%d ",himem_sys_query_a20(1)); fflush(stdout);\r
+ printf("\n");\r
+\r
+ himem_sys_update_free_memory_status();\r
+ printf("Free memory: %luKB (largest block %luKB)\n",\r
+ (unsigned long)himem_sys_total_free,\r
+ (unsigned long)himem_sys_largest_free);\r
+\r
+ printf("Attempting to alloc 4KB: ");\r
+ h1 = himem_sys_alloc(4); /* NTS: This is in KB, not bytes */\r
+ if (h1 != -1) printf("ok, handle %u\n",h1);\r
+ else printf("failed\n");\r
+\r
+ printf("Attempting to alloc 64KB: ");\r
+ h2 = himem_sys_alloc(46); /* NTS: This is in KB, not bytes */\r
+ if (h2 != -1) printf("ok, handle %u\n",h2);\r
+ else printf("failed\n");\r
+\r
+ printf("Attempting to alloc 1MB: ");\r
+ h3 = himem_sys_alloc(1024); /* NTS: This is in KB, not bytes */\r
+ if (h3 != -1) printf("ok, handle %u\n",h3);\r
+ else printf("failed\n");\r
+\r
+ if (h1 != -1) {\r
+ if (!himem_sys_free(h1)) printf(" - Free failed\n");\r
+ }\r
+ if (h2 != -1) {\r
+ if (!himem_sys_free(h2)) printf(" - Free failed\n");\r
+ }\r
+ if (h3 != -1) {\r
+ if (!himem_sys_free(h3)) printf(" - Free failed\n");\r
+ }\r
+\r
+ printf("Attempting to alloc 1MB (for writing to): ");\r
+ h3 = himem_sys_alloc(1024); /* NTS: This is in KB, not bytes */\r
+ if (h3 != -1) {\r
+ uint32_t ofs;\r
+ unsigned int i;\r
+ struct himem_block_info binf;\r
+#if TARGET_MSDOS == 32\r
+ char *msg;\r
+ unsigned char *tmp;\r
+ uint16_t tmpsel=0,msgsel=0;\r
+ const char *msgref = "Testing 123 hello";\r
+#else\r
+ unsigned char tmp[16];\r
+ const char *msg = "Testing 123 hello";\r
+#endif\r
+\r
+#if TARGET_MSDOS == 32\r
+ tmp = dpmi_alloc_dos(16,&tmpsel);\r
+ if (tmp == NULL) abort();\r
+ msg = dpmi_alloc_dos(strlen(msgref)+16,&msgsel);\r
+ if (msg == NULL) abort();\r
+ memcpy(msg,msgref,strlen(msgref)+1);\r
+#endif\r
+\r
+ printf("ok, handle %u\n",h3);\r
+\r
+ if (himem_sys_get_handle_info(h3,&binf)) {\r
+ printf("Handle info:\n");\r
+ printf(" Lock count=%u Free handles=%u Size=%luKB\n",\r
+ (unsigned int)binf.lock_count,\r
+ (unsigned int)binf.free_handles,\r
+ (unsigned long)binf.block_length_kb);\r
+ }\r
+ else {\r
+ printf("Cannot get handle info\n");\r
+ }\r
+\r
+#if TARGET_MSDOS == 32\r
+ if (!himem_sys_move(h3,0,0/*conventional memory*/,(unsigned long)(msg),16))\r
+#else\r
+ if (!himem_sys_move(h3,0,0/*conventional memory*/,((unsigned long)FP_SEG(msg) << 4UL) + (unsigned long)FP_OFF(msg),sizeof(tmp)))\r
+#endif\r
+ printf("Copy didn't work\n");\r
+\r
+ for (i=0;i < 16;i += 2) {\r
+ tmp[i+0] = 0x55;\r
+ tmp[i+1] = 0xAA;\r
+ }\r
+\r
+#if TARGET_MSDOS == 32\r
+ if (!himem_sys_move(0/*conventional memory*/,(unsigned long)(tmp),h3,0,16))\r
+#else\r
+ if (!himem_sys_move(0/*conventional memory*/,((unsigned long)FP_SEG(tmp) << 4UL) + (unsigned long)FP_OFF(tmp),h3,0,sizeof(tmp)))\r
+#endif\r
+ printf("Copy didn't work\n");\r
+\r
+ for (i=0;i < 16;i++) printf("%02x ",tmp[i]);\r
+ printf("\n");\r
+\r
+ ofs = himem_sys_lock(h3);\r
+ if (ofs != 0UL) {\r
+ printf(" - Locked: Physical memory address 0x%08lX\n",(unsigned long)ofs);\r
+ if (!himem_sys_unlock(h3)) printf(" - Cannot unlock\n");\r
+ }\r
+ else {\r
+ printf(" - Cannot lock\n");\r
+ }\r
+\r
+ printf("now resizing to 2MB\n");\r
+ if (himem_sys_realloc(h3,2048)) {\r
+#if TARGET_MSDOS == 32\r
+ if (!himem_sys_move(0/*conventional memory*/,(unsigned long)(tmp),h3,0,16))\r
+#else\r
+ if (!himem_sys_move(0/*conventional memory*/,((unsigned long)FP_SEG(tmp) << 4UL) + (unsigned long)FP_OFF(tmp),h3,0,sizeof(tmp)))\r
+#endif\r
+ printf("Copy didn't work\n");\r
+\r
+ for (i=0;i < 16;i++) printf("%02x ",tmp[i]);\r
+ printf("\n");\r
+\r
+ ofs = himem_sys_lock(h3);\r
+ if (ofs != 0UL) {\r
+ printf(" - Locked: Physical memory address 0x%08lX\n",(unsigned long)ofs);\r
+ if (!himem_sys_unlock(h3)) printf(" - Cannot unlock\n");\r
+ }\r
+ else {\r
+ printf(" - Cannot lock\n");\r
+ }\r
+ }\r
+ else {\r
+ printf(" - Cannot realloc\n");\r
+ }\r
+\r
+ if (!himem_sys_free(h3)) printf(" - Free failed\n");\r
+\r
+#if TARGET_MSDOS == 32\r
+ dpmi_free_dos(tmpsel); tmp=NULL;\r
+ dpmi_free_dos(msgsel); msg=NULL;\r
+#endif\r
+ }\r
+ else printf("failed\n");\r
+\r
+ printf("Attempting to alloc 129MB (for writing to): ");\r
+ h3 = himem_sys_alloc(129UL * 1024UL); /* NTS: This is in KB, not bytes */\r
+ if (h3 != -1) {\r
+ uint32_t ofs;\r
+ unsigned int i;\r
+ unsigned char tmp[16];\r
+ struct himem_block_info binf;\r
+ const char *msg = "Testing 123 hello";\r
+\r
+ printf("ok, handle %u\n",h3);\r
+\r
+ if (himem_sys_get_handle_info(h3,&binf)) {\r
+ printf("Handle info:\n");\r
+ printf(" Lock count=%u Free handles=%u Size=%luKB\n",\r
+ (unsigned int)binf.lock_count,\r
+ (unsigned int)binf.free_handles,\r
+ (unsigned long)binf.block_length_kb);\r
+ }\r
+ else {\r
+ printf("Cannot get handle info\n");\r
+ }\r
+\r
+#if TARGET_MSDOS == 32\r
+ if (!himem_sys_move(h3,0,0/*conventional memory*/,(unsigned long)(msg),16))\r
+#else\r
+ if (!himem_sys_move(h3,0,0/*conventional memory*/,((unsigned long)FP_SEG(msg) << 4UL) + (unsigned long)FP_OFF(msg),sizeof(tmp)))\r
+#endif\r
+ printf("Copy didn't work\n");\r
+\r
+ for (i=0;i < 16;i += 2) {\r
+ tmp[i+0] = 0x55;\r
+ tmp[i+1] = 0xAA;\r
+ }\r
+\r
+#if TARGET_MSDOS == 32\r
+ if (!himem_sys_move(0/*conventional memory*/,(unsigned long)(tmp),h3,0,16))\r
+#else\r
+ if (!himem_sys_move(0/*conventional memory*/,((unsigned long)FP_SEG(tmp) << 4UL) + (unsigned long)FP_OFF(tmp),h3,0,sizeof(tmp)))\r
+#endif\r
+ printf("Copy didn't work\n");\r
+\r
+ for (i=0;i < 16;i++) printf("%02x ",tmp[i]);\r
+ printf("\n");\r
+\r
+ ofs = himem_sys_lock(h3);\r
+ if (ofs != 0UL) {\r
+ printf(" - Locked: Physical memory address 0x%08lX\n",(unsigned long)ofs);\r
+ if (!himem_sys_unlock(h3)) printf(" - Cannot unlock\n");\r
+ }\r
+ else {\r
+ printf(" - Cannot lock\n");\r
+ }\r
+\r
+ printf("now resizing to 144MB\n");\r
+ if (himem_sys_realloc(h3,144UL*1024UL)) {\r
+ if (himem_sys_get_handle_info(h3,&binf)) {\r
+ printf("Handle info:\n");\r
+ printf(" Lock count=%u Free handles=%u Size=%luKB\n",\r
+ (unsigned int)binf.lock_count,\r
+ (unsigned int)binf.free_handles,\r
+ (unsigned long)binf.block_length_kb);\r
+ }\r
+ else {\r
+ printf("Cannot get handle info\n");\r
+ }\r
+\r
+#if TARGET_MSDOS == 32\r
+ if (!himem_sys_move(0/*conventional memory*/,(unsigned long)(tmp),h3,0,16))\r
+#else\r
+ if (!himem_sys_move(0/*conventional memory*/,((unsigned long)FP_SEG(tmp) << 4UL) + (unsigned long)FP_OFF(tmp),h3,0,sizeof(tmp)))\r
+#endif\r
+ printf("Copy didn't work\n");\r
+\r
+ for (i=0;i < 16;i++) printf("%02x ",tmp[i]);\r
+ printf("\n");\r
+\r
+ ofs = himem_sys_lock(h3);\r
+ if (ofs != 0UL) {\r
+ printf(" - Locked: Physical memory address 0x%08lX\n",(unsigned long)ofs);\r
+ if (!himem_sys_unlock(h3)) printf(" - Cannot unlock\n");\r
+ }\r
+ else {\r
+ printf(" - Cannot lock\n");\r
+ }\r
+ }\r
+ else {\r
+ printf(" - Cannot realloc\n");\r
+ }\r
+\r
+ if (!himem_sys_free(h3)) printf(" - Free failed\n");\r
+ }\r
+ else printf("failed\n");\r
+ }\r
+ else {\r
+ printf("HIMEM.SYS not found\n");\r
+ }\r
+\r
+ return 0;\r
+}\r
+\r