From: sparky4 Date: Fri, 7 Apr 2017 20:30:15 +0000 (-0500) Subject: p16 is being worked on a bunch by me wwww [16_ca needs huge amounts of work and I... X-Git-Url: http://4ch.mooo.com/gitweb/?a=commitdiff_plain;h=b0e52bf89f50997ba85d95c748f00dbf386f7fae;p=16.git p16 is being worked on a bunch by me wwww [16_ca needs huge amounts of work and I should remember what needs to be done soon][OpenVGMFile needs to be ported to 16_snd.c]going to port rest of code to borland c some time so we can use the core components of id engine here [going to add 16_us.c eventually but the debug system and CA_ PM_ and MM_ usage is priority now]older zcroll renamed to xcroll][zcroll is now the pre menu game loop system with PROPER data usage with CAMMPM] MM_ShowMemory is quite buggy on real machines. i need to debug it and fix added a struct printer[gvar.mm is FUCKING HUGE 14402 bytes FAT\!]imfplay works better than vgmtest --- diff --git a/doc/If this image offends you, then please GTFO wwww.jpg b/doc/If this image offends you, then please GTFO wwww.jpg new file mode 100755 index 00000000..eba189c1 Binary files /dev/null and b/doc/If this image offends you, then please GTFO wwww.jpg differ diff --git a/makefile b/makefile index 9de0c726..ee61e51c 100755 --- a/makefile +++ b/makefile @@ -135,10 +135,10 @@ LIBFLAGS=$(WLIBQ) -b -n # # objects # -VGMSNDOBJ = vgmSnd.$(OBJ) 16_sd.$(OBJ) +VGMSNDOBJ = vgmSnd.$(OBJ) #OLDLIBOBJS=bitmap.$(OBJ) 16render.$(OBJ) GFXLIBOBJS = 16_vl.$(OBJ) 16_vl_1.$(OBJ) 16_vlpal.$(OBJ) 16text.$(OBJ) bakapee.$(OBJ) scroll16.$(OBJ) 16_vrs.$(OBJ) 16_spri.$(OBJ) $(OLDLIBOBJS) -16LIBOBJS = 16_mm.$(OBJ) 16_pm.$(OBJ) 16_ca.$(OBJ) 16_tail.$(OBJ) 16_head.$(OBJ) 16_enti.$(OBJ) 16_dbg.$(OBJ) 16_in.$(OBJ) kitten.$(OBJ) 16_hc.$(OBJ) 16_wcpu.$(OBJ) 16_timer.$(OBJ) jsmn.$(OBJ) 16_map.$(OBJ) 16text.$(OBJ) +16LIBOBJS = 16_mm.$(OBJ) 16_pm.$(OBJ) 16_ca.$(OBJ) 16_tail.$(OBJ) 16_head.$(OBJ) 16_enti.$(OBJ) 16_dbg.$(OBJ) 16_in.$(OBJ) kitten.$(OBJ) 16_hc.$(OBJ) 16_wcpu.$(OBJ) 16_timer.$(OBJ) jsmn.$(OBJ) 16_map.$(OBJ) 16text.$(OBJ) 16_sd.$(OBJ) DOSLIBOBJ = adlib.$(OBJ) 8254.$(OBJ) 8259.$(OBJ) dos.$(OBJ) cpu.$(OBJ) !ifeq DEBUGSERIAL 1 DOSLIBOBJ += 8250.$(OBJ) diff --git a/src/imfplay.c b/src/imfplay.c index 7fb6753e..3aefa2d2 100755 --- a/src/imfplay.c +++ b/src/imfplay.c @@ -19,6 +19,8 @@ #include "src/lib/16_mm.h" #include "src/lib/16_hc.h" #include "src/lib/16_dbg.h" +#include "src/lib/16_sd.h" + // #include // #include /* this is where Open Watcom hides the outp() etc. functions */ // #include @@ -29,14 +31,10 @@ // #include // #include // #include - -#include -#include -#include /* 8254 timer */ -#include -#include +struct glob_game_vars *ggvv; static void (interrupt *old_irq0)(); +/*static void (interrupt *old_irq0)(); static volatile unsigned long irq0_ticks=0; static volatile unsigned int irq0_cnt=0,irq0_add=0,irq0_max=0; @@ -112,19 +110,20 @@ int imf_load_music(const char *path, global_game_variables_t *gvar) { PRINTBB; return 1; } - -/* WARNING: subroutine call in interrupt handler. make sure you compile with -zu flag for large/compact memory models */ -void interrupt irq0() { - irq0_ticks++; - if ((irq0_cnt += irq0_add) >= irq0_max) { - irq0_cnt -= irq0_max; +*/ +// WARNING: subroutine call in interrupt handler. make sure you compile with -zu flag for large/compact memory models +void interrupt irq0() +{ + ggvv->ca.sd.irq0_ticks++; + if ((ggvv->ca.sd.irq0_cnt += ggvv->ca.sd.irq0_add) >= ggvv->ca.sd.irq0_max) { + ggvv->ca.sd.irq0_cnt -= ggvv->ca.sd.irq0_max; old_irq0(); } else { p8259_OCW2(0,P8259_OCW2_NON_SPECIFIC_EOI); } } - +/* void imf_tick() { if (imf_delay_countdown == 0) { do { @@ -185,7 +184,7 @@ void adlib_shut_up() { } adlib_apply_all(); -} +}*/ void main(int argc,char **argv) { static global_game_variables_t gvar; @@ -198,6 +197,7 @@ void main(int argc,char **argv) { #ifdef __DEBUG_MM_ dbg_debugmm=1; #endif + ggvv=&gvar; MM_Startup(&gvar); PM_Startup(&gvar); PM_CheckMainMem(&gvar); PM_UnlockMainMem(&gvar); CA_Startup(&gvar); @@ -216,35 +216,35 @@ void main(int argc,char **argv) { return; } - if (!imf_load_music(argv[1], &gvar)) { + if (!SD_imf_load_music(argv[1], &gvar)) { printf("Failed to load IMF Music\n"); return; } write_8254_system_timer(T8254_REF_CLOCK_HZ / tickrate); - irq0_cnt = 0; - irq0_add = 182; - irq0_max = 1000; /* about 18.2Hz */ + gvar.ca.sd.irq0_cnt = 0; + gvar.ca.sd.irq0_add = 182; + gvar.ca.sd.irq0_max = 1000; /* about 18.2Hz */ old_irq0 = _dos_getvect(8);/*IRQ0*/ _dos_setvect(8,irq0); - adlib_shut_up(); + SD_adlib_shut_up(); shutdown_adlib_opl3(); // NTS: Apparently the music won't play otherwise _cli(); - irq0_ticks = ptick = 0; + gvar.ca.sd.irq0_ticks = ptick = 0; _sti(); while (1) { unsigned long adv; _cli(); - adv = irq0_ticks - ptick; + adv = gvar.ca.sd.irq0_ticks - ptick; if (adv >= 100UL) adv = 100UL; - ptick = irq0_ticks; + ptick = gvar.ca.sd.irq0_ticks; _sti(); while (adv != 0) { - imf_tick(); + SD_imf_tick(&gvar); adv--; } @@ -259,8 +259,8 @@ void main(int argc,char **argv) { } // printf("contents of the imf_music\n[\n%s\n]\n", imf_music); - imf_free_music(&gvar); - adlib_shut_up(); + SD_imf_free_music(&gvar); + SD_adlib_shut_up(); shutdown_adlib(); _dos_setvect(8,old_irq0); write_8254_system_timer(0);/* back to normal 18.2Hz */ diff --git a/src/lib/16_sd.c b/src/lib/16_sd.c index 63e17e5c..f48ae2c0 100755 --- a/src/lib/16_sd.c +++ b/src/lib/16_sd.c @@ -22,6 +22,9 @@ #include "src/lib/16_sd.h" +//static void (interrupt *old_irq0)(); +extern struct glob_game_vars *ggvv; + void opl2out(word reg, word data) { __asm @@ -192,3 +195,139 @@ void FMSetVoice(int voiceNum, FMInstrument *ins){ opCellNum = (byte)0xC0 + (byte)voiceNum; opl2out(opCellNum, ins->Feedback); } /* End of FMSetVoice */ + + +void SD_Initimf(global_game_variables_t *gvar) +{ + gvar->ca.sd.irq0_ticks= + gvar->ca.sd.irq0_cnt= + gvar->ca.sd.irq0_add= + gvar->ca.sd.imf_delay_countdown= + gvar->ca.sd.irq0_max=0; + gvar->ca.sd.imf_music= + gvar->ca.sd.imf_play_ptr= + gvar->ca.sd.imf_music_end=NULL; +} + +void SD_imf_free_music(global_game_variables_t *gvar) +{ + if (gvar->ca.sd.imf_music) free(gvar->ca.sd.imf_music); + MM_FreePtr(MEMPTR gvar->ca.audiosegs[0], gvar); //TODO make behave like id engine + gvar->ca.sd.imf_music = gvar->ca.sd.imf_play_ptr = gvar->ca.sd.imf_music_end = NULL; + gvar->ca.sd.imf_delay_countdown = 0; +} + +int SD_imf_load_music(const char *path, global_game_variables_t *gvar) +{ + unsigned long len; + unsigned char buf[8]; + int fd; + + SD_imf_free_music(gvar); + + fd = open(path,O_RDONLY|O_BINARY); + if (fd < 0) return 0; + + len = lseek(fd,0,SEEK_END); + lseek(fd,0,SEEK_SET); + read(fd,buf,2); + if (buf[0] != 0 || buf[1] != 0) // type 1 IMF + len = *((uint16_t*)buf); + else + lseek(fd,0,SEEK_SET); + + if (len == 0 || len > 65535UL) { + close(fd); + return 0; + } + len -= len & 3; + + MM_GetPtr(MEMPTR gvar->ca.audiosegs[0],len, gvar); + gvar->ca.sd.imf_music = (struct imf_entry *)gvar->ca.audiosegs[0]; + if (gvar->ca.sd.imf_music == NULL) { + close(fd); + return 0; + } + read(fd,gvar->ca.sd.imf_music,len); + close(fd); + + gvar->ca.sd.imf_play_ptr = gvar->ca.sd.imf_music; + gvar->ca.sd.imf_music_end = gvar->ca.sd.imf_music + (len >> 2UL); + return 1; +} + +// WARNING: subroutine call in interrupt handler. make sure you compile with -zu flag for large/compact memory models +/*void interrupt irq0() +{ + ggvv->ca.sd.irq0_ticks++; + if ((ggvv->ca.sd.irq0_cnt += ggvv->ca.sd.irq0_add) >= ggvv->ca.sd.irq0_max) { + ggvv->ca.sd.irq0_cnt -= ggvv->ca.sd.irq0_max; + old_irq0(); + } + else { + p8259_OCW2(0,P8259_OCW2_NON_SPECIFIC_EOI); + } +}*/ + +void SD_imf_tick(global_game_variables_t *gvar) +{ + if (gvar->ca.sd.imf_delay_countdown == 0) { + do { + adlib_write(gvar->ca.sd.imf_play_ptr->reg,gvar->ca.sd.imf_play_ptr->data); + gvar->ca.sd.imf_delay_countdown = gvar->ca.sd.imf_play_ptr->delay; + gvar->ca.sd.imf_play_ptr++; + if (gvar->ca.sd.imf_play_ptr == gvar->ca.sd.imf_music_end) + { +// printf("replay\n"); + gvar->ca.sd.imf_play_ptr = gvar->ca.sd.imf_music; + } + } while (gvar->ca.sd.imf_delay_countdown == 0); + } + else { + gvar->ca.sd.imf_delay_countdown--; + } +} + +void SD_adlib_shut_up() { + int i; + + memset(adlib_fm,0,sizeof(adlib_fm)); + memset(&adlib_reg_bd,0,sizeof(adlib_reg_bd)); + for (i=0;i < adlib_fm_voices;i++) { + struct adlib_fm_operator *f; + f = &adlib_fm[i].mod; + f->ch_a = f->ch_b = f->ch_c = f->ch_d = 1; + f = &adlib_fm[i].car; + f->ch_a = f->ch_b = f->ch_c = f->ch_d = 1; + } + + for (i=0;i < adlib_fm_voices;i++) { + struct adlib_fm_operator *f; + + f = &adlib_fm[i].mod; + f->mod_multiple = 1; + f->total_level = 63 - 16; + f->attack_rate = 15; + f->decay_rate = 4; + f->sustain_level = 0; + f->release_rate = 8; + f->f_number = 400; + f->sustain = 1; + f->octave = 4; + f->key_on = 0; + + f = &adlib_fm[i].car; + f->mod_multiple = 1; + f->total_level = 63 - 16; + f->attack_rate = 15; + f->decay_rate = 4; + f->sustain_level = 0; + f->release_rate = 8; + f->f_number = 0; + f->sustain = 1; + f->octave = 0; + f->key_on = 0; + } + + adlib_apply_all(); +} diff --git a/src/lib/16_sd.h b/src/lib/16_sd.h index a2cb96c4..611982f5 100755 --- a/src/lib/16_sd.h +++ b/src/lib/16_sd.h @@ -26,6 +26,9 @@ #include "src/lib/16_head.h" #include /* 8254 timer */ #include +#include +#include +#include #define MIN_REGISTER 0x01 #define MAX_REGISTER 0xF5 @@ -58,4 +61,11 @@ void FMKeyOff(int voice); void FMKeyOn(int voice, int freq, int octave); void FMSetVoice(int voiceNum, FMInstrument *ins); +void SD_Initimf(global_game_variables_t *gvar); +void SD_imf_free_music(global_game_variables_t *gvar); +int SD_imf_load_music(const char *path, global_game_variables_t *gvar); +//void interrupt irq0(global_game_variables_t *gvar); +void SD_imf_tick(global_game_variables_t *gvar); +void SD_adlib_shut_up(); + #endif /*__16_SND_H_*/ diff --git a/src/lib/16_tdef.h b/src/lib/16_tdef.h index c87b272e..22e9812b 100755 --- a/src/lib/16_tdef.h +++ b/src/lib/16_tdef.h @@ -594,14 +594,25 @@ typedef struct //========================================================================== -/* +//for 16_sd +//========================================================================== #pragma pack(push,1) -typedef struct imf_entry { +typedef struct imf_entry +{ uint8_t reg,data; uint16_t delay; } imf_entry_t; #pragma pack(pop) -*/ + +typedef struct +{ + volatile unsigned long irq0_ticks;//=0; + volatile unsigned int irq0_cnt,irq0_add,irq0_max;//=0; + imf_entry_t* imf_music;//=NULL; + imf_entry_t* imf_play_ptr;//=NULL; + imf_entry_t* imf_music_end;//=NULL; + uint16_t imf_delay_countdown;//=0; +} sd_t; //========================================================================== @@ -660,8 +671,9 @@ typedef struct //TODO: USE THIS!!!! word _seg *grstarts; // array of offsets in egagraph, -1 for sparse//long word _seg *audiostarts; // array of offsets in audio / audiot//long - huffnode huffnode; + huffnode huffnode; + sd_t sd; //TODO: extend! and learn from keen/wolf/catacomb's code wwww memptr spribuff; } ca_t;