Subversion Repositories SvarDOS

Rev

Rev 350 | Rev 366 | 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
 
33
 
353 mateuszvis 34
skipsig:         ; +8Eh
350 mateuszvis 35
 
349 mateuszvis 36
; set up CS=DS=SS and point SP to my private stack buffer
37
mov ax, cs
38
mov ds, ax
39
mov es, ax
40
mov ss, ax
41
mov sp, STACKPTR
42
 
353 mateuszvis 43
; collect the exit code of previous application
44
mov ah, 0x4D
45
int 0x21
46
xor ah, ah          ; clear out termination status, I only want the exit code
47
mov [LEXCODE], ax
48
 
349 mateuszvis 49
; prepare the exec param block
350 mateuszvis 50
mov ax, [ENVSEG]
51
mov [EXEC_PARAM_REC], ax
349 mateuszvis 52
mov ax, COMSPEC
53
mov [EXEC_PARAM_REC+2], ax
54
mov [EXEC_PARAM_REC+4], ds
55
 
56
; execute command.com
57
mov ax, 0x4B00         ; DOS 2+ - load & execute program
58
mov dx, COMSPEC        ; DS:DX  - ASCIZ program name TODO: use real COMSPEC...
59
mov bx, EXEC_PARAM_REC ; ES:BX  - parameter block pointer
60
int 0x21
61
 
62
; if all went well, jump back to start
63
jnc skipsig
64
 
65
; update error string so it contains the error number
66
add al, '0'
67
mov [ERRLOAD + 4], al
68
 
69
; display error message (with trailing COMSPEC)
70
mov ah, 0x09
71
mov dx, ERRLOAD
72
mov [COMSPCZ], byte '$' ; patch comspec terminator to be $
73
int 0x21
74
mov [COMSPCZ], byte 0   ; restore initial (NULL) compsec terminator
75
 
76
; wait for keypress
77
mov ah, 0x08
78
int 0x21
79
 
80
; back to program start
81
jmp skipsig
82
 
83
; ExecParamRec used by INT 21h, AX=4b00 (load and execute program), 14 bytes:
84
;  offset  size  content
85
;     +0     2   segment of environment for child (0 = current)
86
;     +2     4   address of command line to place at PSP:0080
87
;     +6     4   address of an FCB to be placed at PSP:005c
88
;    +0Ah    4   address of an FCB to be placed at PSP:006c
89
EXEC_PARAM_REC db 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0
90
 
91
ERRLOAD db "ERR x, FAILED TO LOAD COMMAND.COM FROM:", 13, 10
92
 
93
COMSPEC db "C:\SVN\SVARDOS\SVARCOM\COMMAND.COM"
94
COMSPCZ db 0
95
 
96
; FreeDOS int 21h functions that I use require at least 32 bytes of stack,
97
; here I allocate 64 bytes to be sure
98
STACKBUF db "0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF0123456789ABCDEF"
99
STACKPTR db "xx"