X-Git-Url: http://git.mutantstargoat.com/user/nuclear/?p=dosdemo;a=blobdiff_plain;f=src%2Ftinyfps.c;fp=src%2Ftinyfps.c;h=4b9d9dbdc4700f6b67519cd1d8c5d9309aa39e66;hp=0000000000000000000000000000000000000000;hb=a8d502c1e163a95f25b2f5aec1478d2cb61027c2;hpb=9dda65bd2ac317cf110c080e561f40b2ee221c93 diff --git a/src/tinyfps.c b/src/tinyfps.c new file mode 100644 index 0000000..4b9d9db --- /dev/null +++ b/src/tinyfps.c @@ -0,0 +1,125 @@ +#include + +#include "tinyfps.h" +#include "demo.h" + +// TinyFPS, just a minimal fraps like font to show FPS during the demo and not just after. +// I'll be using it in my effects for my performance test purposes, just adding it here. +// Maybe it would be nice if initFpsFonts would be called in demo.c once but I avoided touching that code. + +/* +1110 0010 1110 1110 1010 1110 1110 1110 1110 1110 +1010 0010 0010 0010 1010 1000 1000 0010 1010 1010 +1010 0010 1110 0110 1110 1110 1110 0010 1110 1110 +1010 0010 1000 0010 0010 0010 1010 0010 1010 0010 +1110 0010 1110 1110 0010 1110 1110 0010 1110 1110 +*/ + +const unsigned char miniDecimalData[] = { 0xE2, 0xEE, 0xAE, 0xEE, 0xEE, +0xA2, 0x22, 0xA8, 0x82, 0xAA, +0xA2, 0xE6, 0xEE, 0xE2, 0xEE, +0xA2, 0x82, 0x22, 0xA2, 0xA2, +0xE2, 0xEE, 0x2E, 0xE2, 0xEE }; + +unsigned short miniDecimalFonts[FPS_FONT_NUM_PIXELS]; + +unsigned long startingFpsTime = 0; +int fpsFontsInit = 0; +int nFrames = 0; + +void initFpsFonts() +{ + if (fpsFontsInit == 0) + { + unsigned char miniDecimalPixels[FPS_FONT_NUM_PIXELS]; + + int k = 0; + for (int i = 0; i < FPS_FONT_NUM_PIXELS / 8; i++) + { + unsigned char d = miniDecimalData[i]; + for (int j = 0; j < 8; j++) + { + unsigned char c = (d & 0x80) >> 7; + miniDecimalPixels[k++] = c; + d <<= 1; + } + } + + int i = 0; + for (int n = 0; n < FPS_FONTS_NUM; n++) + { + for (int y = 0; y < FPS_FONT_HEIGHT; y++) + { + for (int x = 0; x < FPS_FONT_WIDTH; x++) + { + miniDecimalFonts[i++] = miniDecimalPixels[n * FPS_FONT_WIDTH + x + y * FPS_FONT_WIDTH * FPS_FONTS_NUM] * 0xFFFF; + } + } + } + + fpsFontsInit = 1; + } +} + +void drawFont(unsigned char decimal, int posX, int posY, unsigned char zoom, unsigned short *vram) +{ + int x, y, j, k; + unsigned short c; + + unsigned short *fontData = (unsigned short*)&miniDecimalFonts[decimal * FPS_FONT_WIDTH * FPS_FONT_HEIGHT]; + + vram += posY * fb_width + posX; + + if (zoom < 1) zoom = 1; + if (zoom > 4) zoom = 4; + + for (y = 0; y= 1000) + { + fps = (nFrames * 1000) / dt; + startingFpsTime = time_msec; + nFrames = 0; + } + drawDecimal(fps, 4, 4, 2, vram); +}