; Xbyte.asm. Handles switching between Lisp and the Alto emulator.
; deleted CallFn May 21, 1984  2:54 PM van Melle
; deleted uPC stuff December 16, 1982  10:29 PM van Melle
; Last change May 14, 1981  12:46 AM by Beau Sheil 
; Tone change March 30, 1981  7:56 PM by Beau Sheil 
; Phrase change November 23, 1980  5:51 PM by Beau Sheil 
; Chord change November 19, 1980 10:31 AM by Beau Sheil 

; Procedures defined
	.ent	Iresume, InitLispRegs

; statics defined
	.ent	Bcpl, SubrArgsOffset, SubrBase

; statics used
	.extd	TopLevelFrame, lvNIL

; Lisp extended Nova instructions - dispatch into microcode
	.dusr	MBI        = #67400	; (vahi, vahi) - Lisp ucode
	.dusr	ILispRegs  = #67411	; InitLispRegs() -> memory config

	.ZREL
Bcpl:		bcpl			; global page 0 statics
SubrArgsOffset:	0
SubrBase:	0

	.SREL
Iresume:	resume
InitLispRegs:	.ilr

	.NREL

; *** This is the point to which control is returned from Lisp ***

bcpl:	sta	3, NSA		; save for nargs to subr call
	lda	0, SubrArgsPtr	; addr of first arg
	lda	1, c3
	sub#	1, 3, szr	; skip if nargs eq 3
	jmp	not3
	lda	1, c4
	add	0, 1, snr	; addr of third arg - always skips
not3:	lda	1, SubrArgsOffset
	lda	3, SubrBase
	add	2, 3		; addr of procedure static 
	lda	2, TopLevelFrame ; restore stack ptr
	sta	1, 3,2		; sets up xtra args
	lda	1, c2
	add	0, 1		; addr of second arg
	jsr	@ 0, 3		; indirect to bcpl code thru static
NSA:		3		; with NumSubrArgs arguments

; Entry for Iresume - AC0 has value. 
resume:	mov	0, 3		; addr of result
	lda	0, 0,3		; load hi and lo words into ACs
	lda	1, 1,3
	MBI			; back to Lisp with result in ac0/1

SubrArgsPtr:	210		; addr where ucode leaves first subr arg
c2:	2
c3:	3
c4:	4

; InitLispRegs(X) -> puts ucode params into X!0 et sequa
.ilr:	ILispRegs
	jmp	1,3


	.END