Page 8 of 10
Re: From 8bit breadboard to 6502
Posted: Fri Aug 11, 2017 9:26 pm
by nei02
Ok! You are right! It doesn't work!
Before I go to bed - I want to post the latest status:
(These are my first steps. Please don't hit me!) and the OPHIS Assembler doesn't know STZ BRA PLX ...
Code: Select all
.org $8600
.alias ACIA $4080
.alias ACIA_DATA ACIA+0
.alias ACIA_STAT ACIA+1
.alias ACIA_COMM ACIA+2
.alias ACIA_CTRL ACIA+3
.alias VIA $4010
.alias VIA_DATA_B VIA+$0
.alias VIA_DATA_A VIA+$1
.alias VIA_DDR_B VIA+$2
.alias VIA_DDR_A VIA+$3
.alias VIA_T1CL VIA+$4
.alias VIA_T1CH VIA+$5
.alias VIA_T1LL VIA+$6
.alias VIA_T1LH VIA+$7
.alias VIA_T2CL VIA+$8
.alias VIA_T2CH VIA+$9
.alias VIA_SR VIA+$A
.alias VIA_ACR VIA+$B
.alias VIA_PCR VIA+$C
.alias VIA_IFR VIA+$D
.alias VIA_IER VIA+$E
.alias VIA_ORA VIA+$F ; without handshake
SET_STACK: LDX #$FF ;reset stack
TXS
SET_ACIA: LDA #$00 ;reset status ACIA
STA ACIA_STAT
LDA ACIA_DATA ;unclear if neccessary
LDA #%00011110 ;set 9600 N 1
STA ACIA_CTRL
LDA #%00001011 ;set ACIA no parity no interrupt
STA ACIA_COMM
SET_VIA: LDA #%11111111
STA VIA_DDR_B
STA VIA_DDR_A
LDA #%00000000
STA VIA_ACR
STA VIA_PCR
STA VIA_IER
STA VIA_IFR
START: ldx #$00
OUTPUT: lda hello, x
sta ACIA_DATA
sta VIA_DATA_A
pha
stx $0001
jsr DELAY
ldx $0001
pla
beq INPUT
inx
bne OUTPUT
INPUT: lda ACIA_DATA
sta VIA_DATA_A
beq INPUT ; if no data try again
ECHO: sta ACIA_DATA
sta VIA_DATA_A
lda #$00
beq START
Delay: LDX #$11
LDY #$FF
StartOuterLoop: DEY
StartInnerLoop: DEX
TXA
BNE StartInnerLoop
TYA
BNE StartOuterLoop
RTS
hello: .byte "Input Please:", 0
I have used this long delay to see whats going on.
My terminal writes garbage:
Re: From 8bit breadboard to 6502
Posted: Fri Aug 11, 2017 11:41 pm
by dwight
Almost.
The way you wait for an input is not to read the input buffer.
I thought that was clear before.
You read the status register. When bit 3 is a one, that means
there is something there to read. Then you read the input data.
the buffer doesn't clear because you read it. The status bit
does clear when you read it when you read the input buffer.
I also prefer to always use 2 stop bits. Some com programs
don't work well at updating the screen if you use one stop bit.
You might find you loops easier to calculate if you do:
Code: Select all
LDY #$11
LDX #0
L0:
L1:
DEX
BNE L1
DEY
BNE L0
This is because the first inner loop, you only loop 255 times while
the rest you loop 256 times. Using 0 to start rather than $FF makes
the inner loop always do 256 times. It is easier to calculate.
Putting the DEY and the DEX in front of the branch means
you don't have to TXA or TYA to do a branch test.
If you need to adjust, you can add NOPs to the inner or outer loops.
Dwight
Re: From 8bit breadboard to 6502
Posted: Sat Aug 12, 2017 6:47 am
by nei02
I made some progress.
While waiting for input I read the status register and output the content to some LED's (VIA_DATA_A)
bit 4 is always high
When I press a key the bit 3 goes high.
Then after lda from ACIA_DATA - bit 3 goes low again.
Now its time to study the manual again to see what this means
Code: Select all
lda ACIA_STAT
sta VIA_DATA_A
jsr Delay
jsr Delay
jsr Delay
lda ACIA_DATA
sta VIA_DATA_A
jsr Delay
jsr Delay
jsr Delay
CMP 'Q
bne INPUT
Re: From 8bit breadboard to 6502
Posted: Sat Aug 12, 2017 9:04 am
by mkl0815
and the OPHIS Assembler doesn't know STZ BRA PLX ...
I'm quite sure that Ophis supports the full set of all 6502 and 65C02 instructions. But you need to set the "-c" commandline parameter to tell Ophis to use the 65C02 instruction set.
Mario.
Re: From 8bit breadboard to 6502
Posted: Sat Aug 12, 2017 11:47 am
by nei02
Ophis and 65C02:
Thanks Mario!
Issues Serial Communication:
By the way: A lot of problems I had with the serial transfer was caused by using the USB ports for Arduino EEPROMing and for serial communication. Although I used different USB ports.
After restarting the Mac the serial communication worked fine. But as soon as I have used the Arduino the program the EEPROM the communication was disturbed. Closing the Arduino app didn't help. Only restarting the Mac. Maybe tehre is a driver still loaded. But I can not unload or unbind it.
Question Code:
Why does the program still branch if I enter "Q". Subroutine DELAY doesn't affect Accumulator.
So Comparing 'Q with Accumulator should result in Zero flag and BNE should not branch.
Code: Select all
INPUT: lda ACIA_STAT
sta VIA_DATA_A
and #%00001000 ; check bit3 (Receiver Data Register Full?)
beq INPUT ; branch if not set
jsr Delay
jsr Delay
jsr Delay
lda ACIA_DATA
sta VIA_DATA_A
sta ACIA_DATA
jsr Delay
jsr Delay
jsr Delay
cmp 'Q
bne INPUT ; if "Q" exit INPUT and back to START
lda #$00
beq START
Re: From 8bit breadboard to 6502
Posted: Sat Aug 12, 2017 11:53 am
by BigEd
Not sure of the syntax, but possibly you mean to compare with the literal:
cmp #'Q
(Otherwise you are comparing with a zero page location)
Re: From 8bit breadboard to 6502
Posted: Sat Aug 12, 2017 12:08 pm
by nei02
changed code to
still branches.
According to the LED's the code is $51 after pressing "Q"
Maybe I should compare against this Hex value.
Re: From 8bit breadboard to 6502
Posted: Sat Aug 12, 2017 12:14 pm
by BigEd
It's not a question of Q vs q is it?
What does Delay look like?
Edit: and what about start? Does that start again? In which case, would you know if your test is passing or failing?
Re: From 8bit breadboard to 6502
Posted: Sat Aug 12, 2017 12:16 pm
by nei02
Re: From 8bit breadboard to 6502
Posted: Sat Aug 12, 2017 12:17 pm
by nei02
Code: Select all
START:
ldx #$00
OUTPUT:
lda STRING, x
CMP #$00
beq INPUT ; if end of null terminated byte
sta ACIA_DATA
sta VIA_DATA_A
stx $0001
jsr DELAY
ldx $0001
inx
bne OUTPUT ; if x > $FF
INPUT:
lda ACIA_STAT
sta VIA_DATA_A
and #%00001000 ; check bit3 (Receiver Data Register Full?)
beq INPUT ; branch if not set
jsr Delay
jsr Delay
jsr Delay
lda ACIA_DATA
sta VIA_DATA_A
sta ACIA_DATA
jsr Delay
jsr Delay
jsr Delay
cmp #$51
bne INPUT ; if no "Q" try again
lda #$00
beq START
Delay:
LDY #$FF
LDX #$00
L0:
L1:
DEX
BNE L1
DEY
BNE L0
RTS
STRING: .byte "Input Please:", 0
Re: From 8bit breadboard to 6502
Posted: Sat Aug 12, 2017 12:19 pm
by BigEd
That's good! So 'Q means something different.
Re: From 8bit breadboard to 6502
Posted: Sat Aug 12, 2017 12:59 pm
by nei02
This is the current status. I will optimise the ground connection and the write control cables.
For me it is a learning computer. I know it is not optimal.
I am now thinking if the next step could be to enter a little program via terminal which will be stored and executed in RAM.
Greetings
Prompt "Please enter 1st line of code"
Load Input in address 0000
Prompt "Please enter 2nd line of code"
Load Input in address 0001
...
If Input = Q then exit input
Prompt: "Press P to start the program"
If Input = "P" then jump to 0000
Re: From 8bit breadboard to 6502
Posted: Sat Aug 12, 2017 3:10 pm
by dwight
There is only one bit difference between upper and lower case.
You can use a 'or' mask or 'and' mask to change that bit. That
way your program will be case insensitive. That is a lot handier.
Do be careful to make sure it is a letter first and not a number.
How are you going to enter values? Most like Hex but it requires
converting to a byte value. It could be in binary for a start.
Also you'll need a way to error out and reset the address to the
desired location.
Tinker Dwight
Re: From 8bit breadboard to 6502
Posted: Sat Aug 12, 2017 7:11 pm
by GARTHWILSON
I'm not familiar with Ophis. Does there need to be a closing quote mark after the Q? Will it think it's a label or something else without the closing quote mark, instead of the ASCII value for Q?
Re: From 8bit breadboard to 6502
Posted: Mon Aug 14, 2017 8:37 am
by mkl0815
Not sure what version of Ophis you're using, but
works fine for me.
Code: Select all
...
LDA K_BUFFER ; Get length
CMP #1 ; Is it 1?
BNE ATryImm
LDA K_BUFFER+1 ; Get first char of operand
JSR ToUpper
CMP #'A ; Is it 'A?
BNE ATryImm
LDA #AM_ACCUMULATOR ; Yes, is is accumulator mode
STA AM ; Save it
JMP GenerateCode
...
But it only works with letters, not with other characters.
Mario.