;Blue8x - USB Bluetooth Driver and Interface ; (C) 2009 by Brandon Wilson. All rights reserved. ;Portions in util.asm, usb8x.inc, equates.inc (C) Dan Englender. include "settings.inc" ;Specific settings for this application NOLIST include "ti83plus.inc" LIST include "equates.inc" ;Equates and macros to be used include "header.asm" GLOBALS ON include "usb8x.inc" ;usb8x equates include "bluetooth.inc" SEGMENT MAIN Var USBDriverCall,32 ; 32; RAM calls for U_CALL and callback routine Var USBDriverBuf,128 ;128; Static buffer for USB driver's usage Var numDevicesFound,1 ; 1; Number of Bluetooth devices found in range Var ptrMenu,2 ; 2; Pointer to current menu Var ptrPrevMenu,2 ; 2; Pointer to previous menu Var ptrConnectionHandle,2 ; 2; Pointer to connection handle for remote device EXTERN DispHexHL,DispHexA,IPutC,PutSApp,INewLine,IPutS,IGetKey,VPutSApp EXTERN VPutSAppCenter,SoftKey,VDispHexA,IVPutMap,IPutS11,DispHexHLB EXTERN SendHCICommand,InitializeBluetooth,KillBluetooth,RequestHCIData EXTERN ResetBluetoothDevice,HCI_CreateConnection EXTERN HCI_Disconnect,GetLocalDeviceName,SetScanMode,RequestHCIData_NoWait EXTERN DoChatDemo,DoSendFileDemo,DoReceiveFileDemo,DoKeyboardDemo,DoMouseDemo EXTERN DrawMenu,DoDeviceSelection,AwaitIncomingConnection,AcceptConnectionRequest EXTERN L2CAP_RequestData,ACL_SendData,ACL_RequestData,ACL_IsDataAvailable ;----------------------------------------------------------------------------- Init: B_CALL ClrLCDFull B_CALL HomeUp IFDEF NOFLASHSIM ;Fire up usb8x U_CALL_INIT 0 jr c,ErrDriverNotFound ld hl,USBDriverBuf U_CALL DriverInit jr c,ExitAppNoUSB ENDIF DisplayAboutScreen: ;Display the About screen B_CALL ForceFullScreen B_CALL ClrLCDFull ld hl,1 ld (curRow),hl ld hl,sAboutText call PutSApp ld hl,Splash_DS ld de,appBackUpScreen ld bc,57 ldir ld hl,appBackUpScreen ld de,49*256+5 B_CALL DisplayImage ld hl,57*256+9 ld (pencol),hl ld hl,Intro_Web call VPutSApp ld hl,30*256+29 ld (pencol),hl ld hl,Intro_Version call VPutSApp ld a,37 ld (penRow),a ld hl,Intro_Build call VPutSAppCenter xor a ld (kbdKey),a ld (kbdScanCode),a B_CALL GetKey StartApp: ;Display main menu ld hl,0 ld (ptrPrevMenu),hl ld hl,sMainMenu ld (ptrMenu),hl jr DrawMenu InquiryScan: B_CALL ClrLCDFull B_CALL HomeUp call InitializeBluetooth jr c,ErrGeneric ld ix,saveSScreen+128 ld hl,tempSwapArea call DoDeviceSelection jr c,StartApp ;DoDeviceSelection throws its own errors cp kQuit jr z,ExitApp ;if they hit [2nd]+[QUIT], get out now or a jr nz,StartApp ;if they pressed anything else, go back to the main menu ;IX contains the inquiry result block call KillBluetooth jr StartApp DoMakeVisible: B_CALL ClrLCDFull B_CALL HomeUp call InitializeBluetooth jr c,ErrGeneric call AwaitIncomingConnection jr c,StartApp call AcceptConnectionRequest jr c,ErrGeneric ;The below is all test code for the wireless chat demo ; It really needs to be reworked to deal with services/profiles, once I learn about it :) ;HL points to connection handle object ld de,OP4 ld bc,10 push de ldir pop hl ld (ptrConnectionHandle),hl B_CALL ClrLCDFull B_CALL HomeUp ld hl,saveSScreen ld d,0 call ACL_RequestData visibleChatLoop: call ACL_IsDataAvailable jr z,$F ld hl,saveSScreen+4 call IPutS ld hl,saveSScreen ld d,0 call ACL_RequestData $$: ei halt B_CALL GetCSC cp sk2nd jr z,visibleChatLoopDone or a jr z,visibleChatLoop cp skMode jr z,$F ld hl,OP3 ld (hl),'B' ld bc,1 jr visibleSend $$: ld hl,sHelloWorld ld de,OP3 ld bc,11 push de push bc ldir pop bc pop hl visibleSend: ld ix,(ptrConnectionHandle) call ACL_SendData jr c,ErrGeneric jr visibleChatLoop visibleChatLoopDone: call KillBluetooth jr StartApp sHelloWorld: DB "Hello world!",0 DoConfigure: jr ExitApp DoDemos: ld hl,sMainMenu ld (ptrPrevMenu),hl ld hl,sDemosMenu ld (ptrMenu),hl jr DrawMenu ExitApp: IFDEF NOFLASHSIM call KillBluetooth U_CALL DriverKill ENDIF ExitAppNoUSB: B_CALL ClrLCDFull B_CALL HomeUp B_JUMP JForceCmdNoChar ErrDriverNotFound: ld hl,sDriverNotFound call PutSApp B_CALL GetKey jr ExitAppNoUSB ErrGeneric: B_CALL ClrLCDFull B_CALL HomeUp ld hl,sGenericError call PutSApp B_CALL GetKey jr StartApp sAboutText: DB " Blue8x " DB " Brandon Wilson ",0 Splash_DS: DB 5, 86 DB 231,188,199,107,220,28,204,107,222,103, 28 DB 214,25, 172,107, 26,49,172,105,140,214,176 DB 215,25, 236,123,154,25,172,105,140,214,152 DB 214,25, 172,107, 26,13,172,105,140,214,140 DB 231,153,167,107,220,56,207, 49,158,102,184 Intro_Web: DB "detachedsolutions.com",0 Intro_Version: DB "Version ",VER_STRING,0 Intro_Build: DB "Build ",BUILD_STRING,0 sDriverNotFound: DB "usb8x was not " DB "found on your " DB "calculator. " DB "It must be on " DB "your calculator " DB "before you can " DB "run this " DB "application.",0 sDriverFailed: DB "usb8x failed to " DB "initialize " DB "properly. " DB " " DB "Please try " DB "again.",0 sGenericError: DB "ERROR! " DB "A generic error " DB "occurred. " DB " " DB "Press any key " DB "and try again.",0 sMainMenu: DB 6 DB "Blue8X ",VER_STRING,0 DB " 1) Inquiry",0 DW InquiryScan DB " 2) Make Visible",0 DW DoMakeVisible DB " 3) Configure",0 DW DoConfigure DB " 4) Demos",0 DW DoDemos DB " 5) About",0 DW DisplayAboutScreen DB " 6) Quit",0 DW ExitApp sDemosMenu: DB 6 DB "Demos",0 DB " 1) Chat",0 DW DoChatDemo DB " 2) Send File",0 DW DoSendFileDemo DB " 3) Recv File",0 DW DoReceiveFileDemo DB " 4) Keyboard",0 DW DoKeyboardDemo DB " 5) Mouse",0 DW DoMouseDemo DB " 6) Back",0 DW StartApp