Subversion Repositories SvarDOS

Rev

Rev 490 | Rev 519 | Go to most recent revision | Show entire file | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 490 Rev 517
Line 46... Line 46...
46
EXEC_PARAM_REC db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0   ; +5Dh
46
EXEC_PARAM_REC db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0   ; +5Dh
47
 
47
 
48
; Program to execute, preset by SvarCOM (128 bytes, ASCIIZ)  ; +6Bh
48
; Program to execute, preset by SvarCOM (128 bytes, ASCIIZ)  ; +6Bh
49
EXECPROG dd 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
49
EXECPROG dd 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
50
 
50
 
-
 
51
; offset within EXECPROG for out and in filenames in case stdin or stdout
-
 
52
; needs to be redirected (0xffff=no redirection)
-
 
53
REDIR_OUTFIL dw 0xffff    ; +EBh
-
 
54
REDIR_INFIL dw 0xffff     ; +EDh
-
 
55
REDIR_OUTAPPEND dw 0      ; +EFh
-
 
56
 
51
skipsig:         ; +EBh
57
skipsig:         ; +F1h
52
 
58
 
53
; set up CS=DS=SS and point SP to my private stack buffer
59
; set up CS=DS=SS and point SP to my private stack buffer
54
mov ax, cs
60
mov ax, cs
55
mov ds, ax
61
mov ds, ax
56
mov es, ax
62
mov es, ax
57
mov ss, ax
63
mov ss, ax
58
mov sp, STACKPTR
64
mov sp, STACKPTR
59
 
65
 
-
 
66
; revert stdin/stdout redirections (if any) to their initial state
-
 
67
call REVERT_REDIR_IF_ANY
-
 
68
 
-
 
69
; redirect stdout if required
-
 
70
call REDIR_OUTFILE_IF_REQUIRED
-
 
71
 
60
; should I executed command.com or a pre-set application?
72
; should I executed command.com or a pre-set application?
61
or [EXECPROG], byte 0
73
or [EXECPROG], byte 0
62
jz EXEC_COMMAND_COM
74
jz EXEC_COMMAND_COM
63
 
75
 
64
; TODO: perhaps I should call the DOS SetPSP function here? But if I do, the
76
; TODO: perhaps I should call the DOS SetPSP function here? But if I do, the
Line 146... Line 158...
146
; called as respawn (as opposed to being invoked as a normal application)
158
; called as respawn (as opposed to being invoked as a normal application)
147
; this allows multiple copies of SvarCOM to stack upon each other.
159
; this allows multiple copies of SvarCOM to stack upon each other.
148
CMDTAIL db 0x01, 0x0A, 0x0D
160
CMDTAIL db 0x01, 0x0A, 0x0D
149
 
161
 
150
ERRLOAD db "ERR x, FAILED TO LOAD COMMAND.COM", 13, 10, '$'
162
ERRLOAD db "ERR x, FAILED TO LOAD COMMAND.COM", 13, 10, '$'
-
 
163
 
-
 
164
; variables used to revert stdin/stdout to their initial state
-
 
165
OLD_STDOUT dw 0xffff
-
 
166
OLD_STDIN  dw 0xffff
-
 
167
 
-
 
168
 
-
 
169
; *** ROUTINES ***************************************************************
-
 
170
 
-
 
171
 
-
 
172
; revert stdin/stdout redirections (if any) to their initial state
-
 
173
; all memory accesses are CS-prefixes because this code may be called at
-
 
174
; times when DS is out of whack.
-
 
175
REVERT_REDIR_IF_ANY:
-
 
176
; is stdout redirected?
-
 
177
mov bx, [OLD_STDOUT]
-
 
178
cmp bx, 0xffff
-
 
179
je STDOUT_DONE
-
 
180
; revert the stdout handle (dst in BX alread)
-
 
181
mov cx, 1        ; src handle (1=stdout)
-
 
182
mov ah, 0x46     ; redirect a handle
-
 
183
int 0x21
-
 
184
mov [OLD_STDOUT], word 0xffff ; mark stdout as "not redirected"
-
 
185
STDOUT_DONE:
-
 
186
ret
-
 
187
 
-
 
188
 
-
 
189
; redirect stdout if REDIR_OUTFIL points to something
-
 
190
REDIR_OUTFILE_IF_REQUIRED:
-
 
191
mov si, [REDIR_OUTFIL]
-
 
192
cmp si, 0xffff
-
 
193
je NO_STDOUT_REDIR
-
 
194
add si, EXECPROG       ; si=output file
-
 
195
mov ax, 0x6c00         ; Extended Open/Create
-
 
196
mov bx, 1              ; access mode (0=read, 1=write, 2=r+w)
-
 
197
xor cx, cx             ; file attribs when(if) file is created (0=normal)
-
 
198
mov dx, [REDIR_OUTAPPEND] ; action if file exist (0x11=open, 0x12=truncate)
-
 
199
int 0x21               ; ax=handle on success (CF clear)
-
 
200
mov [REDIR_OUTFIL], word 0xffff
-
 
201
jc NO_STDOUT_REDIR     ; TODO: abort with an error message instead
-
 
202
; duplicate current stdout so I can revert it later
-
 
203
push ax                ; save my file handle in stack
-
 
204
mov ah, 0x45           ; duplicate file handle BX
-
 
205
mov bx, 1              ; 1=stdout
-
 
206
int 0x21               ; ax=new (duplicated) file handle
-
 
207
mov [OLD_STDOUT], ax   ; save the old handle in memory
-
 
208
; redirect stdout to my file
-
 
209
pop bx                 ; dst handle
-
 
210
mov cx, 1              ; src handle (1=stdout)
-
 
211
mov ah, 0x46           ; "redirect a handle"
-
 
212
int 0x21
-
 
213
; close the original file handle, I no longer need it
-
 
214
mov ah, 0x3e           ; close a file handle (handle in BX)
-
 
215
NO_STDOUT_REDIR:
-
 
216
ret