Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ; text-edit demo
- ; Features a navigatable text buffer for data insertion
- start:
- JSR init_devices
- ; Initialize text buffer
- SET I, [text_cursor]
- SET J, [working_end]
- JSR draw_buffer
- main_loop:
- SET A, 1
- HWI [keyboard_index]
- IFE C, 0
- SET PC, main_loop
- IFE C, 0x10 ; Backspace
- SET PC, backspace
- IFE C, 0x13
- SET PC, delete
- IFE C, 0x82
- SET PC, left
- IFE C, 0x83
- SET PC, right
- IFE C, 0x91
- SET PC, main_loop
- IFE C, 0x90
- SET PC, main_loop
- ; Insert character into buffer
- SET [I], C
- ADD I, 1
- SET [text_cursor], I
- JSR draw_buffer
- SET PC, main_loop
- ; Buffer storage:
- ; Hello, [ ]world!
- ; ^text_cursor ^working_end
- backspace:
- IFE I, text_buffer_start
- SET PC, main_loop
- SUB I, 1
- SET [text_cursor], I
- JSR draw_buffer
- SET PC, main_loop
- delete:
- IFE J, text_buffer_end + 1
- SET PC, main_loop
- ADD J, 1
- SET [working_end], J
- JSR draw_buffer
- SET PC, main_loop
- left:
- IFE I, text_buffer_start
- SET PC, main_loop
- SUB J, 1
- SUB I, 1
- SET [J], [I]
- SET [working_end], J
- SET [text_cursor], I
- JSR draw_buffer
- SET PC, main_loop
- right:
- IFE J, text_buffer_end + 1
- SET PC, main_loop
- SET [I], [J]
- ADD I, 1
- ADD J, 1
- SET [text_cursor], I
- SET [working_end], J
- JSR draw_buffer
- SET PC, main_loop
- draw_buffer:
- SET A, text_buffer_start
- SET B, 0
- .loop:
- IFE A, [text_cursor]
- SET A, [working_end]
- IFE A, text_buffer_end + 1
- SET PC, .finish
- IFE [A], '\n'
- SET PC, .newline
- SET [screen_buffer + B], [A]
- IFN A, [working_end]
- BOR [screen_buffer + B], 0xF000
- IFE A, [working_end]
- BOR [screen_buffer + B], 0xF800
- .iterate:
- ADD A, 1
- ADD B, 1
- SET PC, .loop
- .finish:
- SET C, B
- IFG 32 * 12, B
- JSR .clear
- IFE [working_end], text_buffer_end + 1
- SET [screen_buffer + C], '_' | 0xF000 | 0x80
- SET PC, POP
- .newline:
- DIV B, 32
- MUL B, 32
- ADD B, 31
- SET PC, .iterate
- .clear:
- SET [screen_buffer + B], ' ' | 0xF000
- ADD B, 1
- IFG 32 * 12, B
- SET PC, .clear
- SET PC, POP
- ; Subroutines
- init_devices:
- ; Get number of devices
- HWN A
- SUB A, 1
- SET PUSH, X
- SET PUSH, Y
- JSR .loop
- SET Y, POP
- SET X, POP
- SET PC, POP
- .loop:
- ; Loop through them all
- IFE A, -1
- SET PC, POP
- SET PUSH, A
- HWQ A
- IFE A, 0xf615
- IFE B, 0x7349
- SET PC, .init_screen
- IFE A, 0x7406
- IFE B, 0x30cf
- SET PC, .init_keyboard
- SET A, POP
- .finish:
- SUB A, 1
- SET PC, .loop
- .init_screen:
- SET C, POP
- SET A, 0
- SET B, screen_buffer
- HWI C
- SET A, C
- SET PC, .finish
- .init_keyboard:
- SET [keyboard_index], [SP]
- SET PC, .finish - 1
- ; Reserved memory
- screen_buffer:
- .reserve 32 * 12
- screen_buffer_end:
- keyboard_index:
- .dat 0
- text_cursor:
- .dat default_end
- working_end:
- .dat text_buffer_end + 1
- text_buffer_start:
- .ascii "SirCmpwn's Text Editor (WIP)\nControls:\nArrows,Backspace,Delete,Return\nExpect optimizations later."
- default_end:
- .equ text_buffer_end 0xF000 ; Leave 0x100 words of stack (a little much, but whatever)
Advertisement
Add Comment
Please, Sign In to add comment