Skip to content

Instantly share code, notes, and snippets.

@exelotl
Created October 27, 2019 13:44
Show Gist options
  • Save exelotl/0b50b4465daa4eb22035bbce507ab18c to your computer and use it in GitHub Desktop.
Save exelotl/0b50b4465daa4eb22035bbce507ab18c to your computer and use it in GitHub Desktop.
type PalUsage = distinct uint32
proc objIndex(u:var PalUsage): int = ((u.uint32 and 0x0000000fu32) shr 0).int
proc objCount(u:var PalUsage): int = ((u.uint32 and 0x0000fff0u32) shr 4).int
proc bgIndex(u:var PalUsage): int = ((u.uint32 and 0x000f0000u32) shr 16).int
proc bgCount(u:var PalUsage): int = ((u.uint32 and 0xfff00000u32) shr 20).int
proc `objIndex=`(u:var PalUsage, v:int) = u = ((v.uint32 shl 0) or (u.uint32 and not 0x0000000fu32)).PalUsage
proc `objCount=`(u:var PalUsage, v:int) = u = ((v.uint32 shl 4) or (u.uint32 and not 0x0000fff0u32)).PalUsage
proc `bgIndex=`(u:var PalUsage, v:int) = u = ((v.uint32 shl 16) or (u.uint32 and not 0x000f0000u32)).PalUsage
proc `bgCount=`(u:var PalUsage, v:int) = u = ((v.uint32 shl 20) or (u.uint32 and not 0xfff00000u32)).PalUsage
var p:PalUsage
p.objCount = 1
p.objCount = p.objCount + 1 # works
p.objCount += 1 # error
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment