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


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

Re: QuickViewDHGR - A simple Apple II graphics viewer

From "Bill Buckels" <bbuckels@mts.net>
Newsgroups comp.sys.apple2.programmer
Subject Re: QuickViewDHGR - A simple Apple II graphics viewer
Date 2018-03-20 02:12 -0500
Organization Aioe.org NNTP Server
Message-ID <p8qc86$n3d$1@gioia.aioe.org> (permalink)
References <b1891b88-d1ec-4c9e-94f7-b42aeeab9997@googlegroups.com> <8a5ee1cb-afd1-4023-bb03-93595ccf1944@googlegroups.com>

Show all headers | View raw


<gids.rs@sasktel.net> wrote:

>there are no Packbytes decompressors for the II+/IIe/IIc

If that were even true, how do you explain this code then... (written in 
Aztec C65 for the Apple II) see below...

( distributed with http://www.aztecmuseum.ca/extras/B2S.zip see the 
following thread
https://groups.google.com/forum/#!topic/comp.sys.apple2.programmer/JJ3blfdKBCI )

It is perfectly trivial to compile this in either cc65 or in Aztec C65 for 
the II+/IIe/IIc... taken from the source code for pntlode.c...


/* the following is a modified version of Andy McFadden's UnpackBytes from
   CiderPress's SHR image viewer.

   CiderPress is written in C++ for Win32 so obviously this has been
   back-ported and changed somewhat to work in an 8 bit Aztec C program but
   the algorithm is the same and so is the control structure...

   Since Andy is an expert in these matters there is no point in reinventing
   the wheel. The Ciderpress SHR code is well commented and when combined
   with Apple's technical notes provides a very rich environmnent to learn
   all about working with these images. Thank you Andy for taking the time
   to pass-on this knowledge.

   */


/*
 * Unpack the Apple PackBytes format.
 *
 * Format is:
 * <flag><data> ...
 *
 * Flag values (first 6 bits of flag byte):
 * 00xxxxxx: (0-63) 1 to 64 bytes follow, all different
 * 01xxxxxx: (0-63) 1 to 64 repeats of next byte
 * 10xxxxxx: (0-63) 1 to 64 repeats of next 4 bytes
 * 11xxxxxx: (0-63) 1 to 64 repeats of next byte taken as 4 bytes
 *    (as in 10xxxxxx case)
 *
 * Pass the open file handle in "fh", expected packed source
 * length in "srcLen", and expected unpacked output size in "destRem".
 *
 * Returns 0 on success, nonzero if the buffer is overfilled or underfilled.
 */

/* read video data in 7680 byte chunks */
#define BLOCK_SIZE 7680


int UnpackBytes(fh, destRem,srcLen)
int fh;
unsigned destRem,srcLen;
{

 unsigned dest;
 unsigned char ch, *auxbuf,*buf;
 int i, flag, count, bytes, status = 0;

    /* use hi-res screen2 as a buffer area */
    buf = (unsigned char *)0x4000;
    auxbuf = (unsigned char *)0x5E00;

    /* make sure we can at least read the file...
       I am only trying for 256 bytes for now. */
 if (read(fh,buf,BLOCK_SIZE) < 256) return -1;
 bytes = 0;

 /* set destination to scanline 0 in auxiliary memory area */
 dest = 0x2000;

 while (srcLen > 0) {

  ch = buf[bytes]; bytes++;
  if (bytes == BLOCK_SIZE) {
   read(fh,buf,BLOCK_SIZE);
   bytes = 0;
  }

        flag = (0xc0 & ch);
        count = (0x3f & ch) +1;
  srcLen--;

  if (flag == 0x00) {
   /* 1 to 64 bytes follow, all different */
   for (i = 0; i < count; i++) {
    if (srcLen < 1 || destRem < 1) {
     status = -2; break;
    }
    auxbuf[i] = buf[bytes]; bytes++;
    if (bytes == BLOCK_SIZE) {
     read(fh,buf,BLOCK_SIZE);
     bytes = 0;
    }
    srcLen--;
    destRem--;
   }


   if (i!=0){
    maintoaux(0x5e00,0x5dff+i,dest); dest+=i;
   }
            if (status != 0) return status;
   }
   else if (flag == 0x40) {
   /* 1 to 64 repeats of next byte */
   if (srcLen < 1) return -3;
   ch = buf[bytes]; bytes++;
   if (bytes == BLOCK_SIZE) {
    read(fh,buf,BLOCK_SIZE);
    bytes = 0;
   }
   srcLen--;
   for (i = 0; i < count; i++) {
    if (destRem < 1) {
     status = -3; break;
    }
    auxbuf[i] = ch;
    destRem--;

   }
   if (i!=0){
    maintoaux(0x5e00,0x5dff+i,dest); dest+=i;
   }
            if (status != 0) return status;
  }
  else if (flag == 0x80) {

      /* 1 to 64 repeats of next 4 bytes */
   if (srcLen < 4 || destRem < 4) return -4;
   srcLen -= 4;
            for (i = 0; i < 4; i++) {
    auxbuf[i] = buf[bytes]; bytes++;
    if (bytes == BLOCK_SIZE) {
     read(fh,buf,BLOCK_SIZE);
     bytes = 0;
    }
   }

   for (i = 0; i < count; i++) {
    if (destRem < 4) return -4;
    destRem -= 4;
    maintoaux(0x5e00,0x5e03,dest); dest+=4;
   }
  }
  else {


   /* flag == 0xc0)
      1 to 64 repeats of next byte taken as 4 bytes */

   if (srcLen < 1 || destRem < 4) return -5;

   for (i = 0; i < 4; i++) auxbuf[i] = buf[bytes];

   for (i = 0; i < count; i++) {
    if (destRem < 4) return -5;
    destRem -= 4;
    maintoaux(0x5e00,0x5e03,dest); dest+=4;
   }

   bytes++;
   if (bytes == BLOCK_SIZE) {
    read(fh,buf,BLOCK_SIZE);
    bytes = 0;
   }
   srcLen--;
  }


 }

 /* require that we completely fill the buffer */
 if (destRem > 0) status = -6;

 return status;
}



and with the advent of LZ4 (as well as other compression schemes), which has 
a way higher compression ratio and way faster decompression speed, it no 
longer makes sense.

Fourth, Apple no longer supports us

Fifth, it will be easier to implement and identify screens and not necessary 
to load the file first to load a byte from a screen hole


A filetype of $08 can be used in conjunction with the Aux type to indicate 
all modes of screens that can be created on the Apple II.

I am asking the the Apple II community to adopt the file type of $08 with 
the following Aux values.



Hi-byte - only one bit can be turned on at a time

bit #7 ($80) - on = SHR graphics - mostly for Carte Blanche cards on a IIe
       - or can be considered reserved
       - or reserved for Fadden's file type and other specialty file types
bit #6 ($40) - on = Dbl hi-res - with this bit on would get $40xx
bit #5 ($20) = on = Hi-res - would get $20xx
bit #4 ($10) = on = Dbl lo-res - would get $10xx
bit #3 ($08) = on = lo-res - would get $08xx
bit #2 ($04) = on = 80-col text screen
bit #1 ($02) = on = 40-col text screen
bit #0 ($01) = on = Data block


Lo-byte - identifiers for following compression types


$00 = uncompressed B/W (hi-byte $20,40,80)
$01 = uncompressed color (hi-byte $08,$10,$20,40,80)

$00 = Normal Text Screen RLE (Hi byte is 1, 2 or 4)
$01 = Mouse Text screen RLE (Hi byte is 1, 2 or 4)
$02 = Text file compression using Prodos method (Hi byte is 1, 2 or 4)
$03 = Text file compression using dictionary libraries (Hi byte is 1, 2 or 
4)

$66 = fhpack (with hi byte set to $80)

* Mainly related to Hi-res compression
$80 = RLE
$81 = Axe Packer
$82 = Beagle Scrunch

* Mainly related to Dbl hi-res compression
$90 = Beagle Dbl Scrunch
$91 = Pic Pac Dbl Res

* Mainly related to Super Hi-res Compression used when a Carte Blanche card 
is installed in a IIe

$C0 = Apple Packbytes  (Hi byte $20 for hi-res $40 for dhr, $80 for super 
hi-res)
$C1 = Paintworks
$C2 = Apple Preferred
$C3 = Dream Graphics

* Mainly related to Non platform specific compression


$E0 = LZ4
$E1 = LZW
$E2 = LZSS
$E3 = LZ? reserved
$E4 = LZ? reserved
$E5 = Huffman

* Specialty
$F0 = Zip
$F1 = gzip
$F2 = 7z
$F3 = Exocrunch




Included here is my file type and Aux type changer to batch change all 
binary files to $08 and Aux type calculated by using the above chart.

To calculate the Aux value, get the hi-byte first beside the type of screen 
it is.  i.e. dbl hi-res has $40.  Then get the lo byte value $00 for 
uncompressed b/w or $01 for uncompressed color or one of the compression 
bytes.  Put the two together to get a 16-bit value.  In this case $4000 
would be an uncompressed b/w dbl hi-res image.  Enter the decimal value for 
AX in line #6:  $4000 = 16384

Next do a CATALOG and put the last 5 digits of the ENDFILE in L$ in line #5. 
And last, change line #6 to the decimal values for the file type and decimal 
value for the Aux type for each file to be changed to.  And RUN the program.

This will batch change all binary files with a file length of $4000 (16384) 
over to the $08 file type and an Aux value of $4000 to indicate an 
uncompressed b/w dbl hi-res image.

  5 FT$ = "BIN":L$ = "04000": REM change files from File Type and with 
ENDFILE value
  6 FT = 8:AX = 16384: REM change files to the File Type and to the value 
from the chart above
 10 D$ =  CHR$ (4)
 15  IF  PEEK (897) <  > 128 THEN  PRINT D$"- FT.AUX"
 30  ONERR  GOTO 70
 35  PRINT D$"PREFIX": INPUT V$
 40  PRINT D$"OPEN"V$",TDIR": PRINT D$"READ"V$
 45  INPUT A$: INPUT A$: INPUT A$
 50  FOR X = 0 TO 1: INPUT A$
 55 F$ = MID$(A$,1,15) : FOR I = 1 TO 15: IF MID$(F$,I,1) = " " THEN F$ = 
LEFT$(F$,I-1): I = 15
 57 NEXT
 60 IF MID$(A$,18,3) <> FT$ OR MID$(A$,67,5) <> L$ THEN X=0: NEXT
 60  & F$,FT,AX :N = N + 1:X = 0: NEXT
 65  POKE 216,0: PRINT D$"CLOSE"N$
 70 PRINT N-1 " files processed"
SAVE FT.CHANGER

CALL-151
0300:A9 4C 8D F5 03 A9 10 8D F6 03 A9 03 8D F7 03 60
0310:20 74 03 20 B7 00 C9 2C D0 03 20 BE DE 20 7B DD
0320:20 FD E5 C9 00 F0 04 C9 40 90 05 A2 B0 4C 12 D4
0330:A8 8C 80 02 88 B1 5E 99 81 02 88 10 F8 20 00 BF
0340:C4 80 03 B0 2C 20 4C E7 8A A0 04 99 80 03 A9 07
0350:8D 80 03 20 BE DE 20 67 DD 20 52 E7 A0 05 A5 50
0360:99 80 03 A5 51 99 81 03 20 00 BF C3 80 03 B0 01
0370:60 4C D0 03 A9 0A 8D 80 03 4C 06 E3 00 00 00 00
0380:0A 80 02 00 00 00 00 00 00 00 00 00 00 00 00 00
0390:00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00
3D0G
BSAVE FT.AUX,A$300,L$A0


Enjoy! 

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


Thread

QuickViewDHGR - A simple Apple II graphics viewer markpmlim@yahoo.com.sg - 2018-03-18 23:34 -0700
  Re: QuickViewDHGR - A simple Apple II graphics viewer gids.rs@sasktel.net - 2018-03-19 13:59 -0700
    Re: QuickViewDHGR - A simple Apple II graphics viewer markpmlim@yahoo.com.sg - 2018-03-19 18:25 -0700
    Re: QuickViewDHGR - A simple Apple II graphics viewer "Bill Buckels" <bbuckels@mts.net> - 2018-03-20 02:12 -0500
      Re: QuickViewDHGR - A simple Apple II graphics viewer "Bill Buckels" <bbuckels@mts.net> - 2018-03-20 02:19 -0500
        Re: QuickViewDHGR - A simple Apple II graphics viewer James Davis <JPD.Enterprises@outlook.com> - 2018-03-20 11:55 -0700
      Re: QuickViewDHGR - A simple Apple II graphics viewer gids.rs@sasktel.net - 2018-03-20 09:59 -0700
        Re: QuickViewDHGR - A simple Apple II graphics viewer markpmlim@yahoo.com.sg - 2018-03-20 18:21 -0700
          Re: QuickViewDHGR - A simple Apple II graphics viewer markpmlim@yahoo.com.sg - 2018-04-17 00:15 -0700
            Re: QuickViewDHGR - A simple Apple II graphics viewer markpmlim@yahoo.com.sg - 2018-05-13 18:10 -0700
              Re: QuickViewDHGR - A simple Apple II graphics viewer markpmlim@yahoo.com.sg - 2018-09-24 04:22 -0700
    Re: QuickViewDHGR - A simple Apple II graphics viewer gids.rs@sasktel.net - 2018-03-20 09:04 -0700
      Re: QuickViewDHGR - A simple Apple II graphics viewer gids.rs@sasktel.net - 2018-03-20 20:53 -0700
    Re: QuickViewDHGR - A simple Apple II graphics viewer gids.rs@sasktel.net - 2018-03-20 09:31 -0700
      Re: QuickViewDHGR - A simple Apple II graphics viewer markpmlim@yahoo.com.sg - 2018-03-20 14:35 -0700
  Re: QuickViewDHGR - A simple Apple II graphics viewer "Bill Buckels" <bbuckels@mts.net> - 2018-03-20 01:01 -0500
  Re: QuickViewDHGR - A simple Apple II graphics viewer "Bill Buckels" <bbuckels@mts.net> - 2018-03-21 04:23 -0500

csiph-web