( app/left : text editor TODO - Copy/Cut/Paste - Save/Load - Double-click select word - Right-click find next instance of selection - Draw tab characters - Scrollbar - Don't scroll past oef - Hor scroll - Follow cursor when moving out of the screen - Real scrolling distance ) &Console { pad 8 stdio 1 } &Screen { width 2 height 2 pad 4 x 2 y 2 color 1 } &Sprite { pad 8 x 2 y 2 addr 2 color 1 } &Controller { buttons 1 } &Keyboard { key 1 } &Mouse { x 2 y 2 state 1 chord 1 xt 1 yt 1 } &File { pad 8 name 2 length 2 load 2 save 2 } &Document { eof 2 body 8000 } &Range2d { from 2 to 2 } &Point2d { x 2 y 2 } &Label2d { x 2 y 2 color 1 addr 2 } &Textarea2d { x1 2 y1 2 x2 2 y2 2 addr 2 cursor 1 } &Touch2d { x1 2 y1 2 x2 2 y2 2 state 1 } ;lock 1 ;i 2 ;j 2 ;addr 2 ;selection Range2d ;position Point2d ;scroll Point2d ;pt Point2d ;mouse Point2d ;touch Touch2d ;textarea Textarea2d ;label Label2d ( remove ) |0100 @RESET ( load file ) ,filepath ,load-file JSR2 ( place textarea ) #0018 =textarea.x1 ~SCRN.height #0008 SUB2 =textarea.y2 ,select JSR2 ,redraw JSR2 BRK @FRAME ( ctrl ) ,ctrl-end ~CTRL #00 EQU ~lock #00 NEQ #0000 NEQ2 JMP2? POP2 ( lock ) #04 =lock ,no-ctrl-up ~CTRL #10 NEQ JMP2? POP2 ( clamp ) ,no-ctrl-up ~position.y #0000 EQU2 JMP2? POP2 ,find-lineoffset JSR2 =position.x ~position.y #0001 SUB2 =position.y ,find-selection JSR2 DUP2 =selection.from #0001 ADD2 =selection.to ,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2 @no-ctrl-up ,no-ctrl-down ~CTRL #20 NEQ JMP2? POP2 ,find-lineoffset JSR2 =position.x ~position.y #0001 ADD2 =position.y ,find-selection JSR2 DUP2 =selection.from #0001 ADD2 =selection.to ,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2 @no-ctrl-down ,no-ctrl-left ~CTRL #40 NEQ JMP2? POP2 ( clamp ) ,no-ctrl-left ~selection.from ,document.body EQU2 JMP2? POP2 ~selection.from #0001 SUB2 DUP2 =selection.from #0001 ADD2 =selection.to ,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2 @no-ctrl-left ,no-ctrl-right ~CTRL #80 NEQ JMP2? POP2 ~selection.from #0001 ADD2 DUP2 =selection.from #0001 ADD2 =selection.to ,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2 @no-ctrl-right ( alt ) ,no-alt ~CTRL #0f AND #02 NEQ JMP2? POP2 ,no-aup ~CTRL #04 ROR #01 NEQ JMP2? POP2 ,find-wordstart JSR2 =selection.to ,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2 @no-aup ,no-adown ~CTRL #04 ROR #02 NEQ JMP2? POP2 ,find-wordend JSR2 =selection.to ,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2 @no-adown ,no-aleft ~CTRL #04 ROR #04 NEQ JMP2? POP2 ~selection.to #0001 SUB2 =selection.to ,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2 @no-aleft ,no-aright ~CTRL #04 ROR #08 NEQ JMP2? POP2 ~selection.to #0001 ADD2 =selection.to ,clamp-selection JSR2 ,redraw JSR2 ,ctrl-end JMP2 @no-aright @no-alt ( ctrl ) ,no-ctrl ~CTRL #0f AND #01 NEQ JMP2? POP2 ,no-cup ~CTRL #04 ROR #01 NEQ JMP2? POP2 ~scroll.y #0004 SUB2 =scroll.y ,redraw JSR2 ,ctrl-end JMP2 @no-cup ,no-cdown ~CTRL #04 ROR #02 NEQ JMP2? POP2 ~scroll.y #0004 ADD2 =scroll.y ,redraw JSR2 ,ctrl-end JMP2 @no-cdown ,no-cleft ~CTRL #04 ROR #04 NEQ JMP2? POP2 ,goto-linestart JSR2 ,redraw JSR2 ,ctrl-end JMP2 @no-cleft ,no-cright ~CTRL #04 ROR #08 NEQ JMP2? POP2 ,goto-lineend JSR2 ,redraw JSR2 ,ctrl-end JMP2 @no-cright @no-ctrl @ctrl-end ( keys ) ,keys-end ~KEYS #00 EQU JMP2? POP2 ,no-backspace ~KEYS #08 NEQ JMP2? POP2 ( erase ) ~selection.to ~selection.from SUB2 ,shift-left JSR2 ~selection.from #0001 SUB2 =selection.from ~selection.from #0001 ADD2 =selection.to ( release ) #00 =KEYS ,redraw JSR2 ,keys-end JMP2 @no-backspace ( insert ) ~selection.to ~selection.from SUB2 ,shift-right JSR2 ~KEYS ~selection.from STR ~selection.from #0001 ADD2 =selection.from ~selection.from #0001 ADD2 =selection.to ( release ) #00 =KEYS ,redraw JSR2 @keys-end ( mouse ) ,touch-end ~MOUS.state #00 EQU JMP2? POP2 ,touch-linebar ~MOUS.x #0010 LTH2 JMP2? POP2 ,touch-body ~MOUS.x ~SCRN.width #0008 SUB2 LTH2 JMP2? POP2 ,touch-scrollbar JMP2 @touch-end ~MOUS.state =touch.state ( unlock ) ,skip-unlock ~lock #00 EQU JMP2? POP2 ~lock #01 SUB =lock @skip-unlock ,draw-cursor JSR2 BRK @touch-scrollbar ,no-click-scroll-up ~MOUS.y #0008 GTH2 JMP2? POP2 ( decr ) ~scroll.y #00 ~scroll.y #0000 NEQ2 SUB2 =scroll.y ,redraw JSR2 ,touch-end JMP2 @no-click-scroll-up ,no-click-scroll-down ~MOUS.y ~SCRN.height #0008 SUB2 LTH2 JMP2? POP2 ( incr ) ~scroll.y #0001 ADD2 =scroll.y ,redraw JSR2 ,touch-end JMP2 @no-click-scroll-down ~MOUS.y #0008 SUB2 =scroll.y ,redraw JSR2 ,touch-end JMP2 RTS @touch-linebar ~MOUS.y #0008 DIV2 ~scroll.y ADD2 =position.y #0000 =position.x ,find-selection JSR2 DUP2 =selection.from #0001 ADD2 =selection.to ,redraw JSR2 ,touch-end JMP2 RTS @touch-body ~MOUS.y #0008 DIV2 ~scroll.y ADD2 =position.y ~MOUS.x ~textarea.x1 SUB2 #0007 ADD2 #0007 DIV2 =position.x ,touch-when ~MOUS.state ~touch.state NEQ ~CTRL #0f AND #02 NEQ #0101 EQU2 JMP2? POP2 ( on drag ) ,find-selection JSR2 #0001 ADD2 =selection.to ,clamp-selection JSR2 ,redraw JSR2 ,touch-end JMP2 @touch-when ( on click ) ,find-selection JSR2 DUP2 =selection.from #0001 ADD2 =selection.to ,redraw JSR2 ,touch-end JMP2 RTS @load-file ( path ) =FILE.name #8000 =FILE.length ,document.body =FILE.load ( get file length ) ,document.body =document.eof @load-file-loop ( incr ) ~document.eof #0001 ADD2 =document.eof ,load-file-loop ~document.eof LDR #00 NEQ JMP2? POP2 RTS @shift-left ( length ) =i ~selection.from #0001 SUB2 =j ( start -> end ) @shift-left-loop ( move ) ~j ~i ADD2 LDR ~j STR ( incr ) ~j #0001 ADD2 =j ,shift-left-loop ~j ~document.eof LTH2 JMP2? POP2 ~document.eof ~i SUB2 =document.eof RTS @shift-right ( length ) =i ~document.eof =j ( end -> start ) @shift-right-loop ( move ) ~j ~i SUB2 LDR ~j STR ( decr ) ~j #0001 SUB2 =j ,shift-right-loop ~j ~selection.from GTH2 JMP2? POP2 ~document.eof ~i ADD2 =document.eof RTS @clamp-selection ~selection.from ~selection.to LTH2 RTS? ~selection.from #0001 ADD2 =selection.to RTS @goto-linestart @goto-linestart-loop ~selection.from #0001 SUB2 LDR #0a EQU RTS? ~selection.from #0001 SUB2 LDR #0d EQU RTS? ( decr ) ~selection.from DUP2 =selection.to #0001 SUB2 =selection.from ,goto-linestart-loop ~selection.from LDR #00 NEQ JMP2? POP2 ( clamp at document body ) ~selection.from ,document.body GTH2 RTS? ,document.body DUP2 =selection.from #0001 ADD2 =selection.to RTS @goto-lineend @goto-lineend-loop ~selection.from LDR #0a EQU RTS? ~selection.from LDR #0d EQU RTS? ( incr ) ~selection.from #0001 ADD2 DUP2 #0001 ADD2 =selection.to =selection.from ,goto-lineend-loop ~selection.from LDR #00 NEQ JMP2? POP2 ( clamp at document body ) ~selection.from ,document.eof LTH2 RTS? ,document.eof #0001 SUB2 DUP2 =selection.from #0001 ADD2 =selection.to RTS @find-wordstart ~selection.to =j @find-wordstart-loop ( decr ) ~j #0001 SUB2 =j ,find-wordstart-end ~j LDR #20 EQU JMP2? POP2 ,find-wordstart-end ~j LDR #0a EQU JMP2? POP2 ,find-wordstart-end ~j LDR #0d EQU JMP2? POP2 ,find-wordstart-loop ~j ,document.body GTH2 JMP2? POP2 @find-wordstart-end ( return ) ~j #0001 SUB2 RTS @find-wordend ~selection.to =j @find-wordend-loop ( incr ) ~j #0001 ADD2 =j ,find-wordend-end ~j LDR #20 EQU JMP2? POP2 ,find-wordend-end ~j LDR #0a EQU JMP2? POP2 ,find-wordend-end ~j LDR #0d EQU JMP2? POP2 ,find-wordend-loop ~j ,document.body GTH2 JMP2? POP2 @find-wordend-end ( return ) ~j #0001 ADD2 RTS @find-lineoffset ( return character offset from linestart ) #0000 =j @find-lineoffset-loop ( incr ) ~j #0001 ADD2 =j ,find-lineoffset-end ~selection.from ~j SUB2 LDR #0a EQU JMP2? POP2 ,find-lineoffset-end ~selection.from ~j SUB2 LDR #0d EQU JMP2? POP2 ,find-lineoffset-loop ~selection.from ~j SUB2 ,document.body GTH2 JMP2? POP2 @find-lineoffset-end ( return ) ~j RTS @find-line ( position -> addr ) ,document.body =j #0000 =pt.y @find-line-loop ,find-line-end ~pt.y ~position.y #0001 SUB2 GTH2 JMP2? POP2 ,find-line-no-space ~j LDR #0a NEQ ~j LDR #0d NEQ #0101 EQU2 JMP2? POP2 ( incr ) ~pt.y #0001 ADD2 =pt.y @find-line-no-space ( incr ) ~j #0001 ADD2 =j ,find-line-loop ~j LDR #00 NEQ JMP2? POP2 @find-line-end ( return ) ~j RTS @find-selection ( position -> addr ) ,find-line JSR2 ( find line ) #0000 =pt.x @find-selection-loop ,find-selection-end ~j ~pt.x ADD2 LDR #0a EQU JMP2? POP2 ,find-selection-end ~j ~pt.x ADD2 LDR #0d EQU JMP2? POP2 ( incr ) ~pt.x #0001 ADD2 =pt.x ,find-selection-loop ~pt.x ~position.x #0001 SUB2 LTH2 JMP2? POP2 @find-selection-end ( return ) ~pt.x ADD2 RTS @select ( position -> selection ) ,document.body =selection.from #0000 =pt.x #0000 =pt.y @select-loop ,no-space ~selection.from LDR #0a NEQ ~selection.from LDR #0d NEQ #0101 EQU2 JMP2? POP2 ( incr ) ~pt.y #0001 ADD2 =pt.y #0000 =pt.x @no-space ,no-reached ~pt.y ~position.y #0001 SUB2 GTH2 ~pt.x ~position.x #0001 SUB2 GTH2 #0101 NEQ2 JMP2? POP2 ~selection.from #0001 ADD2 =selection.to RTS @no-reached ( incr ) ~pt.x #0001 ADD2 =pt.x ( incr ) ~selection.from #0001 ADD2 =selection.from ,select-loop ~selection.from LDR #00 NEQ JMP2? POP2 RTS ( drawing functions ) @redraw ,draw-lines JSR2 ,draw-textarea JSR2 ,draw-scrollbar JSR2 ,draw-titlebar JSR2 ( save/load icons ) ~SCRN.height #0008 SUB2 =SPRT.y ~SCRN.width #0018 SUB2 =SPRT.x ,load_icn =SPRT.addr #02 =SPRT.color ~SCRN.width #0010 SUB2 =SPRT.x ,save_icn =SPRT.addr #02 =SPRT.color RTS @draw-lines #0000 =j #0000 =SPRT.x #0000 =SPRT.y @draw-lines-loop ~scroll.y ~j ADD2 =addr #0000 =SPRT.x ,font_hex #00 ,addr #0001 ADD2 LDR #f0 AND #04 ROR #08 MUL ADD2 =SPRT.addr ( draw ) #02 ~addr ~position.y EQU2 #06 MUL ADD =SPRT.color #0008 =SPRT.x ,font_hex #00 ,addr #0001 ADD2 LDR #0f AND #08 MUL ADD2 =SPRT.addr ( draw ) #02 ~addr ~position.y EQU2 #06 MUL ADD =SPRT.color ( incr ) ~j #0001 ADD2 =j ( incr ) ~SPRT.y #0008 ADD2 =SPRT.y ,draw-lines-loop ~j ~SCRN.height #0008 SUB2 #0008 DIV2 NEQ2 JMP2? POP2 RTS @draw-short ( short ) =addr ,font_hex #00 ,addr LDR #f0 AND #04 ROR #08 MUL ADD2 =SPRT.addr ( draw ) #0e =SPRT.color ~SPRT.x #0008 ADD2 =SPRT.x ,font_hex #00 ,addr LDR #0f AND #08 MUL ADD2 =SPRT.addr ( draw ) #0e =SPRT.color ~SPRT.x #0008 ADD2 =SPRT.x ,font_hex #00 ,addr #0001 ADD2 LDR #f0 AND #04 ROR #08 MUL ADD2 =SPRT.addr ( draw ) #0e =SPRT.color ~SPRT.x #0008 ADD2 =SPRT.x ,font_hex #00 ,addr #0001 ADD2 LDR #0f AND #08 MUL ADD2 =SPRT.addr ( draw ) #0e =SPRT.color RTS @draw-cursor ~mouse.x ~MOUS.x NEQU2 ~mouse.y ~MOUS.y NEQU2 #0000 EQU2 RTS? ( Return if unchanged ) ( clear last cursor ) ~mouse.x =SPRT.x ~mouse.y =SPRT.y ,blank_icn =SPRT.addr #10 =SPRT.color ( record mouse positions ) ~MOUS.x =mouse.x ~MOUS.y =mouse.y ( draw new cursor ) ~mouse.x =SPRT.x ~mouse.y =SPRT.y ,cursor_icn =SPRT.addr #13 =SPRT.color RTS @draw-textarea ( x y color addr ) ,document.body =textarea.addr ( scroll to position ) #0000 =j ( j is linebreaks ) @find-scroll-offset ,find-scroll-offset-end ~scroll.y ~j EQU2 JMP2? POP2 ,no-break ~textarea.addr LDR #0a NEQ ~textarea.addr LDR #0d NEQ #0101 EQU2 JMP2? POP2 ( incr ) ~j #0001 ADD2 =j @no-break ( incr ) ~textarea.addr #0001 ADD2 =textarea.addr ,find-scroll-offset ~textarea.addr LDR #00 NEQ JMP2? POP2 @find-scroll-offset-end ~textarea.addr #0000 ADD2 =textarea.addr #0000 =SPRT.y ~textarea.addr =j #0018 =SPRT.x @draw-textarea-loop ,draw-textarea-end ~SPRT.y ~SCRN.height #0010 SUB2 GTH2 JMP2? POP2 ( get character ) ,font #00 ~j LDR #20 SUB #0008 MUL2 ADD2 =SPRT.addr ( draw ) #01 ~j ~selection.from #0001 SUB2 GTH2 ~j ~selection.to LTH2 #0101 EQU2 #05 MUL ADD =SPRT.color ,no-linebreak ~j LDR #0a NEQ ~j LDR #0d NEQ #0101 EQU2 JMP2? POP2 ( draw linebreak ) ,linebreak_icn =SPRT.addr ( draw ) #03 ~j ~selection.from #0001 SUB2 GTH2 ~j ~selection.to LTH2 #0101 EQU2 #05 MUL ADD =SPRT.color ( fill clear ) @fill-clear ( incr ) ~SPRT.x #0008 ADD2 =SPRT.x ,font =SPRT.addr #01 =SPRT.color ,fill-clear ~SPRT.x ~SCRN.width #0008 SUB2 LTH2 JMP2? POP2 #0010 =SPRT.x ( incr ) ~SPRT.y #0008 ADD2 =SPRT.y @no-linebreak ( incr ) ~j #0001 ADD2 =j ( incr ) ~SPRT.x #0007 ADD2 =SPRT.x ,draw-textarea-loop ~j LDR #00 NEQ JMP2? POP2 @draw-textarea-end RTS @draw-scrollbar ~SCRN.width #0008 SUB2 =SPRT.x #0000 =SPRT.y ,scrollbar_bg =SPRT.addr @draw-scrollbar-loop ( draw ) #08 =SPRT.color ( incr ) ~SPRT.y #0008 ADD2 =SPRT.y ,draw-scrollbar-loop ~SPRT.y ~SCRN.height LTH2 JMP2? POP2 #0000 =SPRT.y ,arrowup_icn =SPRT.addr ( draw ) #08 =SPRT.color ( at ) ~scroll.y #0008 ADD2 =SPRT.y ,scrollbar_fg =SPRT.addr ( draw ) #08 =SPRT.color ~SCRN.height #0008 SUB2 =SPRT.y ,arrowdown_icn =SPRT.addr ( draw ) #08 =SPRT.color RTS @draw-titlebar #0018 ~SCRN.height #0008 SUB2 #09 ,filepath ( load ) =label.addr =label.color =SPRT.y =SPRT.x ~label.addr @draw-titlebar-loop ( draw ) DUP2 LDR #00 SWP #20 SUB #0008 MUL2 ,font ADD2 =SPRT.addr ~label.color =SPRT.color ( incr ) #0001 ADD2 ( incr ) ~SPRT.x #0008 ADD2 =SPRT.x DUP2 LDR #00 NEQ ,draw-titlebar-loop ROT JMP2? POP2 POP2 ( selection ) ~selection.from ,document.body SUB2 ,draw-short JSR2 RTS @font_hex ( 0-F TODO: should pull from @font instead.. ) [ 003c 464a 5262 3c00 0018 0808 0808 1c00 003c 4202 3c40 7e00 003c 421c 0242 3c00 000c 1424 447e 0400 007e 407c 0242 3c00 003c 407c 4242 3c00 007e 0204 0810 1000 003c 423c 4242 3c00 003c 4242 3e02 3c00 003c 4242 7e42 4200 007c 427c 4242 7c00 003c 4240 4042 3c00 007c 4242 4242 7c00 007e 4078 4040 7e00 007e 4078 4040 4000 ] @font ( specter8-frag font ) [ 0000 0000 0000 0000 0008 0808 0800 0800 0014 1400 0000 0000 0024 7e24 247e 2400 0008 1e28 1c0a 3c08 0000 2204 0810 2200 0030 4832 4c44 3a00 0008 1000 0000 0000 0004 0808 0808 0400 0020 1010 1010 2000 0000 2214 0814 2200 0000 0808 3e08 0800 0000 0000 0000 0810 0000 0000 3e00 0000 0000 0000 0000 0800 0000 0204 0810 2000 003c 464a 5262 3c00 0018 0808 0808 1c00 003c 4202 3c40 7e00 003c 421c 0242 3c00 000c 1424 447e 0400 007e 407c 0242 3c00 003c 407c 4242 3c00 007e 0204 0810 1000 003c 423c 4242 3c00 003c 4242 3e02 3c00 0000 0010 0000 1000 0000 1000 0010 1020 0000 0810 2010 0800 0000 003e 003e 0000 0000 1008 0408 1000 003c 420c 1000 1000 003c 4232 4a42 3c00 003c 4242 7e42 4200 007c 427c 4242 7c00 003c 4240 4042 3c00 007c 4242 4242 7c00 007e 4078 4040 7e00 007e 4078 4040 4000 003c 4240 4642 3c00 0042 427e 4242 4200 001c 0808 0808 1c00 007e 0202 0242 3c00 0042 4478 4442 4200 0040 4040 4040 7e00 0042 665a 4242 4200 0042 6252 4a46 4200 003c 4242 4242 3c00 007c 4242 7c40 4000 003c 4242 4244 3a00 007c 4242 7c44 4200 003e 403c 0242 3c00 007e 0808 0808 1000 0042 4242 4244 3a00 0042 4242 4224 1800 0042 4242 5a66 4200 0042 423c 4242 4200 0042 423e 0242 3c00 007e 020c 3040 7e00 000c 0808 0808 0c00 0040 2010 0804 0200 0030 1010 1010 3000 0008 1400 0000 0000 0000 0000 0000 7e00 0008 0400 0000 0000 0000 3c02 3e42 3a00 0040 407c 4242 7c00 0000 3c42 4042 3c00 0002 023e 4242 3e00 0000 3c42 7e40 3e00 0000 3e40 7840 4000 0000 3c42 3e02 3c00 0040 405c 6242 4200 0008 0018 0808 0400 0008 0018 0808 4830 0040 4244 7844 4200 0010 1010 1010 0c00 0000 6c52 5252 5200 0000 5c62 4242 4200 0000 3c42 4242 3c00 0000 7c42 427c 4040 0000 3e42 423e 0202 0000 5c62 4040 4000 0000 3e40 3c02 7c00 0008 7e08 0808 1000 0000 4242 4244 3a00 0000 4242 4224 1800 0000 5252 5252 2e00 0000 4224 1824 4200 0000 4242 3e02 7c00 0000 7e02 3c40 7e00 000c 0810 1008 0c00 0008 0808 0808 0800 0030 1008 0810 3000 0000 0032 4c00 0000 3c42 99a1 a199 423c ] @linebreak_icn [ 003e 7474 3414 1400 ] @blank_icn [ 0000 0000 0000 0000 ] @cursor_icn [ 80c0 e0f0 f8e0 1000 ] @scrollbar_bg [ aa55 aa55 aa55 aa55 ] @scrollbar_fg [ ffff ffff ffff ffff ] @arrowup_icn [ 0010 387c fe10 1010 ] @arrowdown_icn [ 0010 1010 fe7c 3810 ] @load_icn [ feaa d6aa d4aa f400 ] @save_icn [ fe82 8282 848a f400 ] @filepath1 [ projects/examples/jumptest.usm 00 ] @filepath [ projects/software/left.usm 00 ] |4000 ;document Document |d000 @ERROR BRK |FF00 ;dev/console Console |FF10 ;SCRN Screen |FF20 ;SPRT Sprite |FF30 ;CTRL Controller |FF40 ;KEYS Keyboard |FF50 ;MOUS Mouse |FF60 ;FILE File |FFF0 .RESET .FRAME .ERROR ( vectors ) |FFF8 [ a0fe a0f7 a0f2 ] ( palette )