omsxctl.z80 3.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. ; MSX-DOS utility to execute openMSX commands from within the MSX.
  2. ;
  3. ; This can be used to e.g. integrate a MSX program in a build chain
  4. ; on the host computer.
  5. ;
  6. ; For example start openMSX from the command line like this:
  7. ; openmsx -script omsxctl.tcl -diska my_directory
  8. ;
  9. ; And inside my_directory/ put the a AUTOEXEC.BAT with content:
  10. ; omsxctl after time 100 "exit 1"
  11. ; my_tool my_data.in my_data.out
  12. ; omsxctl exit 0
  13. bdos: equ 0x5
  14. PutChr: equ 0x2
  15. ArgSize: equ 0x0080
  16. ArgData: equ 0x0081
  17. ScriptPort: equ 0x2d
  18. org 0x0100
  19. ; Detect whether the 'omsxctl.tcl' script is active.
  20. ld hl,ZeroStr ; empty command (doesn't produce output)
  21. scf
  22. out (ScriptPort),a ; script should change clear carry flag
  23. jr c,ErrNoScript
  24. ; Process command line.
  25. ld a,(ArgSize)
  26. or a
  27. jr z,ErrNoArgs
  28. ld hl,ArgData
  29. add a,l
  30. ld l,a
  31. ld (hl),0 ; write 0-terminator (needed for DOS1?)
  32. ; Execute command.
  33. ld hl,ArgData+1 ; skip first space
  34. ld de,ResultBuf
  35. ld bc,ResultBufSize
  36. out (ScriptPort),a
  37. ; Did the command give an error?
  38. jr nc,NoError
  39. ld hl,TxtCmdError
  40. push bc
  41. call Print
  42. pop bc
  43. NoError:
  44. ; Was the result string truncated?
  45. ld a,b
  46. and c
  47. inc a ; BC == 0xffff ?
  48. jr nz,NotTruncated
  49. ld hl,TxtTruncated
  50. call Print
  51. ld bc,ResultBufSize
  52. NotTruncated:
  53. ; Print the result string and translate \n to \r\n.
  54. ld hl,ResultBuf
  55. ResultLoop: ld a,b
  56. or c
  57. jr z,Done
  58. push hl
  59. push bc
  60. ld a,(hl)
  61. cp 10
  62. jr nz,Not10
  63. ld e,13
  64. ld c,PutChr
  65. call bdos
  66. ld a,10
  67. Not10: ld e,a
  68. ld c,PutChr
  69. call bdos
  70. pop bc
  71. pop hl
  72. inc hl
  73. dec bc
  74. jr ResultLoop
  75. Done: ld hl,TxtNewLine
  76. jr Print
  77. ErrNoScript: ld hl,TxtErrNoScript
  78. jr Print
  79. ErrNoArgs: ld hl,TxtErrNoArgs
  80. ;jr Print
  81. Print: ld a,(hl)
  82. or a
  83. ret z
  84. ld e,a
  85. ld c,PutChr
  86. push hl
  87. call bdos
  88. pop hl
  89. inc hl
  90. jr Print
  91. TxtErrNoScript: db "The 'omsxctl.tcl' script is not active.", 0
  92. TxtErrNoArgs: db "No arguments given.", 0
  93. TxtCmdError: db "ERROR: ", 0
  94. TxtTruncated: db "[truncated]"
  95. TxtNewLine: db 13, 10
  96. ZeroStr: db 0
  97. ResultBuf:
  98. ResultBufSize: equ 0x4000 - $