
* SEND UTILITY FOR SK*DOS LEVEL I

* THIS UTILITY CONVERTS A BINARY S1-S9 DISK FILE
* TO MS FORMAT AND SENDS IT TO THE EMERALD COMPUTER

* COPYRIGHT (C) 1985 BY PETER A. STARK

* MODIFIED 7-14-86 TO ACCEPT S3 AND S7

* EQUATES TO SK*DOS

SYSFCB  EQU    $C840     SYSTEM FCB
WARMST  EQU    $CD03     WARM START
PUTCH   EQU    $CD18     OUTPUT CHARACTER
PDATA   EQU    $CD54
PCRLF   EQU    $CD24     PRINT RETURN / LINE FEED
GETNAM  EQU    $CD2D     GET FILE SPECIFICATION
DEFEXT  EQU    $CD33     DEFAULT EXTENSION
PERROR  EQU    $CD3F     REPORT ERROR NUMBER
FCSCLS  EQU    $D403     CLOSE FILES
FCS     EQU    $D406     CALL FCS

        ORG    $C100

SEND    BRA    START     GO TO START

VER     FCB    2         VERSION NUMBER

* START OF ACTUAL PROGRAM
START   JSR    PCRLF     START ON NEW LINE
        LDX    #SYSFCB   POINT TO SYSTEM FCB
        JSR    GETNAM    GET FILE SPEC INTO FCB
        BCC    NAMEOK    IF FILE NAME WAS OK
        LDB    #21       ELSE IT'S ERROR 21 - FILE NAME
        STB    1,X       STORE ERROR CODE IN FCB

* ERROR ROUTINE

ERROR   JSR    PERROR    PRINT ERROR CODE
CLOSE   JSR    FCSCLS    CLOSE THE FILE
        JMP    WARMST    AND RETURN TO SK*DOS

* FILE SPEC WAS OK; DEFAULT TO .BIN
NAMEOK  LDA    #0        DEFAULT EXTENSION CODE
        JSR    DEFEXT    DEFAULT TO .BIN

* NOW ACTUALLY OPEN THE FILE
        LDA    #1        OP CODE FOR OPEN FOR READ
        STA    0,X       SAVE OPERATION CODE
        JSR    FCS       AND GO OPEN THE FILE
        BNE    ERROR     IF NOT ZERO (Z = 0)

* MAIN LOOP TO READ CHARS AND PUT THEM INTO LINE BUFFER
MAIN    LDX    #$0400    TIME DELAY
WAIT    LEAX   -1,X
        BNE    WAIT      WAIT A BIT
        LDY    #LINE     POINT TO LINE
        LDX    #SYSFCB   POINT TO SYSTEM FCB

LOOP    JSR    FCS       GO READ NEXT CHARACTER
        BNE    CHEROR    IF THERE WAS AN ERROR
        STA    0,Y+      STORE INTO LINE BUFFER
        CMPA   #$0D      IS IT CR?
        BNE    LOOP      NO, REPEAT FOR MORE
        BRA    LINEOK    FINISHED READING A LINE

* IF THERE WAS AN ERROR, SEE IF END OF FILE
CHEROR  LDA    1,X       GET ERROR CODE
        CMPA   #8        COMPARE WITH END OF FILE (IE) ERROR
        BNE    ERROR     NOT END OF FILE, SO REAL ERROR
        BRA    CLOSE     ON E-O-F, JUST CLOSE FILE AND QUIT

* LINE IS NOW IN BUFFER; PROCESS IT
LINEOK  LEAY   -3,Y      BACKUP TO LAST DATA
        STY    LAST      AND SAVE IT
        LDD    LINE      GET FIRST TWO CHARACTERS
        CMPD   #$5339    IS IT S9?
        LBEQ   CLOSE     YES, CLOSE FILE AND QUIT
        CMPD   #$5338    IS IT S8?
        LBEQ   CLOSE     YES, CLOSE FILE AND QUIT
        CMPD   #$5337    IS IT S7?
        LBEQ   CLOSE     YES, CLOSE FILE AND QUIT
        CMPD   #$5331    IS IT S1?
        BEQ    S1        YES
        CMPD   #$5332    IS IT S2?
        BEQ    S2        YES
        CMPD   #$5333    IS IT S3?
        BEQ    S3        YES
        BRA    MAIN      ELSE LOOK FOR NEXT LINE

S1      LDX    #MSMSG
        JSR    PDATA     PRINT "MS"
        LDX    #LINE+4
        LDB    #4
        BSR    PRNTIT    GO PRINT 4-CHAR ADDRESS
        BRA    DOREST    THEN GO DO THE REST

S2      LDX    #MSMSG
        JSR    PDATA     PRINT "MS"
        LDX    #LINE+4
        LDB    #6
        BSR    PRNTIT    GO PRINT 6-CHAR ADDRESS
        BRA    DOREST    THEN GO DO THE REST

S3      LDX    #MSMSG
        JSR    PDATA     PRINT "MS"
        LDX    #LINE+4
        LDB    #8
        BSR    PRNTIT    GO PRINT 8-CHAR ADDRESS

DOREST  LDB    #2
        BSR    PRNTIT    GO PRINT 2-CHAR BYTE
        CMPX   LAST      DONE?
        BNE    DOREST    NO, PRINT ONE MORE BYTE

* AT END OF LINE, DO CR
        LDA    #$0D
        JSR    PUTCH
        LDA    #$0A
        JSR    PUTCH
        JMP    MAIN      AND THEN CONTINUE

* SUBROUTINE TO PRINT SPACE, FOLLOWED BY (B)
* CHARS STARTING AT (X)

PRNTIT  LDA    #$20
        JSR    PUTCH     OUTPUT A SPACE
PLOOP   LDA    0,X+      GET NEXT CHARACTER
        JSR    PUTCH     OUTPUT IT
        DECB             DECREMENT COUNTER
        BNE    PLOOP     OUTPUT UNTIL DONE
        RTS              THEN RETURN

* TEXT
MSMSG   FCC    'MS',4

* DATA

LAST    RMB    2         POINTS PAST CR AFTER LINE BUFFER
LINE    RMB    256       LINE BUFFER

        END    SEND
