Skip to content

Commit

Permalink
Fix timer0 infinite loop bug (#123)
Browse files Browse the repository at this point in the history
  • Loading branch information
tiberiusbrown authored Jan 5, 2025
1 parent d4cb70b commit 1e32313
Show file tree
Hide file tree
Showing 8 changed files with 1,195 additions and 896 deletions.
2 changes: 1 addition & 1 deletion bench/cycles/cycles.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ int main(int argc, char** argv)
else
{
prev_cycle = arduboy.cpu.cycle_count - prev_cycle - 1;
printf("%" PRIu64 "\n", prev_cycle);
printf(" %" PRIu64 " |", prev_cycle);
prev_cycle = 0;
}
}
Expand Down
62 changes: 27 additions & 35 deletions bench/cycles/sprites_cycles/SpritesABC.cpp
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
#include "SpritesABC.hpp"

[[ gnu::naked, gnu::noinline ]]
static void SpritesABC::draw(
static void SpritesABC::drawFX(
int16_t x, int16_t y,
uint24_t image, uint8_t mode, uint16_t frame)
{
Expand Down Expand Up @@ -73,71 +73,63 @@ static void SpritesABC::draw(
, [spsr] "I" (_SFR_IO_ADDR(SPSR))
, [sreg] "I" (_SFR_IO_ADDR(SREG))
, [page] "i" (&FX::programDataPage)
, [drawf] "" (SpritesABC::drawSized)
, [drawf] "" (SpritesABC::drawSizedFX)
);
}

[[ gnu::naked, gnu::noinline ]]
static void SpritesABC::drawSized(
static void SpritesABC::drawSizedFX(
int16_t x, int16_t y, uint8_t w, uint8_t h,
uint24_t image, uint8_t mode, uint16_t frame)
{
asm volatile(R"ASM(
SpritesABC_drawSized:
push r4
push r5
push r6
push r14
push r15
push r16
; w * (h >> 3)
; w * (h >> 3) * (plusmask ? 2 : 1)
mov r0, r18
lsr r0
lsr r0
lsr r0
sbrc r12, 0
lsl r0
mul r0, r20
movw r30, r0
; t = frame * w * (h >> 3)
; image += frame * w * (h >> 3)
mul r30, r10
movw r4, r0
add r14, r0
adc r15, r1
mul r31, r10
add r5, r0
adc r6, r1
mul r30, r15
add r5, r0
adc r6, r1
mul r31, r15
add r6, r0
add r15, r0
adc r16, r1
mul r30, r11
add r15, r0
adc r16, r1
mul r31, r11
add r16, r0
clr r1
1:
; image += t
add r14, r4
adc r15, r5
adc r16, r6
; if(mode & MODE_PLUSMASK) image += t
sbrs r12, 0
rjmp 1f
add r14, r4
adc r15, r5
adc r16, r6
1:
pop r6
pop r5
pop r4
call %x[drawf]
jmp %x[drawf]
pop r16
pop r15
pop r14
)ASM"
:
: [drawf] "" (SpritesABC::drawBasic)
: [drawf] "" (SpritesABC::drawBasicFX)
);
}

[[ gnu::naked, gnu::noinline ]]
void SpritesABC::drawBasic(
void SpritesABC::drawBasicFX(
int16_t x, int16_t y, uint8_t w, uint8_t h,
uint24_t image, uint8_t mode)
{
Expand Down
6 changes: 3 additions & 3 deletions bench/cycles/sprites_cycles/SpritesABC.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,15 +16,15 @@ struct SpritesABC
static constexpr uint8_t MODE_SELFMASK = 4;
static constexpr uint8_t MODE_SELFMASK_ERASE = 6; // like selfmask but erases pixels

static void drawBasic(
static void drawBasicFX(
int16_t x, int16_t y, uint8_t w, uint8_t h,
uint24_t image, uint8_t mode);

static void drawSized(
static void drawSizedFX(
int16_t x, int16_t y, uint8_t w, uint8_t h,
uint24_t image, uint8_t mode, uint16_t frame);

static void draw(
static void drawFX(
int16_t x, int16_t y,
uint24_t image, uint8_t mode, uint16_t frame);
};
16 changes: 0 additions & 16 deletions bench/cycles/sprites_cycles/img_Sprites.hpp

This file was deleted.

58 changes: 57 additions & 1 deletion bench/cycles/sprites_cycles/img_SpritesU.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,63 @@

constexpr uint8_t IMG_SPRITESU[] PROGMEM =
{
16, 16,
2, 8, 8, 8, 16, 16, 32, 32, 64, 64, 128, 64,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
255, 63, 207, 247, 251, 251, 253, 253, 253, 252, 251, 251, 247, 207, 15, 191,
255, 255, 255, 255, 255, 255, 255, 255, 255, 63, 207, 247, 251, 251, 253, 253,
Expand Down
Loading

0 comments on commit 1e32313

Please sign in to comment.