MicroQuiz: how to speed up increment?

You can talk about almost anything that you want to on this board.

Moderator: Moderators

Post Reply
User avatar
aa-dav
Posts: 106
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

MicroQuiz: how to speed up increment?

Post by aa-dav » Wed Oct 14, 2020 10:05 pm

First handheld games of Nintendo - Game & Watch use 4-bit Sharp microcontrollers of 5xx series.
For example: Donkey Kong game uses chip Sharp SM-510.
It has segmented program address space and PC inside segment has 6 bits.
Someone could suppose that simpliest operation with 6-bit counter is increment and operation of calculation of address of next instruction is as simple as increment because it is increment.

But no! Creators of SM-510 belived that increment of 6 bit counter is too slow and they speed up it.
Do you know how this can be possible? :)

lidnariq
Posts: 9796
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

Re: MicroQuiz: how to speed up increment?

Post by lidnariq » Wed Oct 14, 2020 10:36 pm

I assume it's the same LFSR design used in the later SM590s that were used for the NES's CIC. Both 6- and 7- bit LFSRs only require a single XOR gate.

User avatar
aa-dav
Posts: 106
Joined: Tue Apr 14, 2020 9:45 pm
Location: Russia

Re: MicroQuiz: how to speed up increment?

Post by aa-dav » Thu Oct 15, 2020 2:34 am

lidnariq wrote:
Wed Oct 14, 2020 10:36 pm
I assume it's the same LFSR design...
Exactly. During "increment" PC is shifted right by 1 bit and upper is bit set to (x == y) where x and y are the two lowest bits of PC before shift.

Code: Select all

int feed = ((pc >> 1 ^ pc) & 1) ? 0 : 0x20;
new_pc = feed | (pc >> 1 & 0x1f);
Every bit of new PC depends on 1 or 2 bits only and this could be calculated in one step.
In contrast increments propagate carry bit through digits and more bits you have more time it requires to get stable result.
SM5xx has 4-bit increments/decrements, but six bits seems to annoy developers.
Drawbacks are non-linear fetch sequence:

Code: Select all

00:00 01:20 02:30 03:38 04:3c 05:3e 06:1f 07:2f
08:37 09:3b 0a:3d 0b:1e 0c:0f 0d:27 0e:33 0f:39 
10:1c 11:2e 12:17 13:2b 14:35 15:1a 16:0d 17:06
18:03 19:21 1a:10 1b:28 1c:34 1d:3a 1e:1d 1f:0e
20:07 21:23 22:31 23:18 24:2c 25:36 26:1b 27:2d
28:16 29:0b 2a:25 2b:12 2c:09 2d:04 2e:22 2f:11
30:08 31:24 32:32 33:19 34:0c 35:26 36:13 37:29
38:14 39:2a 3a:15 3b:0a 3c:05 3d:02 3e:01 3f:00
(00->20->30->38->and so on)
and 'illegal' value 'FF' which produces itself, so it cannot be used. There are 63 steps only and 63 available memory cells for program in each segment as a result.
used in the later SM590s that were used for the NES's CIC.
I didn't know this. :)

Post Reply