; TTXVDU.S - VDU driver for Teletext Display ; J.G.Harston, 22 March 1985 ; A simple VDU driver that uses the Teletext screen driver. ; Implements CHR$8,9,10,11,12,13,30 for cursor movement. ; Tokens expanded, all other characters stored in display memory. ; Display is not scrolled, output wraps to top of display. TTXT EQU &F900 ; Base of VDU display driver TTXDRAW EQU TTXT+3 ; Display memory at HL TTXLFT EQU TTXT+6 ; Left margin TTXTOP EQU TTXLFT+1 ; Top margin DFCC EQU TTXT+8 ; Address in display of current position TTXBASE EQU &FC00 ; Address of display memory POTOKEN EQU &0C10 ; Expand token ORG TTXT-256 ; Just below TTXT driver LOAD ENTRY INIT JP PRINIT ; Initialise ; Print out a character ; --------------------- ; On entry, A=character ; On exit, AF/BC/DE/HL corrupted ; PRCHAR CP 32 JR C,PRCTRL ; Jump with control codes CP 35 JR Z,PRHASH ; Store '#' as 95 CP 95 JR Z,PRDASH ; Store '_' as 96 CP 96 JR NZ,PRNEXT ; Store '£' as 35 SUB 121 PRHASH ADD A,59 PRDASH INC A PRNEXT LD D,A ; D=character SUB 165 ; A=token offset SET 1,(IY+1) ; Suppress leading spaces JP NC,POTOKEN ; Expand token PRCHR1 CALL PRPOSN ; Get current position LD (HL),D ; Store character in screen PUSH HL CALL PRLINE ; HL=start of line, DE=start of attrs XOR A LD C,1 ; Redraw 1 line CALL TTXDRAW ; Redraw this line POP HL ; To update the print position we now fall through into CHR$9 ; ----------------------------------------------------------- CTRL9 LD DE,+1 ; Move forward one character ; Update print position ; --------------------- PRMOVE ADD HL,DE ; Move to new position LD (DFCC),HL ; Store new position RET ; Control codes ; ------------- PRCTRL CP 8 CCF ; The Spectrum colour commands fail if Carry set on exit RET NC ; Exit with control codes, with Carry clear LD HL,(DFCC) ; Get current position JR Z,CTRL8 ; CHR$8 - back CP 10 JR C,CTRL9 ; CHR$9 - forwards JR Z,CTRL10 ; CHR$10 - down CP 12 JR C,CTRL11 ; CHR$11 - up JR Z,CTRL12 ; CHR$12 - cls CP 30 JR Z,CTRL30 ; CHR$30 - home CP 13 RET NZ ; CHR$13 - newline ; Cursor movement ; --------------- CTRL13 XOR A LD (TTXLFT),A ; Left margin=0 CALL PRLINE ; HL=start of line ; Continue to move +40 chars to next line CTRL10 LD DE,+40 ; Move forward 40 characters JR PRMOVE CTRL11 LD DE,-40 ; Move back 40 characters JR PRMOVE CTRL8 LD DE,-1 ; Move back one character JR PRMOVE ; Clear screen ; ------------ CTRL12 LD HL,TTXBASE+0 LD DE,TTXBASE+1 LD BC,&3FF LD (HL),&20 ; Clear initial byte LDIR ; Clear display file CTRL30 LD HL,TTXBASE LD (DFCC),HL ; Set print position to (0,0) LD HL,0 ; Clear margins LD (TTXLFT),HL JP TTXT ; Exit by redrawing whole screen ; Find start of line ; ------------------ PRLINE PUSH HL LD DE,&FF00 ; Line -1 LD BC,40 ; 40 chars per line AND A PRLOOP INC D ; Inc line counter SBC HL,BC ; Subtract 40 until off top of display LD A,H CP TTXBASE/256 JR NC,PRLOOP ADD HL,BC ; HL=&xx00 to &xx27, Carry clear LD C,L ; C=0 to 39 POP HL SBC HL,BC ; HL=start of line, Carry clear LD A,D RRA RR E RRA RR E RRA RR E OR &58 LD D,A ; DE=start of attrs RET ; Check if position outside screen ; -------------------------------- PRPOSN LD HL,(DFCC) ; Get current position PRCHK LD A,H ; Get high byte of DFCC CP TTXBASE/256 ; Above top of screen JR C,PRCHKLO CP (TTXBASE/256)+3 RET C ; Above bottom 1/4 of screen RET NZ ; Not bottom 1/4 of screen LD A,L CP &C0 ; 40*24 = &3C0 RET C ; Above end of screen ; LD HL,TTXBASE+&398 ; Force to (0,23) ; RET ; NB: Should scroll PRCHKLO LD HL,TTXBASE ; Force to (0,0) RET ; NB: Should scroll PRINIT LD HL,(23631) ; CHANS LD DE,15 ADD HL,DE ; HL=>'P' output address LD DE,PRCHAR ; PRINT LD (HL),E INC HL LD (HL),D RET DEFW LOAD,ENTRY