Subversion Repositories SvarDOS

Rev

Rev 448 | Rev 459 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

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