Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- org 100h
- ESC_ equ 01bh ;ascii code of escape
- BELL_ equ 7 ;ascii code of ring
- Q_SS_ equ 10h ;scancode of q
- W_SS_ equ 11h ;scancode of w
- E_SS_ equ 12h ;scancode of e
- R_SS_ equ 13h ;scancode of r
- start_:
- mov ah, 09h ;output - helloStr
- mov dx, helloStr_
- int 21h
- main_:
- mov ah, 00h ;no echo input with waiting - output ah-scancode, al-ascii code
- int 16h
- cmp al, ESC_ ;was it escape?
- jne other_ ;if no go to other_
- jmp exit_ ;if yes exit
- other_:
- cmp ah, Q_SS_ ;if scancode is less than Q it's incorrect, jump to err_
- jb err_ ;jump if below
- cmp ah, R_SS_ ;if scancode is greater than R it's incorrect, jump to err_
- ja err_ ;jump if above
- push ds ;save data segment
- mov bx, 40h ;mov 40h to bx
- mov ds, bx ;mov 40h to ds (you cannot use immediate value here)
- mov bx, 17h ;mov 17h to bx
- mov al, byte [bx] ;keyboard flags are at the address 40h:17h
- and al, 02h ;second bit is shift flag
- pop ds ;retrieve data segment
- cmp al, 02h ;is shift pressed?
- jne err_ ;if no jump to err_
- mov bx, shiftStr_ ;if yes mov address of first symbol of "SHIFT+0" to bx
- add bx, 6 ;offset to "0" in "SHIFT+0"
- cmp ah, Q_SS_ ;was the letter Q?
- je shift_q_ ;if yes jump to shift_q_
- cmp ah, W_SS_ ;etc.....
- je shift_w_
- cmp ah, E_SS_
- je shift_e_
- cmp ah, R_SS_
- je shift_r_
- err_:
- mov ah, 02h ;play ring
- mov dl, BELL_
- int 21h
- jmp main_ ;go back to start
- displ_comb_:
- mov ah, 09h ;set text property of next...
- mov cx, 7 ;...7 characters (next 7 characters will have color set in bl)
- int 10h
- mov dx, shiftStr_ ;output that string
- int 21h
- jmp main_
- shift_q_:
- mov byte [bx], 'Q' ;in bx address of "0", change it to correct letter
- xor bh, bh ;clear bh
- mov bl, 1fh ;set color
- jmp displ_comb_ ;jump to displ_comb_
- shift_w_:
- mov byte [bx], 'W'
- xor bh, bh
- mov bl, 20h
- jmp displ_comb_
- shift_e_:
- mov byte [bx], 'E'
- xor bh, bh
- mov bl, 0f4h
- jmp displ_comb_
- shift_r_:
- mov byte [bx], 'R'
- xor bh, bh
- mov bl, 06h
- jmp displ_comb_
- exit_:
- mov ah, 09h ;output - byeStr
- mov dx, byeStr
- int 21h
- mov ah, 07h ;wait for input
- int 21h
- ret
- helloStr_ db "This program changes text properties", $0d, $0a, "You can exit on ESC", $0d, $0a, "Try to input SHIFT + Q, W, E, R:", $0d, $0a, "$"
- byeStr db 0dh, 0ah, "The program has now terminated. Press anything to continue...$"
- shiftStr_ db "SHIFT+0 $"
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement