6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 10, 2024 10:04 am

All times are UTC




Post new topic Reply to topic  [ 138 posts ]  Go to page Previous  1 ... 6, 7, 8, 9, 10  Next
Author Message
PostPosted: Mon Aug 14, 2017 12:44 pm 
Offline

Joined: Fri Jul 21, 2017 8:16 pm
Posts: 59
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"


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 14, 2017 1:25 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10976
Location: England
That's right, you want to output 8 characters, so you have a little work to do!


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 14, 2017 2:41 pm 
Offline

Joined: Mon Mar 25, 2013 9:26 pm
Posts: 183
Location: Germany
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.

Code:
;
; 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
.scend

_________________
How should I know what I think, until I hear what I've said.


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 14, 2017 3:55 pm 
Offline

Joined: Fri Jul 21, 2017 8:16 pm
Posts: 59
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. ;-)


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 14, 2017 3:56 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
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.

Code:
;
; 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
.scend


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.

Below 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:
      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 return

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 14, 2017 4:34 pm 
Offline

Joined: Mon Mar 25, 2013 9:26 pm
Posts: 183
Location: Germany
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.


Your are right. I think this happened when I had to backport the following code from 65C02 to 6502 for my MOUSE2Go. because the emulator for the Arduino only supported 6502 opcodes for this time. Seems I never tested this. Thanks for pointing that out.

Here's the 65C02 code:

Code:
;
; 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.


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 14, 2017 5:00 pm 
Offline

Joined: Thu Mar 03, 2011 5:56 pm
Posts: 284
Here's a slightly more compact version (posted mainly because I have never posted any 6502 code here before):

Code:
     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



Argument in A, overwrites A and X. The "jsr fded" should make it clear what computer (or emulator) I tested with.


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 14, 2017 5:05 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10976
Location: England
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.


Top
 Profile  
Reply with quote  
PostPosted: Mon Aug 14, 2017 6:05 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
rwiker wrote:
Here's a slightly more compact version (posted mainly because I have never posted any 6502 code here before):

Code:
     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



Argument in A, overwrites A and X. The "jsr fded" should make it clear what computer (or emulator) I tested with.


Very nice, two bytes shorter than my current routine, I like it.

_________________
Regards, KM
https://github.com/floobydust


Top
 Profile  
Reply with quote  
PostPosted: Tue Aug 15, 2017 3:27 pm 
Offline

Joined: Fri Jul 21, 2017 8:16 pm
Posts: 59
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.
:lol:


Top
 Profile  
Reply with quote  
PostPosted: Sat Aug 26, 2017 7:42 am 
Offline

Joined: Fri Jul 21, 2017 8:16 pm
Posts: 59
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! :-)


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 04, 2017 2:42 pm 
Offline

Joined: Tue Apr 12, 2016 6:30 pm
Posts: 13
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


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 04, 2017 6:26 pm 
Offline

Joined: Fri Jul 21, 2017 8:16 pm
Posts: 59
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


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 04, 2017 7:19 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8538
Location: Southern California
nei02 wrote:
I also would like to recommend the book: 6502 Assembly Language Subroutines from Leventhal and Saville.

Be sure you go further though. That book only uses the NMOS instruction set which is quite limiting compared to that of the CMOS 65c02 that you have. Use the resources on this site and in the sites of the members.

_________________
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?


Top
 Profile  
Reply with quote  
PostPosted: Mon Sep 04, 2017 7:55 pm 
Offline

Joined: Fri Jul 21, 2017 8:16 pm
Posts: 59
Thanks! Yes I will!
I like the Symon Emulator. And it seems that it only supports the NMOS Opcodes.
:(


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 138 posts ]  Go to page Previous  1 ... 6, 7, 8, 9, 10  Next

All times are UTC


Who is online

Users browsing this forum: No registered users and 4 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot post attachments in this forum

Search for:
Jump to: