OXYGENHUB
◆ main openmsx / Contrib / basictorom.tcl
2.1 KiB · Tcl · last changed chore(): initial commit 1 month ago source blame history raw
1
### basictorom.tcl ###
2
#
3
# This script was developed together with Daniel Vik to have an automated tool
4
# to convert BASIC programs to ROM files. See this forum thread for more
5
# details:
6
#
7
#   http://www.msx.org/forumtopic9249.html
8
#
9
# To use it, put a file 'prog.bas' in the current directory (can be either in
10
# ascii format or an already tokenized basic file). Then execute this script by
11
# using the openMSX commandline. And after a few seconds the ROM image
12
# 'prog.rom' will be generated.
13
#
14
#   input: prog.bas
15
#   output prog.rom
16
#   start with:  openmsx -script basictorom.tcl
17
#
18
# Note: This script only works on MSX machines that have a disk drive and have
19
#       MSX-BASIC built-in. So for example it won't work on the default C-bios
20
#       based machines. So either select a different MSX machine as your
21
#       default machine, or pass the '-machine <machine-config>' as extra
22
#       option when starting openMSX.
23
#
24
25
proc do_stuff1 {} {
26
  # insert openMSX ramdisk in the MSX disk drive
27
  diska ramdsk
28
29
  # import host file to ramdisk
30
  diskmanipulator import diska "prog.bas"
31
32
  # change basic start address
33
  poke16 0xf676 0x8011
34
35
  # add rom header
36
  poke   0x8000 0x41
37
  poke   0x8001 0x42
38
  poke16 0x8002 0x0000
39
  poke16 0x8004 0x0000
40
  poke16 0x8006 0x0000
41
  poke16 0x8008 0x8010
42
  poke16 0x800a 0x0000
43
  poke16 0x800c 0x0000
44
  poke16 0x800e 0x0000
45
  poke   0x8010 0x00
46
47
  # instruct MSX to load the BASIC program
48
  type "load\"prog.bas\"\r"
49
50
  # give MSX some time to process this
51
  #  wait long enough so that even very long BASIC programs can be loaded
52
  after time 100 do_stuff2
53
}
54
55
proc do_stuff2 {} {
56
  # save rom file
57
  set data [debug read_block "memory" 0x8000 0x4000]
58
  set file [open "prog.rom" "WRONLY CREAT TRUNC"]
59
  fconfigure $file -translation binary
60
  puts -nonewline $file $data
61
  close $file
62
63
  # exit emulator
64
  exit
65
}
66
67
# don't store the settings below for future openmsx sessions
68
set save_settings_on_exit false
69
# don't show MSX screen (remove if you want to see what's going on)
70
set renderer none
71
# go as fast as possible
72
set throttle off
73
74
# give emulated MSX some time to boot
75
after time 20 do_stuff1