Ooops
November 28, 2020, 11:14:49 AM

Author Topic: [bb] PokeByteAdd / PokeByteSubtract by _33 [ 1+ years ago ]  (Read 408 times)

Offline BlitzBot

  • Jr. Member
  • **
  • Posts: 1
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
  1. Function PokeByteAdd(address%, disp%, value%, bind = True)
  2.         Local byte% = PeekByte(address, disp) + value
  3.         If bind = True Then
  4.                 If byte > 255 Then byte = 255
  5.         EndIf
  6.         PokeByte (address, disp, byte)
  7. End Function
  8.  
  9. Function PokeByteSubtract(address%, disp%, value%, bind = True)
  10.         Local byte% = PeekByte(address, disp) - value
  11.         If bind = True Then
  12.                 If byte < 0 Then byte = 0
  13.         EndIf
  14.         PokeByte (address, disp, byte)
  15. End Function


Comments :


_33(Posted 1+ years ago)

 Test with this code:
Code: [Select]
bnkTest=CreateBank(4)

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

WaitKey()


 

SimplePortal 2.3.6 © 2008-2014, SimplePortal