Shop OBEX P1 Docs P2 Docs Learn Events
Propeller VGA Demo: Text color and graphics — Parallax Forums

Propeller VGA Demo: Text color and graphics

Beau SchwabeBeau Schwabe Posts: 6,545
edited 2006-11-07 06:08 in Propeller 1
Here is a little something I have been putting together... It still needs some code optimization, but feel free to play around with it.
It uses the 'VGA_512x384_Bitmap' object that Chip put out awhile ago to allow you to include graphics as well as text.



[b]COMMAND Summary[/b]
[b]PUB[/b] Sine(Ang)|Arg1_             ' Input = 13-bit angle ranging from 0 to 8191
[b]PUB[/b] Cosine(Ang)|Arg1_           ' Input = 13-bit angle ranging from 0 to 8191
[b]PUB[/b] ArcSine(Ang)|Arg1_          ' Input = signed 16-bit value ranging from $FFFF0001 ('-1') to $0000FFFF ('1')
[b]PUB[/b] ArcCosine(Ang)|Arg1_,sign   ' Input = signed 16-bit value ranging from $FFFF0001 ('-1') to $0000FFFF ('1')
[b]PUB[/b] plot(x,y)| Arg2_,Arg3_,Arg4_                        'Sets pixel value at location x,y
[b]PUB[/b] point(x,y)| Arg2_ , Arg3_,Arg4_                     'Reads pixel value at location x,y
[b]PUB[/b] character(offX,offY,chr)|Arg3_,Arg4_,Arg5_          'Place a text character from the ROM table at offset location offsetX,offsetY
[b]PUB[/b] line (px,py,dx,dy)| Arg4_,Arg5_,Arg6_,Arg7_,Arg8_   'Draws line from px,py to dx,dy
[b]PUB[/b] box(x1,y1,x2,y2)| Arg4_,Arg5_,Arg6_,Arg7_,Arg8_     'Draws a box from opposite corners x1,y1 and x2,y2
[b]PUB[/b] color(tile,cval)                                    'Set Color tiles on VGA screen
[b]PUB[/b] pointcolor(pc)                                      'Sets pixel color "1" or "0"
[b]PUB[/b] Text(offX,offY,Address)|chr,i                       'Place a text string from the ROM table at offset location offsetX,offsetY
[b]PUB[/b] shape(x,y,sizeX,sizeY,sides,rotation)|angle,sx1,sy1,sx2,sy2         'Draws a shape with center located at x,y
[b]PUB[/b] deg(angle)                                          'translate deg(0-360) ---> to ---> 13-bit angle(0-8192)
[b]PUB[/b] bit13(angle)                                        'translate 13-bit angle(0-8192) ---> to ---> deg(0-360)
[b]PUB[/b] SimpleNum(x,y,DecimalNumber,DecimalPoint)|sign,DecimalIndex,TempNum,spacing,DecimalFlag,Digit    'Crude decimal number printing





Simple Spin Demo program:

[b]CON[/b]
  [b]_clkmode[/b] = [b]xtal[/b]1 + [b]pll[/b]16x
  [b]_xinfreq[/b] = 5_000_000

  '512x384
  tiles = gr#tiles
[b]OBJ[/b]
  gr    : "vga graphics ASM"

[b]PUB[/b] MainLoop|h,i,deg,x,y,mask,ii,char
    gr.start
    gr.pointcolor(1)
    [b]repeat[/b] i [b]from[/b] 0 to tiles - 1                        'init tile colors to white on black
      'gr.color(i,$FF00)
      gr.color(i,$FF<<8+i)                              'init tile colors "Nice view" 
    gr.text(0,0,[b]string[/b]("Parallax VGA text [b]and[/b] graphics"))
    gr.SimpleNum(464,32,123,3)

    gr.box(30,50,80,100)                                'draw a box
    'or
    'gr.shape(55,75,71,71,4,gr.deg(45))                  'draw a box

    [b]repeat[/b] i [b]from[/b] 3 to 15
      gr.shape(256,192,300,300,i,gr.deg(90))            'i = 3  triangle
                                                        'i = 4  square
                                                        'i = 5  pentagon
                                                        'i = 6  hexagon
                                                        'i = 7  heptagon
                                                        'i = 8  octagon
                                                        'i = 9  nonagon
                                                        'i = 10 decagon
                                                        'i = 11 hendecagon
                                                        'i = 12 didecqgon
                                                        'i = 13 tridecagon
                                                        'i = 14 tetradecagon
                                                        'i = 15 pentadecagon
    [b]repeat[/b]
      [b]repeat[/b] i [b]from[/b] 0 to 359
        gr.pointcolor(1)
        gr.shape(256,192,145,145,3,gr.deg(i))
        gr.shape(256,192,70,70,4,gr.deg(359-i*2))
        gr.shape(256,192,30,30,5,gr.deg(i*3))
        [b]repeat[/b] 4000                                                  
        gr.pointcolor(0)
        gr.shape(256,192,145,145,3,gr.deg(i))
        gr.shape(256,192,70,70,4,gr.deg(359-i*2))
        gr.shape(256,192,30,30,5,gr.deg(i*3))



▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
Beau Schwabe

IC Layout Engineer
Parallax, Inc.

Post Edited (Beau Schwabe (Parallax)) : 9/26/2006 3:56:22 AM GMT
1800 x 1200 - 473K

Comments

  • Beau SchwabeBeau Schwabe Posts: 6,545
    edited 2006-09-27 20:27
    Here is an Assembly update that might be a little easier to follow...

    Version 1.1 - Optimized Nested Assembly routines and reduced variable overhead
                - fixed offset problem with 'boxfill' command
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • El PaisaEl Paisa Posts: 375
    edited 2006-09-28 01:24
    Should be a warning that this program does not work with the basic VGA (640x480).
  • Beau SchwabeBeau Schwabe Posts: 6,545
    edited 2006-09-28 15:23
    El Paisa,

    In my first post on this thread, I state that this object uses the 'VGA_512x384_Bitmap' object that Chip released.

    The reason there is not a 640x480 or higher is purely because of memory limitations.· For a screen resolution of
    512 x 384 , this requires 6144 longs and leaves 2048 longs for your program space.· If the screen resolution were
    640 x 480, it would require 9600 longs.· This exceeds the capacity of the Propeller by 1408 longs.

    Longs = ( {Screen max X} / 32 ) * {Screen max Y}



    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Dennis FerronDennis Ferron Posts: 480
    edited 2006-09-28 15:47
    Can this be made to work with TV output?
  • Beau SchwabeBeau Schwabe Posts: 6,545
    edited 2006-09-28 16:02
    Dennis,

    There is already a graphics driver for TV output. I'm not sure I understand your request.

    Look at the 'Graphics_Demo.spin' program located where you installed the Propeller IDE under Examples--> Library
    The 'Graphics_Demo.spin' uses an object called 'Graphics.spin' located in the Propeller IDE installation directory.

    Essentially both graphics objects (VGA and TV) work the same, with the main difference being features that one graphics
    engine has that the other does not. The "core" assembly command dispatch program for the VGA graphics was actually
    copied from 'Graphics.spin', so you should see similarities between the two.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • Jim CJim C Posts: 76
    edited 2006-10-01 15:40
    Team:

    I have a question about the graphics for VGA. Graphing a set of data, line-graph style, would be helpful for a project I am working on. There was a thread a while ago that showed how to do this for with TV output (2 months ago?). I can't find the thread, but seems to me it showed code that graphed sound waves, or something like that, on a TV.

    Does anyone remember that thread? And, could this VGA graphics routine be used to do something similar on a VGA output?

    Thanks,

    Jim C
  • Beau SchwabeBeau Schwabe Posts: 6,545
    edited 2006-10-02 04:01
    Jim C,

    Since 'plot' and 'line' commands are available with the VGA graphics, it would be just a matter of getting the XY dataset you wanted to graph within the Propeller.
    There are several ways to do this, either by hard programming, or by setting up a com between PC and Propeller, etc.

    As far as the thread you mention, I don't recall, but there is a "microphone to VGA" demo already available that converts sound waves and displayes them on a VGA monitor.

    http://forums.parallax.com/showthread.php?p=590649

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 10/2/2006 4:42:41 AM GMT
  • Jim CJim C Posts: 76
    edited 2006-10-02 14:37
    Beau:

    Yes, that's the thread I was thinging about. (I guess it was a VGA monitor, not a TV.) I'll see if I can get something working, using Chip's program and your new drivers.

    Thanks.

    Jim C
  • Beau SchwabeBeau Schwabe Posts: 6,545
    edited 2006-10-02 17:02
    Jim C,

    This should work ok since the "microphone to VGA" uses the same "VGA_512x384_Bitmap" object. If you look at the assembly 'plot' routine in the "microphone to VGA"
    object verses the "vga graphics ASM" object's "Pixel_Core" routine you will notice some similarities, however there is a slight difference in the way the pixel position is
    calculated between the two. I based my assembly code from the example Chip gives in the "vga_512x384_bitmap_demo". I quite literally took the Spin code that he had...

    pixels[noparse][[/noparse]y << 4 + x >> 5 ] |= |< x
    
    



    ...and converted it to assembly.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • MC-BerndMC-Bernd Posts: 8
    edited 2006-10-09 15:17
    Hello Beau Schwabe,

    many thanks for that helpful VGA-grafik Demo.
    That's what I'm looking for. Drawing lines and write text together on VGA.
    I think that is the main reason to choose the PROPELLER. The people want the grafik possibilities on a Mikrocontroller.
    But in the grafik you need also some Text!

    I have two questions:
    1. Is there a possibility to write smaller text ?
    2. Can I write lines with different colors at the same screen ?

    Regards
    MC-Bernd
  • Beau SchwabeBeau Schwabe Posts: 6,545
    edited 2006-10-09 16:09
    MC-Bernd,

    Attached is the newest version of the VGA graphics... As this object evolves as I go, and as I need a particular function from it when making another demo, I will
    (for now) keep this open ended before I post it to the object exchange library.

    1) "Is there a possibility to write smaller text ?"
    ··· When I have some time, I will add a method for creating or using a custom font.· Be it a standard 8x8 or something else.

    2) "Can I write lines with different colors at the same screen ?"
    ··· You·can, but they must fall within a tile.· Each tile has two colors·you can·assign, a foreground (lines, text, etc.) and a background.· With·the color command,
    ··· the·color value is·represented as a WORD ($FFFF).· The Upper BYTE represents the foreground color, and the Lower BYTE represents the background color.

    Here is a list of the current VGA graphics commands:
    Sine(Ang)                                 ' Input = 13-bit angle ranging from 0 to 8191
                                              ' Output = 16-bit Sine value ranging from $FFFF0001 ('-1') to $0000FFFF ('1')
     
    Cosine(Ang)                               ' Input = 13-bit angle ranging from 0 to 8191
                                              ' Output = 16-bit Cosine value ranging from $FFFF0001 ('-1') to $0000FFFF ('1')
     
    ArcSine(Ang)                              ' Input = signed 16-bit value ranging from $FFFF0001 ('-1') to $0000FFFF ('1')
                                              ' Output = signed 11-bit angle ranging from -2047 (-pi/2) to 2047 (pi/2)
     
    ArcCosine(Ang)                            ' Input = signed 16-bit value ranging from $FFFF0001 ('-1') to $0000FFFF ('1')
                                              ' Output = signed 11-bit angle ranging from -2047 (-pi/2) to 2047 (pi/2)
     
    plot(x,y)                                 ' Sets pixel value at location x,y
    point(x,y)                                ' Reads pixel value at location x,y
    character(offX,offY,chr)                  ' Place a text character from the ROM table at offset location offsetX,offsetY
    line (px_,py_,dx_,dy_)                    ' Draws line from px,py to dx,dy
    box(x1_,y1_,x2_,y2_)                      ' Draws a box from opposite corners x1,y1 and x2,y2
    boxfill(x1_,y1_,x2_,y2_)                  ' Draws a filled box from opposite corners x1,y1 and x2,y2
    pointcolor(pc)                            ' Sets pixel color "1" or "0"
    clear                                     ' Clear entire screen contents
    color(tile,cval)                          ' Set Color tiles on VGA screen
    Text(offX,offY,Address)                   ' Place a text string from the ROM table at offset location offsetX,offsetY
    deg(angle)                                ' translate deg(0-360) ---> to ---> 13-bit angle(0-8192)
    bit13(angle)                              ' translate 13-bit angle(0-8192) ---> to ---> deg(0-360)
    shape(x,y,sizeX,sizeY,sides,rotation)     ' Draws a shape with center located at x,y
    SimpleNum(x,y,DecimalNumber,DecimalPoint) ' Basic Decimal number printing at location x,y
    
    

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
  • El PaisaEl Paisa Posts: 375
    edited 2006-10-12 03:05
    Beau, I am still confused about your program.
    I assumed that the reason this program wont run in a plain VGA (640x480) is because memory limitations and because is running in the graphics mode?.

    There is also another program xModemVGA_Bmp.spin that seems to run in the text mode and uses the 512x384 and still does not runs in my plain VGA (640x480).

    There is a program VGA_Hires_Text that gives you 3 choices (1024x768, 800x600 and 640x480).
    If I select the 640x480, the program runs just fine.

    My question is:
    Why· the 512x384 resolution does not work in the plain VGA (640x480)?

    Please somebody help me on this?
  • Mike GreenMike Green Posts: 23,101
    edited 2006-10-12 03:30
    The 512 x 384 resolution is actually 1024 x 768 with the pixels doubled up horizontally and vertically. If your monitor can't handle 1024 x 768, this driver will not work. The hires text driver actually reduces the resolution when you recompile it.
  • Jim CJim C Posts: 76
    edited 2006-10-23 15:05
    Team:

    I am slowly lifting the hood on this VGA graphics driver set. So far, things are working OK: It works as expected on one of my VGA monitors, and I've changed the demo to draw lines, boxes, pixels, etc. However, when hooking up to a different monitor at work, I'm getting some strange results.

    The problem is a triangular smeared out region that runs horizontally across the screen, about in the middle of the screen. The smearing-out forms a long narrow triangle that's approx. 50 pixels (Parallax sized) on the left side of the screen, narrowing to about half that on the right side of the screen. The colors in the smeared out long triangle include those from the rest of the screen.

    Several things were tried in an attempt to get at a solution. Screen resolution was changed to no avail. Then, upon randomly messing around with parameters in the "VGA 512x384 2-Color Bitmap Driver v1.0" driver, a partial solution was found. When changing the "pixel rate" parameter from 35 to 40, the screen straightens out, and the weird triangle is gone. But instead, there is now a message in the middle of the screen (presumable from the monitor itself) that says "OUT OF RANGE".

    It is a "Hansol" monitor, of no particular quality. Modes tried were:
    1024 x 768: 60, 70 and 75 Hz
    640 x 480: 60, 70 and 75 Hz

    Any ideas?

    Thanks,

    Jim C
  • Jim CJim C Posts: 76
    edited 2006-10-23 15:59
    After trying a few more things, I seem to have stumbled onto a fix. By changing the horizontal sync pixels parameter to 56, it got everything working. I can't explain why, but I'll take it.

    (Still learning about video....)

    Jim C
  • ALIBEALIBE Posts: 299
    edited 2006-10-23 16:12
    Beau,
    I have not tried this new object yet due to the lack of the display device. But, wanted to ask, when putting out new at x,y via the ::Text(), does that screen location have to be "cleared" before putting out new text on the same coords?

    with regular text mode, we should be fine. In Gx mode however, one needs to clear the area - am I correct in that understanding?

    thanks

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ALIBE - Artificial LIfe BEing. In search of building autonoumous land robot

    http://ALIBE.crosscity.com/
    http://fstop.crosscity.com/
    http://icar.crosscity.com/
    ·
  • Beau SchwabeBeau Schwabe Posts: 6,545
    edited 2006-10-23 16:23
    ALIBE,
    You said...
    when putting out new at x,y via the ::Text(), does that screen location have to be "cleared" before putting out new text on the same coords?
    Yes, that is correct. Only the pixel that is "ON"·will be written... use the boxfill command·or reprint the old text with the pointcolor command·set to "0" to clear previous data.
    Use the clear command to clear the entire screen.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.

    Post Edited (Beau Schwabe (Parallax)) : 10/23/2006 4:27:29 PM GMT
  • ALIBEALIBE Posts: 299
    edited 2006-10-23 16:42
    makes sense - thanks for confirming

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    ALIBE - Artificial LIfe BEing. In search of building autonoumous land robot

    http://ALIBE.crosscity.com/
    http://fstop.crosscity.com/
    http://icar.crosscity.com/
    ·
  • LucidGuppyLucidGuppy Posts: 32
    edited 2006-11-07 04:38
    Thanks for pointing me to the right thread. This should keep me busy for a while. Any quick way of reducing flicker on the demo?
  • Beau SchwabeBeau Schwabe Posts: 6,545
    edited 2006-11-07 06:08
    LucidGuppy,

    I haven't implemented it, but there is a sync indicator that signals each time the VGA screen is redrawn. This is provided within the VGA_512x384_Bitmap object.
    If you throttle your redraws based on the VGA screen refresh you should eliminate most if not all of the flicker.

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Beau Schwabe

    IC Layout Engineer
    Parallax, Inc.
Sign In or Register to comment.