	SUBROUTINE INITMILLI
C Routine to initialize the millipede and segment arrays in order
C to start a new millipede at the top of the screen
	IMPLICIT REAL*8 (A-Z)
	INCLUDE 'ARRAYS.INC/NOLIST'
	INTEGER*4 I,RANDINT,XLOC(2),XDIR(2)
C
C These must be SCREEN_MINX, not BORDER_MINX, to avoid trouble in MOVEMILLI
C if there is a barrier at the upper corner of the screen - this method
C avoids trouble by starting the millipede on top of any such barrier
C Note that BORDER_MINY is used in the code below for the Y coord
C
	DATA XLOC / SCREEN_MINX, SCREEN_MAXX /
	DATA XDIR / -1,1 /
C
C Fill in the links for the milli free list
C
	DO I = 1,MAX_MILLI
	  MI_ARY(M_FLINK,I) = 0
	ENDDO
C
C Fill in the links for the tail of the milli free list and for the
C entry for the initial millipede
C Then set up the pointers to the linked lists
C
	MI_FREEHEAD = 2
	MI_LISTHEAD = 1
C
C Randomly start millipede at either upper left or upper right, and
C create initial millipede array
C
	I = RANDINT(1,2)
	MI_ARY(M_XDIR,1) = XDIR(I)
	MI_ARY(M_YDIR,1) = 1
	MI_ARY(M_HEADPT,1) = 1
	MI_ARY(M_TAILPT,1) = DIF_MAXSEG
C
C Fill in the head's link, and set its location to the upper corner
C
	SE_ARY(S_FLINK,1) = DIF_MAXSEG
	SE_ARY(S_XLOC,1) = XLOC(I)
	SE_ARY(S_YLOC,1) = BORDER_MINY
C
C Set up the millipede as shown below, in case a bullet hits it before all
C segments are on screen
C
C	IF STARTING UPPER LEFT		IF STARTING UPPER RIGHT
C	 v - HEAD    v - TAIL	   TAIL - v   HEAD - v
C	 *************			  ************
C	+---------------		--------------+
C	|  screen			      screen  |
C
C	(MOVING TO LEFT)		(MOVING TO RIGHT)
C
C Fill in the segment links, and set all but head to 'off screen'
C location
C
	DO I = 2,MAX_SEG
	  SE_ARY(S_FLINK,I) = I - 1
	  SE_ARY(S_XLOC,I) = SE_ARY(S_XLOC,I-1) - MI_ARY(M_XDIR,1)
	  SE_ARY(S_YLOC,I) = BORDER_MINY
	ENDDO
	RETURN
	END
