How to make "BLOAD" programs?

Page 1/3
| 2 | 3

By BernardBernoulli

Resident (34)

BernardBernoulli's picture

25-07-2014, 03:11

Hello, i am quite new here, but back in the 90ies, when i was 12 or so, i used to have a Sony HB 75P MSX which i loved (and still love).
Back in those times i didn't have access to any resource beside the manuals that came with the computer and very little more so i could only program in pure and simple BASIC. I also had one game on cassette (no ROM cartridges for me): Decathlon, and i was left wondering how the game could reach those "performances"... i tried everything i could to understand how on earth it would have been possible to reach such speeds... but i soon came to the conclusion that BASIC was just too slow. Whatever was the magic it must have been something to do with the "BLOAD" command.

Now i am 36, in my past school-days i went to a technical (high)school where they taught me Z80 assembly and (mostly digital) electronics so now i have a better understanding of how the "magic" worked... but i still have some "missing" pieces.

I understand how cartridges work: you make your program in assembly, you compile it, you burn it into a EPROM starting at a certain address and that's pretty much it. But how did they store the binary programs into a cassette? I mean... if today i wanted to make a simple, Z80, program and store it to a cassette so that i could then load it with the BLOAD command... how could i do that? Are there any examples "out there"? Maybe with simple assembly examples that do something very simple and all the tools needed just for teaching purposes?

Thank you for any answer or link that could make me better understand this topic.

BTW, also... sorry for my horrible english, it is not my native language.

Login or register to post comments

By Daemos

Paragon (1713)

Daemos's picture

25-07-2014, 08:06

bload as used by basic requires a special header to be set in front of your assembly code. The same also applies for the .com files and even the cartridges. I remember to have asked the same thing before and had the correct answer to that. Just let me check.

Quoted from: http://www.msx.org/forum/development/msx-development/questio...

Quote:
db 0x0FE
dw start, endadr, start

org 0xc000
start: 
.
.
.
endadr: end

The asm parser will use the label "endadr:" as it's END adr and put's it in the first 7 bytes header as you declared in the beginning of your source.
The start adr, in this case, is the same as the "run" adr.

thats the default template to make a working .bin files which can be loaded with bload.

It may also be a good plan to check out map.grauw.nl

For the casette part you will need someone else. I have never worked with casettes just disks.

By Manuel

Ascended (16855)

Manuel's picture

25-07-2014, 09:40

If you have no assembler or tools, but you did write a machine language program, you simply make a basic program that pokes the ML code into memory and then you save it with the BSAVE command... On a tape that would be: BSAVE"CAS:name", [startaddr], [endaddr], [execution start addr]. It just dumps the RAM to the tape and adds the header from previous post in front of it (0xFE and the 3 addresses). This way BLOAD knows that it's a binary file, where to load it to, how long it is and where to jump to if the ,R option is given.

By gdx

Prophet (3676)

gdx's picture

25-07-2014, 10:29

If you assemble online with clrhome.org.

Quote:

.org $D000-7
.db $FE
.dw ProgStart
.dw ProgEnd
.dw ProgStart

ProgStart:
;
; Your program
;
ProgEnd:

Change $D000 value according to your needs, this is program start address.

By BernardBernoulli

Resident (34)

BernardBernoulli's picture

25-07-2014, 13:51

Thanks to everyone for your answers and links, they are very informative.
Just a couple more questions...

I see from your answers that you have to define a start-address... is that arbitrary? I mean, i remember that when i used to program Z80 all the programs had to start at a precise address (100h maybe? my memories are rusty) to make the program execute. Here can i decide any address i prefer? Are there preferred addresses? Is there a way to see this kind of information from a (commercial) cassette program? I mean... if i wanted to see where my old "Decathlon" game was stored in memory... how could i do that?

Manuel suggests to use BASIC's POKE to save ML code into RAM and then save it to cassette with BSAVE. Are there automated tools that do this (not only MSX-tools, also something i can run on today's computers)? Do you think that it would be possible to read an existing cartridge from BASIC byte by byte and save it to cassette with BSAVE somehow?

Thank you for your answers, now the whole process is a clearer and thank you for all your links. Just one more question... do you know any good book that would explain these things, in particular assembly programming for MSX with all the details? I guess they existed back in the 80ies.

Thank you again.

By Daemos

Paragon (1713)

Daemos's picture

25-07-2014, 14:01

Quote:

I see from your answers that you have to define a start-address... is that arbitrary? I mean, i remember that when i used to program Z80 all the programs had to start at a precise address (100h maybe? my memories are rusty)

The 100h adress is when you code for MSXDOS. Since you like to do your stuff in basic you can choose any adress. 0000-3FFFh is the BIOS 4000-7FFFh is the basic rom so you are left with 8000-FFFFh but I remember vaguely that 8000h is not the safest place to work from and C000-D000h is the safest place.

By Grauw

Ascended (9272)

Grauw's picture

25-07-2014, 14:09

DOS programs start at 100H.

BLOAD programs generally load in the Basic environment, which has ROM at address 0-7FFFH, so the program can be loaded at 8000H-D800H. The maximum address is actually a bit fussy, it depends on nr. of disk drives connected etc. HIMEM tells you the exact maximum addres on a specific computer, but D800H is a relatively safe maximum.

Please note that the Basic program also loads at 8000H, and has some variables in high memory, you don’t want to overwrite these. The highest memory address used by the Basic program can be set with the CLEAR command:

CLEAR &HC000

Now you can safely load your Assembly program at address C000H.

The starting address of the Basic program can be raised by poking the new starting address + 1 into address 0F676H and then reloading the program. E.g. to reload the Basic program at start address 0C000H in AUTOEXEC.BAS:

10 IF PEEK(&HF677) <> &HC0 THEN POKE &HC000,0:POKE &HF676,&H01:POKE &HF677,&HC0:RUN "AUTOEXEC.BAS"

The former method is the easiest to use, but the latter method is often used when the program needs to access multiple memory mapper pages (one mapper page goes from 8000H to 0C000H).

Though what’s really the easiest to use is to write a DOS program Smile. The amount of TPA RAM available there is very comfortable (nearly the entire 64K).

By Grauw

Ascended (9272)

Grauw's picture

25-07-2014, 14:17

Some resources:

MSX Assembly Page — information on MSX programming (incl. MSX-DOS)
Programming the Z80 (Rodnay Zaks) — a great book but not MSX-specific
MSX2 Technical Handbook (ASCII) — transscribed by konamiman, a lot of information

I know a couple of good books in Dutch as well, but that probably won’t do you any good :).

By Daemos

Paragon (1713)

Daemos's picture

25-07-2014, 14:16

+ in DOS you will have very convenient disk routines at your disposal

By BernardBernoulli

Resident (34)

BernardBernoulli's picture

25-07-2014, 14:28

Thank you again.

So, with "CLEAR $address" i can set the upper memory limit BASIC will use, then i can use the free memory beyond that point for my ML program.
Unfortunately i didn't have DOS back then, just BASIC (i had a MSX1), so i never really saw a "real" MSX run DOS.

Lets say i want to run a ML program with BLOAD "CAS:", R and then return to BASIC once it is done... do you think it would be possible? All the ML programs i tried up to now never return to BASIC once complete so i guess it is not as easy as it looks... although... if i don't mess with BASIC's memory... it should be safe to do so... so... how should i end my ML program to make it return to BASIC once complete?

By BernardBernoulli

Resident (34)

BernardBernoulli's picture

25-07-2014, 14:34

Grauw wrote:

Some resources:

MSX Assembly Page — information on MSX programming (incl. MSX-DOS)
Programming the Z80 (Rodnay Zaks) — a great book but not MSX-specific
MSX2 Technical Handbook (ASCII) — transscribed by konamiman, a lot of information

I know a couple of good books in Dutch as well, but that probably won’t do you any good :).

Thanx.
Yeah my Dutch is much much worse than my english... :P

It is sad actually... all these language barriers are making everything more difficult. Most of the documentation is probably in japanese only... and in Europe every one of us has its own language... so now we are left with books, messages, magazines, online-forums, etc that would give us a good deal of knowledge (and memories too, just think at the many magazines published in japanese, spanish, etc that would be fun to read) but that we can't read/understand because it is written in foreign languages.

Page 1/3
| 2 | 3