dino.asm 3.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207
  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. section .bss
  8. sz RESB 4 ; 4 byte for window size
  9. num resb 4 ;4 byte for ascii numbers
  10. srow resb 1;
  11. scol resb 1;
  12. section .data
  13. ha db 0 ;hundreds
  14. ta db 0 ;tens
  15. rcount db 0;
  16. lb db 0xa; linebrak
  17. tof db 0; ; top offset
  18. lof db 0; ; left offset
  19. gh db 42; ; game height
  20. gw db 102; ; game width
  21. scrst db 'Score: 000' ; score string
  22. scrstln equ $ - scrst ; sore string length
  23. scrlof equ 5 ;score lfet offset
  24. scrfll equ 85 ;score lfet offset
  25. pls db 0x2b ;plus for corner
  26. hl db 0x2d ;horizontal line |
  27. vl db 0x7c ;vertical line -
  28. section .text
  29. global _start
  30. _start:
  31. ; get windwo size
  32. mov eax, SYS_IOCTL ; syscall ioctl
  33. mov ebx, STDOUT ; stdout for something?
  34. mov ecx, 0x5413 ; get windowsize command TIOCGWINSZ
  35. mov edx, sz ; target struct
  36. int 0x80 ; call kernel
  37. ;print fullscreen
  38. ;save window size
  39. mov al, [sz]
  40. mov [srow], al
  41. mov al, [sz+2]
  42. mov [scol], al
  43. call print
  44. jmp exit
  45. ;calc offset
  46. ;top
  47. mov ax, [srow]
  48. sub ax, [gh]
  49. mov cl, [0x2]
  50. div cl
  51. mov [tof], al
  52. ;left
  53. mov ax, [scol]
  54. sub ax, [gw]
  55. mov bl, 0x2
  56. div bl
  57. mov [lof], al
  58. ;print terminal
  59. print:
  60. topoffset:
  61. mov eax, SYS_WRITE
  62. mov ebx, STDOUT
  63. mov ecx, lb
  64. mov edx, 1
  65. int 0x80
  66. inc byte [rcount]
  67. mov al, [rcount]
  68. cmp al, [tof]
  69. jl topoffset
  70. toprow:
  71. tlcorner:
  72. mov eax, SYS_WRITE
  73. mov ebx, STDOUT
  74. mov ecx, pls
  75. mov edx, 1
  76. int 0x80
  77. tr_start:
  78. mov eax, SYS_WRITE
  79. mov ebx, STDOUT
  80. mov ecx, hl
  81. mov edx, 1
  82. int 0x80
  83. inc byte [rcount]
  84. mov al, [rcount]
  85. cmp al, scrlof
  86. jl tr_start
  87. mov al, 0
  88. mov [rcount], al
  89. tr_score:
  90. mov eax, SYS_WRITE
  91. mov ebx, STDOUT
  92. mov ecx, scrst
  93. mov edx, scrstln
  94. int 0x80
  95. tr_fill:
  96. mov eax, SYS_WRITE
  97. mov ebx, STDOUT
  98. mov ecx, hl
  99. mov edx, 1
  100. int 0x80
  101. inc byte [rcount]
  102. mov al, [rcount]
  103. cmp al, scrfll
  104. jl tr_fill
  105. trcorner:
  106. mov eax, SYS_WRITE
  107. mov ebx, STDOUT
  108. mov ecx, pls
  109. mov edx, 1
  110. int 0x80
  111. linebreak:
  112. mov eax, SYS_WRITE
  113. mov ebx, STDOUT
  114. mov ecx, lb
  115. mov edx, 1
  116. int 0x80
  117. exit:
  118. ;exit
  119. mov eax, 1
  120. mov ebx, 0
  121. int 0x80
  122. ; print rows
  123. mov ecx, 0
  124. mov cl, [sz] ;rows in ecx
  125. hundreds:
  126. mov ebx, 100
  127. cmp ecx, ebx ;check if above 100
  128. js bla
  129. jae inchundred ;jump to increment hundreds if needed
  130. bla:
  131. mov eax,[ha] ;hundred count to eax
  132. add eax, '0' ;convert to ascii
  133. mov [num+0], eax ;move to first byte of num string
  134. tens:
  135. cmp ecx, 0xa ;check if above 10
  136. jge inctens ;jump to increment tens if needed
  137. mov eax,[ta]
  138. add eax, '0'
  139. mov [num+1], eax
  140. mov eax, ecx
  141. add eax, '0'
  142. mov [num+2], eax
  143. mov [num+3], byte 0xa ;linebreak
  144. mov eax, SYS_WRITE
  145. mov ebx, STDOUT
  146. mov ecx, num
  147. mov edx, 4
  148. int 0x80
  149. ;print hundreds
  150. ;mov eax, [ha]
  151. ;add eax, '0'
  152. ;mov[ha], eax
  153. ;mov eax, SYS_WRITE
  154. ;mov ebx, STDOUT
  155. ;mov ecx, ha
  156. ;mov edx, 1
  157. ;int 0x80
  158. ; print cols
  159. ;mov eax, SYS_WRITE
  160. ;mov ebx, STDOUT
  161. ;mov ecx, sz+2
  162. ;mov edx, 3
  163. ;int 0x80
  164. inchundred:
  165. inc byte [ha] ;increment hundreds
  166. sub ecx, 0x64
  167. jmp hundreds
  168. inctens:
  169. inc byte [ta] ;increment tens
  170. sub ecx, 0xa
  171. jmp tens