Subversion Repositories Shiroi

Rev

Rev 7 | Rev 11 | 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 10 2024-08-29 01:39:27Z 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;
30
}
31
 
1 nishi 32
void shiroi_video_mk_i(shiroi_t* shiroi) {
33
	int i;
34
 
35
	uint16_t io = Z80_GET_ADDR(shiroi->z80_pins);
36
	uint16_t addr = io & 0xff;
37
	uint16_t data = (io >> 8) & 0xff;
38
 
39
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
40
		if(shiroi->cards[i].type == SHIROI_VIDEO_MARK_I) {
41
			if(shiroi->z80_pins & Z80_RD) {
42
				/* I/O Read */
43
				if(addr == 1) {
44
					Z80_SET_DATA(shiroi->z80_pins, vrEmuTms9918ReadData(shiroi->cards[i].video.vdp));
45
				} else if(addr == 2) {
46
					Z80_SET_DATA(shiroi->z80_pins, shiroi->cards[i].type);
47
				}
48
			} else if(shiroi->z80_pins & Z80_WR) {
49
				/* I/O Write */
50
				if(addr == 0) {
51
					vrEmuTms9918WriteAddr(shiroi->cards[i].video.vdp, data);
52
				} else if(addr == 1) {
53
					vrEmuTms9918WriteData(shiroi->cards[i].video.vdp, data);
54
				}
55
			}
56
		}
57
	}
58
}
59
 
60
void shiroi_video_mk_i_tick(shiroi_t* shiroi) {
61
	uint8_t scanline[TMS9918_PIXELS_X];
62
	int i, y, x;
63
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
64
		if(shiroi->cards[i].type == SHIROI_VIDEO_MARK_I) {
65
			shiroi->cards[i].video.tick++;
66
			if(shiroi->cards[i].video.tick == 256) {
67
				shiroi->cards[i].video.tick = 0;
68
				for(y = 0; y < TMS9918_PIXELS_Y; y++) {
69
					vrEmuTms9918ScanLine(shiroi->cards[i].video.vdp, y, scanline);
70
					for(x = 0; x < TMS9918_PIXELS_X; x++) {
71
						shiroi->cards[i].video.fb[y * TMS9918_PIXELS_X + x] = vrEmuTms9918Palette[scanline[x]];
72
					}
73
				}
74
			}
75
		}
76
	}
77
}