* 6809 MAC Assembler code * RELEASED TO PUBLIC DOMAIN -- Use at your own risk * CoCo IR Remote Control input code * Assumes RS #276-137 Infrared Detector Module wired to * a joystick button input. * RL Hawkins DELPHI BHAWKINS * Original: March 1991 * Modified: Jan 1992 * FIRE2 EQU $FF00 PIA address for "fire" button. * BASIC USR INTERFACE: USRFRM EQU $B3ED Get USR arg USRTO EQU $B4F4 Return USR val * * Note -- RTMAX must be less than 256: RTMAX EQU 201 Max number of entries (bytes) in run-length table. BUFST EQU $5000 Raw data buffer -- BUFEND EQU $7000 -- past end of raw data buffer RUNTBL EQU $7100 Run-length table TABLEN EQU 33 Expected table length = 2*16 bits + STOP pulse HILO EQU 60 Count that divides "short" from "long" * Note -- this is 1 for the right joystick. To use the left * joystick, change it to 2: FIREBIT EQU 1 Mask for "fire" button's bit in the PIA byte. * ORG $7400 Relocatable code, but tables are fixed for speed. * * * CODE BEGINS: * Read IR input, determine run lengths, store at RUNTBL. REMOTE STB $FFD8 Assure slow (0.895 MHz) speed LDX #BUFST Byte block address. Should have 8K or so available. BSR IRRAW Raw sampled data. LDX #BUFST Point to start of sample. BSR MARK Mark end of valid sample with 0 byte. LDX #BUFST Point to start of sample. BSR RUNS Generate run-length table from sample. BSR MKWORD Generate 16-bit word from run-length table LDD WORDHI,PCR Get word JMP USRTO Back to BASIC * * *********************************************************************** * IR remote raw input * Reads and stores PIA byte as fast as possible, for later analysis. * IN: X <- Starting address of the byte block. (Block ends at #BUFEND.) *USES: A, Y. * IRRAW LDY #FIRE2 PIA address. Held in Y for speed (one cycle!) PSHS CC Save interrupts. ORCC #$50 Disable interrupts. * Wait for IR signal to start. IRWAIT LDA ,Y (4~) BITA #FIREBIT (2~) (9~) overhead = 0.01 mSec BNE IRWAIT (3~) * Read and store PIA status: IRREAD LDA ,Y (4~) STA ,X+ (6~) * Note: the end-of-buffer address is hard-coded as an IMMEDIATE value * for maximum speed in the sample loop. CMPX #BUFEND (4~) (17~) overhead = 0.019 mSec BLT IRREAD (3~) (or 5263 loops in 0.1 sec) PULS CC Restore interrupts. RTS * * Determine the number of actual data bytes in the byte buffer at BUFST, * Mark end with a 0 byte. * End of data is assumed to be more than 255 bytes of "off". MARK LDA ,X+ BITA #FIREBIT BEQ MARK Look for an "off" (high bit 0) byte. * Got an "off": CLRB Consecutive off-byte counter. TFR X,Y Save X in case this the end of data. MRKLOP INCB BEQ ENDMRK 256th "off" byte -- end of data. * LDA ,X+ Next byte. BITA #FIREBIT BNE MRKLOP Loop while "off". * Found an "on" byte -- so go back and look for another "off": BRA MARK ENDMRK CLR -1,Y Mark end of data with a zero byte. RTS * * Fill RUNTBL with run lengths. * IN: X <- address of the byte table. Byte table is 0-terminated. * USE: A, B, Y RUNS BSR CLRTBL Initialize LDY #RUNTBL RUNSLP LDA ,X+ BEQ RUNSEN 0 byte marks end of byte table. BSR RUN Get next run length in B INC ,Y Increment run table index LDA ,Y Get incremented index STB A,Y Store run length in table at index BRA RUNSLP Do it again RUNSEN RTS * * Clear the run-length table CLRTBL LDY #RUNTBL CLRA CLRB CLRLOP STA B,Y INCB CMPB #RTMAX End of table yet? BNE CLRLOP RTS * * Get one run-length. Number of identical bytes, starting at X. * IN: X -> address of byte block. * A -> byte value which must be matched. * OUT: X <- address of first different byte. * B <- number of identical bytes. RUN CLRB STA BYTE1,PCR Byte value for comparison RUNLOP LDA ,X+ INCB CMPA BYTE1,PCR BEQ RUNLOP LEAX -1,X Adjust back to first different byte. RTS * BYTE1 RMB 1 Scratch storage. * * Generate a 16-bit word from the run table: MKWORD CLR WORDHI,PCR CLR WORDLO,PCR LDB RUNTBL CMPB #TABLEN BNE DONE Wrong table length -- error * Correct table length -- continue: LDX #RUNTBL LEAX 2,X Index of first "off" gap * High byte: LDB #8 Bits per byte LDA #HILO For comparison HILOOP CMPA ,X Set carry if > HILO ROL WORDHI,PCR Roll in carry bit LEAX 2,X Skip to next "off" gap DECB BNE HILOOP * Low byte: LDB #8 LOLOOP CMPA ,X ROL WORDLO,PCR LEAX 2,X DECB BNE LOLOOP DONE RTS WORDHI RMB 1 WORDLO RMB 1 * END REMOTE *