aboutsummaryrefslogtreecommitdiff
path: root/sam.c
blob: c921c48228d02784dd6732f1819b57fc7d5b0da5 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
// sam.c
//
// 20060811 Markku Alén

#include "sam.h"
#include "c64.h"
#include "cpu.h"
#include "sid.h"

static void feed(const char *text)
{
	char c;
	while((c = *(text++)) != '\0')
	{
		kbd_ascii_push(c, 1);
		c64_run(20000);
		kbd_ascii_push(c, 0);
		c64_run(20000);
	}
}

static void run_to(int addr_start, int addr_stop)
{
	int pc;
	for(;;)
	{
		pc = get_pc();
		if(pc >= addr_start && pc <= addr_stop)
			break;
		c64_run(20000);
	}
}

void sam_init(void)
{
	c64_init();
	run_to(0xe5cd, 0xe5d5);
	feed("LOAD\"SAM.PRG\",1,1\r RUN\rH");
	run_to(0xe5cd, 0xe5d5);
	feed("]RE\r");
	run_to(0xe5cd, 0xe5d5);
}

void sam_say(const char *text, unsigned int frequency, unsigned char *wave_buf, unsigned int *wave_len_ref)
{
	feed("SAY\"");
	feed(text);
	feed("\"\r");
	start_record(frequency, wave_buf, *wave_len_ref);
	run_to(0xe5cd, 0xe5d5);
	*wave_len_ref = stop_record();
}