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 >
Wrap
Text File
|
1993-08-16
|
2KB
|
95 lines
; /* tab=4 */
; The assembly routine for fast Amiga2IBM conversion and vice versa.
;
; int __inline __asm ibm2amiga(register __a0 char *inbuffer,
; register __a1 char *outbuffer,
; register __d1 int bytes_read);
xdef _ibm2amiga
xdef _amiga2ibm
section code
_ibm2amiga:
move.l a1,a2 ; save initial outbuffer address
tst.l d1 ; check if bytes_read > 0
beq.s toamigacrout
move.b #13,d2 ; store constants in register
move.b #10,d3 ; for quicker access
toamigacrloop:
move.b (a0)+,d0 ; fetch character
toamigacrtest:
move.b d0,(a1)+ ; copy to outbuffer
cmp.b d2,d0 ; test if it is LF?
bne.s toamigacrcont
subq.l #1,d1 ; decrease bytes_read
beq.s toamigacrout ; if out of buffer, exit
move.b (a0)+,d0
cmp.b d3,d0 ; test if it is CR?
bne.s toamigacrtest ; mismatch.. only LF, not LF + CR
move.b d0,-1(a1) ; copy CR over LF in outbuffer
toamigacrcont:
subq.l #1,d1 ; decrease bytes_read
bne.s toamigacrloop ; out of buffer length?
toamigacrout:
sub.l a2,a1 ; subtract initial offset to get bytes
; processed.. of outbuffer
move.l a1,d0 ; return value in register d0
rts
; int __inline __asm amiga2ibm(register __a0 char *inbuffer,
; register __a1 char *outbuffer,
; register __d1 int bytes_read);
_amiga2ibm:
move.l a1,a2 ; save initial outbuffer address
tst.l d1 ; check if bytes_read > 0
beq.s toibmlfcrout
move.b #10,d2 ; place into register for
move.b #13,d3 ; quicker access.
move.b (a0),d0 ; check first character separately
cmp.b d2,d0 ; is it a CR?
bne.s toibmlfcrloop
move.b d3,(a1)+ ; convert first CR -> LF + CR
move.b d2,(a1)+
addq.l #1,a0 ; increase inbuffer address
subq.l #1,d1 ; decrease count (bytes_read)
toibmlfcrloop:
move.b (a0)+,d0 ; fetch character
move.b d0,(a1)+ ; copy into outbuffer
cmp.b d2,d0 ; is it a CR?
bne.s toibmlfcrcont
move.b -2(a0),d0
cmp.b d3,d0 ; is it a LF?
beq.s toibmlfcrcont
toibmlfcrmatch:
move.b d3,-1(a1) ; if CR only then replace with LF + CR
move.b d2,(a1)+
toibmlfcrcont:
subq.l #1,d1 ; decrease bytes_read
bne.s toibmlfcrloop ; out of buffer length?
toibmlfcrout:
sub.l a2,a1 ; subtract initial offset to get bytes
; processed.. of outbuffer
move.l a1,d0 ; return value in register d0
rts
end