Mercurial > repos > simple16
comparison 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 |
comparison
equal
deleted
inserted
replaced
7:8f9a05e2e425 | 8:5176efdda5ae |
---|---|
1 #include <stdint.h> | |
2 #include <string.h> | |
3 #include "vdp.h" | |
4 | |
5 void vdp_init(vdp *context, uint32_t clock_div) | |
6 { | |
7 memset(context, 0, sizeof(vdp)); | |
8 context->clock_inc = clock_div; | |
9 } | |
10 | |
11 void vdp_run(vdp *context, uint32_t target) | |
12 { | |
13 while (context->cycles < target) | |
14 { | |
15 context->hcounter++; | |
16 if (context->hcounter == 416) { | |
17 context->hcounter = 0; | |
18 context->vcounter++; | |
19 if (context->vcounter == 262) { | |
20 context->vcounter = 0; | |
21 } | |
22 } | |
23 //TODO: do rendering stuff here | |
24 if (context->status & VDP_STATUS_FIFO) { | |
25 switch (context->fifo_dest) | |
26 { | |
27 case FIFO_DEST_VRAM: | |
28 if (!(context->status & VDP_STATUS_VRAM)) { | |
29 context->vram[context->dest_offset++] = context->fifo; | |
30 context->dest_offset &= sizeof(context->vram)/2-1; | |
31 context->status &= ~VDP_STATUS_FIFO; | |
32 } | |
33 break; | |
34 case FIFO_DEST_SRAM: | |
35 if (!(context->status & VDP_STATUS_SRAM)) { | |
36 context->sram[context->dest_offset++] = context->fifo; | |
37 context->dest_offset &= sizeof(context->sram)/2-1; | |
38 context->status &= ~VDP_STATUS_FIFO; | |
39 } | |
40 break; | |
41 case FIFO_DEST_CRAM: | |
42 context->cram[context->dest_offset++] = context->fifo; | |
43 context->dest_offset &= sizeof(context->cram)/2-1; | |
44 context->status &= ~VDP_STATUS_FIFO; | |
45 break; | |
46 } | |
47 } | |
48 context->cycles += context->clock_inc; | |
49 } | |
50 } | |
51 void vdp_write_address(vdp *context, uint16_t value) | |
52 { | |
53 context->status &= ~VDP_STATUS_FIFO; | |
54 if (value & 0x8000) { | |
55 context->fifo_dest = FIFO_DEST_VRAM; | |
56 context->dest_offset = (value & (sizeof(context->vram) -1))/2; | |
57 } else if (value & 0xFF00 == 0xFE00) { | |
58 context->fifo_dest = FIFO_DEST_SRAM; | |
59 context->dest_offset = (value & (sizeof(context->sram) -1))/2; | |
60 } else if (value & 0xFF00 == 0xFF00) { | |
61 context->fifo_dest = FIFO_DEST_CRAM; | |
62 context->dest_offset = (value & (sizeof(context->cram) -1))/2; | |
63 } | |
64 } | |
65 | |
66 void vdp_write_data(vdp *context, uint16_t value) | |
67 { | |
68 context->fifo = value; | |
69 context->status |= VDP_STATUS_FIFO; | |
70 } |