6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Fri Sep 20, 2024 6:55 am

All times are UTC




Post new topic Reply to topic  [ 6 posts ] 
Author Message
PostPosted: Wed Oct 07, 2020 2:03 am 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
I am translating the ehBasic program below into the assembler below that. The Basic program works and blinks an LED on the VIA's PB0 pin. So I typed the assembler into the SBC2.7 machine language monitor. The assembler program runs in about six second, but frustratingly the LED does not blink on the exact same machine!

This is embarrassing because I know assembler, and it's a nearly line by line translation. But I can't figure out what I am doing wrong with such a simple program. Can anyone help?

Code:
10 REM Toggle VIA2.PB0 LOW and HIGH
20 REM Set up common VIA2 constants
30 Via2PRB=$7f60
40 Via2DDRB=$7f62
50 FOR X = 0 TO 16
60 REM Set VIA2.PB0 as output
70 A = PEEK Via2DDRB
80 A = A AND $FE
90 POKE Via2DDRB, A
100 A = PEEK Via2PRB
110 A = A EOR $01
120 POKE Via2PRB, A
130 FOR Y = 1 TO 100
140 NEXT Y
150 NEXT X


Code:
1000-   .   A0 16      LDY  #$16
1002-  -b.  AD 62 7F   LDA  $7F62
1005-  )~   29 FE      AND  #$FE
1007-  .b.  8D 62 7F   STA  $7F62
100A-  -`.  AD 60 7F   LDA  $7F60
100D-  I.   49 01      EOR  #$01
100F-  .`.  8D 60 7F   STA  $7F60
1012-   ..  20 19 10   JSR  $1019
1015-  .    88         DEY
1016-  Pj   D0 EA      BNE  $1002
1018-  `    60         RTS
1019-  Z    5A         PHY
101A-   .   A0 00      LDY  #$00
101C-  Z    DA         PHX
101D-  ".   A2 00      LDX  #$00
101F-  J    CA         DEX
1020-  P}   D0 FD      BNE  $101F
1022-  .    88         DEY
1023-  Pz   D0 FA      BNE  $101F
1025-  z    FA         PLX
1026-  z    7A         PLY
1027-  `    60         RTS


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 07, 2020 2:53 am 
Offline

Joined: Thu Mar 12, 2020 10:04 pm
Posts: 702
Location: North Tejas
Martin_H wrote:
Code:
101D-  ".   A2 00      LDX  #$00
101F-  J    CA         DEX
1020-  P}   D0 FD      BNE  $101F
1022-  .    88         DEY
1023-  Pz   D0 FA      BNE  $101F


bne $101D instead of $101F on the second branch?


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 07, 2020 3:01 am 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
BillG wrote:
bne $101D instead of $101F on the second branch?

Thanks, but I don't think that's it. X should contain 0 because the code didn't take the BNE after the DEX. So loading it with zero again shouldn't be needed. I also tested the delay routine separately, and it does delay about a half second at 1 MHz.


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 07, 2020 3:39 am 
Offline

Joined: Sun Apr 26, 2020 3:08 am
Posts: 357
At $1000, Y should be #$10 (16 in decimal).
The loop in line 50 FOR X = 0 TO 16, is a count of 17. In assembler listing, line 1016 should be BPL, not BNE.


Top
 Profile  
Reply with quote  
PostPosted: Wed Oct 07, 2020 3:41 am 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8510
Location: Southern California
You're making PB0 an input instead of an output. In the data-direction registers, 1=output, 0=input. PIC does it the other way around.

_________________
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: Wed Oct 07, 2020 2:03 pm 
Offline

Joined: Wed Jan 08, 2014 3:31 pm
Posts: 578
@IamRob, good catch.

Thanks Garth. I changed address 1005 to ORA #$01 and the assembly code worked! I knew I was missing something about VIA operation, so my primary goal is solved.

But this raises the uncomfortable question why my ehBasic program worked in the first place! I used it to figure out how to blink the LED, and was led astray by it. To debug I added line 85 PRINT A, reran, and as expected the output was zero, but the LED was blinking! Really weird and now obviously wrong

I then changed line 80 in the Basic program to the correct "A = A OR 1", the LED stopped blinking, and the output changed to 1.

Something mysterious is going on with ehBasic, or my version of it. I am not going to pursue it as I have other things to work on, but it makes me rethink using ehBasic for prototyping.


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 6 posts ] 

All times are UTC


Who is online

Users browsing this forum: No registered users and 11 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: