you jump to the Address in HL before even loading something into it Wink the other Correct2: and labels past it are never called if you press up.
Ashbad wrote:
you jump to the Address in HL before even loading something into it Wink the other Correct2: and labels past it are never called if you press up.


No, he's doing it right. The real problem is that bcall(_getCSC) destroys HL.
calc84maniac wrote:
Ashbad wrote:
you jump to the Address in HL before even loading something into it Wink the other Correct2: and labels past it are never called if you press up.


No, he's doing it right. The real problem is that bcall(_getCSC) destroys HL.

Oh, it does? =/
Can I use push hl/pop hl?
technomonkey76 wrote:
calc84maniac wrote:
Ashbad wrote:
you jump to the Address in HL before even loading something into it Wink the other Correct2: and labels past it are never called if you press up.


No, he's doing it right. The real problem is that bcall(_getCSC) destroys HL.

Oh, it does? =/
Can I use push hl/pop hl?

I think that would work. Also, be careful after you run AllCorrect, because the program will return to the loop with an undefined value in HL.
I personally never really use jp (hl) due to no conditionals as arguments or other customizations. a JP ADDRESS in your code would be much better and easier to debug than jumping to the somewhat-unknown value of HL.
Ashbad wrote:
I personally never really use jp (hl) due to no conditionals as arguments or other customizations. a JP ADDRESS in your code would be much better and easier to debug than jumping to the somewhat-unknown value of HL.

It's a very nice tool if you use it correctly. This program is a good exercise in its use.
Okay! The program finally works! Very Happy Thanks for all your help, fellow Cemetechians! I will change Pastebin so it has the final version of the code right now. Smile
well, as long as it works, great Very Happy sorry if I caused any confusion, I just rarely use Rom calls so I can use that as my excuse that I didn't know they usually destroy HL Razz

It seems that you are getting quite adept at z80 programming technomonkey Wink you're a pretty fast learner, like aeTIos. Keep it up! Smile you're already learning it faster than I did the 3rd time I tried XD
It seems to me that Techno is learning very fast indeed, keep up the great work. Ashbad, when in doubt, assume that bcalls() (and calls, for that matter) trash everything, and then look at the relevant documentation (the TI Routine Reference for bcalls, the DCS SDK for ASM libraries, your own code for your own calls) to determine what actually gets destroyed.
KermMartian wrote:
It seems to me that Techno is learning very fast indeed, keep up the great work. Ashbad, when in doubt, assume that bcalls() (and calls, for that matter) trash everything, and then look at the relevant documentation (the TI Routine Reference for bcalls, the DCS SDK for ASM libraries, your own code for your own calls) to determine what actually gets destroyed.

Thanks, Kerm and Ashbad! I need to change line 23 to a more advanced routine to avoid RAM leaks now, however. Sad I just learned that _PowerOff should only be used with apps due to the copying of the program to $9D95. Oh well.
Edit: Very Happy Google found me Reply 23 by thepenguin77 at http://ourl.ca/97495!
Output $02 to port $10 to turn off the screen manually, but remember to send $03 to port $10 to turn it back on Wink

here is example code:


Code:
   LD C,$10
   OUT (C),$02
   PUSH BC
@
   BCALL getCSC   ;Evil BCALL! but used for simplicity ;)
   CP skEnter
   JP NZ,{-1@}
@
   POP BC
   OUT (C),$03


This will keep it off until you press enter, as a crude example Wink

EDIT: not the same effect as PowerOff, but pretty darn close Wink
Errr, what? That's not the right way to do it at all, because you'll be wasting the battery in the loop. You want to enable interrupts with the [on] key set as a valid interrupt trigger, then halt to save battery.
KermMartian wrote:
Errr, what? That's not the right way to do it at all, because you'll be wasting the battery in the loop. You want to enable interrupts with the [on] key set as a valid interrupt trigger, then halt to save battery.

Code? Obviously I'll be using the iy flags, but I'm not good with interrupts yet.
technomonkey76 wrote:
KermMartian wrote:
Errr, what? That's not the right way to do it at all, because you'll be wasting the battery in the loop. You want to enable interrupts with the [on] key set as a valid interrupt trigger, then halt to save battery.

Code? Obviously I'll be using the iy flags, but I'm not good with interrupts yet.
You don't have to actually write an interrupt; you just use im 1, aka the TI interrupt. Here's code copied and pasted directly from Doors CS:


Code:
Off:
   ld a,2
   out ($10),a ;turn off screen
   res OnInterrupt,(iy+OnFlags)
   call debounceon
   call calcAndStore_OSChecksum
   im 1
   ei                        ;enable interrupts
   ld   a,1                  ;enable ONLY [ON] key, no linkport wake
   out   (3),a
   halt
   di
   res OnInterrupt,(iy+OnFlags)
mode on halt
   ld a,%00001011
   out (3),a
   ld a,3
   out ($10),a ;turn on screen
debounceon:
   ld b,16
debounceoninner:
   in a,(4)
   bit 3,a
   jr z,debounceon
   djnz debounceoninner
   ret
;-------------------------------
KermMartian wrote:
technomonkey76 wrote:
KermMartian wrote:
Errr, what? That's not the right way to do it at all, because you'll be wasting the battery in the loop. You want to enable interrupts with the [on] key set as a valid interrupt trigger, then halt to save battery.

Code? Obviously I'll be using the iy flags, but I'm not good with interrupts yet.
You don't have to actually write an interrupt; you just use im 1, aka the TI interrupt. Here's code copied and pasted directly from Doors CS:


Code:
Off:
   ld a,2
   out ($10),a ;turn off screen
   res OnInterrupt,(iy+OnFlags)
   call debounceon
   call calcAndStore_OSChecksum
   im 1
   ei                        ;enable interrupts
   ld   a,1                  ;enable ONLY [ON] key, no linkport wake
   out   (3),a
   halt
   di
   res OnInterrupt,(iy+OnFlags)
mode on halt
   ld a,%00001011
   out (3),a
   ld a,3
   out ($10),a ;turn on screen
debounceon:
   ld b,16
debounceoninner:
   in a,(4)
   bit 3,a
   jr z,debounceon
   djnz debounceoninner
   ret
;-------------------------------

What is the code for calcAndStore_OSChecksum?
I think that calculates the RAM checksum, like the TIOS does so that it doesn't clear RAM when starting the program again.
KermMartian wrote:
Errr, what? That's not the right way to do it at all, because you'll be wasting the battery in the loop. You want to enable interrupts with the [on] key set as a valid interrupt trigger, then halt to save battery.


That indeed would be a great way to do an actual shutoff -- however, what I posted can be used as more of a "Teacher Key" code as it is extremely small, and a full-out shutoff is not always necessary. However what Kerm posted should be used if you have the proper space -- but in some cases you might not, and when you don't and the turn off is meant to be a few seconds I would recommend my routine.
It seems fast enough. Definitely not "a few seconds" Neutral
Deep Thought wrote:
It seems fast enough. Definitely not "a few seconds" Neutral


Well, if you're BSing your teacher for a few seconds is what I meant Razz I doubt you'll be in Teacher Mode for more than ~10 secs.

Not the speed of the actual routine.
Ashbad wrote:
KermMartian wrote:
Errr, what? That's not the right way to do it at all, because you'll be wasting the battery in the loop. You want to enable interrupts with the [on] key set as a valid interrupt trigger, then halt to save battery.


That indeed would be a great way to do an actual shutoff -- however, what I posted can be used as more of a "Teacher Key" code as it is extremely small, and a full-out shutoff is not always necessary. However what Kerm posted should be used if you have the proper space -- but in some cases you might not, and when you don't and the turn off is meant to be a few seconds I would recommend my routine.
No offense, but I'm going to disagree with you there. By the way, I should note that that Checksum routine (which I failed to include, my error) is part of the mechanism that prevents RAM from being cleared if a battery is pulled during the off. My routine, excluding the checksum routine, is 42 bytes; I can't think of anything, even Doors CS, that doesn't have room for 42 bytes. The routine takes milliseconds to complete; I see no reason not to use it even for a few seconds of poweroff.
  
Register to Join the Conversation
Have your own thoughts to add to this or any other topic? Want to ask a question, offer a suggestion, share your own programs and projects, upload a file to the file archives, get help with calculator and computer programming, or simply chat with like-minded coders and tech and calculator enthusiasts via the site-wide AJAX SAX widget? Registration for a free Cemetech account only takes a minute.

» Go to Registration page
Page 4 of 5
» All times are UTC - 5 Hours
 
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum

 

Advertisement