Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- NMI player by Scan/House Designs/DESiRE (Richard Loerakker)
- This is a small example of playing 8-bit samples at 8000Hz using a Commodore 64
- Compile using Kick Assembler (http://www.theweb.dk/KickAssembler/)
- Using Audacity:
- Open some audio file
- Set project frequency at 8000Hz
- Convert audio to mono
- (Apply other fx optionally)
- Select about 6 seconds of data (that's about the most that can fit uncompressed in memory)
- Choose from File menu Export Selected audio
- File type: Other uncompressed files
- Header: RAW (header-less)
- Encoding: Unsigned 8-bit PCM
- References:
- One SID channel digi: http://codebase64.org/doku.php?id=base:vicious_sid_demo_routine_explained
- How I acknowledge and exit NMI: http://codebase64.org/doku.php?id=base:quick_exit_from_interrupt
- Memory map: http://www.awsm.de/mem64/
- Kernal disassembly: http://unusedino.de/ec64/technical/aay/c64/krnromma.htm
- */
- .const samplefile = "carachangren.raw"
- .const NTSCorPAL = $02a6
- .pc = $0801 "Basic UpStart"
- :BasicUpstart2(start)
- .pc = * "Entrypoint"
- start:
- jsr $ff81 // init editor & video chips
- jsr $ff84 // init io, ports & timers
- jsr $ff8a // restore vectors to default
- lda #$00 // turn off screen
- sta $d011
- sei // set interrupt flag
- lda #$35 // turn off basic and kernal rom
- sta $01
- lda #$7f // turn off cia timers
- sta $dc0d
- sta $dd0d
- lda $dc0d // acknowledge possible pending interrupts
- lda $dd0d
- lda $d019
- lda #%00001111 // set generic volume to 15
- sta $d418
- lda #$00 // ADSR voice 3
- sta $d413
- lda #$f0
- sta $d414
- lda #<nmi // set NMI vector
- clc
- adc NTSCorPAL
- sta $fffa
- lda #>nmi
- sta $fffb
- lda #RTI
- sta $dd0c
- lda NTSCorPAL
- bne isPAL
- lda #$81
- bne isNTSC
- isPAL: lda #$7a // set NMI timer to 122 cycles (#$81 for NTSC)
- isNTSC: sta $dd04
- lda #$00
- sta $dd05
- lda #$81 // start the NMI timer
- sta $dd0d
- lda #$01
- sta $dd0e
- cli
- !:
- .label wait = * + 1
- lda #$00 // wait for sample to be finished
- beq !-
- sei
- lda #$37 // turn back on basic and kernal rom
- sta $01
- // wait a little
- ldy #$30
- rep: ldx #$00
- !: dex
- bne !-
- dey
- bne rep
- jmp 64738 // reset
- .pc = * "NMI's"
- nmi:
- nop // wait 6 cycles (otherwise a high-pitched note can be observed)
- nop // (add extra nop for NTSC)
- nop
- nop
- sta $ff
- // this is mostly cut and paste stuff from codebase
- lda #$11 // step 1 (triangle waveform, voice 3 on (ADS cycle)
- sta $d412
- lda #$09 // step 2 & 3 (voice 3 on, disabled, reset noise generator)
- sta $d412
- .label offset = *+1
- lda sample // step 4 (set high byte of frequency with sample data)
- sta $d40f
- lda #$01 // step 5 (voice 3 on, no waveform selected)
- sta $d412
- inc offset
- bne notatend
- inc offset+1
- lda offset+1
- cmp #>end_of_sample
- bne notatend
- inc wait // <- remove this if you want to loop the sample
- lda #>sample
- sta offset+1
- notatend: lda $ff
- jmp $dd0c
- .align 256
- .pc = * "8-bit sample data"
- sample: .import binary samplefile
- .pc = *
- end_of_sample:
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement