Page 1 of 1
Controller Recording
Posted: Wed Oct 10, 2012 11:16 am
by neilbaldwin
Has anyone implemented a controller record-and-playback routine? What approach did you take? Sampled at 60FPS that would take a lot of data. My idea was to have an algorithm that consisted of (16-bit) delta times between different states of the controller. I suppose another way would be to RLE the pad sampling.
Any ideas most welcome

Re: Controller Recording
Posted: Wed Oct 10, 2012 11:34 am
by Dwedit
There is a joypad simulator system for the NES called Nesbot, it is used to verify that Tool Assisted Speedruns work correctly on the console. I bet the same guy also did joypad input recording and playback too.
As for doing it from within a NES program (to create a demo), RLE should be really easy to implement. A simple series of byte-length values would do the trick.
Re: Controller Recording
Posted: Wed Oct 10, 2012 11:39 am
by rainwarrior
I think RLE is fine. Maybe a stream of byte pairs, first the 1 byte controller data, then 1 byte saying how many frames until the next change (if change is >255 frames off, just duplicate, it's only 2 bytes every 4 seconds). That's should be compact enough for most purposes.
Here's a snippet from doppelganger's Super Mario Bros. disassembly:
Code: Select all
DemoActionData:
.db $01, $80, $02, $81, $41, $80, $01
.db $42, $c2, $02, $80, $41, $c1, $41, $c1
.db $01, $c1, $01, $02, $80, $00
DemoTimingData:
.db $9b, $10, $18, $05, $2c, $20, $24
.db $15, $5a, $10, $20, $28, $30, $20, $10
.db $80, $20, $30, $30, $01, $ff, $00
DemoEngine:
ldx DemoAction ;load current demo action
lda DemoActionTimer ;load current action timer
bne DoAction ;if timer still counting down, skip
inx
inc DemoAction ;if expired, increment action, X, and
sec ;set carry by default for demo over
lda DemoTimingData-1,x ;get next timer
sta DemoActionTimer ;store as current timer
beq DemoOver ;if timer already at zero, skip
DoAction: lda DemoActionData-1,x ;get and perform action (current or next)
sta SavedJoypad1Bits
dec DemoActionTimer ;decrement action timer
clc ;clear carry if demo still going
DemoOver: rts
Re: Controller Recording
Posted: Wed Oct 10, 2012 12:01 pm
by thefox
tokumaru posted his RLE encoder here:
viewtopic.php?p=92120#p92120
Re: Controller Recording
Posted: Wed Oct 10, 2012 5:01 pm
by cpow
neilbaldwin wrote:Has anyone implemented a controller record-and-playback routine? What approach did you take? Sampled at 60FPS that would take a lot of data. My idea was to have an algorithm that consisted of (16-bit) delta times between different states of the controller. I suppose another way would be to RLE the pad sampling.
Any ideas most welcome

I implemented controller record-and-playback in NESICIDE in the Test Suite Executive. But that is for implementing repeatable tests [or, conveniently, for running test ROMs with repeatable input patterns for me to use while emudevving].
That said, it'd be *cake* easy for me to add a feature to use the record portion as a funnel to generate an array of controller input data from a run of your program that could be compressed/compiled into your program. Sort of an "attract mode wizard".
In the early days of NESICIDE I actually had a controller input dialog that would allow you to adjust the recorded controller inputs on a widget that looked a lot like an 8-key player piano spool. Then it'd scroll and playback. I have yet to pull that over to the latest codebase.
Re: Controller Recording
Posted: Wed Oct 10, 2012 7:21 pm
by cpow
I made a
video showing the capabilities of what I was talking about in the previous post. I'm no video making expert so it's a RAR-compressed AVI.
Re: Controller Recording
Posted: Thu Oct 11, 2012 6:21 am
by tepples
cpow wrote:In the early days of NESICIDE I actually had a controller input dialog that would allow you to adjust the recorded controller inputs on a widget that looked a lot like an 8-key player piano spool. Then it'd scroll and playback.
The TAS crowd would
expletive love that.
Re: Controller Recording
Posted: Thu Oct 11, 2012 6:38 pm
by cpow
tepples wrote:cpow wrote:In the early days of NESICIDE I actually had a controller input dialog that would allow you to adjust the recorded controller inputs on a widget that looked a lot like an 8-key player piano spool. Then it'd scroll and playback.
The TAS crowd would
expletive love that.
I should
expletive get off my
expletive expletive and pull it into the Qt codebase. Yeah. I should.
