optimise ch32 code slightly

This commit is contained in:
Crispy 2025-06-19 00:16:24 +02:00
parent f1f20cb5e1
commit 382cd92629
2 changed files with 203 additions and 203 deletions

View file

@ -94,9 +94,9 @@ void fill_frame(u8 color) {
void set_pixel(u8 x, u8 y, u8 color) {
if (color)
frame[x] |= (1 << (y & 31));
frame[x] |= 1<<y;
else
frame[x] &= ~(1 << (y & 31));
frame[x] &= ~(1<<y);
}
void rle_horizontal();
@ -149,8 +149,8 @@ void rle_horizontal() {
u8 y = 0;
u8 color = 0;
while (y < HEIGHT) {
u8 run = next_byte();
for (int i = 0; i < run; i++) {
u32 run = next_byte();
while (run--) {
set_pixel(x, y, color);
x += 1;
if (x == WIDTH) {
@ -169,8 +169,8 @@ void rle_vertical() {
u8 y = 0;
u8 color = 0;
while (x < WIDTH) {
u8 run = next_byte();
for (int i = 0; i < run; i++) {
u32 run = next_byte();
while (run--) {
set_pixel(x, y, color);
y += 1;
if (y == HEIGHT) {
@ -206,7 +206,7 @@ void bg_strips_h() {
void cell_diff_8v() {
u32 bitmap = (next_byte() << 16) | (next_byte() << 8) | next_byte();
u8 run_remaining = next_byte();
u32 run = next_byte();
u8 color = 0;
for (u8 x = 0; x < WIDTH; x++) {
u8 cellx = x >> 3;
@ -214,16 +214,16 @@ void cell_diff_8v() {
u8 celly = y >> 3;
if (bitmap >> (cellx + (WIDTH / 8) * celly) & 1) {
// advance rle once
if (run_remaining == 0) {
run_remaining = next_byte();
color = 1 - color;
if (run_remaining == 0) {
run_remaining = next_byte();
color = 1 - color;
if (run == 0) {
run = next_byte();
color = !color;
if (run == 0) {
run = next_byte();
color = !color;
}
}
set_pixel(x, y, color);
run_remaining--;
run--;
}
}
}