annotate Plugins/Input/console/Gb_Cpu.cpp @ 98:e42694a28331 trunk

[svn] More progress -- now loads as an audacious module. :)
author nenolod
date Tue, 01 Nov 2005 21:34:11 -0800
parents 252843aac42f
children 7c5e886205ef
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
90
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
2 // Game_Music_Emu 0.2.4. http://www.slack.net/~ant/libs/
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
3
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
4 #include "Gb_Cpu.h"
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
5
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
6 #include <string.h>
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
7 #include <limits.h>
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
8
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
9 #include "blargg_endian.h"
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
10
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
11 /* Copyright (C) 2003-2005 Shay Green. This module is free software; you
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
12 can redistribute it and/or modify it under the terms of the GNU Lesser
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
13 General Public License as published by the Free Software Foundation; either
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
14 version 2.1 of the License, or (at your option) any later version. This
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
15 module is distributed in the hope that it will be useful, but WITHOUT ANY
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
16 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
17 FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
18 more details. You should have received a copy of the GNU Lesser General
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
19 Public License along with this module; if not, write to the Free Software
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
20 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA */
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
21
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
22 #include BLARGG_SOURCE_BEGIN
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
23
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
24 // Common instructions:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
25 //
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
26 // 365880 FA LD A,IND16
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
27 // 355863 20 JR NZ
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
28 // 313655 21 LD HL,IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
29 // 274580 28 JR Z
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
30 // 252878 FE CMP IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
31 // 230541 7E LD A,(HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
32 // 226209 2A LD A,(HL+)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
33 // 217467 CD CALL
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
34 // 212034 C9 RET
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
35 // 208376 CB CB prefix
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
36 //
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
37 // 27486 CB 7E BIT 7,(HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
38 // 15925 CB 76 BIT 6,(HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
39 // 13035 CB 19 RR C
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
40 // 11557 CB 7F BIT 7,A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
41 // 10898 CB 37 SWAP A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
42 // 10208 CB 66 BIT 4,(HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
43
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
44 static void write_unmapped( Gbs_Emu*, gb_addr_t, int )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
45 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
46 check( false );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
47 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
48
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
49 static int read_unmapped( Gbs_Emu*, gb_addr_t )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
50 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
51 check( false );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
52 return 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
53 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
54
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
55 Gb_Cpu::Gb_Cpu()
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
56 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
57 rst_base = 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
58 callback_data = NULL;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
59 data_writer [page_count] = write_unmapped;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
60 data_reader [page_count] = read_unmapped;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
61 reset();
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
62 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
63
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
64 void Gb_Cpu::reset( const void* unmapped_code_page )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
65 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
66 interrupts_enabled = false;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
67 remain_ = 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
68
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
69 r.pc = 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
70 r.sp = 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
71 r.flags = 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
72 r.a = 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
73 r.b = 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
74 r.c = 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
75 r.d = 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
76 r.e = 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
77 r.h = 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
78 r.l = 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
79
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
80 for ( int i = 0; i < page_count + 1; i++ )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
81 code_map [i] = (const uint8_t*) unmapped_code_page;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
82
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
83 map_memory( 0, 0x10000, read_unmapped, write_unmapped );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
84 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
85
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
86 void Gb_Cpu::map_code( gb_addr_t start, unsigned long size, const void* data )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
87 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
88 // start end end must fall on page bounadries
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
89 require( start % page_size == 0 && size % page_size == 0 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
90
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
91 unsigned first_page = start / page_size;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
92 for ( unsigned i = size / page_size; i--; )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
93 code_map [first_page + i] = (uint8_t*) data + i * page_size;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
94 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
95
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
96 void Gb_Cpu::map_memory( gb_addr_t start, unsigned long size, reader_t read, writer_t write )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
97 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
98 // start end end must fall on page bounadries
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
99 require( start % page_size == 0 && size % page_size == 0 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
100
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
101 if ( !read )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
102 read = read_unmapped;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
103 if ( !write )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
104 write = write_unmapped;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
105 unsigned first_page = start / page_size;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
106 for ( unsigned i = size / page_size; i--; ) {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
107 data_reader [first_page + i] = read;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
108 data_writer [first_page + i] = write;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
109 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
110 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
111
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
112 // Note: 'addr' is evaulated more than once in the following macros, so it
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
113 // must not contain side-effects.
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
114
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
115 #define READ( addr ) (data_reader [(addr) >> page_bits]( callback_data, addr ))
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
116 #define WRITE( addr, data ) (data_writer [(addr) >> page_bits]( callback_data, addr, data ))
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
117
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
118 #define READ_PROG( addr ) (code_map [(addr) >> page_bits] [(addr) & (page_size - 1)])
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
119 #define READ_PROG16( addr ) GET_LE16( &READ_PROG( addr ) )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
120
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
121 int Gb_Cpu::read( gb_addr_t addr ) {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
122 return READ( addr );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
123 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
124
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
125 BOOST::uint8_t* Gb_Cpu::get_code( gb_addr_t addr ) {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
126 return (uint8_t*) &READ_PROG( addr );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
127 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
128
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
129 void Gb_Cpu::write( gb_addr_t addr, int data ) {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
130 WRITE( addr, data );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
131 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
132
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
133 #ifndef GB_CPU_GLUE_ONLY
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
134
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
135 const unsigned z_flag = 0x80;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
136 const unsigned n_flag = 0x40;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
137 const unsigned h_flag = 0x20;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
138 const unsigned c_flag = 0x10;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
139
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
140 #include BLARGG_ENABLE_OPTIMIZER
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
141
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
142 Gb_Cpu::result_t Gb_Cpu::run( long cycle_count )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
143 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
144 const int cycles_per_instruction = 4;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
145
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
146 remain_ = cycle_count + cycles_per_instruction;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
147
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
148 Gb_Cpu::result_t result = result_cycles;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
149
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
150 #if BLARGG_CPU_POWERPC
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
151 const reader_t* data_reader = this->data_reader; // cache
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
152 const writer_t* data_writer = this->data_writer; // cache
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
153 #endif
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
154
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
155 union {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
156 struct {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
157 #if BLARGG_BIG_ENDIAN
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
158 uint8_t b, c, d, e, h, l, unused, a;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
159 # define R8( n ) (r8_ [n])
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
160 #elif BLARGG_LITTLE_ENDIAN
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
161 uint8_t c, b, e, d, l, h, a, unused;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
162 # define R8( n ) (r8_ [(n) ^ 1])
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
163 #else
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
164 # error "Byte order of CPU must be known."
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
165 #endif
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
166 } rg; // registers
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
167 struct {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
168 BOOST::uint16_t bc, de, hl, unused; // pairs
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
169 } rp;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
170 uint8_t r8_ [8]; // indexed registers (use R8 macro due to endian dependence)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
171 BOOST::uint16_t r16 [4]; // indexed pairs
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
172 };
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
173 BOOST_STATIC_ASSERT( sizeof rg == 8 && sizeof rp == 8 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
174
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
175 rg.a = r.a;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
176 rg.b = r.b;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
177 rg.c = r.c;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
178 rg.d = r.d;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
179 rg.e = r.e;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
180 rg.h = r.h;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
181 rg.l = r.l;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
182 unsigned pc = r.pc;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
183 unsigned sp = r.sp;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
184 unsigned flags = r.flags;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
185
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
186 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
187
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
188 unsigned data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
189
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
190 jr_taken:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
191 pc += (BOOST::int8_t) data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
192 inc_pc_loop:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
193 pc++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
194 loop:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
195
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
196 check( (unsigned) pc < 0x10000 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
197 check( (unsigned) sp < 0x10000 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
198 check( (flags & ~0xf0) == 0 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
199
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
200 // Read opcode and first operand. Optimize if processor's byte order is known
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
201 // and non-portable constructs are allowed.
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
202 #if BLARGG_NONPORTABLE && BLARGG_BIG_ENDIAN
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
203 data = *(BOOST::uint16_t*) &READ_PROG( pc );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
204 pc++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
205 unsigned op = data >> 8;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
206 data = (uint8_t) data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
207
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
208 #elif BLARGG_NONPORTABLE && BLARGG_LITTLE_ENDIAN
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
209 data = *(BOOST::uint16_t*) &READ_PROG( pc );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
210 pc++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
211 unsigned op = (uint8_t) data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
212 data >>= 8;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
213
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
214 #else
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
215 unsigned op = READ_PROG( pc );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
216 pc++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
217 data = READ_PROG( pc );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
218
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
219 #endif
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
220
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
221 if ( (remain_ -= cycles_per_instruction) <= 0 )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
222 goto stop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
223
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
224 switch ( op )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
225 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
226
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
227 // Most Common
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
228
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
229 case 0x20: // JR NZ
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
230 if ( !(flags & z_flag) )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
231 goto jr_taken;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
232 goto inc_pc_loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
233
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
234 case 0x21: // LD HL,IMM (common)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
235 rp.hl = READ_PROG16( pc );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
236 pc += 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
237 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
238
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
239 case 0x28: // JR Z
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
240 if ( flags & z_flag )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
241 goto jr_taken;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
242 goto inc_pc_loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
243
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
244 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
245 unsigned temp;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
246
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
247 case 0xF0: // LD A,(0xff00+imm)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
248 temp = data + 0xff00;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
249 pc++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
250 goto ld_a_ind_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
251
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
252 case 0xF2: // LD A,(0xff00+C)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
253 temp = rg.c + 0xff00;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
254 goto ld_a_ind_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
255
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
256 case 0x0A: // LD A,(BC)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
257 temp = rp.bc;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
258 goto ld_a_ind_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
259
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
260 case 0x3A: // LD A,(HL-)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
261 temp = rp.hl;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
262 rp.hl = temp - 1;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
263 goto ld_a_ind_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
264
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
265 case 0x1A: // LD A,(DE)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
266 temp = rp.de;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
267 goto ld_a_ind_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
268
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
269 case 0x2A: // LD A,(HL+) (common)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
270 temp = rp.hl;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
271 rp.hl = temp + 1;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
272 goto ld_a_ind_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
273
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
274 case 0xFA: // LD A,IND16 (common)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
275 temp = READ_PROG16( pc );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
276 pc += 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
277 ld_a_ind_comm:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
278 rg.a = READ( temp );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
279 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
280 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
281
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
282 case 0xBE: // CMP (HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
283 data = READ( rp.hl );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
284 goto cmp_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
285
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
286 case 0xB8: // CMP B
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
287 case 0xB9: // CMP C
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
288 case 0xBA: // CMP D
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
289 case 0xBB: // CMP E
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
290 case 0xBC: // CMP H
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
291 case 0xBD: // CMP L
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
292 data = R8( op & 7 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
293 goto cmp_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
294
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
295 case 0xFE: // CMP IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
296 pc++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
297 cmp_comm:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
298 op = rg.a;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
299 data = op - data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
300 sub_set_flags:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
301 flags = ((op & 15) - (data & 15)) & h_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
302 flags |= (data >> 4) & c_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
303 flags |= n_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
304 if ( data & 0xff )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
305 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
306 flags |= z_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
307 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
308
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
309 case 0x46: // LD B,(HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
310 case 0x4E: // LD C,(HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
311 case 0x56: // LD D,(HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
312 case 0x5E: // LD E,(HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
313 case 0x66: // LD H,(HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
314 case 0x6E: // LD L,(HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
315 case 0x7E: // LD A,(HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
316 R8( (op >> 3) & 7 ) = READ( rp.hl );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
317 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
318
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
319 case 0xC4: // CNZ (next-most-common)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
320 pc += 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
321 if ( flags & z_flag )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
322 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
323 call:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
324 pc -= 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
325 case 0xCD: // CALL (most-common)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
326 data = pc + 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
327 pc = READ_PROG16( pc );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
328 push:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
329 sp--;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
330 WRITE( sp, data >> 8 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
331 sp--;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
332 WRITE( sp, data & 0xff );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
333 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
334
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
335 case 0xC8: // RNZ (next-most-common)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
336 if ( !(flags & z_flag) )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
337 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
338 case 0xC9: // RET (most common)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
339 ret:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
340 pc = READ( sp );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
341 pc += 0x100 * READ( sp + 1 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
342 sp += 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
343 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
344
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
345 case 0x00: // NOP
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
346 case 0x40: // LD B,B
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
347 case 0x49: // LD C,C
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
348 case 0x52: // LD D,D
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
349 case 0x5B: // LD E,E
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
350 case 0x64: // LD H,H
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
351 case 0x6D: // LD L,L
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
352 case 0x7F: // LD A,A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
353 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
354
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
355 // CB Instructions
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
356
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
357 case 0xCB:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
358 pc++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
359 // now data is the opcode
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
360 switch ( data ) {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
361
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
362 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
363 int temp;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
364
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
365 case 0x46: // BIT b,(HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
366 case 0x4E:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
367 case 0x56:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
368 case 0x5E:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
369 case 0x66:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
370 case 0x6E:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
371 case 0x76:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
372 case 0x7E:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
373 temp = READ( rp.hl );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
374 goto bit_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
375
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
376 case 0x40: case 0x41: case 0x42: case 0x43: // BIT b,r
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
377 case 0x44: case 0x45: case 0x47: case 0x48:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
378 case 0x49: case 0x4A: case 0x4B: case 0x4C:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
379 case 0x4D: case 0x4F: case 0x50: case 0x51:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
380 case 0x52: case 0x53: case 0x54: case 0x55:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
381 case 0x57: case 0x58: case 0x59: case 0x5A:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
382 case 0x5B: case 0x5C: case 0x5D: case 0x5F:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
383 case 0x60: case 0x61: case 0x62: case 0x63:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
384 case 0x64: case 0x65: case 0x67: case 0x68:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
385 case 0x69: case 0x6A: case 0x6B: case 0x6C:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
386 case 0x6D: case 0x6F: case 0x70: case 0x71:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
387 case 0x72: case 0x73: case 0x74: case 0x75:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
388 case 0x77: case 0x78: case 0x79: case 0x7A:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
389 case 0x7B: case 0x7C: case 0x7D: case 0x7F:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
390 temp = R8( data & 7 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
391 bit_comm:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
392 int bit = (~data >> 3) & 7;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
393 flags &= ~n_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
394 flags |= h_flag | z_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
395 flags ^= (temp << bit) & z_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
396 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
397 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
398
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
399 case 0x86: // RES b,(HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
400 case 0x8E:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
401 case 0x96:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
402 case 0x9E:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
403 case 0xA6:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
404 case 0xAE:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
405 case 0xB6:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
406 case 0xBE:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
407 case 0xC6: // SET b,(HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
408 case 0xCE:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
409 case 0xD6:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
410 case 0xDE:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
411 case 0xE6:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
412 case 0xEE:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
413 case 0xF6:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
414 case 0xFE: {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
415 int temp = READ( rp.hl );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
416 int bit = 1 << ((data >> 3) & 7);
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
417 temp &= ~bit;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
418 if ( !(data & 0x40) )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
419 bit = 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
420 WRITE( rp.hl, temp | bit );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
421 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
422 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
423
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
424 case 0xC0: case 0xC1: case 0xC2: case 0xC3: // SET b,r
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
425 case 0xC4: case 0xC5: case 0xC7: case 0xC8:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
426 case 0xC9: case 0xCA: case 0xCB: case 0xCC:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
427 case 0xCD: case 0xCF: case 0xD0: case 0xD1:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
428 case 0xD2: case 0xD3: case 0xD4: case 0xD5:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
429 case 0xD7: case 0xD8: case 0xD9: case 0xDA:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
430 case 0xDB: case 0xDC: case 0xDD: case 0xDF:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
431 case 0xE0: case 0xE1: case 0xE2: case 0xE3:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
432 case 0xE4: case 0xE5: case 0xE7: case 0xE8:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
433 case 0xE9: case 0xEA: case 0xEB: case 0xEC:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
434 case 0xED: case 0xEF: case 0xF0: case 0xF1:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
435 case 0xF2: case 0xF3: case 0xF4: case 0xF5:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
436 case 0xF7: case 0xF8: case 0xF9: case 0xFA:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
437 case 0xFB: case 0xFC: case 0xFD: case 0xFF:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
438 R8( data & 7 ) |= 1 << ((data >> 3) & 7);
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
439 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
440
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
441 case 0x80: case 0x81: case 0x82: case 0x83: // RES b,r
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
442 case 0x84: case 0x85: case 0x87: case 0x88:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
443 case 0x89: case 0x8A: case 0x8B: case 0x8C:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
444 case 0x8D: case 0x8F: case 0x90: case 0x91:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
445 case 0x92: case 0x93: case 0x94: case 0x95:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
446 case 0x97: case 0x98: case 0x99: case 0x9A:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
447 case 0x9B: case 0x9C: case 0x9D: case 0x9F:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
448 case 0xA0: case 0xA1: case 0xA2: case 0xA3:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
449 case 0xA4: case 0xA5: case 0xA7: case 0xA8:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
450 case 0xA9: case 0xAA: case 0xAB: case 0xAC:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
451 case 0xAD: case 0xAF: case 0xB0: case 0xB1:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
452 case 0xB2: case 0xB3: case 0xB4: case 0xB5:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
453 case 0xB7: case 0xB8: case 0xB9: case 0xBA:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
454 case 0xBB: case 0xBC: case 0xBD: case 0xBF:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
455 R8( data & 7 ) &= ~(1 << ((data >> 3) & 7));
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
456 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
457
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
458 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
459 int temp;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
460 case 0x36: // SWAP (HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
461 temp = READ( rp.hl );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
462 goto swap_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
463
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
464 case 0x30: // SWAP B
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
465 case 0x31: // SWAP C
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
466 case 0x32: // SWAP D
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
467 case 0x33: // SWAP E
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
468 case 0x34: // SWAP H
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
469 case 0x35: // SWAP L
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
470 case 0x37: // SWAP A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
471 temp = R8( data & 7 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
472 swap_comm:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
473 op = (temp >> 4) | (temp << 4);
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
474 flags = 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
475 goto shift_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
476 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
477
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
478 // Shift/Rotate
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
479
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
480 case 0x06: // RLC (HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
481 case 0x16: // RL (HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
482 case 0x26: // SLA (HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
483 op = READ( rp.hl );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
484 goto rl_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
485
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
486 case 0x20: case 0x21: case 0x22: case 0x23: case 0x24: case 0x25: case 0x27: // SLA A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
487 case 0x00: case 0x01: case 0x02: case 0x03: case 0x04: case 0x05: case 0x07: // RLC A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
488 case 0x10: case 0x11: case 0x12: case 0x13: case 0x14: case 0x15: case 0x17: // RL A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
489 op = R8( data & 7 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
490 goto rl_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
491
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
492 case 0x3E: // SRL (HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
493 data += 0x10; // bump up to 0x4n to avoid preserving sign bit
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
494 case 0x1E: // RR (HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
495 case 0x0E: // RRC (HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
496 case 0x2E: // SRA (HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
497 op = READ( rp.hl );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
498 goto rr_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
499
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
500 case 0x38: case 0x39: case 0x3A: case 0x3B: case 0x3C: case 0x3D: case 0x3F: // SRL A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
501 data += 0x10; // bump up to 0x4n
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
502 case 0x18: case 0x19: case 0x1A: case 0x1B: case 0x1C: case 0x1D: case 0x1F: // RR A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
503 case 0x08: case 0x09: case 0x0A: case 0x0B: case 0x0C: case 0x0D: case 0x0F: // RRC A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
504 case 0x28: case 0x29: case 0x2A: case 0x2B: case 0x2C: case 0x2D: case 0x2F: // SRA A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
505 op = R8( data & 7 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
506 goto rr_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
507
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
508 } // CB op
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
509 assert( false ); // unhandled CB op
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
510
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
511 case 0x07: // RLCA
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
512 case 0x17: // RLA
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
513 data = op;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
514 op = rg.a;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
515 rl_comm:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
516 op <<= 1;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
517 op |= ((data & flags) >> 4) & 1; // RL and carry is set
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
518 flags = (op >> 4) & c_flag; // C = bit shifted out
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
519 if ( data < 0x10 ) // RLC
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
520 op |= op >> 8;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
521 // SLA doesn't fill lower bit
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
522 goto shift_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
523
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
524 case 0x0F: // RRCA
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
525 case 0x1F: // RRA
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
526 data = op;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
527 op = rg.a;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
528 rr_comm:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
529 op |= (data & flags) << 4; // RR and carry is set
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
530 flags = (op << 4) & c_flag; // C = bit shifted out
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
531 if ( data < 0x10 ) // RRC
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
532 op |= op << 8;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
533 op >>= 1;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
534 if ( data & 0x20 ) // SRA propagates sign bit
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
535 op |= (op << 1) & 0x80;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
536 shift_comm:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
537 data &= 7;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
538 if ( !(op & 0xff) )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
539 flags |= z_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
540 if ( data == 6 )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
541 goto write_hl_op_ff;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
542 R8( data ) = op;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
543 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
544
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
545 // Load
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
546
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
547 case 0x70: // LD (HL),B
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
548 case 0x71: // LD (HL),C
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
549 case 0x72: // LD (HL),D
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
550 case 0x73: // LD (HL),E
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
551 case 0x74: // LD (HL),H
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
552 case 0x75: // LD (HL),L
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
553 case 0x77: // LD (HL),A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
554 op = R8( op & 7 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
555 write_hl_op_ff:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
556 WRITE( rp.hl, op & 0xff );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
557 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
558
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
559 case 0x41: case 0x42: case 0x43: case 0x44: case 0x45: case 0x47: // LD r,r
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
560 case 0x48: case 0x4A: case 0x4B: case 0x4C: case 0x4D: case 0x4F:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
561 case 0x50: case 0x51: case 0x53: case 0x54: case 0x55: case 0x57:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
562 case 0x58: case 0x59: case 0x5A: case 0x5C: case 0x5D: case 0x5F:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
563 case 0x60: case 0x61: case 0x62: case 0x63: case 0x65: case 0x67:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
564 case 0x68: case 0x69: case 0x6A: case 0x6B: case 0x6C: case 0x6F:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
565 case 0x78: case 0x79: case 0x7A: case 0x7B: case 0x7C: case 0x7D:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
566 R8( (op >> 3) & 7 ) = R8( op & 7 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
567 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
568
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
569 case 0x08: // LD IND16,SP
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
570 data = READ_PROG16( pc );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
571 pc += 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
572 WRITE( data, sp&0xff );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
573 data++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
574 WRITE( data, sp >> 8 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
575 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
576
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
577 case 0xF9: // LD SP,HL
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
578 sp = rp.hl;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
579 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
580
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
581 case 0x31: // LD SP,IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
582 sp = READ_PROG16( pc );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
583 pc += 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
584 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
585
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
586 case 0x01: // LD BC,IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
587 case 0x11: // LD DE,IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
588 r16 [op >> 4] = READ_PROG16( pc );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
589 pc += 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
590 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
591
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
592 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
593 unsigned temp;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
594 case 0xE0: // LD (0xff00+imm),A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
595 temp = data + 0xff00;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
596 pc++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
597 goto write_data_rg_a;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
598
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
599 case 0xE2: // LD (0xff00+C),A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
600 temp = rg.c + 0xff00;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
601 goto write_data_rg_a;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
602
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
603 case 0x32: // LD (HL-),A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
604 temp = rp.hl;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
605 rp.hl = temp - 1;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
606 goto write_data_rg_a;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
607
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
608 case 0x02: // LD (BC),A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
609 temp = rp.bc;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
610 goto write_data_rg_a;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
611
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
612 case 0x12: // LD (DE),A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
613 temp = rp.de;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
614 goto write_data_rg_a;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
615
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
616 case 0x22: // LD (HL+),A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
617 temp = rp.hl;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
618 rp.hl = temp + 1;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
619 goto write_data_rg_a;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
620
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
621 case 0xEA: // LD IND16,A (common)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
622 temp = READ_PROG16( pc );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
623 pc += 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
624 write_data_rg_a:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
625 WRITE( temp, rg.a );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
626 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
627 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
628
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
629 case 0x06: // LD B,IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
630 rg.b = data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
631 goto inc_pc_loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
632
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
633 case 0x0E: // LD C,IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
634 rg.c = data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
635 goto inc_pc_loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
636
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
637 case 0x16: // LD D,IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
638 rg.d = data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
639 goto inc_pc_loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
640
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
641 case 0x1E: // LD E,IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
642 rg.e = data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
643 goto inc_pc_loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
644
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
645 case 0x26: // LD H,IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
646 rg.h = data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
647 goto inc_pc_loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
648
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
649 case 0x2E: // LD L,IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
650 rg.l = data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
651 goto inc_pc_loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
652
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
653 case 0x36: // LD (HL),IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
654 WRITE( rp.hl, data );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
655 goto inc_pc_loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
656
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
657 case 0x3E: // LD A,IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
658 rg.a = data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
659 goto inc_pc_loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
660
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
661 // Increment/Decrement
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
662
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
663 case 0x03: // INC BC
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
664 case 0x13: // INC DE
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
665 case 0x23: // INC HL
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
666 r16 [op >> 4]++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
667 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
668
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
669 case 0x33: // INC SP
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
670 sp++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
671 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
672
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
673 case 0x0B: // DEC BC
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
674 case 0x1B: // DEC DE
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
675 case 0x2B: // DEC HL
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
676 r16 [op >> 4]--;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
677 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
678
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
679 case 0x3B: // DEC SP
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
680 sp--;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
681 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
682
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
683 case 0x34: // INC (HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
684 op = rp.hl;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
685 data = READ( op );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
686 data++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
687 WRITE( op, data & 0xff );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
688 goto inc_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
689
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
690 case 0x04: // INC B
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
691 case 0x0C: // INC C (common)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
692 case 0x14: // INC D
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
693 case 0x1C: // INC E
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
694 case 0x24: // INC H
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
695 case 0x2C: // INC L
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
696 case 0x3C: // INC A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
697 op = (op >> 3) & 7;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
698 R8( op ) = data = R8( op ) + 1;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
699 inc_comm:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
700 flags = (flags & c_flag) | (((data & 15) - 1) & h_flag) | ((data >> 1) & z_flag);
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
701 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
702
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
703 case 0x35: // DEC (HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
704 op = rp.hl;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
705 data = READ( op );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
706 data--;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
707 WRITE( op, data & 0xff );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
708 goto dec_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
709
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
710 case 0x05: // DEC B
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
711 case 0x0D: // DEC C
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
712 case 0x15: // DEC D
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
713 case 0x1D: // DEC E
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
714 case 0x25: // DEC H
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
715 case 0x2D: // DEC L
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
716 case 0x3D: // DEC A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
717 op = (op >> 3) & 7;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
718 data = R8( op ) - 1;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
719 R8( op ) = data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
720 dec_comm:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
721 flags = (flags & c_flag) | n_flag | (((data & 15) + 0x31) & h_flag);
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
722 if ( data & 0xff )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
723 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
724 flags |= z_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
725 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
726
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
727 // Add 16-bit
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
728
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
729 {
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
730 unsigned long temp; // need more than 16 bits for carry
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
731 unsigned prev;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
732
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
733 case 0xF8: // LD HL,SP+imm
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
734 temp = BOOST::int8_t (data) & 0xffff; // sign-extend to 16 bits
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
735 pc++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
736 flags = 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
737 temp += sp;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
738 prev = sp;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
739 goto add_16_hl;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
740
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
741 case 0xE8: // ADD SP,IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
742 temp = BOOST::int8_t (data) & 0xffff; // sign-extend to 16 bits
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
743 pc++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
744 flags = 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
745 temp += sp;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
746 prev = sp;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
747 sp = temp;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
748 goto add_16_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
749
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
750 case 0x39: // ADD HL,SP
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
751 temp = sp;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
752 goto add_hl_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
753
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
754 case 0x09: // ADD HL,BC
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
755 case 0x19: // ADD HL,DE
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
756 case 0x29: // ADD HL,HL
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
757 temp = r16 [op >> 4];
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
758 add_hl_comm:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
759 prev = rp.hl;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
760 temp += prev;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
761 flags &= z_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
762 add_16_hl:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
763 rp.hl = temp;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
764 add_16_comm:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
765 flags |= (temp >> 12) & c_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
766 flags |= (((temp & 0x0fff) - (prev & 0x0fff)) >> 7) & h_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
767 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
768 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
769
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
770 case 0x86: // ADD (HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
771 data = READ( rp.hl );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
772 goto add_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
773
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
774 case 0x80: // ADD B
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
775 case 0x81: // ADD C
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
776 case 0x82: // ADD D
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
777 case 0x83: // ADD E
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
778 case 0x84: // ADD H
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
779 case 0x85: // ADD L
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
780 case 0x87: // ADD A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
781 data = R8( op & 7 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
782 goto add_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
783
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
784 case 0xC6: // ADD IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
785 pc++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
786 add_comm:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
787 flags = rg.a;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
788 data += flags;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
789 flags = ((data & 15) - (flags & 15)) & h_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
790 flags |= (data >> 4) & c_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
791 rg.a = data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
792 if ( data & 0xff )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
793 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
794 flags |= z_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
795 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
796
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
797 // Add/Subtract
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
798
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
799 case 0x8E: // ADC (HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
800 data = READ( rp.hl );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
801 goto adc_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
802
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
803 case 0x88: // ADC B
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
804 case 0x89: // ADC C
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
805 case 0x8A: // ADC D
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
806 case 0x8B: // ADC E
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
807 case 0x8C: // ADC H
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
808 case 0x8D: // ADC L
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
809 case 0x8F: // ADC A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
810 data = R8( op & 7 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
811 goto adc_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
812
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
813 case 0xCE: // ADC IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
814 pc++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
815 adc_comm:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
816 data += (flags >> 4) & 1;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
817 data &= 0xff; // to do: does carry get set when sum + carry = 0x100?
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
818 goto add_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
819
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
820 case 0x96: // SUB (HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
821 data = READ( rp.hl );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
822 goto sub_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
823
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
824 case 0x90: // SUB B
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
825 case 0x91: // SUB C
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
826 case 0x92: // SUB D
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
827 case 0x93: // SUB E
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
828 case 0x94: // SUB H
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
829 case 0x95: // SUB L
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
830 case 0x97: // SUB A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
831 data = R8( op & 7 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
832 goto sub_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
833
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
834 case 0xD6: // SUB IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
835 pc++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
836 sub_comm:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
837 op = rg.a;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
838 data = op - data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
839 rg.a = data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
840 goto sub_set_flags;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
841
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
842 case 0x9E: // SBC (HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
843 data = READ( rp.hl );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
844 goto sbc_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
845
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
846 case 0x98: // SBC B
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
847 case 0x99: // SBC C
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
848 case 0x9A: // SBC D
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
849 case 0x9B: // SBC E
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
850 case 0x9C: // SBC H
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
851 case 0x9D: // SBC L
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
852 case 0x9F: // SBC A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
853 data = R8( op & 7 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
854 goto sbc_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
855
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
856 case 0xDE: // SBC IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
857 pc++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
858 sbc_comm:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
859 data += (flags >> 4) & 1;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
860 data &= 0xff; // to do: does carry get set when sum + carry = 0x100?
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
861 goto sub_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
862
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
863 // Logical
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
864
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
865 case 0xA0: // AND B
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
866 case 0xA1: // AND C
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
867 case 0xA2: // AND D
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
868 case 0xA3: // AND E
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
869 case 0xA4: // AND H
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
870 case 0xA5: // AND L
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
871 data = R8( op & 7 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
872 goto and_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
873
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
874 case 0xA6: // AND (HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
875 data = READ( rp.hl );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
876 pc--;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
877 case 0xE6: // AND IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
878 pc++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
879 and_comm:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
880 rg.a &= data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
881 case 0xA7: // AND A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
882 flags = h_flag | (((rg.a - 1) >> 1) & z_flag);
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
883 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
884
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
885 case 0xB0: // OR B
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
886 case 0xB1: // OR C
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
887 case 0xB2: // OR D
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
888 case 0xB3: // OR E
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
889 case 0xB4: // OR H
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
890 case 0xB5: // OR L
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
891 data = R8( op & 7 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
892 goto or_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
893
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
894 case 0xB6: // OR (HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
895 data = READ( rp.hl );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
896 pc--;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
897 case 0xF6: // OR IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
898 pc++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
899 or_comm:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
900 rg.a |= data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
901 case 0xB7: // OR A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
902 flags = ((rg.a - 1) >> 1) & z_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
903 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
904
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
905 case 0xA8: // XOR B
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
906 case 0xA9: // XOR C
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
907 case 0xAA: // XOR D
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
908 case 0xAB: // XOR E
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
909 case 0xAC: // XOR H
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
910 case 0xAD: // XOR L
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
911 data = R8( op & 7 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
912 goto xor_comm;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
913
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
914 case 0xAE: // XOR (HL)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
915 data = READ( rp.hl );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
916 pc--;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
917 case 0xEE: // XOR IMM
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
918 pc++;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
919 xor_comm:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
920 data ^= rg.a;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
921 rg.a = data;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
922 data--;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
923 flags = (data >> 1) & z_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
924 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
925
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
926 case 0xAF: // XOR A
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
927 rg.a = 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
928 flags = z_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
929 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
930
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
931 // Stack
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
932
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
933 case 0xC1: // POP BC
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
934 case 0xD1: // POP DE
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
935 case 0xE1:{// POP HL (common)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
936 int temp = READ( sp );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
937 r16 [(op >> 4) & 3] = temp + 0x100 * READ( sp + 1 );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
938 sp += 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
939 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
940 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
941
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
942 case 0xF1: // POP FA
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
943 rg.a = READ( sp );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
944 flags = READ( sp + 1 ) & 0xf0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
945 sp += 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
946 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
947
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
948 case 0xC5: // PUSH BC
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
949 data = rp.bc;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
950 goto push;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
951
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
952 case 0xD5: // PUSH DE
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
953 data = rp.de;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
954 goto push;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
955
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
956 case 0xE5: // PUSH HL
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
957 data = rp.hl;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
958 goto push;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
959
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
960 case 0xF5: // PUSH FA
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
961 data = (flags << 8) | rg.a;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
962 goto push;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
963
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
964 // Flow control
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
965
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
966 case 0xC7: case 0xCF: case 0xD7: case 0xDF: // RST
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
967 case 0xE7: case 0xEF: case 0xF7: case 0xFF:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
968 data = pc;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
969 pc = (op & 0x38) + rst_base;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
970 goto push;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
971
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
972 case 0xCC: // CZ
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
973 pc += 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
974 if ( flags & z_flag )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
975 goto call;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
976 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
977
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
978 case 0xD4: // CNC
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
979 pc += 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
980 if ( !(flags & c_flag) )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
981 goto call;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
982 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
983
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
984 case 0xDC: // CC
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
985 pc += 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
986 if ( flags & c_flag )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
987 goto call;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
988 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
989
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
990 case 0xD9: // RETI
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
991 Gb_Cpu::interrupts_enabled = 1;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
992 goto ret;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
993
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
994 case 0xC0: // RZ
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
995 if ( !(flags & z_flag) )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
996 goto ret;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
997 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
998
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
999 case 0xD0: // RNC
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1000 if ( !(flags & c_flag) )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1001 goto ret;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1002 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1003
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1004 case 0xD8: // RC
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1005 if ( flags & c_flag )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1006 goto ret;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1007 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1008
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1009 case 0x18: // JR
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1010 goto jr_taken;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1011
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1012 case 0x30: // JR NC
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1013 if ( !(flags & c_flag) )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1014 goto jr_taken;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1015 goto inc_pc_loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1016
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1017 case 0x38: // JR C
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1018 if ( flags & c_flag )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1019 goto jr_taken;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1020 goto inc_pc_loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1021
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1022 case 0xE9: // JP_HL
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1023 pc = rp.hl;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1024 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1025
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1026 case 0xC3: // JP (next-most-common)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1027 pc = READ_PROG16( pc );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1028 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1029
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1030 case 0xC2: // JP NZ
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1031 pc += 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1032 if ( !(flags & z_flag) )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1033 goto jp_taken;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1034 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1035
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1036 case 0xCA: // JP Z (most common)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1037 pc += 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1038 if ( !(flags & z_flag) )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1039 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1040 jp_taken:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1041 pc -= 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1042 pc = READ_PROG16( pc );
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1043 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1044
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1045 case 0xD2: // JP NC
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1046 pc += 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1047 if ( !(flags & c_flag) )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1048 goto jp_taken;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1049 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1050
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1051 case 0xDA: // JP C
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1052 pc += 2;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1053 if ( flags & c_flag )
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1054 goto jp_taken;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1055 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1056
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1057 // Flags
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1058
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1059 case 0x2F: // CPL
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1060 rg.a = ~rg.a;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1061 flags |= n_flag | h_flag;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1062 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1063
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1064 case 0x3F: // CCF
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1065 flags = (flags ^ c_flag) & ~(n_flag | h_flag);
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1066 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1067
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1068 case 0x37: // SCF
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1069 flags = (flags | c_flag) & ~(n_flag | h_flag);
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1070 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1071
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1072 case 0xF3: // DI
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1073 interrupts_enabled = 0;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1074 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1075
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1076 case 0xFB: // EI
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1077 interrupts_enabled = 1;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1078 goto loop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1079
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1080 // Special
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1081
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1082 case 0xDD: case 0xD3: case 0xDB: case 0xE3: case 0xE4: // ?
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1083 case 0xEB: case 0xEC: case 0xF4: case 0xFD: case 0xFC:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1084 case 0x10: // STOP
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1085 case 0x27: // DAA (I'll have to implement this eventually...)
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1086 case 0xBF:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1087 case 0xED: // Z80 prefix
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1088 result = Gb_Cpu::result_badop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1089 goto stop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1090
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1091 case 0x76: // HALT
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1092 result = Gb_Cpu::result_halt;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1093 goto stop;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1094 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1095
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1096 assert( false ); // all opcodes should end with a goto
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1097
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1098 stop:
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1099 pc--;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1100
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1101 // copy state back
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1102 r.pc = pc;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1103 r.sp = sp;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1104 r.flags = flags;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1105 r.a = rg.a;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1106 r.b = rg.b;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1107 r.c = rg.c;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1108 r.d = rg.d;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1109 r.e = rg.e;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1110 r.h = rg.h;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1111 r.l = rg.l;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1112
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1113 return result;
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1114 }
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1115
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1116 #endif
252843aac42f [svn] Import the initial sources for console music support.
nenolod
parents:
diff changeset
1117