************************************************************ * TAPEBITS * Read cassette data, record duration of each bit phase. * * The buffer contains 2-byte ints, each of which is the * number of loops during a bit phase (ie: how long it was * 0, or how long it was 1). Each loop is 28 clock cycles, * or about one 31960th of a second. So a '1' bit at 2400Hz * should be about 13.32 loops for the entire bit, or 6.66 * for each phase; and a '0' bit at 1200Hz should be about * 26.63 loops per bit, or 13.32 loops per phase. * So when recieving valid cassette data, the numbers for * each phase should be 6, 7, 13, or 14. ************************************************************ PIA1AD equ $FF20 ; PIA 1, side A, Data register IRQ equ $10 FIRQ equ $40 ACTIVE equ $05FF ; lower right character on screen buffer equ $4000 ; where to store results endbuf equ $8000 org $3000 start equ * bra start2 fcb $99,$08,$25,$18,$10 fcc "TAPEBITS V0.1" start2 equ * orcc #IRQ|FIRQ ; disable interrupts sty tmp_y ; save .y ldx #buffer clr over ; no overflows yet lda PIA1AD anda #1 ; look at cassette input bit new equ * sta prev ; 5 ; remember if it is 0 or 1 ldy #1 ; 4 ; initialize counter * Since each phase has an overhead of 32 cycles (new + diff), * we count one additional loop. Loops take 28 cycles each, * so this is pretty close. same equ * leay 1,y ; 5 cmpy #$FFFF ; 5 ; counter overflow? beq overflow ; 3 lda PIA1AD ; 5 anda #1 ; 2 ; look at cassette input bit cmpa prev ; 5 ; compare with previous beq same ; 3 ; not changed yet; count more * -- * 28 diff equ * inc ACTIVE ; 7 ; show that we're waiting sty ,x++ ; 9 ; phase changed, save count cmpx #endbuf ; 4 ; buffer full? bne new ; 3 ; if not, count more * -- * 23 done equ * stx last ldy #tmp_y ; restore .y andcc #~(IRQ|FIRQ) ; re-enable interrupts rts overflow equ * lda over inca ; another overflow cmpa #30 ; too many? bhs done ; if so, exit sta over ; not too many yet lda prev ; still the same bit value bra diff ; continue counting org $3100 last fdb 0 ; last address filled + 2 prev fcb 0 ; last known value of cassette bit over fcb 0 ; number of counter overflows tmp_y fdb 0 ; .y saved here on entry end start