Linux x86_64 implementation of libglitch : https://github.com/erlehmann/libglitch.git
x86-64
nasm
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

yaglitch.asm 14KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833
  1. ; yaglitch : Yet Another Glitch
  2. ; Copyright (C) 2018 Weber Yann
  3. ;
  4. ; This program is free software; you can redistribute it and/or modify
  5. ; it under the terms of the GNU General Public License as published by
  6. ; the Free Software Foundation; either version 3 of the License, or
  7. ; any later version.
  8. ;
  9. ; This program is distributed in the hope that it will be useful,
  10. ; but WITHOUT ANY WARRANTY; without even the implied warranty of
  11. ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  12. ; GNU General Public License for more details.
  13. ;
  14. ; You should have received a copy of the GNU General Public License
  15. ; along with this program. If not, see <http://www.gnu.org/licenses/>.
  16. ;
  17. [bits 64]
  18. %include "sdl.asm"
  19. %include "utils.asm"
  20. %define STACK_SZ 256
  21. %define MAX_FILE_SZ (16 * 17) ; 16 lines of 16 chars + newline chr
  22. %define NL "!"
  23. section .data
  24. op_ptrs: ; pointers on OP functions
  25. dq OP.t ; a
  26. dq OP.put ; b
  27. dq OP.drop ; c
  28. dq OP.mul ; d
  29. dq OP.div ; e
  30. dq OP.add ; f
  31. dq OP.sub ; g
  32. dq OP.mod ; h
  33. dq 0 ; i : syntax error
  34. dq OP.lshift ; j
  35. dq OP.rshift ; k
  36. dq OP.and ; l
  37. dq OP.or ; m
  38. dq OP.xor ; n
  39. dq OP.not ; o
  40. dq OP.dup ; p
  41. dq OP.pick ; q
  42. dq OP.swap ; r
  43. dq OP.lt ; s
  44. dq OP.gt ; t
  45. dq OP.eq ; u
  46. audiospec_wanted: ; SDL_audio configuration
  47. dd 8000 ; freq
  48. dw AUDIO_U8 ; format
  49. db 1 ; channels
  50. db 0 ; silence
  51. dw 0x100 ; samples
  52. dd 0 ; size
  53. dw 0 ; allign
  54. dq audio_cllbck
  55. dq 0 ; userdata
  56. ; text messages
  57. def_str usage, "Usage : "
  58. def_str opts, {" FILE.glitch",0xA}
  59. def_str openerr, {'Error opening file : "', 0xA}
  60. def_str syntax_error, {"Syntax error", 0xA}
  61. def_str bigline_error, {"Line with more than 16 tokens !", 0xA}
  62. def_str nl_error, {"Character \n is not the last one", 0xA}
  63. def_str badop_error, {"Bad OP", 0xA}
  64. window_title: db "Yaglitch", 0x0
  65. section .bss
  66. ; glitch name (1st line) : len 16 + \0
  67. glitch_name: resb 17
  68. ; program internal repr for stack machine
  69. ; each token uses 2 words : 1st for the callback address 2nd for
  70. ; optional value
  71. glitch_pgm: resq 16 * 16 * 2
  72. ; stack machine ring buffer
  73. stack_buff: resd STACK_SZ
  74. ; top of stack pointer
  75. tosp: resq 1
  76. ; stack machine rgister
  77. t: resd 1
  78. ; audiospec returned from SDL
  79. audiospec_recv: resb 32
  80. ; Event receveid from SDL
  81. %ifdef SDL1
  82. event: resb 24
  83. %endif
  84. %ifdef SDL2
  85. event: resb 56
  86. evt_cnt: resb 1
  87. %endif
  88. %ifdef MIX_AUDIO
  89. cllbck_heap: resq 1
  90. cllbck_heapsz: resw 1
  91. %endif
  92. ; Pipe allowing callback to send data to main thread
  93. ipc_pipe:
  94. .rd: resd 1
  95. .wr: resd 1
  96. visu_data_buff: resb 0x100
  97. %ifdef SDL2
  98. visu_win: resq 1
  99. %endif
  100. visu_scr: resq 1
  101. visu_surf: resq 1
  102. section .text
  103. global _start
  104. _start:
  105. ; checking args
  106. mov rcx, [rsp]
  107. cmp rcx, 2
  108. jne exit.badarg
  109. mov rax, 0x2 ; sys_open
  110. mov rdi, [rsp+16] ; argv[1]
  111. xor rsi, rsi ; no flags
  112. xor rdx, rdx ; O_RDONLY
  113. syscall
  114. cmp rax, 0
  115. jl exit.err_open
  116. push rax ; source fd
  117. mov rax, 0xc ; brk
  118. xor rdi, rdi
  119. syscall
  120. push rax ; heap start
  121. mov rdi, rax
  122. add rdi, MAX_FILE_SZ ; new heap end
  123. mov rax, 0xc ; brk
  124. syscall
  125. pop rsi ; heap start
  126. mov r14, rsi
  127. xor rax, rax ; sys_read
  128. mov rdi, [rsp] ; source_fd
  129. mov rdx, MAX_FILE_SZ
  130. syscall
  131. cmp rax, 0
  132. jl exit.err_open
  133. mov r15, rax
  134. mov rax, 0x3 ; sys_close
  135. pop rdi ; source_fd
  136. syscall
  137. mov rbx, r15 ;read size
  138. mov rdi, r14 ; heap start
  139. add rdi, rbx ; heap end
  140. mov r15, rdi
  141. mov rax, 0xc ; brk
  142. syscall ; shrink heap to read size
  143. ; init program space
  144. mov rdi, glitch_pgm
  145. xor rax, rax
  146. stosq
  147. stosq
  148. mov rsi, r14
  149. push rsi
  150. xor r13, r13
  151. xor rbx, rbx
  152. parse:
  153. ; go trhough file , with rsi current ptr, r15 file stop
  154. ; r13 will contain updated lineno and rbx chr in current line
  155. ; rdi store the destination pointer
  156. ; parse glitch name
  157. mov rcx, 16
  158. mov rdi, glitch_name
  159. .name_loop:
  160. inc rbx
  161. lodsb
  162. test al, al ; EOF
  163. jz .no_nl
  164. cmp al, 0xA
  165. je .trailing_nl
  166. cmp al, "!" ; EOL
  167. je .name_end
  168. cmp al, "_"
  169. je .chrname
  170. cmp al, "0"
  171. jl exit.syntax_error
  172. cmp al, "9"
  173. jle .chrname
  174. cmp al, "a"
  175. jl exit.syntax_error
  176. cmp al, "z"
  177. jg exit.syntax_error
  178. .chrname:
  179. stosb
  180. loop .name_loop
  181. jmp exit.bigline
  182. .name_end:
  183. inc r13 ; lineno
  184. xor rbx, rbx
  185. xor al, al
  186. stosb
  187. ; parsing tokens
  188. xor edx, edx ; 32bits numeric token value
  189. xor eax, eax
  190. xor r10, r10 ; numeric token flag (1 mean in numeric token)
  191. xor r11, r11 ; numeric token len
  192. mov rcx, r15
  193. sub rcx, r14
  194. mov rdi, glitch_pgm
  195. .parse_loop:
  196. inc rbx
  197. lodsb
  198. test al, al
  199. jz .no_nl
  200. cmp al, 0xA
  201. je .trailing_nl
  202. cmp al, "!" ; EOL
  203. je .next_line
  204. cmp al, "." ; token separator
  205. je .next_token
  206. cmp al, "0"
  207. jl exit.syntax_error
  208. cmp al, "9"
  209. jle .dec_token
  210. cmp al, "A"
  211. jl exit.syntax_error
  212. cmp al, "F"
  213. jle .hex_token
  214. jmp .op_match ; allowing loop near jump
  215. .end_op:
  216. stosq
  217. xor rax, rax
  218. stosq
  219. loop .parse_loop
  220. .hex_token:
  221. sub al, "A" - 10
  222. jmp .numeric_token
  223. .dec_token:
  224. sub al, "0"
  225. .numeric_token:
  226. cmp r11, 8
  227. je exit.syntax_error ; Numeric constant OF
  228. inc r11
  229. mov r10, 1
  230. shl edx, 4
  231. add edx, eax
  232. loop .parse_loop
  233. .next_token:
  234. test r10, r10 ; check for numeric constant
  235. jnz .add_numeric
  236. loop .parse_loop
  237. .next_line:
  238. inc r13
  239. xor rbx, rbx
  240. .loop_parse_loop:
  241. loop .parse_loop
  242. .add_numeric:
  243. mov rax, OP.numeric
  244. stosq
  245. xor rax, rax
  246. xor r11, r11
  247. xor r10, r10
  248. xchg rax, rdx
  249. shl rax, 32
  250. stosq
  251. xor rax, rax
  252. jmp .loop_parse_loop
  253. .trailing_nl:
  254. ; check that NL is the last chr, else syntax error
  255. cmp rsi, r15
  256. jne exit.nl_not_last
  257. jmp .parse_end
  258. .op_match:
  259. ; allow loop .parse_loop near jump
  260. cmp al, "a"
  261. jl exit.syntax_error
  262. cmp al, "u"
  263. jg exit.syntax_error
  264. ; OP shortand matching
  265. ; checking for previous numeric token to write
  266. test r10, r10
  267. jz .match_op
  268. push rax
  269. ; add previous numeric token
  270. mov rax, OP.numeric
  271. stosq
  272. xor rax, rax
  273. xor r11, r11 ; numeric token length raz
  274. xor r10, r10 ; numeric token flag raz
  275. xchg rax, rdx
  276. shl rax, 32 ; shl to allow reading as dword ?
  277. stosq
  278. pop rax
  279. .match_op:
  280. sub al, "a"
  281. shl rax, 3 ; mul by 8 (size of ptr)
  282. add rax, op_ptrs
  283. mov rax, [rax]
  284. test rax, rax
  285. jz exit.bad_op
  286. jmp .end_op
  287. .no_nl: ; TODO : print warning
  288. ; no NL at EOF
  289. .parse_end:
  290. ; clean heap
  291. mov rax, 0xc
  292. pop rdi
  293. syscall
  294. ; print glitch name
  295. mov rax, "Playing "
  296. push rax
  297. mov rax, 1
  298. mov rdi, 1
  299. mov rsi, rsp
  300. mov rdx, 8
  301. syscall
  302. pop rax
  303. mov rdi, glitch_name
  304. call strlen
  305. mov rdx, rax
  306. mov rax, 1
  307. mov rdi, 1
  308. mov rsi, glitch_name
  309. syscall
  310. mov rax, `\n`
  311. push rax
  312. mov rax, 1
  313. mov rdi, 1
  314. mov rsi, rsp
  315. mov rdx, 1
  316. syscall
  317. pop rax
  318. ; init stack machine runtime
  319. stack_init:
  320. mov rcx, STACK_SZ
  321. mov rdi, stack_buff
  322. xor rax, rax
  323. mov [t], eax
  324. .loop_buff_init:
  325. stosd
  326. loop .loop_buff_init
  327. mov eax, (STACK_SZ - 1) * 4
  328. mov [tosp], eax
  329. sdl_init:
  330. ; Opening IPC pipe
  331. mov rax, 0x16 ; sys_pipe
  332. mov rdi, ipc_pipe
  333. syscall
  334. test rax, rax
  335. jnz exit_fatal
  336. mov rdi, 0x0000FFFF
  337. call SDL_Init
  338. mov rdi, audiospec_wanted
  339. mov rsi, audiospec_recv
  340. call SDL_OpenAudio
  341. ; video init 256*256 window
  342. ; init visu_scr : *screen
  343. %ifdef SDL1
  344. mov rdi, 256
  345. mov rsi, 256
  346. mov rdx, 32
  347. ;mov rcx, SDL_SWSURFACE
  348. mov rcx, SDL_DOUBLEBUF
  349. call SDL_SetVideoMode
  350. call SDL_GetVideoSurface
  351. mov [visu_scr], rax
  352. %endif
  353. %ifdef SDL2
  354. mov rdi, window_title
  355. mov rsi, SDL_WINDOWPOS_UNDEFINED
  356. mov rdx, SDL_WINDOWPOS_UNDEFINED
  357. mov rcx, 256
  358. mov r8, 256
  359. xor r9, r9
  360. call SDL_CreateWindow
  361. mov [visu_win], rax
  362. mov rdi, rax
  363. call SDL_GetWindowSurface
  364. mov [visu_scr], rax
  365. %endif
  366. ; init SDL surface according to SDL screen in visu_surf
  367. xor rdi, rdi ; flasg
  368. mov rsi, 256 ; width
  369. mov rdx, 256 ; height
  370. mov rcx, 32 ; 32 bits depth
  371. mov r8, 0xff ; rmask
  372. mov r9, 0xff00 ; gmask
  373. mov rax, 0xff0000 ; bmask
  374. push rax
  375. push rax
  376. shl rax, 8 ; amask
  377. mov [rsp+8], rax
  378. call SDL_CreateRGBSurface
  379. mov [visu_surf], rax
  380. test rax, rax
  381. jz sdl_error
  382. pop rcx
  383. pop rcx
  384. ; RAZ surface & blit
  385. call clear_screen
  386. %ifdef MIX_AUDIO
  387. ; init callback heap infos
  388. mov rax, 0xc ; brk
  389. xor rdi, rdi ; get heap start addr
  390. mov [cllbck_heapsz], rdi
  391. syscall
  392. cmp rax, -1
  393. je exit_fatal
  394. mov [cllbck_heap], rax
  395. %endif
  396. audio_start:
  397. ;start audio
  398. xor rdi, rdi
  399. call SDL_PauseAudio
  400. loop_event:
  401. xor rdi, rdi
  402. mov [event], rdi
  403. mov rdi, event
  404. call SDL_WaitEvent
  405. cmp rax, 0
  406. je sdl_error ; error fetching event...
  407. xor rdi, rdi
  408. %ifdef SDL1
  409. mov dil, [event]
  410. cmp dil, SDL_QUIT
  411. je exit
  412. %endif
  413. %ifdef SDL2
  414. mov edi, [event]
  415. cmp edi, SDL_QUIT
  416. je exit
  417. %endif
  418. evt: ; not exit event
  419. visu:
  420. ; starts by reading from IPC pipe
  421. xor rax, rax ; sys_read
  422. xor rdi, rdi
  423. mov edi, [ipc_pipe.rd]
  424. mov rsi, visu_data_buff
  425. mov rdx, 0x100
  426. syscall
  427. cmp rax, -1
  428. je exit_fatal
  429. jmp loop_event ; loop again
  430. sdl_error:
  431. ; display error & exit
  432. call SDL_GetError
  433. push rax
  434. .dbg:
  435. test rax, rax
  436. jz .no_err
  437. mov rdi, rax
  438. call strlen
  439. .printerr:
  440. mov rdx, rsi ; msglen
  441. pop rdi ; msg
  442. mov rax, 1 ; write
  443. mov rdi, 2 ; stderr
  444. syscall
  445. mov rdi, 0xF
  446. jmp sdl_exit_err
  447. .no_err:
  448. mov rdi, 0x5
  449. jmp sdl_exit_err
  450. exit_fatal:
  451. mov rdi, 42
  452. jmp exit.exit_err
  453. sdl_exit_err:
  454. push rdi
  455. call SDL_Quit
  456. pop rdi
  457. mov rax, 0x3c
  458. syscall
  459. exit:
  460. call SDL_Quit
  461. xor rdi, rdi
  462. mov rax, 0x3c
  463. syscall
  464. .err_open:
  465. mov rax, 1
  466. mov rdi, 2
  467. mov rsi, openerr
  468. mov rdx, openerr_len - 1
  469. syscall
  470. mov rdi, [rsp+16]
  471. push rdi
  472. call strlen
  473. mov rdx, rax
  474. mov rax, 1
  475. mov rdi, 2
  476. pop rsi
  477. syscall
  478. mov rax, 1
  479. mov rdi, 2
  480. mov rsi, openerr + openerr_len - 2
  481. mov rdx, 2
  482. syscall
  483. .badarg:
  484. mov rax, 1
  485. mov rdi, 2
  486. mov rsi, usage
  487. mov rdx, usage_len
  488. syscall
  489. mov rdi, [rsp+8]
  490. call strlen
  491. mov rdx, rax
  492. mov rax, 1
  493. mov rdi, 2
  494. mov rsi, [rsp+8]
  495. syscall
  496. mov rax, 1
  497. mov rdi, 2
  498. mov rsi, opts
  499. mov rdx, opts_len
  500. syscall
  501. mov rdi, 1
  502. .exit_err: ; with rdi error code
  503. mov rax, 0x3c ; exit
  504. syscall
  505. ; expect : r13 lineno, rbx chr num in line
  506. ; TODO: real error message
  507. .nl_not_last:
  508. mov rsi, nl_error
  509. mov rsi, nl_error_len
  510. push qword 3
  511. jmp exit.parse_error
  512. .syntax_error:
  513. mov rsi, syntax_error
  514. mov rdx, syntax_error_len
  515. push qword 2
  516. jmp exit.parse_error
  517. .bigline:
  518. mov rsi, bigline_error
  519. mov rdx, bigline_error_len
  520. push qword 2
  521. jmp exit.parse_error
  522. .bad_op:
  523. mov rsi, badop_error
  524. mov rdx, badop_error_len
  525. push qword 2
  526. jmp exit.parse_error
  527. .parse_error:
  528. ; print error lineno & chrno
  529. push rsi ; source ptr
  530. push rdx
  531. push rbx ; chrno in line
  532. sub r14, rsi ; chr count
  533. push 14
  534. mov rdi, "chr:0x"
  535. mov rsi, 6
  536. call short_err
  537. pop rdi ; chr count
  538. mov rsi, 2
  539. call print_hnum
  540. mov rdi, ",line:0x"
  541. mov rsi, 8
  542. call short_err
  543. mov rdi, r13
  544. mov rsi, 2
  545. call print_hnum
  546. mov rdi, ",col:0x"
  547. mov rsi, 7
  548. call short_err
  549. pop rdi
  550. mov rsi, 2
  551. call print_hnum
  552. mov rdi, ` :\t`
  553. mov rsi, 3
  554. call short_err
  555. pop rdx
  556. pop rsi
  557. mov rax, 1
  558. mov rdi, 2
  559. syscall
  560. pop rdi
  561. jmp exit.exit_err
  562. short_err:
  563. ; rdi is the message (less than 8 chr)
  564. ; rsi is message len
  565. push rdi
  566. mov rdx, rsi
  567. mov rsi, rsp
  568. mov rax, 1
  569. mov rdi, 1
  570. syscall
  571. pop rdi
  572. ret
  573. strlen:
  574. ; rdi containing str pointer
  575. ; rax will contain strlen and rdi is unchanged
  576. mov rsi, rdi
  577. xor rdx, rdx
  578. pushf
  579. cld
  580. .loop:
  581. inc rdx
  582. lodsb
  583. mov cl, al
  584. test al, al
  585. jnz .loop
  586. dec rdx
  587. mov rax, rdx
  588. popf
  589. ret
  590. print_hnum:
  591. ; rdi : number to print
  592. ; rsi : output fd
  593. pushf
  594. mov rax, rdi
  595. xor rcx, rcx
  596. push rcx ; using stack as buffer
  597. std
  598. lea rdi, [rsp + 8]
  599. .loop:
  600. test rax, rax
  601. jz .endloop
  602. inc rcx
  603. inc rcx
  604. push rax
  605. and al, 0x0F
  606. call .al2digit
  607. stosb
  608. mov rax, [rsp]
  609. shr al, 4
  610. call .al2digit
  611. stosb
  612. pop rax
  613. shr rax, 8
  614. jmp .loop
  615. .endloop:
  616. mov rax, 1
  617. xchg rdi, rsi
  618. inc rsi
  619. ;mov rdi, rsi
  620. ;mov rsi, rsp
  621. mov rdx, rcx
  622. syscall
  623. pop rax
  624. popf
  625. ret
  626. .al2digit:
  627. cmp al, 9
  628. jg .hex
  629. add al, "0"
  630. ret
  631. .hex:
  632. add al, "A" - 10
  633. ret
  634. %ifndef MIX_AUDIO
  635. ; simplest/shortes audio_callback : copy byte returned by run_glitch in *stream
  636. audio_cllbck:
  637. ; rdi -> *userdata
  638. ; rsi -> *stream
  639. ; rdx -> stream_len
  640. push rbx
  641. mov rcx, rdx
  642. mov rdi, rsi
  643. push rsi
  644. push rdx
  645. .loop:
  646. push rcx
  647. push rdi
  648. call run_glitch
  649. pop rdi
  650. stosb
  651. pop rcx
  652. inc dword [t]
  653. loop .loop
  654. mov rax, 1 ; write stream data to IPC pipe
  655. xor rdi, rdi
  656. mov edi, [ipc_pipe.wr]
  657. pop rdx
  658. pop rsi
  659. syscall
  660. cmp rax, -1
  661. je exit_fatal
  662. pop rbx
  663. ret
  664. %endif
  665. %ifdef MIX_AUDIO
  666. ; another version of the audio callback using heap to store the data
  667. ; and SDL_MixAudio to copy data in *stream
  668. audio_cllbck:
  669. ; rdi -> *userdata
  670. ; rsi -> *stream
  671. ; rdx -> stream_len
  672. push rbx
  673. mov rcx, [cllbck_heapsz]
  674. cmp rcx, rdx
  675. jl .heap_brk
  676. .continue:
  677. mov rdi, [cllbck_heap]
  678. push rdx ; len
  679. push rdi
  680. push rsi ; *stream, dst
  681. mov rcx, rdx
  682. .pop_loop: ; populating heap with glitch datas
  683. push rcx
  684. push rdi
  685. call run_glitch
  686. pop rdi
  687. stosb
  688. pop rcx
  689. inc dword [t]
  690. loop .pop_loop
  691. pop rdi ; *stream
  692. pop rsi ; heap_start
  693. pop rdx ; len
  694. ;mov rsi, [rsp] ; heap_start
  695. ;mov rdx, [rsp+8] ; len
  696. mov rcx, SDL_MAX_VOLUME
  697. call SDL_MixAudio
  698. ;mov rax, 0x1 ; sys_write
  699. ;mov rdi, [ipc_pipe.wr]
  700. ;pop rsi ; heap_start
  701. ;pop rdx ; len
  702. ;syscall
  703. ;cmp rax, -1
  704. ;je exit_fatal
  705. pop rbx
  706. ret
  707. .heap_brk: ; resize heap to handle
  708. push rdi
  709. push rsi
  710. push rdx
  711. mov rdi, [cllbck_heap]
  712. add rdi, rdx
  713. mov rax, 0xc ; brk
  714. syscall
  715. pop rdx
  716. pop rsi
  717. pop rdi
  718. mov [cllbck_heapsz], rdx
  719. jmp .continue
  720. %endif
  721. run_glitch:
  722. ; Run the glitch_pgm
  723. ; return TOSP value in eax
  724. mov rsi, glitch_pgm
  725. .loop:
  726. lodsq
  727. test rax, rax
  728. jz .end_glitch
  729. push rax
  730. lodsq
  731. mov rdi, rax
  732. pop rax
  733. push rsi
  734. call rax
  735. pop rsi
  736. jmp .loop
  737. .end_glitch:
  738. xor rbx, rbx
  739. mov ebx, [tosp]
  740. lea rdi, [stack_buff + rbx]
  741. mov eax, [rdi]
  742. ; DEBUG (can be use to output data to stdout)
  743. ;push rax
  744. ;xor rdi, rdi
  745. ;mov rdi, rax
  746. ;mov rsi, 1
  747. ;call print_hnum
  748. ;mov rax, " "
  749. ;push rax
  750. ;mov rax, 1
  751. ;mov rdi, 1
  752. ;mov rsi, rsp
  753. ;mov rdx, 1
  754. ;syscall
  755. ;pop rax
  756. ;pop rax
  757. ; /DEBUG
  758. ret
  759. %include "yaglitch_op.asm"
  760. %include "yaglitch_ui.asm"