_widgets.tcl 4.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154
  1. namespace eval debug_widgets {
  2. #TODO: Help Texts
  3. proc toggle_show_palette {} {
  4. if {[osd exists palette_viewer]} {
  5. osd destroy palette_viewer
  6. return ""
  7. }
  8. osd create rectangle palette_viewer \
  9. -x 4 -y 4 -w 56 -h 194 -rgba 0x00000080 \
  10. -borderrgba 0xffffffff -bordersize 1
  11. for {set i 0} {$i < 16} {incr i} {
  12. osd create rectangle palette_viewer.$i \
  13. -x 20 -y [expr {($i * 12) + 2}] \
  14. -w 10 -h 10 \
  15. -rgba 0xff0000ff \
  16. -borderrgba 0xffffffff -bordersize 1
  17. osd create text palette_viewer.$i.text \
  18. -x -16 \
  19. -rgba 0xffffffff \
  20. -size 10 \
  21. -text ""
  22. }
  23. update_palette
  24. return ""
  25. }
  26. proc update_palette {} {
  27. if {![osd exists palette_viewer]} return
  28. for {set i 0} {$i < 16} {incr i} {
  29. set color [getcolor $i]
  30. set r [string range $color 0 0]
  31. set g [string range $color 1 1]
  32. set b [string range $color 2 2]
  33. set rgbval [expr {($r << (5 + 16)) + ($g << (5 + 8)) + ($b << 5)}]
  34. osd configure palette_viewer.$i -rgb $rgbval
  35. osd configure palette_viewer.$i.text -text "[format %02d $i] $color"
  36. }
  37. after frame [namespace code update_palette]
  38. }
  39. proc toggle_vdp_reg_viewer {} {
  40. if {[osd exists vdp_reg_viewer]} {
  41. osd destroy vdp_reg_viewer
  42. osd destroy vdp_statreg_viewer
  43. return ""
  44. }
  45. set fontsize 9
  46. # note: this method of VDP detection will fail on e.g. MSX1 machines with V9938
  47. set vdpreg [expr {([debug read "slotted memory" 0x2d]) ? 47 : 8}]
  48. set vdpsta [expr {([debug read "slotted memory" 0x2d]) ? 10 : 1}]
  49. osd create rectangle vdp_reg_viewer \
  50. -x 0 \
  51. -y 0 \
  52. -h 480 \
  53. -w [expr {$fontsize * 8}] \
  54. -rgba 0x00000080
  55. osd create rectangle vdp_statreg_viewer \
  56. -x [expr {($fontsize * 8) + 16}] \
  57. -y 0 \
  58. -h 480 \
  59. -w [expr {$fontsize * 8}] \
  60. -rgba 0x00000080
  61. for {set i 0} {$i < $vdpreg} {incr i} {
  62. osd create rectangle vdp_reg_viewer.indi$i \
  63. -x 0 \
  64. -y [expr {$i * $fontsize}] \
  65. -w [expr {$fontsize * 8}] \
  66. -h $fontsize \
  67. -rgba 0xff0000ff \
  68. -fadeTarget 0 \
  69. -fadePeriod 1
  70. osd create text vdp_reg_viewer.labl$i \
  71. -x 0 \
  72. -y [expr {$i * $fontsize}] \
  73. -size $fontsize \
  74. -text "R# [format %02d $i]:" \
  75. -rgba 0xffffffff
  76. osd create text vdp_reg_viewer.stat$i \
  77. -x [expr {$fontsize * 4}] \
  78. -y [expr {$i * $fontsize}] \
  79. -size $fontsize \
  80. -text "[format 0x%02X [debug read VDP\ regs $i]]" \
  81. -rgba 0xffffffff
  82. }
  83. for {set i 0} {$i < $vdpsta} {incr i} {
  84. osd create rectangle vdp_statreg_viewer.indi$i \
  85. -x 0 \
  86. -y [expr {$i * $fontsize}] \
  87. -w [expr {$fontsize * 8}] \
  88. -h $fontsize \
  89. -rgba 0xff0000ff \
  90. -fadeTarget 0 \
  91. -fadePeriod 1
  92. osd create text vdp_statreg_viewer.labl$i \
  93. -x 0 \
  94. -y [expr {$i * $fontsize}] \
  95. -size $fontsize \
  96. -text "S# [format %02d $i]:" \
  97. -rgba 0xffffffff
  98. osd create text vdp_statreg_viewer.stat$i \
  99. -x [expr {$fontsize * 4}] \
  100. -y [expr {$i * $fontsize}] \
  101. -size $fontsize \
  102. -text "[format 0x%02X [debug read VDP\ status\ regs $i]]" \
  103. -rgba 0xffffffff
  104. }
  105. update_vdp_reg_viewer
  106. return ""
  107. }
  108. proc update_vdp_reg_viewer {} {
  109. if {![osd exists vdp_reg_viewer]} return
  110. # note: this method of VDP detection will fail on e.g. MSX1 machines with V9938
  111. set vdpreg [expr {([debug read "slotted memory" 0x2d]) ? 47 : 8}]
  112. set vdpsta [expr {([debug read "slotted memory" 0x2d]) ? 10 : 1}]
  113. for {set i 0} {$i < $vdpreg} {incr i} {
  114. set vdp_stat "[format 0x%02X [debug read VDP\ regs $i]]"
  115. if {$vdp_stat ne [osd info vdp_reg_viewer.stat$i -text]} {
  116. osd configure vdp_reg_viewer.stat$i -text "$vdp_stat"
  117. osd configure vdp_reg_viewer.indi$i -fadeCurrent 1
  118. }
  119. }
  120. for {set i 0} {$i < $vdpsta} {incr i} {
  121. set vdp_stat "[format 0x%02X [debug read VDP\ status\ regs $i]]"
  122. if {$vdp_stat ne [osd info vdp_statreg_viewer.stat$i -text]} {
  123. osd configure vdp_statreg_viewer.stat$i -text "$vdp_stat"
  124. osd configure vdp_statreg_viewer.indi$i -fadeCurrent 1
  125. }
  126. }
  127. after frame [namespace code update_vdp_reg_viewer]
  128. }
  129. namespace export toggle_show_palette
  130. namespace export toggle_vdp_reg_viewer
  131. } ;# namespace debug_widgets
  132. namespace import debug_widgets::*