+ mov dx,OFFSET emmname //fix by andrius4669\r
+ mov ax,0x3d00\r
+ int EMM_INT // try to open EMMXXXX0 device\r
+ jc error1\r
+\r
+ mov bx,ax\r
+ mov ax,0x4400\r
+\r
+ int EMM_INT // get device info\r
+ jc error1\r
+\r
+ and dx,0x80\r
+ jz error1\r
+\r
+ mov ax,0x4407\r
+\r
+ int EMM_INT // get status\r
+ jc error1\r
+ or al,al\r
+ jz error1\r
+\r
+ mov ah,0x3e\r
+ int EMM_INT // close handle\r
+ jc error1\r
+\r
+ mov ah,EMS_STATUS\r
+ int EMS_INT\r
+ jc error1 // make sure EMS hardware is present\r
+\r
+ mov ah,EMS_VERSION\r
+ int EMS_INT // only work on EMS 3.2 or greater (silly, but...)\r
+ or ah,ah\r
+ jnz error1\r
+ mov [EMSVer],ax // set EMSVer\r
+ cmp al,0x32 // only work on ems 3.2 or greater\r
+ jb error1\r
+\r
+ mov ah,EMS_GETFRAME\r
+ int EMS_INT // find the page frame address\r
+ or ah,ah\r
+ jnz error1\r
+ mov [EMSPageFrame],bx\r
+\r
+ mov ah,EMS_GETPAGES\r
+ int EMS_INT // find out how much EMS is there\r
+ or ah,ah\r
+ jnz error1\r
+ or bx,bx\r
+ jz noEMS // no EMS at all to allocate\r
+ cmp bx,2\r
+ jl noEMS // Require at least 2 pages (32k)\r
+ mov [totalEMSpages],dx\r
+ mov [freeEMSpages],bx\r
+ mov [EMSAvail],bx\r
+ jmp End1\r