Memory map generator

Last Updated or created 2022-08-15

Started to write a program to generate a memory map like this

It will be a python script which generates a ascii table.

| a15 | a14 | a13 | a12 | a11 | a10 | a09 | a08 | a07 | a06 | a05 | a04 | a03 | a02 | a01 | a00 |
|  1  |  a  |  a  |  a  |  a  |  a  |  a  |  a  |  a  |  a  |  a  |  a  |  a  |  a  |  a  |  a  | ROM
|  0  |  0  |  a  |  a  |  a  |  a  |  a  |  a  |  a  |  a  |  a  |  a  |  a  |  a  |  a  |  a  | RAM
|  0  |  1  |  1  |  x  |  x  |  x  |  x  |  x  |  x  |  x  |  x  |  x  |  a  |  a  |  a  |  a  | VIA
|  0  |  0  |  0  |  0  |  0  |  0  |  0  |  1  |  a  |  a  |  a  |  a  |  a  |  a  |  a  |  a  | PS

Above example shows:

  • Rom – $8000 and up
  • Ram – $0000 till $3FFF
  • Via chip – $6xxx-$7xxxx 16 addresses repeating in this block.
    This will be the interesting/hard part
  • Program stack – in RAM – $0100-$01FF

Generated output

| 0000 | ram |     |     |      |      |
| 00ff | ram |     |     |      |      |
| 0100 | ram |     | ps  |      |      |
| 01ff | ram |     | ps  |      |      |
| 0200 | ram |     |     |      |      |
| 3fff | ram |     |     |      |      |
| 4000 |     |     |     |      |      |
| 5fff |     |     |     |      |      |
| 6000 |     |     |     | via1 |      |
| 6fff |     |     |     | via1 |      |
| 7000 |     |     |     |      | via2 |
| 7fff |     |     |     |      | via2 |
| 8000 |     | rom |     |      |      |
| ffff |     | rom |     |      |      |
#!/bin/python

# 0 = address should be 0 .. Duh
# 1 = address should be 1 .. Duh
# a = address 0 or 1
# x = not connected, future function

# try
#via1 = ["0","1","1","0","x","x","x","x","x","x","0","x","a","a","a","a"]

rom = ["1","a","a","a","a","a","a","a","a","a","a","a","a","a","a","a"]
ram = ["0","0","a","a","a","a","a","a","a","a","a","a","a","a","a","a"]
via1 = ["0","1","1","0","x","x","x","x","x","x","x","x","a","a","a","a"]
via2 = ["0","1","1","1","x","x","x","x","x","x","x","x","a","a","a","a"]
ps  = ["0","0","0","0","0","0","0","1","a","a","a","a","a","a","a","a"]

counter = 0
prevhexw = f"{0:04x}"

prevram = "nix"
prevrom = "nix"
prevps = "nix"
prevvia1 = "nix"
prevvia2 = "nix"

while counter < 65536:
    binw = f"{counter:016b}"
    hexw = f"{counter:04x}"
    binint = bin(int(counter))
    address=0

    ramcheck=0    
    romcheck=0    
    pscheck=0
    via1check=0
    via2check=0

    printram = "   "
    printrom = "   "
    printps = "   "
    printvia1 = "    "
    printvia2 = "    "
    myram=ram.copy()
    myrom=rom.copy()
    myps=ps.copy()
    myvia1=via1.copy()
    myvia2=via2.copy()
    while address < 16:

        if myram[address] == "a":
            myram[address]=binw[address]
        if myram[address] == "x":
            myram[address]=binw[address]
        if myram[address] != binw[address]:
            ramcheck=1

        if myrom[address] == "a":
            myrom[address]=binw[address]
        if myrom[address] == "x":
            myrom[address]=binw[address]
        if myrom[address] != binw[address]:
            romcheck=1

        if myps[address] == "a":
            myps[address]=binw[address]
        if myps[address] == "x":
            myps[address]=binw[address]
        if myps[address] != binw[address]:
            pscheck=1

        if myvia1[address] == "a":
            myvia1[address]=binw[address]
        if myvia1[address] == "x":
            myvia1[address]=binw[address]
        if myvia1[address] != binw[address]:
            via1check=1

        if myvia2[address] == "a":
            myvia2[address]=binw[address]
        if myvia2[address] == "x":
            myvia2[address]=binw[address]
        if myvia2[address] != binw[address]:
            via2check=1


        address=address+1

    if ramcheck==0:
        printram="ram"
    if romcheck==0:
        printrom="rom"
    if pscheck==0:
        printps="ps "
    if via1check==0:
        printvia1="via1"
    if via2check==0:
        printvia2="via2"


    if prevram != printram or prevrom != printrom or prevps != printps or prevvia1 != printvia1 or prevvia2 != printvia2:
        printlinep = f"| {prevhexw} | {prevram} | {prevrom} | {prevps} | {prevvia1} | {prevvia2} |"
        printline = f"| {hexw} | {printram} | {printrom} | {printps} | {printvia1} | {printvia2} |"
        if prevram != "nix":
            print(printlinep)
        print(printline)
    prevram=printram
    prevrom=printrom
    prevps=printps
    prevvia1=printvia1
    prevvia2=printvia2
    prevhexw=hexw
    counter=counter+1;
printline = f"| {hexw} | {printram} | {printrom} | {printps} | {printvia1} | {printvia2} |"
print(printline)
Spread the love