annotate src/vdp.c @ 58:bed2d84eeabe

Fix ldimh special casing of loading labels for the case when the label is not a forward reference
author Michael Pavone <pavone@retrodev.com>
date Tue, 06 Sep 2016 09:42:31 -0700
parents 6e7bfe83d2b0
children
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>
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
43
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
7 #define MAX_ACTIVE_LINES 240
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
8 #define TOTAL_LINES 262
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
9 #define ACTIVE_WIDTH 320
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
10 #define TOTAL_WIDTH 416
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
11
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
12 #define VDP_STATUS_FB_SELECT 1
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
13 #define VDP_STATUS_PENDING_VINT 2
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
14 #define VDP_STATUS_VBLANK 4
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
15 #define VDP_STATUS_CRAM_PENDING 8
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
16 #define VDP_STATUS_VINT_ENABLED 0x2000
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
17 #define VDP_STATUS_DEPTH 0x4000
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
18 #define VDP_STATUS_ENABLED 0x8000
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
19
8
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
20 void vdp_init(vdp *context, uint32_t clock_div)
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 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
23 //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
24 //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
25 context->clock_inc = clock_div*2;
8
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
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
28 void vdp_run(vdp *context, uint32_t target)
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
29 {
43
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
30 uint8_t *current_fb = context->status & VDP_STATUS_FB_SELECT ? context->vram + 64*1024 : context->vram;
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
31
8
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
32 while (context->cycles < target)
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
33 {
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
34 context->hcounter+=2;
43
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
35 if (context->hcounter == TOTAL_WIDTH) {
8
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
36 context->hcounter = 0;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
37 context->vcounter++;
43
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
38 if (context->vcounter == TOTAL_LINES) {
8
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
39 context->vcounter = 0;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
40 }
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
41 }
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
42 //Draw to framebuffer
43
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
43 if (context->vcounter < MAX_ACTIVE_LINES && context->hcounter < ACTIVE_WIDTH) {
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
44 if (!context->framebuffer) {
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
45 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
46 //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
47 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
48 }
43
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
49 uint16_t *dest = context->framebuffer + context->vcounter * context->pitch + context->hcounter;
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
50 if (
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
51 context->status & VDP_STATUS_ENABLED
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
52 && context->vcounter >= context->top_skip
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
53 && context->vcounter < MAX_ACTIVE_LINES - context->bottom_skip
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
54 ) {
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
55 if (context->status & VDP_STATUS_DEPTH) {
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
56 uint16_t offset = context->start_offset + (context->vcounter - context->top_skip) * ACTIVE_WIDTH + context->hcounter;
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
57 //8bpp
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
58 *(dest++) = context->cram[current_fb[offset++]];
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
59 *dest = context->cram[current_fb[offset]];
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
60 } else {
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
61 //4bpp
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
62 uint8_t pixels = current_fb[context->start_offset + (context->vcounter - context->top_skip) * ACTIVE_WIDTH + context->hcounter >> 1];
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
63 *(dest++) = context->cram[context->pal_select | pixels >> 4];
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
64 *dest = context->cram[context->pal_select | (pixels & 0xF)];
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
65 }
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
66 } else {
43
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
67 *(dest++) = context->cram[0];
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
68 *dest = context->cram[0];
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
69 }
43
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
70 } else if (context->framebuffer && context->hcounter < ACTIVE_WIDTH) {
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
71 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
72 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
73 }
43
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
74 if (!context->hcounter) {
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
75 if (context->vcounter == (context->vcounter - context->bottom_skip)) {
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
76 context->status |= VDP_STATUS_PENDING_VINT | VDP_STATUS_VBLANK;
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
77 } else if (context->vcounter == context->top_skip) {
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
78 //clear pending interrupt flag since VBlank is over
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
79 context->status &= ~(VDP_STATUS_PENDING_VINT | VDP_STATUS_VBLANK);
8
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
80 }
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
81 }
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
82 context->cycles += context->clock_inc;
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
83 }
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
84 }
43
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
85 void vdp_write_mode(vdp *context, uint16_t value)
8
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
86 {
43
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
87 uint16_t status_bits = VDP_STATUS_ENABLED | VDP_STATUS_DEPTH | VDP_STATUS_VINT_ENABLED | VDP_STATUS_FB_SELECT;
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
88 context->status &= ~status_bits;
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
89 context->status |= value & status_bits;
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
90 context->pal_select = value >> 7 & 0x30;
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
91 context->top_skip = value >> 6 & 0x1F;
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
92 context->bottom_skip = value >> 1 & 0x1F;
8
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
93 }
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
94
43
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
95 void vdp_write_cram(vdp *context, uint16_t value)
8
5176efdda5ae Initial work on VDP emulation
Michael Pavone <pavone@retrodev.com>
parents:
diff changeset
96 {
43
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
97 if (context->status & VDP_STATUS_CRAM_PENDING) {
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
98 context->cram[context->pal_write_index++] = value;
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
99 if (!(--context->pal_write_count)) {
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
100 context->status &= ~VDP_STATUS_CRAM_PENDING;
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
101 }
19
04fc17376999 Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents: 11
diff changeset
102 } else {
43
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
103 context->pal_write_count = value;
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
104 context->pal_write_index = value >> 8;
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
105 context->status |= VDP_STATUS_CRAM_PENDING;
19
04fc17376999 Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents: 11
diff changeset
106 }
04fc17376999 Sort of working tile rendering and tile test ROM
Michael Pavone <pavone@retrodev.com>
parents: 11
diff changeset
107 }
26
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
108
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
109 uint32_t vdp_next_interrupt(vdp *context)
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
110 {
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
111 if (context->status & VDP_STATUS_PENDING_VINT) {
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
112 return 0;
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
113 } else if (context->status & VDP_STATUS_ENABLED) {
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
114 uint32_t next_line = context->vcounter + 1;
43
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
115 uint32_t next_line_cyc = context->cycles + ((TOTAL_WIDTH - context->hcounter) >> 1) * context->clock_inc;
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
116 uint32_t vint_line = (MAX_ACTIVE_LINES - context->bottom_skip);
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
117 if (context->vcounter < vint_line) {
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
118 return next_line_cyc + (vint_line - next_line) * (TOTAL_WIDTH >> 1) * context->clock_inc;
26
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
119 } else {
43
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
120 return next_line_cyc + (vint_line + TOTAL_LINES - next_line) * (TOTAL_WIDTH >> 1) * context->clock_inc;
26
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
121 }
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
122 } else {
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
123 return 0xFFFFFFFF;
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
124 }
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
125 }
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
126
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
127 void vdp_ack_interrupt(vdp *context)
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
128 {
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
129 context->status &= ~VDP_STATUS_PENDING_VINT;
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
130 }
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
131
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
132 uint8_t vdp_interrupt_pending(vdp *context)
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
133 {
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
134 return (context->status & VDP_STATUS_PENDING_VINT) != 0;
083347ccd508 Implemented vblank interrupts and fixed a bug in exception vector address calculation
Michael Pavone <pavone@retrodev.com>
parents: 23
diff changeset
135 }
43
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
136
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
137 uint8_t *vdp_get_back_buffer(vdp *context)
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
138 {
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
139 return context->status & VDP_STATUS_FB_SELECT ? context->vram : context->vram + 64*1024;
6e7bfe83d2b0 Changed the design to vastly simplify the video hardware and support a 23-bit address space on the CPU
Michael Pavone <pavone@retrodev.com>
parents: 26
diff changeset
140 }