home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 5 / ctrom5b.zip / ctrom5b / PROGRAM / DIVERSEN / DOS32V3B / EXAMPLES / EG6.ASM < prev    next >
Assembly Source File  |  1995-02-14  |  7KB  |  217 lines

  1. ;***************************************************************************
  2. ; EG6.ASM
  3. ;              This does lots of simple things with the extender.
  4. ;
  5. ;***************************************************************************
  6.  
  7. .386
  8. .model flat
  9. .stack 200h
  10. .code
  11.  
  12.  
  13.  
  14. memory_pointer  dd 0
  15. File_handle     dw 0
  16. message1        db      ' Reading the file "EXAMPLE1.EXE" into some allocated memory.',10,13
  17.                 db      ' Also hooking IRQ 0 ( the timer ) and altering the VGA color 0',10,13
  18.                 db      'register.     Press any key to stop',10,13,36
  19.  
  20. message2        db      10,10,'Everything was successful $'
  21. message3        db      10,10,'Something went wrong $'
  22. Old_IRQ0_vector df 0
  23.  
  24.  
  25.  
  26. start_Example1:                               ; Start of the program
  27.  
  28.  
  29. ;********************************************************************
  30. ;               DISPLAY A MESSAGE
  31.  
  32.         mov     edx,offset message1
  33.         mov     ah,9                       ; Print string DS:EDX -> string
  34.         int     21h                        ; call a DOS type service
  35.  
  36.  
  37.  
  38.  
  39. ;********************************************************************
  40. ;               ALLOCATE  SOME MEMORY
  41.  
  42.         mov     edx,4000h               ; allocate a 16K memory
  43.         mov     ax,0EE42h
  44.         int     31h                     ; returns EDX = offset of block
  45.         jc   exit_unsucsessfuly         ; jump if error
  46.          mov   memory_pointer,edx        ; save the block pointer
  47.  
  48.  
  49.  
  50.  
  51. ;********************************************************************
  52. ;               LOAD THIS FILE INTO MEMORY
  53.  
  54.         mov     ax,0EE02h               ; Get DOS32 Address info
  55.         int     31h                     ; ECX -> .EXE file name/path
  56.  
  57.         mov     edx,ecx                 ; let DS:EDX points to file name
  58.         mov     ah,3Dh                  ; Open the file
  59.         mov     al,00h                  ; opening flags.  0 = read only
  60.         int     21h
  61.         jc exit_unsucsessfuly           ; exit if error
  62.         mov     File_handle,ax          ; save the file handle
  63.  
  64.  
  65.         mov     ecx,4000h               ; try to read 16Kb of file
  66.         mov     edx,memory_pointer      ; DS:EDX -> receive buffer
  67.         mov     bx,File_handle          ; BX = handle
  68.         mov      ah,3Fh
  69.         int     21h                     ; Read file
  70.  
  71.  
  72.         mov      bx,file_handle           ; Close the file
  73.         mov      ah,3Eh
  74.         int      21h
  75.  
  76.  
  77.  
  78. ;********************************************************************
  79. ;               HOOK  IRQ 0  ( TIMER INTERRUPT )
  80.  
  81.        ;------ save origonal interrupt vector ------------
  82.        mov      bl,8                            ; BL = int number.
  83.        mov      ax,0204h
  84.        int      31h                             ; Call the service.
  85.        mov      Dword Ptr Old_IRQ0_vector,edx   ; Save vector as a 48 bit far
  86.        mov      Word Ptr Old_IRQ0_vector+4,cx   ;  pointer.
  87.  
  88.  
  89.  
  90.        ;------ set the new interrupt vector --------------
  91.        mov      BL,8                            ; BL = int number
  92.        mov      EDX,offset Timer_Interrupt      ; EDX = offset of int vector
  93.        mov      cx,cs                           ; CX = selector value
  94.        mov      ax,0205h
  95.        int      31h                             ; Call the service.
  96.  
  97.          ;( see below for the hadrware interrupt handler )
  98.  
  99.  
  100.  
  101.  
  102. ;********************************************************************
  103. ;               WAIT FOR A KEY TO BE PRESSED
  104.  
  105.                 mov     ah,0                    ; use the BIOS services
  106.                 int     16h
  107.  
  108.  
  109.  
  110.  
  111. ;********************************************************************
  112. ;               DISPLAY A SUCCESSFUL MESSAGE
  113.  
  114.         mov     edx,offset message2
  115.         mov     ah,9
  116.         int     21h
  117.  
  118.  
  119.  
  120. ;********************************************************************
  121. ;               RESTORE ORIGONAL IRQ 0  ( TIMER INTERRUPT )
  122.  
  123.        mov      BL,8                            ; BL = int number
  124.        mov      edx,dword ptr Old_IRQ0_vector   ; Get vector as a 48 bit far
  125.        mov      cx,word ptr Old_IRQ0_vector+4   
  126.        mov      ax,0205h
  127.        int      31h                             ; Call the service.
  128.  
  129.  
  130.  
  131.  
  132. ;********************************************************************
  133. ;                      RESTORE THE VGA COLOR 0 REGISTER TO BLACK
  134.  
  135.                 mov     dx,3c8h
  136.                 mov     al,0
  137.                 out     dx,al
  138.                 inc     dl
  139.                 out     dx,al
  140.                 out     dx,al
  141.                 out     dx,al
  142.  
  143.  
  144. ;********************************************************************
  145. ;                      TERMINATE THIS WONDERFUL PROGRAM
  146. exit_program:
  147.  
  148.             mov   ah,4ch
  149.                 int   21h
  150.  
  151.  
  152.  
  153.  
  154.  
  155. ;********************************************************************
  156. ;               DISPLAY A UNSUCCESSFUL MESSAGE AND EXIT
  157. exit_unsucsessfuly:
  158.  
  159.         mov     edx,offset message3
  160.         mov     ah,9
  161.         int     21h
  162.         jmp exit_program
  163.  
  164.  
  165.  
  166.  
  167.  
  168. ;********************************************************************
  169. ;               OUR  HARDWARE INTERRUPT HANDLER
  170.  
  171. Timer_Interrupt:
  172.         push    ds                           ; Save segemnt registers
  173.         push    edx                          ; must save all registers used.
  174.         push    eax
  175.  
  176.         mov     ax,_TEXT                 ; load ax with program data selector
  177.         mov     ds,ax                    ; and put it in DS.
  178.  
  179.  
  180.  
  181.      ;lets do something so we know this interrupt handler is working.
  182.  
  183.         mov     dx,3C8h                 ; Set color register number 0
  184.         mov     al,0
  185.         out     dx,al
  186.         inc     dl
  187.         mov     al,color0_red
  188.         out     dx,al
  189.         mov     al,color0_green
  190.         out     dx,al
  191.         mov     al,color0_blue
  192.         out     dx,al
  193.  
  194.         inc     color0_blue               ; Update blue
  195.         add     color0_red,2                ; Update red
  196.         add     color0_green,3              ; Update green
  197.         and     color0_blue,1fh
  198.         and     color0_green,1fh
  199.         and     color0_red,1fh
  200.  
  201.  
  202.         pop     eax                       ; restore ALL saved registers
  203.         pop     edx
  204.         pop     ds
  205.         jmp     cs:Old_IRQ0_vector        ; Note we must use CS:
  206.                                           ; because DS can equal
  207.                                           ; anything.
  208.  
  209. color0_green    db 0
  210. color0_blue     db 0
  211. color0_red      db 0
  212.  
  213.  
  214.  
  215.  
  216. END  start_Example1
  217.