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
- W_SS_ equ 11h
- A_SS_ equ 1Eh
- S_SS_ equ 1Fh
- D_SS_ equ 20h
- 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_ ; escape ?
- je exit_ ;if yes exit
- jmp other_ ;if no go to other_
- other_:
- cmp ah, W_SS_ ;if scancode is less than W it's incorrect, jump to not_allowed_key
- jb not_allowed_key ;jump if below W
- cmp ah, D_SS_ ;if scancode is greater than D it's incorrect, jump to not_allowed_key
- ja not_allowed_key ;jump if above D
- cmp ah, A_SS_
- jb check_if_W_ ;jump if below A
- is_WASD:
- push ds ;save data segment
- mov bx, 40h ;mov 40h to bx
- mov ds, bx ;mov 40h to ds
- mov bx, 17h ;mov 17h to bx
- mov al, byte [bx] ;keyboard flags are at the address 40h:17h
- and al, 04h ;3rd bit is ctrl flag
- pop ds ;retrieve data segment
- cmp al, 04h ;is ctrl pressed?
- jne not_allowed_key ;if no jump to not_allowed_key
- mov bx, ctrlStr_ ;if yes mov address of first symbol of "ctrl+0" to bx
- add bx, 5 ;offset to "0" in "SHIFT+0"
- cmp ah, A_SS_ ;was the letter A?
- je ctrl_a_ ;if yes jump to ctrl_a_
- cmp ah, W_SS_ ;etc.....
- je ctrl_w_
- cmp ah, S_SS_
- je ctrl_s_
- jmp ctrl_d_
- check_if_W_:
- cmp ah, W_SS_
- je is_WASD
- jmp not_allowed_key
- not_allowed_key:
- mov ah, 02h
- mov dl, 07h ; sound
- int 21h
- jmp main_ ;go back to start
- displ_comb_:
- mov ah, 09h ;set text property of next...
- mov cx, 6 ;...6 characters (next 6 characters will have color set in bl)
- int 10h
- mov dx, ctrlStr_ ;output that string
- int 21h
- jmp main_
- ctrl_a_:
- mov byte [bx], 'A' ;in bx address of "0", change it to correct letter
- xor bh, bh ;clear bh
- mov bl, $4F ;set color
- jmp displ_comb_ ;jump to displ_comb_
- ctrl_w_:
- mov byte [bx], 'W'
- xor bh, bh
- mov bl, $0F
- jmp displ_comb_
- ctrl_s_:
- mov byte [bx], 'S'
- xor bh, bh
- mov bl, $20
- jmp displ_comb_
- ctrl_d_:
- mov byte [bx], 'D'
- xor bh, bh
- mov bl, $10
- 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 CTRL + W, A, S, D:", $0d, $0a, "$"
- byeStr db 0dh, 0ah, "Press anything to terminate the program...$"
- ctrlStr_ db "ctrl+0 $"
Advertisement
Add Comment
Please, Sign In to add comment