flat assembler
Message board for the users of flat assembler.
Index
> DOS > whats wrong with this code??? |
Author |
|
SeproMan 11 Oct 2009, 13:39
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 : pusha push ds push cs pop ds ... pop ds popa iret 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 |
|
rookie23 16 Oct 2009, 00:24
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? ... ;finish? pop ds ;finish? popa ;finish? iret 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? ex: Newint9: pusha ... call int_dos_routine ... popa iret int_dos_routine: mov ah, 9 mov dx, msg int 16h ret 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 thnks |
|||
16 Oct 2009, 00:24 |
|
SeproMan 19 Oct 2009, 19:43
You're removing your Interrupt Handler from within itself by writing :
Code: call ReStoreInt9 The 2 lines Code: 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 iret 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. Code: ; 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 > |
Forum Rules:
|
Copyright © 1999-2024, Tomasz Grysztar. Also on GitHub, YouTube.
Website powered by rwasa.