how can we load files from floppies in assembly?

Page 2/3
1 | | 3

By zPasi

Champion (495)

zPasi's picture

20-05-2016, 10:03

Something simple, huh?

How about this:

EXEBAS:	equ $4646

start:
	ld	hl,blcommand
	ld	a,(hl)
	call	EXEBAS
	ret
	
blcommand:
	defb	$cf,$22,"mybin.bin",$22
	defb	0

This just bloads the file "mybin.bin", just like BLOAD"mybin.bin" in BASIC.

The trick is calling the BASIC ROM with a tokenized BASIC command, which is at "blcommand" here. $CF is the token for BLOAD.

With the routine at $4646 you can perform almost any BASIC command, from machine code.

By nitrofurano

Champion (296)

nitrofurano's picture

20-05-2016, 11:46

zPasi wrote:

Something simple, huh?

How about this:

EXEBAS:	equ $4646

start:
	ld	hl,blcommand
	ld	a,(hl)
	call	EXEBAS
	ret
	
blcommand:
	defb	$cf,$22,"mybin.bin",$22
	defb	0

This just bloads the file "mybin.bin", just like BLOAD"mybin.bin" in BASIC.

The trick is calling the BASIC ROM with a tokenized BASIC command, which is at "blcommand" here. $CF is the token for BLOAD.

With the routine at $4646 you can perform almost any BASIC command, from machine code.

great one, i'm going to try it asap, thanks! Smile

By Metalion

Paragon (1173)

Metalion's picture

20-05-2016, 12:13

zPasi wrote:

EXEBAS: equ $4646

AFAIK, this is not a "guaranteed" ROM entry point.
Which means that you could have some compatibility issues.

By zPasi

Champion (495)

zPasi's picture

20-05-2016, 14:28

Metalion wrote:
zPasi wrote:

EXEBAS: equ $4646

AFAIK, this is not a "guaranteed" ROM entry point.
Which means that you could have some compatibility issues.

It's guaranteed in practise. It's between NEWSTT and CHRGTR, that are "official", and it's a standard part of the interpreter.

By nitrofurano

Champion (296)

nitrofurano's picture

20-05-2016, 15:19

@zPasi btw, where can we find documentation explaining that? and does that work on all msx 1, 2, 2+ and turbo-r for sure? (except c-bios ones, of course! Big smile )

By zPasi

Champion (495)

zPasi's picture

20-05-2016, 17:53

nitrofurano wrote:

@zPasi btw, where can we find documentation explaining that? and does that work on all msx 1, 2, 2+ and turbo-r for sure? (except c-bios ones, of course! Big smile )

You'll find sources (disassembled) of MSX BIOS & BASIC in https://sourceforge.net/projects/msxsyssrc/?source=directory
under the directories base100 … base410. BASIC versions from 1.0 to 4.1 are covered. The $4646 is the same in all of them.

By nitrofurano

Champion (296)

nitrofurano's picture

21-05-2016, 19:01

thanks, but for as far i could test, or exebas isn’t working at all, or i am doing something wrong there:
https://www.dropbox.com/s/5yn8flcgeg3ms1k/_example01an1_msxz...
(sorry that i used condoleezzabox for sharing this file, since we can’t add attachments in this forum)
(the example is supposed to display a looping screen2 slideshow of 5 pictures, with 1 second of delay or something like that)
(btw, @zPasi, if you, or anyone else, has an example of exebas working somehow, please let us know)

By zPasi

Champion (495)

zPasi's picture

21-05-2016, 20:09

nitrofurano wrote:

thanks, but for as far i could test, or exebas isn’t working at all, or i am doing something wrong there:

EXEBAS works, I know because I'm using it myself Wink

You're making this in Boriel Basic, interesting… it doesn't matter, it should still work. Maybe you're using memory too high, so it conflicts with the disk basic.

EDIT: I haven't installed that Boriel Basic yet. For a quick test, I edited the example01.asm just as much that I could assemble it with Pasmo. And it works! Or maybe not, but at least it loads the files and doesn't crash. Weird.

By nitrofurano

Champion (296)

nitrofurano's picture

21-05-2016, 20:12

i tried to take such care, the code is less than 4kb (fits into a 4kb file) and loaded at $C000 (takes room until $D000) , and pictures are loaded at $8000 (takes room until $B000) - i guess that the disk and variables area only starts around $F000, isn’t it? - i use to set variables around $E000, i guess that seems to be not the problem
and yes, i have been using Boriel Basic for almost everything, it’s a quite neat “swiss knife” (even for coding in assembly! Big smile )

By zPasi

Champion (495)

zPasi's picture

21-05-2016, 20:39

nitrofurano wrote:

i tried to take such care, the code is less than 4kb (fits into a 4kb file) and loaded at $C000 (takes room until $D000) , and pictures are loaded at $8000 (takes room until $B000) - i guess that the disk and variables area only starts around $F000, isn’t it? - i use to set variables around $E000, i guess that seems to be not the problem

The disk basic stuff may go well below $F000. Try running this:

10 HM%=&HFC4A
20 PRINTHEX$(PEEK(HM%)+256*PEEK(HM%+1))


But when I managed to assemble your example01.asm with Pasmo, I got a binary that does load those .bins, and displays some patterns in screen. Even when I didn't change any addresses. The resulting binary is a little different to your main.bin. I don't know if this is normal for Boriel compiled binary, but some difference there is...

Page 2/3
1 | | 3