callbackprocs.tcl 4.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # Callback on read from uninitialized memory (UMR). Not enabled by default.
  2. set_help_text umrcallback \
  3. {This is an example of a UMR callback function. You can set the "umr_callback"
  4. setting in openMSX to "umrcallback" and this function will be called whenever
  5. openMSX detects a read from uninitialized memory. It might be a good idea to
  6. go into 'debug break' mode in this callback, so that you can easily examine
  7. what is going on which has caused the UMR.
  8. @param addr The absolute address in the RAM device.
  9. @param name The name of the RAM device.
  10. }
  11. proc umrcallback {addr name} {
  12. puts stderr [format "UMR detected in RAM device \"$name\", offset: 0x%04X, PC: 0x%04X" $addr [reg PC]]
  13. }
  14. #set umr_callback umrcallback
  15. # Callback on changing the VDP command registers while a command is still in
  16. # progress. Not enabled by default.
  17. set_help_text vdpcmdinprogresscallback \
  18. {This is an example of a vdpcmdinprogress callback function. To use it execute
  19. set vdpcmdinprogress_callback vdpcmdinprogresscallback
  20. After changing that setting this proc will be called whenever openMSX detects a
  21. write to a VDP command engine register while there's still a VDP command in
  22. progress. Often this is an indication of a bug in the MSX program. This example
  23. callback proc only prints the register number, the value that was being written
  24. and the program counter. Feel free to write your own callback procs. For
  25. example it might be a good idea to enter 'debug break' mode in your callback,
  26. so that you can easily examine what is going on.
  27. @param reg The VDP command engine register number that was being written
  28. This is in range 0..14. Note that it's OK to write register 12
  29. while a command is in progress. So this callback will not be
  30. triggered for writes to register 12.
  31. @param val The value that was being written.
  32. }
  33. proc vdpcmdinprogresscallback {reg val} {
  34. puts stderr [format "Write to VDP command engine detected while there's still a command in progress: reg = %d, val = %d, PC = 0x%04X" [expr {$reg + 32}] $val [reg PC]]
  35. }
  36. #set vdpcmdinprogress_callback vdpcmdinprogresscallback
  37. # Callback on setting invalid PSG port directions.
  38. set psg_directions_warning_printed false
  39. proc psgdirectioncallback {} {
  40. if {$::psg_directions_warning_printed} return
  41. set ::psg_directions_warning_printed true
  42. message {The running MSX software has set unsafe PSG port directions.
  43. Real (older) MSX machines can get damaged by this.} warning
  44. }
  45. set invalid_psg_directions_callback psgdirectioncallback
  46. # Callback on setting an invalid PPI mode.
  47. set ppi_mode_warning_printed false
  48. proc ppimodecallback {} {
  49. if {$::ppi_mode_warning_printed} return
  50. set ::ppi_mode_warning_printed true
  51. message {Invalid PPI mode selected. This is not yet correctly emulated. On a real MSX this will most likely hang.} warning
  52. }
  53. set invalid_ppi_mode_callback ppimodecallback
  54. # Callback on DI;HALT.
  55. proc dihaltcallback {} {
  56. set machine [machine_info type]
  57. if {[string match "MSX*" $machine] || $machine eq "SVI"} { # These machines do not use NMI.
  58. message "DI; HALT detected, which means a hang. You can just as well reset the machine now..." warning
  59. }
  60. }
  61. set di_halt_callback dihaltcallback
  62. # Callback on too fast VRAM read/write, not enabled by default
  63. proc warn_too_fast_vram_access {} {
  64. message [format "Too fast VRAM access PC=0x%04x Y-pos=%d" [reg PC] [machine_info VDP_msx_y_pos]] warning
  65. }
  66. proc debug_too_fast_vram_access {} {
  67. warn_too_fast_vram_access
  68. debug break
  69. }
  70. #set VDP.too_fast_vram_access_callback debug_too_fast_vram_access
  71. #set VDP.too_fast_vram_access_callback warn_too_fast_vram_access
  72. proc sensorkidportstatuscallback {port value} {
  73. message "Sensor Kid port $port has been [expr {$value ? "enabled" : "disabled"}]" info
  74. }
  75. proc sensorkidacquirecallback {port} {
  76. set time [machine_info time]
  77. switch $port {
  78. 0 { # Sine
  79. return [expr {int(sin($time * 0.1) * 127.0) + 128}]
  80. }
  81. 1 { # Sawtooth
  82. return [expr {int($time * 10.0) % 256}]
  83. }
  84. 2 { # Triangle
  85. set t [expr {int($time * 4.0) % 512}]
  86. return [expr {($t > 255) ? (511 - $t) : $t}]
  87. }
  88. default {
  89. return 255
  90. }
  91. }
  92. }
  93. set sensor_kid_port_status_callback sensorkidportstatuscallback
  94. set sensor_kid_acquire_callback sensorkidacquirecallback
  95. # show message (also) as OSD message
  96. set message_callback osd::display_message