6502cloud

Bringing the 80's to the cloud

Have you ever wanted to process your data in 6502 assembly? Well now you can.

Sample program using the API.

Requires py65 to assemble, and requests to handle the HTTPS request. Also assume Python2.7.
import cStringIO
import base64
import json
import py65.assembler
from py65.devices.mpu65c02 import MPU as MPU65C02
import requests

# Small method to assemble a small prg
def assemble(prg, start_address):
    # Take the prg and turn it into a IO device.
    asm = py65.assembler.Assembler(MPU65C02())
    prg_io = cStringIO.StringIO(prg)

    pc = start_address
    bytes = []
    for line in prg_io.readlines():
        data = asm.assemble(line, pc)
        pc += len(data)
        bytes.append(data)

    return [ byte for inst in bytes for byte in inst]

# Small test prg
test_code = """LDA #$01
               STA $0200
               LDA #$05
               STA $0201
               LDA #$08
               STA $0202"""

mem = assemble(test_code, 0xc000)

# Encode it in base64 for the 6502cloud
prg = base64.standard_b64encode("".join([chr(i) for i in mem]))

url="https://api.6502cloud.com/v2/6502cloud/"

# Build the request
reqdata = {
        "input" : [
            {
                "start_address" : "c000",
                "data" : prg,
            }
        ],
        "output" : {
            "start_address" : "0200",
            "end_address" : "02ff",
        },
        "execute_address" : "c000",
}

# Execute it on the cloud!
resp = requests.post(url, json.dumps(reqdata))

# Extract the result memory
result_memory = json.loads(resp.content)['memory']

# Decode the base64, and convert into numbers
result_memory = [ord(i) for i in base64.standard_b64decode(result_memory)]

# build a string to print out
output = ""
for i in range(len(result_memory)):
    if i % 16 == 0:
        output += "\n"

    if i % 8 == 0 :
        output += "  "

    output += "%02x " % result_memory[i]

# Print the results.
print output

Sample assembly to use the storage kernel functions

.start $C000

LDA #$29    
LDX #$00    
DEX         
STA $2000,X 
STA $2100,X 
STA $2200,X 
STA $2300,X 
STA $2400,X 
STA $2500,X 
STA $2600,X 
STA $2700,X 
STA $2800,X 
STA $2900,X 
STA $2a00,X 
STA $2b00,X 
STA $2c00,X 
STA $2d00,X 
STA $2e00,X 
STA $2f00,X 
BNE $c002   
LDA #$20    
JSR $FF00   
BNE $C04C   
LDA #$80    
JSR $FF02   
BNE $C04C   
JSR $FF04   
BNE $C04C   
LDA #$00