summaryrefslogtreecommitdiff
path: root/src/Noddybox.Emulation.EightBit.Z80/Z80CpuDecodeED.cs
blob: d06ee3d9e89aa143c150ee220db2de5b3d37cccf (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
// This file is part of the Noddybox.Emulation C# suite.
//
// Noddybox.Emulation is free software: you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// Noddybox.Emulation 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 Foobar.  If not, see <http://www.gnu.org/licenses/>.
//
// Copyright (c) 2012 Ian Cowburn
//
using System;

namespace Noddybox.Emulation.EightBit.Z80
{
    public partial class Z80Cpu
    {
        /// <summary>
        /// Decode and execute an ED-shifted opcode.
        /// </summary>
        /// <param name="opcode">The opcode.</param>
        private void DecodeED(byte opcode)
        {
            ushort addr;
            byte b;

            switch(opcode)
            {
                case 0x40:  // IN B,(C)
                    clock.Add(12);
                    BC.high = device.Read(BC.reg);
                    F = Z80Flags.Carry | PSZtable[BC.high] | H35table[BC.high];
                    break;

                case 0x41:  // OUT (C),B
                    clock.Add(12);
                    device.Write(BC.reg, BC.high);
                    break;

                case 0x42:  // SBC HL,BC
                    clock.Add(15);
                    SBC(ref HL.reg, BC.reg);
                    break;

                case 0x43:  // LD (nnnn),BC
                    clock.Add(20);
                    addr = FetchWord();
                    memory.Write(addr++, BC.low);
                    memory.Write(addr, BC.high);
                    break;

                case 0x44:  // NEG
                    clock.Add(8);
                    b = A;
                    A = 0;
                    SUB8(b);
                    break;
                    
                case 0x45:  // RETN
                    clock.Add(14);
                    IFF1 = IFF2;
                    PC = POP();
                    break; 

                case 0x46:  // IM 0
                    clock.Add(8);
                    IM = 0;
                    break;

                case 0x47:  // LD I,A
                    clock.Add(9);
                    I = A;
                    break;

                case 0x48:  // IN C,(C)
                    clock.Add(12);
                    BC.low = device.Read(BC.reg);
                    F = Z80Flags.Carry | PSZtable[BC.low] | H35table[BC.low];
                    break;

                case 0x49:  // OUT (C),C
                    clock.Add(12);
                    device.Write(BC.reg, BC.low);
                    break;

                case 0x4a:  // ADC HL, BC
                    clock.Add(15);
                    ADC16(ref HL.reg, BC.reg);
                    break;

                case 0x4b:  // LD BC,(nnnn)
                    clock.Add(20);
                    addr = FetchWord();
                    BC.low = memory.Read(addr++);
                    BC.high = memory.Read(addr);
                    break;

                case 0x4c:  // NEG
                    clock.Add(8);
                    b = A;
                    A = 0;
                    SUB8(b);
                    break;
                    
                case 0x4d:  // RETI
                    clock.Add(14);
                    IFF1 = IFF2;
                    PC = POP();
                    break;

                case 0x4e:  // IM 0/1
                    clock.Add(8);
                    IM = 0;
                    break;

                case 0x4f:  // LD R,A
                    clock.Add(9);
                    R = A;
                    break;

                case 0x50:  // IN D,(C)
                    clock.Add(12);
                    DE.high = device.Read(BC.reg);
                    F = Z80Flags.Carry | PSZtable[DE.high] | H35table[DE.high];
                    break;

                case 0x51:  // OUT (C),D
                    clock.Add(12);
                    device.Write(BC.reg, DE.high);
                    break;

                default:
                    break;
            }
        }
    }
}