From 8bit breadboard to 6502
Re: From 8bit breadboard to 6502
I am trying to display the binary data of a register on the terminal
sta ACIA_DATA
The terminal program thinks it gets an character and try to display it.
But how can I tell the terminal that I just von to print binary data. e.g. "00110011"
Do I need to write a encoding macro?
-Take Byte
-Read each BIT
-if 0 then make "0" if 1 then make "1"
sta ACIA_DATA
The terminal program thinks it gets an character and try to display it.
But how can I tell the terminal that I just von to print binary data. e.g. "00110011"
Do I need to write a encoding macro?
-Take Byte
-Read each BIT
-if 0 then make "0" if 1 then make "1"
Re: From 8bit breadboard to 6502
That's right, you want to output 8 characters, so you have a little work to do!
Re: From 8bit breadboard to 6502
I'm using the following code for that in my monitor program. It is written in Ophis Assembler and for the 6502, so optimization for the 65C02 can be done.
k_wchr is the subroutine to output one character.
k_wchr is the subroutine to output one character.
Code: Select all
;
; print out the 8bit value in A as binary code
; X,Y is preserved, A is destroyed
;
.scope
u_bin8out:
txa ; move X to A
pha ; save (X)
tya ; move Y to A
pha ; save (Y)
ldx #$08 ; counter for 8 bit
_loop: clc ; clear carry flag
asl ; shift byte by one position
bcs _p1
tay ; save A
lda #'0
jmp _cont
_p1: tay ; save A
lda #'1 ; print "1"
_cont: jsr k_wchr
tya ; get A back
dex ; decrement counter
bne _loop
pla
tay ; restore Y
pla ; restore X
tax
rts ; return
.scendHow should I know what I think, until I hear what I've said.
Re: From 8bit breadboard to 6502
Thank you for the code example. This helps me to learn assembler.
You shift the byte one bit left (after clearing carry out)
Then you analyse the carry flag. If set than print "1" if not print "0".
I think with 65C02 the code will be shorter because you can push and pull X,y to stack directly.
Cool! Thank you! So this evening I have something to do while my wife is watching Germany next top model.
You shift the byte one bit left (after clearing carry out)
Then you analyse the carry flag. If set than print "1" if not print "0".
I think with 65C02 the code will be shorter because you can push and pull X,y to stack directly.
Cool! Thank you! So this evening I have something to do while my wife is watching Germany next top model.
- floobydust
- Posts: 1394
- Joined: 05 Mar 2013
Re: From 8bit breadboard to 6502
mkl0815 wrote:
I'm using the following code for that in my monitor program. It is written in Ophis Assembler and for the 6502, so optimization for the 65C02 can be done.
k_wchr is the subroutine to output one character.
k_wchr is the subroutine to output one character.
Code: Select all
;
; print out the 8bit value in A as binary code
; X,Y is preserved, A is destroyed
;
.scope
u_bin8out:
txa ; move X to A
pha ; save (X)
tya ; move Y to A
pha ; save (Y)
ldx #$08 ; counter for 8 bit
_loop: clc ; clear carry flag
asl ; shift byte by one position
bcs _p1
tay ; save A
lda #'0
jmp _cont
_p1: tay ; save A
lda #'1 ; print "1"
_cont: jsr k_wchr
tya ; get A back
dex ; decrement counter
bne _loop
pla
tay ; restore Y
pla ; restore X
tax
rts ; return
.scendBelow is the code I use in my monitor to print the status register. CHROUT sends a character and the CROUT send a CR/LF and returns. You can eliminate the LDA PREG and just have the A reg loaded with the value you want to print. You can also replace the JMP CROUT with a RTS if you don't want to print a CR/LF.
Code: Select all
LDA PREG ;Get Status register preset
LDX #$08 ;Get the index count for 8 bits
SREG_LP LDY #$30 ;Get Ascii "zero"
ASL A ;Shift bit into carry
PHA ;Save Current status register value
BCC SRB_ZERO ;If clear, print a "zero"
INY ;Else increment Y reg to Ascii "one"
SRB_ZERO TYA ;Transfer Ascii character to A reg
JSR CHROUT ;Print it
PLA ;Restore current status register value
DEX ;Decrement bit count
BNE SREG_LP ;Branch back until all bits are printed
JMP CROUT ;Send CR/LF and returnRegards, KM
https://github.com/floobydust
https://github.com/floobydust
Re: From 8bit breadboard to 6502
floobydust wrote:
I believe your code is incomplete. As you specify that the A reg holds the byte value to be printed, your first instruction (TXA) overwrites that value. As it's written, the value in the Y reg would be used. You also don't need the CLC instruction as the carry flag will be set based on the ASL instruction.
Here's the 65C02 code:
Code: Select all
;
; print out the 8bit value in A as binary code
; X,Y is preserved, A is destroyed
;
.scope
u_bin8out:
phx ; save X
phy ; save Y
ldx #$08 ; counter for 8 bit
_loop: clc ; clear carry flag
asl ; shift byte by one position
bcs _p1
tay ; save A
lda #'0
bra _cont
_p1: tay ; save A
lda #'1 ; print "1"
_cont: jsr k_wchr
tya ; get A back
dex ; decrement counter
bne _loop
ply ; restore Y
plx ; restore X
rts ; return
.scend
How should I know what I think, until I hear what I've said.
Re: From 8bit breadboard to 6502
Here's a slightly more compact version (posted mainly because I have never posted any 6502 code here before):
Argument in A, overwrites A and X. The "jsr fded" should make it clear what computer (or emulator) I tested with.
Code: Select all
1 *= $300
2
3 prtbin:
4 0300 a208 ldx #8
5 0302 0a loop: asl
6 0303 48 pha
7 0304 a930 lda #$30
8 0306 6900 adc #0
9 0308 20edfd jsr $fded
10 030b 68 pla
11 030c ca dex
12 030d d0f3 bne loop
13 030f 60 rts
14
15 0310 a9e5 testit: lda #$e5
16 0312 200003 jsr prtbin
Re: From 8bit breadboard to 6502
If the printing subroutine preserves Y, then I'd probably use TAY/TYA instead of PHA/PLA - it's quicker, but also for me just a bit of a preference.
- floobydust
- Posts: 1394
- Joined: 05 Mar 2013
Re: From 8bit breadboard to 6502
rwiker wrote:
Here's a slightly more compact version (posted mainly because I have never posted any 6502 code here before):
Argument in A, overwrites A and X. The "jsr fded" should make it clear what computer (or emulator) I tested with.
Code: Select all
1 *= $300
2
3 prtbin:
4 0300 a208 ldx #8
5 0302 0a loop: asl
6 0303 48 pha
7 0304 a930 lda #$30
8 0306 6900 adc #0
9 0308 20edfd jsr $fded
10 030b 68 pla
11 030c ca dex
12 030d d0f3 bne loop
13 030f 60 rts
14
15 0310 a9e5 testit: lda #$e5
16 0312 200003 jsr prtbin
Regards, KM
https://github.com/floobydust
https://github.com/floobydust
Re: From 8bit breadboard to 6502
Hi,
managed to print binary numbers and managed to use the VIA Interrupt and an ISR.
Thanks you for the Interrupt primer. helped a lot.
I like the picture of the not so important boy you should wait at the backdoor because he always forgets to unlock the door.

managed to print binary numbers and managed to use the VIA Interrupt and an ISR.
Thanks you for the Interrupt primer. helped a lot.
I like the picture of the not so important boy you should wait at the backdoor because he always forgets to unlock the door.
Re: From 8bit breadboard to 6502
I am really happy! For me it is a big step!
I managed to program a little monitor which allows me to copy assembled code via terminal to RAM and execute.
For all of you this is certainly an "old hat". But for me it is just wonderful!
I managed to program a little monitor which allows me to copy assembled code via terminal to RAM and execute.
For all of you this is certainly an "old hat". But for me it is just wonderful!
Re: From 8bit breadboard to 6502
Believe me, you're not the only one enjoying and benefiting from these discussions. I'm working on my own single-board machine and the issues/questions you've brought up are the same as I have had. These guys are phenomenal in the time and patience it takes to help a newcomer get their projects working. We're very fortunate to have such a group.
I'm also a big fan of Ben Eater's videos, and have learned much from them.
My goal is an 8-bit machine with bank-switchable RAM and movable zero page, ala the Apple ///. But I have to get a simple machine going first.
I too am using an Arduino (Mega) in my development. It's a wonderful device to test and see what the computer is doing. The Mega is nice in that it has enough i/o to dedicate pins to the address and data lines without bit-shifting complicating things for a newbie. Fewer points of failure, etc. I'll also use it for my EEPROM programming.
Good luck to you!
Chris Z
I'm also a big fan of Ben Eater's videos, and have learned much from them.
My goal is an 8-bit machine with bank-switchable RAM and movable zero page, ala the Apple ///. But I have to get a simple machine going first.
I too am using an Arduino (Mega) in my development. It's a wonderful device to test and see what the computer is doing. The Mega is nice in that it has enough i/o to dedicate pins to the address and data lines without bit-shifting complicating things for a newbie. Fewer points of failure, etc. I'll also use it for my EEPROM programming.
Good luck to you!
Chris Z
Re: From 8bit breadboard to 6502
Yes I learned really a lot! And got a lot of help in this forum!
What I have done since my last post:
- I took the WozMonitor from the Apple I (found it in www) and adapted the code to my environment.
OPHIS and Symon
- Wrote a Monitorprogramm by myself to load, store, read and run. (of course the code is not optimised with regard to speed and storage. I am no professionell assembler programmer)
I also would like to recommend the book: 6502 Assembly Language Subroutines from Leventhal and Saville.
I found a link to download the pdf here in this forum! Very, very good!
I dont know what to do next. Maybe implement an inline assembler like in the mouse2Go project. Bit don't know where to get this?:-o
What I have done since my last post:
- I took the WozMonitor from the Apple I (found it in www) and adapted the code to my environment.
OPHIS and Symon
- Wrote a Monitorprogramm by myself to load, store, read and run. (of course the code is not optimised with regard to speed and storage. I am no professionell assembler programmer)
I also would like to recommend the book: 6502 Assembly Language Subroutines from Leventhal and Saville.
I found a link to download the pdf here in this forum! Very, very good!
I dont know what to do next. Maybe implement an inline assembler like in the mouse2Go project. Bit don't know where to get this?:-o
- GARTHWILSON
- Forum Moderator
- Posts: 8773
- Joined: 30 Aug 2002
- Location: Southern California
- Contact:
Re: From 8bit breadboard to 6502
nei02 wrote:
I also would like to recommend the book: 6502 Assembly Language Subroutines from Leventhal and Saville.
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?
The "second front page" is http://wilsonminesco.com/links.html .
What's an additional VIA among friends, anyhow?
Re: From 8bit breadboard to 6502
Thanks! Yes I will!
I like the Symon Emulator. And it seems that it only supports the NMOS Opcodes.

I like the Symon Emulator. And it seems that it only supports the NMOS Opcodes.