~ubuntu-branches/ubuntu/utopic/vice/utopic

« back to all changes in this revision

Viewing changes to src/vicii/viciidtv-snapshot.c

  • Committer: Package Import Robot
  • Author(s): Logan Rosen
  • Date: 2014-05-10 21:08:23 UTC
  • mfrom: (17.2.1 utopic-proposed)
  • Revision ID: package-import@ubuntu.com-20140510210823-r7x98jmpl1x7rgop
Tags: 2.4.dfsg+2.4.6-1ubuntu1
Use autotools-dev to update config.{sub,guess} for new arches.

Show diffs side-by-side

added added

removed removed

Lines of Context:
121
121
    /* FIXME: Dispatch all events?  */
122
122
 
123
123
    m = snapshot_module_create (s, snap_module_name, SNAP_MAJOR, SNAP_MINOR);
124
 
    if (m == NULL)
 
124
    if (m == NULL) {
125
125
        return -1;
 
126
    }
126
127
 
127
128
    if (0
128
129
        /* AllowBadLines */
150
151
        /* RasterCycle */
151
152
        || SMW_B(m, (BYTE)(VICII_RASTER_CYCLE(maincpu_clk))) < 0
152
153
        /* RasterLine */
153
 
        || SMW_W(m, (WORD)(VICII_RASTER_Y(maincpu_clk))) < 0)
 
154
        || SMW_W(m, (WORD)(VICII_RASTER_Y(maincpu_clk))) < 0) {
154
155
        goto fail;
 
156
    }
155
157
 
156
 
    for (i = 0; i < 0x50; i++)
 
158
    for (i = 0; i < 0x50; i++) {
157
159
        /* Registers */
158
 
        if (SMW_B(m, vicii.regs[i]) < 0)
 
160
        if (SMW_B(m, vicii.regs[i]) < 0) {
159
161
            goto fail;
 
162
        }
 
163
    }
160
164
 
161
165
    if (0
162
166
        /* DTV stuff */
191
195
        /* VcBase */
192
196
        || SMW_W(m, (WORD)vicii.memptr) < 0
193
197
        /* VideoInt */
194
 
        || SMW_B(m, (BYTE)vicii.irq_status) < 0)
 
198
        || SMW_B(m, (BYTE)vicii.irq_status) < 0) {
195
199
        goto fail;
 
200
    }
196
201
 
197
202
    for (i = 0; i < 8; i++) {
198
203
        if (0
199
204
            /* SpriteXMemPtr */
200
 
            || SMW_B(m,
201
 
                (BYTE)vicii.raster.sprite_status->sprites[i].memptr) < 0
 
205
            || SMW_B(m, (BYTE)vicii.raster.sprite_status->sprites[i].memptr) < 0
202
206
            /* SpriteXMemPtrInc */
203
 
            || SMW_B(m,
204
 
                (BYTE)vicii.raster.sprite_status->sprites[i].memptr_inc) < 0
 
207
            || SMW_B(m, (BYTE)vicii.raster.sprite_status->sprites[i].memptr_inc) < 0
205
208
            /* SpriteXExpFlipFlop */
206
 
            || SMW_B(m,
207
 
                (BYTE)vicii.raster.sprite_status->sprites[i].exp_flag) < 0)
 
209
            || SMW_B(m, (BYTE)vicii.raster.sprite_status->sprites[i].exp_flag) < 0) {
208
210
            goto fail;
 
211
        }
209
212
    }
210
213
 
211
214
    if (0
212
215
        /* FetchEventTick */
213
216
        || SMW_DW(m, vicii.fetch_clk - maincpu_clk) < 0
214
217
        /* FetchEventType */
215
 
        || SMW_B(m, (BYTE)vicii.fetch_idx) < 0)
 
218
        || SMW_B(m, (BYTE)vicii.fetch_idx) < 0) {
216
219
        goto fail;
 
220
    }
217
221
 
218
 
  /* Added in version 1.1 of the snapshot module */
219
 
  /* using "ram_base-ram" is F***ing bullshit - what when external memory
220
 
     is not mapped anywhere in ram[]? We should rather use some more generic
221
 
     configuration info. But as we use it above in V1.0... :-(
222
 
     AF 16jan2001 */
 
222
    /* Added in version 1.1 of the snapshot module */
 
223
    /* using "ram_base-ram" is F***ing bullshit - what when external memory
 
224
       is not mapped anywhere in ram[]? We should rather use some more generic
 
225
       configuration info. But as we use it above in V1.0... :-(
 
226
       AF 16jan2001 */
223
227
    if (0
224
228
        /* RamBase */
225
229
        || SMW_DW(m, (DWORD)(vicii.ram_base_phi2 - mem_ram)) < 0
226
230
        /* VBank */
227
 
        || SMW_W(m, (WORD)vicii.vbank_phi2) < 0)
 
231
        || SMW_W(m, (WORD)vicii.vbank_phi2) < 0) {
228
232
        goto fail;
 
233
    }
229
234
 
230
235
    return snapshot_module_close(m);
231
236
 
232
237
fail:
233
 
    if (m != NULL)
 
238
    if (m != NULL) {
234
239
        snapshot_module_close(m);
 
240
    }
235
241
 
236
242
    return -1;
237
243
}
244
250
 
245
251
    m = snapshot_module_open(s, snap_module_name,
246
252
                             &major_version, &minor_version);
247
 
    if (m == NULL)
 
253
    if (m == NULL) {
248
254
        return -1;
 
255
    }
249
256
 
250
257
    if (major_version > SNAP_MAJOR || minor_version > SNAP_MINOR) {
251
258
        log_error(vicii.log,
261
268
        /* AllowBadLines */
262
269
        || SMR_B_INT(m, &vicii.allow_bad_lines) < 0
263
270
        /* BadLine */
264
 
        || SMR_B_INT(m, &vicii.bad_line) < 0 
 
271
        || SMR_B_INT(m, &vicii.bad_line) < 0
265
272
        /* Blank */
266
273
        || SMR_B_INT(m, &vicii.raster.blank_enabled) < 0
267
274
        /* ColorBuf */
277
284
        /* MatrixBuf */
278
285
        || SMR_BA(m, vicii.vbuf, 40) < 0
279
286
        /* NewSpriteDmaMask */
280
 
        || SMR_B(m, &vicii.raster.sprite_status->new_dma_msk) < 0)
 
287
        || SMR_B(m, &vicii.raster.sprite_status->new_dma_msk) < 0) {
281
288
        goto fail;
 
289
    }
282
290
 
283
291
    {
284
292
        DWORD RamBase;
285
293
 
286
 
        if (SMR_DW(m, &RamBase) < 0)
 
294
        if (SMR_DW(m, &RamBase) < 0) {
287
295
            goto fail;
 
296
        }
288
297
        vicii.ram_base_phi1 = mem_ram + RamBase;
289
298
    }
290
299
 
295
304
        BYTE RasterCycle;
296
305
 
297
306
        if (SMR_B(m, &RasterCycle) < 0
298
 
            || SMR_W(m, &RasterLine) < 0)
 
307
            || SMR_W(m, &RasterLine) < 0) {
299
308
            goto fail;
 
309
        }
300
310
 
301
311
        if (RasterCycle != (BYTE)VICII_RASTER_CYCLE(maincpu_clk)) {
302
312
            log_error(vicii.log,
313
323
        }
314
324
    }
315
325
 
316
 
    for (i = 0; i < 0x50; i++)
317
 
        if (SMR_B(m, &vicii.regs[i]) < 0 /* Registers */ )
 
326
    for (i = 0; i < 0x50; i++) {
 
327
        if (SMR_B(m, &vicii.regs[i]) < 0 /* Registers */) {
318
328
            goto fail;
 
329
        }
 
330
    }
319
331
 
320
332
    if (0
321
333
        /* DTV stuff */
350
362
        /* VcBase */
351
363
        || SMR_W_INT(m, &vicii.memptr) < 0
352
364
        /* VideoInt */
353
 
        || SMR_B_INT(m, &vicii.irq_status) < 0)
 
365
        || SMR_B_INT(m, &vicii.irq_status) < 0) {
354
366
        goto fail;
 
367
    }
355
368
 
356
369
    for (i = 0; i < 8; i++) {
357
370
        if (0
358
371
            /* SpriteXMemPtr */
359
 
            || SMR_B_INT(m,
360
 
                &vicii.raster.sprite_status->sprites[i].memptr) < 0
 
372
            || SMR_B_INT(m, &vicii.raster.sprite_status->sprites[i].memptr) < 0
361
373
            /* SpriteXMemPtrInc */
362
 
            || SMR_B_INT(m,
363
 
                &vicii.raster.sprite_status->sprites[i].memptr_inc) < 0
 
374
            || SMR_B_INT(m, &vicii.raster.sprite_status->sprites[i].memptr_inc) < 0
364
375
            /* SpriteXExpFlipFlop */
365
 
            || SMR_B_INT(m,
366
 
                &vicii.raster.sprite_status->sprites[i].exp_flag) < 0
367
 
            )
 
376
            || SMR_B_INT(m, &vicii.raster.sprite_status->sprites[i].exp_flag) < 0
 
377
            ) {
368
378
            goto fail;
 
379
        }
369
380
    }
370
381
 
371
382
    /* FIXME: Recalculate alarms and derived values.  */
373
384
    if (vicii.raster_irq_prevent) {
374
385
        vicii.raster_irq_clk = CLOCK_MAX;
375
386
        alarm_unset(vicii.raster_irq_alarm);
376
 
    } else
377
 
    {
378
 
        /* 
 
387
    } else {
 
388
        /*
379
389
            We cannot use vicii_irq_set_raster_line as this would delay
380
390
            an alarm on line 0 for one frame
381
391
        */
387
397
                                    + (vicii.cycles_per_line * line));
388
398
            vicii.raster_irq_clk += vicii.raster_irq_offset;
389
399
            /* Raster interrupts on line 0 are delayed by 1 cycle.  */
390
 
            if (line == 0)
 
400
            if (line == 0) {
391
401
                vicii.raster_irq_clk++;
 
402
            }
392
403
 
393
404
            alarm_set(vicii.raster_irq_alarm, vicii.raster_irq_clk);
394
405
        } else {
432
443
            sprite->multicolor = (int)(vicii.regs[0x1c] & msk);
433
444
            sprite->in_background = (int)(vicii.regs[0x1b] & msk);
434
445
            sprite->color = (int) vicii.dtvpalette[vicii.regs[0x27 + i] & 0xf];
435
 
            sprite->dma_flag = (int)(vicii.raster.sprite_status->new_dma_msk
436
 
                               & msk);
 
446
            sprite->dma_flag = (int)(vicii.raster.sprite_status->new_dma_msk & msk);
437
447
        }
438
448
    }
439
449
 
448
458
 
449
459
        sf = vicii_sprites_fetch_table[vicii.sprite_fetch_msk];
450
460
        i = 0;
451
 
        while (sf[i].cycle >= 0 
452
 
            && sf[i].cycle + vicii.sprite_fetch_cycle <= vicii.cycles_per_line)
 
461
        while (sf[i].cycle >= 0 && sf[i].cycle + vicii.sprite_fetch_cycle <= vicii.cycles_per_line)
453
462
        {
454
463
            i++;
455
464
        }
513
522
 
514
523
    vicii_store(0x3c, (BYTE)vicii.regs[0x3c]);
515
524
 
516
 
    vicii.draw_clk = maincpu_clk + (vicii.draw_cycle
517
 
                     - VICII_RASTER_CYCLE(maincpu_clk));
 
525
    vicii.draw_clk = maincpu_clk + (vicii.draw_cycle - VICII_RASTER_CYCLE(maincpu_clk));
518
526
    vicii.last_emulate_line_clk = vicii.draw_clk - vicii.cycles_per_line;
519
527
    alarm_set(vicii.raster_draw_alarm, vicii.draw_clk);
520
528
 
525
533
        if (0
526
534
            || SMR_DW(m, &dw) < 0  /* FetchEventTick */
527
535
            || SMR_B(m, &b) < 0    /* FetchEventType */
528
 
            )
 
536
            ) {
529
537
            goto fail;
 
538
        }
530
539
 
531
540
        vicii.fetch_clk = maincpu_clk + dw;
532
541
        vicii.fetch_idx = b;
534
543
        alarm_set(vicii.raster_fetch_alarm, vicii.fetch_clk);
535
544
    }
536
545
 
537
 
    if (vicii.irq_status & 0x80)
 
546
    if (vicii.irq_status & 0x80) {
538
547
        interrupt_restore_irq(maincpu_int_status, vicii.int_num, 1);
 
548
    }
539
549
 
540
550
    /* added in version 1.1 of snapshot format */
541
551
    if (minor_version > 0) {
544
554
        if (0
545
555
            || SMR_DW(m, &RamBase) < 0
546
556
            || SMR_W_INT(m, &vicii.vbank_phi2) < 0 /* VBank */
547
 
            )
 
557
            ) {
548
558
            goto fail;
 
559
        }
549
560
        vicii.ram_base_phi2 = mem_ram + RamBase;
550
561
 
551
562
        vicii_update_memory_ptrs(VICII_RASTER_CYCLE(maincpu_clk));
556
567
    return 0;
557
568
 
558
569
fail:
559
 
    if (m != NULL)
 
570
    if (m != NULL) {
560
571
        snapshot_module_close(m);
 
572
    }
561
573
    return -1;
562
574
}
563