comparison ztestgen.c @ 619:3072fb746601

Added support for JR and JRcc in Z80 test generator
author Michael Pavone <pavone@retrodev.com>
date Mon, 29 Dec 2014 21:36:17 -0800
parents abc834e4a520
children a6c6b621d0dc
comparison
equal deleted inserted replaced
618:abc834e4a520 619:3072fb746601
287 } 287 }
288 } 288 }
289 reg_usage[inst->reg] = 1; 289 reg_usage[inst->reg] = 1;
290 } 290 }
291 uint8_t counter_reg = Z80_UNUSED; 291 uint8_t counter_reg = Z80_UNUSED;
292 if (inst->op == Z80_JP || inst->op == Z80_JPCC) { 292 if (inst->op >= Z80_JP && inst->op <= Z80_JRCC) {
293 counter_reg = alloc_reg8(reg_usage, reg_values, 0); 293 counter_reg = alloc_reg8(reg_usage, reg_values, 0);
294 } 294 }
295 puts("--------------"); 295 puts("--------------");
296 for (uint8_t reg = 0; reg < Z80_UNUSED; reg++) { 296 for (uint8_t reg = 0; reg < Z80_UNUSED; reg++) {
297 if (reg_values[reg]) { 297 if (reg_values[reg]) {
364 *(cur++) = inst->ea_reg; 364 *(cur++) = inst->ea_reg;
365 } else if ((inst->op == Z80_JP || inst->op == Z80_JPCC) && addr_mode == Z80_IMMED) { 365 } else if ((inst->op == Z80_JP || inst->op == Z80_JPCC) && addr_mode == Z80_IMMED) {
366 uint16_t address = cur - prog + 3 + i; //2 for immed address, 1/2 for instruction(s) to skip 366 uint16_t address = cur - prog + 3 + i; //2 for immed address, 1/2 for instruction(s) to skip
367 *(cur++) = address; 367 *(cur++) = address;
368 *(cur++) = address >> 8; 368 *(cur++) = address >> 8;
369 } else if(inst->op == Z80_JR || inst->op == Z80_JRCC) {
370 *(cur++) = 1 + i; //skip one or 2 instructions based on value of i
369 } else if (addr_mode == Z80_IMMED & inst->op != Z80_IM) { 371 } else if (addr_mode == Z80_IMMED & inst->op != Z80_IM) {
370 *(cur++) = inst->immed & 0xFF; 372 *(cur++) = inst->immed & 0xFF;
371 if (word_sized) { 373 if (word_sized) {
372 *(cur++) = inst->immed >> 8; 374 *(cur++) = inst->immed >> 8;
373 } 375 }
379 *(cur++) = inst->immed & 0xFF; 381 *(cur++) = inst->immed & 0xFF;
380 } 382 }
381 if (instlen == 3) { 383 if (instlen == 3) {
382 *(cur++) = instbuf[2]; 384 *(cur++) = instbuf[2];
383 } 385 }
384 if (inst->op == Z80_JP || inst->op == Z80_JPCC) { 386 if (inst->op >= Z80_JP && inst->op <= Z80_JRCC) {
385 cur = inc_r(cur, counter_reg); 387 cur = inc_r(cur, counter_reg);
386 if (i) { 388 if (i) {
387 //inc twice on second iteration so we can differentiate the two 389 //inc twice on second iteration so we can differentiate the two
388 cur = inc_r(cur, counter_reg); 390 cur = inc_r(cur, counter_reg);
389 } 391 }
460 } 462 }
461 463
462 464
463 uint8_t should_skip(z80inst * inst) 465 uint8_t should_skip(z80inst * inst)
464 { 466 {
465 return inst->op >= Z80_JR || (inst->op >= Z80_LDI && inst->op <= Z80_CPDR) || inst->op == Z80_HALT 467 return inst->op >= Z80_DJNZ || (inst->op >= Z80_LDI && inst->op <= Z80_CPDR) || inst->op == Z80_HALT
466 || inst->op == Z80_DAA || inst->op == Z80_RLD || inst->op == Z80_RRD || inst->op == Z80_NOP 468 || inst->op == Z80_DAA || inst->op == Z80_RLD || inst->op == Z80_RRD || inst->op == Z80_NOP
467 || inst->op == Z80_DI || inst->op == Z80_EI; 469 || inst->op == Z80_DI || inst->op == Z80_EI;
468 } 470 }
469 471
470 void z80_gen_all() 472 void z80_gen_all()