Prev: 16D1 Up: Map Next: 18ED
185A: check_page: Telesoftware page checksum.
Used by the routine at telesoftware_main.
check_page 185A LD DE,(page_receive_buffer_pointer) Set HL to page_receive_buffer_pointer + 40 (row 1, column 0).
185E LD HL,$0028
1861 ADD HL,DE
1862 LD BC,$0398 Set BC to 920 as loop counter.
check_parity_loop 1865 LD A,(HL) Load next byte from receive buffer.
1866 OR A If even parity jump to return_error_1.
1867 JP PE,return_error_1
186A INC HL Loop through 920 characters (rows 1 to 23).
186B DEC BC
186C LD A,C
186D OR B
186E JR NZ,check_parity_loop
1870 LD HL,$0028 Set HL to page_receive_buffer_pointer + 40 (row 1, column 0).
1873 ADD HL,DE
1874 LD BC,$0394 Set BC to 916 as loop counter and clear D (zero checksum).
1877 LD D,$00
checksum_loop 1879 LD A,(HL) Load next byte from receive buffer.
187A XOR D XOR with previous checksum.
187B LD D,A
187C INC HL Loop through 916 characters (rows 1 to 23 minus last four characters).
187D DEC BC
187E LD A,C
187F OR B
1880 JR NZ,checksum_loop
1882 PUSH DE Preserve checksum.
1883 EX DE,HL Swap address of next byte into DE.
1884 LD HL,checksum_nibbles Set HL to address of checksum_nibbles.
1887 CALL load_nibbles Call load_nibbles.
188A POP DE Restore checksum.
188B LD A,(checksum_nibbles) Load low byte of checksum_nibbles.
188E XOR D XOR with checksum and clear bit 7.
188F AND $7F
1891 JP NZ,return_error_1 If any bits set jump to return_error_1.
1894 LD A,($5B82) If high byte of checksum_nibbles is not zero jump to return_error_2.
1897 OR A
1898 JP NZ,return_error_2
189B LD A,(blocks_remaining) If blocks_remaining is not zero jump to check_page_0 else this is first block received.
189E OR A
189F JP NZ,check_page_0
18A2 LD DE,(page_receive_buffer_pointer) Set HL to page_receive_buffer_pointer + 925 (row 23, column 5) (number of blocks).
18A6 LD HL,$039D
18A9 ADD HL,DE
18AA LD A,(HL) Copy low 6 bits to number_of_blocks and blocks_remaining.
18AB AND $3F
18AD LD (number_of_blocks),A
18B0 LD (blocks_remaining),A
18B3 LD HL,$03A4 Set HL to page_receive_buffer_pointer + 932 (row 23, column 12).
18B6 ADD HL,DE
18B7 LD DE,footer_buffer Copy 24 characters to footer_buffer.
18BA LD BC,$0018
18BD LDIR
18BF JP return_ok Skip forward to return success.
check_page_0 18C2 LD DE,(page_receive_buffer_pointer) Set HL to page_receive_buffer_pointer + 925 (row 23, column 5) (number of blocks).
18C6 LD HL,$039D
18C9 ADD HL,DE
18CA LD A,(number_of_blocks) Load number_of_blocks.
18CD XOR (HL) Compare with byte at address in HL.
18CE AND $3F
18D0 JP NZ,return_error_2 If values don't match jump to return_error_2.
18D3 LD HL,$03A4 Set HL to page_receive_buffer_pointer + 932 (row 23, column 12).
18D6 ADD HL,DE
18D7 LD DE,footer_buffer Load address of footer_buffer into DE.
18DA LD B,$18 Set B to 24 as loop counter.
compare_bytes_loop 18DC LD A,(DE) Load next byte from footer_buffer into A.
18DD CP (HL) Compare with byte in page receive buffer.
18DE JP NZ,return_error_2 If bytes don't match jump to return_error_2.
18E1 INC HL Loop through 24 bytes.
18E2 INC DE
18E3 DJNZ compare_bytes_loop
return_ok 18E5 XOR A Return $00.
18E6 RET
return_error_1 18E7 LD A,$01 Return error $01.
18E9 RET
return_error_2 18EA LD A,$02 Return error $02.
18EC RET
Prev: 16D1 Up: Map Next: 18ED