I need of an INTERRUPT TIME hook for a sound SFX in assembler

ページ 1/2
| 2

By gasparrini

Champion (334)

gasparrini さんの画像

07-02-2021, 23:05

Hello to all you User's MSX World,

I need of an INTERRUPT TIME hook for a sound SFX in assembler,
PLEASE....... (^_^)

Here under there is the source in assembler code Z80 MSX for compiler
CHAOS ASSEMBLER 3.

.org $E000 - 7

.db $fe
.dw startProgram,endProgram,startProgram

startProgram:

START_SOUND_SFX:

; ---------------------------
; SET SOUND SFX
 
  LD    A,$01
  LD    E,$02
  CALL  $93 ;sound
  LD    A,$08
  LD    E,$0F
  CALL  $93                  
; --------------------------

LOOP1:  
      INC   E
  LD    A,E
  CP    $00
  JR    Z,SOUND
  LD    A,$00 
  CALL  $93
  NOP
  CALL  $93
  NOP        
  CALL  $93
  NOP
  CALL  $93
  NOP
  CALL  $93  
;;
  NOP
  CALL  $93
  NOP
  CALL  $93
  NOP        
  CALL  $93
  NOP
  CALL  $93
  NOP
  CALL  $93    
  NOP
  CALL  $93
  NOP
  CALL  $93
  NOP        
  CALL  $93
  NOP
  CALL  $93
  NOP
  CALL  $93
 
  NOP 
  CALL  $93   
  NOP 
  CALL  $93
  NOP        
  CALL  $93
  NOP
  CALL  $93
  NOP
  CALL  $93    
  JR    LOOP1   ;LOOP to LOOP1

SOUND:
   LD    E,$16
LOOP2:
   LD    A,E
  CP    $00
  RET   Z          ;exit if A=0
  LD    A,$08
  CALL  $93
  LD    A,$00
  CALL  $93
  DEC   E          ;E=E-1
  CALL  $93
  NOP
  JR    LOOP2     ;LOOP to LOOP2

endProgram:

.end

Instead here uder there is the BASIC programm in code machine:

100 REM
110 REM ** LOADER L/M SOUND SFX BONUS **
120 REM
130 CLEAR300,57343:RESTORE 200
140 FOR X=57344 TO 57470
150 READ A$:Y=VAL("&H"+A$)
160 POKE X,Y:CK=CK+Y
170 NEXT X
180 READ X:IF X<>CK THEN BEEP:PRINT"ERRORE NEI DATA: RICONTROLLA!":LIST 200-360:END
190 DEFUSR=&HE000:END
200 DATA 3E,01,1E,02,CD,93,00,3E
210 DATA 08,1E,0F,CD,93,00,1C,7B
220 DATA FE,00,28,53,3E,00,CD,93
230 DATA 00,00,CD,93,00,00,CD,93
240 DATA 00,00,CD,93,00,00,CD,93
250 DATA 00,00,CD,93,00,00,CD,93
260 DATA 00,00,CD,93,00,00,CD,93
270 DATA 00,00,CD,93,00,00,CD,93
280 DATA 00,00,CD,93,00,00,CD,93
290 DATA 00,00,CD,93,00,00,CD,93
300 DATA 00,00,CD,93,00,00,CD,93
310 DATA 00,00,CD,93,00,00,CD,93
320 DATA 00,00,CD,93,00,18,A7,1E
330 DATA 16,7B,FE,00,C8,3E,08,CD
340 DATA 93,00,3E,00,CD,93,00,1D
350 DATA CD,93,00,00,18,EB,FF
360 DATA 11095

The effect are is allocated to the address E00h
so to hear it simply type
A=USR(0): REM PLAY SOUND SFX BONUS!

As a sound effect, it might be fine when the player
1UP, collides with a bonus score item.

When starting this bonus sound effect, the BASIC remains frozen for a short time,
while the sound effect with A = USR (0) is heard, and therefore it is necessary to put
a time interrupt on the Z80, so that while the 'sound effect starts, BASIC remains free,
this is because if a program of a small videogames in BASIC, without the TIME INTERRUPT
to the Z80 the videogame would slow down a lot, and this should not happen.

Below is a small example of using the HOOK interrupt time:

.org $C000 - $C07

.db $fe
.dw startProgram,endProgram,startProgram

startProgram:
;*************************************************************
;       How to use HOOK safety
;       This routine uses TIMER INTERRUPT HOOK
;  
;       To start play SOUND SFX,    do  DEFUSR=&HC000 :A=USR(0)
;       To continue sound SFX ,      do  DEFUSR=&HC030:A=USR(0)
;       To pause sound SFX,            do  DEFUSR=&HC050:A=USR(0)
;*************************************************************
;
CHGCAP   .EQU 0132H      ;CAPS LAMP on/off
CAPST       .EQU 0FCABH    ;CAPS LOCK status
TIMI          .EQU 0FD9FH    ;timer interrupt hook
JPCODE     .EQU 0C3H
TIMER       .EQU 020H


;----- interrupt on ----- Note:  restore the former hook
;when changing the hook
     
START:  ; load and initialize START SOUND SFX

 .ORG $C020 - $C00  ; CONTINUE SOUND SFX

INTON:
      DI
LD HL,TIMI ;OLD HOOK SAVE
LD DE,HKSAVE
LD BC,5
LDIR

LD A,JPCODE ;NEW HOOK SET
LD (TIMI),A
LD HL,INT
LD (TIMI+1),HL
EI
RET

.ORG $C050 - $C00 ; PAUSE SOUND

;----- interrupt off ----- Note:  restore the reserved hook and exit

INTOFF:
      DI
LD HL,HKSAVE
LD DE,TIMI
LD BC,5
LDIR
EI  
CALL $90 ; resetta canale audio
RET

;----- interrupt routine -----

INT: PUSH AF
LD A,(CAPST)
OR A
JR Z,CAPON

CAPOFF:
   CALL $90   ;CALL MUTE  ; silence
   RET      

CAPON:
   CALL START_SOUND_SFX ; play 1 quark
   
FIN:
  POP AF
CALL HKSAVE ;old HOOK call

RET

COUNT1:          
      .DB TIMER
COUNT2:
      .DB TIMER

HKSAVE:
      NOP ;old HOOK save area
NOP
NOP
NOP
RET  

;----- interrupt routine -----

#INCLUDE "SOUND.ASM" ; routine sound.asm

endProgram:

.end

What I would like to ask you and what I want to achieve is that the sound effect
works with the interrupt time at the Z80, I repeat, so that BASIC remains free,
without any BASIC program slowing down when it is running.

That's all for now, I'm waiting for one
your positive answer.

Best Regards
(^_^)
Andrea Italy

ログイン/登録して投稿

By Daemos

Prophet (2168)

Daemos さんの画像

07-02-2021, 23:50

Something like this?

InterruptHandler:

 
  push  af


  ld    a,1               ;set s#1
  out   ($99),a
  ld    a,15+128
  out   ($99),a
  in    a,($99)           ;check and acknowledge line interrupt
  rrca
  jp    c,.Lineint        ;lineint detected, so jp to that routine

  xor   a                 ;set s#0
  out   ($99),a
  ld    a,15+128
  out   ($99),a
  in    a,($99)           ;check and acknowledge vblank interrupt
  rlca
  jp    c,vblank          ;vblank detected, so jp to that routine


  pop   af                ;at this point neither lineint NOR vblank was
  ei
  ret

Then on either vblank or lineint (whatever suits you most)

push  bc
  push  de
  push  hl
  exx
  ex    af,af'
  push  af
  push  bc
  push  de
  push  hl
  push  ix

  Call sfx (or whatever

pop   ix
  pop   hl
  pop   de
  pop   bc
  pop   af
  ex    af,af'
  exx
  pop   hl
  pop   de
  pop   bc


  pop   af 



  ei
  ret

By gasparrini

Champion (334)

gasparrini さんの画像

08-02-2021, 00:12

Hello,

Honestly, I don't get it right, but your two routines certainly aren't correct at all!
Any other users would like to move forward?

By Pencioner

Scribe (1609)

Pencioner さんの画像

08-02-2021, 01:08

Every other user would certainly post not at all correct ones, so why they would bother...

By syn

Prophet (2133)

syn さんの画像

08-02-2021, 01:47

Just use ayfx maybe?

By Louthrax

Prophet (2494)

Louthrax さんの画像

08-02-2021, 02:04

I wouldn’t trust a person whose sole experience on MSX has been porting Super Cool Game to it. He probably does not know what he’s talking about...

{mod: please, something is not to be spoken out loud}

By ro

Scribe (5057)

ro さんの画像

08-02-2021, 08:46

Daemos's routines are a typical custom ISR portion. When using BASIC, you just hook #FD9F to your own routine.
Furthermore, to have such FX played on interrupt requires a different replay approach. You see, Gasparrini, your code will loop until it's done. For interrupt that's not gonna work. It's more complex.

I'd suggest you take a copy of SEE (Sound Effect Editor), it's here on MRC in de download db. It includes an editor and replayer in assembly. Including interrupt hooking *iirc.
Or, as syn suggested, use another SFX editor like ayfx. same stuff.

how's that?

By gasparrini

Champion (334)

gasparrini さんの画像

08-02-2021, 10:55

Hello, Good Morning,

The point of my situation is as follows:

I already own the SEE Editor (Sound Effect Editor), but this program is for MSX2,
and it wouldn't work for MSX1!

I already own the AYFX editor as SFX, but what I would like to achieve is to simply
use my original assembler routine, run my sound effect from BASIC with HOOK at
address FD9Fh on the system area!

Using this interrupt time at HOOK, the effect is not to go into continuous LOOP, what I
want to do is that it must be in automatic. Once the sound effect starts with A=USR(0),
it has to stop by itself.I think my assembler development request is very complicated,
that's why I'm asking for your kind cooperation and asking for help in this forum.

Unfortunately I have very little experience with the Z80 MSX assembler.

By ro

Scribe (5057)

ro さんの画像

08-02-2021, 11:08

SEE: The editor is self is MSX2, indeed. The replayer, however, is MSX1 compatible of course.

Okay, let's look at it like this.

Currently you are looping in one go. While doing this on the interrupt requires a system that "remembers" where you sound fx loop is, and continue on the next frame. So you might make the FX settings in a table, keep a pointer and place the whole system on vBlank (*interrupt at the bottom of the screen, FD9F).

Quote:

Unfortunately I have very little experience with the Z80 MSX assembler.

If your goal is to simply have SFX, use SEE in that case. It's straigh forward, has a driver and is easy to use in BASIC. Perhaps it needs some tweaking for BASIC replay.

And, why not slowly dive into MSX Z80 coding Smile Somethings take a bit more effort...

By gasparrini

Champion (334)

gasparrini さんの画像

08-02-2021, 11:37

Yes, of course, I agree with you, the fact that SEE library (Sound Effect Editor)
is also partially compatible for MSX1, because we are talking about the same
sound chip as the PSG.

Where can I find the driver from BASIC to use SFX for SEE ?? Maybe it should be
changed for BASIC replay?

By Daemos

Prophet (2168)

Daemos さんの画像

08-02-2021, 13:52

See replayer is what you are looking for. It is written purely in machine language. Simply put the see data somewhere in ram/rom whatever fits then put the replayer somewhere accessible by the interrupthandler then use the bioses int or vblank hook. Call see replayer from there don't forget to pop back your pushed bytes and if you did some slot switching put slots back into correct position and voila you will have psg sound. If you are using any screen split like code call the player on the inthook.

ページ 1/2
| 2