Simple Receive command for CP/M binary files

I have written a simple CP/M program that relocates it self below the TPA and then will receive a hex file (created with the PC program attached called 2hex.com (this is a16 bit program)) and when done it will exit to the command prompt where you can then use SAVE ?? filename.ext to save the transfered binary program (converted from the hex file sent). Replace the ?? with the size of the original binary file / 256 and rounded up (the number of pages it uses). This uses the same procedure as the post on the modified Pip program for receiving files (see this post).

Click here for the files: cpmrcv.zip

       .org        0100H
; Move code to 050H
       ld          de,050H
       ld          hl,RelocStart
       ld          bc,RelocEnd - RelocStart
       ldir                     ; Code copied
       jp          050H         ;Execute

RelocStart:
       .org        050H
       ld          hl,0100H     ; Where we are storing the data
HighNib:
       call        ByteRead
       ld          (hl),a       ; Save the byte
       inc         hl
       ld          bc,(Size)
       inc         bc
       ld          (Size),bc
       jr          HighNib      ; Do more bytes
Size:
.db 0,0

; **** Subroutines ****

; Get a byte from 2 Hex butes
ByteRead:
       push       de
       call       HexByte
       rlca
       rlca
       rlca
       rlca
       and   240               ;Clear lower
       ld         d,a
       call       HexByte
       or         d
       pop        de
       ret

; Convert hex in A to byte
HexByte:
       call       ModIn
       sub        48
       cp         10
       jr         C,HexByte1
       sub        7
HexByte1:
       ret

; Send character in A out to screen
ConOut:
       push        af
       push        bc
       push        de
       push        hl
       ld          e,a
       ld          c,2
       call        5
       pop         hl
       pop         de
       pop         bc
       pop         af
       ret

; Check if a byte is available and return
; it in A. NC set if no character
ModIn:
       in          a,(05FH)     ; Read status
       rra                      ; Rotate RXREADY into CF
       rra
       jr          NC,ModIn     ; Wait for a byte
       in          a,(05EH)     ; Get character
       cp          26           ; Is it CTRL +Z
       jr          NZ,ModInExit ; no
       jp          0H           ; Done - quit
ModInExit:
       call        ConOut       ; Display Modem Byte
       cp          48           ; Is it less than "0"
       jr          C,ModIn      ; Yes get another byte
       ret
RelocEnd:

Leave a Reply

Your email address will not be published. Required fields are marked *