CMD
This page was last modified 23:50, 1 October 2021 by Mars2000you. Based on work by NYYRIKKI and Gdx and others.

Contents

Effect

CMD is a reserved word that has been rarely used in official products. You can find it in the Hard BASIC, SonyVoice BASIC, Tyzack64M BASIC and TyzackVSD BASIC extensions.

It has been used by MSX fans

This instruction was probably created to start disk operating system, but MSX Disk BASIC implemented CALL SYSTEM instead. Microsoft later resurrected this instruction name when they implemented 32bit version of COMMAND.COM for Windows.

The execution of this instruction normally causes just "Illegal function call"-error, but as it also calls hook H.CMD (0FE0Dh), it is relatively easy to divert this instruction to enhance BASIC built-in functionality.

Syntax

CMD <Parameters>

Parameters

<Parameters> is optional and can be anything including other instruction. By default no instruction or parameter definition exists. User must create the functionality otherwise "Illegal function call" error occurs when 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 an instruction 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 set 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