
(part 4 of 4)

OUTR_LP_EO_SND:
        LD HL,65535            ;inner loop counter
INNR_LP_EO_SND:
        IN A,(C)               ;read status port
        LD E,A                 ;save it in E
        CP 255                 ;does the port exist?
        JR Z,NO_PORT           ;NO

IF OFP_CHK
        AND 56                 ;YES, so 00111000 any
framing/parity/overrun errors?
        JR NZ,OR_FR_P_ERR      ;YES, so exit
        LD A,E                 ;NO, so check status again
ELSE
ENDIF

        AND 1                  ;is it ready to receive a character?
        JR NZ,SEND_RDY_EO      ;YES, so send it
        DEC HL                 ;NO, not yet, so one less inner loop
        LD A,H

        OR L                   ;are we down to zero?
        JR NZ,INNR_LP_EO_SND   ;NO, so keep trying on inner loop
        DEC D                  ;YES, so one less outer loop
        JR NZ,OUTR_LP_EO_SND   ;not done yet, so reset inner loop and
try again
        JR TIME_OUT            ;we have timed out!
;********
SEND_RDY_EO:
        POP AF                 ;restore character
        POP DE                 ;all done with outer loop counter
        DEC C                  ;back up to data port
        OUT (C),A              ;send the character
        INC C                  ;restore C=status port
        JR SET_ZF2             ;ZF=1 for ok exit, leaving character in A


;****************************************************************

;Parallel printer send with timeout check.
;Modified PR #2 routine from SmartBASIC 1.x version 20Y by
Richard F. Drushel

;On entry, A=character to send.  On exit, if the send was
successful, ZF=1 and
;A=entry character.  If the printer timed out (either not on-line
or non-
;existent), ZF=0 and A=error code.

;errors:

;CHAR_DEV_TIMEOUT_ERR   EQU  25       ;parallel or serial timed
out
;CHAR_DEV_NO_PORT_ERR   EQU  26       ;no port found for parallel
or serial
;PRINTER_OFFLINE_ERR    EQU  28       ;parallel printer is
off-line

__WRITE_PAR:
        PUSH HL
        PUSH BC               ;save for loop counters
        PUSH AF               ;save character
        LD B,9                ;big loop counter
LITTLE_LOOP:
        LD HL,65535           ;little loop counter
ONLINE_CHECK:
        IN A,(PAR_PORT)       ;read the parallel port
        CP 255                ;does it exist?
        JR Z,NO_PAR_PORT      ;NO, so no parallel port error
        AND 1                 ;is it on-line?
        JR NZ,PAR_READY_CHECK ;YES
PAR_NOT_READY:
        DEC HL                ;NO, so decrement little loop counter
        LD A,H
        OR L                  ;are we down to zero?

        JR NZ,ONLINE_CHECK    ;NO, so keep trying
        DEC B                 ;YES, so decrement big loop counter
        JR NZ,LITTLE_LOOP     ;not done yet, so restart little loop
PAR_TIMEOUT:
        IN A,(PAR_PORT)       ;we've timed out!  so let's find out why
        BIT 1,A               ;so was it off-line?
        LD A,PRINTER_OFFLINE_ERR  ;let's assume not on-line
        JR NZ,PAR_ERR_EXIT    ;YES
        LD A,CHAR_DEV_TIMEOUT_ERR  ;NO, anything else is busy
PAR_ERR_EXIT:
        OR A                  ;ZF=0 for error
        POP BC                ;get rid of AF on stack
        JR PAR_BYE_BYE        ;and exit
;********
PAR_READY_CHECK:
        IN A,(PAR_PORT)       ;read the parallel port
        AND 2                 ;is it ready to receive another character?
        JR NZ,PAR_NOT_READY   ;NO, so keep trying
        POP AF                ;YES, so restore character
        OUT (PAR_PORT),A      ;send it
        CALL SET_ZF           ;ZF=1 for ok exit while preserving A
PAR_BYE_BYE:
        POP BC
        POP HL
        RET
;**********
NO_PAR_PORT:
        LD A,CHAR_DEV_NO_PORT_ERR  ;no parallel port found
        JR PAR_ERR_EXIT            ;so error exit




IV.  For Next Time.

In my next article, I will discuss interrupt deferral techniques
to prevent reentrancy in the EOS video RAM routines.  This will
include a transcript of some discussions that Chris Braymen and I 
had  on the subject,  as well a complete pseudocode for the algo
rithms,  which  I  successfully implemented in EOS-8,  and  in  a 
modified version of SmartBASIC 1.x (as proof of concept).

V.  Administrivia.

I finally unpacked my 486 system after ADAMcon 09,  so now I  can 
start  working  on all the leftovers in my  buffer,  including  a 
master set of distribution disks for ADAMserve (including ADAMse
rve PowerPaint,  and user-configurability of server hardware).  I 
will get lynched soon if I don't clean it up!

        See you next week!

        *Rich*


*****************************************************************

Note:  TWWMCA is archived.  Back issues are available via
anonymous ftp.


        ftp://junior.apk.net/pub/users/drushel/twwmca/

Files have the form wkyymmdd.txt, where yy=year, mm=month,
dd=day.

*****************************************************************

