Site hosted by Angelfire.com: Build your free website today!
NaN Title

; --===========================================================================--
; 32 Boolean Flags in 4 bytes.
;
; 05.09.01
; Written by NaN (c)
; (Jaymeson@hotmail.com)
; --===========================================================================--
;
; These four macro's are designed to free up wasted memory for every
; time a boolean flag is defined using a BYTE, WORD, or DWORD.  The
; method is very simple.  There are four macros to help do this:
;
; SETBIT  -  Sets (1) bits (1,2,3,..,32) individually.  On the first
;            ocourance of this macro, a 'DATA DWORD ?' is defined
;            automatically, and added into the Data Segment, this
;            variable will house the 32 global flags for your programs.
;
; CLEARBIT - Clears (0) bits (1,2,3,..,32) individually.  This is the 
;            opposite of SETBIT and has not other feature than this.
;
; IF_FLAGGED - This is to be treated as a normal conditionall such
;              as ".if (eax==1)", and hence this macro REQUIRES a
;              ".endif" or compile errors will result.  The condition
;              tests if bit (1,2,3,...,32) is set to (1).
;
; IF_NOT_FLAGGED - This is the opposite to IF_FLAGGED as also requires
;                  an ".endif" for proper usage.  It tests if bit
;                  (1,2,3,..,32) is set to (0). 
;
; NOTE: I have not added equates to this macro list, as they are optional,
;       but i do recomend them.  They make defining unique flag names easier.
;       For example:
;
;       BIT1  equ 00000001H
;       BIT2  equ 00000002H
;       BIT3  equ 00000004H
;       BIT4  equ 00000008H
;       BIT5  equ 00000010H
;       ....
;       BIT32 equ 80000000H
;
; Now by simply including the macros and these equates in your program, a flag
; can be defined quickly and with meaning.  Here is a full example of all 
; macros:
;
; Found_32 equ BIT1
; Hidden   equ BIT2
; IsOn     equ BIT3
;
; .code
;    ...
;    SETBIT IsOn                               ; Initially set IsOn == 1
;
;    invoke Something
;    .if (eax)
;       SETBIT Found_32                        ; Set Found_32 on return true
;     .endif
;     
;     IF_FLAGGED Found_32
;        CLEARBIT IsOn                         ; Clear IsOn if Found_32 is set 
;     .endif
;     
;     IF_NOT_FLAGGED IsOn
;         invoke TerminateProcess, hWnd, 0     ; End process if IsOn is cleared
;     .endif
;     ... 
; --===========================================================================--

    SETBIT MACRO data:REQ
       ifndef __DATAFLAGS__
          __DATAFLAGS__ equ 1
          .data?
             DATA dd ?
          .code
          mov DATA, 0
       endif
       or DATA, data
     ENDM

; --===========================================================================--
     
     CLEARBIT MACRO data:REQ
        push eax
        mov eax, data
        not eax
        and DATA, eax
        pop eax
     ENDM

; --===========================================================================--
     
     IF_FLAGGED MACRO bit:REQ
        mov eax, bit
        .if ( eax & DATA )
     ENDM     

; --===========================================================================--

     IF_NOT_FLAGGED MACRO bit:REQ
        mov eax, bit
        .if !( eax & DATA )
     ENDM     
     
; --======================================================= Happy Coding NaN ==--

Go Back?