mirror of
https://github.com/safiire/n65.git
synced 2024-12-22 02:31:05 +00:00
Linted utils
This commit is contained in:
parent
4123bf0b06
commit
dbeaf4170a
@ -13,6 +13,9 @@ Style/Documentation:
|
|||||||
Lint/MissingSuper:
|
Lint/MissingSuper:
|
||||||
Enabled: false
|
Enabled: false
|
||||||
|
|
||||||
|
Style/ParallelAssignment:
|
||||||
|
Enabled: false
|
||||||
|
|
||||||
Layout/EmptyLinesAroundAttributeAccessor:
|
Layout/EmptyLinesAroundAttributeAccessor:
|
||||||
Enabled: true
|
Enabled: true
|
||||||
|
|
||||||
|
@ -1,91 +1,89 @@
|
|||||||
#!/usr/bin/env ruby
|
#!/usr/bin/env ruby
|
||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
###############################################################################
|
##############################################################################
|
||||||
## http://www.6502.org/tutorials/6502opcodes.html
|
# From http://www.6502.org/tutorials/6502opcodes.html
|
||||||
## This web page has information about each and every 6502 instruction
|
# This web page has information about each and every 6502 instruction
|
||||||
## Specifically:
|
# Specifically:
|
||||||
##
|
#
|
||||||
## - Description of what each of the instructions do
|
# - Description of what each of the instructions do
|
||||||
## - Which modes are supported by which instructions, immediate, zero page
|
# - Which modes are supported by which instructions, immediate, zero page
|
||||||
## zero page x, and y, absolute, indirect, relative etc.
|
# zero page x, and y, absolute, indirect, relative etc.
|
||||||
## - The hex codes each instruction assembles to, in each mode.
|
# - The hex codes each instruction assembles to, in each mode.
|
||||||
## - The lengths in bytes of each instruction, by mode
|
# - The lengths in bytes of each instruction, by mode
|
||||||
## - The possibly variable number of cycles each instruction takes.
|
# - The possibly variable number of cycles each instruction takes.
|
||||||
##
|
#
|
||||||
## There are 56 of them, and in my programmer laziness I just wrote this
|
# There are 56 of them, and in my programmer laziness I just wrote this
|
||||||
## script to parse the page into the data structure that you see in
|
# script to parse the page into the data structure that you see in
|
||||||
## opcodes.yaml. This really helped in creating the assembler, and
|
# opcodes.yaml. This really helped in creating the assembler, and
|
||||||
## it had basically everything I needed to know, and sped up writing
|
# it had basically everything I needed to know, and sped up writing
|
||||||
## this by huge factor. So, yay to this page, and this script!
|
# this by huge factor. So, yay to this page, and this script!
|
||||||
|
|
||||||
require 'yaml'
|
require 'yaml'
|
||||||
|
|
||||||
## Instruction name, and output structure to fill in.
|
# Instruction name, and output structure to fill in.
|
||||||
name = :adc
|
name = :adc
|
||||||
output = {name => {}}
|
output = { name: {} }
|
||||||
|
|
||||||
## Copy paste the tables from that website into this heredoc:
|
# Copy paste the tables from that website into this heredoc:
|
||||||
text =<<-TEXT
|
text = <<~'TEXT'
|
||||||
Immediate ADC #$44 $69 2 2
|
Immediate ADC #$44 $69 2 2
|
||||||
Zero Page ADC $44 $65 2 3
|
Zero Page ADC $44 $65 2 3
|
||||||
Zero Page,X ADC $44,X $75 2 4
|
Zero Page,X ADC $44,X $75 2 4
|
||||||
Absolute ADC $4400 $6D 3 4
|
Absolute ADC $4400 $6D 3 4
|
||||||
Absolute,X ADC $4400,X $7D 3 4+
|
Absolute,X ADC $4400,X $7D 3 4+
|
||||||
Absolute,Y ADC $4400,Y $79 3 4+
|
Absolute,Y ADC $4400,Y $79 3 4+
|
||||||
Indirect,X ADC ($44,X) $61 2 6
|
Indirect,X ADC ($44,X) $61 2 6
|
||||||
Indirect,Y ADC ($44),Y $71 2 5+
|
Indirect,Y ADC ($44),Y $71 2 5+
|
||||||
TEXT
|
TEXT
|
||||||
|
|
||||||
|
# And now iterate over each line to extract the info
|
||||||
## And now iterate over each line to extract the info
|
|
||||||
lines = text.split(/\n/)
|
lines = text.split(/\n/)
|
||||||
lines.each do |line|
|
lines.each do |line|
|
||||||
|
# Grab out the values we care about
|
||||||
## Grab out the values we care about
|
|
||||||
parts = line.split
|
parts = line.split
|
||||||
cycles, len, hex = parts[-1], parts[-2], parts[-3]
|
cycles, len, hex = parts[-1], parts[-2], parts[-3]
|
||||||
hex = "0x%X" % hex.gsub('$', '').to_i(16)
|
hex = format('0x%X', hex.gsub('$', '').to_i(16))
|
||||||
|
|
||||||
match_data = cycles.match(/([0-9]+)(\+?)/)
|
match_data = cycles.match(/([0-9]+)(\+?)/)
|
||||||
cycles = match_data[1]
|
cycles = match_data[1]
|
||||||
boundary = match_data[2]
|
boundary = match_data[2]
|
||||||
hash = {:hex => hex, :len => len, :cycles => cycles, :boundry_add => boundary != ""}
|
hash = { hex: hex, len: len, cycles: cycles, boundry_add: boundary != '' }
|
||||||
|
|
||||||
## And now decide which mode the line belongs to, collecting each listed mode
|
# And now decide which mode the line belongs to, collecting each listed mode
|
||||||
hash = case line
|
hash = case line
|
||||||
when /^Accumulator/
|
when /^Accumulator/
|
||||||
{:accumulator => hash}
|
{ accumulator: hash }
|
||||||
when /^Immediate/
|
when /^Immediate/
|
||||||
{:immediate => hash}
|
{ immediate: hash }
|
||||||
when /^Zero Page,X/
|
when /^Zero Page,X/
|
||||||
{:zero_page_x => hash}
|
{ zero_page_x: hash }
|
||||||
when /^Zero Page,Y/
|
when /^Zero Page,Y/
|
||||||
{:zero_page_y => hash}
|
{ zero_page_y: hash }
|
||||||
when /^Zero Page/
|
when /^Zero Page/
|
||||||
{:zero_page => hash}
|
{ zero_page: hash }
|
||||||
when /^Absolute,X/
|
when /^Absolute,X/
|
||||||
{:absolute_x => hash}
|
{ absolute_x: hash }
|
||||||
when /^Absolute,Y/
|
when /^Absolute,Y/
|
||||||
{:absolute_y => hash}
|
{ absolute_y: hash }
|
||||||
when /^Absolute/
|
when /^Absolute/
|
||||||
{:absolute => hash}
|
{ absolute: hash }
|
||||||
when /^Indirect,X/
|
when /^Indirect,X/
|
||||||
{:indirect_x => hash}
|
{ indirect_x: hash }
|
||||||
when /^Indirect,Y/
|
when /^Indirect,Y/
|
||||||
{:indirect_y => hash}
|
{ indirect_y: hash }
|
||||||
when /^Indirect/
|
when /^Indirect/
|
||||||
{:indirect => hash}
|
{ indirect: hash }
|
||||||
when /^Implied/
|
when /^Implied/
|
||||||
{:implied => hash}
|
{ implied: hash }
|
||||||
else
|
else
|
||||||
{}
|
{}
|
||||||
end
|
end
|
||||||
output[name].merge!(hash)
|
output[name].merge!(hash)
|
||||||
end
|
end
|
||||||
|
|
||||||
## Now output some yaml, and I only had to do this about 45 times
|
# Now output some yaml, and I only had to do this about 45 times
|
||||||
## instead of laboriously and mistak-pronely doing it by hand.
|
# instead of laboriously and mistak-pronely doing it by hand.
|
||||||
puts YAML.dump(output).gsub("'", '')
|
puts YAML.dump(output).gsub("'", '')
|
||||||
|
|
||||||
## See opcodes.yaml
|
# See opcodes.yaml
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user