home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Transactor
/
Transactor_26_1988_Transactor_Publishing.d64
/
printdriver.src
< prev
next >
Wrap
Text File
|
2023-02-26
|
11KB
|
511 lines
.opt nos
;put"@0:printdriver.src
;* * * * * * * * * * * * * * * * *
;* *
;* c-128 centronics printer... *
;* driver for the user port *
;* *
;* written 1-08-87 w.j. brier *
;* *
;* revised *
;* *
;* copyright (c) 1987 *
;* *
;* this program is not to be... *
;* sold. it is permissible... *
;* to copy it but credit must... *
;* be given in the documentation *
;* *
;* see the documentation for... *
;* instructions on using this... *
;* utility with your software. *
;* *
;* * * * * * * * * * * * * * * * *
;
;
;
;* * * * * * * * * * * * * * * * *
;* *
;* <<< program assignments >>> *
;* *
;* * * * * * * * * * * * * * * * *
;
;
;
;operating system functions...
;
clkspd =$d030 ;system clock speed
;
mmu =$ff00 ;configuration
;
lkupla =$ff59 ;search for file
indfet =$ff74 ;indirect fetch
chrout =$ffd2 ;output byte
;
;
;zero page assignments...
;
status =$90 ;i/o status word
;
ldtnd =$98 ;number of open files
;
dfltn =$99 ;current input device
dflto =$9a ;current output device
;
msgflg =$9d ;kernal message flag
;
fnlen =$b7 ;filename length
la =$b8 ;file number
sa =$b9 ;secondary address
fa =$ba ;device number
fnadr =$bb ;filename address
fnbank =$c7 ;bank holding filename
;
datax =$ef ;character buffer
;
;
;kernal i/o tables...
;
latbl =$0362 ;file numbers
fatbl =$036c ;device numbers
satbl =$0376 ;secondary addesses
;
;
;cia #2 registers...
;
d2pra =$dd00 ;data port a
d2prb =$dd01 ;data port b
d2ddra =$dd02 ;data direction a
d2ddrb =$dd03 ;data direction b
;
d2icr =$dd0d ;interrupt control
;
;
*=$1a00
;
;
.pag
;# # # # # # # # # # # # # # # # #
;# #
;# centronics printer driver 128 #
;# #
;# # # # # # # # # # # # # # # # #
;
;
;
;driver jump table
;
jmp open ;open file
;
jmp close ;close file
;
jmp ckout ;open output
;
jmp clrch ;close output
;
jmp bsout ;output character
;
jmp setprt ;set up port
;
;---------------------------------
;
;alternate indirect vectors
;
opena .byt 0,0
;
closea .byt 0,0
;
ckouta .byt 0,0
;
clrcha .byt 0,0
;
bsouta .byt 0,0
;
.byt 0,0 ;reserved
;
;---------------------------------
;
;control flags
;
pdev .byt 0 ;device number
;
lfflg .byt 0 ;linefeed flag
;
;=================================
;
;patch to kernal open routine
;
open lda fa ;current device
cmp #2 ;rs-232
beq ilgdev ;illegal device
;
cmp pdev ;port device number
beq open01
;
jmp (opena) ;not port printer
;
open01 lda la ;current file
jsr lkupla ;search for file
bcc filopn ;file already open
;
ldx ldtnd ;number of open files
cpx #10
beq toomny ;too many files
;
inc ldtnd ;one more file
sta latbl,x ;add file to table
;
lda fa ;device number
sta fatbl,x ;add to table
;
lda sa ;secondary address
cmp #7 ;upper/lower case output
beq open02
;
cmp #5 ;transparent output
beq open02
;
lda #0 ;must be 0, 5 or 7
;
open02 sta satbl,x ;add to table
;
ldy #0
sty status ;clear
sty pmode ;initialize
cmp #7
bne open03 ;uppercase only
;
dec pmode ;indicate u.c./l.c.
;
open03 jsr setprt ;set up user port
;
;
;output command string...
;
ldy #0
;
open04 cpy fnlen ;command string length
beq open05 ;done
;
lda #fnadr ;filename pointer
ldx fnbank ;ram bank
jsr indfet ;fetch character
;
jsr pout ;output character
iny
bne open04 ;loop
;
open05 lda #0
clc ;no error
;
rts
;
;---------------------------------
;
;handle errors
;
toomny lda #1 ;too many files
.byt $2c ;bit op-code
;
filopn lda #2 ;file already open
.byt $2c
;
flnopn lda #3 ;file not open
.byt $2c
;
ilgdev lda #9 ;illegal device number
pha ;save error code
jsr clrch ;default i/o
bit msgflg ;kernal message flag
bvc error3 ;messages disabled
;
ldy #0
;
error1 lda errmsg,y ;'i/o error...'
beq error2 ;end of string
;
jsr bsout ;output message
iny
bne error1 ;loop
;
error2 pla ;fetch error code
pha ;write it back
ora #48 ;change it to ascii
jsr bsout ;output error number
;
error3 pla ;retrieve error code
sec ;indicate error
;
rts
;
;---------------------------------
;
;patch to kernal close routine
;
close php ;save status register
pha ;save file number
ldx ldtnd ;number of files
;
close1 dex ;file table offset
bpl close3
;
close2 pla ;recover file number
plp ;recover status register
jmp (closea) ;not port printer
;
close3 cmp latbl,x ;file number table
bne close1 ;not found
;
lda fatbl,x ;fetch device
cmp pdev
bne close2 ;not port printer
;
pla ;clear stack
pla
dec ldtnd ;one less file
cpx ldtnd ;check file position
beq close5 ;no table shift
;
ldy ldtnd ;new file count
;
close4 lda latbl,y ;shift table
sta latbl,x
lda fatbl,y
sta fatbl,x
lda satbl,y
sta satbl,x
;
close5 lda #0
clc ;no error
;
rts
;
;---------------------------------
;
;patch to kernal chkout routine
;
ckout txa ;swap file number
jsr lkupla ;search for file
bcs flnopn ;file not open
;
cpx pdev
beq ckout1 ;port printer
;
tax ;restore file number
jmp (ckouta) ;not port printer
;
ckout1 sta la ;set file number
stx fa ;set device number
stx dflto ;set output device
sty sa ;set secondary address
jsr setprt ;set up port
;
clc ;no error
lda #0
;
rts
;
;---------------------------------
;
;patch to kernal clrchn routine
;
clrch lda dflto ;output device
cmp pdev ;port printer
beq clrch1
;
jmp (clrcha) ;normal clrchn
;
clrch1 lda #0
ldy #3
sta d2prb ;clear output
sta dfltn ;standard input
sty dflto ;standard output
;
clc ;all ok
;
rts
;
;---------------------------------
;
;patch to kernal chrout routine
;
bsout sta datax ;save character
;
lda dflto ;output device
cmp pdev ;port printer
beq bout01
;
lda datax ;restore character
jmp (bsouta) ;normal bsout
;
bout01 txa ;preserve registers
pha
tya
pha
;
ldx #0 ;mode flag
stx status
;
lda datax ;fetch character
ldy sa ;secondary address
cpy #5
beq bout08 ;transparent
;
cmp #17 ;cursor down
bne bout02
;
dex ;set lower case
bmi bout03
;
bout02 cmp #145 ;cursor up
bne bout04
;
bout03 stx pmode ;set mode &...
jmp bout09 ;exit
;
bout04 cmp #27 ;escape
bne bout05
;
dex
bmi bout08 ;set escape flag
;
bout05 bit escflg
bmi bout08 ;no conversion
;
cmp #15 ;expanded off
bne bout06
;
lda #20 ;ascii expanded off
;
bout06 bit pmode
bpl bout07 ;u.c. only
;
cmp #65 ;petscii l.c.
bcc bout08
;
cmp #91
bcs bout07
;
ora #32 ;change to ascii l.c.
;
bout07 cmp #193 ;petscii u.c.
bcc bout08
;
cmp #219
bcs bout08
;
and #127 ;change to ascii u.c.
;
bout08 stx escflg ;set/clear
jsr pout ;write to port
;
lda sa
cmp #5
beq bout09 ;transparent output
;
bit lfflg
bpl bout09 ;linefeeds not enabled
;
cpx #13
bne bout09 ;not a return
;
lda #10 ;linefeed
jsr pout
;
bout09 pla ;restore registers
tay
pla
tax
lda datax
;
clc ;all ok
;
rts
;
;---------------------------------
;
;output to port printer
;
pout tax ;hold character
tya
pha ;save .y register
lda clkspd
pha ;save clock rate
ldy #0
sty clkspd ;slow speed
sty status ;clear
;
ldy #128
;
pout01 dey
bpl pout01 ;output throttle
;
stx d2prb ;write to port
nop ;wait 6 microseconds
nop
nop
jsr toggl ;toggle strobe
;
lda #%00010000 ;icr mask
;
pout02 bit d2icr ;wait for ack
beq pout02 ;not received
;
pla
sta clkspd ;restore clock
pla
tay ;restore
;
rts
;
;---------------------------------
;
;set up user port for output
;
setprt lda #%01111111 ;mask interrupts
sta d2icr
;
lda d2pra ;port a output
jsr toggl1 ;set strobe high
;
lda d2ddra ;data direction a
ora #%00000100 ;set strobe...
sta d2ddra ;as output
;
ldx #0 ;bring all printer...
stx d2prb ;output lines low
dex ;set up port b...
stx d2ddrb ;as output
;
rts
;
;---------------------------------
;
;toggle strobe line
;
toggl lda d2pra
and #%11111011 ;bring...
sta d2pra ;strobe low &...
;
toggl1 ora #%00000100 ;then...
sta d2pra ;high again
;
rts
;
;---------------------------------
;
;error message text
;
errmsg .byt 13,'i/o error #',0
;
;---------------------------------
;
;storage
;
escflg *=*+1 ;escape mode flag
;
pmode *=*+1 ;output mode
;
;=================================
.end