Skip to content

Commit

Permalink
buzzpirat sixth shoot
Browse files Browse the repository at this point in the history
  • Loading branch information
therealdreg committed Nov 13, 2023
1 parent 5508768 commit 22447f2
Show file tree
Hide file tree
Showing 10 changed files with 97 additions and 26 deletions.
Binary file removed buzzpirathlp.dll
Binary file not shown.
1 change: 1 addition & 0 deletions software/basehw.pas
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ TBaseHardware = class
procedure SPIDeinit; virtual; abstract;
function SPIRead(CS: byte; BufferLen: integer; var buffer: array of byte): integer; virtual; abstract;
function SPIWrite(CS: byte; BufferLen: integer; buffer: array of byte): integer; virtual; abstract;
function SPIWriteRead(CS: byte; WBufferLen: integer; WBuffer: array of byte;RBufferLen: integer; var RBuffer: array of byte): integer; virtual; abstract;

//I2C
procedure I2CInit; virtual; abstract;
Expand Down
Binary file modified software/buzzpirathlp.dll
Binary file not shown.
16 changes: 12 additions & 4 deletions software/buzzpirathlp/buzzpirathlp/buzzpirathlp.c
Original file line number Diff line number Diff line change
Expand Up @@ -651,14 +651,18 @@ BUZZPIRATHLP_API unsigned int __stdcall bhl_asprog_spi_readwrite_no_cs(unsigned
ComWriteByte(com_glb, size_wbuffer & 0x000000FF, 0);
ComWriteByte(com_glb, (size >> 8) & 0x000000FF, 0);
ComWriteByte(com_glb, size & 0x000000FF, 0);

Sleep(1);
if (size_wbuffer)
{
ComWriteBuff(com_glb, bufferw, size_wbuffer, 0);
for (i = 0; i < size_wbuffer; i++)
{
ComWriteByte(com_glb, bufferw[i], 0);
}
}

if (size)
{
Sleep(1);
do
{
if (end_fast)
Expand Down Expand Up @@ -1139,12 +1143,16 @@ BUZZPIRATHLP_API unsigned int __stdcall bhl_asprog_i2c_readwrite(unsigned int de
ComWriteByte(com_glb, (size_buffwr + 1) & 0x000000FF, 0);
ComWriteByte(com_glb, (size >> 8) & 0x000000FF, 0);
ComWriteByte(com_glb, size & 0x000000FF, 0);

Sleep(1);
ComWriteByte(com_glb, devaddr, 0);
if (size_buffwr)
{
ComWriteBuff(com_glb, buffwr, size_buffwr, 0);
for (i = 0; i < size_buffwr; i++)
{
ComWriteByte(com_glb, buffwr[i], 0);
}
}
Sleep(1);

do
{
Expand Down
8 changes: 4 additions & 4 deletions software/buzzpirathlp/buzzpirathlp/buzzpirathlp.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@
<EnableUAC>false</EnableUAC>
</Link>
<PostBuildEvent>
<Command>xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\ &amp;&amp; xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\..\</Command>
<Command>xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|Win32'">
Expand All @@ -133,7 +133,7 @@
<EnableUAC>false</EnableUAC>
</Link>
<PostBuildEvent>
<Command>xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\ &amp;&amp; xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\..\</Command>
<Command>xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Debug|x64'">
Expand All @@ -154,7 +154,7 @@
<EnableUAC>false</EnableUAC>
</Link>
<PostBuildEvent>
<Command>xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\ &amp;&amp; xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\..\</Command>
<Command>xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemDefinitionGroup Condition="'$(Configuration)|$(Platform)'=='Release|x64'">
Expand All @@ -179,7 +179,7 @@
<EnableUAC>false</EnableUAC>
</Link>
<PostBuildEvent>
<Command>xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\ &amp;&amp; xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\..\</Command>
<Command>xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\</Command>
</PostBuildEvent>
</ItemDefinitionGroup>
<ItemGroup>
Expand Down
30 changes: 30 additions & 0 deletions software/buzzpirathw.pas
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ TBuzzpiratHardware = class(TBaseHardware)
//spi
function SPIRead(CS: byte; BufferLen: integer; var buffer: array of byte): integer; override;
function SPIWrite(CS: byte; BufferLen: integer; buffer: array of byte): integer; override;
function SPIWriteRead(CS: byte; WBufferLen: integer; WBuffer: array of byte; RBufferLen: integer; var RBuffer: array of byte): integer; override;
function SPIInit(speed: integer): boolean; override;
procedure SPIDeinit; override;

Expand Down Expand Up @@ -358,6 +359,31 @@ procedure TBuzzpiratHardware.SPIDeinit;
if not FDevOpened then Exit;
end;

function TBuzzpiratHardware.SPIWriteRead(CS: byte; WBufferLen: integer; WBuffer: array of byte; RBufferLen: integer; var RBuffer: array of byte): integer;
var
sMessage: pbyte;
i: Integer;
begin
if not FDevOpened then Exit(-1);

if RBufferLen > 0 then FillChar(RBuffer, RBufferLen - 1, 105);

BhlSPICsLow();
if BhlSPIReadWriteNoCs(RBufferLen, @WBuffer[0], WBufferLen) <> 1 then
begin
BhlSPICsHigh();
LogPrint('Error SPIRead BhlSPIReadWriteNoCs');
Exit(-1);
end;
BhlSPICsHigh();

sMessage := BhlSPIGetMemaux();

for i := 0 to RBufferLen - 1 do
RBuffer[i] := sMessage[i];
result := RBufferLen;
end;

function TBuzzpiratHardware.SPIRead(CS: byte; BufferLen: integer; var buffer: array of byte): integer;
var
sMessage: pbyte;
Expand All @@ -372,6 +398,7 @@ function TBuzzpiratHardware.SPIRead(CS: byte; BufferLen: integer; var buffer: ar
BhlSPICsLow();
if BhlSPIReadWriteNoCs(BufferLen, nil, 0) <> 1 then
begin
BhlSPICsHigh();
LogPrint('Error SPIRead BhlSPIReadWriteNoCs (CS:1)');
Exit(-1);
end;
Expand All @@ -382,6 +409,7 @@ function TBuzzpiratHardware.SPIRead(CS: byte; BufferLen: integer; var buffer: ar
BhlSPICsLow();
if BhlSPIReadWriteNoCs(BufferLen, nil, 0) <> 1 then
begin
BhlSPICsHigh();
LogPrint('Error SPIRead BhlSPIReadWriteNoCs (CS:0)');
Exit(-1);
end;
Expand All @@ -403,6 +431,7 @@ function TBuzzpiratHardware.SPIWrite(CS: byte; BufferLen: integer; buffer: array
BhlSPICsLow();
if BhlSPIReadWriteNoCs(0, @buffer[0], BufferLen) <> 1 then
begin
BhlSPICsHigh();
LogPrint('Error SPIRead BhlSPIReadWriteNoCs (CS:1)');
Exit(-1);
end;
Expand All @@ -413,6 +442,7 @@ function TBuzzpiratHardware.SPIWrite(CS: byte; BufferLen: integer; buffer: array
BhlSPICsLow();
if BhlSPIReadWriteNoCs(0, @buffer[0], BufferLen) <> 1 then
begin
BhlSPICsHigh();
LogPrint('Error SPIRead BhlSPIReadWriteNoCs (CS:0)');
Exit(-1);
end;
Expand Down
4 changes: 2 additions & 2 deletions software/main.lfm
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ object MainForm: TMainForm
Top = 209
Width = 853
ActiveControl = RadioSPI
Caption = 'AsProgrammer dregmod v3.7 - Stop all current operations: keep pressing ESC key - Launch Console: keep pressing F1 key'
Caption = 'AsProgrammer dregmod v3.9 - Stop all current operations: keep pressing ESC key - Launch Console: keep pressing F1 key'
ClientHeight = 521
ClientWidth = 853
Constraints.MinHeight = 300
Expand Down Expand Up @@ -699,7 +699,7 @@ object MainForm: TMainForm
Width = 853
Align = alBottom
Lines.Strings = (
'AsProgrammer dregmod v3.7'
'AsProgrammer dregmod v3.9'
'https://github.com/therealdreg/asprogrammer-dregmod'
'dreg@rootkit.es'
)
Expand Down
49 changes: 42 additions & 7 deletions software/spi25.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
interface

uses
Classes, Forms, SysUtils, utilfunc;
Classes, Forms, SysUtils, utilfunc, BaseHW;

const

Expand Down Expand Up @@ -50,6 +50,7 @@ function UsbAsp25_EX4B(): integer;

function SPIRead(CS: byte; BufferLen: integer; out buffer: array of byte): integer;
function SPIWrite(CS: byte; BufferLen: integer; buffer: array of byte): integer;
function SPIReadWrite(CSR: byte; CSW: byte; RBufferLen: integer; out rbuffer: array of byte; WBufferLen: integer; wbuffer: array of byte): integer;

implementation

Expand Down Expand Up @@ -126,8 +127,15 @@ function UsbAsp25_Read(Opcode: byte; Addr: longword; var buffer: array of byte;
buff[2] := hi(lo(addr));
buff[3] := lo(addr);

SPIWrite(0, 4, buff);
result := SPIRead(1, bufflen, buffer);
if AsProgrammer.Current_HW = CHW_BUZZPIRAT then
begin
result := AsProgrammer.Programmer.SPIWriteRead(1, 4, buff, bufflen, buffer);
end
else
begin
SPIWrite(0, 4, buff);
result := SPIRead(1, bufflen, buffer);
end;
end;

function UsbAsp25_Read32bitAddr(Opcode: byte; Addr: longword; var buffer: array of byte; bufflen: integer): integer;
Expand All @@ -141,8 +149,15 @@ function UsbAsp25_Read32bitAddr(Opcode: byte; Addr: longword; var buffer: array
buff[3] := hi(lo(addr));
buff[4] := lo(lo(addr));

SPIWrite(0, 5, buff);
result := SPIRead(1, bufflen, buffer);
if AsProgrammer.Current_HW = CHW_BUZZPIRAT then
begin
result := AsProgrammer.Programmer.SPIWriteRead(1, 5, buff, bufflen, buffer);
end
else
begin
SPIWrite(0, 5, buff);
result := SPIRead(1, bufflen, buffer);
end;
end;

function UsbAsp25_Wren(): integer;
Expand Down Expand Up @@ -205,8 +220,15 @@ function UsbAsp25_WriteSR_2byte(sreg1, sreg2: byte): integer;

function UsbAsp25_ReadSR(var sreg: byte; opcode: byte = $05): integer;
begin
SPIWrite(0, 1, opcode);
result := SPIRead(1, 1, sreg);
if AsProgrammer.Current_HW = CHW_BUZZPIRAT then
begin
result := AsProgrammer.Programmer.SPIWriteRead(1, 1, opcode, 1, sreg);
end
else
begin
SPIWrite(0, 1, opcode);
result := SPIRead(1, 1, sreg);
end;
end;

//Возвращает сколько байт записали
Expand Down Expand Up @@ -295,5 +317,18 @@ function SPIWrite(CS: byte; BufferLen: integer; buffer: array of byte): integer;
result := AsProgrammer.Programmer.SPIWrite(CS, BufferLen, buffer);
end;

function SPIReadWrite(CSR: byte; CSW: byte; RBufferLen: integer; out rbuffer: array of byte; WBufferLen: integer; wbuffer: array of byte): integer;
begin
if AsProgrammer.Current_HW = CHW_BUZZPIRAT then
begin
result := AsProgrammer.Programmer.SPIWriteRead(1, WBufferLen, wbuffer, RBufferLen, rbuffer);
end
else
begin
SPIWrite(CSW, WBufferLen, wbuffer);
result := SPIRead(CSR, RBufferLen, rbuffer);
end;
end;

end.

6 changes: 2 additions & 4 deletions software/spi45.pas
Original file line number Diff line number Diff line change
Expand Up @@ -87,8 +87,7 @@ function UsbAsp45_ReadSectorLockdown(var buffOut: array of byte): integer;
function UsbAsp45_ReadSR(var sreg: byte): integer;
begin
sreg := $D7; //57H Legacy
SPIWrite(0, 1, sreg);
result := SPIRead(1, 1, sreg);
result := SPIReadWrite(1, 0, 1, sreg, 1, sreg);
end;

//Возвращает сколько байт записали
Expand Down Expand Up @@ -129,8 +128,7 @@ function UsbAsp45_Read(PageAddr: word; var buffer: array of byte; bufflen: integ

buffer[3] := 0;

SPIWrite(0, 8, buffer);
result := SPIRead(1, bufflen, buffer);
result := SPIReadWrite(1, 0, bufflen, buffer, 8, buffer);
end;

end.
Expand Down
9 changes: 4 additions & 5 deletions software/spi95.pas
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
interface

uses
Classes, SysUtils, spi25;
Classes, SysUtils, spi25, BaseHW;

function UsbAsp95_Read(ChipSize: integer; Addr: longword; var buffer: array of byte; bufflen: integer): integer;
function UsbAsp95_Write(ChipSize: integer; Addr: longword; buffer: array of byte; bufflen: integer): integer;
Expand Down Expand Up @@ -66,8 +66,7 @@ function UsbAsp95_Read(ChipSize: integer; Addr: longword; var buffer: array of b
len := 4;
end;

SPIWrite(0, len, buff);
result := SPIRead(1, bufflen, buffer);
result := SPIReadWrite(1, 0, bufflen, buffer, len, buff);
end;

function UsbAsp95_Write(ChipSize: integer; Addr: longword; buffer: array of byte; bufflen: integer): integer;
Expand Down Expand Up @@ -151,8 +150,8 @@ function UsbAsp95_WriteSR(var sreg: byte): integer;
function UsbAsp95_ReadSR(var sreg: byte): integer;
begin
sreg := $05;
SPIWrite(0, 1, sreg);
result := SPIRead(1, 1, sreg);

result := SPIReadWrite(1, 0, 1, sreg, 1, sreg);
end;

end.
Expand Down

0 comments on commit 22447f2

Please sign in to comment.