push ds mov ax, 40h mov ds, ax mov ax, word [82h] ; end of circular keypress buffer mov dx, word [80h] ; start of circular buffer test ax, ax jz .forcekeybuffer test dx, dx jz .forcekeybuffer mov bx, ax sub bx, dx ; cmp end, start jbe .forcekeybuffer ; below or equal is invalid --> test bl, 1 ; even amount of bytes ? jnz .forcekeybuffer ; no, invalid --> mov bx, word [1Ah] ; current head of circular buffer cmp bx, ax jae .forcekeybuffer sub bx, dx jb .forcekeybuffer test bl, 1 jnz .forcekeybuffer ; invalid --> mov bx, word [1Ch] ; current tail of circular buffer cmp bx, ax jae .forcekeybuffer sub bx, dx jb .forcekeybuffer test bl, 1 jz @F ; valid --> .forcekeybuffer: pop ds mov word [io_end_buffer], 3Eh mov word [io_start_buffer], 1Eh db __TEST_IMM8 ; (skip pop) @@: pop ds .check_rombios_buffer: push bx push dx mov ax, 40h ; dual mode segment/selector push ax mov ax, word [io_end_buffer] mov dx, word [io_start_buffer] pop ds test ax, ax jnz @F mov ax, word [82h] ; end of circular keypress buffer @@: test dx, dx jnz @F mov dx, word [80h] ; start of circular buffer @@: mov bx, ax sub bx, dx ; cmp end, start jbe .ret_dx_bx ; invalid --> test bl, 1 ; even amount of bytes ? jnz .ret_dx_bx ; invalid --> mov bx, word [1Ah] ; current head of circular buffer .loop: cmp bx, word [1Ch] ; equal to current tail ? je .ret_dx_bx ; yes, all entries checked --> cmp byte [bx], 3 ; is it Ctrl-C ? je handle_ctrl_c ; yes, handle --> inc bx inc bx ; -> next entry cmp bx, ax ; at end of buffer ? jb .loop ; no, loop --> ja .ret_dx_bx ; invalid --> mov bx, dx ; reset to start of buffer jmp .loop ; then loop --> .ret_dx_bx: pop dx pop bx