;periph8x - USB Peripheral Driver(s) ;UnivOS - I/O / USB Signed/Unsigned OS Receiver ; (C) 2007 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 SEGMENT MAIN EXTERN DispHexA,IGetKey,IPutS,IPutC,DispHexHL,DialogBox,DriverInit,VPutSAppCenter,StopLog,WaitTimerBms,ifastcopy EXTERN USBactivityHook,sendReadResponse,SendData,MassStorageInit,VPutSApp,MassStorageHandle,CalculatorInit,LCDdelay EXTERN KeyboardInit,DriverKill,SendInterruptData,PutSApp,SendKeypress,fastCopy,SetupLog,DispLog,InitializePeriphUSB EXTERN BCALL_replacement,BCALL_replacementStart,BCALL_replacementEnd,silentLinkHook,receiveAndWriteUSBData_fromInt EXTERN initUSBStuff,initCrystalTimer,MouseInit,GamepadInit,RecycleUSB,getNext Var USBcallbackAddress,2 Var USBcallbackPage,1 Var menuAddr,2 Var numChoices,1 Var debugStep,1 Var dataAddr,2 Var col1,1 Var col2,2 Var flagsBackup,3 Var curVATptr,2 Var lwrCaseFlag,1 AboutScreen: ;Display the About screen ld a,(iy+appLwrCaseFlag) ld (lwrCaseFlag),a 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 Init: B_CALL CanAlphIns ld (iy+periph8xFlags),0 ld a,0FFh ;***TESTING xor a ld (debugStep),a ;***TESTING xor a ;***TESTING ld (col1),a ;***TESTING ld (col2),a ;***TESTING ld hl,mainMenu ld (menuAddr),hl DrawMenu: B_CALL ClrLCDFull B_CALL HomeUp ld hl,(menuAddr) call PutSApp ld de,0001h ld b,(hl) ld a,b ld (numChoices),a inc hl $$: push bc ld (curRow),de push de call PutSApp pop de inc e inc hl inc hl pop bc djnz $B keyLoop: B_CALL GetKey cp k8 jr nz,$F ld a,5 B_CALL PutC di ld a,87h out (7),a ld hl,8000h ld (hl),0 ld de,8001h ld bc,4000h-1 ldir ld a,81h out (7),a jr keyLoop $$: cp k9 ;*** TESTING call z,InitializePeriphUSB ;*** TESTING cp kQuit jr z,exitApp cp kClear jr z,exitApp cp k1 jr c,keyLoop sub k1 ld b,a ld a,(numChoices) dec a cp b jp m,keyLoop inc b push bc ld hl,(menuAddr) xor a ld bc,16 cpir inc hl pop de dec hl dec hl $$: inc hl inc hl xor a ld bc,16 cpir dec d jr nz,$B ld e,(hl) inc hl ld d,(hl) ex de,hl jp (hl) ;Keyboard GUI ;----------------------------------------------------------------------------- DoKeyboard: B_CALL DisableApd call displayKeyboardScreen ld b,1 call KeyboardInit ;jr c,Init ; res debugOn,(iy+periph8xFlags) keyboardLoop: set lwrCaseActive,(iy+appLwrCaseFlag) B_CALL GetKeyRetOff ld b,a in a,(4) bit 3,a ld a,b jr nz,$F ;Check for ON+key combinations here cp kMode jr z,onModePressed $$: cp kClear jr z,keyboardLoopDone bit 4,(iy+9) res 4,(iy+9) jr nz,keyboardLoop ld c,a xor a call SendKeypress jr keyboardLoop onModePressed: ;Display keyboard driver help B_CALL ClrLCDFull B_CALL GrBufClr res bufferOnly,(iy+plotFlag3) set plotLoc,(iy+plotFlags) res textWrite,(iy+sGrFlags) ld l,1 ld h,1 ld e,93 ld d,61 call DialogBox ld de,3*256+3 ld (penCol),de ld hl,sKeyboardHelp call VPutSApp ld de,17*256+3 ld (penCol),de call VPutSApp ld de,24*256+3 ld (penCol),de call VPutSApp ld de,31*256+3 ld (penCol),de call VPutSApp ld de,38*256+3 ld (penCol),de call VPutSApp ld a,54 ld (penRow),a call VPutSAppCenter B_CALL GetKey call displayKeyboardScreen jr keyboardLoop keyboardLoopDone: call DriverKill jr Init displayKeyboardScreen: B_CALL ClrLCDFull B_CALL GrBufClr res bufferOnly,(iy+plotFlag3) set plotLoc,(iy+plotFlags) res textWrite,(iy+sGrFlags) ld l,1 ld h,1 ld e,93 ld d,61 call DialogBox ld de,3*256+3 ld (penCol),de ld hl,sKeyboardMessage call VPutSApp ld de,10*256+3 ld (penCol),de call VPutSApp ld de,17*256+3 ld (penCol),de call VPutSApp ld de,31*256+3 ld (penCol),de call VPutSApp ld de,38*256+3 ld (penCol),de call VPutSApp ld a,54 ld (penRow),a call VPutSAppCenter ret ;----------------------------------------------------------------------------- ;Mass storage GUI ;----------------------------------------------------------------------------- DoMassStorage: B_CALL ClrLCDFull B_CALL HomeUp IF LOGGING_ENABLED = 1 ld hl,8000h ;*** HACK: using page 87h for logging (not anymore) ld b,87h ;call SetupLog ENDIF ld hl,sMassStorageMessage call PutSApp B_CALL HomeUp ld b,1 call MassStorageInit massKeyLoop: ei halt B_CALL GetCSC cp skClear jr z,$F jr massKeyLoop $$: call DriverKill call StopLog jr Init ;----------------------------------------------------------------------------- ;Mouse GUI ;----------------------------------------------------------------------------- DoMouse: B_CALL ClrLCDFull B_CALL HomeUp IF LOGGING_ENABLED = 1 ld hl,8000h ;*** HACK: using page 87h for logging ld b,87h call SetupLog ENDIF ld b,1 call MouseInit jr c,Init $$: ei B_CALL GetCSC cp skClear jr z,$F jr $B $$: call DriverKill call StopLog jr Init ;----------------------------------------------------------------------------- ;Gamepad GUI ;----------------------------------------------------------------------------- DoGamepad: B_CALL ClrLCDFull B_CALL HomeUp IF LOGGING_ENABLED = 1 ld hl,8000h ;*** HACK: using page 87h for logging ld b,87h call SetupLog ENDIF ld b,1 call GamepadInit jr c,Init $$: ei B_CALL GetCSC cp skClear jr z,$F jr $B $$: call DriverKill call StopLog jr Init ;----------------------------------------------------------------------------- ;Calculator GUI ;----------------------------------------------------------------------------- DoCalculator: B_CALL ClrLCDFull B_CALL HomeUp IF LOGGING_ENABLED = 1 ld hl,8000h ld b,87h call SetupLog ENDIF ld hl,sCalculatorMessage call PutSApp B_CALL HomeUp ld b,1 call CalculatorInit jr c,Init calcKeyLoop: in a,(4) bit 3,a jr z,$F ei halt jr calcKeyLoop $$: call DriverKill call StopLog jr Init ;----------------------------------------------------------------------------- ;UnivOS Stuff ;----------------------------------------------------------------------------- StartUnivOS: ld a,(iy+appLwrCaseFlag) ld (lwrCaseFlag),a B_CALL ForceFullScreen B_CALL CanAlphIns ld (iy+periph8xFlags),0 B_CALL ClrLCDFull B_CALL HomeUp ld hl,sUnivOSSelection call PutSApp $$: B_CALL GetKey cp kClear jr z,exitUnivOS cp k1 jr z,$F cp k2 jr z,UnivOS_IO jr $B $$: IF LOGGING_ENABLED = 1 ld hl,8000h ld b,82h call SetupLog ENDIF B_CALL ClrLCDFull B_CALL HomeUp ld hl,sUnivOSMessage call PutSApp B_CALL HomeUp ;*** TESTING ld b,1 call CalculatorInit UnivOSLoop: ei halt in a,(4) bit 3,a jr z,exitUnivOS jr UnivOSLoop UnivOS_IO: B_CALL ClrLCDFull B_CALL HomeUp ld hl,sUnivOSMessage_IO call PutSApp in a,(6) ld hl,silentLinkHook B_CALL EnableSilentLinkHook $$: B_CALL GetKey cp kClear jr nz,$B exitUnivOS: call StopLog B_CALL DisableLinkActivityHook jr exitApp ;----------------------------------------------------------------------------- exitApp: ld a,(lwrCaseFlag) ld (iy+appLwrCaseFlag),a B_CALL ClrLCDFull call DriverKill ;kill any USB connections we might have ; call InitializePeriphUSB ;hopefully this isn't really dumb to do right now call RecycleUSB ; rst 28h ; dw 5311h res indicOnly,(iy+indicFlags) B_JUMP JForceCmdNoChar mainMenu: DB "periph8x ",VER_STRING,0 DB 7 DB "1) Mass Storage",0 DW DoMassStorage DB "2) Keyboard",0 DW DoKeyboard DB "3) Calculator",0 DW DoCalculator DB "4) Mouse",0 DW DoMouse DB "5) Gamepad",0 DW DoGamepad DB "6) View Log",0 DW DispLog DB "7) About",0 DW AboutScreen ; DB "7) Quit",0 ; DW exitApp sKeyboardMessage: DB "Press keys on the keypad",0 DB "to send them to the ",0 DB "connected host.",0 DB "Press ",LlBrack,"CLEAR] to",0 DB "disconnect and quit.",0 DB "Help: ",LlBrack,"MODE]",0 sKeyboardHelp: DB "Additional keys:",0 DB LlBrack,"VARS] - Backspace",0 DB LlBrack,"MATH] - !",0 DB LlBrack,"(-)] - _",0 DB LlBrack,"2ND]+",LlBrack,"MEM] - '",0 DB "Press any key...",0 sMassStorageMessage: DB "Mass storage " DB "driver is " DB "active. " DB " " DB "Press CLEAR to " DB "disconnect and " DB "quit.",0 sCalculatorMessage: DB "Calculator " DB "driver is " DB "active. " DB " " DB "Press ",LlBrack,"ON] to " DB "return. ",0 sUnivOSSelection: DB "UnivOS ",VER_STRING," " DB " " DB "1) USB Cable " DB "2) I/O Cable " DB " " DB "Press ",LlBrack,"CLEAR] to" DB "exit.",0 sUnivOSMessage: DB "USB driver " DB "started. " DB " " DB "Start PC/calc OS" DB "transfer now. " DB " " DB "Press ",LlBrack,"ON] to " DB "abort transfer.",0 sUnivOSMessage_IO: DB "I/O driver " DB "started. " DB " " DB "Start PC/calc OS" DB "transfer now. " DB " " DB "Press ",LlBrack,"CLEAR] to" DB "abort transfer.",0 sAboutText: DB " periph8x " 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