| e8555c89 Andy McCall |
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 |
|
| 14 |
bdos: equ 0x5 |
| 15 |
PutChr: equ 0x2 |
| 16 |
ArgSize: equ 0x0080 |
| 17 |
ArgData: equ 0x0081 |
| 18 |
ScriptPort: equ 0x2d |
| 19 |
|
| 20 |
org 0x0100 |
| 21 |
|
| 22 |
; Detect whether the 'omsxctl.tcl' script is active. |
| 23 |
ld hl,ZeroStr ; empty command (doesn't produce output) |
| 24 |
scf |
| 25 |
out (ScriptPort),a ; script should change clear carry flag |
| 26 |
jr c,ErrNoScript |
| 27 |
|
| 28 |
; Process command line. |
| 29 |
ld a,(ArgSize) |
| 30 |
or a |
| 31 |
jr z,ErrNoArgs |
| 32 |
ld hl,ArgData |
| 33 |
add a,l |
| 34 |
ld l,a |
| 35 |
ld (hl),0 ; write 0-terminator (needed for DOS1?) |
| 36 |
|
| 37 |
; Execute command. |
| 38 |
ld hl,ArgData+1 ; skip first space |
| 39 |
ld de,ResultBuf |
| 40 |
ld bc,ResultBufSize |
| 41 |
out (ScriptPort),a |
| 42 |
|
| 43 |
; Did the command give an error? |
| 44 |
jr nc,NoError |
| 45 |
ld hl,TxtCmdError |
| 46 |
push bc |
| 47 |
call Print |
| 48 |
pop bc |
| 49 |
NoError: |
| 50 |
|
| 51 |
; Was the result string truncated? |
| 52 |
ld a,b |
| 53 |
and c |
| 54 |
inc a ; BC == 0xffff ? |
| 55 |
jr nz,NotTruncated |
| 56 |
ld hl,TxtTruncated |
| 57 |
call Print |
| 58 |
ld bc,ResultBufSize |
| 59 |
NotTruncated: |
| 60 |
|
| 61 |
; Print the result string and translate \n to \r\n. |
| 62 |
ld hl,ResultBuf |
| 63 |
ResultLoop: ld a,b |
| 64 |
or c |
| 65 |
jr z,Done |
| 66 |
push hl |
| 67 |
push bc |
| 68 |
ld a,(hl) |
| 69 |
cp 10 |
| 70 |
jr nz,Not10 |
| 71 |
ld e,13 |
| 72 |
ld c,PutChr |
| 73 |
call bdos |
| 74 |
ld a,10 |
| 75 |
Not10: ld e,a |
| 76 |
ld c,PutChr |
| 77 |
call bdos |
| 78 |
pop bc |
| 79 |
pop hl |
| 80 |
inc hl |
| 81 |
dec bc |
| 82 |
jr ResultLoop |
| 83 |
|
| 84 |
Done: ld hl,TxtNewLine |
| 85 |
jr Print |
| 86 |
|
| 87 |
|
| 88 |
ErrNoScript: ld hl,TxtErrNoScript |
| 89 |
jr Print |
| 90 |
|
| 91 |
ErrNoArgs: ld hl,TxtErrNoArgs |
| 92 |
;jr Print |
| 93 |
|
| 94 |
Print: ld a,(hl) |
| 95 |
or a |
| 96 |
ret z |
| 97 |
ld e,a |
| 98 |
ld c,PutChr |
| 99 |
push hl |
| 100 |
call bdos |
| 101 |
pop hl |
| 102 |
inc hl |
| 103 |
jr Print |
| 104 |
|
| 105 |
|
| 106 |
TxtErrNoScript: db "The 'omsxctl.tcl' script is not active.", 0 |
| 107 |
TxtErrNoArgs: db "No arguments given.", 0 |
| 108 |
TxtCmdError: db "ERROR: ", 0 |
| 109 |
TxtTruncated: db "[truncated]" |
| 110 |
TxtNewLine: db 13, 10 |
| 111 |
ZeroStr: db 0 |
| 112 |
|
| 113 |
ResultBuf: |
| 114 |
ResultBufSize: equ 0x4000 - $ |