[bb] PokeByteAdd / PokeByteSubtract by _33 [ 1+ years ago ]

Started by BlitzBot, June 29, 2017, 00:28:40

Previous topic - Next topic

BlitzBot

Title : PokeByteAdd / PokeByteSubtract
Author : _33
Posted : 1+ years ago

Description : I wanted to have functions to perform math operations on values in banks, and found this way to do it.  They are practical little functions (in my book).

Oh, and if yuo have a faster way of doing the same thing on a bank, give me a shout!


Code :
Code (blitzbasic) Select
Function PokeByteAdd(address%, disp%, value%, bind = True)
Local byte% = PeekByte(address, disp) + value
If bind = True Then
If byte > 255 Then byte = 255
EndIf
PokeByte (address, disp, byte)
End Function

Function PokeByteSubtract(address%, disp%, value%, bind = True)
Local byte% = PeekByte(address, disp) - value
If bind = True Then
If byte < 0 Then byte = 0
EndIf
PokeByte (address, disp, byte)
End Function


Comments :


_33(Posted 1+ years ago)

 Test with this code:
bnkTest=CreateBank(4)

PokeByte (bnkTest,0,100)
PokeByteSubtract (bnkTest,0,1)
Print PeekByte(bnkTest,0)
FreeBank bnkTest

WaitKey()