From 085cc148944aedac0e325be9623bb2c1b94c59cb Mon Sep 17 00:00:00 2001 From: Clyne Sullivan Date: Sat, 11 Jan 2025 17:59:48 -0500 Subject: [PATCH] play sound --- beep.ogg | Bin 0 -> 4361 bytes src/ada_chip.adb | 30 +++++++++++++++++++++++++----- src/cpu.ads | 1 - 3 files changed, 25 insertions(+), 6 deletions(-) create mode 100644 beep.ogg diff --git a/beep.ogg b/beep.ogg new file mode 100644 index 0000000000000000000000000000000000000000..a452254f20699e36480d99486c87fd39487f9eec GIT binary patch literal 4361 zcmai24O~-KvOf`o1Q8=d8fw}m2n#ntpTVGpT`Qodxj>N%K@&=?fr#NtNr2W>+$ezs ziV-0qM)b#5Py(S!fhzlItv2C92#AvS(LS_Ru;M;<>ssvEU3YGxt=sp0-Saz~oO|Y+ znKLv0nLC%b^z;NY3q5agr{kgIbcIxjD6dlrwkxD^CAmOZ(@y?Cd!J(eIYWsfPyW=% zlO(0I#Wat;=Gnis0Vf9|KF~MGcWiqzPLa;el1r29?Abzg$dZsHOO`L;vjYiPT7IfL zC!HOYQy^Dt&&ihM?b1axYb*^|e0t1Dw=M*yta*&pCN|-SGk)`P8oTyW{aZlFoa|`Kb7sZ5p z+g$y2*taK}G-3AxyGA4D1b2<$F}(4l)Q(SGQg$mXf~mUa1I?}n8}1V6;*&;?q>}7Q zv6fl|uyUxyMk-JftvkpNo@QJ+%^JS!7x!IIyjSSurBMlqu_9>sDH{u9wt{?HL7}*| zIQdMW_)Kx~wc?bS;w{XQ=lx0H#0=T(sDf+(FmUvGQucmYK?$F|mFsHjUTx7f|10=CQs>S}j~B-l{e@C{ox zs(Umn@X+0@Z)F_4@_AX}(SWn9wMXq9%(D300bgQ+M@;ocMs-Sy&|Rl@%yxPnbv3q* z!J5xhorl?H3+$7R>0Dc{Z-TSpQQhRpvkaJ(X^#eUpG|b|dk%}%ck3*l3vR=SvKvP; z&(cz0_Cs3T{|?j0wO_&~9Q?NB8q<7iAG=WFB4uz|IMuJ`9q_2G=k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 with Ada.Command_Line; with Ada.Numerics.Discrete_Random; with Ada.Text_IO; with Sf; +with Sf.Audio; +with Sf.Audio.Sound; +with Sf.Audio.SoundBuffer; with ISA; use ISA; with CPU; with Video; procedure Ada_Chip is + use Sf.Audio; + package Random_Byte is new Ada.Numerics.Discrete_Random (Byte); Steps_Per_Frame : constant := 8; State : CPU.Instance; Random_Generator : Random_Byte.Generator; + Delay_Timer : Byte := 0; + Sound_Timer : Byte := 0; + + Beep_Sound_Buffer : constant sfSoundBuffer_Ptr := + SoundBuffer.createFromFile ("beep.ogg"); + Beep_Sound : constant sfSound_Ptr := Sound.create; procedure Draw_Sprite (VX, VY : Register_Index; N : Byte) is use Sf; @@ -114,12 +125,13 @@ procedure Ada_Chip is end case; when Misc => case To_Byte (ins) is when 16#07# => - State.Registers (X_Register (ins)) := State.Delay_Timer; + State.Registers (X_Register (ins)) := Delay_Timer; when 16#0A# => State.Registers (X_Register (ins)) := Byte (Video.Next_Key); when 16#15# => - State.Delay_Timer := State.Registers (X_Register (ins)); - when 16#18# => null; -- TODO: sound + Delay_Timer := State.Registers (X_Register (ins)); + when 16#18# => + Sound_Timer := State.Registers (X_Register (ins)); when 16#1E# => State.Address_Register := State.Address_Register + Address (State.Registers (X_Register (ins))); @@ -160,18 +172,26 @@ begin Video.Initialize; Random_Byte.Reset (Random_Generator); CPU.Load_File (State, Ada.Command_Line.Argument (1)); + Sound.setBuffer (Beep_Sound, Beep_Sound_Buffer); while Video.Is_Running loop Video.Display; Video.Poll_Events; - if State.Delay_Timer > 0 then - State.Delay_Timer := State.Delay_Timer - 1; + if Delay_Timer > 0 then + Delay_Timer := Delay_Timer - 1; + end if; + + if Sound_Timer > 0 then + Sound.play (Beep_Sound); + Sound_Timer := Sound_Timer - 1; end if; for I in 0 .. Steps_Per_Frame loop Run_Step; end loop; end loop; + + Sound.destroy (Beep_Sound); end if; end Ada_Chip; diff --git a/src/cpu.ads b/src/cpu.ads index ebf2486..340375b 100644 --- a/src/cpu.ads +++ b/src/cpu.ads @@ -31,7 +31,6 @@ package CPU is Program_Counter : Address := Start_Address; Address_Register : Address := 0; Stack : Address_Stack.Vector; - Delay_Timer : Byte := 0; end record; procedure Load_File (Inst : in out Instance; File_Name : String);