home *** CD-ROM | disk | FTP | other *** search
- TITLE METHOD1
- ; Purpose: demonstrates interfacing between
- ; protected mode program and real mode program
- ; via interrupt.
-
- ; We are using the following interrupt number because
- ; it seems not to conflict with other programs, but we
- ; could easily use a different number, if we wish.
- INTNUM EQU 48h
- NULL equ 0
-
- print macro string
- LOCAL next,done
- lea si,string
- next: lodsb
- or al,al
- jz done
- mov ah,0Eh
- int 10h
- jmp next
- done:
- endm
-
- _DATA SEGMENT WORD PUBLIC 'DATA'
- ; The calling program uses the AX register to pass an
- ; argument indicating which of several routines to call.
- ; The following macro defines a table of code pointers
- ; to those routines for which the argument acts as an index.
- ;
- code_table label byte
- HIGHEST_INDEX = 0
- IRP label_number, <0,1,2,3,4>
- dw p&label_number
- HIGHEST_INDEX = label_number
- ENDM
- dw NULL
-
- ; The following defines 1000 bytes of storage to be used
- ; as a buffer between the real and protected mode programs.
- data_buffer db 1000 dup (?)
-
- ; The next three strings are used to verify that the calling
- ; program can indeed call real mode routines, by having
- ; routine p1 output msg1, etc.
- even
- msg1 db 'Message 1',0dh,0ah,0
- even
- msg2 db 'Message 2',0dh,0ah,0
- even
- msg3 db 'Message 3',0dh,0ah,0
- even
- msg4 db 'Goodbye',0
- end_msg4 equ $
- _DATA ENDS
-
- ; We use Phar Lap's Intermode stack. We leave the
- ; following segment definition in place, however,
- ; in case we decide to use our own.
- STACK SEGMENT WORD STACK 'STACK'
- db 100 dup (?)
- end_stack label byte
- STACK ENDS
-
- DGROUP GROUP _DATA, STACK
-
- _TEXT SEGMENT PARA PUBLIC 'CODE'
- ASSUME CS: _TEXT, DS: DGROUP, SS: DGROUP, ES: DGROUP
- ; The Interrupt Service Routine.
- ; Return value in ax. Destroys bx,cx.
- isr proc near
- push si ; save si
- mov bx, DGROUP
- mov ds,bx ; point ds at real mode data
- cmp ax,HIGHEST_INDEX
- jbe index_ok
- stc
- jmp short exit
- index_ok:
- lea bx,code_table ; get pointer to code table
- shl ax,1 ; index * size of code pointer
- add bx,ax ; now, index into table
- call [bx] ; call desired routine
- exit:
- pop si ; restore si
- ; return value of 0 means ok, anything else means problem
- sbb ax,ax ; return value in ax
- iret
-
- ; The first time the protected mode code calls the real
- ; mode program, it calls p0, which passes back the real
- ; mode address of the data buffer in bx,cx. The segment
- ; address goes to cx, the offset goes to bx. After this,
- ; both programs can communicate through the data buffer.
- ; The next three times the protected mode code calls the
- ; real mode program, it calls p1, p2, and p3, which output
- ; msg1, msg2, and msg3 respectively, to verify that the
- ; table-driven program is working.
- ; The fourth time the protected mode program calls, it
- ; moves a string into the data buffer, which is then
- ; printed by the real mode program. The real mode program
- ; then moves a different string into the buffer and returns.
- ; The protected mode program then prints out the new contents.
- ; This is to verify that both programs can communicate through
- ; the data buffer.
-
- p0 label near
- mov cx,DGROUP
- lea bx,data_buffer
- clc
- ret
- p1 label near
- print msg1
- clc
- ret
- p2 label near
- print msg2
- clc
- ret
- p3 label near
- print msg3
- clc
- ret
- p4 label near
- print data_buffer
- push di
- push es
- push ds
- pop es
- lea si, msg4
- lea di,data_buffer
- mov cx,end_msg4-msg4
- rep movsb
- pop es
- pop di
- clc
- ret
- isr endp
-
- ; The following code is used to initialize the Interrupt
- ; Service Routine and leave it resident. This code and
- ; all memory above it is given back to the operating
- ; system by the call to Int 21h, function 31h at the end
- ; of the code.
- ALIGN 16
- initialize proc near
- end_tsr label byte
- lea dx, isr
- push cs
- pop ds
- mov ah,25h
- mov al,INTNUM
- int 21h
- ; go back to MS-DOS leaving ISR resident
- lea ax,end_tsr
- mov cl,4
- shr ax,cl ; convert to paragraphs
- mov dx,_TEXT
- add dx,ax
- mov ax,3100h ; terminate and stay resident
- int 21h
- initialize endp
- _TEXT ENDS
- END initialize
-