Subversion Repositories Shiroi

Rev

Rev 10 | Rev 19 | Go to most recent revision | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
1 nishi 1
/* $Id: shiroi_video_mk_i.c 11 2024-08-29 02:49:47Z 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
	int x, y;
20
	for(y = 0; y < TMS9918_PIXELS_Y; y++) {
21
		for(x = 0; x < TMS9918_PIXELS_X; x++) {
22
			shiroi->cards[slot].video.fb[y * TMS9918_PIXELS_X + x] = 0;
23
		}
24
	}
25
}
26
 
10 nishi 27
void shiroi_video_mk_i_reset(shiroi_t* shiroi, int slot) {
28
	vrEmuTms9918Reset(shiroi->cards[slot].video.vdp);
29
	shiroi->cards[slot].video.tick = 0;
11 nishi 30
	int y, x;
31
	for(y = 0; y < shiroi->cards[slot].video.height; y++) {
32
		for(x = 0; x < shiroi->cards[slot].video.width; x++) {
33
			shiroi->cards[slot].video.fb[y * shiroi->cards[slot].video.width + x] = 0x000000ff;
34
		}
35
	}
36
	int i;
37
	int addr;
38
	addr = 0 | 0x4000;
39
	vrEmuTms9918WriteAddr(shiroi->cards[slot].video.vdp, (addr & 0xff00) >> 8);
40
	vrEmuTms9918WriteAddr(shiroi->cards[slot].video.vdp, (addr & 0xff));
41
	for(i = 0; i < 0xffff; i++) {
42
		vrEmuTms9918WriteData(shiroi->cards[slot].video.vdp, 0);
43
	}
10 nishi 44
}
45
 
1 nishi 46
void shiroi_video_mk_i(shiroi_t* shiroi) {
47
	int i;
48
 
49
	uint16_t io = Z80_GET_ADDR(shiroi->z80_pins);
50
	uint16_t addr = io & 0xff;
51
	uint16_t data = (io >> 8) & 0xff;
52
 
53
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
54
		if(shiroi->cards[i].type == SHIROI_VIDEO_MARK_I) {
55
			if(shiroi->z80_pins & Z80_RD) {
56
				/* I/O Read */
57
				if(addr == 1) {
58
					Z80_SET_DATA(shiroi->z80_pins, vrEmuTms9918ReadData(shiroi->cards[i].video.vdp));
59
				} else if(addr == 2) {
60
					Z80_SET_DATA(shiroi->z80_pins, shiroi->cards[i].type);
61
				}
62
			} else if(shiroi->z80_pins & Z80_WR) {
63
				/* I/O Write */
64
				if(addr == 0) {
65
					vrEmuTms9918WriteAddr(shiroi->cards[i].video.vdp, data);
66
				} else if(addr == 1) {
67
					vrEmuTms9918WriteData(shiroi->cards[i].video.vdp, data);
68
				}
69
			}
70
		}
71
	}
72
}
73
 
74
void shiroi_video_mk_i_tick(shiroi_t* shiroi) {
75
	uint8_t scanline[TMS9918_PIXELS_X];
76
	int i, y, x;
77
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
78
		if(shiroi->cards[i].type == SHIROI_VIDEO_MARK_I) {
79
			shiroi->cards[i].video.tick++;
80
			if(shiroi->cards[i].video.tick == 256) {
81
				shiroi->cards[i].video.tick = 0;
82
				for(y = 0; y < TMS9918_PIXELS_Y; y++) {
83
					vrEmuTms9918ScanLine(shiroi->cards[i].video.vdp, y, scanline);
84
					for(x = 0; x < TMS9918_PIXELS_X; x++) {
85
						shiroi->cards[i].video.fb[y * TMS9918_PIXELS_X + x] = vrEmuTms9918Palette[scanline[x]];
86
					}
87
				}
88
			}
89
		}
90
	}
91
}