mirror of
https://github.com/safiire/n65.git
synced 2025-03-03 16:29:07 +00:00
Added Bank switching code
This commit is contained in:
parent
a48ce496e8
commit
21af1f0bf6
@ -3,12 +3,12 @@ require_relative '../instruction_base'
|
|||||||
|
|
||||||
module N65
|
module N65
|
||||||
|
|
||||||
|
|
||||||
####
|
####
|
||||||
## This directive instruction can setup an ines header
|
## This directive instruction can setup an iNES header
|
||||||
class INESHeader < InstructionBase
|
class INESHeader < InstructionBase
|
||||||
attr_reader :prog, :char, :mapper, :mirror
|
attr_reader :prog, :char, :mapper, :mirror, :battery_backed, :fourscreen_vram, :prog_ram, :tv
|
||||||
|
|
||||||
|
Defaults = {prog: 1, char: 0, mapper: 0, mirror: 0, battery_backed: 0, fourscreen_vram: 0, prog_ram: 0, tv: 0}
|
||||||
|
|
||||||
####
|
####
|
||||||
## Implementation of the parser for this directive
|
## Implementation of the parser for this directive
|
||||||
@ -17,14 +17,36 @@ module N65
|
|||||||
return nil if match_data.nil?
|
return nil if match_data.nil?
|
||||||
|
|
||||||
header = JSON.parse(match_data[1])
|
header = JSON.parse(match_data[1])
|
||||||
INESHeader.new(header['prog'], header['char'], header['mapper'], header['mirror'])
|
header = header.inject({}) do |hash, (key, val)|
|
||||||
|
hash[key.to_sym] = val
|
||||||
|
hash
|
||||||
|
end
|
||||||
|
|
||||||
|
header = Defaults.merge(header)
|
||||||
|
|
||||||
|
INESHeader.new(
|
||||||
|
header[:prog],
|
||||||
|
header[:char],
|
||||||
|
header[:mapper],
|
||||||
|
header[:mirror],
|
||||||
|
header[:battery_backed],
|
||||||
|
header[:fourscreen_vram],
|
||||||
|
header[:prog_ram],
|
||||||
|
header[:tv])
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
####
|
####
|
||||||
## Construct a header
|
## Construct a header
|
||||||
def initialize(prog, char, mapper, mirror)
|
def initialize(prog, char, mapper, mirror, battery_backed, fourscreen_vram, prog_ram, tv)
|
||||||
@prog, @char, @mapper, @mirror = prog, char, mapper, mirror
|
@prog = prog
|
||||||
|
@char = char
|
||||||
|
@mapper = mapper
|
||||||
|
@mirror = mirror
|
||||||
|
@battery_backed = battery_backed
|
||||||
|
@fourscreen_vram = fourscreen_vram
|
||||||
|
@prog_ram = prog_ram
|
||||||
|
@tv = tv
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
@ -36,16 +58,38 @@ module N65
|
|||||||
|
|
||||||
|
|
||||||
####
|
####
|
||||||
## Emit the header bytes, this is not exactly right, but it works for now.
|
## Emit the header bytes
|
||||||
def emit_bytes
|
def emit_bytes
|
||||||
[0x4E, 0x45, 0x53, 0x1a, @prog, @char, @mapper, @mirror, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
|
|
||||||
|
mapper_lo_nybble = (@mapper & 0x0f)
|
||||||
|
mapper_hi_nybble = (@mapper & 0xf0) >> 4
|
||||||
|
|
||||||
|
flag6 = 0
|
||||||
|
flag6 |= 0x1 if @mirror == 1
|
||||||
|
flag6 |= 0x2 if @battery_backed == 1
|
||||||
|
flag6 |= 0x8 if @fourscreen_vram == 1
|
||||||
|
flag6 |= (mapper_lo_nybble << 4)
|
||||||
|
|
||||||
|
flag7 = 0
|
||||||
|
flag7 |= (mapper_hi_nybble << 4)
|
||||||
|
|
||||||
|
[0x4E, 0x45, 0x53, 0x1a,
|
||||||
|
@prog & 0xff,
|
||||||
|
@char & 0xff,
|
||||||
|
flag6 & 0xff,
|
||||||
|
flag7 & 0xff,
|
||||||
|
@prog_ram & 0xff,
|
||||||
|
0x0, 0x0, 0x0, 0x0, 0x0, 0x0, 0x0]
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
####
|
####
|
||||||
## Display
|
## Display
|
||||||
def to_s
|
def to_s
|
||||||
".ines {\"prog\": #{@prog}, \"char\": #{@char}, \"mapper\": #{@mapper}, \"mirror\": #{@mirror}}"
|
[".ines {\"prog\": #{@prog}, \"char\": #{@char}, \"mapper\": #{@mapper}, ",
|
||||||
|
"\"mirror\": #{@mirror}}, \"battery_backed\": #{@battery_backed}, ",
|
||||||
|
"\"fourscreen_vram\": #{@fourscreen_vram}, \"prog_ram\": #{@prog_ram}, ",
|
||||||
|
"\"tv\": #{@tv}"].join
|
||||||
end
|
end
|
||||||
|
|
||||||
end
|
end
|
||||||
|
@ -1,3 +1,3 @@
|
|||||||
module N65
|
module N65
|
||||||
VERSION ||= "1.0.0"
|
VERSION ||= "1.1.0"
|
||||||
end
|
end
|
||||||
|
Loading…
x
Reference in New Issue
Block a user