; Terminate and Stay Resident program that clears screen, changes bgcolor to GREEN when 'G' is pressed, changes bgcolor to Blue when 'B' is pressed. [org 0x0100] jmp start oldkb: dd 0 attrib: db 0x07 ; keyboard interrupt service routine kbisr: push ax in al, 0x60 ; read char from keyboard port cmp al, 0x22 ; has G pressed je setGreen cmp al, 0x30 ; has B pressed je setBlue jmp noMatch ; B or G not pressed setBlue: mov byte [cs:attrib], 0x17 jmp clrscr setGreen: mov byte [cs:attrib], 0x27 clrscr: mov ax, 0xb800 ; load video base in ax mov es, ax ; point es to video base xor di, di ; point di to top left column mov al, 0x20 ; load space char in al mov ah, [cs:attrib] ; load attribute byte in ah mov cx, 2000 ; number of screen locations cld ; auto increment mode rep stosw ; clear the whole screen jmp exit noMatch: pop ax jmp far [cs:oldkb] ; call original keyboard ISR exit: mov al, 0x20 out 0x20, al ; send EOI to PIC pop ax iret ; return from interrupt start: mov ax, 0xb800 ; load video base in ax mov es, ax ; point es to video base xor di, di ; point di to top left column mov al, 0x20 ; load space char in al mov ah, [cs:attrib] ; load attribute byte in ah mov cx, 2000 ; number of screen locations cld ; auto increment mode rep stosw ; clear the whole screen xor ax, ax mov es, ax ; point es to IVT base mov ax, [es:9*4] mov [oldkb], ax ; save offset of old routine mov ax, [es:9*4+2] mov [oldkb+2], ax ; save segment of old routine cli ; disable interrupts mov word [es:9*4], kbisr ; store offset at n*4 mov [es:9*4+2], cs ; store segment at n*4+2 sti ; enable interrupts mov dx, start ; end of resident portion add dx, 15 ; round up to next para mov cl, 4 shr dx, cl ; number of paras mov ax, 0x3100 ; terminate and stay resident int 0x21