Skip to content

Commit

Permalink
Do a TODO: move clk to diskunit.
Browse files Browse the repository at this point in the history
Actually it's not really moving clk, because diskunit_context_t already has clk_ptr,
so it's more a de-duplication. Using the clock from the unit makes more clear
that both drives in a unit share their clock.


git-svn-id: https://svn.code.sf.net/p/vice-emu/code/trunk@44110 379a1393-f5fb-40a0-bcee-ef074d9b53f7
  • Loading branch information
Rhialto committed Jun 24, 2023
1 parent 5a9f55a commit 8710ee6
Show file tree
Hide file tree
Showing 4 changed files with 37 additions and 29 deletions.
8 changes: 5 additions & 3 deletions vice/src/drive/drive-writeprotect.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,18 +33,20 @@

uint8_t drive_writeprotect_sense(drive_t *dptr)
{
CLOCK clk = *(dptr->diskunit->clk_ptr);

/* Clear the write protection bit for the time the disk is pulled out on
detach. */
if (dptr->detach_clk != (CLOCK)0) {
if (*(dptr->clk) - dptr->detach_clk < DRIVE_DETACH_DELAY) {
if (clk - dptr->detach_clk < DRIVE_DETACH_DELAY) {
return 0x0;
}
dptr->detach_clk = (CLOCK)0;
}
/* Set the write protection bit for the minimum time until a new disk
can be inserted. */
if (dptr->attach_detach_clk != (CLOCK)0) {
if (*(dptr->clk) - dptr->attach_detach_clk
if (clk - dptr->attach_detach_clk
< DRIVE_ATTACH_DETACH_DELAY) {
return 0x10;
}
Expand All @@ -53,7 +55,7 @@ uint8_t drive_writeprotect_sense(drive_t *dptr)
/* Clear the write protection bit for the time the disk is put in on
attach. */
if (dptr->attach_clk != (CLOCK)0) {
if (*(dptr->clk) - dptr->attach_clk < DRIVE_ATTACH_DELAY) {
if (clk - dptr->attach_clk < DRIVE_ATTACH_DELAY) {
return 0x0;
}
dptr->attach_clk = (CLOCK)0;
Expand Down
19 changes: 9 additions & 10 deletions vice/src/drive/drive.c
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,6 @@ int drive_init(void)
for (d = 0; d < NUM_DRIVES; d++) {
drive = diskunit->drives[d];

drive->clk = &diskunit_clk[unit];
drive->unit = unit;
drive->drive = d;
drive->diskunit = diskunit_context[unit];
Expand Down Expand Up @@ -251,8 +250,8 @@ int drive_init(void)
drive->P64_image_loaded = 0;
drive->P64_dirty = 0;
drive->read_only = 0;
drive->led_last_change_clk = *(drive->clk);
drive->led_last_uiupdate_clk = *(drive->clk);
drive->led_last_change_clk = *(diskunit->clk_ptr);
drive->led_last_uiupdate_clk = *(diskunit->clk_ptr);
drive->led_active_ticks = 0;
drive->read_write_mode = 1;

Expand Down Expand Up @@ -604,8 +603,8 @@ void drive_reset(void)
for (d = 0; d < NUM_DRIVES; d++) {
drive_t *drive = unit->drives[d];

drive->led_last_change_clk = *(drive->clk);
drive->led_last_uiupdate_clk = *(drive->clk);
drive->led_last_change_clk = *(unit->clk_ptr);
drive->led_last_uiupdate_clk = *(unit->clk_ptr);
drive->led_active_ticks = 0;
}
is_jammed[dnr] = false;
Expand Down Expand Up @@ -889,15 +888,15 @@ static void drive_led_update(diskunit_context_t *unit, drive_t *drive, int base)
my_led_status = drive->led_status;
}

/* Update remaining led clock ticks. TODO: move clk to diskunit. */
/* Update remaining led clock ticks. */
if (drive->led_status & 1) {
drive->led_active_ticks += *(drive->clk)
drive->led_active_ticks += *(unit->clk_ptr)
- drive->led_last_change_clk;
}
drive->led_last_change_clk = *(drive->clk);
drive->led_last_change_clk = *(unit->clk_ptr);

led_period = *(drive->clk) - drive->led_last_uiupdate_clk;
drive->led_last_uiupdate_clk = *(drive->clk);
led_period = *(unit->clk_ptr) - drive->led_last_uiupdate_clk;
drive->led_last_uiupdate_clk = *(unit->clk_ptr);

if (led_period == 0) {
return;
Expand Down
5 changes: 1 addition & 4 deletions vice/src/drive/drive.h
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ struct gcr_s;
struct disk_image_s;

/* TODO: more parts of that struct should go into diskunit_context_s.
candidates: clk, clock_frequency
candidates: unit
*/
typedef struct drive_s {
unsigned int unit; /* 0 ... NUM_DISK_UNITS-1 */
Expand All @@ -220,9 +220,6 @@ typedef struct drive_s {
/* Pointer to the containing diskunit_context */
struct diskunit_context_s *diskunit;

/* Pointer to the diskunit clock. */
CLOCK *clk;

int led_status;

CLOCK led_last_change_clk;
Expand Down
34 changes: 22 additions & 12 deletions vice/src/drive/rotation.c
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ void rotation_reset(drive_t *drive)
rotation[dnr].accum = 0;
rotation[dnr].seed = 0;
rotation[dnr].xorShift32 = 0x1234abcd;
rotation[dnr].rotation_last_clk = *(drive->clk);
rotation[dnr].rotation_last_clk = *(drive->diskunit->clk_ptr);
rotation[dnr].ue7_counter = 0;
rotation[dnr].uf4_counter = 0;
rotation[dnr].fr_randcount = 0;
Expand Down Expand Up @@ -294,16 +294,21 @@ inline static uint32_t RANDOM_nextUInt(rotation_t *rptr)

void rotation_begins(drive_t *dptr)
{
/*
* FIXME: does this mean that rotation of both drives in a unit is the same?
* Fortunately the dual drives are not emulated at this level;
* the 2nd CPU is emulated abstractly.
*/
unsigned int dnr = dptr->unit;
rotation[dnr].rotation_last_clk = *(dptr->clk);
rotation[dnr].rotation_last_clk = *(dptr->diskunit->clk_ptr);
rotation[dnr].cycle_index = 0;
}

/* calculate wobble factor from the respective resources */
static void rotation_do_wobble(drive_t *dptr)
{
/* cpu cycles since last call */
CLOCK cpu_cycles = *(dptr->clk) - rotation[dptr->unit].rotation_last_clk;
CLOCK cpu_cycles = *(dptr->diskunit->clk_ptr) - rotation[dptr->unit].rotation_last_clk;

/* FIXME: we should introduce random deviation too */
#if 0
Expand Down Expand Up @@ -571,8 +576,9 @@ static void rotation_1541_gcr_cycle(drive_t *dptr)
CLOCK one_rotation = rptr->frequency ? 400000 : 200000;

/* cpu cycles since last call */
cpu_cycles = *(dptr->clk) - rptr->rotation_last_clk;
rptr->rotation_last_clk = *(dptr->clk);
CLOCK clk = *(dptr->diskunit->clk_ptr);
cpu_cycles = clk - rptr->rotation_last_clk;
rptr->rotation_last_clk = clk;
/* modulo, at least one revolution, but not more than two */
while (cpu_cycles > one_rotation * 2) {
cpu_cycles -= one_rotation;
Expand Down Expand Up @@ -942,8 +948,9 @@ static void rotation_1541_p64_cycle(drive_t *dptr)
CLOCK one_rotation = rptr->frequency ? 400000 : 200000;

/* cpu cycles since last call */
cpu_cycles = *(dptr->clk) - rptr->rotation_last_clk;
rptr->rotation_last_clk = *(dptr->clk);
CLOCK clk = *(dptr->diskunit->clk_ptr);
cpu_cycles = clk - rptr->rotation_last_clk;
rptr->rotation_last_clk = clk;
/* modulo, at least one revolution, but not more than two */
while (cpu_cycles > one_rotation * 2) {
cpu_cycles -= one_rotation;
Expand Down Expand Up @@ -975,7 +982,7 @@ static void rotation_1541_p64_cycle(drive_t *dptr)
}

/*******************************************************************************
* very simple and fast emulation for perfect images like those comming from
* very simple and fast emulation for perfect images like those coming from
* dxx files
******************************************************************************/
static void rotation_1541_simple(drive_t *dptr)
Expand All @@ -993,8 +1000,9 @@ static void rotation_1541_simple(drive_t *dptr)

/* Calculate the number of bits that have passed under the R/W head since
the last time. */
delta = *(dptr->clk) - rptr->rotation_last_clk;
rptr->rotation_last_clk = *(dptr->clk);
CLOCK clk = *(dptr->diskunit->clk_ptr);
delta = clk - rptr->rotation_last_clk;
rptr->rotation_last_clk = clk;

tmp += ((long)dptr->wobble_factor * 1000000L) / 3200000L;
tmp *= 30000UL;
Expand Down Expand Up @@ -1135,14 +1143,16 @@ uint8_t rotation_sync_found(drive_t *dptr)

void rotation_byte_read(drive_t *dptr)
{
CLOCK clk = *(dptr->diskunit->clk_ptr);

if (dptr->attach_clk != (CLOCK)0) {
if (*(dptr->clk) - dptr->attach_clk < DRIVE_ATTACH_DELAY) {
if (clk - dptr->attach_clk < DRIVE_ATTACH_DELAY) {
dptr->GCR_read = 0;
} else {
dptr->attach_clk = (CLOCK)0;
}
} else if (dptr->attach_detach_clk != (CLOCK)0) {
if (*(dptr->clk) - dptr->attach_detach_clk < DRIVE_ATTACH_DETACH_DELAY) {
if (clk - dptr->attach_detach_clk < DRIVE_ATTACH_DETACH_DELAY) {
dptr->GCR_read = 0;
} else {
dptr->attach_detach_clk = (CLOCK)0;
Expand Down

0 comments on commit 8710ee6

Please sign in to comment.