From 8bit breadboard to 6502

Building your first 6502-based project? We'll help you get started here.
nei02
Posts: 59
Joined: 21 Jul 2017

Re: From 8bit breadboard to 6502

Post 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:
Attachments
screenshot2.jpeg
dwight
Posts: 213
Joined: 08 Jun 2004

Re: From 8bit breadboard to 6502

Post 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
nei02
Posts: 59
Joined: 21 Jul 2017

Re: From 8bit breadboard to 6502

Post 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 :o :idea:

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
mkl0815
Posts: 183
Joined: 25 Mar 2013
Location: Germany
Contact:

Re: From 8bit breadboard to 6502

Post by mkl0815 »

Quote:
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.
How should I know what I think, until I hear what I've said.
nei02
Posts: 59
Joined: 21 Jul 2017

Re: From 8bit breadboard to 6502

Post 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


User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: From 8bit breadboard to 6502

Post 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)
nei02
Posts: 59
Joined: 21 Jul 2017

Re: From 8bit breadboard to 6502

Post by nei02 »

changed code to

Code: Select all

cmp #'Q
				bne INPUT		
still branches.

According to the LED's the code is $51 after pressing "Q"
Maybe I should compare against this Hex value.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: From 8bit breadboard to 6502

Post 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?
nei02
Posts: 59
Joined: 21 Jul 2017

Re: From 8bit breadboard to 6502

Post by nei02 »

yes! This works!

Code: Select all

cmp #$51
				bne INPUT	
nei02
Posts: 59
Joined: 21 Jul 2017

Re: From 8bit breadboard to 6502

Post 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
Last edited by nei02 on Sat Aug 12, 2017 12:27 pm, edited 1 time in total.
User avatar
BigEd
Posts: 11463
Joined: 11 Dec 2008
Location: England
Contact:

Re: From 8bit breadboard to 6502

Post by BigEd »

That's good! So 'Q means something different.
nei02
Posts: 59
Joined: 21 Jul 2017

Re: From 8bit breadboard to 6502

Post 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.
Quote:
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




Attachments
IMG_1168.JPG
dwight
Posts: 213
Joined: 08 Jun 2004

Re: From 8bit breadboard to 6502

Post 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
User avatar
GARTHWILSON
Forum Moderator
Posts: 8773
Joined: 30 Aug 2002
Location: Southern California
Contact:

Re: From 8bit breadboard to 6502

Post 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?
http://WilsonMinesCo.com/ lots of 6502 resources
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
mkl0815
Posts: 183
Joined: 25 Mar 2013
Location: Germany
Contact:

Re: From 8bit breadboard to 6502

Post by mkl0815 »

Not sure what version of Ophis you're using, but

Code: Select all

CMP #'Q
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.
How should I know what I think, until I hear what I've said.
Post Reply