[Contents] [Commodore] [New] [Search] [Home]

Commodore CP/M v2.2 for the C64
I/O Configuration Utility

;
;	IO CONFIGURATION UTILITY FOR COMMODORE 64
;
;	COPYRIGHT (C) 1982
;       COMMODORE INTERNATIONAL
;
;
;	EQUATES
;
BUFFER	EQU	0F800H
IOMEM	EQU	0FC00H
IOTYPE	EQU	0FCFFH
FNBASE	EQU	0FC10H
KYBASE	EQU	0FD00H
VICWR	EQU	1
CMD	EQU	0F900H
DATA	EQU	0F901H
SECTOR	EQU	0F902H
TRACK	EQU	0F903H
DISKNO	EQU	0F904H
KYCHAR	EQU	0F905H
KYBDMD	EQU	33H
CRPOS	EQU	1
SHFTST	EQU	0F28DH
LASTKY	EQU	63H
MSGPTR	EQU	66H
CONINV	EQU	09H
OFF	EQU	01H
MODESW	EQU	0CE00H
;
BOOT	EQU	0000H
BDOS	EQU	0005H
CLS	EQU	0CH
CR	EQU	0DH
LF	EQU	0AH
	ORG	100H
;
START:	LXI	SP,STACK	;INITIALIZE STACK PTR
	LXI	D,IOMSG
	CALL	PRINT
;
	LDA	IOTYPE
	ANI	01H	;# OF DISKS
	ADI	'1'	;FORM ASCII
	MOV	E,A
	CALL	CONOUT
;
	LXI	D,PRTMSG
	CALL	PRINT
;
	LXI	D,P1515
	LDA	IOTYPE
	ANI	02H	;CHECK PRINTER TYPE
;
	JZ	ST1	;1515 IF = 0
;
	LXI	D,P4022	;4022 IF = 1
;
ST1:	CALL	PRINT
;
	LXI	D,CAPMSG
	CALL	PRINT
;
	LXI	D,ONMSG	;ASSUME ON
	LDA	IOTYPE
	ANI	20H	;BIT 5
;
	JZ	ST2
	LXI	D,OFFMSG
;
ST2:	CALL	PRINT
;
	LXI	D,MENU
	CALL	PRINT
;
ST3:	CALL	KEYIN
	CPI	'1'
	JZ	CHGDRV
;
	CPI	'2'
	JZ	CHGPRT
;
	CPI	'3'
	JZ	CHGCAP
;
	CPI	'4'
	JZ	CHGFNC
;
	CPI	'5'
	JZ	CHGKEY
;
	CPI	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1
	MVI	L,KYBDMD ;UNSHIFT=0, CAPS=1
	MOV	B,M
	LDA	SHFTST	;GET MODIFIER STATUS
	ANI	01H	;IS SHIFT KEY DOWN?
	JZ	CK1	;JUMP IF NO
;
	MVI	B,2	;SHIFT=2
CK1:	LDA	SHFTST
	ANI	04H	;IS THE CONTROL KEY DOWN?
	JZ	CK2	;JUMP IF NO
;
	MVI	B,3	;CONTROL=3
CK2:	LHLD	BOOT+1
	MVI	L,LASTKY
	MOV	A,M
	STA	KYCHK	;SAVE FOR EXIT TEST
	ADD	A	;*2
	ADD	A	;*4
	ADD	B	;ADD IN OFFSET
	LXI	H,KYBASE
	ADD	L
	MOV	L,A	;HL NOW HAS ADDRESS OF KEY
;
	SHLD	KYADDR	;ADDRESS OF KEY
	MOV	A,B	;B IS THE MODE
	STA	KYMODE
;
	LHLD	BOOT+1
	MVI	L,MSGPTR
	MVI	M,0
	INX	H
	MVI	M,0	;DISABLE MESSAGE MODE IF ANY
;
	LXI	D,ISMSG
	CALL	PRINT
;
	LHLD	KYADDR
	MOV	A,M	;GET KEY CODE
	CALL	PHEX	;  AND PRINT IN HEX
;
	LXI	D,INMSG
	CALL	PRINT
;
	LDA	KYMODE
	LXI	D,UNSH	;UNSHIFT MODE IF 0
	CPI	0
	JZ	PMODE
;
	LXI	D,CAPS
	CPI	1
	JZ	PMODE	;CAPS MODE IF 1
;
	LXI	D,SHIFT	
	CPI	2
	JZ	PMODE	;SHIFT MODE IF 2
;
	LXI	D,CONT	;MUST BE CONTROL MODE
;
PMODE:	CALL	PRINT
;
	LXI	D,MODE
	CALL	PRINT
;
	CALL	GHEX
;
	JNZ	ASGKEY
;
	LDA	KYCHK	;NO CHARACTERS, 2 CR'S?
	CPI	CRPOS	;IS IT CR KEY POSITION?
	JZ	START	;RESTART IF 2 CR'S
;
	JMP	CK0	;NEXT KEY
ASGKEY:	LHLD	KYADDR
	MOV	M,A	;PUT NEW CHARACTER IN MEMORY
	JMP	CK0
;
PHEX:	PUSH	PS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SAV1:	MOV	A,M
	STAX	D
	INX	H
	INX	D
	MOV	A,L
	ANA	A
	JNZ	SAV1	;256 TIMES
;
	MVI	A,0
	STA	DISKNO
;
	INR	A
	STA	TRACK
;
	MVI	A,VICWR
	CALL	IO6510
	LDA	DATA
	ANA	A
	JNZ	WRERR
;
	LDA	SECTOR
	INR	A
	STA	SECTOR
	CPI	5
	JNZ	SAV2	;WRITE SECTORS 3 AND 4
;
	JMP	START
;
WRERR:	LXI	D,WERMSG
	CALL	PRINT
	CALL	CONIN
	JMP	START
;
;
;	MESSAGES
;
IOMSG:	DB	CLS,LF,'COMMODORE 64 I/O CONFIGURATION UTILITY',CR,LF,LF
	DB	'THE CURRENT I/O ASSIGNMENTS ARE:',CR,LF,LF
	DB	'  NUMBER OF DRIVES:  $'
;
PRTMSG:	DB	CR,LF
	DB	'  PRINTER TYPE:  $'
;
P1515:	DB	'1515',CR,LF,'$'
P4022:	DB	'4022',CR,LF,'$'
;
CAPMSG:	DB	'  INITIAL CAPS MODE:  $'
;
ONMSG:	DB	'ON',CR,LF,'$'
OFFMSG:	DB	'OFF',CR,LF,'$'
;
MENU:	DB	LF,LF
	DB	'DO YOU WISH TO:',CR,LF,LF
	DB	'  1.  CHANGE NUMBER OF DISK DRIVES',CR,LF
	DB	'  2.  CHANGE PRINTER TYPE',CR,LF
	DB	'  3.  CHANGE INITIAL CAPS MODE',CR,LF
	DB	'  4.  CHANGE FUNCTION KEY ASSIGNMENTS',CR,LF
	DB	'  5.  CHANGE KEY CODES',CR,LF
	DB	'  6.  SAVE CURRENT I/O SETUP ON DISK',CR,LF
	DB	'  7.  RETURN TO CP/M',CR,LF,LF
	DB	'PLEASE ENTER SELECTION (1-7) $'
;
WERMSG:	DB	CR,LF,LF,'DISK WRITE ERROR',CR,LF
	DB	'PRESS ANY KEY TO CONTINUE $'
KYINST:	DB	CLS,LF
	DB	'PRESS KEY TO EXAMINE KEY CODE',CR,LF,LF
	DB	'TO CHANGE KEY CODE, ENTER DATA IN',CR,LF
	DB	'   HEXADECIMAL AFTER "CHANGE TO"',CR,LF,LF
	DB	'TO EXIT KEY CODE MODE, TYPE "RETURN"',CR,LF
	DB	'   TWICE AFTER "PRESS KEY"',CR,LF,LF
	DB	'TO KEEP CURRENT KEY CODE, TYPE',CR,LF
	DB	'   "RETURN" AFTER "CHANGE TO"',CR,LF,LF
	DB	'$'
;
PRSMSG:	DB	CR,LF,'PRESS KEY $'
;
ISMSG:	DB	CR,'IS $'
;
INMSG:	DB	' IN $'
CAPS:	DB	'CAPS   $'
SHIFT:	DB	'SHIFT  $'
CONT:	DB	'CONTROL$'
UNSH:	DB	'UNSHIFT$'
MODE:	DB	' MODE - CHANGE TO $'
;
FNKMSG:	DB	CLS,LF,'THE FUNCTION KEY ASSIGNMENTS ARE:',CR,LF,LF
	DB	'$'
FM1	DB	'  F$'
;
FM2	DB	':  "$'
;
CRM	DB	'<CR>$'
CRLFM	DB	CR,LF,'$'
;
FNINST	DB	LF,'ENTER FUNCTION KEY NUMBER (1-8)',CR,LF
	DB	'  TO CHANGE PRESET VALUES.',CR,LF,LF
	DB	'ENTER 9 TO LEAVE FUNCTION',CR,LF
	DB	'  KEY UTILITY.  $'
;
FM3	DB	CR,LF,LF,'TYPE IN TEXT, USING "RETURN"',CR,LF
	DB	'  OR "CTRL-Z" AS TERMINATOR.',CR,LF,LF,'$'
;
KYADDR	DS	2	;KEYBOARD LOOKUP ADDRESS
KYMODE	DS	1	;KEYBOARD MODE
KYCHK	DS	1
HEXIN	DS	1
NUMCHR	DS	1
	DS	32
STACK	EQU	$


[Contents] [Commodore] [New] [Search] [Home]
This page has been created by Sami Rautiainen.
Read the small print. Last updated December 01, 1998.