@@ -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, Waves, Song, EmulationThread, Utils, Constants, |
9 |
FileUtil, math, Instruments, Waves, Song, Utils, Constants, |
| 10 |
sound, vars, machine, about_hugetracker, TrackerGrid, lclintf, lmessages, |
10 |
sound, vars, machine, about_hugetracker, TrackerGrid, lclintf, lmessages, |
| 11 |
Buttons, Grids, DBCtrls, HugeDatatypes, LCLType, Clipbrd, RackCtls, Codegen, |
11 |
Buttons, Grids, DBCtrls, HugeDatatypes, LCLType, Clipbrd, RackCtls, Codegen, |
| 12 |
SymParser, options, IniFiles, bgrabitmap, effecteditor, RenderToWave, |
12 |
SymParser, options, IniFiles, bgrabitmap, effecteditor, RenderToWave, |
| 13 |
modimport, strutils, Types; |
13 |
modimport, mainloop, strutils, Types; |
| 14 |
|
14 |
|
| 15 |
type |
15 |
type |
| 16 |
{ TfrmTracker } |
16 |
{ TfrmTracker } |
@@ -370,8 +370,6 @@ type |
| 370 |
CurrentInstrumentBank: TInstrumentType; |
370 |
CurrentInstrumentBank: TInstrumentType; |
| 371 |
LoadedFileName: String; |
371 |
LoadedFileName: String; |
| 372 |
|
372 |
|
| 373 |
EmulationThread: TThread; |
|
|
| 374 |
|
|
|
| 375 |
PreviewingInstrument: Integer; |
373 |
PreviewingInstrument: Integer; |
| 376 |
DrawingWave: Boolean; |
374 |
DrawingWave: Boolean; |
| 377 |
Playing: Boolean; |
375 |
Playing: Boolean; |
@@ -401,8 +399,11 @@ type |
| 401 |
procedure CopyOrderMatrixToOrderGrid; |
399 |
procedure CopyOrderMatrixToOrderGrid; |
| 402 |
procedure CopyWaveIntoWaveRam(Wave: Integer); |
400 |
procedure CopyWaveIntoWaveRam(Wave: Integer); |
| 403 |
function ConvertWaveToHexString(Wave: Integer): String; |
401 |
function ConvertWaveToHexString(Wave: Integer): String; |
| 404 |
function PreparePreview: Boolean; |
402 |
|
| 405 |
procedure ResetEmulationThread; |
403 |
function GetPreviewReady: Boolean; |
|
|
404 |
procedure GetROMReady(ROM: String); |
|
|
405 |
procedure HaltPlayback; |
|
|
406 |
procedure FDCallback; |
| 406 |
|
407 |
|
| 407 |
procedure OnFD(var Msg: TLMessage); message LM_FD; |
408 |
procedure OnFD(var Msg: TLMessage); message LM_FD; |
| 408 |
procedure OnUndoOccured(var Msg: TLMessage); message LM_UNDO_OCCURED; |
409 |
procedure OnUndoOccured(var Msg: TLMessage); message LM_UNDO_OCCURED; |
@@ -441,7 +442,7 @@ procedure TfrmTracker.UpdateUIAfterLoad(FileName: String = ''); |
| 441 |
var |
442 |
var |
| 442 |
I: Integer; |
443 |
I: Integer; |
| 443 |
begin |
444 |
begin |
| 444 |
ResetEmulationThread; |
445 |
HaltPlayback; |
| 445 |
|
446 |
|
| 446 |
LoadingFile := True; // HACK!!!!! |
447 |
LoadingFile := True; // HACK!!!!! |
| 447 |
LoadInstrument(itSquare, 1); |
448 |
LoadInstrument(itSquare, 1); |
@@ -669,9 +670,7 @@ procedure TfrmTracker.PreviewInstrument(Freq: Integer; Instr: TInstrument; |
| 669 |
var |
670 |
var |
| 670 |
Regs: TRegisters; |
671 |
Regs: TRegisters; |
| 671 |
begin |
672 |
begin |
| 672 |
// TODO: Find some way to synchronize with the playback thread, so it doesn't |
673 |
LockPlayback; |
| 673 |
// fail sometimes. |
|
|
| 674 |
|
|
|
| 675 |
with Instr do |
674 |
with Instr do |
| 676 |
begin |
675 |
begin |
| 677 |
case Type_ of |
676 |
case Type_ of |
@@ -710,6 +709,7 @@ begin |
| 710 |
end; |
709 |
end; |
| 711 |
end; |
710 |
end; |
| 712 |
end; |
711 |
end; |
|
|
712 |
UnlockPlayback; |
| 713 |
end; |
713 |
end; |
| 714 |
|
714 |
|
| 715 |
procedure TfrmTracker.PreviewC5; |
715 |
procedure TfrmTracker.PreviewC5; |
@@ -723,6 +723,7 @@ end; |
| 723 |
|
723 |
|
| 724 |
procedure TfrmTracker.Panic; |
724 |
procedure TfrmTracker.Panic; |
| 725 |
begin |
725 |
begin |
|
|
726 |
LockPlayback; |
| 726 |
// Silence CH1 |
727 |
// Silence CH1 |
| 727 |
Spokeb(NR12, 0); |
728 |
Spokeb(NR12, 0); |
| 728 |
Spokeb(NR14, %10000000); |
729 |
Spokeb(NR14, %10000000); |
@@ -737,6 +738,7 @@ begin |
| 737 |
// Silence CH4 |
738 |
// Silence CH4 |
| 738 |
Spokeb(NR42, 0); |
739 |
Spokeb(NR42, 0); |
| 739 |
Spokeb(NR44, %10000000); |
740 |
Spokeb(NR44, %10000000); |
|
|
741 |
UnlockPlayback; |
| 740 |
end; |
742 |
end; |
| 741 |
|
743 |
|
| 742 |
procedure TfrmTracker.OnTrackerGridResize(Sender: TObject); |
744 |
procedure TfrmTracker.OnTrackerGridResize(Sender: TObject); |
@@ -860,7 +862,7 @@ begin |
| 860 |
Result += hexStr(CurrentWave^[I], 1); |
862 |
Result += hexStr(CurrentWave^[I], 1); |
| 861 |
end; |
863 |
end; |
| 862 |
|
864 |
|
| 863 |
function TfrmTracker.PreparePreview: Boolean; |
865 |
function TfrmTracker.GetPreviewReady: Boolean; |
| 864 |
var |
866 |
var |
| 865 |
I: Integer; |
867 |
I: Integer; |
| 866 |
begin |
868 |
begin |
@@ -869,9 +871,8 @@ begin |
| 869 |
SymbolTable := ParseSymFile('hUGEDriver/preview.sym'); |
871 |
SymbolTable := ParseSymFile('hUGEDriver/preview.sym'); |
| 870 |
|
872 |
|
| 871 |
// Start emulation on the rendered preview binary |
873 |
// Start emulation on the rendered preview binary |
| 872 |
StopPlayback; |
874 |
LockPlayback; |
| 873 |
EmulationThread.Free; |
875 |
GetROMReady('hUGEDriver/preview.gb'); |
| 874 |
EmulationThread := TEmulationThread.Create('hUGEDriver/preview.gb'); |
|
|
| 875 |
PokeSymbol(SYM_TICKS_PER_ROW, Song.TicksPerRow); |
876 |
PokeSymbol(SYM_TICKS_PER_ROW, Song.TicksPerRow); |
| 876 |
for I := 0 to 3 do |
877 |
for I := 0 to 3 do |
| 877 |
snd[I+1].ChannelOFF := HeaderControl1.Sections[I].ImageIndex = 0; |
878 |
snd[I+1].ChannelOFF := HeaderControl1.Sections[I].ImageIndex = 0; |
@@ -881,7 +882,18 @@ begin |
| 881 |
else Result := False; |
882 |
else Result := False; |
| 882 |
end; |
883 |
end; |
| 883 |
|
884 |
|
| 884 |
procedure TfrmTracker.ResetEmulationThread; |
885 |
procedure TfrmTracker.GetROMReady(ROM: String); |
|
|
886 |
begin |
|
|
887 |
z80_reset; |
|
|
888 |
ResetSound; |
|
|
889 |
enablesound; |
|
|
890 |
|
|
|
891 |
vars.FDCallback := @Self.FDCallback; |
|
|
892 |
|
|
|
893 |
load(ROM); |
|
|
894 |
end; |
|
|
895 |
|
|
|
896 |
procedure TfrmTracker.HaltPlayback; |
| 885 |
begin |
897 |
begin |
| 886 |
Playing := False; |
898 |
Playing := False; |
| 887 |
|
899 |
|
@@ -891,10 +903,13 @@ begin |
| 891 |
ToolButton2.ImageIndex := 74; |
903 |
ToolButton2.ImageIndex := 74; |
| 892 |
|
904 |
|
| 893 |
LockPlayback; |
905 |
LockPlayback; |
| 894 |
EmulationThread.Free; |
906 |
GetROMReady('halt.gb'); |
| 895 |
EmulationThread := TEmulationThread.Create('halt.gb'); |
|
|
| 896 |
UnlockPlayback; |
907 |
UnlockPlayback; |
| 897 |
//EmulationThread.Start; |
908 |
end; |
|
|
909 |
|
|
|
910 |
procedure TfrmTracker.FDCallback; |
|
|
911 |
begin |
|
|
912 |
PostMessage(frmTracker.Handle, LM_FD, 0, 0); |
| 898 |
end; |
913 |
end; |
| 899 |
|
914 |
|
| 900 |
procedure TfrmTracker.OnFD(var Msg: TLMessage); |
915 |
procedure TfrmTracker.OnFD(var Msg: TLMessage); |
@@ -1209,11 +1224,8 @@ begin |
| 1209 |
|
1224 |
|
| 1210 |
// Get the emulator ready to make sound... |
1225 |
// Get the emulator ready to make sound... |
| 1211 |
EnableSound; |
1226 |
EnableSound; |
| 1212 |
|
|
|
| 1213 |
EmulationThread := TEmulationThread.Create('halt.gb'); |
|
|
| 1214 |
StartPlayback; |
1227 |
StartPlayback; |
| 1215 |
//EmulationThread.Start; |
1228 |
HaltPlayback; //TODO: remove this hack |
| 1216 |
ResetEmulationThread; //TODO: remove this hack |
|
|
| 1217 |
|
1229 |
|
| 1218 |
// Start the Oscilloscope repaint timer |
1230 |
// Start the Oscilloscope repaint timer |
| 1219 |
OscilloscopeUpdateTimer.Enabled := ScopesOn; |
1231 |
OscilloscopeUpdateTimer.Enabled := ScopesOn; |
@@ -1935,19 +1947,12 @@ begin |
| 1935 |
if OrderEditStringGrid.Row > -1 then |
1947 |
if OrderEditStringGrid.Row > -1 then |
| 1936 |
ReloadPatterns; |
1948 |
ReloadPatterns; |
| 1937 |
|
1949 |
|
| 1938 |
if Playing then begin |
1950 |
{if Playing then begin |
| 1939 |
if TrackerGrid.HighlightedRow <> 0 then begin |
1951 |
LockPlayback; |
| 1940 |
if OrderEditStringGrid.Row = 1 then begin |
1952 |
PokeSymbol(SYM_CURRENT_ORDER, 2*(OrderEditStringGrid.Row-1)); |
| 1941 |
if PreparePreview then |
1953 |
PokeSymbol(SYM_ROW, 0); |
| 1942 |
Playing := True; |
1954 |
UnlockPlayback; |
| 1943 |
end |
1955 |
end} |
| 1944 |
else begin |
|
|
| 1945 |
PokeSymbol(SYM_CURRENT_ORDER, 2*(OrderEditStringGrid.Row-2)); |
|
|
| 1946 |
PokeSymbol(SYM_ROW, 63); |
|
|
| 1947 |
end; |
|
|
| 1948 |
end; |
|
|
| 1949 |
//EmulationThread.Start; |
|
|
| 1950 |
end |
|
|
| 1951 |
end; |
1956 |
end; |
| 1952 |
|
1957 |
|
| 1953 |
procedure TfrmTracker.OrderEditStringGridColRowDeleted(Sender: TObject; |
1958 |
procedure TfrmTracker.OrderEditStringGridColRowDeleted(Sender: TObject; |
@@ -1983,19 +1988,13 @@ procedure TfrmTracker.OrderEditStringGridDblClick(Sender: TObject); |
| 1983 |
var |
1988 |
var |
| 1984 |
Highest: Integer; |
1989 |
Highest: Integer; |
| 1985 |
begin |
1990 |
begin |
| 1986 |
if Playing then begin |
1991 |
{if Playing then begin |
| 1987 |
if OrderEditStringGrid.Row = 1 then begin |
1992 |
LockPlayback; |
| 1988 |
if PreparePreview then begin |
1993 |
PokeSymbol(SYM_CURRENT_ORDER, 2*(OrderEditStringGrid.Row-1)); |
| 1989 |
Playing := True; |
1994 |
PokeSymbol(SYM_ROW, 0); |
| 1990 |
end; |
1995 |
UnlockPlayback; |
| 1991 |
end |
|
|
| 1992 |
else begin |
|
|
| 1993 |
PokeSymbol(SYM_CURRENT_ORDER, 2*(OrderEditStringGrid.Row-2)); |
|
|
| 1994 |
PokeSymbol(SYM_ROW, 63); |
|
|
| 1995 |
end; |
|
|
| 1996 |
//EmulationThread.Start; |
|
|
| 1997 |
end |
1996 |
end |
| 1998 |
else begin |
1997 |
else} begin |
| 1999 |
Highest := Song.Patterns.MaxKey; |
1998 |
Highest := Song.Patterns.MaxKey; |
| 2000 |
|
1999 |
|
| 2001 |
with OrderEditStringGrid do begin |
2000 |
with OrderEditStringGrid do begin |
@@ -2088,41 +2087,37 @@ end; |
| 2088 |
|
2087 |
|
| 2089 |
procedure TfrmTracker.ToolButton10Click(Sender: TObject); |
2088 |
procedure TfrmTracker.ToolButton10Click(Sender: TObject); |
| 2090 |
begin |
2089 |
begin |
| 2091 |
//EmulationThread.Terminate; |
|
|
| 2092 |
StopPlayback; |
|
|
| 2093 |
if RenderPreviewROM(Song) then begin |
2090 |
if RenderPreviewROM(Song) then begin |
| 2094 |
SymbolTable := ParseSymFile('hUGEDriver/preview.sym'); |
2091 |
SymbolTable := ParseSymFile('hUGEDriver/preview.sym'); |
| 2095 |
frmRenderToWave.ShowModal; |
2092 |
frmRenderToWave.ShowModal; |
| 2096 |
ResetEmulationThread; |
2093 |
HaltPlayback; |
| 2097 |
end; |
2094 |
end; |
| 2098 |
end; |
2095 |
end; |
| 2099 |
|
2096 |
|
| 2100 |
procedure TfrmTracker.ToolButton2Click(Sender: TObject); |
2097 |
procedure TfrmTracker.ToolButton2Click(Sender: TObject); |
| 2101 |
begin |
2098 |
begin |
| 2102 |
if PreparePreview then begin |
2099 |
if GetPreviewReady then begin |
| 2103 |
Playing := True; |
2100 |
Playing := True; |
| 2104 |
|
2101 |
|
| 2105 |
PokeSymbol(SYM_CURRENT_ORDER, 2*(OrderEditStringGrid.Row-1)); |
2102 |
PokeSymbol(SYM_CURRENT_ORDER, 2*(OrderEditStringGrid.Row-1)); |
| 2106 |
PokeSymbol(SYM_ROW, TrackerGrid.Cursor.Y); |
2103 |
PokeSymbol(SYM_ROW, TrackerGrid.Cursor.Y); |
| 2107 |
|
2104 |
|
| 2108 |
StartPlayback; |
2105 |
UnlockPlayback; |
| 2109 |
//EmulationThread.Start; |
|
|
| 2110 |
end |
2106 |
end |
| 2111 |
end; |
2107 |
end; |
| 2112 |
|
2108 |
|
| 2113 |
procedure TfrmTracker.ToolButton3Click(Sender: TObject); |
2109 |
procedure TfrmTracker.ToolButton3Click(Sender: TObject); |
| 2114 |
begin |
2110 |
begin |
| 2115 |
if PreparePreview then begin |
2111 |
if GetPreviewReady then begin |
| 2116 |
Playing := True; |
2112 |
Playing := True; |
| 2117 |
StartPlayback; |
2113 |
UnlockPlayback; |
| 2118 |
//EmulationThread.Start; |
|
|
| 2119 |
end; |
2114 |
end; |
| 2120 |
end; |
2115 |
end; |
| 2121 |
|
2116 |
|
| 2122 |
procedure TfrmTracker.ToolButton4Click(Sender: TObject); |
2117 |
procedure TfrmTracker.ToolButton4Click(Sender: TObject); |
| 2123 |
begin |
2118 |
begin |
| 2124 |
TrackerGrid.HighlightedRow := -1; |
2119 |
TrackerGrid.HighlightedRow := -1; |
| 2125 |
ResetEmulationThread; |
2120 |
HaltPlayback; |
| 2126 |
end; |
2121 |
end; |
| 2127 |
|
2122 |
|
| 2128 |
procedure TfrmTracker.ExportGBButtonClick(Sender: TObject); |
2123 |
procedure TfrmTracker.ExportGBButtonClick(Sender: TObject); |