Bercriber's Blog

ゲームボーイのDAA(BCD)完全に理解した

なにもわからない。どこからともなくコピペして完全に敗北した。

BCD(Binary Coded Decimal)は16進数を10進数に変換したもの。

ゲームボーイではDAA命令を使って変換する。

0x9 -> 0x09

0xa -> 0x10

0xb -> 0x11

0x1a -> 0x20

0x2a -> 0x30

みたいな感じ。

以下正解。

let tmp = this.a;
if (this.negative == 0) {
  if (this.carry == 1 || tmp > 0x99) {
    tmp += 0x60;
    this.carry = 1;
  }
  if (this.half == 1 || (tmp & 0xf) > 0x9) {
    tmp += 0x06;
  }
} else {
  if (this.carry == 1) {
    tmp -= 0x60;
  }
  if (this.half == 1) {
    tmp -= 0x06;
  }
}
this.a = tmp & 0xff;
this.zero = this.a == 0;
this.half = 0;

よくわからなくてむかつくので全パターンはる。

negative = 0, half = 0, carry = 0
$00 -> $00
$01 -> $01
$02 -> $02
$03 -> $03
$04 -> $04
$05 -> $05
$06 -> $06
$07 -> $07
$08 -> $08
$09 -> $09
$0A -> $10
$0B -> $11
$0C -> $12
$0D -> $13
$0E -> $14
$0F -> $15
$10 -> $10
$11 -> $11
$12 -> $12
$13 -> $13
$14 -> $14
$15 -> $15
$16 -> $16
$17 -> $17
$18 -> $18
$19 -> $19
$1A -> $20
$1B -> $21
$1C -> $22
$1D -> $23
$1E -> $24
$1F -> $25
$20 -> $20
$21 -> $21
$22 -> $22
$23 -> $23
$24 -> $24
$25 -> $25
$26 -> $26
$27 -> $27
$28 -> $28
$29 -> $29
$2A -> $30
$2B -> $31
$2C -> $32
$2D -> $33
$2E -> $34
$2F -> $35
$30 -> $30
$31 -> $31
$32 -> $32
$33 -> $33
$34 -> $34
$35 -> $35
$36 -> $36
$37 -> $37
$38 -> $38
$39 -> $39
$3A -> $40
$3B -> $41
$3C -> $42
$3D -> $43
$3E -> $44
$3F -> $45
$40 -> $40
$41 -> $41
$42 -> $42
$43 -> $43
$44 -> $44
$45 -> $45
$46 -> $46
$47 -> $47
$48 -> $48
$49 -> $49
$4A -> $50
$4B -> $51
$4C -> $52
$4D -> $53
$4E -> $54
$4F -> $55
$50 -> $50
$51 -> $51
$52 -> $52
$53 -> $53
$54 -> $54
$55 -> $55
$56 -> $56
$57 -> $57
$58 -> $58
$59 -> $59
$5A -> $60
$5B -> $61
$5C -> $62
$5D -> $63
$5E -> $64
$5F -> $65
$60 -> $60
$61 -> $61
$62 -> $62
$63 -> $63
$64 -> $64
$65 -> $65
$66 -> $66
$67 -> $67
$68 -> $68
$69 -> $69
$6A -> $70
$6B -> $71
$6C -> $72
$6D -> $73
$6E -> $74
$6F -> $75
$70 -> $70
$71 -> $71
$72 -> $72
$73 -> $73
$74 -> $74
$75 -> $75
$76 -> $76
$77 -> $77
$78 -> $78
$79 -> $79
$7A -> $80
$7B -> $81
$7C -> $82
$7D -> $83
$7E -> $84
$7F -> $85
$80 -> $80
$81 -> $81
$82 -> $82
$83 -> $83
$84 -> $84
$85 -> $85
$86 -> $86
$87 -> $87
$88 -> $88
$89 -> $89
$8A -> $90
$8B -> $91
$8C -> $92
$8D -> $93
$8E -> $94
$8F -> $95
$90 -> $90
$91 -> $91
$92 -> $92
$93 -> $93
$94 -> $94
$95 -> $95
$96 -> $96
$97 -> $97
$98 -> $98
$99 -> $99
$9A -> $00
$9B -> $01
$9C -> $02
$9D -> $03
$9E -> $04
$9F -> $05
$A0 -> $00
$A1 -> $01
$A2 -> $02
$A3 -> $03
$A4 -> $04
$A5 -> $05
$A6 -> $06
$A7 -> $07
$A8 -> $08
$A9 -> $09
$AA -> $10
$AB -> $11
$AC -> $12
$AD -> $13
$AE -> $14
$AF -> $15
$B0 -> $10
$B1 -> $11
$B2 -> $12
$B3 -> $13
$B4 -> $14
$B5 -> $15
$B6 -> $16
$B7 -> $17
$B8 -> $18
$B9 -> $19
$BA -> $20
$BB -> $21
$BC -> $22
$BD -> $23
$BE -> $24
$BF -> $25
$C0 -> $20
$C1 -> $21
$C2 -> $22
$C3 -> $23
$C4 -> $24
$C5 -> $25
$C6 -> $26
$C7 -> $27
$C8 -> $28
$C9 -> $29
$CA -> $30
$CB -> $31
$CC -> $32
$CD -> $33
$CE -> $34
$CF -> $35
$D0 -> $30
$D1 -> $31
$D2 -> $32
$D3 -> $33
$D4 -> $34
$D5 -> $35
$D6 -> $36
$D7 -> $37
$D8 -> $38
$D9 -> $39
$DA -> $40
$DB -> $41
$DC -> $42
$DD -> $43
$DE -> $44
$DF -> $45
$E0 -> $40
$E1 -> $41
$E2 -> $42
$E3 -> $43
$E4 -> $44
$E5 -> $45
$E6 -> $46
$E7 -> $47
$E8 -> $48
$E9 -> $49
$EA -> $50
$EB -> $51
$EC -> $52
$ED -> $53
$EE -> $54
$EF -> $55
$F0 -> $50
$F1 -> $51
$F2 -> $52
$F3 -> $53
$F4 -> $54
$F5 -> $55
$F6 -> $56
$F7 -> $57
$F8 -> $58
$F9 -> $59
$FA -> $60
$FB -> $61
$FC -> $62
$FD -> $63
$FE -> $64
$FF -> $65

negative = 0, half = 0, carry = 1
$00 -> $60
$01 -> $61
$02 -> $62
$03 -> $63
$04 -> $64
$05 -> $65
$06 -> $66
$07 -> $67
$08 -> $68
$09 -> $69
$0A -> $70
$0B -> $71
$0C -> $72
$0D -> $73
$0E -> $74
$0F -> $75
$10 -> $70
$11 -> $71
$12 -> $72
$13 -> $73
$14 -> $74
$15 -> $75
$16 -> $76
$17 -> $77
$18 -> $78
$19 -> $79
$1A -> $80
$1B -> $81
$1C -> $82
$1D -> $83
$1E -> $84
$1F -> $85
$20 -> $80
$21 -> $81
$22 -> $82
$23 -> $83
$24 -> $84
$25 -> $85
$26 -> $86
$27 -> $87
$28 -> $88
$29 -> $89
$2A -> $90
$2B -> $91
$2C -> $92
$2D -> $93
$2E -> $94
$2F -> $95
$30 -> $90
$31 -> $91
$32 -> $92
$33 -> $93
$34 -> $94
$35 -> $95
$36 -> $96
$37 -> $97
$38 -> $98
$39 -> $99
$3A -> $A0
$3B -> $A1
$3C -> $A2
$3D -> $A3
$3E -> $A4
$3F -> $A5
$40 -> $A0
$41 -> $A1
$42 -> $A2
$43 -> $A3
$44 -> $A4
$45 -> $A5
$46 -> $A6
$47 -> $A7
$48 -> $A8
$49 -> $A9
$4A -> $B0
$4B -> $B1
$4C -> $B2
$4D -> $B3
$4E -> $B4
$4F -> $B5
$50 -> $B0
$51 -> $B1
$52 -> $B2
$53 -> $B3
$54 -> $B4
$55 -> $B5
$56 -> $B6
$57 -> $B7
$58 -> $B8
$59 -> $B9
$5A -> $C0
$5B -> $C1
$5C -> $C2
$5D -> $C3
$5E -> $C4
$5F -> $C5
$60 -> $C0
$61 -> $C1
$62 -> $C2
$63 -> $C3
$64 -> $C4
$65 -> $C5
$66 -> $C6
$67 -> $C7
$68 -> $C8
$69 -> $C9
$6A -> $D0
$6B -> $D1
$6C -> $D2
$6D -> $D3
$6E -> $D4
$6F -> $D5
$70 -> $D0
$71 -> $D1
$72 -> $D2
$73 -> $D3
$74 -> $D4
$75 -> $D5
$76 -> $D6
$77 -> $D7
$78 -> $D8
$79 -> $D9
$7A -> $E0
$7B -> $E1
$7C -> $E2
$7D -> $E3
$7E -> $E4
$7F -> $E5
$80 -> $E0
$81 -> $E1
$82 -> $E2
$83 -> $E3
$84 -> $E4
$85 -> $E5
$86 -> $E6
$87 -> $E7
$88 -> $E8
$89 -> $E9
$8A -> $F0
$8B -> $F1
$8C -> $F2
$8D -> $F3
$8E -> $F4
$8F -> $F5
$90 -> $F0
$91 -> $F1
$92 -> $F2
$93 -> $F3
$94 -> $F4
$95 -> $F5
$96 -> $F6
$97 -> $F7
$98 -> $F8
$99 -> $F9
$9A -> $00
$9B -> $01
$9C -> $02
$9D -> $03
$9E -> $04
$9F -> $05
$A0 -> $00
$A1 -> $01
$A2 -> $02
$A3 -> $03
$A4 -> $04
$A5 -> $05
$A6 -> $06
$A7 -> $07
$A8 -> $08
$A9 -> $09
$AA -> $10
$AB -> $11
$AC -> $12
$AD -> $13
$AE -> $14
$AF -> $15
$B0 -> $10
$B1 -> $11
$B2 -> $12
$B3 -> $13
$B4 -> $14
$B5 -> $15
$B6 -> $16
$B7 -> $17
$B8 -> $18
$B9 -> $19
$BA -> $20
$BB -> $21
$BC -> $22
$BD -> $23
$BE -> $24
$BF -> $25
$C0 -> $20
$C1 -> $21
$C2 -> $22
$C3 -> $23
$C4 -> $24
$C5 -> $25
$C6 -> $26
$C7 -> $27
$C8 -> $28
$C9 -> $29
$CA -> $30
$CB -> $31
$CC -> $32
$CD -> $33
$CE -> $34
$CF -> $35
$D0 -> $30
$D1 -> $31
$D2 -> $32
$D3 -> $33
$D4 -> $34
$D5 -> $35
$D6 -> $36
$D7 -> $37
$D8 -> $38
$D9 -> $39
$DA -> $40
$DB -> $41
$DC -> $42
$DD -> $43
$DE -> $44
$DF -> $45
$E0 -> $40
$E1 -> $41
$E2 -> $42
$E3 -> $43
$E4 -> $44
$E5 -> $45
$E6 -> $46
$E7 -> $47
$E8 -> $48
$E9 -> $49
$EA -> $50
$EB -> $51
$EC -> $52
$ED -> $53
$EE -> $54
$EF -> $55
$F0 -> $50
$F1 -> $51
$F2 -> $52
$F3 -> $53
$F4 -> $54
$F5 -> $55
$F6 -> $56
$F7 -> $57
$F8 -> $58
$F9 -> $59
$FA -> $60
$FB -> $61
$FC -> $62
$FD -> $63
$FE -> $64
$FF -> $65

negative = 0, half = 1, carry = 0
$00 -> $06
$01 -> $01
$02 -> $02
$03 -> $03
$04 -> $04
$05 -> $05
$06 -> $06
$07 -> $07
$08 -> $08
$09 -> $09
$0A -> $10
$0B -> $11
$0C -> $12
$0D -> $13
$0E -> $14
$0F -> $15
$10 -> $10
$11 -> $11
$12 -> $12
$13 -> $13
$14 -> $14
$15 -> $15
$16 -> $16
$17 -> $17
$18 -> $18
$19 -> $19
$1A -> $20
$1B -> $21
$1C -> $22
$1D -> $23
$1E -> $24
$1F -> $25
$20 -> $20
$21 -> $21
$22 -> $22
$23 -> $23
$24 -> $24
$25 -> $25
$26 -> $26
$27 -> $27
$28 -> $28
$29 -> $29
$2A -> $30
$2B -> $31
$2C -> $32
$2D -> $33
$2E -> $34
$2F -> $35
$30 -> $30
$31 -> $31
$32 -> $32
$33 -> $33
$34 -> $34
$35 -> $35
$36 -> $36
$37 -> $37
$38 -> $38
$39 -> $39
$3A -> $40
$3B -> $41
$3C -> $42
$3D -> $43
$3E -> $44
$3F -> $45
$40 -> $40
$41 -> $41
$42 -> $42
$43 -> $43
$44 -> $44
$45 -> $45
$46 -> $46
$47 -> $47
$48 -> $48
$49 -> $49
$4A -> $50
$4B -> $51
$4C -> $52
$4D -> $53
$4E -> $54
$4F -> $55
$50 -> $50
$51 -> $51
$52 -> $52
$53 -> $53
$54 -> $54
$55 -> $55
$56 -> $56
$57 -> $57
$58 -> $58
$59 -> $59
$5A -> $60
$5B -> $61
$5C -> $62
$5D -> $63
$5E -> $64
$5F -> $65
$60 -> $60
$61 -> $61
$62 -> $62
$63 -> $63
$64 -> $64
$65 -> $65
$66 -> $66
$67 -> $67
$68 -> $68
$69 -> $69
$6A -> $70
$6B -> $71
$6C -> $72
$6D -> $73
$6E -> $74
$6F -> $75
$70 -> $70
$71 -> $71
$72 -> $72
$73 -> $73
$74 -> $74
$75 -> $75
$76 -> $76
$77 -> $77
$78 -> $78
$79 -> $79
$7A -> $80
$7B -> $81
$7C -> $82
$7D -> $83
$7E -> $84
$7F -> $85
$80 -> $80
$81 -> $81
$82 -> $82
$83 -> $83
$84 -> $84
$85 -> $85
$86 -> $86
$87 -> $87
$88 -> $88
$89 -> $89
$8A -> $90
$8B -> $91
$8C -> $92
$8D -> $93
$8E -> $94
$8F -> $95
$90 -> $90
$91 -> $91
$92 -> $92
$93 -> $93
$94 -> $94
$95 -> $95
$96 -> $96
$97 -> $97
$98 -> $98
$99 -> $99
$9A -> $00
$9B -> $01
$9C -> $02
$9D -> $03
$9E -> $04
$9F -> $05
$A0 -> $00
$A1 -> $01
$A2 -> $02
$A3 -> $03
$A4 -> $04
$A5 -> $05
$A6 -> $06
$A7 -> $07
$A8 -> $08
$A9 -> $09
$AA -> $10
$AB -> $11
$AC -> $12
$AD -> $13
$AE -> $14
$AF -> $15
$B0 -> $10
$B1 -> $11
$B2 -> $12
$B3 -> $13
$B4 -> $14
$B5 -> $15
$B6 -> $16
$B7 -> $17
$B8 -> $18
$B9 -> $19
$BA -> $20
$BB -> $21
$BC -> $22
$BD -> $23
$BE -> $24
$BF -> $25
$C0 -> $20
$C1 -> $21
$C2 -> $22
$C3 -> $23
$C4 -> $24
$C5 -> $25
$C6 -> $26
$C7 -> $27
$C8 -> $28
$C9 -> $29
$CA -> $30
$CB -> $31
$CC -> $32
$CD -> $33
$CE -> $34
$CF -> $35
$D0 -> $30
$D1 -> $31
$D2 -> $32
$D3 -> $33
$D4 -> $34
$D5 -> $35
$D6 -> $36
$D7 -> $37
$D8 -> $38
$D9 -> $39
$DA -> $40
$DB -> $41
$DC -> $42
$DD -> $43
$DE -> $44
$DF -> $45
$E0 -> $40
$E1 -> $41
$E2 -> $42
$E3 -> $43
$E4 -> $44
$E5 -> $45
$E6 -> $46
$E7 -> $47
$E8 -> $48
$E9 -> $49
$EA -> $50
$EB -> $51
$EC -> $52
$ED -> $53
$EE -> $54
$EF -> $55
$F0 -> $50
$F1 -> $51
$F2 -> $52
$F3 -> $53
$F4 -> $54
$F5 -> $55
$F6 -> $56
$F7 -> $57
$F8 -> $58
$F9 -> $59
$FA -> $60
$FB -> $61
$FC -> $62
$FD -> $63
$FE -> $64
$FF -> $65

negative = 0, half = 1, carry = 1
$00 -> $66
$01 -> $61
$02 -> $62
$03 -> $63
$04 -> $64
$05 -> $65
$06 -> $66
$07 -> $67
$08 -> $68
$09 -> $69
$0A -> $70
$0B -> $71
$0C -> $72
$0D -> $73
$0E -> $74
$0F -> $75
$10 -> $70
$11 -> $71
$12 -> $72
$13 -> $73
$14 -> $74
$15 -> $75
$16 -> $76
$17 -> $77
$18 -> $78
$19 -> $79
$1A -> $80
$1B -> $81
$1C -> $82
$1D -> $83
$1E -> $84
$1F -> $85
$20 -> $80
$21 -> $81
$22 -> $82
$23 -> $83
$24 -> $84
$25 -> $85
$26 -> $86
$27 -> $87
$28 -> $88
$29 -> $89
$2A -> $90
$2B -> $91
$2C -> $92
$2D -> $93
$2E -> $94
$2F -> $95
$30 -> $90
$31 -> $91
$32 -> $92
$33 -> $93
$34 -> $94
$35 -> $95
$36 -> $96
$37 -> $97
$38 -> $98
$39 -> $99
$3A -> $A0
$3B -> $A1
$3C -> $A2
$3D -> $A3
$3E -> $A4
$3F -> $A5
$40 -> $A0
$41 -> $A1
$42 -> $A2
$43 -> $A3
$44 -> $A4
$45 -> $A5
$46 -> $A6
$47 -> $A7
$48 -> $A8
$49 -> $A9
$4A -> $B0
$4B -> $B1
$4C -> $B2
$4D -> $B3
$4E -> $B4
$4F -> $B5
$50 -> $B0
$51 -> $B1
$52 -> $B2
$53 -> $B3
$54 -> $B4
$55 -> $B5
$56 -> $B6
$57 -> $B7
$58 -> $B8
$59 -> $B9
$5A -> $C0
$5B -> $C1
$5C -> $C2
$5D -> $C3
$5E -> $C4
$5F -> $C5
$60 -> $C0
$61 -> $C1
$62 -> $C2
$63 -> $C3
$64 -> $C4
$65 -> $C5
$66 -> $C6
$67 -> $C7
$68 -> $C8
$69 -> $C9
$6A -> $D0
$6B -> $D1
$6C -> $D2
$6D -> $D3
$6E -> $D4
$6F -> $D5
$70 -> $D0
$71 -> $D1
$72 -> $D2
$73 -> $D3
$74 -> $D4
$75 -> $D5
$76 -> $D6
$77 -> $D7
$78 -> $D8
$79 -> $D9
$7A -> $E0
$7B -> $E1
$7C -> $E2
$7D -> $E3
$7E -> $E4
$7F -> $E5
$80 -> $E0
$81 -> $E1
$82 -> $E2
$83 -> $E3
$84 -> $E4
$85 -> $E5
$86 -> $E6
$87 -> $E7
$88 -> $E8
$89 -> $E9
$8A -> $F0
$8B -> $F1
$8C -> $F2
$8D -> $F3
$8E -> $F4
$8F -> $F5
$90 -> $F0
$91 -> $F1
$92 -> $F2
$93 -> $F3
$94 -> $F4
$95 -> $F5
$96 -> $F6
$97 -> $F7
$98 -> $F8
$99 -> $F9
$9A -> $00
$9B -> $01
$9C -> $02
$9D -> $03
$9E -> $04
$9F -> $05
$A0 -> $00
$A1 -> $01
$A2 -> $02
$A3 -> $03
$A4 -> $04
$A5 -> $05
$A6 -> $06
$A7 -> $07
$A8 -> $08
$A9 -> $09
$AA -> $10
$AB -> $11
$AC -> $12
$AD -> $13
$AE -> $14
$AF -> $15
$B0 -> $10
$B1 -> $11
$B2 -> $12
$B3 -> $13
$B4 -> $14
$B5 -> $15
$B6 -> $16
$B7 -> $17
$B8 -> $18
$B9 -> $19
$BA -> $20
$BB -> $21
$BC -> $22
$BD -> $23
$BE -> $24
$BF -> $25
$C0 -> $20
$C1 -> $21
$C2 -> $22
$C3 -> $23
$C4 -> $24
$C5 -> $25
$C6 -> $26
$C7 -> $27
$C8 -> $28
$C9 -> $29
$CA -> $30
$CB -> $31
$CC -> $32
$CD -> $33
$CE -> $34
$CF -> $35
$D0 -> $30
$D1 -> $31
$D2 -> $32
$D3 -> $33
$D4 -> $34
$D5 -> $35
$D6 -> $36
$D7 -> $37
$D8 -> $38
$D9 -> $39
$DA -> $40
$DB -> $41
$DC -> $42
$DD -> $43
$DE -> $44
$DF -> $45
$E0 -> $40
$E1 -> $41
$E2 -> $42
$E3 -> $43
$E4 -> $44
$E5 -> $45
$E6 -> $46
$E7 -> $47
$E8 -> $48
$E9 -> $49
$EA -> $50
$EB -> $51
$EC -> $52
$ED -> $53
$EE -> $54
$EF -> $55
$F0 -> $50
$F1 -> $51
$F2 -> $52
$F3 -> $53
$F4 -> $54
$F5 -> $55
$F6 -> $56
$F7 -> $57
$F8 -> $58
$F9 -> $59
$FA -> $60
$FB -> $61
$FC -> $62
$FD -> $63
$FE -> $64
$FF -> $65

negative = 1, half = 0, carry = 0
$00 -> $00
$01 -> $01
$02 -> $02
$03 -> $03
$04 -> $04
$05 -> $05
$06 -> $06
$07 -> $07
$08 -> $08
$09 -> $09
$0A -> $0A
$0B -> $0B
$0C -> $0C
$0D -> $0D
$0E -> $0E
$0F -> $0F
$10 -> $10
$11 -> $11
$12 -> $12
$13 -> $13
$14 -> $14
$15 -> $15
$16 -> $16
$17 -> $17
$18 -> $18
$19 -> $19
$1A -> $1A
$1B -> $1B
$1C -> $1C
$1D -> $1D
$1E -> $1E
$1F -> $1F
$20 -> $20
$21 -> $21
$22 -> $22
$23 -> $23
$24 -> $24
$25 -> $25
$26 -> $26
$27 -> $27
$28 -> $28
$29 -> $29
$2A -> $2A
$2B -> $2B
$2C -> $2C
$2D -> $2D
$2E -> $2E
$2F -> $2F
$30 -> $30
$31 -> $31
$32 -> $32
$33 -> $33
$34 -> $34
$35 -> $35
$36 -> $36
$37 -> $37
$38 -> $38
$39 -> $39
$3A -> $3A
$3B -> $3B
$3C -> $3C
$3D -> $3D
$3E -> $3E
$3F -> $3F
$40 -> $40
$41 -> $41
$42 -> $42
$43 -> $43
$44 -> $44
$45 -> $45
$46 -> $46
$47 -> $47
$48 -> $48
$49 -> $49
$4A -> $4A
$4B -> $4B
$4C -> $4C
$4D -> $4D
$4E -> $4E
$4F -> $4F
$50 -> $50
$51 -> $51
$52 -> $52
$53 -> $53
$54 -> $54
$55 -> $55
$56 -> $56
$57 -> $57
$58 -> $58
$59 -> $59
$5A -> $5A
$5B -> $5B
$5C -> $5C
$5D -> $5D
$5E -> $5E
$5F -> $5F
$60 -> $60
$61 -> $61
$62 -> $62
$63 -> $63
$64 -> $64
$65 -> $65
$66 -> $66
$67 -> $67
$68 -> $68
$69 -> $69
$6A -> $6A
$6B -> $6B
$6C -> $6C
$6D -> $6D
$6E -> $6E
$6F -> $6F
$70 -> $70
$71 -> $71
$72 -> $72
$73 -> $73
$74 -> $74
$75 -> $75
$76 -> $76
$77 -> $77
$78 -> $78
$79 -> $79
$7A -> $7A
$7B -> $7B
$7C -> $7C
$7D -> $7D
$7E -> $7E
$7F -> $7F
$80 -> $80
$81 -> $81
$82 -> $82
$83 -> $83
$84 -> $84
$85 -> $85
$86 -> $86
$87 -> $87
$88 -> $88
$89 -> $89
$8A -> $8A
$8B -> $8B
$8C -> $8C
$8D -> $8D
$8E -> $8E
$8F -> $8F
$90 -> $90
$91 -> $91
$92 -> $92
$93 -> $93
$94 -> $94
$95 -> $95
$96 -> $96
$97 -> $97
$98 -> $98
$99 -> $99
$9A -> $9A
$9B -> $9B
$9C -> $9C
$9D -> $9D
$9E -> $9E
$9F -> $9F
$A0 -> $A0
$A1 -> $A1
$A2 -> $A2
$A3 -> $A3
$A4 -> $A4
$A5 -> $A5
$A6 -> $A6
$A7 -> $A7
$A8 -> $A8
$A9 -> $A9
$AA -> $AA
$AB -> $AB
$AC -> $AC
$AD -> $AD
$AE -> $AE
$AF -> $AF
$B0 -> $B0
$B1 -> $B1
$B2 -> $B2
$B3 -> $B3
$B4 -> $B4
$B5 -> $B5
$B6 -> $B6
$B7 -> $B7
$B8 -> $B8
$B9 -> $B9
$BA -> $BA
$BB -> $BB
$BC -> $BC
$BD -> $BD
$BE -> $BE
$BF -> $BF
$C0 -> $C0
$C1 -> $C1
$C2 -> $C2
$C3 -> $C3
$C4 -> $C4
$C5 -> $C5
$C6 -> $C6
$C7 -> $C7
$C8 -> $C8
$C9 -> $C9
$CA -> $CA
$CB -> $CB
$CC -> $CC
$CD -> $CD
$CE -> $CE
$CF -> $CF
$D0 -> $D0
$D1 -> $D1
$D2 -> $D2
$D3 -> $D3
$D4 -> $D4
$D5 -> $D5
$D6 -> $D6
$D7 -> $D7
$D8 -> $D8
$D9 -> $D9
$DA -> $DA
$DB -> $DB
$DC -> $DC
$DD -> $DD
$DE -> $DE
$DF -> $DF
$E0 -> $E0
$E1 -> $E1
$E2 -> $E2
$E3 -> $E3
$E4 -> $E4
$E5 -> $E5
$E6 -> $E6
$E7 -> $E7
$E8 -> $E8
$E9 -> $E9
$EA -> $EA
$EB -> $EB
$EC -> $EC
$ED -> $ED
$EE -> $EE
$EF -> $EF
$F0 -> $F0
$F1 -> $F1
$F2 -> $F2
$F3 -> $F3
$F4 -> $F4
$F5 -> $F5
$F6 -> $F6
$F7 -> $F7
$F8 -> $F8
$F9 -> $F9
$FA -> $FA
$FB -> $FB
$FC -> $FC
$FD -> $FD
$FE -> $FE
$FF -> $FF

negative = 1, half = 0, carry = 1
$00 -> $A0
$01 -> $A1
$02 -> $A2
$03 -> $A3
$04 -> $A4
$05 -> $A5
$06 -> $A6
$07 -> $A7
$08 -> $A8
$09 -> $A9
$0A -> $AA
$0B -> $AB
$0C -> $AC
$0D -> $AD
$0E -> $AE
$0F -> $AF
$10 -> $B0
$11 -> $B1
$12 -> $B2
$13 -> $B3
$14 -> $B4
$15 -> $B5
$16 -> $B6
$17 -> $B7
$18 -> $B8
$19 -> $B9
$1A -> $BA
$1B -> $BB
$1C -> $BC
$1D -> $BD
$1E -> $BE
$1F -> $BF
$20 -> $C0
$21 -> $C1
$22 -> $C2
$23 -> $C3
$24 -> $C4
$25 -> $C5
$26 -> $C6
$27 -> $C7
$28 -> $C8
$29 -> $C9
$2A -> $CA
$2B -> $CB
$2C -> $CC
$2D -> $CD
$2E -> $CE
$2F -> $CF
$30 -> $D0
$31 -> $D1
$32 -> $D2
$33 -> $D3
$34 -> $D4
$35 -> $D5
$36 -> $D6
$37 -> $D7
$38 -> $D8
$39 -> $D9
$3A -> $DA
$3B -> $DB
$3C -> $DC
$3D -> $DD
$3E -> $DE
$3F -> $DF
$40 -> $E0
$41 -> $E1
$42 -> $E2
$43 -> $E3
$44 -> $E4
$45 -> $E5
$46 -> $E6
$47 -> $E7
$48 -> $E8
$49 -> $E9
$4A -> $EA
$4B -> $EB
$4C -> $EC
$4D -> $ED
$4E -> $EE
$4F -> $EF
$50 -> $F0
$51 -> $F1
$52 -> $F2
$53 -> $F3
$54 -> $F4
$55 -> $F5
$56 -> $F6
$57 -> $F7
$58 -> $F8
$59 -> $F9
$5A -> $FA
$5B -> $FB
$5C -> $FC
$5D -> $FD
$5E -> $FE
$5F -> $FF
$60 -> $00
$61 -> $01
$62 -> $02
$63 -> $03
$64 -> $04
$65 -> $05
$66 -> $06
$67 -> $07
$68 -> $08
$69 -> $09
$6A -> $0A
$6B -> $0B
$6C -> $0C
$6D -> $0D
$6E -> $0E
$6F -> $0F
$70 -> $10
$71 -> $11
$72 -> $12
$73 -> $13
$74 -> $14
$75 -> $15
$76 -> $16
$77 -> $17
$78 -> $18
$79 -> $19
$7A -> $1A
$7B -> $1B
$7C -> $1C
$7D -> $1D
$7E -> $1E
$7F -> $1F
$80 -> $20
$81 -> $21
$82 -> $22
$83 -> $23
$84 -> $24
$85 -> $25
$86 -> $26
$87 -> $27
$88 -> $28
$89 -> $29
$8A -> $2A
$8B -> $2B
$8C -> $2C
$8D -> $2D
$8E -> $2E
$8F -> $2F
$90 -> $30
$91 -> $31
$92 -> $32
$93 -> $33
$94 -> $34
$95 -> $35
$96 -> $36
$97 -> $37
$98 -> $38
$99 -> $39
$9A -> $3A
$9B -> $3B
$9C -> $3C
$9D -> $3D
$9E -> $3E
$9F -> $3F
$A0 -> $40
$A1 -> $41
$A2 -> $42
$A3 -> $43
$A4 -> $44
$A5 -> $45
$A6 -> $46
$A7 -> $47
$A8 -> $48
$A9 -> $49
$AA -> $4A
$AB -> $4B
$AC -> $4C
$AD -> $4D
$AE -> $4E
$AF -> $4F
$B0 -> $50
$B1 -> $51
$B2 -> $52
$B3 -> $53
$B4 -> $54
$B5 -> $55
$B6 -> $56
$B7 -> $57
$B8 -> $58
$B9 -> $59
$BA -> $5A
$BB -> $5B
$BC -> $5C
$BD -> $5D
$BE -> $5E
$BF -> $5F
$C0 -> $60
$C1 -> $61
$C2 -> $62
$C3 -> $63
$C4 -> $64
$C5 -> $65
$C6 -> $66
$C7 -> $67
$C8 -> $68
$C9 -> $69
$CA -> $6A
$CB -> $6B
$CC -> $6C
$CD -> $6D
$CE -> $6E
$CF -> $6F
$D0 -> $70
$D1 -> $71
$D2 -> $72
$D3 -> $73
$D4 -> $74
$D5 -> $75
$D6 -> $76
$D7 -> $77
$D8 -> $78
$D9 -> $79
$DA -> $7A
$DB -> $7B
$DC -> $7C
$DD -> $7D
$DE -> $7E
$DF -> $7F
$E0 -> $80
$E1 -> $81
$E2 -> $82
$E3 -> $83
$E4 -> $84
$E5 -> $85
$E6 -> $86
$E7 -> $87
$E8 -> $88
$E9 -> $89
$EA -> $8A
$EB -> $8B
$EC -> $8C
$ED -> $8D
$EE -> $8E
$EF -> $8F
$F0 -> $90
$F1 -> $91
$F2 -> $92
$F3 -> $93
$F4 -> $94
$F5 -> $95
$F6 -> $96
$F7 -> $97
$F8 -> $98
$F9 -> $99
$FA -> $9A
$FB -> $9B
$FC -> $9C
$FD -> $9D
$FE -> $9E
$FF -> $9F

negative = 1, half = 1, carry = 0
$00 -> $FA
$01 -> $01
$02 -> $02
$03 -> $03
$04 -> $04
$05 -> $05
$06 -> $06
$07 -> $07
$08 -> $08
$09 -> $09
$0A -> $0A
$0B -> $0B
$0C -> $0C
$0D -> $0D
$0E -> $0E
$0F -> $0F
$10 -> $10
$11 -> $11
$12 -> $12
$13 -> $13
$14 -> $14
$15 -> $15
$16 -> $16
$17 -> $17
$18 -> $18
$19 -> $19
$1A -> $1A
$1B -> $1B
$1C -> $1C
$1D -> $1D
$1E -> $1E
$1F -> $1F
$20 -> $20
$21 -> $21
$22 -> $22
$23 -> $23
$24 -> $24
$25 -> $25
$26 -> $26
$27 -> $27
$28 -> $28
$29 -> $29
$2A -> $2A
$2B -> $2B
$2C -> $2C
$2D -> $2D
$2E -> $2E
$2F -> $2F
$30 -> $30
$31 -> $31
$32 -> $32
$33 -> $33
$34 -> $34
$35 -> $35
$36 -> $36
$37 -> $37
$38 -> $38
$39 -> $39
$3A -> $3A
$3B -> $3B
$3C -> $3C
$3D -> $3D
$3E -> $3E
$3F -> $3F
$40 -> $40
$41 -> $41
$42 -> $42
$43 -> $43
$44 -> $44
$45 -> $45
$46 -> $46
$47 -> $47
$48 -> $48
$49 -> $49
$4A -> $4A
$4B -> $4B
$4C -> $4C
$4D -> $4D
$4E -> $4E
$4F -> $4F
$50 -> $50
$51 -> $51
$52 -> $52
$53 -> $53
$54 -> $54
$55 -> $55
$56 -> $56
$57 -> $57
$58 -> $58
$59 -> $59
$5A -> $5A
$5B -> $5B
$5C -> $5C
$5D -> $5D
$5E -> $5E
$5F -> $5F
$60 -> $60
$61 -> $61
$62 -> $62
$63 -> $63
$64 -> $64
$65 -> $65
$66 -> $66
$67 -> $67
$68 -> $68
$69 -> $69
$6A -> $6A
$6B -> $6B
$6C -> $6C
$6D -> $6D
$6E -> $6E
$6F -> $6F
$70 -> $70
$71 -> $71
$72 -> $72
$73 -> $73
$74 -> $74
$75 -> $75
$76 -> $76
$77 -> $77
$78 -> $78
$79 -> $79
$7A -> $7A
$7B -> $7B
$7C -> $7C
$7D -> $7D
$7E -> $7E
$7F -> $7F
$80 -> $80
$81 -> $81
$82 -> $82
$83 -> $83
$84 -> $84
$85 -> $85
$86 -> $86
$87 -> $87
$88 -> $88
$89 -> $89
$8A -> $8A
$8B -> $8B
$8C -> $8C
$8D -> $8D
$8E -> $8E
$8F -> $8F
$90 -> $90
$91 -> $91
$92 -> $92
$93 -> $93
$94 -> $94
$95 -> $95
$96 -> $96
$97 -> $97
$98 -> $98
$99 -> $99
$9A -> $9A
$9B -> $9B
$9C -> $9C
$9D -> $9D
$9E -> $9E
$9F -> $9F
$A0 -> $A0
$A1 -> $A1
$A2 -> $A2
$A3 -> $A3
$A4 -> $A4
$A5 -> $A5
$A6 -> $A6
$A7 -> $A7
$A8 -> $A8
$A9 -> $A9
$AA -> $AA
$AB -> $AB
$AC -> $AC
$AD -> $AD
$AE -> $AE
$AF -> $AF
$B0 -> $B0
$B1 -> $B1
$B2 -> $B2
$B3 -> $B3
$B4 -> $B4
$B5 -> $B5
$B6 -> $B6
$B7 -> $B7
$B8 -> $B8
$B9 -> $B9
$BA -> $BA
$BB -> $BB
$BC -> $BC
$BD -> $BD
$BE -> $BE
$BF -> $BF
$C0 -> $C0
$C1 -> $C1
$C2 -> $C2
$C3 -> $C3
$C4 -> $C4
$C5 -> $C5
$C6 -> $C6
$C7 -> $C7
$C8 -> $C8
$C9 -> $C9
$CA -> $CA
$CB -> $CB
$CC -> $CC
$CD -> $CD
$CE -> $CE
$CF -> $CF
$D0 -> $D0
$D1 -> $D1
$D2 -> $D2
$D3 -> $D3
$D4 -> $D4
$D5 -> $D5
$D6 -> $D6
$D7 -> $D7
$D8 -> $D8
$D9 -> $D9
$DA -> $DA
$DB -> $DB
$DC -> $DC
$DD -> $DD
$DE -> $DE
$DF -> $DF
$E0 -> $E0
$E1 -> $E1
$E2 -> $E2
$E3 -> $E3
$E4 -> $E4
$E5 -> $E5
$E6 -> $E6
$E7 -> $E7
$E8 -> $E8
$E9 -> $E9
$EA -> $EA
$EB -> $EB
$EC -> $EC
$ED -> $ED
$EE -> $EE
$EF -> $EF
$F0 -> $F0
$F1 -> $F1
$F2 -> $F2
$F3 -> $F3
$F4 -> $F4
$F5 -> $F5
$F6 -> $F6
$F7 -> $F7
$F8 -> $F8
$F9 -> $F9
$FA -> $FA
$FB -> $FB
$FC -> $FC
$FD -> $FD
$FE -> $FE
$FF -> $FF

negative = 1, half = 1, carry = 1
$00 -> $9A
$01 -> $A1
$02 -> $A2
$03 -> $A3
$04 -> $A4
$05 -> $A5
$06 -> $A6
$07 -> $A7
$08 -> $A8
$09 -> $A9
$0A -> $AA
$0B -> $AB
$0C -> $AC
$0D -> $AD
$0E -> $AE
$0F -> $AF
$10 -> $B0
$11 -> $B1
$12 -> $B2
$13 -> $B3
$14 -> $B4
$15 -> $B5
$16 -> $B6
$17 -> $B7
$18 -> $B8
$19 -> $B9
$1A -> $BA
$1B -> $BB
$1C -> $BC
$1D -> $BD
$1E -> $BE
$1F -> $BF
$20 -> $C0
$21 -> $C1
$22 -> $C2
$23 -> $C3
$24 -> $C4
$25 -> $C5
$26 -> $C6
$27 -> $C7
$28 -> $C8
$29 -> $C9
$2A -> $CA
$2B -> $CB
$2C -> $CC
$2D -> $CD
$2E -> $CE
$2F -> $CF
$30 -> $D0
$31 -> $D1
$32 -> $D2
$33 -> $D3
$34 -> $D4
$35 -> $D5
$36 -> $D6
$37 -> $D7
$38 -> $D8
$39 -> $D9
$3A -> $DA
$3B -> $DB
$3C -> $DC
$3D -> $DD
$3E -> $DE
$3F -> $DF
$40 -> $E0
$41 -> $E1
$42 -> $E2
$43 -> $E3
$44 -> $E4
$45 -> $E5
$46 -> $E6
$47 -> $E7
$48 -> $E8
$49 -> $E9
$4A -> $EA
$4B -> $EB
$4C -> $EC
$4D -> $ED
$4E -> $EE
$4F -> $EF
$50 -> $F0
$51 -> $F1
$52 -> $F2
$53 -> $F3
$54 -> $F4
$55 -> $F5
$56 -> $F6
$57 -> $F7
$58 -> $F8
$59 -> $F9
$5A -> $FA
$5B -> $FB
$5C -> $FC
$5D -> $FD
$5E -> $FE
$5F -> $FF
$60 -> $00
$61 -> $01
$62 -> $02
$63 -> $03
$64 -> $04
$65 -> $05
$66 -> $06
$67 -> $07
$68 -> $08
$69 -> $09
$6A -> $0A
$6B -> $0B
$6C -> $0C
$6D -> $0D
$6E -> $0E
$6F -> $0F
$70 -> $10
$71 -> $11
$72 -> $12
$73 -> $13
$74 -> $14
$75 -> $15
$76 -> $16
$77 -> $17
$78 -> $18
$79 -> $19
$7A -> $1A
$7B -> $1B
$7C -> $1C
$7D -> $1D
$7E -> $1E
$7F -> $1F
$80 -> $20
$81 -> $21
$82 -> $22
$83 -> $23
$84 -> $24
$85 -> $25
$86 -> $26
$87 -> $27
$88 -> $28
$89 -> $29
$8A -> $2A
$8B -> $2B
$8C -> $2C
$8D -> $2D
$8E -> $2E
$8F -> $2F
$90 -> $30
$91 -> $31
$92 -> $32
$93 -> $33
$94 -> $34
$95 -> $35
$96 -> $36
$97 -> $37
$98 -> $38
$99 -> $39
$9A -> $3A
$9B -> $3B
$9C -> $3C
$9D -> $3D
$9E -> $3E
$9F -> $3F
$A0 -> $40
$A1 -> $41
$A2 -> $42
$A3 -> $43
$A4 -> $44
$A5 -> $45
$A6 -> $46
$A7 -> $47
$A8 -> $48
$A9 -> $49
$AA -> $4A
$AB -> $4B
$AC -> $4C
$AD -> $4D
$AE -> $4E
$AF -> $4F
$B0 -> $50
$B1 -> $51
$B2 -> $52
$B3 -> $53
$B4 -> $54
$B5 -> $55
$B6 -> $56
$B7 -> $57
$B8 -> $58
$B9 -> $59
$BA -> $5A
$BB -> $5B
$BC -> $5C
$BD -> $5D
$BE -> $5E
$BF -> $5F
$C0 -> $60
$C1 -> $61
$C2 -> $62
$C3 -> $63
$C4 -> $64
$C5 -> $65
$C6 -> $66
$C7 -> $67
$C8 -> $68
$C9 -> $69
$CA -> $6A
$CB -> $6B
$CC -> $6C
$CD -> $6D
$CE -> $6E
$CF -> $6F
$D0 -> $70
$D1 -> $71
$D2 -> $72
$D3 -> $73
$D4 -> $74
$D5 -> $75
$D6 -> $76
$D7 -> $77
$D8 -> $78
$D9 -> $79
$DA -> $7A
$DB -> $7B
$DC -> $7C
$DD -> $7D
$DE -> $7E
$DF -> $7F
$E0 -> $80
$E1 -> $81
$E2 -> $82
$E3 -> $83
$E4 -> $84
$E5 -> $85
$E6 -> $86
$E7 -> $87
$E8 -> $88
$E9 -> $89
$EA -> $8A
$EB -> $8B
$EC -> $8C
$ED -> $8D
$EE -> $8E
$EF -> $8F
$F0 -> $90
$F1 -> $91
$F2 -> $92
$F3 -> $93
$F4 -> $94
$F5 -> $95
$F6 -> $96
$F7 -> $97
$F8 -> $98
$F9 -> $99
$FA -> $9A
$FB -> $9B
$FC -> $9C
$FD -> $9D
$FE -> $9E
$FF -> $9F

以下失敗。 公式マニュアルのパターンテーブルをべた書きしたのが以下。

const n = this.negative == 1;
const c = this.carry == 1;
const h = this.half == 1;
const m = this.a >> 4 & 0xf;
const l = this.a & 0xf;

const b08 = (b: number): boolean => b >= 0 && b <= 8;
const b09 = (b: number): boolean => b >= 0 && b <= 9;
const baf = (b: number): boolean => b >= 0xa && b <= 0xf;
const b9f = (b: number): boolean => b >= 9 && b <= 0xf;
const b02 = (b: number): boolean => b >= 0 && b <= 2;
const b03 = (b: number): boolean => b >= 0 && b <= 3;
const b7f = (b: number): boolean => b >= 7 && b <= 0xf;
const b6f = (b: number): boolean => b >= 6 && b <= 0xf;

if (!n && !c && !h && b09(m) && b09(l)) {
  this.carry = 0;
} else if (!n && !c && !h && b08(m) && baf(l)) {
  this.a += 0x6;
  this.carry = 0;
} else if (!n && !c && h && b09(m) && b03(l)) {
  this.a += 0x6;
  this.carry = 0;
} else if (!n && !c && !h && baf(m) && b09(l)) {
  this.a += 0x60;
  this.carry = 1;
} else if (!n && !c && !h && b9f(m) && baf(l)) {
  this.a += 0x66;
  this.carry = 1;
} else if (!n && !c && h && baf(m) && b03(l)) {
  this.a += 0x66;
  this.carry = 1;
} else if (!n && c && !h && b02(m) && b09(l)) {
  this.a += 0x60;
  this.carry = 1;
} else if (!n && c && !h && b02(m) && baf(l)) {
  this.a += 0x66;
  this.carry = 1;
} else if (!n && c && h && b03(m) && b03(l)) {
  this.a += 0x66;
  this.carry = 1;
} else if (n && !c && !h && b09(m) && b09(l)) {
  this.carry = 0;
} else if (n && !c && h && b08(m) && b6f(l)) {
  this.a += 0xfa;
  this.carry = 0;
} else if (n && c && !h && b7f(m) && b09(l)) {
  this.a += 0xa0;
  this.carry = 1;
} else if (n && c && h && b6f(m) && b6f(l)) {
  this.a += 0x9a;
  this.carry = 1;
}
this.a &= 0xff;

公式コピペしたのにテスト通らないってどういうことよ。 公式でちがうんだからもう、何にも知らない。もう、何にも知らない。 他にも色々なところからコピペしたり自分で考えたりしてきた。以下続失敗。

let a = this.a;
let h = (this.a >> 4) & 0b1111;
let l = this.a & 0b1111;

if (this.negative == 0) {
  if (this.carry == 0) {
    if (this.half == 0) {
      if (h >= 0 && h <= 8) {
        if (l >= 0 && l <= 9) {
          this.carry = 0;
        } else {
          this.a = this._add_u8(this.a,0x6);
          this.carry = 0;
        }
      } else if (h == 9) {
        if (l >= 0 && l <= 9) {
          this.carry = 0;
        } else {
          this.a = this._add_u8(this.a,0x66);
          this.carry = 1;
        }
      } else {
        if (l >= 0 && l <= 9) {
          this.a = this._add_u8(this.a,0x60);
          this.carry = 1;
        } else {
          this.a = this._add_u8(this.a,0x66);
          this.carry = 1;
        }
      }
    } else {
      if (h >= 0 && h <= 8) {
        if (l >= 0 && l <= 15) {
          this.a = this._add_u8(this.a,0x06);
          this.carry = 0;
        }
      } else if (h == 9) {
        if (l >= 0 && l <= 9) {
          this.a = this._add_u8(this.a,0x06);
          this.carry = 0;
        } else {
          this.a = this._add_u8(this.a,0x66);
          this.carry = 1;
        }
      } else {
        if (l >= 0 && l <= 15) {
          this.a = this._add_u8(this.a,0x66);
          this.carry = 1;
        }
      }
    }
  } else {
    if (this.half == 0) {
      if (l >= 0 && l <= 9) {
        this.a = this._add_u8(this.a,0x60);
        this.carry = 1;
      } else {
        this.a = this._add_u8(this.a,0x66);
        this.carry = 1;
      }
    } else {
      this.a = this._add_u8(this.a,0x66);
      this.carry = 1;
    }
  }
} else {
  if (this.carry == 0) {
    if (this.half == 0) {
      if (h >= 0 && h <= 8) {
        if (l >= 0 && l <= 9) {
          this.carry = 0;
        } else {
          this.a = this._add_u8(this.a,0xfa);
          this.carry = 0;
        }
      } else if (h == 9) {
        if (l >= 0 && l <= 9) {
          this.carry = 0;
        } else {
          this.a = this._add_u8(this.a,0x9a);
          this.carry = 1;
        }
      } else {
        if (l >= 0 && l <= 9) {
          this.a = this._add_u8(this.a,0xa0);
          this.carry = 1;
        } else {
          this.a = this._add_u8(this.a,0x9a);
          this.carry = 1;
        }
      }
    } else {
      if (h >= 0 && h <= 8) {
        if (l >= 0 && l <= 15) {
          this.a = this._add_u8(this.a,0xfa);
          this.carry = 0;
        }
      } else if (h == 9) {
        if (l >= 0 && l <= 9) {
          this.a = this._add_u8(this.a,0xfa);
          this.carry = 0;
        } else {
          this.a = this._add_u8(this.a,0x9a);
          this.carry = 1;
        }
      } else {
        if (l >= 0 && l <= 15) {
          this.a = this._add_u8(this.a,0x9a);
          this.carry = 1;
        }
      }
    }
  } else {
    if (this.half == 0) {
      if (l >= 0 && l <= 9) {
        this.a = this._add_u8(this.a,0xa0);
        this.carry = 1;
      } else {
        this.a = this._add_u8(this.a,0x9a);
        this.carry = 1;
      }
    } else {
      this.a = this._add_u8(this.a,0x9a);
      this.carry = 1;
    }
  }
}

let t = 0;
if (this.half == 1 || l > 9) {
  t++;
}
if (this.carry == 1 || a > 0x99) {
  t += 2;
  this.carry = 1;
}
if (this.negative == 1 && this.half == 0) {
  //this.half = 0;
} else {
  if (this.negative == 1 && this.half == 1) {
    //this.half = l < 6 ? 1 : 0;
  } else {
    //this.half = l >= 0xa ? 1 : 0;
  }
}
let f = this.f;
switch (t) {
  case 1:
    this.a = this._add_u8(this.a, this.negative == 1 ? 0xfa : 0x06);
    break;
  case 2:
    this.a = this._add_u8(this.a, this.negative == 1 ? 0xa0 : 0x60);
    break;
  case 3:
    this.a = this._add_u8(this.a, this.negative == 1 ? 0x9a : 0x66);
    break;
}
this.f = f;

if (this.negative == 0) {
  if (this.half == 1 || l >= 0xa) {
    this.a = this._add_u8(this.a,0x6);
  }
  if (this.carry == 1 || this.a >= 0xa0) {
    this.a = this._add_u8(this.a,0x60);
  }
} else {
  if (this.half == 1 || l >= 0xa) {
    this.a = this._sub_u8(this.a,0x6);
  }
  if (this.carry == 1 || this.a >= 0xa0) {
    this.a = this._sub_u8(this.a,0x60);
  }
}

結局どこぞのエミュのコードコピペして敗北感すごい。 BCDまったくわからない。