Skip to content

Commit

Permalink
now compiles on 1.0
Browse files Browse the repository at this point in the history
  • Loading branch information
ExpandingMan committed Aug 23, 2018
1 parent 7f71451 commit b51efed
Show file tree
Hide file tree
Showing 10 changed files with 159 additions and 172 deletions.
2 changes: 1 addition & 1 deletion REQUIRE
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
julia 0.6
julia 1.0
MacroTools
FunctionWrappers
32 changes: 23 additions & 9 deletions src/Sim6502.jl
Original file line number Diff line number Diff line change
@@ -1,16 +1,8 @@
__precompile__(true)

# Note that I expect to use `import` instead of `using` when making the NES emulator

module Sim6502

using MacroTools

import FunctionWrappers: FunctionWrapper

import Base.fetch
import Base.pointer
import Base: +, -
using FunctionWrappers: FunctionWrapper

include("utils.jl")
include("cpu.jl")
Expand All @@ -21,4 +13,26 @@ include("chipset.jl")
include("opcodes.jl")
include("assembler.jl")

export CPU, fetch, store!, counter!, describe, status, status!, status_string
export Memory, Π, Π8, Π16, reset!, dereference, deref, , , store!
export Chipset

export AddressingMode, DirectMode, IndirectMode, Direct, DirectX, DirectY, IndirectX,
IndirectY

export op!, tick!, @assemble


# these are all instruction pieces which probably shouldn't be exported
export ld!, lda!, ldx!, ldy!, st!, sta!, stx!, sty!, t!, tax!, tay!, txa!, tya!,
tsx!, txs!, pha!, php!, pla!, plp!
export and!, eor!, ora!, bit!, adc!, sbc!, compare!, cmp!, cpx!, cpy!
export increment!, inc!, inx!, iny!, decrement!, dec!, dex!, dey!
export arithmetic_shiftleft!, asl!, logical_shiftright!, lsr!, rotateleft!, rol!,
rotateright!, ror!
export jmp!, jsr!, rts!
export bcc!, bcs!, beq!, bmi!, bne!, bpl!, bvc!, bvs!
export clc!, cld!, cli!, clv!, sec!, sed!, sei!, brk!, nop!, rti!


end # module
5 changes: 2 additions & 3 deletions src/assembler.jl
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ end

_assembly_lookup(op::String, mode::Symbol) = ASSEMBLY_DICT[(op,mode)]

_assembly_args(::Void) = nothing
_assembly_args(::Nothing) = nothing
_assembly_args(x::UInt8) = x
_assembly_args(x::UInt16) = reinterpret(UInt8, [x])

Expand All @@ -51,7 +51,7 @@ end


macro assemble(block::Expr)
program = Vector{UInt8}() # for now we'll dynamically allocate
program = Vector{UInt8}(undef) # for now we'll dynamically allocate
if @capture(block, begin instrs__ end)
for instr instrs
assemble!(program, instr)
Expand All @@ -61,4 +61,3 @@ macro assemble(block::Expr)
end
:($program)
end
export @assemble
4 changes: 2 additions & 2 deletions src/boilerplate.jl
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#===================================================================================================
#==============================================================================================
Here we keep some macros for doing boilerplate code generation...
===================================================================================================#
==============================================================================================#
# TODO deal with page crossings!!!

opfuncname(opcode::UInt8) = Symbol(string("op", hexstring(opcode), "!"))
Expand Down
10 changes: 4 additions & 6 deletions src/chipset.jl
Original file line number Diff line number Diff line change
Expand Up @@ -18,15 +18,13 @@ mutable struct Chipset
δt::Float64

clock::Int64

Chipset(c::CPU, m::Memory, δt::AbstractFloat) = new(c, m, δt, 0)
Chipset(c::CPU, m::Memory) = Chipset(c, m, NES_CLOCK_PERIOD)
Chipset() = Chipset(CPU(), Memory())
end
export Chipset


# this is a nu, not a v
Chipset(c::CPU, m::Memory, δt::AbstractFloat) = new(c, m, δt, 0)
Chipset(c::CPU, m::Memory) = Chipset(c, m, NES_CLOCK_PERIOD)
Chipset() = Chipset(CPU(), Memory())

ν(cs::Chipset) = 1.0/cs.δt
ω(cs::Chipset) = 2π/cs.δt

Expand Down
30 changes: 12 additions & 18 deletions src/cpu.jl
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ mutable struct FlagsRegister
Ω::Bool
V::Bool
N::Bool

FlagsRegister() = new(false, false, false, false, false, false, false, false)
end

FlagsRegister() = new(false, false, false, false, false, false, false, false)


mutable struct CPU
A::UInt8 # accumulator register
Expand All @@ -31,16 +31,13 @@ mutable struct CPU
new(A, X, Y, SP, PC, flags)
end
end
export CPU


@inline fetch(c::CPU, reg::Symbol) = getfield(c, reg)

@inline Base.fetch(c::CPU, reg::Symbol) = getfield(c, reg)
@inline store!(c::CPU, reg::Symbol, val::Integer) = setfield!(c, reg, val)
export fetch, store!

counter!(c::CPU, ℓ::Unsigned) = (c.PC += ℓ)
export counter!



function describe(c::CPU)
Expand All @@ -56,15 +53,13 @@ function describe(c::CPU)
$st
"""
end
export describe

import Base.show
Base.show(io::IO, c::CPU) = print(describe(c))


#===================================================================================================
#==============================================================================================
<status register access>
===================================================================================================#
==============================================================================================#
status(fr::FlagsRegister, flag::Symbol)::Bool = getfield(fr, flag)
status(c::CPU, flag::Symbol)::Bool = getfield(fr, flag)

Expand All @@ -80,17 +75,16 @@ function status_string(fr::FlagsRegister)
end
status_string(c::CPU) = status_string(c.flags)

export status, status!, status_string
#===================================================================================================
#==============================================================================================
</status register access>
===================================================================================================#
==============================================================================================#


#===================================================================================================
#==============================================================================================
<special pointers>
===================================================================================================#
==============================================================================================#
stackpointer(c::CPU) = Π(STACK_PAGE + c.SP)
#===================================================================================================
#==============================================================================================
</special pointers>
===================================================================================================#
==============================================================================================#

Loading

0 comments on commit b51efed

Please sign in to comment.