How to toggle or set single bits in pmem from gpc
1 post
• Page 1 of 1
How to toggle or set single bits in pmem from gpc
This is an example of how to toggle or set a single pmem bit from your gpc code.
Not sure if this has been posted anywhere but I could not find a good example.
Attribution:
Scachi provided the BT_Toggle macro and I provided the BT_SET macro.
Search "singlebit" in the online resources to download the demo file.
Not sure if this has been posted anywhere but I could not find a good example.
Attribution:
Scachi provided the BT_Toggle macro and I provided the BT_SET macro.
Search "singlebit" in the online resources to download the demo file.
- Code: Select all
#pragma METAINFO("SINGLE BIT SET / TOGGLE", 1, 1, "USER101")
/* Interactive Configuration
<cfgdesc>
[BYTE OFFSET 0:]
shortdesc = <b>BIT 0:</b>
byteoffset = 0
bitsize = 1
bitoffset = 0
control = checkbox
default = 0
item = Enable
[TEST 1:]
group = 1
shortdesc = <b>BIT 1:</b>
byteoffset = 0
bitsize = 1
bitoffset = 1
control = checkbox
default = 0
item = Enable
[TEST 2:]
group = 1
shortdesc = <b>BIT 2:</b>
byteoffset = 0
bitsize = 1
bitoffset = 2
control = checkbox
default = 0
item = Enable
[TEST 3:]
group = 1
shortdesc = <b>BIT 3:</b>
byteoffset = 0
bitsize = 1
bitoffset = 3
control = checkbox
default = 0
item = Enable
[TEST 4:]
group = 1
shortdesc = <b>BIT 4:</b>
byteoffset = 0
bitsize = 1
bitoffset = 4
control = checkbox
default = 0
item = Enable
[TEST 5:]
group = 1
shortdesc = <b>BIT 5:</b>
byteoffset = 0
bitsize = 1
bitoffset = 5
control = checkbox
default = 0
item = Enable
[TEST 6:]
group = 1
shortdesc = <b>BIT 6:</b>
byteoffset = 0
bitsize = 1
bitoffset = 6
control = checkbox
default = 0
item = Enable
[TEST 7:]
group = 1
shortdesc = <b>BIT 7:</b>
byteoffset = 0
bitsize = 1
bitoffset = 7
control = checkbox
default = 0
item = Enable
</cfgdesc>
******************/
// TESTING TO SET OR TOGGLE SINGLE BIT IN PMEM //
#define BT_Toggle(_x,_y) (_x ^= 1<<_y)
#define BT_SET(number,n,x) (number ^= (-x ^ number) & (1UL << n))
init {
pmem_load();
}
main {
if (event_active(BUTTON_10)) BitToggle(0,6); //toggle bit 6
if (event_active(BUTTON_11)) BitToggle(0,7); //toggle bit 7
if (event_active(BUTTON_13)) BitSet(0,1,1); //set bit 1 to true
if (event_active(BUTTON_12)) BitSet(0,1,0); //set bit 1 to false
}
combo Save_Write{
wait(500);
pmem_save();
wait(0);
printf("GCMD:InteractiveConfiguration.Refresh");
wait(0);
}
void BitToggle(uint8 ByteOffset, uint8 BitOffset){
uint8 myByte;
pmem_read(ByteOffset,&myByte);
BT_Toggle(myByte,BitOffset);
set_pvar(ByteOffset,myByte);
}
void BitSet(uint8 ByteOffset, uint8 BitOffset, uint8 Bit){
uint8 myByte;
pmem_read(ByteOffset,&myByte);
BT_SET(myByte,BitOffset,Bit);
set_pvar(ByteOffset,myByte);
}
void set_pvar(uint8 idx, uint8 val){
pmem_write(idx, val);
combo_run(Save_Write);
}
-
USER101 - Sergeant Major
- Posts: 100
- Joined: Mon Dec 03, 2018 5:45 pm
1 post
• Page 1 of 1
Return to User's Script Documentation
Who is online
Users browsing this forum: No registered users and 76 guests