dino.asm 4.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303
  1. SYS_EXIT equ 1
  2. SYS_READ equ 3
  3. SYS_WRITE equ 4
  4. STDIN equ 0
  5. STDOUT equ 1
  6. SYS_IOCTL equ 54
  7. SYS_TIMER_FD_CREATE equ 0x142
  8. SYS_TIMER_FD_SETTIME equ 0x145
  9. section .bss
  10. sz RESB 4 ; 4 byte for window size
  11. num resb 4 ;4 byte for ascii numbers
  12. srow resb 1 ;screen rows
  13. scol resb 1 ;screen columns
  14. tof resb 1 ; 1 byte store top offstet
  15. tmp resb 1
  16. section .data
  17. ;num to ascii variables
  18. ha db 0 ;hundreds
  19. ta db 0 ;tens
  20. ;graphics layout
  21. rcount db 0;
  22. lb db 0xa; linebrak
  23. lof db 0; ; left offset
  24. gh db 42; ; game height
  25. gw db 102; ; game width
  26. scrst db 'Score: 000' ; score string
  27. scrstln equ $ - scrst ; sore string length
  28. scrlof equ 5 ;score lfet offset
  29. scrfll equ 85 ;score lfet offset
  30. pls db 0x2b ;plus for corner
  31. hl db 0x2d ;horizontal line |
  32. vl db 0x7c ;vertical line -
  33. ;error
  34. txt_error_term_dim db 'Error terminal got wrong dimensions'
  35. txt_error_term_dim edu 35
  36. ;timer
  37. tfd RESB 4 ;file descriptro
  38. itimer RESQ 2 ;timer init struct
  39. tval RESB 8 ;variable to store triggercount when reading timmerfd
  40. ;dino1
  41. ; __
  42. ; / _)
  43. ; .-^^^-/ /
  44. ; __/ /
  45. ;<__.|_|-|_|
  46. dino11 db ' __ '
  47. dino12 db ' / _)'
  48. dino13 db ' .-^^^-/ / '
  49. dino14 db ' __/ / '
  50. dino15 db '<__.|_|-|_| '
  51. ;dino2
  52. ; __
  53. ; | _)
  54. ; .-^^^-| |
  55. ; __/ /
  56. ;<__./_/-\_\
  57. dino21 db ' __ '
  58. dino22 db ' | _) '
  59. dino23 db ' .-^^^-| | '
  60. dino24 db ' __/ / '
  61. dino25 db '<__./_/-\_\ '
  62. dinolen equ 15
  63. section .text
  64. global _start
  65. _start:
  66. ;create timer
  67. mov eax, SYS_TIMER_FD_CREATE
  68. mov ebx, 1
  69. mov ecx, 0
  70. int 0x80
  71. ;store fd adress
  72. mov [tfd], eax
  73. ; get windwo size
  74. mov eax, SYS_IOCTL ; syscall ioctl
  75. mov ebx, STDOUT ; stdout for something?
  76. mov ecx, 0x5413 ; get windowsize command TIOCGWINSZ
  77. mov edx, sz ; target struct
  78. int 0x80 ; call kernel
  79. ;print fullscreen
  80. ;save window size
  81. mov al, [sz]
  82. mov [srow], al
  83. mov al, [sz+2]
  84. mov [scol], al
  85. ;calc offset
  86. ;top
  87. xor eax, eax
  88. xor bx, bx
  89. movzx ax, [srow] ;move one byte fill rest with zero
  90. ;and ax, 0xFF ; bitmask so that only srow (1byte) is inside ax (2byte) else it is scol+srow
  91. ;mov bx, [gh]
  92. ;and bx, 0xFF
  93. sub ax, [gh] ;screenrows - geameheight
  94. mov bl, 2
  95. div bl
  96. mov al, 0x6
  97. mov [tof], al
  98. ;jmp exit
  99. ;left
  100. movxz ax, [scol]
  101. ;and ax, 0xFF
  102. ;mov bx, [gw]
  103. ;and bx, 0xFF
  104. sub ax, [gw]
  105. mov bl, 0x2
  106. div bl
  107. mov [lof], al
  108. ;print terminal
  109. print:
  110. jmp topoffset
  111. emptyterminal:
  112. mov eax, SYS_WRITE
  113. mov ebx, STDOUT
  114. mov ecx, lb
  115. mov edx, 1
  116. ;int 0x80
  117. inc byte [rcount]
  118. mov al, [rcount]
  119. ;cmp [srow], al
  120. cmp al, [srow]
  121. jl emptyterminal
  122. topoffset:
  123. mov [rcount], byte 0x0
  124. mov eax, SYS_WRITE
  125. mov ebx, STDOUT
  126. mov ecx, lb
  127. mov edx, 1
  128. ;int 0x80
  129. inc byte [rcount]
  130. mov al, [rcount]
  131. cmp al, [tof]
  132. jle topoffset
  133. toprow:
  134. tlcorner:
  135. mov eax, SYS_WRITE
  136. mov ebx, STDOUT
  137. mov ecx, pls
  138. mov edx, 1
  139. int 0x80
  140. tr_start:
  141. mov eax, SYS_WRITE
  142. mov ebx, STDOUT
  143. mov ecx, hl
  144. mov edx, 1
  145. int 0x80
  146. inc byte [rcount]
  147. mov al, [rcount]
  148. cmp al, scrlof
  149. jl tr_start
  150. mov al, 0
  151. mov [rcount], al
  152. tr_score:
  153. mov eax, SYS_WRITE
  154. mov ebx, STDOUT
  155. mov ecx, scrst
  156. mov edx, scrstln
  157. int 0x80
  158. tr_fill:
  159. mov eax, SYS_WRITE
  160. mov ebx, STDOUT
  161. mov ecx, hl
  162. mov edx, 1
  163. int 0x80
  164. inc byte [rcount]
  165. mov al, [rcount]
  166. cmp al, scrfll
  167. jl tr_fill
  168. trcorner:
  169. mov eax, SYS_WRITE
  170. mov ebx, STDOUT
  171. mov ecx, pls
  172. mov edx, 1
  173. int 0x80
  174. linebreak:
  175. mov eax, SYS_WRITE
  176. mov ebx, STDOUT
  177. mov ecx, lb
  178. mov edx, 1
  179. int 0x80
  180. exit:
  181. ;exit
  182. mov eax, 1
  183. mov ebx, 0
  184. int 0x80
  185. ; print rows
  186. mov ecx, 0
  187. mov cl, [sz] ;rows in ecx
  188. hundreds:
  189. mov ebx, 100
  190. cmp ecx, ebx ;check if above 100
  191. js bla
  192. jae inchundred ;jump to increment hundreds if needed
  193. bla:
  194. mov eax,[ha] ;hundred count to eax
  195. add eax, '0' ;convert to ascii
  196. mov [num+0], eax ;move to first byte of num string
  197. tens:
  198. cmp ecx, 0xa ;check if above 10
  199. jge inctens ;jump to increment tens if needed
  200. mov eax,[ta]
  201. add eax, '0'
  202. mov [num+1], eax
  203. mov eax, ecx
  204. add eax, '0'
  205. mov [num+2], eax
  206. mov [num+3], byte 0xa ;linebreak
  207. mov eax, SYS_WRITE
  208. mov ebx, STDOUT
  209. mov ecx, num
  210. mov edx, 4
  211. int 0x80
  212. ;print hundreds
  213. ;mov eax, [ha]
  214. ;add eax, '0'
  215. ;mov[ha], eax
  216. ;mov eax, SYS_WRITE
  217. ;mov ebx, STDOUT
  218. ;mov ecx, ha
  219. ;mov edx, 1
  220. ;int 0x80
  221. ; print cols
  222. ;mov eax, SYS_WRITE
  223. ;mov ebx, STDOUT
  224. ;mov ecx, sz+2
  225. ;mov edx, 3
  226. ;int 0x80
  227. inchundred:
  228. inc byte [ha] ;increment hundreds
  229. sub ecx, 0x64
  230. jmp hundreds
  231. inctens:
  232. inc byte [ta] ;increment tens
  233. sub ecx, 0xa
  234. jmp tens
  235. ;read from timerfd blocking system till timer triggers
  236. fd_wait:
  237. mov eax, SYS_READ
  238. mov ebx, [tfd]
  239. mov ecx, tval
  240. mov edx, 0x20
  241. int 0x80
  242. ret
  243. error_term_dim:
  244. mov eax, SYS_WRITE
  245. mov ebx, STDOUT
  246. mov ecx, txt_error_term_dim
  247. mov edx, txt_error_term_dim_size
  248. int 0x80
  249. jmp exit