0100 ;         JOYSTICK PORT PRINTER HANDLER›0110 ;         EPSON VERSION›0120 ;         -----------------------------›0130 ;         Program by Paul S. Swanson›0140 ;›0150 ; OS equates›0160 ;›0170 HATABS = $031A  ; device handler address table›0180 PACTL = $D302   ; port A control register›0190 PORTA = $D300   ; port A I/O register›0200 TRIG1 = $D011   ; stick trigger 1 register›0210 ;›0220 ; Program equates›0230 ;›0240 ORIGIN = $0680  ; start of new handler›0250 DUMMY = $FFFF   ; dummy address for JMP vector›0260 ;›0270     *=  ORIGIN›0280 ;›0290 ; Start of new handler table›0300 ;›0310 NEWTABLE›0320 ;›0330 ; These are the new handler vectors,›0340 ; presented in the order CIO expects them›0350 ;›0360     .WORD OPEN-1›0370     .WORD CLOSE-1›0380     .WORD GETBYTE-1›0390     .WORD PUTBYTE-1›0400     .WORD STATUS-1›0410     .WORD SPECIAL-1›0420 ;›0430 ; JMP to init (also expected by CIO)›0440 ;›0450 JINIT›0460     JMP EXIT    ; dummy init routine›0470 ;›0480 ; OPEN subroutine›0490 ;›0500 OPEN›0510     LDA #$FF    ; set port A to "output"›0520     BNE PASETUP›0530 ;›0540 ; CLOSE subroutine›0550 ;›0560 CLOSE›0570     LDA #0      ; set port A to "input"›0580 ;›0590 ; Configure port A›0600 ;›0610 PASETUP›0620     LDX #$38›0630     STX PACTL   ; enable data direction control›0640     STA PORTA   ; specify "input" or "output"›0650     LDA #$3C›0660     STA PACTL   ; reset addressing mode›0670     LDA #$FF›0680     STA PORTA   ; clear the port›0690     LDY #1      ; OK status for CIO›0700     RTS ›0710 ;›0720 ; PUT BYTE subroutine›0730 ;›0740 PUTBYTE›0750     LDY TRIG1›0760     BNE PUTBYTE ; wait for busy line›0770     SEI ›0780 ;›0790 ; Process byte to send›0800 ;›0810     CMP #$9B    ; is this an Atari EOL?›0820     BNE PUT1    ; ignore if not›0830     LDA #$0D    ; else convert to printer CR›0840 PUT1›0850     ORA #$80    ; set for active high strobe›0860     STA PORTA   ; and send byte to printer›0870     JSR JINIT   ; waste a few cycles›0880     AND #$7F    ; end the strobe pulse›0890     STA PORTA›0900 ;›0910 ; Wait for busy line›0920 ;›0930     LDY #0›0940 PUT2›0950     LDA TRIG1   ; printer ready?›0960     BNE PUT3    ; yes - continue›0970     DEY ›0980     BNE PUT2    ; else keep waiting›0990     LDY #$8A    ; timeout error code›1000     CLI ›1010     RTS ›1020 PUT3›1030     LDY #1      ; no errors›1040     CLI ›1050     RTS ›1060 ;›1070 ; Unimplemented functions›1080 ;›1090 GETBYTE›1100 STATUS›1110 SPECIAL›1120     LDY #$92    ; error code›1130 EXIT›1140     RTS ›1150 ;›1160 ; Initialization code›1170 ;›1180 PINIT›1190     LDY #0      ; init index›1200 PLOOP›1210     LDA HATABS,Y ; get an ID byte›1220     CMP #'P     ; is this the "P" entry?›1230     BEQ FOUND   ; yes, so change entry›1240     INY         ; otherwise skip 3 bytes›1250     INY ›1260     INY ›1270     BNE PLOOP   ; and keep looking for "P"›1280 ;›1290 ; Change table entry so that›1300 ; it points to our new handler›1310 ;›1320 FOUND›1330     LDA #NEWTABLE&255 ; lsb of table addr›1340     STA HATABS+1,Y›1350     LDA #NEWTABLE/256 ; msb›1360     STA HATABS+2,Y›1370 ;›1380 ; The following JMP vector will be›1390 ; set up when the handler is loaded›1400 ;›1410     JMP DUMMY›1420 ;›1430     .END ›