Subversion Repositories Shiroi

Rev

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

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