Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add support for continuous integration in GitHub #1

Open
wants to merge 5 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
51 changes: 51 additions & 0 deletions .github/workflows/ci.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
name: CI for Ex6502

on: push

permissions:
contents: read

jobs:
lint:
name: Code quality for Ex6502
runs-on: ubuntu-latest
strategy:
matrix:
otp: ["26.2.3"]
elixir: ["1.16.2-otp-26"]
env:
MIX_ENV: test

steps:
- name: Checkout
uses: actions/checkout@v4

- name: Setup elixir
uses: erlef/setup-beam@v1
with:
otp-version: ${{ matrix.otp }}
elixir-version: ${{ matrix.elixir }}

- name: Cache deps
uses: actions/cache@v3
with:
key: deps-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock', '**/mix.exs') }}
path: ./deps

- name: Cache build
uses: actions/cache@v3
with:
key: build-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock', '**/mix.exs') }}
path: ./_build

- name: Cache priv
uses: actions/cache@v3
with:
key: priv-${{ runner.os }}-${{ matrix.otp }}-${{ matrix.elixir }}-${{ hashFiles('**/mix.lock', '**/mix.exs') }}
path: ./priv

- run: mix deps.get
- run: mix compile --warnings-as-errors
- run: mix format --check-formatted
- run: mix dialyzer --format github
- run: mix test
3 changes: 3 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,9 @@ erl_crash.dump
# Ignore package tarball (built via "mix hex.build").
ex6502-*.tar

# Ignore dialyzer plt files
/priv/plts/*.plt
/priv/plts/*.plt.hash

# Temporary files for e.g. tests
/tmp
2 changes: 2 additions & 0 deletions dialyzer_ignore.exs
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
[
]
8 changes: 2 additions & 6 deletions lib/ex6502/computer.ex
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
defmodule Ex6502.Computer do
alias Ex6502.{Computer, CPU, Memory}
use Bitwise
import Bitwise

defstruct break: false,
cpu: %Ex6502.CPU{},
Expand All @@ -14,11 +14,7 @@ defmodule Ex6502.Computer do
@reset_vector 0xFFFC

def init(opts \\ []) do
memory =
opts[:memory] ||
with {:ok, memory} <- Memory.init(0xFFFF) do
memory
end
memory = Keyword.get_lazy(opts, :memory, fn -> Memory.init(0xFFFF) end)

%Computer{cpu: CPU.init(), memory: memory}
|> reset()
Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/cpu.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule Ex6502.CPU do
* `$FFFE` - IRQ
"""

use Bitwise
import Bitwise

alias Ex6502.{Computer, CPU}

Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/cpu/executor/adc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,7 @@ defmodule Ex6502.CPU.Executor.ADC do

alias Ex6502.{Computer, CPU, Memory}

use Bitwise
import Bitwise

def execute(%Computer{} = c) do
if CPU.flag(c, :d), do: raise(RuntimeError, "Decimal mode is not yet supported")
Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/cpu/executor/and.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule Ex6502.CPU.Executor.AND do

alias Ex6502.{Computer, CPU, Memory}

use Bitwise
import Bitwise

# AND #$nn Immediate $29
def execute(%Computer{data_bus: 0x29} = c) do
Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/cpu/executor/asl.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule Ex6502.CPU.Executor.ASL do

alias Ex6502.{Computer, CPU, Memory}

use Bitwise
import Bitwise

# ASL A $0A
def execute(%Computer{data_bus: 0x0A} = c) do
Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/cpu/executor/bit.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ defmodule Ex6502.CPU.Executor.BIT do

alias Ex6502.{Computer, CPU, Memory}

use Bitwise
import Bitwise

# BIT #$nn Immediate $29
def execute(%Computer{data_bus: 0x89} = c) do
Expand Down
2 changes: 0 additions & 2 deletions lib/ex6502/cpu/executor/bra.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,6 @@ defmodule Ex6502.CPU.Executor.BRA do
alias Ex6502.{Computer, CPU}
import CPU.Executor.Branching

use Bitwise

# addressing assembler opc bytes cycles
# relative BRA $nnnn 80 2 3 tp
def execute(%Computer{data_bus: 0x80} = c), do: branch(c, true)
Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/cpu/executor/brk.ex
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ defmodule Ex6502.CPU.Executor.BRK do

alias Ex6502.{Computer, CPU}

use Bitwise
import Bitwise

def execute(%Computer{data_bus: 0x00} = c) do
# flow from https://www.pagetable.com/?p=410
Expand Down
2 changes: 0 additions & 2 deletions lib/ex6502/cpu/executor/cmp.ex
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,6 @@ defmodule Ex6502.CPU.Executor.CMP do

alias Ex6502.{Computer, CPU, Memory}

use Bitwise

def execute(%Computer{} = c) do
c
|> do_execute()
Expand Down
2 changes: 0 additions & 2 deletions lib/ex6502/cpu/executor/cpx.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ defmodule Ex6502.CPU.Executor.CPX do

alias Ex6502.{Computer, CPU, Memory}

use Bitwise

def execute(%Computer{} = c) do
c
|> do_execute()
Expand Down
2 changes: 0 additions & 2 deletions lib/ex6502/cpu/executor/cpy.ex
Original file line number Diff line number Diff line change
Expand Up @@ -29,8 +29,6 @@ defmodule Ex6502.CPU.Executor.CPY do

alias Ex6502.{Computer, CPU, Memory}

use Bitwise

def execute(%Computer{} = c) do
c
|> do_execute()
Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/cpu/executor/dec.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule Ex6502.CPU.Executor.DEC do

alias Ex6502.{Computer, CPU, Memory}

use Bitwise
import Bitwise

# This is a special mode that needs its own special function
#
Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/cpu/executor/dex.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule Ex6502.CPU.Executor.DEX do

alias Ex6502.{Computer, CPU}

use Bitwise
import Bitwise

# addressing assembler opc bytes cycles
# implied DEX CA 1 2
Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/cpu/executor/dey.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule Ex6502.CPU.Executor.DEY do

alias Ex6502.{Computer, CPU}

use Bitwise
import Bitwise

# addressing assembler opc bytes cycles
# implied DEY 88 1 2
Expand Down
20 changes: 10 additions & 10 deletions lib/ex6502/cpu/executor/eor.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ defmodule Ex6502.CPU.Executor.EOR do

alias Ex6502.{Computer, CPU, Memory}

use Bitwise
import Bitwise

# EOR #$nn Immediate $49
def execute(%Computer{data_bus: 0x49} = c) do
with %Computer{data_bus: value} = c <- Computer.put_next_byte_on_data_bus(c),
result <- value ^^^ c.cpu.a do
result <- bxor(value, c.cpu.a) do
c
|> CPU.set(:a, result)
|> CPU.set_flags([:n, :z], result)
Expand All @@ -50,7 +50,7 @@ defmodule Ex6502.CPU.Executor.EOR do
def execute(%Computer{data_bus: 0x4D} = c) do
with c <- Computer.put_absolute_address_on_bus(c),
%Computer{data_bus: value} <- Memory.absolute(c),
result <- value ^^^ c.cpu.a do
result <- bxor(value, c.cpu.a) do
c
|> CPU.set(:a, result)
|> CPU.set_flags([:n, :z], :a)
Expand All @@ -61,7 +61,7 @@ defmodule Ex6502.CPU.Executor.EOR do
def execute(%Computer{data_bus: 0x5D} = c) do
with c <- Computer.put_absolute_address_on_bus(c),
%Computer{data_bus: value} <- Memory.absolute(c, c.cpu.x),
result <- value ^^^ c.cpu.a do
result <- bxor(value, c.cpu.a) do
c
|> CPU.set(:a, result)
|> CPU.set_flags([:n, :z], :a)
Expand All @@ -72,7 +72,7 @@ defmodule Ex6502.CPU.Executor.EOR do
def execute(%Computer{data_bus: 0x59} = c) do
with c <- Computer.put_absolute_address_on_bus(c),
%Computer{data_bus: value} <- Memory.absolute(c, c.cpu.y),
result <- value ^^^ c.cpu.a do
result <- bxor(value, c.cpu.a) do
c
|> CPU.set(:a, result)
|> CPU.set_flags([:n, :z], :a)
Expand All @@ -83,7 +83,7 @@ defmodule Ex6502.CPU.Executor.EOR do
def execute(%Computer{data_bus: 0x45} = c) do
with c <- Computer.put_zero_page_on_address_bus(c),
%Computer{data_bus: value} <- Memory.absolute(c),
result <- value ^^^ c.cpu.a do
result <- bxor(value, c.cpu.a) do
c
|> CPU.set(:a, result)
|> CPU.set_flags([:n, :z], :a)
Expand All @@ -94,7 +94,7 @@ defmodule Ex6502.CPU.Executor.EOR do
def execute(%Computer{data_bus: 0x55} = c) do
with c <- Computer.put_zero_page_on_address_bus(c, c.cpu.x),
%Computer{data_bus: value} <- Memory.absolute(c),
result <- value ^^^ c.cpu.a do
result <- bxor(value, c.cpu.a) do
c
|> CPU.set(:a, result)
|> CPU.set_flags([:n, :z], :a)
Expand All @@ -105,7 +105,7 @@ defmodule Ex6502.CPU.Executor.EOR do
def execute(%Computer{data_bus: 0x52} = c) do
with c <- Computer.put_zero_page_on_address_bus(c),
%Computer{data_bus: value} <- Memory.indirect(c),
result <- value ^^^ c.cpu.a do
result <- bxor(value, c.cpu.a) do
c
|> CPU.set(:a, result)
|> CPU.set_flags([:n, :z], :a)
Expand All @@ -116,7 +116,7 @@ defmodule Ex6502.CPU.Executor.EOR do
def execute(%Computer{data_bus: 0x41} = c) do
with c <- Computer.put_zero_page_on_address_bus(c, c.cpu.x),
%Computer{data_bus: value} <- Memory.indirect(c),
result <- value ^^^ c.cpu.a do
result <- bxor(value, c.cpu.a) do
c
|> CPU.set(:a, result)
|> CPU.set_flags([:n, :z], :a)
Expand All @@ -127,7 +127,7 @@ defmodule Ex6502.CPU.Executor.EOR do
def execute(%Computer{data_bus: 0x51} = c) do
with c <- Computer.put_zero_page_on_address_bus(c),
%Computer{data_bus: value} <- Memory.indirect(c, c.cpu.y),
result <- value ^^^ c.cpu.a do
result <- bxor(value, c.cpu.a) do
c
|> CPU.set(:a, result)
|> CPU.set_flags([:n, :z], :a)
Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/cpu/executor/inc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ defmodule Ex6502.CPU.Executor.INC do

alias Ex6502.{Computer, CPU, Memory}

use Bitwise
import Bitwise

# This is a special mode that needs its own special function
#
Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/cpu/executor/inx.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule Ex6502.CPU.Executor.INX do

alias Ex6502.{Computer, CPU}

use Bitwise
import Bitwise

# addressing assembler opc bytes cycles
# implied INX E8 1 2
Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/cpu/executor/iny.ex
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ defmodule Ex6502.CPU.Executor.INY do

alias Ex6502.{Computer, CPU}

use Bitwise
import Bitwise

# addressing assembler opc bytes cycles
# implied INY C8 1 2
Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/cpu/executor/lsr.ex
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ defmodule Ex6502.CPU.Executor.LSR do

alias Ex6502.{Computer, CPU, Memory}

use Bitwise
import Bitwise

# LSR A accumaltor $4A
def execute(%Computer{data_bus: 0x4A} = c) do
Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/cpu/executor/ora.ex
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ defmodule Ex6502.CPU.Executor.ORA do

alias Ex6502.{Computer, CPU, Memory}

use Bitwise
import Bitwise

# ORA #$nn Immediate $09
def execute(%Computer{data_bus: 0x09} = c) do
Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/cpu/executor/rol.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule Ex6502.CPU.Executor.ROL do

alias Ex6502.{Computer, CPU, Memory}

use Bitwise
import Bitwise

# ROL A accumulator $2A
def execute(%Computer{data_bus: 0x2A} = c) do
Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/cpu/executor/ror.ex
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ defmodule Ex6502.CPU.Executor.ROR do

alias Ex6502.{Computer, CPU, Memory}

use Bitwise
import Bitwise

# ROR A accumulator $6A
def execute(%Computer{data_bus: 0x6A} = c) do
Expand Down
4 changes: 2 additions & 2 deletions lib/ex6502/cpu/executor/sbc.ex
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ defmodule Ex6502.CPU.Executor.SBC do

alias Ex6502.{Computer, CPU, Memory}

use Bitwise
import Bitwise

def execute(%Computer{} = c) do
c
Expand Down Expand Up @@ -73,7 +73,7 @@ defmodule Ex6502.CPU.Executor.SBC do
# 7FH (+ 127,0) and 80H with C = 1 (i.e., ‐12810).
#
# see www.righto.com/2012/12/the-6502-overflow-flag-explained.html
|> CPU.set_flag(:v, (c.cpu.a ^^^ result &&& (255 - value) ^^^ result &&& 0x80) != 0)
|> CPU.set_flag(:v, (bxor(c.cpu.a, result) &&& bxor(255 - value, result) &&& 0x80) != 0)
|> CPU.set_flags([:n, :z], :a)
end

Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/cpu/executor/trb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule Ex6502.CPU.Executor.TRB do

alias Ex6502.{Computer, CPU, Memory}

use Bitwise
import Bitwise

# TRB $nnnn absolute $1C
def execute(%Computer{data_bus: 0x1C} = c) do
Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/cpu/executor/tsb.ex
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ defmodule Ex6502.CPU.Executor.TSB do

alias Ex6502.{Computer, CPU, Memory}

use Bitwise
import Bitwise

# TSB $nnnn absolute $0C
def execute(%Computer{data_bus: 0x0C} = c) do
Expand Down
2 changes: 1 addition & 1 deletion lib/ex6502/disassembler.ex
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
defmodule Ex6502.Disassembler do
alias Ex6502.{Computer, Memory}

use Bitwise
import Bitwise

def disassemble(%Computer{cpu: %{pc: pc}, memory: memory}) do
case Memory.get(memory, pc, 3) do
Expand Down
Loading