• Please review our updated Terms and Rules here

Cloning a PAL/HAL (Part 3)

Chuck(G)

25k Member
Joined
Jan 11, 2007
Messages
44,491
Location
Pacific Northwest, USA
Part 2 of this series can be found Here

With the hardware to read the PAL "brute force", all we need is a program to do it.

Code:
//	Read a 10L8 PAL and come up with a truth table.
//
//		Uses the little board with the 393s
//

#include <stdlib.h>
#include <stdio.h>
#include <dos.h>

#define PRINTER 0x378			// printer base port
#define PAL_DATA 0x80			// bit representing the PAL data
#define PAL_RESET 0x01			// reset PAL
#define PAL_INCR  0x02			// increment count
#define PAL_COUNT 1024			// how many total count?
#define PAL_BITS  16			// how many bits out
#define CLOCK_PULSE { outp( PRINTER,3); outp(PRINTER,1); }

FILE *outfile;

void main( int argc, char *argv[])
{

  int i,j;
  unsigned int pd,tbit;

//  Open the output file

  outfile = 0;
  if (argc >= 2)
  {
    outfile = fopen( argv[1], "w");
    if ( !outfile)
    {
      fprintf( stderr, "\nError - could not open %s\n", argv[1]);
      exit(1);
    }
  } // if file specified


//  Set the printer port up.  Hold reset active.  Note that increment
//  happens on low-to-high transition.

  outp( PRINTER, 0);			// clock low, reset active

  outp( PRINTER, 1);			// release reset

  for (i = 0; i < PAL_COUNT; i++)
  {
    pd = 0;
    for ( j = 0; j < PAL_BITS; j++)
    {
      tbit = (inp(PRINTER+1) & 0x80) ? 1 : 0;
      pd |= tbit << j;
      CLOCK_PULSE;
    } // for each bit
    printf( "%04x\n", ~pd);
    if (outfile)
      fprintf( outfile, "%04x\n", ~pd);
  } // for each byte
  if ( outfile)
    fclose( outfile);
  printf( "\nAll done.\n");
} // end of main

This is run under DOS or Win9x, but not under NT/XP/2K/Vista/Win7 because of the OS blocking direct hardware access. However, you could try it on any of the NT family with something like the GIVEO utility (google it!).

This gets us a list of 1,024 entries that looks like this:

Code:
00f4
00f4
00fd
00fd
00fc
00fc
00fd
00fd
00f6
00f6
00ff
00ff
00fe
00fe
00ff
00ff
00fc
00fc
00fd
00fd
00fc
00fc
00fd
00fd
00fe
...and so on...

If we were lazy, we could burn the entire lot into a 1Kx8 bit bipolar PROM, construct a socket adapter and claim we have the PAL function duplicated.

Except that we'd have to fit a 24-pin device in the space of a 20 pin one, and bipolar PROMs are power-hungry and slower than PALs. It might work, but maybe not, depending on the application.

We can duplicate the function in something called a GAL for Generic Array Logic, a later device with much enhanced functionality, but still capable of emulating the older PAL and HAL devices. We'll use the GAL16V8, which datasheet can be found here. You'll note that our PAL10L8 is mentioned among the devices that can be emulated by this IC.

Even better, if you goof, a GAL can be erased and reprogrammed. And they're fiendishly fast when compared to the older logic.

All we need to do is take our 1,024 output values and derive 8 logic equations, one for each of the PAL outputs.

Easier said than done? Not really; stay tuned for Part 4.
 
Back
Top