The Boston Diaries

The ongoing saga of a programmer who doesn't live in Boston, nor does he even like Boston, but yet named his weblog/journal “The Boston Diaries.”

Go figure.

Saturday, January 21, 2012

99 ways to program a hex, Part 13: COLOR COMPUTER BASIC, EASY

I decided to take a break with the C versions for a few days, given that a) I'm hopelessly behind on posting, and b) the next few versions are interesting and I want to make sure I have plenty of time for the write-ups. So I went back to my programming roots, to the first computer I ever owned, a Tandy Color Computer 2, and figured, why not do a hex dump program for it? In its version of BASIC.

One of the rules I set for myself is that the output of each version should match if at all possible, and I'm afraid that this version (and the next one) fall under those weasle words—the output won't be exactly the same. It's not hard to understand why though, when you realize that the text screen of the Color Computer is 32×16. Yes, it's only sixteen lines of 32 characters each. Yeah, this:

00000170: 44 4F 53 20 42 41 53 49 43 20 54 4F 20 52 55 4E DOS BASIC TO RUN
00000180: 2E 0A 31 36 27 0A 32 30 20 50 52 49 4E 54 20 22 ..16'.20 PRINT "
00000190: 49 4E 50 55 54 20 46 49 4C 45 20 4E 41 4D 45 3A INPUT FILE NAME:
000001A0: 22 3B 0A 32 31 20 49 4E 50 55 54 20 46 4E 24 0A ";.21 INPUT FN$.
000001B0: 32 32 20 4F 50 45 4E 22 49 22 2C 23 31 2C 46 4E 22 OPEN"I",#1,FN

ain't gonna fit!

This, however:

0170 444F532042415349 DOS BASI
0178 4320544F2052554E C TO RUN
0180 2E0A3136270A3230 ..16'.20
0188 205052494E542022  PRINT "
0190 494E505554204649 INPUT FI
0198 4C45204E414D453A LE NAME:
01A0 223B0A323120494E ";.21 IN
01A8 50555420464E240A PUT FN$.
01B0 3232204F50454E22 22 OPEN"
01B8 49222C23312C464E I",#1,FN

would. And we'll be going with that.

And I'm presenting the code as it would (or less) appear on the Color Computer, wrapped at 32 columns (more accurate would be a mid-range green background with a really crappy 8×12 pixel font).

1 '*****************************
2 '* COPYRIGHT 2012 SEAN CONNER
3 '* 
4 '* THIS PROGRAM RELEASED UNDER
5 '* THE GNU LICENSE, VERSION 2
6 '* OF THE LICENSE, OR (AT YOUR
7 '* OPTION) ANY LATER VERSION.
8 '*
9 '* SEE THE GNU GENERAL PUBLIC
10 '* LICENCE FOR MORE DETAILS.
11 '***************************
12 '
13 'COLOR COMPUTER BASIC, EASY
14 'REQUIRES EXTENDED AND
15 'DOS BASIC TO RUN.
16'
20 PRINT "INPUT FILE NAME:";
21 INPUT FN$
22 OPEN"I",#1,FN$
23 I=0
24 Y=0
30 FOR S=1TOLOC(2)
31 GET#1,S
32 D$=INPUT#1
100 FOR B = 1 TO 256 STEP 8
101 DD$ = MID$(D$,B,16)
102 I$=HEX$(I)
103 IF LEN(I$)<>4 THEN I$ = MID$
("000",1,4-LEN(I$))+I$
104 H$ = ""
105 A$ = ""
106 FOR C = 1 TO 8
107 B$ = MID$(H$,C,1)
108 IF CHR$(B$)<32 OR CHR$(B$)>1
26 THEN B$="."
109 A$=A$+B$
110 T$=HEX$(B$)
111 IF LEN(T$)=1 THEN T$="0"+T$
112 H$=H$+T$
113 NEXT C
114 PRINTI$;": ";H$;" ";A$
115 I=I+8
116 Y=Y+1
117 IF Y=15 THEN INPUT T$:Y=1
118 NEXT B
119 NEXT S
120 CLOSE#1
130 END

Now, I don't know if the code actually works (unlike the previous twelve versions). I still have my first computer, but I haven't turned it on in years, and in fact, I would have to dig it out of storage, find a TV that worked to hook it up to (for a video display), then type in the program, debug it, then … um … type it in again, since I don't have any easy way of transferring data off the Color Computer (that would require more digging to piles of cables to find the right set of cables and adaptors, going from a 4-pin DIN to USB with some form of null-modem cable thrown in). So in theory the code works, but in practice …

The main problem is that the DOS BASIC commands are geared towards record based files (both sequential and random access) and not the more modern “stream of bytes” paradigm in use today. I'm reading what I hope are 256 byte binary records. That's where my biggest concern lies really.

Now, I could read in binary data directly; there is a command to do that, but it reads in a raw sector from the disk; I would have to write code to decode the actual file structure. It's not a complicated structure, but it's a bit more effort than I want do go into right now, and would distract from a “simple” program.

So I can only hope that the program presented above works.

Obligatory Picture

[The future's so bright, I gotta wear shades]

Obligatory Contact Info

Obligatory Feeds

Obligatory Links

Obligatory Miscellaneous

You have my permission to link freely to any entry here. Go ahead, I won't bite. I promise.

The dates are the permanent links to that day's entries (or entry, if there is only one entry). The titles are the permanent links to that entry only. The format for the links are simple: Start with the base link for this site: https://boston.conman.org/, then add the date you are interested in, say 2000/08/01, so that would make the final URL:

https://boston.conman.org/2000/08/01

You can also specify the entire month by leaving off the day portion. You can even select an arbitrary portion of time.

You may also note subtle shading of the links and that's intentional: the “closer” the link is (relative to the page) the “brighter” it appears. It's an experiment in using color shading to denote the distance a link is from here. If you don't notice it, don't worry; it's not all that important.

It is assumed that every brand name, slogan, corporate name, symbol, design element, et cetera mentioned in these pages is a protected and/or trademarked entity, the sole property of its owner(s), and acknowledgement of this status is implied.

Copyright © 1999-2024 by Sean Conner. All Rights Reserved.