; Definitions for TERMINAL emulation program

; -->> File :	TERM.LIB
;		========

; Copyright (c)	Werner Cirsovius
;		Hohe Weide 44
;		D-2000 Hamburg 20
;		Federal Republic of Germany
;		Tel.: 040/4223247

;		Version 1.10, February 1988

; This "simple" program allows terminal base function XMODEM
; and optional KEMIT file up- and download as well as the
; capture function

; It also allows online BAUD rate setting

; It is designed running on the JOYCE having the serial
; interface fitted

; Project consists of the following modules:

;	TERMINAL.ASM	The Terminal driver and executor
;	XMODEM.ASM	The XMODEM Up/Download facility
; *)	KERMIT.ASM	The KERMIT Up/Download facility
; *)	KERSUB.ASM	The KERMIT subroutines
;	TIMER.ASM	The Timer module
;	SCREEN.ASM	The screen command module
;	@TOP.ASM	The REAL top of TPA

; *) optional, requested only if KERMIT set TRUE

; It requires the authors system libraries BASELIB and HILIB
; and should be linked as follows:

; link terminal,xmodem,kermit[s],kersub[s],screen,timer,
; &baselib[s],hilib[s],@top

; Program is designed acting like a simple generic terminal
; without code interpretation (such as VT100 emulation)

; It is built running on MAILBOXES which have the XMODEM
; protocol installed.

; It also may use the optional KERMIT protocol, but note that
; not all functions of the original KERMIT are implemented.

; At last it also allows ASCII Uploading (Sending to host)
; and Downloading, which is implemented by the Capture function

; ********* Specials :	Tell connection time
;			Full screen set up

; ===== Constant definitions =====

vers	equ	1	; The version
rev	equ	11	; .. and revision level

false	equ	0
true	equ	not false

; Language definition

german	equ	false	; *** Set to TRUE if you like GERMAN

; Development definition

debug	equ	false	; *** Set to TRUE for use with SID

; Transfer option

kermit	equ	false	; *** Set to TRUE for KERMIT support

; Device I/O option

port	equ	true	; *** Set to TRUE if direct port I/O

; Command loop definition

cmdlop	equ	false	; *** Set to TRUE for loop till illegal
			;     command character found

; Changing one of the above equates requires
; a re-assembling of some of the above modules.
; These are in detail:

;   Module	GERMAN	DEBUG  KERMIT	PORT    CMDLOP
; ====================================================
; TERMINAL.ASM	  +	  +	  +	  +	  +
; XMODEM.ASM	  +	  -	  -	  -	  -
; KERMIT.ASM	  -	  -	  -	  -	  -
; KERSUB.ASM	  +	  +	  -	  -	  -
; TIMER.ASM	  +	  -	  -	  -	  -
; SCREEN.ASM	  +	  +	  -	  -	  -
; @TOP.ASM	  -	  -	  -	  -	  -

; Note that DEBUG set TRUE suppresses all full screen
; operations as well as the screen saver function.
; Also note that the screen saver function activated
; doesn't allow SID operations

; Non printable characters or special ones

soh	equ	01h	; Start of header
stx	equ	02h	; Start of text
etx	equ	03h	; End of text
abort	equ	'C'-'@'	; Ctrl-C
eot	equ	04h	; End of text
ack	equ	06h	; Acknowledge
bell	equ	'G'-'@'	; Ring the bell
bs	equ	'H'-'@'	; Do a backspace
tab	equ	09h	; Do a tab
lf	equ	0ah	; Do a line feed
ff	equ	0ch	; Do a form feed
cr	equ	0dh	; Carriage return
xon	equ	'Q'-'@'	; Ctrl-Q
xoff	equ	'S'-'@'	; Ctrl-S
nak	equ	15h	; Negative acknowledge
can	equ	'X'-'@'	; Cancel Ctrl-X
pause	equ	'Y'-'@'	; Ctrl-Y
eof	equ	'Z'-'@'	; End of file
esc	equ	1bh	; Do an escape
dell	equ	7fh	; Delete left character
crc	equ	'C'	; CRC indicator

delim	equ	0bch	; Special JOYCE character
cprig	equ	0a4h

quarz	equ	40	; *** My 4.0 MHz clock

; XMODEM equates

maxerr	equ	10	; Error retries
errcrc	equ	6

; KERMIT equates

drpsiz	equ	94	;Default receive packet size.
drtime	equ	5	;Default receive time out interval.
drpad	equ	00h	;Default receive padding.
drpadc	equ	00h	;Default receive padding char.
dreol	equ	cr	;Default receive EOL char.
drquot	equ	'#'	;Default receive quote char.
dspsiz	equ	32	;Default send packet size.
dspad	equ	00h	;Default send padding.
dspadc	equ	00h	;Default send padding char.
dseol	equ	cr	;Default send EOL char.
dsquot	equ	'#'	;Default send quote char.
dschkt	equ	'1'	;Default checksum type

maxtry	equ	5	;Default number of retries on a packet
imxtry	equ	16	;Default number of retries
			;send initiate.

; The command key list for different languages

	if german
yes	equ	'J'
Cdel	equ	'L'
Csav	equ	'R'
Cprnt	equ	'D'
Crecv	equ	'E'
Ccapt	equ	'P'
Ccase	equ	'G'
Cclos	equ	'S'
	else
yes	equ	'Y'
Cdel	equ	'D'
Csav	equ	'S'
Cprnt	equ	'P'
Crecv	equ	'R'
Ccapt	equ	'C'
Ccase	equ	'U'
Cclos	equ	'C'
	endif;german

; Some CP/M constants

warm	equ	0000h	; Warm start entry
bdos	equ	0005h	; BDOS entry
caldrv	equ	0050h	; Callers drive
fcb	equ	005ch	; Standard FCB
fcbnam	equ	fcb+1	; Name field
fcbext	equ	fcb+9	; Extension field
fcbrc	equ	fcb+32	; Current record
fcbrnd	equ	fcb+33	; Random record position
dma	equ	0080h	; Standard file buffer
reclng	equ	128	; Standard record length
buflng	equ	80	; Keyboard buffer lenght

mulsec	equ	44	; BDOS multisector count
getdat	equ	105	; BDOS time function
setcon	equ	109	; BDOS console set function

msb	equ	0111$1111b

; I/O ports and bits

reg1	equ	1

iodata	equ	0e0h
ioctrl	equ	0e1h

rcvrdy	equ	0000$0100b
ctsbit	equ	0010$0000b
siores	equ	0001$0000b
rxcav	equ	0000$0001b
frmerr	equ	0100$0000b

; XBIOS codes

stop1	equ	0
nopar	equ	0
bit8	equ	8

rtson	equ	07dh
rtsoff	equ	07eh
dtron	equ	07fh
dtroff	equ	080h

sainit	equ	00b6h	; XBIOS functions
sabaud	equ	00b9h
sapara	equ	00bch
teask	equ	00bfh
setkey	equ	00d7h
cdinfo	equ	00e6h
scrrun	equ	00e9h

myesc	equ	0c0h	; Internal EXIT value
EXITk	equ	8

; ***** Z80 macros *****

ldir	macro
	db	0edh,0b0h
	endm

cpir	macro
	db	0edh,0b1h
	endm

jrnz	macro	?n
	db	20h,?n-$-1
	endm

; ***** The SCREEN definitions *****

col	equ	90	; Columns
row	equ	32	; Rows

xbig	equ	col-2	; The command window
ybig	equ	10	; 10 lines should be enough

xsmall	equ	xbig-2
ysmall	equ	ybig-2

comram	equ	0c000h	; Here we start with the COMMON RAM
roller	equ	0b600h	; Start of mysterious ROLLER RAM
vidlln	equ	90*8	; One VIDEO line length

; ===== The special JOYCE screen control =====

; Perform special functions only if DEBUG FALSE

if debug
window	macro	upper,lower,heigth,width
	endm
poscur	macro	currow,column
	endm
else
window	macro	upper,lower,heigth,width
;;
;; Defines screen window string
;;
	db	esc,'X'		;; ESCAPE prefix
	db	upper+' '	;; .. upper line
	db	lower+' '	;; .. lower line
	db	heigth-1+' '	;; .. heigth of window
	db	width-1+' '	;; .. width of window
	endm

poscur	macro	currow,column
;;
;; Defines y, x coordinates on screen
;;
	db	esc,'Y'		;; ESCAPE prefix
	db	currow+' '	;; .. row
	db	column+' '	;; .. column
	endm
endif;debug

