Code archives/Miscellaneous/PokeByteAdd / PokeByteSubtract

This code has been declared by its author to be Public Domain code.

Download source code

PokeByteAdd / PokeByteSubtract by _332008
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!
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

_332008
Test with this code:
bnkTest=CreateBank(4)

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

WaitKey()



Code Archives Forum