;          TRANSMIT
;
; A program to send DOS binary load
; files from one ATARI 800 to another
; using the SERIAL port. For ground, 
; connect the pins # 6 and/or 4 
; together (via cord/connector). For
; data, connect pin 3 on computer A 
; 5 on computer B, and vice versa.
; 4 conductor phone cord is ok here.
;
;
;        Nick Kennedy
;
;          11/21/86
;
; System Equates:
;
B600LO EQU $CC ; for 600 baud
B600HI EQU $05
B192LO EQU $28 ; for 19.2K baud
B192HI EQU $0
IRQST:  EQU $D20E
SERIN:  EQU $D20D ; Data in register.
SEROUT: EQU $D20D ; Outgoing data here
IRQEN  EQU $D20E ; IRQ enable. 0=disable, 1=enable. Bit 5 is serial input.
;
POKMSK EQU $10 ; Shadow for above.
SKCTL:  EQU $D20F
SSKCTL: EQU $232 ; Shadow for above
AUDCTL  EQU $D208
VSERIN  EQU $20A; Serial input vector
VSEROR: EQU $20C ; Serial out ready.
VSEROC: EQU $20E ; Transmission cpt.
AUDF1:  EQU $D200
AUDF2:  EQU $D202
AUDF3:  EQU $D204
AUDF4:  EQU $D206
AUDC1:  EQU $D201
AUDC2:  EQU $D203
AUDC3:  EQU $D205
AUDC4:  EQU $D207
CH:     EQU $2FC ; Keyboard code here
CIOV:   EQU $E456
ICCOM:  EQU $342
ICSTA:  EQU $343
ICBAL:  EQU $344
ICBAH:  EQU $345
ICBLL:  EQU $348
ICBLH:  EQU $349
ICAX1:  EQU $34A
RTCLOK: EQU $14
BEEP:   EQU $FD
CONSOL: EQU $D01F
;
        ORG $4000
        JMP INIT
LOADL:  DS 1
LOADH:  DS 1
ENDL:   DS 1
ENDH:   DS 1
PLACE:  DS 1
EOFF:   DS 1 ; EOF Flag
FLAG:   DS 1 ;
TVECT:  DS 2 ; Place for VSEROR
SIRF:   DS 1 ; Serial input rdy flag
SORF:   DS 1  ; Output ready flag
TCF:    DS 1 ; Transmission cpt flag
;
;            STRINGS:
SEGMES: DB 'SEGMENT SENT/READY RCVD',$9B
CIOE:   DB 'ERROR IN GETFB Y=$605',$9B
KYBD:   DB 'K:'
PMPT1:  DB 'Awaiting filespec from receiver:',$9B
BSTMSG: DB 'Bad status on opening file.', $9B
NTLF:   DB 'Header error - not a load file.', $9B

;
;
;            INITIALIZE
;
INIT:   LDA #$9B
        JSR PUTBYT
        LDA #$9B
        JSR PUTBYT
        PRINTS PMPT1
        LDA #$9B
        JSR PUTBYT
;
; Set AUDCTL for 1.79 Mhz. into ch 3
; and ch 3 into ch 4:
;
        LDA #%00101000
        STA AUDCTL
;
;    Set baud rate to 600:
;
        LDA #B192LO
        STA AUDF3
        LDA #B192HI
        STA AUDF4
;
;
        LDA #$A0 ; Off Sound 1,2,3
        STA AUDC1
        STA AUDC2
        STA AUDC3
        LDA #$A8 ; On, channel 4
        STA AUDC4
;
; Set the interrupt vectors:
;
        SEI
        LDA #HIGH TINT
        STA VSEROR+1
        LDA #LOW TINT
        STA VSEROR
        LDA #HIGH RINT
        STA VSERIN+1
        LDA #LOW RINT
        STA VSERIN
        LDA #HIGH TCINT
        STA VSEROC+1
        LDA #LOW TCINT
        STA VSEROC
        CLI
;
; Initialize transmission (not) done
; flag & input ready flag.
;
        LDA #0 ; Transmission is cpt.
        STA TCF
        LDA #$FF ; Input not ready.
        STA SIRF
;
; Get the filespec from the other 800
;
        PROC
        JSR RINIT
        LDY #0
:GET1:  JSR RLOOP ; Get filespec byte
        STA RECORD,Y ; store it
        INY
        CMP #$9B ; EOR?
        BNE :GET1 ; No.
;
; Put the filespec to the screen
;
        LDA #LOW RECORD
        STA ICBAL
        LDA #HIGH RECORD
        STA ICBAH
        JSR PUTREC
        JSR TINIT ; To send status.
;
; Now, open the file for input:
; Use IOCB #1
;

        LDX #$10
        LDA #$C
        STA ICCOM,X ; First close it
        JSR CIOV
        LDA #3
        STA ICCOM,X
        LDA #HIGH RECORD
        STA ICBAH,X
        LDA #LOW RECORD
        STA ICBAL,X
        LDA #4
        STA ICAX1,X
        JSR CIOV ; Open it.
        BPL :NOERR
        PRINTS BSTMSG ; Bad open stat
        LDA #0
        JSR TLOOP ; Send badstat
        JSR INIT ; Start over
:NOERR: LDA #$FF ; Send goodstatus
        JSR TLOOP
;
        JSR GETFB ; Get file byte.
        PHA ; Stash byte
        JSR TLOOP ; Send it
        PLA
        CMP #$FF
        BNE :BADHD
        JSR GETFB
        PHA
        JSR TLOOP
        PLA
        CMP #$FF
        BEQ :GOODHD
:BADHD: PRINTS NTLF ; Not load file
        JMP INIT
;
; Get/Send Load/End addresses:
;
:GOODHD JSR GETFB
:GDHD1: STA LOADL
        JSR TLOOP
        JSR GETFB
:GDHD2: