;Copyright (C) 2005 by Daniel Mewes
mov ah,09h
mov dx,offset Question
int 21h

mov ah,10h
mov dx,offset Filename
int 21h

mov ah,3Ch
mov dx,offset Filename+2
mov cx,0
int 21h
mov FileHandle,ax

;It seems that DOS sometimes needs a long time to write the first byte to a file, so we write this byte now and reset the file pointer later
mov cx,1
mov ah,40h
mov bx,FileHandle
mov dx,offset Buffer
int 21h
mov ah,42h
mov al,0
mov cx,0
mov dx,0
int 21h

mov cx,1
mov dx,0
Waitbegin:
    mov ah,2h
    int 14h
    mov Buffer,al
    cmp al,0FFh
    je Readchar
    jmp Waitbegin

Checkend:
    mov ah,2h
    mov dx,0
    int 14h
    mov Buffer,al
    cmp al,23h
    je Endpr
    jmp Savechar

Readchar:
    mov ah,2h
    mov dx,0
    int 14h
    cmp ah,0
    jne Error
    mov Buffer,al
    cmp al,0FFh
    je Checkend
Savechar:
    mov dx,offset Buffer
    mov ah,40h
    mov bx,FileHandle
    int 21h
    jmp Readchar    

Error:
    mov ah,9h
    mov dx,offset ErrorMsg
    int 21h
Endpr:
    mov bx,FileHandle
    mov ah,3Eh
    int 21h
    mov ah,4Ch
    int 21h

Question: db 'Filename: $'
ErrorMsg: db 'Transfer error$'
Filename: db 13
    db 14 DUP (0)
Buffer db 0
FileHandle dw ?
SerHandle dw ?
EndChar: db 1Ah
