View Single Post
Old 10 July 2019, 00:13   #16
earok
Registered User
 
Join Date: Dec 2013
Location: Auckland
Posts: 3,542
Somehow I missed this thread - I did my own implementation of PTPlayer, but as standard Blitz code rather than a lib (it incbins a compiled assembly of PTPlayer).

So I figure I should use the library here instead - but I'm concerned about the MTInstall thing - was this ever permanently addressed and fixed, or does it need to be worked around? (eg, compiling without running first)

EDIT: I read in the other thread (http://eab.abime.net/showpost.php?p=...4&postcount=58) idrougee mentioned that neither MTInstall or MTRemove are needed in the actual game code, as the library loads and unloads these automatically?


In any case, what I've done is in the Zone, with some detail below:



Tracker files need to be loaded into Chipram using the 'Bank' function, but sound effects can be loaded through the standard Blitz LoadSound function before being played through _mt_playfx.


Code:
;Uses PTPlayer by Frank Wille
;Blitz code by Earok

;The binary file
PTPlayer.l = ?PTPlayerBinary
Goto SkipPTPlayerBinary
PTPlayerBinary: INCBIN "PTPlayer.bin"
SkipPTPlayerBinary

;Structs
NEWTYPE .PTPlayer_Request
	sfx_ptr.l ;(pointer to sample start in Chip RAM, even address)
	sfx_len.w ;(sample length in words)
	sfx_per.w ;(hardware replay period for sample)
	sfx_vol.w ;(volume 0..64, is unaffected by the song's master volume)
	sfx_cha.b ;(0..3 selected replay channel, -1 selects best channel)
	sfx_pri.b ;(unsigned priority, must be non-zero)
End NEWTYPE
DEFTYPE .PTPlayer_Request PTRequest

NEWTYPE .PTPlayer_BlitzSound
	_data.l             ;00: NULL if no sound present, else pointer to sound data
	_period.w           ;04: period of sound
	_length.w           ;06: length, in words, of sound data
	_loop.l             ;08: repeat to loop position of sound
	_looplength.w       ;12: length of looping section, in words
	_pad.b[2]           ;14:
End NEWTYPE

;Constants
#_mt_custom = $dff000
#_mt_install_cia = $20
#_mt_remove_cia = $CA
#_mt_init = $202
#_mt_end = $312
#_mt_playfx = $350
#_mt_mastervol = $5AE
#_mt_musicmask = $580
#_mt_enable = $325A
#_mt_e8trigger = $325B
#_mt_musicchannels = $325C

;ASM Functions. Don't use these, they're for internal use only
Function.l GetVBR{}

;http://stingray.untergrund.net/MiniStartup.s
	movem.l	a0-a6,-(a7)
	bsr	GetVBR
	movem.l	(a7)+,a0-a6	
	ASMExit

GetVBR:	
		move.l	a5,-(a7)
		moveq	#0,d0			; default at $0
		move.l	$4,a6
		btst	#0,296+1(a6)		; 68010+?
		beq.b	is68k			; nope.
		lea	getit(pc),a5
		jsr	-30(a6)			; SuperVisor()
		
is68k:
		move.l	(a7)+,a5
		rts

getit:	
		dc.w $4e7a,$0801 ;movec vbr,d0
		rte				; back to user state code
		
End Function

;Used for a simple (no parameter) call
Statement _mt_simple_asm{Address.l}

	movem.l	d0-d7/a0-a6,-(a7)
	Move.l #_mt_custom,A6
	Move.l D0,A0
	JSR (A0)
	movem.l	(a7)+,d0-d7/a0-a6
	ASMExit
	
End Statement

;Used for a simple (one parameter) call
Statement _mt_simple_parameter_asm{Value.l,Address.l}

	movem.l	d0-d7/a0-a6,-(a7)
	Move.l #_mt_custom,A6
	Move.l D1,A0
	JSR (A0)
	movem.l	(a7)+,d0-d7/a0-a6
	ASMExit
	
End Statement

Statement _mt_playfx_asm{SfxStructurePointer.l,Address.l}

; _mt_playfx(a6=CUSTOM, a0=SfxStructurePointer)
	movem.l	d0-d7/a0-a6,-(a7)
	Move.l #_mt_custom,A6
	Move.l D0,A0
	Move.l D1,A1
	JSR (A1)
	movem.l	(a7)+,d0-d7/a0-a6
	ASMExit
	
End Statement

Statement _mt_install_cia_asm{IsPal.b,AutoVecBase.l,Address.l}

	; Install a CIA-B interrupt for calling _mt_music.
	; a6 = CUSTOM
	; a0 = AutoVecBase
	; d0 = PALflag.b (0 is NTSC)
	movem.l	d0-d7/a0-a6,-(a7)
	Move.l #_mt_custom,A6
	Move.l D1,A0
	Move.l D2,A1
	JSR (A1)
	movem.l	(a7)+,d0-d7/a0-a6
	ASMExit
	
End Statement

Statement _mt_init_asm{InitialSongPos.b,TrackerModule.l,Samples.l,Address.l}
; _mt_init(a6=CUSTOM, a0=TrackerModule, a1=Samples|NULL, d0=InitialSongPos.b)
;   Initialize a new module.
;   Reset speed to 6, tempo to 125 and start at the given position.
;   Master volume is at 64 (maximum).
;   When a1 is NULL the samples are assumed to be stored after the patterns.
	movem.l	d0-d7/a0-a6,-(a7)
	Move.l #_mt_custom,A6
	Move.l D1,A0
	Move.l D2,A1	
	Move.l D3,A2
	JSR (A2)
	movem.l	(a7)+,d0-d7/a0-a6
	ASMExit	

End Statement

;Use these functions
Statement MTInstallCIA{}
	Shared PTPlayer
	_mt_install_cia_asm{NTSC=false,GetVBR{},PTPlayer+#_mt_install_cia}		
End Statement

Statement MTRemoveCIA{}
	Shared PTPlayer
	_mt_simple_asm{PTPlayer+#_mt_remove_cia}
End Statement

Statement MTInit{InitialSongPos.b,TrackerModule.l,Samples.l}
	Shared PTPlayer
	_mt_init_asm{InitialSongPos,TrackerModule,Samples,PTPlayer+#_mt_init}
End Statement

Statement MTEnd{}
	Shared PTPlayer
	_mt_simple_asm{PTPlayer+#_mt_end}
End Statement

Statement MTPlayFX{SoundID.w,Vol.w,Channel.b,Priority.b}

	Shared PTPlayer,PTRequest

	;Priority must be non-zero
	if Priority=0
		Priority=1
	endif
	
	*BlitzSnd.PTPlayer_BlitzSound = Addr Sound(SoundID)
	PTRequest\sfx_ptr = *BlitzSnd\_data
	PTRequest\sfx_len = *BlitzSnd\_length
	PTRequest\sfx_per = *BlitzSnd\_period
	PTRequest\sfx_vol = Vol
	PTRequest\sfx_cha = Channel
	PTRequest\sfx_pri = Priority

	_mt_playfx_asm{&PTRequest,PTPlayer+#_mt_playfx}

End Statement

Statement MTMasterVolume{vol.w}
	Shared PTPlayer
	_mt_simple_parameter_asm{vol,PTPlayer+#_mt_mastervol}
End Statement

Statement MTMusicMask{mask.b}
	Shared PTPlayer
	_mt_simple_parameter_asm{mask,PTPlayer+#_mt_musicmask}
End Statement

;Setters and getters for variables
Statement MTEnable_Set{value.b}
	Shared PTPlayer
	Poke.b PTPlayer + #_mt_enable,value
End Statement

Function.b MTEnable_Get{}
	Shared PTPlayer
	Function Return Peek.b(PTPlayer + #_mt_enable)
End Function

Statement MTE8Trigger_Set{value.b}
	Shared PTPlayer
	Poke.b PTPlayer + #_mt_e8trigger,value
End Statement

Function.b MTE8Trigger_Get{}
	Shared PTPlayer
	Function Return Peek.b(PTPlayer + #_mt_e8trigger)
End Function

Statement MTMusicChannels_Set{value.b}
	Shared PTPlayer
	Poke.b PTPlayer + #_mt_musicchannels,value
End Statement

Function.b MTMusicChannels_Get{}
	Shared PTPlayer
	Function Return Peek.b(PTPlayer + #_mt_musicchannels)
End Function

;Load the song to chipram
LoadBank 0,"AlarcityMenus.mod",2

;SFX from alarcity
LoadSound 0,"buy.iff"
LoadSound 1,"entry.iff"
LoadSound 2,"health.iff"
LoadSound 3,"levelup.iff"
LoadSound 5,"rapid.iff"
LoadSound 6,"shopopened.iff"
LoadSound 7,"sniper.iff"
LoadSound 8,"spread.iff"

BLITZ

MTInstallCIA{}

;The demo
MTInit{0,Bank(0),0}
MTEnable_Set{true}

LastJoystickDir = 4

While Joyb(0)+Joyb(1) = 0

	;Make a sound depending on the joystick direction
	JoystickDir = (JoyX(1)+1) + (JoyY(1)+1)*3
	if LastJoystickDir <> JoystickDir
		if JoystickDir <> 4
			MTPlayFX{JoystickDir,64,-1,1}
		endif
		LastJoystickDir = JoystickDir
	endif
	
	VWait
	
Wend

;Fade out
for i = 0 to 64
	MTMasterVolume{64-i}
	VWait
next

MTEnd{}
MTEnable_Set{false}
MTRemoveCIA{}

End

Last edited by earok; 10 July 2019 at 00:55.
earok is offline  
 
Page generated in 0.06371 seconds with 11 queries