; DummyLevBasic.asm
; Copyright Xerox Corporation 1979, 1980
; Last modified July 20, 1980  1:11 AM by Boggs

; outgoing
.ent OsFinish, Junta
.bext SerialNumber, AltoVersion
.bext OsVersion, OsVersionCompatible
.bext lvUserFinishProc, OsFinishCode
.bext UserName, UserPassword, ErrorLogAddress
.bext lvBFN

; incoming
.bext EtherBoot

lUserName = 10.
lUserPassword = 10.

	.srel

Junta:			.Junta
OsFinish:		.OsFinish
SerialNumber:		-1
AltoVersion:		0
OsVersion:		16.
OsVersionCompatible:	16.
lvUserFinishProc:	UserFinishProc
OsFinishCode:		0
lvBFN:			BFN
UserName:		.UserName
UserPassword:		.UserPassword
ErrorLogAddress:	.ErrorLogAddress

	.nrel

			lUserName
.UserName:		.blk lUserName
			lUserPassword
.UserPassword:		.blk lUserPassword
.ErrorLogAddress:	3*400+200	; net 3 host 200 (maxc)
			0		; well known event report
			30		; protocol socket
	

.Junta:	mkzero 3 3
	sta 3 @displayListHead	; turn off display
	lda 2 firstFrame	; reset stack to tippy top of memory
	sta 2 0 2		; link base frame to self
	mov 1 3			; after junta procedure
	jsr 0 3			; call it
	 0			; no parameters
	jsr @353		; finish if it returns

firstFrame:	176774
displayListHead:420


;-----------------------------------------------------------------
; Finish code.  The idea is to EtherBoot the Boot file whose
; number is in BFN (default is zero, the basic Alto diagnostic).
; If the EtherBoot fails, we retry a few times, then (if we
; weren't already trying for the basic diagnostic) try booting
; the basic diagnostic a few times, and then give up by doing a
; jump self.  If EtherBoot fails, Page 0 and Page 2 are
; clobbered, so we must be very careful during retry.  Neither
; this code nor the EtherBoot code should be loaded in either
; of those pages.  Page 2 is where statics are normally loaded,
; so before calling EtherBoot the first time, read its static
; and salt the address away so that retrys don't reference it.
;-----------------------------------------------------------------

.OsFinish: sta 0 @.OsFinishCode	; save finish code
osf1:	lda 3 UserFinishProc
	snz 3 3			; is there a user finish procedure?
	 jmp boot		; no
	lda 0 @.OsFinishCode	; yes. call it with the finish code as arg
	jsr 0 3
	 1
	jmp osf1		; check for more of them
boot:	dir			; There is no return from here
	lda 3 lvEtherBoot	; EtherBoot static
	lda 3 0 3		; de-reference
	sta 3 lvEtherBoot	; save that address
EBRetry:lda 0 BFN		; boot file number
	mkminusone 1 1		; return on fail = true
	jsr @lvEtherBoot	; Call EtherBoot
	 2			; 2 args
	dsz retryCnt		; failed.
	 jmp EBRetry		; try again
	lda 0 BFN		; this file is a loser
	snz 0 0			; is it the basic diagnostic?
	 jmp .			; yes.  something is very wrong.
	sub 0 0			; no.  try the basic diagnostic
	sta 0 BFN
	lda 0 C5		; try 4 more times
	sta 0 retryCnt
	jmp EBRetry

UserFinishProc:	.blk 1
.OsFinishCode:	OsFinishCode
lvEtherBoot:	EtherBoot
retryCnt:	5		; # of times to retry an EtherBoot
C5:		5
BFN:		10		; default is net exec

	.end