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

0 Members and 2 Guests are viewing this topic.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #15 on: May 15, 2011, 10:05:19 am »
My goal is now to try and push b and then pop it so that everything goes allright.

Here's my plan:

Code: [Select]
Loop:
  ;Pop hl and save it to b, how do do this?
  ;Display image
  ;Store b to hl and then push it
  ;ClrLCDFull
  jr Loop

How to do the first and latter (the push and pop)? I can push and pop, but only hl, de, bc, I mean, 2 byte registers.

How can I do that with 1 byte registers? Thanks

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 #16 on: May 15, 2011, 10:14:03 am »
Just do it with loads.

Or if you want to make things easier, just push it and pop it and store HL on the stack. No need to move it to B.
« Last Edit: May 15, 2011, 10:15:24 am by Deep Thought »




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #17 on: May 15, 2011, 01:17:49 pm »
I made this code with the help of Runer and Deep Thought:

Code: [Select]
.nolist
#include "ti83plus.inc"
#include "dcs7.inc"
.list
   .org userMem-2
   .db $BB,$6D
Init:
  B_CALL (_ClrLCDFull)
  ld hl,0
 
Loop:                    ;Waits for the user to press [CLEAR]
 
  ld b,8
  ld ix,MyImage
  ld a,h
  push hl
 
  call iPutSprite        ;Display Image
  call iFastCopy         ;Put it in the buffer
 
  B_CALL(_GrBufClr)
 
  B_CALL (_GetCSC)
  pop hl
  cp skRight
  call z,CheckMoveRight
 
  jr Loop
 
CheckMoveRight:
  ld a,h
  cp 87
 
  call c,MoveRight
  ret

MoveRight:
  inc h
  inc h
  ret

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

You press right and the image goes right until it can't go more (X=88).

It doesn't work so well though :(
It works like the Catalog, when I first press it goes but only if I keep pressing the key it will go fast.
How can I change that? I'm using CSC...

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 #18 on: May 15, 2011, 01:20:10 pm »
CSC uses a system interrupt (TI's) that does that pause before repeating a key (it's part of the GetCSC routine). I think there's a way to change the pause (you could disable it entirely), but I don't know how that's done.

But if you're willing to work with direct input, you can do whatever you want from the key port.
« Last Edit: May 15, 2011, 01:20:16 pm by Deep Thought »




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #19 on: May 15, 2011, 01:22:35 pm »
CSC uses a system interrupt (TI's) that does that pause before repeating a key (it's part of the GetCSC routine). I think there's a way to change the pause (you could disable it entirely), but I don't know how that's done.

But if you're willing to work with direct input, you can do whatever you want from the key port.

That's not B_CALL _GetKey is it? I think not :(

I thought CSC was the way to go for games :P

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 #20 on: May 15, 2011, 01:24:37 pm »
CSC uses a system interrupt (TI's) that does that pause before repeating a key (it's part of the GetCSC routine). I think there's a way to change the pause (you could disable it entirely), but I don't know how that's done.

But if you're willing to work with direct input, you can do whatever you want from the key port.

That's not B_CALL _GetKey is it? I think not :(

Nope, it's this: Low Level Key Input

On the other hand, Xeda made a Speedy Keys program that changes the pause. You should ask her how she did it.




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #21 on: May 16, 2011, 09:14:52 am »
I tried this code:

Code: [Select]
.nolist
#include "ti83plus.inc"
#include "dcs7.inc"
.list
   .org userMem-2
   .db $BB,$6D
Init:
  B_CALL (_ClrLCDFull)
  ld hl,0
 
Loop:                    ;Waits for the user to press [CLEAR]
 
  ld b,8
  ld ix,MyImage
  ld a,h
  push hl
 
  call iPutSprite        ;Display Image
  call iFastCopy         ;Put it in the buffer
 
  B_CALL(_GrBufClr)
 
  ld a,$FB
  out (1),a
  in a,(1)
  cp $FB
  call z,CheckMoveRight
 
  jr Loop
 
CheckMoveRight:
  ld a,h
  cp 87
 
  call c,MoveRight
  ret

MoveRight:
  inc h
  inc h
  ret

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

For direct input, but it doesn't seem to work, the image appears and then disappears quickly and press RIGHT ($FD) does nothing. I think it may also have something related to the stack.

Any ideas?

Thanks

<EDIT>

I added a pop hl and now it displays the image, but nothing happens when I press RIGHT:

Code: [Select]
.nolist
#include "ti83plus.inc"
#include "dcs7.inc"
.list
   .org userMem-2
   .db $BB,$6D
Init:
  B_CALL (_ClrLCDFull)
  ld hl,0
 
Loop:                    ;Waits for the user to press [CLEAR]
 
  ld b,8
  ld ix,MyImage
  ld a,h
  push hl
 
  call iPutSprite        ;Display Image
  call iFastCopy         ;Put it in the buffer
 
  B_CALL(_GrBufClr)
 
  pop hl                             :Added pop hl here
   
  ld a,$FB
  out (1),a
  in a,(1)
  cp $FB
  call z,CheckMoveRight
 
  jr Loop
 
CheckMoveRight:
  ld a,h
  cp 87
 
  call c,MoveRight
  ret

MoveRight:
  inc h
  inc h
  ret

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

Here's the direct getkey code:

Code: [Select]
ld a,$FB
  out (1),a
  in a,(1)
  cp $FB
  call z,CheckMoveRight
 
  jr Loop
 
CheckMoveRight:
  ld a,h
  cp 87
 
  call c,MoveRight
  ret

$FB is the RIGHT keycode according to Z80 Asm in 28 Days.
« Last Edit: May 16, 2011, 04:03:10 pm by Scout »

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #22 on: May 17, 2011, 08:11:10 am »
Code: [Select]
  ld a,$FE
  out (1),a
  nop
  nop
  in a,(1)
  cp $FB
  call z,CheckMoveRight
 
  ld a,$FE
  out (1),a
  nop
  nop
  in a,(1)
  cp $FD
  call z,CheckMoveLeft
 
  ld a,$FE
  out (1),a
  nop
  nop
  in a,(1)
  cp $FE
  call z,CheckMoveDown
 
  ld a,$FE
  out (1),a
  nop
  nop
  in a,(1)
  cp $F7
  call z,CheckMoveUp

This getkeys code is currently not working for multi keys pressing so it won't go diagonal ways if I press both RIGHT and UP.

I also tried this, but also doesn't work:

Code: [Select]
ld a,$FE
  out (1),a
  nop
  nop
  nop
  in a,(1)
 
  bit 0,a
  call z,CheckMoveRight
 
  bit 1,a
  call z,CheckMoveLeft
 
  bit 2,a
  call z,CheckMoveDown
 
  bit 3,a
  call z,CheckMoveUp
« Last Edit: May 18, 2011, 02:25:16 pm by Scout »

Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #23 on: May 18, 2011, 02:26:18 pm »
Make sure that register A is not changed by the time your subroutine ends.  Otherwise you should save your value for A

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #24 on: May 18, 2011, 02:39:01 pm »
I did it, so it looks like this now:

Code: [Select]
.nolist
#include "ti83plus.inc"
#include "dcs7.inc"
.list
   .org userMem-2
   .db $BB,$6D
Init:
  B_CALL (_ClrLCDFull)
  ld hl,0
 
Loop:
 
  ld b,8
  ld ix,MyImage
  ld a,h
  push hl
 
  call iPutSprite        ;Display Image
  call iFastCopy         ;Put it in the buffer
 
  B_CALL(_GrBufClr)
 
  pop hl
   
  ld a,$FE
  out (1),a
  nop
  nop
  nop
  in a,(1)
 
  bit 0,a
  call z,CheckMoveRight
 
  bit 1,a
  call z,CheckMoveLeft
 
  bit 2,a
  call z,CheckMoveDown
 
  bit 3,a
  call z,CheckMoveUp
 
  jr Loop
 
CheckMoveUp:
  push af
  ld a,l
  cp 0
 
  call nz,MoveUp
  pop af
  ret

MoveUp:
  dec l
  dec l
  ret

CheckMoveDown:
  push af
  ld a,l
  cp 56
 
  call nz,MoveDown
  pop af
  ret

MoveDown:
  inc l
  inc l
  ret

CheckMoveLeft:
  push af
  ld a,h
  cp 0
 
  call nz,MoveLeft
  pop af
  ret

MoveLeft:
  dec h
  dec h
  ret

CheckMoveRight:
  push af
  ld a,h
  cp 87
 
  call c,MoveRight
  pop af
  ret

MoveRight:
  inc h
  inc h
  ret

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

It doesn't crash and some of the getkeys work but when i press <DOWN> it goes right and I can't always go right, and multi keypressing only works sometimes. What am I doing wrong?

Thanks in advance.

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 #25 on: May 18, 2011, 06:40:22 pm »
Bit 0 is down, bit 2 is right.




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #26 on: May 19, 2011, 02:54:51 am »
Bit 0 is down, bit 2 is right.

Thanks a lot, that sure worked!

I sort of get it because of the table I can see here. The lowest value is stored in the lower bit (0).

The order is $FE, $FD, $FE, $F7. So 0,1,2,3, Down, Left,Right, Up.

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 #27 on: May 19, 2011, 10:32:38 am »
Hence why with _GetCSC (and Axe), down, left, right, and up are 1, 2, 3, and 4 :)




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #28 on: May 19, 2011, 10:36:14 am »
Hence why with _GetCSC (and Axe), down, left, right, and up are 1, 2, 3, and 4 :)

Ah I see :D

Code: [Select]
.nolist
#include "ti83plus.inc"
#include "dcs7.inc"
.list
   .org userMem-2
   .db $BB,$6D
Init:
  B_CALL (_ClrLCDFull)
  ld hl,0
 
Loop:
 
  ld b,8
  ld ix,MyImage
  ld a,h
  push hl
 
  call iPutSprite        ;Display Image
  call iFastCopy         ;Put it in the buffer
 
  B_CALL(_GrBufClr)      ;Clears the graph screen
 
  pop hl
 
  ;Start of gravity code
  push af
  push hl
 
  ld a,8
  add a,l
  ld e,a                 ;Sets e to y+8
 
  ld a,h                 ;Sets a to x
 
  call iGetPixel
 
  and (hl)
  call z,SetGravity      ;If pixel below image is white, y=y+1
 
  pop hl
  pop af
  ;End of gravity code
 
  ld a,$FE
  out (1),a
  nop
  nop
  nop
  in a,(1)
 
  bit 0,a
  call z,CheckMoveDown
 
  bit 1,a
  call z,CheckMoveLeft
 
  bit 2,a
  call z,CheckMoveRight
 
  bit 3,a
  call z,CheckMoveUp
 
  jp Loop

SetGravity:
  inc l
  ret

CheckMoveUp:
  push af
  ld a,l
  cp 0
 
  call nz,MoveUp
  pop af
  ret

MoveUp:
  dec l
  dec l
  ret

CheckMoveDown:
  push af
  ld a,l
  cp 56
 
  call nz,MoveDown
  pop af
  ret

MoveDown:
  inc l
  inc l
  ret

CheckMoveLeft:
  push af
  ld a,h
  cp 0
 
  call nz,MoveLeft
  pop af
  ret

MoveLeft:
  dec h
  dec h
  ret

CheckMoveRight:
  push af
  ld a,h
  cp 87
 
  call c,MoveRight
  pop af
  ret

MoveRight:
  inc h
  inc h
  ret

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

I have new code, I need to decrease the y position of the sprite by 1 if the pixel below it is white to give a gravity effect. I'm using iGetSprite and have something wrong because there is no gravity at all.

What am I doing wrong?

Thanks in advance.

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 #29 on: May 19, 2011, 10:42:58 am »
Where it is now, CALL z,SetGravity INC's the L returned by iGetPixel, which is then destroyed by the POP HL right after it. You never actually INC the L that you use for a Y-value.