; name ('CLCPM') ; title CLCPM - CP/M Dependent Communications I/O for Local ;;; polygon associates, inc. ; ; R. W. Vornberg 81/12/24 v3.0 ; B. W. Baebler 82/03/31 v3.1 ;;; Copyright (c) 1981, 1982, Polygon Associates, Incorporated. ; ; Reproduction or publication in any form or format prohibited. ; This unpublished program is the property of Polygon Associates, ; Inc. ; ; Current licensees of Polygon Associates, Inc. software which ; requires customization are hereby granted permission to modify ; the source code supplied with the software, and merge it into ; the binary code provided by Polygon, for the purpose of enabling ; Polygon software to execute on the Licensee's computer or CPU ; registered with Polygon Associates, Inc. Any other use is ; prohibited. ; poly-, and poly-XFR are trademarks of Polygon Associates, Inc. ; CP/M is a registered trademark of Digital Research. ;;; CLCPM - CP/M Dependent Communications I/O for XFRLOC. ; ; This module defines the following C Callable functions: ; ; ; TEXT *comini(spd, siz) Initialize Communications ; VOID comend() End communications ; BOOL inpsts() Get input status ; TEXT inpchr() Get input data ; VOID inflsh() Flush any input ; BOOL outsts() Get output status ; VOID outchr(chr) Send character ; COUNT bufin(ptxt,ltxt) Get input buffer ; VOID bufout(ptxt,ltxt) Send character buffer ; COUNT boutin(otxt,olen,itxt,ilen) Send/rcv buffer ; ; where: ; typedef unsigned char TEXT; ; typedef int BOOL, VOID; ; typedef short COUNT; ;;;; Entry Points. ; public comini,comend ; public inpsts,inpchr,inflsh ; public outsts,outchr ; public bufin$,bufout,boutin ; External Symbols. ; public loops$,parm1$,parm2$ ;;;; ;;;; Symbol Definitions. MASK7 equ 07Fh ; 7 Level code MASK8 equ 0FFh ; 8 Level code MASKD equ MASK8 ; Default NO equ 0 ; C logical false YES equ not NO cbase equ 01A5h ; Communications base address ; System Definitions. ivec equ 010h ; Serial device interrupt vector ;; Device Definitions. rdat equ 058h ; Intel 8251 USART rsts equ 059h rcmd equ 059h wdat equ 058h wcmd equ 059h errrst equ 037H ; Error reset, RTS, Enables STSDLY equ 10 ; Status dalay value ;; Dispatch Vector. org cbase ; cseg comini: jmp cini ; Initialize comend: jmp cend ; Terminate inpsts: jmp ists ; Input status inpchr: jmp ichr ; Input data inflsh: jmp ifsh ; Flush input outsts: jmp osts ; Output status outchr: jmp ochr ; Output character bufin$: jmp ibuf ; Input buffer bufout: jmp obuf ; Output buffer boutin: jmp oibf ; Output/Input buffer loops$: dw 65535 ; Timeout loop counter parm1$: dw YES ; Binary transfers parm2$: dw 15 ; Maximum buffer size (128) ;; CINI - Initialize Communications. cini: lda initfg ; Already initialized ora a jnz cini5 ; If initialized di ; Disable interrupts lhld ivec+1 ; Point to interrupt entry point shld IVECSV ; Save pointer lxi h,IRQ ; Point to local routine shld ivec+1 ; Set new vector xra a ; Preset sta comflg ; data ready flag ei ; Renable inr a sta initfg ; Enable communications port. mvi a,errrst ; Error reset, RTS, Enables out wcmd ; Check for 7 - 8 bit control. cini5: pop h ; Return address pop b ; Speed pop b ; Character size push b push b mov a,c cpi 8 mvi a,MASK8 ; Assume 8 level jz cini10 ; If 8 level mvi a,MASK7 cini10: sta ichra ; Set character masks sta ochra sta ochrb lxi b,0 ; Indicate success pchl ; Exit ;; CEND - End communications. cend: di ; Disable lhld IVECSV ; Pick up old vector shld ivec+1 ; Put in place cend10: in rsts ; Get input status ani 4 ; All sent? jz cend10 ; If not ei ; Reenable xra a sta initfg ; Set not initialized ret ; Exit ;; ISTS - Return comm input status. ists: lda comflg ; Pick up flag mov c,a ; Return mvi b,0 ; it to caller ora a rnz ; Exit if ready mvi a,STSDLY ; Pause a slight amount ists5: dcr a jnz ists5 ret ;; ICHR - Return comm input. ichr: xra a ; Reset di ; sta comflg ; lda comdat ; Get data ei ; mov c,a ; Return character mvi b,0 ; to caller ret ; Exit ;; IFSH - Flush any pending input. ifsh: xra a ; Reset sta comflg ; in rsts ; Get input status ani 2 ; Receiver ready? jnz ifsh ; If not ret ;; OSTS - Return status of comm output. osts: in rsts ; Read status ani 1 ; Mask bit mov c,a ; Return mvi b,0 ; it to caller ret ; Exit ;; OCHR - Send comm output. ochr: pop h ; Pick up return address pop b ; Pick up data push b ; Maintain sp mov a,c ; Set data ani MASKD ochra equ $-1 out wdat ; Send pchl ; Exit ;; IBUF - Get input buffer. ibuf: lxi h,0 ; Initialize shld cnt ; number read pop h ; get return pc pop b ; get buffer pointer xthl ; save return pc, get length ibuf10: mov a,h ; End ora l ; of buffer? jz ibuf30 ; If yes dcx h ; Count down remaining push h ; Save remaining length lhld loops$ ; Get loop counter ibuf15: lda comflg ; Read status ora a ; Character ready? jz ibuf20 ; If not xra a ; Reset di ; sta comflg ; flag lda comdat ; Read data ei ; stax b ; Store inx b ; Advance pointer lhld cnt ; Count inx h ; the input shld cnt ; byte pop h ; Get remaining length jmp ibuf10 ; Continue ibuf20: dcx h ; Count down mov a,h ; Timed ora l ; out? jnz ibuf15 ; If not pop h ; Clean stack ibuf30: lhld cnt ; Get count mov b,h ; Put in mov c,l ; return register xthl ; Get return pc push b ; Restore stack pchl ; Exit ;; OBUF - Send character buffer. obuf: pop h ; get return pc pop b ; get buffer pointer xthl ; save return pc, get length obuf10: mov a,h ; End ora l ; of buffer? jz obuf30 ; If yes obuf20: in rsts ; Read status ani 1 ; Mask bit jz obuf20 ; If not ready ldax b ; Get input inx b ; Advance pointer ani MASKD ochrb equ $-1 out wdat ; Write data dcx h ; Count down remaining jmp obuf10 ; Continue obuf30: xthl ; Get return pc push b ; Restore stack pchl ; Exit ;; OIBF - Output/Input buffer. oibf: pop h ; Save caller's shld hlsav ; return pc call obuf ; Send output buffer pop psw ; Remove output buffer pointer pop psw ; Remove output buffer length call ibuf ; Get input buffer push psw ; Restore push psw ; stack lhld hlsav ; Return pchl ; to caller ;;; IRQ - Interrupt request handling. IRQ: push psw ; Save status in rsts ; Get input status ani 2 ; Receiver ready? jz irq10 ; If not in rdat ; Get input ani MASKD ; Significance ichra equ $-1 sta comdat ; Save it mvi a,0FFh ; Set flag sta comflg ; for non-interrupt code irq10: pop psw ; Restore reg and status db 0C3h ; Jump IVECSV: ds 2 ; to builtin interrupt handler ;;; Local Data. ; dseg cnt: ds 2 ; Byte counter hlsav: ds 2 ; Save area initfg: db 0 ; Initialized comdat: ds 1 ; Received data comflg: ds 1 ; Data ready flag end