Title: | 6502 Assembler |
---|---|
Description: | A simple 6502 assembler written purely in R and leveraging R data structures for pre-computing character sets and images. |
Authors: | mikefc |
Maintainer: | mikefc <[email protected]> |
License: | file LICENSE |
Version: | 0.1.4 |
Built: | 2024-11-15 04:36:44 UTC |
Source: | https://github.com/coolbutuseless/c64asm |
Regex patterns for parsing 6502 assembly
asm_patterns
asm_patterns
An object of class character
of length 24.
Compile ASM to a c64 exectuable (in PRG format)
compile(asm, prg = TRUE)
compile(asm, prg = TRUE)
asm |
single character string containing all ASM (including newlines) |
prg |
Should compilation return the bytes of the compiled PRG? Default: TRUE. If FALSE, return the main assembler data.frame which is more useful for debugging. |
prg bytes as a raw vector or prg_df
main assembler data.frame
Split each ASM line into tokens
create_line_tokens(asm)
create_line_tokens(asm)
asm |
a single character string containing full ASM code, including newlines |
A list where element contains the tokens for a single row. Rows with just comments or whitespace are discarded
Create the main compiler datastructure 'prg_df' from a list of 'line_tokens'
create_prg_df(line_tokens)
create_prg_df(line_tokens)
line_tokens |
list of line tokens created by 'create_line_tokens()' |
prg_df the main compiler datastructure
Determine the opcode, address mode etc for a sequence of tokens representing a single instruction
create_prg_df_row(tokens)
create_prg_df_row(tokens)
tokens |
A sequence of ASM tokens for one row of the ASM file. |
single row data.frame containing information about the row
Extract the raw bytes for the assembled PRG
extract_prg_bytes(prg_df)
extract_prg_bytes(prg_df)
prg_df |
main assembler data.frame |
raw vector of bytes
Determine the opcode, address mode etc for a sequence of tokens representing a single instruction
get_opcode_info(tokens)
get_opcode_info(tokens)
tokens |
A sequence of ASM tokens. This must start with a valid opcode, and not be a 'symbol' or an assembler directive like '.text' |
single row data.frame containing information about the instruction
Any leading '#' will be dropped. Values prefixed with "$" will be treated as hexadecimal. Values with a leading 'b' will be treated as binary (MSB bit first)
h2i(h)
h2i(h)
h |
character vector of values e.g. "#$1a", "$12", "#127", "#b00111111" |
vector of integers
Fetch the high byte of a 16bit address
hi(address)
hi(address)
address |
address from $0000 to $ffff |
integer value for the high byte of this address
Fetch the low byte of a 16bit address
lo(address)
lo(address)
address |
address from $0000 to $ffff |
integer value for the low byte of this address
A dataset containing opcode information for 6502 instructions
opcodes
opcodes
An object of class tbl_df
(inherits from tbl
, data.frame
) with 217 rows and 15 columns.
http://www.oxyron.de/html/opcodes02.html
Process any cross-referenced symbols to insert actual addresse/values
process_symbols(prg_df)
process_symbols(prg_df)
prg_df |
main assembler data.frame created by 'create_prg_df()' |
udpated prg_df with actual addresses added for each row, and cross-referenced values resolved
Pad out with zero bytes between address blocks
process_zero_padding(prg_df)
process_zero_padding(prg_df)
prg_df |
main assembler data.frame after 'process_symbols()' has been run |
prg_df updated with zero padding rows between address blocks so that every byte from start to finish is accounted for
This is a complete hack to create CBMASCII bytes from plain text
s2i(string)
s2i(string)
string |
single string |
Vector of integers
Save the PRG to file
save_prg(prg_df, filename)
save_prg(prg_df, filename)
prg_df |
main assembler data.frame |
filename |
c64 PRG file to write to |
Convert a 16bit address to 2 bytes (lo_byte, hi_byte) as is the 6502 way
w2b(address)
w2b(address)
address |
address from $0000 to $ffff |
integer vector of length 2 with (lo_byte, hi_byte)