Subversion Repositories Shiroi

Rev

Rev 10 | Details | Compare with Previous | Last modification | View Log | RSS feed

Rev Author Line No. Line
7 nishi 1
/* $Id: shiroi_video_mk_ii.c 11 2024-08-29 02:49:47Z nishi $ */
2
#include "shiroi_video_mk_ii.h"
3
 
4
#include "shiroi.h"
5
 
6
#include <stdlib.h>
7
 
8
uint64_t shiroi_video_mk_ii_cb(uint64_t pins, void* data) {
9
	shiroi_card_t* card = (shiroi_card_t*)data;
10
	MC6847_SET_DATA(pins, card->video.vram[MC6847_GET_ADDR(pins)]);
11
	return pins;
12
}
13
 
14
void shiroi_video_mk_ii_install(shiroi_t* shiroi, int slot) {
15
	shiroi->cards[slot].type = SHIROI_VIDEO_MARK_II;
16
	shiroi->cards[slot].videoptr = &shiroi->cards[slot].video;
17
 
18
	shiroi->cards[slot].video.width = MC6847_IMAGE_WIDTH + MC6847_BORDER_PIXELS * 2;
19
	shiroi->cards[slot].video.height = MC6847_FRAMEBUFFER_HEIGHT;
20
	shiroi->cards[slot].video.tick = 0;
21
 
22
	mc6847_desc_t desc;
23
	desc.tick_hz = 3 * 1024 * 1024;
24
	desc.framebuffer.ptr = malloc(MC6847_FRAMEBUFFER_SIZE_BYTES);
25
	desc.framebuffer.size = MC6847_FRAMEBUFFER_SIZE_BYTES;
26
	desc.fetch_cb = shiroi_video_mk_ii_cb;
27
	desc.user_data = &shiroi->cards[slot];
28
 
29
	mc6847_init(&shiroi->cards[slot].video.mc6847, &desc);
30
 
31
	int x, y;
32
	for(y = 0; y < shiroi->cards[slot].video.height; y++) {
33
		for(x = 0; x < shiroi->cards[slot].video.width; x++) {
34
			shiroi->cards[slot].video.fb[y * shiroi->cards[slot].video.width + x] = 0;
35
		}
36
	}
37
}
38
 
10 nishi 39
void shiroi_video_mk_ii_reset(shiroi_t* shiroi, int slot) {
40
	mc6847_reset(&shiroi->cards[slot].video.mc6847);
41
	shiroi->cards[slot].video.tick = 0;
11 nishi 42
	int y, x;
43
	for(y = 0; y < shiroi->cards[slot].video.height; y++) {
44
		for(x = 0; x < shiroi->cards[slot].video.width; x++) {
45
			shiroi->cards[slot].video.fb[y * shiroi->cards[slot].video.width + x] = 0x000000ff;
46
		}
47
	}
10 nishi 48
}
49
 
7 nishi 50
void shiroi_video_mk_ii(shiroi_t* shiroi) {
51
	int i;
52
 
53
	uint16_t io = Z80_GET_ADDR(shiroi->z80_pins);
54
	uint16_t addr = io & 0xff;
55
	uint16_t data = (io >> 8) & 0xff;
56
 
57
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
58
		if(shiroi->cards[i].type == SHIROI_VIDEO_MARK_II) {
59
			if(shiroi->z80_pins & Z80_RD) {
60
				/* I/O Read */
61
				if(addr == 1) {
62
					Z80_SET_DATA(shiroi->z80_pins, shiroi->cards[i].video.vram[shiroi->cards[i].video.vram_addr++]);
63
				} else if(addr == 2) {
64
					Z80_SET_DATA(shiroi->z80_pins, shiroi->cards[i].type);
65
				}
66
			} else if(shiroi->z80_pins & Z80_WR) {
67
				/* I/O Write */
68
				if(addr == 0) {
69
					shiroi->cards[i].video.vram_addr >>= 8;
70
					shiroi->cards[i].video.vram_addr |= data << 8;
71
				} else if(addr == 1) {
72
					shiroi->cards[i].video.vram[shiroi->cards[i].video.vram_addr++] = data;
73
				}
74
			}
75
		}
76
	}
77
}
78
 
79
void shiroi_video_mk_ii_tick(shiroi_t* shiroi) {
80
	int i, y, x;
81
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
82
		if(shiroi->cards[i].type == SHIROI_VIDEO_MARK_II) {
83
			shiroi->cards[i].video.tick++;
84
			mc6847_tick(&shiroi->cards[i].video.mc6847, shiroi->cards[i].video.mc6847.pins);
85
			if(shiroi->cards[i].video.tick == 16384) {
86
				shiroi->cards[i].video.tick = 0;
87
				for(y = 0; y < MC6847_FRAMEBUFFER_HEIGHT; y++) {
88
					for(x = 0; x < MC6847_FRAMEBUFFER_WIDTH; x++) {
89
						if(x < shiroi->cards[i].video.width) {
90
							uint32_t c = shiroi->cards[i].video.mc6847.hwcolors[shiroi->cards[i].video.mc6847.fb[y * MC6847_FRAMEBUFFER_WIDTH + x] & 0xf];
91
							shiroi->cards[i].video.fb[y * shiroi->cards[i].video.width + x] = ((c & 0xffffff) << 8) | ((c & 0xff000000) >> 24);
92
						}
93
					}
94
				}
95
			}
96
		}
97
	}
98
}