home *** CD-ROM | disk | FTP | other *** search
/ C!T ROM 2 / ctrom_ii_b.zip / ctrom_ii_b / PROGRAM / ASSEMBLE / BIMODAL / BIMO.ASM next >
Assembly Source File  |  1993-08-02  |  3KB  |  163 lines

  1. ;**
  2. ;** bimo.asm:
  3. ;**    Interrupt handlers for real- and protected-mode INT 0xC, or 0x0B
  4. ;** if the -2 command-line option is used.  See the bimodal.c example
  5. ;** program for details.
  6. ;**
  7.  
  8. .286
  9.  
  10. _TEXT16    SEGMENT    BYTE PUBLIC 'CODE'
  11.     ASSUME    cs:_TEXT16
  12.  
  13.     ;**
  14.     ;** The real-mode interrupt handler is in a 16-bit code segment
  15.     ;** so that the assembler will generate the right code.
  16.     ;**
  17.     ;** We will copy this code to a 16-bit segment in low memory 
  18.     ;** and install it as a real mode interrupt handler before it
  19.     ;** gets executed.  (There's no distinction between code and
  20.     ;** data in real mode.)
  21.     ;**
  22.     ;** Since the handler doesn't get executed before it gets copied,
  23.     ;** putting it in this segment makes the C code simpler.
  24.     ;**
  25.  
  26.     PUBLIC    rmhandler_, _com_port_low
  27. rmhandler_:
  28.     push    ds
  29.     push    bx
  30.     mov    bx,0B800h
  31.     mov    ds,bx                ; DS = 0xB800
  32.     sub    bx,bx                ; BX = 0
  33.     mov    WORD PTR [bx],0720h        ; Clear 2 character cells
  34.     mov    WORD PTR [bx+2],0720h
  35.  
  36.     push    cx
  37.     push    ax
  38.     mov    cx, 20h
  39. rmdelay:
  40.     mov    ax, 1
  41.     mul    cl
  42.     loop    rmdelay                ; RM delay loop (flicker makes
  43.     pop    ax                ;   screen effects understandable)
  44.     pop    cx
  45.  
  46.     mov    BYTE PTR [bx],'R'        ; Write 'R' to memory map
  47.  
  48.     db    0BBh                ; mov bx,...
  49. _com_port_low    DW    ?            ;   com port base address
  50.     push    ax
  51.     push    dx
  52.     lea    dx,[bx+2]            ; int id register
  53.     in    al,dx                ; Read ports so interrupts
  54.     mov    dx,bx                ; can continue to be
  55.     in    al,dx                ; generated
  56.     mov    dx,020h
  57.     mov    al,dl
  58.     out    dx,al                ; Send EOI
  59.     pop    dx
  60.     pop    ax
  61.     pop    bx
  62.     pop    ds
  63.     iret
  64.     ASSUME    cs:NOTHING
  65.  
  66. _TEXT16    ENDS
  67.  
  68. .386p
  69.  
  70. _DATA    SEGMENT DWORD PUBLIC 'DATA'
  71.     EXTRN    _com_port:WORD
  72.     EXTRN    _com_id:BYTE
  73. _DATA    ENDS
  74.  
  75. _TEXT    SEGMENT BYTE PUBLIC 'CODE'
  76.     ASSUME    cs:_TEXT, ds:_DATA
  77.  
  78.     PUBLIC    com_init_
  79. com_init_:
  80.     mov    ax,0F3h                ; 9600,n,8,1
  81.     mov    dl,[_com_id]
  82.     sub    dh,dh
  83.     dec    dx                ; 0 = COM1, 1 = COM2
  84.     int    14h                ; Initialize device
  85.     mov    bx,[_com_port]            ; Base of port space
  86.     lea    dx,[bx+5]            ; line status register
  87.     in    al,dx
  88.     lea    dx,[bx+4]            ; modem control register
  89.     in    al,dx
  90.     or    al,8                ; enable OUT2 interrupt
  91.     out    dx,al
  92.     lea    dx,[bx+2]            ; int id register
  93.     in    al,dx
  94.     mov    dx,bx                ; data receive register
  95.     in    al,dx
  96.     mov    dl,NOT 10h            ; mask for IRQ4
  97.     cmp    [_com_id],1
  98.     je    maskit
  99.     mov    dl,NOT 8h            ; mask for IRQ3
  100. maskit:
  101.     in    al,21h                ; interrupt mask register
  102.     and    al,dl                ; force IRQ unmasked
  103.     out    21h,al
  104.     lea    dx,[bx+1]            ; int enable register
  105.     mov    al,1
  106.     out    dx,al                ; enable received-data int
  107.     ret
  108.  
  109.     ASSUME    ds:NOTHING
  110.  
  111.     ;**
  112.     ;** The protected-mode interrupt handler is in a 32-bit code
  113.     ;** segment.  Even so, we have to be sure to force an IRETD
  114.     ;** at the end of the handler, because MASM doesn't generate
  115.     ;** one.  This handler will be called on a 32-bit stack by
  116.     ;** DOS/4GW.
  117.     ;**
  118.  
  119.     PUBLIC    pmhandler_
  120. pmhandler_:
  121.     push    ds
  122.     push    ebx
  123.     mov    bx,_DATA
  124.     mov    ds,bx
  125.  
  126.     ASSUME    ds:_DATA
  127.  
  128.     mov    ebx,0B8000h            ; DS:EBX = flat:0B8000h
  129.     mov    DWORD PTR [ebx],07200720h    ; Clear 2 character cells
  130.  
  131.     push    eax
  132.     push    ecx
  133.     mov    ecx, 20h
  134. pmdelay:
  135.     mov    ax, 1
  136.     mul    cl
  137.     loop    pmdelay                ; PM delay loop (for clarity
  138.     pop    ecx                ;   of display only)
  139.  
  140.     mov    BYTE PTR [ebx+2],'P'        ; Write 'P' to memory map
  141.  
  142.     push    edx
  143.     mov    bx,[_com_port]
  144.     lea    dx,[bx+2]
  145.     in    al,dx                ; Read ports so interrupts
  146.     mov    dx,bx                ; can continue to be
  147.     in    al,dx                ; generated
  148.     mov    dx,020h
  149.     mov    al,dl
  150.     out    dx,al                ; Send EOI
  151.     pop    edx
  152.     pop    eax
  153.     pop    ebx
  154.     pop    ds
  155.  
  156.     ASSUME    ds:NOTHING
  157.  
  158.     iretd
  159.  
  160. _TEXT    ENDS
  161.  
  162. END
  163.