home *** CD-ROM | disk | FTP | other *** search
/ Frozen Fish 1: Amiga / FrozenFish-Apr94.iso / bbs / oct93 / cli_util / addcr.lha / AddCR / Src / AddCR_asm.a next >
Text File  |  1993-08-16  |  2KB  |  95 lines

  1.  
  2. ; /* tab=4 */
  3.  
  4. ; The assembly routine for fast Amiga2IBM conversion and vice versa.
  5. ;
  6. ; int __inline __asm ibm2amiga(register __a0 char *inbuffer,
  7. ;                              register __a1 char *outbuffer,
  8. ;                              register __d1 int bytes_read);
  9.  
  10.         xdef _ibm2amiga
  11.         xdef _amiga2ibm
  12.  
  13.         section code
  14.  
  15. _ibm2amiga:
  16.         move.l    a1,a2                ; save initial outbuffer address
  17.         tst.l    d1                    ; check if bytes_read > 0
  18.         beq.s    toamigacrout
  19.         move.b    #13,d2                ; store constants in register
  20.         move.b    #10,d3                ; for quicker access
  21.  
  22. toamigacrloop:
  23.         move.b    (a0)+,d0            ; fetch character
  24.  
  25. toamigacrtest:
  26.         move.b    d0,(a1)+            ; copy to outbuffer
  27.         cmp.b    d2,d0                ; test if it is LF?
  28.         bne.s    toamigacrcont
  29.  
  30.         subq.l    #1,d1                ; decrease bytes_read
  31.         beq.s    toamigacrout        ; if out of buffer, exit
  32.  
  33.         move.b    (a0)+,d0
  34.         cmp.b    d3,d0                ; test if it is CR?
  35.         bne.s    toamigacrtest        ; mismatch.. only LF, not LF + CR
  36.  
  37.         move.b    d0,-1(a1)            ; copy CR over LF in outbuffer
  38.  
  39. toamigacrcont:
  40.         subq.l    #1,d1                ; decrease bytes_read
  41.         bne.s    toamigacrloop        ; out of buffer length?
  42.  
  43. toamigacrout:
  44.         sub.l    a2,a1                ; subtract initial offset to get bytes
  45.                                     ; processed.. of outbuffer
  46.         move.l    a1,d0                ; return value in register d0
  47.         rts
  48.  
  49.  
  50. ; int __inline __asm amiga2ibm(register __a0 char *inbuffer,
  51. ;                              register __a1 char *outbuffer,
  52. ;                              register __d1 int bytes_read);
  53.  
  54. _amiga2ibm:
  55.         move.l    a1,a2                ; save initial outbuffer address
  56.         tst.l    d1                    ; check if bytes_read > 0
  57.         beq.s    toibmlfcrout
  58.         move.b    #10,d2                ; place into register for
  59.         move.b    #13,d3                ; quicker access.
  60.  
  61.         move.b    (a0),d0                 ; check first character separately
  62.         cmp.b    d2,d0                ; is it a CR?
  63.         bne.s    toibmlfcrloop
  64.  
  65.         move.b    d3,(a1)+            ; convert first CR -> LF + CR
  66.         move.b    d2,(a1)+
  67.         addq.l    #1,a0                ; increase inbuffer address
  68.         subq.l    #1,d1                ; decrease count (bytes_read)
  69.  
  70. toibmlfcrloop:
  71.         move.b    (a0)+,d0            ; fetch character
  72.         move.b    d0,(a1)+            ; copy into outbuffer
  73.         cmp.b    d2,d0                ; is it a CR?
  74.         bne.s    toibmlfcrcont
  75.  
  76.         move.b    -2(a0),d0
  77.         cmp.b    d3,d0                ; is it a LF?
  78.         beq.s    toibmlfcrcont
  79.  
  80. toibmlfcrmatch:
  81.         move.b    d3,-1(a1)            ; if CR only then replace with LF + CR
  82.         move.b    d2,(a1)+
  83.  
  84. toibmlfcrcont:
  85.         subq.l    #1,d1                ; decrease bytes_read
  86.         bne.s    toibmlfcrloop        ; out of buffer length?
  87.  
  88. toibmlfcrout:
  89.         sub.l    a2,a1                ; subtract initial offset to get bytes
  90.                                     ; processed.. of outbuffer
  91.         move.l    a1,d0                ; return value in register d0
  92.         rts
  93.  
  94.         end
  95.