forked from RobertBaruch/vz80core
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsequencer_tasks.vh
383 lines (344 loc) · 8.81 KB
/
sequencer_tasks.vh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
`ifndef _sequencer_tasks_vh_
`define _sequencer_tasks_vh_
`include "z80.vh"
// Index of tasks:
//
// task_done()
// task_read_mem(n, addr) // requires one cycle delay with task_collect_data(n)
// task_collect_data(n)
// task_write_mem(n, addr, data) // requires one cycle delay with task_write_mem_done(n)
// task_write_mem_done(n)
// task_read_io(addr) // requires one cycle delay with task_collect_data(1)
// task_write_io(addr, data) // requires one cycle delay with task_write_io_done()
// task_write_io_done()
// task_read_reg(n, rnum)
// task_write_reg(rnum, data)
// task_write_i(data) // write the I register
// task_write_r(data) // write the R register
// task_write_f(data) // write the Flags register
// task_block_inc()
// task_block_dec()
// task_compare_block_inc()
// task_compare_block_dec()
// task_ex_de_hl()
// task_ex_af_af2()
// task_exx()
// task_alu8_op(func, x, y)
// task_alu16_op(func, x, y)
// task_rotate_decimal(left, acc, mem, addr) // For RRD/RLD insns.
// task_jump(addr)
// task_jump_relative(offset)
// task_enable_interrupts()
// task_disable_interrupts()
// task_accept_nmi()
// task_ret_from_nmi()
// task_set_im(mode)
// task_read_mem(n, addr)
//
// n is 1 or 2, depending on whether you're reading for the first time
// in the instruction, or the second time (not including instruction
// bytes).
//
// Set up to read memory at the given address. n is the
// number of the read in this instruction, starting from 1.
// n makes no difference in the logic, but does matter to
// formal.
task task_read_mem;
input [1:0] local_n;
input [15:0] local_addr;
begin
next_addr = local_addr;
next_mem_rd = 1;
`ifdef Z80_FORMAL
if (local_n == 1) begin
next_z80fi_mem_rd = 1;
next_z80fi_bus_raddr = local_addr;
end else begin
next_z80fi_mem_rd2 = 1;
next_z80fi_bus_raddr2 = local_addr;
end
`endif
end
endtask
// task_read_io(addr)
//
// Reads a byte of I/O with the given address.
task task_read_io;
input [15:0] local_addr;
begin
next_addr = local_addr;
next_mem_rd = 0;
next_io_rd = 1;
`ifdef Z80_FORMAL
next_z80fi_io_rd = 1;
next_z80fi_bus_raddr = local_addr;
`endif
end
endtask
// task_collect_data(n)
// Collect the data read from memory. n is the
// number of the read in this instruction, starting from 1.
// The collected data is in next_collected_data.
task task_collect_data;
input [1:0] local_n;
begin
if (local_n == 1) next_collected_data[7:0] = bus_rdata;
else next_collected_data[15:8] = bus_rdata;
`ifdef Z80_FORMAL
if (local_n == 1) next_z80fi_bus_rdata = bus_rdata;
else next_z80fi_bus_rdata2 = bus_rdata;
`endif
end
endtask
// task_write_mem(n, addr, data)
//
// n is 1 or 2, depending on whether you're writing for the first time
// in the instruction, or the second time.
//
// You must delay one cycle before continuing (or ending) the instruction,
// with task_write_mem_done(n).
task task_write_mem;
input [1:0] local_n;
input [15:0] local_addr;
input [7:0] local_data;
begin
next_addr = local_addr;
next_mem_rd = 0;
next_mem_wr = 1;
next_bus_wdata = local_data;
end
endtask
task task_write_mem_done;
input [1:0] local_n;
begin
next_mem_wr = 0;
`ifdef Z80_FORMAL
if (local_n == 1) begin
next_z80fi_mem_wr = 1;
next_z80fi_bus_waddr = addr;
next_z80fi_bus_wdata = bus_wdata;
end else begin
next_z80fi_mem_wr2 = 1;
next_z80fi_bus_waddr2 = addr;
next_z80fi_bus_wdata2 = bus_wdata;
end
`endif
end
endtask
// task_write_io(addr, data)
//
// You must delay one cycle before continuing (or ending) the instruction,
// with task_write_io_done().
task task_write_io;
input [15:0] local_addr;
input [7:0] local_data;
begin
next_addr = local_addr;
next_mem_rd = 0;
next_io_rd = 0;
next_io_wr = 1;
next_bus_wdata = local_data;
end
endtask
task task_write_io_done;
begin
next_io_wr = 0;
`ifdef Z80_FORMAL
next_z80fi_io_wr = 1;
next_z80fi_bus_waddr = addr;
next_z80fi_bus_wdata = bus_wdata;
`endif
end
endtask
// task_read_reg places the given register on the given
// register output bus (there are two of them, 1 and 2). Remember that
// if you need the register output for more than one cycle, you
// have to read it again. This doesn't cost anything.
task task_read_reg;
input [1:0] local_n;
input `reg_select local_rnum;
begin
if (local_n == 1) reg1_rnum = local_rnum;
else reg2_rnum = local_rnum;
end
endtask
// task_write_reg writes the given register with the given data
// on the next positive edge of the clock. If writing an 8-bit
// register, the upper 8 bits of the data are ignored.
task task_write_reg;
input `reg_select local_wnum;
input [15:0] local_data;
begin
reg_wr = 1;
reg_wnum = local_wnum;
reg_wdata = local_data;
end
endtask
// Sets up the registers to do a block increment operation on the
// next positive edge of the clock.
task task_block_inc;
begin
block_inc = 1;
end
endtask
// Sets up the registers to do a block decrement operation on the
// next positive edge of the clock.
task task_block_dec;
begin
block_dec = 1;
end
endtask
// Sets up the registers to do a compare block increment operation on the
// next positive edge of the clock.
task task_compare_block_inc;
begin
block_inc = 1;
block_compare = 1;
end
endtask
// Sets up the registers to do a compare block decrement operation on the
// next positive edge of the clock.
task task_compare_block_dec;
begin
block_dec = 1;
block_compare = 1;
end
endtask
// Sets up the registers to exchange DE and HL on the
// next positive edge of the clock.
task task_ex_de_hl;
begin
ex_de_hl = 1;
end
endtask
// Sets up the registers to exchange AF and AF2 on the
// next positive edge of the clock.
task task_ex_af_af2;
begin
ex_af_af2 = 1;
end
endtask
// Sets up the registers to exchange BC, DE, HL and BC2, DE2, HL2
// on the next positive edge of the clock.
task task_exx;
begin
exx = 1;
end
endtask
// task_write_i writes the I register on the next positive edge of the clock.
task task_write_i;
input [7:0] local_data;
begin
i_wr = 1;
i_wdata = local_data;
end
endtask
// task_write_r writes the R register on the next positive edge of the clock.
task task_write_r;
input [7:0] local_data;
begin
r_wr = 1;
r_wdata = local_data;
end
endtask
// task_write_f writes the Flags register on the next positive edge of the clock.
task task_write_f;
input [7:0] local_data;
begin
f_wr = 1;
f_wdata = local_data;
end
endtask
task task_alu8_compare;
input [7:0] local_x;
input [7:0] local_y;
begin
alu8_x = local_x;
alu8_y = local_y;
alu8_func = `ALU_FUNC_SUB;
end
endtask
task task_alu8_op;
input [3:0] local_op;
input [7:0] local_x;
input [7:0] local_y;
begin
alu8_x = local_x;
alu8_y = local_y;
alu8_func = local_op;
end
endtask
task task_alu16_op;
input [2:0] local_op;
input [15:0] local_x;
input [15:0] local_y;
begin
alu16_x = local_x;
alu16_y = local_y;
alu16_func = local_op;
end
endtask
task task_rotate_decimal;
input left;
input [7:0] a;
input [7:0] m;
input [15:0] addr;
begin
task_write_reg(`REG_A, left ? {a[7:4], m[7:4]} : {a[7:4], m[3:0]});
task_write_mem(1, addr, left ? {m[3:0], a[3:0]} : {a[3:0], m[7:4]});
task_write_f({
a[7], // S
a[7:4] == 0 && (left ? m[7:4] : m[3:0]) == 0, // Z
f_rdata[`FLAG_5_NUM],
1'b0, // H
f_rdata[`FLAG_3_NUM],
_alu_parity8(left ? {a[7:4], m[7:4]} : {a[7:4], m[3:0]}), // V
1'b0, // N
f_rdata[`FLAG_C_NUM]
});
end
endtask
task task_disable_interrupts;
begin
disable_interrupts = 1;
end
endtask
task task_enable_interrupts;
begin
enable_interrupts = 1;
end
endtask
task task_accept_nmi;
begin
accept_nmi = 1;
end
endtask
task task_ret_from_nmi;
begin
ret_from_nmi = 1;
end
endtask
task task_jump;
input [15:0] local_addr;
begin
next_z80_reg_ip = local_addr;
end
endtask
task task_jump_relative;
input [15:0] offset;
begin
next_z80_reg_ip = next_z80_reg_ip + offset;
end
endtask
task task_set_im;
input [1:0] mode;
begin
next_z80_reg_im = mode;
end
endtask
// task_done must be run at the end of an instruction, otherwise the
// instruction will never end!
task task_done;
next_done = 1;
endtask
`endif // _sequencer_tasks_vh_