Trailing-Edge
-
PDP-10 Archives
-
SRI_NIC_PERM_SRC_3_19910112
-
utilities/search.mac
There are 3 other files named search.mac in the archive. Click here to see a list.
TITLE SEARCH GAME PROGRAM
SEARCH MONSYM,MACSYM,DPYDEF ;GET DEFINITIONS
T1=1 ;TEMP ACS
T2=2
T3=3
T4=4
X=5 ;CURRENT X LOCATION
Y=6 ;CURRENT Y POSITION
D=7 ;DIRECTION CODE
P=17 ;STACK POINTER
PDLSIZ==20 ;STACK SIZE
SIZE==^D10 ;BOARD SIZE
NUM==SIZE/2 ;NUMBER OF TARGETS TO FIND
SUBTTL INITIALIZATION
SEARCH: RESET ;CLEAR EVERYTHING
MOVE P,[IOWD PDLSIZ,PDL] ;SET UP A STACK
MOVE T1,[CALL DPYUUO] ;GET LUUO DISPATCH
MOVEM T1,.JB41## ;SET IT UP
SETZM RANNUM ;CLEAR RANDOM NUMBER
SETZM GAMES ;CLEAR NUMBER OF GAMES PLAYED
SETZM MOVES ;AND TOTAL NUMBER OF MOVES USED
MOVEI T1,.PRIIN ;PRIMARY INPUT
RFMOD ;READ STATUS OF TERMINAL
TXZ T2,TT%ECO ;CLEAR ECHO BIT
SFMOD ;TELL SYSTEM TO NOT ECHO
INI$ ;INITIALIZE DPY
CALL DOGAME ;PLAY A GAME
JRST .-1 ;ALL DONE, PLAY AGAIN
TTY$ $TTCLR ;WANTS TO QUIT, CLEAR SCREEN
HALTF ;EXIT
JRST .-1 ;STAY THAT WAY
SUBTTL GAME PLAYING
DOGAME: SETZM DONE ;CLEAR DONE FLAG
SETZM TRIES ;CLEAR NUMBER OF TRIES
SETZM KNOWNS ;AND NUMBER OF KNOWN TARGETS
MOVE T1,[BOARD,,BOARD+1] ;GET READY
SETZM BOARD ;TO CLEAR THE BOARD
BLT T1,BOARD+SIZE*SIZE-1 ;DO IT
MOVE T1,[MOVTAB,,MOVTAB+1] ;GET READY
SETZM MOVTAB ;TO CLEAR MOVE TABLE
BLT T1,MOVTAB+4*SIZE-1 ;DO IT
MOVEI T4,NUM ;GET NUMBER OF TARGETS TO CREATE
TARGEN: MOVEI T1,SIZE*SIZE ;SET UP MAXIMUM
CALL RANDOM ;RANDOMLY GENERATE AN OFFSET
SKIPE BOARD(T1) ;IS THIS LOCATION IN USE?
JRST TARGEN ;YES, TRY AGAIN
SETOM BOARD(T1) ;IT'S NOW IN USE
SOJG T4,TARGEN ;LOOP OVER ALL TARGETS
MOVLOP: CALL SHOW ;SHOW CURRENT STATUS
CALL DOMOVE ;GO MAKE A MOVE
SKIPN DONE ;IS GAME OVER?
JRST MOVLOP ;NO, KEEP PLAYING
SKIPL DONE ;WANTS TO QUIT?
AOS (P) ;YES, DO SKIP RETURN
RET ;DONE
SUBTTL ROUTINE TO INPUT A MOVE
DOMOVE: CALL GETCHR ;READ NEXT CHARACTER
CAIE T1," " ;SPACE?
JRST DOMOVE ;NO, EAT IT
MOVSI T1,-SIZE*SIZE ;GET SET
SKIPL BOARD(T1) ;FOUND NEW PLACE?
AOBJN T1,.-1 ;NO, KEEP LOOKING
JUMPGE T1,HACK ;GO IF NO NEW PLACE
MOVMS BOARD(T1) ;MAKE TARGET VISIBLE
RET ;DONE
HACK: SETOM DONE ;WE ARE DONE
RET ;RETURN
SUBTTL ROUTINE TO PRINT OUT THE BOARD
SHOW: MOVSI Y,-SIZE ;GET READY FOR LOOP OVER ROWS
SHWROW: MOVSI X,-SIZE ;GET READY FOR LOOP OVER COLUMNS
STR$ [ASCIZ/ /] ;SPACE OVER SOME
SHWLOP: MOVEI T1,(Y) ;GET ROW NUMBER
IMULI T1,SIZE ;GENERATE OFFSET
ADDI T1,(X) ;ADD IN COLUMN
SKIPG BOARD(T1) ;IS THIS A KNOWN TARGET LOCATION?
STR$ [ASCIZ/. /] ;NO
SKIPLE BOARD(T1) ;WELL?
STR$ [ASCIZ/* /] ;YES
AOBJN X,SHWLOP ;LOOP OVER WHOLE ROW
STR$ [BYTE (7)12,12] ;DONE, MOVE DOWN
AOBJN Y,SHWROW ;THEN SHOW IT
DPY$ ;ALL DONE, SHOW CHANGES
RET ;DONE
SUBTTL ROUTINE TO READ A CHARACTER
;ROUTINE TO READ IN A MOVE. RETURNS CHARACTER IN T1.
GETCHR: PBIN ;READ IT
CAIN T1,15 ;CARRIAGE RETURN?
JRST GETCHR ;YES, IGNORE IT
CAIL T1,"A"+40 ;LOWER CASE?
CAILE T1,"Z"+40 ;WELL?
RET ;NO, DONE
SUBI T1,40 ;YES, CONVERT
RET ;DONE
SUBTTL RANDOM NUMBER GENERATOR
;CALLED WITH MAXIMUM VALUE IN T1. RETURNS NUMBER IN T1 IN RANGE
;ZERO TO VALUE-1. DESTROYS T2 AND T3.
RANDOM: MOVE T3,T1 ;MOVE NUMBER
SKIPN T1,RANNUM ;GET OLD RANDOM NUMBER IF ANY
TIME ;NONE, USE SYSTEM TIME AS SEED
IMUL T1,[^D<125*125*125*125*125>] ;MAGIC CONSTANT
ADDI T1,^D17 ;HELP IF ZERO
TXZ T1,1B0 ;MAKE SURE POSITIVE
MOVEM T1,RANNUM ;SAVE FOR NEXT TIME
MUL T1,T3 ;GET RESULT
RET ;DONE
SUBTTL DATA
PDL: BLOCK PDLSIZ ;STACK STORAGE
DONE: BLOCK 1 ;SET WHEN GAME IS DONE
GAMES: BLOCK 1 ;NUMBER OF GAMES PLAYED
MOVES: BLOCK 1 ;TOTAL NUMBER OF MOVES
TRIES: BLOCK 1 ;NUMBER OF MOVES IN CURRENT GAME
KNOWNS: BLOCK 1 ;NUMBER OF KNOWN TARGETS IN CURRENT GAME
RANNUM: BLOCK 1 ;CURRENT RANDOM NUMBER
BOARD: BLOCK SIZE*SIZE ;PLAYING BOARD
MOVTAB: BLOCK 4*SIZE ;TABLE OF MOVES PLAYED
END SEARCH