庞大资源库的计算机教程网站!
设为首页
加入收藏
总编信箱
投稿或申请专栏请先 [登 陆]
首页 操作系统 程序设计 图形图像 媒体动画 机械电子 WEB开发 数 据 库 办公系列 路由技术 网络原理 网络应用
认证考试 安全技术
首页>程序设计>汇编语言>相关源码>正文
资料搜索
Google搜索
Google
返回上级列表

推荐文章

快速保存网页中所有图片的方法
Windows中让光驱巧妙“隐身”技
防范非法用户入侵Win 2000/XP系
两款比较典型的ASP木马防范方法
有关表格边框的css语法整理
Windows XP中可以被禁用的服务
SQL Server导出导入数据方法
Javascript所有对象的属性的获
网页(HTML)中的特殊字符
与篮球共舞,尽显模式本色
QQ病毒的手工清除方法
Photoshop为极品美女打造性感睫
天衣无缝:IIS与PHP水火也相容
SQL Server存储过程编写和优化

汇编的的各类源码--break

 作者:本站收集   日期:2005-8-1 15:39:28
字号选择〖 〗/ 双击滚屏 单击停止   
        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

上一篇:汇编的的各类源码--BRK    下一篇:汇编的的各类源码--basmain  
[发送给好友]  [关闭窗口]  [返回顶部]   转载请注明来源:www.it00.com   
特别声明: 本站除部分特别声明禁止转载的专稿外的其他文章可以自由转载,但请务必注明出处和原始作者。文章版权归文章原始作者所有。对于被本站转载文章的个人和网站,我们表示深深的谢意。如果本站转载的文章有版权问题请联系编辑人员,我们尽快予以更正。
责任编辑: 原点 投稿作者: 本站收集
信息来源: 网络 录入时间: 2005-8-1 15:39:28
关于我们 - 广告服务 - 版权申明 - 网站地图 - 联系方式 - 总编信箱 - 会员投稿