diff --git a/adlib.c b/adlib.c index 0c4fff7..5f0e6ce 100755 --- a/adlib.c +++ b/adlib.c @@ -1,5 +1,6 @@ #include "adlib.h" +int adlib_present; static void adlib_wait(int delay) { int i; for (i = 0; i < delay; i ++) adlib_read(); @@ -20,7 +21,22 @@ void adlib_reset() { } } -void adlib_init() { - adlib_reset(); - atexit(adlib_reset); +void adlib_detect() { + int status1, status2; + adlib_write(4, 0x60); + adlib_write(4, 0x80); + status1 = adlib_read(); + adlib_write(2, 0xff); + adlib_write(4, 0x21); + adlib_wait(160); + status2 = adlib_read(); + adlib_present = (status1 & 0xe0) == 0 && (status2 & 0xe0) == 0xc0; +} + +void adlib_init() { + adlib_detect(); + if (adlib_present) { + adlib_reset(); + atexit(adlib_reset); + } } diff --git a/adlib.h b/adlib.h index 009857f..1523257 100755 --- a/adlib.h +++ b/adlib.h @@ -1,5 +1,6 @@ #include +extern int adlib_present; void adlib_init(); #define adlib_read() inp(0x388) void adlib_write(int reg, int val); diff --git a/boot.jim b/boot.jim index 93ad3d2..a3f1549 100755 Binary files a/boot.jim and b/boot.jim differ diff --git a/debug.jim b/debug.jim index 5af2f12..b09d42b 100755 Binary files a/debug.jim and b/debug.jim differ diff --git a/defs.jim b/defs.jim index 4cc3021..cef31c0 100755 Binary files a/defs.jim and b/defs.jim differ diff --git a/end.jim b/end.jim index 707c5b1..e6a81ba 100755 Binary files a/end.jim and b/end.jim differ diff --git a/entity.jim b/entity.jim index 07a0e17..857078c 100755 Binary files a/entity.jim and b/entity.jim differ diff --git a/fakelib.c b/fakelib.c new file mode 100755 index 0000000..984726d --- /dev/null +++ b/fakelib.c @@ -0,0 +1,51 @@ +#include "fakelib.h" +#include "timer.h" + +void fakelib_shutup() { + outportb(0x61, inportb(0x61) & 0xfc); +} + +void fakelib_init() { + atexit(fakelib_shutup); +} + +static unsigned int remaining_ticks; +static unsigned int last_tick; +static unsigned int fnumlow; +void fakelib_write(int reg, int val) { + if (reg == 0xa0) { // writing a new frequency to voice 0 + fnumlow = (val & 0xff); + } else if (reg == 0xb0) { + if (val & 0x20) { + unsigned long fnum = ((val & 0x03) << 8) | fnumlow; + unsigned int oct = (val & 0x1c) >> 2; + unsigned long div = (24L << (20 - oct)) / fnum; + unsigned char tmp; + + outportb(0x43, 0xb6); + outportb(0x42, div & 0xff); + outportb(0x42, (div >> 8) & 0xff); + outportb(0x61, inportb(0x61) | 0x03); + + // todo: guess at duration based on instrument decay + remaining_ticks = 2; + last_tick = timer_counter; + } else { + fakelib_shutup(); + remaining_ticks = 0; + } + } +} + +void fakelib_tick() { + if (remaining_ticks > 0) { + unsigned int tickdiff = timer_counter - last_tick; + if (tickdiff >= remaining_ticks) { + fakelib_shutup(); + remaining_ticks = 0; + } else { + remaining_ticks -= tickdiff; + } + } + last_tick = timer_counter; +} \ No newline at end of file diff --git a/fakelib.h b/fakelib.h new file mode 100755 index 0000000..eacad42 --- /dev/null +++ b/fakelib.h @@ -0,0 +1,3 @@ +void fakelib_init(); +void fakelib_write(int reg, int val); +void fakelib_tick(); diff --git a/footer.jim b/footer.jim index 41d3f27..3c0eb6d 100755 Binary files a/footer.jim and b/footer.jim differ diff --git a/game.jim b/game.jim index 7e24001..4d73e36 100755 Binary files a/game.jim and b/game.jim differ diff --git a/input.jim b/input.jim index ec6afa8..4e3ee8d 100755 Binary files a/input.jim and b/input.jim differ diff --git a/jiles.jim b/jiles.jim index fad390b..1b1a97a 100755 Binary files a/jiles.jim and b/jiles.jim differ diff --git a/job.jim b/job.jim index 1a41319..f943079 100755 Binary files a/job.jim and b/job.jim differ diff --git a/lev00001.jim b/lev00001.jim index 7e5e12a..85f14d4 100755 Binary files a/lev00001.jim and b/lev00001.jim differ diff --git a/lev00002.jim b/lev00002.jim index 7d93b82..0b94e8d 100755 Binary files a/lev00002.jim and b/lev00002.jim differ diff --git a/lev00003.jim b/lev00003.jim index 48de308..3c5c825 100755 Binary files a/lev00003.jim and b/lev00003.jim differ diff --git a/lev00004.jim b/lev00004.jim index 8cbd9a2..37b9c1c 100755 Binary files a/lev00004.jim and b/lev00004.jim differ diff --git a/lev00005.jim b/lev00005.jim index 5eeefd8..e91484f 100755 Binary files a/lev00005.jim and b/lev00005.jim differ diff --git a/lev00006.jim b/lev00006.jim index dffbad6..8d46439 100755 Binary files a/lev00006.jim and b/lev00006.jim differ diff --git a/level.jim b/level.jim index 68edf52..7767b90 100755 Binary files a/level.jim and b/level.jim differ diff --git a/map.jim b/map.jim index d5f27a0..76ab8a0 100755 Binary files a/map.jim and b/map.jim differ diff --git a/neuttowr.exe b/neuttowr.exe index ea6c40f..9215f88 100755 Binary files a/neuttowr.exe and b/neuttowr.exe differ diff --git a/neuttowr.prj b/neuttowr.prj index 0fa410d..863ad26 100755 Binary files a/neuttowr.prj and b/neuttowr.prj differ diff --git a/sound.jim b/sound.jim index ad7c171..645c738 100755 Binary files a/sound.jim and b/sound.jim differ diff --git a/state.jim b/state.jim index 49509bf..628ab22 100755 Binary files a/state.jim and b/state.jim differ diff --git a/testbed.c b/testbed.c index 3d0f78f..dd046a7 100755 --- a/testbed.c +++ b/testbed.c @@ -18,6 +18,7 @@ #include "jorth.h" #include "egamap.h" #include "adlib.h" +#include "fakelib.h" /*** T E X T ***/ char far *font = NULL; @@ -270,6 +271,8 @@ void game_init() { timer_init(TIMER_30HZ); text_init(); adlib_init(); + fakelib_init(); + timer_setcallback(fakelib_tick); loadscr("title"); /* f = fopen("TITLE.TIF", "rb"); @@ -407,11 +410,20 @@ void f_drawportrait() { DROP(1); } +int use_adlib; void f_adlib() { - adlib_write(TOP().u, ST1().u); + if (use_adlib) { + adlib_write(TOP().u, ST1().u); + } else { + fakelib_write(TOP().u, ST1().u); + } DROP(2); } +void f_adlib_present() { + PUSHI(adlib_present); +} + cell f_atexit; void f_cleanup() { f_execcp(f_atexit); @@ -827,6 +839,9 @@ void game_f_init(char *exe, char *bootjor) { CDEF("boss", f_showboss); CDEF("system", f_system); CDEF("adlib!", f_adlib); + CDEF("adlib?", f_adlib_present); + PCONST("use-adlib", &use_adlib); + use_adlib = adlib_present; CDEF("mouseshow", f_mouseshow); CDEF("mousehide", f_mousehide); diff --git a/timer.jim b/timer.jim index b622560..89ef1b7 100755 Binary files a/timer.jim and b/timer.jim differ diff --git a/title.jim b/title.jim index 4680cd7..883abbd 100755 Binary files a/title.jim and b/title.jim differ