comparison upd78k2_util.c @ 2718:8ce5d1a7ef54

Initial work to integrate PAC-less LaserActive emulation
author Michael Pavone <pavone@retrodev.com>
date Wed, 16 Jul 2025 12:32:28 -0700
parents 033d8d4308e3
children
comparison
equal deleted inserted replaced
2717:04007ac9ee3b 2718:8ce5d1a7ef54
1 #include <string.h> 1 #include <string.h>
2 2
3 //#define FETCH_DEBUG
3 void upd78k2_read_8(upd78k2_context *upd) 4 void upd78k2_read_8(upd78k2_context *upd)
4 { 5 {
6 #ifdef FETCH_DEBUG
5 uint32_t tmp = upd->scratch1; 7 uint32_t tmp = upd->scratch1;
8 #endif
6 upd->scratch1 = read_byte(upd->scratch1, (void **)upd->mem_pointers, &upd->opts->gen, upd); 9 upd->scratch1 = read_byte(upd->scratch1, (void **)upd->mem_pointers, &upd->opts->gen, upd);
10 #ifdef FETCH_DEBUG
7 if (tmp == upd->pc) { 11 if (tmp == upd->pc) {
8 printf("uPD78K/II fetch %04X: %02X, AX=%02X%02X BC=%02X%02X DE=%02X%02X HL=%02X%02X SP=%04X\n", tmp, upd->scratch1, 12 printf("uPD78K/II fetch %04X: %02X, AX=%02X%02X BC=%02X%02X DE=%02X%02X HL=%02X%02X SP=%04X\n", tmp, upd->scratch1,
9 upd->main[1], upd->main[0], upd->main[3], upd->main[2], upd->main[5], upd->main[4], upd->main[7], upd->main[6], upd->sp); 13 upd->main[1], upd->main[0], upd->main[3], upd->main[2], upd->main[5], upd->main[4], upd->main[7], upd->main[6], upd->sp);
10 } 14 }
15 #endif
11 //FIXME: cycle count 16 //FIXME: cycle count
12 upd->cycles += 2 * upd->opts->gen.clock_divider; 17 upd->cycles += 2 * upd->opts->gen.clock_divider;
13 } 18 }
14 19
15 void upd78k2_write_8(upd78k2_context *upd) 20 void upd78k2_write_8(upd78k2_context *upd)
177 cycle += upd->tm1_cycle; 182 cycle += upd->tm1_cycle;
178 if (cycle < next_int) { 183 if (cycle < next_int) {
179 next_int = cycle; 184 next_int = cycle;
180 } 185 }
181 } 186 }
187 #ifdef FETCH_DEBUG
182 if (next_int != upd->int_cycle) { 188 if (next_int != upd->int_cycle) {
183 printf("UPD78K/II int cycle: %u, cur cycle %u\n", next_int, upd->cycles); 189 printf("UPD78K/II int cycle: %u, cur cycle %u\n", next_int, upd->cycles);
184 } 190 }
191 #endif
185 upd->int_cycle = next_int; 192 upd->int_cycle = next_int;
186 } 193 }
187 194
188 uint8_t upd78237_sfr_read(uint32_t address, void *context) 195 uint8_t upd78237_sfr_read(uint32_t address, void *context)
189 { 196 {
490 vector = 0x20; 497 vector = 0x20;
491 } 498 }
492 } 499 }
493 fatal_error("upd78k2_calc_vector: %X\n", upd->scratch1); 500 fatal_error("upd78k2_calc_vector: %X\n", upd->scratch1);
494 } 501 }
502
503 void upd78k2_adjust_cycles(upd78k2_context *upd, uint32_t deduction)
504 {
505 upd78k2_update_timer0(upd);
506 upd78k2_update_timer1(upd);
507 if (upd->cycles <= deduction) {
508 upd->cycles = 0;
509 } else {
510 upd->cycles -= deduction;
511 }
512 if (upd->tm0_cycle <= deduction) {
513 upd->tm0_cycle = 0;
514 } else {
515 upd->tm0_cycle -= deduction;
516 }
517 if (upd->tm1_cycle <= deduction) {
518 upd->tm1_cycle = 0;
519 } else {
520 upd->tm1_cycle -= deduction;
521 }
522 }