1
0
mirror of https://github.com/safiire/n65.git synced 2025-03-03 01:30:07 +00:00

Updated the demo, realized anonymous scopes don't work right :(

This commit is contained in:
Safiire 2015-03-05 17:21:51 -08:00
parent 8f2500dd60
commit dfb4410497
2 changed files with 35 additions and 20 deletions

View File

@ -25,10 +25,10 @@ sprite:
.dw irq .dw irq
.org $C000
;;;; ;;;;
; Here is our code entry point, which we'll call main. ; Here is our code entry point, which we'll call main.
main: .org $C000
.scope main
; Disable interrupts and decimal flag ; Disable interrupts and decimal flag
sei sei
cld cld
@ -74,40 +74,43 @@ main:
cli cli
forever: forever:
jmp forever jmp forever
.
;;;; ;;;;
; Set basic PPU registers. Load background from $0000, ; Set basic PPU registers. Load background from $0000,
; sprites from $1000, and the name table from $2000. ; sprites from $1000, and the name table from $2000.
init_ppu: .scope init_ppu
lda #$88 lda #$88
sta $2000 sta $2000
lda #$1E lda #$1E
sta $2001 sta $2001
rts rts
.
;;;; ;;;;
; Initialize all the sprites, palettes, nametables, and scrolling ; Initialize all the sprites, palettes, nametables, and scrolling
init_graphics: .scope init_graphics
jsr init_sprites jsr init_sprites
jsr load_palette jsr load_palette
jsr load_name_tables jsr load_name_tables
jsr init_scrolling jsr init_scrolling
rts rts
.
;;;; ;;;;
; Initialize the controller input, keeping track of the A button ; Initialize the controller input, keeping track of the A button
init_input: .scope init_input
lda #$00 lda #$00
sta $01 ; $01 = A button sta $01 ; $01 = A button
rts rts
.
;;;; ;;;;
; Initialize the APU to known values ; Initialize the APU to known values
init_sound: .scope init_sound
; initialize sound hardware
lda #$01 lda #$01
sta $4015 sta $4015
lda #$00 lda #$00
@ -115,13 +118,14 @@ init_sound:
lda #$40 lda #$40
sta $4017 sta $4017
rts rts
.
;;;; ;;;;
; Clear page #2, which we'll use to hold sprite data ; Clear page #2, which we'll use to hold sprite data
; This subroutine clearly shows why I need to have symbols ; This subroutine clearly shows why I need to have symbols
; to refer to bits of RAM in the zero page like dx, etc. ; to refer to bits of RAM in the zero page like dx, etc.
init_sprites: .scope init_sprites
lda #$00 lda #$00
ldx #$00 ldx #$00
sprite_clear1: sprite_clear1:
@ -140,26 +144,28 @@ init_sprites:
lda #$01 lda #$01
sta $00 ; dx = $00 sta $00 ; dx = $00
rts rts
.
;;;; ;;;;
; Load palette into $3F00 ; Load palette into $3F00
load_palette: .scope load_palette
lda #$3F lda #$3F
ldx #$00 ldx #$00
sta $2006 sta $2006
stx $2006 stx $2006
loady_loop: loop:
lda palette, X lda palette, X
sta $2007 sta $2007
inx inx
cpx #$20 cpx #$20
bne loady_loop bne loop
rts rts
.
;;;; ;;;;
; Put the ASCII values from bg into the first name table, at $2400 ; Put the ASCII values from bg into the first name table, at $2400
; The tile values are conveniently mapped to their ASCII values ; The tile values are conveniently mapped to their ASCII values
load_name_tables: .scope load_name_tables
ldy #$00 ldy #$00
ldx #$04 ldx #$04
lda #<bg lda #<bg
@ -170,14 +176,14 @@ load_name_tables:
sta $2006 sta $2006
lda #$00 lda #$00
sta $2006 sta $2006
go_back: loop:
lda ($10), Y lda ($10), Y
sta $2007 sta $2007
iny iny
bne go_back bne loop
inc $11 inc $11
dex dex
bne go_back bne loop
; This now clears the second name table? ; This now clears the second name table?
; I think this is because writing to $2007 auto increments the ; I think this is because writing to $2007 auto increments the
; written value ; written value
@ -191,15 +197,17 @@ load_name_tables:
dex dex
bne back bne back
rts rts
.
;;;; ;;;;
; This initializes the scrolling storing the scroll ; This initializes the scrolling storing the scroll
; value in the zero page variable $02 ; value in the zero page variable $02
init_scrolling: .scope init_scrolling
lda #$F0 lda #$F0
sta $02 sta $02
rts rts
.
;;;; ;;;;
@ -217,7 +225,6 @@ update_sprite:
jsr high_c jsr high_c
jmp edge_done jmp edge_done
hit_left: hit_left:
ldx #$01 ldx #$01
stx $00 ; dx stx $00 ; dx

View File

@ -7,10 +7,16 @@ module Assembler6502
## This directive to include bytes ## This directive to include bytes
class EnterScope < InstructionBase class EnterScope < InstructionBase
#### ####
## Try to parse an incbin directive ## Try to parse an incbin directive
def self.parse(line) def self.parse(line)
## Anonymous scope
match_data = line.match(/^\.scope$/)
unless match_data.nil?
EnterScope.new
end
## Named scope
match_data = line.match(/^\.scope\s+([a-zA-Z][a-zA-Z0-9_]+)$/) match_data = line.match(/^\.scope\s+([a-zA-Z][a-zA-Z0-9_]+)$/)
return nil if match_data.nil? return nil if match_data.nil?
EnterScope.new(match_data[1]) EnterScope.new(match_data[1])
@ -19,7 +25,7 @@ module Assembler6502
#### ####
## Initialize with filename ## Initialize with filename
def initialize(name) def initialize(name = nil)
@name = name @name = name
end end
@ -32,7 +38,9 @@ module Assembler6502
## name as a label, it can return the address when the scope opened. ## name as a label, it can return the address when the scope opened.
def exec(assembler) def exec(assembler)
assembler.symbol_table.enter_scope(@name) assembler.symbol_table.enter_scope(@name)
assembler.symbol_table.define_symbol("-#{@name}", assembler.program_counter) unless @name.nil?
assembler.symbol_table.define_symbol("-#{@name}", assembler.program_counter)
end
end end