SirCmpwn

Untitled

Jun 15th, 2012
43
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.49 KB | None | 0 0
  1. ; text-edit demo
  2. ; Features a navigatable text buffer for data insertion
  3.  
  4. start:
  5. JSR init_devices
  6. ; Initialize text buffer
  7. SET I, [text_cursor]
  8. SET J, [working_end]
  9. JSR draw_buffer
  10. main_loop:
  11. SET A, 1
  12. HWI [keyboard_index]
  13. IFE C, 0
  14. SET PC, main_loop
  15. IFE C, 0x10 ; Backspace
  16. SET PC, backspace
  17. IFE C, 0x13
  18. SET PC, delete
  19. IFE C, 0x82
  20. SET PC, left
  21. IFE C, 0x83
  22. SET PC, right
  23. IFE C, 0x91
  24. SET PC, main_loop
  25. IFE C, 0x90
  26. SET PC, main_loop
  27. ; Insert character into buffer
  28. SET [I], C
  29. ADD I, 1
  30. SET [text_cursor], I
  31. JSR draw_buffer
  32. SET PC, main_loop
  33.  
  34.  
  35. ; Buffer storage:
  36. ; Hello, [ ]world!
  37. ; ^text_cursor ^working_end
  38. backspace:
  39. IFE I, text_buffer_start
  40. SET PC, main_loop
  41.  
  42. SUB I, 1
  43. SET [text_cursor], I
  44.  
  45. JSR draw_buffer
  46. SET PC, main_loop
  47. delete:
  48. IFE J, text_buffer_end + 1
  49. SET PC, main_loop
  50.  
  51. ADD J, 1
  52. SET [working_end], J
  53.  
  54. JSR draw_buffer
  55. SET PC, main_loop
  56. left:
  57. IFE I, text_buffer_start
  58. SET PC, main_loop
  59.  
  60. SUB J, 1
  61. SUB I, 1
  62.  
  63. SET [J], [I]
  64.  
  65. SET [working_end], J
  66. SET [text_cursor], I
  67.  
  68. JSR draw_buffer
  69. SET PC, main_loop
  70. right:
  71. IFE J, text_buffer_end + 1
  72. SET PC, main_loop
  73.  
  74. SET [I], [J]
  75. ADD I, 1
  76. ADD J, 1
  77. SET [text_cursor], I
  78. SET [working_end], J
  79.  
  80. JSR draw_buffer
  81. SET PC, main_loop
  82.  
  83. draw_buffer:
  84. SET A, text_buffer_start
  85. SET B, 0
  86. .loop:
  87. IFE A, [text_cursor]
  88. SET A, [working_end]
  89. IFE A, text_buffer_end + 1
  90. SET PC, .finish
  91. IFE [A], '\n'
  92. SET PC, .newline
  93. SET [screen_buffer + B], [A]
  94. IFN A, [working_end]
  95. BOR [screen_buffer + B], 0xF000
  96. IFE A, [working_end]
  97. BOR [screen_buffer + B], 0xF800
  98. .iterate:
  99. ADD A, 1
  100. ADD B, 1
  101. SET PC, .loop
  102. .finish:
  103. SET C, B
  104. IFG 32 * 12, B
  105. JSR .clear
  106. IFE [working_end], text_buffer_end + 1
  107. SET [screen_buffer + C], '_' | 0xF000 | 0x80
  108. SET PC, POP
  109. .newline:
  110. DIV B, 32
  111. MUL B, 32
  112. ADD B, 31
  113. SET PC, .iterate
  114. .clear:
  115. SET [screen_buffer + B], ' ' | 0xF000
  116. ADD B, 1
  117. IFG 32 * 12, B
  118. SET PC, .clear
  119. SET PC, POP
  120.  
  121. ; Subroutines
  122. init_devices:
  123. ; Get number of devices
  124. HWN A
  125. SUB A, 1
  126.  
  127. SET PUSH, X
  128. SET PUSH, Y
  129. JSR .loop
  130. SET Y, POP
  131. SET X, POP
  132.  
  133. SET PC, POP
  134. .loop:
  135. ; Loop through them all
  136. IFE A, -1
  137. SET PC, POP
  138. SET PUSH, A
  139. HWQ A
  140. IFE A, 0xf615
  141. IFE B, 0x7349
  142. SET PC, .init_screen
  143. IFE A, 0x7406
  144. IFE B, 0x30cf
  145. SET PC, .init_keyboard
  146. SET A, POP
  147. .finish:
  148. SUB A, 1
  149. SET PC, .loop
  150. .init_screen:
  151. SET C, POP
  152. SET A, 0
  153. SET B, screen_buffer
  154. HWI C
  155. SET A, C
  156. SET PC, .finish
  157. .init_keyboard:
  158. SET [keyboard_index], [SP]
  159. SET PC, .finish - 1
  160.  
  161. ; Reserved memory
  162. screen_buffer:
  163. .reserve 32 * 12
  164. screen_buffer_end:
  165. keyboard_index:
  166. .dat 0
  167. text_cursor:
  168. .dat default_end
  169. working_end:
  170. .dat text_buffer_end + 1
  171. text_buffer_start:
  172. .ascii "SirCmpwn's Text Editor (WIP)\nControls:\nArrows,Backspace,Delete,Return\nExpect optimizations later."
  173. default_end:
  174. .equ text_buffer_end 0xF000 ; Leave 0x100 words of stack (a little much, but whatever)
Advertisement
Add Comment
Please, Sign In to add comment