I have a space-like project and am trying to handle keyboard interruption. My problem is that I do not want to use global variable(ship) in my_keyboard_interrupt_handler . But I send the ship as a parameter for this function, I do not know how to organize setvect(0x09,my_keyboard_interrupt_handler); . If there is any way to use the setvect function, please give me some recommendations.
int main() { void interrupt (*old_keyboard_interrupt_handler)(); ship = (space_ship*)malloc(sizeof(space_ship)); old_keyboard_interrupt_handler = getvect(0x09); ... setvect(0x09,my_keyboard_interrupt_handler); return 0; } int handle_key() { int key; asm{ sti in al,60H xor ah,ah mov key,ax in al,61h or al,82h out 61h,al and al,7fh out 61h,al mov al,20h out 20h,al } return key; }
my keyboard interception handler:
void interrupt my_keyboard_interrupt_handler() { int key = handle_key(); if(key == SPACE){ }else if(key == RIGHT){ ship->column++; }else if(key == LEFT){ ship->column--; }else if(key == UP){ ship->row_start--; ship->row_end--; } else if(key == DOWN){ ship->row_start++; ship->row_end++; }else if(key == ESC){ } clrscr(); print_space_ship(ship); }
In short, I want to do void interrupt my_keyboard_interrupt_handler(space_ship* ship){..} . But I do not know how to handle the setvect function in this situation.
source share