stage0_monitor.hex 7.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276
  1. ## Copyright (C) 2016 Jeremiah Orians
  2. ## This file is part of stage0.
  3. ##
  4. ## stage0 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. ## (at your option) any later version.
  8. ##
  9. ## stage0 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 stage0. If not, see <http://www.gnu.org/licenses/>.
  16. # start:
  17. # Let us first setup our stack
  18. BC0001 # mov sp,0x100
  19. B8007E # mov ax,0x7e00
  20. 8ED0 # mov ss,ax
  21. # Setup segment to shove input
  22. B80010 # mov ax,0x1000
  23. 8EC0 # mov es,ax
  24. BD0000 # mov bp,0x0
  25. # Initialize variables
  26. B80000 # mov ax,0x0
  27. BF0100 # mov di,0x1
  28. BE0000 # mov si,0x0
  29. # loop:
  30. E85100 # call read_char
  31. # Check for C-d
  32. 3C04 # cmp al,0x4
  33. 7505 # jnz 0x25 [Skip over next 2 instructions]
  34. E8E400 # call execute_code
  35. EBF4 # jmp loop
  36. # Check for C-l
  37. 3C0C # cmp al,0xc
  38. 7505 # jnz 0x2e [Skip over next 2 instructions]
  39. E84600 # call clear_screen
  40. EBEB # jmp loop
  41. # Check for [Enter]
  42. 3C0D # cmp al,0xd
  43. 7505 # jnz 0x37 [Skip over next 2 instructions]
  44. E85800 # call display_newline
  45. EBE2 # jmp loop
  46. # Otherwise just print the char
  47. E82E00 # call print_char
  48. E88D00 # call hex
  49. 3C00 # cmp al,0x0 [Check if is hex char]
  50. 7CD8 # jl loop
  51. 83FF00 # cmp di,byte +0x0 [Check if toggled]
  52. 740A # jz 0x50 [Skip over next 4 instructions]
  53. # Process first nibble of pair
  54. BE0F00 # mov si,0xf
  55. 21C6 # and si,ax
  56. BF0000 # mov di,0x0
  57. EBC9 # jmp loop
  58. # Process second nibble of pair
  59. C1E604 # shl si,byte 0x4
  60. 83E00F # and ax,byte +0xf
  61. 01F0 # add ax,si
  62. BF0100 # mov di,0x1
  63. 89EB # mov bx,bp
  64. # Write out byte
  65. 268807 # mov [es:bx],al
  66. # Update our pointer
  67. 83C501 # add bp,byte +0x1
  68. E8C900 # call insert_spacer
  69. EBB1 # jmp loop
  70. # print_char:
  71. B40E # mov ah,0xe
  72. CD10 # int 0x10
  73. C3 # ret
  74. # read_char:
  75. B400 # mov ah,0x0
  76. CD16 # int 0x16
  77. C3 # ret
  78. # clear_screen:
  79. # The actual clearing of the screen
  80. B000 # mov al,0x0
  81. B406 # mov ah,0x6
  82. B707 # mov bh,0x7
  83. B100 # mov cl,0x0
  84. B500 # mov ch,0x0
  85. B250 # mov dl,0x50
  86. B618 # mov dh,0x18
  87. CD10 # int 0x10
  88. # The resetting of the cursor
  89. B402 # mov ah,0x2
  90. B700 # mov bh,0x0
  91. B600 # mov dh,0x0
  92. B200 # mov dl,0x0
  93. CD10 # int 0x10
  94. C3 # ret
  95. # display_newline:
  96. E81B00 # call get_cursor_position
  97. 80FC0C # cmp ah,0xc
  98. 7E04 # jng 0x99 [Skip over next 2 instructions]
  99. E81C00 # call word 0xb4
  100. C3 # ret
  101. # Move the cursor down if required
  102. B601 # mov dh,0x1
  103. 00E6 # add dh,ah
  104. B402 # mov ah,0x2
  105. B700 # mov bh,0x0
  106. B200 # mov dl,0x0
  107. CD10 # int 0x10
  108. B00D # mov al,0xd
  109. E8BEFF # call print_char
  110. C3 # ret
  111. # get_cursor_position:
  112. B403 # mov ah,0x3
  113. B700 # mov bh,0x0
  114. CD10 # int 0x10
  115. 89D0 # mov ax,dx
  116. C3 # ret
  117. # scroll_window:
  118. B001 # mov al,0x1
  119. B406 # mov ah,0x6
  120. B707 # mov bh,0x7
  121. B100 # mov cl,0x0
  122. B500 # mov ch,0x0
  123. B250 # mov dl,0x50
  124. B618 # mov dh,0x18
  125. CD10 # int 0x10
  126. B00D # mov al,0xd
  127. E89FFF # call print_char
  128. C3 # ret
  129. # hex:
  130. # Deal with line comments starting with #
  131. 3C23 # cmp al,0x23
  132. 742A # jz ascii_comment
  133. # Deal with line comments starting with ;
  134. 3C3B # cmp al,0x3b
  135. 7426 # jz ascii_comment
  136. # Deal with all ascii less than '0'
  137. 3C30 # cmp al,0x30
  138. 7C1F # jl ascii_other
  139. # Deal with '0' through '9'
  140. 3C3A # cmp al,0x3a
  141. 7C12 # jl ascii_num
  142. # Deal with all ascii less than 'A'
  143. 3C41 # cmp al,0x41
  144. 7C17 # jl ascii_other
  145. # Deal with 'A' through 'F'
  146. 3C47 # cmp al,0x47
  147. 7C10 # jl ascii_high
  148. # Deal with all ascii less than 'a'
  149. 3C61 # cmp al,0x61
  150. 7C0F # jl ascii_other
  151. # Deal with 'a' through 'f'
  152. 3C67 # cmp al,0x67
  153. 7C05 # jl ascii_low
  154. # Deal with everything else
  155. EB09 # jmp ascii_other
  156. # ascii_num:
  157. 2C30 # sub al,0x30
  158. C3 # ret
  159. # ascii_low:
  160. 2C57 # sub al,0x57
  161. C3 # ret
  162. # ascii_high:
  163. 2C37 # sub al,0x37
  164. C3 # ret
  165. # ascii_other:
  166. B0FF # mov al,0xff
  167. C3 # ret
  168. # ascii_comment:
  169. E872FF # call read_char
  170. E86AFF # call print_char
  171. 3C0D # cmp al,0xd
  172. 75F6 # jnz ascii_comment
  173. E8AFFF # call scroll_window
  174. EBEE # jmp ascii_other
  175. # execute_code:
  176. # Clear the screen to be nice
  177. E868FF # call clear_screen
  178. # Zero all registers and segments before jump
  179. B80000 # mov ax,0x0
  180. BB0000 # mov bx,0x0
  181. B90000 # mov cx,0x0
  182. BA0000 # mov dx,0x0
  183. BE0000 # mov si,0x0
  184. BF0000 # mov di,0x0
  185. BD0000 # mov bp,0x0
  186. 8ED8 # mov ds,ax
  187. 8ED0 # mov ss,ax
  188. 8EC0 # mov es,ax
  189. 8EE0 # mov fs,ax
  190. 8EE8 # mov gs,ax
  191. # Load the code that we input by hand
  192. 680010 # push word 0x1000
  193. 6A00 # push byte +0x0
  194. # Using intersegment return
  195. CF # iretw
  196. # insert_spacer:
  197. B020 # mov al,0x20
  198. E834FF # call word 0x68
  199. C3 # ret
  200. # done:
  201. F4 # hlt
  202. 90 90 90 90 # 4 nops
  203. 90 90 90 90 # 4 nops
  204. 90 90 90 90 # 4 nops
  205. 90 90 90 90 # 4 nops
  206. 90 90 90 90 # 4 nops
  207. 90 90 90 90 # 4 nops
  208. 90 90 90 90 # 4 nops
  209. 90 90 90 90 # 4 nops
  210. 90 90 90 90 # 4 nops
  211. 90 90 90 90 # 4 nops
  212. 90 90 90 90 # 4 nops
  213. 90 90 90 90 # 4 nops
  214. 90 90 90 90 # 4 nops
  215. 90 90 90 90 # 4 nops
  216. 90 90 90 90 # 4 nops
  217. 90 90 90 90 # 4 nops
  218. 90 90 90 90 # 4 nops
  219. 90 90 90 90 # 4 nops
  220. 90 90 90 90 # 4 nops
  221. 90 90 90 90 # 4 nops
  222. 90 90 90 90 # 4 nops
  223. 90 90 90 90 # 4 nops
  224. 90 90 90 90 # 4 nops
  225. 90 90 90 90 # 4 nops
  226. 90 90 90 90 # 4 nops
  227. 90 90 90 90 # 4 nops
  228. 90 90 90 90 # 4 nops
  229. 90 90 90 90 # 4 nops
  230. 90 90 90 90 # 4 nops
  231. 90 90 90 90 # 4 nops
  232. 90 90 90 90 # 4 nops
  233. 90 90 90 90 # 4 nops
  234. 90 90 90 90 # 4 nops
  235. 90 90 90 90 # 4 nops
  236. 90 90 90 90 # 4 nops
  237. 90 90 90 90 # 4 nops
  238. 90 90 90 90 # 4 nops
  239. 90 90 90 90 # 4 nops
  240. 90 90 90 90 # 4 nops
  241. 90 90 90 90 # 4 nops
  242. 90 90 90 90 # 4 nops
  243. 90 90 90 90 # 4 nops
  244. 90 90 90 90 # 4 nops
  245. 90 90 90 90 # 4 nops
  246. 90 90 90 90 # 4 nops
  247. 90 90 90 90 # 4 nops
  248. 90 90 90 90 # 4 nops
  249. 90 90 90 90 # 4 nops
  250. 90 90 90 90 # 4 nops
  251. 90 90 90 90 # 4 nops
  252. 55AA # Magic Number