ca65 V2.17 - Git 582aa41 Main file : vdu.ca65 Current file: vdu.ca65 000000r 1 ; 000000r 1 ; ACORN System 1 Applications: VDU 000000r 1 ; 000000r 1 ; From the Acorn Teletext Board Technical Manual 000000r 1 ; 000000r 1 ; (Chris Oddy January 2022) 000000r 1 ; 000000r 1 ; entry point $0300 000000r 1 ; 000000r 1 .setcpu "6502" 000000r 1 .listbytes unlimited 000000r 1 ; 000000r 1 LF := $0A ; LineFeed 000000r 1 FF := $0C ; FormFeed 000000r 1 CR := $0D ; Carriage Return 000000r 1 SCAP := $20 000000r 1 LINE := $21 000000r 1 WORK := $23 000000r 1 DEL := $7F ; DELete 000000r 1 SCRA := $0400 ; memory addresses for the screen 000000r 1 SCRB := $0500 000000r 1 SCRC := $0600 000000r 1 SCRD := $0700 000000r 1 CRTA := $0800 ; 6845 crt controller 000000r 1 CRTB := $0801 000000r 1 ; 000000r 1 .org $0300 000300 1 ; 000300 1 A4 20 CHATS: ldy SCAP ; CHAracter To Screen 000302 1 C9 20 cmp #$20 000304 1 90 37 bcc CTL ; all control characters 000306 1 C9 7F cmp #DEL 000308 1 F0 27 beq DELETE 00030A 1 20 CD 03 TOSCRN: jsr WRCH 00030D 1 C8 iny 00030E 1 C0 28 cpy #$28 000310 1 90 05 bcc VDUB ; automatic scroll when line filled 000312 1 20 80 03 FILLED: jsr SCROL 000315 1 A0 00 VDUA: ldy #$00 000317 1 20 B5 03 VDUB: jsr CALCN 00031A 1 84 20 sty SCAP 00031C 1 A0 0F ldy #$0F ; rewrite cursor position 00031E 1 8C 00 08 sty CRTA 000321 1 A4 23 ldy WORK 000323 1 8C 01 08 sty CRTB 000326 1 A0 0E ldy #$0E 000328 1 8C 00 08 sty CRTA 00032B 1 A4 25 ldy WORK+2 00032D 1 8C 01 08 sty CRTB 000330 1 60 VDUC: rts 000331 1 000331 1 88 DELETE: dey 000332 1 30 FC bmi VDUC ; refuse to delete before line start 000334 1 A9 20 lda #$20 ; write in a blank 000336 1 20 CD 03 jsr WRCH 000339 1 A9 7F lda #$7F 00033B 1 D0 DA bne VDUB 00033D 1 C9 0D CTL: cmp #CR ; carriage return ? 00033F 1 F0 D4 beq VDUA 000341 1 C9 0A cmp #LF ; linefeed ? 000343 1 F0 06 beq SCR 000345 1 C9 0C cmp #FF ; formfeed ? 000347 1 F0 09 beq CLEARS 000349 1 D0 BF bne TOSCRN 00034B 1 20 80 03 SCR: jsr SCROL ; scroll screen and rewrite cursor 00034E 1 A4 20 ldy SCAP 000350 1 B0 C5 bcs VDUB 000352 1 48 CLEARS: pha ; clear entire buffer 000353 1 A0 00 ldy #$00 000355 1 A9 20 lda #$20 000357 1 99 00 04 CLR: sta SCRA,y 00035A 1 99 00 05 sta SCRB,y 00035D 1 99 00 06 sta SCRC,y 000360 1 99 00 07 sta SCRD,y 000363 1 C8 iny 000364 1 D0 F1 bne CLR 000366 1 84 20 sty SCAP 000368 1 A0 0F ldy #$0F 00036A 1 8C 00 08 SETCRT: sty CRTA ; set up all the crt parameters 00036D 1 B9 DA 03 lda CRTTAB,y 000370 1 8D 01 08 sta CRTB 000373 1 88 dey 000374 1 10 F4 bpl SETCRT 000376 1 A9 C0 lda #$C0 000378 1 85 21 sta LINE 00037A 1 A9 07 lda #$07 00037C 1 85 22 sta LINE+1 00037E 1 68 pla 00037F 1 60 rts 000380 1 ; 000380 1 08 SCROL: php ; scroll subroutine 000381 1 48 pha 000382 1 D8 cld 000383 1 A0 28 ldy #$28 000385 1 20 B5 03 jsr CALCN 000388 1 A5 23 lda WORK 00038A 1 85 21 sta LINE 00038C 1 A5 25 lda WORK+2 00038E 1 85 22 sta LINE+1 000390 1 A0 0D ldy #$0D 000392 1 8C 00 08 sty CRTA 000395 1 A5 21 lda LINE 000397 1 38 SEC 000398 1 E9 C0 SBC #$C0 00039A 1 8D 01 08 sta CRTB 00039D 1 88 dey 00039E 1 8C 00 08 sty CRTA 0003A1 1 A5 25 lda WORK+2 0003A3 1 E9 03 SBC #$03 0003A5 1 8D 01 08 sta CRTB 0003A8 1 A0 27 ldy #$27 0003AA 1 A9 20 lda #$20 0003AC 1 20 CD 03 CLEARL: jsr WRCH 0003AF 1 88 dey 0003B0 1 10 FA bpl CLEARL 0003B2 1 68 pla 0003B3 1 28 plp 0003B4 1 60 rts 0003B5 1 0003B5 1 08 CALCN: php ; do calculation to make sure that the 0003B6 1 48 pha ; processor and crt controlier agree on 0003B7 1 D8 cld ; position of screen 0003B8 1 18 clc 0003B9 1 98 tya 0003BA 1 65 21 adc LINE 0003BC 1 85 23 sta WORK 0003BE 1 A5 22 lda LINE+1 0003C0 1 69 00 adc #$00 0003C2 1 85 25 sta WORK+2 0003C4 1 29 07 and #$07 0003C6 1 09 04 ora #$04 0003C8 1 85 24 sta WORK+1 0003CA 1 68 pla 0003CB 1 28 plp 0003CC 1 60 rts 0003CD 1 0003CD 1 20 B5 03 WRCH: jsr CALCN 0003D0 1 84 25 sty WORK+2 0003D2 1 A0 00 ldy #$00 0003D4 1 99 23 00 sta WORK,y 0003D7 1 A4 25 ldy WORK+2 0003D9 1 60 rts 0003DA 1 ; 0003DA 1 3F CRTTAB: .byte $3F ; total number of characters per line 0003DB 1 28 .byte $28 ; 40 characters displayed 0003DC 1 33 .byte $33 ; position of horizontal sync 0003DD 1 05 .byte $05 ; width in uS of horizontal sync pulse 0003DE 1 1E .byte $1E ; total number of character rows 0003DF 1 02 .byte $02 ; additional no. of lines for 312 total 0003E0 1 19 .byte $19 ; 25 displayed character rows 0003E1 1 18 .byte $18 ; position of vertical sync pulse 0003E2 1 00 .byte $00 ; set non-interlace mode 0003E3 1 09 .byte $09 ; set 10 lines per character row 0003E4 1 68 .byte $68 ; slow blink cursor from line 9 0003E5 1 09 .byte $09 ; to line 10 0003E6 1 04 .byte $04 ; high address of VDU ram 0003E7 1 00 .byte $00 ; low address of VDU ram 0003E8 1 07 .byte $07 ; high address of initial cursor position 0003E9 1 C0 .byte $C0 ; low address of intial cursor position 0003EA 1 ; 0003EA 1