flat assembler
Message board for the users of flat assembler.

Index > OS Construction > What's the most elegant way to monitor key presses in RM?

Author
Thread Post new topic Reply to topic
zhak



Joined: 12 Apr 2005
Posts: 490
Location: Belarus
zhak
Hi people!
The idea is simple... I want my program to execute until ESC is pressed.
I installed INT 1Ch handler:
Code:
mov si, 001Ch*4
    mov eax, [si]
    mov [int1C], eax
    cli
    mov word [si], int_1C
    mov [si+2], bx
    sti    


The handler itself is
Code:
int_1C:
    push ds
    push bx
    xor bx, bx
    mov ds, bx
    mov bl, [041Ch]
    add bx, 03FFh           ;start of kbd_buf + 1
  @@:
    mov al, [bx]
    mov bl, [0480h]
    mov bh, bl
    mov word [041Ah], bx
    cmp al, key_scancode_esc
    jz .esc_pressed
    pop bx
    pop ds
    iret
  .esc_pressed:
    pop bx
    pop ds
    push ds
    push cancel
    iret    

it checks if ESC was pressed (by scan code in kbd buffer) and if so, jumps to label cancel:
Code:
cancel:;+
    push szHaltedByUser_Error
    cli
    mov eax, [int1C]
    mov [001Ch*4], eax
    sti
    mov dx, 140Fh                ;just output some messages like
    call set_cursor                 ; press ESC to continue or X to reboot
    mov si, szHalted
    call show_msg
    pop si
    call show_msg
    mov si, szEsc2Load
    call show_msg
  .wait_keypress:
    xor ax, ax
    int 16h
    cmp al, 0Dh
    jz boot_next_device
    cmp al, 1Bh
    jz cold_reboot
    jmp .wait_keypress    

this doesn't work neither in bochs nor in wmware.
I can't understand where the problem is. It outputs only one char of the first string, then stuns.
Is there any more elegant way to monitor if a key was pressed in background? This code is used in bootloader. Thanks!
Post 20 Jul 2006, 08:13
View user's profile Send private message Reply with quote
zhak



Joined: 12 Apr 2005
Posts: 490
Location: Belarus
zhak
I found the solution at last... I intercepted INT 9:
Code:
int_9:
    push ax                  ;save AX 'cause it may be in use somewhere
    in al, 60h
    cmp al, 81h             ;break code for ESC
    jnz @f
    add sp, 4
    push cancel
    mov al, [041Ah]      ;clear kbd buffer because Int 16h Fn 1 will
    mov [041Ch], al      ;return previous keypress immediately
    sub sp, 2
  @@:
    pop ax
    jmp dword [cs:int9]   ;execute default INT 9 handler. CS is used because
                                  ;I use the same segment for code and data    

I deleted the previously submitted peace of code because it was wrong.
This routine seems to be working correctly... I hope it's so Smile
Post 20 Jul 2006, 16:53
View user's profile Send private message 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.