Page 1 of 1

assembly errors for first "game"

Posted: Tue Nov 27, 2018 5:52 pm
by hellz
making my first game, and it's giving me a bit of trouble,

the error i'm getting is this:
shooter.asm(119): Error: Symbol `enities' is undefined
shooter.asm(120): Note: Expanded from here
make: *** [shooter.nes] Error 1

Code: Select all

.segment "HEADER"

	.byte "NES"
	.byte $1a
	.byte $02			; 4 - 2*16k PRG ROM
	.byte $01			; 5 - 8k CHR ROM
	.byte %00000001		; 6 - mapper - horizontal mirroring
	.byte $00			; 7
	.byte $00			;8 -
	.byte $00			;9 - NTSC
	.byte $00
	; Filler
	.byte $00,$00,$00,$00,$00

.scope EntityType
	NoEntity = 0
	PlayerType = 1
	Bullet = 2
	FlyBy = 3
.endscope

.struct Entity
	xpos .byte
	ypos .byte
	type .byte
.endstruct


.segment "STARTUP"


.segment "ZEROPAGE"
;0x00 - 0xff
controller: .res 1
scrollx: 	.res 1
scrolly:	.res 1
MAXENTITIES = 10
entities:	.res .sizeof(Entity) * MAXENTITIES
TOTALENTITIES = .sizeof(Entity) * MAXENTITIES
buttonflag: .res 1
swap:		.res 1
hswaph:		.res 1
bgloadlo:	.res 1
bgloadhi:	.res 1
bglow:		.res 1
bghi:		.res 1
seed:		.res 2		; initialize 16-bit seed to any value except 0
flicker:	.res 1
spritemem:	.res 2


.segment "CODE"

prng:
	ldx #8		;iteration count (generates 8 bits)
	lda seed+0
:
	asl			;shift the register
	rol seed+1
	bcc :+
	eor #$2D	;apply XOR feedback whenever a 1 bit is shifted out
:
	dex
	bne :--
	sta seed+0
	cmp #0		;reload flags
	rts

WAITFORVBLANK:
	bit $2002
	bpl WAITFORVBLANK
	rts

RESET:
	sei
	cld
	ldx #$40
	stx $4017
	ldx #$ff
	txs
	inx
	stx $2000
	stx $2001
	stx $4010

	jsr WAITFORVBLANK

	txa

CLEARMEM:
	sta $0000, x
	sta $0100, x
	sta $0300, x
	sta $0400, x
	sta $0500, x
	sta $0600, x
	sta $0700, x
	lda #$ff
	sta $0200, x
	lda #$00
	sta controller
	inx
	bne CLEARMEM

	lda #$21
	sta hswaph

; initialize entities+Entity::xpos
	lda #$80
	sta entities+Entity::xpos
	lda #$78
	sta entities+Entity::ypos
	lda #EntityType::PlayerType
	sta entities+Entity::type

	ldx #$03
	lda #$ff
CLEARENTITIES:
	sta enities+Entity::xpos, x
	sta enities+Entity::ypos, x
	lda #$00
	sta entities+Entity::type, x
	lda #$ff
	inx ; faster to do 3 increments than an add bc 2 less cycles
	inx
	inx
	cpx #TOTALENTITIES
	bne CLEARENTITIES

;clear register and set
;palette address
	lda $2002
	lda #$3f
	sta $2006
	lda #$10
	sta $2006

;init bg hi and lo

	lda #$10
	sta seed
	sta seed+1

	lda #$02
	sta scrolly


	ldx #$00
	
PALETTELOAD:
	lda PALETTE, x
	sta $2007
	inx
	cpx #$20
	bne PALETTELOAD

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

	lda #$c0
	sta bgloadlo
	lda #$03
	sta bgloadhi
	ldy #$00

	lda $2002
	lda #$20
	sta $2006
	lda #$00
	sta $2006

BGLOAD:
	jsr prng
	lsr
	sta $2007
	iny
	cpy #$00
	bne SKIPBGINC
	inc bghi

SKIPBGINC:
	dec bgloadlo
	lda bgloadlo
	cmp #$ff
	bne BGLOAD
	dec bgloadhi
	lda bgloadhi
	cmp #$ff
	bne BGLOAD

;config for loading attr
	lda $2002
	lda #$23
	sta $2006
	lda #$c0
	sta $2006
	ldx #$00
	txa
ATTLOAD:
	sta $2007
	inx
	cpx #$08
	bne ATTLOAD

	jsr WAITFORVBLANK

	lda #%10000000
	sta $2000
	lda #%00011110
	sta $2001

FOREVER:
	jmp FOREVER

VBLANK:
;todo: rework so game engine code in main exec &
;only handle graphic update in VBLANK
	lda #$02
	sta $07ff

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

;begin populating OAM data in mem
	ldx #$00
	lda #$00
	ldy #$00
	sta spritemem
	lda #$02
	sta spritemem+1

DRAWENTITIES:
	lda entities+Entity::type, x
	cmp #EntityType::PlayerType
	beq PLAYERSPRITE
	cmp #EntityType::Bullet
	beq BULLET
	jmp CHECKENDSPRITE

BULLET:
	lda entities+Entity::ypos, x ; y
	sta (spritemem), y
	iny
	lda #$01 ;tile
	sta (spritemem), y
	iny
	lda #$02 ;palette etc
	sta (spritemem), y
	iny
	lda entities+Entity::xpos, x; ; x
	sta (spritemem), y
	iny
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

	jmp CHECKENDSPRITE

FLYBY:
PLAYERSPRITE:
	;tl sprite
	lda entities+Entity::ypos, x ; y
	sta (spritemem), y
	iny
	lda #$00 ;tile
	sta (spritemem), y
	iny
	lda #$01 ;palette etc
	sta (spritemem), y
	iny
	lda entities+Entity::xpos, x; ; x
	sta (spritemem), y
	iny

	;bl sprite
	lda entities+Entity::ypos, x ; y
	clc
	adc #$08
	sta (spritemem), y
	iny
	lda #$10 ; tile
	sta (spritemem), y
	iny
	lda #$01 ; palette etc
	sta (spritemem), y
	iny
	lda entities+Entity::xpos, x; ; x
	sta (spritemem), y
	iny

	;tr sprite
	lda entities+Entity::ypos, x ; y
	sta (spritemem), y
	iny
	lda #$00 ; tile
	sta (spritemem), y
	iny
	lda #$41 ; palette etc
	sta (spritemem), y
	iny
	lda entities+Entity::xpos, x; ; x
	clc
	adc #$08
	sta (spritemem), y
	iny

	lda entities+Entity::ypos, x ; y
	clc
	adc #$08
	sta (spritemem), y
	iny
	lda #$10 ; tile
	sta (spritemem), y
	iny
	lda #$41 ; palette etc
	sta (spritemem), y
	iny
	lda entities+Entity::xpos, x; ; x
	clc
	adc #$08
	sta (spritemem), y
	iny
	;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
CHECKENDSPRITE:
	txa
	clc
	adc #.sizeof(Entity)
	tax
	cpx #TOTALENTITIES
	beq DONESPRITE
	jmp DRAWENTITIES

DONESPRITE:
	inc flicker
	lda flicker
	and #$0c
	bne noflicker

	inc hswaph
	lda hswaph
	cmp #$23
	bne skiproll
	lda #$21
	sta hswaph

skiproll:

;clear reg & set
;palette address
	lda $2002
	lda #$3f
	sta $2006
	lda #$17
	sta $2006

	lda hswaph
	sta $2007

noflicker:

; DMA copy sprites
	lda #$00
	sta $2003 ;reset counter
	lda #$02  ;set mem to $0200 range
	sta $4014
	nop		  ;improve scan sync

	lda #$00  ;clear reg
	sta $2006
	sta $2006

	lda scrollx
	sta $2005
	lda scrolly
	sta $2005

	lda #%10001000
	ora swap
	ldx $2002 ; clear reg before reset bc were in vblank
	sta $2000

donewithppu:
	lda #$01
	sta $07ff

INITALIZESPRITES:
	ldy #$00
	lda #$ff
INITIALIZESPRITESLOOP:
	sta (spritemem), y
	iny
	eor #$ff
	sta (spritemem), y
	iny
	sta (spritemem), y
	iny
	eor #$ff
	sta (spritemem), y
	iny
	beq startreadcontrollers
	jmp INITIALIZESPRITESLOOP

startreadcontrollers:

	;read controls
	lda #$01
	sta $4016
	lda #$00
	sta $4016

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

readcontrollerbuttons:

	lda $4016		;a
	ror A
	rol controller
	lda $4016		;b
	ror A
	rol controller
	lda $4016		;select
	ror A
	rol controller
	lda $4016		;start
	ror A
	rol controller
	lda $4016		;up
	ror A
	rol controller
	lda $4016		;down
	ror A
	rol controller
	lda $4016		;left
	ror A
	rol controller
	lda $4016		;right
	ror A
	rol controller

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

checkleft:

	lda controller
	and #$02
	beq checkright
	dec entities+Entity::xpos
	jmp checkup ; dont allow l & r at same time

checkright:

	lda controller
	and #$01
	beq checkup
	inc entities+Entity::xpos

checkup:
	
	lda controller
	and #$04
	beq checkdown
	dec entities+Entity::ypos
	jmp donecheckingdirectional ;dont allow u & d at same time

checkdown:

	lda controller
	and #$04
	beq donecheckingdirectional
	inc entities+Entity::ypos

donecheckingdirectional:

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
checkbuttons:

checka:
	lda controller
	and #$80
	beq checkarelease
	lda buttonflag
	ora #$01
	sta buttonflag
	jmp finishcontrols
checkarelease:
	lda buttonflag
	and #$01
	beq finishcontrols
	dec buttonflag ; a works bc its bit 1
	jmp addbullet
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
addbullet:
	nop
	nop
	nop
	nop
	ldx #$00
addbulletloop:
	cpx #TOTALENTITIES-.sizeof(Entity)  ;stop here bc were interested in up to 1c, but dont wanna go past
	beq finishcontrols					;if we hit max, no more available entities for this
	lda entities+Entity::type, x 		;get entity type from mem
	cmp #EntityType::NoEntity			;is this a used entity slot?
	beq addbulletentity					;if its free, add bullet
	txa 								;if not, increment to next entity & loop
	clc
	adc #.sizeof(Entity)
	tax
	jmp addbulletloop			;end loop
addbulletentity:
	lda entities+Entity::xpos
	clc
	adc #$04
	sta entities+Entity::xpos, x
	lda entities+Entity::ypos
	sta entities+Entity::ypos, x
	lda #EntityType::Bullet
	sta entities+Entity::type, x
	jmp finishcontrols
;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
finishcontrols:
processcrolling:
	lda scrolly
	sec
	sbc #$02
	sta scrolly
	cmp #$00
	bne donescroll
	lda #$ee
	sta scrolly
	lda swap
	eor #$02
	sta swap
donescroll:

processentities:
	ldx #.sizeof(Entity)
processentitiesloop:
	lda entities+Entity::type, x
	cmp #EntityType::Bullet
	bne skipentity
processbullet:
	lda entities+Entity::ypos, x
	sec
	sbc #$03
	sta entities+Entity::ypos, x
	bcs entitycomplete
	lda #EntityType::NoEntity
	sta entities+Entity::type, x
	lda #$ff
	sta entities+Entity::xpos, x
	sta entities+Entity::ypos, x
entitycomplete:
skipentity:
	txa
	clc
	adc #.sizeof(Entity)
	tax
	cmp #$1e
	bne processentitiesloop
doneprocessingentities:

	rti

PALETTE:
	.byte $0d, $30, $16, $27
	.byte $0d, $00, $10, $12
	.byte $0d, $0c, $1c, $3c
	.byte $0d, $00, $10, $12
	.byte $0d, $00, $10, $12
	.byte $0d, $00, $10, $12
	.byte $0d, $00, $10, $12
	.byte $0d, $00, $10, $12


.segment "VECTORS"
	.word VBLANK
	.word RESET
	.word 0

.segment "CHARS"
	.incbin "shooter.chr"

Re: assembly errors for first "game"

Posted: Tue Nov 27, 2018 5:56 pm
by tokumaru
You did write "enities" instead of "entities", maybe it's just a typo.

Re: assembly errors for first "game"

Posted: Tue Nov 27, 2018 6:23 pm
by hellz
really? sublime isn't picking that up.

*EDIT*

wait nvm, i thought you said i put in "entites" it does pick up several instances of "enities" i'll fix it now and see if it helps.

Re: assembly errors for first "game"

Posted: Wed Nov 28, 2018 4:25 am
by Sumez
Time to build that intellisense IDE for CA65 :3

Re: assembly errors for first "game"

Posted: Wed Nov 28, 2018 7:11 am
by hellz
IKR? i might post some more things on here if i have new problems...like now, i finally managed to make the file, but my emulator just shows a black screen.

idk how to debug with Nestopia tho.

Re: assembly errors for first "game"

Posted: Wed Nov 28, 2018 7:30 am
by tepples
Nestopia does not include a debugger. Use Mesen or FCEUX (Windows version).

Re: assembly errors for first "game"

Posted: Thu Nov 29, 2018 1:50 pm
by cpow
Sumez wrote:Time to build that intellisense IDE for CA65 :3
Yep. I'ma add that to nesicide tonight. :beer:
https://qscintilla.com/general-autocompletion/

Re: assembly errors for first "game"

Posted: Fri Nov 30, 2018 2:16 am
by Sumez
Neat!

Re: assembly errors for first "game"

Posted: Fri Nov 30, 2018 8:37 am
by Banshaku
@cpow

A little bit off topic but how is nesicide these days? I didn't follow for years so I'm a little late on the news ;)