Log In  
Follow
eruonna
[ :: Read More :: ]

Cart #13375 | 2015-08-31 | Code ▽ | Embed ▽ | No License
11

Working on a pool game. Also includes Loop.

Added zoomed out mode to pool. Press button 2 to toggle zoom. Also added a check so that any ball that makes it outside the bounds of the table is considered to have gone in a pocket (because I think the most likely way to achieve that is by bouncing through a pocket in some strange way).

Cart #13350 | 2015-08-30 | Code ▽ | Embed ▽ | No License
11

P#13351 2015-08-30 19:59 ( Edited 2015-11-20 18:09)

[ :: Read More :: ]

I didn't see this documented anywhere, and I had to work it out for my drumbeat cart, so I thought I'd save everyone else the trouble and publish what I know.

SFX:

A sound effect is stored in 68 bytes. Sfx 0 starts at address 0x3200, sfx 1 at address 0x3244, and so on.

The first 64 bytes (offset 0..63) store the 32 notes of the sound effect as described below.

Offset 64 is a byte that determines the editor mode: 0 for graph mode, nonzero for tracker mode. This has no effect on playback, just on the mode opened in the editor by default.

Offset 65 stores the playback speed. (Higher values correspond to slower playback, so "speed" isn't exactly the right name, but that is what is used in the editor.)

Offsets 66 and 67 store the loop begin and loop end times. A sound effect contains only 32 notes, but these times may be set to any byte value. All times past 32 simply play silence.

Note format:

A note is stored in 16 bits, two bytes little-endian.

Bits 0..5 store the pitch, ranging from 0 (C in octave 0) to 63 (D# in octave 5). The tracker mode editor can only enter pitches up to 60 (C 5), but it can display and play higher pitches.

Bits 6..8 store the instrument; the values are the same as in the tracker mode editor.

Bits 9..11 store the volume. Volume 0 corresponds to silence.

Bits 12..14 store the effect; the values are the same as in the tracker mode editor.

Bit 15 appears to be unused.

Example code:

-- This code is public domain, feel free to copy, use, and modify however you'd like

function make_note(pitch, instr, vol, effect)
  return { pitch + 64*(inst%4) , 16*effect + 2*vol + flr(instr/4) } -- flr may be redundant when this is poke'd into memory
end

function get_note(sfx, time)
  local addr = 0x3200 + 68*sfx + 2*time
  return { peek(addr) , peek(addr + 1) }
end

function set_note(sfx, time, note)
  local addr = 0x3200 + 68*sfx + 2*time
  poke(addr, note[1])
  poke(addr+1, note[2])
end

function get_speed(sfx)
  return peek(0x3200 + 68*sfx + 65)
end

function set_speed(sfx, speed)
  poke(0x3200 + 68*sfx + 65, speed)
end

function get_loop_start(sfx)
  return peek(0x3200 + 68*sfx + 66)
end

function get_loop_end(sfx)
  return peek(0x3200 + 68*sfx + 67)
end

function set_loop(sfx, start, end)
  local addr = 0x3200 + 68*sfx
  poke(addr + 66, start)
  poke(addr + 67, end)
end

Music format:

A music pattern consists of four channels, each of which may have a sound effect played on it, plus some playback control flags.

The patterns are stored in four bytes, with pattern 0 at address 0x3100. Each byte describes one channel.

Bits 0..5 are the sfx to be played on the channel.

Bit 6 is mute. If it is 0, the channel is played; if it is 1, the channel is silenced.

Bit 7 contains the playback control flags:
Byte 0 bit 7 is the loop start flag
Byte 1 bit 7 is the loop end flag
Byte 2 bit 7 is the stop flag
Byte 3 bit 7 is unused

Playback control is as follows (I haven't tested all possibilities here):
When a pattern reaches the end, if the stop flag is set on this pattern, playback stops.
Otherwise, if the loop end flag is set on this pattern, move back until a pattern with the loop start flag set is found, and continue playback from there.
Otherwise, continue playback with the next pattern.

P#13179 2015-08-26 18:29 ( Edited 2018-06-04 05:54)

[ :: Read More :: ]

Cart #12907 | 2015-08-23 | Code ▽ | Embed ▽ | No License
5

Generate some random drum beats. Press Z for a new one. They are saved as sfx 0 on the cart, in case you get one you want to use somewhere else. Based on ideas from this.

I hope to add more complex and longer beats.

Added a menu with some different generation algorithms. Mutating creates a beat that changes a little at regular intervals. Sometimes it uses some non-percussive sounds, which is a bug, but I have not been able to track down the cause.

Cart #12872 | 2015-08-22 | Code ▽ | Embed ▽ | No License
5

P#12873 2015-08-21 21:08 ( Edited 2016-10-16 10:00)

Follow Lexaloffle:          
Generated 2024-03-29 04:38:30 | 0.077s | Q:16