annotate src/vdp.c @ 8:5176efdda5ae

Initial work on VDP emulation
author Michael Pavone <pavone@retrodev.com>
date Sun, 27 Mar 2016 00:24:31 -0700
parents
children 04d8efe7a1f0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
8
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
1 #include <stdint.h>
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
2 #include <string.h>
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
3 #include "vdp.h"
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
4
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
5 void vdp_init(vdp *context, uint32_t clock_div)
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
6 {
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
7 memset(context, 0, sizeof(vdp));
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
8 context->clock_inc = clock_div;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
9 }
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
10
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
11 void vdp_run(vdp *context, uint32_t target)
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
12 {
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
13 while (context->cycles < target)
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
14 {
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
15 context->hcounter++;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
16 if (context->hcounter == 416) {
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
17 context->hcounter = 0;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
18 context->vcounter++;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
19 if (context->vcounter == 262) {
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
20 context->vcounter = 0;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
21 }
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
22 }
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
23 //TODO: do rendering stuff here
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
24 if (context->status & VDP_STATUS_FIFO) {
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
25 switch (context->fifo_dest)
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
26 {
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
27 case FIFO_DEST_VRAM:
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
28 if (!(context->status & VDP_STATUS_VRAM)) {
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
29 context->vram[context->dest_offset++] = context->fifo;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
30 context->dest_offset &= sizeof(context->vram)/2-1;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
31 context->status &= ~VDP_STATUS_FIFO;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
32 }
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
33 break;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
34 case FIFO_DEST_SRAM:
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
35 if (!(context->status & VDP_STATUS_SRAM)) {
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
36 context->sram[context->dest_offset++] = context->fifo;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
37 context->dest_offset &= sizeof(context->sram)/2-1;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
38 context->status &= ~VDP_STATUS_FIFO;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
39 }
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
40 break;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
41 case FIFO_DEST_CRAM:
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
42 context->cram[context->dest_offset++] = context->fifo;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
43 context->dest_offset &= sizeof(context->cram)/2-1;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
44 context->status &= ~VDP_STATUS_FIFO;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
45 break;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
46 }
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
47 }
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
48 context->cycles += context->clock_inc;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
49 }
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
50 }
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
51 void vdp_write_address(vdp *context, uint16_t value)
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
52 {
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
53 context->status &= ~VDP_STATUS_FIFO;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
54 if (value & 0x8000) {
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
55 context->fifo_dest = FIFO_DEST_VRAM;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
56 context->dest_offset = (value & (sizeof(context->vram) -1))/2;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
57 } else if (value & 0xFF00 == 0xFE00) {
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
58 context->fifo_dest = FIFO_DEST_SRAM;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
59 context->dest_offset = (value & (sizeof(context->sram) -1))/2;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
60 } else if (value & 0xFF00 == 0xFF00) {
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
61 context->fifo_dest = FIFO_DEST_CRAM;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
62 context->dest_offset = (value & (sizeof(context->cram) -1))/2;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
63 }
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
64 }
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
65
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
66 void vdp_write_data(vdp *context, uint16_t value)
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
67 {
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
68 context->fifo = value;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
69 context->status |= VDP_STATUS_FIFO;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
70 }