Author Topic: Routines  (Read 293689 times)

0 Members and 1 Guest are viewing this topic.

Offline ztrumpet

  • The Rarely Active One
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5712
  • Rating: +364/-4
  • If you see this, send me a PM. Just for fun.
    • View Profile
Re: Routines
« Reply #90 on: March 17, 2010, 04:07:03 pm »
Thanks, should make my source slightly smaller if I got many sprites
Yup. :D
Note: I wanted to point out that DJ's sentence is 100% correct, as the source is smaller.  However, the compiled program will still be the same size. :)

SirCmpwn

  • Guest
Re: Routines
« Reply #91 on: March 19, 2010, 01:04:04 am »
Super cool routine!
Okay, with the help of Will_W and Player_, I got this routine:
Program Write-Back
Call this first (I mean first, have it as the first line):
Asm(21788411DF83010900EDB0

then, this:
Asm(21DF83E7EFF1421A47131A4F13131321959DEDB0

Attached is the source code that makes it work.  Please note that you cannot corrupt the last 9 bytes of tempSwapArea (L4).

NOTE: This routine is buggy and obsolete.  Please look ahead for a more appropriate solution.

*EDIT*
Added a .gif of it in action
« Last Edit: March 25, 2010, 09:57:12 am by SirCmpwn »

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Routines
« Reply #92 on: March 19, 2010, 01:16:11 am »
nice, but could you explain in more details how it works? Like, does it store to external vars and which ones? Does it use Self-modifying code? And if it's the later, where does it store the data in the program?

SirCmpwn

  • Guest
Re: Routines
« Reply #93 on: March 19, 2010, 10:51:36 am »
Well, the first routine gets the name of the program from OP1 and stores it to the last 9 bytes of tempSwapArea.  The last routine restores the name to OP1 and looks up the program, finds the length, and copies the program from 9D95 back into the original location (writeback).  That means you can modify any data that came from a [] statement and it will get saved back.  I'm not too sure though, because when I was playing around with it, I found that it crashed under certain conditions, such as If statements, While, Repeat, getkey().  I think Axe may use the last 9 bytes of tempSwapArea, which would explain it.  I'll look into it in a minute here and see if I can fix it.

*EDIT*
After comparing WikiTI's documentation of tempSwapArea to Axe's documentation of tempSwapArea, I found that tempSwapArea is 323 bytes long, but Axe only gives you 232.  I'll try revising my code to store to a different location and see if it works a bit better.
« Last Edit: March 19, 2010, 10:55:50 am by SirCmpwn »

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6265
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: Routines
« Reply #94 on: March 19, 2010, 11:20:26 am »
so pretty much program write back to preserve SMC? can't wait to try that! it will help immensely for saving things :)
/e

SirCmpwn

  • Guest
Re: Routines
« Reply #95 on: March 19, 2010, 11:23:16 am »
That's exactly what it does, but I can't figure out why it crashes when you use certain tokens in your Axe program.  Anyone care to look at my source code and try to figure it out?
« Last Edit: March 19, 2010, 11:23:37 am by SirCmpwn »

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6265
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: Routines
« Reply #96 on: March 19, 2010, 11:24:34 am »
have you tried to debug with wabbitemu? that might help, but sure post it and I'll try to help.
/e

SirCmpwn

  • Guest
Re: Routines
« Reply #97 on: March 19, 2010, 11:27:05 am »
I've been trying with Wabbit.  Look back a few posts to find the code.

Offline Eeems

  • Mr. Dictator
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6265
  • Rating: +318/-36
  • little oof
    • View Profile
    • Eeems
Re: Routines
« Reply #98 on: March 19, 2010, 11:28:44 am »
ah ok. It would probably help if you knew what was being used by the routines created for the tokens.
/e

SirCmpwn

  • Guest
Re: Routines
« Reply #99 on: March 19, 2010, 11:38:51 am »
Code: [Select]
Repeat getkey(15)
End
Dissassemles to:
Code: [Select]
Start:
 ld hl, $FD40
 call Label1
 jr Label2
Label1:
 ld a, h
 out ($01), a
 ld h, $00
 in a, ($01)
 and l
 ld l, h
 ret nz
 inc l
 ret
Label2:
 ld a, h
 or l
 jp nz, Label3
 jp Start
Label3:
 ret

SirCmpwn

  • Guest
Re: Routines
« Reply #100 on: March 19, 2010, 12:10:36 pm »
So I found out that nested conditionals are the deciding factor in whether or not it works.  However, I do not know why this is.  Help?

Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: Routines
« Reply #101 on: March 19, 2010, 12:37:56 pm »
Actually, looking at your hex codes, it seems like you are mixing up B and C when loading the size of the program. It is stored as little-endian. Also, since you are skipping the BB,6D bytes you may want to decrease BC twice to make sure there is not an overflow.
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

SirCmpwn

  • Guest
Re: Routines
« Reply #102 on: March 19, 2010, 01:12:57 pm »
Oh!  That is actually a really good point, let me try.

SirCmpwn

  • Guest
Re: Routines
« Reply #103 on: March 19, 2010, 01:24:18 pm »
Great, it worked!  Here are the new routines:
Program Write-back
This routine will allow you to save any changes you make during your program to data stored with the [] tokens.  Run this code in the very first line
Asm(217884118483010900EDB0

And run this to save your program:
Asm(218483E7EFF1421A4F131A4713131321959D0B0BEDB0

This routine uses the last nine bytes of L4 (tempSwapArea), so be careful not to modify them.

Attached is the code/hex.

Offline DJ Omnimaga

  • Clacualters are teh gr33t
  • CoT Emeritus
  • LV15 Omnimagician (Next: --)
  • *
  • Posts: 55942
  • Rating: +3154/-232
  • CodeWalrus founder & retired Omnimaga founder
    • View Profile
    • Dream of Omnimaga Music
Re: Routines
« Reply #104 on: March 19, 2010, 01:54:48 pm »
Would there be a way to have it stored to a less volatile area of the memory, like L1 or L2, so we don't have problems archiving/unarchiving or the like after we exit the program (assuming that's what Axe doc means)?
« Last Edit: March 19, 2010, 01:55:07 pm by DJ Omnimaga »