CMD
This page was last modified 12:01, 18 May 2020 by Mars2000you. Based on work by Gdx and Rderooy and others.

Contents

Effect

CMD is a reserved word that has never been used. This instruction was probably created to start MSX-DOS, but instead CALL SYSTEM was used.

The execution of this instruction causes just a call to the hook H.CMD (0FE0Dh). This allows the instruction to be diverted to create a new one.

Syntax

CMD <Command>

Parameters

<Command> can be any thing. No command exist. The user must create a command otherwise "Illegal function call" error occurs if CMD is executed.

Use

When calling the Hook, the HL register of the CPU contains the pointer of the Basic interpreter in the buffer of the currently executing instruction. The last value placed in the stack contains the values of the AF registers (F containing the error flags of the interpreter).

It is possible to add parameters behind the instructions but this requires an advanced knowledge of the Basic interpreter. The pointer does not point to a simple ASCII text but a text with many tokens. For example, if you enter "CMD PRINT", the HL register will point to the PRINT instruction code (091h) and not the text "PRINT" (070h 072h 069h 06Eh 074h in ASCII).

To create your instruction, you have the following BASIC ROM routines available: CHRGTR (0010h or 4666h), FRMEVL (04C64h), FRMQNT (542Fh), GETBYT (521Ch), FRESTR (67D0h), PTRGET (5EA4h) and NEWSTT (4601h).

Example

Create a command to change the CPU from MSX turbo R.

;
; Use: CMD Z80 or CMD R800 under MSX-Basic 2.0~
;
CHGCPU	EQU	0180h	; Change le CPU Z80/R800
HCMD	EQU	0fe0dh	; CMD Hook
 
	ORG	0d000h-7	; Routine Address - 7
;
; Header (Size = 7 bytes)
;
	DB	0feh
	DW	Start
	DW	End
	DW	Start
;
; Diverting the CMD instruction via the Hook
;
Start:	LD	BC,5
	LD	DE,HCMD
	LD	HL,HDAT
	LDIR		; Places the jump instruction in the Hook
	RET
;
; Jump instruction data (5 octets)
;
HDAT:	JP	R800ROM
	NOP
	NOP
;
; CMD Z80 or CMD R800? (Routine executed by CMD)
;
R800ROM:	CP	5AH	; Tests if the first character
	JR	Z,Z80MODE	; of parameter is "Z"
	CP	052H	; Tests if it's "R"
	RET	NZ
	RST	10	; Next character
	LD	A,(HL)
	CP	038H	; Tests if the second character is "8"
	RET	NZ
	RST	10	; Next character
	LD	A,(HL)
	CP	030H	; Test if the third is "0"
	RST	10
	RST	10	; Next character
	LD	A,(HL)
	CP	030H	; Tests if the fourth is "0"
	RET	NZ
	LD	A,081H	; Value for R800 mode with ROM
	JR	RETBASIC
Z80MODE:
	RST	10	; Next character
	LD	A,(HL)
	CP	038H	; Tests if the second character is "8"
	RET	NZ
	RST	10	; Next character
	LD	A,(HL)
	CP	030H	; Test if the third is "0"
	RET	NZ
	LD	A,080H	; Value for Z80
RETBASIC:
	CALL	CHGCPU	; Changes the CPU
	POP	AF	; To not to have an error
	RST	10	; Moves the pointer at end of instruction
	RET
END:

Once the routine is assembled and saved in binary format under the name "CMDR800.bin", enter the following instructions to sets the new instruction.

CLEAR300,&HD000:BLOAD”CMDR800.bin”,R

The extra instruction is CMD R800/Z80.

Related to

ATTR$(), FPOS(), IPL

Compatibility

MSX-BASIC 1.0 or higher