Instead of registering an on_unmask listener every time we want a
transfer, and unregistering the listener every time we're done with it,
SB16 now registers a handler during init, and keeps this handler
registered throughout the session. The handler function is moved to SB16's
prototype.
The dma_waiting_transfer flag indicates whether the handler should
actually carry out the transfer.
- Constant variable names to uppercase.
- Consistent use of spacing and semicolons.
- Avoid recursion.
- Prefer bitwise operators.
- Place operators before line continuation (to disambiguate problems
associated with automatic semicolon insertion).
Previously, the channel_count and channel_addr registers were
incremented/decremented using read_count. However, read_bytes can be
reassigned (from the original bytes assosiated with channel_count) to
len. When do_write is performed with len less than available data,
read_bytes is reduced to len, but read_count is still referring to the
entire data, making subsequent writes restarting at the initial address.
Everything that is valid json plus arraybuffers and arraybuffer-views
can be restored automatically (without making changes to other code).
Properties that should not be part of the state buffer needed to be
annotated using a magic `_state_skip` property. Shared arraybuffer views
are broken during restoration and also need to be annotated. Adapters
are not (and should never be) saved.
Current limitations:
- Before restoring, the cpu needs to be initialised with the original
settings. This is not a hard requirement and can be fixed later.
- Pending asynchronous operations are lost. It's a good idea to pause
the cpu before saving the state.