CODE:000006CA ; =============== S U B R O U T I N E ======================================= CODE:000006CA CODE:000006CA ; reads one bit of CTRL and processes bit buffer CODE:000006CA CODE:000006CA readCTRL: ; CODE XREF: sub_69A+4p CODE:000006CA tst.w (CTRLState1).l CODE:000006D0 bne.s actuallyReadCTRL ; if CTRLState1 is not equal to 0, branch CODE:000006D2 jsr getCTS ; copy serial state to A5 and set D1 to CTS state ($FF if 1, $00 if 0) CODE:000006D6 tst.b d1 CODE:000006D8 bpl.w return_7FE ; if negative not set (CTS is 0), return; if CTS is 1, D1 is $FF, which is -1 when signed CODE:000006DC addq.w #1,(CTRLState1).l ; increment CTRLState1 by 1 CODE:000006E2 move.w #4,(CTRLState2).l ; set CTRLState2 to 4 CODE:000006EA move.w #0,(CTRLBitBuf_Pos).l ; set CTRLBitBuf_Pos to 0 CODE:000006F2 rts ; return CODE:000006F4 ; --------------------------------------------------------------------------- CODE:000006F4 CODE:000006F4 actuallyReadCTRL: ; CODE XREF: readCTRL+6j CODE:000006F4 move.w (CTRLState1).l,d0 CODE:000006FA addq.w #1,d0 CODE:000006FC move.w d0,(CTRLState1).l ; increment CTRLState1 by 1 and leave value in D0 CODE:00000702 move.w (CTRLState2).l,d1 ; move CTRLState2 to D1 CODE:00000708 cmp.w d0,d1 CODE:0000070A bgt.w return_7FE ; if CTRLState2 is greater than CTRLState1, return CODE:0000070E moveq #4,d1 CODE:00000710 cmp.w d1,d0 CODE:00000712 bgt.w loc_74E ; if CTRLState1 is greater than 4, branch CODE:00000716 jsr getCTS ; get CTS (set D1 to $FF if DSR is high, $00 if low) CODE:0000071A tst.b d1 CODE:0000071C bpl.s loc_738 ; if negative not set (CTS is 0), branch; if CTS is 1, D1 is $FF, which is -1 when signed CODE:0000071E move.w #$E,(CTRLState2).l ; set CTRLState2 to $E CODE:00000726 moveq #7,d0 ; set D0 to 7 (so that the loop happens 8 times) CODE:00000728 lea (CTRLBitBuffer).l,a5 ; make A5 point to CTRLBitBuffer CODE:0000072E moveq #0,d1 ; set D1 to 0 CODE:00000730 CODE:00000730 loc_730: ; CODE XREF: readCTRL:loc_732j CODE:00000730 move.b d1,(a5)+ CODE:00000732 CODE:00000732 loc_732: ; DATA XREF: sub_2DCCE+42o CODE:00000732 dbf d0,loc_730 ; loop zeroes out 8 bytes of of CTRLBitBuffer, since each byte represents a bit, this just gets rid of one byte of CTRL data CODE:00000736 rts ; return CODE:00000738 ; --------------------------------------------------------------------------- CODE:00000738 CODE:00000738 loc_738: ; CODE XREF: readCTRL+52j CODE:00000738 moveq #0,d0 ; zero out CTRLStates CODE:0000073A move.w d0,(CTRLState2).l CODE:00000740 move.w d0,(CTRLBitBuf_Pos).l CODE:00000746 move.w d0,(CTRLState1).l CODE:0000074C rts CODE:0000074E ; --------------------------------------------------------------------------- CODE:0000074E CODE:0000074E loc_74E: ; CODE XREF: readCTRL+48j CODE:0000074E moveq #$5E,d1 ; '^' ; set D1 to $5E (94) CODE:00000750 cmp.w d1,d0 ; compare CTRLState1 with $5E CODE:00000752 bge.s loc_776 ; if CTRLState1 is >= $5E, branch CODE:00000754 jsr getCTS ; copy serial state to A5 and set D1 to CTS state ($FF if 1, $00 if 0) CODE:00000758 lea (CTRLBitBuffer).l,a5 ; set A5 to the address of CTRLBitBuffer CODE:0000075E adda.w (CTRLBitBuf_Pos).l,a5 ; add CTRLBitBuf_Pos to A5 (point to current location in the bit buffer) CODE:00000764 move.b d1,(a5) ; place the CTS state into where A5 points CODE:00000766 addq.w #1,(CTRLBitBuf_Pos).l ; increment CTRLBitBuf_Pos CODE:0000076C addi.w #$A,(CTRLState2).l ; increment CTRLState2 by $A (10) CODE:00000774 rts CODE:00000776 ; --------------------------------------------------------------------------- CODE:00000776 CODE:00000776 loc_776: ; CODE XREF: readCTRL+88j CODE:00000776 jsr getCTS ; copy serial state to A5 and set D1 to CTS state ($FF if 1, $00 if 0) CODE:0000077A tst.b d1 CODE:0000077C bmi.s loc_7EA ; if CTS is $FF (1/high), branch CODE:0000077E lea (CTRLBitBuffer).l,a5 ; set A5 to the address of CTRLBitBuffer CODE:00000784 adda.w (CTRLBitBuf_Pos).l,a5 ; add CTRLBitBuf_Pos to A5 (point to the current location in the bit buffer) CODE:0000078A move.w (CTRLBitBuf_Pos).l,d1 ; move CTRLBitBuf_Pos to D1 CODE:00000790 subq.w #1,d1 ; subtract 1 from D1 CODE:00000792 moveq #0,d0 ; set D0 to 0 CODE:00000794 CODE:00000794 loc_794: ; CODE XREF: readCTRL:loc_79Ej CODE:00000794 tst.b -(a5) ; decrement A5 and test the byte that A5 points to CODE:00000796 bmi.s loc_79C ; if the byte is negative (1/$FF in CTS terms), branch (set the bit to 0) CODE:00000798 bset d1,d0 ; otherwise, set bit d1 of d0 to 1 CODE:0000079A bra.s loc_79E CODE:0000079C ; --------------------------------------------------------------------------- CODE:0000079C CODE:0000079C loc_79C: ; CODE XREF: readCTRL+CCj CODE:0000079C bclr d1,d0 ; set bit d1 of d0 to 0 CODE:0000079E CODE:0000079E loc_79E: ; CODE XREF: readCTRL+D0j CODE:0000079E dbf d1,loc_794 ; do loop (set CTRLBitBuf_Pos-1 bits of D0 to contents of the bit buffer) CODE:000007A2 lea (CTRL_BUFFER).l,a1 ; load the address the CTRL buffer into A1 CODE:000007A8 move.w (CTRL_H).l,d1 ; move CTRL_H (current buffer position) to D1 CODE:000007AE adda.w d1,a1 ; add D1 (H) to A1 (get address of current position in buffer) CODE:000007B0 move.b d0,(a1)+ ; add the byte D0 onto the buffer CODE:000007B2 addq.w #1,d1 ; increment 3F19 (H) by 1 CODE:000007B4 cmpi.w #$1F4,d1 ; compare D1 to $1F4 (500, presumably the ring buffer size) CODE:000007B8 bne.s loc_7BC ; if we haven't reached maximum buffer, branch CODE:000007BA moveq #0,d1 ; if we have, set buffer location to 0 CODE:000007BC CODE:000007BC loc_7BC: ; CODE XREF: readCTRL+EEj CODE:000007BC move.w d1,(CTRL_H).l ; update buffer location CODE:000007C2 move.w d1,d0 ; move buffer location to D0 CODE:000007C4 CODE:000007C4 loc_7C4: ; DATA XREF: sub_15EC8+20o CODE:000007C4 move.w (CTRL_T).l,d1 ; move CTRL_T (how far the CTRL parser is in the buffer) into D1 CODE:000007CA CODE:000007CA loc_7CA: ; DATA XREF: sub_15EC8+5Eo CODE:000007CA sub.w d1,d0 ; set D0 to CTRL_H minus CTRL_T CODE:000007CC bcc.w loc_7D4 ; if CTRL_H >= CTRL_T, branch CODE:000007D0 CODE:000007D0 loc_7D0: ; DATA XREF: sub_26B62+D8o CODE:000007D0 ; sub_26B62+118o CODE:000007D0 addi.w #$1F4,d0 ; add $1F4 (500, ring buffer size) to D0 (CTRL_H-CTRL_T) CODE:000007D4 CODE:000007D4 loc_7D4: ; CODE XREF: readCTRL+102j CODE:000007D4 move.w d0,((HEAP_3B897+$25CB)).l ; set 25CB (not sure what this is for) to the result CODE:000007DA cmp.w (CTRL_MAX).l,d0 CODE:000007E0 bcs.w loc_7EA ; if D0 < CTRL_MAX, branch CODE:000007E4 move.w d0,(CTRL_MAX).l ; set CTRL_MAX to D0 (CTRL_H-CTRL_T+500) CODE:000007EA CODE:000007EA loc_7EA: ; CODE XREF: readCTRL+B2j CODE:000007EA ; readCTRL+116j CODE:000007EA moveq #0,d0 ; zero out CTRL states CODE:000007EC move.w d0,(CTRLState2).l CODE:000007F2 move.w d0,(CTRLBitBuf_Pos).l CODE:000007F8 move.w d0,(CTRLState1).l CODE:000007FE CODE:000007FE return_7FE: ; CODE XREF: readCTRL+Ej CODE:000007FE ; readCTRL+40j CODE:000007FE rts ; return CODE:000007FE ; End of function readCTRL