Memory getting weird using DrawBitMap
T Chap
Posts: 4,223
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
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
If so, I don't immediately see how that is possible, unless you are out of memory and the stack is corrupted or something...
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.
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...
(Btw, my memory gets weird using alcohol)
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.