I was trying to come up with a way of doing interrupt driven beeper sound effects using a fixed number of t-states. I failed, but I did come up with a short routine which could be useful for adding sound effects to BASIC programs.
Código: Seleccionar todo
; simpleFX by Andrew Owen
; totally relocatable without recompiling
ld hl, 300 ; duration (0-14445)
ld a, (23624) ; border colour
and %00111000 ; mask
rrca ; rotate
rrca ; right
rrca ; three
ld c, a ; store it in C
loop:
ld a, (hl) ; get byte from ROM
and %00010000 ; throw everything away except the MIC bit
or c ; add the border colour
out (0xfe), a ; write it
ld b, l ; b, 0-255 for pitch or l/h for envelope
inner:
djnz inner ; timing loop
dec hl ; decrease pointer to ROM
ld a, h ; test
or l ; for zero
ret z ; return if done
jr loop ; else loop
And here's a BASIC version with the code stored just below the UDGs:
Código: Seleccionar todo
10 CLEAR 65340
20 RESTORE 100
30 FOR m=65341 TO 65367
40 READ d
50 POKE m,d
60 NEXT m
70 RANDOMIZE USR 65341
80 STOP
100 DATA 33,44,1,58,72,92,230
110 DATA 56,15,15,15,79,126,230
120 DATA 16,177,211,254,69,16
130 DATA 254,43,124,181,200,24
140 DATA 241