Skip to content

Instantly share code, notes, and snippets.

@podstawek
Last active April 11, 2022 17:46
Show Gist options
  • Save podstawek/f3ee0982d49f8613da40bb2b270bf9af to your computer and use it in GitHub Desktop.
Save podstawek/f3ee0982d49f8613da40bb2b270bf9af to your computer and use it in GitHub Desktop.
;-----------------------------------------
; Adapted from the original Lisa ROM listing
; https://www.apple.asimov.net/documentation/applelisa/AppleLisa-BootROMListing.pdf
; D0 = desired frequency ($00 - $AA)
; D1 = duration (0 = .5 msec)
; D2 = volume (0,2,4,...,E)
; D3 = pulse train shape as a string of 8 bits
;-----------------------------------------
ORG $800
VIA1BASE EQU $00FCDD81
ORB1 EQU $0
DDRB1 EQU $4
T2CL1 EQU $10
SHR1 EQU $14
ACR1 EQU $16
DISKROM EQU $FCC031
SLOTMR EQU 5
; approximate pitches
d_sharp_3 EQU $CC
e_3 EQU $C2
f_3 EQU $B7
f_sharp_3 EQU $AA ; 186Hz, should be 185
g_3 EQU $A1 ; 196 Hz, close enough
g_sharp_3 EQU $98 ; 207 Hz, close enough
a_3 EQU $90 ; 219, should be 220
a_sharp_3 EQU $87 ; 234, should be 233
b_3 EQU $80
c_4 EQU $78
c_sharp_4 EQU $70
d_4 EQU $6B ; 295 Hz, should be closer to 293.7
d_sharp_4 EQU $65
e_4 EQU $60
f_4 EQU $59
f_sharp_4 EQU $55 ;369Hz
g_4 EQU $50
g_sharp_4 EQU $4B ; 419 Hz, should be 415
a_4 EQU $47 ; 442 Hz, should be 440
a_sharp_4 EQU $43 ; 468 Hz, should be 466
b_4 EQU $3F ; 497 Hz, should be 494
c_5 EQU $3C ; 517 Hz, should be 523
c_sharp_5 EQU $38 ; 553 Hz, should be 554
d_5 EQU $35 ; 585 Hz, should be 587
d_sharp_5 EQU $32 ; 622 Hz, close enough
e_5 EQU $2F ; 663 Hz, should be 659
f_5 EQU $2C ;
f_sharp_5 EQU $2A ; 737 Hz, should be 740
g_5 EQU $27 ; 796 Hz, very far should be 784
g_sharp_5 EQU $25 ;
a_5 EQU $23 ; 884 Hz, should be 880
pause EQU $0 ; 0 frequency is silence
; approximate note values at 120 bpm
sixtyfour EQU $40
thirtytwo EQU $80
sixteen EQU $100
eight EQU $200
eightplus EQU eight+sixteen
quarter EQU $400
half EQU $800
whole EQU $1000
MUSIC
MOVE.W #%11110000,D3 ; pulse train shape
MOVE.w #e_5,D0 ; pitch
MOVE.w #quarter,D1 ; duration
MOVE.W #$2,D2 ; volume
BSR TONE2
MOVE.w #d_5,D0
MOVE.w #eight,D1
MOVE.W #$4,D2
BSR TONE2
MOVE.W #%01011101,D3
MOVE.w #c_5,D0
MOVE.w #sixteen,D1
MOVE.W #$6,D2
BSR TONE2
TONE MOVEM.L A0/A4/D4,-(SP) ;save regs
BSR TONE2 ;go do tone
LEA zero,A4
BRA.S TONE2
RTS
zero
MOVEM.L (SP)+,A0/A4/D4 ;restore and exit
RTS
; separate entry point for call without memory usage
TONE2 MOVEA.L #VIA1BASE,A0 ;set VIA ptr
ORI.B #$0E,DDRB1(A0) ;set volume bits for output
ANDI.B #$F1,ORB1(A0) ;clear and then
OR.B D2,ORB1(A0) ; set volume bits
ANDI.B #$E3,ACR1(A0) ;clear shift mode bits
ORI.B #$10,ACR1(A0) ;set shift reg for continuous rotate
; check system type
TST.B DISKROM ;test for Lisa 1 board CHG014
BPL.S three ;no changes if yes CHG014
BTST #SLOTMR,DISKROM ;else check if slow timers CHG029
BNE.S three ;skip if yes CHG029
MOVE.B D0,D4 ;else adjust input parm CHG014
LSR.B #2,D4 ; by factor of .25 CHG014
ADD.B D4,D0 ; CHG014
three MOVE.B D0,T2CL1(A0) ;set frequency
MOVE.B D3,SHR1(A0) ;set pulse train
; Do time delay - enter with count in D1 (about .5 msec per count)
one MOVE.W #$00D0,D4 ;set delay constant
two DBF D4,two
DBF D1,one
SILENCE ANDI.B #$E3,ACR1(A0) ;disable tone
RTS ;and return
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment