Skip to content

Commit

Permalink
Another TODO: move unit from drive_t to diskunit_context_t.
Browse files Browse the repository at this point in the history
Again this is really a deduplication, but one was signed an the other unsigned.
I settled on unsigned (like in drive_t) but a lot of printf formats needed
adjustment for that.


git-svn-id: https://svn.code.sf.net/p/vice-emu/code/trunk@44116 379a1393-f5fb-40a0-bcee-ef074d9b53f7
  • Loading branch information
Rhialto committed Jun 24, 2023
1 parent 2e31993 commit e980822
Show file tree
Hide file tree
Showing 20 changed files with 59 additions and 64 deletions.
12 changes: 5 additions & 7 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->unit = unit;
drive->drive = d;
drive->diskunit = diskunit_context[unit];
}
Expand Down Expand Up @@ -492,7 +491,7 @@ int drive_enable(diskunit_context_t *drv)
}

DBG(("drive_enable unit: %d", 8 + drv->mynumber));
resources_get_int_sprintf("Drive%dTrueEmulation", &drive_true_emulation, 8 + drv->mynumber);
resources_get_int_sprintf("Drive%uTrueEmulation", &drive_true_emulation, 8 + drv->mynumber);

/* Always disable kernal traps. */
if (!drive_true_emulation) {
Expand Down Expand Up @@ -536,8 +535,8 @@ void drive_disable(diskunit_context_t *drv)
drive initialization. */
drv->enable = 0;

DBG(("drive_disable unit: %d", 8 + drv->mynumber));
resources_get_int_sprintf("Drive%dTrueEmulation", &drive_true_emulation, 8 + drv->mynumber);
DBG(("drive_disable unit: %u", 8 + drv->mynumber));
resources_get_int_sprintf("Drive%uTrueEmulation", &drive_true_emulation, 8 + drv->mynumber);

if (rom_loaded) {
if (drv->type == DRIVE_TYPE_2000 || drv->type == DRIVE_TYPE_4000 ||
Expand Down Expand Up @@ -745,7 +744,7 @@ void drive_move_head(int step, drive_t *drive)
log_warning(drive_log, "ambiguous step count (%d)", step);
}
drive_gcr_data_writeback(drive);
drive_sound_head(drive->current_half_track, step, drive->unit);
drive_sound_head(drive->current_half_track, step, drive->diskunit->mynumber);
drive_set_half_track(drive->current_half_track + step, drive->side, drive);
}

Expand Down Expand Up @@ -920,7 +919,7 @@ static void drive_led_update(diskunit_context_t *unit, drive_t *drive, int base)

if (led_pwm1 != drive->led_last_pwm
|| my_led_status != drive->old_led_status) {
ui_display_drive_led(drive->unit, base, led_pwm1,
ui_display_drive_led(drive->diskunit->mynumber, base, led_pwm1,
(my_led_status & 2) ? 1000 : 0);
drive->led_last_pwm = led_pwm1;
drive->old_led_status = my_led_status;
Expand Down Expand Up @@ -1060,7 +1059,6 @@ static void drive_setup_context_for_unit(diskunit_context_t *drv,
/* TODO: init functions for allocated memory */
drv->drives[d]->image = NULL;
drv->drives[d]->diskunit = drv;
drv->drives[d]->unit = unr;
drv->drives[d]->drive = d;
}

Expand Down
4 changes: 0 additions & 4 deletions vice/src/drive/drive.h
Original file line number Diff line number Diff line change
Expand Up @@ -210,11 +210,7 @@ typedef struct drive_type_info_s {
struct gcr_s;
struct disk_image_s;

/* TODO: more parts of that struct should go into diskunit_context_s.
candidates: unit
*/
typedef struct drive_s {
unsigned int unit; /* 0 ... NUM_DISK_UNITS-1 */
unsigned int drive; /* DRIVE_NUMBER_MIN ... DRIVE_NUMBER_MAX */

/* Pointer to the containing diskunit_context */
Expand Down
6 changes: 3 additions & 3 deletions vice/src/drive/drivecpu.c
Original file line number Diff line number Diff line change
Expand Up @@ -91,8 +91,8 @@ void drivecpu_setup_context(struct diskunit_context_s *drv, int i)
cpu->d_bank_start = 0;
cpu->pageone = NULL;
if (i) {
cpu->snap_module_name = lib_msprintf("DRIVECPU%d", drv->mynumber);
cpu->identification_string = lib_msprintf("DRIVE#%d", drv->mynumber + 8);
cpu->snap_module_name = lib_msprintf("DRIVECPU%u", drv->mynumber);
cpu->identification_string = lib_msprintf("DRIVE#%u", drv->mynumber + 8);
cpu->monitor_interface = monitor_interface_new();
}
mi = cpu->monitor_interface;
Expand Down Expand Up @@ -512,7 +512,7 @@ static void drivecpu_jam(diskunit_context_t *drv)
break;
}

tmp = drive_jam(drv->mynumber, "%s (%d) CPU: JAM at $%04X ", dname, drv->mynumber + 8, (unsigned int)reg_pc);
tmp = drive_jam(drv->mynumber, "%s (%u) CPU: JAM at $%04X ", dname, drv->mynumber + 8, (unsigned int)reg_pc);
switch (tmp) {
case JAM_RESET:
reg_pc = 0xeaa0;
Expand Down
4 changes: 2 additions & 2 deletions vice/src/drive/drivecpu65c02.c
Original file line number Diff line number Diff line change
Expand Up @@ -80,8 +80,8 @@ void drivecpu65c02_setup_context(struct diskunit_context_s *drv, int i)
cpu->d_bank_start = 0;
cpu->pageone = NULL;
if (i) {
cpu->snap_module_name = lib_msprintf("DRIVECPU%d", drv->mynumber);
cpu->identification_string = lib_msprintf("DRIVE#%d", drv->mynumber + 8);
cpu->snap_module_name = lib_msprintf("DRIVECPU%u", drv->mynumber);
cpu->identification_string = lib_msprintf("DRIVE#%u", drv->mynumber + 8);
cpu->monitor_interface = monitor_interface_new();
}
mi = cpu->monitor_interface;
Expand Down
6 changes: 3 additions & 3 deletions vice/src/drive/driverom.c
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ int driverom_snapshot_write(snapshot_t *s, const drive_t *drive)
const uint8_t *base;
int len;

sprintf(snap_module_name, "DRIVEROM%u", drive->unit);
sprintf(snap_module_name, "DRIVEROM%u", drive->diskunit->mynumber);

m = snapshot_module_create(s, snap_module_name, ROM_SNAP_MAJOR, ROM_SNAP_MINOR);

Expand Down Expand Up @@ -334,7 +334,7 @@ int driverom_snapshot_read(snapshot_t *s, drive_t *drive)
uint8_t *base;
int len;

sprintf(snap_module_name, "DRIVEROM%u", drive->unit);
sprintf(snap_module_name, "DRIVEROM%u", drive->diskunit->mynumber);

m = snapshot_module_open(s, snap_module_name, &major_version, &minor_version);
if (m == NULL) {
Expand Down Expand Up @@ -434,7 +434,7 @@ int driverom_snapshot_read(snapshot_t *s, drive_t *drive)
return -1;
}

machine_drive_rom_do_checksum(drive->unit);
machine_drive_rom_do_checksum(drive->diskunit->mynumber);

return snapshot_module_close(m);
}
Expand Down
6 changes: 3 additions & 3 deletions vice/src/drive/drivetypes.h
Original file line number Diff line number Diff line change
Expand Up @@ -161,9 +161,9 @@ struct wd1770_s;
struct cmdhd_context_s;

typedef struct diskunit_context_s {
int mynumber; /* init to [0123] */
CLOCK *clk_ptr; /* shortcut to drive_clk[mynumber] */
struct drive_s *drives[2];
unsigned int mynumber; /* 0 ... NUM_DISK_UNITS-1 */
CLOCK *clk_ptr; /* shortcut to drive_clk[mynumber] */
struct drive_s *drives[NUM_DRIVES];

struct drivecpu_context_s *cpu;
struct drivecpud_context_s *cpud;
Expand Down
4 changes: 2 additions & 2 deletions vice/src/drive/iec/cia1571d.c
Original file line number Diff line number Diff line change
Expand Up @@ -281,7 +281,7 @@ void cia1571_setup_context(diskunit_context_t *ctxptr)

cia->prv = lib_malloc(sizeof(drivecia1571_context_t));
cia1571p = (drivecia1571_context_t *)(cia->prv);
cia1571p->number = (unsigned int)(ctxptr->mynumber);
cia1571p->number = ctxptr->mynumber;

cia->context = (void *)ctxptr;

Expand All @@ -294,7 +294,7 @@ void cia1571_setup_context(diskunit_context_t *ctxptr)

cia->debugFlag = 0;
cia->irq_line = IK_IRQ;
cia->myname = lib_msprintf("CIA1571D%d", ctxptr->mynumber);
cia->myname = lib_msprintf("CIA1571D%u", ctxptr->mynumber);

cia1571p->diskunit = ctxptr;

Expand Down
4 changes: 2 additions & 2 deletions vice/src/drive/iec/cia1581d.c
Original file line number Diff line number Diff line change
Expand Up @@ -255,7 +255,7 @@ void cia1581_setup_context(diskunit_context_t *ctxptr)

cia->prv = lib_malloc(sizeof(drivecia1581_context_t));
cia1581p = (drivecia1581_context_t *)(cia->prv);
cia1581p->number = (unsigned int)(ctxptr->mynumber);
cia1581p->number = ctxptr->mynumber;

cia->context = (void *)ctxptr;

Expand All @@ -269,7 +269,7 @@ void cia1581_setup_context(diskunit_context_t *ctxptr)

cia->debugFlag = 0;
cia->irq_line = IK_IRQ;
cia->myname = lib_msprintf("CIA1581D%d", ctxptr->mynumber);
cia->myname = lib_msprintf("CIA1581D%u", ctxptr->mynumber);

cia1581p->drive = ctxptr->drives[0];
cia1581p->iecbus = iecbus_drive_port();
Expand Down
22 changes: 11 additions & 11 deletions vice/src/drive/iec/cmdhd.c
Original file line number Diff line number Diff line change
Expand Up @@ -1005,7 +1005,7 @@ void cmdhd_setup_context(diskunit_context_t *ctxptr)
ctxptr->drives[0]->side = 0;

ctxptr->cmdhd = lib_calloc(1, sizeof(cmdhd_context_t));
ctxptr->cmdhd->myname = lib_msprintf("CMDHD%d", ctxptr->mynumber);
ctxptr->cmdhd->myname = lib_msprintf("CMDHD%u", ctxptr->mynumber);
ctxptr->cmdhd->mycontext = ctxptr;

ctxptr->cmdhd->image = NULL;
Expand All @@ -1023,12 +1023,12 @@ void cmdhd_setup_context(diskunit_context_t *ctxptr)
via10->rmw_flag = &(ctxptr->cpu->rmw_flag);
via10->clk_ptr = ctxptr->clk_ptr;

via10->myname = lib_msprintf("CMDHD%dVIA10", ctxptr->mynumber);
via10->my_module_name = lib_msprintf("CMDHD%dVIA10", ctxptr->mynumber);
via10->myname = lib_msprintf("CMDHD%uVIA10", ctxptr->mynumber);
via10->my_module_name = lib_msprintf("CMDHD%uVIA10", ctxptr->mynumber);

viacore_setup_context(via10);

via10->my_module_name_alt1 = lib_msprintf("CMDHDVIA10-%d", ctxptr->mynumber);
via10->my_module_name_alt1 = lib_msprintf("CMDHDVIA10-%u", ctxptr->mynumber);
via10->my_module_name_alt2 = lib_msprintf("CMDHDVIA10");

via10->irq_line = IK_IRQ;
Expand Down Expand Up @@ -1062,12 +1062,12 @@ void cmdhd_setup_context(diskunit_context_t *ctxptr)
via9->rmw_flag = &(ctxptr->cpu->rmw_flag);
via9->clk_ptr = ctxptr->clk_ptr;

via9->myname = lib_msprintf("CMDHD%dVIA9", ctxptr->mynumber);
via9->my_module_name = lib_msprintf("CMDHD%dVIA9", ctxptr->mynumber);
via9->myname = lib_msprintf("CMDHD%uVIA9", ctxptr->mynumber);
via9->my_module_name = lib_msprintf("CMDHD%uVIA9", ctxptr->mynumber);

viacore_setup_context(via9);

via9->my_module_name_alt1 = lib_msprintf("CMDHDVIA9-%d", ctxptr->mynumber);
via9->my_module_name_alt1 = lib_msprintf("CMDHDVIA9-%u", ctxptr->mynumber);
via9->my_module_name_alt2 = lib_msprintf("CMDHDVIA9");

via9->irq_line = IK_IRQ;
Expand All @@ -1093,7 +1093,7 @@ void cmdhd_setup_context(diskunit_context_t *ctxptr)
ctxptr->cmdhd->scsi = lib_calloc(1, sizeof(scsi_context_t));
scsi = ctxptr->cmdhd->scsi;
scsi->p = ctxptr->cmdhd;
scsi->myname = lib_msprintf("CMDHD%dSCSI", ctxptr->mynumber);
scsi->myname = lib_msprintf("CMDHD%uSCSI", ctxptr->mynumber);

ctxptr->cmdhd->i8255a = lib_calloc(1, sizeof(i8255a_state));
i8255a = ctxptr->cmdhd->i8255a;
Expand All @@ -1105,7 +1105,7 @@ void cmdhd_setup_context(diskunit_context_t *ctxptr)
i8255a->get_pb = get_pb;
i8255a->get_pc = get_pc;

name = lib_msprintf("CMDHD%dRTC", ctxptr->mynumber);
name = lib_msprintf("CMDHD%uRTC", ctxptr->mynumber);
ctxptr->cmdhd->rtc = rtc72421_init(name);
lib_free(name);

Expand Down Expand Up @@ -1229,7 +1229,7 @@ static void cmdhd_findbaselba(cmdhd_context_t *hd)

if (!hd->mycontext->parallel_cable && rlpresent) {
hd->mycontext->parallel_cable = 1;
CRIT((ERR, "CMDHD: RAMLink detected. Drive %d 'parallel cable' set to 'standard'.",
CRIT((ERR, "CMDHD: RAMLink detected. Drive %u 'parallel cable' set to 'standard'.",
hd->mycontext->mynumber + 8));
}
}
Expand Down Expand Up @@ -1303,7 +1303,7 @@ void cmdhd_reset(cmdhd_context_t *hd)
CRIT((ERR, "CMDHD: Image size too small, starting up in installation mode."));
if (hd->mycontext->parallel_cable) {
hd->mycontext->parallel_cable = 0;
CRIT((ERR, "CMDHD: Drive %d 'parallel cable' set to none. Set it back to 'standard' when",
CRIT((ERR, "CMDHD: Drive %u 'parallel cable' set to none. Set it back to 'standard' when",
hd->mycontext->mynumber + 8));
CRIT((ERR, "CMDHD: HDDOS installation is complete."));
}
Expand Down
2 changes: 1 addition & 1 deletion vice/src/drive/iec/pc8477.c
Original file line number Diff line number Diff line change
Expand Up @@ -251,7 +251,7 @@ void pc8477_setup_context(diskunit_context_t *drv)
{
int i;
drv->pc8477 = lib_calloc(1, sizeof(pc8477_t));
drv->pc8477->myname = lib_msprintf("PC8477_%d", drv->mynumber);
drv->pc8477->myname = lib_msprintf("PC8477_%u", drv->mynumber);
for (i = 0; i < 4; i++) {
drv->pc8477->fdds[i].num = i;
drv->pc8477->fdds[i].fdd = NULL;
Expand Down
6 changes: 3 additions & 3 deletions vice/src/drive/iec/via1d1541.c
Original file line number Diff line number Diff line change
Expand Up @@ -371,12 +371,12 @@ void via1d1541_setup_context(diskunit_context_t *ctxptr)
via->rmw_flag = &(ctxptr->cpu->rmw_flag);
via->clk_ptr = ctxptr->clk_ptr;

via->myname = lib_msprintf("1541Drive%dVia1", ctxptr->mynumber);
via->my_module_name = lib_msprintf("1541VIA1D%d", ctxptr->mynumber);
via->myname = lib_msprintf("1541Drive%uVia1", ctxptr->mynumber);
via->my_module_name = lib_msprintf("1541VIA1D%u", ctxptr->mynumber);

viacore_setup_context(via);

via->my_module_name_alt1 = lib_msprintf("VIA1D%d", ctxptr->mynumber);
via->my_module_name_alt1 = lib_msprintf("VIA1D%u", ctxptr->mynumber);
via->my_module_name_alt2 = lib_msprintf("VIA1D1541");

via->irq_line = IK_IRQ;
Expand Down
6 changes: 3 additions & 3 deletions vice/src/drive/iec/via4000.c
Original file line number Diff line number Diff line change
Expand Up @@ -290,12 +290,12 @@ void via4000_setup_context(diskunit_context_t *ctxptr)
via->rmw_flag = &(ctxptr->cpu->rmw_flag);
via->clk_ptr = ctxptr->clk_ptr;

via->myname = lib_msprintf("4000Drive%dVia1", ctxptr->mynumber);
via->my_module_name = lib_msprintf("4000VIA1D%d", ctxptr->mynumber);
via->myname = lib_msprintf("4000Drive%uVia1", ctxptr->mynumber);
via->my_module_name = lib_msprintf("4000VIA1D%u", ctxptr->mynumber);

viacore_setup_context(via);

via->my_module_name_alt1 = lib_msprintf("VIA1D%d", ctxptr->mynumber);
via->my_module_name_alt1 = lib_msprintf("VIA1D%u", ctxptr->mynumber);
via->my_module_name_alt2 = lib_msprintf("VIA4000");

via->irq_line = IK_IRQ;
Expand Down
2 changes: 1 addition & 1 deletion vice/src/drive/iec/wd1770.c
Original file line number Diff line number Diff line change
Expand Up @@ -179,7 +179,7 @@ void wd1770d_init(diskunit_context_t *drv)
}

drv->wd1770 = lib_calloc(1, sizeof(wd1770_t));
drv->wd1770->myname = lib_msprintf("WD1770%d", drv->mynumber);
drv->wd1770->myname = lib_msprintf("WD1770%u", drv->mynumber);
drv->wd1770->fdd = fdd_init(4 * drv->mynumber, drv->drives[0]);
drv->wd1770->cpu_clk_ptr = drv->clk_ptr;
drv->wd1770->is1772 = 0;
Expand Down
2 changes: 1 addition & 1 deletion vice/src/drive/ieee/fdc.c
Original file line number Diff line number Diff line change
Expand Up @@ -975,7 +975,7 @@ void fdc_init(diskunit_context_t *drv)
log_message(fdc_log, "fdc_init(drive %u)", fnum);
#endif

buffer = lib_msprintf("fdc%i", drv->mynumber);
buffer = lib_msprintf("fdc%u", drv->mynumber);
sysfdc->fdc_alarm = alarm_new(drv->cpu->alarm_context, buffer, int_fdc,
drv);
lib_free(buffer);
Expand Down
2 changes: 1 addition & 1 deletion vice/src/drive/ieee/riot1d.c
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ void riot1_setup_context(diskunit_context_t *ctxptr)

riotcore_setup_context(riot);

riot->myname = lib_msprintf("RIOT1D%d", ctxptr->mynumber);
riot->myname = lib_msprintf("RIOT1D%u", ctxptr->mynumber);

riot->undump_pra = undump_pra;
riot->undump_prb = undump_prb;
Expand Down
2 changes: 1 addition & 1 deletion vice/src/drive/ieee/riot2d.c
Original file line number Diff line number Diff line change
Expand Up @@ -295,7 +295,7 @@ void riot2_setup_context(diskunit_context_t *ctxptr)

riotcore_setup_context(riot);

riot->myname = lib_msprintf("RIOT2D%d", ctxptr->mynumber);
riot->myname = lib_msprintf("RIOT2D%u", ctxptr->mynumber);

riot2p->drives[0] = ctxptr->drives[0];
riot2p->drives[1] = ctxptr->drives[1];
Expand Down
6 changes: 3 additions & 3 deletions vice/src/drive/ieee/via1d2031.c
Original file line number Diff line number Diff line change
Expand Up @@ -327,12 +327,12 @@ void via1d2031_setup_context(diskunit_context_t *ctxptr)
via->rmw_flag = &(ctxptr->cpu->rmw_flag);
via->clk_ptr = ctxptr->clk_ptr;

via->myname = lib_msprintf("2031Drive%dVia1", ctxptr->mynumber);
via->my_module_name = lib_msprintf("2031VIA1D%d", ctxptr->mynumber);
via->myname = lib_msprintf("2031Drive%uVia1", ctxptr->mynumber);
via->my_module_name = lib_msprintf("2031VIA1D%u", ctxptr->mynumber);

viacore_setup_context(via);

via->my_module_name_alt1 = lib_msprintf("VIA1D%d", ctxptr->mynumber);
via->my_module_name_alt1 = lib_msprintf("VIA1D%u", ctxptr->mynumber);

via->irq_line = IK_IRQ;

Expand Down
Loading

0 comments on commit e980822

Please sign in to comment.