view target-utils/buzplayer/melplay.c @ 923:804aaac0b53d

CHANGES: document SE K2x0 FFS additions
author Mychaela Falconia <falcon@freecalypso.org>
date Mon, 02 Jan 2023 01:06:03 +0000
parents 158dd05fb9f9
children
line wrap: on
line source

#include "types.h"
#include "melody.h"

extern struct melentry *melody_buf_start, *melody_buf_tailptr;
extern int melody_mode;

#define	ARMIO_LOAD_TIM	(*(volatile u16 *) 0xFFFE4808)
#define	BUZZ_LIGHT_REG	(*(volatile u16 *) 0xFFFE480E)

#define	PWT_FRC_REG	(*(volatile u8 *) 0xFFFE8800)
#define	PWT_VCR_REG	(*(volatile u8 *) 0xFFFE8801)

void
melody_play_bu()
{
	struct melentry *p;
	int count;

	wait_for_tdma_frame();
	for (p = melody_buf_start; p < melody_buf_tailptr; p++) {
		if (p->tone) {
			ARMIO_LOAD_TIM = p->tone;
			BUZZ_LIGHT_REG = 1;
		} else
			BUZZ_LIGHT_REG = 0;
		for (count = p->dur; count; count--)
			wait_for_tdma_frame();
		BUZZ_LIGHT_REG = 0;
	}
}

void
melody_play_pwt()
{
	struct melentry *p;
	int count;

	wait_for_tdma_frame();
	for (p = melody_buf_start; p < melody_buf_tailptr; p++) {
		PWT_FRC_REG = p->tone;
		PWT_VCR_REG = p->vol;
		for (count = p->dur; count; count--)
			wait_for_tdma_frame();
		PWT_VCR_REG = 0;
	}
}

void
melody_play()
{
	switch (melody_mode) {
	case 1:
		melody_play_bu();
		return;
	case 2:
		melody_play_pwt();
		return;
	default:
		printf("ERROR: no melody entered\n");
	}
}