CassLan
12-27-2009, 10:16 PM
This is the routine that fills the DisplayBuffer with exactly what should be in the text editing window (ie whitespaces are " ").
It takes the Address of the start of a line, as well as the horizontal offset and fills buffer[].
It works well but is slow, granted this does the whole editing window, while it probably only needs to do one line at a time while editing, but I thought I would ask some people who are more experienced than myself (most of youhttp://forums.parallax.com/images/smilies/lol.gif ) if you see anything that would shave some clocks off this.
PUB DisplayBufferFill(addr,horizoffset)
' Fills the Display Buffer for the editing window as it will display on screen
counter := 0 'index of Buffer array
counter2 := 0 'index of DisplayBuffer
counter4 := 0 'current cursor location on that line
counter5 := 0 'horizoffset counter
counter6 := 0 'horizontal EOL Flag
'
' Lets start by determining what we COULD be running into
' With Horizontal Offset of 0
' 1) A single Character..followed by more characters
' 2) A single Character..followed by an EOL (Carriage Return)
' 3) An EOL..followed by more characters
' 4) An EOL..followed by another EOL
'
' With a Horizontal Offset of some value
' 5) Skipping over Characters..to Display a single character followed by more characters
' 6) Skipping over Characters and EOL .. to Display nothing on that line
' 7) Skipping over EOL..to display nothing on that line
'
repeat until counter2 == DisplayBufferSize ' do this until we have filled out display buffer
counter6 := 0 'reset horiz EOL Flag
If HorizOffset <> 0 and counter4 == 0
'we have a horizoffset value to consider and we are at the beginning of the line
'We are skipping over characters..we need to check what they are
counter5:=0
repeat until counter5 == horizoffset ' do this for every horizontal offset value (character we are skipping)
case sdcard.vbpeek(0,addr+counter)
32..126: 'we are skipping standard characters
counter++ 'increment buffer index
counter5++ 'increment horizoffset counter
13: ' we have come across an EOL before we are displaying any chars on this line
if sdcard.vbpeek(0,addr+counter+1) == 10 'quick check to see if we have a linefeed (most likely)
counter++ ' if we do increment the Buffer index to skip over this we are now lined up on it
repeat ((DisplayWidth-2)-counter4) ' Fill the DisplayBuffer with spaces until the end of the display on that line
buffer[counter2]:=32
counter2++ ' increment the DisplayBuffer index as we insert spaces
counter++ 'increment the Buffer index (passed the linefeed/EOL)
counter4:= 0'reset the CharactersOnLine counter (should,have been 0 anyway)
'we should exit this loop at this point
counter5 := horizoffset ' we will no longer display characters on this line
counter6 := 1 'set this flag to skip the line char render since we are at a new line now
other: ' for odd chars, we will treat just like standards for now
counter++ 'increment buffer index
counter5++ 'increment horizoffset counter
If counter6 == 0
case sdcard.vbpeek(0,addr+counter)
32..126: 'standard character
buffer[counter2] := sdcard.vbpeek(0,addr+counter) 'place this chacter value in the Display Buffer
counter++ 'increment the Buffer index
counter2++ 'increment the DisplayBuffer index
counter4++ 'increment the CharacterOnLine counter
149: 'standard character
buffer[counter2] := 15 'place this chacter value in the Display Buffer
counter++ 'increment the Buffer index
counter2++ 'increment the DisplayBuffer index
counter4++ 'increment the CharacterOnLine counter
13:
if sdcard.vbpeek(0,addr+counter+1) == 10 'quick check to see if we have a linefeed (most likely)
counter++ ' if we do increment the Buffer index to skip over this we are now lined up on it
repeat ((DisplayWidth-2)-counter4) ' Fill the DisplayBuffer with spaces until the end of the display on that line
buffer[counter2] := 32
counter2++ ' increment the DisplayBuffer index as we insert spaces
counter++ 'increment the Buffer Index (now passed the LineFeed onto next character)
counter4:=0 'reset out CharactersOnLine counter back to 0..we have ended this line
other: ' Just to catch some unusual chars..we may end up getting them, we will treat as a standard char with a funny display to catch it
buffer[counter2] := 127 '
counter++ 'increment the Buffer index
counter2++ 'increment the DisplayBuffer index
counter4++ 'increment the CharacterOnLine counter
' Now we need to see if we just put the last character on a line that will fit
if counter4 == (DisplayWidth-2)
repeat until sdcard.vbpeek(0,addr+counter) == 13 ' we search until we find an EOL in the Buffer, the displaybuffer is already lines up for the next line
counter++
if sdcard.vbpeek(0,addr+counter+1) == 10 'quick check to see if we have a linefeed (most likely)
counter++ 'if we do increment the Buffer index to skip over this we are now lined up on it
counter++ 'increment the Buffer index
counter4:=0 'reset the CharacterOnLine counter
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NYC Area Prop Club (http://www.gothampropclub.com)
Prop Forum Search (Via Google) (http://search.parallax.com/search?site=parallax&client=parallax&output=xml_no_dtd&proxystylesheet=parallax&proxycustom=<HOME/>&ie=&oe=&lr=)
Post Edited (CassLan) : 1/2/2010 11:23:13 PM GMT
It takes the Address of the start of a line, as well as the horizontal offset and fills buffer[].
It works well but is slow, granted this does the whole editing window, while it probably only needs to do one line at a time while editing, but I thought I would ask some people who are more experienced than myself (most of youhttp://forums.parallax.com/images/smilies/lol.gif ) if you see anything that would shave some clocks off this.
PUB DisplayBufferFill(addr,horizoffset)
' Fills the Display Buffer for the editing window as it will display on screen
counter := 0 'index of Buffer array
counter2 := 0 'index of DisplayBuffer
counter4 := 0 'current cursor location on that line
counter5 := 0 'horizoffset counter
counter6 := 0 'horizontal EOL Flag
'
' Lets start by determining what we COULD be running into
' With Horizontal Offset of 0
' 1) A single Character..followed by more characters
' 2) A single Character..followed by an EOL (Carriage Return)
' 3) An EOL..followed by more characters
' 4) An EOL..followed by another EOL
'
' With a Horizontal Offset of some value
' 5) Skipping over Characters..to Display a single character followed by more characters
' 6) Skipping over Characters and EOL .. to Display nothing on that line
' 7) Skipping over EOL..to display nothing on that line
'
repeat until counter2 == DisplayBufferSize ' do this until we have filled out display buffer
counter6 := 0 'reset horiz EOL Flag
If HorizOffset <> 0 and counter4 == 0
'we have a horizoffset value to consider and we are at the beginning of the line
'We are skipping over characters..we need to check what they are
counter5:=0
repeat until counter5 == horizoffset ' do this for every horizontal offset value (character we are skipping)
case sdcard.vbpeek(0,addr+counter)
32..126: 'we are skipping standard characters
counter++ 'increment buffer index
counter5++ 'increment horizoffset counter
13: ' we have come across an EOL before we are displaying any chars on this line
if sdcard.vbpeek(0,addr+counter+1) == 10 'quick check to see if we have a linefeed (most likely)
counter++ ' if we do increment the Buffer index to skip over this we are now lined up on it
repeat ((DisplayWidth-2)-counter4) ' Fill the DisplayBuffer with spaces until the end of the display on that line
buffer[counter2]:=32
counter2++ ' increment the DisplayBuffer index as we insert spaces
counter++ 'increment the Buffer index (passed the linefeed/EOL)
counter4:= 0'reset the CharactersOnLine counter (should,have been 0 anyway)
'we should exit this loop at this point
counter5 := horizoffset ' we will no longer display characters on this line
counter6 := 1 'set this flag to skip the line char render since we are at a new line now
other: ' for odd chars, we will treat just like standards for now
counter++ 'increment buffer index
counter5++ 'increment horizoffset counter
If counter6 == 0
case sdcard.vbpeek(0,addr+counter)
32..126: 'standard character
buffer[counter2] := sdcard.vbpeek(0,addr+counter) 'place this chacter value in the Display Buffer
counter++ 'increment the Buffer index
counter2++ 'increment the DisplayBuffer index
counter4++ 'increment the CharacterOnLine counter
149: 'standard character
buffer[counter2] := 15 'place this chacter value in the Display Buffer
counter++ 'increment the Buffer index
counter2++ 'increment the DisplayBuffer index
counter4++ 'increment the CharacterOnLine counter
13:
if sdcard.vbpeek(0,addr+counter+1) == 10 'quick check to see if we have a linefeed (most likely)
counter++ ' if we do increment the Buffer index to skip over this we are now lined up on it
repeat ((DisplayWidth-2)-counter4) ' Fill the DisplayBuffer with spaces until the end of the display on that line
buffer[counter2] := 32
counter2++ ' increment the DisplayBuffer index as we insert spaces
counter++ 'increment the Buffer Index (now passed the LineFeed onto next character)
counter4:=0 'reset out CharactersOnLine counter back to 0..we have ended this line
other: ' Just to catch some unusual chars..we may end up getting them, we will treat as a standard char with a funny display to catch it
buffer[counter2] := 127 '
counter++ 'increment the Buffer index
counter2++ 'increment the DisplayBuffer index
counter4++ 'increment the CharacterOnLine counter
' Now we need to see if we just put the last character on a line that will fit
if counter4 == (DisplayWidth-2)
repeat until sdcard.vbpeek(0,addr+counter) == 13 ' we search until we find an EOL in the Buffer, the displaybuffer is already lines up for the next line
counter++
if sdcard.vbpeek(0,addr+counter+1) == 10 'quick check to see if we have a linefeed (most likely)
counter++ 'if we do increment the Buffer index to skip over this we are now lined up on it
counter++ 'increment the Buffer index
counter4:=0 'reset the CharacterOnLine counter
▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
NYC Area Prop Club (http://www.gothampropclub.com)
Prop Forum Search (Via Google) (http://search.parallax.com/search?site=parallax&client=parallax&output=xml_no_dtd&proxystylesheet=parallax&proxycustom=<HOME/>&ie=&oe=&lr=)
Post Edited (CassLan) : 1/2/2010 11:23:13 PM GMT