6502.org Forum  Projects  Code  Documents  Tools  Forum
It is currently Tue Sep 24, 2024 1:28 pm

All times are UTC




Post new topic Reply to topic  [ 256 posts ]  Go to page Previous  1 ... 3, 4, 5, 6, 7, 8, 9 ... 18  Next
Author Message
 Post subject: Quick Update
PostPosted: Wed Jun 08, 2022 2:24 am 
Offline

Joined: Fri Mar 18, 2022 6:33 pm
Posts: 489
All right! I have "solved" the problems I was having in the time honored tradition of avoiding them. :) I have some more components on the way; when they get here I'll make a new backplane with - hopefully - a better power supply. In the meantime, as long as I don't put anything into the two bus slots next to the voltage regulator, Blue April is running rock solid. This afternoon I finished the keyboard interface, so I now have actual I/O. I can type on the LCD!

SHIFT, ENTER, ESC (clears the screen), and BACKSPACE all work. I haven't implemented any of the extended scan-codes (so no arrow keys), but what I do have is enough to start using some of the interesting routines from old [s]BYTE magazines[/s] Dr. Dobb's Journals. I should have an actual monitor up and running soon! Unfortunately, I have discovered that my LCD is not exactly ASCII compatible - it has an asian character set! I guess that makes sense, since it comes from an ELEGOO (Chinese) electronics kit. This doesn't really matter much, except that '\' looks like '¥!' :shock: :lol:

This is not that big of a deal, really, but it does reduce my motivation to make a full-featured shell for it. I might as well leave it rudimentary and get on with reading the CRT Controller Handbook and making a real VDU module.

A couple of design notes:

I started out working from Ben Eater's PS/2 keyboard videos, like many people. My keyboard interface hardware is almost identical, except that I added some 3.3k pullup resistors to the CLK and DATA lines; they're required by the PS/2 spec. Ben left them out, for some reason, but I was getting all kinds of ghostly interrupts from an unstable CLK line until I added them.

My software is a bit different (although I did use his circular buffer - it was cool). Ben does everything in the interrupt handler, and I didn't want to do that; my interrupt handler just puts the next scan-code into a buffer and returns. I wrote a dispatcher subroutine, and ran into the first thing so far that has seemed really strange about the 6502: no conditional calling - only branching! I ended up doing this:

Code:
kb_dispatcher:
    lda    <next scancode>

    cmp    #$<case1>
    beq    kb_case1
    .
    .
    .
    cmp    #$<caseN>
    beq    kb_caseN

;   default
    jmp    kb_default

kb_case1:
    <do some work>
    rts

kb_caseN:
    <do some work>
    rts

kb_default:
    <do some work>
    rts


I don't know if that's the cleanest way to structure this sort of thing, but it looks the most like how I used to do it in SCHEME, so it's at least logically clear, and it works! :D

_________________
"The key is not to let the hardware sense any fear." - Radical Brad


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 08, 2022 3:30 am 
Offline
User avatar

Joined: Fri Aug 03, 2018 8:52 am
Posts: 746
Location: Germany
hmm, wouldn't using branches like that cause an issue if you check for too many cases, or if your <do some work> code becomes too large?
because branches only reach around 127 bytes forward

so why not just use a jump table? no branches or CMP's required.

example:
Code:
kb_dispatcher:
   LDA <next scancode>
   ASL A
   BCS kb_upper_half
   TAX
   JMP (kb_table,X)
   kb_upper_half:
   TAX
   JMP (kb_table + 256,X)


kb_case1:
   <do stuff>
   RTS

...

kb_caseN:
   <do stuff>
   RTS

...

kb_default:
   <do stuff>
   RTS

; Jump Table, expected to be 512 Bytes large because the input value is technically 9 bits wide
kb_table:
   .word kb_case1
   ...
   .word kb_caseN
   ...
   .word kb_default


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 08, 2022 8:15 am 
Offline

Joined: Tue Sep 03, 2002 12:58 pm
Posts: 325
I've also gone with a table, but because it only needs special handling for a small number of keys (the rest just get printed) I've put the code in the table too.

Code:
   ldx #codeTableEnd-codeTableStart
loop
   cmp codeTable-1, x
   beq found
   dex
   bne loop
   ; "handler not found" code here
   rts

found
   lda handlerHighTable, x
   pha
   lda handlerLowTable, x
   pha
   rts

codeTable
   .byte scanCodeA, scanCodeB, ...
codeTableEnd
handlerHighTable
   .byte >(handlerA-1), >(handlerB-1), ...
handlerLowTable
   .byte <(handlerA-1), <(handlerB-1), ...

(it's been a while since I've done 8 bit 6502... I've probably got high and low bytes the wrong way around everywhere)


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 08, 2022 3:56 pm 
Offline

Joined: Fri Mar 18, 2022 6:33 pm
Posts: 489
Proxy wrote:
hmm, wouldn't using branches like that cause an issue if you check for too many cases, or if your <do some work> code becomes too large?
because branches only reach around 127 bytes forward
[/code]


Yes, that is a potential problem, but I haven't run into it yet. I have been reading about jump tables, and figured I'd have to learn how to use them soon. I never thought of using the scan-code itself as the index, though - ingenious! It seems like I would need an awfully large table for a relatively few handlers, though.

_________________
"The key is not to let the hardware sense any fear." - Radical Brad


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 08, 2022 3:58 pm 
Offline

Joined: Fri Mar 18, 2022 6:33 pm
Posts: 489
[quote="John West"]
Code:
found
   lda handlerHighTable, x
   pha
   lda handlerLowTable, x
   pha
   rts


It took me a second to see what you were doing here. That's clever!

_________________
"The key is not to let the hardware sense any fear." - Radical Brad


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 08, 2022 5:29 pm 
Offline
User avatar

Joined: Wed Feb 14, 2018 2:33 pm
Posts: 1467
Location: Scotland
Paganini wrote:
John West wrote:
Code:
found
   lda handlerHighTable, x
   pha
   lda handlerLowTable, x
   pha
   rts


It took me a second to see what you were doing here. That's clever!


From the Woz Sweet16 sources... Discussion here:

http://www.6502.org/source/interpreters/sweet16.htm#When_is_an_RTS_really_a_JSR_ When is an RTS really a JSR?

-Gordon

_________________
--
Gordon Henderson.
See my Ruby 6502 and 65816 SBC projects here: https://projects.drogon.net/ruby/


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 08, 2022 7:36 pm 
Offline
User avatar

Joined: Fri Aug 30, 2002 1:09 am
Posts: 8514
Location: Southern California
Paganini wrote:
Proxy wrote:
hmm, wouldn't using branches like that cause an issue if you check for too many cases, or if your <do some work> code becomes too large?
because branches only reach around 127 bytes forward

Yes, that is a potential problem, but I haven't run into it yet. I have been reading about jump tables, and figured I'd have to learn how to use them soon. I never thought of using the scan-code itself as the index, though - ingenious! It seems like I would need an awfully large table for a relatively few handlers, though.

Assuming the handling of each case is short enough to branch around, you can handle it right there, and branch around it in the case of a match not being found yet. So instead of
Code:
    cmp    #$<case1>
    beq    kb_case1
    .
    .
    .
    cmp    #$<caseN>
    beq    kb_caseN

you'd do:
Code:
    cmp    #$<case1>
    bne    test_for_case_2
    <handle case1 here, ending in RTS or jump to the end of the set>

test_for_case_2:
    cmp    #$<case2>
    bne    test_for_case_3
    <handle case2 here, ending in RTS or jump to the end of the set>

test_for_case_3:

    <etc.>

That's what the CASE structure in my program flow-control macros does. See http://wilsonminesco.com/StructureMacros/#case . The example is given there of treating different special output characters in a display:
Code:
        CASE  ACCUM       ; Test the accumulator against the following cases.
           CASE_OF  $0A   ; In the case of it containing the linefeed character,
              <actions>   ; execute these instructions,
              <actions>
           END_OF         ; then jump to the first instruction after END_CASE.


           CASE_OF  $0D   ; If it has the carriage-return character,
              <actions>   ; execute these instructions,
              <actions>
           END_OF         ; then jump to the first instruction after END_CASE.


           CASE_OF  $08   ; If it has the backspace character,
              <actions>   ; execute these instructions,
              <actions>
           END_OF         ; then jump to the first instruction after END_CASE.


           <actions>      ; If the character is anything else, do these default
           <actions>      ; actions to feed it to the display as display data.
        END_CASE

It makes it more readable, eliminates the labels, and assembles probably exactly the same thing you'd do by hand (except that doing it by hand makes you more likely to get a bug). Any assembler with macro capability should be able to do it.

_________________
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  
 Post subject: A partial failure
PostPosted: Thu Jun 09, 2022 9:33 pm 
Offline

Joined: Fri Mar 18, 2022 6:33 pm
Posts: 489
Here is my breadboard circuit:
Attachment:
20220609_165220.jpg
20220609_165220.jpg [ 3.83 MiB | Viewed 1078 times ]


It works great! As I mentioned up thread, it's pretty close to identical with the one from Ben Eater's video. If you're interested, I can sketch a schematic, or point you to the video, etc., but I mostly include the photo just to show the wiring - bit loopy data lines, long unshielded wires from the PS2 connector (that's what's going off the right side of the frame) and so on. This seems to run indefinitely with no errors.

Since that was so, I thought now would be a good time to add it to my custom I/O card that holds my LCD circuit. Here it is:
Attachment:
20220609_165358.jpg
20220609_165358.jpg [ 4.36 MiB | Viewed 1078 times ]
Attachment:
20220609_165416.jpg
20220609_165416.jpg [ 5.03 MiB | Viewed 1078 times ]


The LCD plugs in just under the VIA on the left.

It... kinda works. The good part is, adding the PS2 stuff to the board did not make the LCD stuff that was already there stop working. I don't expect anyone to try and analyze that rat's-nest of wiring, I'm just posting it so you can see my technique (or lack of it!).

So, what's happening is, the keyboard circuit does work. When I push down the spacebar, I get a space... usually! But sometimes I get a random character. This is what happened on the breadboard circuit before I added the pullup resister on the data line. I've poked around with my multimeter and everything to do with the data line seems to be hooked up the right way. The other thing is that my voltage regulator (LM7805) is now getting REALLY hot. It wasn't doing that before, so something must be wrong with my power network. I'm not sure what though; there don't seem to be any shorts.

What I'm wondering here is, how to troubleshoot this with just a multimeter?

_________________
"The key is not to let the hardware sense any fear." - Radical Brad


Top
 Profile  
Reply with quote  
 Post subject: Re: A partial failure
PostPosted: Thu Jun 09, 2022 10:40 pm 
Offline

Joined: Sat Oct 09, 2021 11:21 am
Posts: 713
Location: Texas
Paganini wrote:
It... kinda works.


Ahh, that takes me back. Love the pictures! Here was my first contraption. viewtopic.php?f=12&t=6818&start=120#p88404 It also worked... kindof. :)

If something is getting hot, gosh, I would be scared. The only time I had something get HOT was a small CPLD that Bill gave me to test things out on. It was FRIED because of... the power supply! Yep my little USB wall-wart was running 12V into it, when it should have gotten 5V. IT. GOT. HOT. So perhaps this is a place where you are getting 'noise'?

Sorry about no help, again, but thanks for posting the update!

Chad


Top
 Profile  
Reply with quote  
 Post subject: Progress has been made!
PostPosted: Sun Jun 12, 2022 7:15 pm 
Offline

Joined: Fri Mar 18, 2022 6:33 pm
Posts: 489
Here's another picture for Chad. :P

Attachment:
20220612_145714.jpg
20220612_145714.jpg [ 4.45 MiB | Viewed 1045 times ]


I don't seem to be able to be both operational and tidy. That big mess is working great at 8Mhz. My continuing mission uncovered a whole comedy of errors... wrong resistor value, wrong capacitor value, (both of these off by an order of magnitude), a crucial capacitor connected to VCC instead of GND (!) - yikes.

The really critical bit, though, that made it work without errors was altering the design slightly. I had to reduce the value of the resistor in the RC circuit from 3k3 to 2k2 to eliminate the intermittent errors I was getting. I was getting the right number of pulses, but they didn't always line up with the data, so I was getting garbled scancodes every so often. I did not do any math to figure out the resistor size, I am slightly embarrassed to say; I just grabbed my big ammo-pack book of resistors and applied the good old "cut 'n try" method. :D

I think that maybe the reason I had to reduce the resistor size is that I'm using 74AHCT logic instead of the 74HC logic in Ben Eater's reference design.

_________________
"The key is not to let the hardware sense any fear." - Radical Brad


Top
 Profile  
Reply with quote  
PostPosted: Sun Jun 12, 2022 9:33 pm 
Offline

Joined: Sat Oct 09, 2021 11:21 am
Posts: 713
Location: Texas
Paganini wrote:
Here's another picture for Chad. :P

I think that maybe the reason I had to reduce the resistor size is that I'm using 74AHCT logic instead of the 74HC logic in Ben Eater's reference design.


Thanks for the picture :) It looks like a nice setup honestly. I like how you have a backplane to plug modules into, and out of. I have never used one, but it seems handy.

Is that breadboard that the LCD is attached to itself attached to the backplane?

This is my greatest failing personally. Little resistor values that change big things. I, like you, just "wing it" when it comes to those sorts of things. 3k3 for anything connected to control lines on the 6502, 4k7 for anything on an address bus (basically banked RAM with a VIA), and 10k for slow things like keyboards and whatnot. I have no clue if that is good or not, but it has worked so far!

Why are you using the 74AHCT logic in particular? Perhaps the fast edges were not happy with the 3k3 resistor, but ok with the 2k2 resistor?

It's coming along well! So what's next on the to-do list? :)

Chad


Top
 Profile  
Reply with quote  
PostPosted: Sun Jun 12, 2022 11:41 pm 
Offline

Joined: Fri Mar 18, 2022 6:33 pm
Posts: 489
The thing with the mini-breadboard is TEBL's "RC Project Board." https://github.com/tebl/RC-Project-Board I made a few of them; I think they're really handy. My favorite one has female headers for the VIA ports, so I can use jumper wires to attach them to the breadboard, but I think I melted the headers internally (they're really cheap ones) when I was soldering them on, because if I bump data lines I get a whole lot of chaos. The one in the picture has male headers, which are more of a pain to use, but it's working fine so I can't complain. :) The breadboard is held on with adhesive, but it's not actually on the bus unless you wire it up. You can see on the right hand side there are a couple of VCC/GND headers for the power rails.

I'm using -T logic in particular because in the long run I want to mix in some older components. I have some M6845 CRT controllers, for example. I went with AHC over HC because TI seems to market it as equivalent to HC but better. Retro Brew Computers has some good info that suggests AHCT is basically a drop-in upgrade for 74HCT/74LS. Just to see what would happen, I tried taking all of the 74AHCT logic out and replacing it with 74LS, and the computer ran fine at 4Mhz, but not at 8Mhz. I think you are probably right about the fast edges!

Next I think I will have another try at making a more permanent keyboard circuit on my perf-board. I ordered some better wire-wrap wire (I hope!). The wire I was using has PVC insulation that won't fit through my wire-wrap tool the way it does in Garth's primer. I ordered a spool of Kynar wire; hopefully that will work better!

_________________
"The key is not to let the hardware sense any fear." - Radical Brad


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 14, 2022 11:54 am 
Offline
User avatar

Joined: Tue Aug 11, 2020 3:45 am
Posts: 311
Location: A magnetic field
Paganini on Tue 26 Apr 2022 wrote:
Since I have two index register that, in combination, can count up to $FFFF, I feel intuitively that I should be able to create one general purpose delay function that simply accepts a parameter telling it what to count to.


Trust your intuition because it is far better than mine.

Paganini on Mon 30 May 2022 wrote:
Code:
    pla
    cli


This is working. If I move sei down one instruction, or cli up one instruction I start to have problems.


Your interrupt routine is disrupting registers or stack. Are you pushing and pulling all modified registers in the traditional order?

_________________
Modules | Processors | Boards | Boxes | Beep, Beep! I'm a sheep!


Top
 Profile  
Reply with quote  
PostPosted: Tue Jun 14, 2022 3:11 pm 
Offline

Joined: Fri Mar 18, 2022 6:33 pm
Posts: 489
Sheep64 wrote:

Paganini on Mon 30 May 2022 wrote:
Code:
    pla
    cli


This is working. If I move sei down one instruction, or cli up one instruction I start to have problems.


Your interrupt routine is disrupting registers or stack. Are you pushing and pulling all modified registers in the traditional order?


That would seem logical - my guess was stack corruption. The only problem is, the ISR doesn't use any registers.

_________________
"The key is not to let the hardware sense any fear." - Radical Brad


Top
 Profile  
Reply with quote  
PostPosted: Wed Jun 15, 2022 9:52 pm 
Offline

Joined: Tue Jul 05, 2005 7:08 pm
Posts: 1041
Location: near Heidelberg, Germany
If the ISR does not use any registers - what does it actually do?

_________________
Author of the GeckOS multitasking operating system, the usb65 stack, designer of the Micro-PET and many more 6502 content: http://6502.org/users/andre/


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

All times are UTC


Who is online

Users browsing this forum: janik and 83 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: