;
; The Falling Man
;
; Formatted for the SB-Assembler (https://www.sbprojects.net/sbasm/)
;
; From an article in Practical Electronics December 1979
;
; Chris Oddy Dec 2023
;
		.CR		scmp
		.LF		the_falling_man.list		; listing file
		.TF		the_falling_man.bin		; object file
;		.TF		the_falling_man.hex,INT		; Intel hex file
;
RAM		.EQ		$0F00		; for variables
DISP		.EQ		$0B00		; Display Memory
;
;		RAM Offsets
;
COL		.EQ		2		; Column
CNT		.EQ		3		; Counter
ROW 		.EQ		4		; Row count
;
		.OR		$0F20		; set origin
;
ENTER:	LDI	/RAM		; (high byte)
		XPAH	3
		LDI	RAM		; (low byte)
		XPAL	3		; P3 to variables
BEGIN:	LDI	/DISP		; (high byte)
		XPAH	1
LOOP:		LDI	6
		ST	COL(3)
NEWMAN:	XPAL	1		; begin new man
		LDI	/MAN		; (high byte)
		XPAH	2
		LDI	MAN		; (low byte)
		XPAL	2		; P2 to man pattern
		LDI	19
		ST	CNT(3)
COPY:		LDI	15		; rows per picture
		ST	ROW(3)
NEWROW:	LD	@1(2)
		ST	@1(1)
		LD	@1(2)
		ST	@7(1)		; point to next row
		DLD	ROW(3)	; picture done 7
		JNZ	NEWROW
		LD	@-30(2)	; reset P2
		LD	@-112(1)	; reset P1 1 row down
		DLY	$40		; wait ...
		DLD	CNT(3)
		XRI	4		; 4 sweeps to go?
		JZ	LAND		; yes - change picture
		XRI	4		; restore CNT
		JNZ	COPY		; fresh sweep 7
		DLY	$FF		; leave man standing
		DLD	COL(3)	; next man
		DLD	COL(3)	; subtract 2
		JP	NEWMAN	; all done 7
		LDI	0
CLEAR:	XPAL	1		; clear screen
		LDI	0		; blamk
		ST	@1(1)
		XPAL	1
		JNZ	CLEAR		; more to do
		JMP	BEGIN		; repeat for ever
LAND:		LD	@+28(2)	; P2 to standing man
		JMP	COPY		; continue
;
					; Bit Patterns for Falling Man
MAN:		.DB	$00,$00,$43,$08,$43,$08
		.DB	$3F,$F0,$0F,$C0,$07,$80
		.DB	$03,$00,$07,$80,$04,$80
		.DB	$08,$40,$08,$40,$04,$80
		.DB	$04,$80,$04,$80,$00,$00
;
					; Bit Petterns for Standing Man
		.DB	$03,$00,$03,$00,$0F,$C0
		.DB	$1F,$E0,$27,$90,$43,$08
		.DB	$07,$80,$0C,$C0,$10,$20
		.DB	$20,$10,$10,$20,$08,$40
		.DB	$00,$00,$00,$00
