Pink Music 
A program for the PAIA 8700
 by Bob Yannes and Steve Witham 
*= $0000
ADDR	CODE 		LABEL		INSTRUCTION		COMMENTS
0000	4C 03 00 	BPOINT 		JMP PINK 		BREAKPOINT TRAPS
0003	A2 FF		PINK		LDX #$FF		INITIALIZE
0005	9A						TXS				STACK POINTER. 
0006	D8 						CLD 			SET HEX MODE. 
0007	86 B1 					STX KEY 		INITIALIZE KEY. 
0009	A5 B1 		KEYLOOP		LDA KEY			GET KEY... 
000B	8D 20 08				STA DISP		AND SHOW IT. 
000E	E6 B1					INC KEY			NEXT KEY, 
0010	45 B1					EOR KEY			GET PATTERN OF CHANCED KEY BITS... 
0012	85 82					STA DELTA		AND STORE IT. 
0014	A2 04					LDX #VOXNUM		GET # OF VOICES, 
0016	A0 00					LDY #0			INITIALIZE RND COUNTER. 
0018	A9 00		VOXLOOP		LDA #0			CLEAR THE 
001A	95 B4					STA TOTAL-1,X	RUNNING SUM FOR VOICE #X. 
0010	A9 08					LDA #8			INITIALIZE BIT COUNTER... 
001E	85 B3					STA NUMBIT		AND STORE IT. 
0020	A5 B2 					LDA DELTA		GET CHANGED BIT PATTERN. 
0022	2A			RNDLOOP		ROL A			PREPARE TO TEST LEFTMOST BIT. 
0023	48						PHA				SAVE SHIFTED PATTERN. 
0024	90 0C					BCC ADDEM		BIT DIDN'T CHANGE--KEEP OLD RND #. 
0026	20 83 00	PICK		JSR RNDGEN		BIT DID CHANGE--GET NEW RND #. 
0029	29 07					AND #7			TRUNCATE IT. 
002B	C9 05					CMP #LIMIT+1	# OUT OF RANGE? 
002D	B0 F7					BCS PICK		YES, GO GET ANOTHER. 
002F	99 00 01				STA RANDOM,Y	NO STORE IT IN LOCATION Y. 
0032	B9 00 01	ADDEM		LDA RANDOM,Y	GET THE RANDOM # FROM LOCATION Y. 
0035	18						CLC				PREPARE TO ADD. 
0036	75 84					ADC TOTAL-1,X	ADD IT TO THE RUNNING SUM FOR VOICE # 
0038	95 B4					STA TOTAL-1,X	STORE THE RUNNING SUM (PINK #) FOR VO 
003A	C8 						INY				NEXT RND #
003B	68						PLA				GET SHIFTED PATTERN BACK. 
003C	C6 83					DEC				NUMBIT NEXT BIT. 
003E	D0 E2					BNE RNDLOOP		DONE ALL BITS? IP NO, GO DO NEXT. 
0040	CA						DEX				NEXT VOICES. 
0041	D0 D5					BNE VOXLOOP		DONE ALL VOICES? IF NO, GO DO NEXT. 
0043	A9 C0					LDA #ONBITS		PLAY NOTES WITH 
0045	20 5B 00				JSR PLAY		GATE & GLIDE FORCED ON. 
0048	A9 00					LDA #0			PLAY GATE & GLIDE ONLY 
004A	20 5B 00				JSR PLAY		ON SUSTAINED NOTES. 
004D	A2 04					LDX #VOXNUM		GET # OF VOICES, 
004F	B4 B4		SCALOOP		LDY TOTAL-1,X	GET PINK # FOR VOICE #X.
0051	89 RD 00				LDA SCALE,Y		USE IT AS POINTER FOR SCALE TABLE. 
0054	95 B8					STA OLD-1,X		STORE QUANTIZED NOTE FOR VOICE #X. 
0056	CA						DEX				NEXT VOICE. 
0057	D0 F6					BNE SCALOOP		DONE ALL VOICES? IF NO, GO DO NEXT. 
0059	F0 AE					BEQ KEYLOOP		BRANCH ALWAYS. 
005B	85 B4 		PLAY		STA NOTESTAT	STORE GATE & GLIDE STATUS.
005D	A9 20					LDA #TEMPO		INITIALIZE 
005F	85 DD					STA COUNTEMP	TEMPO COUNTER.
0061	A2 04		TEMPLOOP	LDX #VOXNUM		GET # OF VOICES.
0063	B5 B8		UPDATE		LDA OLD-1,X		GET NOTE TO BE PLAYED.(OLD NOTE) VOICE
0065	B4 B4					LDY TOTAL-1,X	GET NEW PINK # (POINTER) FOR VOICE #X.
0067	D9 BD 00				CMP SCALE,Y		OLD NOTE = NEW NOTE?
006A	D0 02					ENE CHOP		NO, GO CLEAR.
0060	09 C0					ORA #ONBITS		YES FORCE GATE & GLIDE ON.
006E	05 B4		CHOP		ORA NOTESTAT	CLEAR GATE & GLIDE UNLESS FORCED.
0070	8D 00 09				STA DAC			LET DAC SETTLE...
0073	9D FB 09				STA QUASH-1,X	SEND IT TO QUASH CHANNEL #X...
0076	A0 25					LDY #$25		AND DELAY
0078	88			SETTLE		DEY				UNTIL QUASH
0079	D0 FD					BNE SETTLE		SETTLES.
007B	CA						DEX				NEXT VOICE.
007C	D0 E5					BNB				UPDATE DONE ALL VOICES? IF NO, GO DO NEXT.
0078	C6 DD					DEC COUNTEMP	1 LESS TEMPO DELAY.
0080	D0 DF					ENE TEMPLOOP	DONS TEMPO DELAY? IF NO, DO IT ALL AG
0082	60						RTS				RETURN
0083	98			RNDGEN		TYA				SAVE
0084	48						PHA				Y
0085	A4 AC					LDY BYT1
0087	AS AD					LDA BYT2
0089	84 AD					STY BYT2		8YT2=OLD BYT1
0088	A4 AE					LDY BYT3
008D	85 AE					STA BYT3		BYT3=OLD BYT2.
008F	AS AF					LDA BYT4		ACCUM.=OLD BYT4.
0091	84 AF					STY BYT4		BYTA=OLD BYT3.
0093	84 B0					STY SHREG		SHREG=OLD BYT3.
0095	06 B0					ASL SHREG		SHIFTED ONCE
0097	2A						ROL A			INTO A.
0098	85 AC					STA BYT1
009A	06 B0					ASL SHREG		TWICE.
009C	2A						ROL A
009D	06 B0					ASL SHREG		THRICE.
009F	2A						ROL A
00A0	06 B0					ASL SHREG		FOURCE (FOURCE?).
00A2	2A						ROL A
00A3	45 AC					EOR BYT1		EXOR WITH ONCE-SHIFTED BITS.
00A5	85 AC					STA BYT1		BACK INTO BYT1 AS NEW RANDOM #.
00A7	68						PLA				GET Y
00A8	A8						TAY				BACK.
00A9	A5 AC					LDA BYT1		LOAD NEW RANDOM NUMBER.
0OAB	60						RTS				RETURN.

Data Storage
ADDRESS	NAME	ADDRESS		NAME.
OOAC 	EYT1	00B3		NUMBIT
00AD	BYT2	00B4		NOTESTAT
OOAE 	BYT3	00B5-00B8	TOTAL
00AF	BYT4	00B9-00BC	OLD
00B0	SHREG	00BD-OODC	SCALE
00B1	KEY		00DD		COUNTEMP
0082	DELTA	0100-011F	RANDOM 

