-
Honey, somebody shrunk the Kenbak-1!
08/10/2021 at 00:46 • 0 commentsI mentioned at the beginning of this project's Details that Adwater & Stir had some fine KENBAK-1 offerings. Based on Mark Wilson's code Adwater & Stir offers a ruler sized nanoKENBAK-1, a half size µKENBAK-1 kit, and will soon be offering a full sized kit as well.
Well I couldn't resist getting myself a nanoKENBAK-1. It comes fully assembled and tested.
From tip to tip it's about 210 mm wide and 40 mm tall. It's so cool to be able to program this ruler sized device, and as can be seen on the rear silk screen it includes both built in programs and the ability to store your own programs to EEPROM.
I couldn't resist making a minimal case and stand. It sits on my desk now running the built in BCD clock program (it has a RTC chip).
-
My KENBAK-2/5 Was Featured in MagPi Magazine
08/03/2021 at 18:35 • 4 comments -
Added a Disassembler
07/15/2021 at 20:09 • 0 commentsI can't seem to stop wanting to improve my KENBAK-2/5 project, and anything that gets me "into the weeds" of the instruction set is especially appealing. To that end I have created a stand alone command line Disassembler. I have added the Python script to my GitHub repository and created a release.
Here is the online help:
usage: Disassemble a binary or delimited text file to KENBAK-1 source [-h] [-s] [-d] [-a] -f FILE optional arguments: -h, --help show this help message and exit -s, --save save the disassembly to a .asm file -d, --dump dump the disassembly to standard out -a, --address add the instruction address to each line -f FILE, --file FILE file to disassemble
Writing a disassembler is an interesting exercise, one that I had never undertaken before. Faced with an array of 256 raw bytes and trying to coax some meaningful structure out of it was pretty daunting.
The first thing I did was to determine which of the bytes represented the program code vs program data. Fortunately the first byte of code can be ascertained by looking at the fourth byte in memory which holds the PC (program counter/instruction pointer - defaults to 4). From that point, consecutive instructions can be readily resolved, that is until a "jump" instruction is encountered. By carefully following all of the jumps to other blocks of code you can create a map of all the code in the program.
All of the non-code bytes are then assumed to be data. But which of those bytes represent constants vs data bytes that will be manipulated by the program. Since all of the "registers" on a KENBAK-1 (A, B, X, PC, OUTPUT, AOC, BOC, XOC, and INPUT) are at fixed positions in memory that is a good place to start marking them as data bytes using a DB directive. The other bytes that will be written to can be determined by looking at all of the instructions that store to memory: STORE, SET, and JMK. Everything else is then treated as a constant.
Finally I did a pass to convert all of the memory references in the code to labels to make reading the emitted code a bit easier.
To test the disassembler I input the 256 byte "Day of the Week.bin" file created by the IDE assembler and compared the assembly output to the original code that I wrote. Furthermore I ran the disassembled code inside of the IDE to ensure that it indeed worked as expected.
Here is the original code:
; Program to calculate the day of the week for any date. To start this program you will ; have to input the date in four parts: Century, Year, Month, and Day. Each of the parts ; is entered as a two digit Binary Coded Decimal number (ie. the first digit will occupy ; bits 7-4 as a binary number, and the second digit bits 3-0) using the front panel data ; buttons. The steps to run this program are: ; ; 1) Set the PC register (at address 3) to 4. ; 2) Clear the input data then enter the date Century. ; 3) Press Start. ; 4) Clear the input data then enter the date Year. ; 5) Press Start. ; 6) Clear the input data then enter the date Month. ; 7) Press Start. ; 8) Clear the input data then enter the date Day. ; 9) Press Start. ; ; The day of the week will be returned via the data lamps using the following encoding: ; ; 7-Sunday 6-Monday 5-Tuesday 4-Wednesday 3-Thursday 2-Friday 1-Saturday ; ; All lamps turned on means the last item entered was invalid and you have to restart. ; ; ; Get the date we want the day for. ; load A,INPUT ; Get the century. jmk bcd2bin store A,century halt load A,INPUT ; Get the year. jmk bcd2bin store A,year halt load A,INPUT ; Get the month. jmk bcd2bin sub A,1 ; Convert from 1 based to 0 based. store A,month halt load A,INPUT ; Get the day. jmk bcd2bin store A,day load A,0b10000000 ; Setup the rotation pattern. store A,rotate ; ; All the inputs should be in place. Start the conversion. ; load A,year ; Get the year. sft A,R,2 ; Divide by 4. store A,B ; Save to B the working result. add B,day ; Add the day of the month. load X,month ; Use X as index into the month keys. add B,monkeys+X ; Add the month key. jmk leapyr ; Returns a leap year offset in A if applicable. jmk working ; Working... sub B,A ; Subtract the leap year offset. jmk cencode ; Returns a century code in A if applicable. jmk working ; Working... add B,A ; Add the century code. add B,Year ; Add the year input to the working result. chkrem load A,B ; Find the remainder when B is divided by 7. and A,0b11111000 ; Is B > 7? jmp A,EQ,isseven ; No then B is 7 or less. sub B,7 ; Yes then reduce B by 7. jmk working ; Working... jmp chkrem ; Check again for remainder. isseven load A,B ; Is B = 7? sub A,7 ; Subtract 7 from B value. jmp A,LT,gotday ; No B is less than 7. load B,0 ; Set B to zero because evenly divisible. gotday load X,B ; B holds the resulting day number. Use as index. load A,sat+X ; Convert to a day lamp. store A,OUTPUT halt error load A,0xff ; Exit with error store A,OUTPUT ; All lamps lit. halt ; ; Store inputs. ; century db year db month db day db ; ; Static table to hold month keys. ; monkeys 1 4 4 0 2 5 0 3 6 1 4 6 ; ; Need to preserve A while performing some steps. ; saveA db ; ; Subroutine to blink the lamps to indicate working. ; rotate db ; Pattern to rotate. working db ; Save space for return adderess. store A,saveA ; Remember the value in A. load A,rotate ; Get the rotate pattern. store A,OUTPUT ; Show the rotated pattern. rot A,R,1 ; Rotate the pattern. store A,rotate ; Save the new rotation. load A,saveA ; Restore the value of A. jmp (working) ; Return to caller. org 133 ; Skip over registers. ; ; Subroutine takes a BCD nuber in A as input and returns the equivalent binary number ; also in A. ; bcd2bin db ; Save space for return address. store A,X ; Save A. sft A,R,4 ; Get the 10's digit. jmk chkdig ; Make sure digit is 0 - 9. store A,B ; B will hold the 10's digit x 10 result add B,B ; B now X 2 sft A,L,3 ; A is now 10's digit X 8 add B,A ; B now 10's digit X 10 store X,A ; Retrieve original value of A and A,0b00001111 ; Get the 1's digit value in binary. jmk chkdig ; Make sure digit is 0 - 9. add A,B ; Add the 10's digit value in binary. jmp (bcd2bin) ; A now has the converted BCD value. ; ; Subroutine determines if the date is a leap year in January or February and returns ; an offset of 1 if it is, and 0 otherwise. ; leapyr db ; Save space for return address. load A,month ; Check to see if month is January or February. and A,0b11111110 ; Are any bits other than bit 0 set? jmp A,NE,notlpyr ; Yes then not January or February. Return 0. load A,year ; Is this an even century? jmp A,NE,chkyear ; No then have to check the year. load A,century ; Yes so see if century evenly divisible by 4. and A,0b00000011 ; Are bits 1 or 0 set? jmp A,EQ,islpyr ; Yes evenly divisible by 4 and is a leap year. jmp notlpyr ; No this is not a leap year. chkyear load A,year ; See if rear evenly divisible by 4. and A,0b00000011 ; Are bits 1 or 0 set? jmp A,NE,notlpyr ; Yes so not evenly divisible by 4 and not a leap year. islpyr load A,1 ; Offset 1. jmp (leapyr) ; Return offset. notlpyr load A,0 ; Offset 0. jmp (leapyr) ; Return offset. ; ; Subroutine determines if a century code needs to be applied to the calculation. ; cencode db ; Save space for return address. load A,century ; Century must be between 17 - 20. chkmin sub A,17 ; Is century less than 17? jmp A,GE,chkmax ; Yes so century >= 17. Check max boundry. load A,century ; Increase century by 4. add A,4 store A,century jmp chkmin chkmax load A,century ; Century must be between 17 - 20. sub A,20 ; Is century greater than 20? jmp A,LT,retcode ; No so calculate century code. jmp A,EQ,retcode load A,century ; Decrease century by 4. sub A,4 store A,century jmp chkmax+2 retcode load X,century ; Calculate the century code sub X,17 ; Create an index into the century codes. load A,ctcodes+X ; Get the appropriate century code. jmp (cencode) ; Return century code. ; ; Subroutine that checks if the digit passed in A is in range 0 - 9. ; chkdig db ; Save space for return adderess. store A,saveA ; Remember value in A. load A,9 sub A,saveA ; Subtract value passed from 9. and A,0b10000000 ; Is negative bit set? jmp A,NE,error ; Yes so value in A not in range 0 - 9. load A,saveA ; No so A value in range. jmp (chkdig) ; Return to caller. ; ; Static table to hold the output pattern for the day of the week. ; sat 0b00000010 sun 0b10000000 mon 0b01000000 tues 0b00100000 wed 0b00010000 thur 0b00001000 fri 0b00000100 ; ; Static table to hold century codes. ; ctcodes 4 2 0 6
And here is the disassembled code:
; ; Disassembly for [Day of the Week.bin] ; org 0 A db B db X db PC db load A,INPUT jmk LAB133 store A,LAB094 halt load A,INPUT jmk LAB133 store A,LAB095 halt load A,INPUT jmk LAB133 sub A,1 store A,LAB096 halt load A,INPUT jmk LAB133 store A,LAB097 load A,128 store A,LAB111 load A,LAB095 sft A,R,2 store A,B add B,LAB097 load X,LAB096 add B,LAB098+X jmk LAB156 jmk LAB112 sub B,A jmk LAB189 jmk LAB112 add B,A add B,LAB095 LAB062 load A,B and A,248 jmp A,EQ,LAB074 sub B,7 jmk LAB112 jmp LAB062 LAB074 load A,B sub A,7 jmp A,LT,LAB082 load B,0 LAB082 load X,B load A,LAB243+X store A,OUTPUT halt LAB089 load A,255 store A,OUTPUT halt LAB094 db LAB095 db LAB096 db LAB097 db LAB098 1 4 4 0 2 5 0 3 6 1 4 6 LAB110 db LAB111 db LAB112 db store A,LAB110 load A,LAB111 store A,OUTPUT rot A,R,1 store A,LAB111 load A,LAB110 jmp (LAB112) 0 0 OUTPUT db OCA db OCB db OCX db 0 LAB133 db store A,X sft A,R,4 jmk LAB228 store A,B add B,B sft A,L,3 add B,A store X,A and A,15 jmk LAB228 add A,B jmp (LAB133) LAB156 db load A,LAB096 and A,254 jmp A,NE,LAB185 load A,LAB095 jmp A,NE,LAB175 load A,LAB094 and A,3 jmp A,EQ,LAB181 jmp LAB185 LAB175 load A,LAB095 and A,3 jmp A,NE,LAB185 LAB181 load A,1 jmp (LAB156) LAB185 load A,0 jmp (LAB156) LAB189 db load A,LAB094 LAB192 sub A,17 jmp A,GE,LAB204 load A,LAB094 add A,4 store A,LAB094 jmp LAB192 LAB204 load A,LAB094 LAB206 sub A,20 jmp A,LT,LAB220 jmp A,EQ,LAB220 load A,LAB094 sub A,4 store A,LAB094 jmp LAB206 LAB220 load X,LAB094 sub X,17 load A,LAB250+X jmp (LAB189) LAB228 db store A,LAB110 load A,9 sub A,LAB110 and A,128 jmp A,NE,LAB089 load A,LAB110 jmp (LAB228) LAB243 2 128 64 32 16 8 4 LAB250 4 2 0 6 0 INPUT db
As mentioned the disassembler will accept 256 byte raw binary files as input (files with a .bin extension). It can also parse delimited text files (with a .txt extension). The delimiters can be any combination of white space characters (like spaces, tabs, newlines, etc.) plus periods, commas, colons, and semi-colons. The bytes themselves can be expressed as hexidecimal (starts with 0x), decimal (start with 1-9), octal (starts with 0), or binary (starts with 0b) , but must resolve to a number less than 256.
If the --save option is chosen a disassembly file will be generated. The file name will be the same as the input's with the extension replaced by ".asm".
-
OK Another One More Thing
07/06/2021 at 23:46 • 0 commentsI realize that not too many people are going to make a physical KENBAK-1 reproduction, but I really want people to experience Bob Blankenbaker's creation should they desire to. So, I created a simulator that is integrated into my KENBAK-2/5 IDE. Not much to say here. The simulator appears as a pop-up window when you click the Console button.
Here is a demonstration of the console simulator running my Fibonacci program written in KENBAK-1 assembler.
I have added a new script KENBAK_IDE_With_Console.py to my GitHub repository as I didn't want to alter the non Console version until I have done more testing. I'll combine the two in a bit. This script also requires the Front Panel Text Colored.png image.
Update 07/08/2021: I have integrate the Console into the main script now and created a release.
-
A Reply from John Blankenbaker
05/15/2021 at 15:23 • 0 commentsOver on Instructables GilDev, who also did a wonderful KENBAK-1 Replica, suggested "Feel free to send photos of your creation to John Blankenbaker, he replied to my mails and was very kind!" So I did and he was. The first thing he said in his reply "Your email was the most interesting thing I have received today. I was very impressed!". Sure made my day too!
As part of my Email I said the following, "I also wrote a Day of the Week program. It took me 251 bytes to write. If I understand what you said in the VCF East keynote you gave in 2016, Day of the Week was one of three programs that you had simultaneously loaded into memory for demonstration purposes. Amazing!".
Here is his reply.
You overestimated my capability in programming the day of the week problem. I did it only for the 20th century. One reason for limiting it was the problem becomes more complicated very quickly since the English jumped ahead 12 days in 1753 to come into agreement with the European calendars. One of the interesting side aspects of demonstrating this problem was that most people could only verify two dates/day of the week. The were Pearl Harbor and their marriage day. Another interesting point is that only about half of the high school math teachers could quote the rules for
skipping dates in the calendar. My most complex program was for three dimensional tic-tac-toe on a 4 x 4 x 4 board. When the program was done, it did not have enough memory left to recognize the end of the game.I was so nice of John Blankenbaker to take the time to reply.
-
One More Thing
05/07/2021 at 19:34 • 0 commentsWhen John Blankenbaker was demonstrating his KENBAK-1 Personal Computer back in 1971, one of the programs he always showed was a Day of the Week calculator. Given any date, it can tell you what day of the week that date fell on. It was something that was pretty cool that everyone could relate to.
Well I didn't feel that my KENBAK-2/5 reproduction would be quite complete until it could do the same. It was a fun programming challenge that exercised a lot more of the capabilities of my machine, and in fact uncovered a few minor issues with my emulator software:
- JMK operand was not saving the return address correctly
- HALT operand needed to advance the program counter (PC)
- I tweaked some of the console interactions.
- I added a DB directive to reserve a byte of memory.
I feel a lot more confident now that my reproduction is a very close work-a-like to the original. Here is the code:
; Program to calculate the day of the week for any date. To start this program you will ; have to input the date in four parts: Century, Year, Month, and Day. Each of the parts ; is entered as a two digit Binary Coded Decimal number (ie. the first digit will occupy ; bits 7-4 as a binary number, and the second digit bits 3-0) using the front panel data ; buttons. The steps to run this program are: ; ; 1) Set the PC register (at address 3) to 4. ; 2) Clear the input data then enter the date Century. ; 3) Press Start. ; 4) Clear the input data then enter the date Year. ; 5) Press Start. ; 6) Clear the input data then enter the date Month. ; 7) Press Start. ; 8) Clear the input data then enter the date Day. ; 9) Press Start. ; ; The day of the week will be returned via the data lamps using the following encoding: ; ; 7-Sunday 6-Monday 5-Tuesday 4-Wednesday 3-Thursday 2-Friday 1-Saturday ; ; All lamps turned on means the last item entered was invalid and you have to restart. ; ; ; Get the date we want the day for. ; load A,INPUT ; Get the century. jmk bcd2bin store A,century halt load A,INPUT ; Get the year. jmk bcd2bin store A,year halt load A,INPUT ; Get the month. jmk bcd2bin sub A,1 ; Convert from 1 based to 0 based. store A,month halt load A,INPUT ; Get the day. jmk bcd2bin store A,day load A,0b10000000 ; Setup the rotation pattern. store A,rotate ; ; All the inputs should be in place. Start the conversion. ; load A,year ; Get the year. sft A,R,2 ; Divide by 4. store A,B ; Save to B the working result. add B,day ; Add the day of the month. load X,month ; Use X as index into the month keys. add B,monkeys+X ; Add the month key. jmk leapyr ; Returns a leap year offset in A if applicable. jmk working ; Working... sub B,A ; Subtract the leap year offset. jmk cencode ; Returns a century code in A if applicable. jmk working ; Working... add B,A ; Add the century code. add B,Year ; Add the year input to the working result. chkrem load A,B ; Find the remainder when B is divided by 7. and A,0b11111000 ; Is B > 7? jmp A,EQ,isseven ; No then B is 7 or less. sub B,7 ; Yes then reduce B by 7. jmk working ; Working... jmp chkrem ; Check again for remainder. isseven load A,B ; Is B = 7? sub A,7 ; Subtract 7 from B value. jmp A,LT,gotday ; No B is less than 7. load B,0 ; Set B to zero because evenly divisible. gotday load X,B ; B holds the resulting day number. Use as index. load A,sat+X ; Convert to a day lamp. store A,OUTPUT halt error load A,0xff ; Exit with error store A,OUTPUT ; All lamps lit. halt ; ; Store inputs. ; century db year db month db day db ; ; Static table to hold month keys. ; monkeys 1 4 4 0 2 5 0 3 6 1 4 6 ; ; Need to preserve A while performing some steps. ; saveA db ; ; Subroutine to blink the lamps to indicate working. ; rotate db ; Pattern to rotate. working db ; Save space for return adderess. store A,saveA ; Remember the value in A. load A,rotate ; Get the rotate pattern. store A,OUTPUT ; Show the rotated pattern. rot A,R,1 ; Rotate the pattern. store A,rotate ; Save the new rotation. load A,saveA ; Restore the value of A. jmp (working) ; Return to caller. org 133 ; Skip over registers. ; ; Subroutine takes a BCD nuber in A as input and returns the equivalent binary number ; also in A. ; bcd2bin db ; Save space for return address. store A,X ; Save A. sft A,R,4 ; Get the 10's digit. jmk chkdig ; Make sure digit is 0 - 9. store A,B ; B will hold the 10's digit x 10 result add B,B ; B now X 2 sft A,L,3 ; A is now 10's digit X 8 add B,A ; B now 10's digit X 10 store X,A ; Retrieve original value of A and A,0b00001111 ; Get the 1's digit value in binary. jmk chkdig ; Make sure digit is 0 - 9. add A,B ; Add the 10's digit value in binary. jmp (bcd2bin) ; A now has the converted BCD value. ; ; Subroutine determines if the date is a leap year in January or February and returns ; an offset of 1 if it is, and 0 otherwise. ; leapyr db ; Save space for return address. load A,month ; Check to see if month is January or February. and A,0b11111110 ; Are any bits other than bit 0 set? jmp A,NE,notlpyr ; Yes then not January or February. Return 0. load A,year ; Is this an even century? jmp A,NE,chkyear ; No then have to check the year. load A,century ; Yes so see if century evenly divisible by 4. and A,0b00000011 ; Are bits 1 or 0 set? jmp A,EQ,islpyr ; Yes evenly divisible by 4 and is a leap year. jmp notlpyr ; No this is not a leap year. chkyear load A,year ; See if rear evenly divisible by 4. and A,0b00000011 ; Are bits 1 or 0 set? jmp A,NE,notlpyr ; Yes so not evenly divisible by 4 and not a leap year. islpyr load A,1 ; Offset 1. jmp (leapyr) ; Return offset. notlpyr load A,0 ; Offset 0. jmp (leapyr) ; Return offset. ; ; Subroutine determines if a century code needs to be applied to the calculation. ; cencode db ; Save space for return address. load A,century ; Century must be between 17 - 20. chkmin sub A,17 ; Is century less than 17? jmp A,GE,chkmax ; Yes so century >= 17. Check max boundry. load A,century ; Increase century by 4. add A,4 store A,century jmp chkmin chkmax load A,century ; Century must be between 17 - 20. sub A,20 ; Is century greater than 20? jmp A,LT,retcode ; No so calculate century code. jmp A,EQ,retcode load A,century ; Decrease century by 4. sub A,4 store A,century jmp chkmax+2 retcode load X,century ; Calculate the century code sub X,17 ; Create an index into the century codes. load A,ctcodes+X ; Get the appropriate century code. jmp (cencode) ; Return century code. ; ; Subroutine that checks if the digit passed in A is in range 0 - 9. ; chkdig db ; Save space for return adderess. store A,saveA ; Remember value in A. load A,9 sub A,saveA ; Subtract value passed from 9. and A,0b10000000 ; Is negative bit set? jmp A,NE,error ; Yes so value in A not in range 0 - 9. load A,saveA ; No so A value in range. jmp (chkdig) ; Return to caller. ; ; Static table to hold the output pattern for the day of the week. ; sat 0b00000010 sun 0b10000000 mon 0b01000000 tues 0b00100000 wed 0b00010000 thur 0b00001000 fri 0b00000100 ; ; Static table to hold century codes. ; ctcodes 4 2 0 6
While there is a check to make sure that the BCD inputs only contain the digits 0-9, some additional checks for the month (1-12) and day (1-31) were not implemented because I ran out of memory space. The above program takes up 251 of the 255 bytes of available memory. So while the instruction set is more than adequate for most tasks, the limiting factor for doing interesting things on this machine is memory.
The updated IDE and this example have been added to the GitHub for this project.
-
Finishing Up
04/28/2021 at 19:13 • 0 commentsI did some additional testing of the IDE and added a Help button to popup some information on the assembly syntax.
I made a video where I try to demonstrate how the KENBAK-2/5, with it's built in Raspberry Pi, does a good job as a KENBAK-1 reproduction. As with the original you can enter and run programs, and view internal machine memory, just using the switches, buttons, and lamps on the front panel of the console.
But in addition, using the power of the Raspberry Pi 4 to implement an Integrated Development Environment, you can key in programs using native KENBAK-1 assembly language. With breakpoints, single step modes, and memory visualizations, debugging suddenly become a lot easier.
When I first looked at the KENBAK-1 Programming Reference Manual I was very impressed with the instruction set for a machine with no microprocessor, just discrete logic chips. Implementing an Assembler and Emulator only served to deepen my appreciation for what John Blankenbaker created.
-
Running the KENBAK-2/5 IDE
04/26/2021 at 15:39 • 0 commentsRunning the KENBAK-1 IDE
The KENBAK-IDE.py file is available from my GitHub repository. If used outside of the KENBAK-2/5 hardware environment, it should run on any machine that supports Python3 without any library dependencies. In this mode you can still write, debug, and run KENBAK-1 assembly language programs. It's a great learning environment all by itself.
If you are running on the KENBAK-2/5's Raspberry Pi with the port extender hat you will have to first make sure that the wiringpi library is installed.
pip3 install wiringpi
I created a folder on the Pi
mkdir /home/pi/KENBAK-1
and copied the KENBAK-IDE.py file there. Then its a simple matter of running the Python script.
cd /home/pi/KENBAK-1 python3 KENBAK-IDE.py
Auto Start the KENBAK-1 IDE
If you are running KENBAK-1 IDE as a dedicated console on the built-in Raspberry Pi like I am it's convenient to have the program start automatically when the machine boots. Here is what I did to make this happen.
I created an autostart folder on my Pi and switched to that folder.
mkdir /home/pi/.config/autostart cd /home/pi/.config/autostart
Into the autostart folder just created I added the following two files.
runKENBAK-1
cd /home/pi/KENBAK-1 /usr/bin/python3 KENBAK-IDE.py
KENBAK-1.desktop
[Desktop Entry] Type=Application Name=KENBAK-1 Exec=/home/pi/.config/autostart/runKENBAK-1
In addition the runKENBAK-1 file must be made executable with the following command:
chmod 777 runKENBAK-1
Now if you reboot the system, you should briefly see the desktop appear, and shortly after KENBAK-IDE application will load.
Setting up VNC
Current Raspberry Pi OS versions have RealVNC baked in. If you are running the Raspberry Pi in the KENBAK-2/5 console headless as I am you have to setup a virtual desktop for the VNC client to connect to. The easiest way I have found to do this is to add the following lines to the end of the /etc/rc.local file before the exit 0 on the Pi.
# Setup a virtual screen for the VNC server. sudo -u pi vncserver -randr=1920x1080
Set the screen dimension to be the same as the machine that you will be accessing the KENBAK-IDE from. You should then be able to connect to the KENBAK-2/5 with a RealVNC client at the machines IP address with a :1 appended, for example in my case 192.169.123.122:1.
-
Lots of Progress
04/25/2021 at 23:03 • 0 commentsI have integrated the Console functionality (being able to read the buttons and show the lamps ) with the Emulator. With just this in place I now have a fully functional KENBAK-1. I can load and run programs and view memory locations from the front panel as described in the Programming Reference Manual and Laboratory Exercises.
But that's not all I wanted to accomplish. With the further integration of my KENBAK-1 Assembler, the IDE that I had envisioned for this project is really taking shape. As can be seen in a previous log, the Assembler has no "passes". The assembler instructions are continuously parsed as you type and when the corresponding binary code no longer has any question marks you know the syntax for the line is correct. It all works quite well.
I'm running the Raspberry Pi 4 inside my reproduction headless, but when I VNC into it, this is what I see.
Here I have just loaded the Fibonacci program seen in previous logs. The upper right quadrant is of course the assembler code and to it's left the equivalent binary instructions. By clicking on the binary instructions you can set or clear breakpoints (the skp instruction has a breakpoint set for instance).
To the lower left is the state of the predefined "registers" including the address register which is used to load and read memory locations. Middle bottom is a hex dump of all 256 memory locations, and lower right shows the same memory locations in more detail with hex, decimal, octal and binary representations for each location. All references to memory locations are in decimal (leftmost columns in the instruction, hex dump, and details panels and rightmost column in the instruction panel).
The entries rendered in green represent the memory location currently pointed to by the program counter (PC).
The front panel console is fully integrated with the IDE. So for instance you could start the Fibonacci program shown above by pressing the physical START button on the console or by clicking the Run button in the IDE. Similarly pressing and holding the STOP button and then pressing START will perform a single step as will the IDE's Step button.
Anything written to the OUTPUT register will show up on the data lamps on the console. Data stored from the console to memory locations through the address register will be reflected in the IDE.
The IDE does offer some additional features. Your programs can be saved and loaded to disk (the assembler code and the binary memory image both). The Restart button will reset everything to the last loaded image. Clear will zero out memory and the assembler program space then set the PC to memory location 4. Auto will run the program at a rate of about one instruction per second.
You can debug your program by single stepping or by setting breakpoints and observing the memory and registers.
If you just want to play around with KENBAK-1 code, you can run the IDE "standalone" on any platform that supports Python, but of course you will only be able to integrate the KENBAK-2/5 console on a Raspberry Pi since it's bound to the wiringpi library.
Over the next couple of days I'm going to try and put together a video of all of this in action.
-
We Have Blinkenlights!
04/17/2021 at 17:18 • 3 commentsWith the wiring complete I wrote a small program in Python to test the lights, buttons, and switches on the front panel. To be clear this is NOT the KENBAK-2/5 emulator running a program (yet).
As it turns out I did have to replace one of the LEDs which wasn't working.
The Python script communicates with the MCP23017 32 Channel I/O Expansion HAT through the Python wiringpi library. Here is the code for my test program.
#!/usr/bin/python import wiringpi as wiringpi from time import sleep # Set the base number of ic1. ic1_pin_base = 65 # Pin number to code number: # 1 = 65, 2 = 66, 3 = 67, 4 = 68, 5 = 69, 6 = 70, 7 = 71, 8 = 72, 9 = 73, 10 = 74, 11 = 75, 12 = 76, 13 = 77, 14 = 78, 15 = 79, 16 = 80 # Define the i2c address of ic1. ic1_i2c_addr = 0x24 # Set the base number of ic2. ic2_pin_base = 81 # Pin number to code number: # 1 = 81, 2 = 82, 3 = 83, 4 = 84, 5 = 85, 6 = 86, 7 = 87, 8 = 88, 9 = 89, 10 = 90, 11 = 91, 12 = 92, 13 = 93, 14 = 94, 15 = 95, 16 = 96 # Define the i2c address of ic2. ic2_i2c_addr = 0x20 # Initialize the wiringpi library. wiringpi.wiringPiSetup() # enable ic1 on the mcp23017 hat wiringpi.mcp23017Setup(ic1_pin_base,ic1_i2c_addr) # enable ic2 on the mcp23017 hat wiringpi.mcp23017Setup(ic2_pin_base,ic2_i2c_addr) # Setup led pins. light_stop = 65 light_store = 66 light_set = 67 light_clear = 68 light_0 = 73 light_1 = 74 light_2 = 75 light_3 = 76 light_4 = 77 light_5 = 78 light_6 = 79 light_7 = 80 # Setup toggle pins. toggle_off = 69 toggle_on = 70 toggle_unl = 71 toggle_lock = 72 # Setup button pins button_stop = 81 button_start = 82 button_store = 83 button_read = 84 button_set = 85 button_display = 86 button_clear = 87 button_0 = 89 button_1 = 90 button_2 = 91 button_3 = 92 button_4 = 93 button_5 = 94 button_6 = 95 button_7 = 96 # Set the pin mode to an output for all the leds. wiringpi.pinMode(light_stop,1) wiringpi.pinMode(light_store,1) wiringpi.pinMode(light_set,1) wiringpi.pinMode(light_clear,1) wiringpi.pinMode(light_0,1) wiringpi.pinMode(light_1,1) wiringpi.pinMode(light_2,1) wiringpi.pinMode(light_3,1) wiringpi.pinMode(light_4,1) wiringpi.pinMode(light_5,1) wiringpi.pinMode(light_6,1) wiringpi.pinMode(light_7,1) # Set all the leds off to start with. wiringpi.digitalWrite(light_stop,0) wiringpi.digitalWrite(light_store,0) wiringpi.digitalWrite(light_set,0) wiringpi.digitalWrite(light_clear,0) wiringpi.digitalWrite(light_0,0) wiringpi.digitalWrite(light_1,0) wiringpi.digitalWrite(light_2,0) wiringpi.digitalWrite(light_3,0) wiringpi.digitalWrite(light_4,0) wiringpi.digitalWrite(light_5,0) wiringpi.digitalWrite(light_6,0) wiringpi.digitalWrite(light_7,0) # Set the pin mode to an input for all the switches and buttons. wiringpi.pinMode(toggle_off,0) wiringpi.pinMode(toggle_on,0) wiringpi.pinMode(toggle_lock,0) wiringpi.pinMode(toggle_unl,0) wiringpi.pinMode(button_stop,0) wiringpi.pinMode(button_start,0) wiringpi.pinMode(button_store,0) wiringpi.pinMode(button_read,0) wiringpi.pinMode(button_set,0) wiringpi.pinMode(button_display,0) wiringpi.pinMode(button_clear,0) wiringpi.pinMode(button_0,0) wiringpi.pinMode(button_1,0) wiringpi.pinMode(button_2,0) wiringpi.pinMode(button_3,0) wiringpi.pinMode(button_4,0) wiringpi.pinMode(button_5,0) wiringpi.pinMode(button_6,0) wiringpi.pinMode(button_7,0) # Enable the internal pull-ups on all the inputs wiringpi.pullUpDnControl(toggle_off,2) wiringpi.pullUpDnControl(toggle_on,2) wiringpi.pullUpDnControl(toggle_lock,2) wiringpi.pullUpDnControl(toggle_unl,2) wiringpi.pullUpDnControl(button_stop,2) wiringpi.pullUpDnControl(button_start,2) wiringpi.pullUpDnControl(button_store,2) wiringpi.pullUpDnControl(button_read,2) wiringpi.pullUpDnControl(button_set,2) wiringpi.pullUpDnControl(button_display,2) wiringpi.pullUpDnControl(button_clear,2) wiringpi.pullUpDnControl(button_0,2) wiringpi.pullUpDnControl(button_1,2) wiringpi.pullUpDnControl(button_2,2) wiringpi.pullUpDnControl(button_3,2) wiringpi.pullUpDnControl(button_4,2) wiringpi.pullUpDnControl(button_5,2) wiringpi.pullUpDnControl(button_6,2) wiringpi.pullUpDnControl(button_7,2) # Test step = 0 while True: # Check for button presses. if not wiringpi.digitalRead(button_0): wiringpi.digitalWrite(light_0,1) else: wiringpi.digitalWrite(light_0,0) if not wiringpi.digitalRead(button_1): wiringpi.digitalWrite(light_1,1) else: wiringpi.digitalWrite(light_1,0) if not wiringpi.digitalRead(button_2): wiringpi.digitalWrite(light_2,1) else: wiringpi.digitalWrite(light_2,0) if not wiringpi.digitalRead(button_3): wiringpi.digitalWrite(light_3,1) else: wiringpi.digitalWrite(light_3,0) if not wiringpi.digitalRead(button_4): wiringpi.digitalWrite(light_4,1) else: wiringpi.digitalWrite(light_4,0) if not wiringpi.digitalRead(button_5): wiringpi.digitalWrite(light_5,1) else: wiringpi.digitalWrite(light_5,0) if not wiringpi.digitalRead(button_6): wiringpi.digitalWrite(light_6,1) else: wiringpi.digitalWrite(light_6,0) if not wiringpi.digitalRead(button_7): wiringpi.digitalWrite(light_7,1) else: wiringpi.digitalWrite(light_7,0) if not wiringpi.digitalRead(button_stop): wiringpi.digitalWrite(light_stop,1) else: wiringpi.digitalWrite(light_stop,0) if not wiringpi.digitalRead(button_start): wiringpi.digitalWrite(light_stop,1) else: wiringpi.digitalWrite(light_stop,0) if not wiringpi.digitalRead(button_store): wiringpi.digitalWrite(light_store,1) else: wiringpi.digitalWrite(light_store,0) if not wiringpi.digitalRead(button_read): wiringpi.digitalWrite(light_store,1) else: wiringpi.digitalWrite(light_store,0) if not wiringpi.digitalRead(button_set): wiringpi.digitalWrite(light_set,1) else: wiringpi.digitalWrite(light_set,0) if not wiringpi.digitalRead(button_display): wiringpi.digitalWrite(light_set,1) else: wiringpi.digitalWrite(light_set,0) if not wiringpi.digitalRead(button_clear): wiringpi.digitalWrite(light_clear,1) else: wiringpi.digitalWrite(light_clear,0) if not wiringpi.digitalRead(toggle_on): wiringpi.digitalWrite(light_clear,1) else: wiringpi.digitalWrite(light_clear,0) if not wiringpi.digitalRead(toggle_off): wiringpi.digitalWrite(light_set,1) else: wiringpi.digitalWrite(light_set,0) if not wiringpi.digitalRead(toggle_lock): wiringpi.digitalWrite(light_store,1) else: wiringpi.digitalWrite(light_store,0) if not wiringpi.digitalRead(toggle_unl): wiringpi.digitalWrite(light_stop,1) else: wiringpi.digitalWrite(light_stop,0) if step == 0: wiringpi.digitalWrite(light_7,0) wiringpi.digitalWrite(light_0,1) elif step == 1: wiringpi.digitalWrite(light_0,0) wiringpi.digitalWrite(light_1,1) elif step == 2: wiringpi.digitalWrite(light_1,0) wiringpi.digitalWrite(light_2,1) elif step == 3: wiringpi.digitalWrite(light_2,0) wiringpi.digitalWrite(light_3,1) elif step == 4: wiringpi.digitalWrite(light_3,0) wiringpi.digitalWrite(light_4,1) elif step == 5: wiringpi.digitalWrite(light_4,0) wiringpi.digitalWrite(light_5,1) elif step == 6: wiringpi.digitalWrite(light_5,0) wiringpi.digitalWrite(light_6,1) elif step == 7: wiringpi.digitalWrite(light_6,0) wiringpi.digitalWrite(light_7,1) step = (step + 1) % 8 # Wait a bit. sleep(.2)
Sometimes I miss the bad old days where new things seldom worked on the first try and you really had to slog for it, but as is more often than not the case these days everything worked as expected out of the gate (for the exception of the bad LED).
I'm running Eclipse with PyDev for development on my Windows machine using the Remote Systems feature of Eclipse to save the target .py scripts on the Raspberry Pi 4. From there I simply run the programs on the Pi via SSH or VNC.