/** * In Dune2, the frequency of the VOC files are all over the place. * Atari STE/TT/Falcon sound only supports a few fixed frequencies. * So, we convert all audio to one frequency. That's also the occasion * to convert from unsigned 8bits samples to SIGNED 8bits samples. * Sadly, our knowledge of audio is not really good, so this is a linear * scaler. */ static uint32 DSP_ConvertAudio(uint32 freq, const uint8 * src, uint32 len) { uint32 newlen = len * DMASOUND_FREQ / freq; uint8 *w; uint8 sample; uint32 i, j; Debug("converting freq from %uHz to %u.\n", freq, DMASOUND_FREQ); if(newlen > s_stRamBufferSize) { if(Mshrink(s_stRamBuffer, newlen) == 0) { s_stRamBufferSize = newlen; } else { Error("Mshrink() of ST RAM buffer failed. newlen=%u\n", newlen); return 0; } } w = s_stRamBuffer; for (i = 1, j = 0; i <= len; i++) { sample = (*src++) ^ 0x80; /* unsigned to signed conversion */ while (j < i * DMASOUND_FREQ / freq) { *w++ = sample; j++; } } return newlen; }
/* use long instead of int so vfork works OK with -mshort */ long tfork(int (*func)(long), long arg) { register BASEPAGE *b; register long pid; register long savpending, savmask; register BASEPAGE *savbase; sighandler_t savhandler[NSIG]; long now; int i; b = (BASEPAGE *)Pexec(PE_CBASEPAGE, 0L, "", 0L); (void)Mshrink(b, SIZE+256); b->p_tbase = (char *)startup; b->p_dbase = (char *)func; b->p_dlen = arg; b->p_hitpa = ((char *)b) + SIZE + 256; pid = Pexec(104, 0L, b, 0L); if (pid == -ENOSYS) { /* save the signal masks and signal handlers, * the child may change them */ savpending = _sigpending; _sigpending = 0; savmask = _sigmask; _sigmask = 0; for (i = 0; i < NSIG; i++) savhandler[i] = _sig_handler[i]; savbase = _base; _base = b; now = _clock(); pid = Pexec(4, 0L, b, 0L); _base = savbase; /* restore signal stuff */ for (i = 0; i < NSIG; i++) _sig_handler[i] = savhandler[i]; _sigmask = savmask; _sigpending = savpending; if (pid >= 0) { long retval = pid; /* see the TOS algorithm for getpid() */ pid = ((long)b) >> 8; __waitval = (pid << 16) | retval; raise(SIGCHLD); __waittime = _clock() - now; _childtime += __waittime; }
static void start(BASEPAGE *bp) { long shrinklen; _base = bp; shrinklen = bp->p_tlen + bp->p_dlen + bp->p_blen + STACK + 0x100; if (bp->p_lowtpa + shrinklen <= bp->p_hitpa) { static char null[1] = {""}; static char *argv[2] = {null, NULL}; extern __builtin_putreg P_((int, long)); /* totally bogus */ __builtin_putreg(15, bp->p_lowtpa + shrinklen); Mshrink((void *)bp->p_lowtpa, shrinklen); main(1, argv); } Pterm(ENSMEM); }
void _crtinit(void) { register BASEPAGE *bp; register long m; register long freemem; bp = _base; /* m = # bytes used by environment + args */ m = parseargs(bp); /* make m the total number of bytes required by program sans stack/heap */ m += (bp->p_tlen + bp->p_dlen + bp->p_blen + sizeof(BASEPAGE)); m = (m + 3L) & (~3L); /* freemem the amount of free mem accounting for MINFREE at top */ if ((freemem = (long)bp->p_hitpa - (long)bp - MINFREE - m) <= 0L) goto notenough; /* make m the total number of bytes including stack */ m += _stksize; /* make sure there's enough room for the stack */ if (((long)bp + m) > ((long)bp->p_hitpa - MINFREE)) goto notenough; /* set up the new stack to bp + m */ _setstack((char *)bp + m); /* shrink the TPA */ (void)Mshrink(0, bp, m); Pterm(main()); __builtin_unreachable(); notenough: (void) Cconws("Fatal error: insufficient memory\r\n" "Hint: either decrease stack size using 'stack' command (not recomended)\r\n" " or increase TPA_INITIALMEM value in mint.cnf.\r\n"); Pterm(-1); __builtin_unreachable(); }