diff --git a/buzzpirathlp.dll b/buzzpirathlp.dll deleted file mode 100644 index 650d4af..0000000 Binary files a/buzzpirathlp.dll and /dev/null differ diff --git a/software/basehw.pas b/software/basehw.pas index 5699566..345cff4 100644 --- a/software/basehw.pas +++ b/software/basehw.pas @@ -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; diff --git a/software/buzzpirathlp.dll b/software/buzzpirathlp.dll index 650d4af..be17a94 100644 Binary files a/software/buzzpirathlp.dll and b/software/buzzpirathlp.dll differ diff --git a/software/buzzpirathlp/buzzpirathlp/buzzpirathlp.c b/software/buzzpirathlp/buzzpirathlp/buzzpirathlp.c index 518aaf5..da97d6c 100644 --- a/software/buzzpirathlp/buzzpirathlp/buzzpirathlp.c +++ b/software/buzzpirathlp/buzzpirathlp/buzzpirathlp.c @@ -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) @@ -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 { diff --git a/software/buzzpirathlp/buzzpirathlp/buzzpirathlp.vcxproj b/software/buzzpirathlp/buzzpirathlp/buzzpirathlp.vcxproj index bfe4161..f51312c 100644 --- a/software/buzzpirathlp/buzzpirathlp/buzzpirathlp.vcxproj +++ b/software/buzzpirathlp/buzzpirathlp/buzzpirathlp.vcxproj @@ -108,7 +108,7 @@ false - xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\ && xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\..\ + xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\ @@ -133,7 +133,7 @@ false - xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\ && xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\..\ + xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\ @@ -154,7 +154,7 @@ false - xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\ && xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\..\ + xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\ @@ -179,7 +179,7 @@ false - xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\ && xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\..\ + xcopy /y $(TargetDir)buzzpirathlp.dll $(TargetDir)..\..\ diff --git a/software/buzzpirathw.pas b/software/buzzpirathw.pas index d6ed1de..0a2a76c 100644 --- a/software/buzzpirathw.pas +++ b/software/buzzpirathw.pas @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; @@ -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; diff --git a/software/main.lfm b/software/main.lfm index 25f588e..be9470f 100644 --- a/software/main.lfm +++ b/software/main.lfm @@ -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 @@ -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' ) diff --git a/software/spi25.pas b/software/spi25.pas index 586581f..b7046ad 100644 --- a/software/spi25.pas +++ b/software/spi25.pas @@ -5,7 +5,7 @@ interface uses - Classes, Forms, SysUtils, utilfunc; + Classes, Forms, SysUtils, utilfunc, BaseHW; const @@ -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 @@ -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; @@ -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; @@ -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; //Возвращает сколько байт записали @@ -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. diff --git a/software/spi45.pas b/software/spi45.pas index 9f1c138..d256988 100644 --- a/software/spi45.pas +++ b/software/spi45.pas @@ -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; //Возвращает сколько байт записали @@ -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. diff --git a/software/spi95.pas b/software/spi95.pas index 0016c03..9573e34 100644 --- a/software/spi95.pas +++ b/software/spi95.pas @@ -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; @@ -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; @@ -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.