Binary files in basic, how ?

Page 3/3
1 | 2 |

By WORP3

Paladin (803)

WORP3's picture

06-11-2010, 19:54

Anyone has seen this bug before ?

By tvalenca

Paladin (705)

tvalenca's picture

14-08-2018, 03:59

NYYRIKKI wrote:

about 40 seconds on a 7mhz msx, so that is not to bad.

I don't think that we should talk about seconds on this kind of tasks...

... just to show you how easy this would be to solve in assembler... This is not even speed optimized, but it sure should not take a second even on 3.5MHz (sure it depends of the storage device you use)

;Usage: UPLOAD <filename.ext>
;
;Should compile on sjASM or similar... 
;Requires MSX-DOS, but easy to port as BASIC BIN-file if needed.

OUTPUT "UPLOAD.COM"

IOPORT:	EQU #00 ; I/O port where the data should be sent after load...


	ORG #100

	LD DE,#4000	;FREE SPACE
	LD C,#1A	;SET DATA TRANSFER ADDRESS
	CALL 5

	LD DE,#5C	;FCB

	LD C,#F 	;Open
        PUSH DE
	CALL 5
	POP DE
	
	LD HL,1
	LD (FCB+#E),HL

	LD HL,#4000
	LD C,#27	;Read all (but max 16K)
        PUSH DE
	CALL 5
	POP DE

	PUSH HL
	LD C,#10        ;Close
	CALL 5
	POP DE		;DE=Lenght of file = send all of the file

	LD HL,#4000
LOOP:
	LD A,(HL)
	OUT (IOPORT),A	;Send to device
	INC HL
	DEC DE
	LD A,D
	OR E
	RET Z
	JR LOOP
	

Yep, I'm reviving an 8-year old thread with a noob/lazy question: Running Naked in a Field of Flowers

what changes are needed to run from BASIC?

By NYYRIKKI

Enlighted (5026)

NYYRIKKI's picture

15-08-2018, 00:37

Well... lazy is bad, but tips are free. Smile

Basic programs don't accept natively file names as parameters, so you need to create the FCB by other means, like custom "Input filename"-BASIC program. Other than this problem you need to change all "CALL 5" by "CALL #F37D" and if you don't want to change the RAM buffer to higher address then you need to enable RAM to #4000-#7FFF before the loading and select BASIC again after loading using ENASLT (#24)... Program naturally also needs to be loaded to address => #8000... Other than these minor details the program should work just fine.

By SLotman

Paragon (1203)

SLotman's picture

15-08-2018, 01:05

What about something like this... long time I don't code in BASIC but...

10 DIM A%(1024)
20 BLOAD"FILE.BIN",,VARPTR(A%)

Just save the binary file with header pointing to 00 00 as the start address and it should work in theory, right?
(Or you can just set its header to a fixed location, load it outside of BASIC area, and just peek and poke to get its contents from somewhere in memory)

By NYYRIKKI

Enlighted (5026)

NYYRIKKI's picture

15-08-2018, 01:54

SLotman wrote:

What about something like this... long time I don't code in BASIC but...

10 DIM A%(1024)
20 BLOAD"FILE.BIN",,VARPTR(A%)

Just save the binary file with header pointing to 00 00 as the start address and it should work in theory, right?

Hmm... Interesting theory... I think it might work... ( BLOAD"FILE.BIN",VARPTR(A%(0)) )

At least on MSX2 we have this COPY-command that can be used exactly like this without need for the custom 7-byte header.

How ever, I must say I'm not sure what goal we are talking about anymore :)

By tvalenca

Paladin (705)

tvalenca's picture

16-08-2018, 01:28

We are talking about reading a file and "squeezing" it through an I/O port. AFAIK, There is no [COPY "file" TO ioport].

I didn't wanted to work from DOS because I'll still have to switch back to BASIC to do some other stuff.

I thought something like:
10 BLOAD "UPLOAD.BIN"
20 CALL UPLOAD(port,"file") (or at least _UPLOAD("file") and the port would be hardcoded)

By NYYRIKKI

Enlighted (5026)

NYYRIKKI's picture

16-08-2018, 11:04

tvalenca wrote:

We are talking about reading a file and "squeezing" it through an I/O port. AFAIK, There is no [COPY "file" TO ioport].

Indeed... I was talking about the idea of loading file to an array.

Quote:

I thought something like:
10 BLOAD "UPLOAD.BIN"
20 CALL UPLOAD(port,"file") (or at least _UPLOAD("file") and the port would be hardcoded)

Ok... USR("file") is easier to handle, since CALL is more targeted for ROM-files instead of BIN-files, but naturally both are working options...

If you decide to go with CALL-command, you need to write loader for it that moves it to #4000 in RAM and updates call statement extension flag (bit 5) in RAM slot location, offset 1 of slot attribute table. Please remember to keep the data transfer address in free RAM area. If the files you plan to send are large you may want to split the loading ie. to 8KB blocks and just loop the loading / sending part until all is sent. There should be enough space for the file buffer after your program it self.

FCB is described here:
https://www.msx.org/wiki/FCB

How to make call commands (with example) is described here:
https://www.msx.org/wiki/CALL

I don't remember seeing any very good documentation of setting call statement extension flag, but you can use this routine:

	LD A,(#F342) ; Get SlotID of RAM in #4000

SET_CALL_FLAG:
	; Set CALL-extension flag
	; Input: A=SlotID

	AND A
	JP M,.SKIP
	AND 3
.SKIP
	AND 15
	LD E,A
	RLCA
	RLCA
	RLCA
	RLCA
	OR E
	AND 60
	LD D,0
	LD E,A
	LD HL,#FCCA
	ADD HL,DE
	SET 5,(HL)
	RET

This is not needed if you soft reboot the computer after loading so that it will initialize all "cartridges" again, but as you may imagine, that is not very handy or even working option if your boot disk has DOS.

Good luck with your project!

By NYYRIKKI

Enlighted (5026)

NYYRIKKI's picture

16-08-2018, 14:50

Little update... I added this routine & another example inside CALL-command Wiki-page.

By sergio max

Rookie (24)

sergio max's picture

16-08-2018, 17:16

Please help me I code the RADIOLA VG5000µ in assembly but I want to know how to do with msx.

By sergio max

Rookie (24)

sergio max's picture

18-08-2018, 12:21

Excuse me everyone but I want to know how to put Z80 binary code assembly in bluemsx emulator ? thanks
{mod: please stay on topic or open a new thread for your question}

Page 3/3
1 | 2 |
My MSX profile