PC <-> ZX link sourse (ZX)
ZXNet echo conference «code.zx»
From Aleksandr Majorov → To Dmitriy Dobretsov 7 January 1999
Greetings, oh dearest Dmitriy!
Once in morning 07-01-98 04:18:53 somebody Dmitriy Dobretsov has
written to Aleksandr Majorov about 'Galvanic isolation'.
[ ]
AM>> if you're interested, I can throw the sources into the .code and show you
AM>> where you can optimize..
DD> throw it if it doesn't break...
Here I am throwing...
I’ll say right away - for ZX I more or less optimized everything,
but for the PC - no...
Tama, I generally picked up all the waiting delays
experimentally so that it accepts normally...
Obviously all the constants were set to my PC (166)
2_FK0: I’ll tell you right away - if you can say anything
essentially, optimize the code, etc. then no problem.
If you just shout that everything is glitches and MD,
then it’s better not to write...
If you can't offer an alternative, at least
don't interfere!
====================================================
;PC LINE SCAN
;this item is called MMD quite often...
;if CY=1 no data,
;CY=0 - data received, BC - length
SCAN_PC IN A,(#1F): AND 3: JR Z,PCL_PAS
CP 2: SCF: RET NZ
PCL_ACT LD A,2: LD (PCLINK),A
OUT (#DD),A: SCF: RET
PCL_PAS LD A,(PCLINK): OR A: SCF: RET Z
XOR A: LD (PCLINK),A: OUT (#DD),A
;CAUGHT A SYNCH PULSE
LD A,3: LD (BAUD),A ;remembered speed
;at the beginning of the block there are bytes #AA and #55 for control
CALL PC_IN: CP #AA: SCF: RET NZCALL PC_IN: CP #55: SCF: RET NZ
;then comes the block length
CALL PC_IN: LD E,A
CALL PC_IN: LD D,A
LD (BLEN),DE ;block length
LD HL,(ABUF) ;buffer address
;and now the data is coming
PC_IND CALL PC_IN: LD (HL),A
INC HL: DEC DE
LD A,D: OR E: JP NZ,PC_IND
;we set registers and flags - the block was accepted
LD BC,(BLEN) ;length
LD D,3 ;this is the speed number
LD A,1 ;CY=1, A=1 accepted block
RET
;************************************************
;transmitting a block of length BC
;waiting for the PC to be ready
PC_TRANS CALL PCWAIT_0
RET C ;not responding
LD A,2: OUT (#DD),A
CALL PCWAIT_1
LD A,0: OUT (#DD),A
RET C ;not responding
;transmit synchro
LD A,#AA: CALL PC_OUT
LD A,#55: CALL PC_OUT
;pass the block length
LD A,C: CALL PC_OUT
LD A,B: CALL PC_OUT
LD HL,(ABUF)
LD E,C: LD D,B
;data has flown
PC_OUTD LD A,(HL): CALL PC_OUT
INC HL: DEC DE
LD A,D: OR E: JR NZ,PC_OUTD
OR A: RET
;----------------------------------
;transmit byte
PC_OUT EXX: LD B,8: LD C,A
PC_OUT1 LD DE,1000 ;waiting for response
PCW0OUT IN A,(#1F): AND 2: JP Z,PCW0OUT1
DEC DE:LD A,D:OR E:JP NZ,PCW0OUT
JR PC_ERR ;PC hung....
PCW0OUT1 LD A,1: RL C: RLA: OUT (#DD),A
LD DE,1000 ;waiting for response
PCW1OUT IN A,(#1F):AND 2: JP NZ,PCW1OUT1DEC DE:LD A,D:OR E:JP NZ,PCW1OUT
;error... remove the return address and immediately
;jump up with the “no data” flag
PC_ERR OUT (#DD),A: POP HL: SCF: RET
PCW1OUT1 XOR A: OUT (#DD),A
DJNZ PC_OUT1
EXX: OR A: RET
;--------------------------------
;receive byte
PC_IN EXX: LD B,8
PC_IN1 LD DE,1000 ;waiting for response
PCW1IN IN A,(#1F): AND 2: JP NZ,PCW1IN1
DEC DE:LD A,D:OR E:JP NZ,PCW1IN
JR PC_ERR ;PC hung....
PCW1IN1 IN A,(#1F): RRA: RL C
LD A,2: OUT (#DD),A
LD DE,1000 ;waiting for response
PCW0IN IN A,(#1F): AND 2: JP Z,PCW0IN1
DEC DE:LD A,D:OR E:JP NZ,PCW0IN
JR PC_ERR
PCW0IN1 XOR A: OUT (#DD),A
DJNZ PC_IN1
LD A,C: EXX: OR A: RET
;-----------------------
;long wait for response from the PC - called
;before transmission.
;they wait a long time, otherwise the PC is busy with something ;-)
;wait until the PC sets "0"
PCWAIT_0 LD DE,2000
PCWAIT0 IN A,(#1F): AND 2: RET Z
DEC DE
LD A,D: OR E: JP NZ,PCWAIT0
SCF: RET
;we wait until the PC sets "1"
PCWAIT_1 LD DE,2000
PCWAIT1 IN A,(#1F): AND 2: RET NZ
DEC DE
LD A,D: OR E: JP NZ,PCWAIT1
SCF: RET
;********************************
====================================================
Well that's it *MAS* with a sledgehammer