home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
ftp.barnyard.co.uk
/
2015.02.ftp.barnyard.co.uk.tar
/
ftp.barnyard.co.uk
/
cpm
/
walnut-creek-CDROM
/
SIMTEL
/
CPMUG
/
CPMUG001.ARK
/
MAZE.ASM
< prev
next >
Wrap
Assembly Source File
|
1984-04-29
|
5KB
|
485 lines
;***************************;
; MAZE PROGRAM FROM INTEL ;
;***************************;
ORG 100H
CPM EQU 0005H
BOOT EQU 0000H
CR EQU 0DH
LF EQU 0AH
NUL EQU 0FFH
FF EQU 0CH
MAZE: LXI SP,STACK
LXI D,MAZ
MVI C,09
CALL CPM
MAZE1: LXI D,CRLF
MVI C,09
CALL CPM
MVI A,0
STA PFLAG
STA MFLAG
LXI H,MTX
LXI B,MTXE
M3: MVI M,0
INX H
MOV A,L
CMP C
JNZ M3
MOV A,H
CMP B
JNZ M3
CALL SIZE
LXI D,PAGE
MVI C,09
CALL CPM
CALL START
M1: CALL TEST
MOV A,E
ORA A
JZ M2
CALL MOVE
JMP M1
M2: CALL SCAN
JC M1
CALL PMAZE
LXI D,AGAIN
MVI C,09
CALL CPM
MVI C,01
CALL CPM
PUSH PSW
MVI C,09
LXI D,CRLF
CALL CPM
POP PSW
CPI 'Y'
JZ MAZE1
CPI 079H
JZ MAZE1
JMP BOOT
SIZE: LXI D,WIDE
MVI C,09
CALL CPM
SIZE1: CALL RND
MVI C,11
CALL CPM
ORA A
JZ SIZE1
CALL BIN
PUSH PSW
LXI D,CRLF
MVI C,9
CALL CPM
POP PSW
CPI 40+1
JNC SIZE
STA CMAX
SIZE2: LXI D,HIGH
MVI C,09
CALL CPM
CALL BIN
PUSH PSW
LXI D,CRLF
MVI C,09
CALL CPM
POP PSW
CPI 40+1
JNC SIZE2
STA BMAX
RET
START: LDA CMAX
MOV E,A
CALL RNDR
STA SPOS
MOV C,A
MVI B,0
CALL MATRIX
MVI M,1
RET
TEST: MVI D,0
MOV A,B
CPI 0
JZ T1
DCR B
CALL MATRIX
INR B
MOV A,M
RRC
JC T1
MOV A,D
ORI 01H
MOV D,A
T1: LDA BMAX
DCR A
CMP B
JNZ T8
LDA PFLAG
ORA A
JZ T2
JMP T3
T8: INR B
CALL MATRIX
DCR B
MOV A,M
RRC
JC T3
T2: MOV A,D
ORI 02
MOV D,A
T3: MOV A,C
CPI 0
JZ T4
DCR C
CALL MATRIX
INR C
MOV A,M
RRC
JC T4
MOV A,D
ORI 04H
MOV D,A
T4: LDA CMAX
DCR A
CMP C
JZ T5
INR C
CALL MATRIX
DCR C
MOV A,M
RRC
JC T5
MOV A,D
ORI 08H
MOV D,A
T5: MVI E,0
MOV A,D
ORA A
T6: RAR
JNC T7
INR E
T7: ORA A
JNZ T6
RET
MOVE: MVI A,1
STA MFLAG
CALL RNDR
MOV E,A
MOV A,D
INR E
DCR E
RRC
JNC MV1
JZ MOVEUP
DCR E
MV1: RRC
JNC MV2
JZ MOVEDOWN
DCR E
MV2: RRC
JNC MOVERIGHT
JZ MOVELEFT
JMP MOVERIGHT
MOVEUP: DCR B
CALL MATRIX
MOV A,M
ORI 05H
MOV M,A
RET
MOVEDOWN:
CALL MATRIX
MOV A,M
ORI 04H
MOV M,A
LDA BMAX
DCR A
CMP B
JZ MD1
INR B
CALL MATRIX
MOV A,M
ORI 01H
MOV M,A
RET
MD1: MVI A,1
STA PFLAG
MVI B,0
LDA SPOS
MOV C,A
RET
MOVELEFT:
DCR C
CALL MATRIX
MOV A,M
ORI 03H
MOV M,A
RET
MOVERIGHT:
CALL MATRIX
MOV A,M
ORI 02H
MOV M,A
INR C
CALL MATRIX
MOV A,M
ORI 01H
MOV M,A
RET
SCAN: INR C
LDA CMAX
CMP C
JZ S1
S2: CALL MATRIX
MOV A,M
RRC
JNC SCAN
RET
S1: MVI C,0
INR B
LDA BMAX
CMP B
JNZ S2
MVI B,0
LDA MFLAG
ORA A
RZ
MVI A,0
STA MFLAG
JMP S2
PMAZE: LXI D,CRLF
MVI C,09
CALL CPM
LXI D,CRLF
MVI C,09
CALL CPM
LXI D,OD
MVI C,09
CALL CPM
MVI B,0
MVI C,0
PM1: LDA SPOS
CMP C
JZ PM2
PUSH B
LXI D,CD
MVI C,09
CALL CPM
POP B
JMP PM3
PM2: PUSH B
LXI D,OD
MVI C,09
CALL CPM
POP B
PM3: INR C
LDA CMAX
CMP C
JNZ PM1
PM4: PUSH B
LXI D,CRLF
MVI C,09
CALL CPM
LXI D,CLR
MVI C,09
CALL CPM
POP B
MVI C,0
PM5: CALL MATRIX
MOV A,M
ANI 02H
JZ PM6
PUSH B
LXI D,OPR
MVI C,09
CALL CPM
POP B
JMP PM7
PM6: PUSH B
LXI D,CLR
MVI C,09
CALL CPM
POP B
PM7: INR C
LDA CMAX
CMP C
JNZ PM5
PUSH B
LXI D,CRLF
MVI C,09
CALL CPM
LXI D,OD
MVI C,09
CALL CPM
POP B
MVI C,0
PM8: CALL MATRIX
MOV A,M
ANI 04H
JZ PM9
PUSH B
LXI D,OD
MVI C,09
CALL CPM
POP B
JMP PM10
PM9: PUSH B
LXI D,CD
MVI C,09
CALL CPM
POP B
PM10: INR C
LDA CMAX
CMP C
JNZ PM8
INR B
LDA BMAX
CMP B
JNZ PM4
LXI D,CRLF
MVI C,09
CALL CPM
LXI D,PAGE
MVI C,09
CALL CPM
RET
BIN: PUSH B
MVI B,0
BIN1: PUSH B
MVI C,01
CALL CPM
POP B
CPI CR
JZ BIN2
CPI '0'
JC BIN1
CPI '9'+1
JNC BIN1
MOV C,A
MOV A,C
ANI 0FH
MOV C,A
MOV A,B
ADD A
MOV B,A
ADD A
ADD A
ADD B
ADD C
MOV B,A
JMP BIN1
BIN2: MOV A,B
POP B
RET
RNDR: PUSH B
CALL RND
MOV C,A
MVI B,0
RNDR1: DCR E
JZ RNDR2
ADD C
JNC RNDR1
INR B
JMP RNDR1
RNDR2: MOV A,B
POP B
RET
RND: PUSH H
PUSH B
LXI H,SHIFT
MVI B,8
MOV A,M
RND1: RLC
RLC
RLC
XRA M
RAL
RAL
LXI H,SHIFT
MOV A,M
RAL
MOV M,A
INX H
MOV A,M
RAL
MOV M,A
INX H
MOV A,M
RAL
MOV M,A
INX H
MOV A,M
RAL
MOV M,A
DCR B
JNZ RND1
POP B
POP H
RET
MATRIX: PUSH D
PUSH PSW
LDA CMAX
MOV E,A
MVI D,0
LXI H,0
MOV A,B
MULT: PUSH B
MVI B,9
MULT1: DCR B
JZ MULT2
DAD H
RAL
JNC MULT1
DAD D
JMP MULT1
MULT2: POP B
MOV E,C
DAD D
LXI D,MTX
DAD D
POP PSW
POP D
RET
SHIFT: DB 0FFH
DB 0FFH,0FFH,0FFH
PFLAG: DS 1
MFLAG: DS 1
BMAX: DS 1
CMAX: DS 1
SPOS: DS 1
MTX: DS 1600
MTXE EQU $
PAGE: DB CR,LF,FF,NUL
DB NUL,NUL,NUL,NUL,NUL,NUL
DB NUL,NUL,NUL,NUL,NUL,'$'
CRLF: DB CR,LF,NUL,'$'
OD: DB ' :','$'
CD: DB '--:','$'
OPR: DB ' ','$'
CLR: DB ' I','$'
MAZ: DB '8080 MAZE PROGRAM ','$'
WIDE: DB 'HOW WIDE? ','$'
HIGH: DB 'HOW HIGH? ','$'
AGAIN: DB 'AGAIN? ','$'
DS 64
STACK EQU $
END MAZE