Simple assembly program not working on MSX 2

Page 1/2
| 2

By gzito

Supporter (4)

gzito's picture

18-05-2019, 16:04

I've written this simple asm program:

		ORG		0E000H-7
	
		DB		0FEH
		DW		BEGIN,THEEND,BEGIN
		
BEGIN:	CALL	0849H
		LD		A,'A'
NEXT:	CALL	00A2H
		INC		A
		CP		'Z'+1
		JR		NZ,NEXT
		LD		A,0DH
		CALL	00A2H
		LD		A,0AH
		CALL	00A2H
		RET
THEEND:	END

I assembled the program into a BIN file using sjasmplus (V1.06). Then load the program into BlueMSX, using:
CLEAR 200,&HDFFF
BLOAD"FIRST.BIN",R

It perfectly works using machine profile "MSX" (general MSX 1 machine), don't work using profile "MSX 2" instead.
Any suggestions please?

Login or register to post comments

By Rogerup

Resident (38)

Rogerup's picture

18-05-2019, 19:32

CLS is at 0848H. It would be better to use CALL 00C3H, like you call CHPUT (using 00A2H instead of directly 08BCH)

Maybe the ORG is too HIGH. Try 0D000H

By gzito

Supporter (4)

gzito's picture

18-05-2019, 19:37

CLS		EQU		00C3H	
		
BEGIN:	XOR		A
		CALL		CLS

works perfectly also on MSX 2.

Thanks!

By RetroTechie

Paragon (1563)

RetroTechie's picture

18-05-2019, 19:57

Welcome here, gzito! Smile2

Use "CALL 00C3H" rather than "CALL 0849H". On an MSX1 (or at least some of those), this address (00C3h) jumps to the address you used. On an MSX2, this entry jumps to some other address, and at 0849h there will be code that does something else entirely. The 00C3h entry (CLS) is an official entry, guaranteed to do the same thing on different MSX models. 0849h is not, this could change randomly between models (as you found out). Where did you get this address anyway?

Also I suggest you put the BIOS addresses on top of your listing using EQU statements, using the names from official MSX bios documentation. That way your listing becomes much easier to read. And if for some reason you decide to use some other address for one of them, you only need to change 1 point in your source listing (vs. 3 here if for example you'd use something else for 00A2h). Same can be done for other constants.

Pro tip: I usually put the ORG after the BLOAD header.

For example like so:

CHPUT:		EQU		00A2H
CLS:		EQU		00C3H

CR:		EQU		0DH
LF:		EQU		0AH


		DB		0FEH
		DW		BEGIN,THEEND-1,BEGIN

		ORG		0E000H
		
BEGIN:		CALL CLS
		LD		A,'A'
NEXT:		CALL	CHPUT
		INC		A
		CP		'Z'+1
		JR		NZ,NEXT
		LD		A,CR
		CALL	CHPUT
		LD		A,LF
		CALL	CHPUT
		RET

THEEND:		END

By gzito

Supporter (4)

gzito's picture

18-05-2019, 20:47

RetroTechie wrote:

Where did you get this address anyway?

See book "Starting Machine Code On Msx" by G.P. Ridley, on page 78.
BTW I've found a lot of typos in it....

Anyway using official bios routines entry points is safer and also much more correct, you're right. Also using EQUs make code more readable.

I'm just playing again with Z80 assembly on MSX after 30+ years, I was about 13 years old when used Zen Assembler for the first time... Now I'm 47 and currently trying sjasmplus and asmsx cross compilers on Windows 10 Smile

Congratulations to all the people behind the site.
I think MSX.org is really great !

By Rogerup

Resident (38)

Rogerup's picture

18-05-2019, 21:30

Here you find this information in a better format to consult:
MSX Red Book

By gzito

Supporter (4)

gzito's picture

18-05-2019, 22:05

Rogerup wrote:

Here you find this information in a better format to consult:
MSX Red Book

Wow!
Thanks so much!

By Ritter

Supporter (4)

Ritter's picture

18-05-2019, 23:59

A nice cross compiler is rasm.

By ARTRAG

Enlighted (6239)

ARTRAG's picture

23-05-2019, 08:22

RASM seems very good
http://www.cpcwiki.eu/forum/programming/rasm-z80-assembler-i...

Is there anyone using it actively for msx development?

By Grauw

Ascended (8395)

Grauw's picture

23-05-2019, 09:27

Is RASM cross platform or Windows only?

MSX Red Book is full of information about exact routine addresses in the BASIC / BIOS ROM. This can be interesting if you want to disassemble the ROM, but do not use them in programs or you will get compatibility problems like you did with CLS above. Instead use the official entries in the jump table that starts at 0000H.

I would rather recommend the MSX2 Technical Handbook which Nestor transscribed for us. Also I maintain the MSX Assembly Page which contains a lot of reference manuals and programming information.

By ARTRAG

Enlighted (6239)

ARTRAG's picture

23-05-2019, 09:50

I see a dos version at the same link and a Linux version at the coder's home page

Page 1/2
| 2