Shop OBEX P1 Docs P2 Docs Learn Events
VGA_TEXT.SPIN clear screen — Parallax Forums

VGA_TEXT.SPIN clear screen

Richard S.Richard S. Posts: 70
edited 2007-09-20 12:05 in Propeller 1
There is a command ($00) in the VGA_TEXT.SPIN file called 'clear screen', see below:

·case flag
··· $00: case c·· ' clear screen
·········· $00: wordfill(@screen, $220, screensize)
··············· col := row := 0
·········· $01: col := row := 0

Why is the value $220 used to·fill ('clear')·the screen memory block?· I do not understand it's purpose.· I would have thought filling screen memory with spaces or blanks would have be adequate.

I would like to clear the screen and set the background/foreground colors.



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Richard in Michigan

Comments

  • Mike GreenMike Green Posts: 23,101
    edited 2007-03-20 04:19
    The screen buffer actually contains a word for each character position. This word is a pointer (with a little modification) into the ROM font table. The $220 happens to be the code for a blank with the default color. The background/foreground colors are set separately. You'll need to look at the VGA.SPIN source code comments for a detailed description of the color table.
  • Richard S.Richard S. Posts: 70
    edited 2007-03-21 01:00
    Thanx Mike...

    I now understand what is going on in 'wordfill(@screen, $220, screensize)' with $220 representing 'blank' in the ROM font table.

    I do understand how to set colors. I was hoping the the 'clear screen' function might integrate color palette selection but I can see this is not so. It would be a nice way to paint the screen a specific color.

    Your time and comments are much appreciated!

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Richard in Michigan
  • Paul BakerPaul Baker Posts: 6,351
    edited 2007-03-21 14:16
    You can make it as such, c is a long, yet only the first 8 bits are used. You can place an extra condition in the case statement (placed immediately before the default case):
         $100..$107: wordfill(@screen, (c & 7) << 11 + $220, screensize)
                     
    

    This shifts the last 3 bits into the color position of the screen's data. So to clear screen to a different palette you would out(cindex + $100)



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.

    Post Edited (Paul Baker (Parallax)) : 3/21/2007 2:21:08 PM GMT
  • Richard S.Richard S. Posts: 70
    edited 2007-09-20 01:59
    It has been awhile, but I am back at it.·

    The info on "painting a screen" worked well.·Thank-you very much!!

    What I would like is to paint a screen yellow, and then display a menu list without having to pad with spaces to have the entire screen appear a uniform yellow background.· This would save memory space·(not having to store all of those $20-spaces)·when using multiple text menu screens.

    When I "paint screen" yellow, then write to the screen with red foreground / yellow background color pallete selection....the text lines·do not have·yellow in all columns·unless padded to the end with "spaces".· Apparently the screen buffer is overwritten with the default colors (red/black) just prior to a string write?

    Below is an example of text padded to end with spaces...therefore the whole line is yellow with red text

    · vga_text.str(string($A,1,$08,$C,2,"·········· MAIN MENU··········· "))

    Below is an example of text not padded to the end...therefore the yello line stops at the end of the text and the rest is black

    · vga_text.str(string($A,1,$08,$C,2,"·········· MAIN MENU"))

    The $C,2 is my red/yellow color pallete selection.

    I·also noticed·that in order to start at X-zero position, since in a string I cannot use $A,0 because of zero terminated string problem...I had to select X-one position then backspace with $08 command.· It would have been convenient had the numbering of the columns and lines started with 1 rather than zero, if·I understand this correctly.

    Any comments would be greatly appreciated!· Thanx!



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Richard in Michigan
  • RaymanRayman Posts: 14,162
    edited 2007-09-20 02:33
    Only way I see that happening is if the "cols" constant (32) was changed to be smaller. In this case a shorter text string would trigger a "newline" function call that erases a line with a predefined color. Or, maybe "newline" is being called in some other way?
  • Richard S.Richard S. Posts: 70
    edited 2007-09-20 04:15
    From what I believe is happening ... is that the screen top·left corner is x=0 y=0·and the lower right corner is x=31 y=14.·So to use string($A,0) or String($B,0)·one gets an error·code stating zeros·are not allowed in string functions (because·of the use of zero for string termination).·To get around this when I wish to print a new screen, I ignore $B since by default it is set to zero.· $A is another problem.· If I wish to print a character at string($A,0,"R") I have to declare the following ... string($A,1,$08,"R") ... this sets X=1 then backspaces to X=0.

    It would have been easier,for me at least, if the·top·left corner·was x=1 y=1·and the lower right corner was·x=32 y=15.· Then there would be no problem using string commands to load·the top row.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Richard in Michigan
  • hippyhippy Posts: 1,981
    edited 2007-09-20 04:56
    Richard S. said...
    It would have been easier,for me at least, if the top left corner was x=1 y=1 and the lower right corner was x=32 y=15

    You could always go in and edit the lower level object to make that its behaviour, or ( better to retain compatibility with other code which may use the object ) add a parsing routine which takes the string you want to write ( origin=1,1 ) and converts it to calls which achieve what you want.
  • deSilvadeSilva Posts: 2,967
    edited 2007-09-20 05:51
    The ..TEXT.SPIN object is a very, very, very easy piece of SPIN code. Why do you people not READ it rather than speculate about arbitrary behaviour.

    You can tune it to your own wishes as you like, as hippy pointed out!

    I again see that it is high time to post my Video Tutorial - but I am still not satisfied with it. I see there is - week after week - ALWAYS the same misconception of a "screen buffer"; I think mainly because the tile vector is called "screen" in some demos smile.gif
  • RaymanRayman Posts: 14,162
    edited 2007-09-20 12:05
    Richard,·
    Instead of using the 'str' function to position the text, just set the global variables 'row' and 'col' to the desired position and then print your string...

    You can also just use the 'color' variable to select your color before calling 'str' to print the string.
    ·
Sign In or Register to comment.