view target-utils/buzplayer/melentry.c @ 887:3e398f9c31a0

fc-imy2pwt: overhaul melody error handling, report position
author Mychaela Falconia <falcon@freecalypso.org>
date Sun, 03 Apr 2022 04:17:08 +0000
parents 9092ff68e37d
children
line wrap: on
line source

#include <sys/types.h>
#include <ctype.h>
#include <stdlib.h>
#include "types.h"
#include "melody.h"

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

void
melody_init()
{
	melody_buf_tailptr = melody_buf_start;
	melody_mode = 1;
	pwt_off();
}

void
melody_init_pwt()
{
	melody_buf_tailptr = melody_buf_start;
	melody_mode = 2;
	pwt_on();
}

void
melody_entry(argbulk)
	char *argbulk;
{
	char *argv[3];
	u32 tone, dur;

	if (melody_mode != 1) {
		printf("ERROR: wrong mode for melody entry\n");
		return;
	}
	if (parse_args(argbulk, 2, 2, argv, 0) < 0)
		return;
	tone = strtoul(argv[0], 0, 0);
	dur = strtoul(argv[1], 0, 0);
	if (tone > 255 || dur < 1 || dur > 0xFFFF) {
		printf("ERROR: argument(s) out of range\n");
		return;
	}
	melody_buf_tailptr->tone = tone;
	melody_buf_tailptr->dur = dur;
	melody_buf_tailptr++;
}

void
pwt_entry_note(argbulk)
	char *argbulk;
{
	char *argv[4];
	u32 tone, vol, dur;

	if (melody_mode != 2) {
		printf("ERROR: wrong mode for melody entry\n");
		return;
	}
	if (parse_args(argbulk, 3, 3, argv, 0) < 0)
		return;
	tone = strtoul(argv[0], 0, 0);
	vol = strtoul(argv[1], 0, 0);
	dur = strtoul(argv[2], 0, 0);
	if (tone > 47 || vol > 63 || dur < 1 || dur > 0xFFFF) {
		printf("ERROR: argument(s) out of range\n");
		return;
	}
	melody_buf_tailptr->tone = tone;
	melody_buf_tailptr->vol = (vol << 1) | 1;
	melody_buf_tailptr->dur = dur;
	melody_buf_tailptr++;
}

void
pwt_entry_rest(argbulk)
	char *argbulk;
{
	char *argv[2];
	u32 dur;

	if (melody_mode != 2) {
		printf("ERROR: wrong mode for melody entry\n");
		return;
	}
	if (parse_args(argbulk, 1, 1, argv, 0) < 0)
		return;
	dur = strtoul(argv[0], 0, 0);
	if (dur < 1 || dur > 0xFFFF) {
		printf("ERROR: argument out of range\n");
		return;
	}
	melody_buf_tailptr->tone = 0;
	melody_buf_tailptr->vol = 0;
	melody_buf_tailptr->dur = dur;
	melody_buf_tailptr++;
}