Prev: 7815 Up: Map Next: 7B6B
7B15: Copy a line of text to the ZX Printer
The Hobbit can send its output to a ZX Printer (the PRINT and NOPRINT commands). If the flag at $B5E3 is set, this routine is called by 7694 at the end of every line of text, and it copies the 8 pixel rows of that line from the screen, starting at $5020, to the printer.
The ZX Printer is driven directly through port $FB. For each pixel row, the 32 bytes are sent one bit at a time: for each dot the routine waits for the printer's encoder signal (bit 0 of the port) and then outputs the dot. D controls the motor speed: it starts at 1 (slow), and after the first two rows the value derived from E runs the motor at full speed. After the 8 rows the motor is stopped (OUT ($FB),4). If the printer is not connected (bit 7 of the port reads as 1) the routine gives up straight away.
7B15 LD A,($B5E3) Is the printer switched on?
7B18 AND A Is A zero?
7B19 RET Z Return if it is zero
7B1A PUSH HL Save HL
7B1B PUSH DE Save DE
7B1C PUSH BC Save BC
7B1D LD D,$01 Slow motor; HL = start of the line on the screen
7B1F LD HL,$5020 HL = $5020
7B22 XOR A A = 0
7B23 LD E,A E = A
7B24 OUT ($FB),A Start the motor and wait for the printer to be ready
7B26 IN A,($FB) Read the keyboard/port
7B28 ADD A,A Add A,A
7B29 JP M,$7B67 Bit 7 set: no printer connected
7B2C JR NC,$7B26 If carry clear, go to 7B26
7B2E PUSH HL Save HL
7B2F PUSH DE Save DE
7B30 LD A,D A = D
7B31 CP $02 Compare with 2
7B33 SBC A,A Subtract A,A with carry
7B34 AND E Keep only the bits of E
7B35 RLCA Rotate A left
7B36 AND E Keep only the bits of E
7B37 LD D,A D = A
7B38 LD C,(HL) C = (HL)
7B39 PUSH HL Save HL
7B3A LD B,$08 Send eight dots per screen byte
7B3C LD A,D A = D
7B3D RLC C Shift/rotate C
7B3F RRA Rotate A right through carry
7B40 LD H,A H = A
7B41 IN A,($FB) Wait for the encoder...
7B43 RRA Rotate A right through carry
7B44 JR NC,$7B41 If carry clear, go to 7B41
7B46 LD A,H A = H
7B47 OUT ($FB),A ...and send the dot
7B49 DJNZ $7B3C Loop back until B reaches 0
7B4B POP HL Restore HL
7B4C INC HL Next byte, until all 32 have been done
7B4D LD A,L A = L
7B4E AND $1F Keep only the bits of $1F
7B50 JR NZ,$7B38 If it is not zero, go to 7B38
7B52 IN A,($FB) Read the keyboard/port
7B54 RRA Rotate A right through carry
7B55 JR NC,$7B52 If carry clear, go to 7B52
7B57 LD A,D A = D
7B58 RRCA Rotate A right
7B59 OUT ($FB),A Write to the port (border colour, beeper or printer)
7B5B POP DE Restore DE
7B5C POP HL Restore HL
7B5D INC H Next pixel row
7B5E INC E Increment E
7B5F BIT 3,E Test bit 3 of E
7B61 JR Z,$7B24 If the bit is clear, go to 7B24
7B63 LD A,$04 Stop the motor
7B65 OUT ($FB),A Write to the port (border colour, beeper or printer)
7B67 POP BC Restore BC
7B68 POP DE Restore DE
7B69 POP HL Restore HL
7B6A RET Done
Prev: 7815 Up: Map Next: 7B6B