RADIX 10 ; ; U7 - TMS70C40 Data Encryption Chip ; aIOCNT0 EQU >0100 ;P0 - I/O Control Register 0 aT1CNTL EQU >0103 ;P3 - Timer 1 Control aAPORT EQU >0104 ;P4 - Port A Data aBPORT EQU >0106 ;P6 - Port B Data aCPORT EQU >0108 ;P8 - Port C Data aCDDR EQU >0109 ;P9 - Port C Direction aDPORT EQU >010A ;P10 - Port D Data aDDDR EQU >010B ;P11 - Port D Direction aIOCNT1 EQU >0110 ;P16 - I/O Control Register 1 ; ORG >F000 ; DB >12,>03,>EB,>D4,>B4,>0A ; ;U7 ROM Checksum Bytes LF006 DB >68,>17 ; ;S1 thru S8 Selection Primitives ; of Data Encryption Standard ; LF008 DB >0E,>00,>04,>0F,>0D,>07,>01,>04 DB >02,>0E,>0F,>02,>0B,>0D,>08,>01 DB >03,>0A,>0A,>06,>06,>0C,>0C,>0B DB >05,>09,>09,>05,>00,>03,>07,>08 DB >04,>0F,>01,>0C,>0E,>08,>08,>02 DB >0D,>04,>06,>09,>02,>01,>0B,>07 DB >0F,>05,>0C,>0B,>09,>03,>07,>0E DB >03,>0A,>0A,>00,>05,>06,>00,>0D ; LF048 DB >0F,>03,>01,>0D,>08,>04,>0E,>07 DB >06,>0F,>0B,>02,>03,>08,>04,>0E DB >09,>0C,>07,>00,>02,>01,>0D,>0A DB >0C,>06,>00,>09,>05,>0B,>0A,>05 DB >00,>0D,>0E,>08,>07,>0A,>0B,>01 DB >0A,>03,>04,>0F,>0D,>04,>01,>02 DB >05,>0B,>08,>06,>0C,>07,>06,>0C DB >09,>00,>03,>05,>02,>0E,>0F,>09 ; LF088 DB >0A,>0D,>00,>07,>09,>00,>0E,>09 DB >06,>03,>03,>04,>0F,>06,>05,>0A DB >01,>02,>0D,>08,>0C,>05,>07,>0E DB >0B,>0C,>04,>0B,>02,>0F,>08,>01 DB >0D,>01,>06,>0A,>04,>0D,>09,>00 DB >08,>06,>0F,>09,>03,>08,>00,>07 DB >0B,>04,>01,>0F,>02,>0E,>0C,>03 DB >05,>0B,>0A,>05,>0E,>02,>07,>0C ; LF0C8 DB >07,>0D,>0D,>08,>0E,>0B,>03,>05 DB >00,>06,>06,>0F,>09,>00,>0A,>03 DB >01,>04,>02,>07,>08,>02,>05,>0C DB >0B,>01,>0C,>0A,>04,>0E,>0F,>09 DB >0A,>03,>06,>0F,>09,>00,>00,>06 DB >0C,>0A,>0B,>01,>07,>0D,>0D,>08 DB >0F,>09,>01,>04,>03,>05,>0E,>0B DB >05,>0C,>02,>07,>08,>02,>04,>0E ; LF108 DB >02,>0E,>0C,>0B,>04,>02,>01,>0C DB >07,>04,>0A,>07,>0B,>0D,>06,>01 DB >08,>05,>05,>00,>03,>0F,>0F,>0A DB >0D,>03,>00,>09,>0E,>08,>09,>06 DB >04,>0B,>02,>08,>01,>0C,>0B,>07 DB >0A,>01,>0D,>0E,>07,>02,>08,>0D DB >0F,>06,>09,>0F,>0C,>00,>05,>09 DB >06,>0A,>03,>04,>00,>05,>0E,>03 ; LF148 DB >0C,>0A,>01,>0F,>0A,>04,>0F,>02 DB >09,>07,>02,>0C,>06,>09,>08,>05 DB >00,>06,>0D,>01,>03,>0D,>04,>0E DB >0E,>00,>07,>0B,>05,>03,>0B,>08 DB >09,>04,>0E,>03,>0F,>02,>05,>0C DB >02,>09,>08,>05,>0C,>0F,>03,>0A DB >07,>0B,>00,>0E,>04,>01,>0A,>07 DB >01,>06,>0D,>00,>0B,>08,>06,>0D ; LF188 DB >04,>0D,>0B,>00,>02,>0B,>0E,>07 DB >0F,>04,>00,>09,>08,>01,>0D,>0A DB >03,>0E,>0C,>03,>09,>05,>07,>0C DB >05,>02,>0A,>0F,>06,>08,>01,>06 DB >01,>06,>04,>0B,>0B,>0D,>0D,>08 DB >0C,>01,>03,>04,>07,>0A,>0E,>07 DB >0A,>09,>0F,>05,>06,>00,>08,>0F DB >00,>0E,>05,>02,>09,>03,>02,>0C ; LF1C8 DB >0D,>01,>02,>0F,>08,>0D,>04,>08 DB >06,>0A,>0F,>03,>0B,>07,>01,>04 DB >0A,>0C,>09,>05,>03,>06,>0E,>0B DB >05,>00,>00,>0E,>0C,>09,>07,>02 DB >07,>02,>0B,>01,>04,>0E,>01,>07 DB >09,>04,>0C,>0A,>0E,>08,>02,>0D DB >00,>0F,>06,>0C,>0A,>09,>0D,>00 DB >0F,>03,>03,>05,>05,>06,>08,>0B ; ; Key for Fixed Authorization Mode ; LF208 DB >65,>66,>69,>72,>69,>6E,>67 ; ; Key for BA Mode (Signal Type >18) ; LF20F DB >CE,>35,>4E,>8D,>E0,>17,>C5,>0C ; ; Key for BA Mode (Signal Type >18) ; LF217 DB >B0,>5C,>4C,>5A,>71,>08,>87,>91 ; ; ; Command Message Lengths ; ; Length Command LF21F DB >05 ;>00 - DB >01 ;>01 - DB >08 ;>02 - DB >0C ;>03 - DB >13 ;>04 - DB >04 ;>05 - DB >04 ;>06 - DB >01 ;>07 - DB >01 ;>08 - DB >02 ;>09 - DB >14 ;>0A - DB >09 ;>0B - DB >08 ;>0C - DB >01 ;>0D - DB >02 ;>0E - DB >01 ;>0F - DB >01 ;>10 - DB >01 ;>11 - DB >14 ;>12 - DB >02 ;>13 - ; ; Table of Command ; Branch Vectors ; ; Address Command ; LF233 BR @LF343 ;>00 - BR @LF36A ;>01 - BR @LF38C ;>02 - BR @LF3B5 ;>03 - BR @LF3E6 ;>04 - BR @LF498 ;>05 - BR @LF498 ;>06 - BR @LF556 ;>07 - BR @LF519 ;>08 - BR @LF528 ;>09 - BR @LF5F9 ;>0A - BR @LF57F ;>0B - BR @LF5B4 ;>0C - BR @LF5D3 ;>0D - BR @LF56E ;>0E - BR @LF579 ;>0F - BR @LF498 ;>10 - BR @LF61E ;>11 - BR @LF63C ;>12 - BR @LF725 ;>13 - ; ; TRAP 20 ; ; Read U19 Data ; & Save @ R4A- ; LF26F MOV %>FF,R114 LF272 MOVD %>0503,R113 ;Timer Value MOV %>01,B LF278 AND %>01,B XOR %>01,B MOVP B,BPORT CMP %>FF,R114 JZ LF28A DECD R113 ;Decrement Timer JC LF28A ;Jump if No Timeout Yet CALL @LFDD6 ;Error Routine LF28A MOVP APORT,A ;Get Communications Status BTJZ %>02,A,LF278 ;Wait for A1 to go High CMP %>FF,R114 ;Any bytes in message ? JNZ LF2A9 ;Yes MOVP DPORT,B ;Get Command Byte from U19 CMP %>14,B ;> 20? JNC LF29D ;No, continue CALL @LFDD6 ;Else Error LF29D MOV %>4A,R109 ;Put command data at >4A (R74) LDA @LF21F(B) ;Command Message Length from Table MOV A,R111 ;Put in R111 MOV B,R114 ;R114 is Command Byte JMP LF2AF LF2A9 MOVP DPORT,A ;Message data from U19 STA *R109 ;Put in buffer (4A - ..) INC R109 ;Point to Next Buffer Location LF2AF MOV %>08,A ;Bit Status Code to A ORP A,CPORT ;Set C3 High (Tell U19 Byte Read) MOV %>FF,R110 ;Timer LF2B6 MOVP APORT,B ;Wait for A1 to go Low (U19 Acknowledge) BTJZ %>02,B,LF2C1 ;See if U19 Acknowledged Yet, Go if Yes DJNZ R110,LF2B6 ;Decrement timer CALL @LFDD6 ;Error on Timeout LF2C1 ANDP %>F7,CPORT ;Set C3 Low (U19 Handshake) DJNZ R111,LF272 ;Get next byte MOVP %>00,BPORT ; RETS ;Done ; ; ; TRAP 15 ; ; Write Data in ; A to U19 ; LF2CB MOV %>FF,R110 LF2CE DJNZ R110,LF2D4 CALL @LFDD6 ;Error LF2D4 BTJZP %>02,APORT,LF2CE ;Wait for A1 to go Low BTJZP %>80,APORT,LF2E0 ;Is A7 Low ? (Tied High) MOVP A,BPORT ;Output data to U19 JMP LF2E5 LF2E0 MOVP A,DPORT ;Write A to U19 MOVP %>FF,DDDR ;Set D Port Direction LF2E5 MOV %>08,A ;Set C3 High ORP A,CPORT ;Set Flag for U19 MOV %>FF,R110 ;Timer LF2EC DJNZ R110,LF2F2 ;Decrement timer CALL @LFDD6 ;Error LF2F2 BTJOP %>02,APORT,LF2EC ;Wait for A1 to go High MOVP %>00,DDDR ;Set D Port Direction ANDP %>F7,CPORT ;Set C3 Low RETS ;Done ; ; TRAP 16 ; ; Write # Bytes in B @ R62 to ; U5 Parallel/Serial Converter ; LF2FD MOV %>62,R107 ;Point to Data in RAM Register File LF300 LDA *R107 ;Get a Byte from U7 Register File MOVP A,BPORT ;Send to U5 INC R107 ;Bump Pointer to Register File ANDP %>EF,CPORT ;Set C4 Low (Strobe U5 Comm Line) ORP %>10,CPORT ;Set C4 High DJNZ B,LF300 ;Go to next byte RETS ;Done ; ; Device Initialization ; LF30F DINT ;Disable interrupts MOVP %>00,BPORT MOVP %>00,CPORT MOVP %>00,DPORT MOVP %>FF,CDDR ;Set port C to Output MOVP %>FF,DDDR ;Set port D to Output MOVP %>20,IOCNT0 ;Clear INT3 MOVP %>20,T1CNTL ;Halt low power mode IDLE ;Wait for INT1 LF326 DINT ;Disable interrupts MOVP %>00,IOCNT1 ;Disable INT4 and INT5 MOVP %>30,IOCNT0 ;Clear and Enable INT3 ANDP %>10,IOCNT0 MOV %>79,B ;SP= >79 LDSP ;Set Stack to 79 MOVP %>00,BPORT MOVP %>95,CPORT MOVP %>FF,CDDR ;Set port C to Output MOVP %>00,DDDR ;Set port D to Input EINT ;Enable interrupts BR @LFDC8 ;Begin main program ; ; Command >00 ; ; Process Seed Key Pointer Data and ; Encrypt Unit ID + 4 Key Bytes in Buffer ; to Generate an Initialization Vector ; LF343 MOVD R75,R79 ;Get Seed Key Info from Buffer MOVD R77,R81 MOVD R27,R75 MOVD R29,R77 MOV R78,B ;Seed Key Pointer to B AND %>0F,B ;Isolate Key Pointer Bits MOV B,R60 ;Save Key Pointer Byte in R60 AND %>03,B ;Isolate Bits 0 & 1 MPY %>07,B ;Compute Index to 1st Seed Key ADD %>1E,B ;Add to Seed Key Base Address XCHB R107 ;R107 ==> Proper Seed Key TRAP 18 ;DES Algorithm MOV %>4A,R107 ;Get DES Output Block MOV %>42,R109 ;Save it @ R42-R49 (Unit ID Pass #1) MOV %>08,B ;8 bytes TRAP 19 ;Copy 8 bytes from >4A to >42 BR @LFDC8 ;Done ; ; Command >01 ; ; Process Encrypted Unit ID + 4-Byte Vector ; Using 2nd Seed Key in Pointer ; LF36A MOV %>42,R107 ;Get Previous Output Block (ID # Pass # 1) MOV %>4A,R109 ;Move to DES Input Block Area MOV %>08,B ;8 bytes TRAP 19 ;Copy 8 bytes from >42 to >4A MOV R60,B ;Seed Key Pointer Byte to B AND %>0C,B ;Isolate 2nd Seed Key Bits in B RR B ;Shift them to Bits 0 & 1 RR B MPY %>07,B ;Compute Index to Proper Seed Key ADD %>1E,B ;Add to Base Address of Seed Keys XCHB R107 ;R107 ==> Proper Seed Key TRAP 18 ;DES Algorithm MOV %>4A,R107 ;Get DES Output Block MOV %>42,R109 ;Save it @ R42-R49 (Unit ID Pass #2) MOV %>08,B ;8 bytes TRAP 19 ;Copy 8 bytes from >4A to >42 BR @LFDC8 ;Done ; ; Command >02 ; ;; Get & Save AUTHORIZATION MASK & ; Process Unit ID + 4-Byte Vector with ; 1st Seed Key Specified in Pointer ; LF38C MOV %>4A,R107 ;Get AUTH Mask MOV %>13,R109 ;Save AUTH Mask @ R13-R19 MOV %>07,B ;7 bytes TRAP 19 ;Copy 7 bytes from >4A to >13 MOV %>42,R107 ;Get Unit ID Pass #2 MOV %>4A,R109 ;Move it to DES Input Block MOV %>08,B ;8 bytes TRAP 19 ;Copy 8 bytes from >42 to >4A MOV R60,B ;Seed Key Pointer Byte to B AND %>03,B ;Isolate 1st Seed Key Bits MPY %>07,B ;Compute Index to Proper Key ADD %>1E,B ;Add to Base Address of Seed Keys XCHB R107 ;R107 ==> Seed Key TRAP 18 ;DES Algorithm MOV %>42,R109 ;Point to Storage Area MOV %>4A,R107 ;Point to DES Output Block Area MOV %>08,B ;8 bytes TRAP 19 ;Copy 8 bytes from >4A to >42 (ID# Pass #3) BR @LFDC8 ;Done ; ; Command >03 ; ; Process PPV Bytes and Decrypt Unique Subscriber Category ; Key using the Vector Generated by the 00, 01 & 02 Code ; (Unit Key) to Decrypt the Month's Working Encryption Key ; LF3B5 MOVD R83,R62 ;Get 1st 2 PPV Bytes & Put in R61-R62 MOV R84,R60 ;Get 3rd PPV Byte & Put in R60 MOV %>42,R107 ;Point to Unit ID Pass #3 MOV %>02,R109 ;Move it to R02-R08 MOV %>07,B ;Only 7 bytes are Significant TRAP 19 ;Copy 7 bytes from >42 to >02 MOV %>13,R107 ;Point to AUTH Mask MOV %>02,R109 ;Point to 7 Bytes of Unit ID Pass #3 MOV %>07,B ;7 bytes TRAP 17 ;XOR Data @ *R107 with *R109 & Save @ *R109 MOV %>02,R107 ;Point to XOR'ed Result as DES Key TRAP 18 ;DES Algorithm (Data is Unique Sub Cat Key) XOR R61,R78 ;XOR 1st PPV Byte with 5th Output Byte XOR R62,R79 ;XOR 2nd PPV Byte with 6th Output Byte XOR R60,R80 ;XOR 3rd PPV Byte with 7th Output Byte MOV %>4A,R107 ;Point to DES Output Block (After XOR) MOV %>02,R109 ;Point to Storage Area for Month Working Key MOV %>07,B ;7 bytes in Month's Working Encryption Key TRAP 19 ;Copy 7 bytes from >4A to >02 BR @LFDC8 ;Done ; ; Command >04 ; ; Process AVAILABILITY DATA Using Working Key Decrypted ; from Unique Subscriber Category Key to Decrypt ; the Current Program Key (Channel Key) ; LF3E6 MOV %>4A,R107 ;Point to AVAIL Mask in Buffer MOV %>0C,R109 ;Save @ R0C-R12 MOV %>07,B ;7 bytes TRAP 19 ;Copy 7 bytes from >4A to >0C MOVD R82,R75 ;Move 8 Bytes of AVAIL Data Program MOVD R84,R77 ;Key to DES Input Block Area MOVD R86,R79 MOVD R88,R81 ;Key Move Completed MOV %>02,R107 ;Point to Month's Working Encryption Key MOV %>52,R109 ;Copy it to R52-R58 MOV %>07,B ;7 bytes TRAP 19 ;Copy 7 bytes (Data Stored @ R52-R58) XOR R89,R82 ;XOR AVAIL Data @ R59 with Byte 1 of Key XOR R90,R83 ;XOR AVAIL Data @ R5A with Byte 2 of Key XOR R91,R84 ;XOR AVAIL Data @ R5B with Byte 3 of Key MOV R91,R60 ;Save AVAIL Data Byte @ R5B in R3C (R60) PUSH R89 ;Save AVAIL Data Byte @ R59 on Stack PUSH R90 ;Save AVAIL Data Byte @ R5A on Stack MOV %>52,R107 ;Use Month Working Encryption Key as DES Key TRAP 18 ;DES Algorithm (Data is Encrypted Prog Key) POP R90 ;Restore AVAIL Data Byte @ R5A POP R89 ;Restore AVAIL Data Byte @ R5B MOV %>13,R107 ;Point to AUTH Mask Copy MOV %>0C,R109 ;Point to AVAIL Mask Copy MOV %>07,R110 ;7 bytes in Each Mask LF425 LDA *R107 ;Get AUTH Mask Byte XCHB A ;Save in B LDA *R109 ;Get AVAIL Mask Byte AND B,A ;Check if Matching 1's JNZ LF47B ;Jump if Matching 1's & Generate Program Key INC R107 ;Else Bump Pointers INC R109 DJNZ R110,LF425 ;Check all 7 Bytes BTJZ %>80,R60,LF484 ;Check for PPV Mode, Go if Not Enabled CMP R74,R9 ;Here if PPV Mode Enabled JNZ LF447 CMP R75,R10 JNZ LF447 CMP R76,R11 JMP LF47B LF447 MOVD R64,R99 MOV R65,R100 DINT ;Disable interrupts TSTA ;Clear Carry Flag DAC R89,R98 ADC R90,R99 ADC %>00,R100 JC LF484 CLR R101 MOVD R62,R103 SETC ;Set Carry Flag (Set No Borrow for DSB) DSB R98,R101 SBB R99,R102 SBB R100,R103 JNC LF484 MOVD R99,R64 MOV R100,R65 TRAP 21 ;B = XOR >41 to >3E (R65-R62) MOV B,R121 MOVD R75,R10 MOV R76,R11 EINT ;Enable interrupts LF47B MOV %>4A,R107 ;Point to DES Output Block (Program Key) MOV %>0C,R109 ;Point to AVAIL Mask MOV %>07,B ;7 bytes TRAP 17 ;XOR AVAIL Mask with Key for Program Key LF484 EINT ;Enable interrupts MOVD %>0000,R99 ;Clear Registers, Exit with Channel Key MOVD %>0000,R101 ;@ R0C-R12 MOVD %>0000,R103 MOVD %>0000,R105 BR @LFDC8 ;Done ; ; Command >10 ; ; U7 Keystream Synchronizing Command ; LF498 CMP %>10,R114 ;Check if Mode is BA JNZ LF4A9 ;See if FA or SA if Not BA MOVD %LF20F,R107 ;Point to BA Key 1 MOV %>62,R109 ;Save for TRAP 16 Write to U5 MOV %>08,B ;8 bytes TRAP 19 ;Copy 8 bytes from LF20F to >62 CLR R106 ;R106 = >00 ; ; Command >05 ; Command >06 ; ; U7 Keystream to U5 Synchronizing Commands ; ; Sends Last DES Output Block to U5, ; then Sends 3 Program Clock Bytes from ; U19 to U5 and Saves them in DES Input ; Block for Decryption Using Current Program ; Key @ R0C-R12 ; LF4A9 MOV %>08,B ;8 bytes ANDP %>9F,CPORT ORP %>40,CPORT TRAP 16 ;Write 8 bytes at >62 (R98) to U5 CMP %>10,R114 ;Command >10 ? JNZ LF4C5 ;No MOVD %LF217,R107 ;Point to BA Key 2 MOV %>62,R109 MOV %>08,B ;8 bytes TRAP 19 ;Copy 8 bytes from LF217 to >62 CLR R106 ;R106 = >00 JMP LF4D8 LF4C5 MOVD %>0000,R78 ;Zero Bytes 4-8 of Buffer MOVD %>0000,R80 ; CLR R81 ;Last Byte of Buffer Cleared MOV %>08,B ;8 bytes MOV %>4A,R107 ;Point to Program Clock Bytes in Buffer MOV %>62,R109 ;Save @ R62-R69 TRAP 19 ;Copy 8 bytes from >4A to >62 LF4D8 MOV %>08,B ;8 bytes ANDP %>9F,CPORT ORP %>60,CPORT TRAP 16 ;Write 8 bytes at >62 (R98) to U5 ANDP %>9F,CPORT ORP %>00,CPORT MOV R116,R98 ;R98=57 (Byte from Unit ID Load Command) MOV %>01,B ;1 byte TRAP 16 ;Write 1 byte at >62 (R98) to U5 ANDP %>9F,CPORT ORP %>20,CPORT MOV R115,R98 ;R98=90 (Byte from Unit ID Load Command) MOV %>01,B ;1 byte TRAP 16 ;Write 1 byte at >62 (R98) to U5 CMP %>10,R114 ;Command >10 ? JZ LF516 ;Yes CMP %>06,R114 ;Command >06 ? (Use Fixed Authorization Key) JZ LF508 ;Yes MOV %>0C,R107 ;Else Use Closed Key Mode, Key @ R0C-R12 JMP LF50C ;Enter DES Algorithm LF508 MOVD %LF208,R107 ;Fixed Key Stored in ROM ('efiring') LF50C TRAP 18 ;DES Algorithm (Data is Program Clock) MOV %>08,B ;8 bytes MOV %>4A,R107 ;Point to DES Output Block MOV %>62,R109 ;Save @ R62-R69 for Write to U5 TRAP 19 ;Copy 8 bytes from >4A to >62 LF516 BR @LFDC8 ;Done ; ; Command >08 ; LF519 ANDP %>9F,CPORT ORP %>00,CPORT MOV R117,R98 ;>37 (Byte from Unit ID Load Command) MOV %>01,B ;1 byte TRAP 16 ;Write 1 byte at >62 (R98) to U5 BR @LFDC8 ;Done ; ; Command >09 ; ; Compute Protected Account Balance ; LF528 MOV R74,R79 ;Month Key ID in Buffer to R4F MOVD R64,R75 MOV R65,R76 MOVD R62,R81 TRAP 21 CMP R1,R121 JZ LF540 MOVD %>0000,R78 JMP LF544 LF540 MOVD %>FFFF,R78 LF544 MOV %>42,R107 ;Point to Key TRAP 18 ;DES Algorithm MOVD %>004A,R107 ;Point to DES Output Block MOVD %>005A,R109 ;Save it @ R5A-R61 MOV %>08,B ;8 bytes TRAP 19 ;Copy 8 bytes from >4A to >5A BR @LFDC8 ;Done ; ; Command >07 ; ; Send 3 Bytes @ R3F-R41 to U19, then ; Send 8 Bytes @ R5A-R61 to U19, ; Data Sent is Actually the Credit Balance ; LF556 MOV %>3F,R107 MOV %>0B,B ;11 bytes LF55B CMP %>08,B ;Byte 8 Yet ? JNZ LF562 ;No, Keep Sending from R3F-R41 MOV %>5A,R107 ;Yes, Start Sending from R5A-R61 LF562 LDA *R107 ;Get a Byte TRAP 15 ;Write A to U19 INC R107 ;Next byte DJNZ B,LF55B ;Send 11 Bytes Total CLR A ;End Data with a Zero Byte TRAP 15 ;Write 0 to U19 BR @LFDC8 ;Done ; ; Command >0E ; LF56E MOV R74,A ;Get Parameter from Buffer (U19 R07) AND %>F7,A ;Clear Bit 3 (C3) OR %>10,A ;Set Bit 4 (C4) MOVP A,CPORT ;Write A to U5 (If Bit 0=1, Switch to Mono) BR @LFDC8 ;Done ; ; Command >0F ; ; Return A Port Status to U19 ; LF579 MOVP APORT,A ;>87 Usually TRAP 15 ;Write A to U19 BR @LFDC8 ;Done ; ; Command >0B ; ; Receive New Seed Key from U19 ; LF57F MOV R74,A ;1st Byte is Key Identifier INC A ;Key ID = Key ID + 1 CLR B ;B=00 SETC ;Set Carry Flag LF584 RLC B ;Rotate B Left thru Carry DJNZ A,LF584 ;Left Shift 'B' A Times MOV B,R113 ;Save B (B = 1, 2, 4 or 8) AND R58,B ;AND B with Unit ID Status Byte JNZ LF5A1 ;Exit if This Seed Key Already Loaded MOV R74,B ;Else, Key ID Byte to B MPY %>07,B ;Compute Index to Seed Key Storage Address ADD %>1E,B ;Add Index to Base Address of Keys XCHB R109 ;R109 ==> to Seed Key Storage Area MOV %>4B,R107 ;R107 ==> to Seed Key in Buffer MOV %>07,B ;Only 7 bytes are Significant TRAP 19 ;Copy 7 bytes from >4B to *R109 TRAP 14 ;Do XOR Checksum of Unit ID + Keys MOV B,R59 ;Save Result in R3B OR R113,R58 ;Flag This Seed Key # Loaded in R3A LF5A1 MOVD %>0000,R75 ;Zero Out Buffer Area MOVD %>0000,R77 MOVD %>0000,R79 MOVD %>0000,R81 ;Buffer Zeroed BR @LFDC8 ;Done ; ; Command >0C ; ; Load New Unit ID Number ; LF5B4 BTJO %>10,R58,LF5D0 ;Check serial number flag MOV %>4A,R107 ;Point to Unit ID in Buffer MOV %>1A,R109 ;Unit ID Storage Area MOV %>04,B ;4 Bytes in ID Number TRAP 19 ;Copy 4 bytes from >4A to >1A MOV %>4E,R107 ;Point to Bytes Following Unit ID MOV %>73,R109 ;Save the 90, 57, 37 @ R115-R116 MOV %>03,B ;3 bytes (>90,>57,>37) TRAP 19 ;Copy 3 bytes from >4E to >73 TRAP 14 ;B = Unit ID + Seed Keys Checksummed MOV B,R59 ;Save in R59 OR %>10,R58 ;Set serial number flag (Unit ID Loaded) LF5D0 BR @LFDC8 ;Done ; ; Command >0D ; ; Send Crypto Byte & Unit ID Number to U19 ; LF5D3 TRAP 14 ;B = Unit ID + Seed Keys Checksummed MOV R58,A ;Get R58 (Unit ID Flag Register) AND %>1F,A ;Clear Bits 5, 6 & 7 CMP R1,R59 ;See if Checksums Match JNZ LF5DF OR %>80,A ;Set Bit 7 in A LF5DF PUSH A ;Save A on Stack TRAP 21 ;Compute PPV Checksum ? POP A ;Restore A CMP R1,R121 ;B JNZ LF5E9 OR %>40,A ;Set Bit 6 in A LF5E9 TRAP 15 ;Write A to U19 ( >DF if U7 is OK ) MOV %>1A,R107 ;Unit ID Number Location MOV %>04,B ;4 bytes LF5EF LDA *R107 ;Get Byte of Unit ID in A TRAP 15 ;Write A to U19 INC R107 ;Go to next byte DJNZ B,LF5EF BR @LFDC8 ;Done ; ; Command >0A ; ; Clear U7 RAM for New Unit ID & Seed Keys ; LF5F9 MOV %>ED,A ;Start with >ED MOV %>5C,R107 LF5FE CMPA *R107 ;Do Command Validity Check Sequence JNZ LF61B ;Done CMP %>4A,R107 JZ LF60C INC A DEC R107 JMP LF5FE ;Repeat until A = >FF LF60C MOV %>7F,A ;127 bytes (Can't zero A) CLR B ;B = >00 LDSP ;SP = >00 DINT ;Disable interrupts LF611 PUSH B ;Zero all RAM except A (R0) DJNZ A,LF611 MOV %>79,B ;B = >79 LDSP ;SP = >79 TRAP 21 MOV B,R121 EINT ;Enable interrupts LF61B BR @LFDC8 ;Done ; ; Command >11 ; LF61E MOVD R119,R75 MOV R120,R76 CLR R77 MOVD %>0000,R79 MOVD %>0000,R81 MOVD %>0042,R107 ;Point to Unit Key from Commands 00,01 & 02 TRAP 18 ;DES Algorithm MOVD R75,R119 ;Save Output Block Bytes 1 & 2 in R118-R119 MOV R76,R120 ;Save Output Block Byte 3 in R120 BR @LFDC8 ;Done ; ; Command >12 ; ; Factory Test Procedure to Generate U7 Signature ; LF63C MOV %>ED,A MOV %>5C,R107 LF641 CMPA *R107 JNZ LF61B ;Done CMP %>4A,R107 JZ LF64F INC A DEC R107 JMP LF641 LF64F MOVD %LF008,R107 ;Begin ROM Checksum @ F008 MOVD %>0000,R109 ;Checksum Running Total Initialized to 00 LF657 LDA *R107 ADD R0,R109 ADC %>00,R108 ADD %>01,R107 ADC %>00,R106 CMP %>00,R106 JNZ LF657 CLR B ;B = >00 LDA @LF006(B) ;A = >68 CMP R0,R109 JNZ LF6B5 INC B ;B = >01 ? LDA @LF006(B) ;A = >17 ? CMP R0,R108 JNZ LF6B5 MOVD %>007F,R3 CLR A CLR B LF682 MOV R3,A STA *R3 XCHB A LDA *R3 XCHB A CMP R0,B JNZ LF6B5 INV A STA *R3 XCHB A LDA *R3 XCHB A CMP R0,B JNZ LF6B5 DECD R3 CMP %>3B,R3 JNZ LF6A4 MOVD %>0019,R3 LF6A4 CMP %>03,R3 JNZ LF682 MOV %>55,A MOV %>02,R2 INV R2 CMP %>FD,R2 JZ LF6B7 LF6B5 MOV %>AA,A LF6B7 MOVP %>00,BPORT MOVP %>00,CPORT ORP %>01,CPORT ;Toggle C0 (Pin 28) ANDP %>FE,CPORT MOVP %>02,CPORT ORP %>01,CPORT ;Toggle C0 (Pin 28) ANDP %>FE,CPORT MOVP A,BPORT ORP %>01,CPORT ;Toggle C0 (Pin 28) ANDP %>FE,CPORT MOVP DPORT,A MOVP A,BPORT ORP %>01,CPORT ;Toggle C0 (Pin 28) ANDP %>FE,CPORT MOVP APORT,A MOVP A,BPORT ORP %>01,CPORT ;Toggle C0 (Pin 28) ANDP %>FE,CPORT MOVP %>00,BPORT ORP %>01,CPORT ;Toggle C0 (Pin 28) ANDP %>FE,CPORT MOVP %>01,BPORT ORP %>01,CPORT ;Toggle C0 (Pin 28) ANDP %>FE,CPORT MOVP %>02,BPORT ORP %>01,CPORT ;Toggle C0 (Pin 28) ANDP %>FE,CPORT MOV %>04,A LF705 INV A MOV A,B INV A ORP A,CPORT ORP A,BPORT ORP %>01,CPORT ;Set C0 high ANDP B,CPORT ANDP B,BPORT ANDP %>FE,CPORT ;Set C0 low RLC A JNC LF705 MOVP %>00,CPORT ORP %>01,CPORT ;Toggle C0 (Pin 28) ANDP %>FE,CPORT BR @LF63C ; ; Command >13 ; ; Return First Byte of Buffer to U19 ; LF725 MOV R74,A TRAP 15 ;Write A to U19 BR @LFDC8 ; ; TRAP 14 ; ; Checksum Unit ID + Seed Keys ; and Save Result in B Register ; LF72B MOV %>39,R107 ;Point to End of Seed Key 3 CLR B ;Clear B LF72F LDA *R107 ;Get a Byte ADD R0,B ;Add to Running Sum in B XOR R107,B ;XOR Address of Byte with Running Sum in B DEC R107 ;Decrement Pointer CMP %>19,R107 ;End of Unit ID Yet ? JNZ LF72F ;No, Continue RETS ; ; TRAP 21 ; ; Do PPV Checksum ; LF73D MOV %>41,R107 CLR B LF741 LDA *R107 ADD R0,B XOR R107,B DEC R107 CMP %>3E,R107 JNZ LF741 RETS ; ; TRAP 19 ; ; Copy # Bytes in B from *R107 to *R109 ; LF74F LDA *R107 ;Get Byte from Source STA *R109 ;Save at Destination INC R107 ;Bump Data Address Pointers INC R109 DJNZ B,LF74F ;Copy B Bytes RETS ;Return to Caller ; ; TRAP 17 ; ; XOR # Bytes in B @ *R107 with Bytes ; @ *R109 and Save Result @ *R109 ; LF75A LDA *R107 ;Get Source Byte MOV A,R113 ;Save in R113 LDA *R109 ;Get Destination Byte XOR R113,A ;XOR Bytes STA *R109 ;Save Result @ *R109 INC R107 ;Bump Byte Pointers INC R109 DJNZ B,LF75A ;Do 'B' Bytes RETS ; ; TRAP 18 ; ; Data Encryption Standard Algorithm ; ; Key is Pointed to by R107 (7 Byte Key) ; Data is @R4A-R51 (8 Byte Input Block) ; LF76B MOVP %>20,BPORT ;Set B5 (Pin 1) high LDA *R107 ;Get Byte of Key MOV A,R98 ;Save in R62 (R98) INC R107 LDA *R107 MOV A,R99 INC R107 LDA *R107 MOV A,R100 INC R107 LDA *R107 MOV A,R101 INC R107 LDA *R107 MOV A,R102 INC R107 LDA *R107 MOV A,R103 INC R107 LDA *R107 MOV A,R104 ;Key Saved in R62-R68 (R98-R104) CLR R106 ;Clear R6A CLR A ;Clear A BTJZ %>40,R98,LF79F ;Generate C0 D0 Bit Selection of KEY OR %>40,A ;Start with D0 Byte 1 LF79F BTJZ %>20,R99,LF7A5 OR %>20,A LF7A5 BTJZ %>10,R100,LF7AB OR %>10,A LF7AB BTJZ %>08,R101,LF7B1 OR %>08,A LF7B1 BTJZ %>04,R102,LF7B7 OR %>04,A LF7B7 BTJZ %>02,R103,LF7BD OR %>02,A LF7BD BTJZ %>01,R104,LF7C3 OR %>01,A LF7C3 MOV A,R97 ;Save D0 Byte 1 in R97 CLR A BTJZ %>80,R104,LF7CC ;Do D0 Byte 2 OR %>40,A LF7CC BTJZ %>20,R98,LF7D2 OR %>20,A LF7D2 BTJZ %>10,R99,LF7D8 OR %>10,A LF7D8 BTJZ %>08,R100,LF7DE OR %>08,A LF7DE BTJZ %>04,R101,LF7E4 OR %>04,A LF7E4 BTJZ %>02,R102,LF7EA OR %>02,A LF7EA BTJZ %>01,R103,LF7F0 OR %>01,A LF7F0 MOV A,R96 ;Save D0 Byte 2 in R96 CLR A BTJZ %>80,R103,LF7F9 ;Do D0 Byte 3 OR %>40,A LF7F9 BTJZ %>40,R104,LF7FF OR %>20,A LF7FF BTJZ %>10,R98,LF805 OR %>10,A LF805 BTJZ %>08,R99,LF80B OR %>08,A LF80B BTJZ %>04,R100,LF811 OR %>04,A LF811 BTJZ %>02,R101,LF817 OR %>02,A LF817 BTJZ %>01,R102,LF81D OR %>01,A LF81D MOV A,R95 ;Save D0 Byte 3 in R95 CLR A BTJZ %>80,R102,LF826 ;Do D0 Byte 4 OR %>40,A LF826 BTJZ %>40,R103,LF82C OR %>20,A LF82C BTJZ %>20,R104,LF832 OR %>10,A LF832 BTJZ %>08,R98,LF838 OR %>08,A LF838 BTJZ %>04,R99,LF83E OR %>04,A LF83E BTJZ %>02,R100,LF844 OR %>02,A LF844 BTJZ %>01,R101,LF84A OR %>01,A LF84A MOV A,R94 ;Save D0 Byte 4 in R94 CLR A BTJZ %>01,R98,LF853 ;Do C0 Byte 1 OR %>40,A LF853 BTJZ %>80,R98,LF859 OR %>20,A LF859 BTJZ %>40,R99,LF85F OR %>10,A LF85F BTJZ %>20,R100,LF865 OR %>08,A LF865 BTJZ %>10,R101,LF86B OR %>04,A LF86B BTJZ %>08,R102,LF871 OR %>02,A LF871 BTJZ %>04,R103,LF877 OR %>01,A LF877 MOV A,R93 ;Save C0 Byte 1 in R93 CLR A BTJZ %>02,R104,LF880 ;Do C0 Byte 2 OR %>40,A LF880 BTJZ %>02,R98,LF886 OR %>20,A LF886 BTJZ %>01,R99,LF88C OR %>10,A LF88C BTJZ %>80,R99,LF892 OR %>08,A LF892 BTJZ %>40,R100,LF898 OR %>04,A LF898 BTJZ %>20,R101,LF89E OR %>02,A LF89E BTJZ %>10,R102,LF8A4 OR %>01,A LF8A4 MOV A,R92 ;Save C0 Byte 2 in R92 CLR A BTJZ %>08,R103,LF8AD ;Do C0 Byte 3 OR %>40,A LF8AD BTJZ %>04,R104,LF8B3 OR %>20,A LF8B3 BTJZ %>04,R98,LF8B9 OR %>10,A LF8B9 BTJZ %>02,R99,LF8BF OR %>08,A LF8BF BTJZ %>01,R100,LF8C5 OR %>04,A LF8C5 BTJZ %>80,R100,LF8CB OR %>02,A LF8CB BTJZ %>40,R101,LF8D1 OR %>01,A LF8D1 MOV A,R91 ;Save C0 Byte 3 in R91 CLR A BTJZ %>20,R102,LF8DA ;Do C0 Byte 4 OR %>40,A LF8DA BTJZ %>10,R103,LF8E0 OR %>20,A LF8E0 BTJZ %>08,R104,LF8E6 OR %>10,A LF8E6 BTJZ %>80,R101,LF8EC OR %>08,A LF8EC BTJZ %>40,R102,LF8F2 OR %>04,A LF8F2 BTJZ %>20,R103,LF8F8 OR %>02,A LF8F8 BTJZ %>10,R104,LF8FE OR %>01,A LF8FE MOV A,R90 ;Save C0 Byte 4 in R90 MOV %>08,B ;Prepare to Do Initial Permutation of MOV %>40,R110 ;Input Block per DES (IP) LF905 CLR A ;Clear A BTJZ R110,R74,LF90C OR %>80,A LF90C BTJZ R110,R75,LF912 OR %>40,A LF912 BTJZ R110,R76,LF918 OR %>20,A LF918 BTJZ R110,R77,LF91E OR %>10,A LF91E BTJZ R110,R78,LF924 OR %>08,A LF924 BTJZ R110,R79,LF92A OR %>04,A LF92A BTJZ R110,R80,LF930 OR %>02,A LF930 BTJZ R110,R81,LF936 OR %>01,A LF936 STA @L0051(B) ;Initial Permutation Saved @ R52-5A RRC R110 ;Point to Next Bits to Get RRC R110 DJNZ B,LF905 ;Do all 8 Bytes of Input Block MOV %>10,R113 ;Set Kn Counter for 16 Passes LF942 CLR A BTJZ %>01,R96,LF949 ;Do Permuted Choice 2 (PC-2) of OR %>80,A ;Cn,Dn Group LF949 BTJZ %>10,R95,LF94F OR %>40,A LF94F BTJZ %>08,R96,LF955 OR %>20,A LF955 BTJZ %>10,R94,LF95B OR %>10,A LF95B BTJZ %>40,R97,LF961 OR %>08,A LF961 BTJZ %>04,R97,LF967 OR %>04,A LF967 MOV A,R105 ;R98-R105 Holds 8 6-Bit Kn Blocks CLR A BTJZ %>10,R97,LF970 OR %>80,A LF970 BTJZ %>01,R94,LF976 OR %>40,A LF976 BTJZ %>40,R95,LF97C OR %>20,A LF97C BTJZ %>02,R97,LF982 OR %>10,A LF982 BTJZ %>01,R95,LF988 OR %>08,A LF988 BTJZ %>10,R96,LF98E OR %>04,A LF98E MOV A,R104 CLR A BTJZ %>20,R94,LF997 OR %>80,A LF997 BTJZ %>04,R95,LF99D OR %>40,A LF99D BTJZ %>04,R96,LF9A3 OR %>20,A LF9A3 BTJZ %>08,R97,LF9A9 OR %>10,A LF9A9 BTJZ %>04,R94,LF9AF OR %>08,A LF9AF BTJZ %>40,R96,LF9B5 OR %>04,A LF9B5 MOV A,R103 CLR A BTJZ %>20,R95,LF9BE OR %>80,A LF9BE BTJZ %>01,R97,LF9C4 OR %>40,A LF9C4 BTJZ %>02,R94,LF9CA OR %>20,A LF9CA BTJZ %>02,R95,LF9D0 OR %>10,A LF9D0 BTJZ %>02,R96,LF9D6 OR %>08,A LF9D6 BTJZ %>20,R97,LF9DC OR %>04,A LF9DC MOV A,R102 CLR A BTJZ %>02,R92,LF9E5 OR %>80,A LF9E5 BTJZ %>10,R90,LF9EB OR %>40,A LF9EB BTJZ %>10,R93,LF9F1 OR %>20,A LF9F1 BTJZ %>20,R92,LF9F7 OR %>10,A LF9F7 BTJZ %>04,R91,LF9FD OR %>08,A LF9FD BTJZ %>02,R90,LFA03 OR %>04,A LFA03 MOV A,R101 CLR A BTJZ %>20,R93,LFA0C OR %>80,A LFA0C BTJZ %>04,R92,LFA12 OR %>40,A LFA12 BTJZ %>20,R90,LFA18 OR %>20,A LFA18 BTJZ %>10,R91,LFA1E OR %>10,A LFA1E BTJZ %>04,R93,LFA24 OR %>08,A LFA24 BTJZ %>02,R91,LFA2A OR %>04,A LFA2A MOV A,R100 CLR A BTJZ %>20,R91,LFA33 OR %>80,A LFA33 BTJZ %>01,R91,LFA39 OR %>40,A LFA39 BTJZ %>08,R92,LFA3F OR %>20,A LFA3F BTJZ %>01,R90,LFA45 OR %>10,A LFA45 BTJZ %>02,R93,LFA4B OR %>08,A LFA4B BTJZ %>08,R90,LFA51 OR %>04,A LFA51 MOV A,R99 CLR A BTJZ %>08,R91,LFA5A OR %>80,A LFA5A BTJZ %>01,R92,LFA60 OR %>40,A LFA60 BTJZ %>40,R90,LFA66 OR %>20,A LFA66 BTJZ %>40,R92,LFA6C OR %>10,A LFA6C BTJZ %>40,R93,LFA72 OR %>08,A LFA72 BTJZ %>08,R93,LFA78 OR %>04,A LFA78 MOV A,R98 MOV %>01,R110 CMP %>10,R113 JZ LFA93 CMP %>09,R113 JZ LFA93 CMP %>02,R113 JZ LFA93 CMP %>01,R113 JZ LFA93 INC R110 LFA93 RRC R94 JNC LFA9A OR %>80,R97 LFA9A RRC R97 JNC LFAA1 OR %>80,R96 LFAA1 RRC R96 JNC LFAA8 OR %>80,R95 LFAA8 RRC R95 JNC LFAAF OR %>40,R94 LFAAF RRC R90 JNC LFAB6 OR %>80,R93 LFAB6 RRC R93 JNC LFABD OR %>80,R92 LFABD RRC R92 JNC LFAC4 OR %>80,R91 LFAC4 RRC R91 JNC LFACB OR %>40,R90 LFACB MOV %>7F,A AND R0,R90 AND R0,R91 AND R0,R92 AND R0,R93 AND R0,R94 AND R0,R95 AND R0,R96 AND R0,R97 DJNZ R110,LFA93 MOVD R83,R79 ;L Bits of Input Block to R Bits MOVD R85,R81 ;per DES CLR A BTJZ %>01,R78,LFAF5 OR %>80,A LFAF5 BTJZ %>80,R81,LFAFB OR %>40,A LFAFB BTJZ %>40,R81,LFB01 OR %>20,A LFB01 BTJZ %>20,R81,LFB07 OR %>10,A LFB07 BTJZ %>10,R81,LFB0D OR %>08,A LFB0D BTJZ %>08,R81,LFB13 OR %>04,A LFB13 XOR R0,R105 ;XOR E-Bit Group with Kn Group CLR A BTJZ %>10,R81,LFB1D OR %>80,A LFB1D BTJZ %>08,R81,LFB23 OR %>40,A LFB23 BTJZ %>04,R81,LFB29 OR %>20,A LFB29 BTJZ %>02,R81,LFB2F OR %>10,A LFB2F BTJZ %>01,R81,LFB35 OR %>08,A LFB35 BTJZ %>80,R80,LFB3B OR %>04,A LFB3B XOR R0,R104 CLR A BTJZ %>01,R81,LFB45 OR %>80,A LFB45 BTJZ %>80,R80,LFB4B OR %>40,A LFB4B BTJZ %>40,R80,LFB51 OR %>20,A LFB51 BTJZ %>20,R80,LFB57 OR %>10,A LFB57 BTJZ %>10,R80,LFB5D OR %>08,A LFB5D BTJZ %>08,R80,LFB63 OR %>04,A LFB63 XOR R0,R103 CLR A BTJZ %>10,R80,LFB6D OR %>80,A LFB6D BTJZ %>08,R80,LFB73 OR %>40,A LFB73 BTJZ %>04,R80,LFB79 OR %>20,A LFB79 BTJZ %>02,R80,LFB7F OR %>10,A LFB7F BTJZ %>01,R80,LFB85 OR %>08,A LFB85 BTJZ %>80,R79,LFB8B OR %>04,A LFB8B XOR R0,R102 CLR A BTJZ %>01,R80,LFB95 OR %>80,A LFB95 BTJZ %>80,R79,LFB9B OR %>40,A LFB9B BTJZ %>40,R79,LFBA1 OR %>20,A LFBA1 BTJZ %>20,R79,LFBA7 OR %>10,A LFBA7 BTJZ %>10,R79,LFBAD OR %>08,A LFBAD BTJZ %>08,R79,LFBB3 OR %>04,A LFBB3 XOR R0,R101 CLR A BTJZ %>10,R79,LFBBD OR %>80,A LFBBD BTJZ %>08,R79,LFBC3 OR %>40,A LFBC3 BTJZ %>04,R79,LFBC9 OR %>20,A LFBC9 BTJZ %>02,R79,LFBCF OR %>10,A LFBCF BTJZ %>01,R79,LFBD5 OR %>08,A LFBD5 BTJZ %>80,R78,LFBDB OR %>04,A LFBDB XOR R0,R100 CLR A BTJZ %>01,R79,LFBE5 OR %>80,A LFBE5 BTJZ %>80,R78,LFBEB OR %>40,A LFBEB BTJZ %>40,R78,LFBF1 OR %>20,A LFBF1 BTJZ %>20,R78,LFBF7 OR %>10,A LFBF7 BTJZ %>10,R78,LFBFD OR %>08,A LFBFD BTJZ %>08,R78,LFC03 OR %>04,A LFC03 XOR R0,R99 CLR A BTJZ %>10,R78,LFC0D OR %>80,A LFC0D BTJZ %>08,R78,LFC13 OR %>40,A LFC13 BTJZ %>04,R78,LFC19 OR %>20,A LFC19 BTJZ %>02,R78,LFC1F OR %>10,A LFC1F BTJZ %>01,R78,LFC25 OR %>08,A LFC25 BTJZ %>80,R81,LFC2B OR %>04,A LFC2B XOR R0,R98 ;48 Bit E-Bit Group XOR'ed with Kn MOV R98,B ;Get 1st 6-Bit Result of E-Bit XOR RR B RR B LDA @LF1C8(B) ;Get S8 Value from ROM Table MOV A,R98 ;Save 4-Bit Output Nibble MOV R99,B RR B RR B LDA @LF188(B) ;Get S7 MOV A,R99 MOV R100,B RR B RR B LDA @LF148(B) ;Get S6 MOV A,R100 MOV R101,B RR B RR B LDA @LF108(B) ;Get S5 MOV A,R101 MOV R102,B RR B RR B LDA @LF0C8(B) ;Get S4 MOV A,R102 MOV R103,B RR B RR B LDA @LF088(B) ;Get S3 MOV A,R103 MOV R104,B RR B RR B LDA @LF048(B) ;Get S2 MOV A,R104 MOV R105,B RR B RR B LDA @LF008(B) ;Get S1 MOV A,R105 MOV %>59,R109 CLR A BTJZ %>01,R102,LFC80 OR %>80,A LFC80 BTJZ %>02,R104,LFC86 OR %>40,A LFC86 BTJZ %>01,R101,LFC8C OR %>20,A LFC8C BTJZ %>08,R100,LFC92 OR %>10,A LFC92 BTJZ %>08,R98,LFC98 OR %>08,A LFC98 BTJZ %>01,R103,LFC9E OR %>04,A LFC9E BTJZ %>01,R99,LFCA4 OR %>02,A LFCA4 BTJZ %>08,R101,LFCAA OR %>01,A LFCAA XCHB A LDA *R109 XOR B,A STA *R109 DEC R109 CLR A BTJZ %>08,R105,LFCB9 OR %>80,A LFCB9 BTJZ %>02,R102,LFCBF OR %>40,A LFCBF BTJZ %>02,R100,LFCC5 OR %>20,A LFCC5 BTJZ %>04,R99,LFCCB OR %>10,A LFCCB BTJZ %>08,R104,LFCD1 OR %>08,A LFCD1 BTJZ %>04,R101,LFCD7 OR %>04,A LFCD7 BTJZ %>02,R98,LFCDD OR %>02,A LFCDD BTJZ %>04,R103,LFCE3 OR %>01,A LFCE3 XCHB A LDA *R109 XOR B,A STA *R109 DEC R109 CLR A BTJZ %>04,R105,LFCF2 OR %>80,A LFCF2 BTJZ %>01,R104,LFCF8 OR %>40,A LFCF8 BTJZ %>01,R100,LFCFE OR %>20,A LFCFE BTJZ %>04,R102,LFD04 OR %>10,A LFD04 BTJZ %>01,R98,LFD0A OR %>08,A LFD0A BTJZ %>02,R99,LFD10 OR %>04,A LFD10 BTJZ %>02,R105,LFD16 OR %>02,A LFD16 BTJZ %>08,R103,LFD1C OR %>01,A LFD1C XCHB A LDA *R109 XOR B,A STA *R109 DEC R109 CLR A BTJZ %>02,R101,LFD2B OR %>80,A LFD2B BTJZ %>08,R102,LFD31 OR %>40,A LFD31 BTJZ %>04,R98,LFD37 OR %>20,A LFD37 BTJZ %>04,R104,LFD3D OR %>10,A LFD3D BTJZ %>04,R100,LFD43 OR %>08,A LFD43 BTJZ %>02,R103,LFD49 OR %>04,A LFD49 BTJZ %>01,R105,LFD4F OR %>02,A LFD4F BTJZ %>08,R99,LFD55 OR %>01,A LFD55 XCHB A LDA *R109 XOR B,A STA *R109 CMP %>01,R113 ;See if Done with Algorithm JZ LFD77 ;Jump if Finished all 16 Kn Blocks MOVD R83,R99 MOVD R85,R101 MOVD R87,R83 MOVD R89,R85 MOVD R99,R87 MOVD R101,R89 DEC R113 ;Count a Pass thru DES Routine BR @LF942 LFD77 MOV %>08,B ;Prepare to Do Inverse Initial MOV %>01,R110 ;Permutation of DES Pre-Output Block LFD7C CLR A ;Clear A BTJZ R110,R85,LFD83 OR %>80,A LFD83 BTJZ R110,R89,LFD89 OR %>40,A LFD89 BTJZ R110,R84,LFD8F OR %>20,A LFD8F BTJZ R110,R88,LFD95 OR %>10,A LFD95 BTJZ R110,R83,LFD9B OR %>08,A LFD9B BTJZ R110,R87,LFDA1 OR %>04,A LFDA1 BTJZ R110,R82,LFDA7 OR %>02,A LFDA7 BTJZ R110,R86,LFDAD OR %>01,A LFDAD STA @L0049(B) ;DES Output Block Stored @ R4A-R51 RL R110 ;Point to Next Bit of IP-1 DJNZ B,LFD7C ;Do all 8 Bytes of Pre-Output MOVD %>0000,R99 MOVD %>0000,R101 MOVD %>0000,R103 MOVD %>0000,R105 MOVP %>00,BPORT ;Set B5 (Pin 1) low RETS ;Return to Caller ; ; ; Main Loop Program ; ; Wait for Commands from U19 ; LFDC8 CLR R106 CLR R108 TRAP 20 ;Get Command and Data MOV R114,B ;B = Command MPY %>03,B ;Offset to Jump Table BR @LF233(B) ;Go to Command ; JMP LFDC8 ;? ; ; Error Routine ; LFDD6 MOVP %>00,DDDR ; LFDD9 JMP LFDD9 ; ; ; ORG >FF40 ; ; TRAP 1 - INT1 - RESET* ; LFF40 BTJOP %>80,IOCNT0,LFF47 BR @LF30F LFF47 BR @AA00 ; ; TRAP 2 - Timer 1 (Not used) ; LFF4A BTJOP %>80,IOCNT0,LFF51 BR @LF30F LFF51 BR @AA00 ; ; TRAP 3 - INT3 - RESET* ; LFF54 BTJOP %>80,IOCNT0,LFF5B BR @LF30F LFF5B BR @AA00 ; ; TRAP 0 ; TRAP 4 ; TRAP 22 ; LFF5E BTJZP %>01,APORT,LFF65 BR @LF326 LFF65 MOVP %>40,IOCNT0 ;Set peripheral expansion mode CLR B ;B = >00 MOV %>7F,A ;127 bytes (Can't zero A) CLR B ;B = >00 LDSP ;SP = >7F LFF6D PUSH B ;Zero all RAM DJNZ A,LFF6D MOVP %>80,IOCNT0 ;Set full expansion mode BR @AA00 ; ORG >FFD0 ; ; Trap Vectors ; ; Trap - Function ; DW >7800 ;23 - Not used DW LFF5E ;22 - Not used DW LF73D ;21 - Compute PPV Checksum DW LF26F ;20 - Read command and data from DPORT DW LF74F ;19 - Copy B bytes from *R107 to *R109 DW LF76B ;18 - DES Algorithm DW LF75A ;17 - XOR B bytes from *R107 with *R109 DW LF2FD ;16 - Write B bytes at >62 (R98) to U5 DW LF2CB ;15 - Write A to U19 (BPORT) DW LF72B ;14 - Compute Unit ID + Seed Key Checksum DW >FFFF ;13 - Not used DW >8800 ;12 - Not used DW >FFFF ;11 - Not used DW >FFFF ;10 - Not used DW >FFFF ;9 - Not used DW >FFFF ;8 - Not used DW >FFFF ;7 - Not used DW >FFFF ;6 - Not used DW >9800 ;5 - INT5 - Not used DW LFF5E ;4 - INT4 - Not used DW LFF54 ;3 - INT3 - Not used DW LFF4A ;2 - INT2 - Timer 1 (Not Used) DW LFF40 ;1 - INT1 - Not used DW LFF5E ;0 - Reset - Initial Program Counter ; END