home *** CD-ROM | disk | FTP | other *** search
- /*
-
- CPU.c - program to write current CPUs in use to stdout
-
- Ethan Dicks
- based upon WhatCPU by Dave Haynie
-
- Version 2.1
- (c) 26-Feb-1990
-
- This program is *not* in the public domain, but may be freely
- redistributed on the condition that it is not sold, nor used in any
- commercial or shareware package without the express written permission
- of the author. This program may be included in a freely redistributable
- library, including, but not limited to the Fred Fish library collection.
- In other words, selling this program is right out, but giving it away is
- encouraged.
-
- This program is an example of a standalone C module. As of March 1989,
- one of the discussions on comp.sys.amiga has been regarding writing C
- without linking in startup code, such as AStartup.obj or c.o, and without
- linking in libraries, such as Amiga.lib. This program is one example. It
- is, however, bizarre, due to several shortcuts to shrink the size. There
- have been many odd techniques used to cut corners, including assumptions
- about the content of the output, strange char array manipulation, and
- unusual register defines. While the program could be clearer, it probably
- can't be made smaller. The purpose of this program is not to be a good
- example, but, rather, to be an example of TIGHT C code.
-
- COMPILATION INSTRUCTIONS:
-
- This code has been tested under Lattice 5.04, but will probably compile
- under Lattice 4.x as well.
-
- To compile, either use LMK and the provided Makefile, or use the commands:
-
- lc -b -r -v -y CPU.c
- blink CPU.o to CPU SC SD ND
- */
-
- #include <exec/types.h>
- #include <exec/execbase.h>
- #include <libraries/dos.h>
- #include <proto/exec.h>
- #include <proto/dos.h>
- /* This is all there is */
-
-
- /* Define the processor type strings */
- char banner[] = "System Configuration: 680";
- char id_68000[] = "00";
- char id_68010[] = "10";
- char id_68020[] = "20";
-
- char id_68881[] = "68881";
-
- char crlf[] = "\n";
-
- /* Here goes nuthin... */
- void _main()
- {
-
- /* set up Intuition/AmigaDOS structure pointers */
- struct DOSBase *DOSBase;
- struct ExecBase **SysBase;
- register struct ExecBase *ExecBase;
-
- /* define other variables as registers, to save space */
- register int attnflag; /* processor type bits from ExecBase struct */
- register ULONG stdout; /* file handle of stdout */
- register char *proc; /* pointer to processor type string */
-
- /* Set up the ExecBase pointer manually, since we don't link with anybody */
- SysBase = (struct ExecBase **) (4L);
- ExecBase = *SysBase;
-
- /* Open the DOS library, since there is no one to do it for us */
- DOSBase = (struct DOSBase *)OpenLibrary(DOSNAME, 0);
-
- /* Get the stdout filehandle */
- stdout = Output();
-
- /* Start printing */
- Write(stdout, banner, sizeof(banner));
-
- /* Only read the ExecBase structure once, to save space */
- attnflag = ExecBase -> AttnFlags;
-
- if (attnflag & AFF_68020)
- {
- proc = id_68020; /* point to string "20" */
- }
- else
- {
- if (attnflag & AFF_68010)
- {
- proc = id_68010; /* point to string "10" */
- }
- else
- {
- proc = id_68000; /* point to string "00" */
- }
- }
-
- /* Write out the processor type string - always 2 chars */
- Write(stdout, proc, 2);
-
- /* check for math co-processor */
- if (attnflag & AFF_68881)
- {
- Write(stdout, id_68881, sizeof(id_68881));
- }
-
- /* terminate the line */
- Write(stdout, crlf, sizeof(crlf));
-
- /* Clean up and go home */
- (void) CloseLibrary(DOSBase);
-
- }
-