Category : Assembly Language Source Code
Archive   : CBREAK.ZIP
Filename : CBREAK.LST

 
Output of file : CBREAK.LST contained in archive : CBREAK.ZIP
 The Microsoft MACRO Assembler , Version 1.25 Page 1-1
Control-Break handler for Lattice C programs 08-29-85


1 title Control-Break handler
for Lattice C programs
2 name cbreak
3 C include dos.mac
4 C ;**
5 C ;
6 C ; This macro library defines the operat
ing environment for the 8086 small
7 C ; memory model, which allows 64Kbytes o
f data and 64Kbytes of program.
8 C ;
9 C ;**
10 = 0002 C MSDOS EQU 2
11 C
12 C ;**
13 C ;
14 C ; The following symbols define the 8086
memory mode being used. Set LPROG
15 C ; to 1 for a large program segment (gre
ater than 64K-bytes), and set LDATA
16 C ; to 1 for a large data segment. Set C
OM to 1 to generate .COM files
17 C ; instead of .EXE files. Note that if
COM is not zero, then LPROG and
18 C ; LDATA must be 0.
19 C ;
20 C ;**
21 = 0000 C COM EQU 0
22 = 0000 C LPROG EQU 0
23 = 0000 C LDATA EQU 0
24 C
25 C ;**
26 C ;
27 C ; The following symbols are established
via LPROG and LDATA as follows:
28 C ;
29 C ; S8086 set for small model (sm
all prog, small data)
30 C ; D8086 set for model with larg
e data, small prog
31 C ; P8086 set for model with larg
e prog, small data
32 C ; L8086 set for large model
33 C ;
34 C ;**
35 C IF (LPROG EQ 0) AND (LDATA
EQ 0)
36 = 0001 C S8086 EQU 1
37 = 0000 C D8086 EQU 0
38 = 0000 C P8086 EQU 0
39 = 0000 C L8086 EQU 0
40 C ENDIF
41 C
 The Microsoft MACRO Assembler , Version 1.25 Page 1-2
Control-Break handler for Lattice C programs 08-29-85


42 C ENDIF
43 C
44 C ENDIF
45 C
46 C ENDIF
47 C
48 C
49 C ;**
50 C ;
51 C ; The DSEG and PSEG macros are defined
to generate the appropriate GROUP
52 C ; and SEGMENT statements for the memory
model being used. The ENDDS and
53 C ; ENDPS macros are then used to end the
segments.
54 C ;
55 C ;**
56 C DSEG MACRO
57 C DGROUP GROUP DATA
58 C DATA SEGMENT WORD PUBLIC 'DATA'
59 C ASSUME DS:DGROUP
60 C ENDM
61 C ENDDS MACRO
62 C DATA ENDS
63 C ENDM
64 C
65 C IF S8086
66 C PSEG MACRO
67 C PGROUP GROUP PROG
68 C PROG SEGMENT BYTE PUBLIC 'PROG'
69 C ASSUME CS:PGROUP
70 C ENDM
71 C ENDPS MACRO
72 C PROG ENDS
73 C ENDM
74 C ENDIF
75 C
76 C ENDIF
77 C
78 C ENDIF
79 C
80 C ENDIF
81 ;
82 ; Control-Break Interrupt Handler for
Lattice C programs
83 ; running on IBM PC's ( and ROM BIOS
compatibles ).
84 ;
85 ; Written by: Ray Duncan, May 19
85 ( DDJ #107 September 1985 )
86 ;
87 ; Transcribed by: Lee J. Sarama, Augu
st 1985
 The Microsoft MACRO Assembler , Version 1.25 Page 1-3
Control-Break handler for Lattice C programs 08-29-85


88 ;
89 ; This module allows C programs runnin
g on the IBM PC
90 ; to retain control when the user ente
rs a Control-break
91 ; and/or Control-C. This is accomplis
hed by taking over the
92 ; Int 23H (MS-DOS Control-Break) and I
nt 1BH (IBM PC Rom BIOS
93 ; Keyboard Driver Control-Break) Inter
rupt Vectors.
94 ; The interupt handler sets an interna
l flag (which must be
95 ; declared STATIC INT) to TRUE within
the C program; the C
96 ; program can poll or ignore this flag
as it wishes.
97 ;
98 ; The Module follows the Lattice C par
ameter passing
99 ; conventions, and also relies on the
Lattice file DOS.MAC
100 ; for the definitions of certain const
ants and macros.
101 ;
102 ; The Int 23H Control-Break handler is
a function of MS-DOS
103 ; and is present on all MS-DOS machine
s, however, the INT 1BH
104 ; handler is a function of the IBM PC
ROM BIOS and will not
105 ; necessarily be present on other mach
ines.
106 ;
107 ;
108 else
109 = 0004 args equ 4 ;off
set of arguments, Small models
110 endif
111 ;
112 = 000D cr equ 0DH ;ASC
II carriage return
113 = 000A lf equ 0AH ;ASC
II line feed
114 ;
115 pseg
116 0000 + PROG SEGMENT BYTE PUBLIC 'PROG'
117 ;
118 public capture,release ;Fun
ction names for C
119 ;
120 ;
121 ; The function CAPTURE is called by th
 The Microsoft MACRO Assembler , Version 1.25 Page 1-4
Control-Break handler for Lattice C programs 08-29-85


e C program to
122 ; take ove the MS-DOS and keyboard dri
ver Control-
123 ; Break interrupts ( 1BH and 23H). It
is passed the
124 ; address of a flag within the C progr
am which is set
125 ; to TRUE whenever a Control-Break and
/or Control-C
126 ; is detected. The function is used i
n the form:
127 ;
128 ; static int flag;
129 ; capture (&flag);
130 ;
131 ;
132 0000 capture proc near ;Tak
e over Control-Break
133 0000 55 push bp ;int
errupt vectors
134 0001 8B EC mov bp,sp
135 0003 1E push ds
136 0004 8B 46 04 mov ax,word ptr [bp+args]
137 0007 2E: A3 0078 R mov cs:flag,ax ;sav
e address of interger
138 000B 2E: 8C 1E 007A R mov cs:flag+2,ds ;fla
g variable in C program
139 ;pic
k up original vector contents
140 0010 B8 3523 mov ax,3523H ;for
interrupt 23H (MS-DOS
141 0013 CD 21 int 21H ;Con
trol-Break handler)
142 ;
143 0015 2E: 89 1E 007C R mov cs:int23,bx
144 001A 2E: 8C 06 007E R mov cs:int23+2,es
145 001F B8 351B mov ax,351BH ;and
interrupt 1BH
146 0022 CD 21 int 21H ;(IB
M PC ROM BIOS keyboard driver
147 0024 2E: 89 1E 0080 R mov cs:int1b,bx ;Con
trol-Break interrupt handler)
148 0029 2E: 8C 06 0082 R mov cs:int1b+2,es
149 ;
150 002E 0E push cs ;set
address of new handler
151 002F 1F pop ds
152 0030 BA 0065 R mov dx,offset ctrlbrk ;loa
d offset of Control-Break
153 0033 B8 2523 mov ax,02523H ;for
interrupt 23H
154 0036 CD 21 int 21H
155 ;
 The Microsoft MACRO Assembler , Version 1.25 Page 1-5
Control-Break handler for Lattice C programs 08-29-85


156 0038 B8 251B mov ax,0251BH ;for
interrupt 1BH
157 003B CD 21 int 21H
158 ;
159 003D 1F pop ds ;res
tore registers and
160 003E 5D pop bp ;ret
urn to C program
161 ;
162 003F C3 ret
163 ;
164 0040 capture endp
165 ;
166 ;
167 ; The function RELEASE is called by th
e C program to
168 ; return the MS-DOS and keyboard drive
r Control-Break
169 ; interrupt vectors ( 1BH and 23H) to
their original state.
170 ; Interrupt 23H is also automatically
restored by MS-DOS
171 ; upon the termination of a process,
however, calling
172 ; RELEASE allows the C program to rest
ore the default
173 ; action of a Control-C withiout termi
nating. The function
174 ; is used in the form:
175 ;
176 ; release();
177 ;
178 ;
179 0040 release proc near ;Res
tore Control-Break interrupt
180 0040 55 push bp ;vec
tors to their original state
181 0041 8B EC mov bp,sp
182 0043 1E push ds
183 0044 2E: 8B 16 0080 R mov dx,cs:int1b ;Set
interrupt 1BH
184 0049 2E: 8E 1E 0082 R mov ds,cs:int1b+2 ;(MS
-DOS Control-Break
185 004E B8 251B mov ax,0251BH ;int
errupt handler)
186 0051 CD 21 int 21H
187 ;
188 0053 2E: 8B 16 007C R mov dx,cs:int23 ;Set
interrupt 23H
189 0058 2E: 8E 1E 007E R mov ds,cs:int23+2 ;(IB
M PC ROM BIOS keyboard driver
190 005D B8 2523 mov ax,02523H ;Con
trol-Break interrupt handler)
 The Microsoft MACRO Assembler , Version 1.25 Page 1-6
Control-Break handler for Lattice C programs 08-29-85


191 0060 CD 21 int 21H
192 ;
193 0062 1F pop ds ;res
tore registers and
194 0063 5D pop bp ;ret
urn to C program
195 ;
196 0064 C3 ret
197 ;
198 0065 release endp
199 ;
200 ;
201 ; This is the actual interrupt handler
which is called by
202 ; the ROM BIOS keyboard driver and/or
by MS-DOS when a
203 ; Control-C and/or Control-Break is de
tected. Since the
204 ; interrupt handler may be called asyn
chronously by the
205 ; keyboard driver, it is severely res
tricted in what it
206 ; may do without crashing the system (
e.g. no calls on
207 ; DOS allowed). In this version, it
simply sets a flag
208 ; within the C program to TRUE to indi
cate that a Control-
209 ; C and/or Control-Break has been dete
cted; the address of
210 ; this flag was passed by the C progra
m during the call to
211 ; the CAPTURE function.
212 ;
213 ;
214 0065 ctrlbrk proc far ;Con
trol-Break interrupt handler
215 0065 53 push bx ;Sav
e affected regiserts
216 0066 1E push ds
217 ;
218 0067 2E: 8B 1E 0078 R mov bx,cs:flag ;set
flag within C program
219 006C 2E: 8E 1E 007A R mov ds,cs:flag+2 ;to
"TRUE"
220 0071 C7 07 FFFF mov word ptr ds:[bx],-1
221 ;
222 0075 1F pop ds ;res
tore registers and
223 0076 5B pop bx ;exi
t
224 ;
225 0077 CF iret
 The Microsoft MACRO Assembler , Version 1.25 Page 1-7
Control-Break handler for Lattice C programs 08-29-85


226 ;
227 0078 ctrlbrk endp
228 ;
229 ;
230 0078 0000 0000 flag dw 0,0 ;Lon
g address of C program's
231 ;Con
trol-Break detected flag
232 ;
233 007C 0000 0000 int23 dw 0,0 ;Ori
ginal contents of MS-DOS
234 ;Con
trol-Break interrupt 23H vector
235 ;
236 0080 0000 0000 int1b dw 0,0 ;Ori
ginal contents of ROM BIOS
237 ;key
board driver Control-Break
238 ;int
errupt 1BH vector
239 ;
240 endps
241 0084 + PROG ENDS
242 ;
243 end

 The Microsoft MACRO Assembler , Version 1.25 Page Symbols
-1
Control-Break handler for Lattice C programs 08-29-85


Macros:

N a m e Length

DSEG . . . . . . . . . . . . . . 0003
ENDDS. . . . . . . . . . . . . . 0001
ENDPS. . . . . . . . . . . . . . 0001
PSEG . . . . . . . . . . . . . . 0003

Segments and groups:

N a m e Size align combine class

PGROUP . . . . . . . . . . . . . GROUP
PROG . . . . . . . . . . . . . . 0084 BYTE PUBLIC 'PROG'

Symbols:

N a m e Type Value Attr

ARGS . . . . . . . . . . . . . . Number 0004
CAPTURE. . . . . . . . . . . . . N PROC 0000 PROG Global Length
=0040
COM. . . . . . . . . . . . . . . Number 0000
CR . . . . . . . . . . . . . . . Number 000D
CTRLBRK. . . . . . . . . . . . . F PROC 0065 PROG Length =0013
D8086. . . . . . . . . . . . . . Number 0000
FLAG . . . . . . . . . . . . . . L WORD 0078 PROG
INT1B. . . . . . . . . . . . . . L WORD 0080 PROG
INT23. . . . . . . . . . . . . . L WORD 007C PROG
L8086. . . . . . . . . . . . . . Number 0000
LDATA. . . . . . . . . . . . . . Number 0000
LF . . . . . . . . . . . . . . . Number 000A
LPROG. . . . . . . . . . . . . . Number 0000
MSDOS. . . . . . . . . . . . . . Number 0002
P8086. . . . . . . . . . . . . . Number 0000
RELEASE. . . . . . . . . . . . . N PROC 0040 PROG Global Length
=0025
S8086. . . . . . . . . . . . . . Number 0001

Warning Severe
Errors Errors
0 0


  3 Responses to “Category : Assembly Language Source Code
Archive   : CBREAK.ZIP
Filename : CBREAK.LST

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/