Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => TI Z80 => Topic started by: ACagliano on August 30, 2011, 05:48:25 pm

Title: OFFSCRIPT
Post by: ACagliano on August 30, 2011, 05:48:25 pm
What should the OFFSCRIPT variable look like (hex) if you want it to tell the calc to run a program named "OFFBY1" on startup? I have a reason for asking for the complete hex, a reason that is currently a surprise.

Will zStart interfere with this?
Title: Re: OFFSCRIPT
Post by: thepenguin77 on August 30, 2011, 06:48:15 pm
Well, OFFSCRPT is just assembly. So the assembly code would be:

Code: [Select]
.org $8001
bit 4, (iy + 8)
ret nz ;apd

ld hl, progName
rst 20h
bcall(_executePrgm)
ret
progName:
.db protProgObj, "OFFBY1", 0

And the hex would be:
Code: [Select]
FD CB 08 66 C0 21 0E 80 E7 EF 7C 4E C9 06 4F 46 46 42 59 31 00

zStart won't interfere unless you turn on the displaying of pictures or make a program so it runs on startups. DCS will interfere the very first time you run it regardless of settings though.


Edit:
    The normal rules of running TI-OS programs applies here. i.e. it can't be archived, and you can't be out of memory
Title: Re: OFFSCRIPT
Post by: ACagliano on August 30, 2011, 07:12:45 pm
Thanks thepenguin. Could I do a quick _ChkFindSym to see if it exists? And perhaps unarchive, then rearchive to solve the archive problem?
Title: Re: OFFSCRIPT
Post by: thepenguin77 on August 30, 2011, 07:57:52 pm
Go for it.

Another thing though, you need to be sure that OFFBY1 doesn't mess with $8000. If it does, it's going to overwrite your code and crash when it returns. This leaves you with a few options:

Title: Re: OFFSCRIPT
Post by: ACagliano on August 31, 2011, 03:48:02 pm
Ok, so here's what I have:

Code: [Select]
.nolist
#include "ti83plus.inc"
#include "dcs7.inc"
.list
_ExecutePrgm .equ 4E7Ch
.org progstart
ld hl, AppVar
rst 20h
bcall(_ChkFindSym)
jr nc, notOK
ld hl, AppVar
rst 20h
ld hl,AppVar-AppVarCode
bcall(_CreateAppVar)
jr c, notOK
ld hl, AppVarCode
ld bc,AppVar-AppVarCode
ldir
set 1,(iy+33h)
ret
notOK:
ld hl, 0
ld (CurCol),hl
ld hl, TextError
bcall(_PutS)
ret

AppVarCode:
.relocate $8001
bit 4, (iy + 8)
ret nz ;apd

ld hl, progName
rst 20h
bcall(_ChkFindSym)
ld a,b
or a
call nz, UnArchive
bcall(_ExecutePrgm)
call UnArchive
ret
UnArchive:
ld hl, progName
rst 20h
bcall(_Arc_Unarc)
ld hl, progName
rst 20h
ret

progName:
.db protProgObj, "OFFBY1", 0
AppVar:
.db AppVarObj,"OFFSCRPT"
TextError:
.db "Error!",0

.end
END
Title: Re: OFFSCRIPT
Post by: thepenguin77 on September 01, 2011, 03:07:52 pm
I had to fix a few little things, but now it should work exactly like you want it to.

Code: [Select]
.nolist
#include "ti83plus.inc"
#include "dcs7.inc"
.list
_ExecutePrgm .equ 4E7Ch ;feel free to add this to ti83plus.inc
.org progstart ;  doing this everytime will eventually
ld hl, AppVar ;  be a pain when you have a lot
rst 20h
bcall(_ChkFindSym) ;this leaves OP1 intact
jr c, appvarDoesntExist
bcall(_delVarArc)

; jr nc, notOK ;see below VV

ld hl, AppVar
rst 20h
appVarDoesntExist:

ld hl,AppVar-AppVarCode
bcall(_CreateAppVar)
; jr c, notOK ;this throws Err:Memory, not C
inc de ;|
inc de ;|these two are because DE is originally
ld hl, AppVarCode ;  pointing to the size bytes
ld bc,AppVar-AppVarCode
ldir
set 1,(iy+33h)
ret
;notOK:
; ld hl, 0 ;          ^^
; ld (CurCol),hl ;this is a matter of style, but you probably
; ld hl, TextError ; just want to overwrite OFFSCRPT. the reason
; bcall(_PutS) ; for this is in case you run your program twice
; ret ; or there's an OFFSCRPT present you didn't make

AppVarCode:
.relocate $8001
bit 4, (iy + 8)
ret nz ;apd

ld hl, progName
rst 20h
bcall(_ChkFindSym)
ret c ;you probably just forgot this
ld a,b
or a
call nz, UnArchive
bcall(_ExecutePrgm)
call UnArchive
ret
UnArchive:
ld hl, progName
rst 20h
bcall(_Arc_Unarc)
ld hl, progName
rst 20h
ret

progName:
.db protProgObj, "OFFBY1", 0
AppVar:
.db AppVarObj,"OFFSCRPT"

;TextError:
;.db "Error!",0 ;not needed now

.end
END

Every change I made includes a comment.
Title: Re: OFFSCRIPT
Post by: Deep Toaster on September 01, 2011, 05:31:40 pm
And make sure it's OFFSCRPT, not OFFSCRIPT (like in the topic title).