title Control-Break handler for Lattice C programs
name break
include dos.mac
;
; Control-Break Interrupt Handler for Lattice C programs
; Running on IBM PCs (and ROM BIOS compatibles)
;
; Ray Duncan, May 1985
;
; This module allows C programs running on the IBM PC
; To retain control when the user enters a Control-Break
; Or Control-C. This is accomplished by taking over the
; Int 23H (MS-DOS Control-Break) and Int 1BH (IBM PC
; ROM BIOS Keyboard Driver Control-Break) interrupt
; Vectors. The interrupt handler sets an internal
; Flag (which must be declared STATIC INT) to TRUE within
; The C program; the C program can poll or ignore this
; Flag as it wishes.
;
; The module follows the Lattice C parameter passing
; Conventions, and also relies on the Lattice file DOS.MAC
; For the definition of certain constants and macros.
;
; The Int 23H Control-Break handler is a function of MS-DOS
; And is present on all MS-DOS machines, however, the Int 1BH
; Handler is a function of the IBM PC ROM BIOS and will not
; Necessarily be present on other machines.
;
if lprog
args equ 6; offset of arguments, Large models
else
args聽聽聽 equ聽聽聽聽 4聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ;offset of arguments, Small models
聽聽聽聽聽聽聽 endif
cr equ 0dh; ASCII carriage return
lf equ 0ah; ASCII line feed
聽聽聽聽聽聽聽 pseg
聽聽聽聽聽聽聽 public聽 capture,release ;function names for C
;
; The function CAPTURE is called by the C program to
; take over the MS-DOS and keyboard driver Control-
; Break interrupts (1BH and 23H).聽 It is passed the
; address of a flag within the C program which is set
; to TRUE whenever a Control-Break or Control-C
; is detected.聽 The function is used in the form:
;
;聽聽聽聽聽聽聽聽聽聽聽聽聽聽 static int flag;
;聽聽聽聽聽聽聽聽聽聽聽聽聽聽 capture(&flag)
;
capture proc聽聽聽 near聽聽聽聽聽聽聽聽聽聽聽 ;take over Control-Break
聽聽聽聽聽聽聽 push聽聽聽 bp聽聽聽聽聽聽聽聽聽聽聽聽聽 ;interrupt vectors
聽聽聽聽聽聽聽 mov聽聽聽聽 bp,sp
聽聽聽聽聽聽聽 push聽聽聽 ds
聽聽聽聽聽聽聽 mov聽聽聽聽 ax,word ptr [bp+args]
聽聽聽聽聽聽聽 mov聽聽聽聽 cs:flag,ax聽聽聽聽聽 ;save address of integer
聽聽聽聽聽聽聽 mov聽聽聽聽 cs:flag+2,ds聽聽聽 ;flag variable in C program
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ;pick up original vector contents
聽聽聽聽聽聽聽 mov聽聽聽聽 ax,3523h聽聽聽聽聽聽聽 ;for interrupt 23H (MS-DOS
聽聽聽聽聽聽聽 int聽聽聽聽 21h聽聽聽聽聽聽聽聽聽聽聽聽 ;Control-Break handler)
聽聽聽聽聽聽聽 mov聽聽聽聽 cs:int23,bx
聽聽聽聽聽聽聽 mov聽聽聽聽 cs:int23+2,es
聽聽聽聽聽聽聽 mov聽聽聽聽 ax,351bh聽聽聽聽聽聽聽 ;and interrupt 1BH
聽聽聽聽聽聽聽 int聽聽聽聽 21h聽聽聽聽聽聽聽聽聽聽聽聽 ;(IBM PC ROM BIOS keyboard driver
聽聽聽聽聽聽聽 mov聽聽聽聽 cs:int1b,bx聽聽聽聽 ;Control-Break interrupt handler)
聽聽聽聽聽聽聽 mov聽聽聽聽 cs:int1b+2,es
聽聽聽聽聽聽聽 push聽聽聽 cs聽聽聽聽聽聽聽聽聽聽聽聽聽 ;set address of new handler聽聽聽聽
聽聽聽聽聽聽聽 pop聽聽聽聽 ds
聽聽聽聽聽聽聽 mov聽聽聽聽 dx,offset ctrlbrk
聽聽聽聽聽聽聽 mov聽聽聽聽 ax,02523H聽聽聽聽聽聽 ;for interrupt 23H
int 21h
聽聽聽聽聽聽聽 mov聽聽聽聽 ax,0251bH聽聽聽聽聽聽 ;and interrupt 1BH
int 21h
聽聽聽聽聽聽聽 pop聽聽聽聽 ds聽聽聽聽聽聽聽聽聽聽聽聽聽 ;restore registers and
聽聽聽聽聽聽聽 pop聽聽聽聽 bp聽聽聽聽聽聽聽聽聽聽聽聽聽 ;return to C program
ret
capture endp
;
; The function RELEASE is called by the C program to
; return the MS-DOS and keyboard driver Control-Break
; interrupt vectors to their original state.聽 Int 23h is
; also automatically restored by MS-DOS upon the termination
; of a process, however, calling RELEASE allows the C
; program to restore the default action of a Control-C
; without terminating.聽 The function is used in the form:
;
;聽聽聽聽聽聽聽聽聽聽聽聽聽聽 release()
;
release proc聽聽聽 near聽聽聽聽聽聽聽聽聽聽聽 ;restore Control-Break interrupt
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ;vectors to their original state聽聽聽聽聽聽聽
聽聽聽聽聽聽聽 push聽聽聽 bp
聽聽聽聽聽聽聽 mov聽聽聽聽 bp,sp
聽聽聽聽聽聽聽 push聽聽聽 ds
聽聽聽聽聽聽聽 mov聽聽聽聽 dx,cs:int1b聽聽聽聽 ;set interrupt 1BH
聽聽聽聽聽聽聽 mov聽聽聽聽 ds,cs:int1b+2聽聽 ;(MS-DOS Control-Break
聽聽聽聽聽聽聽 mov聽聽聽聽 ax,251bh聽聽聽聽聽聽聽 ;interrupt handler)聽聽聽聽
int 21h
聽聽聽聽聽聽聽 mov聽聽聽聽 dx,cs:int23聽聽聽聽 ;set interrupt 23H
聽聽聽聽聽聽聽 mov聽聽聽聽 ds,cs:int23+2聽聽 ;(IBM PC ROM BIOS keyboard driver
聽聽聽聽聽聽聽 mov聽聽聽聽 ax,2523h聽聽聽聽聽聽聽 ;Control-Break interrupt handler)
int 21h
聽聽聽聽聽聽聽 pop聽聽聽聽 ds聽聽聽聽聽聽聽聽聽聽聽聽聽 ;restore registers and
聽聽聽聽聽聽聽 pop聽聽聽聽 bp聽聽聽聽聽聽聽聽聽聽聽聽聽 ;return to C program
ret
release endp
;
; This is the actual interrupt handler which is called by
; the ROM BIOS keyboard driver or by MS-DOS when a Control-C
; or Control-Break is detected.聽 Since the interrupt handler
; may be called asynchronously by the keyboard driver, it
; is severely restricted in what it may do without crashing
; the system (e.g. no calls on DOS allowed).聽 In this
; version, it simply sets a flag within the C program to
; TRUE to indicate that a Control-C or Control-Break has
; been detected; the address of this flag was passed
; by the C program during the call to the CAPTURE function.
;
ctrlbrk proc聽聽聽 far聽聽聽聽聽聽聽聽聽聽聽聽 ;Control-Break interrupt handler
聽聽聽聽聽聽聽 push聽聽聽 bx聽聽聽聽聽聽聽聽聽聽聽聽聽 ;save affected registers
聽聽聽聽聽聽聽 push聽聽聽 ds
聽聽聽聽聽聽聽 mov聽聽聽聽 bx,cs:flag聽聽聽聽聽 ;set flag within C program
聽聽聽聽聽聽聽 mov聽聽聽聽 ds,cs:flag+2聽聽聽 ;to "True"
聽聽聽聽聽聽聽 mov聽聽聽聽 word ptr ds:[bx],-1
聽聽聽聽聽聽聽 pop聽聽聽聽 ds聽聽聽聽聽聽聽聽聽聽聽聽聽 ;restore registers and exit
聽聽聽聽聽聽聽 pop聽聽聽聽 bx
聽聽聽聽聽聽聽 iret
ctrlbrk endp
flag聽聽聽 dw聽聽聽聽聽 0,0聽聽聽聽聽聽聽聽聽聽聽聽 ;long address of C program''s
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ;Control-Break detected flag
int23聽聽 dw聽聽聽聽聽 0,0聽聽聽聽聽聽聽聽聽聽聽聽 ;original contents of MS-DOS
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ;Control-Break Interrupt 23H
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ;vector
int1b聽聽 dw聽聽聽聽聽 0,0聽聽聽聽聽聽聽聽聽聽聽聽 ;original contents of ROM BIOS
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ;keyboard driver Control-Break
聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽聽 ;Interrupt 1BH vector
聽聽聽聽聽聽聽 endps
end
相关链接:
U.S. will send Experts want to increase overseas trade negotiations to combat piracy weightXviD To MP4MKV to ZuneIn-depth analysis Of ASP.NET 2.0 buffer system (2)Good Audio CD PlayersHart governance "disease" Hewlett-PackardEvaluation Management And DistributionM2TS To MKVHigher Heat Blow, "Kabbah Wind" Paper Submitted Until 15th Of The MonthWho in the sale of national sentiment!Test emergency response capacity of cities: urban emergency on the roadLists Mathematics EducationIntel Strikes starteds.m.a.r.t. failure how to correct This hardStorage Inventory And BarcodingSymantec said the new storm worm detected