;*************************************************
;** Change history --
;** 30mar81: Broken off from general interface.
;** 30mar81: Set up for Zilog ZLAB 8000
;** 09may81: Tell cpu when state is free.
;** 19jan82: Allow segmented users.
;** 21jan82: Took out references to freecpu and needcpu
;** 15feb82: Dummy out need/free cpu.
;** 13may82: Comment out references to setfp and resfp
;*************************************************

	.title	"sysdep MODULE"
	.input	"biosdefs2.z8k"

;*************************************************
;** SAVED CPU STATE --
;** is specified by the following "constants."
;** Offset stapcsg must point to the word preceding
;** the saved PC offset, EVEN FOR NONSEGMENTED
;** OPERATION.
;*************************************************
__data	.sect
	.GLOBAL	stareg,staevnt,stafcw,stapcsg
stareg	.WORD	 4	;offset of r0
staevnt	.WORD	36	;saved 1st word
stafcw	.WORD	38	;saved fcw
stapcsg	.WORD	40	;seg word of PC

;*************************************************
;** ADDRESSES --
;** as input parameters to the routines below are
;** delivered in register pairs (i.e. as though
;** segmented).  The high-order word of such an
;** address is undefined when the process running
;** in that address space runs in nonsegmented
;** mode.
;*************************************************
	.eject
;*************************************************
;** GET NEXT INSTRUCTION WORD -- 
;** Input:
;**	rr6 = saved PC -- seg # must be fixed for
;**		nonseg users
;** Output:
;**	r3  = next instruction word
;*************************************************
__data	.sect
gttxt:	.WORD	0
__text	.sect
	.GLOBAL gettext
gettext:			; PROCEDURE ENTRY
;	ld	r5,#2		; it is system data
;	ldl	rr2,#0		; required parameter
;	sc	#MEM_SC		; MAP source

	pushl	@r15,rr6
	ld	r7,#gttxt	; address of temp
	ld	r5,#0		; it is caller Instruction
	ldl	rr2,#0		; required parameter
	sc	#MEM_SC		; MAP destination

	ldl	rr4,rr6
	popl	rr6,@r15	; restore source
	ldl	rr2,#2		; byte count to move
	sc	#MEM_SC		; DO TRANSFER

	ld	r3,gttxt	; load return values
	ldb	rl2,#0
	ret

	.eject
;*************************************************
;** GET MEMORY BYTES --
;** Segmented emulator input --
;**	rr6 - src address (trapee space)
;**	rr4 - dst address (emulator space)
;**	 r3 - byte count
;*************************************************
	.GLOBAL getmem
getmem:
	push	@r15,r3
;	pushl	@r15,rr4
;	ld	r5,#4		; it is user data
;	ldl	rr2,#0		; required parameter
;	sc	#MEM_SC		; MAP source
;
;	popl	rr4,@r15
	pushl	@r15,rr6	; save source
	ldl	rr6,rr4		; position dest
	ld	r5,#0		; it is caller data
	ldl	rr2,#0		; required parameter
	sc	#MEM_SC		; MAP destination

	ldl	rr4,rr6
	popl	rr6,@r15	; restore source
	pop	r3,@r15		; restore byte count
	ld	r2,#0		; requrired parameter
	sc	#MEM_SC		; DO TRANSFER

	ret

	.eject
;*************************************************
;** PUT MEMORY BYTES --
;** Emulator input --
;**	rr6 - src address (emulator space)
;**	rr4 - dst address (trapee space)
;**	 r3 - byte count
;*************************************************
	.GLOBAL putmem
putmem:				; PROCEDURE ENTRY
	push	@r15,r3
	pushl	@r15,rr4
	ld	r5,#0		; it is caller data
	ldl	rr2,#0		; required parameter
	sc	#MEM_SC		; MAP source

	popl	rr4,@r15
;	pushl	@r15,rr6	; save source
;	ldl	rr6,rr4		; position destination
;	ld	r5,#2		; it is system data
;	ldl	rr2,#0		; required parameter
;	sc	#MEM_SC		; MAP destination
;
;	ldl	rr4,rr6
;	popl	rr6,@r15	; restore source
	pop	r3,@r15		; restore byte count
	ld	r2,#0		; required parameter
	sc	#MEM_SC		; DO TRANSFER

	ret
