Skip to content

Trigger a sound on Sord M5

Reuse a small real effect, understand who stops it, and compare its native output with an omitted-trigger control.

Give an accepted action a sound. The same caller changes its picture and triggers this effect; a second version performs the action with the trigger removed. Listen to both.

Working effect

Trigger omitted

Take the effect

The reusable effect

sound.inc
PSG equ $20
; Pulse on SN76489 tone0, eight serviced frames. Other channels are muted here.
trigger_sound:
    push af
    ld a,$80
    out (PSG),a
    ld a,$10
    out (PSG),a
    ld a,$90
    out (PSG),a
    ld a,8
    ld (SOUND_TICKS),a
    pop af
    ret
service_sound:
    ld a,(SOUND_TICKS)
    or a
    ret z
    dec a
    ld (SOUND_TICKS),a
    ret nz
    ld a,$9f
    out (PSG),a
    ret

SN76489 tone 0 at $20, duration $7005. Trigger preserves AF/B; service changes AF. The caller owns the VDP and starts through the monitor cartridge header.

Include sound.inc once with the caller’s constants and duration byte. Initialise the duration byte to zero before the first service call. Call trigger_sound for an accepted action, then call service_sound exactly once per accepted display update. The eighth service call mutes the effect. Because the supplied caller services in the triggering iteration too, this is a count of service calls, not eight complete elapsed frame intervals. Triggering again restarts the duration; there is no queue.

The complete initialiser also mutes other channels. To reuse just this effect beside music, agree channel ownership and remove unrelated global setup only after providing a replacement. Device latches, power, routing and master volume may affect more than one voice.

Change it and recognise a mistake

Change the divisor or attenuation. Keep SN76489 writes separate from VDP status reads at $11; both chips need ownership, for different reasons.

The omitted-trigger control still accepts the action but fails the same audio guard as the working caller. Keyboard clicks or other machine output are not enough: the BASIC checks compare against a separate rejected-command recording.

Deliberately omitted sound trigger

no-sound.asm
; Original capability caller: owns VDP, one audio channel and declared RAM.
VDP_DATA equ $10
VDP_CTRL equ $11
TURNS equ $7000
SOUND_TICKS equ $7005
; Sord M5 monitor-started homebrew cartridge. Space commits an untimed turn.
; Owns VDP/keyboard and $7000-$7003; stack below $7FF0; no monitor return.
    org $2000
    db 0
    dw start,init_return      ; monitor calls initialiser, then entry vector
    jp irq_return
    jp irq_return
start:
    di
    ld sp,$7ff0
    xor a
    ld ($7000),a
    ld ($7001),a
    ld ($7002),a
    ld ($7003),a
    in a,($11)
    xor a
    out ($11),a
    ld a,$80
    out ($11),a               ; R0 legacy graphics
    xor a
    out ($11),a
    ld a,$81
    out ($11),a               ; R1 display and VDP IRQ disabled
    call init_picture
main:
    call wait_frame
    ld hl,($7002)
    inc hl
    ld ($7002),hl
    include "../sample.inc"
    ld a,($7001)
    cpl
    and b
    jr z,no_action
    ld a,($7000)
    inc a
    ld ($7000),a
    nop
    nop
    nop
no_action:
    ld a,b
    ld ($7001),a
    call draw_picture
    call service_sound
    jp main
wait_frame:
    in a,($11)
wait_new:
    in a,($11)
    and $80
    jr z,wait_new
    ret
init_return:
irq_return:
    ret
    include "../picture.inc"
    include "../sound.inc"
    defs $6000-$,0

The working implementation above repairs that omission. If an effect instead drones on, check the mute/service path and that its state is initialised. Servicing twice makes a counted effect shorter; servicing only after input can leave it running while the player waits. Those are lifecycle decisions to test when adapting it.

Run the caller

Build the complete caller with make -C sord-m5/patterns/assembly/input/read-action. Press Space once, keep it held, then release and press again. The piece moves on each new press and returns to its starting position after two; holding does not repeat the action. Load the cartridge produced by the Makefile in the named configuration; retain its reset/header setup.

Sord M5 native caller after accepted input.
Captured from the running caller in the configuration below.

Where setup, trigger and service belong

demo.asm
; Original capability caller: owns VDP, one audio channel and declared RAM.
VDP_DATA equ $10
VDP_CTRL equ $11
TURNS equ $7000
SOUND_TICKS equ $7005
; Sord M5 monitor-started homebrew cartridge. Space commits an untimed turn.
; Owns VDP/keyboard and $7000-$7003; stack below $7FF0; no monitor return.
    org $2000
    db 0
    dw start,init_return      ; monitor calls initialiser, then entry vector
    jp irq_return
    jp irq_return
start:
    di
    ld sp,$7ff0
    xor a
    ld ($7000),a
    ld ($7001),a
    ld ($7002),a
    ld ($7003),a
    in a,($11)
    xor a
    out ($11),a
    ld a,$80
    out ($11),a               ; R0 legacy graphics
    xor a
    out ($11),a
    ld a,$81
    out ($11),a               ; R1 display and VDP IRQ disabled
    call init_picture
main:
    call wait_frame
    ld hl,($7002)
    inc hl
    ld ($7002),hl
    include "sample.inc"
    ld a,($7001)
    cpl
    and b
    jr z,no_action
    ld a,($7000)
    inc a
    ld ($7000),a
    call trigger_sound
no_action:
    ld a,b
    ld ($7001),a
    call draw_picture
    call service_sound
    jp main
wait_frame:
    in a,($11)
wait_new:
    in a,($11)
    and $80
    jr z,wait_new
    ret
init_return:
irq_return:
    ret
    include "picture.inc"
    include "sound.inc"
    defs $6000-$,0

Compare blocking, serviced and queued sound when choosing the next step.

Verification and sources

Target: NTSC M5, monitor-started cartridge. These callers were executed with released Emu198x 0.44.1; assembly uses Asm198x 0.0.71. The sample folder contains reproduction instructions and retained observations. The independent checker binds source, native captures and actual output; its rejection tests exercise wrong state, missing files and false audio claims.

This qualifies the named emulator/firmware path. Pitch accuracy, original hardware and other peripherals require their own observations.

Sord BASIC-G Appendix H: I/O map; Sord M5C-01 schematic: decoding; TI SN76489A and TMS9918A data manuals. The specific Space polarity is configuration-specific executed evidence.