Author Topic: MASM examples -> Spectrum  (Read 195 times)

LordAdef

  • Posts: 6
MASM examples -> Spectrum
« on: 14 Oct '21 - 22:03 »
Hello everyone

I'm new here, and started studying the MASM examples.

In my Windows 10, I'm having issues (Spectrum crashes). I am thus providing here the fix that worked for me, in the hopes it may help anyone who may face similar issues.

SPECTRUM example

Issue: Crashes when MODE_WAVE and MODE_FFT is selected.

solution:
   timeSetEvent seemed to be the problem. I switched to SetTimer

   comment line:
  ; mov Timer, rv(timeSetEvent, 25, 25, ADDR UpdateSpectrum, 0, TIME_PERIODIC)
   
   replace with
   mov Timer, rv (SetTimer, Wnd, 25, 25, UpdateSpectrum)

   likewise, change the timer release invoke:

    ;invoke timeKillEvent, Timer
    invoke KillTimer,  Wnd, Timer


I hope that may be useful.
Alex
     
« Last Edit: 14 Oct '21 - 22:42 by LordAdef »

Ian @ un4seen

  • Administrator
  • Posts: 23991
Re: MASM examples -> Spectrum
« Reply #1 on: 15 Oct '21 - 17:30 »
The MASM SPECTRUM example is based on (an old version of) the C example that's included in the BASS package. That uses timeSetEvent too, so it should be fine in theory. Are you building a 32-bit or 64-bit EXE? If the latter, perhaps the problem is that the "dwUser" parameter is still 32-bit instead of 64-bit?

Falcosoft

  • Posts: 67
Re: MASM examples -> Spectrum
« Reply #2 on: 15 Oct '21 - 19:58 »
It's interesting but the 32-bit spectrum executable compiled with Masm really behaves erratic on Win 10 64-bit and only on Win 10 64 bit. Under Win 7 64-bit and Win XP 32-bit the same executable works perfectly. The problem is really related to timeSetEvent despite the fact that the parameter definitions are correct.

LordAdef

  • Posts: 6
Re: MASM examples -> Spectrum
« Reply #3 on: 16 Oct '21 - 05:56 »
Hi Ian and Faldo,

Sorry I forgot to mention. I built a 32-bit exe, using ml and UAsm.

timeSetEvent Is really the culprit, unless there is a secondary side effect involved.

The build runs smoothly and solid with setTimer, on my win10 64 machine.

Ian @ un4seen

  • Administrator
  • Posts: 23991
Re: MASM examples -> Spectrum
« Reply #4 on: 18 Oct '21 - 14:54 »
SetTimer doesn't have the same resolution as timeSetEvent (ie. the timer might not run at the requested interval), although it probably is good enough in this case.

Do you know when exactly the crash is happening, eg. is it in the timeSetEvent call, or in the UpdateSpectrum callback, or perhaps when UpdateSpectrum returns? For comparison, is the pre-compiled SPECTRUM.EXE example from the BASS package (C\BIN folder) working OK for you?

Falcosoft

  • Posts: 67
Re: MASM examples -> Spectrum
« Reply #5 on: 18 Oct '21 - 16:14 »
SetTimer doesn't have the same resolution as timeSetEvent (ie. the timer might not run at the requested interval), although it probably is good enough in this case.

Do you know when exactly the crash is happening, eg. is it in the timeSetEvent call, or in the UpdateSpectrum callback, or perhaps when UpdateSpectrum returns? For comparison, is the pre-compiled SPECTRUM.EXE example from the BASS package (C\BIN folder) working OK for you?

The problem must be related to some implementation details/register usage of timeSetEvent. The error occurs in winmm.dll but the problem can be cured by inserting PUSHAD at the very beginning and POPAD at the very end of UpdateSpectrum callback. Of course with further investigation it could be determined what exact registers have to be saved to avoid the problem but I currently do not have the mood and time to do it. Inserting PUSHAD/POPAD just does the job :)

@Edit:
OK, you have to save EDI and ESI registers to prevent freezes/erratic behavior.
So:

Code: [Select]
  LOCAL DC    : HDC
  LOCAL x, sc : SDWORD
  LOCAL Temp  : QWORD
 
  PUSH ESI
  PUSH EDI
...
 invoke ReleaseDC, Wnd, DC
 
 POP EDI
 POP ESI

 ret
« Last Edit: 18 Oct '21 - 16:29 by Falcosoft »