I didn’t want to go into a whole lot of C basics in my previous posts, just refreshing my memory on arrays and pointers was the main objective. In the next series of posts I will be showing the progression of the conversion of my Action! library into C (CC65). In this first post, I convert and demonstrate routines that convert from Atari 8 bit ATASCII codes to internal codes and back. The routines themselves (source code) will be presented with the entire library once the conversion is complete.
Why do I want to convert to internal code from ATASCII? Simple, direct screen I/O. With the internal code, a byte can be placed directly into screen memory without going through the I/O routines, making it much faster.
This is the source for the test program. The routines being tested are StrAI() and StrIA(). StrAI() converts a string from ATASCII code to internal code. StrIA() converts from internal code to ATASCII. These routine require you to pass the length of the string (char array) to be converted. This is required because the internal code for space is 0, which is the C string termination value. When dealing with Atari internal coded strings, most C string functions won’t perform as expected if there is a space in the string.
// ------------------------------------------------------------
// Program: strai.c
// Desc...: String ATASCII->Internal demonstration
// Author.: Ripdubski
// Date...: 202208
// Notes..: cl65 -v -O -t atari strai.c -o strai.xex
// ------------------------------------------------------------
// Pull in include files
#include <stdio.h>
#include <conio.h>
#include <string.h>
#include <atari.h>
#include "a8defines.h"
// ------------------------------------------------------------
// Func...: void StrAI(unsigned char *pS, byte bS)
// Desc...: Converts string from ATASCII code to internal code
// Param..: pS = pointer to string to convert
// bS = size (number) of chars in string to convert
// Notes..: Manual iteration so we can process space which has
// 0 as internal code (c string terminator).
// ------------------------------------------------------------
void StrAI(unsigned char *pS, byte bS)
{
// REDACTED until release
}
// ------------------------------------------------------------
// Func...: void StrIA(unsigned char *pS, byte bS)
// Desc...: Converts string from internal code to ATASCII code
// Param..: pS = pointer to string to convert
// bS = size (number) of chars in string to convert
// Notes..: Manual iteration so we can process space which has
// 0 as internal code (c string terminator).
// ------------------------------------------------------------
void StrIA(unsigned char *pS, byte bS)
{
// REDACTED until release
}
// ------------------------------------------------------------
// Func...: void main(void)
// Desc...: Main routine
// ------------------------------------------------------------
void main(void)
{
// Declare char and char array
char ca[11];
// Setup screen
clrscr();
printf("-[CC65 ATASCII->Internal Tests]---------");
// Show char array and address
printf("\nCHAR ARRAY\n");
strcpy(ca, "1234567890");
printf(" ca (array): %s\n", ca);
printf(" &ca address: %p\n", &ca);
// Convert to internal
StrAI(ca, 10);
printf(" ca internal: %s\n", ca);
// Convert to atascii
StrIA(ca, 10);
printf(" ca atascii: %s\n", ca);
// Wait for a keypress
while (! kbhit()) { };
// Exit
return;
}
Screenshot of the test program showing the successful conversion from ATASCII to internal and back to ATASCII:
