;AddAsm by Brandon Wilson ;08/12/04 ; ;This program allows you to run assembly programs (that do not ; require a shell such as MirageOS) from the homescreen without ; using 'Asm('. You simply run them like you do BASIC programs. ; The TI-OS will automatically insert 'Asm(' for you once you ; have pressed ENTER. ; ;Notes: uses parser hook, checks for previous hook and warns if it exists ; include "ti83plus.inc" EXT_APP equ 1 ;This definition is required of all apps cseg ;This linker directive is required of all apps. db 080h,0Fh ;Field: Program length db 00h,00h,00h,00h ;Length=0 (N/A for unsigned apps) db 080h,012h ;Field: Program type db 01h,04h ;Type= Shareware, TI-83Plus db 080h,021h ;Field: App ID db 01h ;Id = 1 db 080h,031h ;Field: App Build db 01h ;Build = 1 db 080h,048h ;Field: App Name db 05Ah,041h,064h,064h,041h,073h,06Dh,020h ;Name = "ZAddAsm " must be 8 characters db 080h,081h ;Field: App Pages db 01h ;App Pages = 1 db 080h,090h ;No default splash screen db 03h,026h ,09h,04h, 04h,06fh,01bh,80h ;Field: Date stamp- 5/12/1999 db 02h,0dh,040h ;Dummy encrypted TI date stamp signature db 0a1h ,06bh ,099h ,0f6h ,059h ,0bch ,067h db 0f5h ,085h ,09ch ,09h ,06ch ,0fh ,0b4h ,03h ,09bh ,0c9h db 03h ,032h ,02ch ,0e0h ,03h ,020h ,0e3h ,02ch ,0f4h ,02dh db 073h ,0b4h ,027h ,0c4h ,0a0h ,072h ,054h ,0b9h ,0eah ,07ch db 03bh ,0aah ,016h ,0f6h ,077h ,083h ,07ah ,0eeh ,01ah ,0d4h db 042h ,04ch ,06bh ,08bh ,013h ,01fh ,0bbh ,093h ,08bh ,0fch db 019h ,01ch ,03ch ,0ech ,04dh ,0e5h ,075h db 80h,7Fh ;Field: Program Image length db 0,0,0,0 ;Length=0, N/A db 0,0,0,0 ;Reserved db 0,0,0,0 ;Reserved db 0,0,0,0 ;Reserved db 0,0,0,0 ;Reserved ParserHookPtr equ 9BACh _SetParserHook equ 5026h _ResParserHook equ 5029h parserHookActive equ 1 parserHookFlag equ 36h ;See if parser hook is enabled B_CALL ClrLCDFull B_CALL ClrTxtShd ld hl,0 ld (curRow),hl bit parserHookActive,(iy+parserHookFlag) ;hook enabled? jr z,enableHook ;Parser hook is already installed; is it ours? ld hl,(ParserHookPtr) ld a,(ParserHookPtr+2) ld de,appBackUpScreen ld bc,Hook_End-Hook_Start B_CALL FlashToRam ;copy current hook to appBackUpScreen ld hl,appBackUpScreen ld de,Hook_Start ld b,Hook_End-Hook_Start checkHook: ld a,(hl) ld c,a ld a,(de) cp c ;compare current hook to our hook jr nz,invalidHook ;go to warning if not the same inc hl inc de djnz checkHook ;diable parser hook B_CALL ResParserHook ;disable old parser hook ld hl,sDisabled call PutSApp ld hl,0002h ld (curRow),hl ld hl,sPressAnyKey call PutSApp ;display disabled status and exit B_CALL GetKey B_CALL ClrLCDFull B_CALL ClrTxtShd ld hl,0 ld (curRow),hl B_JUMP JForceCmdNoChar ;Another hook found; display warning and ask what to do invalidHook: B_CALL ClrLCDFull ;display warning message B_CALL RunIndicOff ld hl,0 ld (curRow),hl ld hl,sWarning call PutSApp _ihGK: B_CALL GetCSC cp sk1 jr z,enableHook ;enable if Y cp sklog jr nz,_ihGK B_CALL ClrLCDFull ;exit if N B_CALL ClrTxtShd ld hl,0 ld (curRow),hl B_JUMP JForceCmdNoChar ;Parser hook was either invalid or disabled; enable it enableHook: B_CALL ResParserHook ;enable our parser hook ld hl,Hook_Start in a,(6) B_CALL SetParserHook B_CALL ClrLCDFull B_CALL ClrTxtShd ld hl,0 ld (curRow),hl ld hl,sEnabled call PutSApp ;display status and exit ld hl,0002h ld (curRow),hl ld hl,sPressAnyKey call PutSApp B_CALL GetKey B_JUMP JForceCmdNoChar ;PutS for applications PutSApp: ld a,(hl) or a ret z B_CALL PutC inc hl jr PutSApp ;AddAsm strings sEnabled: db "AddAsm Enabled",0 sDisabled: db "AddAsm Disabled",0 sWarning: db " WARNING! " db " " db "The parser hook " db " is already " db " enabled. " db " " db "Overwrite? (Y/N)",0 sPressAnyKey: db "Press any key",0 ;AddAsm parser hook Hook_Start: db 83h or a ;preparser condition? jp nz,_exitHook ; no, get out ld hl,op1 ld de,appBackUpScreen ld bc,9 ldir B_CALL ChkFindSym ;find program being run ld a,(de) ld l,a inc de ld a,(de) ld h,a inc de ld a,(de) cp 5Fh ;is first byte 5Fh? (prgm token) jp nz,_exitHook ; no, get out and let OS continue dec hl push hl B_CALL ZeroOP1 pop bc inc de ex de,hl ld de,op1+1 ldir ld a,ProtProgObj ld (op1),a B_CALL ChkFindSym ;try finding program to be run as ProgObj jp nc,_foundVar ld a,ProgObj ld (op1),a B_CALL ChkFindSym ;no, now try as ProtProgObj jp c,_exitHook _foundVar: inc de inc de ld a,(de) cp 0BBh ;0BBh? (two-byte token) jp nz,_exitHook inc de ld a,(de) cp 06Dh ;6Dh? (AsmPrgm) (tells us it's an assembly program) jp nz,_exitHook ld hl,2 B_CALL EnoughMem ;need to increase program to insert Asm(; can we? jp c,_exitHook ld hl,appBackUpScreen rst 20h B_CALL ChkFindSym push de inc de inc de ld hl,2 B_CALL InsertMem ;insert two bytes (for two-byte token, 'Asm(') pop hl push hl B_CALL ldhlind ld bc,2 add hl,bc ex de,hl pop hl ld (hl),e inc hl ld (hl),d B_CALL ChkFindSym inc de inc de ld a,0BBh ld (de),a ;load in 0BBh (part 1 of two-byte token) inc de ld a,06Ah ;load in 6Ah (part 2 of 'Asm(') ld (de),a B_CALL ParseInp ;force our own parse of new line with 'Asm(' ld a,1 ;cancel TI-OS's parse or a ret _exitHook: xor a ret Hook_End: