; sample player ; need 317 tstates per sample org 32768 ; ld hl,22016 ; start address of sample data ; ld bc,221 ; length of sample data, in bytes ; push bc start ; call init_ay ; ret init_ay ld a,7 ; set bits 0-5 of AY register 7 so that all channels are fixed at 'high' ld bc,0xfffd ; output - this way the AY is not generating waveforms of its own, and out (c),a ; varying the volume (channels 8/9/10) creates our own wave output instead ld a,63 ld b,0xbf out (c),a ; ret main_loop ld ix, 60000 ld de, 17 ld a, 00 scf call 0x0556 ld ix, 16384 ld de, 6912 ld a, 255 scf call 0x0556 ld b, 255 loppsa nop ld a,1 nop ld a,1 nop ld a,1 nop ld a,1 djnz loppsa di ld hl, 20672 ld bc, 64 call samplelp ; This call re-enables interrupts before returning ld hl, 20928 ld bc, 64 call samplelp ; This call re-enables interrupts before returning ld hl, 21184 ld bc, 64 call samplelp ; This call re-enables interrupts before returning ld hl, 21440 ld bc, 29 call samplelp ; This call re-enables interrupts before returning ; ei jp main_loop ret samplelp push bc ; 11 ; get low 4 bits to use as the first volume level ld a,(hl) ; 7 and 0x0f ; 7 ; delay 117ish tstates ld b,8 ; 7 zzz2 djnz zzz2 ; output that volume level to channels 8/9/10 ld bc,0xfffd ; 10 ld d,8 ; 7 out (c),d ; 12 ld b,0xbf ; 7 out (c),a ; 12 inc d ; 4 ld b,0xff ; 7 out (c),d ; 12 ld b,0xbf ; 7 out (c),a ; 12 inc d ; 4 ld b,0xff ; 7 out (c),d ; 12 ld b,0xbf ; 7 out (c),a ; 12 ; get the next volume level from the high 4 bits ld a,(hl) ; 7 ; start tstate count here srl a ; 8 srl a ; 8 srl a ; 8 srl a ; 8 ; delay 152ish tstates ld b,11 ; 7 (orignally 11) zzz1 djnz zzz1 ; 8 ; output that volume level to channels 8/9/10 ld b,0xff ; 7 ld d,8 ; 7 out (c),d ; 12 ld b,0xbf ; 7 out (c),a ; 12 inc d ; 4 ld b,0xff ; 7 out (c),d ; 12 ld b,0xbf ; 7 out (c),a ; 12 inc d ; 4 ld b,0xff ; 7 out (c),d ; 12 ld b,0xbf ; 4 out (c),a ; 12 ; move on to next byte inc hl ; 6 ; loop if we haven't reached the end of the sample pop bc ; 11 dec bc ; 6 ld a,b ; 4 or c ; 4 jr nz,samplelp ; 12 ret