view target-utils/buzplayer/melplay.c @ 921:74d284add54d

fc-fsio: guard against bogus readdir results from the target If the FFS being operated on contains SE K2x0 extended filenames, readdir will return strings that are bad for printing. We need to guard against this possibility, and also against possible other bogosity that could be sent by other alien firmwares.
author Mychaela Falconia <falcon@freecalypso.org>
date Sat, 31 Dec 2022 22:55:23 +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");
	}
}