A83: Re: High Score...


[Prev][Next][Index][Thread]

A83: Re: High Score...




Tutorial #40...kindly post by your friend James Matthews, right here for ya
:)

HTH,

James.

Introduction.
Why would you want to write back to a program?  Best reason would be for
storing options, or high scores in games.  Other reasons could include
programs you don't want to be modified, you could make the program write
back to itself every time it is run.
Before we start looking at the program writeback, we must first look at two
new programs.  DevPac83, and ZASMLOAD.  DevPac83 is a program written by
Hannes Edfeldt (aka Moxax) that will run TASM, then squish your program into
an 83P file, ready to be transferred to your Ti.  ZASMLOAD takes a squished
program and runs it.  Both can be downloaded from either Ti-Files or
ticalc.org.  Here's a quick sub-tutorial on how to use them.
DevPac83.
Well, this isn't exactly, hard.  Write your program, go to the DOS Prompt,
and type "zasm [progname]".  If everything is ok, your program will be
compiled as a squished program ready to send to the your calculator.  Now,
squished programs cannot be run using the standard Send(9prgm[progname]
technique.  You will either need to use ZASMLOAD (described below), or one
of the OS's (SOS, for example).
ZASMLOAD.
First of all, do a little experiment.  Write following BASIC program:
"HELLO
Send(9prgmXXXX
Let XXXX be a program you don't have on your calculator, just to simplify
things.  Run that program.  It will crash at the program command.  Quit to
the Ti-OS…now, take a look at Ans.  Hello!  Just a useful bit of
information…and also good to understand ZASMLOAD.
To use ZASMLOAD you do exactly what we did above, except 'Hello' is replaced
by your program, and 'XXXX' is replaced by ZASMLOAD.  Obviously you need
ZASMLOAD on your calculator :)…quite a few games use it, so hopefully you'll
have a copy there already.  Now on to the real stuff…
If you would like to know more, please check out Ian Graf's explanation in
the reference section.  Thanks to Ian for helping me out on this…
New Commands.
No new commands, this is straight-forward
"use-your-existing-knowledge-in-a-clever-way"…
The Code.
Here we go…
call    _clrLCDFull
call    _homeup
ld      hl,ScoreText
call    _puts
call    _newline
ld      a,(highscore)
ld l,a
 ld      h,0
 call _dispHL  ; Display high score
call    _newline
ld      de,821ch
ld      hl,prompt
ld      bc,16
ldir
ld      a,1
ld      (ASM_IND_CALL),a
call    PGMIO_EXEC
call    _convop1
ld      a,e
 push af                  ; write back state
      call _zerooop1           ;
      ld de,op1                ;
      ld hl,prog               ;
      ld bc,7                  ;
      ldir                     ;
      call _chkfindsym         ;
      inc de                   ;
      inc de                   ;
      ld hl,highscore-$9327    ;
      add hl,de                ;
      pop af                   ;
      ld (hl),a                ;
      ret                      ; ret

prompt:        .db "Points: ",0
ScoreText:     .db "High Score: ",0
HighScore: .db 0000h
prog:  .db 5,"ZHIGH",0
Pretty straight forward right?  The only explanation probably needed is the
ld hl, highscore-$9327.  Well, hopefully that number is pretty familiar by
now.  Yes, its where your programs start in the memory.  So, what Ian (he
wrote this section, I copied it :) does it takes the address of the
highscore in the memory, subtract 9327 from it, so he has the address
relative the to the beginning of the program.  DE already has where the
program starts, since he's gone through the _chkfindsym etc.  So, he adds
those two together…then he puts in the value of A.
Remember:  You must squish this program for it to work!
Conclusion.
Thanks again to Ian…
Now, for a look ahead…most of the things we'll be dealing with are pretty
basic.  I'll be just guiding you through the steps necessary, but
occasionally they'll be a hairy tutorial or two…look out for an interrupt
program tutorial coming soon!  Also, less and less code will be just left
for us to assume that it works…I will explain more and more about how the
code works.  A good example is the next tutorial, a pixel plotting routine
by Olle Hedman.  Over and out…
 Related Topics.
All tutorials Copyright (c) James Matthews 1998, unless specified.