mirror of
https://github.com/arabine/open-story-teller.git
synced 2025-12-06 17:09:06 +01:00
Add syscall 3, home button exit VM on choice media
This commit is contained in:
parent
86ab93211e
commit
cd26f407fc
5 changed files with 62 additions and 4 deletions
|
|
@ -95,9 +95,28 @@ This system call is used to wait for machine events. Use R0 to mask events to wa
|
|||
Example:
|
||||
|
||||
```
|
||||
mov r0,
|
||||
mov r0, 0b1000
|
||||
syscall 2
|
||||
```
|
||||
|
||||
## SYSCALL 3 (Send signal)
|
||||
|
||||
Send a specific signal event to the machine.
|
||||
Use R0 register to pass the signal argument.
|
||||
|
||||
```
|
||||
mov r0, 42
|
||||
syscall 3
|
||||
```
|
||||
|
||||
Supported signals:
|
||||
|
||||
| Signal | Number |
|
||||
|------- |-------- |
|
||||
| reserved | 0 |
|
||||
| Quit story | 1 |
|
||||
|
||||
|
||||
# Assembler
|
||||
|
||||
Basic grammar
|
||||
|
|
|
|||
|
|
@ -29,7 +29,7 @@
|
|||
mov t5, r0 ; save it
|
||||
|
||||
; wait for event
|
||||
lcons r0, 0b111 ; mask for OK, previous and next buttons
|
||||
lcons r0, 0b100111 ; mask for OK, previous and next buttons, home button
|
||||
syscall 2
|
||||
; Event is stored in R0
|
||||
|
||||
|
|
@ -45,6 +45,11 @@
|
|||
skipz r1 ; not OK, skip jump
|
||||
jump .media_previous
|
||||
|
||||
lcons r1, 0b100000 ; mask for home button
|
||||
and r1, r0 ; r1 = r1 AND r0
|
||||
skipz r1 ; not Home, skip jump
|
||||
jump .media_exit
|
||||
|
||||
; all other events mean: next node
|
||||
eq r0, t0, t4 ; t4 est le dernier élément
|
||||
skipz r0 ; zéro, on peut incrémenter l'adresse
|
||||
|
|
@ -71,4 +76,9 @@
|
|||
call t5 ; jump to the node
|
||||
lcons r0, 0b10000100001 ; mask for end of audio, Ok, and home buttons
|
||||
syscall 2 ; wait for event (OK, home or end of audio), return to choice loop
|
||||
jump .media_loop
|
||||
jump .media_loop
|
||||
|
||||
.media_exit:
|
||||
lcons r0, 1 ; Home button pressed, send signal to exit story
|
||||
syscall 3 ; exit story, we should never return from this call
|
||||
halt ; just in case
|
||||
|
|
|
|||
|
|
@ -22,6 +22,12 @@ class MediaEvent {
|
|||
MediaEvent(this.image, this.sound);
|
||||
}
|
||||
|
||||
class SignalEvent {
|
||||
int signal;
|
||||
|
||||
SignalEvent(this.signal);
|
||||
}
|
||||
|
||||
Completer<bool> periodic(Duration interval, Function(int cycle) callback) {
|
||||
final done = Completer<bool>();
|
||||
() async {
|
||||
|
|
@ -96,8 +102,10 @@ class StoryVm {
|
|||
|
||||
if (i == 0) {
|
||||
eventBus.fire(MediaEvent(file, ""));
|
||||
} else {
|
||||
} else if (i == 1) {
|
||||
eventBus.fire(MediaEvent("", file));
|
||||
} else if (i == 2) {
|
||||
eventBus.fire(SignalEvent(1));
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -160,6 +160,14 @@ class _MyHomePageState extends State<MyHomePage> {
|
|||
}
|
||||
});
|
||||
|
||||
eventBus.on<SignalEvent>().listen((event) {
|
||||
if (event.signal == 1) {
|
||||
state = PlayerState.indexFile;
|
||||
showCurrentStoryIndex();
|
||||
}
|
||||
});
|
||||
|
||||
|
||||
audioPlayerSub = player.onPlayerComplete.listen((event) {
|
||||
if (state == PlayerState.inStory) {
|
||||
// Send end of music event
|
||||
|
|
|
|||
|
|
@ -118,6 +118,19 @@ uint8_t story_player_syscall(chip32_ctx_t *ctx, uint8_t code)
|
|||
event_mask = ctx->registers[R0];
|
||||
retCode = SYSCALL_RET_WAIT_EV; // set the VM in pause
|
||||
}
|
||||
else if (code == 3) // Signal
|
||||
{
|
||||
if (ctx->registers[R0] == 1)
|
||||
{
|
||||
// EXIT
|
||||
std::cout << "[STORYVM] Syscall 3 (exit)" << std::endl;
|
||||
if (gMediaCallback)
|
||||
{
|
||||
std::cout << "[STORYVM] Execute callback (sound)" << std::endl;
|
||||
gMediaCallback(2, "");
|
||||
}
|
||||
}
|
||||
}
|
||||
return retCode;
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Reference in a new issue