AY music menu/player

Any discussions related to the creation of new hardware or software for the ZX80 or ZX81
User avatar
Andy Rea
Posts: 1521
Joined: Fri May 09, 2008 2:48 pm
Location: notts UK

Re: AY music menu/player

Post by Andy Rea » Fri Nov 11, 2016 5:37 pm

here is the document i have for the STC file format it can be seen that bytes 1, 2&3, 4&5, 6&7 are used to store information about the SNG and bytes 8 thru 27 are a text field whichh in my compiler is set to "ZX81 Compiler A.Rea." exactly 20 characters !

Code: Select all

                      SOUNDTRACKER TECHNICAL REFERENCE                
                      --------------------------------        
                              (C) 1993 RAMSOFT
                      
                      Document revision 1.0  (30/07/93)
                                                                


UNCOMPILED SONGS STRUCTURE                                      
                                                                
Start address= 25000  (61A8h)                                   
Lenght= 3009 (0BC1h)+576 (0240h)x[number of patterns]           
                                                                
Start                = uncompiled samples                       
Start + 1950 (079Eh) = positions map                            
Start + 2462 (099Eh) = song's lenght in patterns                
Start + 2463 (099Fh) = uncompiled ornaments                     
Start + 3007 (0BBFh) = delay value                              
Start + 3008 (0BC0h) = patterns lenght                          
Start + 3009 (0BC1h) = patterns data                            
                                                                
                                                                
UNCOMPILED SAMPLES STRUCTURE                                    
                                                                
Length= 130 (82h) bytes per sample                              
                                                                
Bytes 00-31  (00h-1Fh) = envelope values (volumes)              
Bytes 32-63  (20h-3Fh) = noise values                           
Bytes 64-127 (40h-7Fh) = addition for effects                   
Byte   128     (80h)   = repeat value                           
Byte   129     (81h)   = repeat lenght value                    
                                                                
Note: bit 4 of additions is for sign.                           
                                                                
                                                                
UNCOMPILED POSITIONS MAP STRUCTURE                              
                                                                
Lenght= 2 bytes per positions                                   
                                                                
Byte 1 = pattern number in position                             
Byte 2 = height of pattern in this position                     
                                                                
                                                                
UNCOMPILED ORNAMENT STRUCTURE                                   
                                                                
Lenght= 32 (20h) bytes per ornament                             
                                                                
Positive values = normal                                        
Negative values = obtained with one's complement                
                                                                
                                                                
UNCOMPILED PATTERN STRUCTURE                                    
                                                                
Lenght= 576 (0240h) bytes per pattern                           
Lenght of location data= 9 bytes (3 bytes per channel)          
Channel data sequence= A,B,C.                                   
                                                                
Byte n.1:     bits 0-2  = octave number                         
              bit   3   = flat note flag (0=no;1=yes)           
              bits 4-6  = note name (0=A;7=G)                   
              bit   7   = rest flag                             
                                                                
Byte n.2:     bits 0-3  = effect selected number                
              bits 4-7  = sample number                         
                                                                
Byte n.3:     bits 0-3  = low part of effect or ornament number 
              bits 4-7  = high part of effect                   
                                                                
----------------------------------------------------------------
                                                                
COMPILED SONG STRUCTURE                                         
                                                                
Start            = delay value                                  
Start + 1        = offset of positions map                      
Start + 3        = offset of compiled ornaments                 
Start + 5        = offset of patterns data                      
Start + 27 (1Bh) = compiled samples                             
                                                                
Note: every offset must be added to 'Start' address.            
                                                                
                                                                
COMPILED POSITIONS MAP STRUCTURE                                
                                                                
Byte 1 = song's lenght in patterns                              
Remaining bytes are the same as uncompiled.                     
End marker = 255 (FFh)                                          
                                                                
                                                                
COMPILED ORNAMENTS STRUCTURE                                    
                                                                
Lenght of compiled ornament = 33 (21h) bytes                    
Byte 1 = ornament number                                        
Remaining bytes are the same as uncompiled.                     
                                                                
Note:ornaments are stored from number 0 (empty ornament)        
                                                                
                                                                
COMPILED PATTERNS DATA STRUCTURE                                
                                                                
Lenght of each pattern data = 7 bytes                           
                                                                
Byte    1   = pattern number                                    
Bytes  2/3  = offset of channel A data                          
Bytes  4/5  = offset of channel B data                          
Bytes  6/7  = offset of channel C data                          
                                                                
                                                                
COMPILED SAMPLES STRUCTURE                                      
                                                                
Lenght of compiled sample = 99 (63h) bytes                      
                                                                
Byte      1     (01h) = sample number                           
Bytes 02-97 (02h-61h) = 32 (20h) groups of 3 bytes; each group  
                        holds the values for envelope,noise     
                        and addition for effects                
Byte     98     (62h) = repeat value                            
Byte     99     (63h) = repeat lenght value                     
                                                                
Each group of 3 bytes is arranged as below:                     
                                                                
Byte n.1:     bits 0-3 = envelope value (volume)                
              bits 4-7 = high part of addition for effects      
                                                                
Byte n.2:     bits 0-4 = noise value                            
              bit   5  = addition for effects sign              
              bit   6  = envelope mask setting                  
              bit   7  = noise mask setting                     
                                                                
Byte n.3:     bits 0-8 = low part of addition for effects       
                                                                
                                                                
CODES MEANING ON CHANNEL DATA                                   
                                                                
If:    code<96  (60h)  => bits 0-4 = note in semitones (00=C-1) 
       code<112 (70h)  => bits 0-4 = sample number              
       code<128 (80h)  => bits 0-4 = ornament number            
       code=128 (80h)  => rest (shuts channel)                  
       code=129 (81h)  => empty location                        
       code=130 (82h)  => selects ornament 0                    
       code<143 (8Fh)  => selects effect                        
       code=255 (FFh)  => end channel data                      
                                                                
Codes between 161 (A1h) and 224 (E0h),by subtracting 161 (A1h), 
tell the number of empty locations after the subsequent code.

-----------------------------------------------------------------------------
Converted from Tasword II with Ramsoft TAS2TXT


it should be noted that the uncompiled SNG data is laid out in memeory slightly different to that in the document above BUT it is what i observed on a zx spectrum

Code: Select all

;=================
;
;SONG DATA FORMAT IS SET OUT BELOW
;
;SECTION IS PARTLY HERE FOR REFERENCE
;
;AND PARTLY TO PROVIDE ADDRESS 'LABELS'
;
;FOR THE CODE ABOVE
;

SONG_DATA_START:	EQU 28282
	;THIS LAYOUT DIFFERS FROM THE DOCUMENTATION
	; BUT MATCHED THAT OBSERVED ON A ZX SPECTRUM

;UNCOMPILED PATTERN STRUCTURE    
;                                                                 
; Lenght= 576 (0240h) bytes per pattern                           
; Lenght of location data= 9 bytes (3 bytes per channel)          
; Channel data sequence= A,B,C.                                   
;                                                                 
; Byte n.1:     bits 0-2  = octave number                         
;               bit   3   = flat note flag (0=no;1=yes)           
;               bits 4-6  = note name (0=A;7=G)                   
;               bit   7   = rest flag                             
;                                                                 
; Byte n.2:     bits 0-3  = effect selected number                
;               bits 4-7  = sample number                         
;                                                                 
; Byte n.3:     bits 0-3  = low part of effect or ornament number 
;               bits 4-7  = high part of effect      

PATTERN_DATA:		EQU SONG_DATA_START

; UNCOMPILED SAMPLES STRUCTURE                                    
;                                                                 
; Length= 130 (82h) bytes per sample                              
;                                                                 
; Bytes 00-31  (00h-1Fh) = envelope values (volumes)              
; Bytes 32-63  (20h-3Fh) = noise values                           
; Bytes 64-127 (40h-7Fh) = addition for effects                   
; Byte   128     (80h)   = repeat value                           
; Byte   129     (81h)   = repeat lenght value                    
;                                                                 
; Note: bit 4 of additions is for sign.   


SAMPLES: 			EQU	SONG_DATA_START+ (576*31)		;31 PATTERNS @ 576 BYTES EACH
SAMPLE_1:			EQU	SAMPLES
SAMPLE_1_ENVELOPE:	EQU	SAMPLE_1		;ENVELOPE VALUES
SAMPLE_1_NOISE: 	EQU	SAMPLE_1+32
SAMPLE_1_ADDITION:	EQU	SAMPLE_1+64	;ADDITION FOR EFFECT
SAMPLE_1_REPEAT:	EQU	SAMPLE_1+128	;REPEAT VALUE
SAMPLE_1_LENGTH:	EQU	SAMPLE_1+129	;REPEAT LENGTH
	
SAMPLE_2:			EQU	SAMPLE_1+130
SAMPLE_3:			EQU	SAMPLE_2+130
SAMPLE_4:			EQU	SAMPLE_3+130
SAMPLE_5:			EQU	SAMPLE_4+130
SAMPLE_6:			EQU	SAMPLE_5+130
SAMPLE_7:			EQU	SAMPLE_6+130
SAMPLE_8:			EQU	SAMPLE_7+130
SAMPLE_9:			EQU	SAMPLE_8+130
SAMPLE_A:			EQU	SAMPLE_9+130
SAMPLE_B:			EQU	SAMPLE_A+130
SAMPLE_C:			EQU	SAMPLE_B+130
SAMPLE_D:			EQU	SAMPLE_C+130
SAMPLE_E:			EQU	SAMPLE_D+130
SAMPLE_F:			EQU	SAMPLE_E+130
		
; UNCOMPILED POSITIONS MAP STRUCTURE                              
;                                                                 
; Lenght= 2 bytes per positions                                   
;                                                                 
; Byte 1 = pattern number in position                             
; Byte 2 = height of pattern in this position 

POSITIONS_MAP:		EQU	SAMPLES + 1950				;15 SAMPLES @ 130 BYTES EACH

SONG_LENGTH:		EQU	POSITIONS_MAP + 512			;256 (0 - 255) * 2 BYTES PER POSITION.            

; UNCOMPILED ORNAMENT STRUCTURE                                   
;                                                                 
; Lenght= 32 (20h) bytes per ornament                             
;                                                                 
; Positive values = normal                                        
; Negative values = obtained with 2'S COMPLIMENT.  
             
ORNAMENTS:			EQU	SONG_LENGTH + 1

DELAY_VALUE:		EQU	ORNAMENTS + 544	;(16 * 32 BYTES (ORNS ARE 32 BYTES + 32 EMPTY BYTES)))

PATTERNS_LENGTH:	EQU	DELAY_VALUE +1
6 x ZX81, 1 x TS1500 , 1 x +3e, 1 x timex 2040 printer, 1 x timex 2020 cassette deck, siclair printer and some spectrum

Moggy
Posts: 1727
Joined: Wed Jun 18, 2008 2:00 pm

Re: AY music menu/player

Post by Moggy » Sat Nov 12, 2016 3:00 pm

Decompiler.Decompiler.Decompiler.Decompiler.Decompiler.Decompiler.Decompiler.Decompiler.
Decompiler.Decompiler.Decompiler.Decompiler.Decompiler.Decompiler.Decompiler.Decompiler.
Decompiler.Decompiler.Decompiler.Decompiler.Decompiler.Decompiler.Decompiler.Decompiler.

"Build it and I will come"

(Hmm that sounds a bit rude) :lol:

Sorry Andy but being terminally thick ASM listings are just so much noise to me sooooooooo
give up six years of your life to create a decompiler (which only I will probably use) and I will write sweet musics in your honour. :D

daveZX4th
Posts: 11
Joined: Mon Dec 04, 2017 2:22 pm

Re: AY music menu/player

Post by daveZX4th » Fri Dec 22, 2017 1:19 pm

I'd like do a version of STC player for Tree/H4th ZX81Forth. I'm familiar with STC file format and have done a quick disassembly of JUK.P but it would make life a lot easier if the source was available ;)

What makes it easier is H4th has a user frame counter which can action a routine when exhausted.

User avatar
Andy Rea
Posts: 1521
Joined: Fri May 09, 2008 2:48 pm
Location: notts UK

Re: AY music menu/player

Post by Andy Rea » Fri Dec 22, 2017 4:25 pm

@davezx4th i can either send you the source for the stc player when I get back to England or you can search out the mighty Sirmorris's latest master piece zedragon which i believe he has open sourced and place on git hub for everyone, the player code is also there. I assume since as you have disassembled stuff you'll have no problem with it, of course the tricky thing is hooking the zx81 display routine but.once that is achieved it reasonably plain sailing.
Regards andy
6 x ZX81, 1 x TS1500 , 1 x +3e, 1 x timex 2040 printer, 1 x timex 2020 cassette deck, siclair printer and some spectrum

User avatar
Andy Rea
Posts: 1521
Joined: Fri May 09, 2008 2:48 pm
Location: notts UK

Re: AY music menu/player

Post by Andy Rea » Fri Dec 22, 2017 4:26 pm

Duh... My bad since you can continuously set your 4th frame counter to 1 so that a routine can be actioned every frame you'll be singing in no time.

P.s my auto carrots is broccoli
6 x ZX81, 1 x TS1500 , 1 x +3e, 1 x timex 2040 printer, 1 x timex 2020 cassette deck, siclair printer and some spectrum

daveZX4th
Posts: 11
Joined: Mon Dec 04, 2017 2:22 pm

Re: AY music menu/player

Post by daveZX4th » Wed Dec 27, 2017 1:27 pm

Thanks, I've just downloaded zedragon and will have a look. Just need to relocate code to a suitable place for H4th.

daveZX4th
Posts: 11
Joined: Mon Dec 04, 2017 2:22 pm

Re: AY music menu/player

Post by daveZX4th » Tue Jan 02, 2018 3:44 pm

Thanks Andy, your source reduced what would have been a week or two of head scratching to about one day :-)

Though I was a bit puzzled with the CLEAR_AY_ENV_SHAPE routine until I realised it would have to deal with false retriggering of the AY envelope. Here's my take on it:

Code: Select all

CHANNEL_1_PROG_STORE_MINUS_2:  $00 no envelope (default/ornament set)
                               $01 envelope shape to be sent
                               $02 envelope shape already sent

CLEAR_AY_ENV_SHAPE:

L4393   ld      a,(iy+#07)
        inc     a               ;is this channel 'off'?
        ret     z               ;yes, return (amplitude register M=0)
        ld      a,(iy-#02)      ;else
        or      a               ;no envelope for this channel?
        ret     z               ;yes, return (amplitude register M=0)
        cp      #02             ;else has envelope shape already been sent?
        jp      z,L43a9         ;yes, so prevent any retriggering
        ld      (iy-#02),#02    ;else block it for next call, but for this call
        jp      L43ad           ;allow envelope shape (3 to E) to be sent

L43a9   xor     a               ;zero (means envelope registers won't get re-sent)
        ld      (L41d0),a       ;envelope shape register
L43ad   set     4,(hl)          ;set amplitude register M bit for this channel
        ret                     ;(M=1 use AY envelope for this channels amplitude)

User avatar
Andy Rea
Posts: 1521
Joined: Fri May 09, 2008 2:48 pm
Location: notts UK

Re: AY music menu/player

Post by Andy Rea » Tue Jan 02, 2018 6:10 pm

Glad it was of use, as you can probably guess my annotations are my best guess at what's what... And yeah it took a while and plenty of single stepping the code to work it out.

Regards Andy
6 x ZX81, 1 x TS1500 , 1 x +3e, 1 x timex 2040 printer, 1 x timex 2020 cassette deck, siclair printer and some spectrum

Post Reply