view target-utils/buzplayer/melplay.c @ 965:2969032bdfac

fcup-smsend[mult]: fix buglet in K&R C NULL pointer passing The only 100% safe way to pass a NULL pointer as a function argument in K&R C is to cast 0 to a pointer type; failing to do so may cause mysterious bugs (invalid stack frames or garbage in argument registers) on 64-bit machines. This issue has already been fixed in most of FC host tools, but I just found some missed spots: passing of NULL UDH to PDU encoding functions in fcup-smsend[mult] in the case of single (not concatenated) SMS.
author Mychaela Falconia <falcon@freecalypso.org>
date Fri, 01 Sep 2023 07:33:51 +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");
	}
}