Shop OBEX P1 Docs P2 Docs Learn Events
assembly programming and the vga_512x384_bitmap obj — Parallax Forums

assembly programming and the vga_512x384_bitmap obj

tonyp12tonyp12 Posts: 1,951
edited 2009-05-24 23:39 in Propeller 1
UPDATE: further down is a TEXT SCROLLER.
A short little routine that does a good job, and is·helpful to learn from.

Just had the propeller for a few days.
I'm skipping Spin and go directly to pasm.
Here is·my first·VGA test, it's simple so it's easy to learn from.
1: Fills the color blocks with red/dark_blue
2: put in 16 columns, 64 pixels high.
3: rotate them in sync with monitor display.
Any veterans that have inputs what should have been done in better way?

CON
  _clkmode = xtal1 + pll16x
  _xinfreq = 5_000_000
  tiles    = vga#xtiles * vga#ytiles
  tiles32  = tiles * 32

OBJ
  vga : "vga_512x384_bitmap"

VAR
  long  sync, pixels[noparse][[/noparse]tiles32]
  word  colors[noparse][[/noparse]tiles]

PUB start | h, i, j, k, x, y
  'start vga
  vga.start(16, @colors, @pixels, @sync)
 
  'implant pointers and launch assembly program into COG
  asm_colors := @colors
  asm_pixels := @pixels
  asm_sync := @sync
 
 cognew(@asm_entry, 0)
 
DAT  '
'
' Assembly program
'
              org

 
asm_entry     mov counter, #192                         '192 words to write
:loop         wrword palette,asm_colors                 'write to hub ram, one time setup rutine.                 
              add asm_colors, #2                        'move forward 2 bytes
              djnz counter, #:loop 
 
main
              mov counter, #16                           '16 longs wide is one horisontal line
              shl counter, #6                            'multiply with 64
              mov asm_pixpntr,asm_pixels                 'buffer the asm_pixels pointer
:loop         wrlong pix_data, asm_pixpntr               'write long for 32 pixels.
              add asm_pixpntr, #4                        'move forward 4 bytes
              djnz counter, #:loop
 
:waitforsync  rdlong sync_clear, asm_sync wz             'read long from hub ram and do a zero flag check
              if_z jmp #:waitforsync                     'if zero, test again.
              mov sync_clear, #0                         'reset it,
              wrlong sync_clear,asm_sync                 'write long to hub ram
              rol pix_data, #1                           'rotate pixel dat left, as lsb is first it will look ror
              jmp #main
 
asm_colors    long      0                               'pixel base (set at runtime)
asm_pixels    long      0                               'pixel base (set at runtime)
asm_sync      long      0                               'sync (set at runtime)
asm_pixpntr   long      0                               'buffer for asm_pixels pointer
palette       long      %100000 <<10 + %000001 <<2      'RrGgBbxx + RrGgBbxx (forground and background colors)
pix_data      long      $000000ff 
sync_clear    res       1
counter       res       1

Post Edited (tonyp12) : 5/24/2009 11:43:24 PM GMT

Comments

  • virtuPICvirtuPIC Posts: 193
    edited 2009-05-20 19:16
    Ever had a look at microphone_to_vga.spin? This little beasty converts your demo board to an oscilloscope showing sound it takes from its microphone. It erases the pixel curve individually and draws new pixel when they become available.

    I don't know if it is of interest for you. Just my $.02...

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Airspace V - international hangar flying!
    www.airspace-v.com/ggadgets for tools & toys
  • tonyp12tonyp12 Posts: 1,951
    edited 2009-05-20 19:41
    I looked at it, but I like to start small with very basic stuff and add stuff as I learn.
    I posted it on youtube
    [url=mhtml:{4C6317E7-E7BB-490B-92C7-AF4FA83717C3}mid://00000001/!x-usc:http://www.youtube.com/watch?v=GWViWCxK_SM][/url]



    I can NOT find a 4 color bitmap driver on the OBJ exchange?

    And one have·source for that?

    preferable just a modified version of·the vga_512x384_bitmap obj

    320 pixels/8*2· *240 pixels =··19kb for pixel data




    Post Edited (tonyp12) : 5/20/2009 7:58:12 PM GMT
  • tonyp12tonyp12 Posts: 1,951
    edited 2009-05-23 02:18
    I played around a little more.
    Reads a letter in cog ram, finds the corresponding font bitmap in ROM.
    Get rid of the interleaving.

    the result: http://www.youtube.com/watch?v=dtahz8WwBm0

    [color=black]CON[/color]
    [color=black]  _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000[/color]
    [color=black]  tiles    = vga#xtiles * vga#ytiles
      tiles32  = tiles * 32[/color]
    
    [color=black]OBJ[/color]
    [color=black]  vga : "vga_512x384_bitmap"[/color]
    
    [color=black]VAR[/color]
    [color=black]  long  sync, pixels[noparse][[/noparse]tiles32]
      word  colors[noparse][[/noparse]tiles][/color]
    
    [color=black]PUB start | h, i, j, k, x, y[/color]
    [color=black]  'start vga
      vga.start(16, @colors, @pixels, @sync)[/color]
    [color=black]  'implant pointers and launch assembly program into COG
      asm_colors := @colors
      asm_pixels := @pixels
      asm_sync := @sync
      cognew(@asm_entry, 0)[/color]
     
    [color=black]DAT  '
    '
    ' Assembly program
    '
                  org
    asm_entry     mov counter1, #192                        '192 words to write
                  mov asm_colpnt, asm_colors                'buffer the asm_color pointer  
    :loop         wrword palette,asm_colpnt                 'write to hub ram.              
                  add asm_colpnt, #2                        'move forward 2 bytes
                  djnz counter1, #:loop [/color]
    [color=black]main 
                  mov counter1, #16                         '16 chars per line
                  mov asm_pixpntr,asm_pixels                'buffer the asm_pixels pointer
                  
    :loop1        mov fontpnt, text                         'init font pointer  
                  add :loop1,#1                             'self modifying code, increase text pointer.
                  shr fontpnt, #1 wc                        'no odd numbers please, but let me know if it was.
                  shl fontpnt, #7                           'multiply by 64 plus counteract the SHR above
                  add fontpnt, fontmap                      'add $8000
                  mov counter2, #32                         '32 pixels tall  [/color]
    [color=black]:loop2        rdlong pix_data, fontpnt                  'read from Hub-ROM
                  if_nc and pix_data, mask1                 'it was an even number (checked 5 lines above)
                  if_c and pix_data, mask2                  'it was an odd number  (get rid of interleaving) 
                  mov pix_data2, pix_data                   'make a copy of the font
                  if_nc shl pix_data2, #1                   'if even, shift the copy left 1 pixel
                  if_c shr pix_data2, #1                    'if odd, shift the copy right 1 pixel 
                  or pix_data,pix_data2                     'mix them togheter.
                  
                  wrlong pix_data, asm_pixpntr              'write long to hub ram for 32 pixels.
                  add asm_pixpntr, #64                      'move forward 64 bytes
                  add fontpnt, #4                           'next long
                  djnz counter2, #:loop2
                  sub asm_pixpntr, nextblock                'counteract all the #64 we added
                  djnz counter1, #:loop1
                    
            [/color]
    
    [color=black]waitforsync   rdlong sync_clear, asm_sync wz            'read long from hub ram and with a zero flag check
                  if_z jmp #waitforsync                     'if zero, test again.
                  mov sync_clear, #0                        'reset it,
                  wrlong sync_clear,asm_sync                'write long to hub ram
                 
                  
                  mov counter1, #16
                  mov asm_colpnt, asm_colors
                  add asm_colpnt,#32      
                  movs palette, #%11111000
                  sub  palette, palette_cnt
                  djnz palette_cnt, #:loop
                  mov  palette_cnt, #200
    :loop         wrword palette,asm_colpnt                 'write to hub ram                 
                  add palette, #4
                  add asm_colpnt, #2                        'move forward 2 bytes
                  djnz counter1, #:loop 
                  jmp #waitforsync[/color]
     
    [color=black]asm_colors    long    0                               'pixel base (set at runtime)
    asm_colpnt    long    0                               '
    asm_pixels    long    0                               'pixel base (set at runtime)
    asm_sync      long    0                               'sync (set at runtime)
    asm_pixpntr   long    0                               'buffer for asm_pixels pointer[/color]
    [color=black]palette       long    %100000 <<10 + %000001 <<2      'RrGgBbxx + RrGgBbxx (forground and background colors)
    palette_cnt   long    200[/color]
    [color=black]pix_data      long    0
    pix_data2     long    0  
    nextblock     long    64*32-4       'move back the pixel pointer to where you started + one long
    fontmap       long    $8000
    fontpnt       long    0
    mask1         long    %01010101_01010101_01010101_01010101
    mask2         long    %10101010_10101010_10101010_10101010[/color]
    [color=black]text          long    "Hi I'm PROPELLER"
                   [/color]
    [color=black]sync_clear    res     1
    counter1      res     1
    counter2      res     1  
    [/color]        [url=http://www.youtube.com/watch?v=dtahz8WwBm0][/url]
    
  • tonyp12tonyp12 Posts: 1,951
    edited 2009-05-24 23:39
    OK the final showing of the bitmap obj and assembly demo

    A Text Scroller.

    In a·clever way it uses RCR for both shifting and insertion of font bits.

    The result: http://www.youtube.com/watch?v=dZZMfN2loAg

    [color=black]CON[/color]
    [color=black]  _clkmode = xtal1 + pll16x
      _xinfreq = 5_000_000[/color]
    [color=black]  tiles    = vga#xtiles * vga#ytiles
      tiles32  = tiles * 32[/color]
    
    [color=black]OBJ[/color]
    [color=black]  vga : "vga_512x384_bitmap"[/color]
    
    [color=black]VAR[/color]
    [color=black]  long  sync, pixels[noparse][[/noparse]tiles32]
      word  colors[noparse][[/noparse]tiles][/color]
    
    [color=black]PUB start | h, i, j, k, x, y[/color]
    [color=black]  'start vga
      vga.start(16, @colors, @pixels, @sync)[/color]
    [color=black]  'implant pointers and launch assembly program into COG
      asm_colors := @colors
      asm_pixels := @pixels
      asm_sync := @sync
      cognew(@asm_entry, 0)[/color]
     
    [color=black]DAT  '
    '
    ' Assembly program
    '
                  org
    asm_entry     mov counter1, #192                        '192 words to write
     :loop        wrword palette,asm_colors                 'write to hub ram.              
                  add asm_colors , #2                       'move forward 2 bytes
                  djnz counter1, #:loop 
                    
           
    scroller      mov fontpntr, text wz                     'init font pointer
                  add scroller, #1                          'self modifying code  
                  if_z movs scroller, #text                 'reset text pointer
                  if_z mov fontpntr, #32                    'use space
                  mov mask, #%01 
                  shr fontpntr, #1 wc                       'no odd numbers please, but let me know if it was.[/color]
    [color=black]              if_c mov mask, #%10 
                  shl fontpntr, #7                          'multiply by 64 plus counteract the SHR above
                  add fontpntr,fontrom                      'adds $8000 +127  
                  
    :waitforsync  rdlong sync_clear, asm_sync wz            'read long from hub ram and with a zero flag check
                  if_z jmp #:waitforsync                    'if zero, test again.
                  mov sync_clear, #0                        'reset it,
                  wrlong sync_clear,asm_sync                'write long to hub ram[/color]
    [color=black]              mov asm_pixpntr, asm_pixels               'buffer the asm_pixel pointer         
                  add asm_pixpntr, block                    'start in a lower right corner 
                  mov counter1, #256                        
                  shl counter1, #1                          'make it 512[/color]
     
    [color=black]:loop         rdlong pix_data, asm_pixpntr  
                  test counter1, #%1111 wz                  'only happens every other 16 times           
                  if_z  rdlong pix_data2,fontpntr           'read font ROM in hub
                  if_z  sub fontpntr,#4                     'move up one line for next time
                  if_z  test pix_data2,mask wc              'set c flag if a 1, as 1 it's an odd number of bits.          
                  rcr pix_data, #1 wc                       [b]'shift right with carry flag[/b], use #2 for double speed/wide font
                  wrlong pix_data, asm_pixpntr              'write to the bitmap in hub
                  sub asm_pixpntr, #4                       'move backwards 4 bytes
                  djnz counter1, #:loop
                  
                  add fontpntr, #128                        'counteract all the the sub4 that was done 32 times. [/color]
    [color=black]              shl mask,#2  wz                           'shift left, z flag if you shifted youself out to zero
                  if_nz jmp #:waitforsync                   'if it was not zero, just wait for sync and use same font.
                  jmp #scroller
               [/color] 
    [color=black]asm_colors    long    0                               'pixel base (set at runtime)                            '
    asm_pixels    long    0                               'pixel base (set at runtime)
    asm_sync      long    0                               'sync (set at runtime)
    palette       long    %100000 <<10 + %000001 <<2      'RrGgBbxx + RrGgBbxx (forground and background colors)
    block         long    64*32*3-4                       'start at 3 blocks down, line31 right side
    fontrom       long    $8000+127                       'ROM location$8000 plus start 31 lines down 
    text          long    "          I have been impressed with the urgency of doing. Knowing is not enough; we must apply."
                  long    " Being willing is not enough; we must do. ( Leonardo da Vinci )"
                  long    "       We have to do the best we can. This is our sacred human responsibility. (Albert Einstein)",0
    asm_pixpntr   res     1                               'buffer for asm_pixels pointer  
    pix_data      res     1                               'buffer for vga bitmap
    pix_data2     res     1                               'buffer for font bits 
    mask          res     1                               'the rolling mask
    sync_clear    res     1                               
    counter1      res     1
    fontpntr      res     1
         [/color]
    

    Post Edited (tonyp12) : 5/25/2009 1:24:16 AM GMT
Sign In or Register to comment.