Subversion Repositories SvarDOS

Rev

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

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