I am stil hacking away... I've searched far and wide for CC65 examples that were very basic. I found some but I decided to write one as I go. Here is the result.
#include <atari.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <conio.h> // standard cc65 for 'console' based applications
/***************************************************************
* #define SAVMSC is a cc65 MACRO for the Atari 8-BIT platform. *
* SAVMSC points to hardware register at memory location 88. *
* refer to [url="http://www.atariarchives.org/mapping/memorymap.php"]http://www.atariarchives.org/mapping/memorymap.php[/url] *
* *
***************************************************************/
The following define for SAVMSC is to assign a pointer
#define SAVMSC *(unsigned int *) 88 // pointer to atari hardware register that holds the screen position address
/***************************************************************
* __fastcall__ is a cc65 preprocessor command to place the *
* the variable referenced at the top of the memory heap thus *
* enabling faster access by the cpu *
***************************************************************/
void __fastcall__ statusLine(int x, int y, int capture); // debug line to display function variables. Should convert to a constructor
int __fastcall__ getCalc(int oper, int x, int y, int z); // calculate the operation requested
/*************************************************************
* This program is built upon exercise 2.19 found in How to *
* program C by Dietel / Dietel. It has been addapted *
* to work on the Atari 8-Bit platform. *
* *
* Things to do: *
1. Call to statusLine should be done during a VLI *
2. Convert statusLine to a structure to handle more cases*
3. Use TGI (Having probelms loading driver) *
*************************************************************/
void main(void)
{
int sum, average, product, smallest, largest; // create five operators for math calculations
int i1, i2, i3; // create three integers for to be used by the five operators.
char c; // character c is need to check for EOF / user exit
cursor(1); // turn the atari cursor off
gotox(0); // position the cursor on X line 0
printf("Enter three numbers: ");
cscanf("%d", &i1); // need to add test for out of range entries
statusLine(wherex(),wherey(),i1); // debug function to determine where cursor is and the value of i1
gotoxy(27,0); // Put cursor on Line X 0 and Y 27 as it was moved by statusLine
cscanf("%d", &i2);
statusLine(wherex(),wherey(),i2);
gotoxy(30,0);
cscanf("%d", &i3);
statusLine(wherex(),wherey(),i3);
gotoxy(10,6); // Move cursor to center of screen and display results
sum = getCalc(1,i1,i2,i3);
average = getCalc(2,i1,i2,i3);
product = getCalc(3,i1,i2,i3);
smallest = getCalc(4,i1,i2,i3);
largest = getCalc(5,i1,i2,i3);
printf("The sum = %d\n", sum);
gotox(10);
printf("The average = %d\n", average);
gotox(10);
printf("The product = %d\n", product);
gotox(10);
printf("The smallest = %d\n", smallest);
gotox(10);
printf("The largest = %d\n", largest);
cursor(0);
gotox(10);
printf("Press Enter to exit");
while (1)
{
gotoxy(20,11);
statusLine(wherex(),wherey(),c=cgetc());
if (c=='\n' || c==EOF)
{
break;
}
}
return;
}
int __fastcall__ getCalc(int operand, int x, int y, int z)
{
switch (operand)
{
case 1: // calculate the sum
operand = x + y + z;
return operand;
case 2: // calculate the average
operand = (x + y + z) / 3;
return operand;
case 3: // calculate the product
operand = x*y*z;
return operand;
case 4: // calculate the smallest
if (x <= y && y <= z)
return x;
else if (x >= y && y <= z)
return y;
else (x >= y && x >= z);
return z;
case 5: // calculate the largest
if (x > y && x > z)
return x;
else if (y > x && y > z)
return y;
else (z > x && z > y);
return z;
default: // no calculation
return EOF;
}
}
void __fastcall__ statusLine(int x,int y, int capture)
{
gotoxy(0,20);
printf("You entered: %d\n", capture);
printf("Position x = %d\n" ,x);
printf("Position y = %d ",y);
return;
}