 .OPT NO LIST›; Cassette 60317-60438›; In old source, SIO is SIOINT›; and SIOMAIN is SIO. Labels›; here are per Mapping The Atari›; Also SENDEN is DOSENDE›;  " ISRODEN is XSEROUT›;  " ISRSIR  is XSERIN›;  " ISRTD is XSEROC› .PAGE "SIO"›  LIST› .LOCAL›;›SIO› LDA #$3C    Turn off tape› STA PACTL   motor› LDA #$3C    Raise not Cmd› STA PBCTL   line› LDA #3      Setup Pokey:› STA SSKCTL  Enable Kbd scan,› STA SOUNDR  debounce and i/o› STA SKCTL   noise off› RTS›;›SIOMAIN› TSX         SIO main routine› STX STACKP› LDA #1      Flag time› STA CRITIC  critical i/o› LDA DDEVIC› CMP #$60    Cassette?› BNE ?NOTCST No› JMP ?CASENT Yes, go›;›?NOTCST› LDA #0      Flag not› STA CASFLG  tape› LDA #1      Set device› STA DRETRY  retries›;›?COMMND› LDA #13     Send cmd frm› STA CRETRY  set retries›;›; Send command frame›;›?COMFRM› LDA #$28    Set 19.2kbaud› STA AUDF3› LDA #0› STA AUDF4› CLC› LDA DDEVIC  Setup cmd› ADC DUNIT   frame› ADC #$FF    less 1› STA CDEVIC  as bus i.d.› LDA DCOMND› STA CCOMND  bus command› LDA DAUX1› STA CAUX1   and aux bytes› LDA DAUX2› STA CAUX2› CLC         Point to› LDA # <CDEVIC command› STA BUFRLO  frame buffer› ADC #4› STA BFENLO› LDA # >CDEVIC› STA BUFRHI› STA BFENHI› LDA #$34    Lower not› STA PBCTL   command line› JSR ?SENDIN Send cmd frame› LDA ERRFLG  Check for bus err› BNE ?BADCOM Go if any›;› TYA         Go if Ack› BNE ?ACKREC received›;›?BADCOM› DEC CRETRY  Got err› BPL ?COMFRM Go if any left›;› JMP ?DERR1  To return code›;›?ACKREC› LDA DSTATS  Go if no data› BPL ?WATCOM to send.›;› LDA #13     Send data frame› STA CRETRY  Set retries› JSR ?LDPNTR Set buffr ptrs› JSR ?SENDIN Send data› BEQ ?DERR1  Go if timed out›;›; Wait for completion›;›?WATCOM› JSR ?STTMOT Put time› LDA #0      out in x,y› STA ERRFLG  Clear errflg› JSR ?WAITER Set timer/wait› BEQ ?DERR   Go if timeout›;› BIT DSTATS› BVS ?MODATA Go if receiving data›;› LDA ERRFLG› BNE ?DERR1  Branch if error› BEQ ?RETURN Else exit›;›; Receive a data frame›;›?MODATA› JSR ?LDPNTR set ptrs› JSR ?RECEIV›;›?DERR› LDA ERRFLG  Go if no› BEQ ?NOTERR error preceeded›;    data› LDA TSTAT   Get temp status› STA STATUS  store in real›;›?NOTERR› LDA STATUS› CMP #1› BEQ ?RETURN Go if success›;›?DERR1› DEC DRETRY  Go if out of› BMI ?RETURN device retries› JMP ?COMMND else redo cmd›;›; Complete sio op›;›?RETURN› JSR ?SENDDS Kill Pokey› LDA #0      ints & reenable› STA CRITIC  stage 2 vblank› LDY STATUS  Return status in› STY DSTATS  y and dcb and› RTS         leave flag valid›;›; Subroutine: ›;›?WAIT› LDA #0      Wait for ACK› STA ERRFLG  or completion› CLC› LDA # <TEMP Setup temporary› STA BUFRLO  one byte buffer› ADC #1› STA BFENLO› LDA # >TEMP› STA BUFRHI› STA BFENHI› LDA #$FF    Set no cksum› STA NOCKSUM follows data flag› JSR ?RECEIV Go get byte› LDY #$FF    Assume success› LDA STATUS› CMP #1› BNE ?NWOK   Go if bad›;› LDA TEMP› CMP #'A     Ack?› BEQ ?GOOD›;› CMP #'C     Complete?› BEQ ?GOOD›;› CMP #'E     Error?› BNE ?NOTDER No›;› LDA #144    Else error 144› STA STATUS› BNE ?NWOK›;›?NOTDER› LDA #139    NAK error 139› STA STATUS›;›?NWOK› LDA STATUS› CMP #138    Timeout?› BEQ ?BAD    Yes, go›;› LDA #$FF    Flag some error› STA ERRFLG  Return with› BNE ?GOOD   y<>0›;›?BAD› LDY #0      y=0 if timeout›;›?GOOD› LDA STATUS› STA TSTAT› RTS›;›?SEND› LDA #1      Send buffer to› STA STATUS  serial bus› JSR DOSENDE Enable send› LDY #0› STY CHKSUM  Clear chksum› STY CHKSNT  and sent flag› STY XMTDON  and xmit done› LDA (BUFRLO),Y Load first› STA SEROUT  byte and› STA CHKSUM  start checksum›;›?NOTDON› LDA BRKKEY›;› BNE ?NTBRK0› JMP ?BROKE  Go if Break key›;›?NTBRK0› LDA XMTDON  Loop til› BEQ ?NOTDON xmission done›;› JSR ?SENDDS Disable sending› RTS›;›XSEROUT› TYA         Process serial› PHA         output ready irq› INC BUFRLO  Bump buffer ptr› BNE ?NOWRP0›;› INC BUFRHI›;›?NOWRP0› LDA BUFRLO  Check if› CMP BFENLO  past end› LDA BUFRHI› SBC BFENHI› BCC ?NOTEND Branch if not›;› LDA CHKSNT  Go if chksum› BNE ?RELONE sent›;› LDA CHKSUM  Send checksum› STA SEROUT› LDA #$FF› STA CHKSNT› BNE ?CHKDON›;›?RELONE› LDA POKMSK  Enable› ORA #$08    transmit done› STA POKMSK  interrupt› STA IRQEN›;›?CHKDON› PLA         Exit interrupt› TAY› PLA› RTI›;›?NOTEND› LDY #0      Send next byte› LDA (BUFRLO),Y from buffer› STA SEROUT› CLC› ADC CHKSUM  Add to csum› ADC #0› STA CHKSUM› JMP ?CHKDON Return›;›; Process serial output comp›;›XSEROC› LDA CHKSNT  Go if csum› BEQ ?FOOEY  not yet sent›;› STA XMTDON  Else flag done› LDA POKMSK  Disable xmit› AND #$F7    done interrupt› STA POKMSK› STA IRQEN›;›?FOOEY› PLA› RTI›;›?RECEIV› LDA #0      Receive subrtn› LDY CASFLG› BNE ?NOCLR  Go if cassette›;› STA CHKSUM  Clear cksum,›;›?NOCLR› STA BUFRFL  full flag,› STA RECVDN  and done flag› LDA #1› STA STATUS  Default good› JSR ?RECVEN Enable receive› LDA #$3C    Command frame hi› STA PBCTL   to pia›;›?CHKTIM› LDA BRKKEY› BNE ?NTBRK1›;› JMP ?BROKE  Go if Break key›;›?NTBRK1› LDA TIMFLG  If timeout› BEQ ?TOUT   go set error›;› LDA RECVDN  Done?› BEQ ?CHKTIM›;› RTS         Yes, exit›;›?TOUT› LDA #138    Timeout› STA STATUS› RTS›;›XSERIN› TYA         Process serial› PHA         input ready irq› LDA SKSTAT› STA SKREST  Reset status reg› BMI ?NTFRAM Go if no framerr›;› LDY #140    Framing error› STY STATUS›;›?NTFRAM› AND #$20    Go if no› BNE ?NTOVRN overrun error›;› LDY #142    Data frame› STY STATUS  overrun›;›?NTOVRN› LDA BUFRFL  Go if bffr› BEQ ?NOTYET not filled›;› LDA SERIN   Else, byte is› CMP CHKSUM  checksum› BEQ ?SRETRN Branch if match›;› LDY #143    Checksum err› STY STATUS›;›?SRETRN› LDA #$FF    Flag receive› STA RECVDN  done›;›?SUSUAL› PLA› TAY› PLA› RTI›;›?NOTYET› LDA SERIN› LDY #0      Store input in› STA (BUFRLO),Y buffer› CLC› ADC CHKSUM  Add to csum› ADC #0› STA CHKSUM›;› INC BUFRLO  Bump buffer› BNE ?NTWRP1›;› INC BUFRHI›;›?NTWRP1› LDA BUFRLO› CMP BFENLO› LDA BUFRHI› SBC BFENHI› BCC ?SUSUAL Go if end bffr›;› LDA NOCKSUM Go if a csum› BEQ ?GOON   will follow data›;› LDA #0› STA NOCKSUM Clear flag› BEQ ?SRETRN Go always›;›?GOON› LDA #$FF    Set buffer› STA BUFRFL  full flag› BNE ?SUSUAL Go always›;›; Subroutine: Set buffer pointer›; and end+1›;›?LDPNTR› CLC› LDA DBUFLO› STA BUFRLO› ADC DBYTLO› STA BFENLO› LDA DBUFHI› STA BUFRHI› ADC DBYTHI› STA BFENHI› RTS›;›; @ Cassette handler entry›;›?CASENT› LDA DSTATS  Tape i/o› BPL ?CASRED Go if input›;›; Write a record›;› LDA #$CC    Set 600 baud› STA AUDF3› LDA #5› STA AUDF4› JSR DOSENDE Enable mark tone›;› LDX PALNTS  Mod for pal/ntsc›;› LDY NTSC.PAL+4,X Short gap› LDA DAUX2› BMI ?SRTIR0 Go if short ok›;› LDY NTSC.PAL,X Else long gap›;›?SRTIR0› LDX #0› JSR ?SETVBX Set write time› LDA #$34› STA PACTL   Motor on›;›?TIMIT› LDA TIMFLG  Loop til› BNE ?TIMIT  done›;› JSR ?LDPNTR Set buffr ptrs› JSR ?SEND   Send buffer› JMP ?CRETRN Exit›;›?CASRED› LDA #$FF    Receive tape› STA CASFLG  set flag›;› LDX PALNTS› LDY NTSC.PAL+6,X Short irg› LDA DAUX2› BMI ?SRTIR1 Go if ok›;› LDY NTSC.PAL+2,X Else long›;›?SRTIR1› LDX #0      Set timeout› JSR ?SETVBX for read› LDA #$34› STA PACTL   Motor on›;›?TIMIT1› LDA TIMFLG  Loop til› BNE ?TIMIT1 done›;› JSR ?LDPNTR set ptrs› JSR ?STTMOT set timeout› JSR ?SETVBX in y,x; exec› JSR ?BEGIN  set baud rate› JSR ?RECEIV receive block›;›?CRETRN› LDA DAUX2› BMI ?SRTIR2 Go if short irg› LDA #$3C    Else turn off› STA PACTL   motor›;›?SRTIR2› JMP ?RETURN›;›?CLRTMFG› LDA #0      Timer expiration› STA TIMFLG  for cdtimer1› RTS›;›; Subroutine: Enable SIO send›;›DOSENDE› LDA #7› AND SSKCTL  Save kbd/pot bits› ORA #$20    set tx mode› LDY DDEVIC› CPY #$60› BNE ?NOTCAS Go if not tape›;› ORA #8      Set fsk o/p bit› LDY #7› STY AUDF2   Set low tone› LDY #5› STY AUDF1   and high tone›;›?NOTCAS› STA SSKCTL  Set mask› STA SKCTL   and actual›;› LDA #$C7    Disable serial› AND POKMSK  interrupts› ORA #$10    Enable seror› JMP ?CONTIN›;›?RECVEN› LDA #7      Enable sio rx› AND SSKCTL› ORA #$10    set rx asynch› STA SSKCTL› STA SKCTL› STA SKREST  reset port/kbd› LDA #$C7    kill old ints› AND POKMSK› ORA #$20    enable serin›;›?CONTIN› STA POKMSK  Set up send› STA IRQEN   or receive› LDA #$28    clock ch3 with 4› STA AUDCTL  @ 1.79 mhz› LDX #6      pure tone no vol› LDA #$A8› LDY SOUNDR  quiet i/o?› BNE ?NOISE1 no, noise on› LDA #$A0    kill noise›;›?NOISE1› STA AUDC1,X Into all› DEX         four audc regs› DEX› BPL ?NOISE1›;› LDA #$A0    no noise in› STA AUDC3   audc3› LDY DDEVIC› CPY #$60    cassette?› BEQ ?CAS31  yes go›;› STA AUDC1   no noise in› STA AUDC2   ch1/2 for disk›;›?CAS31› RTS›;›; Subroutine: Disable send or›; receive and kill all audio›;›?SENDDS› NOP› LDA #$C7› AND POKMSK› STA POKMSK› STA IRQEN› LDX #6› LDA #0›?ZERIT› STA AUDC1,X› DEX› DEX› BPL ?ZERIT› RTS›;›; Subroutine: Set device timeout›; into y,x. In essence: Dtimlo*$100/4›;›?STTMOT› LDA DTIMLO› ROR A› ROR A› TAY› AND #$3F› TAX› TYA› ROR A› AND #$C0› TAY› RTS›;›; These 3 addresses are not referenced›;› .WORD XSERIN sio› .WORD XSEROUT interrupt› .WORD XSEROC handlers›;›; Subroutine: Send to intelligent›; device›;›?SENDIN› LDX #1       ; 2  Delay 1282 cycles›?DELAY0› LDY #$FF     ; 2›?DELAY1› DEY          ; 2  Inner: 255*5-1› BNE ?DELAY1  ; 3  (2 on last)› DEX          ; 2› BNE ?DELAY0  ; 2  Branch never!› JSR ?SEND   Send buffer to serial bus›;› LDY #2      set ack timeout› LDX #0›;›; Subroutine: Set timer and wait›; for response›;›?WAITER› JSR ?SETVBX› JSR ?WAIT› TYA         Timeout if y=0› RTS›;›; @ Subroutine: Compute baud rate›;›?COMPUT› STA TIMER2  Compute› STY TIMER2+1 baud rate› JSR ?ADJUST adjust Vcount›;› STA TIMER2› LDA TIMER1› JSR ?ADJUST› STA TIMER1› LDA TIMER2  Find Vcount› SEC         difference› SBC TIMER1› STA TEMP1› LDA TIMER2+1› SEC› SBC TIMER1+1› TAY› LDX PALNTS› LDA #0› SEC› SBC NTSC.PAL+8,X›;›?HITIMR› CLC         multiply› ADC NTSC.PAL+8,X› DEY› BPL ?HITIMR›;› CLC         total Vcount› ADC TEMP1   difference›;›?FINDX› TAY         label not ref› LSR A       from 800› LSR A› LSR A› ASL A› SEC› SBC #22     adj table index› TAX         div by 4› TYA› AND #7      get 3 low bits› TAY› LDA #-11›;›?DOINTP› CLC         accumulate› ADC #11     interpolation› DEY         constant› BPL ?DOINTP›;›?ENINTP› LDY #0      lbl not ref (800)› SEC         adjust interpol.› SBC #7      const› BPL ?PLUS›;› DEY›;›?PLUS› CLC         add const to lsb› ADC TPFV,X  freq table val› STA CBAUDL› TYA› ADC TPFV+1,X carry to msb› STA CBAUDH› RTS›;›; @ Subroutine: Adjust VCOUNT value›;›?ADJUST› CMP #$7C› BMI ?ADJ1›;› SEC› SBC #$7C› RTS›;›?ADJ1› CLC› LDX PALNTS› ADC NTSC.PAL+10,X› RTS›;›?BEGIN› LDA BRKKEY  Set initial› BNE ?NTBRK2 baud rate›;› JMP ?BROKE›;›?NTBRK2› SEI› LDA TIMFLG  go if not timed› BNE ?OKTIM1 out›;› BEQ ?TOUT1  Else glitch›;›?OKTIM1› LDA SKSTAT  Read serial› AND #$10    port› BNE ?BEGIN  Start bit?›;› STA SAVIO   Save data in› LDX VCOUNT  Read count› LDY RTCLOK+2› STX TIMER1  Save initial› STY TIMER1+1 timer value› LDX #1› STX TEMP3› LDY #$0A›;›?60776› LDA BRKKEY› BEQ ?BROKE›;› LDA TIMFLG› BNE ?60789›;›?TOUT1› CLI› JMP ?TOUT›;›?60789› LDA SKSTAT› AND #$10› CMP SAVIO› BEQ ?60776›;› STA SAVIO› DEY› BNE ?60776›;› DEC TEMP3› BMI ?60822›;› LDA VCOUNT› LDY RTCLOK+2› JSR ?COMPUT› LDY #9› BNE ?60776›;›?60822› LDA CBAUDL› STA AUDF3   audf3› LDA CBAUDH› STA AUDF4   audf4› LDA #0› STA SKCTL› LDA SSKCTL› STA SKCTL› LDA #$55› STA (BUFRLO),Y› INY› STA (BUFRLO),Y› LDA #$AA› STA CHKSUM› CLC› LDA BUFRLO› ADC #2› STA BUFRLO› LDA BUFRHI› ADC #0› STA BUFRHI› CLI› RTS›;›?BROKE› JSR ?SENDDS Process› LDA #$3C    Break key› STA PACTL› LDA #$3C› STA PBCTL› LDA #128    Break abort› STA STATUS› LDX STACKP  Restore stack› TXS         to entry condit.› DEC BRKKEY› CLI› JMP ?RETURN›;›?SETVBX› LDA # <?CLRTMFG Set› STA CDTMA1  countdown timer1› LDA # >?CLRTMFG address› STA CDTMA1+1› LDA #1      y and x preset› SEI         by caller› JSR SETVBV  set cdtimer1?› LDA #1› STA TIMFLG› CLI› RTS›;›TPFV› .WORD $03E8› .WORD $0443 Pokey› .WORD $049E› .WORD $04F9 frequency› .WORD $0554› .WORD $05AF values› .WORD $060A› .WORD $0665› .WORD $06C0› .WORD $071A› .WORD $0775› .WORD $07D0›