home *** CD-ROM | disk | FTP | other *** search
/ The Pier Shareware 6 / The_Pier_Shareware_Number_6_(The_Pier_Exchange)_(1995).iso / 024 / psi110g.zip / PIVEC.ASM < prev    next >
Assembly Source File  |  1993-09-16  |  5KB  |  247 lines

  1. ; :ts=8
  2. ;%    .MODEL  MEMMOD,C
  3. include asmglobal.h        
  4.     LOCALS
  5.     %MACS
  6.     .LALL
  7.  
  8.     extrn   Stktop,Spsave,Sssave,piint:proc,doret:proc,eoi:proc
  9.  
  10. DMAEN   equ     4
  11.  
  12.     .DATA
  13.  
  14.     public  acc_delay
  15. acc_delay       dw      0
  16. diff            dw      0
  17. tick1           dw      0
  18. tick2           dw      0
  19.  
  20.  
  21.     .CODE
  22. dbase   dw      @Data           ; save loc for ds (must be in code segment)
  23.  
  24. ;  This routine calculates the constant to be used in the delay loops
  25. ;  which satisfy the SCC's access recovery time.  This needs to be timed and
  26. ;  calculated because a fixed value would not work in a 4.77mhz XT
  27. ;  to a 40mhz 486 (and beyond).
  28.     public set_acc_delay
  29. set_acc_delay proc
  30.     pushf
  31.     cli
  32.     push    ax
  33.     push    bx
  34.     push    cx
  35.     push    dx
  36.  
  37.     mov     cx,1000
  38.  
  39.     mov     al,0                    ;latch counter zero.
  40.     out     43h,al
  41.     in      al,40h                  ;read counter zero.
  42.     mov     ah,al
  43.     in      al,40h
  44.     xchg    ah,al
  45.     mov     tick1,ax
  46.  
  47. h1:     loop    h1
  48.  
  49.     mov     al,0                    ;latch counter zero.
  50.     out     43h,al
  51.     in      al,40h                  ;read counter zero.
  52.     mov     ah,al
  53.     in      al,40h
  54.     xchg    ah,al
  55.     mov     tick2,ax
  56.     mov     ax,tick1
  57.     sub     ax,tick2
  58.     mov     diff,ax ; Elapsed counts
  59.     mov     bx,ax
  60.     mov     dx,0
  61.     mov     ax,5000 ; Divide by
  62.     div     bx      ; the number of counts elapsed
  63.     cmp     al,0
  64.     jne     set_acc_2
  65.     mov     al,1    ; Delay constant must be at least 1
  66. set_acc_2:
  67.     xor     ah,ah
  68.     mov     acc_delay,ax
  69.  
  70.     pop     dx
  71.     pop     cx
  72.     pop     bx
  73.     pop     ax
  74.     popf
  75.     ret
  76. set_acc_delay   endp
  77.  
  78.     public  wrtscc
  79. wrtscc  proc
  80.     arg     cbase:word,ctl:word,reg:word,val:word
  81.  
  82.     pushf
  83.     cli
  84.  
  85.     mov dx,cbase    ; get address of dma enable port
  86.     add dx,DMAEN
  87.     mov al,0        ; Write a 0 to disable DMA while we touch the scc
  88.     out dx,al
  89.  
  90.     mov cx,acc_delay
  91. Loop1:  nop
  92.     loop Loop1
  93.  
  94.     mov dx,ctl      ; Get address of scc control reg
  95.     mov ax,reg      ; Select register
  96.     out dx,al
  97.  
  98.     mov cx,acc_delay
  99. Loop2:  nop
  100.     loop Loop2
  101.  
  102.     mov ax,val      ; Output value
  103.     out dx,al
  104.  
  105.     mov cx,acc_delay
  106. Loop3:  nop
  107.     loop Loop3
  108.  
  109.     mov dx,cbase    ; get address of dma enable port
  110.     add dx,DMAEN
  111.     mov al,1        ; Enable DMA
  112.     out dx,al
  113.  
  114.     popf
  115.     ret
  116. wrtscc  endp
  117.  
  118.     public  rdscc
  119. rdscc   proc
  120.     arg     cbase:word,ctl:word,reg:byte
  121.     pushf
  122.     cli
  123.  
  124.     mov dx,cbase    ; Get address of dma enable port
  125.     add dx,DMAEN;
  126.     mov al,0        ; Disable DMA while we touch the scc
  127.     out dx,al;
  128.  
  129.     mov cx,acc_delay
  130. Loop4:  nop
  131.     loop Loop4
  132.  
  133.     mov dx,ctl      ; Get address of SCC control reg
  134.     mov al,reg      ; Select register
  135.     out dx,al;
  136.  
  137.     mov cx,acc_delay
  138. Loop5:  nop
  139.     loop Loop5
  140.  
  141.     in al,dx        ; read register
  142.     xor ah,ah
  143.     push ax         ; save return value
  144.  
  145.     mov cx,acc_delay
  146. Loop6:  nop
  147.     loop Loop6
  148.  
  149.     mov dx,cbase    ; get address of dma enable port
  150.     add dx,DMAEN
  151.     mov al,1        ; Enable DMA
  152.     out dx,al
  153.  
  154.     pop     ax      ; recover return value
  155.     popf
  156.     ret
  157. rdscc   endp
  158.  
  159. ; pi0vec - Pi card #0 interrupt handler
  160.     public  pi0vec
  161.     label   pi0vec far
  162.     push    ds              ; save on user stack
  163.     mov     ds,cs:dbase     ; establish interrupt data segment
  164.  
  165.     mov     Sssave,ss       ; stash user stack context
  166.     mov     Spsave,sp
  167.  
  168.     mov     ss,cs:dbase
  169.     lea     sp,Stktop
  170.  
  171.     ; push    ax              ; save user regs on interrupt stack
  172.     ; push    bx
  173.     ; push    cx
  174.     ; push    dx
  175.     ; push    bp
  176.     ; push    si
  177.     ; push    di
  178.     PUSHALL
  179.     push    es
  180.     call    eoi
  181.  
  182.     mov     ax,0            ; arg for service routine
  183.     push    ax
  184.     call    piint
  185.     pop     ax
  186.     jmp     doret
  187.  
  188. ; pi1vec - Pi card #1 interrupt handler
  189.     public  pi1vec
  190.     label   pi1vec far
  191.     push    ds              ; save on user stack
  192.     mov     ds,cs:dbase     ; establish interrupt data segment
  193.  
  194.     mov     Sssave,ss       ; stash user stack context
  195.     mov     Spsave,sp
  196.  
  197.     mov     ss,cs:dbase
  198.     lea     sp,Stktop
  199.  
  200.     ; push    ax              ; save user regs on interrupt stack
  201.     ; push    bx
  202.     ; push    cx
  203.     ; push    dx
  204.     ; push    bp
  205.     ; push    si
  206.     ; push    di
  207.     PUSHALL
  208.     push    es
  209.     call    eoi
  210.  
  211.     mov     ax,1            ; arg for service routine
  212.     push    ax
  213.     call    piint
  214.     pop     ax
  215.     jmp     doret
  216.  
  217. ; pi2vec - Pi card #2 interrupt handler
  218.     public  pi2vec
  219.     label   pi2vec far
  220.     push    ds              ; save on user stack
  221.     mov     ds,cs:dbase     ; establish interrupt data segment
  222.  
  223.     mov     Sssave,ss       ; stash user stack context
  224.     mov     Spsave,sp
  225.  
  226.     mov     ss,cs:dbase
  227.     lea     sp,Stktop
  228.  
  229.     ; push    ax              ; save user regs on interrupt stack
  230.     ; push    bx
  231.     ; push    cx
  232.     ; push    dx
  233.     ; push    bp
  234.     ; push    si
  235.     ; push    di
  236.     PUSHALL
  237.     push    es
  238.     call    eoi
  239.  
  240.     mov     ax,2            ; arg for service routine
  241.     push    ax
  242.     call    piint
  243.     pop     ax
  244.     jmp     doret
  245.  
  246.     end
  247.