Jump to content
IGNORED

cgetc, cc65 and learning C


rchennau

Recommended Posts

Hey Team Atari :D,

I posted this on my blog but figured I would post here as well in case anyone like me is searching for some programming tips using cc65. And thus with no more preamble.

 

----------------------

 

I am (re)learning C through dutifully typing out all the examples and exercises in the book. However my goal is to compile applications to the Atari 8-bit platform. I wanted to be able to test compile quickly using gcc and then compile later with cc65.

 

To solve the problem I test for a predefined macro by the preprocessor of the compiler I am using. For gcc the MACRO __ATARI__ is not defined but it is for cc65. Thus in my code I test for the condition with ifdef and then put in my platform specific code if the condition is true. This method also works for including platform specific includes.

 

I think the current practice is define all this in a makefile for the target platform. But I don’t feel like learning sed to change source file on the fly (at least not yet).

 

Sample code testing for the macro __ATARI__ and then executing platform specific code.

 

#ifdef __ATARI__

(void) cgetc();

#endif

 

Now of course I could probably just use scanf(“%c”, &aChar); but where is the fun in that when you have cgetc() ?

 

 

 

 

 

 

 

 

  • Like 1
Link to comment
Share on other sites

  • 1 month later...

Continuing my journey of learning C. Please note the attached for all those who wish to learn like me. Note the code was origionally supplied by Shawn Jefferson. I've just butchered with comments.

 

#include <atari.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <unistd.h>
#include <conio.h>

#define SAVMSC *(unsigned int*) 88 	// create a pointer to save to the scren memory area of the Atari

void __fastcall__ str_to_internal(char *s); // load function to internal function to convert to atari screen format

int main (void) 
{
char *screen; 			// pointer to a char array of labled screen
char txt[15]; 			// create a character array txt with 15 entries

_graphics(2);			// call to Atari graphics mode 2
screen = (char * ) SAVMSC; 	// point screen to memory address of the atari display 

strcpy(txt, "this is atari");	// stdio function to copy the words into the char array
printf("%s\n", txt);		// print to the bottom half of _graphics(2) which is graphics(0)
str_to_internal(txt);		// call function to convert txt to screen format of _graphics(2)
memcpy(&screen[20], txt, 14);	// copy memory contents txt into the reference to the Atari address 88 the first 14 positions. 

(void) cgetc (); 		// wait till any key is pressed and then exit

return 0;				// time to load up memo pad!
}

/* str_to_internal
*
* Converts a string from atascii code to internal character set code.
* Usually we want to do this before writing it to a bitmap.
*/
void __fastcall__ str_to_internal(char *s)
{
unsigned int i;
unsigned int len;


len = strlen(s);
for(i = 0; i < len; i++) {
if (s[i] < 32) 
	s[i] += 64;
else if (s[i] < 96)
	s[i] -= 32;
}

Edited by rchennau
  • Like 1
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...