home *** CD-ROM | disk | FTP | other *** search
/ Club Amiga de Montreal - CAM / CAM_CD_1.iso / files / 148.lha / AsciiTable / ASCTable.c < prev    next >
C/C++ Source or Header  |  1980-11-15  |  4KB  |  152 lines

  1. /* Simple ASCII Table hack I did while avoiding work */
  2. /* \251 (c) A. Caleb Gattegno, this is freely redistributable and all that
  3.  * stuff.
  4.  * Notes:   Written with Manx 3.40a
  5.  * Warnings:  This program is not at all smart.  In fact it might be called
  6.  *     brain damaged.  What I mean is that I have a feeling it won't look at
  7.  *    all pretty if you are not using a standard font.  I don't think it will
  8.  *    eat your computer, but as this is a "hack I did while avoiding work"
  9.  *    I'm not gonna worry about it too much.  Eventually, I'll make this
  10.  *    resizable, and allow for custom fonts, but not until I get my current
  11.  *    jobs done.  In other words, expect more out of me NOT RSN! }:->
  12.  *    Aside from that, enjoy this for what it is.
  13.  * Requests:  As I do plan on doing more with this, up to and including, having
  14.  *    this be a part of my eventual text editor, please don't go around
  15.  *    making changes/additions to the source and u/ling it.  Feel free to
  16.  *    use this code for education, though I don't thinks it's worth much on
  17.  *    that line, and for your own toying, but PLEASE don't put any "new and
  18.  *    improved" versions on the nets as I might get confused :-(
  19.  *
  20.  * In any case, enjoy and happy ASCIIing!  ACG   7-23-88
  21.  * CI$ UID: 76164,3006   "Can be found" haunting AMIGATECH
  22. */
  23. #include <exec/types.h>
  24. #include <exec/execbase.h>
  25. #include <graphics/gfxbase.h>
  26. #include <intuition/intuition.h>
  27. #include "DecHexTables.h"
  28.  
  29. IMPORT struct ExecBase *SysBase;
  30.  
  31. struct GfxBase *GfxBase = NULL;
  32. struct IntuitionBase *IntuitionBase = NULL;
  33.  
  34. struct Window *Window = NULL;
  35. struct RastPort *RP;
  36.  
  37. UBYTE ASCIITop;
  38.  
  39. main()
  40. {
  41.     VOID Wait(), ReplyMsg(), *OpenLibrary(), *OpenWindow();
  42.     struct NewWindow nw;
  43.     struct IntuiMessage *msg, *GetMsg();
  44.     
  45.     if (!(GfxBase = OpenLibrary("graphics.library", 0))) CleanUp(101);
  46.     if (!(IntuitionBase = OpenLibrary("intuition.library", 0)))
  47.         CleanUp(102);
  48.     
  49.     nw.LeftEdge = 460;
  50.     nw.TopEdge = 10;
  51.     nw.Width = 176;
  52.     nw.Height = 140;
  53.     nw.DetailPen = -1;
  54.     nw.BlockPen = -1;
  55.     nw.IDCMPFlags = CLOSEWINDOW | RAWKEY | REFRESHWINDOW;
  56.     nw.Flags = WINDOWCLOSE | WINDOWDRAG | WINDOWDEPTH | SIMPLE_REFRESH;
  57.     nw.FirstGadget = NULL;
  58.     nw.CheckMark = NULL;
  59.     nw.Title = "ASCII Table";
  60.     nw.Screen = NULL;
  61.     nw.BitMap = NULL;
  62.     nw.MinWidth = 0;
  63.     nw.MinHeight = 0;
  64.     nw.MaxWidth = 176;
  65.     nw.MaxHeight = 150;
  66.     nw.Type = WBENCHSCREEN;
  67.     
  68.     if (!(Window = OpenWindow(&nw))) CleanUp(201);
  69.     RP = Window->RPort;
  70.     SetAPen(RP, 1);
  71.     SetBPen(RP, 0);
  72.     SetDrMd(RP, JAM2);
  73.  
  74.     ASCIITop = 0;
  75.     ListASCII();
  76.     FOREVER {
  77.         Wait(1 << Window->UserPort->mp_SigBit);
  78.         
  79.         while (msg = GetMsg(Window->UserPort)) {
  80.             ULONG class;
  81.             UWORD code;
  82.             
  83.             class = msg->Class;
  84.             code = msg->Code;
  85.             
  86.             ReplyMsg(msg);
  87.             
  88.             switch (class) {
  89.             case REFRESHWINDOW:
  90.                 ListASCII();
  91.                 break;
  92.             case CLOSEWINDOW:
  93.                 CleanUp(0);
  94.                 break;
  95.             case RAWKEY:
  96.                 if (code == 0x4c) { /* Up Arrow */
  97.                     if (ASCIITop)
  98.                         ASCIITop -= 32;
  99.                     else
  100.                         ASCIITop = 224;
  101.                     ListASCII();
  102.                 } else if (code == 0x4d) { /* Down Arrow */
  103.                     if (ASCIITop == 224)
  104.                         ASCIITop = 0;
  105.                     else
  106.                         ASCIITop += 32;
  107.                     ListASCII();
  108.                 }
  109.                 break;
  110.             } /* switch */
  111.         } /* while */
  112.     } /* FOREVER */
  113. }
  114.  
  115. ListASCII()
  116. {
  117.     REGISTER UBYTE i, j;
  118.     UBYTE c;
  119.     
  120.     Move(RP, 88, 10);
  121.     Draw(RP, 88, 148);
  122.     for (i = 16, j = ASCIITop; i < 144; i += 8, j++) {
  123.         Move(RP, 8, i);
  124.         Text(RP, Decimal[j], 3);
  125.         Move(RP, 40, i);
  126.         Text(RP, Hex[j], 3);
  127.         c = j;
  128.         Move(RP, 72, i);
  129.         Text(RP, &c, 1);
  130.         
  131.         Move(RP, 96, i);
  132.         Text(RP, Decimal[j + 16], 3);
  133.         Move(RP, 128, i);
  134.         Text(RP, Hex[j + 16], 3);
  135.         c = j + 16;
  136.         Move(RP, 160, i);
  137.         Text(RP, &c, 1);
  138.     }
  139. }
  140.  
  141. CleanUp(errcode)
  142. ULONG errcode;
  143. {
  144.     VOID CloseWindow(), CloseLibrary();
  145.     
  146.     if (Window) CloseWindow(Window);
  147.     if (IntuitionBase) CloseLibrary(IntuitionBase);
  148.     if (GfxBase) CloseLibrary(GfxBase);
  149.     
  150.     exit(errcode);
  151. }
  152.