Subversion Repositories SvarDOS

Rev

Rev 448 | Rev 459 | Go to most recent revision | Only display areas with differences | Ignore whitespace | Details | Blame | Last modification | View Log | RSS feed

Rev 448 Rev 450
1
;
1
;
2
; rmod - resident module of the SvarCOM command interpreter
2
; rmod - resident module of the SvarCOM command interpreter
3
;
3
;
4
; Copyright (C) 2021 Mateusz Viste
4
; Copyright (C) 2021 Mateusz Viste
5
; MIT license
5
; MIT license
6
;
6
;
7
; this is installed in memory by the transient part of SvarCOM. it has only
7
; this is installed in memory by the transient part of SvarCOM. it has only
8
; two jobs: providing a resident buffer for command history, environment, etc
8
; two jobs: providing a resident buffer for command history, environment, etc
9
; and respawning COMMAND.COM whenever necessary.
9
; and respawning COMMAND.COM whenever necessary.
10
 
10
 
11
CPU 8086
11
CPU 8086
12
org 0h           ; this is meant to be executed without a PSP
12
org 0h           ; this is meant to be executed without a PSP
13
 
13
 
14
section .text    ; all goes into code segment
14
section .text    ; all goes into code segment
15
 
15
 
16
                 ; offset
16
                 ; offset
17
SIG1 dw 0x1983   ;  +0
17
SIG1 dw 0x1983   ;  +0
18
SIG2 dw 0x1985   ;  +2
18
SIG2 dw 0x1985   ;  +2
19
SIG3 dw 0x2017   ;  +4
19
SIG3 dw 0x2017   ;  +4
20
SIG4 dw 0x2019   ;  +6
20
SIG4 dw 0x2019   ;  +6
21
 
21
 
22
; environment segment - this is updated by SvarCOM at init time
22
; environment segment - this is updated by SvarCOM at init time
23
ENVSEG   dw 0    ;  +8
23
ENVSEG   dw 0    ;  +8
24
 
24
 
25
; exit code of last application
25
; exit code of last application
26
LEXCODE  dw 0    ; +0Ah
26
LEXCODE  dw 0    ; +0Ah
27
 
27
 
28
; input buffer used for the "previous command" history
-
 
29
BUF000 db 128, 0 ; +0Ch
-
 
30
BUF064 db "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"
-
 
31
BUF128 db "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"
-
 
32
 
-
 
33
; offset of the COMSPEC variable in the environment block, 0 means "use
28
; offset of the COMSPEC variable in the environment block, 0 means "use
34
; boot drive". this value is patched by the transient part of COMMAND.COM
29
; boot drive". this value is patched by the transient part of COMMAND.COM
35
COMSPECPTR dw 0  ; +8Eh
30
COMSPECPTR dw 0  ; +0Ch
36
 
31
 
37
; fallback COMSPEC string used if no COMPSEC is present in the environment
32
; fallback COMSPEC string used if no COMPSEC is present in the environment
38
; drive. drive is patched by the transient part of COMMAND.COM
33
; drive. drive is patched by the transient part of COMMAND.COM
39
COMSPECBOOT db "@:\COMMAND.COM", 0 ; +90h
34
COMSPECBOOT db "@:\COMMAND.COM", 0 ; +0Eh
40
 
-
 
41
; ECHO status used by COMMAND.COM. 0 = ECHO OFF, 1 = ECHO ON
-
 
42
CMDECHO db 1     ; +9Fh
-
 
43
 
-
 
44
; segment of the first batch in batch chain. this is used by transient
-
 
45
; COMMAND.COM to chain multiple batch files (through CALL). 0 means "none".
-
 
46
BATCHCHAIN dw 0  ; +A0h
-
 
47
 
-
 
48
; original parent (segment of)
-
 
49
ORIGPARENT dd 0  ; +A2h
-
 
50
 
35
 
51
skipsig:         ; +A6h
36
skipsig:         ; +1Dh
52
 
37
 
53
; set up CS=DS=SS and point SP to my private stack buffer
38
; set up CS=DS=SS and point SP to my private stack buffer
54
mov ax, cs
39
mov ax, cs
55
mov ds, ax
40
mov ds, ax
56
mov es, ax
41
mov es, ax
57
mov ss, ax
42
mov ss, ax
58
mov sp, STACKPTR
43
mov sp, STACKPTR
59
 
44
 
60
; collect the exit code of previous application
45
; collect the exit code of previous application
61
mov ah, 0x4D
46
mov ah, 0x4D
62
int 0x21
47
int 0x21
63
xor ah, ah          ; clear out termination status, I only want the exit code
48
xor ah, ah          ; clear out termination status, I only want the exit code
64
mov [LEXCODE], ax
49
mov [LEXCODE], ax
65
 
50
 
66
; preset the default COMSPEC pointer to ES:DX (ES is already set to DS)
51
; preset the default COMSPEC pointer to ES:DX (ES is already set to DS)
67
mov dx, COMSPECBOOT
52
mov dx, COMSPECBOOT
68
 
53
 
69
; do I have a valid COMSPEC?
54
; do I have a valid COMSPEC?
70
or [COMSPECPTR], word 0
55
or [COMSPECPTR], word 0
71
jz USEDEFAULTCOMSPEC
56
jz USEDEFAULTCOMSPEC
72
; set ES:DX to actual COMSPEC
57
; set ES:DX to actual COMSPEC
73
mov es, [ENVSEG]
58
mov es, [ENVSEG]
74
mov dx, [COMSPECPTR]
59
mov dx, [COMSPECPTR]
75
USEDEFAULTCOMSPEC:
60
USEDEFAULTCOMSPEC:
76
 
61
 
77
; prepare the exec param block
62
; prepare the exec param block
78
mov ax, [ENVSEG]
63
mov ax, [ENVSEG]
79
mov [EXEC_PARAM_REC], ax
64
mov [EXEC_PARAM_REC], ax
80
mov ax, CMDTAIL
65
mov ax, CMDTAIL
81
mov [EXEC_PARAM_REC+2], ax
66
mov [EXEC_PARAM_REC+2], ax
82
mov [EXEC_PARAM_REC+4], cs
67
mov [EXEC_PARAM_REC+4], cs
83
 
68
 
84
; execute command.com
69
; execute command.com
85
mov ax, 0x4B00         ; DOS 2+ - load & execute program
70
mov ax, 0x4B00         ; DOS 2+ - load & execute program
86
push es                ;
71
push es                ;
87
pop ds                 ;
72
pop ds                 ;
88
;mov dx, COMSPEC       ; DS:DX  - ASCIZ program name (preset already)
73
;mov dx, COMSPEC       ; DS:DX  - ASCIZ program name (preset already)
89
push cs
74
push cs
90
pop es
75
pop es
91
mov bx, EXEC_PARAM_REC ; ES:BX  - parameter block pointer
76
mov bx, EXEC_PARAM_REC ; ES:BX  - parameter block pointer
92
int 0x21
77
int 0x21
93
 
78
 
94
; if all went well, jump back to start
79
; if all went well, jump back to start
95
jnc skipsig
80
jnc skipsig
96
 
81
 
97
; restore DS=CS
82
; restore DS=CS
98
mov bx, cs
83
mov bx, cs
99
mov ds, bx
84
mov ds, bx
100
 
85
 
101
; update error string so it contains the error number
86
; update error string so it contains the error number
102
add al, '0'
87
add al, '0'
103
mov [ERRLOAD + 4], al
88
mov [ERRLOAD + 4], al
104
 
89
 
105
; display error message
90
; display error message
106
mov ah, 0x09
91
mov ah, 0x09
107
mov dx, ERRLOAD
92
mov dx, ERRLOAD
108
int 0x21
93
int 0x21
109
 
94
 
110
; wait for keypress
95
; wait for keypress
111
mov ah, 0x08
96
mov ah, 0x08
112
int 0x21
97
int 0x21
113
 
98
 
114
; back to program start
99
; back to program start
115
jmp skipsig
100
jmp skipsig
116
 
101
 
117
; command.com tail arguments, in PSP format (length byte followed by arg)
102
; command.com tail arguments, in PSP format (length byte followed by arg)
118
CMDTAIL db 0
103
CMDTAIL db 0
119
 
104
 
120
; ExecParamRec used by INT 21h, AX=4b00 (load and execute program), 14 bytes:
105
; ExecParamRec used by INT 21h, AX=4b00 (load and execute program), 14 bytes:
121
;  offset  size  content
106
;  offset  size  content
122
;     +0     2   segment of environment for child (0 = current)
107
;     +0     2   segment of environment for child (0 = current)
123
;     +2     4   address of command line to place at PSP:0080
108
;     +2     4   address of command line to place at PSP:0080
124
;     +6     4   address of an FCB to be placed at PSP:005c
109
;     +6     4   address of an FCB to be placed at PSP:005c
125
;    +0Ah    4   address of an FCB to be placed at PSP:006c
110
;    +0Ah    4   address of an FCB to be placed at PSP:006c
126
EXEC_PARAM_REC db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
111
EXEC_PARAM_REC db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
127
 
112
 
128
ERRLOAD db "ERR x, FAILED TO LOAD COMMAND.COM", 13, 10, '$'
113
ERRLOAD db "ERR x, FAILED TO LOAD COMMAND.COM", 13, 10, '$'
129
 
114
 
130
; DOS int 21h functions that I use require at least 32 bytes of stack, here I
115
; DOS int 21h functions that I use require at least 32 bytes of stack, here I
131
; allocate 64 bytes to be sure
116
; allocate 64 bytes to be sure
132
STACKBUF db "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"
117
STACKBUF db "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"
133
STACKPTR db "xx"
118
STACKPTR db "xx"
134
 
119