Prev: 1394 Up: Map Next: 1481
13B4: init_hamming_table: Create 256 byte look up table of Hamming 8/4 decoded bytes.
Used by the routine at init_variables.
init_hamming_table 13B4 XOR A Set hamming_table_counter to 0, and load hamming_decode_table_pointer into HL.
13B5 LD (hamming_table_counter),A
13B8 LD HL,(hamming_decode_table_pointer)
hamming_table_loop 13BB PUSH HL Preserve HL and AF.
13BC PUSH AF
13BD XOR A Clear P1_flag, P2_flag, P3_flag, and P4_flag.
13BE LD (P1_flag),A
13C1 LD (P2_flag),A
13C4 LD (P3_flag),A
13C7 LD (P4_flag),A
13CA LD A,(hamming_table_counter) If bits 0, 1, 5, and 7 of hamming_table_counter have odd parity, set P1_flag.
13CD AND $A3
13CF JP PE,skip_P1
13D2 LD A,$01
13D4 LD (P1_flag),A
skip_P1 13D7 LD A,(hamming_table_counter) If bits 1, 2, 3, and 7 of hamming_table_counter have odd parity, set P2_flag.
13DA AND $8E
13DC JP PE,skip_P2
13DF LD A,$01
13E1 LD (P2_flag),A
skip_P2 13E4 LD A,(hamming_table_counter) If bits 1, 3, 4, and 5 of hamming_table_counter have odd parity, set P3_flag.
13E7 AND $3A
13E9 JP PE,skip_P3
13EC LD A,$01
13EE LD (P3_flag),A
skip_P3 13F1 LD A,(hamming_table_counter) If all bits of hamming_table_counter have odd parity, set P4_flag.
13F4 AND A
13F5 JP PE,skip_P4
13F8 LD A,$01
13FA LD (P4_flag),A
skip_P4 13FD LD A,(P1_flag) If P1_flag, P2_flag, P3_flag, and P4_flag are all set, call store_hamming_nibble, then jump to next_hamming_byte.
1400 LD B,A
1401 LD A,(P2_flag)
1404 LD C,A
1405 LD A,(P3_flag)
1408 LD D,A
1409 LD A,(P4_flag)
140C ADD A,B
140D ADD A,C
140E ADD A,D
140F CP $04
1411 JR NZ,hamming_errors
1413 CALL store_hamming_nibble
1416 JP next_hamming_byte
hamming_errors 1419 LD A,(P1_flag) Else if only P4_flag is clear, call store_hamming_nibble, then jump to next_hamming_byte.
141C LD B,A
141D LD A,(P2_flag)
1420 LD C,A
1421 LD A,(P3_flag)
1424 ADD A,C
1425 ADD A,B
1426 CP $03
1428 JR NZ,P4_error
142A LD A,(P4_flag)
142D AND A
142E JR NZ,P4_error
1430 CALL store_hamming_nibble
1433 JP next_hamming_byte
P4_error 1436 LD A,(P1_flag) Else if any of P1_flag, P2_flag, P3_flag are clear and P4_flag is clear, call store_hamming_error, then jump to next_hamming_byte.
1439 LD B,A
143A LD A,(P2_flag)
143D LD C,A
143E LD A,(P3_flag)
1441 ADD A,B
1442 ADD A,C
1443 CP $03
1445 JR Z,P1_error
1447 LD A,(P4_flag)
144A AND A
144B JR Z,P1_error
144D CALL store_hamming_error
1450 JP next_hamming_byte
P1_error 1453 LD A,(P1_flag) Else if P1_flag is set then set bit 0 of B.
1456 LD B,$00
1458 AND A
1459 JR Z,P2_error
145B INC B
P2_error 145C LD A,(P2_flag) If P2_flag is set then set bit 1 of B.
145F AND A
1460 JR Z,P3_error
1462 SET 1,B
P3_error 1464 LD A,(P3_flag) If P3_flag is set then set bit 2 of B.
1467 AND A
1468 JR Z,correct_errors
146A SET 2,B
correct_errors 146C LD C,B Copy B to C and call store_hamming_nibble.
146D PUSH BC
146E CALL store_hamming_nibble
1471 POP BC
1472 CALL correct_and_store_nibble Call correct_and_store_nibble to correct a single bit error.
next_hamming_byte 1475 POP AF Restore AF and HL.
1476 POP HL Increment HL.
1477 INC HL
1478 INC A Increment A and store in hamming_table_counter.
1479 LD (hamming_table_counter),A
147C AND A Loop back to hamming_table_loop for 256 iterations then return.
147D JP NZ,hamming_table_loop
1480 RET
Prev: 1394 Up: Map Next: 1481