basictorom.tcl 2.1 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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. proc do_stuff1 {} {
  25. # insert openMSX ramdisk in the MSX disk drive
  26. diska ramdsk
  27. # import host file to ramdisk
  28. diskmanipulator import diska "prog.bas"
  29. # change basic start address
  30. poke16 0xf676 0x8011
  31. # add rom header
  32. poke 0x8000 0x41
  33. poke 0x8001 0x42
  34. poke16 0x8002 0x0000
  35. poke16 0x8004 0x0000
  36. poke16 0x8006 0x0000
  37. poke16 0x8008 0x8010
  38. poke16 0x800a 0x0000
  39. poke16 0x800c 0x0000
  40. poke16 0x800e 0x0000
  41. poke 0x8010 0x00
  42. # instruct MSX to load the BASIC program
  43. type "load\"prog.bas\"\r"
  44. # give MSX some time to process this
  45. # wait long enough so that even very long BASIC programs can be loaded
  46. after time 100 do_stuff2
  47. }
  48. proc do_stuff2 {} {
  49. # save rom file
  50. set data [debug read_block "memory" 0x8000 0x4000]
  51. set file [open "prog.rom" "WRONLY CREAT TRUNC"]
  52. fconfigure $file -translation binary
  53. puts -nonewline $file $data
  54. close $file
  55. # exit emulator
  56. exit
  57. }
  58. # don't store the settings below for future openmsx sessions
  59. set save_settings_on_exit false
  60. # don't show MSX screen (remove if you want to see what's going on)
  61. set renderer none
  62. # go as fast as possible
  63. set throttle off
  64. # give emulated MSX some time to boot
  65. after time 20 do_stuff1