Hallo All,
here an useful macro (but not my final version) to create tables of bits.
Usage is very simple:
<bittable tablename,numbits,ranges>
where
numbits *should* be a multiple of 8 and
ranges could be in the form "10->20" (ascending) or single numbers indicating the bit to set, like "10","27"
For example, to create a "valid" chars ascii table of 128 bits
bittable validascii,128,\
41h->5Ah,\ ;A-Z
30h->39h,\ ;0-9
20h,\ ;space
61h->7Ah,\ ;a-z
9,0Dh,0Ah ;tab,cr,lf
Here the macro
macro buildtable argtable,argstart,argend {
local posstart,posend
local initbyte,totalbits,bytestart
local part1,part3,tmpbyte
totalbits = argend - argstart +1
bytestart = argstart / 8
posstart = argstart mod 8
posend = argend mod 8
if totalbits < 9 & totalbits > 1
if posstart = 0 | posstart < posend
initbyte = 00000001b
repeat totalbits-1
initbyte = initbyte shl 1
initbyte = initbyte or 1
end repeat
repeat posstart
initbyte = initbyte shl 1
end repeat
initbyte = initbyte and 0FFh
load tmpbyte byte from argtable+bytestart
store (initbyte or tmpbyte) at argtable+bytestart
else
;display "/in 2 bytes/"
;data in 2 bytes 1<sum<9 bits
;---------first byte-------------
initbyte = 0FFh
repeat posstart
initbyte = initbyte shl 1
end repeat
load tmpbyte byte from argtable+bytestart
initbyte = initbyte and 0FFh
store (initbyte or tmpbyte) at argtable+bytestart
;---------second byte-------------
initbyte = 00000001b
repeat posend
initbyte = initbyte shl 1
initbyte = initbyte or 1
end repeat
load tmpbyte byte from argtable+bytestart+1
initbyte = initbyte and 0FFh
store (initbyte or tmpbyte) at argtable+bytestart+1
end if
else if totalbits = 1
;single bit
initbyte = 00000001b
repeat posstart
initbyte = initbyte shl 1
end repeat
load tmpbyte byte from argtable+bytestart
initbyte = initbyte and 0FFh
store byte (initbyte or tmpbyte) at argtable+bytestart
else
;-------------------variable bytes------------------
;----------------------------PART1
; store first bits
part1 = 0FFh
repeat posstart
part1 = part1 shl 1
end repeat
load tmpbyte byte from argtable+bytestart
part1 = part1 and 0FFh
store byte (part1 or tmpbyte) at argtable+bytestart
totalbits = totalbits - (8 - posstart)
;-----------------------------PART2
numbytes = totalbits / 8
if numbytes > 0
repeat numbytes
;store full byte
store byte 0FFh at argtable+bytestart+%
end repeat
totalbits = totalbits - (8 * numbytes)
end if
;-----------------------------PART3
if totalbits > 0
initbyte = 00000001b
;store last bits
repeat totalbits-1
initbyte = initbyte shl 1
initbyte = initbyte or 1
end repeat
load tmpbyte byte from argtable+bytestart+numbytes+1
initbyte = initbyte and 0FFh
store byte (initbyte or tmpbyte) at argtable+bytestart+numbytes+1
end if
end if
}
macro bittable argname,argbitmap,[argranges] {
common
argname:
db (argbitmap/8) dup (0)
forward
define status 0
match =0 p1->p2,status argranges \{
buildtable argname,p1,p2
define status 1
\}
match =0,status \{
buildtable argname,argranges,argranges
define status 1
\}
common
display "#------ Bittable generator --------x",13,10
display "| macro to create tables of bits |",13,10
display "| by hopcode[mrk] |",13,10
display "| Datum: 5/03/2009 |",13,10
display "x------- ------------------- ------x",13,10
display " ---------------------------------- ",13,10
display " - 7 6 5 4 3 2 1 0 -",13,10
display " ---------------------------------- ",13,10
repeat (argbitmap/8)
load a byte from argname+(%-1)
tmp = a
display " "
repeat 8
a = tmp and 10000000b
a = a shr 7
display_decimal a
display " "
tmp = tmp shl 1
end repeat
display " | "
display_decimal (%-1)*8
display 13,10
end repeat
}
;------usage-------------------
bittable varbyte,128,\
30h->39h,\ ;0-9
41h->5Ah,\ ;A-Z
61h->7Ah,\ ;a-z
20h,9,0Dh,0Ah ;space,tab,cr,lf
;------------------------------
Hope it will be useful.
Enjoy,
hopcode