The Novels

Economics 101, a Novel (Rough Draft) -- My first sustained attempt at a novel, two-thirds finished in rough draft, and heading a little too far south.
What would you do if you and your study partner, with whom you had been seriously discussing marriage, suddenly found yourselves all alone together on a desert island? Study economics?
Sociology 500, a Romance (Second Draft) -- The first book in the Economics 101 Trilogy.(On hold.)
Karel and Dan, former American football teammates and now graduate students, meet fellow graduate students Kristie and Bobbie, and the four form a steady study group.

Featured Post

Sociology 500, a Romance, ch 1 pt 1 -- Introducing Bobbie

TOC Well, let's meet Roberta Whitmer. Bobbie entered the anthropology department office and looked around. Near the receptionis...

Wednesday, June 24, 2020

Backup: 33209: Straits -- Status Display

Backup of https://joelrees-novels.blogspot.com/2020/06/33209-straits-status-display.html.


Chapter 13.2: Straits -- Sabbath

Chapter 13.3: Straits -- Status Display


"Okay, guys, I have to focus on Julia's computer, so let's all work on the keyboard controllers on our own for a while."

"For your girlfriend, huh?" Tanya was apparently feeling a little catty.

"So you're finally owning up to it?", Suzanne pouted. "What did it take?"

"Oh, shutup, Suzanne," Mike grumbled. "I, for one, don't want to hear about it."

Wallace also complained, "Leading us on, and then jumping ship for your girlfriend?"

Winston admonished, "We can handle this. Bob and Jennifer almost have it worked out, anyway."

Jennifer shook her head. "It's time for us all to work on our own for a bit. That's what we're here for."

"Should you just abandon everyone for me?" Julia asked.

"I'm not abandoning anybody, and Jennifer's right."

Doctor Brown just watched in amusement.

There was more grumbling, and some of the members of the group parked themselves where they could watch as I used scratch paper to show Julia how the display translation tables would be put together. But I ignored them and proceeded to recreate a diagram from Saturday.
                 

"Others have theirs wired up differently, but the way you ended up wiring yours is the same order as the diagram I drew. Bottom left is the high bit, and decimal is the low bit. Let's name those."

"Name them?"

"Give them names in the program."

"Okay."

"We'll call the bottom left segment BLS, and it will be binary 10000000."

"You and Dad both told me about converting to hexadecimal four bits at a time, so that's $80?"

I gave her a thumbs-up and scrawled
BLS EQU $80 ; 1000 0000
"BLT would not be a good name?"

Julia and I chuckled, and so did the students who were listening.

"No?"

"Well, I was thinking S for segment, but why not? T for the last letter of 'bit'. How about the rest?"

"Like this?" Julia wrote out code, intuiting the permutations from the line I'd written:
BLT  EQU $80 ; 1000 0000
BT   EQU $40 ; 0100 0000
BRT  EQU $20 ; 0010 0000
MT   EQU $10 ; 0001 0000
TLT  EQU $08 ; 0000 1000
TT   EQU $04 ; 0000 0100
TRT  EQU $02 ; 0000 0010
DT   EQU $01 ; 0000 0001
"Yep."

"Oh, maybe T is a little confusing."

"It's okay. We'll keep it. As long as we can read it and understand it."

"Then we need a comment line to help us remember?"

"Such as?"

She wrote,
* BOTTOM, TOP, MIDDLE
* LEFT, RIGHT, DECIMAL
"Looks good."

"Do the last four lines need the dollar sign and the zero?"

"No, but removing them would make the form less obvious, so let's keep them. Now, let's use those to make a table of segments, like we figured out on Saturday. The zero will be the first entry. Which bits does it use?"

"All but the middle and the decimal?"

"Okay. We can use '.OR.' to put bits together, so it can look like this:"
TABLE
    FCB BLT.OR.BT.OR.BRT.OR.TRT.OR.TT.OR.TLT
"That's not going to fit in the 32 column screen."

"True, but that's okay. But it's also ugly -- hard to read, and that is not okay. Maybe I can think of something to help."

After some thought, I wrote
CUP EQU BLT.OR.BT.OR.BRT
CAP EQU TRT.OR.TT.OR.TLT
*
TABLE
    FCB CUP.OR.CAP
"It sort of helps."

"Heh. Okay, there's zero. One is easy."

She scribbled her guess, "BRT.OR.TRT". "Is that it?"

"Right."

With a bit of scribbling, erasing, and rescribbling, we had this:
BCUP EQU BLT.OR.BT.OR.BRT
TCAP EQU TRT.OR.TT.OR.TLT
ONET EQU BRT.OR.TRT
TRCUP EQU TT.OR.TRT.OR.MT
BLCUP EQU MT.OR.BLT.OR.BT
BRCUP EQU MT.OR.BRT.OR.BT
TCUP EQU TLT.OR.MT.OR.TLT
TLCUP EQU TT.OR.TLT.OR.MT
BCAP EQU BLT.OR.BT.OR.BRT
VBAR EQU TLT.OR.BLT
*
SEGTBL
    FCB BCUP.OR.TCAP ; 0
    FCB ONET ; 1
    FCB TRCUP.OR.BLCUP ; 2
    FCB TRCUP.OR.BRCUP ; 3
    FCB TCUP.OR.BRT ; 4
    FCB TLCUP.OR.BRCUP ; 5
    FCB TLCUP.OR.BCUP ; 6
    FCB TT.OR.ONET ; 7
    FCB BCUP.OR.TCAP.OR.MT ; 8
    FCB TCAP.OR.BRCUP ; 9
    FCB TCAP.OR.BCAP ; A
    FCB VBAR.OR.BRCUP ; b
    FCB BLCUP ; c
    FCB BLCUP.OR.ONET ; d
    FCB TCAP.OR.BLCUP ; e
    FCB VBAR.OR.TLCUP ; F
"I can sort of see what the table is, but how does that get into the LEDs?" Julia asked me.

"I've been avoiding that question all week. I want to use a parameter stack, but we're short of both RAM and registers. I guess we're not going to be trying to run two displays at once, so global variables should work."

Julia looked at me with a blank expression.

I proceeded anyway. "We'll have a variable for the current number to display and a variable for the current column to display in, and --" I scribbled:
NUMDSP RMB 1
CLMDSP RMB 1
"We can squeeze those into a single byte if we need to, but let's do it simple first."
PUTDIG
    LDX NUMDSP ; HIGH BITS ZERO!
    LDA SEGTBL,X
    LDX CLMDSP ; HIGH BITS ZERO!
"I'm lost."

The lab erupted in applause, and I looked around and realized that everyone was gathered around listening, and Mark, Jeff, Mike, and even Bob and Jennifer had been taking turns transferring our scribblings and musings to the chalkboard.

I looked over at Doctor Brown, and he gave just gave me a "Who, me?" look.

I chuckled in embarrassment.

"Okay. Maybe we should do this as a group, and then you can all adjust it for how you wired yours. But I guess we need to use teamwork on the notes, and explanations. Who followed how we put the table together?"

Bob, Jennifer, Mark, Jeff, and Mike said they were good on it, some of the others raised their hands hesitantly. There was a lot of doubt.

After making new arrangements to make sure Julia would not be so busy taking notes that she couldn't think and ask questions, I started over, working through the 6805 assembler language and syntax.

"'EQU' is short for equate. It equates the label on the left to the expression on the right. Hopefully we don't need to know when the expression is evaluated, because I don't know and I don't want to waste time figuring that out.

"So when we write
BLT  EQU $80 ; 1000 0000
"that could mean bacon, lettuce, and tomato is flagged by bit seven, or it could mean the bottom left segment bit is bit seven."

That got some chuckles.

"'.OR.' is the logical-or operator. It performs a column-by-column logical or, keeping the column results in their columns. That means that'
ONET EQU BRT.OR.TRT
"equates the label ONET to the result of 00100000 or-ed with 00000010, which is 00100010, or hexadecimal 22. And if we put $22 on the segments port and hold one the anode of one of the displays down to 0, it should make the top and bottom left segments light up, showing us a '1'. If we want to see that, we could try something like"
START
    LDA #22
    STA CATHODES
    LDA #FE
    STA ANODES
WAITLP
    BRA WAITLP
"'LDA loads a small value into the accumulator, STA stores the accumulator to memory or I/O space, BRA branches always and forever, letting us see the results. I think we could use a WAIT instruction, but this loop forever to itself will do what we need with most CPUs, so it's a good thing for everyone to see."

I decided to stop and demonstrate it. I asked Julia to type it in, assemble it, and burn it into her 68705, and run the program. When it produced a 1 on the rightmost seven segment display, she seemed a bit more confident of what she was understanding, and so did certain of the other students.

"Hopefully everybody's working out the equate definitions for your own circuits while we do this.

"The FCB that we use to construct the table of constants stands for 'Form Constant Byte or some such, and it means store a constant value into the program object code. By putting them into a table in the object code, we make the patterns available for look-up.

"Now, if we shift the anode bit, we can light up one digit at a time, but it's going to happen so fast it will look like they're all lit up at once. The LSL instruction shifts the argument one bit to the left, and we'll use it."

Eyes were glazing over, so I wrote another bit of demonstration code, using the defined constants directly:
PAUSE
     DECX ; IDLE COUNT
     BNE PAUSE
     RTS
*
START
    CLRX
    LDA #FE
    STA ANODES
    LDA #ONET
    STA CATHODES
    BSR PAUSE ; LET PORT SETTLE
    LSL ANODES
    LDA #TCAP
    STA CATHODES
    BSR PAUSE
    LSL ANODES
    LDA #VBAR
    STA CATHODES
    BSR PAUSE
    LSL ANODES
    LDA #BLCUP
    STA CATHODES
    BSR PAUSE
    LSL ANODES
    LDA #TRCUP
    STA CATHODES
    BSR PAUSE
    LSL ANODES
    LDA #TCUP
    STA CATHODES
    BSR PAUSE
    LSL ANODES
    LDA #BCAP
    STA CATHODES
    BSR PAUSE
    BRA START
"The PAUSE routine uses the X register as an idle counter. DEC counts X down one, and BNE loops back to count again until X is zero. 'B' for Branch. 'NE' for Not Equal, or in other words, not zero. I suppose I'll have to explain that more later."

"Get your minds out of the gutter, guys, BRA is a BRanch Always. so when we have displayed all the patterns, one place at a time, we go back and do it again.

Suzanne complained, "I suppose some male engineer thought that acronym up."

"You suppose right. I do not defend him. In a little bit, I'll show you how to use a macro to give that instruction a better mnemonic name."

"I don't suppose anyone will forget the original mnemonic," Bob commented, and Jennifer slapped him over the head.

Doctor Brown watched this in amusement, taking no sides.

Again, Julia typed it in, assembled it, and burned it, this time into a 68705 she borrowed from Jeff while hers was in the eraser.


She was rather dissatisfied with the cryptic output, so she got back on the computer and added equates for each digit:
N0 EQU BCUP.OR.TCAP ; 0
N1 EQU ONET ; 1
N2 EQU TRCUP.OR.BLCUP ; 2
N3 EQU TRCUP.OR.BRCUP ; 3
N4 EQU TCUP.OR.BRT ; 4
N5 EQU TLCUP.OR.BRCUP ; 5
N6 EQU TLCUP.OR.BCUP ; 6
N7 EQU TT.OR.ONET ; 7
N8 EQU BCUP.OR.TCAP.OR.MT ; 8
N9 EQU TCAP.OR.BRCUP ; 9
NA EQU TCAP.OR.BCAP ; A
NB EQU VBAR.OR.BRCUP ; b
NC EQU BLCUP ; c
ND EQU BLCUP.OR.ONET ; d
NE EQU TCAP.OR.BLCUP ; e
NF EQU VBAR.OR.TLCUP ; F
*
SEGTBL
    FCB N0
    FCB N1
    FCB N2
    FCB N3
    FCB N4
    FCB N5
    FCB N6
    FCB N7
    FCB N8
    FCB N9
    FCB NA
    FCB NB
    FCB NC
    FCB ND
    FCB NE
    FCB NF
Then she modified the test code:
START
    CLRX
    LDA #FE
    STA ANODES
    LDA #N0
    STA CATHODES
    BSR PAUSE ; LET PORT SETTLE
    LSL ANODES
    LDA #N1
    STA CATHODES
    BSR PAUSE
    LSL ANODES
    LDA #N2
    STA CATHODES
    BSR PAUSE
    LSL ANODES
    LDA #N3
    STA CATHODES
    BSR PAUSE
    LSL ANODES
    LDA #N4
    STA CATHODES
    BSR PAUSE
    LSL ANODES
    LDA #N5
    STA CATHODES
    BSR PAUSE
    LSL ANODES
    LDA #N6
    STA CATHODES
    BSR PAUSE
    BRA START
And she tried it again, borrowing a 68705 from Mark.


I think everyone cheered.

"But I have a question."

"Yeah?"

"I don't think we're actually using the table in this test."

"True. And I could get a swelled head and imagine I taught you that, but I think you've done more figuring out than I've done teaching."

"Oh, give her a kiss," Winston said. "She deserves it."

"No es para ...," I began, but Julia shook her head just perceptively enough to stop me.

"Whether I reward him with a kiss or not is my business," she said.

Wolf whistles and other unnecessary noises of appreciation ensued, and Julia and I cleared our throats simultaneously, with lopsided grins.

"Back to work," Julia said.

I continued. "So now we need to actually use the table. We'll use the X register to pick the pattern to display:"
    ORG $88 ; VARIABLES
PAUSER RMB 1
    ORG ROM ; CODE
PAUSE
    CLR PAUSER
PAUSELP
    DEC PAUSER
    BNE PAUSELP
*
START
    LDX #1
    SEC
DISPLP
    ROL ANODES
    LDA SEGTBL,X
    STA CATHODES
    BSR PAUSE
    INCX
    CPX #8
    BNE DISPLP
    BRA START
"ORG means origin, and it sets the address where the next part is assembled to. RMB Reserves a Memory Byte in low memory, which we will use instead of X as the idle loop counter. We label that byte PAUSER. CLR clears the variable, and DEC decrements it by 1.

"The indexed addressing mode used in 'LDA SEGTBL,X' adds the constant address of the base of the SEGTBL table to the value in X and uses the result as the address from which to load the accumulator. With a 1 in X, that points to the bit pattern to display a 1.

"Then we count X up 1, and use CMP to CoMPare X to the end value, 8. BNE Branches back to do another if X is Not Equal to 8."
 Julia moved over and let Freddie practice typing and burning, but we still used Julia's circuit so the wiring would be right. This demonstration produced the numbers 1 through 7 on the displays.

"If you're not comfortable with all of that, try some of your own later. Now we need to write the real display code.

"We want to be able to do other things besides display numbers, so we're going to use the timer built into the 6805 to count instead of having the CPU count, and we'll have the timer interrupt the program to actually display the numbers."

"Is this only for displaying numbers?" Tanya asked in a slightly petulant tone.

"Well, the numbers might mean things. For instance, if something goes wrong during boot, we could put an error code and an address on the display, to give clues about the error state. Or we might say that a blank display is an all-operational status."

I can tell your eyes are glazing over now, so, rather than walk you through it with us I'll just note that we read in the manual about the timer, and I walked them through initialization, using the pre-scaler to set the granularity, calculating the value to initialize the timer and pre-scaler to interrupt the CPU once every millisecond, and constructing the interupt routine to display the digits one place at a time.

Someday, somewhere in my blogs, I'll show the complete keyboard debounce and status display routine, complete with display suppression and other features that we evenutally added. Suffice it to say that we had Julia's status display functional at a usable level on Monday before I went home to deliver newspapers, and that about half of the group had theirs functional by the time I got back.

Chapter 13.4: Keyboard Decoding

[Backed up at https://joel-rees-economics.blogspot.com/2020/06/bk-33209-straits-status-display.html.]




No comments:

Post a Comment

Keep it on topic, and be patient with the moderator. I have other things to do, too, you know.