Prince-of-Persia-Apple-II

A running-jumping-swordfighting game Jordan Mechner made on the Apple II from 1985-89
Log | Files | Refs | README | LICENSE

SOUND.S (4425B)


      1 * sound
      2 org = $ea00
      3  lst off
      4 *-------------------------------
      5 *
      6 *   S  O  U  N  D
      7 *
      8 *-------------------------------
      9  org org
     10 
     11  jmp PLAYBACK
     12 
     13 *-------------------------------
     14 savex ds 1
     15 
     16 spkr = $c030
     17 
     18 *-------------------------------
     19  put soundnames
     20  put gameeq
     21  put eq
     22 
     23 *-------------------------------
     24 *
     25 *  L O O K U P
     26 *
     27 *  Sound routine lookup table
     28 *
     29 *-------------------------------
     30 lookup
     31 
     32 :0 dw DoPlateDown
     33 :1 dw DoPlateUp
     34 :2 dw DoGateDown
     35 :3 dw DoSpecialKey1
     36 :4 dw DoSpecialKey2
     37 :5 dw DoSplat
     38 :6 dw DoMirrorCrack
     39 :7 dw DoLooseCrash
     40 :8 dw DoGotKey
     41 :9 dw DoFootstep
     42 :10 dw DoRaisingExit
     43 :11 dw DoRaisingGate
     44 :12 dw DoLowerGate
     45 :13 dw DoSmackWall
     46 :14 dw DoImpaled
     47 :15 dw DoGateSlam
     48 :16 dw DoFlashMsg
     49 :17 dw DoSwordClash1
     50 :18 dw DoSwordClash2
     51 :19 dw DoJawsClash
     52 
     53 endlook
     54 
     55 maxaddr = endlook-lookup
     56 
     57 *-------------------------------
     58 *
     59 *  Z E R O S O U N D
     60 *
     61 *  Zero sound table
     62 *
     63 *-------------------------------
     64 ZEROSOUND
     65  lda #0 ;# sounds in table
     66  sta soundtable
     67  rts
     68 
     69 *-------------------------------
     70 *
     71 *  A D D S O U N D
     72 *
     73 *  Add sound to sound table
     74 *  (preserve registers)
     75 *
     76 *  In: A = sound #
     77 *
     78 *-------------------------------
     79 ADDSOUND
     80  stx savex
     81 
     82  ldx soundtable
     83  cpx #maxsfx
     84  bcs :rts ;sound table full
     85 
     86  inx
     87  sta soundtable,x
     88  stx soundtable ;# sounds in table
     89 
     90 :rts ldx savex
     91  rts
     92 
     93 *-------------------------------
     94 *
     95 *  P L A Y B A C K
     96 *
     97 *  Playback all sounds listed in sound table
     98 *
     99 *-------------------------------
    100 PLAYBACK
    101  lda soundon
    102  beq :rts ;sound switched off?
    103 
    104  ldx soundtable
    105  beq :rts ;sound table empty?
    106 
    107 :loop lda soundtable,x
    108 
    109  stx savex
    110 
    111  jsr makesound ;make sound #A
    112 ;(may destroy registers)
    113  ldx savex
    114 
    115  dex
    116  bne :loop
    117 
    118 :rts rts
    119 
    120 *-------------------------------
    121 *
    122 *  M A K E S O U N D
    123 *
    124 *  In: A = sound # (0-127)
    125 *
    126 *-------------------------------
    127 makesound
    128  asl
    129  cmp #maxaddr
    130  bcs :rts ;don't exceed lookup table
    131 
    132  tax
    133  lda lookup,x
    134  sta :sm+1
    135  lda lookup+1,x
    136  sta :sm+2
    137 
    138 :sm jmp $ffff ;self-modifying code
    139 
    140 :rts rts
    141 
    142 *-------------------------------
    143 *
    144 *  S O U N D   R O U T I N E S
    145 *
    146 *-------------------------------
    147 * Kid steps on pressplate
    148 
    149 DoPlateDown
    150  ldy #70
    151  ldx #0
    152  lda #4
    153  jmp tone
    154 
    155 *-------------------------------
    156 * Pressplate pops back up
    157 
    158 DoPlateUp
    159  ldy #90
    160  ldx #0
    161  lda #4
    162  jmp tone
    163 
    164 *-------------------------------
    165 * Gate hits stone floor with an ominous CLANG
    166 
    167 DoGateDown
    168  ldy #70
    169  ldx #0
    170  lda #4
    171  jmp tone
    172 
    173 *-------------------------------
    174 * Jaws clash
    175 
    176 DoJawsClash
    177  ldy #10
    178  ldx #0
    179  lda #50
    180  jmp tone
    181 
    182 *-------------------------------
    183 * Acknowledge special keypress
    184 
    185 SK1Pitch = 15
    186 SK1Dur = 50
    187 
    188 SK2Pitch = 40
    189 SK2Dur = 50
    190 
    191 DoSpecialKey1
    192 DoSwordClash1
    193 DoSwordClash2
    194  ldy #SK1Pitch
    195  ldx #>SK1Pitch
    196  lda #SK1Dur
    197  jmp tone
    198 
    199 DoSpecialKey2
    200  ldy #SK2Pitch
    201  ldx #>SK2Pitch
    202  lda #SK2Dur
    203  jmp tone
    204 
    205 *-------------------------------
    206 * Splat
    207 
    208 SplatPitch = 1000
    209 SplatDur = 3
    210 
    211 DoSplat
    212  ldy #SplatPitch
    213  ldx #>SplatPitch
    214  lda #SplatDur
    215  jmp tone
    216 
    217 *-------------------------------
    218 * Mirror Crack
    219 
    220 DoMirrorCrack
    221  jmp DoSplat
    222  rts
    223 
    224 *-------------------------------
    225 * Loose Floor Crash
    226 
    227 DoLooseCrash
    228  jmp DoSplat
    229 
    230 *-------------------------------
    231 * Flash message
    232 
    233 ]HiPitch = 100
    234 ]HiDur = 25
    235 ]LoPitch = 500
    236 ]LoDur = 15
    237 
    238 DoGotKey
    239 DoFlashMsg
    240  lda #2
    241 :loop pha
    242 
    243  ldy #]LoPitch
    244  ldx #>]LoPitch
    245  lda #]LoDur
    246  jsr tone
    247 
    248  ldy #]HiPitch
    249  ldx #>]HiPitch
    250  lda #]HiDur
    251  jsr tone
    252 
    253  pla
    254  sec
    255  sbc #1
    256  bne :loop
    257 
    258  rts
    259 
    260 *-------------------------------
    261 * Footstep
    262 
    263 DoFootstep
    264  ldy #35
    265  ldx #0
    266  lda #3
    267  jmp tone
    268 
    269 *-------------------------------
    270 * Raising Exit
    271 
    272 DoRaisingExit
    273  ldy #40
    274  ldx #0
    275  lda #6
    276  jmp tone
    277 
    278 *-------------------------------
    279 * Raising Gate
    280 
    281 DoRaisingGate
    282  ldy #20
    283  ldx #0
    284  lda #2
    285  jmp tone
    286 
    287 *-------------------------------
    288 * Lowering Gate
    289 
    290 DoLowerGate
    291  ldy #7
    292  ldx #0
    293  lda #8
    294  jmp tone
    295 
    296 *-------------------------------
    297 * Smack Wall
    298 
    299 SWPitch = 1000
    300 SWDur = 3
    301 
    302 DoSmackWall
    303  ldy #SWPitch
    304  ldx #>SWPitch
    305  lda #SWDur
    306  jmp tone
    307 
    308 ]rts rts
    309 
    310 *-------------------------------
    311 * Impaled
    312 
    313 DoImpaled
    314  jmp DoSmackWall
    315 
    316 *-------------------------------
    317 * Gate Slam
    318 
    319 DoGateSlam
    320  jmp DoSmackWall
    321 
    322 
    323 *-------------------------------
    324 *
    325 *  T O N E
    326 *
    327 *  In: y-x = pitch lo-hi
    328 *      a = duration
    329 *
    330 *-------------------------------
    331 tone
    332  sty :pitch
    333  stx :pitch+1
    334 
    335 :outloop bit spkr
    336 
    337  ldx #0
    338 :midloop ldy #0
    339 
    340 :inloop iny
    341  cpy :pitch
    342  bcc :inloop
    343 
    344  inx
    345  cpx :pitch+1
    346  bcc :midloop
    347 
    348  sec
    349  sbc #1
    350  bne :outloop
    351 
    352  rts
    353 
    354 :pitch ds 2
    355 
    356 *-------------------------------
    357  lst
    358 eof ds 1
    359  usr $a9,20,$e00,*-org
    360  lst off