rchennau Posted September 28, 2010 Share Posted September 28, 2010 Hey Team Atari , 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() ? 1 Quote Link to comment Share on other sites More sharing options...
rchennau Posted November 23, 2010 Author Share Posted November 23, 2010 (edited) 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 November 23, 2010 by rchennau 1 Quote Link to comment Share on other sites More sharing options...
ilmenit Posted November 23, 2010 Share Posted November 23, 2010 3 parts of my C tutorial for CC65. Written in Polish, however you could use far from perfect Google translate: Part 1 - http://translate.google.com/translate?client=tmpg&hl=pl&u=http%3A//atarionline.pl/v01/index.php%3Fsubaction%3Dshowfull%26id%3D1282312984%26archive%3D%26start_from%3D0%26ucat%3D1%26ct%3Dnowinki&langpair=pl|en Part 2 - http://translate.google.com/translate?client=tmpg&hl=pl&u=http%3A//atarionline.pl/v01/index.php%3Fsubaction%3Dshowfull%26id%3D1282742930%26archive%3D%26start_from%3D20%26ucat%3D1%26ct%3Dnowinki%26amp%253Bid%3D1235271352%26amp%253Bucat%3D1%26amp%253Bsubaction%3Dshowfull&langpair=pl|en Part 3 - http://translate.google.com/translate?client=tmpg&hl=pl&u=http%3A//atarionline.pl/v01/index.php%3Fsubaction%3Dshowfull%26id%3D1282846694%26archive%3D%26start_from%3D20%26ucat%3D1%26amp%253Bid%3D1243163472%26amp%253Barchive%3D%26amp%253Bstart_from%3D0%26amp%253Bucat%3D5%26amp%253Bct%3Dwywiady%26ct%3Dnowinki&langpair=pl|en Do not copy-paste sources directly from the website. They won't compile because of problems with displaying special chars like '<', '>' or '\'. At the end of each article there is a file to download sources and executables. 1 Quote Link to comment Share on other sites More sharing options...
Recommended Posts
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.