home *** CD-ROM | disk | FTP | other *** search
/ Transactor / Transactor_26_1988_Transactor_Publishing.d64 / printdriver.src < prev    next >
Text File  |  2023-02-26  |  11KB  |  511 lines

  1. .opt nos
  2. ;put"@0:printdriver.src
  3. ;* * * * * * * * * * * * * * * * *
  4. ;*                               *
  5. ;* c-128 centronics printer...   *
  6. ;* driver for the user port      *
  7. ;*                               *
  8. ;* written  1-08-87  w.j. brier  *
  9. ;*                               *
  10. ;* revised                       *
  11. ;*                               *
  12. ;* copyright (c) 1987            *
  13. ;*                               *
  14. ;* this program is not to be...  *
  15. ;* sold.  it is permissible...   *
  16. ;* to copy it but credit must... *
  17. ;* be given in the documentation *
  18. ;*                               *
  19. ;* see the documentation for...  *
  20. ;* instructions on using this... *
  21. ;* utility with your software.   *
  22. ;*                               *
  23. ;* * * * * * * * * * * * * * * * *
  24.               ;
  25.               ;
  26.               ;
  27. ;* * * * * * * * * * * * * * * * *
  28. ;*                               *
  29. ;*  <<< program assignments >>>  *
  30. ;*                               *
  31. ;* * * * * * * * * * * * * * * * *
  32.               ;
  33.               ;
  34.               ;
  35. ;operating system functions...
  36.               ;
  37. clkspd =$d030 ;system clock speed
  38.               ;
  39. mmu    =$ff00 ;configuration
  40.               ;
  41. lkupla =$ff59 ;search for file
  42. indfet =$ff74 ;indirect fetch
  43. chrout =$ffd2 ;output byte
  44.               ;
  45.               ;
  46. ;zero page assignments...
  47.               ;
  48. status =$90   ;i/o status word
  49.               ;
  50. ldtnd  =$98   ;number of open files
  51.               ;
  52. dfltn  =$99   ;current input device
  53. dflto  =$9a   ;current output device
  54.               ;
  55. msgflg =$9d   ;kernal message flag
  56.               ;
  57. fnlen  =$b7   ;filename length
  58. la     =$b8   ;file number
  59. sa     =$b9   ;secondary address
  60. fa     =$ba   ;device number
  61. fnadr  =$bb   ;filename address
  62. fnbank =$c7   ;bank holding filename
  63.               ;
  64. datax  =$ef   ;character buffer
  65.               ;
  66.               ;
  67. ;kernal i/o tables...
  68.               ;
  69. latbl  =$0362 ;file numbers
  70. fatbl  =$036c ;device numbers
  71. satbl  =$0376 ;secondary addesses
  72.               ;
  73.               ;
  74. ;cia #2 registers...
  75.               ;
  76. d2pra  =$dd00 ;data port a
  77. d2prb  =$dd01 ;data port b
  78. d2ddra =$dd02 ;data direction a
  79. d2ddrb =$dd03 ;data direction b
  80.               ;
  81. d2icr  =$dd0d ;interrupt control
  82.               ;
  83.               ;
  84.       *=$1a00
  85.               ;
  86.               ;
  87.               .pag
  88. ;# # # # # # # # # # # # # # # # #
  89. ;#                               #
  90. ;# centronics printer driver 128 #
  91. ;#                               #
  92. ;# # # # # # # # # # # # # # # # #
  93.        ;
  94.        ;
  95.        ;
  96. ;driver jump table
  97.        ;
  98.        jmp open  ;open file
  99.        ;
  100.        jmp close ;close file
  101.        ;
  102.        jmp ckout ;open output
  103.        ;
  104.        jmp clrch ;close output
  105.        ;
  106.        jmp bsout ;output character
  107.        ;
  108.        jmp setprt ;set up port
  109.        ;
  110. ;---------------------------------
  111.        ;
  112. ;alternate indirect vectors
  113.        ;
  114. opena  .byt 0,0
  115.        ;
  116. closea .byt 0,0
  117.        ;
  118. ckouta .byt 0,0
  119.        ;
  120. clrcha .byt 0,0
  121.        ;
  122. bsouta .byt 0,0
  123.        ;
  124.        .byt 0,0 ;reserved
  125.        ;
  126. ;---------------------------------
  127.        ;
  128. ;control flags
  129.        ;
  130. pdev   .byt 0 ;device number
  131.        ;
  132. lfflg  .byt 0 ;linefeed flag
  133.        ;
  134. ;=================================
  135.        ;
  136. ;patch to kernal open routine
  137.        ;
  138. open   lda fa ;current device
  139.        cmp #2 ;rs-232
  140.        beq ilgdev ;illegal device
  141.        ;
  142.        cmp pdev ;port device number
  143.        beq open01
  144.        ;
  145.        jmp (opena) ;not port printer
  146.        ;
  147. open01 lda la ;current file
  148.        jsr lkupla ;search for file
  149.        bcc filopn ;file already open
  150.        ;
  151.        ldx ldtnd ;number of open files
  152.        cpx #10
  153.        beq toomny ;too many files
  154.        ;
  155.        inc ldtnd ;one more file
  156.        sta latbl,x ;add file to table
  157.        ;
  158.        lda fa ;device number
  159.        sta fatbl,x ;add to table
  160.        ;
  161.        lda sa ;secondary address
  162.        cmp #7 ;upper/lower case output
  163.        beq open02
  164.        ;
  165.        cmp #5 ;transparent output
  166.        beq open02
  167.        ;
  168.        lda #0 ;must be 0, 5 or 7
  169.        ;
  170. open02 sta satbl,x ;add to table
  171.        ;
  172.        ldy #0
  173.        sty status ;clear
  174.        sty pmode ;initialize
  175.        cmp #7
  176.        bne open03 ;uppercase only
  177.        ;
  178.        dec pmode ;indicate u.c./l.c.
  179.        ;
  180. open03 jsr setprt ;set up user port
  181.        ;
  182.        ;
  183. ;output command string...
  184.        ;
  185.        ldy #0
  186.        ;
  187. open04 cpy fnlen ;command string length
  188.        beq open05 ;done
  189.        ;
  190.        lda #fnadr ;filename pointer
  191.        ldx fnbank ;ram bank
  192.        jsr indfet ;fetch character
  193.        ;
  194.        jsr pout ;output character
  195.        iny
  196.        bne open04 ;loop
  197.        ;
  198. open05 lda #0
  199.        clc ;no error
  200.        ;
  201.        rts
  202.        ;
  203. ;---------------------------------
  204.        ;
  205. ;handle errors
  206.        ;
  207. toomny lda #1 ;too many files
  208.        .byt $2c ;bit op-code
  209.        ;
  210. filopn lda #2 ;file already open
  211.        .byt $2c
  212.        ;
  213. flnopn lda #3 ;file not open
  214.        .byt $2c
  215.        ;
  216. ilgdev lda #9 ;illegal device number
  217.        pha ;save error code
  218.        jsr clrch ;default i/o
  219.        bit msgflg ;kernal message flag
  220.        bvc error3 ;messages disabled
  221.        ;
  222.        ldy #0
  223.        ;
  224. error1 lda errmsg,y ;'i/o error...'
  225.        beq error2 ;end of string
  226.        ;
  227.        jsr bsout ;output message
  228.        iny
  229.        bne error1 ;loop
  230.        ;
  231. error2 pla ;fetch error code
  232.        pha ;write it back
  233.        ora #48 ;change it to ascii
  234.        jsr bsout ;output error number
  235.        ;
  236. error3 pla ;retrieve error code
  237.        sec ;indicate error
  238.        ;
  239.        rts
  240.        ;
  241. ;---------------------------------
  242.        ;
  243. ;patch to kernal close routine
  244.        ;
  245. close  php ;save status register
  246.        pha ;save file number
  247.        ldx ldtnd ;number of files
  248.        ;
  249. close1 dex ;file table offset
  250.        bpl close3
  251.        ;
  252. close2 pla ;recover file number
  253.        plp ;recover status register
  254.        jmp (closea) ;not port printer
  255.        ;
  256. close3 cmp latbl,x ;file number table
  257.        bne close1 ;not found
  258.        ;
  259.        lda fatbl,x ;fetch device
  260.        cmp pdev
  261.        bne close2 ;not port printer
  262.        ;
  263.        pla ;clear stack
  264.        pla
  265.        dec ldtnd ;one less file
  266.        cpx ldtnd ;check file position
  267.        beq close5 ;no table shift
  268.        ;
  269.        ldy ldtnd ;new file count
  270.        ;
  271. close4 lda latbl,y ;shift table
  272.        sta latbl,x
  273.        lda fatbl,y
  274.        sta fatbl,x
  275.        lda satbl,y
  276.        sta satbl,x
  277.        ;
  278. close5 lda #0
  279.        clc ;no error
  280.        ;
  281.        rts
  282.        ;
  283. ;---------------------------------
  284.        ;
  285. ;patch to kernal chkout routine
  286.        ;
  287. ckout  txa ;swap file number
  288.        jsr lkupla ;search for file
  289.        bcs flnopn ;file not open
  290.        ;
  291.        cpx pdev
  292.        beq ckout1 ;port printer
  293.        ;
  294.        tax ;restore file number
  295.        jmp (ckouta) ;not port printer
  296.        ;
  297. ckout1 sta la ;set file number
  298.        stx fa ;set device number
  299.        stx dflto ;set output device
  300.        sty sa ;set secondary address
  301.        jsr setprt ;set up port
  302.        ;
  303.        clc ;no error
  304.        lda #0
  305.        ;
  306.        rts
  307.        ;
  308. ;---------------------------------
  309.        ;
  310. ;patch to kernal clrchn routine
  311.        ;
  312. clrch  lda dflto ;output device
  313.        cmp pdev ;port printer
  314.        beq clrch1
  315.        ;
  316.        jmp (clrcha) ;normal clrchn
  317.        ;
  318. clrch1 lda #0
  319.        ldy #3
  320.        sta d2prb ;clear output
  321.        sta dfltn ;standard input
  322.        sty dflto ;standard output
  323.        ;
  324.        clc ;all ok
  325.        ;
  326.        rts
  327.        ;
  328. ;---------------------------------
  329.        ;
  330. ;patch to kernal chrout routine
  331.        ;
  332. bsout  sta datax ;save character
  333.        ;
  334.        lda dflto ;output device
  335.        cmp pdev ;port printer
  336.        beq bout01
  337.        ;
  338.        lda datax ;restore character
  339.        jmp (bsouta) ;normal bsout
  340.        ;
  341. bout01 txa ;preserve registers
  342.        pha
  343.        tya
  344.        pha
  345.        ;
  346.        ldx #0 ;mode flag
  347.        stx status
  348.        ;
  349.        lda datax ;fetch character
  350.        ldy sa ;secondary address
  351.        cpy #5
  352.        beq bout08 ;transparent
  353.        ;
  354.        cmp #17 ;cursor down
  355.        bne bout02
  356.        ;
  357.        dex ;set lower case
  358.        bmi bout03
  359.        ;
  360. bout02 cmp #145 ;cursor up
  361.        bne bout04
  362.        ;
  363. bout03 stx pmode ;set mode &...
  364.        jmp bout09 ;exit
  365.        ;
  366. bout04 cmp #27 ;escape
  367.        bne bout05
  368.        ;
  369.        dex
  370.        bmi bout08 ;set escape flag
  371.        ;
  372. bout05 bit escflg
  373.        bmi bout08 ;no conversion
  374.        ;
  375.        cmp #15 ;expanded off
  376.        bne bout06
  377.        ;
  378.        lda #20 ;ascii expanded off
  379.        ;
  380. bout06 bit pmode
  381.        bpl bout07 ;u.c. only
  382.        ;
  383.        cmp #65 ;petscii l.c.
  384.        bcc bout08
  385.        ;
  386.        cmp #91
  387.        bcs bout07
  388.        ;
  389.        ora #32 ;change to ascii l.c.
  390.        ;
  391. bout07 cmp #193 ;petscii u.c.
  392.        bcc bout08
  393.        ;
  394.        cmp #219
  395.        bcs bout08
  396.        ;
  397.        and #127 ;change to ascii u.c.
  398.        ;
  399. bout08 stx escflg ;set/clear
  400.        jsr pout ;write to port
  401.        ;
  402.        lda sa
  403.        cmp #5
  404.        beq bout09 ;transparent output
  405.        ;
  406.        bit lfflg
  407.        bpl bout09 ;linefeeds not enabled
  408.        ;
  409.        cpx #13
  410.        bne bout09 ;not a return
  411.        ;
  412.        lda #10 ;linefeed
  413.        jsr pout
  414.        ;
  415. bout09 pla ;restore registers
  416.        tay
  417.        pla
  418.        tax
  419.        lda datax
  420.        ;
  421.        clc ;all ok
  422.        ;
  423.        rts
  424.        ;
  425. ;---------------------------------
  426.        ;
  427. ;output to port printer
  428.        ;
  429. pout   tax ;hold character
  430.        tya
  431.        pha ;save .y register
  432.        lda clkspd
  433.        pha ;save clock rate
  434.        ldy #0
  435.        sty clkspd ;slow speed
  436.        sty status ;clear
  437.        ;
  438.        ldy #128
  439.        ;
  440. pout01 dey
  441.        bpl pout01 ;output throttle
  442.        ;
  443.        stx d2prb ;write to port
  444.        nop ;wait 6 microseconds
  445.        nop
  446.        nop
  447.        jsr toggl ;toggle strobe
  448.        ;
  449.        lda #%00010000 ;icr mask
  450.        ;
  451. pout02 bit d2icr ;wait for ack
  452.        beq pout02 ;not received
  453.        ;
  454.        pla
  455.        sta clkspd ;restore clock
  456.        pla
  457.        tay ;restore
  458.        ;
  459.        rts
  460.        ;
  461. ;---------------------------------
  462.        ;
  463. ;set up user port for output
  464.        ;
  465. setprt lda #%01111111 ;mask interrupts
  466.        sta d2icr
  467.        ;
  468.        lda d2pra ;port a output
  469.        jsr toggl1 ;set strobe high
  470.        ;
  471.        lda d2ddra ;data direction a
  472.        ora #%00000100 ;set strobe...
  473.        sta d2ddra ;as output
  474.        ;
  475.        ldx #0 ;bring all printer...
  476.        stx d2prb ;output lines low
  477.        dex ;set up port b...
  478.        stx d2ddrb ;as output
  479.        ;
  480.        rts
  481.        ;
  482. ;---------------------------------
  483.        ;
  484. ;toggle strobe line
  485.        ;
  486. toggl  lda d2pra
  487.        and #%11111011 ;bring...
  488.        sta d2pra ;strobe low &...
  489.        ;
  490. toggl1 ora #%00000100 ;then...
  491.        sta d2pra ;high again
  492.        ;
  493.        rts
  494.        ;
  495. ;---------------------------------
  496.        ;
  497. ;error message text
  498.        ;
  499. errmsg .byt 13,'i/o error #',0
  500.        ;
  501. ;---------------------------------
  502.        ;
  503. ;storage
  504.        ;
  505. escflg *=*+1 ;escape mode flag
  506.        ;
  507. pmode  *=*+1 ;output mode
  508.        ;
  509. ;=================================
  510. .end
  511.