PC tool to tokenize MSX basic

Page 1/2
| 2

By dvik

Prophet (2200)

dvik's picture

05-12-2008, 07:59

I'm wondering if there are any PC tools to tokenize MSX basic programs. I want to write my programs in a regular PC editor, and create a tokenized .bas file that I can run on my MSX. Any ideas if there are any tools like that?

Login or register to post comments

By ARTRAG

Enlighted (6323)

ARTRAG's picture

05-12-2008, 09:44

The closest think I know does the reverse and is by vincent van dam
http://home.kabelfoon.nl/~vincentd/download/list.zip

BTW, the msx basic can safely load basic programs in plain ASCII with the very same load command that you use for tokenized files.

The things I do not remember are the convention on end line (CR or CR/NL) and if the case of the command matter.
To solve the issue, try to save a test file with save"test.bas",A see how the basic behavies and use the same conventions

By wouter_

Champion (421)

wouter_'s picture

05-12-2008, 12:32

I also don't know an existing PC tool to do this. But by using the openMSX scripting capabilities you can easily turn ARTRAG's approach into an automated PC tool:

### tokenize.tcl ###
# Transform a ASCII basic program to a tokenized version
#   input: prog.asc
#   output prog.bas
#   start with:  openmsx -script tokenize.tcl

proc do_stuff1 {} {
  # insert openMSX ramdisk in the MSX disk drive
  diska ramdsk
  # import host file to ramdisk
  diskmanipulator import diska "prog.asc"
  # instruct MSX to load the BASIC program
  type "load\"prog.asc\"\r"
  # give MSX some time to process this
  after time 20 do_stuff2
}

proc do_stuff2 {} {
  # save BASIC prog back to disk (in tokenized form)
  type "save\"prog.bas\"\r"
  # again wait till MSX has processed this
  after time 20 do_stuff3
}

proc do_stuff3 {} {
  # export the content of the MSX disk to the host
  diskmanipulator export diska .
  exit
}

# don't store the settings below for future openmsx sessions
set save_settings_on_exit false
# don't show MSX screen (remove if you want to see what's going on)
set renderer none
# go as fast as possible
set throttle off

# give emulated MSX some time to boot
after time 20 do_stuff1

Save this script to a file named "tokenize.tcl". In the same directory put your ASCII basic source in a file named "prog.asc". Then execute "openmsx -script tokenize.tcl". As result this will save the tokenized BASIC program to the file "prog.bas".

I hope this helps.

By dvik

Prophet (2200)

dvik's picture

05-12-2008, 20:43

What I really need is to be able to have .bas files as source files in a gmake based build system that outputs a basic ROM file. I already have the part that takes a tokenized basic file and makes a .rom file. For the Yahtzee game I did for msxdev last year, I did kindof what wouter described but in blueMSX, but thats hard to automate in a makefile.

Perhaps there are some tools that goes all the way, from an un-tokenized .bas file to a .rom file. That works too.

By dvik

Prophet (2200)

dvik's picture

05-12-2008, 20:45

I read your post more detailed wouter, and it looks like this could be done from the command line without opening the openMSX gui, or?

By wouter_

Champion (421)

wouter_'s picture

05-12-2008, 22:25

That's right it works without opening the gui. And it's certainly possible to extend this script to create a ROM file. Or use it as a step in a makefile.

By dvik

Prophet (2200)

dvik's picture

05-12-2008, 22:50

Ah good. I'll try it out. So for my build system I could create a /tools/openMSX/ directory in my build system, place openmsx and a machine config and the script there, and just invoke it from my Makefile, right?

By Vampier

Prophet (2311)

Vampier's picture

06-12-2008, 07:05

dvik you can even use the listing command in openMSX do to the reverse Wink (thanks to Vincent's script mentioned above)

By wouter_

Champion (421)

wouter_'s picture

06-12-2008, 09:36

dvik: It's easiest if you use your global openMSX installation, running this script won't disturb that installation in any way. And you're right you need to run this on an emulated MSX that has a diskdrive and MSX-BASIC (the default CBIOS config won't do). So either make such a config your default or pass the -machine option on the openMSX commandline.

By dvik

Prophet (2200)

dvik's picture

07-12-2008, 18:59

Thanks, it worked almost right away. The only thing was that the timeout for loading and saving the basic program was too short for my rather big basic program. I increased the timeout to 100 and then it worked perfect. I ended up putting a slimmed down openMSX installation in my tools directory since I don't have a global install of it, plus I want the build environment to be easily portable and it works great.

By dvik

Prophet (2200)

dvik's picture

07-12-2008, 20:11

I actually ended up making a different script that does the whole conversion from a basic file to a rom file:

### tokenize.tcl ###
# Transform a basic program to a basic rom
#   input: prog.bas
#   output prog.bin
#   start with:  openmsx -script basictorom.tcl

proc do_stuff1 {} {
  # insert openMSX ramdisk in the MSX disk drive
  diska ramdsk
  # import host file to ramdisk
  diskmanipulator import diska "prog.bas"
  # change basic start address
  type "POKE &HF676,&H11\r"
  type "POKE &HF677,&H80\r"
  type "POKE &H8010,0\r"
  # instruct MSX to load the BASIC program
  type "load\"prog.bas\"\r"
  # give MSX some time to process this
  after time 100 do_stuff2
}

proc do_stuff2 {} {
  # Add ROM header
  type "POKE &H8000,&H41\r"
  type "POKE &H8001,&H42\r"
  type "POKE &H8002,0\r"
  type "POKE &H8003,0\r"
  type "POKE &H8004,0\r"
  type "POKE &H8005,0\r"
  type "POKE &H8006,0\r"
  type "POKE &H8007,0\r"
  type "POKE &H8008,&H10\r"
  type "POKE &H8009,&H80\r"
  type "POKE &H800A,0\r"
  type "POKE &H800B,0\r"
  type "POKE &H800C,0\r"
  type "POKE &H800D,0\r"
  type "POKE &H800E,0\r"
  type "POKE &H800F,0\r"
  type "POKE &H8010,0\r"
  # save ROM file
  type "bsave\"prog.bin\",&H8000,&HBFFF\r"
  # again wait till MSX has processed this
  after time 100 do_stuff3
}

proc do_stuff3 {} {
  # export the content of the MSX disk to the host
  diskmanipulator export diska .
  exit
}

# don't store the settings below for future openmsx sessions
set save_settings_on_exit false
# don't show MSX screen (remove if you want to see what's going on)
set renderer none
# go as fast as possible
set throttle off

# give emulated MSX some time to boot
after time 20 do_stuff1

The only minor thing that it doesn't to 100% is to strip off the bload bin header. Any way to add that to the disk maipulator as well?

Now I'm using a very tiny tniasm program to strip out the header from the output of the openmsx generated bin file and it works ok:

    fname "prog.rom"
incbin "prog.bin",7
Page 1/2
| 2