[Oberon] Fw: FPGA - Bitmaps.Mod
Tomas Kral
thomas.kral at email.cz
Fri Apr 7 14:31:28 CEST 2017
Hi Joerg,
Thank you, trying to follow your guidance, while adhering ETH Bitmaps
style, I recoded as follows.
Good news it compiles, but I am not sure if it is good for the
collector, also I wish the code be didactic and easy to follow.
What do you think?
Thanks you.
Tomas
MODULE Bitmaps; (*TK 2017*)
IMPORT SYSTEM, Kernel, Display;
TYPE
Base = POINTER TO BaseDesc;
BaseDesc = RECORD (*ARRAY OF BYTEs allocated by Kernel.New*) END;
Bitmap* = POINTER TO BitmapDesc;
BitmapDesc* = RECORD
width*, height*, depth*: INTEGER;
base*: Base;
size*: INTEGER
END;
PROCEDURE New*(W, H, Dpt: INTEGER) : Bitmap;
VAR b: Bitmap;
BEGIN
NEW(b);
IF b # NIL THEN
b.width := W; b.height := H; b.depth := Dpt;
b.size := (W+7) DIV 8 * H; (*nbr of bytes*)
Kernel.New(SYSTEM.VAL(INTEGER, b.base), b.size);
IF b.base = NIL THEN b := NIL END
END
RETURN b END New;
END Bitmaps.
On Fri, 7 Apr 2017 14:10:31 +0200
Jörg <joerg.straube at iaeth.ch> wrote:
> No.
>
> The first parameter is declared VAR, so the address of "b.base" is
> handed over. The second parameter shall be a pointer to a type tag.
> The size of a type is stored at offset 0 of the type tag.
>
> Kernel.New expects the parameter "tag" to be a pointer to type tag.
> SYSTEM.ADR(b.size) is interpreted as a pointer to a type tag.
>
> The code I was providing is not something a beginner in Oberon should
> use! 1) It's dirty pointer hacking, something that normally C is
> famous for :-) 2) it's very low level, as it bases on internals of
> the implementation of the Oberon memory management.
>
> But there are typos in my code
> - Firstly, you have to IMPORT SYSTEM as well.
> - Secondly, we have to compare "b.base" to 0 iso NIL, as "b.base" is
> not a pointer.
>
> br
> Jörg
>
> -----Original Message-----
> From: Oberon [mailto:oberon-bounces at lists.inf.ethz.ch] On Behalf Of
> Tomas Kral Sent: Freitag, 7. April 2017 12:55
> To: oberon at lists.inf.ethz.ch
> Subject: Re: [Oberon] Fw: FPGA - Bitmaps.Mod
>
> Hi Joerg,
>
> Should it not be coded rather like this?
> Kernel.New(SYSTEM.ADR(b.base), b.size);
>
> On Fri, 7 Apr 2017 11:43:45 +0200
> Jörg <joerg.straube at iaeth.ch> wrote:
>
> > Kernel.New(b.base, SYSTEM.ADR(b.size));
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related
> systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
>
> --
> Oberon at lists.inf.ethz.ch mailing list for ETH Oberon and related
> systems https://lists.inf.ethz.ch/mailman/listinfo/oberon
More information about the Oberon
mailing list