Mercurial > repos > simple16
annotate src/vdp.c @ 19:04fc17376999
Sort of working tile rendering and tile test ROM
author | Michael Pavone <pavone@retrodev.com> |
---|---|
date | Mon, 28 Mar 2016 23:43:31 -0700 |
parents | 04d8efe7a1f0 |
children | 91ded3b12d96 |
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> |
19
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
3 #include <stdio.h> |
8
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
4 #include "vdp.h" |
11
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
5 #include "system.h" |
8
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 void vdp_init(vdp *context, uint32_t clock_div) |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
8 { |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
9 memset(context, 0, sizeof(vdp)); |
11
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
10 //clock div specifies the pixel clock divider |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
11 //but our emulation step is half that fast |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
12 context->clock_inc = clock_div*2; |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
13 context->drawbuffer = context->linebuffers; |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
14 context->readbuffer = context->linebuffers+320; |
8
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
15 } |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
16 |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
17 void vdp_run(vdp *context, uint32_t target) |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
18 { |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
19 while (context->cycles < target) |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
20 { |
11
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
21 context->hcounter+=2; |
8
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
22 if (context->hcounter == 416) { |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
23 context->hcounter = 0; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
24 context->vcounter++; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
25 if (context->vcounter == 262) { |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
26 context->vcounter = 0; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
27 } |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
28 } |
19
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
29 context->status &= ~(VDP_STATUS_VRAM|VDP_STATUS_SRAM); |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
30 //Render to linebuffer |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
31 if (context->vcounter > 15 && context->vcounter < 240 && context->hcounter < 406) { |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
32 if (context->hcounter < 246) { |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
33 context->status |= VDP_STATUS_VRAM; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
34 if (!context->hcounter) { |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
35 //flip linebuffers |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
36 if (context->drawbuffer == context->linebuffers) { |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
37 context->drawbuffer = context->linebuffers + 328; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
38 context->readbuffer = context->linebuffers; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
39 } else { |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
40 context->drawbuffer = context->linebuffers; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
41 context->readbuffer = context->linebuffers + 328; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
42 } |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
43 context->draw_dest = 0; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
44 } |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
45 if (context->draw_counter) { |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
46 context->draw_counter--; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
47 uint16_t pixels = context->vram[context->draw_source++]; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
48 for (int i = 0; i < 4; i++) |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
49 { |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
50 uint8_t pixel = ((pixels >> ((3-i) * 4)) & 0xF) | context->palpriority; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
51 context->drawbuffer[context->draw_dest++] = pixel; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
52 } |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
53 } else { |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
54 //00VV VVVV VVHH HHHH |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
55 uint16_t vpos = (context->vscroll & 0x7FF) + context->vcounter - 16; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
56 uint16_t vmask = (context->vscroll >> 2) & 0x3E00; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
57 uint16_t vcoarse = (vpos << 3) & 0x3FC0; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
58 uint16_t vfine = vpos & 7; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
59 uint16_t hcoarse = ((context->hscroll >> 3) + context->hcounter/6) & 0x3F; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
60 uint16_t tableaddress = hcoarse | (vcoarse & ~vmask) | ((context->vscroll << 3) & vmask); |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
61 //printf("VCounter: %X, VScroll: %X, HCounter: %X, Table: %X\n", context->vcounter, context->vscroll, context->hcounter, tableaddress); |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
62 uint16_t entry = context->vram[tableaddress]; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
63 context->draw_source = (entry & 0x3FF) * 16; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
64 if (entry & 0x1000) { |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
65 context->draw_source += 14 - vfine * 2; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
66 } else { |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
67 context->draw_source += vfine * 2; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
68 } |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
69 context->palpriority = entry >> 9 & 0x70; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
70 context->draw_counter = 2; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
71 //TODO: handle horizontal flip |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
72 } |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
73 //TODO: Scan sprite table |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
74 } else { |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
75 //TODO: Render sprites |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
76 } |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
77 } |
11
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
78 //Draw to framebuffer |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
79 if (context->vcounter > 8 && context->vcounter < 249 && context->hcounter < 320) { |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
80 if (!context->hcounter && context->vcounter == 9) { |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
81 context->framebuffer = system_get_framebuffer(&context->pitch); |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
82 //pitch is in terms of bytes, but we want it in terms of pixels |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
83 context->pitch /= sizeof(uint16_t); |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
84 } |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
85 uint16_t *dest = context->framebuffer + (context->vcounter - 9) * context->pitch + context->hcounter; |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
86 if (context->status & VDP_STATUS_ENABLED && context->vcounter > 16 && context->vcounter < 241) { |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
87 *dest = context->cram[0x3F & context->readbuffer[context->hcounter]]; |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
88 dest++; |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
89 *dest = context->cram[0x3F & context->readbuffer[context->hcounter+1]]; |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
90 } else { |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
91 //Display is disabled or we're in the border area, draw the background color |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
92 *dest = *context->cram; |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
93 dest++; |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
94 *dest = *context->cram; |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
95 } |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
96 } else if(!context->hcounter && context->vcounter == 249) { |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
97 system_framebuffer_updated(); |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
98 context->framebuffer = NULL; |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
99 } |
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
100 //Handle the FIFO |
8
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
101 if (context->status & VDP_STATUS_FIFO) { |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
102 switch (context->fifo_dest) |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
103 { |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
104 case FIFO_DEST_VRAM: |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
105 if (!(context->status & VDP_STATUS_VRAM)) { |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
106 context->vram[context->dest_offset++] = context->fifo; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
107 context->dest_offset &= sizeof(context->vram)/2-1; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
108 context->status &= ~VDP_STATUS_FIFO; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
109 } |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
110 break; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
111 case FIFO_DEST_SRAM: |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
112 if (!(context->status & VDP_STATUS_SRAM)) { |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
113 context->sram[context->dest_offset++] = context->fifo; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
114 context->dest_offset &= sizeof(context->sram)/2-1; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
115 context->status &= ~VDP_STATUS_FIFO; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
116 } |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
117 break; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
118 case FIFO_DEST_CRAM: |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
119 context->cram[context->dest_offset++] = context->fifo; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
120 context->dest_offset &= sizeof(context->cram)/2-1; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
121 context->status &= ~VDP_STATUS_FIFO; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
122 break; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
123 } |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
124 } |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
125 context->cycles += context->clock_inc; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
126 } |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
127 } |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
128 void vdp_write_address(vdp *context, uint16_t value) |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
129 { |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
130 context->status &= ~VDP_STATUS_FIFO; |
11
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
131 if (!(value & 0x8000)) { |
8
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
132 context->fifo_dest = FIFO_DEST_VRAM; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
133 context->dest_offset = (value & (sizeof(context->vram) -1))/2; |
11
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
134 } else if ((value & 0xFF00) == 0xFE00) { |
8
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
135 context->fifo_dest = FIFO_DEST_SRAM; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
136 context->dest_offset = (value & (sizeof(context->sram) -1))/2; |
11
04d8efe7a1f0
Initial stab at video output and background color rendering. Fixed address decoding in address port write handler.
Michael Pavone <pavone@retrodev.com>
parents:
8
diff
changeset
|
137 } else if ((value & 0xFF00) == 0xFF00) { |
8
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
138 context->fifo_dest = FIFO_DEST_CRAM; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
139 context->dest_offset = (value & (sizeof(context->cram) -1))/2; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
140 } |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
141 } |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
142 |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
143 void vdp_write_data(vdp *context, uint16_t value) |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
144 { |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
145 context->fifo = value; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
146 context->status |= VDP_STATUS_FIFO; |
5176efdda5ae
Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff
changeset
|
147 } |
19
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
148 |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
149 void vdp_write_hscroll(vdp *context, uint16_t value) |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
150 { |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
151 context->hscroll = value & 0x1FF; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
152 if (value & 0x8000) { |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
153 context->status |= VDP_STATUS_ENABLED; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
154 } else { |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
155 context->status &= ~VDP_STATUS_ENABLED; |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
156 } |
04fc17376999
Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents:
11
diff
changeset
|
157 } |