~ubuntu-branches/debian/sid/mame/sid

« back to all changes in this revision

Viewing changes to src/emu/machine/rtc65271.c

  • Committer: Bazaar Package Importer
  • Author(s): Jordi Mallach, Emmanuel Kasper, Félix Arreola Rodríguez, Jordi Mallach
  • Date: 2011-05-11 21:06:50 UTC
  • mfrom: (1.1.1 upstream)
  • Revision ID: james.westby@ubuntu.com-20110511210650-jizvh8a6x117y9hr
Tags: 0.142-1
[ Emmanuel Kasper ]
* New upstream release
* Set NOWERROR=1 to allow compiling with gcc-4.6
* Remove fix_powerpc_build.patch, as upstream has taken it in this release
* Add gnome-video-arcade front end as a suggested package

[ Félix Arreola Rodríguez ]
* Add kfreebsd-build.patch to quilt series, to fix build on kfreebsd

[ Jordi Mallach ]
* Remove unneeded and bogus addition of --with-quilt to the dh invocation.
* Add Cesare Falco (long time Ubuntu maintainer) to Uploaders, and wrap
  them into multiple lines.

Show diffs side-by-side

added added

removed removed

Lines of Context:
25
25
 
26
26
/* Delay between the beginning (UIP asserted) and the end (UIP cleared and
27
27
update interrupt asserted) of the update cycle */
28
 
#define UPDATE_CYCLE_TIME ATTOTIME_IN_USEC(1984)
 
28
#define UPDATE_CYCLE_TIME attotime::from_usec(1984)
29
29
/* Delay between the assertion of UIP and the effective start of the update
30
30
cycle */
31
 
/*#define UPDATE_CYCLE_DELAY ATTOTIME_IN_USEC(244)*/
 
31
/*#define UPDATE_CYCLE_DELAY attotime::from_usec(244)*/
32
32
 
33
33
typedef struct _rtc65271_state rtc65271_state;
34
34
struct _rtc65271_state
193
193
/*
194
194
    load the SRAM and register contents from file
195
195
*/
196
 
static int rtc65271_file_load(device_t *device, mame_file *file)
 
196
static int rtc65271_file_load(device_t *device, emu_file &file)
197
197
{
198
198
        rtc65271_state *state = get_safe_token(device);
199
199
        UINT8 buf;
200
200
 
201
201
 
202
202
        /* version flag */
203
 
        if (mame_fread(file, & buf, 1) != 1)
 
203
        if (file.read(&buf, 1) != 1)
204
204
                return 1;
205
205
        if (buf != 0)
206
206
                return 1;
207
207
 
208
208
        /* control registers */
209
 
        if (mame_fread(file, &buf, 1) != 1)
 
209
        if (file.read(&buf, 1) != 1)
210
210
                return 1;
211
211
        state->regs[reg_A] = buf & (reg_A_DV /*| reg_A_RS*/);
212
 
        if (mame_fread(file, &buf, 1) != 1)
 
212
        if (file.read(&buf, 1) != 1)
213
213
                return 1;
214
214
        state->regs[reg_B] = buf & (reg_B_SET | reg_B_DM | reg_B_24h | reg_B_DSE);
215
215
 
216
216
        /* alarm registers */
217
 
        if (mame_fread(file, &state->regs[reg_alarm_second], 1) != 1)
218
 
                return 1;
219
 
        if (mame_fread(file, &state->regs[reg_alarm_minute], 1) != 1)
220
 
                return 1;
221
 
        if (mame_fread(file, &state->regs[reg_alarm_hour], 1) != 1)
 
217
        if (file.read(&state->regs[reg_alarm_second], 1) != 1)
 
218
                return 1;
 
219
        if (file.read(&state->regs[reg_alarm_minute], 1) != 1)
 
220
                return 1;
 
221
        if (file.read(&state->regs[reg_alarm_hour], 1) != 1)
222
222
                return 1;
223
223
 
224
224
        /* user RAM */
225
 
        if (mame_fread(file, state->regs+14, 50) != 50)
 
225
        if (file.read(state->regs+14, 50) != 50)
226
226
                return 1;
227
227
 
228
228
        /* extended RAM */
229
 
        if (mame_fread(file, state->xram, 4096) != 4096)
 
229
        if (file.read(state->xram, 4096) != 4096)
230
230
                return 1;
231
231
 
232
232
        state->regs[reg_D] |= reg_D_VRT;        /* the data was backed up successfully */
236
236
                system_time systime;
237
237
 
238
238
                /* get the current date/time from the core */
239
 
                device->machine->current_datetime(systime);
 
239
                device->machine().current_datetime(systime);
240
240
 
241
241
                /* set clock registers */
242
242
                state->regs[reg_second] = systime.local_time.second;
277
277
/*
278
278
    save the SRAM and register contents to file
279
279
*/
280
 
static int rtc65271_file_save(device_t *device, mame_file *file)
 
280
static int rtc65271_file_save(device_t *device, emu_file &file)
281
281
{
282
282
        rtc65271_state *state = get_safe_token(device);
283
283
        UINT8 buf;
285
285
 
286
286
        /* version flag */
287
287
        buf = 0;
288
 
        if (mame_fwrite(file, & buf, 1) != 1)
 
288
        if (file.write(& buf, 1) != 1)
289
289
                return 1;
290
290
 
291
291
        /* control registers */
292
292
        buf = state->regs[reg_A] & (reg_A_DV | reg_A_RS);
293
 
        if (mame_fwrite(file, &buf, 1) != 1)
 
293
        if (file.write(&buf, 1) != 1)
294
294
                return 1;
295
295
        buf = state->regs[reg_B] & (reg_B_SET | reg_B_DM | reg_B_24h | reg_B_DSE);
296
 
        if (mame_fwrite(file, &buf, 1) != 1)
 
296
        if (file.write(&buf, 1) != 1)
297
297
                return 1;
298
298
 
299
299
        /* alarm registers */
300
 
        if (mame_fwrite(file, &state->regs[reg_alarm_second], 1) != 1)
301
 
                return 1;
302
 
        if (mame_fwrite(file, &state->regs[reg_alarm_minute], 1) != 1)
303
 
                return 1;
304
 
        if (mame_fwrite(file, &state->regs[reg_alarm_hour], 1) != 1)
 
300
        if (file.write(&state->regs[reg_alarm_second], 1) != 1)
 
301
                return 1;
 
302
        if (file.write(&state->regs[reg_alarm_minute], 1) != 1)
 
303
                return 1;
 
304
        if (file.write(&state->regs[reg_alarm_hour], 1) != 1)
305
305
                return 1;
306
306
 
307
307
        /* user RAM */
308
 
        if (mame_fwrite(file, state->regs+14, 50) != 50)
 
308
        if (file.write(state->regs+14, 50) != 50)
309
309
                return 1;
310
310
 
311
311
        /* extended RAM */
312
 
        if (mame_fwrite(file, state->xram, 4096) != 4096)
 
312
        if (file.write(state->xram, 4096) != 4096)
313
313
                return 1;
314
314
 
315
315
        return 0;
408
408
                                {
409
409
                                        if (data & reg_A_RS)
410
410
                                        {
411
 
                                                attotime period = ATTOTIME_IN_HZ(SQW_freq_table[data & reg_A_RS]);
412
 
                                                attotime half_period = attotime_div(period, 2);
413
 
                                                attotime elapsed = timer_timeelapsed(state->update_timer);
 
411
                                                attotime period = attotime::from_hz(SQW_freq_table[data & reg_A_RS]);
 
412
                                                attotime half_period = period / 2;
 
413
                                                attotime elapsed = state->update_timer->elapsed();
414
414
 
415
 
                                                if (attotime_compare(half_period, elapsed) > 0)
416
 
                                                        timer_adjust_oneshot(state->SQW_timer, attotime_sub(half_period, elapsed), 0);
 
415
                                                if (half_period > elapsed)
 
416
                                                        state->SQW_timer->adjust(half_period - elapsed);
417
417
                                                else
418
 
                                                        timer_adjust_oneshot(state->SQW_timer, half_period, 0);
 
418
                                                        state->SQW_timer->adjust(half_period);
419
419
                                        }
420
420
                                        else
421
421
                                        {
422
422
                                                state->SQW_internal_state = 0;  /* right??? */
423
423
 
424
424
                                                /* Stop the divider used for SQW and periodic interrupts. */
425
 
                                                timer_adjust_oneshot(state->SQW_timer, attotime_never, 0);
 
425
                                                state->SQW_timer->adjust(attotime::never);
426
426
                                        }
427
427
                                }
428
428
                                /* The UIP bit is read-only */
505
505
                field_interrupts(device);
506
506
        }
507
507
 
508
 
        half_period = attotime_div(ATTOTIME_IN_HZ(SQW_freq_table[state->regs[reg_A] & reg_A_RS]), 2);
509
 
        timer_adjust_oneshot(state->SQW_timer, half_period, 0);
 
508
        half_period = attotime::from_hz(SQW_freq_table[state->regs[reg_A] & reg_A_RS]) / 2;
 
509
        state->SQW_timer->adjust(half_period);
510
510
}
511
511
 
512
512
/*
522
522
                state->regs[reg_A] |= reg_A_UIP;
523
523
 
524
524
                /* schedule end of update cycle */
525
 
                timer_set(device->machine, UPDATE_CYCLE_TIME, (void *)device, 0, rtc_end_update_callback);
 
525
                device->machine().scheduler().timer_set(UPDATE_CYCLE_TIME, FUNC(rtc_end_update_callback), 0, (void *)device);
526
526
        }
527
527
}
528
528
 
688
688
        rtc65271_config *config = (rtc65271_config *)downcast<const legacy_device_config_base &>(device->baseconfig()).inline_config();
689
689
        rtc65271_state *state = get_safe_token(device);
690
690
 
691
 
        state->update_timer = timer_alloc(device->machine, rtc_begin_update_callback, (void *)device);
692
 
        timer_adjust_periodic(state->update_timer, ATTOTIME_IN_SEC(1), 0, ATTOTIME_IN_SEC(1));
693
 
        state->SQW_timer = timer_alloc(device->machine, rtc_SQW_callback, (void *)device);
 
691
        state->update_timer = device->machine().scheduler().timer_alloc(FUNC(rtc_begin_update_callback), (void *)device);
 
692
        state->update_timer->adjust(attotime::from_seconds(1), 0, attotime::from_seconds(1));
 
693
        state->SQW_timer = device->machine().scheduler().timer_alloc(FUNC(rtc_SQW_callback), (void *)device);
694
694
        state->interrupt_callback = config->interrupt_callback;
695
695
 
696
 
        state_save_register_device_item_array(device, 0, state->regs);
697
 
        state_save_register_device_item(device, 0, state->cur_reg);
698
 
        state_save_register_device_item_array(device, 0, state->xram);
699
 
        state_save_register_device_item(device, 0, state->cur_xram_page);
700
 
        state_save_register_device_item(device, 0, state->SQW_internal_state);
 
696
        device->save_item(NAME(state->regs));
 
697
        device->save_item(NAME(state->cur_reg));
 
698
        device->save_item(NAME(state->xram));
 
699
        device->save_item(NAME(state->cur_xram_page));
 
700
        device->save_item(NAME(state->SQW_internal_state));
701
701
}
702
702
 
703
703
 
704
704
static DEVICE_NVRAM( rtc65271 )
705
705
{
706
706
        if (read_or_write)
707
 
                rtc65271_file_save(device, file);
 
707
                rtc65271_file_save(device, *file);
708
708
        else if (file)
709
 
                rtc65271_file_load(device, file);
 
709
                rtc65271_file_load(device, *file);
710
710
}
711
711
 
712
712