1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

sdccでmsx その2

Last updated at Posted at 2016-03-20

概要

sdccでmsxのpsgを叩いて、音を鳴らして見た。

開発環境

SDCC : ver2.8.1
ruMSX : ver0.41

MakeFile

All : psg.hex psg.rom
psg.hex : psg.o
	sdcc -V -mz80 --no-std-crt0 --code-loc 0x4020 --data-loc 0x8000 -o psg.hex  psg.o
psg.rom : psg.hex
	hex2rom psg.hex psg.rom
psg.o : psg.c
	sdcc -V -mz80 psg.c

サンプルコード

# define	WRTPSG		#0x0093
# define	CHPUT		#0x00A2
# define	CHGET		#0x009F
void setpsg(unsigned char e, unsigned char a);
void wait(int t);
void putchar(char c);
int  getchar();
void main(void)
{
	unsigned int psg[] = {
		0xaa, 0xaa, 0xaa, 0xa0, 0xaa, 0xaa, 0xd6, 0xd6, 0xbe, 0xbe,
		0xd6, 0xbe, 0xaa, 0x10d, 0xe3, 0xaa, 0xaa, 0xaa, 0xa0, 0xaa,
		0xaa, 0xd6, 0xbe, 0xbe, 0xd6, 0xe3, 0xfe, 0x7f, 0x7f, 0x7f,
		0x7f, 0x7f, 0x7f, 0xaa, 0xaa, 0xaa, 0xaa, 0xa0, 0x8f, 0xa0,
		0xaa, 0xaa, 0xa0, 0xaa, 0xaa, 0xd6, 0xd6, 0xbe, 0xbe, 0xd6,
		0xe3, 0xfe, 0x153, 0x153, 0x140, 0x153, 0x153, 0x1ac, 0x1ac,
		0x17d, 0x17d, 0x1ac, 0x17d, 0x153, 0x153, 0x153, 0x140, 0x153,
		0x153, 0x1ac, 0x1ac, 0x17d, 0x17d, 0x1ac, 0x01c5, 0x01fc, 0x7f, 0x7f,
		0x7f, 0x7f, 0x7f, 0x7f, 0x7f, 0xaa, 0xaa, 0xaa, 0xa0, 0x8f, 0xa0,
		0xaa, 0xaa, 0xa0, 0xaa, 0xaa, 0xd6, 0xd6, 0xbe, 0xbe, 0xd6, 0xe3,
		0xfe
	};
	unsigned int i, j, e, a;
	i = j = e = a = 0;
	a = 0x07;
	e = 0xfe;
	setpsg(e, a);
	for (i = 0; i < 101; i++)
	{
		e = psg[i] & 0xff;
		a = 0x00;
		setpsg(e, a);
		e = (psg[i] >> 8) & 0xff;
		a = 0x01;
		setpsg(e, a);
		e = 0x05;
	  	a = 0x08;
  		setpsg(e, a);
		wait(98000);
		e = 0x00;
		a = 0x08;
		setpsg(e, a);
		wait(2000);
	}
	putchar(getchar());
}
void setpsg(unsigned char e, unsigned char a)
{
	_asm
	ld 		e, 4(ix)
	ld 		a, 5(ix)
	call 	WRTPSG
	_endasm;
}
void putchar(char c)
{
	_asm
	ld 		a, 4(ix)
	call 	CHPUT
	_endasm;
}
int getchar()
{
	_asm
	call 	CHGET
	ld 		l, a
	ld 		h, #0
	_endasm;
}
void wait(int t)
{
	while(t--);
}

1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?