Commit 210d627

Nick Faro committed on
Fully working instrument preview
commit 210d6278e1173da39fe79ffd4ad822b25f6b1317 parent bcf6302
6 changed files +122−66
Modifiedconstants.pas +8−0
@@ -28,6 +28,14 @@ const
28 SYM_TICKS_PER_ROW = 'ticks_per_row'; 28 SYM_TICKS_PER_ROW = 'ticks_per_row';
29 SYM_ORDER_COUNT = 'order_cnt'; 29 SYM_ORDER_COUNT = 'order_cnt';
30 30
31 SYM_HALT_INSTR = 'instrument';
32 SYM_HALT_PERIOD = 'channel_period';
33 SYM_HALT_SUBPATTERN = 'subpattern';
34 SYM_HALT_START = 'start_ch';
35 SYM_HALT_RUNNING = 'running_ch';
36 SYM_HALT_WAVEFORMS = 'waveforms';
37 SYM_HALT_NOTE = 'channel_note';
38
31 // Sound controller registers 39 // Sound controller registers
32 NR10 = $FF10; 40 NR10 = $FF10;
33 NR11 = $FF11; 41 NR11 = $FF11;
ModifiedhUGETracker.lpi +6−1
@@ -208,7 +208,7 @@
208 <PackageName Value="LCL"/> 208 <PackageName Value="LCL"/>
209 </Item5> 209 </Item5>
210 </RequiredPackages> 210 </RequiredPackages>
211 <Units Count="26"> 211 <Units Count="27">
212 <Unit0> 212 <Unit0>
213 <Filename Value="hUGETracker.lpr"/> 213 <Filename Value="hUGETracker.lpr"/>
214 <IsPartOfProject Value="True"/> 214 <IsPartOfProject Value="True"/>
@@ -345,6 +345,11 @@
345 <IsPartOfProject Value="True"/> 345 <IsPartOfProject Value="True"/>
346 <UnitName Value="TBMImport"/> 346 <UnitName Value="TBMImport"/>
347 </Unit25> 347 </Unit25>
348 <Unit26>
349 <Filename Value="instrumentpreview.pas"/>
350 <IsPartOfProject Value="True"/>
351 <UnitName Value="InstrumentPreview"/>
352 </Unit26>
348 </Units> 353 </Units>
349 </ProjectOptions> 354 </ProjectOptions>
350 <CompilerOptions> 355 <CompilerOptions>
Modifiedhalt.asm +9−1
@@ -36,6 +36,8 @@ subpattern2: ds (3*64)
36 subpattern3: ds (3*64) 36 subpattern3: ds (3*64)
37 subpattern4: ds (3*64) 37 subpattern4: ds (3*64)
38 38
39 waveforms: ds (16*16)
40
39 start_zero: 41 start_zero:
40 42
41 start_ch1: db 43 start_ch1: db
@@ -61,7 +63,6 @@ init_note1:
61 ld a, [hl+] 63 ld a, [hl+]
62 ldh [rAUD1ENV], a 64 ldh [rAUD1ENV], a
63 ld a, [hl] 65 ld a, [hl]
64 ; ld a, 0
65 ld [highmask1], a 66 ld [highmask1], a
66 67
67 xor a 68 xor a
@@ -212,6 +213,13 @@ _addr = _addr + 1
212 xor a 213 xor a
213 ld [row], a 214 ld [row], a
214 215
216 ;; Setup waves pointer
217 ld hl, waves
218 ld a, LOW(waveforms)
219 ld [hl+], a
220 ld a, HIGH(waveforms)
221 ld [hl], a
222
215 ;; Zero some ram 223 ;; Zero some ram
216 ld c, end_zero - start_zero 224 ld c, end_zero - start_zero
217 ld hl, start_zero 225 ld hl, start_zero
Addedinstrumentpreview.pas +67−0
@@ -0,0 +1,67 @@
1 unit InstrumentPreview;
2
3 {$mode ObjFPC}{$H+}
4
5 interface
6
7 uses
8 Classes, SysUtils, instruments, constants, hugedatatypes, symparser, machine, utils;
9
10 procedure StartInstrumentPreview(Instr: TInstrument; Note: Integer; SquareOnCh2: Boolean = False);
11 procedure StopInstrumentPreview(Channel: Integer);
12
13 implementation
14
15 function GetLabel(Constant: String; Number: Integer): String;
16 begin
17 Result := Constant+IntToStr(Number);
18 end;
19
20 procedure StartInstrumentPreview(Instr: TInstrument; Note: Integer; SquareOnCh2: Boolean);
21 var
22 Addr: Integer;
23 AsmInstrument: TAsmInstrument;
24 HighMask: Integer;
25 Channel: Integer;
26 begin
27 AsmInstrument := InstrumentToBytes(Instr);
28
29 case Instr.Type_ of
30 itSquare: if SquareOnCh2 then Channel := 2 else Channel := 1;
31 itWave: Channel := 3;
32 itNoise: Channel := 4;
33 end;
34
35 if Instr.Type_ = itNoise then begin
36 Addr := SymbolAddress(GetLabel(SYM_HALT_INSTR, Channel));
37 spokeb(Addr, AsmInstrument[1]);
38
39 HighMask := AsmInstrument[0];
40 if Instr.LengthEnabled then
41 HighMask := HighMask or %01000000;
42 if Instr.CounterStep = swSeven then
43 HighMask := HighMask or %10000000;
44 spokeb(Addr+3, HighMask);
45 end else begin
46 WriteBufferToSymbol(GetLabel(SYM_HALT_INSTR, Channel), AsmInstrument, SizeOf(TAsmInstrument));
47 end;
48
49 WriteBufferToSymbol(GetLabel(SYM_HALT_SUBPATTERN, Channel),
50 SubpatternToBytes(Instr.Subpattern),
51 SizeOf(TSubpatternBytes));
52
53 WordPokeSymbol(GetLabel(SYM_HALT_PERIOD, Channel), NotesToFreqs.KeyData[Note]);
54 PokeSymbol(GetLabel(SYM_HALT_NOTE, Channel), Note);
55
56 PokeSymbol(GetLabel(SYM_HALT_START, Channel), 1);
57 if Instr.SubpatternEnabled then
58 PokeSymbol(GetLabel(SYM_HALT_RUNNING, Channel), 1);
59 end;
60
61 procedure StopInstrumentPreview(Channel: Integer);
62 begin
63 PokeSymbol(GetLabel(SYM_HALT_RUNNING, Channel), 0);
64 end;
65
66 end.
67
Modifiedsymparser.pas +12−5
@@ -16,6 +16,7 @@ procedure WordPokeSymbol(Symbol: String; Value: Word);
16 function PeekSymbol(Symbol: String): Integer; 16 function PeekSymbol(Symbol: String): Integer;
17 procedure PokeSymbol(Symbol: String; Value: Byte); 17 procedure PokeSymbol(Symbol: String; Value: Byte);
18 procedure WriteBufferToSymbol(Symbol: String; const Buffer; Count: Integer); 18 procedure WriteBufferToSymbol(Symbol: String; const Buffer; Count: Integer);
19 procedure WriteBufferToAddress(Address: Integer; const Buffer; Count: Integer);
19 20
20 procedure ParseSymFile(F: String); 21 procedure ParseSymFile(F: String);
21 22
@@ -26,15 +27,18 @@ uses machine;
26 var 27 var
27 SymbolTable: TSymbolMap; 28 SymbolTable: TSymbolMap;
28 29
29 procedure WriteBufferToSymbol(Symbol: String; const Buffer; Count: Integer); 30
31 procedure WriteBufferToAddress(Address: Integer; const Buffer; Count: Integer);
30 var 32 var
31 I: Integer; 33 I: Integer;
32 Addr: Integer;
33 begin 34 begin
34 Addr := SymbolAddress(Symbol);
35
36 for I := 0 to Count-1 do 35 for I := 0 to Count-1 do
37 spokeb(Addr+I, PByte(@Buffer)[I]); 36 spokeb(Address+I, PByte(@Buffer)[I]);
37 end;
38
39 procedure WriteBufferToSymbol(Symbol: string; const Buffer; Count: Integer);
40 begin
41 WriteBufferToAddress(SymbolAddress(Symbol), Buffer, Count);
38 end; 42 end;
39 43
40 procedure ParseSymFile(F: String); 44 procedure ParseSymFile(F: String);
@@ -86,6 +90,9 @@ begin
86 WriteLn(StdErr, '[WARNING] Attempting to poke unloaded symbol: ', symbol); 90 WriteLn(StdErr, '[WARNING] Attempting to poke unloaded symbol: ', symbol);
87 Exit; 91 Exit;
88 end; 92 end;
93
94 writeln('poking ', symbol, ' with ', value);
95
89 spokeb(SymbolTable.KeyData[Symbol], Value); 96 spokeb(SymbolTable.KeyData[Symbol], Value);
90 end; 97 end;
91 98
Modifiedtracker.pas +20−59
@@ -6,11 +6,11 @@ interface
6 uses 6 uses
7 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, ComCtrls, 7 Classes, SysUtils, Forms, Controls, Graphics, Dialogs, ExtCtrls, ComCtrls,
8 Menus, Spin, StdCtrls, ActnList, StdActns, SynEdit, SynHighlighterAny, 8 Menus, Spin, StdCtrls, ActnList, StdActns, SynEdit, SynHighlighterAny,
9 FileUtil, math, Instruments, Song, Utils, Constants, 9 FileUtil, math, Instruments, Song, Utils, Constants, sound, vars, machine,
10 sound, vars, machine, about_hugetracker, TrackerGrid, lclintf, lmessages, 10 about_hugetracker, TrackerGrid, lclintf, lmessages, Buttons, Grids, DBCtrls,
11 Buttons, Grids, DBCtrls, HugeDatatypes, LCLType, Clipbrd, RackCtls, Codegen, 11 HugeDatatypes, LCLType, Clipbrd, RackCtls, Codegen, SymParser, options,
12 SymParser, options, bgrabitmap, effecteditor, RenderToWave, 12 bgrabitmap, effecteditor, RenderToWave, modimport, mainloop, strutils, Types,
13 modimport, mainloop, strutils, Types, Keymap, hUGESettings, vgm, TBMImport; 13 Keymap, hUGESettings, vgm, TBMImport, InstrumentPreview;
14 14
15 // TODO: Move to config file? 15 // TODO: Move to config file?
16 const 16 const
@@ -841,61 +841,23 @@ end;
841 procedure TfrmTracker.PreviewInstrument(Note: Integer; Instr: TInstrument; 841 procedure TfrmTracker.PreviewInstrument(Note: Integer; Instr: TInstrument;
842 SquareOnCh2: Boolean = False); 842 SquareOnCh2: Boolean = False);
843 var 843 var
844 Regs: TRegisters; 844 Addr: Integer;
845 AsmInstrument: TAsmInstrument; 845 Wave: TWave;
846 I, Addr, Freq: Integer;
847 HighMask: Integer;
848 begin 846 begin
849 Freq := NotesToFreqs.KeyData[Note];
850 AsmInstrument := InstrumentToBytes(Instr);
851
852 LockPlayback; 847 LockPlayback;
853 848
854 with Instr do 849 if Instr.Type_ = itWave then begin
855 begin 850 CopyWaveIntoWaveRam(Instr.Waveform);
856 case Type_ of
857 itSquare: begin
858 WriteBufferToSymbol('instrument1', AsmInstrument, SizeOf(TAsmInstrument));
859 WordPokeSymbol('channel_period1', NotesToFreqs.KeyData[Note]);
860 PokeSymbol('channel_note1', Note);
861 WriteBufferToSymbol('subpattern1', SubpatternToBytes(Instr.Subpattern), SizeOf(TSubpatternBytes));
862
863 PokeSymbol('start_ch1', 1);
864 if Instr.SubpatternEnabled then
865 PokeSymbol('running_ch1', 1);
866 end;
867 itWave: begin
868 CopyWaveIntoWaveRam(Waveform);
869
870 WriteBufferToSymbol('instrument3', AsmInstrument, SizeOf(TAsmInstrument));
871 WordPokeSymbol('channel_period3', NotesToFreqs.KeyData[Note]);
872 PokeSymbol('channel_note3', Note);
873 WriteBufferToSymbol('subpattern3', SubpatternToBytes(Instr.Subpattern), SizeOf(TSubpatternBytes));
874 851
875 PokeSymbol('start_ch3', 1); 852 Addr := SymbolAddress(SYM_HALT_WAVEFORMS);
876 if Instr.SubpatternEnabled then 853 for Wave in Song.Waves do begin
877 PokeSymbol('running_ch3', 1); 854 WriteBufferToAddress(Addr, ConvertWaveform(Wave), SizeOf(T4bitWave));
878 end; 855 Inc(Addr, SizeOf(T4bitWave));
879 itNoise: begin
880 Addr := SymbolAddress('instrument4');
881 spokeb(Addr, AsmInstrument[1]);
882
883 HighMask := AsmInstrument[0];
884 if Instr.LengthEnabled then
885 HighMask := HighMask or %01000000;
886 if Instr.CounterStep = swSeven then
887 HighMask := HighMask or %10000000;
888 spokeb(Addr+3, HighMask);
889
890 PokeSymbol('channel_note4', Note);
891 WriteBufferToSymbol('subpattern4', SubpatternToBytes(Instr.Subpattern), SizeOf(TSubpatternBytes));
892
893 PokeSymbol('start_ch4', 1);
894 if Instr.SubpatternEnabled then
895 PokeSymbol('running_ch4', 1);
896 end;
897 end; 856 end;
898 end; 857 end;
858
859 StartInstrumentPreview(Instr, Note, SquareOnCh2);
860
899 UnlockPlayback; 861 UnlockPlayback;
900 end; 862 end;
901 863
@@ -926,11 +888,10 @@ begin
926 Spokeb(NR42, 0); 888 Spokeb(NR42, 0);
927 Spokeb(NR44, %10000000); 889 Spokeb(NR44, %10000000);
928 890
929 // Stop running subpatterns 891 StopInstrumentPreview(1);
930 PokeSymbol('running_ch1', 0); 892 StopInstrumentPreview(2);
931 PokeSymbol('running_ch2', 0); 893 StopInstrumentPreview(3);
932 PokeSymbol('running_ch3', 0); 894 StopInstrumentPreview(4);
933 PokeSymbol('running_ch4', 0);
934 895
935 UnlockPlayback; 896 UnlockPlayback;
936 end; 897 end;