[Oberon] FPGA - Screen.Mod

Paul Reed paulreed at paddedcell.com
Sat Sep 16 11:38:38 CEST 2017

Hi Tomas,

> I am looking for `Screen.Mod' module (mainly its `Screen.Gr[a]b' command)
> hinted in PO2013 pictures. I have completed early version of
> `Bitmaps.Mod' supporting basic set of raster operations.

It's an interesting exercise.  The following is a routine I sent to Prof.
Wirth which I believe is what he used (I had it in System; it seems he
chose to put it in a separate module called Screen; you may want to add it
to your Bitmaps.Mod instead).  You should easily be able to change this to
your needs, e.g. whether you want white-on-black or black-on-white, or any
other colours for that matter...

With thanks to Florian Negele for the bit-reversal code!


MODULE System;

    VAR S: Texts.Scanner; F: Files.File; R: Files.Rider;
      x, y, a, bits: INTEGER;
  BEGIN GetArg(S);
    IF S.class = Texts.Name THEN
      Texts.WriteString(W, "System.Grab "); Texts.WriteString(W, S.s);
      Texts.Append(Oberon.Log, W.buf);
      F := Files.New(S.s);
      IF F # NIL THEN Files.Set(R, F, 0);
        (*Windows Bitmap File Header*)
        Files.Write(R, "B"); Files.Write(R, "M");
        Files.WriteInt(R, 14+40+8+128*768); (*file size*)
        Files.WriteInt(R, 0); (*reserved*)
        Files.WriteInt(R, 14+40+8); (*offset of bits*)
        (*Windows Bitmap WinHeader*)
        Files.WriteInt(R, 40); (*header size*)
        Files.WriteInt(R, 1024); Files.WriteInt(R, 768); (*w,h*)
        Files.WriteInt(R, 00010001H); (*planes, bpp*)
        Files.WriteInt(R, 0); (*no compression*)
        Files.WriteInt(R, 0); (*size of bitmap - can be 0 if uncompressed*)
        Files.WriteInt(R, 15000); Files.WriteInt(R, 15000); (*h&vres in ppm*)
        Files.WriteInt(R, 2); Files.WriteInt(R, 2); (*colours used,
        (*colour table*)
        Files.WriteInt(R, 0); Files.WriteInt(R, 0FFFFFFH); (*padded rgb*)
        a := Display.base;
        FOR y := 0 TO 767 DO
          FOR x := 0 TO 124 BY 4 DO
            SYSTEM.GET(a, bits); INC(a, 4);
            bits := SYSTEM.MSK(ROR(bits, 4), 00F0F0F0FH)
              + SYSTEM.MSK(ROR(bits, 28), 0F0F0F0F0H);
            bits := SYSTEM.MSK(ROR(bits, 2), 033333333H)
              + SYSTEM.MSK(ROR(bits, 30), 0CCCCCCCCH);
            bits := SYSTEM.MSK(ROR(bits, 1), 055555555H)
              + SYSTEM.MSK(ROR(bits, 31), 0AAAAAAAAH);
            Files.WriteInt(R, bits)
        Files.Register(F); Texts.WriteString(W, " done.")
      ELSE Texts.WriteString(W, " failed.")
  END Grab;

System.Grab Screen0.bmp

More information about the Oberon mailing list