Skip to content

Instantly share code, notes, and snippets.

@skmp
Created March 12, 2021 14:54
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save skmp/92ed37e53a94978cdc5c8dfd7e8591ef to your computer and use it in GitHub Desktop.
Save skmp/92ed37e53a94978cdc5c8dfd7e8591ef to your computer and use it in GitHub Desktop.
FPPAdc: HLS testbench
#include "refrend_hls.h"
#include <stdio.h>
using namespace std;
int main()
{
int err =0;
// draw a few tiles
for (int kk = 0; kk < 20; kk++) {
TileCommand(CLEARFPU << 24, 0);
TileCommand((AREA << 24) | ( 0 << 16), 0);
TileCommand((AREA << 24) | ( 1 << 16), 0);
TileCommand((AREA << 24) | ( 2 << 16), 31);
TileCommand((AREA << 24) | ( 3 << 16), 31);
TileCommand(CLEAR << 24, 0);
TileCommand(ISP << 24, (7 << 29) | ( 1 << 23));
TileCommand(TSP << 24, 1 << 29);
TileCommand(TCW << 24, 0);
TileCommand(RENDERMODE << 24, 0); // RM_OPAQUE
TileCommand((VTX << 24) | ( 0 << 16) | (0 << 8) | 0, 0); // X
TileCommand((VTX << 24) | ( 0 << 16) | (1 << 8) | 0, 0); // Y
TileCommand((VTX << 24) | ( 0 << 16) | (2 << 8) | 0, 0x3f800000); // Z
TileCommand((VTX << 24) | ( 0 << 16) | (3 << 8) | 0, 0x8000a000); // Col
TileCommand((VTX << 24) | ( 1 << 16) | (0 << 8) | 0, 0); // X
TileCommand((VTX << 24) | ( 1 << 16) | (1 << 8) | 0, 0x42000000); // Y - 32
TileCommand((VTX << 24) | ( 1 << 16) | (2 << 8) | 0, 0x3f800000); // Z
TileCommand((VTX << 24) | ( 1 << 16) | (3 << 8) | 0, 0); // Col
TileCommand((VTX << 24) | ( 2 << 16) | (0 << 8) | 0, 0x42000000); // X - 32
TileCommand((VTX << 24) | ( 2 << 16) | (1 << 8) | 0, 0x42000000); // Y - 32
TileCommand((VTX << 24) | ( 2 << 16) | (2 << 8) | 0, 0x3f800000); // Z
TileCommand((VTX << 24) | ( 2 << 16) | (3 << 8) | 0, 0x008000a0); // Col
// background poly
TileCommand(DRAW << 24, 0);
// non-bg triangle
TileCommand(DRAW << 24, 0);
TileCommand((VTX << 24) | ( 0 << 16) | (0 << 8) | 0, 0); // X
TileCommand((VTX << 24) | ( 0 << 16) | (1 << 8) | 0, 0x40e00000); // Y
TileCommand((VTX << 24) | ( 0 << 16) | (2 << 8) | 0, 0x3f800000); // Z
TileCommand((VTX << 24) | ( 0 << 16) | (3 << 8) | 0, 0x10101080); // Col
TileCommand((VTX << 24) | ( 1 << 16) | (0 << 8) | 0, 0x40e00000); // X
TileCommand((VTX << 24) | ( 1 << 16) | (1 << 8) | 0, 0x41700000); // Y
TileCommand((VTX << 24) | ( 1 << 16) | (2 << 8) | 0, 0x41700000); // Z
TileCommand((VTX << 24) | ( 1 << 16) | (3 << 8) | 0, 0x80801020); // Col
TileCommand((VTX << 24) | ( 2 << 16) | (0 << 8) | 0, 0x40e00000); // X
TileCommand((VTX << 24) | ( 2 << 16) | (1 << 8) | 0, 0x40e00000); // Y
TileCommand((VTX << 24) | ( 2 << 16) | (2 << 8) | 0, 0x3f800000); // Z
TileCommand((VTX << 24) | ( 2 << 16) | (3 << 8) | 0, 0x10108010); // Col
// another triangle
TileCommand(DRAW << 24, 0);
TileCommand(DRAWTSP << 24, 0);
}
printf("P1\n32 32\n");
for (int i = 0; i < 32; i++) {
for (int j = 0; j < 32; j++) {
printf("%d ", TileCommand((READ << 24) | (0 << 16) | (i* 32 + j), 0));
}
printf("\n");
}
FILE* fptr = fopen("col.tga", "wb");
putc(0,fptr);
putc(0,fptr);
putc(2,fptr); /* uncompressed RGB */
putc(0,fptr); putc(0,fptr);
putc(0,fptr); putc(0,fptr);
putc(0,fptr);
putc(0,fptr); putc(0,fptr); /* X origin */
putc(0,fptr); putc(0,fptr); /* y origin */
putc((32 & 0x00FF),fptr);
putc((32 & 0xFF00) / 256,fptr);
putc((32 & 0x00FF),fptr);
putc((32 & 0xFF00) / 256,fptr);
putc(32,fptr); /* 24 bit bitmap */
putc(0,fptr);
for (int i = 0; i < 32; i++) {
for (int j = 0; j < 32; j++) {
u32 col = TileCommand((READ << 24) | (4 << 16) | (i* 32 + j), 0);
putc(col >> 24, fptr);
putc(col >> 16, fptr);
putc(col >> 8, fptr);
putc(col >> 0, fptr);
}
}
fclose(fptr);
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment