*bump* So how's this going, David? Are you still working on honing your ASM? I've seen you on IRC a few times.
I have a new question:
Code:
I heard that I can shorten this to make it only 1 call. I'd also know how to make this able for press RIGHT and UP at the same time for example.
Oh and thanks calcdude, he told me this.
I was very happy to code most of that alone But I need help to polish it and make it even better.
Code:
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
I heard that I can shorten this to make it only 1 call. I'd also know how to make this able for press RIGHT and UP at the same time for example.
Oh and thanks calcdude, he told me this.
I was very happy to code most of that alone But I need help to polish it and make it even better.
When multiple keys are pressed, the key value (the number in A after in (A),1) is basically all of them AND'd together. It works like this:
For the arrow group, DOWN is $FE. That's %11111110. RIGHT is $FB, or %11111011. If both of them are pressed at the same time, the value in A would be %11111110 AND %11111011, or %11111010. So to check if one of the keys are pressed, you use BIT to see if that particular bit is reset or not.
So here's some code:
Code:
No need to keep doing LD A,$FE \ OUT (1),A since the key port's already set to $FE.
For the arrow group, DOWN is $FE. That's %11111110. RIGHT is $FB, or %11111011. If both of them are pressed at the same time, the value in A would be %11111110 AND %11111011, or %11111010. So to check if one of the keys are pressed, you use BIT to see if that particular bit is reset or not.
So here's some code:
Code:
LD A,$FE
OUT (1),A
NOP
NOP
IN A,(1)
BIT 0,A
CALL z,CheckMoveDown
BIT 1,A
CALL z,CheckMoveLeft
BIT 2,A
CALL z,CheckMoveRight
BIT 2,A
CALL z,CheckMoveUp
No need to keep doing LD A,$FE \ OUT (1),A since the key port's already set to $FE.
That alone didn't work so I did this:
Code:
I got what you did, but I still can't press multiple keys, but yeah a hell of an optimization in the code
So how can I press multiple keys?
Code:
ld a,$FE
out (1),a
nop
nop
in a,(1)
bit 0,a
cp $FB
call z,CheckMoveRight
bit 1,a
cp $FD
call z,CheckMoveLeft
bit 2,a
cp $FE
call z,CheckMoveDown
bit 3,a
cp $F7
call z,CheckMoveUp
I got what you did, but I still can't press multiple keys, but yeah a hell of an optimization in the code
So how can I press multiple keys?
[/code] bit 2,a
cp $FE [/code] Is not correct. The bit opcode sets or resets the zero flag. The cp $FE afterwards wipes out the result of the bit operation. Just remove all the cp's.
cp $FE [/code] Is not correct. The bit opcode sets or resets the zero flag. The cp $FE afterwards wipes out the result of the bit operation. Just remove all the cp's.
I tried this and none of the keys work:
Code:
I also tried adding another 'nop' but with no success.
Code:
.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
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:
ld a,l
cp 0
call nz,MoveUp
ret
MoveUp:
dec l
dec l
ret
CheckMoveDown:
ld a,l
cp 56
call nz,MoveDown
ret
MoveDown:
inc l
inc l
ret
CheckMoveLeft:
ld a,h
cp 0
call nz,MoveLeft
ret
MoveLeft:
dec h
dec h
ret
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
I also tried adding another 'nop' but with no success.
Notice that each of your calls is going to wipe out the accumulator (a); you need to do something about that.
If you mean saving the value of 'a' everytime I call a CheckMove label I tried this with no luck too:
Code:
I don't get what calls you're referring to, is it the other calls like iPutSprite and such that ruin a so I have to save it?
Code:
bit 0,a
ld d, 0
ld e, a
push de
call z,CheckMoveRight
pop de
pop de
bit 1,a
ld d,0
ld e,a
push de
call z,CheckMoveLeft
pop de
bit 2,a
ld d,0
ld e,a
push de
call z,CheckMoveDown
pop de
bit 3,a
ld d,0
ld e,a
push de
call z,CheckMoveUp
pop de
I don't get what calls you're referring to, is it the other calls like iPutSprite and such that ruin a so I have to save it?
Um, what the heck are you doing there? You know there's push af and pop af, right? No need to move to de every time. I was saying that in CheckMoveLeft and CheckMoveRight, you modify the value of the accumulator.
Yeah I only found out about af now... :$
Code:
I got this, but not working perfectly yet, the multi key pressing only works sometimes and when I press <DOWN> it goes left *sometimes*, going left doesn't always work, and it's *very* weird.
Code:
.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
I got this, but not working perfectly yet, the multi key pressing only works sometimes and when I press <DOWN> it goes left *sometimes*, going left doesn't always work, and it's *very* weird.
Oddly enough, I don't see anything wrong with that code. Can anyone else spot something that I've missed? David, did you happen to find the problem in the meantime?
calcman wrote:
Wouldn't the compiler notify you of your mistake?
*Assembler, and only mistakes that are obvious opcode mistakes such as misspelled opcodes or invalid operands. It won't detect if you do something incorrectly but with individually-valid opcodes.
The assembler told me nothing, here's what I did:
Code:
Because Deep Though said this here:
Bit 0 is down, bit 2 is right.
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.
<EDIT>
Code:
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.
Code:
bit 0,a
call z,CheckMoveDown
bit 1,a
call z,CheckMoveLeft
bit 2,a
call z,CheckMoveRight
bit 3,a
call z,CheckMoveUp
Because Deep Though said this here:
Quote:
Bit 0 is down, bit 2 is right.
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.
<EDIT>
Code:
.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.
You mean iGetPixel; there's no iGetSprite. That doesn't work because after you inc l you pop hl again.
Cemetech should really have scrollbars when code is too big :/
Code:
This is my current code, the problem with it is the sprite is going through the line I draw, so gravity is not really working.
Code:
.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
This is my current code, the problem with it is the sprite is going through the line I draw, so gravity is not really working.
No, you should really Pastebin code that is too big. Giant blocks of code take up tons of space in the database, and I like being miserly about database space to limit the rate of growth of the DB so that Cemetech stays sustainable for the long term.
Ah ok Kerm
All of my current code is here.
I tried implementing some stuff I was recommended by other ASM coders over at Omnimaga, but the ball still doesn't stop in the lines.
All of my current code is here.
I tried implementing some stuff I was recommended by other ASM coders over at Omnimaga, but the ball still doesn't stop in the lines.
You didn't listen to me. I told you that you were popping hl after modifying it, so all you needed to do was move the pop hl to right before call z,SetGravity.
If I do that, then I won't be testing 'and hl' the right way I think.
<EDIT> The z flag is set, popping won't reset it actually I think</EDIT>
http://pastebin.com/LqNhsVWq
Here it is, my current code, the sprite goes wild.
<EDIT> The z flag is set, popping won't reset it actually I think</EDIT>
http://pastebin.com/LqNhsVWq
Here it is, my current code, the sprite goes wild.
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
» Go to Registration page
Page 8 of 10
» 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
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