home *** CD-ROM | disk | FTP | other *** search
/ Amiga Developer CD v1.2 / amidev_cd_12.iso / reference / amiga_mail_vol2 / ix-1 / read34.asm < prev   
Assembly Source File  |  1992-09-03  |  4KB  |  183 lines

  1. ;
  2. ; read34.asm
  3. ;
  4. ; interface code for the "2 more players" parallel port hack.
  5. ;
  6.     csect    text            ; this here's the meat
  7.  
  8.     xdef    Name            ; Name of our application, so that
  9. Name    dc.b    '4play',0        ; other applications will know
  10.                     ; who's tying up the port. ;-)
  11.  
  12.  
  13.     xdef    _read34            ; function names for linker
  14.     xdef    _getport
  15.     xdef    _freeport
  16.  
  17.     xref    _portptr        ; c pointer for port data
  18.     xref    _fireptr        ; c pointer for fire buttons
  19.  
  20.     xref    _SysBase        ; exec system base (from c.o)
  21.  
  22.  
  23.     INCLUDE    "resources/misc.i"
  24.  
  25.  
  26.     xdef    MiscName
  27. MiscName    MISCNAME        ; macro from resources/misc.i
  28.  
  29.     xdef    _MiscResource
  30. _MiscResource    dc.l    0        ; place to store misc.resource base
  31.  
  32. ;parallel port hardware addresses (from amiga.lib)
  33.  
  34.     xref    _ciaaprb            ; the actual port address
  35.     xref    _ciaaddrb        ; data direction register
  36.  
  37.     xref    _ciabpra            ; control lines are here
  38.     xref    _ciabddra        ; data direction register
  39. ;from amiga.lib
  40.     xref    _LVOOpenResource
  41.     xref    _LVOAllocMiscResource
  42.     xref    _LVOFreeMiscResource
  43.  
  44. _getport
  45. ;This routine simply allocates the parallel port in a system friendly
  46. ;way, and sets up the lines we want to use as input lines.
  47. ;
  48.  
  49.  
  50. ;save registers on the stack
  51.  
  52.     movem.l    a2-a6/d2-d7,-(sp)    ; push regs
  53.  
  54.  
  55. ;open the misc.resource
  56.  
  57.     lea    MiscName,a1        ; put name of misc.resource in a1
  58.     movea.l    _SysBase,a6        ; put SysBase in a6
  59.     jsr    _LVOOpenResource(a6)
  60.     move.l    d0,_MiscResource    ; store address of misc.resource
  61.     bne.s    grabit
  62.  
  63. ;Oops, couldn't open misc.resource.  Sounds like big trouble to me.
  64.  
  65.     moveq    #20,d0            ; error code
  66.     bra    done
  67.  
  68.  
  69. ;This is where we grab the hardware.  If some other task has allocated
  70. ;the parallel data port or the parallel control bits, this routine will
  71. ;return non-zero.
  72.  
  73. ;This part grabs the port itself
  74.  
  75. grabit    lea    Name,a1            ; The name of our app
  76.     moveq    #MR_PARALLELPORT,d0    ; what we want
  77.     movea.l    _MiscResource,a6    ; MiscResource Base is in A6
  78.     jsr    _LVOAllocMiscResource(a6)
  79.     move.l    d0,d1
  80.     beq.s    grab2
  81.  
  82. ;well, somebody else must've got the port first.
  83.  
  84.     moveq    #30,d0            ; error code
  85.     bra    done
  86.  
  87. ;This part grabs the control bits (busy, pout, and sel.)
  88. ;We really don't need pout, but it comes free with PARALLELBITS,
  89. ;so we'll take it anyway.
  90.  
  91. grab2    lea    Name,a1            ; The name of our app
  92.     moveq    #MR_PARALLELBITS,d0    ; what we want
  93.     jsr    _LVOAllocMiscResource(a6)
  94.     move.l    d0,d1
  95.     beq.s    setread
  96.  
  97. ;well, somebody else must've got the bits first.
  98.  
  99.     moveq    #40,d2
  100.     bra    freepar
  101.  
  102.  
  103. ;set up parallel port for reading
  104.  
  105. setread    move.b    #0,_ciaaddrb        ; all lines read
  106.  
  107.     andi.b    #$FF,_ciabddra        ; busy, pout, and sel. to read
  108.  
  109. ;Well, we made it this far, so we've got exclusive access to
  110. ;the parallel port, and all the lines we want to use are
  111. ;set up.   From here we can just put back the regs and return to
  112. ;the caller.
  113.  
  114.     bra    done
  115.  
  116.  
  117. ;If something happened AFTER we got exclusive access to the parallel port,
  118. ;we'll need to let go of the port before we return the error.
  119.  
  120. freepar    moveq    #MR_PARALLELPORT,d0
  121.     movea.l    _MiscResource,a6
  122.     jsr    _LVOFreeMiscResource(a6)
  123.  
  124.     move.l    d2,d0            ; put error code into d0
  125.  
  126.  
  127. ;Restore registers and return
  128. ;(error code is in d0)
  129.  
  130. done    movem.l (sp)+,a2-a6/d2-d7    ; pop regs
  131.     rts
  132.  
  133.  
  134. _freeport
  135. ;This routine just makes sure that we let go of the parallel port and
  136. ;control lines, so somebody else can use 'em, now that we're all done.
  137. ;
  138. ;PS - Don't call this one if you got an error from _getport, as some
  139. ;of the resources might not have been opened, etc.
  140. ;
  141.  
  142. ;save registers on the stack
  143.  
  144.     movem.l    a2-a6/d2-d7,-(sp)    ; push regs
  145.  
  146.  
  147. ;free control lines
  148.  
  149.     moveq    #MR_PARALLELBITS,d0
  150.     movea.l    _MiscResource,a6
  151.     jsr    _LVOFreeMiscResource(a6)
  152.  
  153.  
  154. ;free parallel port
  155.  
  156.     moveq    #MR_PARALLELPORT,d0
  157.     movea.l    _MiscResource,a6
  158.     jsr    _LVOFreeMiscResource(a6)
  159.  
  160.  
  161. ;Clean up, restore registers, and return
  162.  
  163.     movem.l (sp)+,a2-a6/d2-d7    ; pop regs
  164.     rts
  165.  
  166.  
  167. _read34
  168. ;All this routine does is copy the data from the ports to other addresses.
  169. ;
  170. ;In this case the destinations happens to be whatever C variables are
  171. ;pointed at by _portptr and _fireptr.
  172. ;
  173.  
  174.     movea.l    _portptr,a1        ; a1 now holds the destination
  175.     move.b    _ciaaprb,(a1)        ; move byte from port to dest
  176.  
  177.     movea.l    _fireptr,a1        ; a1 now holds the destination
  178.     move.b    _ciabpra,(a1)        ; move byte from port to dest
  179.  
  180.     rts
  181.  
  182.     end
  183.