I have been told by setting the shift register on the via to 10101010 i can generate a continous square wave on the CB2 pin. However i am having trouble and my program does not seem to work.
i have come accross limited resources documenting this feature and all i have seen is that i should set bits 2-4 as 100 of ACR
Code: Select all
LDA #$08
STA $A00BApparently, by changing the values in timer 2, the rate at which the shifting is done should change:
Code: Select all
LDA #$C6
STA $A008
LDA #$01
STA A009Also do i need to set port B as an output or is this done automatically?
hopefuly then by connecting a speaker through a capacitor to CB2 this code will make a note
Any help really is GREATLY appreciated.
Code below!
Code: Select all
SETVAL: SET TEMPY=$00
SET TEMPX=$00
SET PAUSEX=$50 ;PAUSEX/Y set to 50k cycles
SET PAUSEY=$C3
SET NOTENUM=$00 ;note number - next note to play - 00=start
ORG $F800
SETCB2: LDA #$FF
STA $A002 ; set port B (CB2) as output
SRSET: LDA #$99 ; 10101010 goes into
STA $A00A ; shift register to be looped = pulse
TMRSET: LDA#$08 ; set shift reg to timer2 mode - timer 2 is then set to cont mode
STA $A00B
PLAY : LDY NOTENUM ; what note to play next
LDX TUNE,Y ; loads note number X from NOTES
INY ;increment note number
STY NOTENUM ;store next note
CPX #$01 ; check value from memory and play corresponding note
BEQ NOTEA
CPX #$02
BEQ NOTEB
CPX #$03
BEQ NOTEC
CPX #$04
BEQ NOTEC
CPX #$05
BEQ NOTED
CPX #$06
BEQ NOTEE
CPX #$07
BEQ NOTEF
CPX #$08
BEQ NOTEG
CPX #$FF ; FF symbolises end of tune
BEQ ENDJUMP
JSR WAIT
JMP PLAY ; jump back up to play next note
ENDJUMP: JMP TMRSTP
WAIT: STX TEMPX
STY TEMPY
LDX #$00 ;WAITS FOR SPECIFIED DURATION BETWEEN EACH NOTE
WOL: INX
LDY #$00
WIL: INY
CPY PAUSEY ;WAIT MULTIPLIER
BNE WIL
CPX PAUSEX ;WAIT DURATION
BNE WOL
LDY TEMPY
LDX TEMPX
INC
RTS
NOTEA: LDA #$C6 ; sets timer 2 to the corresponding note frequency
STA $A008 ;lsb
LDA #$01
STA $A009 ;msb
JMP PLAY
NOTEB: LDA #$94
STA $A008 ;lsb
LDA #$01
STA $A009 ;msb
JMP PLAY
NOTEC: LDA #$7E
STA $A008 ;lsb
LDA #$01
STA $A009 ;msb
JMP PLAY
NOTED: LDA #$54
STA $A008 ;lsb
LDA #$01
STA $A009 ;msb
JMP PLAY
NOTEE: LDA #$2F
STA $A008 ;lsb
LDA #$01
STA $A009 ;msb
JMP PLAY
NOTEF: LDA #$0E
STA $A008 ;lsb
LDA #$01
STA $A009 ;msb
JMP PLAY
NOTEG: LDA #$FF
STA $A008 ;lsb
LDA #$00
STA $A009 ;msb
JMP PLAY
TUNE : BYT #$01 ;NOTES FOR TUNE
BYT #$02
BYT #$03
BYT #$04
BYT #$05
BYT #$06
BYT #$07
BYT #$08
BYT #$07
BYT #$06
BYT #$05
BYT #$04
BYT #$03
BYT #$02
BYT #$01
BYT #$02
BYT #$04
BYT #$06
BYT #$08
BYT #$07
BYT #$05
BYT #$03
BYT #$01
BYT #$FF ;FF - end of tune
TMRSTP: LDA #$00 ; by setting shift reg to 000 it will
STA $A00B ; stop the timer and shift register
ORG $FFFC
WRD SETCB2
END ; the end