News:

MASM32 SDK Description, downloads and other helpful links
MASM32.com New Forum Link
masmforum WebSite

Trap Control-C

Started by indiocolifa, September 22, 2005, 05:31:44 AM

Previous topic - Next topic

indiocolifa

Suppose a for-loop...
// write memory values
        FOR (xor(ebx,ebx); ebx < 16 && cx <= endaddr; inc(ebx)) do
            mov             ([eax+ecx], dl);    // fetch byte from 6502 memory
            stdout.put      (dl," ");
            IF (ebx == 7) THEN stdout.put("-") ;ENDIF;
            inc             (cx);       
        ENDFOR;


¿How I can trap Control-C to stop the listing?

James Ladd


    ; set console handler ...
    ;
    invoke SetConsoleCtrlHandler, main_ctrl_handler, 1
    mov eax, server

somewhere else in the code

; -----------------------------------------------------------------------------
; Handler for when user presses Ctrl-C or Ctrl-Brk on the console. Stops the
; app nicely.
;
align 4
main_ctrl_handler proc event:DWORD
    local error:DWORD
    xor eax, eax
    mov ebx, event
    .if ebx == CTRL_C_EVENT \
          || ebx == CTRL_BREAK_EVENT \
          || ebx == CTRL_LOGOFF_EVENT \
          || ebx == CTRL_SHUTDOWN_EVENT \
          || ebx == CTRL_CLOSE_EVENT
        ; disable ctrl handler and shutdown the server
        ;
        invoke SetConsoleCtrlHandler, main_ctrl_handler, 0
        mov eax, server
        invoke ExitProcess
    .endif
    ret
main_ctrl_handler endp

indiocolifa

Nice code (it's in MASM but it's easy to translate to HLA syntax).

I've seen this on the HLA Standard Library Reference:

Quote
ex.ControlC ($c000013a)
If control-C checking is enabled, Windows will raise this exception whenever the user presses control-C on the console device.

The enabling of Control-C trapping is done by SetConsoleCtrlHandler only? There is no "generic" (no-platform specific) method in HLA to do this?


Thank you very much.  :U