Monthly Archives: September 2011

Emulator progress, and envy…

I’ve made a tiny bit of headway, but also encountered a link which makes me envious of much greater hacking skill. Óscar Toledo did an 8080 emulator that can boot CP/M as part of the 19th International Obfuscated C Code Contest, winning Best of Show. Its brevity is the “soul of wit”. Check it out.

Toledo 8080 emulator

Óscar also has written several tiny chess programs, and a Javascript chess program. Awesome.

While I didn’t find his code to be all that helpful (it’s, well, dense to say the least), I did find his approach to be helpful. A few additional minutes of hacking, and I managed to get the Tiny BASIC that he runs on his simulator to work on my own. Witness the following BASIC program:

>LIST
  10 PRINT "A PROGRAM TO EXPLORE THE 3 * X + 1 PROBLEM"
  20 FOR I = 1 TO 10
  25 T = I 
  30 GOSUB 100
  35 PRINT
  40 NEXT I
  50 STOP
 100 PRINT T,
 110 IF T = 1 GOTO 1000
 120 LET J = T / 2 
 130 IF 2 * J # T GOTO 140
 135 LET T = J
 136 GOTO 100
 140 T = 3 * T + 1 
 150 GOTO 100
1000 PRINT
1010 RETURN

OK
>RUN
A PROGRAM TO EXPLORE THE 3 * X + 1 PROBLEM
     1

     2     1

     3    10     5    16     8     4     2     1

     4     2     1

     5    16     8     4     2     1

     6     3    10     5    16     8     4     2     1

     7    22    11    34    17    52    26    13    40    20    10     5    16     8     4     2     1

     8     4     2     1

     9    28    14     7    22    11    34    17    52    26    13    40    20    10     5    16     8     4     2     1

    10     5    16     8     4     2     1


OK
>

Not bad! I suspect that even though my 8080 simulator is still pretty rough, I could get CP/M booted on it in much the same way that he did. More later.

More on my 8080 emulator…

I spent some more time hacking on my emulator today. The key to getting an emulator to work is to have good, clear references on how the system works, and some example code that torture tests your simulator. Except for the DAA instruction (more on that later), the documentation for the 8080 is pretty good, and reading about several of the VHDL and Verilog simulations of the 8080 turned me onto CPUDIAG.ASM, a program which was designed to exercise the 8080 (apparently early NEC clones of the 8080A had difficulties with the DAA instruction). As it turns out, this little chunk of code proved to be incredibly useful.

;***********************************************************************
; MICROCOSM ASSOCIATES  8080/8085 CPU DIAGNOSTIC VERSION 1.0  (C) 1980
;***********************************************************************
;
;DONATED TO THE "SIG/M" CP/M USER'S GROUP BY:
;KELLY SMITH, MICROCOSM ASSOCIATES
Click here for the complete source.

After a couple of hours more tinkering, my efforts were rewarded with:

::: brainwagon 8080 emulator version 0.0
::: 1453 bytes of code loaded.

 CPU IS OPERATIONAL

Huzzah! Okay, there are still a few things this thing doesn’t test, like interrupts and the like. And I couldn’t figure out how the DAA instruction is supposed to work. It’s not clear to me that SIMH implements this properly either, a quick peek at their code seems to show that none of the ADD instructions do anything to set the auxillary carry bit. For now, I just commented out the offending tests. I’ll put them back in when I have some confidence that I understand how they are supposed to work.

Now that the instructions basically work, it appears that the next thing to do would be to try to figure out how to boot CP/M on the virtual machine. Then… tidy it up to see if I can shrink the code (the code for my linux box is about 12K). Then… well, we’ll see.

On ARISSat-1 SSTV images…

I’ve been trying to get out and record more ARISSAT-1 passes, in the hopes of getting some nice SSTV images. If you follow @brainwagon on twitter, you are likely to see some of the more mundane images that I’ve been getting thusfar. I keep hoping to snag some truly great ones, but thus far, the earth seems to be really good at evading the lens of ARISSAT-1 while it’s above my radio horizon. For instance, today I got these two pictures:

Not exactly exciting. There is an 82 degree pass later today, maybe I’ll luck out.

One thing that might not be obvious is that ARISSat-1 has four cameras. You can tell which camera is in use by looking at the color of the RS01S logo in the upper left of the SSTV image.

  • Red indicates the camera pointing along the -Y axis.
  • Green indicates the +Z camera. You can sometimes see the 2m antenna in this view (as you can in the green logo image above, poking in from screen right).
  • Blue is -Z pointing view, out the “bottom” of the satellite.
  • Magenta is the +Y pointing camera.

When I look at the ARISSat-1 SSTV gallery hosted by AMSAT, I see that most of the “good” pictures come from the blue and magenta cameras, but it seems clear that the orientation of the satellite drifts a bit, and there is no guarantee. I’ll just keep plugging away until I get something better.

Yours Truly on the Zombie Tech podcast

One of the more gratifying benefits of blogging is that it provides an opportunity to meet people who share your interests and enthusiasms. A few months ago, I became aware of the crew on the #savagecircuits IRC channel on AfterNET and started hanging out there. Various group members like Atdiy, whisker, JohnS_AZ, MakerDino, and Roy_Eltham (and others) all have participated in Ustream sessions, group Skype calls, and even played some Minecraft together. It’s a fun group.

Atdiy and whisker have started a new podcast called “Zombie Tech” which is basically just an extension of these online sessions. Nominally, the purpose is to pool our geek talents to figure out how we might survive the inevitable Zombie Apocalypse™, but as serious as that is, we seem to spend most of our time talking about some of the geeky projects we are engaged in, trying to teach each other and learn more about electronics, microcontrollers, programming, and using the Internet to spread more enthusiasm for more of the same.

They asked me to be on this week, and we talked for an hour. I’d be interested in hearing any feedback (hopefully positive and constructive, but any is welcome). And thanks to Atdiy and whisker for inviting me on.

ZombieTech – Zombie Tech 004.

An 8080 emulator…

A couple of days ago I got intrigued by this cool project which ran CP/M on an AVR. The basic idea was to equip an AVR with an external RAM, and then write a compact 8080 emulator to run on the AVR. Instead of floppy drives, the AVR accesses data stored on a small SD card. I thought it was really cool.

So I decided to see how far I could get.

A couple of hours work spent watching TV had the basic framework in place, and it’s beginning to execute code. For instance, here is the simple “Hello World” program, written in 8080 assembler (it presumes that you are running on a CP/M system to supply a printing system call):

bdos    equ     0005H
        org 0x100
start:  mvi c,9
        lxi d,msg
        call bdos
        hlt
msg:    db 'Hello World!', 0xA, '$'
end     start

Unless you like assembling code by hand, you need an assembler. I thought about using a simulated CP/M system running on simh, but that quickly got annoying, so instead I searched around and ultimately stumbled on asmx, a multi-CPU assembler which seemed to work just fine. It produced a nice little Intel hex format file, which my emulator can then load. I trap calls to the BDOS entry vector, and implement them with standard C calls (at the moment), and the net result is the rather unimpressive:

::: brainwagon 8080 emulator version 0.0
::: 23 bytes of code loaded.
Hello World!

Most of the control functions work, I need to get the conditional returns to work properly. I don’t have interrupt support yet, nor does it compute cycle counts, but the overall framework is quite good. I suspect that another couple of hours of work will get 95% of the instructions working, and then I could consider doing something like implementing Space Invaders. Ultimately, I kind of want to run a simple simulated CP/M system. We’ll see how it goes: stay tuned.

RIP: Michael S. Hart, founder of Project Gutenberg

Dan alerted me to the fact that Project Gutenberg founder Michael Hart passed away. On the Project Gutenberg site, Dr. Gregory Newby wrote a very nice obituary:

Michael S. Hart – Gutenberg.

I also liked this quote from Hart:

“One thing about eBooks that most people haven’t thought much is that eBooks are the very first thing that we’re all able to have as much as we want other than air. Think about that for a moment and you realize we are in the right job.”

I’m a huge fan of Project Gutenberg. I’ve enjoyed many classic books in their collection, from the stories of Conan Doyle, to Robert Louis Stevenson, to Lewis Carroll, Bram Stoker, Mark Twain, Charles Dickens… And on and on, as far as the public domain can take me. It’s hard to overestimate the value to public literacy that Project Gutenberg provides, and it could provide much more as a resource if people used it more. Thanks to Michael Hart, what a great contribution to humanity, and what a great legacy.

Are ‘ham’ operators going the way of 8-tracks and VCRs?

Jeff, KE9V pointed at the following article via Twitter:

Are ‘ham’ operators going the way of 8-tracks and VCRs?

The author actually meanders a bit (into the why we call it “ham radio”, for some odd reason, but his main point seems to be this:

As National Public Radio found last March, amateur radio is an experience that can’t be duplicated surfing the Internet. That’s why when NPR attended a ham radio convention in St. Louis, a reporter found teens carrying on the hobby. As one 15-year-old said, Facebook and texting are fun, but it can’t match making friends with a $200 radio for which you don’t have to pay a monthly fee.

I groaned a bit inside, because this is complete balderdash.

Okay, it’s not complete balderdash. I am not one to tell teens (or anyone else) what is fun and what is not fun: they are capable of figuring that out for themselves. I’ve no doubt that the teens they interviewed at a ham radio convention thought ham radio was fun, otherwise, they probably wouldn’t have been there. But I also suspect that if you took away a teen’s mobile phone and replaced it with a $200 HT, you’d find that even those attending the conference would probably be more than a little upset.

The reason is obvious: a mobile phone and an HT aren’t interchangeable. They don’t do the same thing.

Most notably, an HT is a ham radio, and radios like that are almost exclusively for communicating with other hams. If you want to communicate with someone who isn’t a ham, a ham radio isn’t really all that valuable. At best, it requires a clumsy relay. In practice, it just isn’t done. You’d just fire up your phone and call them. Or text them. Or email them. Or Twitter. Or Facebook. Or post something to a blog. You’d send them a picture. Or a link to a YouTube video. If you really want to communicate with someone, I’d submit that the Internet provides a much richer environment than amateur radio.

Okay, but let’s say you do want to talk to hams. Isn’t ham radio the most obvious way to communicate with other hams?

Well, I’d submit the answer is mostly no. If your goal is to communicate, all of the ways that I mentioned above are still excellent, reliable, high bandwidth means of communication. Even if you toss in the requirement that the communication be free, the wide availability of WiFi in many areas (from coffee shops to libraries) makes conventional Internet a very attractive means of communication.

If you accept this, then it does seem that amateur radio is going to go the way of the Dodo.

But I don’t believe it will, because ham radio does provide some things that the conventional Internet doesn’t.

First of all, it relies somewhat less on infrastructure, so it provides a backup in times of emergency. This capability is widely trumpeted as the (primary?) virtue of amateur radio, and as justification for our spectrum allotment. Our pool of self-trained emergency communicators can provide some valuable assistance to local communities in case of emergency as a kind of failsafe.

Secondly, even in non-emergency cases, ham radio can provide some capabilities which would be difficult to reproduce using more conventional wired or wireless technology. Repeaters can provide broad coverage in areas not well served by cell towers. HT’s and small HF rigs can enable people hiking and camping in remote areas to communicate.

But primarily, ham radio is a kind of sport: an active pastime. A form of recreation. We do it because we like to do it. It provides us an interesting opportunity to achieve mastery. Mastery makes us feel better. The activity provides a means to connect with other humans and relate to them about our shared interests.

The invention of the motorboat didn’t end surfing or swimming. The invention of canned tuna fish didn’t end fishing. The invention of cars didn’t end walking or running. Depending on the emergency, skills like walking, fishing or swimming may save your life, but that’s still not why people do them: they do them because it’s fun.

As long as ham radio continues to be fun, ham radio will continue.

Sprites mods – CP/M on an AVR

I’ve always been fascinated by emulation and virtual machines, as well as retro-computing: resurrecting the old machines of my past. I never owned an old CP/M machine, but there are still some neat projects where people construct there own, and simulators like SIMH and YAZE-AG are good software simulators. But what I always wondered was whether a small microcontroller like an Atmel AVR could simulate an 8080 or Z80 fast enough to simulate these older machines.

And of course, today I found a link to someone who did just that. With a remarkably simple chunk of hardware. One AVR, a dynamic RAM, and an SD card to serve as a mass storage device. The combination is good enough to run Zork. I’m suitably impressed. The design and code are all GPL.

Sprites mods – CP/M on an AVR – Intro.

ARISSat-1 and the ISS over California

I got a tweet from twisst, the ISS pass prediction robot yesterday indicating that I’d have a good pass around 8:25PM. While I am fighting off a cold, the weather was beautiful and nice, and so I ran some path predictions to see what the path looked like, and also checked on ARISSat-1’s path to see how it was doing. I hadn’t recorded ARISSat-1 since it’s first launch weeks ago, and hoped that in spite of it’s rapidly increasing battery problems, that it would still be in sunlight, and would therefore still have a strong signal. ARRISSat-1 would lead the ISS by about 23 minutes, rising around 8:02 or so, but since I have a tall horizon to the north where it would rise, I wouldn’t expect to pick up a good signal until it cleared the hills, about 8:06 or so.

It turned out to be a really good pass: I got three different SSTV images, and some really clear audio telemetry. The first SSTV image and the last were pretty marginal, but the middle one was really clear (sad, since it was the least interesting). When I first recorded ARISSat-1 shortly after launch, I had periodic fades which I hypothesized as tumbling of the satellite: those appear to be entirely gone. I’ll have to try again to see if I can get a better and more interesting SSTV image.

After ARISSAT-1 set, I waited until 8:25 to see if the ISS would come up. I tuned into 145.825 (the ISS packet radio frequency) and waited with my iPhone camera ready. By then, it was surprisingly dark, so my camera recorded mostly just blackness, but toward the end of the clip, you can see a faint dot in the recording (and very little else). Not too exciting, but I left the audio from the radio playing in the background, so you can hear the digital packet signals being echoed through the ISS. The ISS was predicted to peak at magnitude -3.1, which made it brighter than any star in the sky, and it was very easy to see.

Here’s the resulting video. WARNING, spoiler: I forgot to edit out the “secret word” in this recording. Blame it on the cold medicine I’m on.

I’ll probably try to record another pass soon. Stay tuned.