Àïïàðàòíîå îáåñïå÷åíèå ïåðñîíàëüíîãî êîìïüþòåðà

       

Ïðîãðàììà TESTHMA


Ïåðâàÿ ïðîãðàììà ñ íàçâàíèåì TESTHMA (ëèñòèíã 11.1) äåìîíñòðèðóåò ïðîâåðêó ïîäêëþ÷åíèÿ äðàéâåðà è èñïîëüçîâàíèå åãî îñíîâíûõ ôóíêöèé.

Ëèñòèíã 11.1. Ôàéë testhma\testhma.asm

; =====================================================

; Âûçîâ îñíîâíûõ ôóíêöèé API äðàéâåðà HIMEM.SYS

;

; (C) A. Frolov, 1997

;

; E-mail: frolov@glas.apc.org

; WWW:    http://www.glasnet.ru/~frolov

;            or

;         http://www.dials.ccas.ru/frolov

; =====================================================

@@out_ch MACRO c1,c2,c3,c4,c5,c6,c7,c8,c9,c10



  mov   ah,02h

  IRP   chr,<c1,c2,c3,c4,c5,c6,c7,c8,c9,c10>

  IFB   <chr>

  EXITM

  ENDIF

  mov   dl,chr

  int   21h

  ENDM

  ENDM

@@out_str MACRO

  mov   ah,9

  int   21h

  ENDM

BEEP  MACRO

  mov bx,0

  mov ax, 0E07h

  int 10h

  ENDM

  .model small

  .STACK  100h

  .DATA

msg    DB 13,10,"HIMEM.SYS API Demo", 13, 10

       DB "(C) Frolov A., 1997",13,10,13,10

       DB "$"

noHMM     DB 13,10

          DB "HIMEM.SYS not installed",13,10,"$"

yesHMM    DB 13,10,"HIMEM.SYS istalled, ", "$"

ver1      DB "version: ", "$"

ver2      DB ", modification: ", "$"

errmsg    DB 13,10,"Error code ", "$"

okmsg     DB 13,10,"Success!", "$"

hmareq    DB 13,10,"Request HMA", "$"

hmarel    DB 13,10,"Release HMA", "$"

enA20     DB 13,10,"Open A20", "$"

dsA20     DB 13,10,"Close A20", "$"

loc_enA20 DB 13,10,"Local open A20","$"

loc_dsA20 DB 13,10,"Local close A20", "$"

check_A20 DB 13,10,"Check A20", "$"

free_ext_mem DB 13,10,"Extended memory, Kbyte: ", "$"

max_ext_block DB 13,10,"Max free Extended memory block, Kbyte: ", "$"


HMMEntry dd ?

  .CODE

begin:

  mov ax, DGROUP

  mov ds, ax

  mov ah, 9h ; Âûâîäèì çàãîëîâîê

  mov dx, OFFSET msg

  int 21h

; Ïðîâåðÿåì, óñòàíîâëåí ëè äðàéâåð HIMEM.SYS

  mov ax, 4300h

  int 2fh

  cmp al, 80h

  je  HMM_installed

; Åñëè íå óñòàíîâëåí, âûâîäèì ñîîáùåíèå è çàâåðøàåì

; ðàáîòó ïðîãðàììû

  mov ah, 9h

  mov dx, OFFSET noHMM

  int 21h

  jmp terminate

HMM_installed:

  mov ah, 9h

  mov dx, OFFSET yesHMM

  int 21h

; Ïîëó÷àåì àäðåñ óïðàâëÿþùåé ôóíêöèè äðàéâåðà

  mov ax, 4310h

  int 2fh

  mov word ptr cs:[HMMEntry][0], bx

  mov word ptr cs:[HMMEntry][2], es

; Ïîëó÷àåì íîìåð âåðñèè

  mov  ah, 9h

  mov  dx, OFFSET ver1

  int  21h

  mov  ax,0

  call cs:[HMMEntry]

; Âûâîäèì íîìåð âåðñèè íà ýêðàí

  call  Print_word

  mov   ah, 9h

  mov   dx, OFFSET ver2

  int   21h

  mov   ax, bx

  call  Print_word

; Çàïðàøèâàåì îáëàñòü HMA

  mov   ah, 9h

  mov   dx, OFFSET hmareq

  int   21h

  mov   ax,0100h

  mov   dx,0ffffh

  call  cs:[HMMEntry]

  or    ax, ax

  jnz   hmareq_ok

  jmp   error

hmareq_ok:

  mov   ah, 9h

  mov   dx, OFFSET okmsg

  int   21h

; Îòêðûâàåì ëèíèþ A20

  mov   ah, 9h

  mov   dx, OFFSET enA20

  int   21h

  mov   ax,0300h

  call  cs:[HMMEntry]

  or    ax, ax

  jnz   enA20_ok

  jmp   error

enA20_ok:

  mov   ah, 9h

  mov   dx, OFFSET okmsg

  int   21h

; Çàêðûâàåì ëèíèþ A20

  mov   ah, 9h

  mov   dx, OFFSET dsA20

  int   21h

  mov   ax,0400h

  call  cs:[HMMEntry]

  or    ax, ax

  jnz   dsA20_ok

  jmp   error

dsA20_ok:

  mov   ah, 9h

  mov   dx, OFFSET okmsg

  int   21h

; Îñâîáîæäàåì îáëàñòü HMA

  mov   ah, 9h

  mov   dx, OFFSET hmarel

  int   21h

  mov   ax,0200h

  call  cs:[HMMEntry]



 

  or    ax, ax

  jz    error

  mov   ah, 9h

  mov   dx, OFFSET okmsg

  int   21h

; Ïîëó÷àåì ëîêàëüíûé äîñòóï ê ëèíèè A20

  mov   ah, 9h

  mov   dx, OFFSET loc_enA20

  int   21h

  mov   ax,0500h

  call  cs:[HMMEntry]

  or    ax, ax

  jz    error

  mov   ah, 9h

  mov   dx, OFFSET okmsg

  int   21h

; Ïðîâåðÿåì ëèíèþ A20

  mov   ah, 9h

  mov   dx, OFFSET check_A20

  int   21h

  mov   ax,0700h

  call  cs:[HMMEntry]

  or    ax, ax

  jz    error

  mov   ah, 9h

  mov   dx, OFFSET okmsg

  int   21h

; Îïðåäåëÿåì ðàçìåð ñâîáîäíîé ðàñøèðåííîé ïàìÿòè

  mov   ah, 9h

  mov   dx, OFFSET free_ext_mem

  int   21h

  mov   ax,0800h

  call  cs:[HMMEntry]

  push  ax

  mov   ax, dx

  call  Print_word

  mov   ah, 9h

  mov   dx, OFFSET max_ext_block

  int   21h

  pop   ax

  call  Print_word

; Îñâîáîæäàåì ëèíèþ A20

  mov   ah, 9h

  mov   dx, OFFSET loc_dsA20

  int   21h

  mov   ax,0600h

  call  cs:[HMMEntry]

  or    ax, ax

  jz    error

  mov   ah, 9h

  mov   dx, OFFSET okmsg

  int   21h

  jmp   terminate

error:

  push  bx

  mov   ah, 9h

  mov   dx, OFFSET errmsg

  int   21h

  pop   ax

  call  Print_word

terminate:

; Çàâåðøàåì ðàáîòó ïðîãðàììû è

; âîçâðàùàåì óïðàâëåíèå îïåðàöèîííîé ñèñòåìå

  mov ax, 4C00h

  int 21h

; Âûâîä íà ýêðàí ñîäåðæèìîãî ðåãèñòðà AX

Print_word proc near

;--------------------

  push ax

  push bx

  push dx

  push ax

  mov cl,8

  rol ax,cl

  call Byte_to_hex

  mov bx,dx

  @@out_ch bh

  @@out_ch bl

  pop ax

  call Byte_to_hex

  mov bx,dx

  @@out_ch bh

  @@out_ch bl

  pop dx

  pop bx

  pop ax

  ret

Print_word endp

Byte_to_hex proc near

;--------------------

; al - input byte

; dx - output hex

;--------------------

  push ds

  push cx

  push bx

  lea bx,tabl

  mov dx,cs

  mov ds,dx

  push ax

  and al,0fh

  xlat

  mov dl,al

  pop ax

  mov cl,4

  shr al,cl

  xlat

  mov dh,al

  pop bx

  pop cx

  pop ds

  ret

tabl db '0123456789ABCDEF'

Byte_to_hex endp

 

  END begin


Ñîäåðæàíèå ðàçäåëà