_text_echo.tcl 1.2 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. # TODO: add a way to turn this off...
  2. namespace eval text_echo {
  3. set_help_text text_echo \
  4. {Echoes all characters printed in text mode to stderr, meaning they will appear on the command line that openMSX was started from.
  5. }
  6. variable graph
  7. variable escape
  8. variable escape_count
  9. proc text_echo {} {
  10. variable graph 0
  11. variable escape 0
  12. variable escape_count 0
  13. debug set_bp 0x0018 {[pc_in_slot 0 0]} {text_echo::print}
  14. debug set_bp 0x00A2 {[pc_in_slot 0 0]} {text_echo::print}
  15. return ""
  16. }
  17. proc print {} {
  18. variable graph
  19. variable escape
  20. variable escape_count
  21. set char [reg A]
  22. if {$graph} {
  23. #puts -nonewline stderr [format "\[G%x\]" $char]
  24. set graph 0
  25. } elseif {$escape} {
  26. #puts -nonewline stderr [format "\[E%x\]" $char]
  27. if {$escape_count == 0} {
  28. if {$char == 0x59} {
  29. set escape_count 2
  30. } else {
  31. set escape_count 1
  32. }
  33. } else {
  34. incr escape_count -1
  35. if {$escape_count == 0} {
  36. set escape 0
  37. }
  38. }
  39. } elseif {$char == 0x01} {
  40. set graph 1
  41. } elseif {$char == 0x1B} {
  42. set escape 1
  43. } elseif {$char == 0x0A || $char >= 0x20} {
  44. puts -nonewline stderr [format %c $char]
  45. } else {
  46. #puts -nonewline stderr [format "\[N%x\]" $char]
  47. }
  48. }
  49. namespace export text_echo
  50. } ;# namespace text_echo
  51. namespace import text_echo::*