fox32rom: Add play_audio and stop_audio routines
This commit is contained in:
parent
8d6c90498a
commit
c7464fa4bc
97
audio.asm
Normal file
97
audio.asm
Normal file
|
@ -0,0 +1,97 @@
|
||||||
|
; audio routines
|
||||||
|
|
||||||
|
; use ffmpeg to convert an audio file for playback:
|
||||||
|
; ffmpeg -i input.mp3 -f s16le -ac 1 -ar 22050 audio.raw
|
||||||
|
|
||||||
|
; fox32's audio output works by swapping between two buffers
|
||||||
|
; interrupt 0xFE (vector 0x000003F8) is fired when it's time to swap buffers
|
||||||
|
; when that interrupt fires, it calls `refill_buffer` which fills up the buffer
|
||||||
|
|
||||||
|
const CURRENT_BUFFER: 0x01FFFF00
|
||||||
|
const AUDIO_POINTER: 0x01FFFF01
|
||||||
|
const AUDIO_LENGTH: 0x01FFFF05
|
||||||
|
const OLD_BUFFER_SWAP_VECTOR: 0x01FFFF09
|
||||||
|
|
||||||
|
; play an audio clip (does not block)
|
||||||
|
; inputs:
|
||||||
|
; r0: pointer to audio clip
|
||||||
|
; r1: length of audio clip in bytes (must be a multiple of 32768 bytes)
|
||||||
|
; outputs:
|
||||||
|
; none
|
||||||
|
play_audio:
|
||||||
|
push r0
|
||||||
|
push r1
|
||||||
|
|
||||||
|
; set the interrupt vector for interrupt 0xFE and save the old one
|
||||||
|
mov [OLD_BUFFER_SWAP_VECTOR], [0x000003F8]
|
||||||
|
mov [0x000003F8], refill_buffer
|
||||||
|
|
||||||
|
; store audio pointer
|
||||||
|
mov [AUDIO_POINTER], r0
|
||||||
|
|
||||||
|
; store audio length
|
||||||
|
; floor it to the nearest multiple of 32768
|
||||||
|
and r1, 0xFFFF8000
|
||||||
|
mov [AUDIO_LENGTH], r1
|
||||||
|
|
||||||
|
; reset the current buffer to zero
|
||||||
|
; fox32 resets its current buffer to zero internally, so reset it to zero here to stay in sync
|
||||||
|
; refill_buffer will bitwise not this before checking it,
|
||||||
|
; so set it to 0xFF so that it becomes zero when checked for the first time
|
||||||
|
mov.8 [CURRENT_BUFFER], 0xFF
|
||||||
|
|
||||||
|
; enable audio playback
|
||||||
|
mov r0, 0x80000600
|
||||||
|
out r0, 1
|
||||||
|
|
||||||
|
pop r1
|
||||||
|
pop r0
|
||||||
|
ret
|
||||||
|
refill_buffer:
|
||||||
|
push r0
|
||||||
|
push r1
|
||||||
|
push r31
|
||||||
|
|
||||||
|
not.8 [CURRENT_BUFFER]
|
||||||
|
cmp.8 [CURRENT_BUFFER], 0
|
||||||
|
ifnz jmp refill_buffer_1
|
||||||
|
refill_buffer_0:
|
||||||
|
mov r31, 8192 ; 32768 bytes = 8192 words
|
||||||
|
mov r0, [AUDIO_POINTER]
|
||||||
|
mov r1, 0x0212C000 ; buffer 0 address
|
||||||
|
refill_buffer_loop:
|
||||||
|
mov [r1], [r0]
|
||||||
|
add r0, 4
|
||||||
|
add r1, 4
|
||||||
|
loop refill_buffer_loop
|
||||||
|
mov [AUDIO_POINTER], r0
|
||||||
|
sub [AUDIO_LENGTH], 32768
|
||||||
|
ifz call stop_audio
|
||||||
|
|
||||||
|
pop r31
|
||||||
|
pop r1
|
||||||
|
pop r0
|
||||||
|
reti
|
||||||
|
refill_buffer_1:
|
||||||
|
mov r31, 8192 ; 32768 bytes = 8192 words
|
||||||
|
mov r0, [AUDIO_POINTER]
|
||||||
|
mov r1, 0x02134000 ; buffer 1 address
|
||||||
|
jmp refill_buffer_loop
|
||||||
|
|
||||||
|
; stop audio playback
|
||||||
|
; inputs:
|
||||||
|
; none
|
||||||
|
; outputs:
|
||||||
|
; none
|
||||||
|
stop_audio:
|
||||||
|
push r0
|
||||||
|
|
||||||
|
; disable audio playback
|
||||||
|
mov r0, 0x80000600
|
||||||
|
out r0, 0
|
||||||
|
|
||||||
|
; restore the old buffer swap vector
|
||||||
|
mov [0x000003F8], [OLD_BUFFER_SWAP_VECTOR]
|
||||||
|
|
||||||
|
pop r0
|
||||||
|
ret
|
|
@ -71,6 +71,10 @@ string_length: jmp [0xF0046018]
|
||||||
; integer jump table
|
; integer jump table
|
||||||
string_to_int: jmp [0xF0047000]
|
string_to_int: jmp [0xF0047000]
|
||||||
|
|
||||||
|
; audio jump table
|
||||||
|
play_audio: jmp [0xF0048000]
|
||||||
|
stop_audio: jmp [0xF0048004]
|
||||||
|
|
||||||
; event types
|
; event types
|
||||||
const EVENT_TYPE_MOUSE_CLICK: 0x00000000
|
const EVENT_TYPE_MOUSE_CLICK: 0x00000000
|
||||||
const EVENT_TYPE_MOUSE_RELEASE: 0x00000001
|
const EVENT_TYPE_MOUSE_RELEASE: 0x00000001
|
||||||
|
|
6
main.asm
6
main.asm
|
@ -112,6 +112,7 @@ get_rom_version:
|
||||||
ret
|
ret
|
||||||
|
|
||||||
; code
|
; code
|
||||||
|
#include "audio.asm"
|
||||||
#include "background.asm"
|
#include "background.asm"
|
||||||
#include "boot.asm"
|
#include "boot.asm"
|
||||||
#include "cursor.asm"
|
#include "cursor.asm"
|
||||||
|
@ -218,6 +219,11 @@ get_rom_version:
|
||||||
org.pad 0xF0047000
|
org.pad 0xF0047000
|
||||||
data.32 string_to_int
|
data.32 string_to_int
|
||||||
|
|
||||||
|
; audio jump table
|
||||||
|
org.pad 0xF0048000
|
||||||
|
data.32 play_audio
|
||||||
|
data.32 stop_audio
|
||||||
|
|
||||||
org.pad 0xF004F000
|
org.pad 0xF004F000
|
||||||
standard_font_width:
|
standard_font_width:
|
||||||
data.16 8
|
data.16 8
|
||||||
|
|
Loading…
Reference in New Issue
Block a user