Page 1 of 1

Display AutoCad Slides on a Nokia 6610 LCD display

Posted: Sat Jun 16, 2012 7:13 am
by cfbsoftware
This is the source code of the LPC1766 Cortex-M3 version of the Oberon program shown in the YouTube video:

http://www.youtube.com/watch?v=qmSqhAG_ea0

Code: Select all

MODULE SlideDemo;
(* =========================================================================  
   Main Program for AutoCad Slide Demo
  
   Target: Hardware-independent
   
   (c) 2009-2012 CFB Software   
   http://www.astrobe.com  
   
   ========================================================================= *)

IMPORT MCU, SYSTEM, Slide, Main, Timer, StPauls, Columbia;

PROCEDURE Run;
BEGIN
  WHILE TRUE DO
    Slide.Display("StPauls", 0);
    Timer.MSecDelay(1000);
    Slide.Display("Columbia", 0);
    Timer.MSecDelay(1000);
    Slide.Display("StPauls", 5);
    Timer.MSecDelay(1000);
    Slide.Display("Columbia", 5);
    Timer.MSecDelay(1000)
  END 
END Run;

BEGIN
  Run()
END SlideDemo.
Slide.mod:

Code: Select all

MODULE Slide;
(* =========================================================================  
   Display an AutoCad Slide-format File 
  
   Target: Hardware-independent
   
   (c) 2009-2012 CFB Software   
   http://www.astrobe.com  
   
   ========================================================================= *)

  IMPORT Graph, IO, Out, Timer;

  CONST
    offset    = 0FBX; (* -5 *)
    endfile   = 0FCX; (* -4 *)
    endPoint  = 0FEX; (* -2 *)
    newColour = 0FFX; (* -1 *)

  VAR
    c: CHAR;
    colour: INTEGER;
    scaleFactor*: INTEGER;
    zoom: INTEGER;
    hX, hY: INTEGER;
    panX, panY: INTEGER;
    
  PROCEDURE* XScale (x: INTEGER): INTEGER;
  BEGIN
    RETURN (x * zoom DIV scaleFactor) - panX
  END XScale;

  PROCEDURE* YScale (y: INTEGER): INTEGER;
  BEGIN
    RETURN Graph.MaxY - ((y * zoom DIV scaleFactor) - panY)
  END YScale;

  PROCEDURE Draw(zoomm, zoomd, px, py, delay: INTEGER);
  VAR
    drawLine: BOOLEAN;
    end1, end2, fromX, fromY: INTEGER;
    i, count: INTEGER;
    lastX, lastY: INTEGER;
    offset1, offset2, offset3, offset4: INTEGER;
    toX, toY: INTEGER;
  BEGIN
    Graph.Init;
    IO.Reset();
    IO.ReadHeader(hX, hY);
    IF hX > hY THEN 
      scaleFactor := (hX DIV zoomm); zoom := zoomd * Graph.MaxX 
    ELSE 
      scaleFactor := (hY DIV zoomm); zoom := zoomd * Graph.MaxY 
    END;
    panX := px;
    panY := py;
    c := IO.ReadType();
    lastX := 0;
    lastY := 0;
    i := 0;
    count := 0;
    REPEAT
      drawLine := TRUE;
      IF c = offset THEN 
          IO.GetOffset(offset1, offset2, offset3, offset4);
          fromX := lastX + offset1;
          fromY := lastY + offset2;
          toX := lastX + offset3;
          toY := lastY + offset4;
          lastX := fromX;
          lastY := fromY;
      ELSIF c = endPoint THEN 
          fromX := lastX;
          fromY := lastY;
          IO.GetEndpoint(end1, end2);
          toX := lastX + end1;
          toY := lastY + end2;
          lastX := toX;
          lastY := toY;
      ELSIF c = newColour THEN 
          colour := IO.GetColour();
          drawLine := FALSE
      ELSE
          IO.GetVector(fromX, fromY, toX, toY);
          lastX := fromX;
          lastY := fromY
      END;
      IF drawLine THEN
        Graph.Line(XScale(fromX), YScale(fromY), XScale(toX), YScale(toY), colour);
        IF delay > 0 THEN Timer.MSecDelay(delay) END;
      END;
      c := IO.ReadType();
      INC(count)
    UNTIL (c = endfile)
  END Draw;

  PROCEDURE Display*(name: ARRAY OF CHAR; delay: INTEGER);
  BEGIN
     IF IO.Open(name) THEN
      Draw(1, 1, 0, -40, delay)
    ELSE
      Out.String("name "); Out.String("not found"); Out.Ln
    END 
  END Display;

END Slide.
Graph.mod:

Code: Select all

(* =========================================================================  
   Map Slide Functions onto Astrobe Library functions

   Target: Hardware-independent
  
   (c) 2009-2012 CFB Software   
   http://www.astrobe.com  
   
   ========================================================================= *)

MODULE Graph;

IMPORT LCD := LCDEpson, Graphics;

CONST
  size = 10;
  whiteOnBlack* = TRUE;
  MaxX* = LCD.MaxX;
  MaxY* = LCD.MaxY;

VAR
  highX*, highY*: INTEGER;
  colourMap: ARRAY 9 OF INTEGER;
  lastFromX, lastFromY, lastToX, lastToY, lastColour: INTEGER;

PROCEDURE Init*;
VAR
  i: INTEGER;
BEGIN
  (* AutoCad colours are numbered differently to adapter colours. *)
  (* The colourMap array is used for conversion.                  *)
  colourMap[1] := LCD.Red;
  colourMap[2] := LCD.Yellow;
  colourMap[3] := LCD.Green;
  colourMap[4] := LCD.Cyan;
  colourMap[5] := LCD.Blue;
  colourMap[6] := LCD.Magenta;
  IF whiteOnBlack THEN
  	colourMap[7] := LCD.White;
  	colourMap[8] := LCD.Black
  ELSE
  	colourMap[7] := LCD.Black;
  	colourMap[8] := LCD.White
  END;

(*  FOR i := 0 TO LEN(colourMap) - 1 DO colourMap[i] := LCD.Black END; *)
  highX := LCD.MaxX;
  highY := LCD.MaxY;
  lastFromX := -1;
  lastFromY := -1;
  lastToX := -1;
  lastToY := -1;
  lastColour := -1;
  LCD.Init;
  Graphics.Init(LCD.MaxX, LCD.MaxY, LCD.DrawDot)
END Init;

PROCEDURE Line*(fromX, fromY, toX, toY: INTEGER; colour: INTEGER);
BEGIN
  IF (lastFromX # fromX) OR (lastFromY # fromY) OR (lastToX # toX) OR (lastToY # toY) OR (lastColour # colour) THEN 
    Graphics.Line(colourMap[colour], fromX, fromY, toX, toY);
    lastFromX := fromX; 
    lastFromY := fromY; 
    lastToX := toX; 
    lastToY := toY; 
    lastColour := colour
  END 
END Line;

END Graph.
IO.def

Code: Select all

DEFINITION MODULE IO;

  PROCEDURE ReadByte*(): INTEGER;

	PROCEDURE ReadType* (): CHAR;

  PROCEDURE GetOffset* (VAR o1, o2, o3, o4: INTEGER);

	PROCEDURE GetColour* (): INTEGER;

	PROCEDURE GetEndpoint* (VAR end1, end2: INTEGER);

	PROCEDURE Get2Vector* (VAR v1, v2: INTEGER);

	PROCEDURE GetVector* (VAR v1, v2, v3, v4: INTEGER);

	PROCEDURE ReadHeader* (VAR highX, highY: INTEGER);

  PROCEDURE Reset*;
  
  PROCEDURE Open*(name: ARRAY OF CHAR): BOOLEAN;

END IO.
Graphics.def

Code: Select all

DEFINITION MODULE Graphics; 

TYPE 
  DrawDotProc* = PROCEDURE (colour, x, y: INTEGER);

PROCEDURE Line*(colour, x0, y0, x1, y1: INTEGER);

PROCEDURE Circle*(colour, x0, y0, r: INTEGER);

PROCEDURE Ellipse*(colour, x0, y0, a, b: INTEGER);

PROCEDURE Init*(maxX, maxY: INTEGER; dd: DrawDotProc);

END Graphics.
LCDEpson.def:

Code: Select all

DEFINITION MODULE LCDEpson;
(* =========================================================================  
   Example ARM Oberon Module  
 
   Description:
     Epson S1D15G00 LCD Controller Driver for 132x132 LCD Nokia-type display

   Target:
     LPC17xx systems
     
   Tested on: 
     Olimex LPC1766-STK Development Prototype Board
   
   Reference:
     Seiko Epson S1D15G00 Series DataSheet Rev 1.0 2001.
     
   (c) 2009-2012 CFB Software
   http://www.astrobe.com
   
   ========================================================================= *)
IMPORT Timer, MCU, ResData, SPI, SYSTEM;

CONST 
  (* 12-bit color definitions *)
  White*   = 0FFFH;
  Black*   = 0000H;
  Red*     = 0F00H;
  Green*   = 00F0H;
  Blue*    = 000FH;
  Cyan*    = 00FFH;
  Magenta* = 0F0FH;
  Yellow*  = 0FF0H;
  Brown*   = 0B22H;
  Orange*  = 0FA0H;
  Pink*    = 0F6AH;
  
  MaxX* = 131;
  MaxY* = 131;
  
  (* 8 x 10 font *)
  MaxCol* = MaxX DIV 8;
  MaxRow* = MaxY DIV 10;

  PROCEDURE LoadFont*(name: ARRAY OF CHAR): BOOLEAN;

 (* ************************************************************************************* *)
 (* Draws two dots in the specified color at the specified x and y coordinates *)
 (* color = 12-bit color value xxxxrrrrggggbbbb *)
 (* 0000 colour is off, 1111 colour is full on *)
  PROCEDURE DrawDot*(colour, x, y: INTEGER);

  PROCEDURE FillRectangle*(colour, x1, y1, x2, y2: INTEGER);

  PROCEDURE DrawChar*(colour: INTEGER; ch: CHAR; x1, y1: INTEGER);

  PROCEDURE ClearScreen*(Colour: INTEGER);
  
  PROCEDURE Init*;
  
END LCDEpson.