Since I got another calculator to play around with, I decided to make a simple, 2 player game over a link cable like nibls, where you both try to avoid each other.
The program successfully manages to decide if it is player 1, or player 2 and will exit if another player isn't found within a certain amount of time (IDK exactly; about 7 seconds?). However, once you get to the part where you actually play the game, the other player moves, but doesn't change direction, even if they press a key to do so. In addition, it moves in a direction different from the default direction, so some type of data has been received.
Here is some pseudo-code for what I'm trying to do:
;establish what player
draw screen
keyloop:
;adjust your own direction based on key presses
::if player1
::::halt to ensure that the other calc is ready to receive
::::send both low ($D3) to tell the other calc you are ready (it should be waiting in a loop for both to be set to low)
::::send your direction (sending 0-3; this should be a cheap way to avoid complicated sending)
::::start waiting for the other calc to send both low
::::halt to give the other calc enough time to send it's direction
::::read in the data from the port & save it to player 2's direction
::if player2, do the same thing, just in the opposite order
::advance the "snakes" & update screen (and check to see if someone has won)
Any help would be greatly appreciated; I have posted the entire source code below (converted from calcz80 to computerz80 code).
EDIT: This is the part of code that has the key loops, the part that is most likely causing trouble, below it is the entire source.
Code:
Code:
The program successfully manages to decide if it is player 1, or player 2 and will exit if another player isn't found within a certain amount of time (IDK exactly; about 7 seconds?). However, once you get to the part where you actually play the game, the other player moves, but doesn't change direction, even if they press a key to do so. In addition, it moves in a direction different from the default direction, so some type of data has been received.
Here is some pseudo-code for what I'm trying to do:
;establish what player
draw screen
keyloop:
;adjust your own direction based on key presses
::if player1
::::halt to ensure that the other calc is ready to receive
::::send both low ($D3) to tell the other calc you are ready (it should be waiting in a loop for both to be set to low)
::::send your direction (sending 0-3; this should be a cheap way to avoid complicated sending)
::::start waiting for the other calc to send both low
::::halt to give the other calc enough time to send it's direction
::::read in the data from the port & save it to player 2's direction
::if player2, do the same thing, just in the opposite order
::advance the "snakes" & update screen (and check to see if someone has won)
Any help would be greatly appreciated; I have posted the entire source code below (converted from calcz80 to computerz80 code).
EDIT: This is the part of code that has the key loops, the part that is most likely causing trouble, below it is the entire source.
Code:
fkeyloop:
b_call(_grbufcpy)
ld a,(dirp2)
ld e,a
ld a,$fe
out (1),a
in a,(1)
cp $fe
call z,keydown
cp $fd
call z,keyleft
cp $fb
call z,keyright
cp $f7
call z,keyup
ld a,e
ld (dirp2),a
ld a,$d0
out (0),a
fkey1:
in a,(0)
and 3
cp 3
jr nz,fkey1
halt
in a,(0)
and 3
ld (dirp1),a
halt
ld a,$d3
out (0),a
ld a,$d0
or e
ld b,15
fkey2:
out (0),a
djnz fkey2
ld hl,fkeyloop
push hl
jp move
start:
call drawscreen
keyloop:
b_call(_grbufcpy)
ld a,(dirp1)
ld e,a
ld a,$fe
out (1),a
in a,(1)
cp $fe
call z,keydown
cp $fd
call z,keyleft
cp $fb
call z,keyright
cp $f7
call z,keyup
ld a,e
ld (dirp1),a
halt
ld a,$d3
out (0),a
ld a,$d0
or e
ld b,15
ksloop:
out (0),a
djnz ksloop
ld a,$d0
out (0),a
ksloop2:
;wait for othercalc
in a,(0)
and 3
cp 3
jr nz,ksloop2
halt
in a,(0)
and 3
ld (dirp2),a
ld hl,keyloop
push hl
Code:
#include "ti83plus.inc"
.list
.org $9D93
.db t2ByteTok, tAsmCmp
b_call(_runindicoff)
ld b,255
ld a,$d0
out (0),a
checkloop:
in a,(0)
bit 0,a
jr z,foundsig
djnz checkloop
ld a,1
ld (pnum),a
ld hl,$0eff
sendloop:
ld b,255
sl2:
ld a,$d1
out (0),a
djnz sl2
ld b,255
ld a,$d0
out (0),a
sl3:
in a,(0)
bit 0,a
jr z,start
djnz sl3
dec hl
ld a,h
or a
jp nz,sendloop
;loop timed out
ld hl,timedmsg
b_call(_newline)
b_call(_puts)
ret
foundsig:
ld b,255
fs2:
ld a,$d1
out (0),a
djnz fs2
call drawscreen
fkeyloop:
b_call(_grbufcpy)
ld a,(dirp2)
ld e,a
ld a,$fe
out (1),a
in a,(1)
cp $fe
call z,keydown
cp $fd
call z,keyleft
cp $fb
call z,keyright
cp $f7
call z,keyup
ld a,e
ld (dirp2),a
ld a,$d0
out (0),a
fkey1:
in a,(0)
and 3
cp 3
jr nz,fkey1
halt
in a,(0)
and 3
ld (dirp1),a
halt
ld a,$d3
out (0),a
ld a,$d0
or e
ld b,15
fkey2:
out (0),a
djnz fkey2
ld hl,fkeyloop
push hl
jp move
start:
call drawscreen
keyloop:
b_call(_grbufcpy)
ld a,(dirp1)
ld e,a
ld a,$fe
out (1),a
in a,(1)
cp $fe
call z,keydown
cp $fd
call z,keyleft
cp $fb
call z,keyright
cp $f7
call z,keyup
ld a,e
ld (dirp1),a
halt
ld a,$d3
out (0),a
ld a,$d0
or e
ld b,15
ksloop:
out (0),a
djnz ksloop
ld a,$d0
out (0),a
ksloop2:
;wait for othercalc
in a,(0)
and 3
cp 3
jr nz,ksloop2
halt
in a,(0)
and 3
ld (dirp2),a
ld hl,keyloop
push hl
move:
;advance snake
ld hl,p2y
ld a,(dirp2)
or a
jr nz,TEMPX1
inc (hl)
TEMPX1:
cp 3
jr nz,TEMPX2
dec (hl)
TEMPX2:
ld hl,p2x
cp 1
jr nz,TEMPX3
dec (hl)
TEMPX3:
cp 2
jr nz,TEMPX4
inc (hl)
TEMPX4:
ld a,(p2y)
ld e,a
ld a,(hl)
call getpixel
ld b,a
and (hl)
jp nz,p2lose
ld a,b
or (hl)
ld (hl),a
ld hl,p1y
ld a,(dirp1)
or a
jr nz,TEMPX5
inc (hl)
TEMPX5:
cp 3
jr nz,TEMPX6
dec (hl)
TEMPX6:
ld hl,p1x
cp 1
jr nz,TEMPX7
dec (hl)
TEMPX7:
cp 2
jr nz,TEMPX8
inc (hl)
TEMPX8:
ld a,(p1y)
ld e,a
ld a,(hl)
call getpixel
ld b,a
and (hl)
jp nz,p1lose
ld a,b
or (hl)
ld (hl),a
ret
p2lose:
pop hl
b_call(_newline)
ld a,(pnum)
ld hl,text
ld d,0
ld b,a
add a,a
add a,a
add a,b
add a,a
ld e,a
add hl,de
b_call(_puts)
ret
p1lose:
pop hl
b_call(_newline)
ld a,(pnum)
xor 1
ld b,a
ld hl,text
add a,a
add a,a
add a,b
add a,a
ld e,a
ld d,0
add hl,de
b_call(_puts)
ret
text:
.db "you lose!",0
.db "you win!!",0
keydown:
ld e,0
ret
keyup:
ld e,3
ret
keyleft:
ld e,1
ret
keyright:
ld e,2
ret
drawscreen:
;draw box around edge
ld hl,plotsscreen
ld de,plotsscreen+1
ld a,$00
ld (hl),a
ld bc,767
ldir
ld hl,plotsscreen
ld de,plotsscreen+1
ld a,$ff
ld (hl),a
ld bc,11
ldir
ld hl,plotsscreen+756
ld de,plotsscreen+757
ld (hl),a
ld bc,11
ldir
ld b,62
ld hl,plotsscreen+12
colloop:
ld a,(hl)
set 7,a
ld (hl),a
ld de,11
add hl,de
ld a,(hl)
set 0,a
ld (hl),a
inc hl
djnz colloop
b_call(_grbufcpy)
ret
getpixel:
ld h,0
ld d,h
ld l,e
add hl,hl
add hl,de
add hl,hl
add hl,hl
ld e,a
srl e
srl e
srl e
add hl,de
ld de,plotsscreen
add hl,de
and 7
ld b,a
ld a,$80
ret z
gploop:
rrca
djnz gploop
ret
pnum:
.db 0
timedmsg:
.db "link timed out.",0
dirp1:
.db 2
dirp2:
.db 1
p1x:
.db 16
p1y:
.db 16
p2x:
.db 80
p2y:
.db 48
.end
.end