English Amiga Board


Go Back   English Amiga Board > Coders > Coders. Language > Coders. Blitz Basic

 
 
Thread Tools
Old 19 February 2019, 11:40   #1
MickGyver
Registered User

MickGyver's Avatar
 
Join Date: Oct 2008
Location: Finland
Posts: 407
Unsigned bytes

Is it possible to have a byte (.b) be handled as unsigned rather than signed?

I'm reading a tilemap as a binary file with one byte representing one tile. The values in the tilemap are unsigned (0-255). I read the tilemap into a byte array in Blitz Basic and the values become signed when reading from the array (all values after 128 become negative). Can I overcome this without using a word (.w) array?
MickGyver is offline  
Old 19 February 2019, 13:13   #2
MickGyver
Registered User

MickGyver's Avatar
 
Join Date: Oct 2008
Location: Finland
Posts: 407
I just figured out one way to do it. If you look at the example:

Code:
; Byte variables in BB2 are signed ( -127..128)

; So let's set the value of a byte variable to 200
variable.b=200

; If we now read the variable it will have a value of -56, since values above 128 are negative for a signed byte.
Print variable ; -56 is printed, which is NOT what we want

; If we use bitwise AND on the variable with 255 (%11111111), we get the correct value
Print (variable & 255) ; 200 is printed, which IS what we want
Any better ways?

Last edited by MickGyver; 20 February 2019 at 17:23.
MickGyver is offline  
Old 20 February 2019, 21:53   #3
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 4,009
Yeah, all variables are signed in Blitz unfortunately. The simplest way around it would be to use a Word array, with the obvious downside of doubled memory usage. It shouldn't significantly slow things down however, given the 16-bit bus on even the lowest of Amigas.
Daedalus is offline  
Old 21 February 2019, 11:44   #4
MickGyver
Registered User

MickGyver's Avatar
 
Join Date: Oct 2008
Location: Finland
Posts: 407
Quote:
Originally Posted by Daedalus View Post
Yeah, all variables are signed in Blitz unfortunately. The simplest way around it would be to use a Word array, with the obvious downside of doubled memory usage. It shouldn't significantly slow things down however, given the 16-bit bus on even the lowest of Amigas.
Thanks! I will move to using a word array if the bitwise AND trick will show to be too slow. I would save some memory by using bytes though. With a 16-bit bus, is there actually ANY speed difference with using 8-bit or 16-bit variables?
MickGyver is offline  
Old 21 February 2019, 16:09   #5
Daedalus
Registered User

Daedalus's Avatar
 
Join Date: Jun 2009
Location: Dublin, then Glasgow
Posts: 4,009
Probably not. If the compiler was clever and saw that you were loading multiple 8-bit values from adjacent locations (such as a string or an array), it might be able to load two at once, but I don't think the Blitz compiler is all that smart when you're dealing with each value separately. It would be an interesting benchmark to test, but I can't see there being any difference at all.
Daedalus is offline  
Old 23 March 2019, 02:21   #6
idrougge
Registered User
 
Join Date: Sep 2007
Location: Stockholm
Posts: 3,793
You can turn off overflow errors in the compiler settings if you know what you're doing.
idrougge is offline  
 


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools

Similar Threads
Thread Thread Starter Forum Replies Last Post
How to get free bytes on volume? AGS Coders. System 12 02 March 2016 16:58
Elysium by Magic Bytes CodyJarrett request.Old Rare Games 41 28 December 2011 18:33
WallStreet - Magic bytes dlfrsilver HOL contributions 0 20 September 2008 23:37
0 bytes ADF Files Bueller support.WinUAE 2 30 September 2005 13:50

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +2. The time now is 23:23.


Powered by vBulletin® Version 3.8.11
Copyright ©2000 - 2019, vBulletin Solutions Inc.
Page generated in 0.06608 seconds with 13 queries