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 3 years have passed since last update.

ASM6でnesファイルを作ってみた(2)

Last updated at Posted at 2020-12-07

環境

  • Windows 10 Home (64bit)
  • ASM6 (v1.6)

ソース

原始的サウンドドライバ

VBlank割込みを使った原始的サウンドドライバ。

test9.asm
;asm6 test9.asm test9.nes

tick	= $00
seq	= $01

	; iNES header
	db	"NES", $1a
	db	$01	; PRG-ROM
	db	$01	; CHR-ROM
	db	$00	; mapper / mirroring
	dsb	9, $00

	base	$c000
Reset:
	lda	#$00
	sta	seq
	lda	#$01
	sta	tick

	lda	#$01
	sta	$4015	; 音声チャンネル制御レジスタ
	lda	#%10111100
	sta	$4000	; 矩形波CH1制御レジスタ1
	lda	#$00
	sta	$4001	; 矩形波CH1制御レジスタ2
	sta	$4002	; 矩形波CH1周波数値レジスタ1
	sta	$4003	; 矩形波CH1周波数値レジスタ2

	lda	#$80
	sta	$2000	; PPU制御レジスタ1
	lda	#$08
	sta	$2001	; PPU制御レジスタ2
-
	jmp	-

VBlank:
	dec	tick
	bne	++
	ldx	seq
	lda	sequence, x
	bne	+
	ldx	#$00
	stx	seq
	lda	sequence
+
	sta	$4002	; 矩形波CH1周波数値レジスタ1
	inc	seq
	lda	#30
	sta	tick
++
	rti

sequence:	; 1,790,000Hz / (1,000Hz * 16) - 1 = 110.875 = $6f
	db	$37, $6f, $00

	org	$fffa
	dw	VBlank	; NMI VBlank
	dw	Reset
	dw	0	; IRQ/BRK

	; fsutil file createNew test.chr 8192
	incbin	"test.chr"

ノイズ発生

ABボタンでノイズ発生。

test10.asm
;asm6 test10.asm test10.nes

button_a	= $00
button_b	= $01

	; iNES header
	db	"NES", $1a
	db	$01	; PRG-ROM
	db	$01	; CHR-ROM
	db	$00	; mapper / mirroring
	dsb	9, $00

	base	$c000
Reset:
	lda	#$80
	sta	$2000	; PPU制御レジスタ1
	lda	#$08
	sta	$2001	; PPU制御レジスタ2
-
	jmp	-

VBlank:
	lda	#$01
	sta	$4016	; ジョイパッド1レジスタ
	lda	#$00
	sta	$4016

	; Aボタン
	lda	$4016
	and	#$01
	bne	+
	lda	#$00
	jmp	++
+
	lda	button_a
	bne	++
	ldx	#%10000111
	jsr	sound
	lda	#$ff
++
	sta	button_a

	; Bボタン
	lda	$4016
	and	#$01
	bne	+
	lda	#$00
	jmp	++
+
	lda	button_b
	bne	++
	ldx	#%00000111
	jsr	sound
	lda	#$ff
++
	sta	button_b

	rti

sound:
	lda	#%00001111
	sta	$400c	; ノイズ制御レジスタ
	stx	$400e	; ノイズ乱数レジスタ
	lda	#%00001000
	sta	$400f	; ノイズ時間レジスタ
	lda	#$08
	sta	$4015	; 音声チャンネル制御レジスタ
	rts

	org	$fffa
	dw	VBlank	; NMI VBlank
	dw	Reset
	dw	0	; IRQ/BRK

	incbin	"test.chr"
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?