Browse Source

Fix indexing mistakes, add 'X'

master
cancel 6 years ago
parent
commit
903f9b50e3
  1. 10
      bank.c
  2. 37
      sim.c

10
bank.c

@ -10,7 +10,7 @@ Usz bank_entry_padding(Usz glyph_count) {
} }
ORCA_FORCE_STATIC_INLINE ORCA_FORCE_STATIC_INLINE
Usz bank_entry_size(Usz glyph_count) { Usz bank_entry_size(Usz glyph_count) {
return ORCA_BANK_ENTRY_HEADER + bank_entry_padding(glyph_count); return ORCA_BANK_ENTRY_HEADER + glyph_count + bank_entry_padding(glyph_count);
} }
void bank_init(Bank* bank) { void bank_init(Bank* bank) {
@ -43,7 +43,7 @@ Usz bank_append(Bank* restrict bank, Usz cur_size, Usz index,
Usz new_size = cur_size + bank_entry_size(glyph_count); Usz new_size = cur_size + bank_entry_size(glyph_count);
if (new_size > bank->capacity) if (new_size > bank->capacity)
bank_enlarge_to(bank, new_size); bank_enlarge_to(bank, new_size);
char* data = bank->data; char* data = bank->data + cur_size;
Bank_entry* entry = Bank_entry* entry =
(Bank_entry*)ORCA_ASSUME_ALIGNED(data, ORCA_BANK_ENTRY_ALIGN); (Bank_entry*)ORCA_ASSUME_ALIGNED(data, ORCA_BANK_ENTRY_ALIGN);
entry->index = (U32)index; entry->index = (U32)index;
@ -77,14 +77,16 @@ next:
goto fail; goto fail;
entry_size = entry->size; entry_size = entry->size;
if (entry_index < index) { if (entry_index < index) {
offset += ORCA_BANK_ENTRY_HEADER + entry_size; offset +=
ORCA_BANK_ENTRY_HEADER + entry_size + bank_entry_padding(entry_size);
goto next; goto next;
} }
num_to_copy = dest_count < entry_size ? dest_count : entry_size; num_to_copy = dest_count < entry_size ? dest_count : entry_size;
memcpy(dest, bank_data + offset + ORCA_BANK_ENTRY_HEADER, num_to_copy); memcpy(dest, bank_data + offset + ORCA_BANK_ENTRY_HEADER, num_to_copy);
if (num_to_copy < dest_count) if (num_to_copy < dest_count)
memset(dest, '.', dest_count - num_to_copy); memset(dest, '.', dest_count - num_to_copy);
*cursor = ORCA_BANK_ENTRY_HEADER + entry_size; *cursor = offset + ORCA_BANK_ENTRY_HEADER + entry_size +
bank_entry_padding(entry_size);
return num_to_copy; return num_to_copy;
fail: fail:

37
sim.c

@ -268,7 +268,8 @@ Usz UCLAMP(Usz val, Usz min, Usz max) {
_('I', 'i', increment) \ _('I', 'i', increment) \
_('J', 'j', jump) \ _('J', 'j', jump) \
_('M', 'm', modulo) \ _('M', 'm', modulo) \
_('O', 'o', offset) _('O', 'o', offset) \
_('X', 'x', teleport)
ORCA_DECLARE_OPERATORS(ORCA_SOLO_OPERATORS, ORCA_DUAL_OPERATORS) ORCA_DECLARE_OPERATORS(ORCA_SOLO_OPERATORS, ORCA_DUAL_OPERATORS)
@ -381,7 +382,7 @@ BEGIN_DUAL_PHASE_0(offset)
coords[1] = PEEK(0, -2); coords[1] = PEEK(0, -2);
STORE(coords); STORE(coords);
read_y = UCLAMP(INDEX(coords[0]), 0, 16); read_y = UCLAMP(INDEX(coords[0]), 0, 16);
read_x = UCLAMP(INDEX(coords[0]) + 1, 1, 16); read_x = UCLAMP(INDEX(coords[1]) + 1, 1, 16);
} }
BEGIN_DUAL_PORTS BEGIN_DUAL_PORTS
I_PORT(0, -1, LOCKING | HASTE); I_PORT(0, -1, LOCKING | HASTE);
@ -404,6 +405,38 @@ BEGIN_DUAL_PHASE_1(offset)
STUN(0, 1); STUN(0, 1);
END_PHASE END_PHASE
BEGIN_DUAL_PHASE_0(teleport)
REALIZE_DUAL;
Usz write_y = 0;
Usz write_x = 1;
if (DUAL_IS_ACTIVE) {
Glyph coords[2];
coords[0] = PEEK(0, -1);
coords[1] = PEEK(0, -2);
STORE(coords);
write_y = UCLAMP(INDEX(coords[0]), 0, 16);
write_x = UCLAMP(INDEX(coords[1]), 1, 16);
}
BEGIN_DUAL_PORTS
I_PORT(0, -1, LOCKING | HASTE);
I_PORT(0, -2, LOCKING | HASTE);
I_PORT(1, 0, LOCKING);
O_PORT((Isz)write_y, (Isz)write_x, NONLOCKING);
END_PORTS
END_PHASE
BEGIN_DUAL_PHASE_1(teleport)
STOP_IF_NOT_BANGED;
Isz write_y = 0;
Isz write_x = 1;
Glyph coords[2];
if (LOAD(coords)) {
write_y = (Isz)UCLAMP(INDEX(coords[0]), 0, 16);
write_x = (Isz)UCLAMP(INDEX(coords[1]), 1, 16);
}
POKE(write_y, write_x, PEEK(0, 1));
STUN(write_y, write_x);
END_PHASE
//////// Run simulation //////// Run simulation
#define SIM_EXPAND_SOLO_PHASE_0(_oper_char, _oper_name) \ #define SIM_EXPAND_SOLO_PHASE_0(_oper_char, _oper_name) \

Loading…
Cancel
Save