fl { This demo saves text from a VT100 terminal to sdcard. It is not a text editor, I am still working on the SDram version. This demo can be run on any Standard Propboard with Propforth 4.6. and Sdcard on pins 0..3 Users may have to rebuild Propforth, it only requires the SDdriver, without sdfs. The sdcard will also have to be reformatted (FAT16) if you have already created a filesys using sd_scripts. NOTE I have not tried to run the demo on Propforth with sdfs. If you wish to try, reset cogs 0 and 6 before loading the demo. Maybe there will be enough free memory. Paste this demo to your VT100 and enter init_edit. Enter text and edit the line but note, the line in this demo cannot be edited once you have committed it to sdcard CR Note there is no word wrap. Lines are stored on sdcard 4 lines per block. Text is packed in longs in big endian format. To exit Insert mode, once you have enter the last line of the text, use the following keys Esc 3 CR (hex 1b 0d 33) in that order. Text from the sdcard will be displayed one page at a time. It is fast, very fast. Additional info. A line of text is edited in Hub at edbuf, the first word in edbuf is reserved for the line length The word immediately following the last character in the line is reserved for the line no. Once a line in entered it is copied and packed in BIG ENDIAN format and copied to cog ram starting at cogbuf plus blk_ptr . Cog ram stores four lines of packed text starting at cogbuf (128 longs). Each line adrs in cogbuf are offset by blk_ptr. Cog ram block is then written to SDcard at blk_no. Up to 256 lines can be entered and the process repeated until Esc 3 CR is keyed (hex 1b 0d 33). Then Insert mode is exited and the text is read back from sdcard and displayed. The SD version of the text editor which I am still working follows the same format. The main difference is that up and down arrow allows the user to move through the lines of text. New lines can be inserted or edited. Inserted lines are appended to the end of the file, then the line numbers are re-calculated. This occurs only if the current line no. entered is less that last line no. in the file. The SDram version will use a flb (file list blk) packed one long for each four lines of text. The Editor will use this data block to display lines in the correct order. The Editor will be limited to 256 lines of text. Each line( with word wrap) has a maximum of chars when completed. Hopefully the full Editor will be available when I have had a look at Propforth rev 5.00 later in the year. } hex 127 wconstant del_key 80 wconstant col_max \ max Col no. 15 wconstant fblock_base \ sd starting block no. for file 5 wconstant line_min \ start line no. 15 wconstant line_max \ max line no. wvariable edbuf 80 allot \ input buffer text is edited here, and commited to memory on cr wvariable line \ line number on screen (can be set from 5 to 40) wvariable col \ col number on screen (can be set from 40 to 128 ) wvariable eof \ last line number in xmem (max 255 lines) wvariable temp \ temp register wvariable page \ screen page number wvariable mode \ 0 insert 1 edit 2 delete 3 exit editor wvariable cog_buf_adr \ next line adr in cog memory ( sd_cogbuf + blk_ptr ) wvariable blk_no. \ current SDcard block no. wvariable blk_ptr \ current line no. offset for current line : W-! dup W@ rot - swap W! ; : .digits dup 9 > if a u/mod 30 + emit then 30 + emit ; \ still does not trap chr f > TOFIX) : cursor 1b emit 5b emit .digits ." ;" .digits ." f" ; \ set cursor, get col and row data from TOS : cls 1b emit 5b emit ." 2J" ; \ ANSI VT100 clear screen \ ~~~~~~~~~~~~~~~~~~~~~~~~~~RamBlade external memory dump and breakpoint routines~~~~~~~~~~~~~~~~~~~~~~~~~ : db 20 10 cursor st? col W@ line W@ cursor key drop ; \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ : clr_buffer col_max 0 do 20 edbuf i + C! loop ; \ clear Editor line buffer in Hub : cln 0 line W@ cursor col_max 0 do 20 emit loop 0 line W@ cursor ; \ clear next VT100 line : pause cr c" Strike any key to continue " .cstr key drop cls ; : inc_col 1 col W+! ; : dec_col 1 col W-! ; : inc_line line W@ 1+ dup line_max > if pause drop 5 then line W! page W@ 15 + page W! ; : dec_line 1 line W-! ; : inc_eof 1 eof W+! ; : dec_eof 1 eof W-! ; : inc_blk_no. 1 blk_no. W+! ; : new_page cls 0 col line_min line W! cursor ; : upd_blk_ptr blk_ptr W@ 60 = if 0 blk_ptr W! else 20 blk_ptr W+! then ; : disp_ln 0 line W@ cursor col W@ 0 do edbuf 1 + i + C@ emit loop col W@ 1 + line W@ cursor ; : set_cog_buf_adr sd_cogbuf blk_ptr W@ + cog_buf_adr W! ; : hub_to_cog set_cog_buf_adr 20 0 do edbuf i 4 * + L@ cog_buf_adr W@ i + COG! loop upd_blk_ptr ; : cog_to_hub set_cog_buf_adr 20 0 do cog_buf_adr W@ i + COG@ edbuf i 4 * + L! loop upd_blk_ptr ; : disp_cog_blk 4 0 do cog_to_hub edbuf .cstr inc_line 0 col W! col W@ line W@ cursor loop ; : disp_file cls 0 dup col W! 5 dup line W! cursor blk_no. W@ fblock_base do i sd_blockread disp_cog_blk loop ; : clr_cursor_eol inc_col line W@ cursor col_max col W@ - 0 do space loop ; : wrline edbuf col C@ 2 + hex dump ; : save_xmem col W@ 1 - edbuf C! edbuf col W@ + line W@ swap C! hub_to_cog clr_buffer inc_eof 0 col C! ; : col_max col W@ - 0 do edbuf col_max + 1 - i - C@ edbuf col_max + i - C! loop ; : mvup line ; : mvdown ; { ~~~~~~~~~~~~~~~ ESC manager for arrow keys ~~~~~~~~~~~~~~~~~~~ A single arrow key generates 3 bytes. The first key stroke (any arrow key) will push 1B to TOS to release the next byte the key word is called again. If the byte is 5B another call to Key is used to decode the arrow key. So what would happens if an escape key pressed by itself leaving no other key in the input stream ? The process would hang until another character is recieved. Once a key is pressed it will be dropped and processing continues normally. The ESC manager has been extended to provide additional modes. } : modes mode W@ 31 = if drop else dup 32 = if drop then then ; : esc key dup 5B = if drop key dup 41 = if mvup else dup 42 = if mvdown else dup 43 = if inc_col else dup 44 = if dec_col then then then then else dup mode W! then ; : sv_chr dup d <> if edbuf col W@ + 1 + C! else drop then ; : save_chr dup dup dup 0 <> if dup 7F = if col W@ 0 > if drop sv_chr inc_col then else drop then ; : keyin key dup 1B = if esc else save_chr then ; : ed_accept col_max 0 do keyin dup d = if leave else dup 1b = if col W@ line W@ cursor else disp_ln then drop then drop loop drop ; : mode_chk mode 33 mode W@ = if leave then ; : test sd_init hex 0 blk_ptr W! 15 blk_no. W! disp_file cr ; \ takes block number from TOS \ ~~~~~~~~~~~~~~~~~~~~~~~~~ MAIN LOOP ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ : init_edit cls 10 0 cursor c" SDCard Demo " .cstr hex sd_init 0 dup eof W! dup page W! dup mode W! dup blk_ptr W! col W! 5 line W! fblock_base blk_no. W! sd_cogbufclr begin 0 line W@ cursor clr_buffer ed_accept save_xmem 0 blk_ptr W@ = if blk_no. W@ sd_blockwrite \ sd_cogbufclr inc_blk_no. then inc_line mode W@ until blk_ptr W@ 0 <> if blk_no. W@ sd_blockwrite sd_cogbufclr inc_blk_no. then cls c" Stike any Key to continue" .cstr key drop 0 blk_ptr W! disp_file cr cr c" Thats it from me Folks" .cstr cr ; \ exit on mode 3 \ ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~