Calculator Community > Axe

Self-modifying code

(1/2) > >>

DJ Omnimaga:
In a post somewhere in that 3300+ posts sub-forum, Calc84maniac mentionned how is SMC behavior with Axe programs. However, I cannot find it anymore and I wanted to be certain SMC can really be used in Axe and if it's recommended.

If, for example, you store 7 to {GDB1+6}, is the data changed permanently, or is it reverted back to normal after exit?

What would be the behavior in the following?

(RAM prgm) no-stub
(RAM prgm) MirageOs
(RAM prgm) Ion
(RAM prgm) DoorCS
(RAM prgm) DoorCS from home screen (Noshell/Calcutil style)
(archived prgm) MirageOs with writeback to archived programs ON
(archived prgm) MirageOs with writeback to archived programs OFF
(archived prgm) Ion
(archived prgm) DoorCS
(archived prgm) DoorCS from home screen (Noshell/Calcutil style)

I would like to know, because to make a game, I would like to create a map editor and edit the map data directly. However, I am unsure if I want to have to use an APPVAR for that. If I can put the data and permanently modify it directly inside my program, I would rather do that instead (I backup often, anyway).

Quigibo:
Quite simply, no.  Self modifying code is not possible without disassembly of the generated programs becasue you need to get the address of the instruction to modify.  This is a bad practice becasue future versions and new optimizations change the size and order of the code which means you lose compatibility with newer versions.  That doesn't even include the fact that every time you modify your code, you have to disassemble again to get the address since it changes with how many bytes come before the SMC.  And yet another thing, it doesn't actually save very much space nor speed especially for the effort you would have to go through to implement it.  This does require greater than average assembly knowledge to do.

EDIT: Oops! I misread your post.  If you just want a write back, you can do this with axe commands by copying the running program in ram (address E9D93) into the program itself which you can get via the getcalc() command.  You can also get the size of the amount of data you need to copy with that command by reading the 2 byte number directly before the pointer.

DJ Omnimaga:
ah yeah that sounds more complicated than I expected x.x. Thanks for the info.

I guess I'll have to resort to storing to appvars then

calcdude84se:
Quigibo, is there any way to get the name of the program from w/in it? Because I may compile a program as DEMO but someone could rename it to DEMO4. Is there any way to check, or do I have to read OP1 at the beginning of the program?

calc84maniac:
Quigibo, are you aware that all shell programs automatically write-back? (Well, except the case DJ mentioned where an archived program is run in MirageOS with archive writeback turned off.)

Navigation

[0] Message Index

[#] Next page

Go to full version