perm filename ALPNTY.PAL[AID,HE]1 blob sn#375074 filedate 1978-08-23 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00003 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002	.TITLE  AL INTERPRETER
C00006 00003	 program initialization
C00016 ENDMK
C⊗;
.TITLE  AL INTERPRETER

.OFFSET -160000		;Load us into the zonker: virtual 0 → physical 160 000
			;Comtab and patch areas are in code & data spaces

;These need only be looked at during the first pass:
    .IF1
        .INSRT ALHEAD.PAL[AL,HE]
	.INSRT ZONKER.PAL[AL,HE]

	STSW  FLOAT,1	;1 => put in the floating-string conversions
	STSW  KERNEL,1	;1 => use the kernel
	STSW  MOVING,1	;1 => assume the servo is loaded too
	STSW  ALAID,1	;1 => put in the ALAID debugging stuff
	STSW  DETECT,0	;1 => put in the collision detector only
	STSW  LBDEBUG,0	;1 => first word of any large block is address of maker.
	STSW  YELLOW,0	;1 => the yellow arm is in.

        .INSRT K1DEF.PAL[11,SYS]
    .ENDC

	;If DDT sends us to user I space this will start the Kernel up anyway
. = START

	RESTRT		;EMT gets us into Kernel I space
	RESTRT
	RESTRT		;This is the INIT entry point to the Kernel

. = PATCH

	.BLKW 375	;Patch area

. = INTCOD
CODE$ == INTCOD		;Interpreter code & data spaces start here
DATA$ == INTDAT
SPSWITCH == 0		;Make sure we start off with everyone properly defined
DATA

.PRINT /	ALIO
/
.INSRT ALIO.PAL[AL,HE]

.PRINT /	LARGEB
/
.INSRT LARGEB.PAL[AL,HE]

			;Small block allocator
.PRINT /	SMALLB
/
.INSRT SMALLB.PAL[AL,HE]

			;The interpreter
.PRINT /	INTERP
/
.INSRT INTERP.PAL[AL,HE]

.IFNZ ALAID		;The debugging package
    FLOAT==1		;uses floating output
.PRINT /	PNTAID
/
    .INSRT PNTAID.PAL[AID,HE]
.ENDC

.IFNZ FLOAT		;The floating I/O
.PRINT /	FLOAT
/
    .INSRT FLOAT.PAL[AL,HE]
.ENDC

			;Graph structure
.PRINT /	GRAPHS
/
.INSRT GRAPHS.PAL[AL,HE]


.IFNZ DETECT		;Collision detector
.PRINT /	DETECT ?!?!?!?
/
    .INSRT DETECT.PAL[AL,HE]
.ENDC

DATA	;Data areas

MAINBL:: PDBLK 1,20	;Makes a process descriptor for main process
MAININ:: PDBLK 1,150,F	;Makes another PDB for the main (1st) interpreter

ISTBLK:: .BLKW ISBS	;Dummy interpreter status block (used in linking only)
PROLST:: .WORD 0	;List of procedures currently active

CODE
temp == %OFFSE	;Save the current offset
.OFFSET 0	;We want to use real physical addresses here for the kernel

	PUTLOC JOBDAT, MAINBL
	PUTLOC JOBSA, AL
	PUTLOC JOBDM, USRDM

.OFFSET temp	;Restore Offset
; program initialization

AL:	
	;initialize the world
	MOV USKMAX+MAINBL,SP	;Make sure we have a good stack pointer
	JSR PC,IOINIT	;Initialize input-output
	EVWAIT CSLEVT	;Grab the console
	MOV #STRMES,R0	;Print AL runtime system message
	JSR PC,TYPSTR
	EVSIG CSLEVT	;Release the console
	JSR PC,FRINIT	;Initialize free storage
	CALL SBINIT	;Initialize small block space
	JSR PC,GSINIT	;Initialize graph structure
	;check to see that the PCODE is compatible
	CMP PCDVER,#PCVERSION	;Version compatible?
	BEQ 1$		;Yes
	ALERR STMES	;No
1$:
    .IFNZ MOVING
	MOV #DVBKSZ,R0	;Get a device block
	JSR PC,GTFREE	;
	MOV R0,R1
	MOV R0,-(SP)	;Save address of device block so we can free it
	JSR PC,@LINTARM	;Initialize the arm code
	TST R0		;All well?
	BEQ 3$		;Yes
	CMP R0,#10	;Is it the reference supply?
	BNE 2$
	ALERR STMES3	; yup - complain about it.
	BR 3$
2$:	CMP R0,#7	;Is it the power supply?
	BNE 22$
	ALERR STMES4	; yup - complain about it.
	BR 3$
22$:	ALERR STMES2	;Just make a general complaint.
3$:	MOV (SP)+,R0	;R0 ← LOC[device block]
	JSR PC,RLFREE	;Release it
    .ENDC

	CMP ARMVER,#VERSION	;Arm compatible?
	BEQ 4$		;Yes
	ALERR STMES1	;No
4$:
	;set up the first interpreter
	JSR PC,INTINIT		;Initialize the interpreter events
	MOV #ISBS,R0		;R0 ← Size (in words) of an interpreter status block
	JSR PC,GTFREE		;R0 ← LOC[new interpreter status block]
	MOV R0,NXTINT+ISTBLK	;Prime the interpreter list.
	CLR NXTINT(R0)
	CLR PROLST		;Prime the active procedure list
	MOV #PCODE,IPC(R0)	;new IPC ← interpreter start address
	EVMAK			;-(SP) ← event for EVT in this interpreter
	MOV (SP),EVT(R0)	;new EVT ← event just created.
	MOV R0,-(SP)		;Save LOC[new interpreter status block]
	MOV #INSTSZ,R0		;R0 ← Size needed for an interpreter stack
	JSR PC,GTFREE		;R0 ← LOC[new interpreter stack]
	MOV (SP)+,R1		;R1 ← LOC[new interpreter status block]
	MOV R0,STKBAS(R1)	;Store away new stack base
	ADD #2*INSTSZ,R0	;R0 ← LOC[top of new stack] (INSTSZ is in bytes)
	MOV #MAININ,R2		;R2 ← LOC[main interpreter process descriptor]
	BIS #UGRSAV+USKSAV,PDBSTA(R2)	;Use saved registers so we can set things up
	MOV R0,PDBR3(R2)	;Store away new interp stack pointer (reg 3)
	MOV R2,PDB(R1)		;Store away LOC[PDB] in new ISB
	MOV R1,PDBR4(R2)	;Store away LOC[ISB] in reg 4 of PDB
	MOV USKMAX(R2),USKP(R2)	;Make sure we have a good stack pointer
    .IFNZ ALAID
	MOV R1,CURNAM	;This is the current interpreter
    .ENDC
	SCHEDU R2,#INTERP,#USRDM,#2 ;Cause the new process to be started, suspended
    .IFNZ ALAID
	JSR PC,ALINIT	;Initialize ALAID
    .ENDC
	EVWAIT 		;Wait for the return signal
	BCC  5$		;All well?
	ALERR TSTMES	;No
5$:	EVWAIT CSLEVT	;Grab the console
	MOV #ENDMES,R0	;Print ALL DONE message
	JSR PC,TYPSTR
	EVSIG CSLEVT	;Release the console
    .LIF NZ ALAID
	JSR PC,ALKILL	;Kill ALAID
	DISMIS		;Go away
DATA
PNTMES:: ASCIE </CAN'T CONTINUE/>
STMES::	ASCIE </INCOMPATIBLE PCODE VERSION.  PROCEED AT YOUR OWN RISK/>
STMES1:: ASCIE </INCOMPATIBLE ARM VERSION.  PROCEED AT YOUR OWN RISK/>
STMES2:: ASCIE </CAN'T INITIALIZE ARM.  ERROR CODE IN R0./>
STMES3:: ASCIE </CAN'T INITIALIZE ARM.  REFERENCE POWER SUPPLY OUT OF RANGE./>
STMES4:: ASCIE </Can't initialize arm.  Interface power supply turnd off/>
TSTMES:: ASCIE </BAD RETURN FROM MAIN INTERPRETER/>
STRMES:: ASCIE </
AL runtime system

/>
ENDMES:: ASCIE </
ALL DONE NOW.  SEE YOU AROUND!
/>

CODE
	PUTLOC LGETVAL, GETVAL
	PUTLOC LGETARG, GETARG
	PUTLOC LINVLDT, INVLDT

DATEND == DATA$		;Get end of data address - free storage starts there

.IF2
DATA
CODE
	.INFO <First location after interpreter code = >,\CODE$
	.INFO <Data ends at = >,\DATA$
	.INFO <Free storage size = >,\FREL
.ENDC

.END  START