mirror of
https://github.com/arabine/open-story-teller.git
synced 2025-12-06 17:09:06 +01:00
Working media loop + fix call VM
This commit is contained in:
parent
bde25fd004
commit
7df8e38b2c
4 changed files with 24 additions and 30 deletions
|
|
@ -189,8 +189,10 @@ chip32_result_t chip32_step(chip32_ctx_t *ctx)
|
||||||
}
|
}
|
||||||
case OP_CALL:
|
case OP_CALL:
|
||||||
{
|
{
|
||||||
ctx->registers[RA] = ctx->registers[PC] + 3; // set return address to next instruction after CALL
|
ctx->registers[RA] = ctx->registers[PC] + 2; // set return address to next instruction after CALL
|
||||||
ctx->registers[PC] = _NEXT_SHORT - 1;
|
const uint8_t reg = _NEXT_BYTE;
|
||||||
|
_CHECK_REGISTER_VALID(reg)
|
||||||
|
ctx->registers[PC] = ctx->registers[reg] - 1;
|
||||||
// save all temporary registers on stack
|
// save all temporary registers on stack
|
||||||
ctx->registers[SP] -= 4*10; // reserve memory
|
ctx->registers[SP] -= 4*10; // reserve memory
|
||||||
// fill memory
|
// fill memory
|
||||||
|
|
|
||||||
|
|
@ -152,7 +152,7 @@ typedef struct {
|
||||||
{ OP_MOV, 2, 2 }, { OP_PUSH, 1, 1 }, {OP_POP, 1, 1 }, \
|
{ OP_MOV, 2, 2 }, { OP_PUSH, 1, 1 }, {OP_POP, 1, 1 }, \
|
||||||
{ OP_STORE, 3, 4 }, { OP_LOAD, 3, 4 }, { OP_ADD, 2, 2 }, { OP_SUB, 2, 2 }, { OP_MUL, 2, 2 }, \
|
{ OP_STORE, 3, 4 }, { OP_LOAD, 3, 4 }, { OP_ADD, 2, 2 }, { OP_SUB, 2, 2 }, { OP_MUL, 2, 2 }, \
|
||||||
{ OP_DIV, 2, 2 }, { OP_SHL, 2, 2 }, { OP_SHR, 2, 2 }, { OP_ISHR, 2, 2 }, { OP_AND, 2, 2 }, \
|
{ OP_DIV, 2, 2 }, { OP_SHL, 2, 2 }, { OP_SHR, 2, 2 }, { OP_ISHR, 2, 2 }, { OP_AND, 2, 2 }, \
|
||||||
{ OP_OR, 2, 2 }, { OP_XOR, 2, 2 }, { OP_NOT, 1, 1 }, { OP_CALL, 1, 2 }, { OP_RET, 0, 0 }, \
|
{ OP_OR, 2, 2 }, { OP_XOR, 2, 2 }, { OP_NOT, 1, 1 }, { OP_CALL, 1, 1 }, { OP_RET, 0, 0 }, \
|
||||||
{ OP_JUMP, 1, 2 }, { OP_SKIPZ, 1, 1 }, { OP_SKIPNZ, 1, 1 } }
|
{ OP_JUMP, 1, 2 }, { OP_SKIPZ, 1, 1 }, { OP_SKIPNZ, 1, 1 } }
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
|
|
||||||
|
|
@ -368,7 +368,8 @@ void MainWindow::buildScript()
|
||||||
|
|
||||||
// Update ROM memory
|
// Update ROM memory
|
||||||
std::copy(m_program.begin(), m_program.end(), m_rom_data);
|
std::copy(m_program.begin(), m_program.end(), m_rom_data);
|
||||||
m_ramView->SetMemory(m_rom_data, m_program.size());
|
m_ramView->SetMemory(m_ram_data, sizeof(m_ram_data));
|
||||||
|
m_romView->SetMemory(m_rom_data, m_program.size());
|
||||||
chip32_initialize(&m_chip32_ctx);
|
chip32_initialize(&m_chip32_ctx);
|
||||||
m_dbg.run_result = VM_OK;
|
m_dbg.run_result = VM_OK;
|
||||||
updateAll();
|
updateAll();
|
||||||
|
|
|
||||||
|
|
@ -11,8 +11,8 @@ $yaya DC8, "yaya.bmp"
|
||||||
$rabbit DC8, "rabbit.bmp"
|
$rabbit DC8, "rabbit.bmp"
|
||||||
$someConstant DC32, 12456789
|
$someConstant DC32, 12456789
|
||||||
|
|
||||||
; Liste des labels
|
; Liste des noeuds à appeler
|
||||||
$ChoiceObject DC32, .MEDIA_02, .MEDIA_03
|
$ChoiceObject DC32, 2, .MEDIA_02, .MEDIA_03
|
||||||
|
|
||||||
; DVsxx to declare a variable in RAM, followed by the number of elements
|
; DVsxx to declare a variable in RAM, followed by the number of elements
|
||||||
$MyArray DV8, 10 ; array of 10 bytes
|
$MyArray DV8, 10 ; array of 10 bytes
|
||||||
|
|
@ -27,48 +27,39 @@ $ChoiceMem DV32, 10 ; 10 elements for the choices, to be generated
|
||||||
lcons r0, $imageBird ; image name address in ROM located in R0 (null terminated)
|
lcons r0, $imageBird ; image name address in ROM located in R0 (null terminated)
|
||||||
lcons r1, $soundChoice ; set to 0 if no sound
|
lcons r1, $soundChoice ; set to 0 if no sound
|
||||||
syscall 1
|
syscall 1
|
||||||
|
lcons r0, $ChoiceObject
|
||||||
; We put all the choices in reserved global memory
|
|
||||||
lcons t2, 4 ; address increment
|
|
||||||
lcons t0, $ChoiceMem
|
|
||||||
lcons t1, .MEDIA_02
|
|
||||||
store @t0, t1, 4 ; @t0 = t1
|
|
||||||
|
|
||||||
lcons r0, .MEDIA_03
|
|
||||||
push r0
|
|
||||||
lcons r2, 2 ; 3 iterations
|
|
||||||
jump .media ; no return possible, so a jump is enough
|
jump .media ; no return possible, so a jump is enough
|
||||||
|
|
||||||
; Generic media choice manager
|
; Generic media choice manager
|
||||||
.media:
|
.media:
|
||||||
; Les adresses des différents medias sont dans la stack
|
; Les adresses des différents medias sont dans la stack
|
||||||
; Arguments:
|
; Arguments:
|
||||||
; r1: address of the first media address
|
; r0: address d'une structure de type "media choice"
|
||||||
; r2: nombre d'itérations
|
|
||||||
|
|
||||||
; Local:
|
; Local:
|
||||||
; t0: loop counter
|
; t0: loop counter
|
||||||
; t1: increment 1
|
; t1: increment 1
|
||||||
; t2: increment 4
|
; t2: increment 4
|
||||||
; t4: current media address
|
; t3: current media address
|
||||||
|
|
||||||
.media_loop_start:
|
.media_loop_start:
|
||||||
mov t0, r2 ; i = 3
|
load t0, @r0, 4 ; Le premier élément est le nombre de choix possibles, t0 = 3 (exemple)
|
||||||
lcons t1, 1
|
lcons t1, 1
|
||||||
lcons t2, 4
|
lcons t2, 4
|
||||||
mov t4, r1 ; copy address, r4 will be modified
|
mov t3, r0
|
||||||
.media_loop:
|
.media_loop:
|
||||||
sub t0, t1 ; i--
|
add t3, t2 ; @++
|
||||||
add t4, t3 ; @++
|
|
||||||
skipnz t0 ; if (r0) goto start_loop;
|
|
||||||
jump .media_loop_start
|
|
||||||
load r0, @t4, 4 ; r0 = content in ram at address in T4
|
|
||||||
call r0
|
|
||||||
|
|
||||||
|
|
||||||
|
; ------- On appelle un autre media node
|
||||||
|
push r0 ; save r0
|
||||||
|
load r0, @t3, 4 ; r0 = content in ram at address in T4
|
||||||
|
call r0
|
||||||
|
pop r0
|
||||||
; TODO: wait for event
|
; TODO: wait for event
|
||||||
|
|
||||||
; TODO: if ok event, free stack, then
|
sub t0, t1 ; i--
|
||||||
|
skipnz t0 ; if (r0) goto start_loop;
|
||||||
|
jump .media_loop_start
|
||||||
jump .media_loop
|
jump .media_loop
|
||||||
|
|
||||||
.MEDIA_02:
|
.MEDIA_02:
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue