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

View File

@ -7,10 +7,16 @@ module Assembler6502
## This directive to include bytes
class EnterScope < InstructionBase
####
## Try to parse an incbin directive
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_]+)$/)
return nil if match_data.nil?
EnterScope.new(match_data[1])
@ -19,7 +25,7 @@ module Assembler6502
####
## Initialize with filename
def initialize(name)
def initialize(name = nil)
@name = name
end
@ -32,7 +38,9 @@ module Assembler6502
## name as a label, it can return the address when the scope opened.
def exec(assembler)
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