open-story-teller/story-editor/scripts/media.chip32

74 lines
2.4 KiB
Text

; Generic media choice manager
.media:
; Les adresses des différents medias sont dans la stack
; Arguments:
; r0: address d'une structure de type "media choice"
; Local:
; t0: current media address
; t1: increment 4
; t3: address of the first element in the choice array
; t4: address of the last element in the choice array
; t5: where to jump when OK button is pressed
mov t3, r0 ; copie de R0 pour travailler dessus
mov t2, r0 ; sauvegarde de R0
load r0, @t3, 4 ; Le premier élément est le nombre de choix possibles, ex: r0 = 12
lcons t1, 4
mul r0, t1 ; on calcule l'offset: r0 = nb_elements * 4 = 48
mov t4, t3 ; t4 = t3
add t4, r0 ; t4 pointe maintenant sur le dernier élément de la structure
add t3, t1 ; t3 pointe maintenant sur le premier élément
mov t0, t3 ; on commence sur le premier élément
.media_loop:
; --------- We call a media transition node
load r0, @t0, 4 ; Get the address located at memory T0
call r0 ; call subroutine
; Return argument in R0: the address of the node to call whe OK is pressed
mov t5, r0 ; save it
; wait for event
lcons r0, 0b111 ; mask for OK, previous and next buttons
syscall 2
; Event is stored in R0
; ----- Test if event is OK button
lcons r1, 1 ; mask for OK button
and r1, r0 ; r1 = r1 AND r0
skipz r1 ; not OK, skip jump
jump .media_wait_event
; test previous event
lcons r1, 2 ; mask for previous button
and r1, r0 ; r1 = r1 AND r0
skipz r1 ; not OK, skip jump
jump .media_previous
; 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
jump .media_set_first
add t0, t1 ; t0 += 4
jump .media_loop
.media_set_first: ; on reboucle sur le premier élément de la structure
mov t0, t3
jump .media_loop
.media_previous:
eq r0, t0, t3 ; on teste si on est au premier élément
skipz r0 ; zéro, on peut décrémenter l'adresse
jump .media_set_last
sub t0, t1 ; t0 += 4
jump .media_loop
.media_set_last: ; on reboucle sur le dernier élément de la structure
mov t0, t4
jump .media_loop
.media_wait_event:
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