# Re: 6702 chip

From: Rhialto <rhialto_at_falu.nl>
Date: Sat, 26 May 2012 10:14:41 +0200
Message-ID: <20120526081441.GB10175@falu.nl>
```On Fri 25 May 2012 at 10:49:50 +0200, Rhialto wrote:
> I've seen a different pattern by now, I think.
> Still with basically the same program as before;
> I wrote 6 times 9 (%1001), then once 1, then many times 9 again.
> The pattern for bit 3 (period 8) was
>
> 0 0 0 0 0 0
> 0
> 1 1 1 1 1 1 0 1  0 0 0 0 0 0 1 0  1 1 1 1 1 1 0 1  0 0 0 0 0 0 1 0 etc
>
> This is 2 changes in the period of 8.
> Of course I've caused 2 changes with this; perhaps I should simplify
> the program.

I've done a series of tests with an odd sequence that changes only once.
I tested bit 1 only.

The first sequence of tests wrote 3 a variable number of times, then 1.
These results were boring since the output of bit 1 never deviated from
its 111 000 pattern.

Writing first some 1s, then some 3s was more interesting. (To better
show the period of 3 I now show the initial output value here)

output of bit 1 only, in groups of 3:

1					initial value
1					1 time 1
1 011 011 011 011 ...			many times 3
^

1
11					2 times 1
001 001 001 001...
^

1
11 0					3 times 1
00 000 000 000...
^

1
11 00					4 times 1
0 100 100 100 100...
^

1
11 000					5 times 1
110 110 110 110...
^

1
11 000 1				6 times 1
11 111 111 111...
^

1
11 000 11				7 times 1
1 011 011 011...
^

I noticed here that after writing the changed value, the original
pattern of 000 111 goes on for a while, and only in the 3rd read after
the change there is a difference. I've put ^ below that bit for each
case.

In my model of the 6702 I've replaced William's shift register with a
complicated reload with a circular register. If a 1 shifts out, it
toggles the output bit, and it comes back on the left.

A changing input bit also changes the bit on the left (so its change
will be visible only in the future).

That model gives  me the code below, which predicts the patterns above,
and the more complicated one that I've quoted. Unfortunately it doesn't
pass the validation routine but I haven't looked into the difference.

#define MAGIC 0xd6		/* 214 = (128 + 64 + 16 + 4 + 2) = %1101 0110 */

static int a[8] = { 0, 0, 0, 0, 0, 0, 0, 0 };
static int reload[8] = { 1<<6, 1<<3, 1<<7, 1<<8, 1<<1, 1<<3, 1<<5, 1<<2 };
static int val = MAGIC;
static int prevodd;
static int canchange;

unsigned char Read6702( void ) {

return val;

} // End of function Read6702

void Reset6702( void ) {
int i;

for (i = 0; i < 8; i++) {
if ((1 << i) & (MAGIC | 1))
else
a[i] = 0;
}
val = MAGIC;
prevodd = 1;
}

and to calculate the next value:

int v = val;
int changed = prevodd ^ input;

/* loop over all 8 output bits / shift registers */
for (i = 7; i >= 0; i--, mask >>= 1) {
if (a[i] & 1) {
a[i] ^= reload[i]; /* wrap bit around */
}
/* If the input bit changed */
}
a[i] >>= 1;
}

prevodd = input;
val = v;
-Olaf.
--
___ Olaf 'Rhialto' Seibert  -- There's no point being grown-up if you
\X/ rhialto/at/xs4all.nl    -- can't be childish sometimes. -The 4th Doctor

Message was sent through the cbm-hackers mailing list
```