The GMC-4 is the Cracker Jack Prize that comes bundled with Otona no Kagaku Magazine, Volume 24. I assume that GMC stands for Gakken Micro-Computer and the 4 indicates four bits. In earlier blog entries I talked about Otona no Kagaku magazine in general and about the contents of Volume 24. In this entry, we will check out the Gakken 4-bit microcomputer itself.
The GMC-4 like other Otono no Kagaku furoku (prizes) is a kit. Veteran electronic kit builders will be a bit dissapointed in that there is very little to assemble. All one needs to do is attach the speaker and circuit board to the base and apply the press-on template for the keypad. The circuit board comes pre-assembled on a 2.5″ x 4.75″ single sided circuit board. I imagine that the GMC-4 could have been designed like the long gone Heath Kits where the builder actually soldered components to the circuit board but, the editors at Otona no Kagaku wisely decided to pre-assembled the board. By choosing the a pre-assembled board approach, the board could be designed using less expensive surface mount technology. More importantly, the boards can be tested before shipping. The Denki-Guy’s GMC-4 worked the first time.
After the kit is assembled, all you need to do is insert fresh alkaline batteries and slide the power switch to on. It is recommended that you do not use rechargeable batteries as the output voltage it too low. If the 7-segment LED shows “F” when power is first turned on, the GMC-4 is probably working. The easiest eay to test is to run one of the build-in sample programs. Sample program 1, the Electronic Organ needs little explanation. To start the program, punch in “RESET”-“9”-“RUN”. To play the organ, simply press a key (1 thru E) on the keypad and a note will be played.
I think I will skip a detailed explanation of the sample programs. Even if you don’t read Japanese, the operation of most of these programs can be figured out by looking at the illustrations and playing with the program. If you need any help figuring something out, feel free to leave me a comment asking your question. The Denki-guy is happy to help.
After playing with the sample programs a bit, many of us are inspired to learn how to write our own programs. Writing programs for the GMC-4 is both easy and hard at the same time. It is easy in that there are only 30 machine instructions to learn. Poking around the web, I discovered that a fellow blogger, Curtis Hoffmann, has already published English (programming) instructions the GMC-4. Since the GMC-4 processor is relatively simple, even a beginner should be able to understanding what exactly each instruction does. The hard part is learning how to string these simple instructions together to perform a useful task. I will try to help with this part. As is the tradition, I will write a “hello world” program first.
I will need to take some liberty with the traditional “hello world” program to make it work on the GMC-4 . The problem is the limited output capabilities. The only output we have to work with is one 7-segment LED, 7 individual (binary) LEDs and a speaker. Now, since the GMC-4 has special instruction to produce tones on the speaker, I decided my program should beep out “HELLO WORLD” in international Morse code.
I must admit, I got the idea to send HELLO WORLD in Morse code while reading the programming manual for the FX-MyComR-165, the predecessor to the GMC-4. The R-165 programming manualis available on the Otona no Kagaku website but only in Japanese. The programming manual reveals some useful nuggets of information when explaining the computer instructions. For example, the programming manual indicates the Call Short Sound (CAL SHTS) and Call Long Sound (CAL LONS) instructions are specifically designed for generating Morse code. Here are the explanations from the manual:
About the CAL SHTS instruction
The execution of this instruction generates a short sound that is passed on port bit R3. This so called short sound along with other features described below is used when writing a program to generate Morse Code Sounds. The short Morse sound is made up from a short sound and a short rest.
About the CAL LONS instruction
An instruction to make the long Morse sound. Use when generating Morse code sounds by arranging sequences with the previously explained CAL SHTS (instruction)
There is another nuget in the R-165 programming manual and that is a listing for a Morse code program (experiment No. 69). This is a great starting point for the hello world program. A secondary goal of a “hello world” program is to become familiar with development tools. In the spirit of this goal, let’s use an assembler to help us generate the machine language code. I was quite surprised to learn that fans in Japan have made a number of GMC-4 assemblers available. For our “hello world” program I choose to use a very simple assembler that can be found here. I would like to give credit to the author but, I cannot find an information page. All I know is the page is hosted on musashinodenpa.com.
The simplified "hello world" entered into the assembler
One final goal of my “hello world” program will be to keep it simple. For this reason, I will shorten the morse code message to “h w”. In (international) Morse Code, “h w” is coded “· · · · · — — “. The dots represent a short Morse sound and the dashes represent the long Morse sound. If you look at the program listing in the assembler input window (above), you can see the correct sequence of short sounds (CAL SHTS) and long sounds (CAL LONS). Between the two letters is an instruction of CAL TIMR. The “Call Timer” instruction is used to create a space between the letters and at the end of the sequence. Let’s see what the programming manual has to say about the “Call Timer” instruction.
About the CAL TIMR instruction
When this instruction is executed a wait for a fixed time period is generated. The wait time is decided by the A register and can be calculated: Wait time = (A register value + 1) x 0.1 seconds. In (experiment) 26 the A register is set to 5 so (5 + 1) x 0.1 sec = a delay of 0.6 seconds.
As you can see, the Call Timer instruction is used twice. The first time it is used is between the Morse Code for H and W. We now know that Call Timer inserts a delay whose length depends on the value of the A register. In this program, the TIA instruction is used to place a delay value in A. At the top of the program you can see A set to 1 and towards the bottom, A is set to 5. This is used to set the intercharacter and interword spacing respectively. The final JUMP instruction tells the program to continue from the top.
Okay, now we know how it works, the next step is to teach the program to the microcomputer. The GMC-4 does not understand the words we wrote; it only understands machine language. Fortunately, the assembler knows how to translate. Simply press the ASSEMBLE「アセンブル実行」button to get the machine language. The assembler will output a chart sort of like the one below ( the actual output is a longer list with only three columns ). The column headers translate as follows:
アドレス = Address = ”Slot” number in main memory
命令 = Assembly Instructions = Human-readable instructions & data
命令コード = Object Code = Machine-readable data
Assembler output of the "hello world" program
The next to last step is to enter the program into the GMC-4 . Remember that the only thing the GMC-4 understands is Object Code so this is the line of data we will enter. Fortunately, the data entry process is simple though it can become a bit tedious for long programs. To enter the “hello world” program, slide the power switch to on and press “RESET”. Press the button for the first Object Code instruction, “8” in this case and then press “INCR”. What you have just done is place a value of 8 in Address 0. The microcomputer is now ready to input a value into address 01. Punch in the next code, “1” and “INCR” again. Continue to input the Object Code values, in order, pressing “INCR” after each value. After you have enterered the final instruction and pressed “INCR”, press “RESET” “1” “RUN” to start the program. You should hear the GMC-4 beep out Didididit Didahdah, Didididit Didahdah, endlessly. Remember, you can press “RESET” to stop the program and save your sanity.
For those of you who are purist and want the program to spell out HELLO WORLD instead of HW, it is a simple matter to expand the program. The Morse Code for “hello world” is “· · · · · · — · · · — · · — — — · — — — — — · — · · — · · — · ·“. I will leave it as an exercise for the reader to write the actual program. My version of the program barely fit into the memory of the GMC-4 (only one unused address). In fact the program spilled over into the data memory area (address 50 – 5F) but seems to be alright as long as the memory addresses are not used in the program.
I hope you were able to get “hello world” working on your GMC-4. For my next blog entry, I plan to write a program to make the binary LEDs scan back and forth like the eye of KITT, the talking car in the Knight Rider TV series. As always, feel free to ask questions or make comments in the comments section.
The Denki-Guy