Hi - I'm largely a newbie to assembly language, so apologies for poor terminology etc!
Context - I've built a Ben Eater style 65C02 style computer ( on breadboards although changing over to a PCB shortly) which works fine. I want to eventually be able to display temperature and set myself the challenge of using the DS18B20. I have been using the
http://6502.org/mini-projects/ds1820/ds1820.htm code by Leo Nechaev to help. I am using retroassembler as the assembler (as an extension to Visual Studio Code
Story so far - I have been working through Leo's code ( adapting as appropriate) and really trying to make sure that I really understand the code, rather than simply blind copying and thus far have been fairly successful - to the point that I can communicate with the device , "ask" it to measure temperature and then send the appropriate pulses to command it to provide the 16 bit temperature - and I since I have an oscilloscope connected to the VIA port that I am using it is responding and the data it is sending back makes sense with respect to the expected temperature.
The problem(s).
The main issue is understanding the code that reads the returned bit(s) from the device, which is as follows.
tmpRead ; reading byte from the device
ldx #8 ; 8 times
- pha
jsr tmpReadBit
pla
ror ; bit-by-bit (in carry)
dex
bne -
rts
tmpReadBit
jsr tmpSetZero
jsr tmpSetOne
lda rgConfig
asl
php
jsr tmpDelay
jsr tmpDelay
jsr tmpDelay
jsr tmpWaitForReady
plp
rts
As I see it, when a bit is read in the tmpReadBit subroutine after sending the ready pulse, the next opcode is asl. So if the bit read was a 1, this will be stored in the accumulator and then shifted left to bit1 and bit0 replaced by a 0. The carry flag will not be set. We then jump back to the tmpRead subroutine which then applies ror to the accumulator - which appears in this case to be the reverse of the asl opcode as there is no carry flag that could have put a 1 in the bit 7. As you can see the comments indicate that the byte is built up bit by bit (in carry), but I can't see how this works!
The
second, albeit less vexing issue is right at the top of the code is
Registers defining:
rgConfig = $6000 ; Write: D7 - output open drain pin with inversion
rgStatus = $6000 ; Read: D7 - input pin without inversion
Now I know that this is changing the pin on the VIA from read to write ( which I achieve with a subroutine) but how does the programme know that rgConfig is write and rgStatus is read when both appear to point to the same memory location ( which again I assume is pointing to the DDR on the VIA)?
Once again apologies for the complete Noob description, but I am hoping that there is someone who understands what I am asking and can point me in the correct direction.