Message board for the users of flat assembler.
> DOS > whats wrong with this code???
im trying to make my custom interrupt.. i searched for some code to start and this is what i have now.. but when i run the program it just shows symbols!!.. i dont get the problem.. can anyone tell me what´s wrong??
on the other hand.. what should i need to do in my NewInt9 to store in the keyboard buffer a different letter than the one i press??.. (if i press a "b" .. store a "k" for example)..
org 100h start: mov ah,09h ; mensaje2 mov dx,msj2 int 21h mov al,09h mov ah,35h int 21h mov [oldint9],bx mov [oldint9+2],es mov ah,09h ; mensaje3 mov dx,msj3 int 21h mov al,09h mov dx,Newint9 ; DS:DX mov ah,25h int 21h mov ah,09h ; prueba 1 mov dx,msj6 int 21h loop1: mov ah,0 int 16h mov dl,ah mov ah,2 int 21h mov ah,09h ; prueba 2 mov dx,msj7 int 21h endp: ;call ReStoreInt9 mov ah,09h ; mensaje5 mov dx,msj5 int 21h xor ah,ah int 16h mov ah, 4Ch ;finish int 21h Newint9: pusha ;code mov ah,09h ; mensaje 1 mov dx,msj1 int 21h mov al, 0x20 ; EOI al PIC1 out 0x20, al ; jump exit. call ReStoreInt9 popa iret ReStoreInt9: mov ah,09h ; mensaje4 mov dx,msj4 int 21h mov al,09h mov dx,[oldint9] mov ds,[oldint9+2] ; pointer to DS:DX mov ah,25h int 21h ret oldint9 dw 0 msj1 db 13,10,"New Vector is Working!!",13,10,24h msj2 db 13,10,"Getting old vector...",13,10,24h msj3 db 13,10,"Setting new vector...",13,10,24h msj4 db 13,10,"Restrogin vector...",13,10,24h msj5 db 13,10,"End",13,10,24h msj6 db 13,10,"prueba 1",13,10,24h msj7 db 13,10,"prueba 2",13,10,24h
|01 Oct 2009, 09:15||
Some thoughts that might get you on the way...
Why do you remove your Interrupt Handler from within itself?
You never loop back to the label Loop1. Why is that?
When writing an Interrupt Handler the only segment register that you can really trust is CS! So you could write :
Moreover, it's not a good idea to call DOS services from within this Interrupt Handler ( DOS not being re-entrant)
When retrieving the old Interrupt Vector is is better to preserve the ES register.
Real Address Mode.
|11 Oct 2009, 13:39||
thnks for your answer seproman!!
- Why do you remove your Interrupt Handler from within itself?
mov al, 0x20 ; EOI al PIC1
out 0x20, al
is this what you mean?.. i saw these lines were necessary for the eoi.. after you do everything you want to.. so i just wrote them down..
- You never loop back to the label Loop1. Why is that?
i forgot to erase this.. loop1 label was created just for control purposes..
- When writing an Interrupt Handler the only segment register that you can really trust is CS! So you could write :
pusha ; start?
push ds ; start?
push cs ; start?
pop ds ;finish?
pop ds ;finish?
so, i need tu use this code when my interrupt handler starts and finishes??
does it matter if my program is a .com? or it is irrelevant?
- Moreover, it's not a good idea to call DOS services from within this Interrupt Handler ( DOS not being re-entrant)
so, if i need to use a DOS int while im inside my int handler, would be possible to call this DOS int from a routine outside my interrupt handler?
mov ah, 9
mov dx, msg
and finally: im using a customized KB handler (it is supposed to ).. but while im inside the routine, would be possible to another program (windows environment) to know what´s going on?.. or to intercept/modify this handler?
i would really appreciate your answer
|16 Oct 2009, 00:24||
You're removing your Interrupt Handler from within itself by writing :
The 2 lines
are necessary only when one services the Keyboard at the hardware level. A lot of effort. BIOS does this very well indeed.
mov al, 0x20 ; EOI al PIC1 out 0x20, al
This is skeleton code that preserves all general registers and makes sure that DS = CS. The type of program is irrelevant.
pusha ; Save all general registers
push ds ; Save DS
push cs ; Copy CS to ...
pop ds ; ... DS
... ; BODY of routine
pop ds ; Restore DS
popa ; Restore all general registers
Calling the INT_DOS_ROUTINE the way you suggested doesn't change a bit!
It still executes within the Interrupt Handler.
I would not bother too much about Windows. Everything you do will always remain IN the DOSBOX environment. So no interaction/interference of say Notepad/Word etc.
In the DOS environment however any program that loads after yours could potentially intercept the same Interrupt. But than again such a program would have been loaded by you, wouldn't it?
I had a lot of fun writing this small demo for you. Hope it is instructive.
Sorry, but the code in the attached file needs some minor changes because I used my own Assembler to write it. I did correct the code in this Post.
; Modified Keyboard Entry - 13/10/2009 ORG 256 mov ax,cs mov ss,ax mov sp,MyStack+64*2 mov ds,ax mov es,ax ; Some arbitrary modification mov byte [Table+"a"],"z" mov byte [Table+"z"],"a" ; Save existing Keyboard Interrupt Vector push es mov ax,3509h int 21h ;DOS 'Get Interrupt Vector' mov [Old_09h],bx mov [Old_09h+2],es pop es ; Setup new Keyboard Interrupt Vector mov dx,New_09h mov ax,2509h int 21h ;DOS 'Set Interrupt Vector' ; Prompt user action mov dx,Msg1 mov ah,09h int 21h ;DOS 'Display String' MainLoop: mov ah,01h int 21h ;DOS 'Keyboard Input & Echo' cmp al,27 ;<ESC> ? jne MainLoop ; Restore old Keyboard Interrupt Vector push ds lds dx,[Old_09h] mov ax,2509h int 21h ;DOS 'Set Interrupt Vector' pop ds ; Terminate mov dx,Msg2 mov ah,09h int 21h ;DOS 'Display String' mov ax,4C00h int 21h ;DOS 'Terminate/ReturnCode' ; ---------------------------------------------- New_09h: push ax bx si ds mov ax,40h ;BIOS_DataSegment mov ds,ax mov si,[001Ch] ;BIOS_KeyboardBufferTailPointer ; Let BIOS take care of the hardware pushf call far dword [cs:Old_09h] cmp si,[001Ch] ;BIOS_KeyboardBufferTailPointer je .t1 ;No new key in buffer mov al,[si] ;ASCII (SCAN in [si+1]) mov bx,Table xlat [cs:bx] mov [si],al ;Updated ASCII .t1: pop ds si bx ax iret ; ---------------------------------------------- ALIGN 4 Old_09h: dd 0 Table: times 256 db %-1 MyStack: dw 64 dup (0) Msg1: db 'Watch <a> and <z> being swapped...',13,10 db 'Please press some keys. <ESC> exits!',13,10,'$' Msg2: db "-- That's all folks",13,10,'$' ; -----------------------------------------------
Real Address Mode.
|19 Oct 2009, 19:43||
< Last Thread | Next Thread >
Copyright © 1999-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.
Website powered by rwasa.