;Android-specific routines include "ti83plus.inc" include "equates.inc" EXTERN DispHexHL,DirectUSB_GetDescriptor,DirectUSB_SendControlData,IPutC EXTERN DirectUSB_Setup,DirectUSB_Connect,DirectUSB_ConfigureDevice EXTERN DirectUSB_SendControlDataOut InitializeAndroidDevice: ;Initializes the connected Android-powered device and driver. ;Inputs: B: Flags ;Outputs: Returns carry flag set if problems ld b,00000011b call DirectUSB_Setup ;Initialize the device call DirectUSB_Connect ret c ld a,01h ld bc,12h ld de,appData call DirectUSB_GetDescriptor ret c ld hl,(appData+8) call DispHexHL ld hl,(appData+10) call DispHexHL ; call INewLine ;Set the configuration ; ld hl,sConfiguring ; call IPutS ; push hl ; call INewLine ld b,1 call DirectUSB_ConfigureDevice ; pop hl ret c ; call IPutS ; call INewLine ;Get Android accessory protocol version (required) ; ld hl,sGettingVersion ; call IPutS ; push hl ; call INewLine ld hl,bGetProtocolVersion rst 20h ld hl,OP1 ld de,OP2 ld bc,2 call DirectUSB_SendControlData ; pop hl ret c ; call IPutS ; call INewLine ld hl,(OP2) call DispHexHL ; call INewLine ; ld hl,sSendingStrings ; call IPutS ; push hl ; call INewLine ld hl,sManufacturerName ld bc,sManufacturerNameEnd-sManufacturerName ld de,0 call SendAndroidString ld hl,sModelName ld bc,sModelNameEnd-sModelName ld de,1 call SendAndroidString ld hl,sDescription ld bc,sDescriptionEnd-sDescription ld de,2 call SendAndroidString ld hl,bVersion ld bc,bVersionEnd-bVersion ld de,3 call SendAndroidString ld hl,sURI ld bc,sURIEnd-sURI ld de,4 call SendAndroidString ld hl,sSerialNumber ld bc,sSerialNumberEnd-sSerialNumber ld de,5 call SendAndroidString ld a,1 out (5Bh),a ei ld hl,bStartAccessoryMode rst 20h ld hl,OP1 ld bc,0 call DirectUSB_SendControlData ; pop hl ret c ld a,5 call IPutC $$: ld a,1 out (5Bh),a ei ret call DirectUSB_Connect ret c ld a,01h ld bc,12h ld de,appData call DirectUSB_GetDescriptor ret c ld hl,(appData+8) call DispHexHL ld hl,(appData+10) call DispHexHL ld a,02h ld bc,08h ld de,appData call DirectUSB_GetDescriptor ret c ld a,02h ld bc,(appData+2) ld de,appData call DirectUSB_GetDescriptor ret c ld a,'D' call IPutC xor a ret sConnecting: DB "Connecting",0CEh,0 DB "Connected",0 sGettingDescriptor: DB "Getting desc",0CEh,0 DB "Got descriptor",0 sManufacturerName: DB "Texas Instruments",0 sManufacturerNameEnd: sConfiguring: DB "Configuring",0CEh,0 DB "Configured",0 sGettingVersion: DB "Getting version",0CEh,0 DB "Got version",0 sSendingStrings: DB "Sending strings",0CEh,0 DB "Strings sent",0 sStartingAccessoryMode: DB "Starting acc " DB "mode",0CEh,0 DB "Acc mode started",0 sTryingReconnect: DB "Trying reconnect",0 DB "Reconnected!",0 sModelName: DB "TI Graphing Calculator",0 sModelNameEnd: sDescription: DB "TI Graphing Calculator",0 sDescriptionEnd: bVersion: DB "0.01",0 bVersionEnd: sURI: DB "http://brandonw.net",0 sURIEnd: sSerialNumber: DB "0000",0 sSerialNumberEnd: SendAndroidString: push de push bc ld de,appData ld bc,256 ldir pop bc pop de ld hl,appData SendString: ;Sends string pointed to by HL with size BC and index DE to Android-powered device. push hl push bc push de ld hl,bSendString rst 20h pop de ld (OP1+4),de pop bc ld (OP1+6),bc ld hl,OP1 pop de jr DirectUSB_SendControlDataOut bGetProtocolVersion: DB 0C0h,51 DW 0000h DW 0000h DW 0002h bSendString: DB 40h,52 DW 0000h DW 0000h DW 0000h bStartAccessoryMode: DB 40h,53 DW 0000h DW 0000h DW 0000h