1 |
nishi |
1 |
/* $Id: shiroi_video_mk_i.c 1 2024-08-28 08:10:28Z nishi $ */
|
|
|
2 |
#include "shiroi_video_mk_i.h"
|
|
|
3 |
|
|
|
4 |
#include "shiroi.h"
|
|
|
5 |
|
|
|
6 |
#include "tms9918util.h"
|
|
|
7 |
|
|
|
8 |
#include <stdlib.h>
|
|
|
9 |
|
|
|
10 |
void shiroi_video_mk_i_install(shiroi_t* shiroi, int slot) {
|
|
|
11 |
shiroi->cards[slot].type = SHIROI_VIDEO_MARK_I;
|
|
|
12 |
shiroi->cards[slot].videoptr = &shiroi->cards[slot].video;
|
|
|
13 |
|
|
|
14 |
shiroi->cards[slot].video.width = TMS9918_PIXELS_X;
|
|
|
15 |
shiroi->cards[slot].video.height = TMS9918_PIXELS_Y;
|
|
|
16 |
shiroi->cards[slot].video.tick = 0;
|
|
|
17 |
|
|
|
18 |
shiroi->cards[slot].video.vdp = vrEmuTms9918New();
|
|
|
19 |
shiroi->cards[slot].video.fb = malloc(TMS9918_PIXELS_Y * TMS9918_PIXELS_X * sizeof(uint32_t));
|
|
|
20 |
int x, y;
|
|
|
21 |
for(y = 0; y < TMS9918_PIXELS_Y; y++) {
|
|
|
22 |
for(x = 0; x < TMS9918_PIXELS_X; x++) {
|
|
|
23 |
shiroi->cards[slot].video.fb[y * TMS9918_PIXELS_X + x] = 0;
|
|
|
24 |
}
|
|
|
25 |
}
|
|
|
26 |
}
|
|
|
27 |
|
|
|
28 |
void shiroi_video_mk_i(shiroi_t* shiroi) {
|
|
|
29 |
int i;
|
|
|
30 |
|
|
|
31 |
uint16_t io = Z80_GET_ADDR(shiroi->z80_pins);
|
|
|
32 |
uint16_t addr = io & 0xff;
|
|
|
33 |
uint16_t data = (io >> 8) & 0xff;
|
|
|
34 |
|
|
|
35 |
for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
|
|
|
36 |
if(shiroi->cards[i].type == SHIROI_VIDEO_MARK_I) {
|
|
|
37 |
if(shiroi->z80_pins & Z80_RD) {
|
|
|
38 |
/* I/O Read */
|
|
|
39 |
if(addr == 1) {
|
|
|
40 |
Z80_SET_DATA(shiroi->z80_pins, vrEmuTms9918ReadData(shiroi->cards[i].video.vdp));
|
|
|
41 |
} else if(addr == 2) {
|
|
|
42 |
Z80_SET_DATA(shiroi->z80_pins, shiroi->cards[i].type);
|
|
|
43 |
}
|
|
|
44 |
} else if(shiroi->z80_pins & Z80_WR) {
|
|
|
45 |
/* I/O Write */
|
|
|
46 |
if(addr == 0) {
|
|
|
47 |
vrEmuTms9918WriteAddr(shiroi->cards[i].video.vdp, data);
|
|
|
48 |
} else if(addr == 1) {
|
|
|
49 |
vrEmuTms9918WriteData(shiroi->cards[i].video.vdp, data);
|
|
|
50 |
}
|
|
|
51 |
}
|
|
|
52 |
}
|
|
|
53 |
}
|
|
|
54 |
}
|
|
|
55 |
|
|
|
56 |
void shiroi_video_mk_i_tick(shiroi_t* shiroi) {
|
|
|
57 |
uint8_t scanline[TMS9918_PIXELS_X];
|
|
|
58 |
int i, y, x;
|
|
|
59 |
for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
|
|
|
60 |
if(shiroi->cards[i].type == SHIROI_VIDEO_MARK_I) {
|
|
|
61 |
shiroi->cards[i].video.tick++;
|
|
|
62 |
if(shiroi->cards[i].video.tick == 256) {
|
|
|
63 |
shiroi->cards[i].video.tick = 0;
|
|
|
64 |
for(y = 0; y < TMS9918_PIXELS_Y; y++) {
|
|
|
65 |
vrEmuTms9918ScanLine(shiroi->cards[i].video.vdp, y, scanline);
|
|
|
66 |
for(x = 0; x < TMS9918_PIXELS_X; x++) {
|
|
|
67 |
shiroi->cards[i].video.fb[y * TMS9918_PIXELS_X + x] = vrEmuTms9918Palette[scanline[x]];
|
|
|
68 |
}
|
|
|
69 |
}
|
|
|
70 |
}
|
|
|
71 |
}
|
|
|
72 |
}
|
|
|
73 |
}
|