Hi!
I just succesfully transmitted a few bytes across the joystick network
cable. As promised, the sources are in this mail.
Final bug was removed just 15 minutes ago, so don't expect optimized code ;)
There is still a weak point in the protocol I used. It can cause trouble if
you send one transfer quickly after another and interrupts are enabled
inbetween. I'll fix it soon. But if you just want to send one byte manually
(for example to check your cable) or you don't mind to keep interrupts
disabled the whole time, this source works perfectly.
The problem lies in the fact that not just the triggers are fixed to '1' by
the BIOS interrupt routine, but also the strobe is fixed to '0'. Since the
strobe is used for the ACK signal, a strobe going to '0' because of the
BIOS can be mistaken for the first ACK of a new transfer. I will fix the
protocol by adding an extra step that will ensure ACK is '0' at the end of
a transfer.
Bye,
Maarten
;-------------------------------------------------------------------
; SENDREC1.ASM
; My first working send & receive program
; for the MSX joystick network.
;
; 25-7-98
; Maarten ter Huurne (Kryten/Mayhem)
; [EMAIL PROTECTED]
PORT_1_MASK: equ %0000 1100
PORT_2_MASK: equ %0100 0011
STROBE_1: equ %0001 0000
STROBE_2: equ %0010 0000
LEFT_MASK: equ %0000 0100
BACK_MASK: equ %0000 0010
FWD_MASK: equ %0000 0001
DR0_MASK: equ %0000 0101
DR1_MASK: equ %0000 1010
org #C000
BIN_START:
BIN_EXEC:
jp init
;in: a = joystick port (0 or 1)
jp send_byte
;in: c = byte
jp recv_byte
;out: c = byte
init:
or a
jr z,init_port1
ld a,PORT_2_MASK
ld c,STROBE_2
jr init_port
init_port1:
ld a,PORT_1_MASK
ld c,STROBE_1
init_port:
ld (portMask),a
ld a,c
ld (ackMask),a
di
call set_neutral
ei
ret
portMask: db 0
ackMask: db 0
set_neutral:
ld a,15
out (#A0),a
in a,(#A2)
or %0000 1111
out (#A1),a
ret
wait_ack:
;d = previous ACK
ld a,14
out (#A0),a
wait_ack_loop:
in a,(#A2)
xor d
bit 2,a
jr z, wait_ack_loop
in a,(#A2)
ld d,a
ret
send_ack:
;changes e
; signal ACK
ld a,15
out (#A0),a
ld a,(ackMask)
ld e,a
in a,(#A2)
xor e
out (#A1),a
ret
send_byte:
;c = data
di
; set port
ld a,15
out (#A0),a
ld a,(portMask)
ld e,a
in a,(#A2)
and %1011 1111
or e
out (#A1),a
; read initial ACK status
ld a,14
out (#A0),a
in a,(#A2)
ld d,a
ld b,8
send_byte_loop:
ld a,15
out (#A0),a
in a,(#A2)
rr c
jr c,send_byte_dr1
; signal DR0
xor DR0_MASK
or e
out (#A1),a
jr send_byte_cont
send_byte_dr1:
; signal DR1
xor DR1_MASK
or e
out (#A1),a
send_byte_cont:
; wait for ACK
call wait_ack
djnz send_byte_loop
ld a,15
out (#A0),a
in a,(#A2)
and DR0_MASK + DR1_MASK
cp DR0_MASK + DR1_MASK
jr z,send_byte_end
call set_neutral
call wait_ack
send_byte_end:
ei
ret
recv_byte:
di
ld d,FWD_MASK + BACK_MASK
ld b,8
recv_byte_loop:
;d = previous trigger status
ld a,14
out (#A0),a
recv_byte_wait:
in a,(#A2)
xor d
and FWD_MASK + BACK_MASK
jr z,recv_byte_wait
rra
rra
rr c
in a,(#A2)
ld d,a
call send_ack
djnz recv_byte_loop
ld a,d
and FWD_MASK + BACK_MASK
cp FWD_MASK + BACK_MASK
jr z,recv_byte_end
recv_byte_wait2:
in a,(#A2)
and FWD_MASK + BACK_MASK
cp FWD_MASK + BACK_MASK
jr nz,recv_byte_wait2
call send_ack
recv_byte_end:
ei
ret
BIN_END:
****
MSX Mailinglist. To unsubscribe, send an email to [EMAIL PROTECTED] and put
in the body (not subject) "unsubscribe msx [EMAIL PROTECTED]" (without the
quotes :-) Problems? contact [EMAIL PROTECTED] (www.stack.nl/~wiebe/mailinglist/)
****