6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Sun Nov 24, 2024 1:58 am

All times are UTC




Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next
Author Message
PostPosted: Fri Aug 14, 2020 6:31 pm 
Offline

Joined: Mon Jun 08, 2020 7:42 pm
Posts: 22
Here is a story of a man-made software issue which really had me stumped.
I’ll pose it as a question , just for fun. The answer to follow in the near future after a few interested readers have had a go, although I’m guessing a number of you may spot this quite easily.
The symptom:
My 6502 SBC has a flashing led routine for testing. It would flash a few leds at a rate of about 1 flash per second, well sometimes. Now and again, it would flash at high speed. I’m using a 1Mhz oscillator.
This is the delay routine:
Code:
delay:
          LDX $FF
loopx:    LDY $FF
loopy:    DEY
          BNE loopy
          DEX
          BNE loopx
          RTS

It is a nested loop routine.
So why did it sometimes produce a correct delay and sometimes a minimal delay?
But wait, there's more:
I also had an 8251 serial comms chip which worked perfectly in another bit of code. Then a few days later it decided not to work.
The part of the code that was blocking things was isolated to this section of code:
Code:
loop1:
      LDA CONFIG8251
      AND #$01    
      BEQ loop1 ; if not ready

It reads a status bit (bit 0) and if the bit is '0', then go back and keep looping until it goes high.
The two problems are related - have you spotted it?
regards
Russell


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 14, 2020 7:18 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Vs lbh'q jevggra naq qbyyne bu bar V'q fnl gur ceboyrz va obgu pnfrf jnf zvffvat gur unfu sbe na vzzrqvngr.

(rot13.com)


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 14, 2020 7:31 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
Ed already pointed out that you're loading your delay registers from a Page Zero location.... but there's nothing that defines if that is supposed to give you a variable delay for multiple uses or just a mistake in coding up the routine. As there's no reference to the Page Zero location, it's likely a mistake.

The second issue is the second routine. If nothing happens with the serial chip, then there's nothing to break it out of the waiting loop, unless you have some ISR that's performing some other task perhaps. The code looks like part of a polled I/O routine, so that can hang the system for a variable length of time.

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


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 14, 2020 7:49 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Nabgure guvat juvpu pna or n ceboyrz vf vs na vagreehcg freivpr ebhgvar snvyf gb fnir naq erfgber ertvfgref, be punatrf fbzr zrzbel ybpngvba vg fubhyqa'g, be vs vg fgnlf va n ybbc sbe gbb ybat naq hfrf hc gbb zhpu gvzr.


Top
 Profile  
Reply with quote  
PostPosted: Fri Aug 14, 2020 8:33 pm 
Offline

Joined: Mon May 01, 2017 7:13 am
Posts: 83
Jurer qvq lbh znc gur 8251 vagb zrzbel? Vg jbhyqa'g unccra gb or pbyyvqvat jvgu $SS, jbhyq vg?

(rot13.com)


Top
 Profile  
Reply with quote  
PostPosted: Sat Aug 15, 2020 1:41 am 
Offline
User avatar

Joined: Fri Dec 11, 2009 3:50 pm
Posts: 3367
Location: Ontario, Canada
Er gur qrynl ebhgvar, V'z pbaivaprq gur nhgube vagraqrq gb hfr na *vzzrqvngr* bcrenaq bs $SS. Vafgrnq, gur pbqr ernqf jung'f ng zrzbel ybpngvba $00SS, naq gur erfhygf ner reengvp orpnhfr guvf ybpngvba unfa'g orra vavgvnyvmrq.

(Ng guvf cbvag V ernq bguref' erfcbafrf, abgvat gung bguref unir vaqrcraqragyl ernpurq gur fnzr pbapyhfvba nobhg gur qrynl ceboyrz. Ohg, er gur frpbaq ceboyrz, fb sne ab-bar unf cebcbfrq gur sbyybjvat. enfpnyfnvybe unf gbyq hf gur gjb ceboyrzf ner eryngrq, fb urer'f zl gurbel.)

PBASVT8251 vf pyrneyl vagraqrq gb ercerfrag na VB ybpngvba, ohg V fhfcrpg n glcb va vgf qrsvavgvba pnhfrf vg, gbb, gb ersre gb na havavgvnyvmrq zrzbel ybpngvba. Guvf zrnaf gur 8251 fgnghf arire rire qbrf trg cbyyrq gb frr vs vg'f ernql, rira ba qnlf jura gur pbqr frrzf gb or jbexvat! V fhfcrpg cbyyvat vf npghnyyl ha-arprffnel, orpnhfr -- sbe jungrire ernfba -- pvephzfgnaprf ner fhpu gung gur 8251 vf NYJNLF ernql ol gur gvzr gur jbhyq-or cbyyvat bpphef! :)

-- Jeff

Edit: The error in part one has happened before. (Spoiler alert)

_________________
In 1988 my 65C02 got six new registers and 44 new full-speed instructions!
https://laughtonelectronics.com/Arcana/ ... mmary.html


Top
 Profile  
Reply with quote  
PostPosted: Sat Aug 15, 2020 6:13 am 
Offline

Joined: Mon Jun 08, 2020 7:42 pm
Posts: 22
Hi - Right you are, those elusive '#' symbols had me stumped.
I'm used to Z80 assembler and the use of parenthesis for indirect memory addressing.
Don't forget the hashes!!


Top
 Profile  
Reply with quote  
PostPosted: Sat Aug 15, 2020 8:57 pm 
Offline

Joined: Mon May 01, 2017 7:13 am
Posts: 83
rascalsailor wrote:
Don't forget the hashes!!


Humph. I assumed that $FF contained a constant initialized before entering the routine, to vary the flash rate. The code behaves exactly as written -- it's not fair to test us against your ability to deduce your original intention. :P


Top
 Profile  
Reply with quote  
PostPosted: Sat Aug 15, 2020 9:14 pm 
Offline
User avatar

Joined: Tue Mar 05, 2013 4:31 am
Posts: 1385
I would also point out that the two pieces of code are not related...

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


Top
 Profile  
Reply with quote  
PostPosted: Sat Aug 15, 2020 9:16 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
Maybe, Russell, you're saying that the second loop was originally unreliable because it too lacked the hash?


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 16, 2021 7:45 pm 
Offline

Joined: Mon Jun 08, 2020 7:42 pm
Posts: 22
Sorry , I hadn't replied - Yes the hash omitted caught me out.


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 18, 2021 10:50 am 
Offline

Joined: Sun Jul 11, 2021 9:12 am
Posts: 155
Is it just me? Or is half of this thread in Klingon?


Top
 Profile  
Reply with quote  
PostPosted: Sun Jul 18, 2021 10:52 am 
Offline

Joined: Sun Jul 11, 2021 9:12 am
Posts: 155
Ok, I understand now. Next question is ‘why?’


Top
 Profile  
Reply with quote  
PostPosted: Mon Jul 19, 2021 3:39 pm 
Offline
User avatar

Joined: Thu Dec 11, 2008 1:28 pm
Posts: 10986
Location: England
I used rot13 for the traditional reason, of avoiding spoilers. I like to have a guess, but whether or not I'm right, I don't want to take away from anyone else the pleasure of having their own guess.


Top
 Profile  
Reply with quote  
PostPosted: Fri Jul 23, 2021 1:02 pm 
Offline

Joined: Sun Jul 11, 2021 9:12 am
Posts: 155
Ah! Got ya! Makes sense now. :D


Top
 Profile  
Reply with quote  
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 16 posts ]  Go to page 1, 2  Next

All times are UTC


Who is online

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