mirror of
https://github.com/safiire/n65.git
synced 2024-12-12 00:29:03 +00:00
Added scope directive
This commit is contained in:
parent
419617382b
commit
4edbff55a5
@ -13,7 +13,7 @@ module Assembler6502
|
||||
def self.parse(line)
|
||||
match_data = line.match(/^\.ascii\s+"([^"]+)"$/)
|
||||
return nil if match_data.nil?
|
||||
ASCII.new($1)
|
||||
ASCII.new(match_data[1])
|
||||
end
|
||||
|
||||
|
||||
|
42
lib/directives/enter_scope.rb
Normal file
42
lib/directives/enter_scope.rb
Normal file
@ -0,0 +1,42 @@
|
||||
require_relative '../instruction_base'
|
||||
|
||||
module Assembler6502
|
||||
|
||||
|
||||
####
|
||||
## This directive to include bytes
|
||||
class EnterScope < InstructionBase
|
||||
|
||||
|
||||
####
|
||||
## Try to parse an incbin directive
|
||||
def self.parse(line)
|
||||
match_data = line.match(/^\.scope\s+([a-zA-Z][a-zA-Z0-9_]+)$/)
|
||||
return nil if match_data.nil?
|
||||
EnterScope.new(match_data[1])
|
||||
end
|
||||
|
||||
|
||||
####
|
||||
## Initialize with filename
|
||||
def initialize(name)
|
||||
@name = name
|
||||
end
|
||||
|
||||
|
||||
####
|
||||
## Execute on the assembler
|
||||
def exec(assembler)
|
||||
assembler.symbol_table.enter_scope(@name)
|
||||
end
|
||||
|
||||
|
||||
####
|
||||
## Display
|
||||
def to_s
|
||||
".scope #{@name}"
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
35
lib/directives/exit_scope.rb
Normal file
35
lib/directives/exit_scope.rb
Normal file
@ -0,0 +1,35 @@
|
||||
require_relative '../instruction_base'
|
||||
|
||||
module Assembler6502
|
||||
|
||||
|
||||
####
|
||||
## This directive to include bytes
|
||||
class ExitScope < InstructionBase
|
||||
|
||||
|
||||
####
|
||||
## Try to parse an incbin directive
|
||||
def self.parse(line)
|
||||
match_data = line.match(/^\.$/)
|
||||
return nil if match_data.nil?
|
||||
ExitScope.new
|
||||
end
|
||||
|
||||
|
||||
####
|
||||
## Execute on the assembler
|
||||
def exec(assembler)
|
||||
assembler.symbol_table.exit_scope
|
||||
end
|
||||
|
||||
|
||||
####
|
||||
## Display
|
||||
def to_s
|
||||
"."
|
||||
end
|
||||
|
||||
end
|
||||
|
||||
end
|
@ -10,6 +10,8 @@ module Assembler6502
|
||||
require_relative 'directives/bytes'
|
||||
require_relative 'directives/ascii'
|
||||
require_relative 'directives/label'
|
||||
require_relative 'directives/enter_scope'
|
||||
require_relative 'directives/exit_scope'
|
||||
|
||||
|
||||
####
|
||||
@ -22,7 +24,7 @@ module Assembler6502
|
||||
class CannotParse < StandardError; end
|
||||
|
||||
|
||||
Directives = [INESHeader, Org, Segment, IncBin, DW, Bytes, ASCII]
|
||||
Directives = [INESHeader, Org, Segment, IncBin, DW, Bytes, ASCII, EnterScope, ExitScope]
|
||||
|
||||
####
|
||||
## Parses a line of program source into an object
|
||||
|
31
scope.asm
Normal file
31
scope.asm
Normal file
@ -0,0 +1,31 @@
|
||||
;;;;
|
||||
; Create an iNES header
|
||||
.ines {"prog": 1, "char": 0, "mapper": 0, "mirror": 0}
|
||||
|
||||
;;;;
|
||||
;; Start a prog segment number 0
|
||||
.segment prog 0
|
||||
.org $8000
|
||||
|
||||
.scope yay
|
||||
main:
|
||||
sei
|
||||
cld
|
||||
loop:
|
||||
ldx $00
|
||||
inx
|
||||
stx $00
|
||||
jmp loop
|
||||
.
|
||||
|
||||
vblank:
|
||||
irq:
|
||||
rti
|
||||
|
||||
;;;;
|
||||
;; Vector table
|
||||
.org $FFFA
|
||||
|
||||
.dw vblank
|
||||
.dw yay.main
|
||||
.dw irq
|
Loading…
Reference in New Issue
Block a user