I'm somewhat new to the RP2040. I've been programming in C/C++ for a long while but not professionally.
A project I am working on involves drawing sprites on a VGA display. I have 12 sprites per scanline but I can't help but think the Pico can do more. I think I'm at the point where I need better tools to give me some tips. For example, how long certain commands are taking.
I also come from the old 6502 days where loop unrolling can drastically speed things up (at the cost of memory) but I'm not sure that applies with C and the RP2040/arm architecture.
I'm using CLion on Linux, BTW.
Do you have any recommendations on what I can use? Thanks!
BTW, for those curious, this is a particular method I am wanting to profile. For the record, it was MUCH slower before I "optimized" it this far. Image may be NSFW.
Clik here to view.
A project I am working on involves drawing sprites on a VGA display. I have 12 sprites per scanline but I can't help but think the Pico can do more. I think I'm at the point where I need better tools to give me some tips. For example, how long certain commands are taking.
I also come from the old 6502 days where loop unrolling can drastically speed things up (at the cost of memory) but I'm not sure that applies with C and the RP2040/arm architecture.
I'm using CLion on Linux, BTW.
Do you have any recommendations on what I can use? Thanks!
BTW, for those curious, this is a particular method I am wanting to profile. For the record, it was MUCH slower before I "optimized" it this far. Image may be NSFW.
Clik here to view.

Code:
void drawSprites(uint16_t screenWidth, uint16_t screenHeight, uint16_t raster_y, uint16_t pixels[screenWidth]) { if (raster_y < 0) return; if (raster_y >= screenHeight) return; for (int s = 0; s < NUMBER_OF_SPRITES; s++) { if (!sprites[s].visible) continue; if (raster_y >= sprites[s].y && raster_y < (sprites[s].y + sprites[s].height)) { int offset = (raster_y - sprites[s].y); uint32_t line = sprites[s].frame[offset]; uint8_t c0 = ((line & 0b11000000000000000000000000000000) >> 30); uint8_t c1 = ((line & 0b00110000000000000000000000000000) >> 28); uint8_t c2 = ((line & 0b00001100000000000000000000000000) >> 26); uint8_t c3 = ((line & 0b00000011000000000000000000000000) >> 24); uint8_t c4 = ((line & 0b00000000110000000000000000000000) >> 22); uint8_t c5 = ((line & 0b00000000001100000000000000000000) >> 20); uint8_t c6 = ((line & 0b00000000000011000000000000000000) >> 18); uint8_t c7 = ((line & 0b00000000000000110000000000000000) >> 16); uint8_t c8 = ((line & 0b00000000000000001100000000000000) >> 14); uint8_t c9 = ((line & 0b00000000000000000011000000000000) >> 12); uint8_t ca = ((line & 0b00000000000000000000110000000000) >> 10); uint8_t cb = ((line & 0b00000000000000000000001100000000) >> 8); uint8_t cc = ((line & 0b00000000000000000000000011000000) >> 6); uint8_t cd = ((line & 0b00000000000000000000000000110000) >> 4); uint8_t ce = ((line & 0b00000000000000000000000000001100) >> 2); uint8_t cf = ((line & 0b00000000000000000000000000000011)); if (c0) { pixels[sprites[s].x + 0] = sprite_palettes[sprites[s].palette].color[c0]; } if (c1) { pixels[sprites[s].x + 1] = sprite_palettes[sprites[s].palette].color[c1]; } if (c2) { pixels[sprites[s].x + 2] = sprite_palettes[sprites[s].palette].color[c2]; } if (c3) { pixels[sprites[s].x + 3] = sprite_palettes[sprites[s].palette].color[c3]; } if (c4) { pixels[sprites[s].x + 4] = sprite_palettes[sprites[s].palette].color[c4]; } if (c5) { pixels[sprites[s].x + 5] = sprite_palettes[sprites[s].palette].color[c5]; } if (c6) { pixels[sprites[s].x + 6] = sprite_palettes[sprites[s].palette].color[c6]; } if (c7) { pixels[sprites[s].x + 7] = sprite_palettes[sprites[s].palette].color[c7]; } if (c8) { pixels[sprites[s].x + 8] = sprite_palettes[sprites[s].palette].color[c8]; } if (c9) { pixels[sprites[s].x + 9] = sprite_palettes[sprites[s].palette].color[c9]; } if (ca) { pixels[sprites[s].x + 10] = sprite_palettes[sprites[s].palette].color[ca]; } if (cb) { pixels[sprites[s].x + 11] = sprite_palettes[sprites[s].palette].color[cb]; } if (cc) { pixels[sprites[s].x + 12] = sprite_palettes[sprites[s].palette].color[cc]; } if (cd) { pixels[sprites[s].x + 13] = sprite_palettes[sprites[s].palette].color[cd]; } if (ce) { pixels[sprites[s].x + 14] = sprite_palettes[sprites[s].palette].color[ce]; } if (cf) { pixels[sprites[s].x + 15] = sprite_palettes[sprites[s].palette].color[cf]; } } }}
Statistics: Posted by cbmeeks — Wed Jul 24, 2024 5:49 pm