TITLE 'Bit Banger for CompuPro DISK1' ; Bit Banger for CompuPro DISK1. ; 7 Data bits, no parity ; For 2 MHz 8085, use 300 Baud. ; For 5 MHz, use 600 Baud. space 4,10 ; Normal bit timings. ; ___ TICK ___ ; Baud uSec/bit 2MHz 5MHz ; 4800 208 <<< 25 ; 2400 416 18 46 ; 1200 833 38 92 ; 600 1667 75 216 ; 300 3333 102 >>> ; 110 can't >>> >>> ; ; Restriction on higher rates is due to the fact ; that we can only adjust speed by integral TICK ; counts: Unless number > 100, cannot tune in closer ; than one percent. ; Timing for the Bit Banger is via programmed delays, ; so be very careful if changes are contemplated. ; Baud = Bit per second of serial data. ; Cycle = Machine cycle (clock period, T-State). ; Tick = 1/n of a bit time (PERIOD of sample). ; ; 1200 baud = 833 uSec/bit ; * 2 MHz = 1667 cycles/bit ; / 16 sample rate= 104 cycles/Tic yBANG: EQU SER ;Serial bit latch port DS 1 ;Banger Threshold (= 0.5 * TICK) TICK: DS 1 ;Banger sample period SAMP: DB -1 ;dummy pre-store DS 10 ;buckets for Space counts DB -1 space 4,10 ; CONSOLE STATUS ; BitBanger has no status available, so always ; replies NO. This means that Ctrl-S will ; not work when using the BitBanger. ; Exit A= FFh means character available. KONST: XOR AX,AX ;A=0, clear Carry RET space 4,10 ; Output 1 Character. ; Entry CL= Character to output. ; Line assumed marking. ; Exit Line marking, but stop time not elapsed. ; Transmission format: ; Data bits inverted; ; Start(0), D0, D1, ..., D6, Stop(1), Leaves marking ; Note: Cannot destroy DX or BX. ; Uses AF, CX. KONOUT: proc PUSH BX PUSH DX MOV AL,CL AND AL,# 7Fh ;use Bit7 as Start bit (0) XOR AL,# 0FFh ;invert data RCL AL ;adjust MOV CL,AL LD CH,# 7+1+1 ;7 bit data, 1 Start, 1 fudge ; Write 8 bits. :N: LD AL,TICK ;(7 7 MOV DL,AL ;(2) ;r STO DH,[bx] ;(7 7 ;r LD DH,# 0 ;(7 7 MOV AL,CL ;(2) RCR AL ;(2) MOV CL,AL ;(2) DEC CH ;(2) JZ :6 ;if enuf bits read INC BX ;(5 6 ; Begin output loop for this bit. :M: OUTB yBANG ;(10) AND AL,# 80h ;(4) RCL AL ;(2) RCR AL ;(2) MOV DH,AL ;(2) DEC DL ;(2) 4) JNZ :M ;(7) ;if not yet one bit time JMP :N :6: LD CH,# 2 ;2 Stop bits :62: LD AL,TICK MOV DL,AL INC DL :65: LD AL,# 0 ;Stop bit= Mark= 1 OUTB yBANG ;(10) AND AL,# 80h ;(4) RCL AL ;(2) RCR AL ;(2) MOV DH,AL ;(2) DEC DL ;(2) 4) JNZ :65 ;(7) DEC CH JNZ :62 ;if more stoppers POP DX POP BX RET space 4,10 ; Bit Banger Input. ; ; Exit A= Character read. ; Bit7 clear. ; Uses AF, CX, DX, BX. ; Timing for 8086 8088 KONIN: if @ldr <> 4 proc LD BX,# SAMP LD CH,# 9+1 ; Wait for Start bit. :L0: INB yBANG RCL AL ;(2) JNC :L0 ;if line still Marking ; Now take 7 uniform samples. ; The number of peeks in each determines the sample width. :N: LD AL,TICK ;(13 13 MOV DL,AL ;(2) STO DH,[bx] ;(7 7 LD DH,# 0 ;(7 7 DEC CH ;(2) JZ :6 ;(10) if enuf bits read INC BX ;(5 6 ; Begin sampling loop for this bit. :M: INB yBANG ;(10) AND AL,# 80h ;(4) RCL AL ;(2) ADD AL,DH ;(2) MOV DH,AL ;(2) DEC DL ;(2) 4) JNZ :M ;(7) JMP :N ;(7) ; Reduce sample counts to data bits. ; Note that due to DISK1 inversion, ; 0 Space = Count[i] > Threshold ; 1 Mark = Count[i] < Threshold ; Actually, all counts "near" mid-range are probably ; errors. :6: LD BX,# SAMP+8 ;-> Data bit 6 LD AL,TICK-1 MOV DH,AL ;C= Threshold for Mark versus Space LD CX,# rev 7 :64: MOV AL,CL RCL AL ;(2) MOV CL,AL LD AL,[bx] CMP AL,DH JNC :66 ;if large count INC CL ;set bit for Mark :66: DEC BX DEC CH JNZ :64 ;if more bits to reduce MOV AL,CL endif RET space 4,10 ; Determine speed of terminal. ; User must input a 'U' ; Relies on being able to measure the width of the ; Start bit. Therefore, needs an odd-numbered Ascii ; to be input. ; Consecutive samples look like this: ; ...11111111111110000..001xxxxxxx... ; Mark Space Mark ; ...Idle Start Data0 (ignore...) BAUD: proc LD BX,# SAMP LD CH,#3 LD DX,#1 ; Wait for Start bit. :L0: INB yBANG RCL AL ;(2) JNC :L0 ;if line still Marking ; Now measure width of next several pulses. ; The number of peeks in each determines the sample width. :N: MOV CL,DL ;(2) LD AL,TICK ;(13 13 STO DH,[bx] ;(7 7 LD DH,#0 ;(7 7 DEC CH ;(2) JZ :6 ;(10) if enuf bits read INC BX ;(5 6 ; Begin sampling loop for this bit. :M: INC DH ;(2) INB yBANG ;(10) AND AL,# 80h ;(4) RCL AL ;(2) CMP AL,CL ;(2) MOV DL,AL ;(2) JZ :M ;(7) JMP :N ;(7) ; Reduce sample counts to data bits. :6: LD AL,SAMP+1 STO AL,TICK ;set nominal bit width CLC ROR AL ;width / 2 = threshold STO AL,TICK-1 RET ; Endx GBcbiot3.asm