Author Topic: David's Z80 Assembly Questions  (Read 16669 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 #30 on: May 19, 2011, 10:52:28 am »
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
 
  pop hl
  pop af
 
  and (hl)
  call z,SetGravity      ;If pixel below image is white, y=y+1
 
 
  ;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

Fixed. Thanks a lot Deep Thought.

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 #31 on: May 19, 2011, 11:02:09 am »
Np, and another thing: Don't be afraid to use gotos (JP/JR) in ASM. You could save a couple of bytes and some clock cycles by putting your MoveUp/MoveDown/MoveLeft/MoveRight routines inline (instead of in a separate CALL'd subroutine).




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #32 on: May 19, 2011, 11:04:28 am »
Np, and another thing: Don't be afraid to use gotos (JP/JR) in ASM. You could save a couple of bytes and some clock cycles by putting your MoveUp/MoveDown/MoveLeft/MoveRight routines inline (instead of in a separate CALL'd subroutine).

Ah yeah I only learnt how to use branched if's a while ago.

I have new code and a new problem:

Code: [Select]
;Draw line code
  push af
  push hl
  ld h,0
  ld l,63
  ld d,95
  ld e,63
  ld a,1
 
  call fastline
 
  pop hl
  pop af 
  ;End of draw line code
 
  ;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
 
  pop hl
  pop af
 
  and (hl)
  call z,SetGravity      ;If pixel below image is white, y=y+1
  ;End of gravity code
« Last Edit: May 19, 2011, 11:04:56 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 #33 on: May 19, 2011, 11:12:40 am »
POP HL \ POP AF now destroys the values returned by iGetPixel.

How about this: Use POP DE to put the value that was originally in HL (the X and Y coordinates) into DE. Then INC E instead of L in your SetGravity code. At the end of the routine, load DE into HL.




Offline calc84maniac

  • eZ80 Guru
  • Coder Of Tomorrow
  • LV11 Super Veteran (Next: 3000)
  • ***********
  • Posts: 2912
  • Rating: +471/-17
    • View Profile
    • TI-Boy CE
Re: David's Z80 Assembly Questions
« Reply #34 on: May 19, 2011, 11:15:26 am »
You're destroying the outputs of iGetPixel when you pop hl and pop af. Note that simply moving and (hl) before these pops won't help, because pop af changes the flags register. What does A hold, anyway?
"Most people ask, 'What does a thing do?' Hackers ask, 'What can I make it do?'" - Pablos Holman

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #35 on: May 19, 2011, 11:15:50 am »
That's actually a very good idea. I tried it but it's not working:

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
 
  ;Draw line code
  push af
  push hl
  ld h,0
  ld l,63
  ld d,95
  ld e,63
  ld a,1
 
  call fastline
 
  pop hl
  pop af 
  ;End of draw line code
 
  ;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
 
  pop de
 
  pop af
 
  and (hl)
  call z,SetGravity      ;If pixel below image is white, y=y+1
  ld l,e
  ld h,d
  ;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 e
  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

Am I loading DE into HL the right way?

@calc84maniac: a is the X of the sprite.
« Last Edit: May 19, 2011, 11:16:26 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 #36 on: May 19, 2011, 11:27:13 am »
POP AF still destroys A before you do the AND (HL) check. Move POP AF after all the gravity code.




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #37 on: May 19, 2011, 11:36:10 am »
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
 
  ;Draw line code
  ld h,0
  ld l,63
  ld d,95
  ld e,63
  ld a,1
 
  call fastline
  ;End of draw line code
 
  ;Start of gravity code
  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
 
  ;End of gravity code
 
  pop hl
 
  ;Getkeys code
  ld a,$FE
  out (1),a
  nop
  nop
  nop
  in a,(1)
 
  bit 1,a
  call z,CheckMoveLeft
 
  bit 2,a
  call z,CheckMoveRight
 
  bit 3,a
  call z,CheckMoveUp
  ;End of getkeys code
 
  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
 
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 found out I don't need to push/pop af and did that, the gravity doesn't work at all though.

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 #38 on: May 19, 2011, 11:50:50 am »
You still have POP HL after the SetGravity call, so anything you do to L in SetGravity is still destroyed.




Offline Hot_Dog

  • CoT Emeritus
  • LV12 Extreme Poster (Next: 5000)
  • *
  • Posts: 3006
  • Rating: +445/-10
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #39 on: May 19, 2011, 12:08:23 pm »
Btw Scout, you're learning ASM as fast as I was, so give yourself a pat on the back.

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #40 on: May 19, 2011, 12:16:37 pm »
Btw Scout, you're learning ASM as fast as I was, so give yourself a pat on the back.
* Scout pats himself on the back.

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
 
  ;Draw line code
  ld h,0
  ld l,63
  ld d,95
  ld e,63
  ld a,1
 
  call fastline
  ;End of draw line code
 
  ;Start of gravity code
  ld a,8
  add a,l
  ld e,a                 ;Sets e to y+8
 
  ld a,h                 ;Sets a to x
 
  call iGetPixel
 
  pop hl
  call z,SetGravity      ;If pixel below image is white, y=y+1
 
  ;End of gravity code
 
  ;Getkeys code
  ld a,$FE
  out (1),a
  nop
  nop
  nop
  in a,(1)
 
  bit 1,a
  call z,CheckMoveLeft
 
  bit 2,a
  call z,CheckMoveRight
 
  bit 3,a
  call z,CheckMoveUp
  ;End of getkeys code
 
  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
 
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

Here's my updated code, the gravity works but the main sprite still goes through the black line, I'm pretty sure I'm checking the pixel beneath the sprite the wrong way:

Code: [Select]
;Start of gravity code
  ld a,8
  add a,l
  ld e,a                 ;Sets e to y+8
 
  ld a,h                 ;Sets a to x
 
  call iGetPixel
 
  pop hl
  call z,SetGravity      ;If pixel below image is white, y=y+1
 
  ;End of gravity code

Basically what I want to do is Y-1 if there is no ON pixel beneath the sprite.

So I did this:

Code: [Select]
call iGetPixel
 
  and (hl)
  call z,SetGravity      ;If pixel below image is white, y=y+1
 
  ;End of gravity code
 
  pop hl                  ;Get old hl value
 
  ld a,l                  ;Set a to l to do some math with ti
  add a,e              ;I add e to a
 
  ld l,a            ;I set l to a, so if anything was increased to 'e', the 'y' position is also increased
...
SetGravity:
  ld e,0
  inc e
  ret

However, the sprite stills goes through the black line.

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 #41 on: May 19, 2011, 01:00:33 pm »
ADD A,E adds E regardless of whether or not SetGravity was called. E is never set to zero except in SetGravity, which means it's still 1 when you do that. Just move LD E,0 to the beginning (right before AND (HL)) and it should work.




Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #42 on: May 19, 2011, 01:02:50 pm »
I tried it Deep Thought as I got what you said (e is not being decreased when the pixel is white), but the square still goes through the line:

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
 
  ;Draw line code
  ld h,0
  ld l,63
  ld d,95
  ld e,63
  ld a,1
 
  call fastline
  ;End of draw line code
 
  ;Start of gravity code
  ld a,8
  add a,l
  ld e,a                 ;Sets e to y+8
 
  ld a,h                 ;Sets a to x
 
  call iGetPixel
 
  ld e,0
  and (hl)
  call z,SetGravity      ;If pixel below image is white, y=y+1
 
  ;End of gravity code
 
  pop hl
 
  ld a,l
  add a,e
 
  ld l,a
 
  ;Getkeys code
  ld a,$FE
  out (1),a
  nop
  nop
  nop
  in a,(1)
 
  bit 1,a
  call z,CheckMoveLeft
 
  bit 2,a
  call z,CheckMoveRight
 
  bit 3,a
  call z,CheckMoveUp
  ;End of getkeys code
 
  jp Loop

SetGravity:
  ld e,0
  inc e
  ret

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

MoveUp:
  dec l
  dec 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

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #43 on: May 21, 2011, 03:41:19 pm »
Bump?

Offline Munchor

  • LV13 Extreme Addict (Next: 9001)
  • *************
  • Posts: 6199
  • Rating: +295/-121
  • Code Recycler
    • View Profile
Re: David's Z80 Assembly Questions
« Reply #44 on: May 27, 2011, 05:12:25 pm »
Code: [Select]
; Written for Doors CS 7.0 and higher
.nolist
#include "ti83plus.inc"
#include "dcs7.inc"
.list
   .org userMem-2
   .db $BB,$6D
Init:
  B_CALL (_ClrLCDFull)
 
  set textWrite,(IY + sGrFlags)
  SET fracDrawLFont,(IY + fontFlags)
 
  ld a,1
  ld (penCol), a
  ld a,1
  ld (penRow), a
  ld hl,Title
  B_CALL (_VPutS)
 
  ld h,0
  ld l,9
  ld d,95
  ld e,9
  ld a,1
  call fastline
 
  call iFastCopy
 
  B_CALL (_GetKey)
 
  ret
 
Title:
  .db "Hello World",0

I managed to display the text where I wanted it, the way I wanted it.

Now I want to display the value I have in hl (I will get it through a Bcall). How can I display a value of HL in that screen?

I know I can use DispHL, but DispHL is homescreen, so how to display it there?

Thanks

I also got this routine in Axe, can it be of use?

Code: [Select]
p_DispInt:
.db 3
B_CALL(_DispHL)