flat assembler
Message board for the users of flat assembler.

flat assembler > DOS > Problems setting up a TSR program

Author
Thread Post new topic Reply to topic
keyoke



Joined: 18 Jun 2003
Posts: 56
Location: London
Hi,
I'm trying to catch input on the keyboard, and check if it's numeric or not... but I'm having trouble going resident. here is my code I'm working off of a old example so I'm not sure this is the correct way to go about it.
where could i find up to date info on this topic. I am hooking "On Buffered Input" right now.

any help would be great thanks

Code:
org 100h                    
use16                          

startdata:
        jmp startcode
        Old_Int dd ?
        Text db 'Interrupt Hooked!',0
startcode:
        mov ah,35h
        mov al,0ah
        int 21h

        mov word [Old_Int],bx
        mov word [Old_Int+2],es

        mov ah,25h
        mov al,0ah
        mov dx,Save_Key
        int 21h

        mov dx,startdata
        int 27h

Save_Key:
        pushf
        push ax
        push di
        push si
        push es
        push ds

        mov ah,09h
        mov dx,Text
        int 21h

        pop ds
        pop es
        pop si
        pop di
        pop ax
        popf

        pushf
        call [Old_Int]
        ret
    
Post 16 Jul 2003, 20:13
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7368
Location: Kraków, Poland
You should put your interrupt handler before the startdata label, because interrupt 27h frees all the memory after that label when you use it this way.
Post 16 Jul 2003, 20:52
View user's profile Send private message Visit poster's website Reply with quote
keyoke



Joined: 18 Jun 2003
Posts: 56
Location: London
hi privalov,
can you or anyone else help me with this I'm trying to set a different interrupt vector. this is a different way i am trying. i copy my routine to a space in memory then try to set the vector to it
Code:
;es=segment of the allocated block
        mov ax,2521h
        push es
        pop ds
        mov dx,100h
        int 21h  
    


here is my own code for before the int not all the correct pushes yet, but it doesnt even get to here yet... everything is copied fine but an error occures while trying the above ?

Code:
New_Int:
        pushf
        cmp ax,0BABEh
        jne Go_Old
        mov ah,09h
        mov dx,TestMsg
        int 21h
Go_Old:
        call [Old_Int]

TestMsg db 'Test',24h
Old_Int dd ?
End_New_Int:   
    
Post 17 Jul 2003, 20:21
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7368
Location: Kraków, Poland
First: you are setting the interrupt vector to es:100h - if this is the block of memory that you have allocated, shouldn't it be es:0? Or are you for some reason copying the routine into the 100h address into that block?

Second: you cannot hook interrupt 21h this way - this is one of the vectors that is automatically restored by DOS when you terminate program (no matter with what function you terminate), to hook this interrupt you need a more advanced techniques - if you want just to learn how to make TSR, try hooking some other interrupt.

Maybe you want some small example of TSR program written in fasm?
Post 17 Jul 2003, 20:26
View user's profile Send private message Visit poster's website Reply with quote
keyoke



Joined: 18 Jun 2003
Posts: 56
Location: London
oh ok...didnt know it was automatically restored Sad
I changed it to different interrupt and dx to 0 now it runs... somehow i thought that a psp was placed before my code that i copy to mem location Razz dunno heh. attached is my current useless attempt at creating an intterrupt F1h it loads into memory but bombs out when testing


Description:
Download
Filename: TSR.zip
Filesize: 2.46 KB
Downloaded: 237 Time(s)

Post 17 Jul 2003, 20:36
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7368
Location: Kraków, Poland
I tried to make it (the example) as simple as possible, it hooks interrupt 2Fh and provides a simple function for checking whether it is installed correctly:
Code:
        org     100h

        jmp     start

handler:
        cmp     ax,0BABEh
        je      function
        jmp     0:0
        label   old_seg word at $-2
        label   old_offs word at $-4
function:
        mov     ax,0BEEFh
        iret

start:
        mov     ax,352Fh
        int     21h
        mov     [old_seg],es
        mov     [old_offs],bx
        mov     ax,252Fh
        mov     dx,handler
        int     21h

        mov     dx,start
        int     27h    

After running the above program you can check it with the code like:
Code:
        mov     ax,0BABEh
        int     2Fh
        cmp     ax,0BEEFh
        je      installed    
Post 17 Jul 2003, 21:01
View user's profile Send private message Visit poster's website Reply with quote
keyoke



Joined: 18 Jun 2003
Posts: 56
Location: London
ok thanks i think this while help alot but
what exactly are you doing here

Quote:

jmp 0:0
label old_seg word at $-2
label old_offs word at $-4


i suppose jmp 0:0 just will jump to the same line... why have you used label instead of normal variable declaration? I'm curious as i have never seen this before why word at $-2.... will that place that value -2 places before '$' our current line ?
Post 17 Jul 2003, 21:35
View user's profile Send private message Visit poster's website Reply with quote
Tomasz Grysztar
Assembly Artist


Joined: 16 Jun 2003
Posts: 7368
Location: Kraków, Poland
This is the run-time fixing of code - the instruction jmp 0:0 is assembled to five bytes: 0EAh - instruction opcode, then zero word - offset of jump destination, and again zero word - segment of jump destination. Then $-2 is the offset of word containing segment and $-4 is the offset of word containing offset - it is filled at run-time with valid values by startup routine - if it wasn't fixed, it would jump to 0:0 an therefore cause crash.

If you don't want to use run-time code modification techniques, you can do it this way:
Code:
        org     100h

        jmp     start

handler:
        cmp     ax,0BABEh
        je      function
        jmp     far dword [old_handler]

old_handler:
  old_offset dw ?
  old_seg dw ?

function:
        mov     ax,0BEEFh
        iret

start:
        mov     ax,352Fh
        int     21h
        mov     [old_seg],es
        mov     [old_offs],bx
        mov     ax,252Fh
        mov     dx,handler
        int     21h

        mov     dx,start
        int     27h    
Post 17 Jul 2003, 22:46
View user's profile Send private message Visit poster's website Reply with quote
keyoke



Joined: 18 Jun 2003
Posts: 56
Location: London
ok thank you for the help Smile
Post 18 Jul 2003, 10:30
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2019, Tomasz Grysztar.

Powered by rwasa.