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...

Showing posts with label backup2. Show all posts
Showing posts with label backup2. Show all posts

Monday, August 24, 2020

Backup01: 33209: Rocks -- 2805

Third version backup of https://joel-rees-economics.blogspot.com/2020/08/bk-33209-rocks-2805.html.

Chapter 13.8 Straits -- Intellectual Property Agreements

Chapter 14.0: Rocks -- 2805


Bill grinned sardonically. "Well, I think this will work out well."

(You may want to put your BS meter away for this chapter, or at least set the threshold level pretty high.)

Bob chuckled. "Stephanie, can you get together with Carrie and see that what these three signed gets replaced with a more appropriate agreement?"

"I'd be happy to, sir."

"The same as Joe and Julia's agreements, with an addendum for their projects?" Ms. Philips asked.

Bill answered for him. "Yes, yes, of course."

And Bob nodded.

Ms. Steward, Ms. Philips, Mike, our Bob, and Jennifer got together at one end of the table.

As Julia and I connected her mainboard to one of the TVs, I whispered to her. "I thought the two guys were from Motorola's legal department."

"I did, too," she whispered back. "Must be much higher up in management."

I nodded my agreement.

(No, I never even came close to meeting Motorola's Bob and Bill in the real world.)

A number of engineers came in, bringing in pizza and liquid refreshment.

"Your friends," Motorola's Bob said to me with a grin, "are having pizza elsewhere. I think we should have some pizza in here, too." He turned to one of the engineers. "Jess, I hope there's something non-alcoholic to drink?"

The engineer named Jesse started, and looked up guiltily from the six-packs he was carrying. "Erm ...."

An engineer on the other side of the room called out, "Denny made sure we had root beer, and I made sure we had some other options." He held up two-liter bottles of soft drinks. "Not all of us are fueled by beer."

"Good job, Tobe."

Tobias gave Bob a thumbs-up.

As we ate pizza and talked, we demonstrated what we had done so far -- the ROM menus, BASIC, TSC's debug system, and Flex, and using Flex to run Motorola's assemblers.

We shared some comments and discussion of the process of getting Flex to run on the Micro Chroma 68, and I described my dynamic RAM refresh circuit, explaining how I borrowed the video scan counter of the 6847, and mentioning the problems I had run into with my original design. I also explained the simplistic bank switching that made it possible to run Flex.

Several of the engineers commented on how my refresh circuit sounded similar to a circuit the engineers who worked with Radio Shack on the Color Computer had produced before they designed the sequential address multiplexor as a separate circuit. Not yet being familiar with the SAM, I couldn't comment.

Jennifer, our Bob, and Mike had taken care of their paperwork by then. Bob knew something about the SAM already, and he discussed it a bit with the engineers.

We showed them the 6801 daughterboard on Julia's mainboard, and her keyboard, and she described the way we were using the 6805 and its timer to scan and debounce the keyboard and control the hexadecimal display, augmenting the I/O with either latch or multiplexor.

Then she loaded Forth on her computer from tape and used it to send numbers out to her keyboard's hexadecimal display.

We stopped for a few minutes while Bob, Bill, and some of the engineers discussed whether Motorola wanted to ask us for permission to use the keyboard decoder/numeric display design and code for an application note, and the upshot was that they did, and the five of us agreed to discuss that with the rest of the group.

Most of the engineers were appreciative of Julia's Forth examples, and I explained what I had done to get the drivers to work, mentioning that we hadn't solved the disk problems yet for Forth.

My disk interface was the topic of considerable discussion, and Ms. Philips and Ms. Steward quickly produced a sharing addendum to allow us to get the schematics out for everyone to look at. Before long, Julia and I had another addendum to our agreements -- an internship contract for producing several tech notes on the use of the 6801 as a floppy disk controller. The addendum allowed Motorola the option of building a semi-custom "system on a chip" SOC floppy disk controller based on my circuits.

Denny had already shared the schematics Julia had drawn up from my scrawls with some of his friends. But now the context was Motorola, so the addendum was deemed wise.

"Ah, to be an undergrad with all the time in the world again," Tobias reflected jocularly. "Do you think you could get a 6805 to handle the floppy controller functions?"

I tilted my head and thought. "That would probably limit sector size, with X being only eight bits. Come to think of it, the size of X might require enough extra code to prevent the processor from keeping up with the data."

Another engineer, Sharon, asked, "What's your general impression of the 6805?"

"It does the job for little things like the keyboard controller," our Bob volunteered.

I concurred.

There was general approval of that analysis.

"But I miss stack support," I added.

"On an eight-bitter?" Jesse queried. "You'd prefer the 6502, maybe?"

Jennifer noted, "The 6502 is a clever design, but it belongs to MOS Technologies and Commodore, doesn't it?"

(In the real world, Motorola might have been smart to use their patent agreements with MOS Technologies and second-source the 6502 in the late 1970s. They did offer to produce SOC chips with the 6502 as the CPU core in the mid-to-late 1980s. But that history is not for this story.)

"The 6502 is a good chip," I asserted. "It straddles some boundaries like the 6809, but I think the way it does so constrains compatible upgrade paths." I paused for thought and emphasis. "Every application wants room to grow. Maybe some shouldn't, but many can profitably grow in scope and function. And growing software reliably wants things like code re-use by re-entrant subroutine call, and keeping subroutines re-entrant requires something like a stack that you can push to and pop from, for parameters and local variables. There's no push or pop on the 6805."

Julia added, "Even if you aren't calling subroutines a lot, a stack helps manage RAM. Global RAM is harder to keep track of, even if you never re-use any variables."

I turned and raised my eyebrows. "You're picking this stuff up."

"A little. Dad has been explaining things you haven't."

"Oh. Sorry. I'll have to do better."

"It's okay." She smiled. "He enjoys it. He always wanted his oldest child to be an engineer."

"Now I know why he likes me so much."

We grinned at each other, then Julia coughed discreetly.

I ducked my head and turned back to the engineers, several of whom were quietly clapping their hands, rolling their eyes, or pretending to give us wolf-whistles.

"Anyway, as Julia points out, a stack you can reference makes RAM much easier to manage. Of course, you can synthesize a stack, but synthesizing is slow, and a disincentive, and the code to support the synthesized stack is a distraction."

An engineer named Pete objected. "Moving up to the 6801 is not that hard."

"But it does require reworking a lot of the code, and checking all of it for side-effects of the differences between the two," I parried. "And there are the bit manipulation instructions in the 6805 that the 6801 does not have, easy enough to synthesize on the 6801, but still requiring time and effort. Adding stack support to the 6805 ought not to be that much of a change, and it would support quite a bit of application growth. That would give the customers' engineers much more confidence in choosing the improved 6805 for small projects with the potential to become large."

(The 68HC11, an evolutionary step from the 6801 that Motorola introduced in 1984, did have bit manipulation instructions. And the 6805 itself later evolved to the confusingly named 68HC08, which did introduce more complete stack support via instruction pre-byte escape -- single stack with stack indexing, as opposed to the dual stack and index marking I suggest  below. In the real world. Several years later.)

Jesse countered, "Okay, how do you propose to add stack support with minimal change? Pre-bytes like on the 6809 are too expensive for a pure eight-bitter."

(Well, they were just a little too expensive in the early 1980s.)

"Add a second stack register. Maybe call it U for user stack, following the 6809's register naming. Add push and pop instructions that push and pop to the U stack, and transfer instructions that allow moving U to X and back. And instructions to save U and restore it using the S stack. Eight instructions should do the trick."

Julia handed me a sheet of scratch paper, and I wrote down the additional instructions:
PSHUA, PULUA
PSHUX, PULUX
PSHSU, PULSU
TUX, TXU
I drew out a map of the registers of the 6805, except for the condition codes:

6805 register b15b14b13b12 b11b10b9b8 b7b6b5b4 b3b2b1b0
A:
A7A6A5A4 A3A2A1A0
X:
X7X6X5X4 X3X2X1X0
SP:00000000 1(SP6)SP5SP4 SP3SP2SP1SP0
PC: ------PC12 PC11PC10PC9PC8 PC7PC6PC5PC4 PC3PC2PC1PC0

Then I drew out a modified map, including the U stack:

2805 register b15b14b13b12 b11b10b9b8 b7b6b5b4 b3b2b1b0
A:
A7A6A5A4 A3A2A1A0
X:
X7X6X5X4 X3X2X1X0
U:00000000 1(U6)U5U4 U3U2U1U0
SP:00000001 00SP5SP4 SP3SP2SP1SP0
PC: ------PC12 PC11PC10PC9PC8 PC7PC6PC5PC4 PC3PC2PC1PC0

"Keeping the stacks separate will allow moving the return stack out of the direct page. It could then be given its own port to the CPU, in its own address space, with separate on-chip address and data lines. That would allow proceeding to the next instruction while the call instruction stacks the return address. That way, calls should end up costing no more than jumps, and it should be possible to make the return operator faster, as well."

The comment about calls taking less time got some discussion of a nature too technical to bore you with here.

Except for the subroutine entry and exit protocol. "Subroutines," I continued, "could look like this:"
ROUTINEA
    TUX
    LDA 0,X ; 1st parameter
    LDX 1,X ; 2nd parameter
    ...
    TUX
    LDA 2,X ; 3rd parameter
    ...
    INX ; clear all parameters
    INX
    INX
    TXU
    RTS
"But X is only eight bits," an engineer named Wayne objected.

"The S register is only six or seven bits in the 6805. The return stack is so small it that it will run out of memory before it cycles through the addresses allocated to it in the direct page. But you can move it out of the direct page and no one would notice, and it could still be effectively less than eight bits to be decremented and incremented by the push and pop.

"If it weren't for wanting to sometimes directly shift local variables, and the lack of sixteen-bit index offsets for the unary instructions in the 6805, you could put the parameter stack outside the direct page, too. Putting it where the return stack is now should be no problem, at any rate, and allow access by unary instructions."

Several of the engineers started scribbling on scratch paper.

Sharon said, "This could be useful."

An engineer named Chuck intoned, "Room in the design for improvement is good engineering."

Bill asked, "Are you taking notes on this, Julia?"

"Is that okay?"

"Can we get a copy, and can we mark parts we don't want shared outside?"

"Sure."

"In that case, thank you, make sure you get Chuck's comment about room for improvement in, too, and please continue."

He and Motorola's Bob again exchanged silent words, and both nodded in agreement.

I shook my head and said quietly, "Julia, I presume upon you too much."

Julia grinned. "I'll claim my pay when we get back home."

I grinned back.

"Get a room!" There was a bit of chuckling. We had an audience again.

An engineer named Jack objected. "Isn't dedicating RAM to a second stack a waste?"

I shook my head. "RAM is easy to make and relatively easy to test, isn't it? Shouldn't it be cheap? Like candy. And the call stack doesn't have to be completely inaccessible. If it's in the extended address space, it would be accessible via extended addressing or 16-bit index offsets."

An engineer named Monty grumbled to himself. "Testing RAM is a good way to bring up new processes, too. Forcing the customer to scrimp on RAM is just a little anti-social."

Motorola's Bob chuckled at that, and asked Julia to quote Monty on it.

Jesse was also sketching something on note paper. "Separate address spaces. We could put part of the direct page RAM in its own address space and give it its own port to the ALU, and shave a cycle of access time for that area in direct page RAM," he muttered, half to himself.

Julia repeated, sub-vocalizing, "... shave a cycle for the direct page RAM access."

Jennifer overheard Jesse, and asked him, "Could that be done without making it difficult to speed the processor up?"

Jesse scratched his head. "Actually, if we're careful, it should make it easier to keep things in sync in a process shrink."

"I was thinking about overclocking."

Jesse chuckled. "Overclocking is one of those dirty secrets we don't talk about, but it can be used to predict whether certain aspects of a process shrink will work."

Our Bob joined him in chuckling.

"Is a process shrink where you make the masks smaller?" Jennifer asked.

Our Bob nodded.

Jesse answered, "It's more than that, but, yeah."

"Could that be used to improve access time to the parameter stack?" I asked.

"That would be a bit more complicated," he replied. "Might be too much beyond the concept of an eight-bit micro-controller."

"You know," I commented, "one thing I'd like to have is a way for the CPU to catch things when calls or interrupts try to push too much on the stack, and when return instructions try to pull too much off."

"How can you save state on the stack when the stack isn't valid?" Wayne asked in a tone that was almost rhetorical.

"Could you have a limit register for S that could trigger an interrupt when a call or interrupt would decrement S below it? The limit register could be set by the program, high enough to allow the stack interrupt room to save state without walking on variables."

Jesse looked up from his scratch calculations. "Shadow register sets that get switched in when handling interrupts could be a rather more elegant solution to the stack overflow conundrum."

Julia held her hand up. "Can you help me write that as a note?"

"Interrupts work like calls on our processors. They save the processor state on the call stack. That allows interrupts to nest, to a certain extent. A stack overflow interrupt would fundamentally be unable to nest anyway, so saving state somewhere else might make sense. Some processors have shadow registers --"

Our Bob cleared his throat and said, in a loud whisper, "Z-80. And the 68000's A7 system stack, although that's just one register."

"-- for fast context switches." Jesse chuckled before continuing. "Shadow registers might be one place where you could save the processor's state on stack overflow."

Julia and Ms. Philips conferred with Jesse and our Bob on this and Julia continued with her notes.

"Speaking of the interrupt stack," an engineer named Craig pointed out, "stacking the U stack on interrupts will mess with stack frame compatibility."

"That's part of the reason I call this ideal processor with conflicting specifications the 2805," I explained.

"Conflicting specifications," Motorola's Bob chuckled, and all the engineers joined him.

Julia looked at me in puzzlement.

Tobias explained with a grin: "Conflicting specifications is part of what makes engineering fun." That got more chuckles.

"Giving the processor another name would help let customers know not to expect perfect compatibility," Wayne nodded. "But it also might make sense to not automatically save the U stack pointer." He frowned in thought.

"Assume the interrupt handler routine will behave nicely with the interrupted routine's parameter space, or switch it out itself?" I asked.

"Something like that. There won't be a lot of RAM to switch the stack around in, in a 6805."

"True."

"So, while we're critiquing the 6805, is there anything else?" Motorola's Bob asked.

"Not enough I/O pins. We had to use either an external 8 bit latch or an external multiplexor to get enough I/O bits to read 64 keys and communicate with the main CPU. If we had a package with sixteen more bits of I/O, we could decode larger keyboards without external parts and still give a parallel interface to the main processor. A serial keyboard interface could be done with fewer, but it would still need more than we have."

Julia looked up as she handed Ms. Steward another page-full of notes. "Serial keyboard cables will be better for office computers anyway, right, Joe?"

I agreed.

Jesse nodded, too. "Flatpack can give 64 pins in a reasonably small package. Socketing those is expensive for now, but surface mount is cheap."

Julia stopped him for explanation, and he drew pictures for her. "Flat-pick looks more like a square black chip than a millipede. Contacts on the edges like this. Sockets for them look like cups, but they are often soldered flat on top of the circuit board."


"So separate parts might actually be a better engineering option?" I asked.

"Maybe."

"Anything else?" Motorola's Bob prompted.

"Daydreams?" I laughed.

"Sure." He grinned.

"The 6801's eight-bit multiply is useful. A pair of eight-bit divides -- integer and fractional -- might be useful, too. But I'm thinking about a complete one-bit multiply and one-bit divide."

He furrowed his brow. "Single bit? That seems like swimming against the current."

"Software multiplies spend a lot of time in branch instructions. If you could do a full single-bit multiply with one instruction and stack those instructions up, you could cut the time for a multiply to maybe a quarter of the time of a software multiply on the 6805 and 6801, without the complexity of a full multiplier circuit. You could get similar improvements with a single-bit divide."

(Again, many versions of the 6805 ended up getting a full 8-bit multiplier circuit, and the 68HC11 ended up getting both the 8-bit integer and fractional divides, in the real world.)

Craig responded. "Which algorithm, and how are the arguments addressed? Several known pits to fall into, but it might be worth looking at again."

Bill had picked up the Forth listing, and was looking at the first page.

"This is the license for using Forth?" he asked.

"For the Forth Interest Group's model interpreter," I replied

Monty explained, "There are many Forth development systems with more traditional licensing. The Forth Interest Group uses the liberal license and some of the models are known to be a little buggy in places. In some cases, it's almost as if they just threw code over the wall and abandoned it."

"How do you mean?" Bob asked.

"A liberal license requires an active development team to be useful. The development team can charge to fix bugs. But their model interpreter for our 6800 has nobody following up on it."

Bill laughed. "There's something cynical about giving code away for free and charging to fix bugs."

Monty shrugged. "On the other hand, the user is also able to look for and fix bugs himself. I saw this work at MIT. The group that works with the liberally licensed LISP interpreters only allows contributions that are liberally licensed into their code base. It's a rather elegant approach to sharing. Code that doesn't get used doesn't get fixed."

Bill's forehead wrinkled. "Elegant and efficient. Survival of the fittest. Hmm."

(I should note, I was actually as prescient as the me of this chapter -- two or three years later in my college career in the real world.

And we should also assure ourselves that the real engineers who worked for the real Motorola were aware of pretty much all of this.

Which path is best is often not clear. Motorola's management in the real world made decisions that, in hindsight, appear to have been counterproductive. Examining certain of those decisions is part of my reason for writing this story.

Hindsight does appear to be clearer than foresight, which is precisely the reason that this story is something of a waste of time, in effect, an idolatry of idealized abstract mathematical machines.

But if we are comparing ways to destructively waste time, I think it's less a waste of time than body pornography -- that's essentially an idolatry of idealized bodies. Modern pornography adds saccharin personality to the mix. Some rich person's ideal, not real, imaginary value only.

Speaking of the real world, of course you know, in the real world, Motorola's management and engineers had no reason to do blue-sky brainstorming like this with me, much less believe my ideas. But for this experiment to work, in the world of this novel, they must.)

Chapter 14.1: Rocks -- what?

[Backed up at https://joel-rees-economics.blogspot.com/2020/08/bk-33209-rocks-2805.html.]


Monday, June 29, 2020

Backup01: 33209: Straits -- Status Display

Second version 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."

"Focus on 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 1000 and 0000, which comes out as $80?"

I gave her a thumbs-up and scrawled
BLS EQU $80 ; 1000 0000
"Instead of BLS, BLT would not be a good name?"
Julia and I chuckled at her joke, 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'll need comment lines to help us remember?"

"Such as?"

She wrote,
* BOTTOM, TOP, MIDDLE
* LEFT, RIGHT, DECIMAL
"Looks good, and it keeps it short for the screen we're working on."

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

"No, they're the same in decimal and hex, with or without the leading zero. 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.TRT
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 for a whole week. I want to use a parameter stack, but we're a little tight on 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 after all, 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.

George apologized, "I don't seem t do hexadecimal math in my head. Can someone explain it?"

Mike started scribbling on some scratch paper. "It's like this, --"

Doctor Brown suggested, "Mike, could you do that at the board for those who need some review?"

After a moment of hesitation, Mike stood up to the chalkboard and quickly wrote out a conversion table:

decimal
hexadecimal
binary
0:$00=0000 0000
1:$01=0000 0001
2:$02=0000 0010
3:$03=0000 0011
4:$04=0000 0100
5:$05=0000 0101
6:$06=0000 0110
7:$07=0000 0111
8:$08=0000 1000
9:$09=0000 1001
10:$0A=0000 1010
11:$0B=0000 1011
12:$0C=0000 1100
13:$0D=0000 1101
14:$0E=0000 1110
15:$0F=0000 1111
16:$10=0001 0000
17:$11=0001 0001
21:$15=0001 0101
32:$20=0010 0000
37:$25=0010 0101
128:$80=1000 0000
133:$85=1000 0101

"We got groups of four binary digits on the right, and they match up with single digits of hexadecimal in the middle. It's not a coincidence. It's a rule."

After a bit of discussion, George just shrugged. "I guess I'm just not seeing something. Maybe we should keep going."

I offered my own suggestions. "Mike can help you, and we'll be showing a lot of examples, I think. Let's see if moving ahead works."

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 as I used it.

"'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 right 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 means branch always and forever, and it does so, looping to itself, letting us see the results. This is a CMOS 1468705, so I think we could use a WAIT instruction here, but this loop forever to itself will do what we need with most CPUs. So it's a good thing for everyone to see, at least once."

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, as also did certain of the other students.

"Hopefully everybody's working out your own equate definitions for your own circuits while we do this. I guess we should put the definitions Julia and I came up with on the chalkboard, but remember yours will be somewhat different." And as I copied to the chalkboard, I added more comments, showing the expected bit values:
* BOTTOM, TOP, MIDDLE
* LEFT, RIGHT, DECIMAL
* SEGMENT BIT T
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
*
BCUP EQU BLT.OR.BT.OR.BRT
* 1110 0000 $E0
TCAP EQU TRT.OR.TT.OR.TLT
* 0000 1110 $0E
ONET EQU BRT.OR.TRT
* 0010 0010 $22
TRCUP EQU TT.OR.TRT.OR.MT
* 0001 0110 $16
BLCUP EQU MT.OR.BLT.OR.BT
* 1101 0000 $D0
BRCUP EQU MT.OR.BRT.OR.BT
* 0111 0000 $70
TCUP EQU TLT.OR.MT.OR.TRT
* 0001 1010 $1A
TLCUP EQU TT.OR.TLT.OR.MT
* 0001 1100 $1C
BCAP EQU BLT.OR.BT.OR.BRT
* 1110 0000 $E0
VBAR EQU TLT.OR.BLT
* 1000 1000 $88
*
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 TLCUP.OR.BLCUP ; E
    FCB VBAR.OR.TLCUP ; F
"The FCB that we use to construct the table of constants stands for 'Form Constant Byte or some such, and it is used to 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, directly using the constants I had defined earlier:
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. Anyway, we turn a digit on, then we pause for a bit so the human eye can register it."

"And get your minds out of the gutter, guys, BRA really 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 mnemonic up."

"You suppose right. Apparently more than one. I do not defend them. In a little bit, I'll show you how to use a macro definition 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, using the equates in the table itself:
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 TLCUP.OR.BLCUP ; E
NF EQU VBAR.OR.TLCUP ; F
*
SEGTBL
    FCB N0 ; $EE 1110 1110
    FCB N1 ; $22 0010 0010
    FCB N2 ; $D6 1101 0110
    FCB N3 ; $76 0111 0110
    FCB N4 ; $3A 0011 1010
    FCB N5 ; $7C 0111 1100
    FCB N6 ; $FC 1111 1100
    FCB N7 ; $26 0010 0110
    FCB N8 ; $FE 1111 1110
    FCB N9 ; $7E 0111 1110
    FCB NA ; $EE 1110 1110
    FCB NB ; $F8 1111 1000
    FCB NC ; $D0 1101 0000
    FCB ND ; $F2 1111 0010
    FCB NE ; $DC 1101 1100
    FCB NF ; $9C 1001 1100
Then she modified the test code to use her new equates:
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 this time.


I think everyone cheered.

"But I have a question."

"Yeah?"

"I don't think my code is 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 for me to see.

"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.

Mike did not join in the circus. 

"Back to work," Julia said.

I continued. "So now we need to try actually using the table. We'll use the X register to pick the pattern to display:"
    ORG $40 ; VARIABLES
PAUSER RMB 1
    ORG ROM ; CODE
PAUSE
    CLR PAUSER
PAUSELP
    DEC PAUSER
    BNE PAUSELP
*
START
    LDA #$FE
    STA ANODES
    LDX #1
    SEC
DISPLP
    LSL 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. 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 in memory here, and DEC decrements it by 1, so it's much the same as using X for the idle count, just slower.

"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 we load the accumulator.

"With a 0 in X, the argument 'SEGTBL,X' points to the bit pattern to display a zero. With a 1 in X, it points to the bit pattern to display a one. And so forth."

I stopped to diagram it on the chalkboard:

SEGTBL,X
(@SEGTBL+X)

SEGTBL+0:11101110(N0=$EE)
(X=1)=>SEGTBL+1:00100010(N1=$22)

SEGTBL+2:11010110(N2=$D6)

SEGTBL+3:01110110(N3=$76)

SEGTBL+4:00111010(N4=$3A)

SEGTBL+5:01111100(N5=$7C)

SEGTBL+6:11111100(N6=$FC)

SEGTBL+7:00100110(N7=$26)

SEGTBL+8:11111110(N8=$FE)

SEGTBL+9:01111110(N9=$7E)

SEGTBL+A:11101110(NA=$EE)

SEGTBL+B:11111000(NB=$F8)

SEGTBL+C:11010000(NC=$D0)

SEGTBL+D:11110010(ND=$F2)

SEGTBL+E:11011100(NE=$DC)

SEGTBL+F:10011100(NF=$9C)

"So we start with X equal to 1, then count X up with INC each time through the loop, after we display the number in that digit for a fraction of a second.

"We can only display seven numbers, so we use CMP to CoMPare X to 8, and BNE Branches back to do another as long as X is Not Equal to 8 at that point in the loop."

I looked at Julia, and she nodded hesitantly.

"I think it sort of makes sense. Should we let someone else do the programming this time?"

Freddie volunteered, so Julia traded places with her to let her take a turn typing and burning, but we still used Julia's circuit so the wiring would be right. By this time, Julia's 68705 was erased and ready to use, so she used it, and this demonstration produced the numbers 1 through 7 on the displays.

When the test proved successful, Freddie returned to helping take notes.

Mark and Jeff were keeping track of how long each MCU was in the eraser.

(As I write this, I don't have hardware to make sure I'm not forgetting something, but the program should look something like what I'm giving here.)

"Anybody who's not comfortable with all of that, try out some of your own variations later. For now we need to write the real display code. Bob, Jennifer, are you up to picking up from here, to give everyone a break from me?"

Bob looked questioningly at Jennifer, and they stood, hesitantly.

Jennifer asked, "I guess we need a variable to hold the number, and a routine to convert from binary to hexadecimal?"

I thought carefully how far I wanted to push them, and actually stopped just long enough to pray for help, before responding with, "I wonder how much time we'll have to do conversions during the interrupt routines."

"Not much?" Bob asked.

Doctor Brown spoke up. "Before worrying about that, let's see what you would do."

I decided I agreed with Doctor Brown. "Go with what you have in mind and see how it works. I need to go deliver newspapers pretty soon."

They took over, and I sat down next to Julia.

She took my hand under the lab table and whispered, "This is hard!"

"You're not the only one who thinks so," I whispered back.

"Are we going to need to do decimal numbers?" Jennifer asked from the chalkboard.

"Somebody might, but, for now, let's just do hexadecimal," I suggested

Bob and Jennifer took separate panes of the chalkboard and both started writing:
    ORG $40
WAITCT RMB 1 ; IDLE COUNTER
CMDOUT RMB 1 ; CMD to DSP
BYTOUT RMB 1 ; BYTE to DISP
ADROUT RMB 2 ; ADR TO DISP
*
    ORG $80
* HI BIT DP
* CLOCKWISE FROM TOP
* LO BIT MIDDLE SEG
SEGTBL
    FCB $7E ; 0 0111 1110
    FCB $30 ; 1 0011 0000
    FCB $6D ; 2 0110 1101
    FCB $79 ; 3 0111 1001
    FCB $33 ; 4 0011 0011
    FCB $5B ; 5 0101 1011
    FCB $5F ; 6 0101 1111
    FCB $70 ; 7 0111 0000
    FCB $7F ; 8 0111 1111
    FCB $7B ; 9 0111 1011
    FCB $77 ; A 0111 0111
    FCB $1F ; b 0001 1111
    FCB $3D ; d 0011 1101
    FCB $0D ; c 0000 1101
    FCB $4F ; E 0100 1111
    FCB $47 ; F 0100 0111
*
*
BITTBL
    FCB 1
    FCB 2
    FCB 4
    FCB 8
    FCB $10
    FCB $20
    FCB $40
    FCB $80
*
DSPCMD
    LDA CMDOUT
GTXNIB
    ANDA  #$0F
    TAX
    LDA SEGTBL,X
    RTS
*
DSPBYT
* HI NIB
    LDA BYTOUT
    LSRA
    LSRA
    LSRA
    LSRA
    BSR GTXNIB
    STA CATHOD
    LDX #5
    LDA BITTBL,X
    STA ANODE
* LO NIB
    LDA BYTOUT
    BSR GTXNIB
    BSR WAIT
    STA CATHOD
    LDX #4
    LDA BITTBL,X
    STA ANODE
    BSR WAIT
    RTS
*
DSPADR
*WAIT
    CLR WAITCT
WAIT0
    INC WAITCT
    BNE WAIT0
    RTS
*
INIT
* INIT PORTS
START
    LDA #$0C
    STA CMDOUT
*    BSR DSPCMD
    LDA #$5A
    STA BYTOUT
    BSR DSPBYT
    LDA #$10
    STA ADROUT
    LDA #$00
    STA ADROUT+1
*     BSR DSPADR
    BRA START
*
    ORG $1FFE
    FDB INIT
    END
(Yes, I'm fudging a little, not showing the initialization code.)

When they got to this point, Bob and Jennifer both put their chalk down and turned around, and Bob said, "Filling in the two undefined display routines feels awkward, and it's going to be a lot of modifying code as we copy, which is an easy place to make mistakes."

Doctor Brown spoke up again. "Let's go ahead and walk us through that and test it, and see if we get any good ideas while we're typing and testing."

Jennifer pointed out, "Our segments are wired differently from Joe's and Julia's."

I commented, "I think your wiring makes it a bit easier to visualize the connection between bits and display segments than the wiring I came up with for Julia."

Julia snickered and poked me in the ribs.

"Theirs does follow a more common pattern," Mike pointed out. "Mine uses the same as theirs."

Tanya asked, "Is WAIT a legal label?"

"Labels and op-code mnemonics are in a different symbol space in the assembler, so it's okay," I explained. "Might confuse humans, though."

"Maybe we should use WAITLP like you do," Bob continued. "Other than the wiring differences, we're just following the same program flow pattern you've been following. All we've added is splitting up the byte into four-bit halves, and shifting things into place, and masking the high bits off so the array reference into the table stays in the table."

Jennifer added, "The LSR instruction does a logical shift right, meaning it's dividing by two but ignoring the sign. It fills the top bit with a zero. The AND instruction masks off the top byte, for when you do the lookup without shifting first."

"I'm doing something completely different than that," Mike asserted.

"When Bob and Jennifer have tested theirs, how about you taking a turn, Mike?" I suggested.

He seemed a little surprised that I suggested it, but agreed.

And I excused myself to go deliver newspapers. Before I left, I mumbled something to Julia about hoping Mike had jumped ahead to just storing the segments in a display buffer, but she just shrugged her shoulders.

"Sorry, you've lost me again. Tell me what you mean when you get back."

By the time I got back, Mike was describing his first step.

Julia gave me an update in a low voice. "Bob and Jennifer got theirs working, but we all helped. Torrence noticed that their bit table was inverted before they burned their first program in, and the fix's on the chalkboard."

The corrected bit table looked like this:
BITTBL
    FCB $FE
    FCB $FD
    FCB $FB
    FCB $F7
    FCB $EF
    FCB $DF
    FCB $BF
    FCB $7F
"They had a typing mistake bug, too, and Doctor Brown showed us how to play computer and do a group walk-through to find it."

"Valuable experience."

"Helped me a lot."

"Let's see what Mike's got."

Mike was describing how he planned to test his understanding of the built-in hardware timer by using it to interrupt the CPU so it could make the segments flash between 1 and E at a fairly precise one second rate. (Again, I'm fudging a little, not actually giving you his initialization code. Init code is easy to get wrong if you don't test, and I can't test. It's also fairly straightforward in cases such as this, if you can get the hardware and are inclined to try it yourself.)
    ORG $40
LONGP RMB 1
    ORG $100
INIT
* SET UP PORTS
* SET TIMER PRESCALE TO 64
* SET TIMER COUNT TO 125
    LDA #125
    STA LONGP
    LDA #$FE
    STA ANODE
    LDA #30 ; 1
    STA CATHOD
    WAIT
TIMINT
    BCLR TIMCR7 ; INT FLAG
    DEC LONGP
    BNE TIMDUN
    LDA #125
    STA LONGP
    LDA CATHOD
    XORA #$FF ; 1 INVERTS TO E
    STA CATHOD
TIMDUN
    RTI
*
    ORG $1FF6
    FDB TIMINT; CMOS MODE TIMER INT
    FDB TIMINT ; ORDINARY TIMER INT
    FDB INIT ; INTERRUPT
    FDB INIT ; SWI
    FDB INIT ; $1FFF RESET
    END
"Using the timer prescaler value of 64 and the timer count of 125, then counting a hundred twenty-five interrupts, we should get a count of 125 times 125 times 64, which is a million. So if the CPU clock is exactly one meghertz, this should be exactly a one second flash rate.

"WAIT clears the CPU's interrupt mask before it puts the CPU in a WAIT state, but lets the timer keep running.

"The exclusive-or with hex FF instruction toggles all the bits in the accumulator, which should show E and the decimal point. And we can see if the BCLR bit clear instruction works and clears the timer interrupt flag."

After Theresa, another of the more quiet students, typed the code in and burned it, Mike's test worked as advertised, and Mike proceeded with his next step.

"What I'm going to do is have a buffer for the digits to display. I'll just have have the timer generate a one millisecond interval interrupt, and it will sequence through displaying each digit for a millisecond. I'm going to steal Bob and Jennifer's code for the bit table and the segment table, if they don't mind."

"No problemo."

And he proceeded to show his code:

    ORG $40
CURDIG RMB 1 ; 1-7
DIGBUF RMB 7 ; 7 DISPLAYS
*
ORG $100
* BIT AND SEGMENT TABLES
TIMINT
    BCLR TIMCR7
    LDA CURDIG
    ANDA #07 ; SAFE MASKING
    STA CURDIG
    TAX
    LDA BITTBL,X
    STA ANODE
    LDX CURDIG
    LDA DIGBUF,X
    ANDA #$0F ; SAFE MASKING
    TAX
    LDA SEGTBL,X
    STA CATHOD
    RTI
*
START
    LDA #5
    STA DIGBUF
    LDA #3
    STA DIGBUF+1
    LDA #7
    STA DIGBUF+2
    LDA #7
    STA DIGBUF+3
    LDA #3
    STA DIGBUF+4
    LDA #8
    STA DIGBUF+5
    LDA #0
    STA DIGBUF+6
    WAIT
Burning the code in produced close to the desired results, but not quite, and we proceeded, as a group, to debug it, and shortly had it working.

It was getting close to dinner time, so I asked everyone, "Should I offer some wrap-up comments about interrupt routines now, or should we go home in a euphoria?"

Mike looked at me in resignation. "Hit me with it."

I laughed and looked at Doctor Brown, and he said, "Just keep it short."

So I turned to the students. "We've done some really good work today, keeping the steps small and working together to fix bugs. Doctor Brown will tell us again why bugs are good tomorrow, I think. A couple or three things to think about tonight -- Is it better to clear the timer interrupt flag at the front of the interrupt routine or the end? What could we do with Mike's code to keep the digits available to look at, but make the interrupt routine itself shorter? And how do we fit the keyboard code into the framework Mike has given us?"

I paused, deliberately, and then added, "By the way, I couldn't have paid Mike, Bob, or Jennifer to give us better code to work with."

*****

Julia leaned against my shoulder across the transmission well, looking out the window at the twilit sky.

"Either you aren't the jealous kind or you have supreme confidence about my feelings for you."

"I trust you to figure out what you want." I lifted my hand from the gearshift and gave her a quick hug.

"Supremely confident."

I chuckled. "And if I disagree, I'm going to be in a world of hurt."

She turned her head and bit my shoulder. Gently.

*****

After dinner and home evening, we sang my recital song in duet, English first, then Julia following along with my pronunciation as I sang in Japanese for a verse. I wrote out the Romanization, and we sang the Japanese together. (I've mentioned Latinization before. In Japanese, it's called ローマ字 -- Rōmaji -- or Romanization.) Then we sat down and worked on homework. After homework, Julia looking over my shoulder while I worked through the TMS 9940 documentation.

"I'm not seeing it."

"What?

"The description of the instruction to call a subroutine. I found the return instruction, but not the call, and I want to get a look at it."

Julia gave me a blank look.

"It's actually a full context switch on this processor, generating a linked list of contexts instead of a straight stack."

 She raised her hands with a smile that said, "I have no idea what you are talking about."

I grinned back. "Just pretend like your listening to something that makes sense."

"Hah."

"I'm going to pretend I'm explaining it to you, but I'm explaining it to myself."

"Uh, huh." She snickered.

"The TMS 9900 has a really unusual register scheme. All the computational registers are actually in memory, pointed to by the working set register."

"Last week, I would have been lost when you said scheme and register."

"What's a register?"

"Registers are where the poor little guy does all those calculations, and RAM is where she stores results."

"Very good. The 9900 uses RAM for registers. And it calls the RAM it uses the context, or working set. And it can keep a link to the previous working set in a memory cell of the current context."

"I can pretend I might understand that someday."

We both laughed. "Thank you. Now you have to know where your registers are, so the 9900 has one real register that points to the working set. It's called WP."

"Working set pointer?"

"Careful. You might actually understand this."

"Hah."

"You also have to know where the instructions are, so the 9900 has a register for that. It's called IP."

"Instruction pointer."

"Nice. Anyway, when you call a new procedure or routine, you usually want to know how to get back to where you were. That's what the link to the previous context working set is."

"I could see that. Someday."

"So the 9900's call instruction holds onto the old IP and WP, loads a new WP to point to a new working set, and stores the old ones in the top of the new working set."

Julia frowned. "You know that almost makes sense."

"Almost. I don't think it's ideal. I haven't mentioned the status register. I think it's the status register. But it saves that, too."

"Now I'm lost again."

"That's okay. The status register is where it remembers such things as whether the last operation resulted in zero or a negative number. I want to see the instruction that sets up the new context frame, so I'm looking for the call instruction, and I can't find it. I can find the return, but not the call. It's called BLWP, for branch and link WP."

I thumbed through the datasheet pages again, with Julia looking over my shoulder again.

"These are jumps?" She said.

"Yeah. Conditional jumps. It's not there."

I thumbed back and forth a bit more.

"Single operand instructions. How many operands does this branch and link, uhm, WP  instruction have?"

"That's actually what I want to find out."

"B for branch."

"Yeah."

"BL."


"Branch and link, but without WP. It's a quick call."

"BLWP," we said in unison.

"Op code 17."

"Where? I don't see seventeen."

"Binary." I pointed to it. "One zero zero zero one."

"Ah. Yeah."

Shortly I was satisfied for the night with what I had learned about the 9940, so I opened up the Forth implementation package and scanne through it.

Julia fell asleep on my shoulder, and I drifted off, as well. Giselle woke us up at 10:30, and I drove her home.

"So, what if I decide to reward you with a kiss?"

We had stopped on her front porch to talk.

"Who am I to turn down a reward?"

It was a nice, sweet reward, giving and getting, but not too much.

Chapter 13.4: Keyboard Decoding

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


Sunday, June 21, 2020

Backup01: 33209: Straits -- Bringing Up Flex

Second version backup of https://joelrees-novels.blogspot.com/2020/06/33209-straits-bringing-up-flex.html.

Chapter 13.0: Straits -- Getting Julia Booted Up

Chapter 13.1: Straits -- Bringing Up Flex


Julia waited patiently while I disappeared down the rabbit hole again.

"So you let those drives do their exercises all night last night, until you got back from delivering your newspapers this morning."

"Yep."

"And they didn't mess up so bad that a retry wouldn't fix it."

"Uh huh."

"Which means now you can load this operating system into memory, right?"

"Yeah, now we can be fairly confident that we can load the OS into RAM with these disk drives."

"But even if you write a program to read the operating system into memory in the place it's supposed to go, it's not going to run?"

"Maybe I'm wrong and it might run after all. But it looks like it will either run off a cliff when it calls I/O routines that it expects to be there but aren't, or it will go looking for those routines, not find them, and give up. And I'm not sure how we'll know which is happening, beyond that it doesn't do what we expect it to."

"That's not very friendly."

"I'm sure they don't have manpower to handle every hardware variation guys like me could dream up. And that means I get to try to figure it out." I continued scanning the manuals in my lap, and Julia didn't say anything more for a moment.

"Oh, I think I found something here."

"What?"

"Hang on." I scanned the pages I had open again. "This entry shows an area where the standard disk drivers are, and there are vectors that they can be called through at the beginning. If my drivers imitate drivers for Western Digital controllers closely enough, I should be able to overwrite those vectors with jumps to my own code."

"I'm lost."

"Vectors are like pointers to where the drivers are actually stored. These are jump vectors, so programs call them and the jump instruction sends them on to the actual driver routines."

"Oh-kay. So you have to write new drivers and put them where the existing drivers are?"

"I'm thinking I'll put them outside the memory Flex uses and overwrite just the vectors that are there for linking through. That should minimize potential for damage."

"As if I knew anything about the question I just asked, much less what you just said."

She laughed, and I leaned over to where she sat on the bench seat and gave her a hug.

"It's sure nice to have someone to talk with while I'm down in that rabbit hole. I'll show you those vectors when I get things put together and running."

"I'm looking forward to it."

We both chuckled at the mixed irony in her tone.

"I guess my first project is to do what the manual suggests and copy the disks they sent me, so that, if I mess something up, we have a backup."

"Good idea. How are you going to do that?"

"The test routines should help. But it's a little scary. I'm worried that my drives will malfunction."

"Isn't there some way to prevent the originals from being copied onto?"

I showed her the write protect notch on the floppy cover and the strips of write-protect tape tabs from the box of floppies I'd bought in Austin. "This is backwards of good engineering, but if I cover this notch with this tape it should protect the disk -- if the drive electronics function correctly."

She smirked. "Doubt your own work?"

"Yeah. I haven't actually implemented the protection in the hardware."

"Well, maybe you should. But why is it backwards?"

"Uhm, I guess maybe it depends on how you look at things, but I'd rather it be protected if the tape falls off."

"I guess that makes sense."

"You know, some computers implement write-protect in the driver software instead of the controller hardware, so you just can change the drivers to make your drives work the way you prefer. But I think you're right, I should add the write-protect circuitry."

I dug up my diagrams, and drew in some additional logic. "If I add a few gates here, and connect it to the controller I/O here, I can make the controller respect the write-protect notch by default in the hardware, but allow the driver to invert the sense."

"Make it complicated? Why not just do it normal and keep it simple?"

"Keep it simple. Didja know that's actually an engineering principle?"

"Engineering principle?" She gave me a lopsided smile of curiosity.

"It has  an acronym: K-I-S-S."

"Okay." She leaned over and gave me a peck on the lips. "And that's three times, now."

I grinned. "And I'm not complaining."

"So -- what's the second 'S'?"

I looked at the floor and coughed. "Erm, you have to understand, it's a special bit of engineering jargon. It sounds a little, uhm, stupid, but it has special meaning."

"Okay. So tell me."

"It's 'stupid'."

"You said that."

"Quote stupid un-quote."

"Oh." Now she gave me a sharp look.

"It means, not trying to be too smart. Trying to be too smart makes things not simple."

"Uh-huh."

"No, seriously."

"I believe you." She laughed. "But I think I'll remember this one."

"Heh."

"So, the write-protect circuit, right? How do you keep it simple?"

"Well, I already have the sensor hooked into an input bit of the controller's MCU, but the controller ignores it for now. Instead of adding hardware, I could do this in the controller's firmware, and that way I wouldn't be depending on the driver software in the computer for protection."

"Does that mean re-programming the controller?"

"Yeah. Hmm. While I'm in it, I could add a switch to allow it to switch between FM and MFM on the fly."

Julia watched and asked questions, and listened to my answers, while I put a 68701 in the EPROM eraser, loaded the floppy controller source code from tape, added the code to handle write-protect and the FM/MFM switch, and programmed the new controller.

For a test, I wrote a quick routine to duplicate and check a single-sided disk in the second drive to the first drive and used the routine to duplicate one of my test floppies. That worked, so I tried to use my disk drives to duplicate the OS disk.

"Error."

"What kind of error?"

"It won't read TSC's floppy."

We both sat and thought for a minute.

"Can you do it with Giselle's computer?"

"Worth a try."

We went in to Giselle's room, and she agreed to set the project she was working on aside long enough to let me try to make a copy. I attached one of my drives to her Color Computer controller as a second drive and wrote a quick program in EDTASM+, then inserted the disks.

"Error."

"Could the disk be bad?"

"Let me look up the error code." I thumbed through Giselle's manual. "Format error. But I'm reading it in raw format, so that shouldn't make a difference."

I thanked Giselle, and we took our stuff back to my room.

"I guess I'm going to have to wait 'til Monday and give them a call."

"TSC?"

"Yeah."

"Nobody in the office today?"

I gave her a quizzical look. "Might be. Worth a try. It's even not the most expensive time to call. But let me make sure what I'm going to ask before we do."

And I dug back into the manuals.

"Oh, look at this."

"What?"

"The disk they sent is FM."

Julia looked pointedly at my stereo tuner.

"You've been waiting a whole week to say that." I laughed, and she laughed.

"Without words. But not the same FM, I guess? And there's no AM?"

"AM. The bit clock is the carrier, so 0 is absence of clock and 1 is presence. Ick."

I reached for some paper, but she put her hand on mine and stopped me.

"I was just joking about the AM."

"Okay, okay, I'll see if I can puzzle that one out later."

The changes to duplicate the FM disk were quick, and the copy proceeded without further error. "And that was verify-after-write, so it should be gold."

"So -- my suggestion to call wasn't necessary?"

I wrinkled my brow and leaned over and gave her a peck on the lips, but stayed close. "It was part of the conversation, and kept me from getting stalled." My eyes searched hers.

She returned my searching look. "Just to be safe, make another?"

"Good idea." I sat back, with some regrets, and made the second copy, then copied the second of the two OS disks TSC had sent, the utilities disk, "Just for good measure."

We shared a hug.

"Okay, now I need to write the drivers."

Because I'd been constructing the controllers to emulate the Western Digital controllers, the basic drivers were a straightforward extract from my test code. And I showed Julia where the vectors were and how I'd over-write them.

"And now the throw-away loader."

"Throw-away?"

"If it works, I'll only use it once to load Flex into memory without using the drivers. Then I'll load my drivers from tape and overwrite the driver vectors, and call the OS's cold boot routine. Then we'll be running Flex, and I'll use Flex itself to make a bootable disk that contains Flex with my drivers."

"Finally running the OS?"

"Yeah. Exciting, huh? I'll probably base the boot loader on the throwaway, so it won't be completely throwaway. But since the first one's throw-away, I can write it to run anywhere. Maybe I should just put it after my drivers anyway, so I can keep the drivers and the loader together."

I was in good form, the loader ran the first time, and I was able to boot Flex. Flex's prompt came up on the screen.
FLEX  2.1            
+++                      
I turned to Julia with a hand outstretched for a slap of the palm, but she wrapped her arms around me and gave me a しっかりした kiss.
Shikkari. 
When I was a new missionary, I hated that word. It seemed to mean whatever fit the speaker's sense of what was right, and it seemed to ignore the right of the person being spoken to to have any sense.
しっかりした体格 shikkari shita taikaku -- proper build/physique (solid build)
しっかりしなさい! Shikkari shinasai! -- Do it right! (Hold it together! or Hang in there!)
Righteous kiss? Proper kiss? Solid kiss? Who has a right to judge a kiss? It's not a sporting event.

Okay, I liked it. And it wasn't just a quick buss. Somehow, "shikkari" fits.

"Ahem," Giselle's voice interrupted. "I hate to interrupt, but, uhm, the missionaries are here?"

We broke apart and turned in unison to give Giselle a guilty look.

She smirked. "Well, it's none of my business, but, since the missionaries are here, maybe you two should save that."

We both stood up a little unsteadily, left the computer at the Flex prompt, and went to meet the missionaries.

*****

The discussion we had with the missionaries was pretty straightforward. At the time, the first lesson in most of the culturally Christian world was an explanation of the vision Joseph Smith Jr. had when he was fourteen, somewhat more complete than I had given her to that point. I will mention here that the interested reader will find it in The Pearl of Great Price, "Joseph Smith -- History", but otherwise leave it out of this story.

Giselle joined the discussion, and, after the discussion, I invited the missionaries to stay for lunch. But they were on their way to see Julia's family, and Mrs. Cisneros had invited them for lunch there.

Julia and Giselle and I ate lunch together, just the three of us.

"They're awfully young." Julia thoughtfully arranged salad on a second slice of bread spread with peanut butter.

She hadn't even commented when I suggested one of our family's mainstay quick lunches. Well, she did comment on the crunchy, no-sugar, no-additive peanut butter we bought in bulk from the co-op. She said she liked being able to taste the peanuts.

"Only a year younger than you and Joe are."

"Okay, they seem young. That wasn't really all that persuasive a presentation."

Giselle reached out and took Julia's hand, and gave her a searching look. "We aren't sending missionaries out to convert the whole world."

"No?"

"No. We are sending them out to teach people who are ready to listen."

"Oh."

*****

On the way to the lab, Julia reached over to where my hand rested on the shift lever, and hesitantly, tentatively covered my hand with hers.

"Mmm?"

"Uhm," she started hesitantly.

"Mmmm?"

"What if I'm not ready to listen?"

I turned my hand over and gave hers a squeeze. "Whether you join the church and whether you and I end up getting together are two separate questions." Then I had to turn my hand back over to shift gears.

She kept her hand over the back of mine, but was silent until we turned right on University Avenue.

"But if I don't convert, then ..."

I waited for her to complete the sentence, but she didn't.

"We'll ask God what to do then. The missionaries have six discussions they present. When we get through those, you'll have the basic understanding of what to do if you're ready. Until then, don't worry about it."

"Will you still like me?"

"Too late to ask that question. I already do."

"I mean, enough to ..."

"Ask you to marry me anyway?"

We were both silent until I parked the car in the west parking lot, and we started unloading our stuff from the back of the Colt.

"Well?" she asked.

I put the Micro Chroma 68 back down in the bed of the compact station wagon, took her in my arms, and we stood face to face, lost in each other's eyes. I nuzzled her nose, and she giggled. Then I gave her a shikkari shita kiss.

I suppose it was at least a half minute later when we heard Mike say, in a voice dripping with sarcasm, "Well if it isn't two love-birds engaged in a little PDA."

I felt Julia start, and stiffen, but I kept my arms around her, and she relaxed before turning to say with a smile, "Yeah. I guess it is."

Pat and George were behind Mike, and neither of them seemed comfortable. Mike looked openly angry, but he seemed to be trying to keep his anger in check. He shook his head and walked past us with no further comment, followed by Pat and George, neither of whom said anything.

"Whenever you're ready, tell me about Mike."

Julia leaned into me and buried her face against my shoulder, and mumbled.

"I didn't understand any of what you just said, but if you're not ready, I'll wait."

She leaned back and held my gaze with her eyes, letting me see her fear. "I guess it wouldn't be fair to you."

I said, as gently as I could, "It's your choice when to tell me. I won't act on information I don't have."

I thought I saw her lower lip quiver before she pulled her face into a tight, wrinkled, hesitant smile.

"We dated really seriously in high school. Dad wasn't happy, but Mike and I promised ourselves to each other. Then Mike seemed to think promises meant more than I thought they did, and I broke it off."

"I can see him not being happy with that."

"He blamed my faith, and I told him point-blank that I would not accept that from him. We could still be friends, but I wasn't going to trust him like that any more."

I smiled and nodded and gave her what I hoped was a reassuring caress.

"He tried to take me too far. I can't let that happen. Not before marriage."

I nodded again, still searching her eyes. After a moment, I guessed, "But there are still some leftover feelings."

She looked down. "Yes, there are."

"He's a good-looking guy."

"You think so?"

"Absolutely. Watch which of the women in our group are watching him today in the lab."

"What about ...?"

"Of course, looks aren't everything. Still, if he's behaved decently towards you since then, I would be lying to deny that it's another point in his favor."

She still hesitated, then seemed to get courage to be more plain. "What about his race?"

"African, I suppose."

"You don't seem to hold that against him, either."

"Cultural issues are much more important than race. If I'm not going to hold religious culture as an issue between you and me, I would be somewhat lacking to hold race, whatever that is, as an issue with anybody."

"You're not jealous?"

"God only knows what the future holds for him, for me, and for you. At this point, I can see several paths ahead. If God tells you and me to get together, and if you are agreed, I'm game. If you aren't, or if God says no, we'll figure that out when it's time."

She wrapped herself around me, and I nuzzled the back of her neck.

"But let's get to the lab before anybody can make up any really egregious rumors about us."

We both giggled as we grabbed our stuff.

*****

Neither Pat nor George, nor Mike, had mentioned the scene in the parking lot when we got to the lab, and we just set the computer up and got started. The lab session turned out to be quite productive.

Mark and Jeff helped Suzanne and Winston with their mainboards while everyone else discussed the keyboard/trainers. I put another diagram up on the chalkboard to help the discussion.



"Those buffers may be internal to the MCU," I commented as I finished the diagram.

Since I hadn't saved an OS image with a complete boot loader, I had to stage load the OS again using the throw-away loader. But it was just an extra couple of steps, and several in the group were very interested in watching me go through the steps.

"I use the TV-BUG L command to load the drivers into place from tape." The code was short, so even though I had saved it to slow tape, it loaded quickly. "My throw-away loader is with the drivers, so I use the TV-BUG G command to jump to it, and it loads the Flex OS, then returns to the monitor so we can check it using the E command. E for examine, I guess."

Wallace complained, "That's just a bunch of hex numbers."

"Well, it's good enough to check Flex's driver vectors and overwrite them with the M command." I did so. "M for modify. And now we can use the G command again to go jump through Flex's cold boot vector and boot Flex."

Flex booted, and we got the prompt again.
FLEX  2.1            
+++                      
With the Micro Chroma 68 running Flex, I was able to load and run Motorola's cross assembler for the 6805. That allowed us to assemble and test code, so several of the students started writing assembly language code the old-fashioned way, with pencil and paper. There were several comments about being glad that they wouldn't have to hand-assemble their programs now, but others noted that we all had to share my computer for a while.

Everybody seemed focused on using the 6805's fancy bit I/O instructions.

Bob and Jennifer were working together, and Jennifer typed in their code while Bob read it to her and checked it over her shoulder, then assembled it and burned it into a 68705 to test. They got their expected output, but then they were stuck on how to generalize their code without making multiple copies of blocks of code, changing each copy a little at a time.

"This isn't just tedious, it's going to be error-prone, isn't it?" Bob commented, Jennifer nodding her head in agreement.

Dr. Brown and I agreed.

We took a look at several other attempts at decoding the keyboard, but they also ran into the same problem of needing to use copy/paste techniques to deal with the whole keyboard matrix.

Neither Dr. Brown nor I seemed inclined to point them to a different approach, but I had a different suggestion.

"Tell you what. Let's take a break from the keyboard decoding and look at getting real output on the LEDs."

"Real output?" Kyle asked.

"So far, all we are doing is lighting up segments. Let's make routines we can call to put actual multi-digit numbers on those LEDs."

There were some complaints, but most of the group shifted gears with me. By this time, Suzanne and Winston's mainboards were giving output, and they joined us, too.

I redrew the display block diagram by itself.


"Is everyone clear on the idea that we will be enabling, or strobing, one digit at a time?"

Sheryl raised her hand. "No?"

Bob stood up and went to the chalkboard. Pointing to the lines coming out of the left buffer, he said, "All these lines -- wires -- are shared -- connected to each display." Then, pointing to the lines connecting each display to the buffer along the bottom. "These lines are not shared. We have to demux them somehow."

"Yep," I agreed. "Maybe I should draw a diagram of one of the digit elements."


"No buffers, no latches, just light emitting diodes in those seven segment LEDs."

Sheryl's forehead wrinkled. "That's common anode, I guess."

"Right."

"And if we have seven banks of those with cathodes connected in parallel, ...," she thought out loud.

"Ah!" Freddie exclaimed. "You have to activate the anode of each digit separately, or they'll all show the same pattern."

There was tentative agreement among the electronics students, but the data processing group and Julia were still lost.

Except Mike wasn't.

Mike stood up at the chalkboard where Bob and I were, and started sketching out the segment matrix. When Bob saw what he was doing, he started helping.

I also raised chalk, but Mike pushed my hand away. "Too many cooks," he grumbled.

I grinned and stepped back. Then I looked over at Julia with my eyebrows raised, but she wasn't looking at us. She was checking the reactions of the other women in the room.


"Nicely done," I said when they were done, and started to reach out for a slap of the palms, but it didn't look like Mike was going to respond to that. So I gave them a thumbs-up, and Mike gave me a dirty look.

Bob looked at me questioningly, so I gave him and Mike a nod, and they took over the explanation. When they were done, everyone was satisfied that activating the strobe for all digits at once would put the same pattern on every digit, and that it might work to strobe them one at a time. But there was considerable concern about flicker.

Dr. Brown got out his TI programmable calculator with LED readout and had Wallace turn out the lights. then he walked around the room waving the calculator so that everyone could see the flicker. Many of the students commented on having noticed the flicker. I think it was Tanya who related it to TV flicker.

I reminded them of the TV refresh rate, and from there we started calculating the refresh rate for the seven segment displays. It was agreed that scanning the entire set of digits thirty times a second should present a somewhat stable display, which would mean each digit should get a seventh of that interval, or 1/210 of a second -- between four and five milliseconds.

With the lights back on, we talked about setting the 6805's timer to interrupt at that rate, and pretty soon several groups were putting code together. By the time Dr. Brown suggested we shut down for the day and go home, all the groups were able to display arbitrary digits on their displays, and two of the groups were able to output bytes in hexadecimal.

Some of the students were curious about brightness, and I tried to venture into duty cycle, but Bob suggested we'd had enough for a day, and I had to agree.

*****

"Are you up for some singing tonight?"

"What?" Julia was lost in thought on the road home.

"I need to practice for my recital."

"Recital," she said absently. "You were right. I think every women in that group has some kind of a crush on Mike."

"Some of the guys, too."

"I'm not going to pretend to understand that. What's this about a recital?"

"The singer's diction course I'm taking."

"Oh, that. You haven't been practicing."

"Not enough. I probably need to practice a half hour a day for the next two weeks."

"I love to sing."

"I know."

"And I can play the piano for you, too."

And that was what we did that night. Julia called her family, and they came over and we had dinner together, played some rounds of Pit and Uno, and had a two-family sing-along, leaving computers and other difficult questions behind for an evening.

Julia and Mom played some four-handed music. And they let me squeeze in some practice. We sang the hymn, "O God, the Enternal Father" in English and Spanish before I practiced it in Japanese.

(Just as a reminder, Julia is a composite of several of the women I knew in College. If this story went at the pace of my real life, it would be turgid, and I'm sure not nearly as interesting to read about. Also, if the fantasy version of me waited for his first kiss until Helen broke my heart in the real world, he would also likely be waiting another four years before digging into computers for real. Events around me would not allow that, for the purpose of this story.)

*****

After Julia gave me a good night hug and went home with her family, Denny called.

"You up for a trip here next Friday?"

"What's up?

"Management wants a bit of your time without the distractions. They wanted to fly you in, but I pointed out that it would be just as fast for you to drive as to catch a flight, and you'd probably want to visit the surplus shop on Saturday. They said they could pay mileage instead of plane fare, if you can make it by five or six."

"Hmm. When do I need to have an answer?"

"Monday morning."


Chapter 13.2: what?

[Second version backup at https://joel-rees-economics.blogspot.com/2020/06/bk01-33209-straits-bringing-up-flex.html.
Original backed up at https://joel-rees-economics.blogspot.com/2020/06/bk-33209-straits-bringing-up-flex.html.
Some more notes at https://joel-rees-economics.blogspot.com/2020/06/notes-33209-straits-bringing-up-flex.html.]