Shop OBEX P1 Docs P2 Docs Learn Events
Memory getting weird using DrawBitMap — Parallax Forums

Memory getting weird using DrawBitMap

T ChapT Chap Posts: 4,223
edited 2012-11-03 09:26 in Propeller 1
I grabbed a few parts from a large code. Can someone explain how the DrawBitMap line is overwriting a byte in VAR called ScreenMode to 0?

Thanks


VAR 
  ' plenty of longs, words, bytes here
  Byte pwtimeout,fppause, plusminusval, test1, menumode, screenerase, ScreenMode, menuindex
  Byte previouslockstate , currentlockstate, chksum

PUB somemethod
           DrawBitmap(@graphic0_data, @graphics70_info)   '  or other similar info

PRI DrawBitmap(pBitmap,  pInfo)|c,i,j,BmpAddress,xPos, yPos, xSize, ySize,bpp,clr

  bpp:=byte[pInfo++]       '<<<<<<<<<<<<  THIS IS WRITING SCREENMODE IN VAR TO 0  >>>>>>>>>>>>>>>>>

  xSize:=byte[pInfo++]
  ySize:=byte[pInfo++]
  xPos:=byte[pInfo++]
  yPos:=byte[pInfo++]
  clr:=byte[pInfo++]
  row:=yPos
  col:=xPos
  c:=0
  BmpAddress:=pBitmap
  repeat j from 0 to (ySize-1) step 2    '2
    repeat i from 0 to (xSize-1)
      screen[row * cols + col] := (clr<<1+1) << 10 + BmpAddress>>6 +c
      screen[(row+1) * cols + col] := (clr<<1) << 10 + BmpAddress>>6 +c
      c++
      col++
    row+=2
    col:=xPos


DAT
UserCharEnd long  '*******************************************************************
'bitmap size and location data
                  '             bpp, width, height,   x,      y,    clr
graphics1_info  byte   1,    2,     4,      5,        13,    0      '1
graphics2_info  byte   1,    2,     4,      5,         8,    0      '2
graphics3_info  byte   1,    2,     4,      5,         3,    0      '2
graphics4_info  byte   1,    2,     4,      10,       13,    0      '2
graphics5_info  byte   1,    2,     4,      10,        8,    0      '2
graphics6_info  byte   1,    2,     4,      10,        3,    0      '2
graphics7_info  byte   1,    2,     4,      15,       13,    0      '2
graphics8_info  byte   1,    2,     4,      15,        8,    0      '2
graphics9_info  byte   1,    2,     4,      15,        3,    0      '2
graphics0_info  byte   1,    2,     4,      20,        8,    0      '2

Comments

  • RaymanRayman Posts: 14,670
    edited 2012-11-02 12:00
    Are you saying that one line "bpp:=byte[pInfo++]" is changing the value of the byte variable,, "screenmode"?

    If so, I don't immediately see how that is possible, unless you are out of memory and the stack is corrupted or something...
  • Mark_TMark_T Posts: 1,981
    edited 2012-11-02 12:04
    You are not clipping the rectangle to the display area - row + ypos can exceed the number of rows?
  • T ChapT Chap Posts: 4,223
    edited 2012-11-02 12:09
    This is the entire DAT section. You can substitute:

    DrawBitmap(@graphic0_data, @graphics60_info)

    and the ScreenMode stays equal to 1 like it should.

    But, if you use any of these it changes ScreenMode to 0:

    DrawBitmap(@graphic0_data, @graphics61_info)
    DrawBitmap(@graphic0_data, @graphics62_info)
    DrawBitmap(@graphic0_data, @graphics63_info)
    DrawBitmap(@graphic0_data, @graphics64_info)
    DrawBitmap(@graphic0_data, @graphics65_info)
    DrawBitmap(@graphic0_data, @graphics66_info)
    DrawBitmap(@graphic0_data, @graphics67_info)
    DrawBitmap(@graphic0_data, @graphics68_info)
    DrawBitmap(@graphic0_data, @graphics69_info)
    DrawBitmap(@graphic0_data, @graphics70_info)

    Remove the line bpp:=byte[pInfo++] and ScreenMode is not affected.

    Remove both the line bpp:=byte[pInfo++] AND xSize:=byte[pInfo++] and ScreenMode changes to some other number besides 0 or 1 which it is supposedly only allowed to be set to. Somehow the var is getting overwritten on in some cases of using @graphics70_info, but not others.


    DAT
    padding LONG 7[16]
    UserCharStart long' *********************************************************
    graphic1_data long
            file "1.dat"
    graphic2_data long
            file "2.dat"
    graphic3_data long
            file "3.dat"
    graphic4_data long
            file "4.dat"
    graphic5_data long
            file "5.dat"
    graphic6_data long
            file "6.dat"
    graphic7_data long
            file "7.dat"
    graphic8_data long
            file "8.dat"
    graphic9_data long
            file "9.dat"
    graphic0_data long
            file "0.dat"
    graphic15_data long
            file "plus.dat"
    graphic16_data long
            file "minus.dat"
    graphic20_data long
            file "dadologomask.dat"  'dado
    graphic21_data long
            file "dadologo1.dat"  'dado
    
    
    '''[[[[[[[  Group 1   ]]]]]]]]]
    {
    graphic39_data long
            file "enteradmin.dat"
    graphic40_data long
            file "menuoptions.dat"
    graphic41_data long
            file "togglescreen.dat"
    graphic42_data long
            file "changeadmin.dat"
    graphic43_data long
            file "changeuser.dat"
    graphic44_data long
            file "enterprint.dat"
    graphic45_data long
            file "deleteprint.dat"
    }
    '''[[[[[[[  Group 2   ]]]]]]]]]
    {
    graphic46_data long
            file "deleteallprints.dat"
    graphic47_data long
            file "setbeepvol.dat"
    graphic50_data long
            file "exitmenu.dat"
    graphic52_data long
            file "exitingmenu.dat"
    graphic53_data long
            file "accepted.dat"
    graphic54_data long
            file "enternewpw.dat"
    graphic56_data long
            file "acceptchange.dat"
    }
    
    '''[[[[[[[  Group 3   ]]]]]]]]]
    {
    graphic57_data long
            file "completed.dat"
    graphic58_data long
            file "placefinger.dat"
    graphic59_data long
            file "removefinger.dat"
    graphic60_data long
            file "alreadyexists.dat"
    graphic110_data long
            file "printaccepted.dat"
    graphic111_data long
            file "pleasewait.dat"
    graphic112_data long
            file "slotnumber.dat"
    }
    
    '''[[[[[[[  Group 4   ]]]]]]]]]
    {
    graphic113_data long
            file "enterslot.dat"
    graphic114_data long
            file "confirmdelete.dat"
    graphic115_data long
            file "printnotfound.dat"
    graphic122_data long
            file "autolockmenu.dat"
    graphic123_data long
            file "autolockicon.dat"
    graphic124_data long
            file "autolockiconmask.dat"
    graphic125_data long
            file "privacy.dat"
    }
    
    '''[[[[[[[[[  KEEP IN DAT   ]]]]]]]]]]
    graphic51_data long
            file "menulistmask.dat"   'KEEP IN
    
    graphic55_data long
            file "numbermask.dat"     'KEEP IN
    graphic22_data long
            file "mainarrows1.dat"  'slide
    graphic23_data long
            file "arrowleft1.dat"  'arrow1
    graphic24_data long
            file "arrowright1.dat"  'arrow2
    graphic25_data long
            file "locksymbol1.dat"  'unlocked
    'graphic26_data long
            'file "locked.dat"  '  "Locked" text option
    graphic27_data long
            file "led1.dat"  'led
    
    '''''''''''''''''''''''''''''''''''''''''''''''
    graphic116_data long
            file "v0.dat"
    graphic117_data long
            file "v1.dat"
    graphic118_data long
            file "v2.dat"
    graphic119_data long
            file "v3.dat"
    graphic120_data long
            file "vmask.dat"
    
    
    ''''''''''''''''''''''''''''''''''''''''''''''''''
    graphic00_data long 0[704]
            'file "2.dat"
    DAT   ' GRAPHICS INFO
    UserCharEnd long  '*******************************************************************
    'bitmap size and location data
            '             bpp, width, height,   x,      y,    clr
    graphics1_info  byte   1,    2,     4,      5,        13,    0      '1
    graphics2_info  byte   1,    2,     4,      5,         8,    0      '2
    graphics3_info  byte   1,    2,     4,      5,         3,    0      '2
    graphics4_info  byte   1,    2,     4,      10,       13,    0      '2
    graphics5_info  byte   1,    2,     4,      10,        8,    0      '2
    graphics6_info  byte   1,    2,     4,      10,        3,    0      '2
    graphics7_info  byte   1,    2,     4,      15,       13,    0      '2
    graphics8_info  byte   1,    2,     4,      15,        8,    0      '2
    graphics9_info  byte   1,    2,     4,      15,        3,    0      '2
    graphics0_info  byte   1,    2,     4,      20,        8,    0      '2
    graphics15_info  byte   1,    2,     4,      20,       3,    0      '2
    graphics16_info  byte   1,    2,     4,      20,      13,    0      '2
    graphics11_info  byte   1,    2,     4,      27,      13,    0      '2
    graphics12_info  byte   1,    2,     4,      27,       8,    0      '2
    graphics13_info  byte   1,    2,     4,      27,       3,    0      '2
    graphics20_info  byte   1,    2,     4,      1,   rows-3,   0     'dado logo mask
    graphics21_info  byte   1,    2,     4,      1,   rows-3,   0     'dado logo
    graphics22_info  byte   1,    2,     4,      9,       8,    0      'main arrows
    graphics23_info  byte   1,    1,     2,      20,     14,     0      'arrow1
    graphics24_info  byte   1,    1,     2,      20,      2,     0      'arrow2
    graphics25_info  byte   1,    1,     2,      26,      8,     0      'unlocked
    'graphics26_info  byte   1,    2,     6,   cols-2,     0,     0      '"locked"
    graphics27_info  byte   1,    1,    2,   26,      2,     2      '"GREEN LED"  *****
    graphics28_info  byte   1,    1,    2,   26,      2,     1      '"RED LED"  *****
    graphics29_info  byte   1,    1,     2,   26,     2,    0      'Blue LED = not connected
    ''''graphics30_info  byte   1,    1,     4,      24,   14,    0     'menumask
    'graphics33_info  byte   1,    1,     2,      24,  14,    0     'scroll up arrow
    'graphics34_info  byte   1,    1,     2,      28,  14,    0     'scroll down arrow
    'graphics35_info  byte   1,    1,     2,      24,  14,    0     'scroll up arrowmask
    'graphics36_info  byte   1,    1,     2,      28,  14,    0     'scroll down arrowmask
    graphics39_info  byte   1,    2,     10,      24,  4,    0     'Enter admin#
    graphics40_info  byte   1,    2,     10,      24,  4,    0     'menu options
    graphics41_info  byte   1,    2,     10,      24,  4,    0     'toggle screen
    graphics42_info  byte   1,    2,     10,      24,  4,    0     'change admin
    graphics43_info  byte   1,    2,     10,      24,  4,    0     'change user
    graphics44_info  byte   1,    2,     10,      24,  4,    0     'enter new print
    graphics45_info  byte   1,    2,     10,      24,  4,    0     'delete print
    graphics46_info  byte   1,    2,     10,      24,  4,    0     'delete all prints
    graphics47_info  byte   1,    2,     10,      24,  4,    0     'set beep vol
    graphics50_info  byte   1,    2,     10,      24,  4,    0     'Exit menu
    graphics51_info  byte   1,    2,     10,      24,  4,    0     'menulistmask
    graphics52_info  byte   1,    2,     10,      24,  4,    0     'exiting menu
    graphics53_info  byte   1,    2,     10,      24,  4,    0     'accepted  pw
    graphics54_info  byte   1,    2,     10,      24,  4,    0     'enter new pw
    graphics56_info  byte   1,    2,     10,      24,  4,    0     'accept change?
    graphics57_info  byte   1,    2,     10,      24,  4,    0     'completed!
    graphics58_info  byte   1,    2,     10,      24,  4,    0     'place finger!
    graphics59_info  byte   1,    2,     10,      24,  4,    0     'Remove Finger
    graphics60_info  byte   1,    2,     10,      24,  4,    0     'Already Exists
    '''password enter char 1
    graphics61_info  byte   1,    2,     4,      28,  14,    0     '1
    graphics62_info  byte   1,    2,     4,      28,  14,    0     '2
    graphics63_info  byte   1,    2,     4,      28,  14,    0     '3
    graphics64_info  byte   1,    2,     4,      28,  14,    0     '4
    graphics65_info  byte   1,    2,     4,      28,  14,    0     '5
    graphics66_info  byte   1,    2,     4,      28,  14,    0     '6
    graphics67_info  byte   1,    2,     4,      28,  14,    0     '7
    graphics68_info  byte   1,    2,     4,      28,  14,    0     '8
    graphics69_info  byte   1,    2,     4,      28,  14,    0     '9
    graphics70_info  byte   1,    2,     4,      28,  14,    0     '0
    
    graphics101_info byte   1,    2,     4,      28,  14,    0     '0
    graphics102_info byte   1,    2,     4,      28,  10,    0     '0
    graphics103_info byte   1,    2,     4,      28,  6,    0     '0
    graphics104_info byte   1,    2,     4,      28,  2,    0     '0
    
    'bitmap size and location data
            '             bpp, width, height,      x,      y,    clr
    graphics110_info  byte   1,    2,     10,      24,  4,    0     'printe accepted
    graphics111_info  byte   1,    2,     10,      24,  4,    0     'please wait
    graphics112_info  byte   1,    2,     10,      24,  4,    0     'slot number
    graphics113_info  byte   1,    2,     10,      24,  4,    0     'enter slot #
    graphics114_info  byte   1,    2,     10,      24,  4,    0     'confirm delete 
    graphics115_info  byte   1,    2,     10,      24,  4,    0     'print not found
    graphics116_info  byte   1,    1,     2,       29,  16,    0     'volume
    
    graphics120_info  byte   1,    2,     2,        23,  8,    0     'A
    graphics121_info  byte   1,    2,     10,       24,  4,    0     'Enter admin#
    
    
    graphics123_info  byte   1,    1,    4,       28,  14,    0     'autolockicon       <<<<<resize
    graphics124_info  byte   1,    1,    4,       28,  14,    0     'autolockiconmask   <<<<<resize
    graphics125_info  byte   1,    1,     4,      28,  15,    0     'privacy  <<<<<resize
    
  • RaymanRayman Posts: 14,670
    edited 2012-11-02 12:32
    Maybe Mark_T is right about running off the edge of the screen?

    I see graphics #61...70 have a big x value and a big width...

    Strange things may happen if it tries to draw a bitmap that is not entirely within the screen bounds...
  • Ahle2Ahle2 Posts: 1,179
    edited 2012-11-02 12:52
    If your memory gets weird using DrawBitMap, then stop using it!
    (Btw, my memory gets weird using alcohol)
  • T ChapT Chap Posts: 4,223
    edited 2012-11-02 13:33
    Thanks for the good eyes! Running off the edge seems to be the problem.
  • T ChapT Chap Posts: 4,223
    edited 2012-11-03 09:15
    I notice that when exporting a 16 x 16 test bitmap out of PixelFormer, and then importing it into Prop1Bit, it says it is a 1X x 2Y tile. When changing the numbers to 1 x 1 and attempting to save as DAT, the app crashes on two different computers. The exported 16x16 bmp says it is 126 bytes on the PC. The test bmp is just a 16 x 16 mono tile with all pixels turned on. I am trying to find out if this extra tile is really getting used in the DAT version which is overstepping the boundaries past 0-15Y or 0-29X on the 4.3 Newhaven.
  • RaymanRayman Posts: 14,670
    edited 2012-11-03 09:17
    Well, it shouldn't crash... But, the 1-bit bitmap app expects y to be a multiple of 2.
    That is because, like the ROM font, it stores 2 tiles of 1 bit data into one 2-bit tile...

    But, you don't have to draw the second tile in your app, you can tell it just to draw 1 tile and that should work fine.
  • T ChapT Chap Posts: 4,223
    edited 2012-11-03 09:20
    So does that mean if you push the dat file up to the last row or column, the extra tile shown in the preview on the Prop1Bit is not actually overlapping the screen boundary?
  • RaymanRayman Posts: 14,670
    edited 2012-11-03 09:26
    Right, when you use the "DrawBitmap" function, just be sure to specify height as 1 tile instead of 2.
Sign In or Register to comment.