Classic Computer Magazine Archive PROGRAM LISTING: 83-10/PRINTER.ASM


0200 ; *********************************
0210 ; *********************************
0220 ; *** SOFTWARE PRINTER INTERFACE **
0230 ; *** ALAN MACY     MAY 21, 1983 **
0240 ; ***                            **
0250 ; *** THESE ROUTINES ALLOW A     **
0260 ; *** DIRECT CONNECTION TO A     **
0270 ; *** PRINTER VIA JOYSTICK PORTS **
0280 ; *** 1, 2, AND 3.               **
0290 ; *********************************
0300 ; *********************************
0310 ;
0320  *=$600          ; PAGE 6 FREE AREA
0330  .OPT NOEJECT
0340  .TITLE "PRINTER INTERFACE  MACY  MAY 21, 1983"
0350 ;
0360 ;  EQUATE TABLE **************************
0370 ;
0380 PORTA=$D300      ;FOR PORTS 1&2
0390 PORTB=$D301      ;FOR PORTS 3&4
0400 PACTL=$D302      ;CONTROL, PORTA
0410 PBCTL=$D303      ;CONTROL, PORTB
0420 ATCR=155         ;ATASCII CARRIAGE RETURN
0430 CR=13            ;ASCII CARRIAGE RETURN
0440 LF=10            ;LINE FEED
0450 FF=12            ;FORM FEED
0460 LPPG=56          ;LINES/PAGE
0470 ;
0480 ; DEVICE HANDLER VECTOR TABLE ************
0490 ;
0500  .WORD POPEN-1   ;OPEN PRINTER
0510  .WORD PCLOS-1   ;CLOSE PRINTER
0520  .WORD NOGOT-1   ;GETBYTE
0530  .WORD CHOUT-1   ;PUTBYTE
0540  .WORD NOGOT-1   ;GETSTAT
0550  .WORD NOGOT-1
0560 ;
0570 ; SINGLE CHARACTER OUTPUT ROUTINE ********
0580 ; CHARACTER IN ACCUMULATOR
0590 ;
0600 CHOUT STA ASAVE
0610  CMP #ATCR       ;ATASCII RETURN
0620  BNE SEND        ;CHAR=ATAS RETURN?
0630  LDA #CR         ;YES, REPLACE WIT
0640 ;                A "REAL ASCII CR"
0650  JSR CHOUT       ;USE RECURSION TO
0660 ;                OUTPUT CR THEN LF
0670  LDA #LF         ;A LINEFEED
0680  STA ASAVE
0690  INC LINNUM      ;INCREMENT PAGE LINE NUMBER
0700  LDA #LPPG       ;COMPARE WITH
0710  CMP LINNUM      ;LINES/PAGE
0720  BPL SEND        ;IF NOT TO END OF PAGE
0730 ;                AT PAGE END
0740  LDA #FF         ;A FORM FEED
0750  STA ASAVE
0760  LDA #00         ;RESET LINE NUMBER
0770  STA LINNUM
0780 SEND LDA # 4     ; CHK BIT 2 TO SEE IF BUSY
0790  AND PORTB
0800  BNE SEND        ;PRINTER BUSY?
0810  LDA ASAVE       ;NO, GET THE CHAR
0820  STA PORTA       ;STORE CHAR IN PORT
0830  LDA #$FE        ;11111110
0840  AND PORTB
0850  STA PORTB       ;STROBE LOW
0860 ;                 MUST HOLD STROBE LOW
0870 ;                 FOR A BIT TO BE SURE
0880 ;                 PRINTER GOT THE MESSAGE
0890  LDX #$10        ;DELAY  COUNTER
0900 XLOOP DEX        ;COUNT DOWN
0910  BPL XLOOP       ;CONTINUE UNTIL <=0
0920  LDA #$01        ; 00000001
0930  ORA PORTB
0940  STA PORTB       ;STROBE HIGH AGAIN
0950 ;
0960 ; THE STROBE HAS NOW BEEN PULSED
0970 ; TELLING THE PRINTER THAT A CHAR
0980 ; MAY BE TAKEN
0990  LDY #01         ;SET STATUS=ALL OK
1000  RTS
1010 ;
1020 ; ROUTINE TO OPEN PRINTER ****************
1030 ; INVOLVES RECONFIGURING PORTS
1040 ;
1050 POPEN LDA #$FB   ;FIRST PORTA
1060  AND PACTL       ;CLEAR BIT 2
1070  STA PACTL
1080  LDA #$FF        ;SET FOR ALL OUTPUT
1090  STA PORTA
1100  LDA #$04        ;SET BIT 2
1110  ORA PACTL
1120  STA PACTL
1130  LDA #$FB        ;NOW DO PORTB
1140  AND PBCTL
1150  STA PBCTL
1160  LDA #$09        ;BITS 0 AND 3 OUT
1170  STA PORTB       ;BITS 1&2 INPUT
1180  LDA #$04
1190  ORA PBCTL
1200  STA PBCTL
1210  LDA #$09
1220  STA PORTB       ;MAKE SURE THAT
1230 ;                INPUT PRIME AND STROBE
1240 ;                ARE HIGH TO START WITH
1250  LDA #00         ;SET LINE NUMBER
1260  STA LINNUM      ;TO ZERO
1270  LDY #01         ;STATUS=ALL OK
1280  RTS
1290 ;
1300 PCLOS LDY #01    ;COME HERE FOR CLOSE
1310 ;                SET STATUS=ALL OK
1320  RTS
1330 ;
1340 NOGOT RTS        ;COME HERE WHEN DON'T HAVE THE ROUTINE
1350 ;
1360  LDA #LF         ;USE THIS FOR TESTING
1370  JSR CHOUT       ;IT OUPUTS A LF
1380  BRK
1390 ;
1400 ; STORAGE LOCATIONS **********************
1410 ;
1420 ASAVE .BYTE 0
1430 LINNUM .BYTE 0

Back to previous page