
; --------------------------------------------------------
; gsx system routines.
; assumes inclusion of 'SYSROT.GEN'
; in general co-ords must be stored in 'ptsin' prior to call.
; jump table:

line	jp xline	; plot line
pline	jp xpline	; plot polyline (mult co-ords qty in 'hl')
sltype	jp xslt		; set line type 0-5 in 'A'
slcol	jp xslcol	; set line colour from 'A' (1=show,0=erase)

text	jp xtext	; plot text at co-ords from DE

mark	jp xmark	; plot polymarker at co-ords
smtype	jp xsmark	; set marker type from 'A' 0-5
smcol	jp xsmcol	; set marker colour from 'A' (1=show,0=erase)

bar	jp xbar		; plot bar (2 pairs co-ords)

open	jp xopen	; open workstation
close	jp xclose	; close workstation
trans	jp xtrans	; load 'ptsin' b/2 words from DE


gsx	equ 115		; gsx function call


; move bytes from DE to 'ptsin'.
; transfer is done for 'b' bytes, so b=words*2!!

xtrans	ld hl,ptsin	; point dest
	ex de,hl	; get into z80 block move format
	ld c,b
	ld b,0
	ldir		; move
	ret

; draw a bar. Enter with 'ptsin' set to :
; - llx, lly, trx, try.

xbar	ld hl,xbar1
	ld (parblk+2),hl
	ld hl,11
	ld (contrl),hl	; func code
	ld hl,2
	ld (contrl+2),hl	; no of vertices (2)
	ld hl,1
	ld (contrl+10),hl	; ID for bar
	jp gdos
	
xbar1	defw 1,1,1,1,1,1,1,0,0,1

; draw one line from 2 vertices

xline	ld hl,2
	jr xpline	; do as for multi line

; draw muliple lines. Enter no of co-ord pairs in hl.

xpline	ld (contrl+2),hl	; load no of vertices
	ld hl,xpl1
	ld (parblk+2),hl
	ld hl,6
	ld (contrl),hl	;func code
	ld hl,1
	ld (contrl+10),hl
	jp gdos

xpl1	defw 1,1,1,1,1,1,1,0,0,1

; set line colour from 'A'. 0=erase, 1=plot.

xslcol	ld hl,17
	jp spc

; set line type from 'A' 0-5.

xslt	ld hl,15

; generalised single parameter call, A=param, HL=op-code.

spc	ld (contrl),hl	; set line type
	ld hl,0
	ld (contrl+2),hl
	ld l,a
	ld h,0
	ld (intin),hl	; pass 1 parameter
	ld hl,intin	; use default array
	ld (parblk+2),hl
	jp gdos


; output text. Enter with text position in 'Ptsin x,y',
; text pointed to by DE.

xtext	ld hl,intin
	ld (parblk+2),hl	; default array
	call tmove		; fetch text to 'intin' array
	ld hl,8
	ld (contrl),hl	; output text func code
	ld hl,1
	ld (contrl+2),hl	; no of points (1)
	jp gdos			; do it.

tmove	ld hl,intin		; point dest start
	ld bc,0			; zero byte count
tmove1	ld a,(de)		; fetch chr
	cp term			; end of move?
	jr z,tmove2		; yes
	ld (hl),a		; save chr
	inc bc
	inc de
	inc hl			; up counters
	ld a,0
	ld (hl),a		; zero msb of chr array
	inc hl
	jr tmove1		; and loop
tmove2	ld (contrl+6),bc	; deposit word count
	ret

; output a polymarker. Enter with 'Ptsin' set
; to one pair of co-ords.

xmark	ld hl,xmark1
	ld (parblk+2),hl	; intin loaded
	ld hl,7
	ld (contrl),hl	;func code
	ld hl,1			; no of vertices (1)
	ld (contrl+2),hl
	jp gdos

xmark1	defw 1,1,1,1,1,1,1,0,0,1
 
; set polymarker colour from 'A'. 0=erase, 1=plot.

xsmcol	ld hl,20
	jp spc

; set marker type from 'A' 0-5.

xsmark	ld hl,18
	jp spc		; as for line type


; open GSX workstation

xopen	ld hl,xopen1
	ld (parblk+2),hl
	ld hl,1
	ld (contrl),hl	; open code
	ld hl,10
	ld (contrl+6),hl	; size of intin array
	jp gdos			; do it

xopen1	defw 1,1,1,1,1,1,1,0,0,1

; close GSX workstation

xclose	ld hl,2
	ld (contrl),hl	; func call 2
	ld hl,0
	ld (contrl+2),hl	; no point pairs
	ld (contrl+6),hl	; return no pairs
	jp gdos		; do it

; gdos call for action

gdos	ld c,gsx	; function call
	ld de,parblk	; parameter address block
	jp bdos		; do it

; paramteter block address table

parblk	defw contrl	; control array
	defw intin	; default input array to GSX
	defw ptsin	; point pairs to plot
	defw intout	; integer output from GSX
	defw ptsout	; point pairs output from GSX
	
; control array

contrl	defs 2		; GSX action code
	defs 2		; number of pairs in PTSIN array
	defs 2		; size of intin array
	defs 2		; size of output points array
	defs 2		; size of intout array
	defs 2		; ID for type 'D'

; default integer input array

intin	defs 30

; integer output array from GSX routine

intout	defs 90		; 45 words

; point pairs array for plotting

ptsin	defs 128	; 64 points if required

; point pairs out from GSX routine

ptsout	defs 24		; 12 words if required


; end of GSX routines.
;--------------------------------------------------------

