;;; ;;; Simple cassette data loader ;;; By: Daniel Tufvesson 2018 ;;; ;;; Monitor routines mon_return: equ $c000 mon_pdata: equ $c009 mon_out4hs: equ $c015 mon_baddr: equ $c01e mon_pcrlf: equ $c021 console_status: equ $7fe5 console_output: equ $7fe8 console_input: equ $7feB page_register: equ $0002 ;;; Address of cassette interface casport: equ $8060 ;;; Program begin here org $a100 jmp start thresh: fcb 0 count: fcb 0 dsta: fdb 0 txt_da: fcc "DstAddr: " fcb $04 txt_st: fcc "Press enter and start tape" fcb $04 txt_ex: fcc "Stop at " fcb $04 start: ldaa #$f0 staa page_register ;; Ask for address ldx #txt_da jsr mon_pdata jsr mon_baddr stx dsta jsr mon_pcrlf ;; Start tape ldx #txt_st jsr mon_pdata jsr console_input cmpa #$0d beq *+5 jmp quit jsr mon_pcrlf ldx dsta ;; Start sync sync: clr thresh clr count jsr console_status tsta beq *+5 jmp quit sync1: jsr cycle tsta beq sync ; resync on timeout adda thresh ; calc running average length lsra ; thresh = (A + thresh ) / 2 staa thresh inc count bne sync1 ;; Calculate threshhold ldaa thresh tab lsrb lsrb sba staa thresh ;; Wait for sync end bit sync2: jsr cycle tsta beq sync ; resync on timeout cmpa thresh bhi sync2 ;; Begin data load load: clr ,x ; prepare destination byte jsr cycle ; start bit cmpa thresh bhi exit ; exit when no start bit ldaa #8 staa count load1: jsr cycle ; data bit tsta beq exit ; exit on timeout suba thresh ; carry will be set on overflow ;; Shift bit into memory byte ;; (inverted data bit now in carry) ldaa ,x rora staa ,x dec count bne load1 com ,x inx bra load ;; End of load ;; Inform user and print end address exit: dex stx dsta ldx #txt_ex jsr mon_pdata ldx #dsta jsr mon_out4hs jsr mon_pcrlf quit: jsr console_status tsta beq quit1 jsr console_input quit1: jmp mon_return ;;; ;;; Get cycle time in A ;;; (0 on timeout) ;;; cycle: clra ldab casport bmi cycle3 ; if high on entry we are out of sync cycle0: inca beq cycle3 ; timeout ldab casport bpl cycle0 ; wait for positive flank clra cycle1: inca beq cycle3 ; timeout ldab casport bmi cycle1 ; wait for negative flank cycle3: rts