1
2
3
4        MODULE  asm_play_sample
5
6        PUBLIC  asm_play_sample
7
8
9        SECTION code_driver
10
11        INCLUDE "target/gb/def/gb_globals.def"
12
13	defc AUD3WAVERAM = 0xff30
14
15asm_play_sample:
16
17; Playback raw sound sample with length BC from HL at 8192Hz rate.
18; BC defines the length of the sample in samples/32 or bytes/16.
19; The format of the data is unsigned 4-bit samples,
20; 2 samples per byte, upper 4-bits played before lower 4 bits.
21;
22; Adaption for GBDK by Lars Malmborg.
23; Original code by Jeff Frohwein.
24
25  ld  a,0x84
26  ldh (NR52),a       ;enable sound 3
27
28  ld a,0
29  ldh (NR30),a
30  ldh (NR51),a
31
32  ld a,0x77
33  ldh (NR50),a       ;select speakers
34  ld a,0xff
35  ldh (NR51),a       ;enable sound 3
36
37  ld a,0x80
38  ldh (NR31),a       ;sound length
39  ld a,0x20
40  ldh (NR32),a       ;sound level high
41
42  ld a,0x00
43  ldh (NR33),a       ;sound freq low
44
45samp2:
46  ld de,AUD3WAVERAM ;12
47  push bc             ;16
48  ld b,16            ;16
49
50  xor a
51  ldh (NR30),a
52samp3:
53  ld a,(hl+)          ;8
54  ld (de),a           ;8
55  inc de              ;8
56  dec b               ;4
57  jr nz,samp3        ;12
58
59  ld a,0x80
60  ldh (NR30),a
61
62  ld a,0x87          ; (256hz)
63  ldh (NR34),a
64
65  ld bc,558          ;delay routine
66samp4:
67  dec bc              ;8
68  ld a,b              ;4
69  or c                ;4
70  jr nz,samp4        ;12
71
72  ld a,0             ;more delay
73  ld a,0
74  ld a,0
75
76  pop bc              ;12
77  dec bc              ;8
78  ld a,b              ;4
79  or c                ;4
80  jr nz,samp2        ;12
81
82  ld a,0xbb
83  ldh (NR51),a       ;disable sound 3
84  ret
85