;Optimized versions of descriptor-sending code per device, to speed up device enumeration include "settings.inc" include "ti83plus.inc" include "equates.inc" SEGMENT Main GLOBALS ON EXTERN cancelUSBHook,WaitTimer20ms,SetupOutPipe,SetupInPipe,WaitPort82,DispHexHL EXTERN P1_READY,P2_READY,P3_READY,P4_READY EXTERN maxPacketSize,jailbreakState,portCur EXTERN descSize,shortConfigDescAddress,descSizeOverride,configDescAddress,SetJailbreakState,GetCompatibilityData EXTERN DispHexA,DispHexHL,BHL_plus_DE,myLoadCIndPaged,LoadPS3JBSettings,myLoadDEIndPaged,finishControlOutput EXTERN Device4ConfigDescriptor2,Device4ConfigDescriptor3,Device4ConfigDescriptor2Short,DelayPort82 PUBLIC SendDevice1ConfigDescriptor SendDevice1ConfigDescriptor: di ld a,1 out (20h),a res overrideSize,(iy+PS3JBFlags) call SetUpQuickPagedGet ;See if we have an external payload AppVar call LoadPS3JBSettings in a,(6) ld (configDescAddress+2),a ld (shortConfigDescAddress+2),a ld a,(Stage1VarName+1) or a jr z,useExistingPayload ld hl,Stage1VarName rst 20h B_CALL ChkFindSym jr c,useExistingPayload ex de,hl ld a,b or a jr z,$F ld de,9 call BHL_plus_DE call myLoadCIndPaged ld d,0 ld e,c call BHL_plus_DE $$: ;BHL points to the AppVar's size bytes call myLoadDEIndPaged ld (descSizeOverride),de set overrideSize,(iy+PS3JBFlags) ;Now BHL points to the payload data ld a,b ld (configDescAddress+2),a ld (configDescAddress),hl useExistingPayload: ;Are we on the last descriptor with length > 8? If so, device 1 is ready ld a,(inputBuffer+2) cp 3 jr nz,$F ld hl,(inputBuffer+6) ld de,8 or a sbc hl,de jr z,$F ld a,P1_READY call SetJailbreakState $$: ld hl,(inputBuffer+6) ;Are we using a separate packet for the config descriptor? If not, skip this step ld de,8 or a sbc hl,de jr nz,$F ld hl,8 ld (descSize),hl ld de,(shortConfigDescAddress) ld (tempAddress),de ld a,(shortConfigDescAddress+2) ld (tempPage),a jr continueConfigDescriptor $$: bit overrideSize,(iy+PS3JBFlags) res overrideSize,(iy+PS3JBFlags) ld hl,0F00h jr z,$F ld hl,(descSizeOverride) $$: ld (descSize),hl ld de,(configDescAddress) ld (tempAddress),de ld a,(configDescAddress+2) ld (tempPage),a continueConfigDescriptor: xor a out (8Eh),a ld a,40h out (91h),a call d1DelayPort82 ld hl,(tempAddress) ld a,(tempPage) ld b,a B_CALL SetupPagedPtr d1descriptorOutLoop: ld hl,maxPacketSize ld b,(hl) ld a,(descSize+1) or a jr nz,d1descriptorOutBig ld a,(descSize) cp b jr c,$F d1descriptorOutBig: ld hl,(descSize) ld bc,(maxPacketSize) ld b,0 or a sbc hl,bc ld (descSize),hl ld b,c jr d1continueOutput $$: ld b,a ld hl,0 ld (descSize),hl d1continueOutput: d1OutputLoop: call asm_ram ;HACK: call _PagedGet through an absolute address for speed purposes out (0A0h),a djnz d1OutputLoop ld hl,(descSize) ld a,h or l jr nz,$F jr d1finishControlOutput $$: xor a out (8Eh),a ld a,2 out (91h),a call d1DelayPort82 jr d1descriptorOutLoop d1finishControlOutput: xor a out (8Eh),a ld a,0Ah out (91h),a call WaitPort82 call WaitPort82 call WaitTimer20ms call WaitTimer20ms call WaitTimer20ms jr cancelUSBHook d1DelayPort82: push bc ld bc,08FFh $$: in a,(82h) bit 0,a jr nz,$F ex hl,(sp) ex hl,(sp) dec bc ld a,b or c jr nz,$B $$: pop bc ret SetUpQuickPagedGet: ;HACK: Get the absolute address of _PagedGet (this works on 2.x OSes up to 2.53MP -- should be fine going forward as well) ld a,7Bh ld hl,_PagedGet ld de,OP1 ld bc,3 B_CALL FlashToRam ld hl,(OP1) ld (asm_ram+1),hl ld a,0C3h ld (asm_ram),a ret SendDevice3ConfigDescriptor: di ld a,1 out (20h),a ld a,(inputBuffer+2) cp 1 jr nz,$F ld hl,(inputBuffer+6) ld de,8 or a sbc hl,de jr z,$F ld a,P3_READY call SetJailbreakState $$: ld hl,(inputBuffer+6) ld (descSize),hl ld de,(configDescAddress) inc de inc de ld a,(de) ld l,a inc de ld a,(de) ld h,a dec de dec de dec de ld bc,(descSize) or a push hl sbc hl,bc pop hl jr nc,$F ld (descSize),hl $$: xor a out (8Eh),a ld a,40h out (91h),a call d1DelayPort82 d3descriptorOutLoop: ld hl,maxPacketSize ld b,(hl) ld a,(descSize+1) or a jr nz,d3descriptorOutBig ld a,(descSize) cp b jr z,$F jr c,$F d3descriptorOutBig: ld hl,(descSize) ld bc,(maxPacketSize) ld b,0 or a sbc hl,bc ld (descSize),hl ld b,c jr d3continueOutput $$: ld b,a ld hl,0 ld (descSize),hl d3continueOutput: $$: ld a,(de) out (0A0h),a inc de djnz $B ld hl,(descSize) ld a,h or l jr z,d3finishControlOutput xor a out (8Eh),a ld a,2 out (91h),a call d1DelayPort82 jr d3descriptorOutLoop d3finishControlOutput: xor a out (8Eh),a ld a,0Ah out (91h),a call WaitPort82 call WaitPort82 call WaitTimer20ms call WaitTimer20ms call WaitTimer20ms jr cancelUSBHook SendDevice4ConfigDescriptor: ld a,1 out (20h),a di ld a,(inputBuffer+2) or a jr z,d4StartSend cp 1 jr nz,$F ;Port 4 config descriptor 2 ld hl,(inputBuffer+6) ld de,8 or a sbc hl,de ld de,Device4ConfigDescriptor2Short ld (configDescAddress),de jr z,d4StartSend ld de,Device4ConfigDescriptor2 ld (configDescAddress),de ld hl,18 ld (descSizeOverride),hl set overrideSize,(iy+PS3JBFlags) jr d4StartSend $$: ld a,(inputBuffer+2) cp 2 jr nz,d4StartSend ;Port 4 config descriptor 3 ld de,Device4ConfigDescriptor3 ld (configDescAddress),de ld a,1 call GetCompatibilityData jr c,$F ld de,externalDataBuffer ld (configDescAddress),de $$: ld hl,(inputBuffer+6) ld de,8 or a sbc hl,de jr z,d4StartSend ld a,P4_READY call SetJailbreakState d4StartSend: ld hl,(inputBuffer+6) ld (descSize),hl ;Are we using a separate packet for the config descriptor? If not, skip this step ld de,(configDescAddress) inc de inc de ld a,(de) ld l,a inc de ld a,(de) ld h,a dec de dec de dec de ld bc,(descSize) or a push hl sbc hl,bc pop hl jr nc,$F ld (descSize),hl $$: bit overrideSize,(iy+PS3JBFlags) res overrideSize,(iy+PS3JBFlags) jr z,$F ld hl,(descSizeOverride) ld (descSize),hl $$: xor a out (8Eh),a ld a,40h out (91h),a call DelayPort82 d4descriptorOutLoop: ld hl,maxPacketSize ld b,(hl) ld a,(descSize+1) or a jr nz,d4descriptorOutBig ld a,(descSize) cp b jr c,$F d4descriptorOutBig: ld hl,(descSize) ld bc,(maxPacketSize) ld b,0 or a sbc hl,bc ld (descSize),hl ld b,c jr d4continueOutput $$: ld b,a ld hl,0 ld (descSize),hl d4continueOutput: $$: ld a,(de) out (0A0h),a inc de djnz $B ld hl,(descSize) ld a,h or l jr nz,$F jr finishControlOutput $$: xor a out (8Eh),a ld a,2 out (91h),a call DelayPort82 jr d4descriptorOutLoop