home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 309_01 / cc09.doc < prev    next >
Text File  |  1990-03-20  |  67KB  |  2,356 lines

  1.  
  2.                               6809 C Compiler for MSDOS
  3.  
  4. Table of Contents
  5.  
  6. Pg Topic
  7. 1   Introduction
  8.     Data types
  9.     Storage Classes
  10. 2   Primaries
  11.     Unary Integer operators
  12.     Binary Integer operators
  13. 3   Logical operators
  14.     Conditional operator
  15.     Assignment operators
  16.     Comma operator
  17. 4   Program control
  18.     Initialization
  19. 5   Embedded compiler commands
  20. 6   Compiler reserved keywords
  21.     Command Line options
  22. 7   Libary files
  23.     Sample compilation
  24. 8   Linking
  25.     Optimization
  26. 9   Sample Program
  27. 11  CC09 Runtime Libraries
  28. 14  ACIA.H
  29. 18  CTYPE.H
  30. 24  DIOBOARD.H
  31. 26  HERCS.H
  32. 30  MCRDRV.H
  33. 31  MEMORY.H
  34. 35  PRINTER.H
  35. 36  SERIAL.H
  36. 40  STRINGS.H
  37. 43  POD Software
  38. 44  Creating Interrupt Routines
  39. 45  Initialization code
  40.     Power Reset Vector
  41.     Origin of C Code
  42.     Stack initialization and entry to c main function
  43. 46  STARTUP.H
  44.     Data Variables
  45. 47  TSTACIA.C
  46. 48  TSTCTYPE.C
  47. 49  TSTDIO.C
  48. 50  TSTHERCS.C
  49.     TSTMCRDR.C
  50. 51  TSTMEMOR.C
  51. 53  TSTPRINT.C
  52.     TSTSERIA.C
  53. 54  TSTSTRIN.C
  54.  
  55. Appendix A
  56. 55  Using AS9
  57.  
  58. 6809 C Compiler (MSDOS) Documentation
  59.  
  60. INTRODUCTION
  61. This compiler is the small C compiler written by Ron Cain and published in Dr.
  62. Dobb's #45 (May '80). The compiler was modified for the 6809 CPU and also
  63. enhanced by Dieter H. Flunkert.  Some help was taken from J. E. Hendrix's
  64. version of the small C compiler and articles from DDJ.
  65.  
  66. The compiler has been modified to run under MSDOS by Brian Brown, and
  67. generates an assembly language output file. The runtime libraries have been
  68. added by Brian Brown. This compiler accepts a subset of standard C.
  69.  
  70.  
  71. DATA TYPES
  72. The data types supported are...
  73.  
  74.  char c;     character
  75.  char *c;    pointer to character
  76.  char c[n];  character array
  77.  int i;      16 bit integer
  78.  int *i;     pointer to integer
  79.  int i();    function returning integer
  80.  int i[n];   integer array
  81.  
  82.  
  83. STORAGE CLASSES
  84.  automatic       This class is the default. It is possible to specify it
  85.                  explicitly, but the preprocessor strips it out (it is #define
  86.                  automatic).
  87.  
  88.  static          Supported for LOCAL variables only.
  89.  
  90.  register        This class is known only by the preprocessor which strips it
  91.                  out.
  92.  
  93.  extern          Supported.
  94.  
  95.  typedef         Not supported.
  96.  
  97. Structures, multidimensional arrays, unions, and more complex types like
  98. "int    **i" are not included.
  99.  
  100.  
  101. PRIMARIES
  102.   array[expression]
  103.   function(arg1,arg2,...,argn)
  104.   constant
  105.   decimal integer
  106.   quoted string    ("sample string")
  107.   primed character ('a'  or  'Z')
  108.   local variable
  109.   global variable
  110. also literals like '\n', '\b' etc.
  111.  
  112.  Each variable must be declared before it is used.
  113.  
  114.  
  115. UNARY INTEGER OPERATORS
  116.   -  minus
  117.   *  indirection (points to object)
  118.   &  address of
  119.   ++ increment, either prefix or suffix
  120.   -- decrement, either prefix or suffix
  121.    7E  complement
  122.   !  not
  123.  
  124.  
  125. BINARY INTEGER OPERATORS
  126.   +  addition
  127.   -  subtraction
  128.   *  multiplication
  129.   /  division
  130.   %  mod, remainder from division
  131.   |  inclusive or
  132.   ^  exclusive or
  133.   &  logical and
  134.   == equal
  135.   != not equal
  136.   <  less than
  137.   <= less than or equal
  138.   >  greater than
  139.   >= greater than or equal
  140.   << left shift
  141.   >> arithmetic right shift
  142.  
  143.  
  144. LOGICAL OPERATORS
  145.   &&  logical and operator
  146.   ||  logical or operator
  147.  
  148.  
  149. CONDITIONAL OPERATOR
  150.   ? : Supported
  151.  
  152.  
  153. ASSIGNMENT OPERATORS
  154.   lvalue = expression
  155.   lvalue += expression
  156.   lvalue -= expression
  157.   lvalue *= expression
  158.   lvalue /= expression
  159.   lvalue %= expression
  160.   lvalue >>= expression
  161.   lvalue <<= expression
  162.   lvalue &= expression
  163.   lvalue ^= expression
  164.   lvalue |= expression
  165.  
  166.  
  167. COMMA OPERATOR
  168.   Supported.
  169.  
  170.  
  171. PROGRAM CONTROL
  172.   if(expression) statement;
  173.   if(expression) statement; else statement;
  174.   while(expression) statement;
  175.   do statement; while(expression);
  176.   for(expression_1;expression_2;expression_3) statement;
  177.    (where the expressions _1,_2,_3 are optional)
  178.   switch(expression) statement;
  179.   case constant-expression : expression;
  180.   default: expression;
  181.   break;
  182.   continue;
  183.   return;
  184.   return expression;
  185.   ;        /* null statement */
  186.   {statement;statement;   ...   statement;}  /* compound statement */
  187.  
  188.  NOT INCLUDED: goto and labels.
  189.  
  190.  
  191. INITIALIZATION
  192. Global and local static variables are by default initialized to zero. It is
  193. possible to assign these variables an initial value.
  194.  
  195.  examples: char c = 'a'   /* c has now the value of 'a' */
  196.   int i = 1;   /* i contains now the value 1 */
  197.  
  198.   char c[80] = "this is a string";
  199.                     /* the array of characters are initialized
  200.       with the text and the rest of the array is
  201.       zero */
  202.  
  203.   int i[10] = 1,2,3;  /* i[0] = 1, i[1] = 2, i[2] = 3
  204.       the rest will be zero */
  205.  
  206.    int i[] = 1,2,3;  /* same as above, but the length of the
  207.       array will be 4, it is the same as:
  208.       int i[4] = 1,2,3,0 */
  209.  
  210. DO NOT USE GLOBAL STATIC VARIABLES (There is a bug in the compiler)
  211.  
  212.  
  213. EMBEDDED COMPILER COMMANDS
  214.  #define name [string]  "name" is replaced by "string" hereafter. If no
  215.      "string" is given only the MACRO name is defined.
  216.  
  217.  #ifdef name   checks whether the name is currently defined in the
  218.      preprocessor; that is, whether it has been defined with #define name.
  219.  
  220.  #ifndef name   A control line of the form checks whether the identifier is
  221.      currently undefined in the pre-processor.
  222.  
  223.  All forms are followed by an arbitrary number of lines, possibly containing a
  224.  control line
  225.  
  226.  #else             and then by a control line
  227.  #endif
  228.  
  229.  #include filename      compiler gets source code from another file (can't be
  230.                         nested)
  231.  
  232.  #asm                   assembly statement code between these two directives
  233.        ....             is passed directly to the assembler.
  234.        ...
  235.  #endasm
  236.  
  237.  #data    defines a ram data segment. Do not use for initialised data. It 
  238.           inserts an assembler directive specifying the .area as RAMDATA
  239.  #code    defines a code segment. The assembler directive inserted is .area
  240.           ROMCODE
  241.  #const   defines a rom data segment. Use for initialised data. It inserts the
  242.           assembler directive .area ROMDATA
  243.  
  244. COMPILER RESERVED KEYWORDS
  245.  asm         automatic  break
  246.  code        char       case
  247.  const       extern     continue
  248.  data        int        default
  249.  define      register   do
  250.  else        static     else
  251.  endasm      for
  252.  endif       if
  253.  ifdef       switch
  254.  ifndef      return
  255.  include     while
  256.  
  257.  
  258.  
  259. COMMAND LINE OPTIONS
  260. When the compiler is run, it reads one C source file and produces one assembly
  261. language output file. The format of the compiler command line is:
  262.  
  263.   cc09 input_file.c [output_file] [options]
  264.  
  265.  Each option is a minus sign followed by a letter:
  266.  
  267.   -c includes the C source code as comments in the compiler generated assembly
  268.      code.
  269.  
  270.   -m display function headers as they are compiled.
  271.  
  272.   -o optimisation on
  273.  
  274.   -z generate code for AS9 assembler
  275.  
  276.  
  277. (Default: Generates code for AS6809 assembler)
  278.  
  279. If no output file is specified, the console screen will be used. In this case
  280. options are invalid. If you desire to see the effect of the options on the
  281. console screen, use the following command format by specifying the output file
  282. as the console device,
  283.  
  284.   cc09  source.c  stdout -c -o -m
  285.  
  286.  
  287. LIBRARY FILES
  288.   C.REL    This is a relocatable object file for handling switch and
  289.            multiply/divide instructions. It is included at link time. If
  290.            generating code for an assembler other than AS6809, use the file 
  291.            C.ASM and assemble it along with the C Compiler output file.
  292.  
  293.  The following routines are included at compile time, using the
  294.  
  295.    #include filename
  296.  
  297.  directive.
  298.  
  299.  ACIA.H     Routines for controlling the ACIA serial port.
  300.  CTYPE.H    Functions for character handling and data conversion between
  301.             character strings and integers.
  302.  HERCS.H    Routines for controlling a hercs card.
  303.  MCRDRV.H   Magnetic Card Reader routines.
  304.  MEMORY.H   Memory manipulation routines.
  305.  SERIAL.H   The IBM-PC serial card functions.
  306.  STARTUP.H  All programs should include this header file, as it contains the
  307.             startup code required before main executes.
  308.  STRINGS.H  String handling functions.
  309.  
  310.  
  311.  
  312. SAMPLE COMPILATION
  313.  
  314.   cc09 test.c test.asm -c
  315.  
  316.  This line causes the compiler to compile the input file test.c and write the
  317. generated code with the c-text interleaved to the output file test.asm.  Any
  318. errors are displayed on the screen.
  319.  
  320.  Control C will abort the compiler.
  321.  
  322.  Assembling
  323.  
  324.   as6809  -los test
  325.  
  326.  This command causes the file TEST.ASM to be assembled, generating a .lst
  327. (list), .rel (object), and .sym (symbol) file. The .rel file consists of four
  328. segments which can be combined with other segments of the same name at link
  329. time to create a loadable module.
  330.  
  331.  
  332. LINKING
  333.  
  334.   aslink -c
  335.  
  336. invokes the relocatable linker, which allows the user to specify the base
  337. address of the various segments within the modules. It may be driven from the
  338. keyboard (-c option) or from a .lnk file (-f option). The following commands
  339. in bold are the users response to link the files and create a loadable module.
  340.  
  341.  aslink>> -s                   generate a motorola s record (.s19)
  342.  aslink>> -m                   generate a map file (.map)
  343.  aslink>> -x                   specify hexadecimal in map file
  344.  aslink>> tsthercs             use tsthercs.rel
  345.  aslink>> c                    use c.rel
  346.  aslink>> -bRAMDATA=0h0000     specify 0 as start of data segment
  347.  aslink>> -bROMCODE=0hc000     specify c000 as start of code segment
  348.  aslink>>
  349.  
  350. In this instance, the base address of the const or ROMDATA segment will be  
  351. the next location after the end of the ROMCODE or code segment.
  352.  
  353.  
  354. OPTIMIZATION
  355. The compiler can produce optimized code, which reduces the compiler output 
  356. code by 15% to 20%. This is achieved by peephole optimization.
  357.  
  358.  The optimizer is invoked at compile time by:
  359.  
  360.   cc09 inputfile [outputfile] -o
  361.  
  362. If you omit the output file specification, the output is directed to the
  363. terminal.
  364.  
  365.  
  366. SAMPLE PROGRAM DEMONSTRATION
  367. The following program works with CIT's 6809 board, and programs a Hercules 
  368. monochrome card.
  369.  
  370.  
  371. /* tsthercs.c */
  372. #include startup.h
  373. #include hercs.h
  374.  
  375. #code
  376.  
  377. main()
  378. {
  379.         int value;
  380.         char data, *memory;
  381.  
  382.         initvideo();
  383.         home();
  384.         clrscr();
  385.         memory = 0xC000;
  386.         while(1) {
  387.                 writeln("Hello there");
  388.  
  389.                 value = 1234;
  390.                 writeint( value );
  391.                 writeln(" ");
  392.  
  393.                 value = -12345;
  394.                 writeint( value );
  395.                 writeln(" ");
  396.  
  397.                 data = 0xfe;
  398.                 writehexbyte( data );
  399.                 writeln(" ");
  400.  
  401.                 writeln("Contents of memory locations C000 -->");
  402.                 for( value = 0; value < 32; value++ )
  403.                         writehexbyte( memory[value] );
  404.                 writeln(" ");
  405.  
  406.                 writeattr("Bold text", BOLD);
  407.                 writeln(" ");
  408.                 writeattr("Underlined text", UNDERLINE);
  409.                 writeln(" ");
  410.                 writeattr("Reversed text", REVERSE);
  411.                 writeln(" ");
  412.                 writeattr("Blinking text", BLINKING);
  413.                 writeln(" ");
  414.         }
  415. }
  416.  
  417. The file is compiled using the command
  418.  
  419.   cc09  tsthercs.c tsthercs.asm -c
  420.  
  421. The assembly file generated by the compiler is converted into a relocatable
  422. object file by the assembler.
  423.  
  424.   as6809 -los tsthercs
  425.  
  426. The linker combines the .rel files together generating a load module.
  427.  
  428.   aslink -c
  429.   aslink>> -s
  430.   aslink>> -m
  431.   aslink>> -x
  432.   aslink>> tsthercs
  433.   aslink>> c
  434.   aslink>> -bRAMDATA=0
  435.   aslink>> -bROMCODE=0hc000
  436.   aslink>> 
  437.  
  438.  
  439. The file tsthercs.s19 is then downloaded to EPROM programmer or target system
  440. via the POD software.
  441.  
  442.   pod tsthercs.s19
  443.  
  444.   MON> r
  445.   MON> h
  446.   MON> i
  447.   MON> l
  448.   MON> g
  449.  
  450.  
  451.  
  452. CC09 RUNTIME LIBRARY
  453. These files are incorporated using the #include statement, and include source
  454. code routines for runtime support of I/O peripheral devices.
  455.  
  456.  ACIA.H
  457.   aciastatus()  returns status (char) from ACIA
  458.   getchne()     returns a character from ACIA, non-echo
  459.   getchar()     returns a character from ACIA and echoes
  460.   getint()      reads an integer from ACIA
  461.   gets()        reads a string from ACIA
  462.   initacia()    initialises ACIA on 6809 card
  463.   kbhit()       checks for recieved character
  464.   putchar()     writes a character to ACIA
  465.   putint()      writes integer to ACIA
  466.   putnl()       writes CR/LF to ACIA
  467.   puts()        writes string to ACIA followed by CR/LF
  468.  
  469.  
  470.  CTYPE.H
  471.   isalnum()  checks for alphanumeric (isalpha | isdigit)
  472.   isalpha()  checks for alphabetic 'A'-'Z' and 'a'-'z'
  473.   isascii()  checks for ascii 0x00-0x7f
  474.   iscntrl()  checks for control character 0x00-0x1f
  475.   isdigit()  checks for digit '0'-'9'
  476.   isgraph()  checks for printable character exluding spaces
  477.   islower()  checks for lowercase 'a'-'z'
  478.   isprint()  iscntrl || isspace
  479.   ispunct()  checks for punctuation
  480.   isspace()  checks for tabs and spaces
  481.   isupper()  checks for 'A'-'Z'
  482.   isxdigit()  checks for '0'-'9' and 'A'-'F'
  483.   toascii()  masks off bit 7
  484.   tolower()  converts to lowercase
  485.   toupper()  converts to uppercase
  486.   atoi()     converts a string to an integer
  487.   itoa()     converts an integer to a string
  488.  
  489.  
  490.  DIOBOARD.H
  491.   initdio()    initialises DIO card
  492.   readanalog() reads value (0-255) from an analog channel
  493.   readkey()    scans key matrix
  494.   readswitches() reads toggle switches
  495.   writeleds()  writes to the leds
  496.   writeseg()   writes to seven segment display
  497.  
  498.  
  499.  HERCS.H
  500.   clrscr()     clears video memory and homes cursor
  501.   gotoxy()     sets cursor
  502.   home()       sets cursor at 0,0
  503.   initvideo()  initialises hercs card
  504.   scrollup()   scrolls entire screen up one line
  505.   write        write a string
  506.   writeattr    write a string with attribute
  507.   writecharattr write a character and its attribute
  508.   writeint     write an integer
  509.   writehexbyte write a character as two hex bytes
  510.   writeln      write a string plus \n
  511.  
  512.  
  513.  MEMORY.H
  514.   getvect()  read an interrupt vector setting
  515.   peek()     read a memory location
  516.   poke()     write to a memory location
  517.   memcmp()   compare two memory areas for equality
  518.   memcpy()   copy from one memory area to another
  519.   memmov()   move from one memory area to another
  520.   memrev()   copy memory areas in reverse order
  521.   memset()   fill a memory block
  522.   setvect()  set an interrupt vector
  523.  
  524.  
  525.  MCRDRV.H
  526.   initmcr()    initializes the PPI on Hugh's digital board
  527.   sensecard()  senses if a card is in the MCR
  528.   readcard()   reads a card connected to the 8255 PPI
  529.   decodecard() attempts to decode the card info
  530.  
  531.  
  532.  PRINTER.H
  533.   initprn()    initialises printer port on HERCS card
  534.   prnchar()    print a character
  535.   prnstatus()  read printer status
  536.  
  537.  
  538.  SERIAL.H
  539.   init8250()   initialises COM1 (PC serial card) to 9600,n,8,1
  540.   pcgetchar()  gets character from COM1, echoes to COM1
  541.   pcgetchne()  gets character from COM1, non-echo
  542.   pcgetint()   read integer from COM1
  543.   pcgets()     read string from COM1
  544.   pckbhit()    checks for recieve character from COM1
  545.   pcputchar()  outputs character to COM1
  546.   pcputint()   outputs integer as a string to COM1
  547.   pcputs()     outputs string to COM1, appends CR/LF
  548.   pcstatus()   returns LSR status of 8250
  549.  
  550.  
  551.  STRINGS.H
  552.   strcat()   appends one string on the end of another
  553.   strcmp()   compares two strings for equality
  554.   strcpy()   copy one string into another
  555.   stricmp()  compare two strings, ignore case
  556.   strlen()   determine length of string
  557.   strncat()  catenate two strings for n characters
  558.   strncmp()  compare two strings for n characters
  559.   strncpy()  copy a string for n characters
  560.   strrev()   reverses a string
  561.  
  562.  
  563.  
  564.  ACIA.H provides the following routines,
  565.  
  566.  
  567. ------------------------------------------------------------------------------
  568. aciastatus()  returns status of on-board ACIA
  569. ------------------------------------------------------------------------------
  570.   example,
  571.  
  572.   char status;
  573.   status = aciastatus();
  574.  
  575.   The status bits are B0 Recieve Data Register Full
  576.                       B1 Transmit Data Register Empty
  577.                       B2 Data Carrier Detect
  578.                       B3 Clear To Send
  579.                       B4 Framing Error
  580.                       B5 Reciever Overrun
  581.                       B6 Parity Error
  582.                       B7 Interrupt Request
  583.  
  584.  
  585. -----------------------------------------------------------------------------
  586. getchar()           reads character from ACIA, echoes back to terminal
  587. -----------------------------------------------------------------------------
  588.   example,
  589.  
  590.   char ch;
  591.   puts("1  Word Processor");
  592.   puts("2  Exit to OS\n");
  593.   puts("Enter choice-->");
  594.   ch = getchar();
  595.   switch( ch ) {
  596.  
  597.  
  598. ------------------------------------------------------------------------------
  599. getchne()           reads character from ACIA, does NOT ECHO
  600. -----------------------------------------------------------------------------
  601.   example,
  602.  
  603.   char ch;
  604.   puts("Press spacebar to contine");
  605.   ch = getchne();
  606.   while( ch != ' ' )
  607.    ch = getchne();
  608.  
  609.  
  610. ------------------------------------------------------------------------------
  611. getint()            reads integer from ACIA
  612. ------------------------------------------------------------------------------
  613.   example,
  614.  
  615.   int number;
  616.   number = getint();
  617.  
  618.  
  619. ACIA ROUTINES
  620. ------------------------------------------------------------------------------
  621. gets()              reads a string from the ACIA, null terminates
  622. ------------------------------------------------------------------------------
  623.   example,
  624.  
  625.   char buffer[80];
  626.   gets( buffer );
  627.  
  628.  
  629. ------------------------------------------------------------------------------
  630. initacia()          initialises ACIA to 9600,n,8,1
  631. ------------------------------------------------------------------------------
  632.   example,
  633.  
  634.   initacia();
  635.   puts("Hello and welcome");
  636.  
  637.  
  638. -----------------------------------------------------------------------------
  639. kbhit()             check for character available, returns 1 if character
  640.                     ready,  returns 0 if no character available
  641. -----------------------------------------------------------------------------
  642.  
  643.   example,
  644.  
  645.   char ch;
  646.   initacia();
  647.   while( kbhit() == 0 )
  648.    ;
  649.   ch = getchar();
  650.  
  651.  
  652. -----------------------------------------------------------------------------
  653. putchar(data)       writes a character to ACIA
  654. char data;
  655.  ------------------------------------------------------------------------------
  656.   example,
  657.  
  658.   char ch;
  659.   ch = 'Z';
  660.   putchar('A');
  661.   putchar(ch);
  662.  
  663.  
  664. ACIA ROUTINES
  665.  
  666. ------------------------------------------------------------------------------
  667. putint(value)       writes integer to ACIA
  668. int value;
  669. ------------------------------------------------------------------------------
  670.   example,
  671.  
  672.   int number;
  673.   number = 1234;
  674.   putint( number ); putnl();
  675.  
  676.  
  677. ------------------------------------------------------------------------------
  678. putnl(value)        writes CR/LF to ACIA
  679. int value;
  680. ------------------------------------------------------------------------------
  681.   example,
  682.  
  683.   int number;
  684.   number = 1234;
  685.   putint( number ); putnl();
  686.  
  687.  
  688. ------------------------------------------------------------------------------
  689. puts(string)        writes a string to ACIA, followed by CR/LF
  690. char *string;
  691. ------------------------------------------------------------------------------
  692.   example,
  693.  
  694.   puts("Hello and welcome.");
  695.  
  696.   puts() accepts the following special characters.
  697.    \n newline
  698.    \r carriage return
  699.    \t tab
  700.    \v vertical tab
  701.    \\ backslash
  702.    \" quote
  703.    \' single quote
  704.  
  705.  
  706.  
  707. CTYPE.H       The following routines are implemented as functions.
  708.  
  709.  
  710. ------------------------------------------------------------------------------
  711. isalnum(ch)         checks for alpanumeric, A-Z, a-z and 0-9
  712. ------------------------------------------------------------------------------
  713.   example,
  714.  
  715.   char ch;
  716.  
  717.   ch = '0';
  718.   if( isalnum(ch) )
  719.    writeln("character is alphanumeric");
  720.  
  721.  
  722. ------------------------------------------------------------------------------
  723. isalpha(ch)         checks for alphabetic, A-Z, a-z
  724. ------------------------------------------------------------------------------
  725.   example,
  726.  
  727.   char ch;
  728.  
  729.   ch = 'l';
  730.   if( isalpha(ch) )
  731.    writeln("character is alphabetic");
  732.  
  733.  
  734. ------------------------------------------------------------------------------
  735. isascii(ch)         checks for ascii, 0x00 - 0x7f
  736. ------------------------------------------------------------------------------
  737.   example,
  738.  
  739.   char ch;
  740.  
  741.   ch = 0xf3;
  742.   if( isascii(ch) )
  743.    writeln("character is ascii");
  744.   else
  745.    writeln("character is not ascii");
  746.  
  747.  
  748. ------------------------------------------------------------------------------
  749. iscntrl(ch)         checks for a control code, 0x00 - 0x1f
  750. ------------------------------------------------------------------------------
  751.   example,
  752.  
  753.   char ch;
  754.  
  755.   ch = getchar();
  756.   if( iscntrl(ch) )
  757.     writeln("Control keys not accepted.");
  758.  
  759.  
  760. CTYPE.H routines
  761.  
  762. ------------------------------------------------------------------------------
  763. isdigit(ch)         checks for a digit 0-9
  764. ------------------------------------------------------------------------------
  765.   example,
  766.  
  767.   char ch;
  768.  
  769.   writeln("Enter a non-digit.");
  770.   ch = getchar();
  771.   while( !isdigit(ch) )
  772.     ch = getchar();
  773.  
  774.  
  775. ------------------------------------------------------------------------------
  776. isgraph(ch)         checks for a printable character, excluding a space
  777. ------------------------------------------------------------------------------
  778.   example,
  779.  
  780.   char ch;
  781.  
  782.   ch = getchar();
  783.   if( isgraph(ch) )
  784.    prnchar(ch);  /*print it*/
  785.  
  786.  
  787. ------------------------------------------------------------------------------
  788. islower(ch)         checks for lowercase
  789. ------------------------------------------------------------------------------
  790.   example,
  791.  
  792.   char ch;
  793.  
  794.   ch = 'l';
  795.  
  796.   if( islower(ch) )
  797.    toupper(ch); /*convert to uppercase*/
  798.  
  799.  
  800. ------------------------------------------------------------------------------
  801. isprint(ch)         checks for a printable character 0x20-0x7e
  802. ------------------------------------------------------------------------------
  803.   example,
  804.  
  805.   char ch;
  806.  
  807.   ch = getchar();
  808.   if( isprint(ch) )
  809.     prnchar(ch);  /*print character*/
  810.  
  811.  
  812.  CTYPE.H routines
  813.  
  814. ------------------------------------------------------------------------------
  815. ispunct(ch)         checks for punctuation characters (iscntrl | isspace)
  816. ------------------------------------------------------------------------------
  817.   example,
  818.  
  819.   char ch;
  820.  
  821.   ch = getchar();
  822.   if( ispunct(ch) )
  823.     puts("Punctuation sysmbols not accepted.");
  824.  
  825.  
  826. ------------------------------------------------------------------------------
  827. isspace(ch)         checks for space, tab, /r, /n, /v, formfeed
  828. ------------------------------------------------------------------------------
  829.   example,
  830.  
  831.   char ch;
  832.  
  833.   ch = getchar();
  834.   while( isspace(ch) )
  835.    ch = getchar();
  836.  
  837.  
  838. ------------------------------------------------------------------------------
  839. isupper(ch)         checks for uppercase
  840. ------------------------------------------------------------------------------
  841.   example,
  842.  
  843.   char ch;
  844.  
  845.   ch = getchar();
  846.   if( isupper(ch) )
  847.    toupper(ch);  /*convert to uppercase*/
  848.  
  849.  
  850. ------------------------------------------------------------------------------
  851. isxdigit(ch)        checks for a hexidecimal digit
  852. ------------------------------------------------------------------------------
  853.   example,
  854.  
  855.   char ch;
  856.  
  857.   ch = getchar();
  858.   whilef( !isxdigit(ch) )
  859.   {
  860.    puts("Please enter a hex digit");
  861.    ch = getchar();
  862.   }
  863.  
  864.  
  865.  
  866.  CTYPE.H routines
  867.  
  868.  
  869. ------------------------------------------------------------------------------
  870. toascii(ch)         converts a character to ascii
  871. ------------------------------------------------------------------------------
  872.   example,
  873.  
  874.   char ch;
  875.  
  876.   ch = getchar();
  877.   ch = toascii(ch);
  878.  
  879.  
  880. ------------------------------------------------------------------------------
  881. tolower(ch)         converts character to lowercase
  882. ------------------------------------------------------------------------------
  883.   example,
  884.  
  885.   char buff[20], *ptr;
  886.  
  887.   strcpy( buff, "HELLO AND WELCOME");
  888.   ptr = buff;
  889.   while( *ptr++ )
  890.    *ptr = tolower(*ptr);
  891.  
  892.  
  893. ------------------------------------------------------------------------------
  894. toupper(ch)         converts character to uppercase
  895. ------------------------------------------------------------------------------
  896.   example,
  897.  
  898.   char buff[20], *ptr;
  899.  
  900.   strcpy( buff, "Hello and welcome");
  901.   ptr = buff;
  902.   while( *ptr++ )
  903.    *ptr = toupper(*ptr);
  904.  
  905.  
  906. ------------------------------------------------------------------------------
  907. int atoi(string)    converts a string to an integer
  908. char *string;
  909. ------------------------------------------------------------------------------
  910.   example,
  911.  
  912.   char buff[20];
  913.   int x;
  914.  
  915.   strcpy(buff, "1234");
  916.   x = atoi(buff);
  917.  
  918.  
  919. CTYPE.H Routines
  920.  
  921. ------------------------------------------------------------------------------
  922. itoa(value, buffer)  converts an integer to a string
  923. int value;
  924. char *buffer;
  925. ------------------------------------------------------------------------------
  926.   example,
  927.  
  928.   char buff[20];
  929.   int x;
  930.  
  931.   x = 200;
  932.   itoa(x, buff);
  933.  
  934.  
  935. DIOBOARD.H
  936. The following routines interface to CIT's DIOBoard and associated panel, which
  937. also needs +12v to work correctly.
  938.  
  939.  
  940. ------------------------------------------------------------------------------
  941. initdio()           initialises DIO Board
  942. ------------------------------------------------------------------------------
  943.   example,
  944.  
  945.   initdio();
  946.  
  947.  
  948. ------------------------------------------------------------------------------
  949. readanalog()        reads analog channel value
  950. ------------------------------------------------------------------------------
  951.   example,
  952.  
  953.   char chn0;
  954.   int millivolts;
  955.  
  956.   chn0 = readanalog( 0 );
  957.   millivolts = chn0 * 20;
  958.  
  959.  
  960. ------------------------------------------------------------------------------
  961. readkey()           scans key matrix, returning '0' - 'F'
  962. ------------------------------------------------------------------------------
  963.   example,
  964.  
  965.   char key;
  966.   key = readkey();
  967.   if( key == '0' ) { 
  968.  
  969.  
  970. ------------------------------------------------------------------------------
  971. readswitch()        reads switches from DIO panel
  972. ------------------------------------------------------------------------------
  973.   example,
  974.  
  975.   char switches;
  976.   switches = readswitch();
  977.   if( switches & 1 ) {   /* select D0 */
  978.  
  979.  
  980. ------------------------------------------------------------------------------
  981. writeleds(val)      writes to the leds on DIO panel
  982. char val;
  983. ------------------------------------------------------------------------------
  984.   example,
  985.  
  986.   char leds;
  987.   leds = 0xff;   /* turn on all leds */
  988.   writeleds( leds );
  989.  
  990.  
  991. DIOBOARD Routines
  992.  
  993. ------------------------------------------------------------------------------
  994. writeseg(seg)       writes to the seven segment display '0' to 'f'
  995. char seg;
  996. ------------------------------------------------------------------------------
  997.   example,
  998.  
  999.   char seg;
  1000.   seg = 'f';   /* display F on seven seg display */
  1001.   writeseg( seg );
  1002.  
  1003.  
  1004. HERCS.H
  1005. uses the following GLOBAL variables,
  1006.   char cursx, cursy;
  1007.  
  1008.  and provides the following routines,
  1009.  
  1010.  
  1011. ------------------------------------------------------------------------------
  1012. clrscr()            clears video memory
  1013. ------------------------------------------------------------------------------
  1014.   example,
  1015.  
  1016.   clrscr();
  1017.  
  1018.  
  1019. ------------------------------------------------------------------------------
  1020. gotoxy(x,y)         positions cursor at x,y co-ordinates
  1021. int x, y;
  1022. ------------------------------------------------------------------------------
  1023.   example,
  1024.  
  1025.   gotoxy( 10, 20 );
  1026.  
  1027.  
  1028. ------------------------------------------------------------------------------
  1029. home()              positions cursor at 0,0
  1030.  ------------------------------------------------------------------------------
  1031.   example,
  1032.  
  1033.   home();
  1034.  
  1035.  
  1036. ------------------------------------------------------------------------------
  1037. initvideo()         initialises hercs card for text mode
  1038. ------------------------------------------------------------------------------
  1039.   example,
  1040.  
  1041.   initvideo();
  1042.  
  1043.  
  1044. ------------------------------------------------------------------------------
  1045. scrollup()          scrolls video up one line, leaves cursor at 0,24
  1046. ------------------------------------------------------------------------------
  1047.   example,
  1048.  
  1049.   scrollup();
  1050.  
  1051.  
  1052. HERCS Routines
  1053.  
  1054. -----------------------------------------------------------------------------
  1055. write(string)       writes a null terminated string to the video
  1056. char *string;       starting at current cursor position.
  1057. ------------------------------------------------------------------------------
  1058.   example,
  1059.  
  1060.   write("hello and welcome");
  1061.  
  1062.  
  1063. ------------------------------------------------------------------------------
  1064. writeattr(string, attr)   writes a null terminated string to the
  1065. char *string, attr;       video starting at current cursor position.
  1066. ------------------------------------------------------------------------------
  1067.   example,
  1068.  
  1069.   writeattr("hello and welcome", NORMAL);
  1070.  
  1071. see function writecharattr() for a description of the string attributes.
  1072.  
  1073.  
  1074. ------------------------------------------------------------------------------
  1075. writecharattr(ch, attrib)  writes character and attribute to current
  1076. char ch, attrib;           cursor position, updates cursor after write
  1077. ------------------------------------------------------------------------------
  1078.   example,
  1079.  
  1080.   char ch, attr;
  1081.  
  1082.   ch = 'A';
  1083.   attr = 0x07;
  1084.   writecharattr( ch, attr );
  1085.  
  1086.  The following video attributes are also defined in HERCS.H
  1087.   BLINKING
  1088.   BOLD
  1089.   NORMAL
  1090.   REVERSE
  1091.   UNDERLINE
  1092.  
  1093.   example,  writecharattr( 'Z', BLINKING );
  1094.  
  1095.  
  1096. ------------------------------------------------------------------------------
  1097. writeln(string)     writes a null terminated string to the video starting at
  1098. char *string;       current cursor position, followed by a newline.
  1099. ------------------------------------------------------------------------------
  1100.   example,
  1101.  
  1102.   writeln("hello and welcome");
  1103.  
  1104.  
  1105.  HERCS.H Routines
  1106.  
  1107.  
  1108. ------------------------------------------------------------------------------
  1109. writehexbyte(data)  writes the character as ascii hex bytes at current
  1110. char data;          cursor location.
  1111. ------------------------------------------------------------------------------
  1112.   example,
  1113.  
  1114.   char data;
  1115.   data = 0xfe;
  1116.   writehexbyte( data );
  1117.  
  1118.  
  1119. ------------------------------------------------------------------------------
  1120. writeint(value)     writes an integer value to current cursor
  1121. int value;          position
  1122. ------------------------------------------------------------------------------
  1123.   example,
  1124.  
  1125.   int sum;
  1126.   sum = 1234;
  1127.   gotoxy( 10,20 );
  1128.   writeint( sum );
  1129.  
  1130.  
  1131.  
  1132. MCRDRV.H
  1133. These routines control a magnetic card reader attatched to the DIO board via
  1134. PORT C.
  1135.  
  1136. ------------------------------------------------------------------------------
  1137. initmcr()           initializes the magnetic card reader (8255 PPI)
  1138. ------------------------------------------------------------------------------
  1139.  example,
  1140.   initmcr();
  1141.  
  1142.  
  1143. ------------------------------------------------------------------------------
  1144. sensecard()         returns 1 if a card is inserted into the reader
  1145. ------------------------------------------------------------------------------
  1146.  example,
  1147.   initmcr();
  1148.   while( sensecard() == 0 )
  1149.    ;
  1150.  
  1151.  
  1152. ------------------------------------------------------------------------------
  1153. readcard()          reads the card inserted in the reader
  1154. ------------------------------------------------------------------------------
  1155.  example,
  1156.   initmcr();
  1157.   while( sensecard() == 0 )
  1158.    ;
  1159.   readcard();
  1160.  
  1161.  
  1162. ------------------------------------------------------------------------------
  1163. decodecard()        decodes the card
  1164. ------------------------------------------------------------------------------
  1165.  example,
  1166.   char card[81];
  1167.   initmcr();
  1168.   while( sensecard() == 0 )
  1169.    ;
  1170.   readcard();
  1171.   if( decodecard(card) ) {
  1172.    write("The card is -->");
  1173.    writeln( card );
  1174.   }
  1175.  
  1176.  
  1177. MEMORY.H
  1178. The following routines provide for memory manipulation.
  1179.  
  1180.  
  1181. ------------------------------------------------------------------------------
  1182.  getvect(vector)   returns address stored in interrupt vector
  1183.  int *vector;
  1184. ------------------------------------------------------------------------------
  1185.   example,
  1186.  
  1187.   int oldintvect;
  1188.  
  1189.   oldintvect = getvect( 0xfffa );
  1190.  
  1191.  
  1192. ------------------------------------------------------------------------------
  1193.  peek(address)   returns byte at memory location
  1194.  char *address;
  1195. ------------------------------------------------------------------------------
  1196.   example,
  1197.   
  1198.   char ch;
  1199.   ch = peek( 0x1000 );
  1200.  
  1201.  
  1202. ------------------------------------------------------------------------------
  1203.  poke(address,value)  writes value to memory location
  1204.  char *address;
  1205.  char value;
  1206. ------------------------------------------------------------------------------
  1207.   example,
  1208.  
  1209.   int x;
  1210.   for( x = 0x1000; x <= 0x1ffff; x++ )
  1211.    poke( x, 0xA5 );
  1212.  
  1213.  
  1214. ------------------------------------------------------------------------------
  1215. memchr(src,chr,len)  searches area pointed to by src of len bytes for
  1216. char *src, chr;      chr returning an int (which can be used as a char *)
  1217. int len;
  1218. ------------------------------------------------------------------------------
  1219.   example,
  1220.  
  1221.   char *ptr, *src, ch;
  1222.   int length;
  1223.  
  1224.   ch = 'A';
  1225.   length = 0x1000;
  1226.   src = 0x2000;
  1227.   ptr = memchr(src,ch,length);
  1228.   if( ptr == 0 )
  1229.    puts("Not found.");
  1230.  
  1231.  
  1232.  
  1233. MEMORY.H Routines
  1234.  
  1235. ------------------------------------------------------------------------------
  1236.  memcmp(lhs,rhs,len)  compares two memory areas for equality
  1237.  char *lhs, *rhs;
  1238.  int len;
  1239. ------------------------------------------------------------------------------
  1240.   example,
  1241.  
  1242.   int equal;
  1243.  
  1244.   equal = memcmp(0x200,0x300,0x20);
  1245.   if( equal == 0 )
  1246.    puts("the blocks are the same.");
  1247.  
  1248.  
  1249. ------------------------------------------------------------------------------
  1250.  memcpy(dest,src,len)  copies len bytes from src to dest
  1251.  char *dest, *src;
  1252.  int len;
  1253. ------------------------------------------------------------------------------
  1254.  example,
  1255.  
  1256.   memcpy( 0x1000, 0x2000, 100 );
  1257.  
  1258.  
  1259. ------------------------------------------------------------------------------
  1260.  memmov(dst,src,len)  copies len bytes from src to dst
  1261.  char *dst, *src;
  1262.  int len;
  1263. ------------------------------------------------------------------------------
  1264.   example,
  1265.  
  1266.   memmov( 0x1000, 0x2000, 100 );
  1267.  
  1268.  
  1269. ------------------------------------------------------------------------------
  1270.  memrev(dst,src,len)  copies len bytes from src to dst, in reverse order
  1271.  char *dst, *src;
  1272.  int len;
  1273. ------------------------------------------------------------------------------
  1274.   example,
  1275.  
  1276.   memrev( 0x1000, 0x2000, 100 );
  1277.  
  1278.  
  1279. ------------------------------------------------------------------------------
  1280.  memset(dst,chr,len)  fills dst with chr for len bytes
  1281.  char *dst, chr;
  1282.  int len;
  1283. ------------------------------------------------------------------------------
  1284.   example,
  1285.  
  1286.   memset( 0x1000, 0x33, 100 );
  1287.  
  1288.  
  1289.  MEMORY.H routines
  1290.  
  1291.  
  1292. ------------------------------------------------------------------------------
  1293.  setvect(vector,function)   sets interrupt vector to address of
  1294.  int *vector, *function;     function name
  1295. ------------------------------------------------------------------------------
  1296.   example,
  1297.  
  1298.   inthandler()  {
  1299.   #asm
  1300.    rti
  1301.   #endasm
  1302.   }
  1303.  
  1304.   main() {
  1305.    setvect(0xfffa, inthandler);
  1306.    while( 1 ) ;
  1307.   }
  1308.  
  1309.  
  1310.  PRINTER.H
  1311.  provides the following routines to control the printer port on a HERCS card.
  1312.  
  1313.  
  1314. ------------------------------------------------------------------------------
  1315.  initprn()   initialises printer port on HERCS card
  1316. ------------------------------------------------------------------------------
  1317.   example,
  1318.  
  1319.   initprn();
  1320.  
  1321.  
  1322. ------------------------------------------------------------------------------
  1323.  prnchar()   writes a character to the printer port on HERCS card
  1324. ------------------------------------------------------------------------------
  1325.   example,
  1326.  
  1327.   char ch;
  1328.   ch = 'Z';
  1329.   initprn();
  1330.   prnchar('A');
  1331.   prnchar( ch );
  1332.  
  1333.  
  1334. ------------------------------------------------------------------------------
  1335.  prnstatus()   returns status of printer port on HERCS card
  1336. ------------------------------------------------------------------------------
  1337.   example,
  1338.  
  1339.   char status;
  1340.   status = prnstatus();
  1341.  
  1342.  
  1343.   The bits of status are  B0 Time Out
  1344.        B1 Unused
  1345.        B2 Unused
  1346.        B3 I/O Error
  1347.        B4 Selected
  1348.        B5 Out of Paper
  1349.        B6 Acknowledge
  1350.        B7 Busy
  1351.  
  1352.  
  1353.  SERIAL.H
  1354.  provides the following routines. The PC serial card requires +12v and -12v.
  1355.  
  1356.  
  1357. ------------------------------------------------------------------------------
  1358.  init8250()   initialises PC-Serial Card to 9600,n,8,1
  1359. ------------------------------------------------------------------------------
  1360.   example,
  1361.  
  1362.   init8250();
  1363.  
  1364.  
  1365. ------------------------------------------------------------------------------
  1366.  pcgetchar()   reads character from COM1, echoes back to terminal
  1367. ------------------------------------------------------------------------------
  1368.   example,
  1369.  
  1370.   char ch;
  1371.   pcputs("1  Word Processor");
  1372.   pcputs("2  Exit to OS");
  1373.   pcputs("Enter choice-->");
  1374.   ch = pcgetchar();
  1375.   switch( ch ) {
  1376.  
  1377.  
  1378. ------------------------------------------------------------------------------
  1379.  pcgetchne()   gets character from COM1, non-echo
  1380. ------------------------------------------------------------------------------
  1381.   example,
  1382.  
  1383.   char ch;
  1384.   pcputs("Press spacebar to contine");
  1385.   ch = pcgetch();
  1386.   while( ch != ' ' )
  1387.    ch = pcgetch();
  1388.  
  1389.  
  1390. ------------------------------------------------------------------------------
  1391.  pcgets()   reads string from COM1, echoes back to terminal
  1392. ------------------------------------------------------------------------------
  1393.   example,
  1394.  
  1395.   char buffer[80];
  1396.   pcgets( buffer );
  1397.  
  1398.  
  1399. ------------------------------------------------------------------------------
  1400.  pcgetint()   reads integer from COM1, echoes back to terminal
  1401. ------------------------------------------------------------------------------
  1402.   example,
  1403.  
  1404.   int temp;
  1405.   temp = pcgetint();
  1406.  
  1407.  
  1408.  SERIAL.H routines
  1409.  
  1410.  
  1411. ------------------------------------------------------------------------------
  1412.  pckbhit() check for character available, returns 1 if character ready,
  1413.   returns 0 if no character available
  1414. ------------------------------------------------------------------------------
  1415.  
  1416.   example,
  1417.  
  1418.   char ch;
  1419.   init8250();
  1420.   while( pckbhit() == 0 )
  1421.    ;
  1422.   ch = pcgetchar();
  1423.  
  1424.  
  1425. ------------------------------------------------------------------------------
  1426.  pcputchar(data)  writes a character to COM1
  1427.  char data;
  1428. ------------------------------------------------------------------------------
  1429.   example,
  1430.  
  1431.   char ch;
  1432.   ch = 'Z';
  1433.   pcputchar('A');
  1434.   pcputchar(ch);
  1435.  
  1436.  
  1437. ------------------------------------------------------------------------------
  1438.  pcputint(value)  writes an integer value to COM1
  1439.  int value;
  1440. ------------------------------------------------------------------------------
  1441.   example,
  1442.  
  1443.   int value;
  1444.   value = 1223;
  1445.   pcputint( value );
  1446.  
  1447.  
  1448. ------------------------------------------------------------------------------
  1449.  pcputs(string)  writes a string to COM1, followed by CR/LF
  1450.  char *string;
  1451. ------------------------------------------------------------------------------
  1452.   example,
  1453.  
  1454.   pcputs("Hello and welcome.");
  1455.  
  1456.   puts() accepts the following special characters.
  1457.    \n newline
  1458.    \r carriage return
  1459.    \t tab
  1460.    \v vertical tab
  1461.    \\ backslash
  1462.    \" quote
  1463.    \' single quote
  1464.  
  1465.  SERIAL.H routines
  1466.  
  1467.  
  1468. ------------------------------------------------------------------------------
  1469.  pcstatus()   returns Line Status Register status of COM1
  1470. ------------------------------------------------------------------------------
  1471.   example,
  1472.  
  1473.   char status;
  1474.   status = pcstatus();
  1475.  
  1476.  
  1477.   The associated bits are
  1478.    B0 Data Ready
  1479.    B1 OverRun Error
  1480.    B2 Parity Error
  1481.    B3 Framing Error
  1482.    B4 Break Interrupt
  1483.    B5 Transmit Buffer Empty
  1484.    B6 TX Shift Register Empty
  1485.    B7 0
  1486.  
  1487.  
  1488.  
  1489.  STRINGS.H
  1490.  provides the following routines,
  1491.  
  1492.  
  1493. ------------------------------------------------------------------------------
  1494.  strcat(string1, string2)   concatenates string2 onto the end of
  1495.  char *string1, *string2;   string1
  1496. ------------------------------------------------------------------------------
  1497.   example,
  1498.  
  1499.   char buff1[40], buff2[20];
  1500.  
  1501.   strcpy(buff1, "Hello ");
  1502.   strcpy(buff2, "and welcome.");
  1503.   strcat(buff1, buff2);
  1504.  
  1505.  
  1506. ------------------------------------------------------------------------------
  1507.  strcmp(string1, string2)  compares two strings for equality.
  1508.  char *string1, *string2;   returns 0 if strings are equal, 1 otherwise
  1509. ------------------------------------------------------------------------------
  1510.   example,
  1511.  
  1512.   if( strcmp("hello", "hello") == 0)
  1513.    puts("Both strings are the same.");
  1514.  
  1515.  
  1516. ------------------------------------------------------------------------------
  1517.  strcpy(string1, string2)   copies string2 into string1
  1518.  char *string1, *string2;
  1519. ------------------------------------------------------------------------------
  1520.   example,
  1521.  
  1522.   char buff[20];
  1523.  
  1524.   strcpy(buff, "Hello and welcome.");
  1525.  
  1526.  
  1527. ------------------------------------------------------------------------------
  1528.  stricmp(str1,str2)    compares two strings for equality, 
  1529.  char *str1,*str2;    ignoring case. returns 0 if equal, 1 otherwise
  1530. ------------------------------------------------------------------------------
  1531.   example,
  1532.  
  1533.   if( stricmp("HELLO","hello") == 0)
  1534.    puts("Both strings are the same.");
  1535.  
  1536.  
  1537.  STRINGS.H routines
  1538.  
  1539. ------------------------------------------------------------------------------
  1540.  strlen(str)     returns length of string
  1541.  char *s;
  1542. ------------------------------------------------------------------------------
  1543.   example,
  1544.  
  1545.   int x,
  1546.  
  1547.   x = strlen("Hello and welcome.");
  1548.   printf("The length of the string is %d\n", x);
  1549.  
  1550.  
  1551. ------------------------------------------------------------------------------
  1552.  strncat(str1,str2,n)   appends n characters of string2 onto the 
  1553.  char *str1, *str2;    end of string1.
  1554.  int n;
  1555. ------------------------------------------------------------------------------
  1556.   example,
  1557.  
  1558.   char buff[20];
  1559.  
  1560.   strcpy(buff, "Hello");
  1561.   strncat(buff, "and welcome", 3 );
  1562.  
  1563.  
  1564. ------------------------------------------------------------------------------
  1565.  strncmp(str1,str2,n)   compares n characters of string2 against
  1566.  char *str1, *str2;    string1. returns 0 if equal, 1 otherwise
  1567.  int n;
  1568. ------------------------------------------------------------------------------
  1569.   example,
  1570.  
  1571.   if( strncmp("hello1", "hello2", 5) == 0)
  1572.    puts("Both strings are the same.");
  1573.  
  1574.  
  1575. ------------------------------------------------------------------------------
  1576.  strncpy(str1,str2,n)   copies n characters of string2 into string1.
  1577.  char *str1, *str2;
  1578.  int n;
  1579. ------------------------------------------------------------------------------
  1580.   example,
  1581.  
  1582.   char buff[20];
  1583.  
  1584.   strncpy(buff, "Hello and welcome", 5);
  1585.  
  1586.  
  1587. STRING.H Routines
  1588.  
  1589. ------------------------------------------------------------------------------
  1590.  strrev(string)    reverses the characters in a string
  1591.  char *string;
  1592. ------------------------------------------------------------------------------
  1593.   example,
  1594.  
  1595.   char buff[20];
  1596.  
  1597.   strcpy(buff,"Hello and welcome.");
  1598.   strrev(buff);
  1599.   writelnstr(buff,0x07);
  1600.  
  1601.  
  1602. POD Software
  1603. This software is useful for downloading code directly into the target systems
  1604. memory. It requires the use of the POD hardware, which connects to CIT's
  1605. Digital I/O board via a ribbon cable. The other part of the POD unit plugs
  1606. directly across the target processor.
  1607.  
  1608.  
  1609. When invoking the POD software, it accepts a command line argument which
  1610. specifies the download software (Motorola S1 record file).
  1611.  
  1612.  
  1613. $ pod filename.bin
  1614. MS-DOS POD Hardware, Version 1.02
  1615.  
  1616.  MON:>
  1617.  Options are:
  1618.  ============
  1619.  
  1620.      Halt The Processor  ......... "H" or "h"
  1621.      Reset The Processor ......... "R" or "r"
  1622.      Initialize the POD  ......... "I" or "i"
  1623.      Load The Program    ......... "L" or "l"
  1624.      Verify The Program  ......... "V" or "v"
  1625.      Run The Processor   ......... "G" or "g"
  1626.      Display Memory      ......... "D" or "d"
  1627.      Set Memory          ......... "S" or "s"
  1628.      Quit the Monitor    ......... "Q" or "q"
  1629.  
  1630.  
  1631.  MON:>
  1632.  
  1633.  
  1634. The normal sequence of options will be
  1635.  
  1636.  R
  1637.  I
  1638.  L
  1639.  G
  1640.  
  1641.  
  1642. If code for the processors RESET vector is not included, it will be necessary to set the reset vector manually using the S option before executing G.
  1643.  
  1644.  
  1645.  
  1646. CREATING INTERRUPT ROUTINES
  1647. Though the compiler does not accept functions of type interrupt, these can
  1648. easily be created. Consider the following code which handles the SWI vector.
  1649.  
  1650.  
  1651. #include startup.h
  1652. #include hercs.h
  1653. #include memory.h
  1654.  
  1655. #code
  1656.  
  1657. swihandler()
  1658. {
  1659.         writeln("Entered SWI routine.");
  1660. #asm    rti
  1661. #endasm
  1662. }
  1663.  
  1664. main()
  1665. {
  1666.         int loop;
  1667.         initvideo();
  1668.         home();
  1669.         clrscr();
  1670.         setvect( 0xfffa, swihandler );
  1671.         writeln("TESTING SWI HANDLER FOR FIVE ITERATIONS");
  1672.         for( loop = 0; loop < 5; loop++ )   {
  1673. #asm
  1674.            swi
  1675. #endasm
  1676.         }
  1677. }
  1678.  
  1679.  
  1680. INITIALIZATION CODE
  1681. Target code normally resides within specific memory areas, such as EPROM. The 6809 processor board has memory mapped as
  1682.  
  1683.  
  1684.  Address      Type              C Directive      Assembler Directive
  1685.  0000 - 7fff  Stack/data/code   #data            .area  RAMDATA (REL,CON)
  1686.  C000 - ffff  Code/constants    #code            .area  ROMCODE (REL,CON)
  1687.                                 #const           .area  CONST   (REL,CON)
  1688.  
  1689.  
  1690.  
  1691.  
  1692. POWER ON RESET VECTOR
  1693. When power is turned on, or upon a RESET, the 6809 processor fetches the
  1694. address of the next instruction from locations fffe and ffff. The address of
  1695. the instruction (which is normally the startup code for the C program) should
  1696. be included into the C source.
  1697.  
  1698.  
  1699. #asm .area _CODE (ABS,OVR)
  1700.    .org 0hfffe
  1701.    .dw  0hC000
  1702. #endasm
  1703.  
  1704.  
  1705. This is automatically inserted by the header file startup.h
  1706.  
  1707.  
  1708.  
  1709. ORIGIN OF C CODE
  1710. This can be handled using the header file startup.h which defines relocatable
  1711. segments for the assembler/linker tools. The base address of the C code is
  1712. specified when running aslink, using the format
  1713.  
  1714.   -bROMCODE=0h....
  1715.  
  1716.  
  1717.  
  1718. STACK INITIALIZATION AND ENTRY TO C MAIN FUNCTION
  1719. The C compiler does not initialize the stack or provide for the processor to
  1720. automatically start execution at the main function. The code to perform this
  1721. is handled by the header file startup.h
  1722.  
  1723.  
  1724.  
  1725. STARTUP.H
  1726. The header file startup.h
  1727.  - initialises the reset vector to 0hc000
  1728.  - initialises the stack pointer to 0h7000
  1729.  - jumps to main
  1730.  
  1731. A user can alter the values of the stack location and entry addresses to suit
  1732. their own requirements.
  1733.  
  1734.  
  1735.  
  1736. DATA VARIABLES
  1737. The data variables supported are
  1738.  
  1739.  uninitialised globals - reside in RAMDATA and can be modified
  1740.  initialised globals - reside in ROMDATA, cannot be modified
  1741.  uninitialised locals - reside on the stack with each function
  1742.  
  1743.  
  1744. The #data directive defines variables of type RAMDATA.
  1745.  
  1746. The #const directive defines variables of type ROMDATA. This is ideal for
  1747. lookup tables etc.
  1748.  
  1749.  
  1750. BEWARE
  1751.  
  1752.  #const
  1753.  int videoregs[16] = { 10,20,86,7,8,0,0 };
  1754.  
  1755.  modify()
  1756.  {
  1757.   videoregs[5] = 7;  /* won't work, trying to alter rom */
  1758.  
  1759.  
  1760.  
  1761. TEST ROUTINES FOR THE VARIOUS HEADER DRIVERS
  1762.  
  1763.  
  1764. /* TSTACIA.C  connect terminal to on-board ACIA */
  1765. #include startup.h
  1766. #include acia.h
  1767.  
  1768. #code
  1769. main()
  1770. {
  1771.         int temp, loop;
  1772.         char data, buffer[80];
  1773.  
  1774.         initacia();
  1775.         puts("initialising acia to 9600,n,8,2");
  1776.         while(1) {
  1777.                 puts("Hello there  TESTING ACIA.H ROUTINES");
  1778.                 puts("Entering terminal routine now, Press @ to escape");
  1779.                 data = getchar();
  1780.                 while( data != '@' )  data = getchar();
  1781.  
  1782.                 puts(" ");
  1783.                 puts("Checking for keypress");
  1784.                 while( kbhit() == 0 )          puts("No key pressed.");
  1785.                 puts("The keypress was --->"); data = getchar();
  1786.                 puts(" ");
  1787.  
  1788.                 puts("Testing getchne() routines, NONECHO, type @ to exit");
  1789.                 loop = 0;
  1790.                 data = getchne();
  1791.                 while( data != '@' )    {
  1792.                         buffer[loop] = data;
  1793.                         data = getchne();
  1794.                         loop++;
  1795.                 }
  1796.                 buffer[loop] = '\0';
  1797.                 puts("What you typed was ");
  1798.                 puts( buffer );
  1799.  
  1800.                 puts("Testing puts character handling routines");
  1801.                 puts("\fform feed");
  1802.                 puts("\\backslash");
  1803.                 puts("\ttab space");
  1804.                 puts("\rcarriage return");
  1805.                 puts("\nnewline");
  1806.                 puts("Hello\bo backspace");
  1807.                 puts("\' single quote");
  1808.  
  1809.                 puts("Testing putint() routine for 1 to 10");
  1810.                 for( temp = 1; temp <= 10; temp++ )
  1811.                         putint( temp );
  1812.                 putnl();
  1813.  
  1814.                 puts("Enter in a string of characters ");
  1815.                 gets( buffer );
  1816.                 puts("The string you typed was ");
  1817.                 puts( buffer );
  1818.  
  1819.                 puts("Enter a numeric integer");
  1820.                 temp = getint();
  1821.                 puts("The number you entered was ");
  1822.                 putint( temp ); putnl();
  1823.  
  1824.                 data = aciastatus();
  1825.                 puts("The status of the ACIA is");
  1826.                 buffer[0] = ((data & 0xf0) >> 4) + '0';
  1827.                 buffer[1] = (data & 0x0f) + '0';
  1828.                 if( buffer[0] > '9' ) buffer[0] = buffer[0] + 7;
  1829.                 if( buffer[1] > '9' ) buffer[1] = buffer[1] + 7;
  1830.                 buffer[2] = '\0';
  1831.                 puts( buffer );
  1832.         }
  1833. }
  1834.  
  1835. /* TSTCTYPE.C  connect HERCS card and monitor */
  1836. #include startup.h
  1837. #include hercs.h
  1838. #include ctype.h
  1839.  
  1840. #code
  1841. main()
  1842. {
  1843.    char buff[20], ch;
  1844.    int value;
  1845.  
  1846.    initvideo();        home();
  1847.    clrscr();           writeln("Hello there");
  1848.  
  1849.    ch = 0x20;
  1850.    if( isascii(ch) ) writeln("ch=0x20 isascii");
  1851.    ch = 0x83;
  1852.    if( isascii(ch) ) writeln("ch=0x83 isascii");
  1853.    else writeln("ch=0x83 is not ascii");
  1854.  
  1855.    ch = 0x00;
  1856.    if( iscntrl(ch) ) writeln("ch=0x00 iscntrl" );
  1857.    ch = 0x56;
  1858.    if( iscntrl(ch) ) writeln("ch=0x56 iscntrl" );
  1859.    else writeln("ch=0x56 is not cntrl" );
  1860.  
  1861.    ch = '0';
  1862.    if( isdigit(ch) ) writeln("ch='0' isdigit" );
  1863.    ch = 'A';
  1864.    if( isdigit(ch) ) writeln("ch='A' isdigit" );
  1865.    else writeln("ch='A' is not digit" );
  1866.  
  1867.    ch = '0';
  1868.    if( isgraph(ch) ) writeln("ch='0' isgraph" );
  1869.    ch = ' ';
  1870.    if( isgraph(ch) ) writeln("ch=' ' isgraph" );
  1871.    else writeln("ch=' ' is not graph" );
  1872.  
  1873.    ch = 'a';
  1874.    if( islower(ch) ) writeln("ch='a' islower" );
  1875.    ch = 'A';
  1876.    if( islower(ch) ) writeln("ch='A' islower" );
  1877.    else writeln("ch='A' is not lower" );
  1878.  
  1879.    ch = '0';
  1880.    if( isprint(ch) ) writeln("ch='0' isprint" );
  1881.    ch = 0x19;
  1882.    if( isprint(ch) ) writeln("ch=0x19 isprint" );
  1883.    else writeln("ch=0x19 is not print" );
  1884.  
  1885.    ch = ' ';
  1886.    if( ispunct(ch) ) writeln("ch=' ' ispunct" );
  1887.    ch = 'A';
  1888.    if( ispunct(ch) ) writeln("ch='A' ispunct" );
  1889.    else writeln("ch='A' is not punct" );
  1890.  
  1891.    ch = ' ';
  1892.    if( ispunct(ch) ) writeln("ch=' ' ispunct" );
  1893.    ch = 'A';
  1894.    if( ispunct(ch) ) writeln("ch='A' ispunct" );
  1895.    else writeln("ch='A' is not punct" );
  1896.  
  1897.    ch = 0x0a;
  1898.    if( isspace(ch) ) writeln("ch=0x0a isspace" );
  1899.    ch = 'A';
  1900.    if( isspace(ch) ) writeln("ch='A' isspace" );
  1901.    else writeln("ch='A' is not space" );
  1902.  
  1903.    ch = 'A';
  1904.    if( isupper(ch) ) writeln("ch='A' isupper" );
  1905.    ch = 'a';
  1906.    if( isupper(ch) ) writeln("ch='a' isupper," );
  1907.    else writeln("ch='a' is not upper" );
  1908.  
  1909.    ch = 'A';
  1910.    if( isxdigit(ch) ) writeln("ch='A' isxdigit" );
  1911.    ch = 'S';
  1912.    if( isxdigit(ch) ) writeln("ch='S' isxdigit," );
  1913.    else writeln("ch='S' is not xdigit" );
  1914.  
  1915.    ch = 'A';
  1916.    if( isupper(ch) ) writeln("ch='A' isupper" );
  1917.    ch = 'a';
  1918.    if( isupper(ch) ) writeln("ch='a' isupper," );
  1919.    else writeln("ch='a' is not upper" );
  1920.  
  1921.    ch = 'A';
  1922.    if( isalnum(ch) ) writeln("ch='A' isalnum" );
  1923.    ch = '!';
  1924.    if( isalnum(ch) ) writeln("ch='!' isalnum," );
  1925.    else writeln("ch='!' is not alnum" );
  1926.  
  1927.    ch = 'A';
  1928.    if( isalpha(ch) ) writeln("ch='A' isalpha" );
  1929.    ch = '0';
  1930.    if( isalpha(ch) ) writeln("ch='0' isalpha," );
  1931.    else writeln("ch='0' is not alpha" );
  1932.  
  1933.    ch = 0xcf;                 ch = toascii(ch);
  1934.    write("ch = ");            writecharattr( ch, 7);
  1935.    writeln(" ");
  1936.  
  1937.    ch = 'A';                  ch = tolower(ch);
  1938.    writecharattr( ch, 7);     writeln(" ");
  1939.  
  1940.    ch = 'a';                  ch = toupper(ch);
  1941.    writecharattr(ch,7);       writeln(" ");
  1942.  
  1943.    value = 0;                 value = atoi("1234");
  1944.    itoa( value, buff );       writeln(buff);
  1945.  
  1946.    while(1)
  1947.       ;
  1948. }
  1949.  
  1950.  
  1951. /* TSTDIO.C  requires use of DIO card, +12V, +5V,  also HERCS card and monitor */
  1952. #include startup.h
  1953. #include hercs.h
  1954. #include ctype.h
  1955. #include dioboard.h
  1956.  
  1957. #code
  1958. main()
  1959. {
  1960.    char temp, ch, sw, analog, buffer[20];
  1961.    int volts, v1;
  1962.  
  1963.    initvideo();       home();         clrscr();
  1964.    ch = '0';          temp = 0;       initdio();
  1965.    while( 1 )   {
  1966.       write("Writing to leds --->");  writehexbyte( temp );  writeln(" ");
  1967.       writeleds( temp );              temp++;
  1968.  
  1969.       write("Writing to seven segment display --->");
  1970.       writecharattr( ch, NORMAL);     writeln(" ");
  1971.       writeseg( ch );                 ch++;
  1972.       if( ch == 0x3a ) ch = 'A';      if( ch == 'G' ) ch = '0';
  1973.  
  1974.       write("The value read from the switches is --->");
  1975.       sw = readswitch();  writehexbyte( sw );   writeln(" ");
  1976.  
  1977.       write("The value read from analog channel 0 is --->");
  1978.       analog = readanalog( 0 );
  1979.       writehexbyte(analog);  writeln(" ");
  1980.       v1 = analog & 0xff;
  1981.       volts = v1 * 20;
  1982.       itoa( volts, buffer );
  1983.       write("which represents "); write( buffer );
  1984.       writeln(" millivolts");
  1985.  
  1986.       write("The key pressed was --->");    ch = readkey();
  1987.       writecharattr( ch, BOLD);             writeln(" ");
  1988.    }
  1989. }
  1990.  
  1991. /* TSTHERCS.C  requires hercs/monochrome adapter and monitor */
  1992. #include startup.h
  1993. #include hercs.h
  1994.  
  1995. #code
  1996. main()
  1997. {
  1998.    int value;
  1999.    char data, *memory;
  2000.  
  2001.    initvideo();        home();        clrscr();       memory = 0xC000;
  2002.    while(1) {
  2003.       writeln("Hello there");         value = 1234;   writeint( value );
  2004.       writeln(" ");
  2005.  
  2006.       value = -12345;                 writeint( value );
  2007.       writeln(" ");
  2008.  
  2009.       data = 0xfe;                    writehexbyte( data );
  2010.       writeln(" ");
  2011.  
  2012.       writeln("Contents of memory locations C000 -->");
  2013.       for( value = 0; value < 32; value++ )    writehexbyte( memory[value] );
  2014.       writeln(" ");
  2015.  
  2016.       writeattr("Bold text", BOLD);                writeln(" ");
  2017.       writeattr("Underlined text", UNDERLINE);     writeln(" ");
  2018.       writeattr("Reversed text", REVERSE);         writeln(" ");
  2019.       writeattr("Blinking text", BLINKING);        writeln(" ");
  2020.   }
  2021. }
  2022.  
  2023.  
  2024.  
  2025. /* TSTMCRDR.C, requires Hercs card and monitor, DIO board (+12v), MCR */
  2026. #include startup.int
  2027. #include hercs.h
  2028. #include mcrdrv.h
  2029.  
  2030. #code
  2031. main()
  2032. {
  2033.    char res[81];
  2034.    initvideo();        initmcr();        clrscr();
  2035.    writeln("Testing MCRDRV.H routines");
  2036.    while( 1 )  {
  2037.       writeln("Insert card in MCR slot");
  2038.       if( sensecard() )  {
  2039.           readcard();
  2040.           if( decodecard( res ))  {
  2041.               write("And the card was ---->");
  2042.               write(res);     writeln(" ");
  2043.           }
  2044.           else writeln("Can't decode card");
  2045.       }
  2046.    }
  2047. }
  2048.  
  2049.  
  2050. /*TSTMEMORY.C, requires hercs card and monitor */
  2051. #include startup.h
  2052. #include hercs.h
  2053. #include memory.h
  2054.  
  2055. #code
  2056. swihandler()
  2057. {
  2058.    writeln("Entered SWI routine.");
  2059. #asm   rti
  2060. #endasm
  2061. }
  2062.  
  2063. main()
  2064. {
  2065.    int vector, temp, loop;
  2066.    char data, *memory, *src, *dst, source[20], destination[20];
  2067.  
  2068.    initvideo();        home();        clrscr();
  2069.    while(1) {
  2070.       writeln("Hello there  TESTING MEMORY.H ROUTINES");
  2071.       vector = getvect(0xfffe);
  2072.       write("Interrupt vector at $fffe is --->");
  2073.       data = (vector & 0xff00) >> 8;      writehexbyte(data);
  2074.       data = (vector & 0x00ff);           writehexbyte(data);
  2075.       writeln(" ");
  2076.  
  2077.       write("Peek of $C000 is --->");     data = peek( 0xC000 );
  2078.       writehexbyte(data);                 writeln(" ");
  2079.       write("Peek of $C001 is --->");     data = peek( 0xC001 );
  2080.       writehexbyte(data);                 writeln(" ");
  2081.  
  2082.       writeln("Poking memory $1000 with 00 to $0f");
  2083.       memory = 0x1000;
  2084.       for( temp = 0; temp < 16; temp++ )   {
  2085.          data = temp & 0xff;              poke(memory + temp, data);
  2086.       }
  2087.  
  2088.       write("Memory $1000 to $100F = ");
  2089.       for( temp = 0; temp < 16; temp++)    {
  2090.          data = peek( memory + temp );    writehexbyte( data );
  2091.       }
  2092.       writeln(" ");
  2093.  
  2094.       writeln("Memchr searching for $04 starting at $1000");
  2095.       src = memchr( 0x1000, 4, 16 );
  2096.       if( src == 0 ) writeln("NOT FOUND");
  2097.       else {
  2098.           write("Value found at location ");
  2099.           writehexbyte( (src & 0xff00) >> 8);
  2100.           writehexbyte( (src & 0x00ff) );    writeln(" ");
  2101.       }
  2102.  
  2103.       writeln("Memchr searching for $04 starting at $1005");
  2104.       src = memchr( 0x1005, 4, 16 );
  2105.       if( src == 0 ) writeln("NOT FOUND");
  2106.       else {
  2107.           write("Value found at location ");
  2108.           writehexbyte( (src & 0xff00) >> 8);
  2109.           writehexbyte( (src & 0x00ff) );    writeln(" ");
  2110.       }
  2111.  
  2112.       write("Memcmp comparing $1000 and $1000 for 10bytes");
  2113.       temp = memcmp( 0x1000, 0x1000, 10);
  2114.       if( temp == 0 ) writeln(" is the same:::::");
  2115.       else writeln(" is different:::::");
  2116.  
  2117.       write("Memcmp comparing $1000 and $1004 for 10bytes");
  2118.       temp = memcmp( 0x1000, 0x1004, 10);
  2119.       if( temp == 0 ) writeln(" is the same:::::");
  2120.       else writeln(" is different:::::");
  2121.  
  2122.       writeln("Memmove from $1000 to $2000 for 10 bytes");
  2123.       memmov( 0x2000, 0x1000, 10);
  2124.       memory = 0x2000;
  2125.       writeln("Memory at $2000 ---> ");
  2126.       for( temp = 0; temp < 10; temp++)  {
  2127.          data = peek( memory + temp );   writehexbyte( data );
  2128.       }
  2129.       writeln(" ");
  2130.  
  2131.       writeln("MemRev from $1000 to $2000 for 10 bytes");
  2132.       memrev( 0x2000, 0x1000, 10);
  2133.       memory = 0x2000;
  2134.       writeln("Memory at $2000 ---> ");
  2135.       for( temp = 0; temp < 10; temp++)  {
  2136.          data = peek( memory + temp );   writehexbyte( data );
  2137.       }
  2138.       writeln(" ");
  2139.  
  2140.       writeln("MemSet starting at $2000 for 10 bytes with $A5");
  2141.       memset( 0x2000, 0xa5, 10);
  2142.       memory = 0x2000;
  2143.       writeln("Memory at $2000 ---> ");
  2144.       for( temp = 0; temp < 10; temp++)  {
  2145.          data = peek( memory + temp );   writehexbyte( data );
  2146.       }
  2147.       writeln(" ");
  2148.  
  2149.       writeln("Setvect of $fffa/b to main");
  2150.       setvect( 0xfffa, main );
  2151.       vector = getvect(0xfffe);
  2152.       write("Interrupt vector at $fffa/b is --->");
  2153.       data = (vector & 0xff00) >> 8;     writehexbyte(data);
  2154.       data = (vector & 0x00ff);          writehexbyte(data);
  2155.       writeln(" ");
  2156.  
  2157.       setvect( 0xfffa, swihandler );
  2158.       writeln("TESTING SWI HANDLER FOR FIVE ITERATIONS");
  2159.       for( loop = 0; loop < 5; loop++ )  {
  2160. #asm
  2161.          swi
  2162. #endasm
  2163.       }
  2164.    }
  2165. }
  2166.  
  2167.  
  2168. /* TSTPRINT.C, requires hercs card + monitor */
  2169. #include startup.h
  2170. #include hercs.h
  2171. #include printer.h
  2172.  
  2173. #const
  2174. char msg[30] = "controlling a printer";
  2175.  
  2176. #code
  2177. main()
  2178. {
  2179.    char *ptr, status;
  2180.    initvideo();        clrscr();        writeln("initialising printer");
  2181.    initprn();
  2182.    ptr = msg;          status = prnstatus() & 128;
  2183.    while( status == 0 )  {
  2184.       status = prnstatus() & 128;      write("printer busy -->");
  2185.    }
  2186.  
  2187.    while(1)   {
  2188.       ptr = msg;
  2189.       while( *ptr ) {
  2190.          writecharattr(*ptr, BOLD);     prnchar( *ptr );     ptr++;
  2191.       }
  2192.       prnchar( 10 ); prnchar( 13 );
  2193.    }
  2194. }
  2195.  
  2196.  
  2197.  
  2198. /* TSTSERIAL.C requires serial card, (+-12v) */
  2199. #include startup.h
  2200. #include serial.h
  2201.  
  2202. #code
  2203. main()
  2204. {
  2205.    int temp, loop;
  2206.    char data, buffer[80];
  2207.  
  2208.    init8250();    pcputs("initialising com1 to 9600,n,8,1");
  2209.    while(1) {
  2210.       pcputs("Hello there  TESTING SERIAL.H ROUTINES");
  2211.       pcputs("Entering terminal routine now, Press @ to escape");
  2212.       data = pcgetchar();
  2213.       while( data != '@' )  data = pcgetchar();
  2214.       pcputs(" ");
  2215.  
  2216.       pcputs("Checking for keypress");
  2217.       while( pckbhit() == 0 )  pcputs("No key pressed.");
  2218.       pcputs("The keypress was --->");
  2219.       data = pcgetchar();      pcputs(" ");
  2220.  
  2221.       pcputs("Testing pcgetchne() routines, NONECHO, type @ to exit");
  2222.       loop = 0;                data = pcgetchne();
  2223.       while( data != '@' )  {
  2224.          buffer[loop] = data;  data = pcgetchne();  loop++;
  2225.       }
  2226.       buffer[loop] = '\0';
  2227.       pcputs("What you typed was ");  pcputs( buffer );
  2228.  
  2229.       pcputs("Testing puts character handling routines");
  2230.       pcputs("\fform feed");          pcputs("\\backslash");
  2231.       pcputs("\ttab space");          pcputs("\rcarriage return");
  2232.       pcputs("\nnewline");            pcputs("Hello\bo backspace");
  2233.       pcputs("\' single quote");
  2234.  
  2235.       pcputs("Testing putint() routine for 1 to 10");
  2236.       for( temp = 1; temp <= 10; temp++ )     pcputint( temp );
  2237.       pcputs(" ");
  2238.  
  2239.       pcputs("Enter in a string of characters ");      pcgets( buffer );
  2240.       pcputs("The string you typed was ");             pcputs( buffer );
  2241.  
  2242.       pcputs("Enter a numeric integer");               temp = pcgetint();
  2243.       pcputs("The number you entered was ");           pcputint( temp );
  2244.       pcputs(" ");
  2245.  
  2246.       data = pcstatus();
  2247.       pcputs("The status of the ACIA is");
  2248.       buffer[0] = ((data & 0xf0) >> 4) + '0';
  2249.       buffer[1] = (data & 0x0f) + '0';
  2250.       if( buffer[0] > '9' ) buffer[0] = buffer[0] + 7;
  2251.       if( buffer[1] > '9' ) buffer[1] = buffer[1] + 7;
  2252.       buffer[2] = '\0';               pcputs( buffer );
  2253.    }
  2254. }
  2255.  
  2256.  
  2257. /* TSTSTRING.C requires hercs card and monitor */
  2258. #include startup.h
  2259. #include hercs.h
  2260. #include strings.h
  2261.  
  2262. #code
  2263. main()
  2264. {
  2265.    char data, source[80], destination[80];
  2266.    int length;
  2267.  
  2268.    initvideo();        home();        clrscr();
  2269.    while(1) {
  2270.       writeln("TESTING STRING.H ROUTINES");
  2271.       strcpy( destination, "String copy works");
  2272.       write("testing strcpy function -->");
  2273.       writeln( destination );
  2274.  
  2275.       strcpy( source, " and so does strcat.");
  2276.       strcat( destination, source );
  2277.       write("testing strcat function -->");
  2278.       writeln( destination );
  2279.  
  2280.       length = strlen( destination );
  2281.       write("The length of the dest string is -->");
  2282.       writeint( length );                writeln(" ");
  2283.  
  2284.       strcpy( destination, "123456789");
  2285.       strrev( destination );
  2286.       write("The dest string reversed is --->");
  2287.       writeln( destination );
  2288.  
  2289.       strcpy( destination, "1234567890");
  2290.       strrev( destination );
  2291.       write("The dest string reversed is --->");
  2292.       writeln( destination );
  2293.  
  2294.       strcpy( destination, "hello there");
  2295.       strcpy( source, "HEllo. My name is");
  2296.       if( stricmp( destination, source ) == 0 )
  2297.           writeln("hello there and HEllo. My name with stricmp failed.");
  2298.       else
  2299.           writeln("stricmp() detected difference in hello there and Hello. My\
  2300.                    name is");
  2301.  
  2302.       strcpy( destination, "hello");
  2303.       strcpy( source, "HEllo");
  2304.       if( stricmp( destination, source ) == 0 )
  2305.           writeln("hello and HEllo with stricmp works");
  2306.       else writeln("problem in stricmp()");
  2307.  
  2308.       strcpy( destination, "HELLO1");
  2309.       strcpy( source, "HELLO2");
  2310.       if( strncmp( destination, source, 5) == 0 )
  2311.           writeln("HELLO1 and HELLO2 for 5 chars works with strncmp");
  2312.       else writeln("problem in strncmp()");
  2313.  
  2314.       strcpy( destination, "HELLO1");
  2315.       strcpy( source, "HELLO2");
  2316.       if( strncmp( destination, source, 6) == 0 )
  2317.           writeln("HELLO1 and HELLO2 for 6 chars failed with strncmp");
  2318.       else writeln("problem in strncmp() detected HELLO1 and HELLO2 as same");
  2319.  
  2320.       strcpy( destination, "Hello and ");
  2321.       strncat( destination, "welcome to the MC6809", 9);
  2322.       writeln("Using strncat it should print Hello and welcome t");
  2323.       writeln( destination );
  2324.  
  2325.       writeln("Using strncpy it should now add o the MC6809");
  2326.       strncpy( destination, "o the MC6809's C", 12);
  2327.       writeln( destination );
  2328.  
  2329.       writeln(" " );
  2330.    }
  2331. }
  2332.  
  2333.  
  2334. APPENDIX A USING THE CCOMPILER WITH AS9
  2335.  
  2336. 1. Include the following as the first line of your source.
  2337.  
  2338.   #define  AS9  1
  2339.   #include startup.h
  2340.  
  2341.  
  2342. NOTE: The symbol AS9 must be defined as non-zero before the inclusion of the
  2343. startup.h header file.
  2344.  
  2345.  
  2346. 2. To run the assembler, type
  2347.  
  2348.   AS9  cfile.asm  c.asm > cfile.lst
  2349.  
  2350.  
  2351.  which generates a file called m.out which consists of motorola S records.
  2352.  
  2353.  
  2354. 3. Refer to detailed instructions in the AS9 manual for assembler directives
  2355.    and their format.
  2356.