Pages

Tuesday, April 29, 2025

Review: PicoCalc

 The latest handheld gadget from Cockworkpi is the PicoCalc, named for its resemblance to advanced calculators popular amongst people who know more about math than is healthy.


The device comes as a kit that needs assembling, but it is an easy process that took me less than 10 minutes to do. The only thing to watch out for is the screen, during assembly it is easy for it to get misaligned and then when tightening the screws, the screen will get cracked, so when you mount it, tape it into place with some electrical tape to keep it in place.

The core of the PicoCalc is a Raspberry Pi Pico. The kit comes with a Pico version one, do yourself a favor and go buy a Pico 2WH. These are pin compatible, have faster processors, more memory and have wireless networking support. You will need to get different firmware for it, those can be downloaded from the following locations;

PicoMite Basic

MicroPython 

There are other firmware's available, such as uLisp and Lua but I suspect those two will be the most popular and easiest to use.

So here is the thing, the PicoCalc was not designed as a Linux system or a game console, although it can be used for both. I have not tried it as a game console, I am not a gamer so this holds no interest for me. I however did briefly try to run Linux on it. This requires replacing the Pico with a Luckfox Lyra, but honestly, this is not a particularly good idea. The memory and CPU limitations makes it far too weak to do anything particularly useful, even using just the command line. The uConsole or Hackberry Pi are much better for this sort of thing. I am not going to call it useless, but functionally it is not useful for much beyond editing text.

What the PicoCalc was designed for is as a development platform. It is meant to boot straight into MicroPython or PicoMite Basic and running programs through those languages. It is meant to hearken back to the 70's and 80's when computers booted straight to basic. Both of the above firmware's have built in editors for writing your programs, and both can read SD Cards, so programs can be saved there, then loaded and run later. The ability to build a personal library of useful programs without the overhead of a Linux operating system is the strength of the PicoCalc I think.

For me, the big advantage is PicoMite Basic is based on MMBasic, the same Basic used on the Color Maximite systems, which I have discussed before. So I already have a fair library of usable programs, written by myself and others. For instance, Z-mim is a z-code interpreter that can be used to play Zork and other Infocom text adventure games. The author of Z-mim was kind enough to update the code base for me, to work perfectly with the PicoCalc. I have played a lot of Zork 1/2/3 in the last couple of weeks testing his tweaks. As of this writing he has not pushed the updates to his Github site, but I expect him to do so in the near future. Thank you Tom, I greatly appreciate your work.

Overall, I think this is a cool little toy. At the $75 + $25 S&H, I think this is well worth the money if you are into tinkering. Unfortunately Clockworkpi is a Chinese company, so tariffs may affect the price in the near future, so you will have to decide if the increased price is worth it to you or not. I am not sure I would have bought one had I not gotten in under the wire.

Saturday, April 5, 2025

Hamurabi.bas

 Hamurabi.bas was a game we use to play in High School on the PDP-10 in the computer lab. The original code is available all over the internet. As a thought experiment, I decided to update it to a more modern format. I took out the line numbers, used meaningful variable names and replaced the GOTO's and GOSUB's with functions.


'hamurabi.bas
' Original code by Creative Computing, Morristown, New Jersey
' Updated code by Chris Stoddard

Randomize

Dim As Integer year, people, grain, harvest, rats, land, yield, immigrants
Dim As Integer starved, totalStarved, totalPercentStarved
Dim As Integer landPrice, acresToBuy, acresToSell, grainToFeed, acresToPlant
Dim As Integer plagueChance, peopleFed, babies, inputValid
Dim As Double percentStarved

year = 0: people = 95: grain = 2800: harvest = 0: rats = 0
land = 3000: yield = 3: landPrice = 17: immigrants = 5
starved = 0: totalStarved = 0: totalPercentStarved = 0

Sub ThinkAgainGrain(grain As Integer)
    Print "HAMURABI: THINK AGAIN. YOU HAVE ONLY "; grain; " BUSHELS OF GRAIN. NOW THEN,"
End Sub

Sub ThinkAgainLand(land As Integer)
    Print "HAMURABI: THINK AGAIN. YOU OWN ONLY "; land; " ACRES. NOW THEN,"
End Sub

Sub ImpossibleRequest()
    Print : Print "HAMURABI: I CANNOT DO WHAT YOU WISH."
    Print "GET YOURSELF ANOTHER STEWARD!!!!!"
    End
End Sub

Sub Bell()
    For i As Integer = 1 To 10
        Print Chr(7);
    Next
End Sub

For year = 1 To 10
    Print : Print : Print "HAMURABI: I BEG TO REPORT TO YOU,"
    If year > 1 Then
        Print "IN YEAR "; year - 1; ", "; starved; " PEOPLE STARVED, "; immigrants; " CAME TO THE CITY,"
    End If
    people = people + immigrants
    If plagueChance = 0 Then
        people = people \ 2
        Print "A HORRIBLE PLAGUE STRUCK! HALF THE PEOPLE DIED."
    End If
    Print "POPULATION IS NOW "; people
    Print "THE CITY NOW OWNS "; land; " ACRES."
    Print "YOU HARVESTED "; yield; " BUSHELS PER ACRE."
    Print "THE RATS ATE "; rats; " BUSHELS."
    Print "YOU NOW HAVE "; grain; " BUSHELS IN STORE."

    landPrice = Int(Rnd * 10) + 17
    Print "LAND IS TRADING AT "; landPrice; " BUSHELS PER ACRE."

    Do
        inputValid = 1
        Print "HOW MANY ACRES DO YOU WISH TO BUY? ";
        Input "", acresToBuy
        If acresToBuy < 0 Then ImpossibleRequest
        If acresToBuy * landPrice > grain Then
            ThinkAgainGrain(grain)
            inputValid = 0
        End If
    Loop Until inputValid = 1

    If acresToBuy > 0 Then
        land += acresToBuy
        grain -= acresToBuy * landPrice
    Else
        Do
            inputValid = 1
            Print "HOW MANY ACRES DO YOU WISH TO SELL? ";
            Input "", acresToSell
            If acresToSell < 0 Then ImpossibleRequest
            If acresToSell > land Then
                ThinkAgainLand(land)
                inputValid = 0
            End If
        Loop Until inputValid = 1
        land = land - acresToSell
        grain = grain + acresToSell * landPrice
    End If

    Do
        inputValid = 1
        Print "HOW MANY BUSHELS DO YOU WISH TO FEED YOUR PEOPLE? ";
        Input "", grainToFeed
        If grainToFeed < 0 Then ImpossibleRequest
        If grainToFeed > grain Then
            ThinkAgainGrain(grain)
            inputValid = 0
        End If
    Loop Until inputValid = 1
    grain = grain - grainToFeed

    Do
        inputValid = 1
        Print "HOW MANY ACRES DO YOU WISH TO PLANT WITH SEED? ";
        Input "", acresToPlant
        If acresToPlant < 0 Then ImpossibleRequest
        If acresToPlant > land Then
            ThinkAgainLand(land)
            inputValid = 0
        ElseIf acresToPlant \ 2 > grain Then
            ThinkAgainGrain(grain)
            inputValid = 0
        ElseIf acresToPlant > people * 10 Then
            Print "BUT YOU HAVE ONLY "; people; " PEOPLE TO TEND THE FIELDS! NOW THEN,"
            inputValid = 0
        End If
    Loop Until inputValid = 1
    grain = grain - acresToPlant \ 2

    yield = Int(Rnd * 5) + 1
    harvest = acresToPlant * yield
    rats = 0
    If Int(Rnd * 2) = 0 Then
        rats = Int(grain / yield)
    End If
    grain = grain + harvest - rats

    babies = Int(yield * (20 * land + grain) / people / 100 + 1)
    immigrants = babies
    peopleFed = grainToFeed \ 20

    plagueChance = Int(10 * (2 * Rnd - 0.3))

    If peopleFed < people Then
        starved = people - peopleFed
        percentStarved = (100.0 * starved) / people
        If percentStarved > 45 Then
            Print : Print "YOU STARVED "; starved; " PEOPLE IN ONE YEAR!!!"
            Print "DUE TO THIS EXTREME MISMANAGEMENT YOU HAVE NOT ONLY"
            Print "BEEN IMPEACHED AND THROWN OUT OF OFFICE BUT YOU HAVE"
            Print "ALSO BEEN DECLARED NATIONAL FINK!!!!"
            End
        End If
    Else
        starved = 0
    End If

    totalStarved += starved
    totalPercentStarved += percentStarved
    people = people - starved
Next

Dim As Integer acresPerPerson = land \ people
Dim As Integer avgStarved = totalPercentStarved \ 10

Print : Print "IN YOUR 10-YEAR TERM OF OFFICE, "; avgStarved; "% OF THE"
Print "POPULATION STARVED PER YEAR ON THE AVERAGE."
Print "A TOTAL OF "; totalStarved; " PEOPLE DIED!!"
Print "YOU STARTED WITH 10 ACRES PER PERSON AND ENDED WITH"
Print acresPerPerson; " ACRES PER PERSON."

If avgStarved > 33 Or acresPerPerson < 7 Then
    Print "YOU STARVED TOO MANY AND LOST TOO MUCH LAND!"
    Print "YOU HAVE BEEN DECLARED A DISASTER!"
ElseIf avgStarved <= 10 And acresPerPerson >= 9 Then
    Print "A FANTASTIC PERFORMANCE!!! CHARLEMAGNE, DISRAELI, AND"
    Print "JEFFERSON COMBINED COULD NOT HAVE DONE BETTER!"
ElseIf avgStarved > 3 Or acresPerPerson < 10 Then
    Print "YOUR PERFORMANCE COULD HAVE BEEN SOMEWHAT BETTER."
    Print Int(people * 0.8 * Rnd); " PEOPLE WOULD DEARLY LIKE TO SEE YOU ASSASSINATED."
Else
    Print "YOUR HEAVY-HANDED PERFORMANCE SMACKS OF NERO AND IVAN IV."
    Print "THE PEOPLE (REMAINING) FIND YOU AN UNPLEASANT RULER AND,"
    Print "FRANKLY, HATE YOUR GUTS!!"
End If

Bell()
Print : Print "SO LONG FOR NOW."
End