/[gxemul]/upstream/0.4.2/src/devices/dev_pal.c
This is repository of my old source code which isn't updated any more. Go to git.rot13.org for current projects!
ViewVC logotype

Contents of /upstream/0.4.2/src/devices/dev_pal.c

Parent Directory Parent Directory | Revision Log Revision Log


Revision 31 - (show annotations)
Mon Oct 8 16:20:48 2007 UTC (16 years, 8 months ago) by dpavlin
File MIME type: text/plain
File size: 3705 byte(s)
0.4.2
1 /*
2 * Copyright (C) 2006 Anders Gavare. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are met:
6 *
7 * 1. Redistributions of source code must retain the above copyright
8 * notice, this list of conditions and the following disclaimer.
9 * 2. Redistributions in binary form must reproduce the above copyright
10 * notice, this list of conditions and the following disclaimer in the
11 * documentation and/or other materials provided with the distribution.
12 * 3. The name of the author may not be used to endorse or promote products
13 * derived from this software without specific prior written permission.
14 *
15 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
16 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE AUTHOR OR CONTRIBUTORS BE LIABLE
19 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
20 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
21 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
22 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
23 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
24 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
25 * SUCH DAMAGE.
26 *
27 *
28 * $Id: dev_pal.c,v 1.4 2006/03/05 16:20:24 debug Exp $
29 *
30 * PAL (TV) emulation. Experimental.
31 *
32 * TODO: Almost everything.
33 */
34
35 #include <stdio.h>
36 #include <stdlib.h>
37 #include <string.h>
38
39 #include "cpu.h"
40 #include "device.h"
41 #include "devices.h"
42 #include "machine.h"
43 #include "memory.h"
44 #include "misc.h"
45
46
47 struct pal_data {
48 uint64_t addr;
49 struct vfb_data *fb;
50
51 double hz;
52 int cur_scanline;
53 int cur_x;
54
55 int visible_x, visible_y;
56 };
57
58
59 /*
60 * dev_pal_tick():
61 *
62 * Called each cycle.
63 */
64 void dev_pal_tick(struct cpu *cpu, void *extra)
65 {
66 struct pal_data *d = extra;
67 int signal = 0x80;
68
69 switch (cpu->machine->machine_type) {
70
71 case MACHINE_AVR_PAL:
72 signal = cpu->cd.avr.portd_write * 4;
73 break;
74
75 case MACHINE_AVR_MAHPONG:
76 signal = (cpu->cd.avr.portc_write & 0x80) |
77 ((cpu->cd.avr.portc_write & 0x08) << 3) |
78 ((cpu->cd.avr.portd_write & 0x10) << 1);
79 break;
80 }
81
82 d->fb->framebuffer[3 * (d->cur_x + d->cur_scanline * d->visible_x)
83 + 0] = signal;
84 d->fb->framebuffer[3 * (d->cur_x + d->cur_scanline * d->visible_x)
85 + 1] = signal;
86 d->fb->framebuffer[3 * (d->cur_x + d->cur_scanline * d->visible_x)
87 + 2] = signal;
88
89 d->cur_x ++;
90 if (d->cur_x >= d->visible_x) {
91 d->cur_x = 0;
92 d->cur_scanline ++;
93 if (d->cur_scanline >= d->visible_y) {
94 d->cur_scanline = 0;
95 d->fb->update_x1 = 0;
96 d->fb->update_x2 = d->visible_x - 1;
97 d->fb->update_y1 = 0;
98 d->fb->update_y2 = d->visible_y - 1;
99 }
100 }
101 }
102
103
104 DEVINIT(pal)
105 {
106 struct pal_data *d;
107 d = malloc(sizeof(struct pal_data));
108 if (d == NULL) {
109 fprintf(stderr, "out of memory\n");
110 exit(1);
111 }
112 memset(d, 0, sizeof(struct pal_data));
113
114 d->hz = 12000000;
115 d->addr = 0x9000000;
116 d->visible_x = 579;
117 d->visible_y = 625;
118
119 switch (devinit->machine->machine_type) {
120 case MACHINE_AVR_PAL:
121 case MACHINE_AVR_MAHPONG:
122 break;
123 default:fatal("Not yet implemented for this machine type.\n");
124 exit(1);
125 }
126
127 d->fb = dev_fb_init(devinit->machine, devinit->machine->memory,
128 d->addr, VFB_GENERIC, d->visible_x, d->visible_y,
129 d->visible_x, d->visible_y, 24, "PAL TV");
130
131 machine_add_tickfunction(devinit->machine, dev_pal_tick, d,
132 0, d->hz);
133
134 return 1;
135 }
136

  ViewVC Help
Powered by ViewVC 1.1.26