Subversion Repositories Shiroi

Rev

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