main test.c
 1#include <stdint.h>
 2#include <stdlib.h>
 3#include <string.h>
 4#include <stdio.h>
 5#include "vdp.h"
 6
 7int headless = 1;
 8uint16_t read_dma_value(uint32_t address)
 9{
10	return 0;
11}
12
13uint32_t render_map_color(uint8_t r, uint8_t g, uint8_t b)
14{
15	return 0;
16}
17
18void render_alloc_surfaces(vdp_context * context)
19{
20	context->oddbuf = context->framebuf = malloc(512 * 256 * 4 * 2);
21	memset(context->oddbuf, 0, 512 * 256 * 4 * 2);
22	context->evenbuf = ((char *)context->oddbuf) + 512 * 256 * 4;
23}
24
25int check_hint_time(vdp_context * v_context)
26{
27	uint32_t orig_hint_cycle = vdp_next_hint(v_context);
28	uint32_t cur_hint_cycle;
29	printf("hint cycle is %d at vcounter: %d, hslot: %d\n", orig_hint_cycle, v_context->vcounter, v_context->hslot);
30	int res = 1;
31	while ((cur_hint_cycle = vdp_next_hint(v_context)) > v_context->cycles)
32	{
33		if (cur_hint_cycle != orig_hint_cycle) {
34			fprintf(stderr, "ERROR: hint cycle changed to %d at vcounter: %d, hslot: %d\n", cur_hint_cycle, v_context->vcounter, v_context->hslot);
35			orig_hint_cycle = cur_hint_cycle;
36			res = 0;
37		}
38		vdp_run_context(v_context, v_context->cycles + 1);
39	}
40	printf("hint fired at cycle: %d, vcounter: %d, hslot: %d\n", cur_hint_cycle, v_context->vcounter, v_context->hslot);
41	vdp_int_ack(v_context, 4);
42	return res;
43}
44
45
46int main(int argc, char ** argv)
47{
48	vdp_context v_context;
49	init_vdp_context(&v_context, 0);
50	vdp_control_port_write(&v_context, 0x8144);
51	vdp_control_port_write(&v_context, 0x8C81);
52	vdp_control_port_write(&v_context, 0x8A7F);
53	vdp_control_port_write(&v_context, 0x8014);
54	v_context.hint_counter = 0x7F;
55	v_context.vcounter = 128;
56	v_context.hslot = 165;
57	//check single shot behavior
58	int res = check_hint_time(&v_context);
59	//check every line behavior
60	while (v_context.vcounter < 225)
61	{
62		vdp_run_context(&v_context, v_context.cycles + 1);
63	}
64	vdp_control_port_write(&v_context, 0x8A00);
65	int hint_count = 0;
66	while (res && v_context.vcounter != 224)
67	{
68		res = res && check_hint_time(&v_context);
69		hint_count++;
70	}
71	if (res && hint_count != 225) {
72		fprintf(stderr, "ERROR: hint count should be 225 but was %d instead\n", hint_count);
73		res = 0;
74	}
75	return 0;
76}