Ledger Nano X - The secure hardware wallet
SHARE
TWEET

Untitled

a guest Apr 9th, 2020 208 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. .286
  2. .287
  3.  
  4. myCode segment para 'code'
  5. assume cs:myCode
  6. assume ss:myStack
  7. assume ds:myData
  8.  
  9. start:
  10. mov  ax,myData
  11. mov  ds,ax
  12.  
  13. push offset music
  14. call far ptr cvt_music
  15. add  sp,2
  16. mov  nNotes,ax
  17.  
  18. call far ptr inst_kbd
  19. call far ptr inst_metro
  20. call far ptr set_mode_13
  21.  
  22. xor  cx,cx
  23. xor  bx,bx
  24.  
  25. forever:
  26. xor  ax,ax
  27. mov  dx,3c8h
  28. out  dx,al
  29. inc  dx
  30. mov  al,ch
  31. out  dx,al
  32. out  dx,al
  33. mov  al,3fh
  34. out  dx,al
  35. cmp  bx,0
  36. jne  reverse
  37. add  cx,10h
  38. cmp  ch,40h
  39. jne  skip_reset
  40. mov  bx,1
  41. sub  cx,10h
  42. jmp  skip_reset
  43. reverse:
  44. sub  cx,10h
  45. cmp  ch,40h
  46. jna  skip_reset
  47. mov  bx,0
  48. add  cx,10h
  49. skip_reset:
  50. hlt
  51. cmp  dying,1
  52. jne  forever
  53.  
  54. call far ptr rem_metro
  55. call far ptr rem_kbd
  56. call far ptr set_mode_txt
  57.  
  58. mov  ah,4ch
  59. int  21h
  60.  
  61. ends myCode
  62.  
  63. farCode segment para 'farcode'
  64. assume cs:farCode
  65. assume ss:myStack
  66. assume ds:myData
  67.  
  68. set_mode_13:
  69. mov  ax,13h
  70. int  10h
  71. retf
  72.  
  73. set_mode_txt:
  74. mov  ax,3h
  75. int  10h
  76. retf
  77.  
  78. note_freq:
  79. nf_semi equ [bp+4]
  80. nf_cntr equ word ptr [bp-2]
  81. nf_cona equ 48
  82. push bp
  83. mov  bp,sp
  84. push ax
  85. mov  ax,nf_semi
  86. sub  ax,nf_cona
  87. ja   nf_high
  88. fld  freq_base_inv
  89. neg  ax
  90. jmp  nf_skip_high
  91. nf_high:
  92. fld  freq_base
  93. nf_skip_high:
  94. fld1
  95. cmp  ax,0
  96. je   nf_skip_power
  97. nf_power_loop:
  98. fmul st(0),st(1)
  99. dec  ax
  100. jnz  nf_power_loop
  101. nf_skip_power:
  102. fld  freq_timer_prediv
  103. fdiv st(0),st(1)
  104. fist nf_cntr
  105. pop  ax
  106. pop  bp
  107. ret
  108.  
  109. txt_to_semi:
  110. ts_src equ [bp+4]
  111. push bp
  112. mov  bp,sp
  113. push si
  114. push di
  115. mov  si,ts_src
  116. xor  cx,cx
  117. mov  cl,[si]
  118. cmp  cl,'-'
  119. jne  ts_norest
  120. mov  ax,0ffffh
  121. jmp  ts_done
  122. ts_norest:
  123. sub  cl,'A'
  124. mov  di,cx
  125. mov  cl,[note_names+di]
  126. inc  si
  127. mov  al,[si]
  128. sub  al,'0'
  129. mov  ah,12
  130. mul  ah
  131. inc  si
  132. cmp  byte ptr [si],'#'
  133. jne  ts_nosharp
  134. inc  cx
  135. jmp  ts_noflat
  136. ts_nosharp:
  137. cmp  byte ptr [si],'b'
  138. jne  ts_noflat
  139. dec  cx
  140. ts_noflat:
  141. add  ax,cx
  142. ts_done:
  143. pop  di
  144. pop  si
  145. pop  bp
  146. ret
  147.  
  148. cvt_music:
  149. cm_music equ [bp+6]
  150. push bp
  151. mov  bp,sp
  152. push si
  153. push di
  154. mov  si,cm_music
  155. mov  di,cm_music
  156. cm_loop:
  157. cmp  byte ptr [si],'$'
  158. je   cm_done
  159. push si
  160. call txt_to_semi
  161. add  sp,2
  162. cmp  ax,0ffffh
  163. je   cm_rest
  164. push ax
  165. call note_freq
  166. add  sp,2
  167. jmp  cm_rest_skip
  168. cm_rest:
  169. mov  ax,0
  170. cm_rest_skip:
  171. mov  [di],ax
  172. add  di,2
  173. add  si,3
  174. jmp  cm_loop
  175. cm_done:
  176. sub  di,cm_music
  177. shr  di,1
  178. mov  ax,di
  179. pop  di
  180. pop  si
  181. pop  bp
  182. retf
  183.  
  184. inst_metro:
  185. metro_freq_div equ 800h
  186. push es
  187. xor  ax,ax
  188. mov  es,ax
  189. cli
  190. mov  ax,es:[0020h]
  191. mov  oldTimerIsrOff,ax
  192. mov  ax,es:[0022h]
  193. mov  oldTimerIsrSeg,ax
  194. mov  word ptr es:[0020h],offset metro_isr
  195. mov  word ptr es:[0022h],farCode
  196. mov  al,00110100b   ; meaning that we're about to load
  197. out  43h,al         ; a new countdown value
  198. mov  ax,metro_freq_div
  199. out  40h,al         ; Output low byte.
  200. mov  al,ah          ; Output high byte.
  201. out  40h,al
  202. sti
  203. push iNote
  204. call do_music_cmd
  205. add  sp,2
  206. pop  es
  207. retf
  208.  
  209. rem_metro:
  210. push es
  211. xor  ax,ax
  212. mov  es,ax
  213. cli
  214. mov  ax,oldTimerIsrOff
  215. mov  es:[0020h],ax
  216. mov  ax,oldTimerIsrSeg
  217. mov  es:[0022h],ax
  218. mov  al,00110100b   ; meaning that we're about to load
  219. out  43h,al         ; a new countdown value
  220. mov  ax,0
  221. out  40h,al         ; Output low byte.
  222. mov  al,ah          ; Output high byte.
  223. out  40h,al
  224. sti
  225. call speaker_off
  226. pop  es
  227. retf
  228.  
  229. speaker_on:
  230. in   al,61h
  231. or   al,00000011b  
  232. out  61h,al
  233. ret
  234.  
  235. speaker_off:
  236. in   al,61h
  237. and  al,11111100b
  238. out  61h,al
  239. ret
  240.  
  241. set_speaker_tone:
  242. st_new_tone equ [bp+4]
  243. push bp
  244. mov  bp,sp
  245. mov  al,10110110b   ; meaning that we're about to load
  246. out  43h,al         ; a new countdown value into channel 0
  247. mov  ax,st_new_tone
  248. out  42h,al         ; Output low byte.
  249. mov  al,ah          ; Output high byte.
  250. out  42h,al
  251. pop  bp
  252. ret
  253.  
  254. do_music_cmd:
  255. dmc_icmd equ [bp+4]
  256. push bp
  257. mov  bp,sp
  258. push bx
  259. mov  bx,dmc_icmd
  260. shl  bx,1
  261. mov  bx,[bx + offset music]
  262. cmp  bx,0
  263. je   music_rest
  264. call speaker_on
  265. jmp  music_rest_skip
  266. music_rest:
  267. call speaker_off
  268. jmp  music_done
  269. music_rest_skip:
  270. push bx
  271. call set_speaker_tone
  272. add  sp,2
  273. music_done:
  274. pop  bx
  275. pop  bp
  276. ret
  277.  
  278. inst_kbd:
  279. push es
  280. xor  ax,ax
  281. mov  es,ax
  282. cli
  283. mov  ax,es:[024h]
  284. mov  old_kbd_off,ax
  285. mov  word ptr es:[024h],offset kbd_isr
  286. mov  ax,es:[026h]
  287. mov  old_kbd_seg,ax
  288. mov  word ptr es:[026h],farCode
  289. sti
  290. pop  es
  291. retf
  292.  
  293. rem_kbd:
  294. push es
  295. xor  ax,ax
  296. mov  es,ax
  297. cli
  298. mov  ax,old_kbd_off
  299. mov  es:[024h],ax
  300. mov  ax,old_kbd_seg
  301. mov  es:[026h],ax
  302. sti
  303. pop  es
  304. retf
  305.  
  306. metro_isr:
  307. dec  metroCounter
  308. jz   metro_cmd
  309. mov  al,20h
  310. out  20h,al
  311. iret
  312. metro_cmd:
  313. push ax
  314. mov  ax,metroStart
  315. mov  metroCounter,ax
  316. mov  ax,iNote
  317. inc  ax
  318. cmp  ax,nNotes
  319. jne  metro_skip_wrap
  320. xor  ax,ax
  321. metro_skip_wrap:
  322. mov  iNote,ax
  323. push ax
  324. call do_music_cmd
  325. add  sp,2
  326. mov  al,20h
  327. out  20h,al
  328. pop  ax
  329. iret
  330.  
  331. kbd_isr:
  332. push ax
  333. in   al,60h
  334. cmp  al,01h
  335. jne  finished
  336. mov  [dying],1
  337. finished:
  338. mov  al,020h
  339. out  020h,al
  340. pop  ax
  341. iret
  342.  
  343. ends farCode
  344.  
  345. myData segment para 'data'
  346. oldTimerIsrOff dw ?
  347. oldTimerIsrSeg dw ?
  348. old_kbd_off dw ?
  349. old_kbd_seg dw ?
  350. dying dw 0
  351. default_tempo equ 100
  352. metroCounter dw default_tempo
  353. metroStart dw default_tempo
  354. freq_base dd 1.059463
  355. freq_base_inv dd 0.943874
  356. freq_timer_prediv dd 2711.775 ; pit oscillator frequency predivided by concert a
  357. note_names db 0,2,3,5,7,8,10
  358. iNote dw 0
  359. nNotes dw ?
  360. music db 'C3 D3 E3 G3 C4 D4 E4 G4 C5 D5 E5 G5 C6 D6 E6 G6 '
  361.       db 'C7 G6 E6 D6 C6 G5 E5 D5 C5 G4 E4 D4 C4 G3 E3 D3 '
  362.       db 'A3 B3 C3 E3 A4 B4 C4 E4 A5 B5 C5 E5 A6 B6 C6 E6 '
  363.       db 'A7 E6 C6 B6 A6 E5 C5 B5 A5 E4 C4 B4 A4 E3 C3 B3 '
  364.       db 'C3 D3 E3 G3 C4 D4 E4 G4 C5 D5 E5 G5 C6 D6 E6 G6 '
  365.       db 'C7 G6 E6 D6 C6 G5 E5 D5 C5 G4 E4 D4 C4 G3 E3 D3 '
  366.       db 'A3 B3 C3 E3 A4 B4 C4 E4 A5 B5 C5 E5 A6 B6 C6 E6 '
  367.       db 'A7 E6 C6 B6 A6 E5 C5 B5 A5 E4 C4 B4 A4 E3 C3 B3 '
  368.       db 'A3 C3 F3 G3 A4 C4 F4 G4 A5 C5 F5 G5 A6 C6 F6 G6 '
  369.       db 'A7 G6 F6 C6 A6 G5 F5 C5 A5 G4 F4 C4 A4 G3 F3 C3 '
  370.       db 'B3 D3 G3 A4 B4 D4 G4 A5 B5 D5 G5 A6 B6 D6 G6 A7 '
  371.       db 'B7 A7 G6 D6 B6 A6 G5 D5 B5 A5 G4 D4 B4 A4 G3 D3 '
  372.       db 'A3bC3 E3bG3 A4bC4 E4bG4 A5bC5 E5bG5 A6bC6 E6bG6 '
  373.       db 'A7bG6 E6bC6 A6bG5 E5bC5 A5bG4 E4bC4 A4bG3 E3bC3 '
  374.       db 'B3bD3 F3 A4 B4bD4 F4 A5 B5bD5 F5 A6 B6bD6 F6 A7 '
  375.       db 'B7bA7 F6 D6 B6bA6 F5 D5 B5bA5 F4 D4 B4bA4 F3 D3 $'
  376. ends myData
  377.  
  378. myStack segment para stack 'stack'
  379. ends myStack
  380.  
  381. end start
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Top