i was reading the 28day tutorial (for the 8th time, i hate z80), and *GASP* i find getcsc also makes A = a hexidecimal value. with this, i wont have to use

Code:

Bcall Getcsc
CP sk1
jq nz,(A label)
CP sk2
jq nz,(another label)
...


...but! i have no idea how to do something like this:

Code:

If A=$3F
call (A label)
...


if i had that "If" for Z80, it would be much help. also, how do you use the Bcall "Random"?
[/code]
So, basically, call an address if A is equal to $3F?


Code:
cp $3F
call z, <Label>


Call can take all of the flags as a conditional that JP can.
oh. im guessing CP $3F tests A for that value.

how about the bcall? that would help for making my first z80 game.
What bcall? You mean bcallz(XXX)? When would you ever use that? If you want you can just jump over the bcall:

Code:
   cp $3F
   jr nz,skipBcall       ;usually you would just use jr nz,$+5 : 5 because jr takes 2 bytes and bcall is 3 bytes, so you jump forward 5 bytes
   bcall(_XXXX)
skipBcall:
Also, in your original example it should be jp not jq Wink

I think z80 code is really beautiful, though another pair (or two) of registers would have been really handy for some more complicated routines.
Mimas has something called JQ, which is replaced by the proper jp or jr on compilation. and i asked about the bcall Random.
LuxenD wrote:
Mimas has something called JQ, which is replaced by the proper jp or jr on compilation. and i asked about the bcall Random.


Just keep in mind that JR can only jump a limited distance forward/backward (128 bytes backward, 127 bytes forward) and doesn't have all the conditional flag modifiers that JP has (but it should be used when possible because it's more optimal on size and space.)

As for a random function, I don't know of any rand BCALL offhand, but you might want to use the ion routine provided in Ion/Mirage/DCS or check this out: http://wikiti.brandonw.net/index.php?title=Routines:Math:Random
chickendude wrote:
What bcall? You mean bcallz(XXX)? When would you ever use that? If you want you can just jump over the bcall


(That's exactly what the BCALLZ macro does; it jumps over the RST 28h instruction if the z flag is zero.)
i never mentioned bcall z,(xxx). Mimas has a BCall that is called Random. but the Ion Random looks nice, may use that instead.
Yeah, the Random bcall is equivalent to the TI-Basic rand, which means it's floating point (not very useful in ASM and also excessively slow, as you may know from Basic). Ion random is certainly a better choice.
LuxenD wrote:
i never mentioned bcall z,(xxx). Mimas has a BCall that is called Random. but the Ion Random looks nice, may use that instead.
Actually, as calc84 clarified, it's the TI-OS that has the Random bcall. Ion Random/iRandom is far better.
okay, i tried using the Mimas DoorsEQU, and Irandom is undefined. it is "CALL IRandom", isnt it?

Edit:I tried "Bcall IRandom" too; that also didnt work.
LuxenD wrote:
okay, i tried using the Mimas DoorsEQU, and Irandom is undefined. it is "CALL IRandom", isnt it?

Edit:I tried "Bcall IRandom" too; that also didnt work.
It is a call, not a bcall; is it case sensitive? If Mimas is in fact case-sensitive, try "iRandom" or "irandom". You could also try ionRandom, just in case.
ok, now ive tried CALL and BCALL, plus every possible case that would make sense. and i checked, it is DCS7 EQU.

im wondering if it was compiled without some of these things.

if it is the same as the code i got from Ashbad, then that also seemed not to work. after being run 3 times, the program crashed.
Did you remember to include the library in mimas?
I did include the library (actually, i even tried all the rest).
I wonder if loading the DCS program preset is required. meaning ill have to start all over...
well, the random thing was solved by just handcoding it into my program from BrandonW's wiki.

now, how would i compare 2 registers to eachother?
To compare to registers, you have a few ways, but let's start off easy...

You can always compare the A register to a number, using "cp *" like this:

Code:

cp 3Fh

If A=3Fh, then the z flag is set, otherwise, you have nz. If A>B, then the c flag is reset, otherwise it is set. Alternatively, you can compare register A to the other registers and (hl). For example:

Code:

cp b     ;compare A to B


If you want to compare B to C, though, there is no instruction for that, so you have to work around it. Two ways are:

Code:

ld a,b
cp c

or

Code:

ld a,c
cp b

There are some optimised alternatives as well, though. For example, instead of doing cp 0, which is 2 bytes and 7 cycles, try "or a" which is 1 byte and 4 cycles. If you don't understand how "or" works, don't worry about this optimisation for now.

Also, if you want to check if a register is 1 or -1 and you aren't worried about modifying it, you can simply do "inc [reg]" to see if reg=-1=255. This is because if you increment from 255, you go back to zero, setting the z flag. To check if the register is 1, do "dec [reg]" and to check if it is 0, you can do "inc [reg] \ dec [reg]."

For now, don't get caught up in the optimisations if you don't understand them. I am only showing them so that you recognise them later Smile For now, stick with "cp."

Also, there is a trick for comparing BC or DE to HL >.>
I don't think 16-bit inc/dec's set the flags, though. To compare 16-bit registers you'll have to use the sbc instruction with hl, just make sure the carry is reset.
chickendude wrote:
I don't think 16-bit inc/dec's set the flags, though. To compare 16-bit registers you'll have to use the sbc instruction with hl, just make sure the carry is reset.


Yep, that is correct. Basically, it is like this:

Code:

or a
sbc hl,bc
add hl,bc

That is essentially comparing HL to BC, returning the z and c flags the same as 'cp' does.
And to check for zero, you can do:

Code:

ld a,l
or h

And if you want to compare de and bc, i suppose you could just "ex de,hl", though i don't think that situation will arise very often Wink
allright, thanks for the codes. i havent started using any of the 16-bits yet for comparisons. now, my program keeps crashing when i load from somewhere else, so i wonder if im doing it wrong:


Code:

LD HL,(fShipX)
LD (curRow),HL

im trying to load fShipX to curRow, but...
  
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 1 of 2
» 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