about Crimson Editor

Dec 16, 2006 27 Replies

That's something most current 'software engineers' don't even know about! (and perhaps why their text editors don't provide such services).

For the record, I do know about such things ;)

Cheers

PeteS

My programs are paged by design, heavily commented (with background equations, memory maps, and chatty notes and asides), have a table of contents (generated by my listing post-processor) and are works of art. They work, too.

John

I do the same, not merely because it's nice for whoever may have to do something to that code later, but for myself in self defense; Earlier in my career I often found myself wondering 'WTF did I do that for?' when I had to do updates after a period of months on something else ;)

Cheers

PeteS

I think the real test of a programming methodology is to come back to a project after a year or two and see how long it takes to make a change. If you can zero in on the page of code where the issue is, and if any interactions with other sections are obvious (referably stated in plain english), and if what's really happening is obvious, then it's good code.

Too much code is write-only, and must be literally and laboriously "decoded" to try to understand it; "Code" indeed! So changes and bug fixes are based on partial understandings and "try this and see if it works" experiments. At some point, fixing a bug has a greater than unity chance of creating another bug.

.SBTTL . TEEPEE : LOAD THE DPLL TRIM DAC

; THIS IS CALLED PERIODICALLY TO REFRESH THE TEMPCO DAC. ; THE DAC PULLS THE LC OSCILLATOR ABOUT +1 PPM/LSB, ; AND 'TEMPC' IS SCALED AS K * 10

; WE'LL DO TRIMDAC = (TEMPC - 350) * KTCFAC / 32

; SO TO FIX A +10 PPM/K TC, THE CAL FACTOR NEEDED IS -32

; THE DAC PULL RANGE IS ABOUT +-2000 PPM, SO WE CAN FIX A 50 PPM ; TEMPCO OVER A +-40K RANGE. SINCE THE OSCILLATOR IS ALREADY TWEAKED ; WITH NTC CAPACITORS, ITS TEMPCO SHOULD BE WELL BELOW 50.

TEEPEE: JSR RTEMP.W ; READ THE CURRENT TEMPERATURE

MOVE.W TEMPC.W, D4 ; NAB TEMP, DEGC * 10 SUB.W # 350, D4 ; PIVOT ABOUT 35 C MULS.W KTCFAC.W, D4 ; SCALE BY TEMPCO THINGIE, NOW LONG ASR.L # 5, D4 ; /32, OPTIMISTICALLY A WORD AGAIN ADDI.W # 2048, D4 ; CENTER UP THE DAC BPL.S TPAK ; NEGATIVE WOULD BE BAD SO CLR.W D4 ; CLAMP AT ZERO

TPAK: CMPI.W # 4095, D4 ; TOO HIGH IS BAD, TOO BLS.S TPAZ ; SO CLAMP MOVE.W # 4095, D4 ; THERE TOO

TPAZ: MOVE.W D4, TRMDAC.W ; SAVE DAC VALUE FOR REFERENCE ADDI.W # MAXB, D4 ; SELECT DAC B JSR MAXIM.W ; AND LOAD RTS

The .sbttl directive creates an entry in the listing table of contents, which has its own indented, very readable structure. The TOC for this program runs 4 pages.

Hey, I just noticed that there's no need to read the temperature, because another routine that runs just before this one has done it already! That'll save me 50 microseconds at least.

Anybody got any beautiful C code? I bet not.

John

As it happens...

I wrote this when I added support to the ianjtag utility for the Corelis

1149.1 card. The port is much more than this, obviously, but here's a sample of my C code :)

int jtag_init(void * otps) { /* otps not used */ /* initialize the interface */ int libstat = 0; /* make sure we are linked */ unsigned char BoardInfo[200]; /* Results from board query */ int status; /* General purpose status of calls */ char *Info; /* Alias for the string */

Info = &BoardInfo[0]; /* Look for the lib first */

libstat = 0x5555; if(test(libstat)!=libstat) { /* should be equal on return */ fprintf(stderr,"Interface library not responding\\n"); return(-1); } /* reset board */ (short) status = hard_reset( FALSE, /* RS422 */ _3_30 /* Voltage */); if(!status) { fprintf(stderr, "PCI1149 card not found\\n"); return(-1); } memset(Info, 0, 80); Info = get_driver_info(); printf("Driver info returned: \\n%s\\n",Info);

/* set scan clock to 10MHz for now */ set_scan_clk(0, _40MHZ, 0, 1); /* 40 MHz base, no prescaling, divide by 4, ports 1 and 2 */ return(0);

}

Cheers

PeteS

On Sun, 17 Dec 2006 10:47:37 -0800, John Larkin wrote in Msg.

Impossible because you can't write C in all-caps.

Why do you all-caps even the comments? Because it looks more assembly-ish? ;-)

robert

Impossible for a number of reasons, some technical and some cultural.

Because I'm used to it and like the way it looks. And because I print my listings on 11x14 fanfold on a dot-matrix printer. And because I have nobody to please but myself.

Last night (during the many commercials of Lord of the Rings) I

*finished* my big crisis project: 5996 lines of assembly, 122 impeccable pages of listing, realtime as all getout, all uppercase except the HELP text. Damn near 4 weeks of work. And I managed to (barely) finish ahead of my FPGA guy, who messed up some clock domain crossings and has to re-do that this week. He crossed our async clock domains at *9* separate flipflops!

This is the gadget:

formatting link

The guy who wrote the original code left, and his stuff (14 k lines!) was such a mess it was easier to start from scratch than to try to untangle what he did. Software can be like that.

John

On Mon, 18 Dec 2006 08:34:20 -0800, John Larkin wrote in Msg.

Tell me about it. Or rather, don't. I know all about it already. Re-writing can be fun, though, because it continuously shows you how much cleverer you are than the guy who did the original.

robert

Join the Discussion

Have something to add? Share your thoughts — no account required.

Didn't find your answer?

Ask the community — no account required