]> 4ch.mooo.com Git - 16.git/commitdiff
found ems library
authorsparky4 <sparky4@lappy4.4ch.mooo.com>
Wed, 21 Jan 2015 02:35:19 +0000 (20:35 -0600)
committersparky4 <sparky4@lappy4.4ch.mooo.com>
Wed, 21 Jan 2015 02:35:19 +0000 (20:35 -0600)
new file:   src/lib/ems1.c

src/lib/ems1.c [new file with mode: 0644]

diff --git a/src/lib/ems1.c b/src/lib/ems1.c
new file mode 100644 (file)
index 0000000..dd9ebe5
--- /dev/null
@@ -0,0 +1,110 @@
+#if !defined(__EMS_H)\r
+#define __EMS_H\r
+\r
+#define EMSPAGESIZE (4096)\r
+#define EMS_ERROR (-1)\r
+struct {\r
+  unsigned long length;\r
+  unsigned char source_type;\r
+  unsigned int source_handle;\r
+  unsigned int source_ofs; \r
+  unsigned int source_seg;\r
+  unsigned char dest_type;\r
+  unsigned int dest_handle;\r
+  unsigned int dest_ofs; \r
+  unsigned int dest_seg;\r
+} myEMSmove;\r
+\r
+\r
+void conv2ems(int PAGE, int HANDLE, char *output) {\r
+      char *x = (char *) &myEMSmove;\r
+      myEMSmove.length = EMSPAGESIZE;\r
+      myEMSmove.source_type = 0;\r
+      myEMSmove.source_handle = 0;\r
+      myEMSmove.source_ofs = FP_OFF(output);\r
+      myEMSmove.source_seg = FP_SEG(output);\r
+      myEMSmove.dest_type = 1;\r
+      myEMSmove.dest_handle = HANDLE;\r
+      myEMSmove.dest_ofs = (PAGE & 3) << 12;\r
+      myEMSmove.dest_seg = PAGE >> 2;\r
+      __asm push ds\r
+      __asm mov       ax, 5700h;        \r
+      __asm lds       si, x\r
+      __asm int       67h \r
+      __asm pop ds\r
+}\r
+\r
+void ems2conv(int PAGE, int HANDLE, char *output) {\r
+      char *x = (char *) &myEMSmove;\r
+      myEMSmove.length = EMSPAGESIZE;\r
+      myEMSmove.source_type = 1;\r
+      myEMSmove.source_handle = HANDLE;\r
+      myEMSmove.source_ofs = (PAGE & 3) << 12;\r
+      myEMSmove.source_seg = PAGE>>2;\r
+      myEMSmove.dest_type = 0;\r
+      myEMSmove.dest_handle = 0;\r
+      myEMSmove.dest_ofs = FP_OFF(output);\r
+      myEMSmove.dest_seg = FP_SEG(output);\r
+      __asm push ds\r
+      __asm mov       ax, 5700h\r
+      __asm lds       si, x\r
+      __asm int       67h \r
+      __asm pop ds\r
+}\r
+\r
+\r
+void freeEMS(int handle) {\r
+  __asm mov       dx, handle;\r
+  __asm mov       ah, 45h;    \r
+  __asm int       67h  \r
+}\r
+\r
+int checkEMS() {\r
+  char *x = "EMMXXXX0";\r
+  __asm {\r
+    mov ax, 3567h\r
+    int 21h\r
+    mov di, 10\r
+    mov si, offset x\r
+    mov cx, 4\r
+    rep cmpsw\r
+    je good \r
+  }\r
+  return -1;\r
+  good:\r
+  __asm {\r
+    sub     ax, ax\r
+    mov     ah, 40h\r
+    int     67h\r
+  }\r
+  return _AX;\r
+}\r
+\r
+int getavailEMS() {\r
+  __asm {\r
+    mov     ah, 42h\r
+    int     67h\r
+    cmp     ah, 00h\r
+    je      getavailEMS_Okay\r
+    mov     bx, -1\r
+  }\r
+  getavailEMS_Okay:\r
+  __asm shl bx, 2\r
+  return _BX;\r
+}\r
+\r
+int allocEMS(int pages) {\r
+  __asm {\r
+    mov     bx, pages\r
+    shr     bx, 2\r
+    mov     ah, 43h\r
+    int     67h\r
+    cmp     ah, 0\r
+    je      allocEMS_Okay\r
+    mov     dx, -1\r
+  }\r
+  allocEMS_Okay:\r
+  return _DX;\r
+}\r
+\r
+#endif\r