Improved readability of theloop.py (ROMv1 native code)

Using, learning, programming and modding the Gigatron and anything related.
Forum rules
Be nice. No drama.
Post Reply
User avatar
marcelk
Posts: 488
Joined: 13 May 2018, 08:26

Improved readability of theloop.py (ROMv1 native code)

Post by marcelk »

This weekend I reworked the Python code that emits the EPROM image (issue #14).

Historically, from the first Fibonacci algorithm and the first video loops on the breadboard prototype, we've used Python notation for assembly. This way we didn't have to write an assembler, but more importantly, we got a free macro assembler and that is really required for the job. This ad-hoc framework was grown bottom-up and got expanded all the way to implementing vCPU, the ROM loader, the audio system, the built-in applications and eventually the release of ROM v1. During that time we never considered the readability of the source syntax. We knew it was poor, but it worked for us. Now is time for big cleanups. As of today, theloop.py (I will rename it later to ROMv1.py) contains no more unintelligible eaYXregOUTIX, busRAM, zp(), lo(), ...etc ... anywhere.

For comparison, before we wrote things like this:

Old:

Code: Select all

# Update LEDs (memory is present and counted, reset is stable)
ld(val(0b0001));                C('LEDs |*OOO|')
ld(val(syncBits^hSync),regOUT)
ld(val(syncBits),regOUT)

# Scan the entire RAM space to collect entropy for a random number generator.
# The 16-bit address space is scanned, even if less RAM was detected.
ld(val(0));                     C('Collect entropy from RAM')
st(d(vAC+0),busAC|ea0DregX)
st(d(vAC+1),busAC|ea0DregY)
That generated the following code:

Code: Select all

ld   $01         ;LEDs |*OOO|
ld   $80,out
ld   $c0,out
ld   $00         ;Collect entropy from RAM
st   [$18],x
st   [$19],y
The new notation is much closer to that.
New:

Code: Select all

# Update LEDs (memory is present and counted, reset is stable)
ld(0b0001);                     C('LEDs |*OOO|')
ld(syncBits^hSync, OUT)
ld(syncBits, OUT)

# Scan the entire RAM space to collect entropy for a random number generator.
# The 16-bit address space is scanned, even if less RAM was detected.
ld(0);                          C('Collect entropy from RAM')
st([vAC+0], X)
st([vAC+1], Y)
The huge disassembly (theloop.asm) is still being generated for those who want to look at a clean listing. In fact, the system is still generating exactly the same object code.

I feel this updated notation is finally quite workable now. One of the next big steps will be to untangle the GCL compiler even more. (Issue #16)
Post Reply