Subversion Repositories SvarDOS

Rev

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