----boundary-LibPST-iamunique-1405274588_-_-
Content-type: text/plain
Wojtek Skulski wrote
>"My more immediate concern is how to make assignments of bit patterns
>such as 0ABH to a variable of a given bit width. These variables are
>directly mapped onto C-style DLL variables like UCHAR or USHORT.
>I have spent considerable time reading C-headers and trying to match
>these to variable types CP is giving me. The interesting part is
>C structures and pointers to C structures.
>Unless I am missing some part of the BlackBox docu, it seems to me
>they have basically left this whole topic away. There is a page
>about DLLs, but practical details are scarce.
>In the past, every compiler vendow would have documented the bit
>layout of their variables. This would make interfacing between
>say Fortran and C doable. The BB documentatin does not say much
>how their variables are laid out in memory. This becomes a critical
>issue once I want to talk to an embedded 8051 microcontroller."
The BB documentation addresses variable layout in memory and on disk
in the language reference and Stores Docus. The mapping of memory bit
numbers to (eg) INTEGERs is not documented as it might be platform
specific.
However bit 5 in a set is bit 5 whatever platform is used. It is an
open secret that on PC's bit 0 is the LSB. What I gues you want to do
is to set (and process) your bits using the SET abstraction, then map them
to BYTEs using SYSTEM.VAL in a potentially platform specific way. (Maybe
some SHORTs are also needed.)
The example below uses this kind of approach to compute a file checksum
using a 32 bit irreducible polynominal over Galois Field 2 - sounds fancy
but is simple bit bashing. Setting the bit patterns using the SET
abstraction is easy; as is converting in and out of INTEGER when required.
PROCEDURE CheckFile (loc : Files.Locator; fInfo : Files.FileInfo) : INTEGER;
CONST
fDatSiz = 102400 * 2;
mask = {0, 1, 27, 28};
lowByte = {0 .. 7};
VAR
i : INTEGER;
fIn : Files.File;
rd : Files.Reader;
fData : ARRAY fDatSiz OF BYTE;
cSum : SET;
BEGIN
IF ~zpr.cSum OR (fInfo.length > fDatSiz) THEN RETURN 0 END;
fIn := dir.Old (loc, fInfo.name, TRUE);
IF fIn = NIL THEN RETURN 0 END;
ASSERT (fIn.Length () = fInfo.length, 65);
rd := fIn.NewReader (rd);
rd.ReadBytes (fData, 0, fInfo.length); INC (xCnt, fInfo.length);
cSum := {0};
FOR i := 0 TO fInfo.length - 1 DO
cSum := cSum / (SYSTEM.VAL (SET, fData [i]) * lowByte);
IF 31 IN cSum THEN
cSum := SYSTEM.LSH (cSum, 1);
cSum := cSum / mask
ELSE
cSum := SYSTEM.LSH (cSum, 1)
END
END;
fIn.Close ();
RETURN SYSTEM.VAL (INTEGER, cSum)
END CheckFile;
Regards
Robert Campbell
--------------------------------------------
To unsubscribe from this mailing list, send a message containing the word "unsubscribe" to:
blackbox-request{([at]})nowhere.xy
To get a list of valid e-mail commands and instructions on their usage, send a message containing the word "help" to the above address.
Send any problem reports or questions related to this email list to the list owner at
owner-blackbox{([at]})nowhere.xy
Current posting policy:
a) To post you should use the same address by which you are subscribed to the mailing list. That way, the list server will recognize you as subscriber and forward your posting immediately, without creating any overhead.
b) If, for some reason, you cannot post from the address, by which you are subscribed, your message will be moderated to avoid spam. Please understand that moderation will often cause some delay, in particular over weekends or holydays.
----boundary-LibPST-iamunique-1405274588_-_-
Content-type: application/rtf
Content-transfer-encoding: base64
Content-Disposition: attachment; filename="rtf-body.rtf"
e1xydGYxXGFuc2lcYW5zaWNwZzEyNTJcZnJvbXRleHQgXGRlZmYwe1xmb250dGJsDQp7XGYwXGZz
d2lzcyBBcmlhbDt9DQp7XGYxXGZtb2Rlcm4gQ291cmllciBOZXc7fQ0Ke1xmMlxmbmlsXGZjaGFy
c2V0MiBTeW1ib2w7fQ0Ke1xmM1xmbW9kZXJuXGZjaGFyc2V0MCBDb3VyaWVyIE5ldzt9fQ0Ke1xj
b2xvcnRibFxyZWQwXGdyZWVuMFxibHVlMDtccmVkMFxncmVlbjBcYmx1ZTI1NTt9DQpcdWMxXHBh
cmRccGxhaW5cZGVmdGFiMzYwIFxmMFxmczIwIFxwYXINCldvanRlayBTa3Vsc2tpIHdyb3RlXHBh
cg0KXHBhcg0KPiJNeSBtb3JlIGltbWVkaWF0ZSBjb25jZXJuIGlzIGhvdyB0byBtYWtlIGFzc2ln
bm1lbnRzIG9mIGJpdCBwYXR0ZXJuc1xwYXINCj5zdWNoIGFzIDBBQkggdG8gYSB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