]> wirehaze git hosting - MS-DOS.git/blob - v4.0/src/CMD/REPLACE/_REPLACE.ASM

wirehaze git hosting

MZ is back!
[MS-DOS.git] / v4.0 / src / CMD / REPLACE / _REPLACE.ASM
1 page 60,132 ;\ f
2 name _replace
3 title Critical error or control break exit
4 ;-------------------------------------------------------------------
5 ;
6 ; MODULE: _replace
7 ;
8 ; PURPOSE: Supplies assembler exit routines for
9 ; critical error or control break situations
10 ;
11 ; CALLING FORMAT:
12 ; crit_err_handler;
13 ; ctl_brk_handler;
14 ;
15 ; DATE: 10/87
16 ;
17 ;-------------------------------------------------------------------
18
19
20 public _crit_err_handler ;AN000;
21 public _ctl_brk_handler ;AN000;
22
23 ;-------------------------------------------------------------------
24 RET_EXIT equ 4ch ; terminate ;AN000;
25 CTLBRK equ 3 ; errorlevel return in al ;AN000;
26 ABORT equ 2 ; if >=, retry ;AN000;
27 XABORT equ 1 ; errorlevel return in al ;AN000;
28 ;-------------------------------------------------------------------
29
30
31 NULL SEGMENT PARA PUBLIC 'BEGDATA' ;AN000;
32 NULL ENDS ;AN000;
33 _DATA SEGMENT PARA PUBLIC 'DATA' ;AN000;
34 extrn _oldint24:dword ;AN000;
35 _DATA ENDS ;AN000;
36 CONST SEGMENT WORD PUBLIC 'CONST' ;AN000;
37 CONST ENDS ;AN000;
38 _BSS SEGMENT WORD PUBLIC 'BSS' ;AN000;
39 _BSS ENDS ;AN000;
40 STACK SEGMENT PARA STACK 'DATA' ;AN000;
41 STACK ENDS ;AN000;
42
43 PGROUP GROUP _TEXT ;AN000;
44 DGROUP GROUP NULL, _DATA, CONST, _BSS, STACK ;AN000;
45
46
47
48 _TEXT segment para public 'CODE' ;AN000;
49 ASSUME CS:PGROUP ;AN000;
50
51 extrn _restore:near ;AN000;
52
53 ;-------------------------------------------------------------------
54 ; CRITICAL ERROR HANDLER
55 ;-------------------------------------------------------------------
56 vector dd 0 ;receives a copy of _oldint24 ;AN000;
57
58 _crit_err_handler proc near ;AN000;
59
60 pushf ; req by int24 handler ;AN000;
61 push ax ; will use ax ;AN000;
62 push ds ; will use ds ;AN000;
63
64 mov ax,dgroup ; setup ;AN000;
65 mov ds,ax ; ;AN000;
66 ASSUME DS:DGROUP ;AN000;
67
68 mov ax,word ptr _oldint24 ; load vector so we can use it ;AN000;
69 mov word ptr vector,ax ; ;AN000;
70 mov ax,word ptr _oldint24+2 ; ;AN000;
71 mov word ptr vector+2,ax ; ;AN000;
72
73 pop ds ; finished with ds ;AN000;
74 ASSUME DS:NOTHING
75
76 pop ax ; finished with ax ;AN000;
77
78 call dword ptr vector ; invoke DOS err hndlr ;AN000;
79
80 cmp al,ABORT ; what was the user's response ;AN000;
81 jnge retry ; ;AN000;
82
83 mov ax,(RET_EXIT shl 8)+XABORT ; return to DOS w/criterr error ;AN000;
84 call call_restore ; restore user's orig append/x ;AN000;
85 ; =================== this call does not return ===============
86
87 retry: ;AN000;
88 ASSUME DS:NOTHING
89 ASSUME ES:NOTHING
90
91 iret ; user response was "retry" ;AN000;
92
93 _crit_err_handler endp ;AN000;
94
95
96 ;-------------------------------------------------------------------
97 ; CONTROL BREAK HANDLER
98 ;-------------------------------------------------------------------
99 _ctl_brk_handler proc near ;AN000;
100
101 ASSUME DS:NOTHING
102 ASSUME ES:NOTHING
103
104 mov ax,(RET_EXIT shl 8)+CTLBRK ; return to DOS w/ctlbrk error ;AN000;
105 ;-------------------------------------------------------------------
106 call call_restore ; restore user's orig append/x ;AN000;
107 ;-------------------------------------------------------------------
108 ; =================== this call does not return ===============
109
110 _ctl_brk_handler endp ;AN000;
111
112 call_restore proc near
113 ;input: ah has the RETURN TO DOS WITH RET CODE function request
114 ; al has the ERRORLEVEL return code to be passed back to DOS
115 ;output: this routine does NOT RETURN, but exits to DOS with ret code.
116
117 push ax ;save errorlevel return code
118 push ds
119 push es
120
121 mov ax,dgroup ; setup "c" code regs ;AN000;
122 mov ds,ax ; ;AN000;
123 ASSUME DS:DGROUP ;AN000;
124
125 mov es,ax ; ;AN000;
126 ASSUME ES:DGROUP ;AN000;
127
128 ;-------------------------------------------------------------------
129 call _restore ; restore user's orig append/x ;AN000;
130 ;-------------------------------------------------------------------
131
132 pop es
133 pop ds
134 pop ax ;restore return code
135 int 21h ; ;AN000;
136 int 20h ; in case int21 fails ;AN000;
137
138 call_restore endp
139
140 _TEXT ends ; end code segment ;AN000;
141 end ;AN000;
142 \1a