joeylib/src/test.c
2018-11-08 21:14:05 -06:00

97 lines
2.3 KiB
C

/*
* JoeyLib
* Copyright (C) 2018 Scott Duensing <scott@kangaroopunch.com>
*
* This software is provided 'as-is', without any express or implied
* warranty. In no event will the authors be held liable for any damages
* arising from the use of this software.
*
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
*
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
#include <stdio.h>
#include <string.h>
#include <stdarg.h>
#include "joey.h"
#ifdef JOEY_IIGS
segment "testapp";
#endif
// Font hacking!
__attribute__((__format__ (__printf__, 4, 0)))
void printAt(jlStaT *font, jint16 cx, jint16 cy, const char *what, ...) {
jint16 x;
jint16 y;
jint16 counter;
char msg[40]; // Very short messages (screen width). Be careful!
va_list va;
va_start(va, what);
vsprintf(msg, what, va);
va_end(va);
for (counter=0; counter<(int)strlen(msg); counter++) {
x = (msg[counter] - ' ') % 40;
y = (msg[counter] - ' ') / 40;
jlDrawBlit8x8(font, x, y, counter + cx, cy);
}
}
int main(void) {
jlStaT *kanga = NULL;
jlStaT *font = NULL;
jlVecT *vec = NULL;
jint16 y;
jlUtilStartup("JoeyLib Test");
jlVecLoad(vec, "nowhere");
jlVecDisplay(vec, 0, 0);
jlDisplayPresent();
jlKeyWaitForAny();
jlStaLoad(kanga, "kanga");
jlStaLoad(font, "font");
jlStaDisplay(kanga);
jlDrawColor(1);
jlDrawBox(0, 0, 319, 199);
jlSoundMusicPlay("music");
jlPaletteSet(15, 15, 15, 15);
while (!jlKeyPressed()) {
y = 17;
printAt(font, 1, y++, "X = %d ", jlGameGetAxis(0));
printAt(font, 1, y++, "Y = %d ", jlGameGetAxis(1));
printAt(font, 1, y++, "T = %d ", jlUtilTimer());
jlDisplayPresent();
}
jlKeyRead();
jlSoundMusicStop();
jlStaFree(font);
jlStaFree(kanga);
jlUtilShutdown();
}