GithubHelp home page GithubHelp logo

davidbuchanan314 / p65a Goto Github PK

View Code? Open in Web Editor NEW
21.0 2.0 0.0 12 KB

Pythonic 6502 Assembler: An experimental alternative to traditional assemblers.

Home Page: https://pypi.org/project/p65a/

License: MIT License

Python 100.00%
6502 6502-assembler 6502-assembly assembler python3 python310

p65a's Introduction

p65a

Pythonic 6502 Assembler: An experimental alternative to traditional assemblers.

At this point I'm unsure whether it's a useful concept or not, but I quite enjoy writing code this way. Consider the API to be unstable.

See the examples/ directory for examples of code written using this library.

Here's a snippet from examples/bootloader.py, which showcases a few nice features:

[...,
	lbl.CRC_LUT_HI,
		Db([crc16(bytes([i])) >> 8 for i in range(0x100)]),
	lbl.CRC_LUT_LO,
		Db([crc16(bytes([i])) & 0xff for i in range(0x100)]),

	lbl.crc_update, # input: A, clobbers: A, Y
		A <= A ^ zp.crc_hi,
		Y <= A,
		A <= zp.crc_lo,
		A <= A  ^ lbl.CRC_LUT_HI[Y],
		zp.crc_hi <= A,
		A <= lbl.CRC_LUT_LO[Y],
		zp.crc_lo <= A,
		RTS(),
...]

This snippet implements a CRC16 checksum function. The lookup tables are generated automagically by Python list comprehensions. Each "line" of assembly is an expression contained within a Python list. The <= operator is overloaded to express assignment.

It is possible to make forward-references to labels. They are treated as symbolic expressions until the layout of code is known (and thus, their concrete value), and then the machine code can finally be finally emitted.

TODO

  • Refactor - there's a lot of code in places it shouldn't be
  • Documentation

p65a's People

Contributors

davidbuchanan314 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.