052001 operation (bcc/daa)

前回の未調査分からの続きです。

0x60-0x7f

op name  mode ~ |operation/note
----------------------------------
   bxx   r8  3/3|if(cond){pc += signed(r8);}else{ dummycycle;}
   lbxx  r16 1/2|if(cond){pc += r16;}else{ dummycycle; pc += 1}
60 bra   r8  3/3|cond:1
61 bhi   r8  3/3|cond:(Z|C) == 0
62 bcc   r8  3/3|cond:C == 0
63 bne   r8  3/3|cond:Z == 0
64 bvc   r8  3/3|cond:V == 0
65 bpl   r8  3/3|cond:N == 0
66 bge   r8  3/3|cond:(N^V) == 0
67 ?
68 lbra  r16 1/3|cond:1
69 lbhi  r16 1/3|cond:(Z|C) == 0
6a lbcc  r16 1/3|cond:C == 0
6b lbne  r16 1/3|cond:Z == 0
6c lbvc  r16 1/3|cond:V == 0
6d lbpl  r16 1/3|cond:N == 0
6e lbge  r16 1/3|cond:(N^V) == 0
6f ?
70 brn   r8  3/3|cond:0
71 bls   r8  3/3|cond:(Z|C) == 1
72 bcs   r8  3/3|cond:C == 1
73 beq   r8  3/3|cond:Z == 1
74 bvs   r8  3/3|cond:V == 1
75 bmi   r8  3/3|cond:N == 1
76 blt   r8  3/3|cond:(N^V) == 1
77 ?
78 lbrn  r16 1/3|cond:0
79 ?
7a lbcs  r16 1/3|cond:C == 1
7b lbeq  r16 1/3|cond:Z == 1
7c lbvs  r16 1/3|cond:V == 1
7d lbmi  r16 1/3|cond:N == 1
7e ?
7f ?
  • ? が記載された命令は分岐命令ではないようで、別の調査が必要です。
    • 0x67 と 0x77 は bgt と ble のはずですが 052001 では動かないようです.
    • 同様に 0x6f と 0x7f の lbgt と lble も動かないようです.
    • lbcc はさらに対になる命令がなぜか動きませんでした。
    • 053248 では分岐命令が動くと思います。
  • 分岐命令では条件以外の pc の代入は同じです。
  • bcc の clock 計算
    • 分岐発生時は 3 clock の待ちが発生します。
    • 分岐しない時は 1 byte のmemory cycle (?) と 1 clock の待ちが発生します。(合計 3 clock)
  • lbcc の clock 計算
    • 分岐発生時は 1 clock の待ちが発生します。
    • 分岐しない時は bcc と同じです。

分岐しない時は 1 byte の dummy memory cycle (?) は特殊で有効な address は発生するようですが、 dtac を H にしても CPU がこれを読んでいないのか停まらずに次の address を生成します。

lbcc の場合は opcode 読み込み -> dummy memory cycle (?) -> pc += 1 となり、 rel16.lo は memory cycle 自体が発生しません。

DAA の実行クロック

DAA は A レジスタの値と CC の Carray と Half Carry によって最小4, 最大10の待ちクロックが発生します。全通りリストアップします。

[c = 0, h = 0]
    x0   x1   x2   x3   x4   x5   x6   x7   x8   x9   xa   xb   xc   xd   xe   xf
0x: 00.a 01.a 02.a 03.a 04.a 05.a 06.a 07.a-08.a 09.a 10.9 11.9 12.9 13.9 14.9 15.9
1x: 10.a 11.a 12.a 13.a 14.a 15.a 16.a 17.a-18.a 19.a 20.9 21.9 22.9 23.9 24.9 25.9
2x: 20.a 21.a 22.a 23.a 24.a 25.a 26.a 27.a-28.a 29.a 30.9 31.9 32.9 33.9 34.9 35.9
3x: 30.a 31.a 32.a 33.a 34.a 35.a 36.a 37.a-38.a 39.a 40.9 41.9 42.9 43.9 44.9 45.9
4x: 40.a 41.a 42.a 43.a 44.a 45.a 46.a 47.a-48.a 49.a 50.9 51.9 52.9 53.9 54.9 55.9
5x: 50.a 51.a 52.a 53.a 54.a 55.a 56.a 57.a-58.a 59.a 60.9 61.9 62.9 63.9 64.9 65.9
6x: 60.a 61.a 62.a 63.a 64.a 65.a 66.a 67.a-68.a 69.a 70.9 71.9 72.9 73.9 74.9 75.9
7x: 70.a 71.a 72.a 73.a 74.a 75.a 76.a 77.a-78.a 79.a 80.9 81.9 82.9 83.9 84.9 85.9
8x: 80.a 81.a 82.a 83.a 84.a 85.a 86.a 87.a-88.a 89.a 90.9 91.9 92.9 93.9 94.9 95.9
9x: 90.a 91.a 92.a 93.a 94.a 95.a 96.a 97.a-98.a 99.a 00.8 01.8 02.8 03.8 04.8 05.8
ax: 00.9 01.9 02.9 03.9 04.9 05.9 06.9 07.9-08.9 09.9 10.8 11.8 12.8 13.8 14.8 15.8
bx: 10.9 11.9 12.9 13.9 14.9 15.9 16.9 17.9-18.9 19.9 20.8 21.8 22.8 23.8 24.8 25.8
cx: 20.9 21.9 22.9 23.9 24.9 25.9 26.9 27.9-28.9 29.9 30.8 31.8 32.8 33.8 34.8 35.8
dx: 30.9 31.9 32.9 33.9 34.9 35.9 36.9 37.9-38.9 39.9 40.8 41.8 42.8 43.8 44.8 45.8
ex: 40.9 41.9 42.9 43.9 44.9 45.9 46.9 47.9-48.9 49.9 50.8 51.8 52.8 53.8 54.8 55.8
fx: 50.9 51.9 52.9 53.9 54.9 55.9 56.9 57.9-58.9 59.9 60.8 61.8 62.8 63.8 64.8 65.8

[c = 1, h = 0]
    x0   x1   x2   x3   x4   x5   x6   x7   x8   x9   xa   xb   xc   xd   xe   xf
0x: 60.7 61.7 62.7 63.7 64.7 65.7 66.7 67.7-68.7 69.7 70.6 71.6 72.6 73.6 74.6 75.6
1x: 70.7 71.7 72.7 73.7 74.7 75.7 76.7 77.7-78.7 79.7 80.6 81.6 82.6 83.6 84.6 85.6
2x: 80.7 81.7 82.7 83.7 84.7 85.7 86.7 87.7-88.7 89.7 90.6 91.6 92.6 93.6 94.6 95.6
3x: 90.7 91.7 92.7 93.7 94.7 95.7 96.7 97.7-98.7 99.7 a0.6 a1.6 a2.6 a3.6 a4.6 a5.6
4x: a0.7 a1.7 a2.7 a3.7 a4.7 a5.7 a6.7 a7.7-a8.7 a9.7 b0.6 b1.6 b2.6 b3.6 b4.6 b5.6
5x: b0.7 b1.7 b2.7 b3.7 b4.7 b5.7 b6.7 b7.7-b8.7 b9.7 c0.6 c1.6 c2.6 c3.6 c4.6 c5.6
6x: c0.7 c1.7 c2.7 c3.7 c4.7 c5.7 c6.7 c7.7-c8.7 c9.7 d0.6 d1.6 d2.6 d3.6 d4.6 d5.6
7x: d0.7 d1.7 d2.7 d3.7 d4.7 d5.7 d6.7 d7.7-d8.7 d9.7 e0.6 e1.6 e2.6 e3.6 e4.6 e5.6
8x: e0.7 e1.7 e2.7 e3.7 e4.7 e5.7 e6.7 e7.7-e8.7 e9.7 f0.6 f1.6 f2.6 f3.6 f4.6 f5.6
9x: f0.7 f1.7 f2.7 f3.7 f4.7 f5.7 f6.7 f7.7-f8.7 f9.7 00.6 01.6 02.6 03.6 04.6 05.6
ax: 00.7 01.7 02.7 03.7 04.7 05.7 06.7 07.7-08.7 09.7 10.6 11.6 12.6 13.6 14.6 15.6
bx: 10.7 11.7 12.7 13.7 14.7 15.7 16.7 17.7-18.7 19.7 20.6 21.6 22.6 23.6 24.6 25.6
cx: 20.7 21.7 22.7 23.7 24.7 25.7 26.7 27.7-28.7 29.7 30.6 31.6 32.6 33.6 34.6 35.6
dx: 30.7 31.7 32.7 33.7 34.7 35.7 36.7 37.7-38.7 39.7 40.6 41.6 42.6 43.6 44.6 45.6
ex: 40.7 41.7 42.7 43.7 44.7 45.7 46.7 47.7-48.7 49.7 50.6 51.6 52.6 53.6 54.6 55.6
fx: 50.7 51.7 52.7 53.7 54.7 55.7 56.7 57.7-58.7 59.7 60.6 61.6 62.6 63.6 64.6 65.6

[c = 0, h = 1]
    x0   x1   x2   x3   x4   x5   x6   x7   x8   x9   xa   xb   xc   xd   xe   xf
0x: 06.7 07.7 08.7 09.7 0a.7 0b.7 0c.7 0d.7-0e.7 0f.7 10.7 11.7 12.7 13.7 14.7 15.7
1x: 16.7 17.7 18.7 19.7 1a.7 1b.7 1c.7 1d.7-1e.7 1f.7 20.7 21.7 22.7 23.7 24.7 25.7
2x: 26.7 27.7 28.7 29.7 2a.7 2b.7 2c.7 2d.7-2e.7 2f.7 30.7 31.7 32.7 33.7 34.7 35.7
3x: 36.7 37.7 38.7 39.7 3a.7 3b.7 3c.7 3d.7-3e.7 3f.7 40.7 41.7 42.7 43.7 44.7 45.7
4x: 46.7 47.7 48.7 49.7 4a.7 4b.7 4c.7 4d.7-4e.7 4f.7 50.7 51.7 52.7 53.7 54.7 55.7
5x: 56.7 57.7 58.7 59.7 5a.7 5b.7 5c.7 5d.7-5e.7 5f.7 60.7 61.7 62.7 63.7 64.7 65.7
6x: 66.7 67.7 68.7 69.7 6a.7 6b.7 6c.7 6d.7-6e.7 6f.7 70.7 71.7 72.7 73.7 74.7 75.7
7x: 76.7 77.7 78.7 79.7 7a.7 7b.7 7c.7 7d.7-7e.7 7f.7 80.7 81.7 82.7 83.7 84.7 85.7
8x: 86.7 87.7 88.7 89.7 8a.7 8b.7 8c.7 8d.7-8e.7 8f.7 90.7 91.7 92.7 93.7 94.7 95.7
9x: 96.7 97.7 98.7 99.7 9a.7 9b.7 9c.7 9d.7-9e.7 9f.7 00.6 01.6 02.6 03.6 04.6 05.6
ax: 06.6 07.6 08.6 09.6 0a.6 0b.6 0c.6 0d.6-0e.6 0f.6 10.6 11.6 12.6 13.6 14.6 15.6
bx: 16.6 17.6 18.6 19.6 1a.6 1b.6 1c.6 1d.6-1e.6 1f.6 20.6 21.6 22.6 23.6 24.6 25.6
cx: 26.6 27.6 28.6 29.6 2a.6 2b.6 2c.6 2d.6-2e.6 2f.6 30.6 31.6 32.6 33.6 34.6 35.6
dx: 36.6 37.6 38.6 39.6 3a.6 3b.6 3c.6 3d.6-3e.6 3f.6 40.6 41.6 42.6 43.6 44.6 45.6
ex: 46.6 47.6 48.6 49.6 4a.6 4b.6 4c.6 4d.6-4e.6 4f.6 50.6 51.6 52.6 53.6 54.6 55.6
fx: 56.6 57.6 58.6 59.6 5a.6 5b.6 5c.6 5d.6-5e.6 5f.6 60.6 61.6 62.6 63.6 64.6 65.6

[c = 1, h = 1]
    x0   x1   x2   x3   x4   x5   x6   x7   x8   x9   xa   xb   xc   xd   xe   xf
0x: 66.4 67.4 68.4 69.4 6a.4 6b.4 6c.4 6d.4-6e.4 6f.4 70.4 71.4 72.4 73.4 74.4 75.4
1x: 76.4 77.4 78.4 79.4 7a.4 7b.4 7c.4 7d.4-7e.4 7f.4 80.4 81.4 82.4 83.4 84.4 85.4
2x: 86.4 87.4 88.4 89.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.4 5d.4-5e.4 5f.4 60.4 61.4 62.4 63.4 64.4 65.4
  • c = ?: CC の Carry の値
  • h = ?: CC の Half Carry の値
  • 0x.x0 の枠に一致する点: daa 命令実行前の A レジスタの値 (0 から 0xff まで 256 通り)
  • vv.l
    • vv: daa 命令実行後の A レジスタの値
    • l: 待ちクロック数

daa はおそらく下記のような命令を順番に実行していると思われます。

	a += 0x06; //加算: 1 clock
	cond = h == 0;  //比較: 1 clock
	if(h){ //分岐: 1 clock
		cond = (a & 0x0f) >= 0x06; //bit3:0 の比較: 1 clock
		if(cond){ //分岐: 1 clock
			a -= 6 //bit3:0 の補正: 1 clock
		}
	}
	a += 0x60; //加算: 1 clock
	cond = c == 0; //比較: 1 clock
	if(c == 0){ //分岐: 1 clock
		cond = a < 0x100 //内部のcarry bit の比較: 1clock
		if(cond){ 
			a -= 0x60 //bit7:4 の補正: 1 clock
		}
	}

6809 は 1 clock で実行出来ると書いてあるのでオリジナルより遅いようです。