4 Commits

Author SHA1 Message Date
SuperIlu
15404baa2a Merge pull request #1 from lifelike/master
Python3 fixes
2025-08-22 14:29:29 +02:00
Pelle Nilsson
cc2d1370db Python3 fixes 2024-07-29 11:57:12 +02:00
Ilu
2644cf58f5 switched from uclock() to PCTIMER in love.timer 2023-07-01 18:55:17 +02:00
Ilu
e320ce7a1e vgm code cleanup 2023-05-14 15:38:33 +02:00
6 changed files with 22 additions and 16 deletions

1
.gitignore vendored
View File

@@ -5,3 +5,4 @@ LOVE/
rel/
test/
test2/
pi/

View File

@@ -1,4 +1,4 @@
#!/usr/bin/python
#!/usr/bin/env python3
import os, sys, shutil, re, textwrap
COMPILER = "i586-pc-msdosdjgpp-gcc"
@@ -28,7 +28,7 @@ def make_c_include(name, data):
name = re.sub("[^a-z0-9]", "_", name.lower())
res = "static const char " + name + "[] = {"
for c in data:
res += str(ord(c)) + ", "
res += str(c) + ", "
res = res.rstrip(", ") + "};"
return name, textwrap.fill(res, width=79)
@@ -46,8 +46,9 @@ def main():
for filename in embedded_files:
name = os.path.basename(filename)
name, text = make_c_include(name, open(filename).read())
open("%s/%s.h" % (TEMPSRC_DIR, name), "wb").write(text)
print(f"filename: {filename}")
name, text = make_c_include(name, open(filename, "rb").read())
open("%s/%s.h" % (TEMPSRC_DIR, name), "wb").write(text.encode())
cfiles = filter(lambda x: x.endswith((".c", ".C")), listdir(SRC_DIR))

View File

@@ -24,6 +24,7 @@
#include "package.h"
#include "vgm.h"
#include "lib/pctimer/gccint8.h"
#include "main.h"
static lua_State *L;
@@ -64,7 +65,7 @@ int main(int argc, char **argv) {
palette_init();
keyboard_init();
mouse_init();
pctimer_init(1000);
pctimer_init(TICKS_PER_SEC);
init_vgm();
/* Init lua */

6
src/main.h Normal file
View File

@@ -0,0 +1,6 @@
#ifndef MAIN_H
#define MAIN_H
#define TICKS_PER_SEC 1000
#endif // MAIN_H

View File

@@ -6,10 +6,11 @@
*/
#include <dos.h>
#include <time.h>
#include "luaobj.h"
#include "image.h"
#include "vga.h"
#include "lib/pctimer/gccint8.h"
#include "main.h"
long long timer_lastStep;
double timer_lastDt;
@@ -21,13 +22,13 @@ double timer_avgTimer;
int l_timer_step(lua_State *L) {
/* Do delta */
long long now;
unsigned long now;
/* Sometimes a call to uclock() will return a slightly earlier time than the
* previous call, resulting in a negative delta time. The below loop keeps
* trying for a proper value if this occurs. */
do {
now = uclock();
timer_lastDt = (now - timer_lastStep) / (double)UCLOCKS_PER_SEC;
now = pctimer_get_ticks();
timer_lastDt = (now - timer_lastStep) / (double)TICKS_PER_SEC;
} while (timer_lastDt < 0);
timer_lastStep = now;
/* Do average */
@@ -64,7 +65,7 @@ int l_timer_getFPS(lua_State *L) {
}
int l_timer_getTime(lua_State *L) {
lua_pushnumber(L, uclock() / (double)UCLOCKS_PER_SEC);
lua_pushnumber(L, pctimer_get_ticks() / (double)TICKS_PER_SEC);
return 1;
}

View File

@@ -34,9 +34,10 @@ VGM specs are at https://vgmrips.net/wiki/VGM_Specification
#include "vgm.h"
#include "lib/pctimer/gccint8.h"
#include "filesystem.h"
#include "main.h"
#define VGM_RESOLUTION 44100
#define VGM_FACTOR 44
#define VGM_FACTOR (VGM_RESOLUTION / TICKS_PER_SEC)
#define VGM_OPL_ADDR 0x388
#define VGM_OPL_DATA 0x389
@@ -117,7 +118,6 @@ typedef struct {
static volatile uint8_t *vgm = NULL;
static volatile vgm_t *vgm_header = NULL;
static volatile bool vgm_playback = false;
static volatile uint8_t *vgm_data = NULL;
static volatile uint32_t vgm_pos = 0;
static volatile uint32_t vgm_end = 0;
@@ -284,14 +284,12 @@ void VgmPlay() {
if (vgm_data) {
vgm_pos = 0;
vgm_wait = 0;
vgm_playback = true;
pctimer_set_hook(vgm_int);
}
}
void VgmStop() {
vgm_playback = false;
pctimer_set_hook(NULL);
vgm_opl_reset();
@@ -303,7 +301,6 @@ static void VgmDiscard() {
filesystem_free((void *)vgm);
}
vgm = NULL;
vgm_playback = false;
vgm_pos = 0;
vgm_end = 0;
vgm_wait = 0;
@@ -361,7 +358,6 @@ void init_vgm() {
// lock down
LOCK_FUNCTION(vgm_int);
LOCK_FUNCTION(vgm_opl_write);
LOCK_VARIABLE(vgm_playback);
LOCK_VARIABLE(vgm_pos);
LOCK_VARIABLE(vgm_data);
LOCK_VARIABLE(vgm_wait);