Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.apple2.programmer > #4481

Re: Solutions for extending cc65 with Double-Resolution Apple II Graphics (links included)

From "Bill Buckels" <bbuckels@mts.net>
Newsgroups comp.sys.apple2.programmer
Subject Re: Solutions for extending cc65 with Double-Resolution Apple II Graphics (links included)
Date 2018-03-30 03:09 -0500
Organization Aioe.org NNTP Server
Message-ID <p9krav$g0m$1@gioia.aioe.org> (permalink)
References (1 earlier) <p9brk3$m7g$1@news.albasani.net> <p9c01p$1r5g$1@gioia.aioe.org> <p9ebrp$gor$1@news.albasani.net> <p9eobo$gqg$1@gioia.aioe.org> <p9jotq$q8a$1@news.albasani.net>

Show all headers | View raw


"Oliver Schmidt" <ol.sc@web.de> wrote:
>An Apple ][+ program displaying all *.hgr images in a directory:
> https://github.com/cc65/cc65/blob/master/testcode/lib/apple2/hgrshow.c

Here's one that uses a timing loop and a script, and filetype. And does not 
use tgi. Uses buffered I/O and inline assembly.

http://www.appleoldies.ca/cc65/programs/hgr/


/* ------------------------------------------------------------------------
System       : cc65 cross-development environment
Platform     : Apple IIe 128K PRODOS 8
Program      : hishow(C) Copyright Bill Buckels 2014.
               All rights reserved.

Description  : Apple //e ProDOS 8 HGR Slideshow Program

               HGR formats supported - BIN files only.

               This program builds two executables based on conditional
               compilation. The code for either is almost exactly the
               same, but they use two different memory configurations
               based on whether they use HGR Screen One or Screen Two.

               The hishow variation that uses Screen One runs at $4000
               directly above Screen One at $2000 and has a good deal more
               memory than the hishow variation that uses Screen Two which
               runs at $0803 under Screen Two (at $4000).

               Either can be launched using Oliver Schmidt's loader.system
               or from BASIC.SYSTEM with the BRUN command.

Date Written : November 2014
Revision     : 1.0 First Release

Licence      : You may use this program for whatever you wish as long
               as you agree that Bill Buckels has no warranty or
               liability obligations whatsoever from said use.
------------------------------------------------------------------------ */

#ifndef HGR_SCREEN_ADDRESS
#define HGR_SCREEN_ADDRESS 0x2000
#else
#if HGR_SCREEN_ADDRESS != 0x4000
#define HGR_SCREEN_ADDRESS 0x2000
#endif
#endif

#ifndef __APPLE2__
#define __APPLE2__
#endif

#include <stdio.h>
#include <errno.h>
#include "_file.h"
#include <stdlib.h>
#include <string.h>
#include <ctype.h>
#include <conio.h>

/* http://www.unix.com/man-page/posix/3/opendir/ */
/* files in current directory */
#include <dirent.h>

#include <apple2enh.h>

unsigned delay = 5;

#pragma optimize (push,off)
void hireson(void)
{
    asm("sta $c057"); /* HI-RES */
#if HGR_SCREEN_ADDRESS == 0x4000
    asm("sta $c055"); /* PAGE TWO */
#else
    asm("sta $c054"); /* PAGE ONE */
#endif
 asm("sta $c050"); /* GRAPHICS */
    asm("sta $c052"); /* GRAPHICS ONLY, NOT MIXED */
}
#pragma optimize (pop)


void hiresclear(void)
{
    /* clear main screen memory */
    memset((char *)HGR_SCREEN_ADDRESS,0,8192);
}


#pragma optimize (push,off)
void hiresoff(void)
{
    asm("sta  $c051"); /* TEXT - HIDE GRAPHICS */
    asm("sta  $c054"); /* PAGE ONE */

}
#pragma optimize (pop)


/* The following loads a non-compressed
   BSaved BIN Image Format hi-res graphics image.

*/
int bload(char *name)
{
 FILE *fp;
 int status=0;

 fp = fopen(name,"rb"); /* open a binary file */
 if (fp == NULL)return -1;
 if (fread((char *)HGR_SCREEN_ADDRESS,1,8192,fp) < 8184) status = -2;
 fclose(fp);

 return status;
}


/* 1MHZ timing loop settings - increase for faster machines */
#define YTIME 60L
#define XTIME 32L
char wait(unsigned duration)
{
    char c = 0;
    long y, x;

    while (duration > 0) {
        for (y=0;y<YTIME;y++) {
            for (x=0;x<XTIME;x++) {
                if (kbhit()) {
                    c = cgetc();
                 if (c > 47 && c < 58) {
      delay = (c-48) * 5;
     }
                    /* clear keyboard buffer */
                    while (kbhit())cgetc();
                    return c;
                }
            }
        }
        duration--;
    }
    return c;
}

/* the following function creates a list of the hi-res
   files in the current directory, in Apple sequential text format. */
FILE *makepiclist()
{
    FILE *fp = NULL;
    int err, cnt = 0, idx, jdx, found;
    DIR *dir;
    struct dirent *dp;

    extern unsigned char _filetype;
    extern unsigned _auxtype;

    /* read files in current directory */
    if ((dir = opendir (".")) == NULL) return NULL;

    /* remove piclist if it already exists */
    if((fp=fopen("PICLIST","r"))!=NULL) {
        fclose(fp);
        remove("PICLIST");
    }

    /* set file to sequential text */
    _filetype = 0x04;
    _auxtype = 0x0000;

    if((fp=fopen("PICLIST","w"))==NULL) {
        closedir(dir);
        return NULL;
    }

    /* write the list to disk */
    while ((dp = readdir (dir)) != NULL) {
  /* check for bin files */
  if (dp->d_type != 0x06) continue;
  /* load address 0x2000 or 0x4000 */
  if (dp->d_auxtype  != 0x2000 && dp->d_auxtype != 0x4000) continue;
  /* check file size */
  /* there is no way to tell the difference between a
  hi-res bsaved image and a double hi-res bin or aux image */
  found = 0;
  if (dp->d_size > 8183  && dp->d_size < 8193) found = 1;
  if (found == 0) continue;

        /* get extension if any */
        jdx = 999;
        for (idx = 0; dp->d_name[idx] != 0; idx++) {
            if (dp->d_name[idx] == '.') {
                jdx = idx+1;
            }
        }

        if (jdx != 999) {
            found = 0;
            for (;;) {
                /* bypass AUX files - I only want BIN files in my list */
                if (toupper(dp->d_name[jdx])   != 'A') break;
                if (toupper(dp->d_name[jdx+1]) != 'U') break;
                if (toupper(dp->d_name[jdx+2]) != 'X') break;
                found = 1;
                break;
            }
            if (found == 1) continue;
        }

        /* if out of disk space quit writing to piclist */
        err = fprintf(fp,"%s%c",dp->d_name, (char)13);
        if (err < 0) break;
        cnt++;
    }

    fclose(fp);
    closedir(dir);

    if (cnt == 0) {
        /* if no files found or no filenames written remove empty piclist */
        remove("PICLIST");
        fp = NULL;
    }
    else {
        /* otherwise open and return the piclist */
        fp = fopen("PICLIST","r");
    }

    return fp;
}

/* fgets for Apple II text files - read native apple II text files properly!
   the cc65 version doesn't! Which means that you need to use unix text 
files
   unless you roll your own fgets like this one which does both... */
char* __fastcall__ fgets (char* s, unsigned size, register FILE* f)
{
    register char* p = s;
    unsigned i;
    int c;

    if (size == 0) {
        /* Invalid size */
        return (char*) _seterrno (EINVAL);
    }

    /* Read input */
    i = 0;
    while (--size) {

        /* Get next character */
        if ((c = fgetc (f)) == EOF) {
            /* Error or EOF */
            if ((f->f_flags & _FERROR) != 0 || i == 0) {
                /* ERROR or EOF on first char */
                *p = '\0';
                return 0;
            } else {
                /* EOF with data already read */
                break;
            }
        }

        /* One char more */
        *p = c;
        ++p;
        ++i;

        /* Stop at end of Apple II or Unix Text File line */
        if ((char)c == (char)13 || (char)c == (char)10) {
            break;
        }
    }

    /* Terminate the string */
    *p = '\0';

    /* Done */
    return s;
}

int main(void)
{
    FILE *fp;
    int status = 0, i;
    char picname[66], c;
    unsigned cnt = 0;

    /* allow delay change from file if found */
    if((fp=fopen("delay.txt","r"))!=NULL) {
       if (fgets(picname,66,fp) != NULL) delay = (unsigned)atoi(picname);
       fclose(fp);
       printf("Delay Over-ride %d. Press any key...\n",delay);
       cgetc();
    }

    /* try to create a piclist if it does not exist */
    if((fp=fopen("PICLIST","r"))==NULL) {

        fp = makepiclist();
        if (fp == NULL) {
            printf("Can't open PICLIST! Press any key...");
            cgetc();
            return 0;
        }
    }
    fclose(fp);

    clrscr();

    /* turn-on hi-res and clear the hgr screen */
    hireson();
    hiresclear();

    /* default */
    /* display each hgr pic for 5 seconds (default) or advance on
       a key press. If ESC is pressed, exit */

    for (;;) {
        while (fgets(picname,66,fp) != NULL) {
            /* load picture */
            /* skip line-feeds in MS-DOS text */
            /* skip comment lines and blank lines if any */
            if (picname[0] < (char)47) continue;
            /* remove trailing eol or unwanted characters */
            for (i=0;picname[i]!=0;i++) {
    if (picname[i] < (char)32 || picname[i] > (char)122) {
     picname[i] = 0;
     break;
    }
   }

            if (bload(picname) < 0) continue;
            if (cnt++ > 100) cnt = 1;
            if (delay == 0) {
                /* if delay == 0 advance on keypress only */
                /* if ESC is pressed then quit */
                c = cgetc();
                if (c == 27) {
                    status = -1; break;
                }

                if (c > 48 && c < 58) {
     delay = (c-48) * 5;
                 while (kbhit())cgetc();
     continue;
    }

            }
            else {
             /* flush keyboard buffer */
             if (kbhit()) c = cgetc();
             else c = 0;

                if (c == 27) {
                    status = -1; break;
                }

                if (c > 47 && c < 58) {
     delay = (c-48) * 5;
    }


   }
            while (kbhit())cgetc();

            if (delay == 0) continue;

            /* advance on timeout or advance on keypress */
            /* if ESC is pressed then quit */
            if (wait(delay)==27) {
                status = -1;
                break;
            }

        }
        fclose(fp);
        if (status != 0) break;

        if (cnt < 1) {
            fp = makepiclist();
            if (fp == NULL) break;
            continue;
        }

        /* no rewind in cc65, so we must
           close and re-open the piclist when we
           reach the end */
        if((fp=fopen("PICLIST","r"))==NULL) break;
    }

    hiresclear();
    hiresoff();
    clrscr();

    if (status == 0 && cnt == 0) {
        printf("Can't create PICLIST! Press any key...");
        cgetc();
    }

    return 0;
}

Back to comp.sys.apple2.programmer | Previous | Next — Previous in thread | Find similar | Unroll thread


Thread

Solutions for extending cc65 with Double-Resolution Apple II Graphics (links included) "Bill Buckels" <bbuckels@mts.net> - 2018-03-25 15:14 -0500
  Re: Solutions for extending cc65 with Double-Resolution Apple II Graphics (links included) ol.sc@web.de (Oliver Schmidt) - 2018-03-26 22:18 +0000
    Re: Solutions for extending cc65 with Double-Resolution Apple II Graphics (links included) "Bill Buckels" <bbuckels@mts.net> - 2018-03-26 18:34 -0500
      Re: Solutions for extending cc65 with Double-Resolution Apple II Graphics (links included) ol.sc@web.de (Oliver Schmidt) - 2018-03-27 21:08 +0000
        Re: Solutions for extending cc65 with Double-Resolution Apple II Graphics (links included) "Bill Buckels" <bbuckels@mts.net> - 2018-03-27 19:41 -0500
          Re: Solutions for extending cc65 with Double-Resolution Apple II Graphics (links included) ol.sc@web.de (Oliver Schmidt) - 2018-03-29 22:21 +0000
            Re: Solutions for extending cc65 with Double-Resolution Apple II Graphics (links included) "Bill Buckels" <bbuckels@mts.net> - 2018-03-30 02:51 -0500
            Re: Solutions for extending cc65 with Double-Resolution Apple II Graphics (links included) "Bill Buckels" <bbuckels@mts.net> - 2018-03-30 03:09 -0500

csiph-web