/* $Id: diskii_nybble.c,v 1.3 2005/03/21 22:13:00 eric Exp eric $ Copyright 2005 Eric Smith diskii_nybble is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License version 2 as published by the Free Software Foundation. Note that I am not granting permission to redistribute or modify diskii_nybble under the terms of any later version of the General Public License. diskii_nybble is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details. You should have received a copy of the GNU General Public License along with this program (in the file "COPYING"); if not, write to the Free Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111, USA. */ #include #include #include #include bool valid_nybble (uint8_t n, int sectors) { uint8_t n2; int i; int c; // A valid nybble must always have the MSB set. if (! (n & 0x80)) return false; // Aside from the D5 and AA nybbles used for address and data marks, // valid nybbles always have at least one pair of consecutive one // bits (not including the MSB). This is a somewhat arbitrary // restriction, though in the 16-sector boot ROM it helps to reduce // the number of valid nybbles in a manner that simplifies automatic // table generation by the boot PROM. n2 = n; c = 0; for (i = 0; i < 6; i++) { if ((n2 & 0x03) == 0x03) c++; n2 >>= 1; } if (c < 1) return false; if (sectors == 13) { // Valid 13-sector nybbles never have two consecutive zero bits. n2 = n; for (i = 0; i < 6; i++) { if ((n2 & 0x03) == 0) return (false); n2 >>= 1; } return true; } if (sectors != 16) return false; // Valid 16-sector nybbles never have three consecutive zero bits. n2 = n; for (i = 0; i < 5; i++) { if ((n2 & 0x07) == 0) return (false); n2 >>= 1; } // Valid 16-sector nybbles never have more than one pair of // consecutive zero bits. This is a somewhat arbitrary restriction // to reduce the number of valid nybbles in a manner that simplifies // with automatic table generation by the boot PROM. n2 = n; c = 0; for (i = 0; i < 6; i++) { if ((n2 & 0x03) == 0) c++; n2 >>= 1; } if (c > 1) return (false); return (true); } int main (int argc, char *argv[]) { int c; int sectors; uint8_t n; for (sectors = 13; sectors <= 16; sectors += 3) { printf ("%d sector nybbles:\n", sectors); c = 0; for (n = 0x80; n >= 0x80; n++) { if (valid_nybble (n, sectors)) { if ((c % 10) == 0) printf (" %2d: ", c); printf (" %02x", n); if ((++c % 10) == 0) printf ("\n"); } } if (c % 10) printf ("\n"); printf ("\n"); } exit (0); }