Subversion Repositories Shiroi

Rev

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