Author Topic: Shutdown command/asm line  (Read 11955 times)

0 Members and 1 Guest are viewing this topic.

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Shutdown command/asm line
« Reply #15 on: March 20, 2011, 07:36:08 pm »
I don't think it resets the stack or any of the non-volatile RAM storage areas (aside from the homescreen), so it shouldn't cause major leaks.
It might cause the copy of your program at $9D95 to never be deleted. That can cause major leaks.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Shutdown command/asm line
« Reply #16 on: March 20, 2011, 07:36:29 pm »
No, the leak occurs when you are running a program (not an APP). The reason is because the OS copies the program and when you use the same exiting routine as an APP or you use EF0850 (or a few other opcodes), the OS never readjusts the memory, creating a memory leak. So for example, running this code:
Code: [Select]
AsmPrgm
EF0850C9
Will make you lose 4 bytes of RAM because the code is four byte long. If you run this:
Code: [Select]
AsmPrgm
210000
224B84
EF4645
EF0850C9
That will make you lose 13 bytes of RAM.

EDIT: Ninja'd :O

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Shutdown command/asm line
« Reply #17 on: March 20, 2011, 07:42:41 pm »
Confirmed (and ninja'd (twice)):

In short, this should only be used in apps, because they don't get copied (not in this sense) in the first place.

EDIT: Huh, Wabbit doesn't do blank screens very well. There's a bug report for Buckeye.
« Last Edit: March 20, 2011, 07:43:43 pm by Deep Thought »




Offline Keoni29

  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2466
  • Rating: +291/-16
    • View Profile
    • My electronics projects at 8times8
Re: Shutdown command/asm line
« Reply #18 on: March 21, 2011, 03:54:33 am »
My programme runs on startup. When someone simply removes the battery while running ram clears and the password is no more (I'm the only one who knows that at my stupit skool XD)
Can I prevent this from happening?
If you like my work: why not give me an internet?








Offline AngelFish

  • Is this my custom title?
  • Administrator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 3242
  • Rating: +270/-27
  • I'm a Fishbot
    • View Profile
Re: Shutdown command/asm line
« Reply #19 on: March 21, 2011, 04:04:08 am »
In Axe? Not much. If you want to get into some fancy Assembly code, I think some people here know how the OS manages to do it though.

Quote
I don't think it resets the stack or any of the non-volatile RAM storage areas (aside from the homescreen), so it shouldn't cause major leaks.
It might cause the copy of your program at $9D95 to never be deleted. That can cause major leaks.

Oh yeah, forgot about that RAM copy. That'd be a major problem...
« Last Edit: March 21, 2011, 04:05:41 am by Qwerty.55 »
∂²Ψ    -(2m(V(x)-E)Ψ
---  = -------------
∂x²        ℏ²Ψ

Offline lookitsan00b

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 173
  • Rating: +37/-3
    • View Profile
Re: Shutdown command/asm line
« Reply #20 on: March 21, 2011, 10:38:22 am »
My programme runs on startup. When someone simply removes the battery while running ram clears and the password is no more (I'm the only one who knows that at my stupit skool XD)
Can I prevent this from happening?
Yep. Asm(215AA522BE85) should prevent ram clears. However, it will probably (never tried it) remain in effect until you next turn the calc off, so when you exit your program you might want to Asm(21000022BE85), although it shouldn't doesn't have any nasty side-effects if you don't.
« Last Edit: March 21, 2011, 10:39:49 am by lookitsan00b »
My TI-94+SE is broken.  I used some flawed existential conditioning on it, and it crashed. :(

Activity level:
{====______}

Spoiler For Securite:
{=========_}

A couple security flaws
Need a good backdoor short of reinstalling the OS
Completely immobilized and invalidated by Zstart. And rendered incompatible.
Spoiler For FFTATIA:
{====______}

framework: mostly done
graphics engine: undergoing complete rewrite
still need character and enemy sprites!!! :P

Offline Michael_Lee

  • LV9 Veteran (Next: 1337)
  • *********
  • Posts: 1019
  • Rating: +124/-9
    • View Profile
Re: Shutdown command/asm line
« Reply #21 on: March 21, 2011, 09:51:31 pm »
My programme runs on startup. When someone simply removes the battery while running ram clears and the password is no more (I'm the only one who knows that at my stupit skool XD)
Can I prevent this from happening?

You could copy the password to archive immediately so that you keep a copy in both RAM and flash.  Then, if somebody clears the RAM, you can check to see if the password exists in archive.
My website: Currently boring.

Projects:
Axe Interpreter
   > Core: Done
   > Memory: Need write code to add constants.
   > Graphics: Rewritten.  Needs to integrate sprites with constants.
   > IO: GetKey done.  Need to add mostly homescreen IO stuff.
Croquette:
   > Stomping bugs
   > Internet version: On hold until I can make my website less boring/broken.

Offline FloppusMaximus

  • LV5 Advanced (Next: 300)
  • *****
  • Posts: 290
  • Rating: +57/-5
    • View Profile
Re: Shutdown command/asm line
« Reply #22 on: March 21, 2011, 09:51:48 pm »
Yep. Asm(215AA522BE85) should prevent ram clears. However, it will probably (never tried it) remain in effect until you next turn the calc off, so when you exit your program you might want to Asm(21000022BE85), although it shouldn't doesn't have any nasty side-effects if you don't.
That's an interesting feature, I never knew about that.  You are missing some important details, though; while it certainly appears simpler than computing the correct checksum, it also has some weird side effects.  For example, you also need to initialize (statVars-2) with the desired boot-time stack pointer.  I wouldn't recommend doing it unless you understand the implications.  And I myself don't understand all of them.

Bear in mind that, whether you use the actual checksum or this A55A trick, you need to ensure that memory actually is in a safe state.  If you're writing a RAM assembly program, for instance, you need to free the allocated memory first (or else go through some horrible contortions to arrange to free yourself after the reset.)

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Shutdown command/asm line
« Reply #23 on: March 21, 2011, 11:19:47 pm »
Here it is. This will turn the calculator off properly with no memory leaks, the only downside is it's a little big.

Asm(21 E1 E5 22 72 98 3E C9 32 74 98 CD 72 98 11 0F 00 19 11 72 98 01 10 00 ED B0 C3 72 98 EF F1 42 EB 5E 23 56 21 95 9D EF 57 43 EF 08 50)

Put the name of your program in OP1 and run this, it deallocates your program and turns the calculator off. Needless to say, you should not run this from within Mirage.

Code: [Select]
ld hl, $E5E1 ;pop hl, push hl
ld (appBackUpScreen), hl
ld a, $C9
ld (appBackUpScreen+2), a
call appBackUpScreen ;we have to get a pointer to the runner
sizeToAdd:
ld de, sizeToAddEnd-sizeToAdd
add hl, de
ld de, appBackUpScreen
ld bc, runnerEnd-runnerStart
ldir
jp appBackUpScreen
sizeToAddEnd:

runnerStart:
bcall(_chkFindSym)
ex de, hl
ld e, (hl) ;grab its size
inc hl
ld d, (hl)
ld hl, $9D95
bcall(_delMem)

bcall(_powerOff) ;that's pretty nifty, I just found this

runnerEnd:

Edit:
    I don't know much about axe, but if you can get a pointer to the start of this routine, I can make it substantially smaller.
« Last Edit: March 21, 2011, 11:25:43 pm by thepenguin77 »
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Shutdown command/asm line
« Reply #24 on: March 22, 2011, 11:00:35 am »
Needless to say, you should not run this from within Mirage.

Why not? I don't know much about shells, sorry :-\
« Last Edit: March 22, 2011, 11:16:47 pm by Deep Thought »




Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Shutdown command/asm line
« Reply #25 on: March 22, 2011, 03:36:45 pm »
You cannot use it with MirageOS because while the OS copies the program to 9D95h, MirageOS moves the program to 9D95h. Pretty much, if you delmem at 9D95h, you delete your program data for good (instead of deleting the copy).

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: Shutdown command/asm line
« Reply #26 on: March 22, 2011, 04:08:33 pm »
Ah, so it'd be the same for any other shell, right?




Offline Xeda112358

  • they/them
  • Moderator
  • LV12 Extreme Poster (Next: 5000)
  • ************
  • Posts: 4704
  • Rating: +719/-6
  • Calc-u-lator, do doo doo do do do.
    • View Profile
Re: Shutdown command/asm line
« Reply #27 on: March 22, 2011, 04:22:15 pm »
Not necessarily, but most likely. If the shell executes the program the same way as the OS (likely by using one of the bcalls), then it wouldn't be a problem. Also, I am pretty sure that as long as the program is archived and there is no writeback, you won't need to worry.

Offline thepenguin77

  • z80 Assembly Master
  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1594
  • Rating: +823/-5
  • The game in my avatar is bit.ly/p0zPWu
    • View Profile
Re: Shutdown command/asm line
« Reply #28 on: March 22, 2011, 05:46:18 pm »
So...
Code: [Select]
:[110F0019117298011000EDB0C37298EFF142EB5E235621959DEF5743EF0850]->GDB000

Then.

:GDB000
:Asm(E9)

That ought to work. Just define GDB000, or whatever you want to call it, then run that little bit of code. The calculator should turn off.

Code: [Select]
sizeToAdd:
ld de, sizeToAddEnd-sizeToAdd
add hl, de
ld de, appBackUpScreen
ld bc, runnerEnd-runnerStart
ldir
jp appBackUpScreen
sizeToAddEnd:

runnerStart:
bcall(_chkFindSym)
ex de, hl
ld e, (hl) ;grab its size
inc hl
ld d, (hl)
ld hl, $9D95
bcall(_delMem)

bcall(_powerOff) ;that's pretty nifty, I just found this

runnerEnd:

Needless to say, you should not run this from within Mirage.

Why not? I don't know much about shells, sorry :-\

Nothing good can happen basically.
1. Program is in ram: The routine will find either the correct size, or random garbage, at which point it will delete your program, and possibly all of ram including the VAT. Or nothing if it's pointing to 0000's. (I've had like 31KB legitimately free before.)
2. Program is in flash: The routine will find some garbage value for the size and will delete all kinds of things in ram either giving you positive or negative memory leaks. But your program should still be intact.

Basically, just don't do it. ;)
zStart v1.3.013 9-20-2013 
All of my utilities
TI-Connect Help
You can build a statue out of either 1'x1' blocks or 12'x12' blocks. The 1'x1' blocks will take a lot longer, but the final product is worth it.
       -Runer112