#include #include #include static void generate_keyhandler(void) { printf("9000 REM ******************\n"); printf("9002 REM * GET KEYPRESSES *\n"); printf("9004 REM ******************\n"); printf("9006 N%%=1\n"); /* memory location -16384 holds keyboard strobe */ /* Loop until a key is pressed. */ printf("9008 X=PEEK(-16384): IF X < 128 THEN 9008\n"); /* get the key value, convert to ASCII */ printf("9010 X=PEEK(-16368)-128\n"); /* Exit if escape or Q pressed */ printf("9020 IF X=27 OR X=81 THEN END\n"); /* increment page count if space or -> */ printf("9030 IF X=21 OR X=32 THEN P%%=P%%+1:N%%=3\n"); /* decrement page count if <- */ printf("9040 IF X=8 THEN P%%=P%%-1:N%%=2\n"); /* keep from going off the end */ printf("9050 IF P%%>TP%% THEN P%%=TP%%\n"); printf("9060 IF P%%<0 THEN P%%=0\n"); printf("9070 RETURN\n"); } static void generate_footer(char *left, char *center, int cols) { int center_len,center_count,i,right_count; printf("10000 REM ****************\n"); printf("10001 REM * PRINT FOOTER *\n"); printf("10002 REM ****************\n"); /* make text black on white; move to bottom line */ printf("10003 HOME: INVERSE : VTAB 24\n"); printf("10005 X$=STR$(P%%)+\"/\":X$=X$+STR$(TP%%)\n"); printf("10007 L%%=LEN(X$)\n"); printf("10010 PRINT \"%s",left); center_len=strlen(center); center_count=(cols-center_len)/2; center_count-=strlen(left); if (center_count<0) { fprintf(stderr,"Error! can't fit text in footer\n"); center_count=0; } for(i=0;i