Subversion Repositories Shiroi

Rev

Rev 8 | Go to most recent revision | Details | Last modification | View Log | RSS feed

Rev Author Line No. Line
7 nishi 1
/* $Id: shiroi_video_mk_ii.c 7 2024-08-28 14:02:52Z 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
	shiroi->cards[slot].video.mc6847.pins |= MC6847_INV;
32
	int x, y;
33
	for(y = 0; y < shiroi->cards[slot].video.height; y++) {
34
		for(x = 0; x < shiroi->cards[slot].video.width; x++) {
35
			shiroi->cards[slot].video.fb[y * shiroi->cards[slot].video.width + x] = 0;
36
		}
37
	}
38
}
39
 
40
void shiroi_video_mk_ii(shiroi_t* shiroi) {
41
	int i;
42
 
43
	uint16_t io = Z80_GET_ADDR(shiroi->z80_pins);
44
	uint16_t addr = io & 0xff;
45
	uint16_t data = (io >> 8) & 0xff;
46
 
47
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
48
		if(shiroi->cards[i].type == SHIROI_VIDEO_MARK_II) {
49
			if(shiroi->z80_pins & Z80_RD) {
50
				/* I/O Read */
51
				if(addr == 1) {
52
					Z80_SET_DATA(shiroi->z80_pins, shiroi->cards[i].video.vram[shiroi->cards[i].video.vram_addr++]);
53
				} else if(addr == 2) {
54
					Z80_SET_DATA(shiroi->z80_pins, shiroi->cards[i].type);
55
				}
56
			} else if(shiroi->z80_pins & Z80_WR) {
57
				/* I/O Write */
58
				if(addr == 0) {
59
					shiroi->cards[i].video.vram_addr >>= 8;
60
					shiroi->cards[i].video.vram_addr |= data << 8;
61
				} else if(addr == 1) {
62
					shiroi->cards[i].video.vram[shiroi->cards[i].video.vram_addr++] = data;
63
				}
64
			}
65
		}
66
	}
67
}
68
 
69
void shiroi_video_mk_ii_tick(shiroi_t* shiroi) {
70
	int i, y, x;
71
	for(i = 0; i < 256 / SHIROI_IO_PORTS; i++) {
72
		if(shiroi->cards[i].type == SHIROI_VIDEO_MARK_II) {
73
			shiroi->cards[i].video.tick++;
74
			mc6847_tick(&shiroi->cards[i].video.mc6847, shiroi->cards[i].video.mc6847.pins);
75
			if(shiroi->cards[i].video.tick == 16384) {
76
				shiroi->cards[i].video.tick = 0;
77
				for(y = 0; y < MC6847_FRAMEBUFFER_HEIGHT; y++) {
78
					for(x = 0; x < MC6847_FRAMEBUFFER_WIDTH; x++) {
79
						if(x < shiroi->cards[i].video.width) {
80
							uint32_t c = shiroi->cards[i].video.mc6847.hwcolors[shiroi->cards[i].video.mc6847.fb[y * MC6847_FRAMEBUFFER_WIDTH + x] & 0xf];
81
							shiroi->cards[i].video.fb[y * shiroi->cards[i].video.width + x] = ((c & 0xffffff) << 8) | ((c & 0xff000000) >> 24);
82
						}
83
					}
84
				}
85
			}
86
		}
87
	}
88
}