home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 262.lha / FastPort / FastPort.asm < prev    next >
Assembly Source File  |  1989-07-07  |  2KB  |  122 lines

  1. ;$$TABS=12 $$MAKE="casm -A %s.asm -O%s -CCQS"
  2. ;
  3. ; Fastport.Asm - Patch AddPort, FindPort, and RemPort to support hashed port names.
  4. ;
  5. ; written for CAPE-68K
  6.  
  7.     exeobj
  8.     include    "lvo.asm"
  9.     include    "strucdef.asm"
  10.  
  11.  
  12. hash_size    equ    32    ; MUST be power of two. The larger this is, the
  13.             ;faster the routines will be (and the more memory
  14.             ; the list will use).
  15. hash_and    equ    (hash_size-1)*16
  16.  
  17. start:    move.l    4,a6    ; execbase
  18.     move.l    #end_code-start_code,d2 ; size
  19.     move.l    d2,d0    ; size
  20.     moveq    #0,d1    ; memory type
  21.     jsr    _LVOAllocMem(a6)
  22.     move.l    d0,a0
  23.     lea    start_code(pc),a1
  24.     subq    #1,d2
  25. copy_lp:    move.b    (a1)+,(a0)+
  26.     dbra    d2,copy_lp
  27.     move.l    d0,a0
  28.     jmp    (a0)
  29.  
  30. start_code:
  31. ; code that gets moved - must be relocatable
  32. ; on entry, a6=execbase
  33.     jsr    _LVOForbid(a6)    ; don't let anyone bother us
  34.                 ; while modifying execbase!
  35.     
  36. ; initialize hash chains:
  37.     lea    hash_list(pc),a0
  38.     move.l    a0,a5
  39.     moveq    #hash_size-1,d0
  40. init_loop:    NEWLIST    a0
  41.     lea    16(a0),a0
  42.     dbra    d0,init_loop
  43.  
  44. ; now, add each port to our list
  45.     move.l    eb_PortList+LH_HEAD(a6),d3
  46. scanloop:    move.l    d3,a2
  47.     move.l    (a2),d3
  48.     beq.s    done_scan
  49. ; now, compute hash function!
  50.     move.l    ln_Name(a2),a0    ; string
  51.     moveq    #0,d0        ; hash value
  52. hash_loop:    move.b    (a0)+,d1
  53.     beq.s    got_hash
  54.     add.b    d1,d0
  55.     addx    d0,d0
  56.     bra.s    hash_loop
  57. got_hash:    and    #hash_and,d0
  58.     lea    hash_list(pc),a0
  59.     add    d0,a0
  60.     move.l    a2,a1
  61.     ADDHEAD
  62.     bra.s    scanloop
  63. done_scan:    move.l    a6,a1
  64.     move    #_LVOAddPort,a0
  65.     lea    my_addport(pc),a2
  66.     move.l    a2,d0
  67.     jsr    _LVOSetFunction(a6)
  68.  
  69. ;    move    #_LVORemPort,a0
  70. ;    lea    my_remport(pc),a2
  71. ;    move.l    a2,d0
  72. ;    jsr    _LVOSetFunction(a6)
  73.     
  74.     move    #_LVOFindPort,a0
  75.     lea    my_findport(pc),a2
  76.     move.l    a2,d0
  77.     jsr    _LVOSetFunction(a6)
  78.     jsr    _LVOPermit(a6)
  79.     move.l    a5,eb_PortList(a6)    ; so can dump hash chain
  80.     moveq    #0,d0        ; ret code
  81.     rts
  82.  
  83. my_findport:
  84.     move.l    a1,a0
  85.     moveq    #0,d0
  86. 1$:    move.b    (a0)+,d1
  87.     beq.s    2$
  88.     add.b    d1,d0
  89.     addx    d0,d0
  90.     bra.s    1$
  91. 2$:    and    #hash_and,d0
  92.     lea    hash_list(pc),a0
  93.     add    d0,a0
  94.     addq.b    #1,$127(a6)            ; forbid()
  95.     jsr    _LVOFindName(a6)
  96.     subq.b    #1,$127(a6)
  97.     rts
  98.  
  99.  
  100. my_addport:
  101.     lea    mp_MSGLIST(a1),a0
  102.     NEWLIST    a0
  103.     move.l    ln_Name(a1),a0
  104.     moveq    #0,d0
  105. 1$:    move.b    (a0)+,d1
  106.     beq.s    2$
  107.     add.b    d1,d0
  108.     addx    d0,d0
  109.     bra.s    1$
  110. 2$:    and    #hash_and,d0
  111.     lea    hash_list(pc),a0
  112.     add    d0,a0
  113.     addq.b    #1,$127(a6)            ; forbid()
  114.     ADDHEAD
  115.     subq.b    #1,$127(a6)            ; permit()
  116.     rts
  117.  
  118. hash_list:    ds.b    hash_size*16
  119.     dc.l    $31415927            ; end marker for dumper
  120. end_code:
  121.     end
  122.