aboutsummaryrefslogtreecommitdiff
path: root/soundasm.s
blob: c1663a4b5b3d880050264e12b07c33262c884f93 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
; Sounds for Taipan! Atari 800 port.

; Made by capturing the Apple II audio and taking wild guesses,
; then refining them.

; I'm not shooting for Atari sounds that are identical to the
; Apple ones: (a) it's impossible anyway, and (b) the Apple
; sounds are a bit harsh to the ear. Hopefully these sound
; a little smoother while still being pretty close.

; This is an asm rewrite of sounds.c. Sounds the same, but weighs
; in at 186 bytes less code

; general form from sounds.c:
;   for(j=0; j<repeats; j++) {
;      for(i=0; i<Yreg; i++) {
;         POKEY_WRITE.audf1 = Areg-i*Xreg;
;         jsleep(delay);
;      }
;   }

 .include "atari.inc"

 .import _jsleep
 .export _bad_joss_sound, _good_joss_sound, _under_attack_sound
 .importzp tmp1, tmp2, tmp3, tmp4, sreg

 .ifdef CART_TARGET
  .segment "HIGHCODE"
 .else
  .code
 .endif

initialpitch = sreg
delay = sreg+1
pitch = tmp1
decrement = tmp2
counter = tmp3
repeats = tmp4

; this must agree with newtitle.s
; 0 = enabled, 1 = disabled
sound_disabled = $cb

_under_attack_sound:
; C version was:
;   for(j=0; j<3; j++) {
;      for(i=0; i<3; i++) {
;         POKEY_WRITE.audf1 = 20-i*3;
;         jsleep(3);
;      }
;   }
 lda #$03
 sta delay
 sta repeats
 tax
 tay
 lda #$14
; fall through to make_sound

; call make_sound with:
; A = initial pitch
; X = decrement amount per frame
; Y = inner loop count (i)
; repeats = outer loop count (j)
; delay = jiffies to delay per inner loop
make_sound:
 sta initialpitch
 stx decrement
 sty counter

 ; if sound is disabled, don't play it at all.
 lda sound_disabled
 bne stop_sound

 ; init sound
 lda #0
 sta AUDCTL
 lda #3
 sta SKCTL
 lda #$AA ; pure tone, volume 10
 sta AUDC1

@repeatloop:
 ldy counter
 lda initialpitch
 sta pitch
@noteloop:
 lda pitch
 sta AUDF1
 sec
 sbc decrement
 sta pitch
 ldx #0
 lda delay
 jsr _jsleep

 ; if user pressed a key, abort the sound entirely.
 ; disabled for now.
 ;lda CH
 ;cmp #$FF
 ;bne stop_sound

 dey
 bne @noteloop
 dec repeats
 bne @repeatloop

stop_sound:
 lda #0
 sta AUDC1
 rts

_bad_joss_sound:
; C version was:
;   for(i=0; i<10; i++) {
;      POKEY_WRITE.audf1 = 80-i*8;
;      jsleep(1);
;   }
; which writes 80 72 64 56 48 40 32 24 16 8 to AUDF1
 lda #$01
 sta repeats
 sta delay
 lda #$50
 ldx #$08
 ldy #$0a
 bne make_sound

_good_joss_sound:
; C version was:
;   for(j=0; j<3; j++) {
;      for(i=0; i<4; i++) {
;         POKEY_WRITE.audf1 = 20-i*5;
;         jsleep(2);
;      }
;   }
; which writes 20 15 10 5 to AUDF1, 3 times
 lda #$03
 sta repeats
 lda #$02
 sta delay
 lda #$14
 ldx #$05
 ldy #$04
 bne make_sound