I want to compile and run a Hello World program in C with the cc65 compiler for an unexpanded VIC-20 model. For printing I'm using the conio.h
function cprintf
, since the conio
implementation requires less memory than stdio
.
The program looks like this (originally suggested by Ulrich von Bassewitz here):
#include <stdlib.h>
#include <conio.h>
int main (void)
{
cprintf ("Hello world!\r\n");
return EXIT_SUCCESS;
}
I compiled with cl65 -t vic20 helloworld.c -o helloworld.prg --mapfile map.txt
The mapfile shows that the compiled code fits, stack starts at 0x1A00, so there is 151 bytes left between 0x18AF and the stack:
Name Start End Size Align
----------------------------------------------------
ZEROPAGE 000002 00001B 00001A 00001
LOADADDR 000FFF 001000 000002 00001
EXEHDR 001001 00100C 00000C 00001
STARTUP 00100D 001046 00003A 00001
ONCE 001047 001052 00000C 00001
CODE 001053 001709 0006B7 00001
RODATA 00170A 001834 00012B 00001
DATA 001835 001868 000034 00001
INIT 001869 001882 00001A 00001
BSS 001883 0018AF 00002D 00001
However when I run the program on the VIC20 emulator of VICE, the program terminates without printing any visible output (except for the "READY." from the OS). It turned out that the text is actually there, but it was printed with white characters on white background, although the foreground color was the default blue.
After adding a clrscr()
command, cprintf
is working:
#include <VIC20> /* this line seems to have no effect */
#include <stdlib.h>
#include <conio.h>
int main (void)
{
clrscr();
cprintf ("Hello world!\r\n");
return EXIT_SUCCESS;
}
On the C64 the printing works independently if there is a clrscr()
or not.
According to the cc65 documentation, conio.h
should work for the VIC20 platform.
What is the reason that cprintf
plays up in the version without the clrscr()
?
#include <VIC20.h>
conio
does not do scrolling; are you sure you want to be using that instead ofstdio
? If you're looking to be a "single screen app" you'd presumably want to be clearing the screen immediately and setting cursor position before every write; if you want to be a more Unixy and "just print stuff to stdout," you'd want to usestdio
instead I think. (Though I admit that stdio'sprintf
not being able to fit into an unexpanded VIC-20 may be an issue. :-))conio
is smaller thanstdio
, but if you want to do C in a limited-memory environment like this, which is fair enough, you're really going to have to know the low-level details of how it gets assembled and linked. So you can't escape from it, but you can use C effectively there if you think of it as sort of a "super-macro" assembler.