Vanilla_Fury

fasm_4_3

May 11th, 2021
283
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.58 KB | None | 0 0
  1. org 100h
  2.  
  3. ESC_ equ 01bh ;ascii code of escape
  4. BELL_ equ 7 ;ascii code of ring
  5.  
  6. W_SS_ equ 11h
  7. A_SS_ equ 1Eh
  8. S_SS_ equ 1Fh
  9. D_SS_ equ 20h
  10.  
  11. start_:
  12. mov ah, 09h ;output - helloStr
  13. mov dx, helloStr_
  14. int 21h
  15. main_:
  16. mov ah, 00h ;no echo input with waiting - output ah-scancode, al-ascii code
  17. int 16h
  18. cmp al, ESC_ ; escape ?
  19. je exit_ ;if yes exit
  20. jmp other_ ;if no go to other_
  21. other_:
  22. cmp ah, W_SS_ ;if scancode is less than W it's incorrect, jump to not_allowed_key
  23. jb not_allowed_key ;jump if below W
  24. cmp ah, D_SS_ ;if scancode is greater than D it's incorrect, jump to not_allowed_key
  25. ja not_allowed_key ;jump if above D
  26. cmp ah, A_SS_
  27. jb check_if_W_ ;jump if below A
  28. is_WASD:
  29. push ds ;save data segment
  30. mov bx, 40h ;mov 40h to bx
  31. mov ds, bx ;mov 40h to ds
  32. mov bx, 17h ;mov 17h to bx
  33. mov al, byte [bx] ;keyboard flags are at the address 40h:17h
  34. and al, 04h ;3rd bit is ctrl flag
  35. pop ds ;retrieve data segment
  36. cmp al, 04h ;is ctrl pressed?
  37. jne not_allowed_key ;if no jump to not_allowed_key
  38. mov bx, ctrlStr_ ;if yes mov address of first symbol of "ctrl+0" to bx
  39. add bx, 5 ;offset to "0" in "SHIFT+0"
  40. cmp ah, A_SS_ ;was the letter A?
  41. je ctrl_a_ ;if yes jump to ctrl_a_
  42. cmp ah, W_SS_ ;etc.....
  43. je ctrl_w_
  44. cmp ah, S_SS_
  45. je ctrl_s_
  46. jmp ctrl_d_
  47. check_if_W_:
  48. cmp ah, W_SS_
  49. je is_WASD
  50. jmp not_allowed_key
  51. not_allowed_key:
  52. mov ah, 02h
  53. mov dl, 07h ; sound
  54. int 21h
  55. jmp main_ ;go back to start
  56. displ_comb_:
  57. mov ah, 09h ;set text property of next...
  58. mov cx, 6 ;...6 characters (next 6 characters will have color set in bl)
  59. int 10h
  60. mov dx, ctrlStr_ ;output that string
  61. int 21h
  62. jmp main_
  63. ctrl_a_:
  64. mov byte [bx], 'A' ;in bx address of "0", change it to correct letter
  65. xor bh, bh ;clear bh
  66. mov bl, $4F ;set color
  67. jmp displ_comb_ ;jump to displ_comb_
  68. ctrl_w_:
  69. mov byte [bx], 'W'
  70. xor bh, bh
  71. mov bl, $0F
  72. jmp displ_comb_
  73. ctrl_s_:
  74. mov byte [bx], 'S'
  75. xor bh, bh
  76. mov bl, $20
  77. jmp displ_comb_
  78. ctrl_d_:
  79. mov byte [bx], 'D'
  80. xor bh, bh
  81. mov bl, $10
  82. jmp displ_comb_
  83. exit_:
  84. mov ah, 09h ;output - byeStr
  85. mov dx, byeStr
  86. int 21h
  87. mov ah, 07h ;wait for input
  88. int 21h
  89. ret
  90.  
  91. 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, "$"
  92. byeStr db 0dh, 0ah, "Press anything to terminate the program...$"
  93. ctrlStr_ db "ctrl+0 $"
Advertisement
Add Comment
Please, Sign In to add comment