Menu

table names as variables

Help
2020-02-04
2020-02-05
  • stan cartwright

    stan cartwright - 2020-02-04

    Sorry to bother you but I want to read from different tables but changing the table name ie tableto read=table xxx or any table doesn't seem to work.

    do
    for temp= 100 to 200
      lander_x=temp:lander_y=temp
     sprite_x=lander_x:sprite_y=lander_y:sprite_width=lander_width:sprite_height=lander_height
      end_data=lander_width*lander_height
      tabledata=lander; !!! WHICH TABLE NOT WORKING !!!!
      sprite (sprite_x,sprite_y) ;draw sprite
      wait 100 ms
    next temp
    loop
    ;
    sub sprite (sprite_x,sprite_y) ;fills box with sprite data
      SetAddressWindow_ILI9341 ( sprite_x,sprite_y,sprite_x + sprite_width-1,sprite_y + sprite_height - 1 )
      for ptr=0 to end_data ;(sprite_width * sprite_height)
        ReadTable tabledata,ptr,pixel ;!!!!! TABLEDATA CAN NOT BE VARIABLE!!!
        SendWord_ILI9341 pixel
      next ptr
    end sub
    ;
    table lander
    sprite data values
    

    so how to use a viable for tables ie table to use = table xyz then read table xyz and although the sub uses table to use it uses table xyz
    Is an array same memory as a table? I was thinking of an alternative of storing sprite data

     
  • stan cartwright

    stan cartwright - 2020-02-04

    Should I use a var that makes it use one sub and table or another sub and table?
    It was for a V flame under the lander sprite but found line works ok, just 2 short lines.
    Coming along nice. The sprite is surrounded by background pixels and only moves one pixel at a time so is self erasing,just plot it and the V flame is only plotted when the thrust key is pressed else it gets erased by the sprite. Neat. Simulate gravity and left/right momentum next.

     
  • Jim giordano

    Jim giordano - 2020-02-05

    Yes, use a variable, it doesn't take up much memory for an if around the readtable.

    e.g. I used this to test and it worked correctly.

    table xx
    1,2,6
    end table
    
    table yy
    3,4,9
    end table
    
    dim aa,ii,jj
    cls
    for ii=1 to 2 ' test 2 tables
      for jj=1 to 3
        if ii=1 then
          readtable xx,jj,aa
        else if ii=2 then
          readtable yy,jj,aa
        end if
        printdatax aa
      next
    next
    do:loop
    sub printdatax (inval)
      print inval:print " "
    end sub
    

    If you look at the asm, the if portion looks like this:

    ;if ii=1 then
        decf    II,W
        btfss   STATUS, Z
        goto    ELSE1_1
    ;readtable xx,jj,aa
        movf    JJ,W
        movwf   SYSSTRINGA
        call    XX
        movwf   AA
    ;else if ii=2 then
        goto    ENDIF1
    ELSE1_1
        movlw   2
        subwf   II,W
        btfss   STATUS, Z
        goto    ENDIF1
    ;readtable yy,jj,aa
        movf    JJ,W
        movwf   SYSSTRINGA
        call    YY
        movwf   AA
    ;end if
    ENDIF1
    

    so not many bytes.

     

    Last edit: Jim giordano 2020-02-05
    • stan cartwright

      stan cartwright - 2020-02-05

      Thanks Jim. So there's no readtable variable. I'll use if then.
      Previously I had two tables same size, 256 bytes each and used a pointer to read the data.
      0 to 256 for first table and add 256 to the pointer to read second table.

       
  • Jim giordano

    Jim giordano - 2020-02-05

    That seems like a quite usable solution. Put it all in one table and just read from where you want. No ifs required.

     
  • stan cartwright

    stan cartwright - 2020-02-05

    As long as the tables are sequencial they can have different names to.
    The following needs explaining but is probably explained somewhere,
    is a table part of the program code or it it stored in ram like an array?
    Is it faster to read an array than a table ie clock cycles?
    Cheers.
    ps Anobiums SetAddressWindow_ILI9341 ( sprite_x,sprite_y,sprite_x + sprite_width-1,sprite_y + sprite_height - 1 ) is nice,must use hardware

     

    Last edit: stan cartwright 2020-02-05
  • Jim giordano

    Jim giordano - 2020-02-05

    You can't rely on that. If the second table won't fit within the current page boundary, it will probably be put in the next page. Not sure, you'd have to ask Evan or Hugh or ?

     
  • Anobium

    Anobium - 2020-02-05

    Its going to depends

    Which chip? AVR/18F have different memory architectures - so they perform differently to 16F and the others.

    Array v Tables. Again what chip? Array use RAM and Table use PROGMEM. I have never tested the performance of array v tables but as stated - it will be dependent on the chip architecture. If some has time - test.. it would be interesting.

    Tables as Byte or Words. This should be tested. Is it faster to use a Table of Bytes or a Table of Words. Testing would yield some insights.

    Test and find out.

     
  • stan cartwright

    stan cartwright - 2020-02-05

    For this demo I chose a pic18f25k22 at 3.3V.
    It's not as versatile as a 328p imho but useful...and no setting up pins.
    I'm not very good at reading the pic data sheets or any data sheets really.
    Gcb dumbs down all that stuff for me.
    I had the idea that ram was continuous not paged and if the program/chip could handle it then maybe faster.
    meanwhile the demo now has 3 switches left,vertical,right thrust and the flame is only lit when the button is pressed and auto erased by the sprite when not.

    Anobium .hi, many things to test like when does using pset to plot xnumber of pixels become faster or slower than using line xnumber of pixels. one of the things I'm testing.
    I think the sprite method of filling a window better than a horizontal loop of pixels inside a vertical loop of rows. like a raster scan using pset.

     

Log in to post a comment.