home *** CD-ROM | disk | FTP | other *** search
/ Power-Programmierung / CD1.mdf / assemblr / library / memory / sems / sems5.asm next >
Assembly Source File  |  1988-12-22  |  104KB  |  4,239 lines

  1.         PAGE    80,132
  2.         NAME    SEMS5
  3. ;************************************************************************
  4. ;*                                    *
  5. ;*                                    *
  6. ;*    EMM/EMS driver program for SUNTAC-62 chip set version B1    *
  7. ;*                                    *
  8. ;*            ONLY EVALUATION                    *
  9. ;*            SAMPLE PROGRAM                    *
  10. ;*                                    *
  11. ;*                Version 4.0/Release 1.x    12/22/1988    *
  12. ;*                                    *
  13. ;************************************************************************
  14.  
  15. ;
  16. ;    physical pages struct
  17. ;
  18. phys_page_struct        STRUC
  19.     emm_handle2            DW    ?    ;EMM handle
  20.     phys_page_port        DW    ?    ;physical page i/o port address
  21.     phys_seg_addr        DW    ?    ;physical page segment address
  22.     log_page_data        DB    ?    ;logical page no. data
  23. phys_page_struct        ENDS
  24.  
  25. handle_page_struct        STRUC
  26.     emm_handle3            DW    ?
  27.     page_alloc_to_handle    DW    ?
  28. handle_page_struct        ENDS
  29.  
  30. partial_page_map_struct        STRUC
  31.     mappable_segment_count    DW    ?
  32.     mappable_segment        DW    4 DUP (?)
  33. partial_page_map_struct        ENDS
  34.  
  35. log_to_phys_map_struct        STRUC
  36.     log_page_number1        DW    ?
  37.     phys_page_number1        DW    ?
  38. log_to_phys_map_struct        ENDS
  39.  
  40. log_to_seg_map_struct        STRUC
  41.     log_page_number2        DW    ?
  42.     mappable_seg_addr        DW    ?
  43. log_to_seg_map_struct        ENDS
  44.  
  45. handle_dir_struct        STRUC
  46.     handle_value        DW    ?
  47.     handle_name1        DB    8 DUP (?)
  48. handle_dir_struct        ENDS
  49.  
  50. map_and_jump_struct        STRUC
  51.     target_address1        DD    ?
  52.     log_phys_map_len        DB    ?
  53.     log_phys_map_ptr        DD    ?
  54. map_and_jump_struct        ENDS
  55.  
  56. map_and_call_struct        STRUC
  57.     target_address2        DD    ?
  58.     new_page_map_len        DB    ?
  59.     new_page_map_ptr        DD    ?
  60.     old_page_map_len        DB    ?
  61.     old_page_map_ptr        DD    ?
  62.     reserved            DW    4 DUP (?)
  63. map_and_call_struct        ENDS
  64.  
  65. move_source_dest_struct        STRUC
  66.     region_length1        DD    ?
  67.     source_memory_type1        DB    ?
  68.     source_handle1        DW    ?
  69.     source_initial_offset1    DW    ?
  70.     source_initial_seg_page1    DW    ?
  71.     dest_memory_type1        DB    ?
  72.     dest_handle1        DW    ?
  73.     dest_initial_offset1    DW    ?
  74.     dest_initial_seg_page1    DW    ?
  75. move_source_dest_struct        ENDS
  76.  
  77. xchg_source_dest_struct        STRUC
  78.     region_length2        DD    ?
  79.     source_memory_type2        DB    ?
  80.     source_handle2        DW    ?
  81.     source_initial_offset2    DW    ?
  82.     source_initial_seg_page2    DW    ?
  83.     dest_memory_type2        DB    ?
  84.     dest_handle2        DW    ?
  85.     dest_initial_offset2    DW    ?
  86.     dest_initial_seg_page2    DW    ?
  87. xchg_source_dest_struct        ENDS
  88.  
  89. mappable_phys_page_struct    STRUC
  90.     phys_page_segment        DW    ?
  91.     phys_page_number2        DW    ?
  92. mappable_phys_page_struct    ENDS
  93.  
  94. hardware_info_struct        STRUC
  95.     raw_page_size        DW    ?
  96.     alternate_register_sets    DW    ?
  97.     context_save_area_size    DW    ?
  98.     DMA_register_sets        DW    ?
  99.     DMA_channel_operation    DW    ?
  100. hardware_info_struct        ENDS
  101.  
  102. HANDLE_CNT        EQU    255    ;max handle count
  103. PAGE_MAX        EQU    216    ;max logical page count
  104. BACK_MAX        EQU    40    ;max mapping data backup count
  105. EMSIOA            EQU    0E8H    ;EMS i/o port address A
  106. EMSIOB            EQU    98H    ;EMS i/o port address B
  107. CHKIOA            EQU    9DH    ;EMS i/o port A check data
  108. CHKIOB            EQU    93H    ;EMS i/o port B check data
  109. I8042            EQU    60H    ;i8042 i/o port address
  110. TIME_OUT        EQU    1000    ;
  111. STATSEG            EQU    0C000H    ;defult start page frame address
  112. ROMSEG            EQU    0F000H    ;option ROM area segment address
  113. ENDSEG            EQU    0F000H    ;BIOS ROM area segment address
  114. NOT_USE            EQU    0AA55H    ;not used logical page code
  115. NON            EQU    0FFFFH    ;non or bad logical page code
  116. CR            EQU    0DH    ;Carriage Return code
  117. LF            EQU    0AH    ;Line Feed code
  118. TAB            EQU    09H    ;TAB code
  119. MEMSIZE            EQU    413H    ;system memory size data area address
  120. DIS_EMS            EQU    0    ;physical page disable data
  121. EMSVER            EQU    40H    ;EMS version 4.0
  122. HANDLE_NAME_SIZE    EQU    8    ;EMM handle name byte size
  123. UNMAP            EQU    0FFFFH    ;unmap code
  124. UNALLOC            EQU    0FFFFH    ;unallocate code
  125. PUSH_REG        EQU    8 * 2    ;push register size
  126. EMMWORK            EQU    50    ;EMM driver work area size
  127. RET_SP            EQU    EMMWORK+PUSH_REG+6+10    ;int67 stack size
  128. PHYS_PAGES        EQU    4    ;physical page count
  129. RAW_PAGES        EQU    400H    ;raw page size (16KB)
  130. CONTEXT_SIZE        EQU    SIZE phys_page_struct * PHYS_PAGES
  131. ALTER_REGS        EQU    0    ;alter map register set count
  132. DMA_REGS        EQU    0    ;alter DMA register set count
  133. DMA_CHANNEL        EQU    0    ;DMA channel number
  134. VOLATILE        EQU    0    ;volatile
  135. NON_VOLATILE        EQU    1    ;non volatile
  136. F23_RETSP        EQU    10    ;
  137. LOG_SIZE        EQU    2    ;logical page flag data size
  138. FLAG_SIZE        EQU    2    ;handle flag size
  139.  
  140. ;
  141. ;    function 15 struct
  142. ;
  143. f15_struct            STRUC
  144.                 DW    8 DUP (?)
  145.     f15_map_data        DB    CONTEXT_SIZE DUP (?)
  146. f15_struct            ENDS
  147.  
  148. ;
  149. ;    function 16 struct
  150. ;
  151. f16_struct            STRUC
  152.                 DW    8 DUP (?)
  153.     f16_map_len            DW    ?
  154.     f16_map_data        DB    CONTEXT_SIZE DUP (?)
  155. f16_struct            ENDS
  156.  
  157. ;
  158. ;    function 17 struct
  159. ;
  160. f17_struct            STRUC
  161.                 DW    8 DUP (?)
  162.     f17_ax_save            DW    ?
  163.     f17_map_len            DW    ?
  164.     f17_map_data        DB    PHYS_PAGES * 4 DUP (?)
  165. f17_struct            ENDS
  166.  
  167. ;
  168. ;    function 22 struct
  169. ;
  170. f22_struct            STRUC
  171.                 DW    8 DUP (?)
  172.     f22_ax_save            DW    ?
  173.     f22_target_off        DW    ?
  174.     f22_target_seg        DW    ?
  175.     f22_map_len            DW    ?
  176.     f22_map_data        DB    PHYS_PAGES * 4 DUP (?)
  177. f22_struct            ENDS
  178.  
  179. ;
  180. ;    function 23 struct
  181. ;
  182. f23_struct            STRUC
  183.                 DW    8 DUP (?)
  184.     f23_target_off        DW    ?
  185.     f23_target_seg        DW    ?
  186.     f23_flag            DW    ?
  187.     f23_retoff            DW    ?
  188.     f23_retseg            DW    ?
  189.     f23_ax_save            DW    ?
  190.     f23_new_map_len        DW    ?
  191.     f23_new_map_data        DB    PHYS_PAGES * 4 DUP (?)
  192.     f23_old_map_len        DW    ?
  193.     f23_old_map_data        DB    PHYS_PAGES * 4 DUP (?)
  194. f23_struct            ENDS
  195.  
  196. ;
  197. ;    function 24 struct
  198. ;
  199. f24_struct            STRUC
  200.                 DW    8 DUP (?)
  201.     source_off            DW    ?
  202.     source_seg            DW    ?
  203.     dest_off            DW    ?
  204.     dest_seg            DW    ?
  205.     source_pno            DW    ?
  206.     dest_pno            DW    ?
  207.     region_low            DW    ?
  208.     region_high            DW    ?
  209.     source_handle        DW    ?
  210.     dest_handle            DW    ?
  211.     source_type            DW    ?
  212.     dest_type            DW    ?
  213.     f24_ax_save            DW    ?
  214.     overlap_flag        DW    ?
  215.     get_source_f        DW    ?
  216.     get_dest_f            DW    ?
  217. f24_struct            ENDS
  218.  
  219. ;
  220. ;    function 28 struct
  221. ;
  222. f28_struct            STRUC
  223.                 DW    8 DUP (?)
  224.     f28_map_data        DB    CONTEXT_SIZE DUP (?)
  225. f28_struct            ENDS
  226.  
  227. ;
  228. ;    register back area struct
  229. ;
  230. retreg        STRUC
  231.     bx_save    DW    ?            ;BX save area
  232.     cx_save    DW    ?            ;CX save area
  233.     dx_save    DW    ?            ;DX save area
  234.     si_save    DW    ?            ;SI save area
  235.     di_save    DW    ?            ;DI save area
  236.     bp_save    DW    ?            ;BP save area
  237.     es_save    DW    ?            ;ES save area
  238.     ds_save    DW    ?            ;DS save area
  239. retreg        ENDS
  240.  
  241. ;
  242. ;    return address struct
  243. ;
  244. ret_struct    STRUC
  245.         DW    8 DUP (?)
  246.         DB    EMMWORK DUP (?)
  247.     ret_offset    DW    ?            ;return offset address
  248.     ret_segment    DW    ?            ;return segment address
  249.     ret_flag    DW    ?            ;return flags
  250. ret_struct    ENDS
  251.  
  252. ;-- EMS REGISTERS -----------------------------------------------------------:
  253. ;                                         :
  254. ; EMS_R0 : 76543210 (Read/Write)                         :
  255. ;          |+-----+--- EMS i/o port address A9 - A3 (defult 13H or 1DH)         :
  256. ;          |                                        * 13H(98H),1DH(E8H)      :
  257. ;          +-(Write)-- [98H/E8H] port read flag (0:not read, 1:read)         :
  258. ;          +-(Read)--- Register data transmit flag (0:end, 1:not end)         :
  259. ;                                         :
  260. ; EMS_R1 : 76543210 (Reserved)                             :
  261. ;                                         :
  262. ; EMS_R2 : 76543210 (Write only)                         :
  263. ;          |    |++--- EMS flag (00:EMS enable , 11:EMS disable)         :
  264. ;          +----+----- System memory size A19 - A14 (A0H = 640KB)         : 
  265. ;                                         :
  266. ; EMS_R3 : 76543210 (Write only)                         :
  267. ;          |    |++--- Bank size (00:16KB)                     :
  268. ;          +----+----- EMS page frame segment address A19 - A14 (C0H = C000H):
  269. ;                                         :
  270. ; EMS_R4 : 76543210 (Write only)                         :
  271. ;          +------+--- Bank 0 page number data (1 - 255)             :
  272. ;               * Data 0 = bank 0 disable                 :
  273. ;                                         :
  274. ; EMS_R5 : 76543210 (Write only)                         :
  275. ;          +------+--- Bank 1 page number data (1 - 255)             :
  276. ;               * Data 0 = bank 1 disable                 :
  277. ;                                         :
  278. ; EMS_R6 : 76543210 (Write only)                         :
  279. ;          +------+--- Bank 2 page number data (1 - 255)             :
  280. ;               * Data 0 = bank 2 disable                 :
  281. ;                                         :
  282. ; EMS_R7 : 76543210 (Write only)                         :
  283. ;          +------+--- Bank 3 page number data (1 - 255)             :
  284. ;               * Data 0 = bank 3 disable                 :
  285. ;                                         :
  286. ;----------------------------------------------------------------------------:
  287.  
  288.  
  289. code        SEGMENT
  290.         ASSUME    CS:code
  291.  
  292.         ORG    0000H
  293.  
  294.         ; DEVICE header block
  295. emmdrv        DW    -1,-1        ;Link to next device
  296.         DW    8000H        ;
  297.         DW    OFFSET emmstat    ;
  298.         DW    OFFSET emmint    ;
  299.         DB    'EMMXXXX0'    ;
  300.  
  301. ptrsav        LABEL    DWORD
  302. parofs        DW    0        ;
  303. parseg        DW    0        ;
  304.  
  305. page_frame_seg    DW    0C000H        ;physical page frame address
  306. total_pages    DW    PAGE_MAX    ;total logical page count
  307. un_alloc_pages    DW    PAGE_MAX    ;unallocate logical page count
  308. handle_count    DW    0        ;EMM handle used count
  309. jump_addr    DW    0        ;EMM function jump address data area
  310. emm_flag    DB    0        ;EMM driver install status
  311.  
  312. ;
  313. ;    Define offsets for io data packet
  314. ;
  315. iodat        STRUC    
  316.     cmdlen    DB    ?    ;LENGTH OF THIS COMMAND
  317.     unit    DB    ?    ;SUB UNIT SPECIFIER
  318.     cmd    DB    ?    ;COMMAND CODE
  319.     status    DW    ?    ;STATUS
  320.         DB    8 DUP (?)
  321.     media    DB    ?    ;MEDIA DESCRIPTOR
  322.     trans    DD    ?    ;TRANSFER ADDRESS
  323.     count    DW    ?    ;COUNT OF BLOCKS OR CHARACTERS
  324.     start    DW    ?    ;FIRST BLOCK TO TRANSFER
  325. iodat        ENDS
  326.  
  327. ;
  328. ;    Define offsets for io data packet 2
  329. ;
  330. iodat2        STRUC
  331.         DB    13 DUP (?)
  332.         DB    ?
  333.     brkoff    DW    ?    ;BREAK ADDRESS (OFFSET)
  334.     brkseg    DW    ?    ;BREAK ADDRESS (SEGMENT)
  335. iodat2        ENDS
  336.  
  337. ;
  338. ; Simplistic Strategy routine for non-multi-Tasking system.
  339. ;
  340. ;    Currently just saves I/O packet pointers in PTRSAV for
  341. ;    later processing by the individual interrupt routines.
  342. ;
  343. emmstat        PROC    FAR
  344.         MOV    CS:parofs,BX    ;
  345.         MOV    CS:parseg,ES    ;
  346.         RET            ;
  347. emmstat        ENDP
  348.  
  349. ;
  350. ; Common program for handling the simplistic I/O packet
  351. ;    processing scheme in MSDOS
  352. ;
  353. emmint        PROC    FAR
  354.         PUSH    AX        ;Save all nessacary registers.
  355.         PUSH    BX        ;
  356.         PUSH    DI        ;
  357.         PUSH    DS        ;
  358.         LDS    BX,CS:ptrsav    ;Retrieve pointer to I/O Packet.
  359.         MOV    AL,[BX].cmd    ;Retrieve Command type. (1 => 11)
  360.         CMP    AL,11        ;Verify that not more than 11 commands.
  361.         JA    cmderr        ;Ah, well, error out.
  362.         CMP    AL,3        ;
  363.         JA    exit        ;
  364.         CMP    AL,0        ;init. command?
  365.         JNZ    emmchk        ;check EMS flag.
  366.         JMP    emminit        ;EMS Driver initial.
  367. cmderr:                    ;
  368.         MOV    AL,3        ;Set unknown command error #.
  369. err_exit:                ;
  370.         MOV    AH,10000001B    ;Set error and done bits.
  371.         STC            ;Set carry bit also.
  372.         JMP    exit1        ;Quick way out.
  373. ;
  374. ;    EMM driver install check routine
  375. ;
  376. emmchk:                    ;
  377.         CMP    CS:emm_flag,1    ;EMM install flag on?
  378.         JNZ    err_exit    ;no
  379. exit:                    ;
  380.         MOV    AH,00000001B    ;Set done bit for MSDOS.
  381. exit1:                    ;
  382.         LDS    BX,CS:ptrsav    ;Retrieve pointer to I/O Packet.
  383.         MOV    [BX].status,AX    ;Save operation compete and status.
  384.         POP    DS        ;Restore registers.
  385.         POP    DI        ;
  386.         POP    BX        ;
  387.         POP    AX        ;
  388.         RET            ;
  389. emmint        ENDP
  390.  
  391. ;+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
  392.  
  393. ;--------------------------------------------------------------------
  394. ;    int 67H EMM driver main routine
  395. ;--------------------------------------------------------------------
  396. int67        PROC    FAR
  397.         CLI                ;
  398.         SUB    SP,EMMWORK        ;
  399.         PUSH    DS            ;Save registers...
  400.         PUSH    ES            ;
  401.         PUSH    BP            ;
  402.         PUSH    DI            ;
  403.         PUSH    SI            ;
  404.         PUSH    DX            ;
  405.         PUSH    CX            ;
  406.         PUSH    BX            ;
  407.         MOV    BP,SP            ;
  408.         CLD                ;
  409.         PUSH    CS            ;
  410.         POP    DS            ;
  411.  
  412.         ASSUME    DS:code
  413.  
  414.         CMP    AH,40H            ;--- function code check ---
  415.         JB    err84            ; FUNCTION 1 - 30 ?
  416.         CMP    AH,5EH            ;
  417.         JNB    err84            ;---------------------------
  418.         PUSH    BX            ;
  419.         MOV    jump_addr,AX        ;
  420.         XCHG    AH,AL            ;
  421.         XOR    AH,AH            ;
  422.         SUB    AX,40H            ;
  423.         SHL    AX,1            ;
  424.         MOV    BX,OFFSET func_table    ;
  425.         ADD    BX,AX            ;
  426.         MOV    AX,[BX]            ;
  427.         XCHG    AX,jump_addr        ;
  428.         POP    BX            ;
  429.         JMP    jump_addr        ;---- jump to functions -----
  430. noerr:                        ;normal return point.
  431.         XOR    AH,AH            ;
  432. err_ret:                    ;error return point.
  433.         POP    BX            ;Restore registers...
  434.         POP    CX            ;
  435.         POP    DX            ;
  436.         POP    SI            ;
  437.         POP    DI            ;
  438.         POP    BP            ;
  439.         POP    ES            ;
  440.         POP    DS            ;
  441.         ADD    SP,EMMWORK        ;
  442.         IRET                ;
  443. int67        ENDP
  444.  
  445. ;--------------------------------------------------------------------
  446. ;    EMM driver function jump table
  447. ;        (40H - 5DH)
  448. ;--------------------------------------------------------------------
  449. func_table    LABEL    WORD
  450.         DW    OFFSET func1        ;function 1
  451.         DW    OFFSET func2        ;function 2
  452.         DW    OFFSET func3        ;function 3
  453.         DW    OFFSET func4        ;function 4
  454.         DW    OFFSET func5        ;function 5
  455.         DW    OFFSET func6        ;function 6
  456.         DW    OFFSET func7        ;function 7
  457.         DW    OFFSET func8        ;function 8
  458.         DW    OFFSET func9        ;function 9
  459.         DW    OFFSET func10        ;function 10
  460.         DW    OFFSET func11        ;function 11
  461.         DW    OFFSET func12        ;function 12
  462.         DW    OFFSET func13        ;function 13
  463.         DW    OFFSET func14        ;function 14
  464.         DW    OFFSET func15        ;function 15
  465.         DW    OFFSET func16        ;function 16
  466.         DW    OFFSET func17        ;function 17
  467.         DW    OFFSET func18        ;function 18
  468.         DW    OFFSET func19        ;function 19
  469.         DW    OFFSET func20        ;function 20
  470.         DW    OFFSET func21        ;function 21
  471.         DW    OFFSET func22        ;function 22
  472.         DW    OFFSET func23        ;function 23
  473.         DW    OFFSET func24        ;function 24
  474.         DW    OFFSET func25        ;function 25
  475.         DW    OFFSET func26        ;function 26
  476.         DW    OFFSET func27        ;function 27
  477.         DW    OFFSET func28        ;function 28
  478.         DW    OFFSET func29        ;function 29
  479.         DW    OFFSET func30        ;function 30
  480.  
  481. ;--------------------------------------------------------------------
  482. ;    error status set routine
  483. ;--------------------------------------------------------------------
  484.  
  485. ;The manager detected a malfunction in the EMM software.
  486. err80:
  487.         MOV    AH,80H
  488.         JMP    err_ret
  489.  
  490. ;The manager detected a malfunction in the expanded memory hardware.
  491. err81:
  492.         MOV    AH,81H
  493.         JMP    err_ret
  494.  
  495. ;The EMM couldn't find the EMM handle your program specified.
  496. err83:
  497.         MOV    AH,83H
  498.         JMP    err_ret
  499.  
  500. ;The function code passed to the EMM is not defined.
  501. err84:
  502.         MOV    AH,84H
  503.         JMP    err_ret
  504.  
  505. ;All EMM handles are being used.
  506. err85:
  507.         MOV    AH,85H
  508.         JMP    err_ret
  509.  
  510. ;The EMM detected a "save" or "restore" page mapping context error.
  511. err86:
  512.         MOV    AH,86H
  513.         JMP    err_ret
  514.  
  515. ;There aren't enough expanded memory pages to satisfy your program's request.
  516. err87:
  517.         MOV    AH,87H
  518.         JMP    err_ret
  519.  
  520. ;There aren't enough unallocated pages to satisfy your program's request.
  521. err88:
  522.         MOV    AH,88H
  523.         JMP    err_ret
  524.  
  525. ;Can't allocate zero (0) pages.
  526. err89:
  527.         MOV    AH,89H
  528.         JMP    err_ret
  529.  
  530. ;The logical page is out of the range of logical pages which are allocated to
  531. ;the EMM handle.
  532. err8a:
  533.         MOV    AH,8AH
  534.         JMP    err_ret
  535.  
  536. ;The physical page to which the logical page is mapped is out of the range of
  537. ;physical pages.
  538. err8b:
  539.         MOV    AH,8BH
  540.         JMP    err_ret
  541.  
  542. ;The page mapping hardware state save area is full.
  543. err8c:
  544.         MOV    AH,8CH
  545.         JMP    err_ret
  546.  
  547. ;The page mapping hardware state save area already has a state associated with
  548. ;the EMM handle.
  549. err8d:
  550.         MOV    AH,8DH
  551.         JMP    err_ret
  552.  
  553. ;The page mapping hardware state save area doesn't have a state associated with
  554. ;the EMM handle.
  555. err8e:
  556.         MOV    AH,8EH
  557.         JMP    err_ret
  558.  
  559. ;The subfunction parameter passed to the function isn't defined.
  560. err8f:
  561.         MOV    AH,8FH
  562.         JMP    err_ret
  563.  
  564. ;The attrbute type is undefined.
  565. err90:
  566.         MOV    AH,90H
  567.         JMP    err_ret
  568.  
  569. ;The system configuration does not support non_volatility.
  570. err91:
  571.         MOV    AH,91H
  572.         JMP    err_ret
  573.  
  574. ;The source and destination expanded memory region have the same handle and
  575. ;overlap. (move)
  576. err92:
  577.         MOV    AH,92H
  578.         JMP    err_ret
  579.  
  580. ;The length of the specified source or destination expanded memory region
  581. ;exceeds the length of the expanded memory region allocated to the specified
  582. ;source or destination handle.
  583. err93:
  584.         MOV    AH,93H
  585.         JMP    err_ret
  586.  
  587. ;The conventional memory region and expanded memory region overlap.
  588. err94:
  589.         MOV    AH,94H
  590.         JMP    err_ret
  591.  
  592. ;The offset within the logical page exceeds the length of the logical page.
  593. err95:
  594.         MOV    AH,95H
  595.         JMP    err_ret
  596.  
  597. ;Region length exceeds 1M_byte limit.
  598. err96:
  599.         MOV    AH,96H
  600.         JMP    err_ret
  601.  
  602. ;The source and destination expanded memory region have the same handle and
  603. ;overlap. (exchanged)
  604. err97:
  605.         MOV    AH,97H
  606.         JMP    err_ret
  607.  
  608. ;The memory source and destination type are undefined/not supported.
  609. err98:
  610.         MOV    AH,98H
  611.         JMP    err_ret
  612.  
  613. ;Alternate map register serts are supported, but the alternate map register set
  614. ;specified is not support.
  615. err9a:
  616.         MOV    AH,9AH
  617.         JMP    err_ret
  618.  
  619. ;Alternate map/DMA register sets are supported. However, all alternate map/DMA
  620. ;register sets are currently allocated.
  621. err9b:
  622.         MOV    AH,9BH
  623.         JMP    err_ret
  624.  
  625. ;Alternate map/DMA register sets are not supported, and the alternate map/DMA
  626. ;register set specified is not zero.
  627. err9c:
  628.         MOV    AH,9CH
  629.         JMP    err_ret
  630.  
  631. ;Alternate map register serts are supported, but the alternate map register set
  632. ;specified is not defined, not allocated, or is the currently allocated map
  633. ;register set.
  634. err9d:
  635.         MOV    AH,9DH
  636.         JMP    err_ret
  637.  
  638. ;Dedicated DMA channels are not supported.
  639. err9e:
  640.         MOV    AH,9EH
  641.         JMP    err_ret
  642.  
  643. ;Dedicated DMA channels are not supported. But the DMA channel specified is not
  644. ;supported.
  645. err9f:
  646.         MOV    AH,9FH
  647.         JMP    err_ret
  648.  
  649. ;No corresponding handle value could be found for the handle name specified.
  650. erra0:
  651.         MOV    AH,0A0H
  652.         JMP    err_ret
  653.  
  654. ;A handle with this name already exists.
  655. erra1:
  656.         MOV    AH,0A1H
  657.         JMP    err_ret
  658.  
  659. ;An attempt was made to "wrap around" the 1M_byte address space during the
  660. ;move/exchange.
  661. erra2:
  662.         MOV    AH,0A2H
  663.         JMP    err_ret
  664.  
  665. ;The contents of the data structure passed to the function have either been
  666. ;corrupted or are meaningless.
  667. erra3:
  668.         MOV    AH,0A3H
  669.         JMP    err_ret
  670.  
  671. ;The operating system has denied access to the this function.
  672. erra4:
  673.         MOV    AH,0A4H
  674.         JMP    err_ret
  675.  
  676. ;------ function 1 --------------------------------------------------
  677. ; Get status
  678. ; output
  679. ;    AH    : status
  680. ;--------------------------------------------------------------------
  681. func1:
  682.         STI                ;
  683.         CMP    emm_flag,1        ;EMM install flag on?
  684.         JNZ    f11            ;no
  685.         JMP    noerr            ;exit
  686. f11:                        ;
  687.         JMP    err80            ;error exit
  688.  
  689. ;------ function 2 --------------------------------------------------
  690. ; Get page frame address
  691. ; output
  692. ;    AH    : status
  693. ;    BX    : page segment address
  694. ;--------------------------------------------------------------------
  695. func2:
  696.         STI                ;
  697.         MOV    BX,page_frame_seg    ;get EMM physical page segment
  698. f21:                        ; address.
  699.         MOV    [BP].bx_save,BX        ;
  700.         JMP    noerr            ;exit
  701.  
  702. ;------ function 3 --------------------------------------------------
  703. ; Get unallocated page count
  704. ; output
  705. ;    AH    : status
  706. ;    BX    : unallocate page
  707. ;    DX    : all page
  708. ;--------------------------------------------------------------------
  709. func3:                        ;v0.5....
  710.         MOV    DX,total_pages        ;Get total page count
  711.         MOV    BX,un_alloc_pages    ;Get unallocated page count
  712.         MOV    [BP].dx_save,DX        ;Save all page count
  713.         JMP    f21            ;
  714.  
  715. ;------ function 4 --------------------------------------------------
  716. ; Allocate pages
  717. ; input
  718. ;    BX    : request allocate page
  719. ; output
  720. ;    AH    : status
  721. ;    DX    : EMM handle
  722. ;--------------------------------------------------------------------
  723. func4:                        ;v0.6....
  724.         OR    BX,BX            ;request page size 0 ?
  725.         JZ    f49            ;yes
  726. f41:                        ;
  727.         CMP    total_pages,BX        ;request total size over ?
  728.         JB    f42            ;yes
  729.         CMP    un_alloc_pages,BX    ;request unallocate size over ?
  730.         JB    f43            ;yes
  731.         XOR    DX,DX            ;
  732.         XOR    SI,SI            ;
  733.         MOV    CX,HANDLE_CNT        ;
  734. f45:                        ;
  735.         CMP    [SI].handle_flag,0    ;not used EMM handle ?
  736.         JZ    f44            ;
  737.         INC    DX            ;
  738.         ADD    SI,FLAG_SIZE        ;add handle flag size
  739.         LOOP    f45            ;
  740.         JMP    err85            ;error exit
  741. f44:                        ;
  742.         MOV    [SI].handle_flag,1    ;handle active flag set
  743.         INC    handle_count        ;used EMM handle count up
  744.         SUB    un_alloc_pages,BX    ;unallocated page - BX
  745.         MOV    [SI].alloc_page_count,BX;EMM handle used page count set
  746.         MOV    [SI].back_address,0    ;backup address clear
  747.         MOV    DI,page_ptr        ;
  748.         MOV    [SI].page_address,DI    ;set page buffer pointer
  749.         PUSH    CS            ;
  750.         POP    ES            ;
  751.         MOV    SI,OFFSET log_page    ;
  752.         XOR    AX,AX            ;
  753.         MOV    CX,BX            ;
  754.         JCXZ    f48            ;CX = 0?
  755. f47:                        ;
  756.         CMP    WORD PTR [SI],NOT_USE    ;unallocated page ?
  757.         JZ    f46            ;
  758. f4a:                        ;
  759.         ADD    SI,LOG_SIZE        ;
  760.         INC    AX            ;
  761.         JMP    f47            ;
  762. f46:                        ;
  763.         MOV    [SI],DX            ;EMM handle set
  764.         STOSW                ;logical page no. set
  765.         LOOP    f4a            ;
  766. f48:                        ;
  767.         MOV    [BP].dx_save,DX        ;return EMM handle
  768.         MOV    [BP].bx_save,BX        ;allocated pages count set
  769.         MOV    page_ptr,DI        ;
  770.         JMP    noerr            ;exit
  771. f49:                        ;
  772.         JMP    err89            ;error exit
  773. f42:                        ;
  774.         JMP    err87            ;error exit
  775. f43:                        ;
  776.         JMP    err88            ;error exit
  777.  
  778. ;------ function 5 --------------------------------------------------
  779. ; Map handle pages
  780. ; input
  781. ;    AL    : physical page no.
  782. ;    BX    : logical page no. (if BX=FFFFH then unmap)
  783. ;    DX    : EMM handle
  784. ; output
  785. ;    AH    : status
  786. ;--------------------------------------------------------------------
  787. func5:                        ;v0.6....
  788.         CMP    AL,PHYS_PAGES        ;physical page no. ok ?
  789.         JNB    f51            ;no
  790.         MOV    DI,OFFSET map_table    ;get phys_page_struct pointer..
  791.         XCHG    AL,CL            ;
  792.         MOV    AX,SIZE phys_page_struct;
  793.         MUL    CL            ;
  794.         ADD    DI,AX            ;
  795.         CMP    DX,HANDLE_CNT        ;check handle data...
  796.         JNB    f5a            ;
  797.         MOV    SI,DX            ;
  798.         SHL    SI,1            ;
  799.         CMP    [SI].handle_flag,0    ;active handle ?
  800.         JZ    f5a            ;
  801.         CMP    BX,UNMAP        ;unmap ?
  802.         JZ    f57            ;
  803.         CMP    BX,[SI].alloc_page_count;logical page no. OK ?
  804.         JNB    f53            ;
  805.         SHL    BX,1            ;
  806.         ADD    BX,[SI].page_address    ;
  807.         MOV    AX,[BX]            ;
  808.         ADD    AL,pageofs        ;
  809.         CMP    DX,[DI]            ;same handle ?
  810.         JNZ    f54            ;
  811.         CMP    AL,[DI].log_page_data    ;same page no. ?
  812.         JZ    f56            ;
  813. f54:                        ;
  814.         PUSH    DX            ;
  815.         MOV    DX,[DI].phys_page_port    ;
  816.         CALL    emsout            ;
  817.         POP    DX            ;
  818.         JB    f59            ;error?
  819. f58:                        ;
  820.         MOV    [DI],DX            ;set handle
  821.         MOV    [DI].log_page_data,AL    ;set logical page no. data
  822. f56:                        ;
  823.         JMP    noerr            ;exit
  824. f57:                        ;
  825.         XOR    AL,AL            ;
  826.         CMP    WORD PTR [DI],UNMAP    ;
  827.         JNZ    f55            ;
  828.         CMP    AL,[DI].log_page_data    ;
  829.         JZ    f56            ;
  830. f55:                        ;
  831.         MOV    DX,[DI].phys_page_port    ;unmapping...
  832.         CALL    emsout            ;
  833.         JB    f59            ;error?
  834.         MOV    DX,UNMAP        ;
  835.         JMP    f58            ;
  836. f51:                        ;
  837.         JMP    err8b            ;error exit
  838. f53:                        ;
  839.         JMP    err8a            ;error exit
  840. f59:                        ;
  841.         JMP    err81            ;error exit
  842. f5a:                        ;
  843.         JMP    err83            ;error exit 
  844.  
  845. ;------ function 6 --------------------------------------------------
  846. ; Deallocate pages
  847. ; input
  848. ;    DX    : EMM handle
  849. ; output
  850. ;    AH    : status
  851. ;--------------------------------------------------------------------
  852. f61:                        ;v0.6....
  853.         JMP    err83            ;error exit 
  854. f63:                        ;
  855.         JMP    err86            ;error exit 
  856. func6:                        ;
  857.         PUSH    CS            ;
  858.         POP    ES            ;
  859.         CMP    DX,HANDLE_CNT        ;check handle data...
  860.         JNB    f61            ;
  861.         MOV    BX,DX            ;
  862.         SHL    BX,1            ;
  863.         CMP    [BX].handle_flag,0    ;handle OK ?
  864.         JZ    f61            ;
  865.         CMP    [BX].back_address,0    ;backup used?
  866.         JNZ    f63            ;
  867.         MOV    CX,[BX].alloc_page_count;
  868.         JCXZ    f6c            ;page = 0 ?
  869.         MOV    DI,[BX].page_address    ;deallocate logical page...
  870.         PUSH    BX            ;
  871. f65:                        ;
  872.         MOV    BX,[DI]            ;
  873.         SHL    BX,1            ;
  874.         MOV    [BX].log_page,NOT_USE    ;
  875.         INC    un_alloc_pages        ;add unallocated pages
  876.         INC    DI            ;
  877.         INC    DI            ;
  878.         LOOP    f65            ;
  879.         POP    BX            ;
  880.         MOV    SI,DI            ;clear & sort page buffer...
  881.         MOV    DI,[BX].page_address    ;
  882.         MOV    CX,page_ptr        ;
  883.         SUB    CX,SI            ;
  884.         SHR    CX,1            ;
  885.         JCXZ    f62            ;
  886.         REPZ    MOVSW            ;
  887. f62:                        ;
  888.         MOV    CX,[BX].alloc_page_count;
  889.         JCXZ    f68            ;
  890.         MOV    AX,UNALLOC        ;
  891.         REPZ    STOSW            ;
  892. f68:                        ;
  893.         XOR    DI,DI            ;change page address....
  894.         MOV    SI,[BX].page_address    ;get page address.
  895.         MOV    AX,[BX].alloc_page_count;get allocated page count.
  896.         SHL    AX,1            ;
  897.         MOV    CX,handle_count        ;
  898. f66:                        ;
  899.         CMP    [DI].handle_flag,0    ;active handle ?
  900.         JZ    f6b            ;
  901.         CMP    [DI].page_address,SI    ;page_address > SI ?
  902.         JNG    f64            ;
  903.         SUB    [DI].page_address,AX    ;page address - AX
  904. f64:                        ;
  905.         LOOP    f6b            ;
  906.         SUB    page_ptr,AX        ;SUB page pointer
  907.         MOV    CX,PHYS_PAGES        ;deallocate physical page...
  908.         XOR    AL,AL            ;
  909.         MOV    SI,OFFSET map_table    ;
  910. f6a:                        ;
  911.         CMP    [SI],DX            ;same handle no.?
  912.         JNZ    f67            ;
  913.         CALL    reset_phys_page        ;reset physical page.
  914.         JNB    f67            ;error?
  915.         JMP    err81            ;error exit.
  916. f6b:                        ;
  917.         ADD    DI,FLAG_SIZE        ;
  918.         JMP    f66            ;
  919. f67:                        ;
  920.         INC    AL            ;
  921.         ADD    SI,SIZE phys_page_struct;
  922.         LOOP    f6a            ;
  923. f6c:                        ;
  924.         MOV    [BX].handle_flag,0    ;clear handle use flag
  925.         MOV    [BX].alloc_page_count,0    ;clear allocate page count
  926.         MOV    [BX].page_address,0    ;clear handle page pointer
  927.         MOV    [BX].back_address,0    ;clear handle back pointer
  928.         MOV    DI,OFFSET handle_name    ;clear handle name data...
  929.         MOV    AX,DX            ;
  930.         MOV    CL,3            ;
  931.         SHL    AX,CL            ;
  932.         ADD    DI,AX            ;
  933.         XOR    AL,AL            ;
  934.         MOV    CX,HANDLE_NAME_SIZE    ;
  935.         REPZ    STOSB            ;
  936.         CMP    DX,0            ;system handle?
  937.         JZ    f6d            ;
  938.         DEC    handle_count        ;not use handle count up
  939.         JMP    noerr            ;exit
  940. f6d:                        ;
  941.         MOV    [BX].handle_flag,1    ;
  942.         JMP    noerr            ;exit
  943.  
  944. ;------ function 7 --------------------------------------------------
  945. ; Get EMS version
  946. ; output
  947. ;    AH    : status
  948. ;    AL    : EMS version number
  949. ;--------------------------------------------------------------------
  950. func7:
  951.         STI                ;
  952.         MOV    AL,EMSVER        ;get version no.
  953.         JMP    noerr            ;
  954.  
  955. ;------ function 8 --------------------------------------------------
  956. ; Save page map
  957. ; input
  958. ;    DX    : EMM handle
  959. ; output
  960. ;    AH    : status
  961. ;--------------------------------------------------------------------
  962. func8:                        ;v0.6....
  963.         PUSH    CS            ;
  964.         POP    ES            ;
  965.         CMP    DX,HANDLE_CNT        ;check handle data
  966.         JNB    f81            ;
  967.         MOV    SI,DX            ;
  968.         SHL    SI,1            ;
  969.         CMP    [SI].handle_flag,1    ;handle OK ?
  970.         JNZ    f81            ;
  971.         CMP    [SI].back_address,0    ;backup ?
  972.         JNZ    f82            ;
  973.         MOV    AL,backup_count        ;
  974.         CMP    AL,BACK_MAX        ;
  975.         JB    f83            ;
  976.         JMP    err8c            ;error exit 
  977. f83:                        ;
  978.         MOV    DI,back_ptr        ;copy mapping data -> [DI]
  979.         MOV    [SI].back_address,DI    ;
  980.         MOV    SI,OFFSET map_table    ;
  981.         MOV    CX,CONTEXT_SIZE        ;
  982.         REPZ    MOVSB            ;
  983.         INC    backup_count        ;
  984.         MOV    back_ptr,DI        ;
  985.         JMP    noerr            ;exit
  986. f81:                        ;
  987.         JMP    err83            ;error exit 
  988. f82:                        ;
  989.         JMP    err8d            ;error exit 
  990.  
  991. ;------ function 9 --------------------------------------------------
  992. ; Restore page map
  993. ; input
  994. ;    DX    : EMM handle
  995. ; output
  996. ;    AH    : status
  997. ;--------------------------------------------------------------------
  998. f91:                        ;v0.6....
  999.         JMP    err83            ;error exit 
  1000. func9:                        ;
  1001.         PUSH    CS            ;
  1002.         POP    ES            ;
  1003.         CMP    DX,HANDLE_CNT        ;check handle data
  1004.         JNB    f91            ;
  1005.         MOV    BX,DX            ;
  1006.         SHL    BX,1            ;
  1007.         CMP    [BX].handle_flag,1    ;handle OK ?
  1008.         JNZ    f91            ;
  1009.         CMP    [BX].back_address,0    ;backup ?
  1010.         JZ    f92            ;
  1011.         MOV    DI,OFFSET map_table    ;disable physical pages...
  1012.         MOV    CX,PHYS_PAGES        ;
  1013. f93:                        ;
  1014.         MOV    DX,[DI].phys_page_port    ;
  1015.         MOV    AL,DIS_EMS        ;
  1016.         CALL    emsout            ;
  1017.         JB    f97            ;
  1018.         ADD    DI,SIZE phys_page_struct;
  1019.         LOOP    f93            ;
  1020.         MOV    CX,CONTEXT_SIZE        ;move mapping data...
  1021.         MOV    SI,[BX].back_address    ;
  1022.         MOV    DI,OFFSET map_table    ;
  1023.         PUSH    DI            ;
  1024.         REPZ    MOVSB            ;
  1025.         POP    DI            ;
  1026.         CALL    set_pages_map        ;enable physical pages...
  1027.         JB    f97            ;
  1028.         DEC    backup_count        ;backup mapping count DEC
  1029.         MOV    DI,[BX].back_address    ;clear & sort backup buffer...
  1030.         MOV    SI,CONTEXT_SIZE        ;
  1031.         ADD    SI,DI            ;
  1032.         MOV    CX,back_ptr        ;
  1033.         SUB    CX,SI            ;
  1034.         JCXZ    f96            ;
  1035.         REPZ    MOVSB            ;
  1036. f96:                        ;
  1037.         MOV    CX,CONTEXT_SIZE        ;
  1038.         MOV    AL,0FFH            ;
  1039.         REPZ    STOSB            ;
  1040.         MOV    SI,[BX].back_address    ;change backup address....
  1041.         MOV    [BX].back_address,0    ;
  1042.         XOR    DI,DI            ;
  1043.         MOV    AX,CONTEXT_SIZE        ;
  1044.         MOV    CX,HANDLE_CNT        ;
  1045. f95:                        ;
  1046.         CMP    [DI].handle_flag,0    ;
  1047.         JZ    f94            ;
  1048.         CMP    [DI].back_address,SI    ;
  1049.         JB    f94            ;
  1050.         SUB    [DI].back_address,AX    ;
  1051. f94:                        ;
  1052.         ADD    DI,FLAG_SIZE        ;
  1053.         LOOP    f95            ;
  1054.         SUB    back_ptr,AX        ;SUB backup pointer
  1055.         JMP    noerr            ;exit
  1056. f92:                        ;
  1057.         JMP    err8e            ;error exit 
  1058. f97:                        ;
  1059.         JMP    err81            ;error exit
  1060.  
  1061. ;------ function 10 -------------------------------------------------
  1062. ; Get page mapping register I/O port array
  1063. ; input
  1064. ;    ES:DI    : buffer address point
  1065. ; output
  1066. ;    AH    : status
  1067. ;    AL    : board count
  1068. ;--------------------------------------------------------------------
  1069. func10:
  1070.         STI                ;
  1071.         MOV    SI,OFFSET port_addr    ;
  1072.         MOV    CX,PHYS_PAGES        ;
  1073.         REPZ    MOVSW            ;
  1074.         MOV    AL,1            ;
  1075.         JMP    noerr            ;
  1076.  
  1077. ;------ function 11 -------------------------------------------------
  1078. ; Get logical-to-physical page translation array
  1079. ; input
  1080. ;    DX    : EMM handle
  1081. ;    ES:DI    : buffer address point
  1082. ; output
  1083. ;    AH    : status code
  1084. ;    BX    : number of pages allocated EMM handle.
  1085. ;--------------------------------------------------------------------
  1086. func11:
  1087.         STI                ;
  1088.         CMP    DX,HANDLE_CNT        ;check handle data
  1089.         JNB    f112            ;
  1090.         MOV    SI,DX            ;
  1091.         SHL    SI,1            ;
  1092.         CMP    [SI].handle_flag,1    ;
  1093.         JNZ    f112            ;
  1094.         MOV    CX,[SI].alloc_page_count;
  1095.         JCXZ    f112            ;
  1096.         MOV    BX,[SI].page_address    ;
  1097. f111:                        ;
  1098.         MOV    AX,[BX]            ;
  1099.         ADD    AL,pageofs        ;
  1100.         XCHG    AH,AL            ;
  1101.         STOSW                ;
  1102.         INC    BX            ;
  1103.         INC    BX            ;
  1104.         LOOP    f111            ;
  1105.         MOV    BX,[SI].alloc_page_count;
  1106.         MOV    [BP].bx_save,BX        ;
  1107.         JMP    noerr            ;exit
  1108. f112:                        ;
  1109.         JMP    err83            ;error exit 
  1110.  
  1111. ;------ function 12 -------------------------------------------------
  1112. ; Get EMM handle count
  1113. ; output
  1114. ;    AH    : status
  1115. ;    BX    : active EMM handles
  1116. ;--------------------------------------------------------------------
  1117. func12:
  1118.         STI                ;
  1119.         MOV    BX,handle_count        ;
  1120. f121:                        ;
  1121.         MOV    [BP].bx_save,BX        ;
  1122.         JMP    noerr            ;exit
  1123.  
  1124. ;------ function 13 -------------------------------------------------
  1125. ; Get EMM handle pages
  1126. ; input
  1127. ;    DX    : EMM handle
  1128. ; output
  1129. ;    AH    : status
  1130. ;    BX    : pages EMM handle
  1131. ;--------------------------------------------------------------------
  1132. func13:                        ;v0.6....
  1133.         STI                ;
  1134.         CMP    DX,HANDLE_CNT        ;check handle data
  1135.         JNB    f131            ;
  1136.         MOV    SI,DX            ;
  1137.         SHL    SI,1            ;
  1138.         CMP    [SI].handle_flag,1    ;handle OK ?
  1139.         JNZ    f131            ;
  1140.         MOV    BX,[SI].alloc_page_count;
  1141.         JMP    f121            ;exit
  1142. f131:                        ;
  1143.         JMP    err83            ;error exit 
  1144.  
  1145. ;------ function 14 -------------------------------------------------
  1146. ; Get all EMM handle pages
  1147. ; input
  1148. ;    ES:DI    : buffer address point
  1149. ; output
  1150. ;    AH    : status
  1151. ;    BX    : number of active EMM handles
  1152. ;--------------------------------------------------------------------
  1153. func14:
  1154.         STI                ;
  1155.         XOR    SI,SI            ;
  1156.         MOV    CX,HANDLE_CNT        ;
  1157.         XOR    BX,BX            ;
  1158.         XOR    DX,DX            ;
  1159. f142:                        ;
  1160.         CMP    [SI].handle_flag,0    ;
  1161.         JZ    f141            ;
  1162.         MOV    AX,DX            ;
  1163.         STOSW                ;
  1164.         MOV    AX,[SI].alloc_page_count;v0.5
  1165.         STOSW                ;
  1166.         INC    BX            ;
  1167. f141:                        ;
  1168.         INC    DX            ;
  1169.         ADD    SI,FLAG_SIZE        ;
  1170.         LOOP    f142            ;
  1171.         JMP    f121            ;
  1172.  
  1173. ;------ function 15 -------------------------------------------------
  1174. ; Get/set page map
  1175. ; input
  1176. ;    AL    : request subfunction no.
  1177. ;    ES:DI    : mapping registers buffer address point
  1178. ; output
  1179. ;    AH    : status
  1180. ;--------------------------------------------------------------------
  1181. func15:
  1182.         CMP    AL,0            ;
  1183.         JZ    get_page_map        ;
  1184.         CMP    AL,1            ;
  1185.         JZ    set_page_map        ;
  1186.         CMP    AL,2            ;
  1187.         JZ    get_set_page_map    ;
  1188.         CMP    AL,3            ;
  1189.         JZ    get_size_page_map    ;
  1190.         JMP    err84            ;error exit 
  1191.  
  1192. ;--------------------------------------------------------------------
  1193. ; Get page map.
  1194. ; input
  1195. ;    ES:DI    : dest_page_map
  1196. ; output
  1197. ;    AH    : status
  1198. ;--------------------------------------------------------------------
  1199. get_page_map:
  1200.         MOV    SI,OFFSET map_table    ;
  1201.         MOV    CX,CONTEXT_SIZE        ;
  1202.         REPZ    MOVSB            ;
  1203.         JMP    noerr            ;exit
  1204.  
  1205. ;--------------------------------------------------------------------
  1206. ; Set page map.
  1207. ; input
  1208. ;    DS:SI    : source_page_map
  1209. ; output
  1210. ;    AH    : status
  1211. ;--------------------------------------------------------------------
  1212. set_page_map:
  1213.         MOV    AX,[BP].ds_save        ;
  1214.         MOV    DS,AX            ;
  1215.         MOV    CX,CONTEXT_SIZE        ;
  1216.         MOV    AX,SS            ;
  1217.         MOV    ES,AX            ;
  1218.         LEA    DI,[BP].f15_map_data    ;save map data.
  1219.         REPZ    MOVSB            ;
  1220. set_page_map3:                    ;
  1221.         LEA    DI,[BP].f15_map_data    ;
  1222.         CALL    check_map_data        ;check map data (ES:DI)
  1223.         JNB    set_page_map2        ;
  1224.         JMP    erra3            ;error exit
  1225. set_page_map2:                    ;
  1226.         MOV    AX,ES            ;
  1227.         MOV    DS,AX            ;
  1228.         MOV    SI,DI            ;
  1229.         PUSH    CS            ;
  1230.         POP    ES            ;
  1231.         MOV    DI,OFFSET map_table    ;
  1232.         MOV    CX,CONTEXT_SIZE        ;
  1233.         REPZ    MOVSB            ;
  1234.         CALL    set_pages_map        ;mapping physical pages.
  1235.         JB    set_page_map1        ;
  1236.         JMP    noerr            ;exit
  1237. set_page_map1:                    ;
  1238.         JMP    err81            ;error exit
  1239.  
  1240. ;--------------------------------------------------------------------
  1241. ; Get & set page map.
  1242. ; input
  1243. ;    DS:SI    : source_page_map
  1244. ;    ES:DI    : dest_page_map
  1245. ; output
  1246. ;    AH    : status
  1247. ;--------------------------------------------------------------------
  1248. get_set_page_map:
  1249.         PUSH    DI            ;save map data...
  1250.         PUSH    DS            ;
  1251.         PUSH    ES            ;
  1252.         MOV    AX,[BP].ds_save        ;
  1253.         MOV    DS,AX            ;
  1254.         MOV    CX,CONTEXT_SIZE        ;
  1255.         MOV    AX,SS            ;
  1256.         MOV    ES,AX            ;
  1257.         LEA    DI,[BP].f15_map_data    ;
  1258.         REPZ    MOVSB            ;
  1259.         POP    ES            ;
  1260.         POP    DS            ;
  1261.         POP    DI            ;
  1262.         MOV    SI,OFFSET map_table    ;move current map data...
  1263.         MOV    CX,CONTEXT_SIZE        ;
  1264.         REPZ    MOVSB            ;
  1265.         MOV    AX,SS            ;
  1266.         MOV    ES,AX            ;
  1267.         JMP    set_page_map3        ;
  1268.  
  1269. ;--------------------------------------------------------------------
  1270. ; Get size of page map save array.
  1271. ; output
  1272. ;    AH    : status
  1273. ;    AL    : size_of_array
  1274. ;--------------------------------------------------------------------
  1275. get_size_page_map:
  1276.         MOV    AL,CONTEXT_SIZE        ;map data size set.
  1277.         JMP    noerr            ;
  1278.  
  1279. ;------ function 16 -------------------------------------------------
  1280. ; Get/set partial page map
  1281. ;--------------------------------------------------------------------
  1282. func16:
  1283.         CMP    AL,0            ;
  1284.         JZ    get_partial_map        ;
  1285.         CMP    AL,1            ;
  1286.         JZ    set_partial_map        ;
  1287.         CMP    AL,2            ;
  1288.         JZ    get_size_partial_map    ;
  1289.         JMP    err84            ;error exit 
  1290.  
  1291. ;--------------------------------------------------------------------
  1292. ; Get size of partial page map save array
  1293. ; input
  1294. ;    BX    : number of pages in the partial array
  1295. ; output
  1296. ;    AH    : status
  1297. ;    AL    : size_of_partial_save_array
  1298. ;--------------------------------------------------------------------
  1299. get_size_partial_map:
  1300.         OR    BX,BX            ;BX = 0?
  1301.         JZ    get_size_partial_map1    ;
  1302.         CMP    BX,PHYS_PAGES        ;BX > physical page count?
  1303.         JG    get_size_partial_map2    ;
  1304.         MOV    AX,SIZE phys_page_struct;get size of partial map array.
  1305.         MUL    BL            ;
  1306.         ADD    AX,2            ;
  1307.         JMP    noerr            ;exit
  1308. get_size_partial_map1:
  1309.         JMP    err8f            ;error exit
  1310. get_size_partial_map2:
  1311.         JMP    err8b            ;error exit
  1312.  
  1313. ;--------------------------------------------------------------------
  1314. ; Get partial page map
  1315. ; input
  1316. ;    DS:SI    : partial_page_map
  1317. ;    ES:DI    : dest_array
  1318. ; output
  1319. ;    AH    : status
  1320. ;--------------------------------------------------------------------
  1321. get_partial_map:
  1322.         MOV    AX,[BP].ds_save        ;
  1323.         MOV    DS,AX            ;
  1324.         LODSW                ;
  1325.         CMP    AX,PHYS_PAGES        ;
  1326.         JG    get_partial_map1    ;rel. 0.2
  1327.         MOV    CX,AX            ;
  1328.         JCXZ    get_partial_map5    ;page count = 0?
  1329.         STOSW                ;
  1330. get_partial_map4:
  1331.         LODSW                ;
  1332.         PUSH    CX            ;
  1333.         MOV    BX,OFFSET map_table    ;
  1334.         MOV    CX,PHYS_PAGES        ;
  1335. get_partial_map3:
  1336.         CMP    AX,CS:[BX].phys_seg_addr;
  1337.         JZ    get_partial_map2    ;
  1338.         ADD    BX,SIZE phys_page_struct;
  1339.         LOOP    get_partial_map3    ;
  1340.         POP    CX            ;
  1341.         JMP    err8b            ;error exit
  1342. get_partial_map2:
  1343.         PUSH    SI            ;move map data...
  1344.         PUSH    DS            ;
  1345.         PUSH    CS            ;
  1346.         POP    DS            ;
  1347.         MOV    SI,BX            ;
  1348.         MOV    CX,SIZE phys_page_struct;
  1349.         REPZ    MOVSB            ;
  1350.         POP    DS            ;
  1351.         POP    SI            ;
  1352.         POP    CX            ;
  1353.         LOOP    get_partial_map4    ;
  1354. get_partial_map5:
  1355.         JMP    noerr            ;exit
  1356. get_partial_map1:
  1357.         JMP    erra4            ;error exit
  1358.  
  1359. ;--------------------------------------------------------------------
  1360. ; Set partial page map
  1361. ; input
  1362. ;    DS:SI    : source_array
  1363. ; output
  1364. ;    AH    : status
  1365. ;--------------------------------------------------------------------
  1366. set_partial_map:
  1367.         MOV    AX,[BP].ds_save        ;
  1368.         MOV    DS,AX            ;
  1369.         LODSW                ;
  1370.         MOV    [BP].f16_map_len,AX    ;save page map data length.
  1371.         MOV    CX,SIZE phys_page_struct;
  1372.         MUL    CL            ;
  1373.         MOV    CX,AX            ;
  1374.         JCXZ    set_partial_map1    ;
  1375.         MOV    AX,SS            ;save page map data...
  1376.         MOV    ES,AX            ;
  1377.         LEA    DI,[BP].f16_map_data    ;
  1378.         REPZ    MOVSB            ;
  1379.         LEA    SI,[BP].f16_map_data    ;set page map data...
  1380.         MOV    AX,ES            ;
  1381.         MOV    DS,AX            ;
  1382.         MOV    AX,CS            ;
  1383.         MOV    ES,AX            ;
  1384.         MOV    CX,[BP].f16_map_len    ;get page map data length.
  1385. set_partial_map4:
  1386.         MOV    AX,[SI].phys_seg_addr    ;
  1387.         CALL    change_seg_page        ;change segment -> phys_page_no
  1388.         JB    set_partial_map3    ;
  1389.         MOV    DI,OFFSET map_table    ;
  1390.         PUSH    CX            ;
  1391.         MOV    CX,SIZE phys_page_struct;
  1392.         MUL    CL            ;
  1393.         ADD    DI,AX            ;
  1394.         REPZ    MOVSB            ;
  1395.         POP    CX            ;
  1396.         LOOP    set_partial_map4    ;
  1397.         CALL    set_pages_map        ;mapping physical pages.
  1398.         JB    set_partial_map2    ;
  1399. set_partial_map1:
  1400.         JMP    noerr            ;exit
  1401. set_partial_map2:
  1402.         JMP    err81            ;error exit
  1403. set_partial_map3:
  1404.         JMP    err8b            ;error exit 
  1405.  
  1406. ;------ function 17 -------------------------------------------------
  1407. ; Map/unmap multiple handle pages
  1408. ;--------------------------------------------------------------------
  1409. func17:
  1410.         STI                ;
  1411.         CMP    AL,0            ;
  1412.         JZ    log_phys_map        ;
  1413.         CMP    AL,1            ;
  1414.         JZ    log_phys_map        ;
  1415.         JMP    err84            ;error exit 
  1416.  
  1417. ;--------------------------------------------------------------------
  1418. ; Logical page/physical page/segment method
  1419. ; input
  1420. ;    AL    : physical page/segment selector
  1421. ;    DX    : EMM handle
  1422. ;    CX    : logical to physical map length
  1423. ;    DS:SI    : pointer to logical to physical/segment map array
  1424. ; output
  1425. ;    AH    : status
  1426. ;--------------------------------------------------------------------
  1427. log_phys_map:
  1428.         MOV    [BP].f17_ax_save,AX    ;
  1429.         MOV    AX,[BP].ds_save        ;
  1430.         MOV    DS,AX            ;
  1431.         CALL    check_handle        ;check handle data.
  1432.         JNB    log_phys_map2        ;
  1433.         JMP    err83            ;error exit
  1434. log_phys_map2:
  1435.         CMP    CX,PHYS_PAGES        ;
  1436.         JNA    log_phys_map1        ;
  1437.         JMP    err8b            ;error exit
  1438. log_phys_map1:
  1439.         JCXZ    log_phys_map9        ;
  1440.         MOV    [BP].f17_map_len,CX    ;save page map data length.
  1441.         MOV    AX,SS            ;
  1442.         MOV    ES,AX            ;
  1443.         LEA    DI,[BP].f17_map_data    ;save page map data.
  1444.         SHL    CX,1            ;
  1445.         REPZ    MOVSW            ;
  1446.         MOV    AX,SS            ;
  1447.         MOV    DS,AX            ;
  1448.         LEA    SI,[BP].f17_map_data    ;set page map data pointer.
  1449.         MOV    CX,[BP].f17_map_len    ;get page map data length.
  1450. log_phys_map7:
  1451.         MOV    BX,[SI].log_page_number1;get logical page no.
  1452.         CMP    BX,UNMAP        ;unmapping?
  1453.         JZ    log_phys_map6        ;
  1454.         CALL    check_log_page        ;check logical page no.
  1455.         JNB    log_phys_map3        ;error?
  1456.         JMP    err8a            ;error exit
  1457. log_phys_map3:
  1458.         MOV    BX,AX            ;set EMM logical page no.
  1459. log_phys_map6:
  1460.         MOV    AX,[BP].f17_ax_save    ;
  1461.         CMP    AL,0            ;subfunction 0?
  1462.         JNZ    log_phys_map8        ;
  1463.         MOV    AX,[SI].phys_page_number1;get physical page no.
  1464.         CMP    AX,PHYS_PAGES        ;check physical page no.
  1465.         JB    log_phys_map4        ;
  1466.         JMP    err8b            ;error exit
  1467. log_phys_map8:
  1468.         MOV    AX,[SI].mappable_seg_addr;get mappable seg_address.
  1469.         CALL    change_seg_page        ;change segment -> phys_page_no
  1470.         JNB    log_phys_map4        ;
  1471.         JMP    err8b            ;error exit 
  1472. log_phys_map4:
  1473.         CMP    BX,UNMAP        ;unmapping?
  1474.         JZ    log_phys_mapa        ;
  1475.         CALL    set_phys_page        ;set physical page
  1476.         JNB    log_phys_map5        ;
  1477.         JMP    err81            ;error exit
  1478. log_phys_mapa:
  1479.         CALL    reset_phys_page        ;reset physical page
  1480.         JNB    log_phys_map5        ;
  1481.         JMP    err81            ;error exit
  1482. log_phys_map5:
  1483.         ADD    SI,SIZE log_to_phys_map_struct;
  1484.         LOOP    log_phys_map7        ;
  1485. log_phys_map9:
  1486.         JMP    noerr            ;exit
  1487.  
  1488. ;------ function 18 ------------------------------------------------------
  1489. ; Reallocate pages
  1490. ; input
  1491. ;    DX    : EMM handle
  1492. ;    BX    : reallocation count
  1493. ; output
  1494. ;    AH    : status
  1495. ;    BX    : number of pages allocated to handle after reallocation
  1496. ;-------------------------------------------------------------------------
  1497. func18:
  1498.         PUSH    CS            ;
  1499.         POP    ES            ;
  1500.         CMP    DX,HANDLE_CNT        ;check handle data...
  1501.         JNB    f181            ;
  1502.         MOV    SI,DX            ;
  1503.         SHL    SI,1            ;
  1504.         CMP    [SI].handle_flag,0    ;
  1505.         JNZ    f181            ;
  1506.         XOR    BX,BX            ;
  1507.         MOV    [BP].bx_save,BX        ;
  1508.         JMP    err83            ;error exit 
  1509. f182:                        ;
  1510.         JMP    err87            ;error exit
  1511. f18a:                        ;
  1512.         JMP    noerr            ;exit
  1513. f181:                        ;
  1514.         CMP    total_pages,BX        ;request total size over ?
  1515.         JB    f182            ;yes
  1516.         MOV    AX,[SI].alloc_page_count;get page size to handle
  1517.         OR    BX,BX            ;reallocate count = 0?
  1518.         JNZ    f184            ;
  1519.         MOV    CX,AX            ;
  1520.         JCXZ    f18a            ;CX = 0 case?
  1521.         MOV    DI,[SI].page_address    ;BX = 0 case...
  1522.         PUSH    BX            ;
  1523. f185:                        ;
  1524.         MOV    BX,[DI]            ;
  1525.         SHL    BX,1            ;
  1526.         MOV    [BX].log_page,NOT_USE    ;unallocate logical page
  1527.         INC    un_alloc_pages        ;add unallocated pages
  1528.         INC    DI            ;
  1529.         INC    DI            ;
  1530.         LOOP    f185            ;
  1531.         POP    BX            ;
  1532.         JMP    f18l            ;
  1533. f184:                        ;
  1534.         CMP    AX,BX            ;check reallocation/allocated
  1535.         JNZ    f18c            ;pages.
  1536.         JMP    noerr            ;same size case.
  1537. f18c:                        ;
  1538.         JNB    f183            ;BX < allocated count?
  1539.         JMP    f186            ;
  1540. f183:                        ;
  1541.         MOV    CX,AX            ;BX < allocated pages case...
  1542.         SUB    CX,BX            ;
  1543.         MOV    DI,[SI].page_address    ;BX = 0 case...
  1544.         MOV    AX,BX            ;
  1545.         SHL    AX,1            ;
  1546.         ADD    DI,AX            ;
  1547.         PUSH    BX            ;
  1548. f18b:                        ;
  1549.         MOV    BX,[DI]            ;
  1550.         SHL    BX,1            ;
  1551.         MOV    [BX].log_page,NOT_USE    ;unallocate logical page
  1552.         INC    un_alloc_pages        ;add unallocated pages
  1553.         INC    DI            ;
  1554.         INC    DI            ;
  1555.         LOOP    f18b            ;
  1556.         POP    BX            ;
  1557. f18l:                        ;
  1558.         MOV    CX,page_ptr        ;clear & sort page buffer...
  1559.         MOV    AX,BX            ;
  1560.         SHL    AX,1            ;
  1561.         ADD    AX,[SI].page_address    ;
  1562.         SUB    CX,AX            ;
  1563.         PUSH    SI            ;
  1564.         MOV    DI,[SI].page_address    ;
  1565.         MOV    AX,BX            ;
  1566.         SHL    AX,1            ;
  1567.         ADD    DI,AX            ;
  1568.         MOV    AX,[SI].alloc_page_count;
  1569.         MOV    SI,[SI].page_address    ;
  1570.         SHL    AX,1            ;
  1571.         ADD    SI,AX            ;
  1572.         SHR    CX,1            ;
  1573.         JCXZ    f18e            ;
  1574.         REPZ    MOVSW            ;
  1575. f18e:                        ;
  1576.         MOV    CX,page_ptr        ;
  1577.         SUB    CX,DI            ;
  1578.         SHR    CX,1            ;
  1579.         JCXZ    f18f            ;
  1580.         MOV    AX,UNALLOC        ;
  1581.         REPZ    STOSW            ;
  1582. f18f:                        ;
  1583.         POP    SI            ;
  1584.         MOV    AX,[SI].alloc_page_count;
  1585.         MOV    [SI].alloc_page_count,BX;set EMM handle used page count
  1586.         XOR    DI,DI            ;change other handle page add-
  1587.         SUB    AX,BX            ;ress....
  1588.         SHL    AX,1            ;
  1589.         MOV    BX,[SI].page_address    ;
  1590.         MOV    CX,handle_count        ;
  1591. f18j:                        ;
  1592.         CMP    [DI].handle_flag,0    ;active handle ?
  1593.         JZ    f18k            ;
  1594.         CMP    [DI].page_address,BX    ;page_address > BX ?
  1595.         JNG    f18m            ;
  1596.         SUB    [DI].page_address,AX    ;page_address - AX
  1597. f18m:                        ;
  1598.         LOOP    f18k            ;
  1599.         SUB    page_ptr,AX        ;page_ptr - AX
  1600.         CMP    [SI].alloc_page_count,0    ;allocate page count = 0 ?
  1601.         JNZ    f18o            ;
  1602.         MOV    [SI].page_address,0    ;clear page buffer pointer
  1603. f18o:                        ;
  1604.         JMP    noerr            ;exit.
  1605. f18k:                        ;
  1606.         ADD    DI,FLAG_SIZE        ;
  1607.         JMP    f18j            ;
  1608. f186:                        ;
  1609.         MOV    CX,BX            ;BX > allocated pages case...
  1610.         SUB    CX,AX            ;
  1611.         CMP    un_alloc_pages,CX    ;request unallocate size over ?
  1612.         JNB    f187            ;no
  1613.         MOV    AX,[SI].alloc_page_count;
  1614.         MOV    [BP].bx_save,AX        ;
  1615.         JMP    err88            ;error exit
  1616. f187:                        ;
  1617.         PUSH    SI            ;move page buffer...
  1618.         MOV    DI,page_ptr        ;
  1619.         CMP    [SI].page_address,0    ;not poniter address?
  1620.         JNZ    f18p            ;
  1621.         MOV    [SI].page_address,DI    ;set page pointer
  1622.         JMP    f18q            ;
  1623. f18p:                        ;
  1624.         DEC    DI            ;
  1625.         MOV    AX,CX            ;
  1626.         SHL    AX,1            ;
  1627.         ADD    DI,AX            ;
  1628.         MOV    AX,[SI].alloc_page_count;
  1629.         SHL    AX,1            ;
  1630.         ADD    AX,[SI].page_address    ;
  1631.         PUSH    CX            ;
  1632.         MOV    CX,page_ptr        ;
  1633.         SUB    CX,AX            ;
  1634.         MOV    SI,page_ptr        ;
  1635.         DEC    SI            ;
  1636.         STD                ;
  1637.         JCXZ    f18g            ;
  1638.         REPZ    MOVSB            ;
  1639. f18g:                        ;
  1640.         POP    CX            ;
  1641. f18q:                        ;
  1642.         SHL    CX,1            ;
  1643.         ADD    page_ptr,CX        ;pointer add
  1644.         POP    SI            ;
  1645.         CLD                ;
  1646.         MOV    DI,[SI].page_address    ;allocate add pages...
  1647.         MOV    AX,[SI].alloc_page_count;
  1648.         MOV    CX,BX            ;
  1649.         SUB    CX,AX            ;
  1650.         SHL    AX,1            ;
  1651.         ADD    DI,AX            ;
  1652.         PUSH    SI            ;
  1653.         MOV    SI,OFFSET log_page    ;
  1654.         XOR    AX,AX            ;
  1655. f188:                        ;
  1656.         CMP    WORD PTR [SI],UNMAP    ;logical page end?
  1657.         JZ    f18d            ;
  1658.         CMP    WORD PTR [SI],NOT_USE    ;unallocated page ?
  1659.         JNZ    f189            ;
  1660.         MOV    WORD PTR [SI],DX    ;
  1661.         STOSW                ;
  1662.         DEC    un_alloc_pages        ;unallocated page - 1
  1663.         LOOP    f189            ;
  1664.         POP    SI            ;
  1665.         MOV    AX,[SI].alloc_page_count;
  1666.         MOV    [SI].alloc_page_count,BX;set EMM handle used page count
  1667.         XOR    DI,DI            ;change other handle page add-
  1668.         XCHG    AX,BX            ;ress....
  1669.         SUB    AX,BX            ;
  1670.         SHL    AX,1            ;
  1671.         MOV    BX,[SI].page_address    ;
  1672.         MOV    CX,handle_count        ;
  1673. f18h:                        ;
  1674.         CMP    [DI].handle_flag,0    ;
  1675.         JZ    f18i            ;
  1676.         CMP    [DI].page_address,BX    ;
  1677.         JNG    f18n            ;
  1678.         ADD    [DI].page_address,AX    ;
  1679. f18n:                        ;
  1680.         LOOP    f18i            ;
  1681.         JMP    noerr            ;exit
  1682. f18i:                        ;
  1683.         ADD    DI,FLAG_SIZE        ;
  1684.         JMP    f18h            ;
  1685. f189:                        ;
  1686.         ADD    SI,LOG_SIZE        ;
  1687.         INC    AX            ;
  1688.         JMP    f188            ;
  1689. f18d:                        ;
  1690.         POP    SI            ;
  1691.         JMP    err80            ;error exit
  1692.  
  1693. ;------ function 19 -------------------------------------------------
  1694. ; Get/set handle attribute
  1695. ;--------------------------------------------------------------------
  1696. func19:
  1697.         STI                ;
  1698.         CMP    AL,0            ;
  1699.         JZ    get_handle_attr        ;
  1700.         CMP    AL,1            ;
  1701.         JZ    set_handle_attr        ;
  1702.         CMP    AL,2            ;
  1703.         JZ    get_attr_cap        ;
  1704.         JMP    err84            ;error exit 
  1705.  
  1706. ;--------------------------------------------------------------------
  1707. ; Get handle attribute
  1708. ; input
  1709. ;    DX    : EMM handle
  1710. ; output
  1711. ;    AH    : status
  1712. ;    AL    : handle attribute
  1713. ;--------------------------------------------------------------------
  1714. get_handle_attr:
  1715.         CALL    check_handle        ;check handle data
  1716.         JNB    get_handle_attr1    ;
  1717.         JMP    err83            ;error exit 
  1718. get_handle_attr1:
  1719.         MOV    AL,VOLATILE        ;handle attribute set
  1720.         JMP    noerr            ;exit
  1721.  
  1722. ;--------------------------------------------------------------------
  1723. ; Set handle attribute
  1724. ; input
  1725. ;    DX    : EMM handle
  1726. ;    BL    : new handle attribute
  1727. ; output
  1728. ;    AH    : status
  1729. ;--------------------------------------------------------------------
  1730. set_handle_attr:
  1731.         CALL    check_handle        ;check handle data
  1732.         JNB    set_handle_attr2    ;
  1733.         JMP    err83            ;error exit
  1734. set_handle_attr2:
  1735.         CMP    BL,VOLATILE        ;
  1736.         JNZ    set_handle_attr1    ;
  1737.         JMP    noerr            ;exit
  1738. set_handle_attr1:
  1739.         CMP    BL,NON_VOLATILE        ;handle attribute check
  1740.         JZ    set_handle_attr3    ;
  1741.         JMP    err90            ;error exit
  1742. set_handle_attr3:
  1743.         JMP    err91            ;error exit
  1744.  
  1745. ;--------------------------------------------------------------------
  1746. ; Get attribute capability
  1747. ; output
  1748. ;    AH    : status
  1749. ;    AL    : attribute capability
  1750. ;--------------------------------------------------------------------
  1751. get_attr_cap:
  1752.         CALL    check_handle        ;check handle data
  1753.         JNB    get_attr_cap1        ;
  1754.         JMP    err83            ;error exit
  1755. get_attr_cap1:
  1756.         MOV    AL,VOLATILE        ;set attribute capability
  1757.         JMP    noerr            ;exit
  1758.  
  1759. ;------ function 20 -------------------------------------------------
  1760. ; Get/set handle name
  1761. ;--------------------------------------------------------------------
  1762. func20:
  1763.         CMP    AL,0            ;
  1764.         JZ    get_handle_name        ;
  1765.         CMP    AL,1            ;
  1766.         JZ    set_handle_name        ;
  1767.         JMP    err84            ;error exit 
  1768.  
  1769. ;--------------------------------------------------------------------
  1770. ; Get handle name
  1771. ; input
  1772. ;    DX    : EMM handle
  1773. ;    ES:DI    : pointer to handle name array
  1774. ; output
  1775. ;    AH    : status
  1776. ;--------------------------------------------------------------------
  1777. get_handle_name:
  1778.         CALL    check_handle        ;check handle data
  1779.         JNB    get_handle_name1    ;
  1780.         JMP    err83            ;error exit
  1781. get_handle_name1:                ;
  1782.         MOV    SI,OFFSET handle_name    ;
  1783.         MOV    AX,DX            ;
  1784.         MOV    CL,3            ;
  1785.         SHL    AX,CL            ;
  1786.         ADD    SI,AX            ;
  1787.         MOV    DI,[BP].di_save        ;
  1788.         MOV    CX,HANDLE_NAME_SIZE    ;
  1789.         REPZ    MOVSB            ;
  1790.         JMP    noerr            ;exit
  1791.  
  1792. ;--------------------------------------------------------------------
  1793. ; Set handle name
  1794. ; input
  1795. ;    DX    : EMM handle
  1796. ;    DS:SI    : pointer to handle name
  1797. ; output
  1798. ;    AH    : status
  1799. ;--------------------------------------------------------------------
  1800. set_handle_name:
  1801.         CALL    check_handle        ;check handle data
  1802.         JNB    set_handle_name1    ;
  1803.         JMP    err83            ;error exit
  1804. set_handle_name1:                ;
  1805.         PUSH    CS            ;
  1806.         POP    ES            ;
  1807.         MOV    AX,[BP].ds_save        ;
  1808.         MOV    DS,AX            ;
  1809.         MOV    BX,DX            ;
  1810.         MOV    CX,HANDLE_CNT        ;check handle name...
  1811.         MOV    DI,OFFSET handle_name    ;
  1812.         XOR    DX,DX            ;
  1813. set_handle_name2:                ;
  1814.         CALL    check_handle        ;check handle data
  1815.         JB    set_handle_name3    ;
  1816.         PUSH    CX            ;compare handle name...
  1817.         PUSH    SI            ;
  1818.         PUSH    DI            ;
  1819.         MOV    CX,HANDLE_NAME_SIZE    ;
  1820.         REPZ    CMPSB            ;
  1821.         POP    DI            ;
  1822.         POP    SI            ;
  1823.         POP    CX            ;
  1824.         JZ    set_handle_name4    ;found same handle name ?
  1825. set_handle_name3:                ;
  1826.         ADD    DI,HANDLE_NAME_SIZE    ;
  1827.         INC    DX            ;
  1828.         LOOP    set_handle_name2    ;
  1829.         MOV    DI,OFFSET handle_name    ;set handle name...
  1830.         MOV    AX,BX            ;
  1831.         MOV    CL,3            ;
  1832.         SHL    AX,CL            ;
  1833.         ADD    DI,AX            ;
  1834.         MOV    CX,HANDLE_NAME_SIZE    ;
  1835.         REPZ    MOVSB            ;
  1836.         JMP    noerr            ;exit
  1837. set_handle_name4:
  1838.         JMP    erra1            ;error exit
  1839.  
  1840. ;------ function 21 -------------------------------------------------
  1841. ; Get handle directory
  1842. ;--------------------------------------------------------------------
  1843. func21:
  1844.         CMP    AL,0            ;
  1845.         JZ    get_handle_dir        ;
  1846.         CMP    AL,1            ;
  1847.         JZ    search_for_name        ;
  1848.         CMP    AL,2            ;
  1849.         JZ    get_total_handle    ;
  1850.         JMP    err84            ;error exit 
  1851.  
  1852. ;--------------------------------------------------------------------
  1853. ; Get handle directory
  1854. ; input
  1855. ;    ES:DI    : pointer to handle_dir
  1856. ; output
  1857. ;    AH    : status
  1858. ;    AL    : number of entries in the handle_dir array
  1859. ;--------------------------------------------------------------------
  1860. get_handle_dir:
  1861.         MOV    CX,HANDLE_CNT        ;
  1862.         MOV    SI,OFFSET handle_name    ;
  1863.         XOR    DX,DX            ;
  1864.         XOR    BL,BL            ;
  1865. get_handle_dir1:                ;
  1866.         CALL    check_handle        ;check handle data
  1867.         JB    get_handle_dir2        ;
  1868.         MOV    AX,DX            ;set EMM handle.
  1869.         STOSW                ;
  1870.         PUSH    CX            ;set handle name...
  1871.         PUSH    SI            ;
  1872.         MOV    CX,HANDLE_NAME_SIZE    ;
  1873.         REPZ    MOVSB            ;
  1874.         POP    SI            ;
  1875.         POP    CX            ;
  1876.         INC    BL            ;inc handle count.
  1877. get_handle_dir2:                ;
  1878.         ADD    SI,HANDLE_NAME_SIZE    ;
  1879.         INC    DX            ;
  1880.         LOOP    get_handle_dir1        ;
  1881.         MOV    AL,BL            ;
  1882.         JMP    noerr            ;exit
  1883.  
  1884. ;--------------------------------------------------------------------
  1885. ; Search for named handle
  1886. ; input
  1887. ;    DS:SI    : search handle_name pointer
  1888. ; output
  1889. ;    AH    : status
  1890. ;    DX    : EMM handle
  1891. ;--------------------------------------------------------------------
  1892. search_for_name:
  1893.         PUSH    CS            ;
  1894.         POP    ES            ;
  1895.         MOV    CX,HANDLE_CNT        ;
  1896.         MOV    DI,OFFSET handle_name    ;
  1897.         MOV    AX,[BP].ds_save        ;
  1898.         MOV    DS,AX            ;
  1899.         XOR    DX,DX            ;
  1900. search_for_name1:                ;
  1901.         PUSH    CX            ;
  1902.         PUSH    SI            ;
  1903.         PUSH    DI            ;
  1904.         MOV    CX,HANDLE_NAME_SIZE    ;
  1905.         REPZ    CMPSB            ;
  1906.         POP    DI            ;
  1907.         POP    SI            ;
  1908.         POP    CX            ;
  1909.         JZ    search_for_name2    ;
  1910.         ADD    DI,HANDLE_NAME_SIZE    ;
  1911.         INC    DX            ;
  1912.         LOOP    search_for_name1    ;
  1913.         JMP    erra0            ;error exit
  1914. search_for_name2:                ;
  1915.         MOV    CX,HANDLE_NAME_SIZE    ;
  1916.         XOR    AL,AL            ;
  1917.         REPZ    SCASB            ;
  1918.         JNZ    search_for_name3    ;
  1919.         JMP    erra1            ;error exit
  1920. search_for_name3:                ;
  1921.         PUSH    CS            ;
  1922.         POP    DS            ;
  1923.         MOV    [BP].dx_save,DX        ;
  1924.         JMP    noerr            ;exit
  1925.  
  1926. ;--------------------------------------------------------------------
  1927. ; Get total handle
  1928. ; output
  1929. ;    AH    : status
  1930. ;    BX    : total_handles
  1931. ;--------------------------------------------------------------------
  1932. get_total_handle:
  1933.         MOV    BX,HANDLE_CNT        ;set max handle count.
  1934.         MOV    [BP].bx_save,BX        ;
  1935.         JMP    noerr            ;exit
  1936.  
  1937. ;------ function 22 -------------------------------------------------
  1938. ; Alter page map & jump.
  1939. ; input
  1940. ;    AL    : physical page number/segment selector
  1941. ;    DX    : EMM handle
  1942. ;    DS:SI    : pointer to map_and_jump structure
  1943. ; output
  1944. ;    AH    : status
  1945. ;--------------------------------------------------------------------
  1946. func22:
  1947.         STI                ;
  1948.         CMP    AL,0            ;
  1949.         JZ    f220            ;
  1950.         CMP    AL,1            ;
  1951.         JZ    f220            ;
  1952.         JMP    err8f            ;error exit
  1953. f220:
  1954.         MOV    [BP].f22_ax_save,AX    ;
  1955.         CALL    check_handle        ;check handle data.
  1956.         JNB    f221            ;
  1957.         JMP    err83            ;error exit
  1958. f221:
  1959.         MOV    AX,[BP].ds_save        ;copy calling parameters...
  1960.         MOV    DS,AX            ;
  1961.         LES    BX,[SI].target_address1    ;
  1962.         MOV    AX,ES            ;
  1963.         MOV    [BP].f22_target_off,BX    ;offset
  1964.         MOV    [BP].f22_target_seg,AX    ;segment
  1965.         MOV    CL,[SI].log_phys_map_len;get mapping data length.
  1966.         XOR    CH,CH            ;
  1967.         MOV    [BP].f22_map_len,CX    ;length
  1968.         JCXZ    f22a            ;
  1969.         LES    BX,[SI].log_phys_map_ptr;get log_phys_map_ptr.
  1970.         LEA    DI,[BP].f22_map_data    ;copy log_phys_map data...
  1971.         SHL    CX,1            ;
  1972. f228:
  1973.         MOV    AX,ES:[BX]        ;
  1974.         MOV    SS:[DI],AX        ;
  1975.         INC    DI            ;
  1976.         INC    DI            ;
  1977.         INC    BX            ;
  1978.         INC    BX            ;
  1979.         LOOP    f228            ;
  1980. f22a:
  1981.         MOV    AX,SS            ;
  1982.         MOV    DS,AX            ;
  1983.         MOV    CX,[BP].f22_map_len    ;length
  1984.         JCXZ    f222            ;
  1985.         LEA    DI,[BP].f22_map_data    ;get mapping data pointer.
  1986. f223:
  1987.         MOV    BX,[DI].log_page_number1;get logical page no.
  1988.         CMP    BX,UNMAP        ;unmapping?
  1989.         JZ    f22b            ;
  1990.         CALL    check_log_page        ;check logical page no.
  1991.         JNB    f224            ;
  1992.         JMP    err8a            ;error exit
  1993. f224:
  1994.         MOV    BX,AX            ;set EMM logical page no.
  1995. f22b:
  1996.         MOV    AX,[BP].f22_ax_save    ;get phys_page_no/seg_selector.
  1997.         CMP    AL,0            ;sub_function 0?
  1998.         JNZ    f229            ;
  1999.         MOV    AX,[DI].phys_page_number1;get physical page no.
  2000.         CMP    AX,PHYS_PAGES        ;
  2001.         JB    f225            ;
  2002.         JMP    err8b            ;error exit
  2003. f229:
  2004.         MOV    AX,[DI].mappable_seg_addr;get mappable segment.
  2005.         CALL    change_seg_page        ;change segment -> phys_page_no.
  2006.         JNB    f225            ;
  2007.         JMP    err8b            ;error exit
  2008. f225:
  2009.         CMP    BX,UNMAP        ;unmapping?
  2010.         JZ    f227            ;
  2011.         CALL    set_phys_page        ;set physical page
  2012.         JNB    f226            ;
  2013.         JMP    err81            ;error exit
  2014. f227:
  2015.         CALL    reset_phys_page        ;reset physical page
  2016.         JNB    f226            ;
  2017.         JMP    err81            ;error exit
  2018. f226:
  2019.         ADD    DI,SIZE log_to_phys_map_struct;
  2020.         LOOP    f223            ;
  2021. f222:
  2022.         MOV    AX,[BP].f22_target_seg    ;get target address.
  2023.         MOV    [BP].ret_segment,AX    ;set FAR:JUMP segment.
  2024.         MOV    AX,[BP].f22_target_off    ;get target address.
  2025.         MOV    [BP].ret_offset,AX    ;set FAR:JUMP offset.
  2026.         JMP    noerr            ;exit
  2027.  
  2028. ;------ function 23 -------------------------------------------------
  2029. ; Alter page map & call
  2030. ;--------------------------------------------------------------------
  2031. func23:
  2032.         STI                ;
  2033.         CMP    AL,0            ;
  2034.         JZ    f2300            ;
  2035.         CMP    AL,1            ;
  2036.         JZ    f2300            ;
  2037.         CMP    AL,2            ;
  2038.         JZ    get_page_map_stack    ;
  2039.         JMP    err84            ;error exit 
  2040.  
  2041. ;--------------------------------------------------------------------
  2042. ; Get page map stack space size
  2043. ; output
  2044. ;    AH    : status
  2045. ;    BX    : stack space required
  2046. ;--------------------------------------------------------------------
  2047. get_page_map_stack:
  2048.         MOV    BX,RET_SP        ;set stack space...
  2049.         MOV    [BP].bx_save,BX        ;
  2050.         JMP    noerr            ;exit
  2051.  
  2052. ;--------------------------------------------------------------------
  2053. ; Alter page map & call
  2054. ; input
  2055. ;    AL    : physical page number/segment selector
  2056. ;    DX    : EMM handle
  2057. ;    DS:SI    : pointer to map_and_call structure
  2058. ; output
  2059. ;    AH    : status
  2060. ;    AL    : number of entries in the handle_dir array
  2061. ;--------------------------------------------------------------------
  2062. f2300:
  2063.         MOV    [BP].f23_ax_save,AX    ;
  2064.         CALL    check_handle        ;check handle data
  2065.         JNB    f2301            ;
  2066.         JMP    err83            ;error exit
  2067. f2301:
  2068.         MOV    AX,[BP].ds_save        ;
  2069.         MOV    DS,AX            ;
  2070.         LES    BX,[SI].target_address2    ;get FAR:CALL target_addr.
  2071.         MOV    [BP].f23_target_off,BX    ;set offset.
  2072.         MOV    AX,ES            ;get segment
  2073.         MOV    [BP].f23_target_seg,AX    ;set segment.
  2074.         MOV    CL,[SI].new_page_map_len;get new_page_map_len.
  2075.         XOR    CH,CH            ;
  2076.         MOV    [BP].f23_new_map_len,CX    ;
  2077.         LES    BX,[SI].new_page_map_ptr;get new_page_map_ptr.
  2078.         JCXZ    f2303            ;
  2079.         LEA    DI,[BP].f23_new_map_data;
  2080.         SHL    CX,1            ;
  2081. f2302:
  2082.         MOV    AX,ES:[BX]        ;
  2083.         MOV    SS:[DI],AX        ;
  2084.         INC    DI            ;
  2085.         INC    DI            ;
  2086.         INC    BX            ;
  2087.         INC    BX            ;
  2088.         LOOP    f2302            ;
  2089. f2303:
  2090.         MOV    CL,[SI].old_page_map_len;get old_page_map_len.
  2091.         XOR    CH,CH            ;
  2092.         MOV    [BP].f23_old_map_len,CX    ;
  2093.         LES    BX,[SI].old_page_map_ptr;get old_page_map_ptr.
  2094.         JCXZ    f2305            ;
  2095.         LEA    DI,[BP].f23_old_map_data;
  2096.         SHL    CX,1            ;
  2097. f2304:
  2098.         MOV    AX,ES:[BX]        ;
  2099.         MOV    SS:[DI],AX        ;
  2100.         INC    DI            ;
  2101.         INC    DI            ;
  2102.         INC    BX            ;
  2103.         INC    BX            ;
  2104.         LOOP    f2304            ;
  2105. f2305:
  2106.         MOV    CX,[BP].f23_new_map_len    ;get new_page_map_len.
  2107.         JCXZ    f2307            ;mapping page length = 0?
  2108.         MOV    AX,SS            ;
  2109.         MOV    DS,AX            ;
  2110.         LEA    SI,[BP].f23_new_map_data;get new_page_map_ptr.
  2111. f2306:
  2112.         MOV    BX,[SI].log_page_number2;get logical page no.
  2113.         CMP    BX,UNMAP        ;unmapping?
  2114.         JZ    f2313            ;
  2115.         CALL    check_log_page        ;
  2116.         JNB    f2309            ;
  2117.         JMP    err8a            ;error exit
  2118. f2309:
  2119.         MOV    BX,AX            ;
  2120. f2313:
  2121.         MOV    AX,[BP].f23_ax_save    ;
  2122.         CMP    AL,0            ;sub_function 0?
  2123.         JZ    f2310            ;
  2124.         MOV    AX,[SI].mappable_seg_addr;
  2125.         CALL    change_seg_page        ;change segment -> phys_page_no.
  2126.         JNB    f2311            ;
  2127.         JMP    err8b            ;error exit
  2128. f2310:
  2129.         MOV    AX,[SI].phys_page_number1;get physical page no.
  2130.         CMP    AX,PHYS_PAGES        ;
  2131.         JB    f2311            ;
  2132.         JMP    err8b            ;error exit
  2133. f2311:
  2134.         CMP    BX,UNMAP        ;unmapping?
  2135.         JZ    f2312            ;
  2136.         CALL    set_phys_page        ;set physical page
  2137.         JNB    f2308            ;error ?
  2138.         JMP    err81            ;error exit
  2139. f2312:
  2140.         CALL    reset_phys_page        ;reset physical page
  2141.         JNB    f2308            ;error ?
  2142.         JMP    err81            ;error exit
  2143. f2308:
  2144.         ADD    SI,SIZE log_to_seg_map_struct;
  2145.         LOOP    f2306            ;
  2146. f2307:
  2147.         MOV    BX,OFFSET f2350        ;get FAR:CALL return_addr
  2148.         MOV    [BP].f23_retoff,BX    ;set offset.
  2149.         MOV    AX,CS            ;
  2150.         MOV    [BP].f23_retseg,AX    ;set segment.
  2151.         MOV    AX,[BP].ret_flag    ;get flags.
  2152.         MOV    [BP].f23_flag,AX    ;set flags.
  2153.         MOV    AH,0            ;
  2154.         POP    BX            ;
  2155.         POP    CX            ;
  2156.         POP    DX            ;
  2157.         POP    SI            ;
  2158.         POP    DI            ;
  2159.         POP    BP            ;
  2160.         POP    ES            ;
  2161.         POP    DS            ;
  2162.         IRET                ;FAR:CALL to target
  2163.  
  2164. ;
  2165. ; far call return point
  2166. ;
  2167. f2350:
  2168.         PUSHF                ;push flags.
  2169.         POP    AX            ;pop flags.
  2170.         CLI                ;
  2171.         SUB    SP,F23_RETSP        ;
  2172.         PUSH    DS            ;PUSH registers...
  2173.         PUSH    ES            ;
  2174.         PUSH    BP            ;
  2175.         PUSH    DI            ;
  2176.         PUSH    SI            ;
  2177.         PUSH    DX            ;
  2178.         PUSH    CX            ;
  2179.         PUSH    BX            ;
  2180.         MOV    BP,SP            ;
  2181.         MOV    [BP].ret_flag,AX    ;set return_flags.
  2182.         MOV    CX,[BP].f23_old_map_len    ;get old_page_map_len.
  2183.         JCXZ    f2351            ;mapping page length = 0?
  2184.         MOV    AX,SS            ;
  2185.         MOV    DS,AX            ;
  2186.         LEA    SI,[BP].f23_old_map_data;get old_page_map_ptr.
  2187. f2352:
  2188.         MOV    BX,[SI].log_page_number2;get logical page no.
  2189.         CMP    BX,UNMAP        ;unmapping?
  2190.         JZ    f2359            ;
  2191.         CALL    check_log_page        ;
  2192.         JNB    f2358            ;
  2193.         JMP    err8a            ;error exit
  2194. f2358:
  2195.         MOV    BX,AX            ;
  2196. f2359:
  2197.         MOV    AX,[BP].f23_ax_save    ;
  2198.         CMP    AL,0            ;
  2199.         JZ    f2354            ;
  2200.         MOV    AX,[SI].mappable_seg_addr;
  2201.         CALL    change_seg_page        ;change segment -> phys_page_no.
  2202.         JNB    f2355            ;
  2203.         JMP    err8b            ;error exit
  2204. f2354:
  2205.         MOV    AX,[SI].phys_page_number1;get physical page no.
  2206.         CMP    AX,PHYS_PAGES        ;
  2207.         JB    f2355            ;
  2208.         JMP    err8b            ;error exit
  2209. f2355:
  2210.         CMP    BX,UNMAP        ;unmapping?
  2211.         JZ    f2357            ;
  2212.         CALL    set_phys_page        ;set physical page
  2213.         JNB    f2353            ;error ?
  2214.         JMP    err81            ;error exit
  2215. f2357:
  2216.         CALL    reset_phys_page        ;reset physical page
  2217.         JNB    f2353            ;error ?
  2218.         JMP    err81            ;error exit
  2219. f2353:
  2220.         ADD    SI,SIZE log_to_seg_map_struct;
  2221.         LOOP    f2352            ;
  2222. f2351:
  2223.         JMP    noerr            ;exit 
  2224.  
  2225. ;------ function 24 -------------------------------------------------
  2226. ; Move/exchange memory region
  2227. ; input
  2228. ;    AL    : move/xchg select data (00 = move,01 = xchg)
  2229. ;    DS:SI    : pointer to move/xchg_source_dest structure
  2230. ; output
  2231. ;    AH    : status
  2232. ;--------------------------------------------------------------------
  2233. func24:
  2234.         CMP    AL,0            ;
  2235.         JZ    f2400            ;
  2236.         CMP    AL,1            ;
  2237.         JZ    f2400            ;
  2238.         JMP    err84            ;error exit
  2239. f2400:
  2240.         MOV    [BP].f24_ax_save,AX    ;
  2241.         MOV    AX,[BP].ds_save        ;get calling parameters...
  2242.         MOV    DS,AX            ;
  2243.         MOV    AX,[SI].source_initial_offset1;get source offset.
  2244.         MOV    [BP].source_off,AX    ;
  2245.         XOR    AH,AH            ;
  2246.         MOV    AL,[SI].source_memory_type1;get source memory type.
  2247.         MOV    [BP].source_type,AX    ;
  2248.         CMP    AX,0            ;conventional?
  2249.         JZ    f2401            ;
  2250.         MOV    AX,[SI].source_handle1    ;get source handle.
  2251.         MOV    [BP].source_handle,AX    ;
  2252.         MOV    AX,[SI].source_initial_seg_page1;get source page no.
  2253.         MOV    [BP].source_pno,AX    ;
  2254.         MOV    AX,CS:page_frame_seg    ;
  2255.         MOV    [BP].source_seg,AX    ;
  2256.         JMP    f2402            ;
  2257. f2401:
  2258.         MOV    AX,[SI].source_initial_seg_page1;get source segment.
  2259.         MOV    [BP].source_seg,AX    ;
  2260. f2402:
  2261.         MOV    AX,[SI].dest_initial_offset1;get dest offset.
  2262.         MOV    [BP].dest_off,AX    ;
  2263.         XOR    AH,AH            ;
  2264.         MOV    AL,[SI].dest_memory_type1;get dest memory type.
  2265.         MOV    [BP].dest_type,AX    ;
  2266.         CMP    AX,0            ;conventional?
  2267.         JZ    f2403            ;
  2268.         MOV    AX,[SI].dest_handle1    ;get dest handle.
  2269.         MOV    [BP].dest_handle,AX    ;
  2270.         MOV    AX,[SI].dest_initial_seg_page1;get dest page no.
  2271.         MOV    [BP].dest_pno,AX    ;
  2272.         MOV    AX,CS:page_frame_seg    ;
  2273.         ADD    AX,400H            ;
  2274.         MOV    [BP].dest_seg,AX    ;
  2275.         JMP    f2404            ;
  2276. f2403:
  2277.         MOV    AX,[SI].dest_initial_seg_page1;get dest segment.
  2278.         MOV    [BP].dest_seg,AX    ;
  2279. f2404:
  2280.         LES    DI,[SI].region_length1    ;get region length...
  2281.         MOV    [BP].region_low,DI    ;
  2282.         MOV    AX,ES            ;
  2283.         MOV    [BP].region_high,AX    ;
  2284.         CMP    AX,10H            ;check region size...
  2285.         JB    f2405            ;
  2286.         JZ    f2406            ;
  2287. f2407:
  2288.         JMP    err96            ;error exit
  2289. f2406:
  2290.         MOV    AX,ES            ;
  2291.         OR    AX,AX            ;
  2292.         JNZ    f2407            ;
  2293. f2405:
  2294.         CMP    [BP].source_type,0    ;check source data...
  2295.         JNZ    f2408            ;
  2296.         XOR    DX,DX            ;
  2297.         MOV    AX,[BP].source_seg    ;conventional case...
  2298.         MOV    BX,10H            ;
  2299.         MUL    BX            ;
  2300.         ADD    AX,[BP].source_off    ;
  2301.         ADC    DX,0            ;
  2302.         CMP    DX,10H            ;check source address...
  2303.         JB    f2409            ;
  2304. f2411:
  2305.         JMP    erra2            ;error exit
  2306. f2409:
  2307.         ADD    DX,[BP].region_high    ;add region length...
  2308.         ADD    AX,[BP].region_low    ;
  2309.         ADC    DX,0            ;
  2310.         CMP    DX,10H            ;check address...
  2311.         JB    f2412            ;
  2312.         OR    AX,AX            ;
  2313.         JNZ    f2411            ;
  2314.         JMP    f2412            ;
  2315. f2408:
  2316.         MOV    DX,[BP].source_handle    ;
  2317.         CALL    check_handle        ;check handle data.
  2318.         JNB    f2413            ;
  2319.         JMP    err83            ;error exit
  2320. f2413:
  2321.         MOV    BX,[BP].source_pno    ;
  2322.         CALL    check_log_page        ;
  2323.         JNB    f2414            ;
  2324.         JMP    err8a            ;error exit
  2325. f2414:
  2326.         MOV    DI,DX            ;
  2327.         MOV    AX,[BP].source_off    ;
  2328.         CMP    AX,4000H        ;
  2329.         JB    f2415            ;
  2330.         JMP    err95            ;error exit
  2331. f2415:
  2332.         MOV    DX,[BP].region_high    ;
  2333.         ADD    AX,[BP].region_low    ;
  2334.         ADC    DX,0            ;
  2335.         MOV    CX,4000H        ;
  2336.         DIV    CX            ;
  2337.         CMP    AX,0            ;
  2338.         JZ    f2416            ;
  2339.         INC    DX            ;
  2340. f2416:
  2341.         ADD    BX,DX            ;
  2342.         MOV    DX,DI            ;
  2343.         CALL    check_log_page        ;
  2344.         JNB    f2412            ;
  2345.         JMP    err93            ;error exit
  2346. f2412:
  2347.         MOV    AX,[BP].dest_type    ;check dest data...
  2348.         CMP    AL,0            ;conventional?
  2349.         JNZ    f2417            ;
  2350.         XOR    DX,DX            ;conventional memory case...
  2351.         MOV    AX,[BP].dest_seg    ;
  2352.         MOV    BX,10H            ;
  2353.         MUL    BX            ;
  2354.         ADD    AX,[BP].dest_off    ;
  2355.         ADC    DX,0            ;
  2356.         CMP    DX,10H            ;check dest address...
  2357.         JB    f2418            ;
  2358. f2420:
  2359.         JMP    erra2            ;error exit
  2360. f2418:
  2361.         ADD    DX,[BP].region_high    ;add region length...
  2362.         ADD    AX,[BP].region_low    ;
  2363.         ADC    DX,0            ;
  2364.         CMP    DX,10H            ;check address...
  2365.         JB    f2421            ;
  2366.         OR    AX,AX            ;
  2367.         JNZ    f2420            ;
  2368.         JMP    f2421            ;
  2369. f2417:
  2370.         MOV    DX,[BP].dest_handle    ;expanded memory case...
  2371.         CALL    check_handle        ;check handle data.
  2372.         JNB    f2422            ;
  2373.         JMP    err83            ;error exit
  2374. f2422:
  2375.         MOV    BX,[BP].dest_pno    ;
  2376.         CALL    check_log_page        ;check logical page no.
  2377.         JNB    f2423            ;
  2378.         JMP    err8a            ;error exit
  2379. f2423:
  2380.         MOV    DI,DX            ;
  2381.         MOV    AX,[BP].dest_off    ;
  2382.         CMP    AX,4000H        ;
  2383.         JB    f2424            ;
  2384.         JMP    err95            ;error exit
  2385. f2424:
  2386.         MOV    DX,[BP].region_high    ;
  2387.         ADD    AX,[BP].region_low    ;
  2388.         ADC    DX,0            ;
  2389.         MOV    CX,4000H        ;
  2390.         DIV    CX            ;
  2391.         CMP    AX,0            ;
  2392.         JZ    f2425            ;
  2393.         INC    DX            ;
  2394. f2425:
  2395.         ADD    BX,DX            ;
  2396.         MOV    DX,DI            ;
  2397.         CALL    check_log_page        ;
  2398.         JNB    f2421            ;
  2399.         JMP    err93            ;error exit
  2400. f2421:
  2401.         MOV    [BP].overlap_flag,0    ;
  2402.         MOV    [BP].get_source_f,0    ;
  2403.         MOV    [BP].get_dest_f,0    ;
  2404.         MOV    AX,[BP].source_type    ;check data overlap...
  2405.         CMP    AX,[BP].dest_type    ;source and dest same type?
  2406.         JZ    f2435            ;
  2407.         CMP    AX,0            ;conventional memory?
  2408.         JZ    f2436            ;
  2409.         MOV    [BP].get_source_f,1    ;
  2410.         JMP    f2426            ;
  2411. f2436:
  2412.         MOV    [BP].get_dest_f,1    ;
  2413.         JMP    f2426            ;
  2414. f2435:
  2415.         CMP    AX,0            ;conventional memory?
  2416.         JZ    f2427            ;
  2417.         MOV    AX,[BP].source_handle    ;expanded memory case...
  2418.         CMP    AX,[BP].dest_handle    ;
  2419.         JNZ    f2426            ;
  2420.         MOV    AX,[BP].source_pno    ;
  2421.         MOV    BX,4000H        ;
  2422.         MUL    BX            ;
  2423.         ADD    AX,[BP].source_off    ;
  2424.         ADC    DX,0            ;
  2425.         MOV    SI,AX            ;
  2426.         MOV    CX,DX            ;
  2427.         MOV    AX,[BP].dest_pno    ;
  2428.         MOV    BX,4000H        ;
  2429.         MUL    BX            ;
  2430.         ADD    AX,[BP].dest_off    ;
  2431.         ADC    DX,0            ;
  2432.         MOV    DI,AX            ;
  2433.         MOV    [BP].get_source_f,1    ;
  2434.         MOV    [BP].get_dest_f,1    ;
  2435.         JMP    f2428            ;
  2436. f2427:
  2437.         MOV    SI,[BP].source_off    ;conventional memory case...
  2438.         MOV    CX,[BP].source_seg    ;
  2439.         MOV    DI,[BP].dest_off    ;
  2440.         MOV    DX,[BP].dest_seg    ;
  2441. f2428:
  2442.         CMP    DX,CX            ;CX:SI = source
  2443.         JB    f2429            ;DX:DI = dest
  2444.         JNZ    f2430            ;
  2445.         CMP    DI,SI            ;
  2446.         JB    f2430            ;
  2447. f2429:
  2448.         XCHG    SI,DI            ;
  2449.         XCHG    CX,DX            ;
  2450. f2430:
  2451.         SUB    DI,SI            ;DX:DI - CX:SI...
  2452.         SBB    DX,CX            ;
  2453.         SUB    DI,[BP].region_low    ;
  2454.         SBB    DX,[BP].region_high    ;
  2455.         JNB    f2426            ;ok
  2456. f2431:
  2457.         MOV    AX,[BP].f24_ax_save    ;get AX
  2458.         CMP    AL,0            ;
  2459.         JZ    f2432            ;
  2460.         JMP    err97            ;error exit
  2461. f2434:
  2462.         JMP    err80            ;error exit
  2463. f2432:
  2464.         MOV    [BP].overlap_flag,1    ;set overlap flag.
  2465. f2426:
  2466.         CLI                ;move/xchg memory...
  2467. f2449:
  2468.         CMP    [BP].get_source_f,1    ;
  2469.         JNZ    f2433            ;
  2470.         MOV    AX,[BP].source_type    ;
  2471.         CMP    AL,0            ;
  2472.         JZ    f2451            ;
  2473.         MOV    DX,[BP].source_handle    ;
  2474.         MOV    BX,[BP].source_pno    ;
  2475.         CALL    check_log_page        ;
  2476.         JB    f2434            ;
  2477.         MOV    BX,AX            ;
  2478.         MOV    AL,0            ;set physical page no.
  2479.         CALL    set_phys_page        ;
  2480.         JB    f2434            ;
  2481. f2451:
  2482.         MOV    SI,[BP].source_off    ;set offset address.
  2483.         MOV    AX,[BP].source_seg    ;set segment address..
  2484.         MOV    DS,AX            ;
  2485. f2433:
  2486.         CMP    [BP].get_dest_f,1    ;
  2487.         JNZ    f2445            ;
  2488.         MOV    AX,[BP].dest_type    ;
  2489.         CMP    AL,0            ;
  2490.         JZ    f2452            ;
  2491.         MOV    DX,[BP].dest_handle    ;
  2492.         MOV    BX,[BP].dest_pno    ;
  2493.         CALL    check_log_page        ;
  2494.         JB    f2434            ;
  2495.         MOV    BX,AX            ;
  2496.         MOV    AL,1            ;set physical page no.
  2497.         CALL    set_phys_page        ;
  2498.         JB    f2434            ;
  2499. f2452:
  2500.         MOV    DI,[BP].dest_off    ;set offset address.
  2501.         MOV    AX,[BP].dest_seg    ;set segment address..
  2502.         MOV    ES,AX            ;
  2503. f2445:
  2504.         MOV    AX,[BP].source_type    ;
  2505.         CMP    AX,[BP].dest_type    ;
  2506.         JNZ    f2437            ;
  2507.         CMP    AL,0            ;
  2508.         JNZ    f2438            ;
  2509.         MOV    DX,[BP].region_high    ;conventional...
  2510.         MOV    CX,[BP].region_low    ;
  2511.         JMP    f2440            ;
  2512. f2437:
  2513.         XOR    DX,DX            ;expanded/conventional...
  2514.         MOV    CX,4000H        ;
  2515.         CMP    AL,0            ;
  2516.         JNZ    f2439            ;
  2517.         MOV    [BP].get_dest_f,1    ;
  2518.         SUB    CX,DI            ;
  2519.         JMP    f2440            ;
  2520. f2439:
  2521.         MOV    [BP].get_source_f,1    ;
  2522.         SUB    CX,SI            ;
  2523.         JMP    f2440            ;
  2524. f2438:
  2525.         MOV    DX,4000H        ;expanded
  2526.         MOV    AX,DX            ;
  2527.         SUB    DX,DI            ;
  2528.         SUB    AX,SI            ;
  2529.         MOV    CX,DX            ;
  2530.         MOV    [BP].get_dest_f,1    ;
  2531.         CMP    AX,DX            ;
  2532.         JNB    f2440            ;
  2533.         MOV    CX,AX            ;
  2534.         MOV    [BP].get_source_f,1    ;
  2535.         MOV    [BP].get_dest_f,0    ;
  2536. f2440:
  2537.         CMP    DX,0            ;
  2538.         JNZ    f2441            ;
  2539.         JCXZ    f2448            ;
  2540. f2441:
  2541.         MOV    AX,[BP].f24_ax_save    ;
  2542.         CMP    AL,0            ;
  2543.         JNZ    f2443            ;
  2544.         MOV    AL,[SI]            ;
  2545.         MOV    ES:[DI],AL        ;
  2546.         JMP    f2444            ;
  2547. f2443:
  2548.         MOV    AL,[SI]            ;
  2549.         XCHG    AL,ES:[DI]        ;
  2550.         MOV    [SI],AL            ;
  2551. f2444:
  2552.         MOV    AX,DS            ;DS:SI + 1...
  2553.         ADD    SI,1            ;
  2554.         ADC    AX,0            ;
  2555.         MOV    DS,AX            ;
  2556.         MOV    AX,ES            ;ES:DI + 1...
  2557.         ADD    DI,1            ;
  2558.         ADC    AX,0            ;
  2559.         MOV    ES,AX            ;
  2560.         MOV    AX,[BP].region_low    ;region_low - 1...
  2561.         SUB    AX,1            ;
  2562.         MOV    [BP].region_low,AX    ;
  2563.         MOV    AX,[BP].region_high    ;region_high - 1...
  2564.         SBB    AX,0            ;
  2565.         MOV    [BP].region_high,AX    ;
  2566.         OR    AX,[BP].region_low    ;
  2567.         JZ    f2448            ;
  2568.         SUB    CX,1            ;DX:CX - 1...
  2569.         SBB    DX,0            ;
  2570.         MOV    AX,CX            ;
  2571.         OR    AX,DX            ;
  2572.         JNZ    f2441            ;
  2573.         CMP    [BP].get_source_f,1    ;
  2574.         JNZ    f2446            ;
  2575.         INC    [BP].source_pno        ;
  2576.         MOV    [BP].source_off,0    ;
  2577.         MOV    [BP].get_source_f,0    ;
  2578. f2446:
  2579.         CMP    [BP].get_dest_f,1    ;
  2580.         JNZ    f2447            ;
  2581.         INC    [BP].dest_pno        ;
  2582.         MOV    [BP].dest_off,0        ;
  2583.         MOV    [BP].get_dest_f,0    ;
  2584. f2447:
  2585.         JMP    f2449            ;
  2586. f2448:
  2587.         CMP    [BP].overlap_flag,1    ;overlap flag on?
  2588.         JNZ    f2450            ;
  2589.         JMP    err92            ;error exit
  2590. f2450:
  2591.         JMP    noerr            ;exit
  2592.  
  2593. ;------ function 25 -------------------------------------------------
  2594. ; Get mappable physical address array
  2595. ;--------------------------------------------------------------------
  2596. func25:
  2597.         STI                ;
  2598.         CMP    AL,0            ;
  2599.         JZ    get_map_phys_addr    ;
  2600.         CMP    AL,1            ;
  2601.         JZ    get_map_phys_ent    ;
  2602.         JMP    err84            ;error exit 
  2603.  
  2604. ;--------------------------------------------------------------------
  2605. ; Get mappable physical address array
  2606. ; input
  2607. ;    ES:DI    : mappable_phys_page
  2608. ; output
  2609. ;    AH    : status
  2610. ;    CX    : number of entries in the mappable_phys_page
  2611. ;--------------------------------------------------------------------
  2612. get_map_phys_addr:
  2613.         MOV    AX,[BP].es_save        ;
  2614.         MOV    ES,AX            ;
  2615.         MOV    CX,PHYS_PAGES        ;
  2616.         MOV    SI,OFFSET map_table    ;
  2617.         XOR    DX,DX            ;
  2618. get_map_phys_addr1:
  2619.         MOV    AX,[SI].phys_seg_addr    ;
  2620.         STOSW                ;
  2621.         MOV    AX,DX            ;
  2622.         STOSW                ;
  2623.         INC    DX            ;
  2624.         ADD    SI,SIZE phys_page_struct;
  2625.         LOOP    get_map_phys_addr1    ;
  2626. get_map_phys_addr2:
  2627.         MOV    CX,PHYS_PAGES        ;
  2628.         MOV    [BP].cx_save,CX        ;set segment addr entrie
  2629.         JMP    noerr            ;exit
  2630.  
  2631. ;--------------------------------------------------------------------
  2632. ; Get mappable physcal address array entries
  2633. ; output
  2634. ;    AH    : status
  2635. ;    CX    : number of entries in the mappable_phys_page
  2636. ;--------------------------------------------------------------------
  2637. get_map_phys_ent:
  2638.         JMP    get_map_phys_addr2    ;
  2639.  
  2640. ;------ function 26 -------------------------------------------------
  2641. ; Get expanded memory hardware infomation
  2642. ;--------------------------------------------------------------------
  2643. func26:
  2644.         STI                ;
  2645.         CMP    AL,0            ;
  2646.         JZ    get_hardware_config    ;
  2647.         CMP    AL,1            ;
  2648.         JZ    get_unalloc_raw_page    ;
  2649.         JMP    err84            ;error exit 
  2650.  
  2651. ;--------------------------------------------------------------------
  2652. ; Get hardware configration array
  2653. ; input
  2654. ;    ES:DI    : hardware_info
  2655. ; output
  2656. ;    AH    : status
  2657. ;--------------------------------------------------------------------
  2658. get_hardware_config:
  2659.         CMP    OSE_flag,0        ;OS/E flag enable?
  2660.         JZ    get_hardware_config1    ;
  2661.         JMP    erra4            ;error exit
  2662. get_hardware_config1:
  2663.         MOV    AX,[BP].es_save        ;
  2664.         MOV    ES,AX            ;
  2665.         MOV    AX,RAW_PAGES        ;
  2666.         STOSW                ;
  2667.         MOV    AX,ALTER_REGS        ;
  2668.         STOSW                ;
  2669.         MOV    AX,CONTEXT_SIZE        ;
  2670.         STOSW                ;
  2671.         MOV    AX,DMA_REGS        ;
  2672.         STOSW                ;
  2673.         MOV    AX,DMA_CHANNEL        ;
  2674.         STOSW                ;
  2675.         JMP    noerr            ;exit
  2676.  
  2677. ;--------------------------------------------------------------------
  2678. ; Get unallocated raw page count
  2679. ; output
  2680. ;    AH    : status
  2681. ;    BX    : unallocated raw pages
  2682. ;    DX    : total raw pages
  2683. ;--------------------------------------------------------------------
  2684. get_unalloc_raw_page:
  2685.         JMP    func3            ;goto function 3
  2686.  
  2687. ;------ function 27 -------------------------------------------------
  2688. ; Allocate raw pages
  2689. ; input
  2690. ;    BX    : num_of_raw_pages_to_alloc
  2691. ; output
  2692. ;    AH    : status
  2693. ;    DX    : raw handle
  2694. ;--------------------------------------------------------------------
  2695. func27:
  2696.         JMP    f41            ;goto function 4
  2697.  
  2698. ;------ function 28 -------------------------------------------------
  2699. ; Alternate map register set
  2700. ;--------------------------------------------------------------------
  2701. func28:
  2702.         STI                ;
  2703.         CMP    OSE_flag,0        ;OS/E flag enable?
  2704.         JZ    f280            ;
  2705.         JMP    erra4            ;error exit
  2706. f280:
  2707.         CMP    AL,0            ;
  2708.         JNZ    f281            ;
  2709.         JMP    get_alter_map_reg    ;
  2710. f281:
  2711.         CMP    AL,1            ;
  2712.         JNZ    f282            ;
  2713.         JMP    set_alter_map_reg    ;
  2714. f282:
  2715.         CMP    AL,2            ;
  2716.         JNZ    f283            ;
  2717.         JMP    get_alter_map_size    ;
  2718. f283:
  2719.         CMP    AL,3            ;
  2720.         JNZ    f284            ;
  2721.         JMP    alloc_alter_map_reg    ;
  2722. f284:
  2723.         CMP    AL,4            ;
  2724.         JNZ    f285            ;
  2725.         JMP    dealloc_alter_map_reg    ;
  2726. f285:
  2727.         CMP    AL,5            ;
  2728.         JNZ    f286            ;
  2729.         JMP    alloc_DMA_reg        ;
  2730. f286:
  2731.         CMP    AL,6            ;
  2732.         JNZ    f287            ;
  2733.         JMP    enable_DMA_alter_reg    ;
  2734. f287:
  2735.         CMP    AL,7            ;
  2736.         JNZ    f288            ;
  2737.         JMP    disable_DMA_alter_reg    ;
  2738. f288:
  2739.         CMP    AL,8            ;
  2740.         JNZ    f289            ;
  2741.         JMP    dealloc_DMA_reg        ;
  2742. f289:
  2743.         JMP    err84            ;error exit
  2744.  
  2745. ;--------------------------------------------------------------------
  2746. ; Get alternate map register set
  2747. ; output
  2748. ;    AH    : status
  2749. ;    BL    : current active alternate map register set number
  2750. ;    ES:DI    : pointer to a map register context save area
  2751. ;--------------------------------------------------------------------
  2752. get_alter_map_reg:
  2753.         MOV    DI,CS:alter_map_off    ;
  2754.         MOV    AX,CS:alter_map_seg    ;
  2755.         MOV    ES,AX            ;
  2756.         OR    AX,DI            ;
  2757.         JNZ    get_alter_map_reg1    ;
  2758.         JMP    get_alter_map_reg2    ;
  2759. get_alter_map_reg1:
  2760.         MOV    SI,OFFSET map_table    ;
  2761.         PUSH    CS            ;
  2762.         POP    DS            ;
  2763.         MOV    CX,CONTEXT_SIZE        ;
  2764.         REPZ    MOVSB            ;
  2765. get_alter_map_reg2:
  2766.         MOV    DI,CS:alter_map_off    ;
  2767.         MOV    AX,CS:alter_map_seg    ;
  2768.         MOV    [BP].di_save,DI        ;
  2769.         MOV    [BP].es_save,AX        ;
  2770.         MOV    BX,[BP].bx_save        ;
  2771.         MOV    BL,0            ;
  2772.         MOV    [BP].bx_save,BX        ;
  2773.         JMP    noerr            ;exit
  2774.  
  2775. ;--------------------------------------------------------------------
  2776. ; Set alternate map register set
  2777. ; input
  2778. ;    BL    : new alternate map register set number
  2779. ;    ES:DI    : pointer to a map register context restore area
  2780. ; output
  2781. ;    AH    : status
  2782. ;--------------------------------------------------------------------
  2783. set_alter_map_reg:
  2784.         CLI                ;
  2785.         CMP    BL,0            ;
  2786.         JZ    set_alter_map_reg1    ;
  2787.         JMP    err9c            ;error exit
  2788. set_alter_map_reg1:
  2789.         MOV    CS:alter_map_off,DI    ;
  2790.         MOV    AX,ES            ;
  2791.         MOV    CS:alter_map_seg,AX    ;
  2792.         OR    AX,DI            ;
  2793.         JNZ    set_alter_map_reg2    ;
  2794.         JMP    noerr            ;exit
  2795. set_alter_map_reg2:
  2796.         MOV    AX,ES            ;
  2797.         MOV    DS,AX            ;
  2798.         MOV    SI,DI            ;
  2799.         MOV    CX,CONTEXT_SIZE        ;
  2800.         MOV    AX,SS            ;
  2801.         MOV    ES,AX            ;
  2802.         LEA    DI,[BP].f28_map_data    ;
  2803.         REPZ    MOVSB            ;
  2804.         LEA    DI,[BP].f28_map_data    ;
  2805.         CALL    check_map_data        ;
  2806.         JNB    set_alter_map_reg3    ;
  2807.         JMP    erra3            ;error exit
  2808. set_alter_map_reg3:
  2809.         MOV    SI,DI            ;
  2810.         MOV    AX,ES            ;
  2811.         MOV    DS,AX            ;
  2812.         MOV    CX,CONTEXT_SIZE        ;
  2813.         MOV    DI,OFFSET map_table    ;
  2814.         PUSH    CS            ;
  2815.         POP    ES            ;
  2816.         PUSH    DI            ;
  2817.         REPZ    MOVSB            ;
  2818.         POP    DI            ;
  2819.         MOV    CX,PHYS_PAGES        ;
  2820. set_alter_map_reg5:
  2821.         MOV    DX,CS:[DI].phys_page_port;mapping physical pages...
  2822.         MOV    AL,CS:[DI].log_page_data;
  2823.         CALL    emsout            ;
  2824.         JNB    set_alter_map_reg4    ;
  2825.         JMP    err81            ;error exit
  2826. set_alter_map_reg4:
  2827.         ADD    DI,SIZE phys_page_struct;
  2828.         LOOP    set_alter_map_reg5    ;
  2829.         JMP    noerr            ;exit
  2830.  
  2831. ;--------------------------------------------------------------------
  2832. ; Get alternate map save array size
  2833. ; output
  2834. ;    AH    : status
  2835. ;    DX    : size_of_array
  2836. ;--------------------------------------------------------------------
  2837. get_alter_map_size:
  2838.         MOV    DX,CONTEXT_SIZE        ;
  2839.         MOV    [BP].dx_save,DX        ;
  2840.         JMP    noerr            ;exit
  2841.  
  2842. ;--------------------------------------------------------------------
  2843. ; Allocate alternate map register set
  2844. ; output
  2845. ;    AH    : status
  2846. ;    BL    : alternate map register set number
  2847. ;--------------------------------------------------------------------
  2848. alloc_alter_map_reg:
  2849.         MOV    BL,0            ;
  2850.         MOV    [BP].bx_save,BX        ;
  2851.         JMP    noerr            ;exit
  2852.  
  2853. ;--------------------------------------------------------------------
  2854. ; Deallocate alternate map register set
  2855. ; input
  2856. ;    BL    : alternate map register set number
  2857. ; output
  2858. ;    AH    : status
  2859. ;--------------------------------------------------------------------
  2860. dealloc_alter_map_reg:
  2861.         CMP    BL,0            ;
  2862.         JZ    dealloc_alter_map_reg1    ;
  2863.         JMP    err9c            ;error exit 
  2864. dealloc_alter_map_reg1:
  2865.         JMP    noerr            ;exit
  2866.  
  2867. ;--------------------------------------------------------------------
  2868. ; Allocate DMA register set
  2869. ; output
  2870. ;    AH    : status
  2871. ;    BL    : DMA register set number
  2872. ;--------------------------------------------------------------------
  2873. alloc_DMA_reg:
  2874.         MOV    BL,0            ;
  2875.         MOV    [BP].bx_save,BX        ;
  2876.         JMP    noerr            ;exit
  2877.  
  2878. ;--------------------------------------------------------------------
  2879. ; Enable DMA on alternate map register set
  2880. ; input
  2881. ;    BL    : DMA register set number
  2882. ;    DL    : DMA channel number
  2883. ; output
  2884. ;    AH    : status
  2885. ;--------------------------------------------------------------------
  2886. enable_DMA_alter_reg:
  2887.         CMP    BL,0            ;
  2888.         JZ    enable_DMA_alter_reg1    ;
  2889.         JMP    err9c            ;error exit 
  2890. enable_DMA_alter_reg1:
  2891.         JMP    noerr            ;exit
  2892.  
  2893. ;--------------------------------------------------------------------
  2894. ; Disable DMA on alternate map register set
  2895. ; input
  2896. ;    BL    : alternate register set number
  2897. ; output
  2898. ;    AH    : status
  2899. ;--------------------------------------------------------------------
  2900. disable_DMA_alter_reg:
  2901.         CMP    BL,0            ;
  2902.         JZ    disable_DMA_alter_reg1    ;
  2903.         JMP    err9c            ;error exit 
  2904. disable_DMA_alter_reg1:
  2905.         JMP    noerr            ;exit
  2906.  
  2907. ;--------------------------------------------------------------------
  2908. ; Deallocate DMA register set
  2909. ; input
  2910. ;    BL    : DMA register set number
  2911. ; output
  2912. ;    AH    : status
  2913. ;--------------------------------------------------------------------
  2914. dealloc_DMA_reg:
  2915.         CMP    BL,0            ;
  2916.         JZ    dealloc_DMA_reg1    ;
  2917.         JMP    err9c            ;error exit 
  2918. dealloc_DMA_reg1:
  2919.         JMP    noerr            ;exit
  2920.  
  2921. ;------ function 29 -------------------------------------------------
  2922. ; Prepare expanded memory hardware for warm boot
  2923. ;--------------------------------------------------------------------
  2924. func29:
  2925.         MOV    AX,CS            ;
  2926.         MOV    ES,AX            ;
  2927.         MOV    DS,AX            ;
  2928.         MOV    DI,OFFSET map_table    ;disable physical pages...
  2929.         MOV    CX,PHYS_PAGES        ;
  2930. f291:                        ;
  2931.         MOV    [DI].emm_handle2,UNMAP    ;
  2932.         MOV    [DI].log_page_data,0    ;
  2933.         ADD    DI,SIZE phys_page_struct;
  2934.         LOOP    f291            ;
  2935.         CALL    set_pages_map        ;
  2936.         JNB    f292            ;
  2937.         JMP    err81            ;error exit
  2938. f292:                        ;
  2939.         MOV    DI,OFFSET handle_flag    ;clear handles...
  2940.         MOV    CX,HANDLE_CNT        ;
  2941.         XOR    AX,AX            ;
  2942.         REPZ    STOSW            ;
  2943.         MOV    DI,OFFSET alloc_page_count;clear handles...
  2944.         MOV    CX,HANDLE_CNT        ;
  2945.         REPZ    STOSW            ;
  2946.         MOV    DI,OFFSET page_address    ;clear handles...
  2947.         MOV    CX,HANDLE_CNT        ;
  2948.         REPZ    STOSW            ;
  2949.         MOV    DI,OFFSET back_address    ;clear handles...
  2950.         MOV    CX,HANDLE_CNT        ;
  2951.         REPZ    STOSW            ;
  2952.         MOV    DI,OFFSET handle_name    ;clear handles...
  2953.         MOV    CX,HANDLE_CNT        ;
  2954.         SHL    CX,1            ;
  2955.         SHL    CX,1            ;
  2956.         REPZ    STOSW            ;
  2957.         MOV    DI,OFFSET alloc_page    ;clear logical page buffer...
  2958.         MOV    CX,PAGE_MAX        ;
  2959.         MOV    AX,0FFFFH        ;
  2960.         REPZ    STOSW            ;
  2961.         XOR    DI,DI            ;set system handle flag...
  2962.         MOV    [DI].handle_flag,1    ;
  2963.         MOV    DI,OFFSET log_page    ;unallocate all logical pages..
  2964.         MOV    AX,NOT_USE        ;
  2965.         MOV    CX,PAGE_MAX        ;
  2966.         REPZ    STOSW            ;
  2967.         XOR    AX,AX            ;
  2968.         MOV    handle_count,1        ;set active handle count
  2969.         MOV    backup_count,AL        ;set backup map count
  2970.         MOV    AX,total_pages        ;
  2971.         MOV    un_alloc_pages,AX    ;set unallocate page count
  2972.         MOV    AX,OFFSET alloc_page    ;set page buffer pointer
  2973.         MOV    page_ptr,AX        ;
  2974.         MOV    AX,OFFSET backup_map    ;set backup map buffer pointer
  2975.         MOV    back_ptr,AX        ;
  2976.         JMP    noerr            ;exit
  2977.         
  2978. ;------ function 30 -------------------------------------------------
  2979. ; Enable/disable OS/E function set functions
  2980. ; input
  2981. ;    BX,CX    : alternate register set number
  2982. ; output
  2983. ;    AH    : status
  2984. ;    BX,CX    : alternate register set number
  2985. ;--------------------------------------------------------------------
  2986. func30:
  2987.         STI                ;
  2988.         CMP    AL,0            ;
  2989.         JZ    enable_OSE_func        ;
  2990.         CMP    AL,1            ;
  2991.         JZ    disable_OSE_func    ;
  2992.         CMP    AL,2            ;
  2993.         JZ    return_access_key    ;
  2994.         JMP    err84            ;error exit 
  2995.  
  2996. ;--------------------------------------------------------------------
  2997. ; Enable OS/E function set
  2998. ; input
  2999. ;    BX,CX    : access_key
  3000. ; output
  3001. ;    AH    : status
  3002. ;    BX,CX    : access_key
  3003. ;--------------------------------------------------------------------
  3004. enable_OSE_func:
  3005.         CMP    OSE_fast,0        ;OS/E fast access flag enable?
  3006.         JZ    enable_OSE_func1    ;
  3007.         CMP    access_key_h,BX        ;compare access key high
  3008.         JNZ    enable_OSE_func2    ;
  3009.         CMP    access_key_l,CX        ;compare access key low
  3010.         JZ    enable_OSE_func1    ;
  3011. enable_OSE_func2:
  3012.         JMP    erra4            ;error exit
  3013. enable_OSE_func1:
  3014.         MOV    OSE_flag,0        ;enable OS/E function
  3015.         MOV    OSE_fast,0FFFFH        ;set OS/E fast access flag
  3016.         MOV    BX,access_key_h        ;
  3017.         MOV    [BP].bx_save,BX        ;
  3018.         MOV    CX,access_key_l        ;
  3019.         MOV    [BP].cx_save,CX        ;
  3020.         JMP    noerr            ;exit
  3021.  
  3022. ;--------------------------------------------------------------------
  3023. ; Disable OS/E function set
  3024. ; input
  3025. ;    BX,CX    : access_key
  3026. ; output
  3027. ;    AH    : status
  3028. ;    BX,CX    : access_key
  3029. ;--------------------------------------------------------------------
  3030. disable_OSE_func:
  3031.         CMP    OSE_fast,0        ;OS/E fast access flag enable?
  3032.         JZ    disable_OSE_func1    ;
  3033.         CMP    access_key_h,BX        ;compare access key high
  3034.         JNZ    disable_OSE_func2    ;
  3035.         CMP    access_key_l,CX        ;compare access key low
  3036.         JZ    disable_OSE_func1    ;
  3037. disable_OSE_func2:
  3038.         JMP    erra4            ;error exit
  3039. disable_OSE_func1:
  3040.         MOV    OSE_flag,0FFFFH        ;disable OS/E function
  3041.         MOV    OSE_fast,0FFFFH        ;set OS/E fast access flag
  3042.         MOV    BX,access_key_h        ;
  3043.         MOV    [BP].bx_save,BX        ;
  3044.         MOV    CX,access_key_l        ;
  3045.         MOV    [BP].cx_save,CX        ;
  3046.         JMP    noerr            ;exit
  3047.  
  3048. ;--------------------------------------------------------------------
  3049. ; Return access key
  3050. ; input
  3051. ;    BX,CX    : access_key
  3052. ; output
  3053. ;    AH    : status
  3054. ;--------------------------------------------------------------------
  3055. return_access_key:
  3056.         CMP    OSE_flag,0        ;OS/E flag enable?
  3057.         JNZ    return_access_key2    ;
  3058.         CMP    access_key_h,BX        ;compare access key high
  3059.         JNZ    return_access_key2    ;
  3060.         CMP    access_key_l,CX        ;compare access key low
  3061.         JZ    return_access_key1    ;
  3062. return_access_key2:
  3063.         JMP    erra4            ;error exit
  3064. return_access_key1:
  3065.         MOV    OSE_flag,0        ;enable OS/E function
  3066.         MOV    OSE_fast,0        ;reset OS/E fast access flag
  3067.         XOR    AX,AX            ;
  3068.         MOV    ES,AX            ;
  3069.         MOV    SI,46CH            ;
  3070.         MOV    AX,ES:[SI]        ;
  3071.         ADD    BX,AX            ;make access key...
  3072.         MOV    access_key_h,BX        ;
  3073.         MOV    SI,46EH            ;
  3074.         ADC    AX,ES:[SI]        ;
  3075.         ADD    CX,AX            ;
  3076.         MOV    access_key_l,CX        ;
  3077.         JMP    noerr            ;exit
  3078.  
  3079. ;========================================================================
  3080.  
  3081. ;--------------------------------------------------------------------
  3082. ; Check mapping data.
  3083. ; input
  3084. ;    ES:DI    : pointer to mapping data
  3085. ; output
  3086. ;    CF = 0    : OK
  3087. ;    CF = 1    : NG
  3088. ;--------------------------------------------------------------------
  3089. check_map_data    PROC    NEAR
  3090.         PUSH    AX            ;
  3091.         PUSH    CX            ;
  3092.         PUSH    SI            ;
  3093.         PUSH    DI            ;
  3094.         MOV    SI,OFFSET map_table    ;
  3095.         MOV    CX,PHYS_PAGES        ;
  3096. check_map_data3:
  3097.         MOV    AX,ES:[DI].phys_page_port;
  3098.         CMP    AX,CS:[SI].phys_page_port;
  3099.         JNZ    check_map_data1        ;
  3100.         MOV    AX,ES:[DI].phys_seg_addr;
  3101.         CMP    AX,CS:[SI].phys_seg_addr;
  3102.         JNZ    check_map_data1        ;
  3103.         ADD    SI,SIZE phys_page_struct;
  3104.         ADD    DI,SIZE phys_page_struct;
  3105.         LOOP    check_map_data3        ;
  3106.         CLC                ;
  3107.         JMP    check_map_data2        ;
  3108. check_map_data1:
  3109.         STC                ;
  3110. check_map_data2:
  3111.         POP    DI            ;
  3112.         POP    SI            ;
  3113.         POP    CX            ;
  3114.         POP    AX            ;
  3115.         RET                ;
  3116. check_map_data    ENDP
  3117.  
  3118. ;--------------------------------------------------------------------
  3119. ; Check logical page no.
  3120. ; input
  3121. ;    BX    : logical page number in handle
  3122. ;    DX    : EMM handle
  3123. ; output
  3124. ;    AX    : logical page number in EMM
  3125. ;    CF = 0    : OK
  3126. ;    CF = 1    : NG
  3127. ;--------------------------------------------------------------------
  3128. check_log_page     PROC    NEAR
  3129.         PUSH    CX            ;v0.6....
  3130.         PUSH    SI            ;
  3131.         MOV    SI,DX            ;
  3132.         SHL    SI,1            ;
  3133.         CMP    BX,CS:[SI].alloc_page_count;
  3134.         JB    check_log_page1        ;
  3135.         STC                ;
  3136.         JMP    check_log_page2        ;
  3137. check_log_page1:                ;
  3138.         MOV    SI,CS:[SI].page_address    ;
  3139.         MOV    AX,BX            ;
  3140.         SHL    AX,1            ;
  3141.         ADD    SI,AX            ;
  3142.         MOV    AX,CS:[SI]        ;get logical no. in EMM
  3143.         CLC                ;
  3144. check_log_page2:                ;
  3145.         POP    SI            ;
  3146.         POP    CX            ;
  3147.         RET                ;
  3148. check_log_page     ENDP
  3149.  
  3150. ;--------------------------------------------------------------------
  3151. ; Check EMM handle no.
  3152. ; input
  3153. ;    DX    : EMM handle
  3154. ; output
  3155. ;    CF = 0    : OK
  3156. ;    CF = 1    : NG
  3157. ;--------------------------------------------------------------------
  3158. check_handle     PROC    NEAR
  3159.         PUSH    AX            ;
  3160.         PUSH    DI            ;
  3161.         CMP    DX,HANDLE_CNT        ;
  3162.         JNB    check_handle1        ;
  3163.         CLC                ;reset CF
  3164.         MOV    DI,DX            ;
  3165.         SHL    DI,1            ;
  3166.         MOV    AX,CS:[DI].handle_flag    ;active handle ?
  3167.         OR    AX,AX            ;
  3168.         JNZ    check_handle2        ;
  3169. check_handle1:                    ;
  3170.         STC                ;set CF
  3171. check_handle2:                    ;
  3172.         POP    DI            ;
  3173.         POP    AX            ;
  3174.         RET                ;
  3175. check_handle     ENDP
  3176.  
  3177. ;--------------------------------------------------------------------
  3178. ; Set physical page map.
  3179. ; output
  3180. ;    CF = 0    : OK
  3181. ;    CF = 1    : NG
  3182. ;--------------------------------------------------------------------
  3183. set_pages_map    PROC    NEAR
  3184.         PUSH    AX            ;
  3185.         PUSH    CX            ;
  3186.         PUSH    DX            ;
  3187.         PUSH    DI            ;
  3188.         MOV    DI,OFFSET map_table    ;
  3189.         MOV    CX,PHYS_PAGES        ;
  3190. set_pages_map2:                    ;
  3191.         MOV    DX,CS:[DI].phys_page_port;mapping physical pages...
  3192.         MOV    AL,CS:[DI].log_page_data;
  3193.         CALL    emsout            ;
  3194.         JB    set_pages_map1        ;
  3195.         ADD    DI,SIZE phys_page_struct;
  3196.         LOOP    set_pages_map2        ;
  3197.         CLC                ;
  3198. set_pages_map1:                    ;
  3199.         POP    DI            ;
  3200.         POP    DX            ;
  3201.         POP    CX            ;
  3202.         POP    AX            ;
  3203.         RET                ;
  3204. set_pages_map    ENDP
  3205.  
  3206. ;--------------------------------------------------------------------
  3207. ; Reset physical page.
  3208. ; input
  3209. ;    AL    : physical page no.
  3210. ;--------------------------------------------------------------------
  3211. reset_phys_page    PROC    NEAR
  3212.         PUSH    AX            ;
  3213.         PUSH    CX            ;
  3214.         PUSH    DX            ;
  3215.         PUSH    DI            ;
  3216.         XOR    AH,AH            ;
  3217.         MOV    DI,OFFSET map_table    ;
  3218.         MOV    CL,SIZE phys_page_struct;
  3219.         MUL    CL            ;
  3220.         ADD    DI,AX            ;
  3221.         MOV    DX,CS:[DI].phys_page_port;
  3222.         MOV    AL,DIS_EMS        ;
  3223.         CALL    emsout            ;
  3224.         JB    reset_phys_page1    ;error ?
  3225.         MOV    CS:[DI].emm_handle2,UNMAP;
  3226.         MOV    CS:[DI].log_page_data,AL;logical page no.
  3227. reset_phys_page1:                ;
  3228.         POP    DI            ;
  3229.         POP    DX            ;
  3230.         POP    CX            ;
  3231.         POP    AX            ;
  3232.         RET
  3233. reset_phys_page    ENDP
  3234.  
  3235. ;--------------------------------------------------------------------
  3236. ; Set physical page.
  3237. ; input
  3238. ;    AL    : physical page no.
  3239. ;    BX    : logical page no. in EMM (if BX=FFFFH then unmap)
  3240. ;    DX    : EMM handle
  3241. ;--------------------------------------------------------------------
  3242. set_phys_page    PROC    NEAR
  3243.         PUSH    AX            ;
  3244.         PUSH    CX            ;
  3245.         PUSH    DX            ;
  3246.         PUSH    DI            ;
  3247.         XOR    AH,AH            ;
  3248.         MOV    DI,OFFSET map_table    ;
  3249.         MOV    CL,SIZE phys_page_struct;
  3250.         MUL    CL            ;
  3251.         ADD    DI,AX            ;
  3252.         PUSH    DX            ;
  3253.         MOV    DX,CS:[DI].phys_page_port;
  3254.         MOV    AX,BX            ;
  3255.         ADD    AL,CS:pageofs        ;
  3256.         CALL    emsout            ;
  3257.         POP    DX            ;
  3258.         JB    set_phys_page1        ;error ?
  3259.         MOV    CS:[DI].emm_handle2,DX    ;handle
  3260.         MOV    CS:[DI].log_page_data,AL;logical page no.
  3261. set_phys_page1:
  3262.         POP    DI            ;
  3263.         POP    DX            ;
  3264.         POP    CX            ;
  3265.         POP    AX            ;
  3266.         RET                ;
  3267. set_phys_page    ENDP
  3268.  
  3269. ;--------------------------------------------------------------------
  3270. ; Change mappable segment address to physical page number.
  3271. ; input
  3272. ;    AX    : mappable segment address
  3273. ; output
  3274. ;    AX    : physical page number
  3275. ;--------------------------------------------------------------------
  3276. change_seg_page    PROC    NEAR
  3277.         PUSH    BX            ;
  3278.         PUSH    CX            ;
  3279.         PUSH    DI            ;
  3280.         CLC                ;reset CF
  3281.         XOR    BX,BX            ;
  3282.         MOV    DI,OFFSET map_table    ;
  3283.         MOV    CX,PHYS_PAGES        ;
  3284. change_seg_page2:
  3285.         CMP    AX,CS:[DI].phys_seg_addr;
  3286.         JZ    change_seg_page1    ;
  3287.         ADD    DI,SIZE phys_page_struct;
  3288.         INC    BX            ;
  3289.         LOOP    change_seg_page2    ;
  3290.         STC                ;set CF
  3291. change_seg_page1:
  3292.         MOV    AX,BX            ;
  3293.         POP    DI            ;
  3294.         POP    CX            ;
  3295.         POP    BX            ;
  3296.         RET                ;
  3297. change_seg_page    ENDP
  3298.  
  3299. ;--------------------------------------------------------------------
  3300. ; Output EMS i/o port.
  3301. ; input
  3302. ;    DX    : i/o port address
  3303. ;    AL    : output data
  3304. ; output
  3305. ;    CF = 0    : OK
  3306. ;    CF = 1    : NG
  3307. ;--------------------------------------------------------------------
  3308. emsout        PROC    NEAR
  3309.         PUSH    AX            ;
  3310.         PUSH    CX            ;
  3311.         PUSH    DX            ;
  3312.         OUT    DX,AL            ;
  3313.         MOV    CX,1000            ;
  3314.         MOV    DX,CS:emsio        ;get EMS status port address.
  3315. emsout2:                    ;
  3316.         IN    AL,DX            ;
  3317.         TEST    AL,80H            ;check TRS flag
  3318.         JZ    emsout1            ;
  3319.         LOOP    emsout2            ;
  3320.         INC    DX            ; 00 -> EMS REGISTER R1...
  3321.         XOR    AL,AL            ;
  3322.         OUT    DX,AL            ;
  3323.         STC                ;set CF
  3324.         JMP    emsout3            ;
  3325. emsout1:                    ;
  3326.         INC    DX            ; 00 -> EMS REGISTER R1...
  3327.         XOR    AL,AL            ;
  3328.         OUT    DX,AL            ;
  3329.         CLC                ;reset CF
  3330. emsout3:                    ;
  3331.         POP    DX            ;
  3332.         POP    CX            ;
  3333.         POP    AX            ;
  3334.         RET                ;
  3335. emsout        ENDP
  3336.  
  3337. ;.........................................................................
  3338.  
  3339. ;--------------------------------------------------------------------
  3340. ;    EMM driver work data area
  3341. ;--------------------------------------------------------------------
  3342. emsio        LABEL    WORD
  3343. ems_io        DW    98H        ;EMS i/o port address
  3344. pageofs        DB    ?        ;logical page no. offset data
  3345. backup_count    DB    0        ;mapping data backup count
  3346. OSE_flag    DW    0        ;OS/E function enable flag
  3347. OSE_fast    DW    0        ;OS/E fast access flag
  3348. access_key_h    DW    0        ;OS/E access key high
  3349. access_key_l    DW    0        ;OS/E access key low
  3350. alter_map    LABEL    DWORD
  3351. alter_map_off    DW    0        ;
  3352. alter_map_seg    DW    0        ;
  3353. page_ptr    DW    alloc_page    ;allocate page buffer pointer.
  3354. back_ptr    DW    backup_map    ;backup map buffer pointer.
  3355.  
  3356. ;
  3357. ;    i/o port address buffer
  3358. ;
  3359. port_addr    LABEL    WORD
  3360.         DW    PHYS_PAGES DUP (-1)
  3361.  
  3362. ;
  3363. ;    physical page status data area
  3364. ;
  3365. map_table    LABEL    phys_page_struct
  3366.         DB    SIZE phys_page_struct * PHYS_PAGES DUP (-1)
  3367.  
  3368. ;
  3369. ;    handle name buffer
  3370. ;
  3371. handle_name    LABEL    BYTE
  3372.         DB    HANDLE_NAME_SIZE * HANDLE_CNT DUP (0)
  3373.  
  3374. ;
  3375. ;    handle status flag buffer pointers (handle)
  3376. ;
  3377. handle_flag    LABEL    WORD
  3378.         DW    HANDLE_CNT DUP(0)
  3379.  
  3380. ;
  3381. ;    allocate page count buffer pointers (handle)
  3382. ;
  3383. alloc_page_count LABEL    WORD
  3384.         DW    HANDLE_CNT DUP(0)
  3385.  
  3386. ;
  3387. ;    mapping data backup buffer pointers (handle)
  3388. ;
  3389. back_address    LABEL    WORD
  3390.         DW    HANDLE_CNT DUP(0)
  3391.  
  3392. ;
  3393. ;    mapping data backup area
  3394. ;
  3395. backup_map    LABEL    WORD
  3396.         DB    SIZE phys_page_struct * PHYS_PAGES * BACK_MAX DUP(-1)
  3397.  
  3398. ;
  3399. ;    allocate pages buffer pointers (handle)
  3400. ;
  3401. page_address    LABEL    WORD
  3402.         DW    HANDLE_CNT DUP(0)
  3403.  
  3404. ;
  3405. ;    allocate data area
  3406. ;
  3407. alloc_page    LABEL    WORD
  3408.         DW    PAGE_MAX DUP(-1)
  3409.  
  3410. ;
  3411. ;    logical page kanri data
  3412. ;    55AAH:not used , 0 - 254:used , FFFFH:bad or non
  3413. ;
  3414. log_page    LABEL    WORD
  3415.         DB    LOG_SIZE * PAGE_MAX DUP (-1)
  3416.  
  3417. ;********************************************************************
  3418.  
  3419. ;--------------------------------------------------------------------
  3420. ; EMM driver initilize program
  3421. ;--------------------------------------------------------------------
  3422. emminit:
  3423.         PUSH    CX            ;Store registers...
  3424.         PUSH    DX            ;
  3425.         PUSH    SI            ;
  3426.         PUSH    ES            ;
  3427.         PUSH    BP            ;
  3428.         PUSH    CS            ;
  3429.         POP    DS            ;
  3430.         XOR    AX,AX            ;
  3431.         MOV    ES,AX            ;
  3432.         MOV    SI,19CH            ;
  3433.         MOV    WORD PTR ES:[SI],OFFSET int67;set int67 offset.
  3434.         MOV    ES:[SI+2],CS        ;set int67 segment.
  3435.         MOV    SI,OFFSET start_msg    ;display start messege.
  3436.         CALL    strdsp            ;
  3437.         CALL    getprm            ;get parameters
  3438.         CALL    ckemsio            ;check EMS i/o port
  3439.         JB    errems            ;error ?
  3440.         CALL    ramchk            ;check EMS memory
  3441.         JB    errems            ;error ?
  3442.         CALL    instmsg            ;display install message.
  3443.         XOR    AX,AX            ;
  3444.         MOV    ES,AX            ;
  3445.         MOV    SI,46CH            ;
  3446.         MOV    AX,ES:[SI]        ;
  3447.         ADD    BX,AX            ;make access key...
  3448.         MOV    access_key_h,BX        ;
  3449.         MOV    SI,46EH            ;
  3450.         ADC    AX,ES:[SI]        ;
  3451.         ADD    BX,AX            ;
  3452.         MOV    access_key_l,BX        ;
  3453.         XOR    DI,DI            ;set system handle...
  3454.         PUSH    CS            ;
  3455.         POP    ES            ;
  3456.         MOV    ES:[DI].handle_flag,1    ;set system handle active.
  3457.         INC    CS:handle_count        ;handle count up
  3458.         MOV    AX,OFFSET emminit    ;make break address...
  3459.         ADD    AX,0FH            ;
  3460.         MOV    CL,4            ;
  3461.         SHR    AX,CL            ;
  3462.         MOV    CX,AX            ;
  3463.         MOV    AX,CS            ;
  3464.         ADD    AX,CX            ;
  3465.         MOV    emm_flag,1        ;set EMM install flag.
  3466.         LDS    BX,ptrsav        ;
  3467.         MOV    [BX].brkoff,0        ;break address offset set.
  3468.         MOV    [BX].brkseg,AX        ;break address segment set.
  3469.         JMP    emmint1            ;
  3470. errems:                        ;
  3471.         MOV    SI,OFFSET notinst    ;display error message
  3472.         CALL    strdsp            ;
  3473.         MOV    emm_flag,0        ;reset EMM install flag.
  3474.         PUSH    CS            ;
  3475.         POP    ES            ;
  3476.         MOV    DI,OFFSET func_table    ;
  3477.         MOV    AX,OFFSET err80        ;
  3478.         MOV    CX,30            ;
  3479.         REPZ    STOSW            ;
  3480.         LDS    BX,ptrsav        ;
  3481.         MOV    AX,OFFSET func2        ;set break address offset.
  3482.         MOV    [BX].brkoff,AX        ;set break address offset.
  3483.         MOV    [BX].brkseg,CS        ;set break address segment.
  3484. emmint1:                    ;
  3485.         POP    BP            ;Restore registers...
  3486.         POP    ES            ;
  3487.         POP    SI            ;
  3488.         POP    DX            ;
  3489.         POP    CX            ;
  3490.         JMP    exit            ;exit initial program.
  3491.  
  3492. ;--------------------------------------------------------------------
  3493. ; Get CONFIG.SYS parameters.
  3494. ;--------------------------------------------------------------------
  3495. getprm        PROC    NEAR
  3496.         PUSH    DS        ;
  3497.         INT    12H        ;get system memory size.
  3498.         MOV    sysmem,AX    ;
  3499.         LES    BX,ptrsav    ;
  3500.         MOV    DI,ES:[BX].count;
  3501.         MOV    AX,ES:[BX].start;
  3502.         MOV    ES,AX        ;
  3503.         XOR    CL,CL        ;
  3504. getpr2:                    ;
  3505.         MOV    AL,ES:[DI]    ;
  3506.         CMP    AL,'/'        ;option switch?
  3507.         JNZ    getpr3        ;
  3508.         INC    DI        ;
  3509.         MOV    AL,ES:[DI]    ;
  3510.         CMP    AL,'M'        ;set system memory size?
  3511.         JNZ    getpr1        ;
  3512.         INC    DI        ;
  3513.         MOV    AL,ES:[DI]    ;
  3514.         CMP    AL,':'        ;
  3515.         JNZ    getpr3        ;
  3516.         INC    DI        ;
  3517.         CALL    ascbin1        ;change data ascii -> binary.
  3518.         JB    getpr5        ;
  3519.         MOV    sysmem,AX    ;set system memory size data.
  3520.         JMP    getpr5        ;next.
  3521. getpr1:                    ;
  3522.         CMP    AL,'P'        ;set page frame address?
  3523.         JNZ    getpr3        ;
  3524.         INC    DI        ;
  3525.         MOV    AL,ES:[DI]    ;
  3526.         CMP    AL,':'        ;
  3527.         JNZ    getpr1        ;
  3528.         INC    DI        ;
  3529.         CALL    ascbin2        ;change data ascii -> binary.
  3530.         JNB    getpr8        ;error ?
  3531.         JMP    getpr5        ;
  3532. getpr8:                    ;
  3533.         MOV    pageseg,AX    ;
  3534.         MOV    page_frame_seg,AX;
  3535.         OR    CL,2        ;set page frame address change flag.
  3536.         JMP    getpr5        ;
  3537. getpr3:                    ;
  3538.         CMP    AL,'I'        ;set EMS i/o port address?
  3539.         JNZ    getpr6        ;
  3540.         INC    DI        ;
  3541.         MOV    AL,ES:[DI]    ;
  3542.         CMP    AL,':'        ;
  3543.         JNZ    getpr1        ;
  3544.         INC    DI        ;
  3545.         CALL    ascbin2        ;change data ascii -> binary.
  3546.         MOV    rqioadr,AX    ;
  3547.         MOV    emsio,AX    ;
  3548.         OR    CL,1        ;set EMS i/o port address change flag.
  3549.         JMP    getpr5        ;
  3550. getpr6:                    ;
  3551.         CMP    AL,CR        ;
  3552.         JZ    getpr4        ;
  3553. getpr5:                    ;
  3554.         INC    DI        ;
  3555.         JMP    getpr2        ;
  3556. getpr4:                    ;
  3557.         MOV    sysflg,CL    ;set system option flag.
  3558.         POP    DS        ;
  3559.         RET            ;
  3560. getprm        ENDP
  3561.  
  3562. ;--------------------------------------------------------------------
  3563. ; Check EMS i/o port.
  3564. ; output
  3565. ;    cf = 0 : OK
  3566. ;    cf = 1 : NG
  3567. ;--------------------------------------------------------------------
  3568. ckemsio        PROC    NEAR
  3569.         MOV    DX,EMSIOA        ;
  3570.         MOV    AL,CHKIOA        ;
  3571.         OUT    DX,AL            ;
  3572.         IN    AL,DX            ;
  3573.         TEST    AL,80H            ;check TRS flag
  3574.         JNZ    ckems7            ;
  3575.         MOV    AL,CHKIOA        ;
  3576.         OUT    DX,AL            ;
  3577.         IN    AL,DX            ;
  3578.         TEST    AL,80H            ;check TRS flag
  3579.         JZ    ckems1            ;
  3580. ckems7:                        ;
  3581.         MOV    CX,1000            ;
  3582. ckems5:                        ;
  3583.         IN    AL,DX            ;
  3584.         TEST    AL,80H            ;check TRS flag
  3585.         JZ    ckems6            ;
  3586.         LOOP    ckems5            ;
  3587.         JMP    ckems1            ;
  3588. ckems6:                        ;
  3589.         MOV    BL,CHKIOA        ;
  3590.         AND    BL,7FH            ;
  3591.         CMP    AL,BL            ;
  3592.         JZ    ckems2            ;
  3593. ckems1:                        ;
  3594.         MOV    DX,EMSIOB        ;
  3595.         MOV    AL,CHKIOB        ;
  3596.         OUT    DX,AL            ;
  3597.         IN    AL,DX            ;
  3598.         TEST    AL,80H            ;check TRS flag
  3599.         JNZ    ckems8            ;
  3600.         MOV    AL,CHKIOB        ;
  3601.         OUT    DX,AL            ;
  3602.         IN    AL,DX            ;
  3603.         TEST    AL,80H            ;check TRS flag
  3604.         JZ    ckems3            ;
  3605. ckems8:                        ;
  3606.         MOV    CX,1000            ;
  3607. ckems9:                        ;
  3608.         IN    AL,DX            ;
  3609.         TEST    AL,80H            ;check TRS flag
  3610.         JZ    ckemsa            ;
  3611.         LOOP    ckems9            ;
  3612.         JMP    ckems3            ;
  3613. ckemsa:                        ;
  3614.         MOV    BL,CHKIOB        ;
  3615.         AND    BL,7FH            ;
  3616.         CMP    AL,BL            ;
  3617.         JNZ    ckems3            ;
  3618. ckems2:                        ;
  3619.         MOV    CS:emsio,DX        ;set i/o port address.
  3620.         TEST    BYTE PTR CS:sysflg,1    ;
  3621.         JZ    ckems4            ;
  3622.         MOV    AX,CS:rqioadr        ;
  3623.         MOV    BX,AX            ;change EMS i/o port addess.
  3624.         MOV    DX,CS:emsio        ;
  3625.         MOV    CL,3            ;
  3626.         SHR    AX,CL            ;
  3627.         OR    AL,80H            ;
  3628.         CALL    emsout            ;
  3629.         MOV    CS:emsio,BX        ;
  3630. ckems4:                        ;
  3631.         CLC                ;reset CF
  3632.         RET                ;
  3633. ckems3:                        ;
  3634.         MOV    SI,OFFSET hard_w_err    ;display wardware error messege.
  3635.         CALL    strdsp            ;
  3636.         STC                ;set CF
  3637.         RET                ;
  3638. ckemsio        ENDP
  3639.  
  3640. ;--------------------------------------------------------------------
  3641. ; Check system memory size.
  3642. ;--------------------------------------------------------------------
  3643. sysram        PROC    NEAR
  3644.         PUSH    CS            ;
  3645.         POP    DS            ;
  3646.         PUSH    ES            ;
  3647.         XOR    AX,AX            ;set system memory size.
  3648.         MOV    ES,AX            ;
  3649.         MOV    AX,sysmem        ;
  3650.         CMP    ES:WORD PTR MEMSIZE,AX    ;memory size same ?
  3651.         JZ    sysram1            ;
  3652.         MOV    ES:WORD PTR MEMSIZE,AX    ;
  3653.         INT    19H            ;reboot...
  3654. sysram1:                    ;
  3655.         POP    ES            ;
  3656.         MOV    BX,40H            ;
  3657.         MUL    BX            ;
  3658.         MOV    DX,emsio        ;
  3659.         ADD    DX,2            ;
  3660.         MOV    AL,AH            ;
  3661.         CALL    emsout            ;output EMS i/o port data.
  3662.         SHR    AL,1            ;
  3663.         SHR    AL,1            ;
  3664.         MOV    pageofs,AL        ;set page no. offset data
  3665.         MOV    DX,STATSEG         ;;;v1.01
  3666.         RET                ;
  3667. sysram        ENDP
  3668.  
  3669. ;--------------------------------------------------------------------
  3670. ; Check expanded memory.
  3671. ; output
  3672. ;    cf = 0 : OK
  3673. ;    cf = 1 : NG
  3674. ;--------------------------------------------------------------------
  3675. ramchk        PROC    NEAR
  3676.         PUSH    AX            ;
  3677.         PUSH    BX            ;
  3678.         PUSH    CX            ;
  3679.         PUSH    DX            ;
  3680.         PUSH    BP            ;
  3681.         PUSH    CS            ;
  3682.         POP    DS            ;
  3683.         MOV    SI,OFFSET port_addr    ;set phys_page i/o port address
  3684.         MOV    DI,OFFSET map_table    ;
  3685.         MOV    CX,PHYS_PAGES        ;
  3686.         MOV    BX,emsio        ;
  3687.         ADD    BX,4            ;
  3688. ramch14:                    ;
  3689.         MOV    [SI],BX            ;
  3690.         MOV    [DI].phys_page_port,BX    ;
  3691.         MOV    [DI].log_page_data,0    ;
  3692.         ADD    DI,SIZE phys_page_struct;
  3693.         MOV    DX,BX            ;disable physical pages ---
  3694.         MOV    AL,DIS_EMS        ;
  3695.         CALL    emsout            ;--------------------------
  3696.         INC    SI            ;
  3697.         INC    SI            ;
  3698.         INC    BX            ;
  3699.         LOOP    ramch14            ;------------------------------
  3700.         CALL    SYSRAM            ;set system memory size
  3701.         TEST    BYTE PTR sysflg,2    ;ver x.x.......
  3702.         JZ    ramch20            ;
  3703.         MOV    AX,pageseg        ;physical page segment set
  3704.         MOV    page_frame_seg,AX    ;
  3705.         JMP    ramch12            ;
  3706. ramch20:                    ;..............
  3707.         XOR    SI,SI            ;
  3708. ramch4:                        ;found 64KB free area...
  3709.         MOV    BP,DX            ;
  3710.         XOR    BX,BX            ;
  3711. ramch6:                        ;
  3712.         MOV    ES,DX            ;
  3713.         MOV    WORD PTR ES:[SI],0000H    ;
  3714.         CMP    WORD PTR ES:[SI],0AA55H    ;
  3715.         JNZ    ckrom1            ;
  3716.         XOR    AH,AH            ;
  3717.         MOV    AL,ES:[SI+2]        ;
  3718.         MOV    CL,5            ;
  3719.         SHL    AX,CL            ;
  3720.         ADD    DX,AX            ;
  3721.         JMP    ramch1            ;
  3722. ckrom1:
  3723.         OR    BX,BX            ;
  3724.         JNZ    ckrom2            ;
  3725.         MOV    AX,DX            ;
  3726.         AND    AX,3FFH            ;
  3727.         OR    AX,AX            ;
  3728.         JZ    ckrom5            ;
  3729.         AND    DX,0FC00H        ;
  3730.         ADD    DX,400H            ;
  3731.         JMP    ramch4            ;
  3732. ckrom2:
  3733.         ADD    DX,80H            ;
  3734. ckrom5:
  3735.         MOV    WORD PTR ES:[SI],55AAH    ;
  3736.         CMP    WORD PTR ES:[SI],55AAH    ;
  3737.         JZ    ramch1            ;
  3738.         INC    BX            ;
  3739.         CMP    BX,20H            ;
  3740.         JNB    ramch2            ;
  3741.         CMP    DX,ROMSEG        ;
  3742.         JB    ramch6            ;
  3743.         JMP    ramch3            ;
  3744. ramch1:                        ;
  3745.         CMP    DX,ENDSEG        ;
  3746.         JB    ramch4            ;
  3747. ramch3:                        ;
  3748.         PUSH    CS            ;
  3749.         POP    DS            ;
  3750.         MOV    SI,OFFSET nomem        ;
  3751.         CALL    strdsp            ;
  3752.         STC                ;
  3753.         JMP    ramch5            ;........................
  3754. ramch2:                        ;
  3755.         PUSH    CS            ;
  3756.         POP    DS            ;
  3757.         MOV    AX,BP            ;
  3758.         MOV    page_frame_seg,AX    ;
  3759. ;        TEST    BYTE PTR sysflg,2    ;ver x.x.............
  3760. ;        JZ    ramch12            ;
  3761. ;        MOV    AX,pageseg        ;physical page segment set
  3762. ;        MOV    page_frame_seg,AX    ;------------------------------
  3763. ramch12:                    ;
  3764.         MOV    AX,page_frame_seg    ;segment start address set
  3765.         MOV    AL,AH            ;
  3766.         MOV    DX,emsio        ;
  3767.         ADD    DX,3            ;
  3768.         CALL    emsout            ;EMS i/o port data out
  3769.         MOV    DI,OFFSET map_table    ;set physical page frame address
  3770.         MOV    CX,PHYS_PAGES        ;
  3771.         MOV    AX,page_frame_seg    ;+
  3772. ramch18:                    ;+
  3773.         MOV    [DI].phys_seg_addr,AX    ;+
  3774.         ADD    DI,SIZE phys_page_struct;+
  3775.         ADD    AX,0400H        ;+
  3776.         LOOP    ramch18            ;------------------------------
  3777.         MOV    SI,OFFSET pagemsg    ;display page test msg..
  3778.         CALL    strdsp            ;
  3779.         IN    AL,I8042+1        ;logical page test...
  3780.         OR    AL,4            ;system memory parity disable
  3781.         OUT    I8042+1,AL        ;
  3782.         MOV    SI,OFFSET port_addr    ;
  3783.         MOV    DI,OFFSET log_page    ;
  3784.         MOV    DX,[SI]            ;
  3785.         CMP    DX,0FFFFH        ;
  3786.         JZ    ramch7            ;
  3787.         XOR    AH,AH            ;
  3788.         MOV    AL,pageofs        ;get EMS logical page start no.
  3789.         MOV    CX,PAGE_MAX        ;
  3790.         XOR    BX,BX            ;
  3791. ramch9:                        ;
  3792.         PUSH    CX            ;
  3793.         CALL    emsout            ;EMS i/o port data out
  3794.         CALL    imgchk            ;
  3795.         JNB    ramch17            ;
  3796.         POP    CX            ;
  3797.         JMP    ramch16            ;
  3798. ramch17:                    ;
  3799.         CALL    pagetst            ;
  3800.         JB    ramch8            ;
  3801.         MOV    [DI],NOT_USE        ;
  3802.         INC    BX            ;
  3803.         ADD    DI,LOG_SIZE        ;
  3804. ramch8:                        ;
  3805.         POP    CX            ;
  3806.         INC    AL            ;
  3807.         LOOP    ramch9            ;
  3808. ramch16:                    ;
  3809.         MOV    total_pages,BX        ;
  3810.         MOV    un_alloc_pages,BX    ;
  3811.         MOV    CX,PHYS_PAGES        ;disable physical pages...
  3812.         MOV    DX,CS:emsio        ;
  3813.         ADD    DX,4            ;
  3814. ramch19:
  3815.         MOV    AL,DIS_EMS        ;
  3816.         CALL    emsout            ;
  3817.         INC    DX            ;
  3818.         LOOP    ramch19            ;
  3819.         IN    AL,I8042+1        ;enable system memory parity..
  3820.         AND    AL,0FBH            ;
  3821.         OUT    I8042+1,AL        ;
  3822.         CMP    total_pages,0        ;total page zero?
  3823.         JNZ    ramch7            ;
  3824.         MOV    SI,OFFSET nopage_err    ;error message display
  3825.         CALL    strdsp            ;
  3826.         STC                ;set CF
  3827.         JMP    ramch5            ;
  3828. ramch7:                        ;
  3829.         CLC                ;
  3830. ramch5:                        ;
  3831.         POP    BP            ;
  3832.         POP    DX            ;
  3833.         POP    CX            ;
  3834.         POP    BX            ;
  3835.         POP    AX            ;
  3836.         RET                ;
  3837. ramchk        ENDP
  3838.  
  3839. ;--------------------------------------------------------------------
  3840. ; Display EMM install opening message.
  3841. ;--------------------------------------------------------------------
  3842. instmsg        PROC    NEAR
  3843.         PUSH    AX            ;
  3844.         PUSH    BX            ;
  3845.         PUSH    CX            ;
  3846.         PUSH    DI            ;
  3847.         PUSH    CS            ;
  3848.         POP    ES            ;
  3849.         MOV    SI,OFFSET openmsg    ;
  3850.         CALL    strdsp            ;
  3851.         MOV    AX,total_pages        ;
  3852.         MOV    DI,OFFSET total_pg    ;
  3853.         CALL    dbinasc            ;
  3854.         MOV    SI,OFFSET install_msg    ;
  3855.         CALL    strdsp            ;
  3856.         MOV    AX,page_frame_seg    ;
  3857.         MOV    DI,OFFSET segadr    ;
  3858.         CALL    hbinasc            ;
  3859.         MOV    SI,OFFSET page_msg    ;
  3860.         CALL    strdsp            ;
  3861.         MOV    AX,emsio        ;
  3862.         MOV    DI,OFFSET pioadr    ;
  3863.         CALL    hbinasc            ;
  3864.         MOV    SI,OFFSET port_msg    ;
  3865.         CALL    strdsp            ;
  3866.         POP    DI            ;
  3867.         POP    CX            ;
  3868.         POP    BX            ;
  3869.         POP    AX            ;
  3870.         RET                ;
  3871. instmsg        ENDP
  3872.  
  3873. ;--------------------------------------------------------------------
  3874. ; check memory size (1024 KByte)
  3875. ;--------------------------------------------------------------------
  3876. imgchk        PROC    NEAR
  3877.         CLD                ;
  3878.         PUSH    AX            ;
  3879.         PUSH    CX            ;
  3880.         PUSH    SI            ;
  3881.         PUSH    DI            ;
  3882.         PUSH    DS            ;
  3883.         MOV    AX,page_frame_seg    ;
  3884.         MOV    ES,AX            ;
  3885.         PUSH    CX            ;
  3886.         XOR    AX,AX            ;
  3887.         MOV    DS,AX            ;
  3888.         XOR    SI,SI            ;
  3889.         XOR    DI,DI            ;
  3890.         MOV    CX,2000H        ;
  3891.         REPZ    CMPSW            ;
  3892.         CMP    CX,0            ;
  3893.         JNZ    imgch1            ;
  3894.         POP    CX            ;
  3895.         STC                ;
  3896.         JMP    imgch3            ;
  3897. imgch1:
  3898.         POP    CX            ;
  3899.         CLC                ;reset CF
  3900. imgch3:
  3901.         POP    DS            ;
  3902.         POP    DI            ;
  3903.         POP    SI            ;
  3904.         POP    CX            ;
  3905.         POP    AX            ;
  3906.         RET                ;
  3907. imgchk        ENDP
  3908.  
  3909. ;--------------------------------------------------------------------
  3910. ; check logical page memory.
  3911. ; input
  3912. ;    AX    : logical page no.
  3913. ;--------------------------------------------------------------------
  3914. pagetst        PROC    NEAR
  3915.         CLD                ;reset DF
  3916.         PUSH    AX            ;push registers...
  3917.         PUSH    BX            ;
  3918.         PUSH    CX            ;
  3919.         PUSH    DX            ;
  3920.         PUSH    SI            ;
  3921.         PUSH    DI            ;
  3922.         PUSH    DS            ;
  3923.         PUSH    CS            ;set ES <- CS..
  3924.         POP    ES            ;
  3925.         SUB    AL,pageofs        ;sub page no. - page offset.
  3926.         MOV    DI,OFFSET tstpage    ;
  3927.         CALL    dbinasc            ;change binary -> ascii.
  3928.         MOV    SI,OFFSET tstpage    ;display message..
  3929.         CALL    strdsp            ;
  3930.         MOV    AX,page_frame_seg    ;set page frame address -> ES..
  3931.         MOV    ES,AX            ;
  3932.         PUSH    CX            ;
  3933.         XOR    AX,AX            ;check 0:0 image data in page_
  3934.         MOV    DS,AX            ;frame...
  3935.         XOR    SI,SI            ;
  3936.         XOR    DI,DI            ;
  3937.         MOV    CX,2000H        ;
  3938.         REPZ    CMPSW            ;
  3939.         CMP    CX,0            ;check ok?
  3940.         JZ    pagets2            ;
  3941.         PUSH    CS            ;
  3942.         POP    DS            ;
  3943.         MOV    BX,OFFSET chkchr    ;fill pattan data...
  3944.         MOV    AX,CS:[BX]        ;
  3945.         XOR    DI,DI            ;
  3946.         MOV    CX,2000H        ;
  3947.         REPZ    STOSW            ;
  3948.         MOV    CX,2000H        ;check pattan data...
  3949.         XOR    DI,DI            ;
  3950.         REPZ    SCASW            ;
  3951.         CMP    CX,0            ;check ok?
  3952.         JZ    pagets1            ;
  3953. pagets2:
  3954.         POP    CX            ;pop CX
  3955.         STC                ;set CF
  3956.         JMP    pagets3            ;
  3957. pagets1:
  3958.         XOR    AX,AX            ;clear expand memory...
  3959.         XOR    DI,DI            ;
  3960.         MOV    CX,2000H        ;
  3961.         REPZ    STOSW            ;
  3962.         POP    CX            ;pop CX
  3963.         CLC                ;reset CF
  3964. pagets3:
  3965.         POP    DS            ;pop registers...
  3966.         POP    DI            ;
  3967.         POP    SI            ;
  3968.         POP    DX            ;
  3969.         POP    CX            ;
  3970.         POP    BX            ;
  3971.         POP    AX            ;
  3972.         RET                ;return.
  3973. pagetst        ENDP
  3974.  
  3975. ;--------------------------------------------------------------------
  3976. ; Change data BYNARY -> ASCII (DEC)
  3977. ; input
  3978. ;    AX    : binary data
  3979. ; output
  3980. ;    ES:DI    : ascii data (DEC)
  3981. ;--------------------------------------------------------------------
  3982. dbinasc:
  3983.         PUSH    AX
  3984.         PUSH    BX
  3985.         PUSH    CX
  3986.         PUSH    DX
  3987.         PUSH    SI
  3988.         MOV    SI,DI
  3989.         MOV    CX,4
  3990.         MOV    BX,1000
  3991.         XOR    DX,DX
  3992. dbinas1:
  3993.         DIV    BX
  3994.         OR    AL,AL
  3995.         JNZ    dbinas2
  3996.         CMP    CL,4
  3997.         JZ    dbinas4
  3998.         CMP    BYTE PTR [SI],' '
  3999.         JNZ    dbinas2
  4000. dbinas4:
  4001.         MOV    AL,' '
  4002.         CMP    CL,1
  4003.         JNZ    dbinas3
  4004.         XOR    AL,AL
  4005. dbinas2:
  4006.         ADD    AL,'0'
  4007. dbinas3:
  4008.         MOV    SI,DI
  4009.         STOSB
  4010.         PUSH    DX
  4011.         XOR    DX,DX
  4012.         MOV    AX,BX
  4013.         MOV    BX,10
  4014.         DIV    BX
  4015.         MOV    BX,AX
  4016.         POP    AX
  4017.         LOOP    dbinas1
  4018.         POP    SI
  4019.         POP    DX
  4020.         POP    CX
  4021.         POP    BX
  4022.         POP    AX
  4023.         DEC    DI
  4024.         RET
  4025.  
  4026. ;--------------------------------------------------------------------
  4027. ; Change data BYNARY -> ASCII (HEX)
  4028. ; input
  4029. ;    AX    : binary data
  4030. ; output
  4031. ;    ES:DI    : ascii data (HEX)
  4032. ;--------------------------------------------------------------------
  4033. hbinasc:
  4034.         PUSH    AX
  4035.         PUSH    BX
  4036.         PUSH    CX
  4037.         PUSH    DX
  4038.         PUSH    SI
  4039.         MOV    SI,DI
  4040.         MOV    CX,4
  4041.         MOV    BX,1000H
  4042.         XOR    DX,DX
  4043. hbinas1:
  4044.         DIV    BX
  4045.         CMP    AL,10
  4046.         JB    hbinas2
  4047.         ADD    AL,7
  4048. hbinas2:
  4049.         ADD    AL,'0'
  4050. hbinas3:
  4051.         MOV    SI,DI
  4052.         STOSB
  4053.         PUSH    DX
  4054.         XOR    DX,DX
  4055.         MOV    AX,BX
  4056.         MOV    BX,10H
  4057.         DIV    BX
  4058.         MOV    BX,AX
  4059.         POP    AX
  4060.         LOOP    hbinas1
  4061.         POP    SI
  4062.         POP    DX
  4063.         POP    CX
  4064.         POP    BX
  4065.         POP    AX
  4066.         DEC    DI
  4067.         RET
  4068.  
  4069. ;--------------------------------------------------------------------
  4070. ; Change data ASCII (DEC) -> BINARY
  4071. ; input
  4072. ;    ES:DI = ascii data address (DEC)
  4073. ; output
  4074. ;    AX = binary data
  4075. ;--------------------------------------------------------------------
  4076. ascbin1:
  4077.         PUSH    BX
  4078.         PUSH    CX
  4079.         PUSH    DX
  4080.         XOR    DL,DL
  4081.         MOV    CX,4
  4082.         XOR    BX,BX
  4083. ascbin11:
  4084.         MOV    AL,ES:[DI]
  4085.         CMP    AL,' '
  4086.         JZ    ascbin13
  4087.         CMP    AL,TAB
  4088.         JNZ    ascbin14
  4089. ascbin13:
  4090.         OR    DL,DL
  4091.         JNZ    ascbin12
  4092.         INC    DI
  4093.         JMP    ascbin11
  4094. ascbin12:
  4095.         OR    DL,DL
  4096.         JNZ    ascbin16
  4097.         STC
  4098.         JMP    ascbin15
  4099. ascbin14:
  4100.         CMP    AL,'0'
  4101.         JB    ascbin12
  4102.         CMP    AL,':'
  4103.         JNB    ascbin12
  4104.         MOV    DL,1
  4105.         SUB    AL,'0'
  4106.         XOR    AH,AH
  4107.         XCHG    BX,AX
  4108.         PUSH    DX
  4109.         MOV    DX,10
  4110.         MUL    DX
  4111.         ADD    BX,AX
  4112.         POP    DX
  4113.         INC    DI
  4114.         LOOP    ascbin11
  4115. ascbin16:
  4116.         MOV    AX,BX
  4117.         CLC
  4118. ascbin15:
  4119.         POP    DX
  4120.         POP    CX
  4121.         POP    BX
  4122.         RET
  4123.  
  4124. ;--------------------------------------------------------------------
  4125. ; Change data ASCII (HEX) -> BINARY
  4126. ; input
  4127. ;    ES:DI = ascii data address (HEX)
  4128. ; output
  4129. ;    AX = binary data
  4130. ;--------------------------------------------------------------------
  4131. ascbin2:
  4132.         PUSH    BX
  4133.         PUSH    CX
  4134.         PUSH    DX
  4135.         XOR    DL,DL
  4136.         MOV    CX,4
  4137.         XOR    BX,BX
  4138. ascbin21:
  4139.         MOV    AL,ES:[DI]
  4140.         CMP    AL,' '
  4141.         JZ    ascbin23
  4142.         CMP    AL,TAB
  4143.         JNZ    ascbin24
  4144. ascbin23:
  4145.         OR    DL,DL
  4146.         JNZ    ascbin22
  4147.         INC    DI
  4148.         JMP    ascbin21
  4149. ascbin22:
  4150.         OR    DL,DL
  4151.         JNZ    ascbin27
  4152.         STC
  4153.         JMP    ascbin25
  4154. ascbin24:
  4155.         CMP    AL,'0'
  4156.         JB    ascbin22
  4157.         CMP    AL,':'
  4158.         JB    ascbin26
  4159.         CMP    AL,'A'
  4160.         JB    ascbin22
  4161.         CMP    AL,'G'
  4162.         JNB    ascbin22
  4163.         SUB    AL,7
  4164. ascbin26:
  4165.         MOV    DL,1
  4166.         SUB    AL,'0'
  4167.         XOR    AH,AH
  4168.         XCHG    BX,AX
  4169.         PUSH    DX
  4170.         MOV    DX,10H
  4171.         MUL    DX
  4172.         ADD    BX,AX
  4173.         POP    DX
  4174.         INC    DI
  4175.         LOOP    ascbin21
  4176. ascbin27:
  4177.         MOV    AX,BX
  4178.         CLC
  4179. ascbin25:
  4180.         POP    DX
  4181.         POP    CX
  4182.         POP    BX
  4183.         RET
  4184.  
  4185. ;--------------------------------------------------------------------
  4186. ; STRINGS DISPLAY SUB
  4187. ; input
  4188. ;    DS:SI    : strings datas
  4189. ;--------------------------------------------------------------------
  4190. strdsp:
  4191.         PUSH    AX            ;
  4192.         PUSH    DX            ;
  4193.         PUSH    ES            ;
  4194.         PUSH    CS            ;
  4195.         POP    ES            ;
  4196.         MOV    DX,SI            ;
  4197.         MOV    AH,9            ;
  4198.         INT    21H            ;bdos call
  4199.         POP    ES            ;
  4200.         POP    DX            ;
  4201.         POP    AX            ;
  4202.         RET                ;
  4203.  
  4204. ;____________________________________________________________________
  4205.  
  4206. ;--------------------------------------------------------------------
  4207. ;    EMM driver initial routine work data area
  4208. ;--------------------------------------------------------------------
  4209. openmsg        DB    CR
  4210.         DB    'xxxxxxxxxxxxxxxxxx EMS Driver Version 4.0',CR,LF
  4211.         DB    'xxxxxxxxxxxxxxxxxxxxx 1988    Release x.x',CR,LF
  4212.         DB    '          -- ONLY EVALUATION --          ',CR,LF
  4213.         DB    '             SAMPLE PROGRAM              ',CR,LF
  4214.         DB    '$'
  4215. install_msg    DB    'EMM Total Pages  : '
  4216. total_pg    DB    '0000',CR,LF,'$'
  4217. page_msg    DB    'EMM Page Segment : '
  4218. segadr        DB    '0000H',CR,LF,'$'
  4219. port_msg    DB    'EMM Port Address : '
  4220. pioadr        DB    '0000H',CR,LF,LF,'$'
  4221. start_msg    DB    'xxxxxxxxxxxxxxxxxx EMS Driver Version 4.0 Release x.x'
  4222.         DB    ' -- ONLY EVALUATION --'
  4223.         DB    CR,LF,LF,'$'
  4224. hard_w_err    DB    'EMS HARDWARE NOT FOUND !',CR,LF,'$'
  4225. nopage_err    DB    'EMS LOGICAL PAGE NOT FOUND !',CR,LF,'$'
  4226. notinst        DB    'EMM DRIVER FAIL TO INSTALL ABORTED !',CR,LF,'$'
  4227. nomem        DB    'NO FREE MEMORY SEGMENT, EMM DRIVER CAN NOT INSTALL !'
  4228.         DB    CR,LF,'$'
  4229. pagemsg        DB    '0000 PAGES TESTING',CR,'$'
  4230. tstpage        DB    '0000',CR,'$'
  4231. pageseg        DW    0    ;physical page segment
  4232. rqioadr        DW    0    ;request EMS i/o port address
  4233. sysflg        DB    0    ;system option flag
  4234. sysmem        DW    0    ;system memory size
  4235. chkchr        DW    55AAH
  4236.  
  4237. code        ENDS
  4238.         END
  4239.