File:  [Infocom source] / coco / screen.src
Revision 1.1.1.3 (vendor branch): download - view: text, annotated - select for diffs
Fri Mar 20 10:20:12 2020 UTC (20 months, 2 weeks ago) by root
Branches: infocom, MAIN
CVS tags: VERSION_D, HEAD
coco interpeter version D

	PAGE
	;SBTTL "--- SCREEN & PRINTER I/O ---"

	; ------------
	; RESTART GAME
	; ------------

ZSTART:	JSR	ZCRLF		; FLUSH OUTPUT BUFFER
 	CLR	SCRIPT		; DISABLE SCRIPTING [ASK 5/28/85]
; 	JSR	ENTER		; "PRESS ANY KEY TO CONTINUE"[ASK 5/28/85]
	LDA	ZCODE+ZSCRIP+1
	STA	SFLAG
 	JMP	LUKE		; SKIP SCRIPT DISABLE
	; FALL THROUGH TO ...

	; ---------
	; COLDSTART
	; ---------

COLD:	CLR	SCRIPT		; DISABLE SCRIPTING
LUKE:	JSR	CLS		; A CLEAN SLATE
	LDD	#SCREEN+228	; POSITION
	STD	CURSOR		; CURSOR
	LDX	#LOADM
	LDB	#LOADML
	JSR	DLINE		; "LOADING GAME ..."
	JMP	START		; AND DO A WARMSTART

LOADM:	.STR	"THE STORY IS LOADING ..."
LOADML	EQU	*-LOADM

	; -----
	; ERROR
	; -----

	; ENTRY: ERROR CODE # IN [A]

INTERR:	.DB	EOL
	.STR	"INTERNAL ERROR #"
IERRL	EQU	*-INTERR

ZERROR:	PSHS	A		; SAVE CODE #
	JSR	ZCRLF		; FLUSH BUFFER
	LDX	#INTERR
	LDB	#IERRL
	JSR	LINE		; "INTERNAL ERROR #"
	PULS	A		; RETRIEVE CODE #
	STA	TEMP+1
	CLR	TEMP
	JSR	NUMBER		; CONVERT ERROR CODE #
	JSR	CR1		; AND SHOW IT

	; FALL THROUGH TO ...

	; ----
	; QUIT
	; ----

ZQUIT:	LDX	#ENDSES
	LDB	#ENDSL
	JSR	LINE		; "END OF SESSION"
	CLR	MOTOR		; SHUT DOWN DRIVE MOTOR

;	JSR	ROMIN		; MAKE SURE ROM'S ACTIVE [ASK 5/15/85]

FREEZE:	BRA	FREEZE		; STOP DEAD

ENDSES:	.STR	"END OF SESSION"
VCODE:	.DB	EOL		; SHARED EOL CHAR
ENDSL	EQU	*-ENDSES

	; --------------------------
	; DISPLAY ZIP VERSION NUMBER
	; --------------------------

	.STR	"COCO VERSION D"
	.DB	EOL
VCODEL	EQU	*-VCODE

VERNUM:	LDX	#VCODE
	LDB	#VCODEL
	JMP	LINE

	; -----------------
	; PRINT A CHARACTER
	; -----------------

COUT:	LDX	#BUFFER		; POINT TO I/O BUFFER
	LDB	CHRPNT		; GET LINE INDEX
	CMPA	#EOL		; IF THIS IS A CR,
	BEQ	ZCRLF		; HANDLE AS SUCH
	CMPA	#SPACE		; IGNORE OTHER CONTROLS
	BLO	COUT1

	STA	B,X		; SEND CHAR TO BUFFER
	CMPB	#31		; END OF SCREEN LINE?
	BHS	FLUSH		; YES, SO FLUSH CURRENT BUFFER
	INC	CHRPNT		; ELSE UPDATE INDEX
COUT1:	RTS			; AND LEAVE

	; FLUSH CONTENTS OF [BUFFER]

FLUSH:	LDA	#SPACE
FLUSH1:	CMPA	B,X		; FIND LAST SPACE CHAR
	BEQ	FLUSH2		; IN CURRENT LINE
	DECB
	BNE	FLUSH1		; KEEP SCANNING
	LDB	#31		; SEND ENTIRE LINE IF NONE FOUND

FLUSH2:	STB	CPSAV		; SAVE
	STB	CHRPNT		; # CHARS IN LINE
	JSR	ZCRLF		; OUTPUT 1ST PART OF LINE

	; START NEW LINE WITH REMAINDER OF OLD

FLUSH3:	INC	CPSAV		; GET 1ST CHAR
	LDB	CPSAV		; OF REMAINDER
	CMPB	#31		; END OF LINE YET?
	BLS	FLUSH4		; NO, MOVE IT FORWARD
	RTS			; ELSE WE'RE DONE HERE

FLUSH4:	LDX	#BUFFER		; POINT TO BUFFER
	LDA	B,X		; GET OLD CHAR
	LDB	CHRPNT		; THIS WAS RESET BY CRLF
	STA	B,X		; MOVE TO START OF BUFFER
	INC 	CHRPNT		; NEXT POSITION
	BRA	FLUSH3		; KEEP MOVING

MORES:	.STR	"[more]"
MOREL	EQU	*-MORES

	; ---------------
	; CARRIAGE RETURN
	; ---------------

ZCRLF:	INC	LINCNT		; NEW LINE GOING OUT
	LDA	LINCNT
	CMPA	#13		; 13 LINES SENT YET?
	BLO	CR1		; NO, KEEP GOING

	BSR	ZUSL		; UPDATE STATUS LINE

	LDD	CURSOR		; GET CURSOR POSITION
	STD	TEMP2		; AND SAVE IT

	LDX	#MORES		; "[MORE]"
	LDB	#MOREL
	JSR	DLINE

	CLR	CFLAG		; NO CURSOR!
	JSR	GETKEY		; GET A KEYPRESS

	LDD	TEMP2
	STD	CURSOR		; RESTORE CURSOR

	LDA	#SPACE		; ERASE "MORE" MESSAGE
	LDB	#MOREL		; WITH SPACES
SPCS:	JSR	OUTCHR
	DECB
	BNE	SPCS

	LDD	TEMP2
	STD	CURSOR		; RESTORE CURSOR AGAIN
	CLR	LINCNT		; RESET LINE COUNTER

CR1:	LDB	CHRPNT
	LDX	#BUFFER
	LDA	#EOL		; INSTALL AN EOL
	STA	B,X		; AT END OF CURRENT LINE
	INC 	CHRPNT		; ADD IT TO CHAR COUNT

LINOUT:	TST	CHRPNT		; IF NO CHARS IN BUFFER
	BEQ	SCDONE		; DON'T PRINT ANYTHING
OUTPUT:	JSR	BUFOUT		; ELSE DISPLAY BUFFER
	CLR	CHRPNT		; RESET CHAR INDEX
SCDONE:	RTS			; AND RETURN

	; ------------------
	; UPDATE STATUS LINE
	; ------------------

ZUSL:	LDA	CHRPNT		; SAVE ALL Z-STRING VARS
	LDB	STBYTF
	LDX	CURSOR
	LDY	ZSTWRD
	PSHS	X,Y,D
	LDA	MPCH		; HIGH BIT OF MPC
	LDB	BINDEX
	LDX	MPCM		; LOW BYTES OF MPC
	LDY	CSTEMP		; TEMP & PERM TOGETHER!
	PSHS	X,Y,D

	LDY	#BUFSAV		; MOVE OUTPUT BUFFER
	LDX	#BUFFER		; TO TEMPORARY STORAGE
	LDB	#SPACE		; CLEAR [BUFFER] WITH SPACES
ZUSL1:	LDA	,X
	STB	,X+
	STA	,Y+
	CMPX	#BUFFER+32
	BLO	ZUSL1

	LDX	#SCREEN
	LDA	#$20		; CLEAR OLD STATUS LINE
ZSL:	STA	,X+
	CMPX	#SCREEN+32
	BLO	ZSL

	; DISPLAY ROOM NAME

	CLR	CHRPNT		; RESET CHAR INDEX
	CLR	SCRIPT		; DISABLE SCRIPTING
	LDD	#SCREEN		; HOME THE
	STD	CURSOR		; CURSOR

	LDA	#$10		; GLOBAL VAR #0 (ROOM #)
	JSR	VARGET
	LDA	TEMP+1
	JSR	PRNTDC		; GET SHORT DESC INTO [BUFFER]

	LDA	#22		; ADVANCE BUFFER INDEX
	STA	CHRPNT		; INTO SCORING POSITION
	LDA	#SPACE		; PRINT A SPACE
	JSR	COUT		; TO SEPARATE THINGS (BM 12/6/84)

	LDA	#$11		; FETCH GLOBAL VARIABLE
	JSR	VARGET		; #1 (SCORE/HOURS)
	TST	TIMEFL		; TIME MODE?
	BNE	PTIME		; YES IF NZ

	; PRINT SCORE

	JSR	NUMBER		; PRINT THE VALUE
	LDA	#$2F		; ASCII SLASH
	BRA	MOVEP

	; PRINT TIME (HOURS)

PTIME:	LDA	TEMP+1
	BNE	PTIME1		; 00 IS REALLY 24
	LDA	#24
PTIME1:	CMPA	#12
	BLE	PTIME2		; IF HOURS IS GREATER THAN 12,
	SUBA	#12		; CONVERT TO 12-HOUR TIME
	STA	TEMP+1
PTIME2:	JSR	NUMBER		; SHOW HOURS VALUE
	LDA	#$3A		; ASCII COLON

MOVEP:	JSR	COUT		; SEND COLON (OR SLASH)
	LDA	#$12		; GLOBAL VAR #2 (MOVES/MINUTES)
	JSR	VARGET
	TST	TIMEFL		; TIME MODE?
	BEQ	PNUM		; NO, DO MOVES

	; PRINT MINUTES

	LDA	TEMP+1
	CMPA	#10		; IF LESS THAN 10 MINUTES,
	BHS	MOVEP1
	LDA	#$30		; ADD ASCII ZERO FOR PADDING
	JSR	COUT

MOVEP1:	JSR	NUMBER		; SHOW MINUTES

	; PRINT "AM/PM"

	LDA	#SPACE		; SEPARATE TIMING
	JSR	COUT		; FROM "AM/PM"
	LDA	#$11		; GLOBAL #1 AGAIN
	JSR	VARGET
	LDA	TEMP+1
	CMPA	#12		; PAST NOON?
	BHS	USEPM		; YES, IT'S PM
	LDA	#$41		; "A"
	BRA	DOM
USEPM:	LDA	#$50		; "P"
DOM:	JSR	COUT
	LDA	#$4D		; "M"
	JSR 	COUT
	BRA	AHEAD		; DONE!

	; PRINT # MOVES

PNUM:	JSR	NUMBER		; SIMPLE, EH?

AHEAD:	JSR	CR1		; DUMP BUFFER
	BSR	INVERT		; INVERT STATUS LINE

	LDY	#BUFSAV		; POINT TO "SAVE" BUFFER
	LDX	#BUFFER		; POINT TO OUTPUT BUFFER
USLEND:	LDA	,Y+
	STA	,X+		; RESTORE PREVIOUS CONTENTS
	CMPX	#BUFFER+32
	BLO	USLEND

	PULS	X,Y,D		; RESTORE EVERYTHING
	STY	CSTEMP
	STX	MPCM
	STB	BINDEX
	STA	MPCH
	PULS	X,Y,D
	STY	ZSTWRD
	STX	CURSOR
	STB	STBYTF
	STA	CHRPNT
	COM	SCRIPT		; RE-ENABLE SCRIPTING
	CLR	MPCFLG		; MPC NO LONGER VALID
	RTS

	; ------------------
	; INVERT STATUS LINE
	; ------------------

INVERT:	LDX	#SCREEN
REVERS:	LDA	,X
	ANDA	#%10111111	; CLEAR BIT 6 (REVERSE VIDEO)
	STA	,X+
	CMPX	#SCREEN+32
	BLO	REVERS
	RTS

	;END


unix.superglobalmegacorp.com