Author Topic: David's Z80 Assembly Questions  (Read 17131 times)

0 Members and 1 Guest are viewing this topic.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
David's Z80 Assembly Questions
« on: May 13, 2011, 03:38:10 pm »
I decided to create a topic to gather all my z80 asm questions since I have a few and I'm still learning.

First of all, I'd like you guys to know how advanced I am, this was my (best?) program:

Code: [Select]
.nolist 
#include "ti83plus.inc" 
.list 
   .org userMem-2 
   .db $BB,$6D 
Init: 
  B_CALL _ClrLCDFull 
   
  ld hl,0
  ld (curCol), hl
  ld hl,Welcome
  B_CALL _PutS

  B_CALL _GetKey 
   
  cp kEnter 
   
  jr z,Win 
   
  B_CALL _ClrLCDFull 

  ld hl,0 
  ld (curCol), hl
   
  ld hl,LoseTxt 
   
  B_CALL _PutS 
   
  B_CALL _GetKey 
  B_CALL _ClrLCDFull 
  ret 

LoseTxt: 
  .db "LOSE",0   
   
Win: 
  B_CALL _ClrLCDFull

  ld hl,0 
  ld (curCol), hl
   
  ld hl,WinTxt

  B_CALL _PutS
  B_CALL _GetKey
  B_CALL _ClrLCDFull
  ret
WinTxt:
  .db "WIN",0
Welcome:
  .db "Press ",$C1,"ENTER]",0

If you run it, it asks you to press [ENTER], if you do, you win, if you don't, well you lose The Game.

My first question is how to make Axe-like loops in Asm? In Axe, I'd do something like Repeat getKey(15). How would I do that in Assembly?

Code: [Select]
TitleScreen:
 ;Title Screen code
Loop:
 ;Code
 cp kClear
 jr z, TitleScreen
 jr Loop

I thought of this, but I can't test it right now. Thanks :D

<Edit>
I actually tried this and it looped forever, freezing my calc:

Code: [Select]
Start:
  cp kClear
  jr z, End
  jr Start
End:
  ret

I'm pretty sure I'm doing something wrong, but I'm a bit rusty at z80 asm.
« Last Edit: May 13, 2011, 03:46:49 pm by Scout »

Ashbad

  • Guest
Re: David's Z80 Assembly Questions
« Reply #1 on: May 13, 2011, 03:47:50 pm »
well, some simple loops:

for statement --

Code: [Select]
   LD B, number_of_loops
@
   ; code
   DJNZ {-1@}
@

Your getkey loop:

Code: [Select]
@
   BCALL(GetKey)
   CP kClear
   JP NZ, {-1@}
@

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #2 on: May 13, 2011, 04:11:11 pm »
Oh my how stupid, I forgot about B_CALL (_GetKey).

Thanks a lot for reminding me of that, this worked:

Code: [Select]
Start:
  B_CALL (_GetKey)
  cp kClear
  jr z, End
  jr Start
End:
  ret

:)

I have a very big problem now, I know how to display images using iPutSprite, but I wanted to make a cursor. My problem was clearing the screen in the end of the loop (it wiped out some registers).

Offline lookitsan00b

  • LV4 Regular (Next: 200)
  • ****
  • Posts: 173
  • Rating: +37/-3
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #3 on: May 13, 2011, 04:55:10 pm »
Actually, if you want something similar to getkey(15), you might want:
Code: [Select]
jr loop_Condition
loop:
 ;code
loop_Condition:
 b_call(getCSC) ;getCSC doesn't wait for a key to be pressed, _GetKey will.
 cp 15             ;Im not sure what the equate is called, prolly skClear
 jr nz,loop

As for wiping out registers, push and pop really help :D
My TI-94+SE is broken.  I used some flawed existential conditioning on it, and it crashed. :(

Activity level:
{====______}

Spoiler For Securite:
{=========_}

A couple security flaws
Need a good backdoor short of reinstalling the OS
Completely immobilized and invalidated by Zstart. And rendered incompatible.
Spoiler For FFTATIA:
{====______}

framework: mostly done
graphics engine: undergoing complete rewrite
still need character and enemy sprites!!! :P

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #4 on: May 13, 2011, 04:57:48 pm »
Actually, if you want something similar to getkey(15), you might want:
Code: [Select]
jr loop_Condition
loop:
 ;code
loop_Condition:
 b_call(getCSC) ;getCSC doesn't wait for a key to be pressed, _GetKey will.
 cp 15             ;Im not sure what the equate is called, prolly skClear
 jr nz,loop

As for wiping out registers, push and pop really help :D

I guess that is indeed better. Also, kClear works for me.

Thanks to the getCSC bcall trick I think I can now make my cursor program.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #5 on: May 14, 2011, 04:30:09 am »
Here's what I did:

Code: [Select]
Start:
  B_CALL (_ClrLCDFull)
Loop:
  B_CALL (_GetKey)
  cp kClear
  jr z,End
  kr Loop
End:
  ret

So this will wait a for a [CLEAR] press and then close the loop.

I tried changing it to this:

Code: [Select]
Start:
  B_CALL (_ClrLCDFull)
Loop:
  B_CALL (_GetCSC)          ;The change is done here
  cp kClear
  jr z,End
  kr Loop
End:
  ret

And it freezes the calculator. Am I not using GetCSC the right way?

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: David's Z80 Assembly Questions
« Reply #6 on: May 14, 2011, 09:41:07 am »
_GetCSC uses different key codes than _GetKey. You should check for skClear (15), not kClear (9).




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #7 on: May 15, 2011, 07:25:26 am »
I have a problem assembling now:

Code: [Select]
.nolist
#include "ti83plus.inc"
#include "dcs7.inc"
.list
   .org userMem-2
   .db $BB,$6D
Init:
  B_CALL (_ClrLCDFull)
  ld ix,MyImage          ;Image
  ld b,8                 ;Height
  ld a,0                 ;X
  ld l,0                 ;Y

  call iPutSprite
  call iFastCopy

Loop:
  B_CALL (_GetKey)
  cp kClear
  jr z,End
  jr Loop
 
MyImage:
  .db $FF,$81,$81,$81,$81,$81,$81,$FF
 
End:
  ret

That's my code, I'm trying to display an image, here's the output from the assembler:

Code: [Select]
----------------------------------
----- Assembling display1 for the TI-83/84 Plus...
Brass Z80 Assembler 1.0.4.11 - Ben Ryves 2005-2006
--------------------------------------------------
Assembling...
Error: Unsupported directive '.end:'. [zztemp.asm:27]
Pass 1 complete. (636ms).
Pass 1 failed, pass 2 therefore skipped.
Errors: 1, Warnings: 0.

I don't have any '.end' in my code :(

Offline JosJuice

  • LV10 31337 u53r (Next: 2000)
  • **********
  • Posts: 1344
  • Rating: +66/-14
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #8 on: May 15, 2011, 07:26:56 am »
Add an .end at the end.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #9 on: May 15, 2011, 07:32:33 am »
This worked for me:

Code: [Select]
.nolist
#include "ti83plus.inc"
#include "dcs7.inc"
.list
   .org userMem-2
   .db $BB,$6D
Init:
  B_CALL (_ClrLCDFull)
  ld ix,MyImage          ;Image
  ld b,8                 ;Height
  ld a,0                 ;X
  ld l,0                 ;Y

  call iPutSprite        ;Display Image
  call iFastCopy         ;Put it in the bugger

  jr Loop

Loop:                    ;Waits for the user to press [CLEAR]
  B_CALL (_GetCSC)
  cp skClear
  ;jr z,End
  jr Loop
 
MyImage:
  .db $FF,$81,$81,$81,$81,$81,$81,$FF

Yes! I displayed an image! Now I'll try and make it move with the arrows.

<Edit>

I tried this to make the sprite move right when the user presses the right key:

Code: [Select]
Init:
  B_CALL (_ClrLCDFull)
  ld ix,MyImage          ;Image
  ld b,8                 ;Height
  ld a,0                 ;X
  ld l,0                 ;Y

  jr Loop

Loop:                    ;Waits for the user to press [CLEAR]
  B_CALL (_GetCSC)
 
  call iPutSprite        ;Display Image
  call iFastCopy         ;Put it in the bugger
 
  cp skRight
  call z,MoveRight
 
  jr Loop

MoveRight:
  inc l

MyImage:
  .db $FF,$81,$81,$81,$81,$81,$81,$FF

However, the sprite isn't even displayed in the right place, is it because GetCSC exterminates registers?
« Last Edit: May 15, 2011, 09:24:42 am by Scout »

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: David's Z80 Assembly Questions
« Reply #10 on: May 15, 2011, 09:25:34 am »
It's actually because END is a reserved keyword in Brass. You used it as a label in your original code, and Brass got confused why it had a colon after it.




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #11 on: May 15, 2011, 09:32:08 am »
Ah thanks a lot Deep Thought, that explains it, Mimas didn't have that problem.

Code: [Select]
.nolist
#include "ti83plus.inc"
#include "dcs7.inc"
.list
   .org userMem-2
   .db $BB,$6D
Init:
  B_CALL (_ClrLCDFull)

Loop:                    ;Waits for the user to press [CLEAR]
  B_CALL (_GetCSC)
 
  ld b,8
  ld ix,MyImage
  ld l,0
 
  call iPutSprite        ;Display Image
  call iFastCopy         ;Put it in the bugger
 
  cp skRight
  call z,MoveRight

  B_CALL (_ClrLCDFull)
 
  jr Loop

MoveRight:
  inc a

MyImage:
  .db $FF,$81,$81,$81,$81,$81,$81,$FF

I tried this to display an image and make it move right when I press RIGHT. However, it has some problems.

I don't know what registers BCalls wipe out, where can I find such info?

Either way, when I press [CLEAR] with that code weird stuff happens.

Any ideas, I'm trying to make a sort of a cursor.

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: David's Z80 Assembly Questions
« Reply #12 on: May 15, 2011, 09:39:29 am »
Ah thanks a lot Deep Thought, that explains it, Mimas didn't have that problem.

Blame TASM. They required the line ".end", then a newline, just to know that the file is done. Brass reserved "end" as a keyword for compatibility.

I don't know what registers BCalls wipe out, where can I find such info?

Either way, when I press [CLEAR] with that code weird stuff happens.

Pretty much everything you need is on WikiTI. Just find the bcall and look up "Destroys".

And if you're ever too lazy to check, just assume it destroys everything. That's what a lot of them do, anyway. Plus it avoids issues where TI releases a new OS where a certain bcall uses more registers than before, and now you gotta rewrite the whole thing.

Any ideas, I'm trying to make a sort of a cursor.

Have you tried the DCS libs? It makes graphical stuff like that a ton easier.




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #13 on: May 15, 2011, 09:42:07 am »
I am using DCS Libs, iPutSprite and iFastCopy, but those are more like Ion.

Thanks a lot for WikiTI link I had forgotten about it.

I will take a look at more graphical functions of DCS Libs then.

I want a cursor, but not DCS's by the way, also:

Code: [Select]
B_CALL _ClrLCDFull

Destroys
All

xD

Offline Deep Toaster

  • So much to do, so much time, so little motivation
  • Administrator
  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 8217
  • Rating: +758/-15
    • View Profile
    • ClrHome
Re: David's Z80 Assembly Questions
« Reply #14 on: May 15, 2011, 09:47:06 am »
Code: [Select]
B_CALL _ClrLCDFull

Destroys
All

xD

A lot of them do that. Even ones you'd expect to be saved (for whatever reason) often get destroyed. Like _DispHL: what it does is display the value of HL in decimal on the screen. You'd expect it to keep HL intact, so you can keep working on it, but it doesn't. It destroys everything except BC.