关于VC2022与NESasm

VC 2022是c语言编译器。 NESASM是任天堂红白机程序的汇编程序。学习版的VC编译 nesasm.通不过,其原因是。原标准库列为不安全文件报错,加“_CRT_SECURE_NO_WARNINGS” 宏通过编译器,和link程序类型不符,偷了一个懒下了一个最新版的NESASM,编任天堂6502机顺利通过。nesasm 原来是linux下使用的。用VC60会通过。可怜的电脑使用环境。学习版总会不清白。

一个源文件例子 enemy.bas

array enemy_x		2
array enemy_y		2
array enemy_xoff	2
array enemy_yoff	2
array enemy_type	2
array enemy_status 2

enemysetup:
	set enemy_type  1
	set enemy_xoff  8
	set enemy_yoff  0
	set enemy_x  3
	set enemy_y  3
	set enemy_dir 0
	set enemy_frame 0
	set which_enemy 0
	set maxenemies 0 //number of enemies -1
	set goomba_feet 0
	set deadsecs 6
	set deadframes 120
	return

enemyhandler:
	set enemy_typevar enemy_type
	gosub goomba_move
//	for which_enemy = 0 to maxenemies
//		set enemy_typevar [ enemy_type which_enemy ]
//		if enemy_typevar = 1 gosub goomba_move
//	next which_enemy
	return

//requires which_enemy
goomba_move:
	if enemy_frame <> 0 goto goomba_move_2
	if enemy_dir = 255 goto goomba_dead
	if enemy_dir = 0 then
		gosub goomba_request_right
		goto goomba_move_2
		endif
	if enemy_dir = 1
		gosub goomba_request_left
goomba_move_2:
	gosub goomba_request_fall
	inc enemy_frame
	if enemy_frame = 4 set enemy_frame 0
	set enemy_sprite 20
	if + screen_x 1 > enemy_x then
		set enemy_yloc 241
		goto goomba_move_3
		endif
	if + screen_x 14 <= enemy_x then
		set enemy_yloc 241
		goto goomba_move_3
		endif
	set enemy_tile 12
	set enemy_yloc + << enemy_y 4 enemy_yoff
	set enemy_xloc + << - enemy_x screen_x 4 - enemy_xoff screen_xoff
goomba_move_3:
	if goomba_feet < 12 then
		set enemy_colorbit 2
		gosub draw_enemy
		endif
	if goomba_feet >= 12 then
		set enemy_colorbit 66
		gosub draw_enemy_reverse
		endif
	inc goomba_feet
	if goomba_feet = 24 set goomba_feet 0
	return

goomba_dead:
	gosub goomba_request_fall
	set enemy_colorbit %10000010
	set enemy_yloc + << enemy_y 4 enemy_yoff
	if + screen_x 14 <= enemy_x set enemy_yloc 245 //hide off-screen
	if + screen_x 1 > enemy_x set enemy_yloc 245 //hide off-screen
	set enemy_xloc + << - enemy_x screen_x 4 - enemy_xoff screen_xoff
	gosub draw_enemy
	dec deadframes
	if deadframes = 0 then
		set deadframes 120
		dec deadsecs
		if deadsecs = 0 then
			set deadsecs 6
			set enemy_dir 1
			endif
		endif
	return

goomba_request_right:
	set idx + + << enemy_y 4 enemy_x 1
	set collide_right [ leveldata idx ]
	if enemy_x >= 16 set collide_right [ leveldata2 idx ]
goomba_request_right_2:
	if collide_right = 0 then
		inc enemy_xoff
		if enemy_xoff = 16 then
			set enemy_xoff 0
			inc enemy_x
			endif
		return
		endif
	set enemy_dir 1 //go left now
	return

goomba_request_left:
	set idx + << enemy_y 4 enemy_x
	set collide_left [ leveldata idx ]
	if enemy_x >= 16 set collide_left [ leveldata2 idx ]
	if collide_left = 0 then
		dec enemy_xoff
		if enemy_xoff = 255 then
			set enemy_xoff 15
			dec enemy_x
			endif
		return
		endif
	set enemy_dir 0 //go right now
	return

goomba_request_fall:
	set idx + + << enemy_y 4 enemy_x 16
	set collide_down [ leveldata idx ]
	if enemy_x >= 16 then
		set idx - idx 16
		set collide_down [ leveldata2 idx ]
		endif
	if collide_down = 0 then
		inc enemy_yoff
		if enemy_yoff = 16 then
			set enemy_yoff 0
			inc enemy_y
			endif
		return
		endif
	return

draw_enemies:
	for which_enemy = 0 to maxenemies
		set enemy_typevar [ enemy_type which_enemy ]
		if enemy_typevar = 1 gosub draw_enemy
	next which_enemy
	return

//requires enemy_sprite, enemy_tile, enemy_xloc, enemy_yloc, enemy_colorbit
draw_enemy:
	set [ spritemem 16 ] enemy_yloc
	set [ spritemem 17 ] enemy_tile
	set [ spritemem 18 ] enemy_colorbit
	set [ spritemem 19 ] enemy_xloc

	set [ spritemem 20 ] enemy_yloc
	set [ spritemem 21 ] + enemy_tile 2
	set [ spritemem 22 ] enemy_colorbit
	set [ spritemem 23 ] + enemy_xloc 8
	return

draw_enemy_reverse:
	set [ spritemem 16 ] enemy_yloc
	set [ spritemem 17 ] + enemy_tile 2
	set [ spritemem 18 ] enemy_colorbit
	set [ spritemem 19 ] enemy_xloc

	set [ spritemem 20 ] enemy_yloc
	set [ spritemem 21 ] enemy_tile
	set [ spritemem 22 ] enemy_colorbit
	set [ spritemem 23 ] + enemy_xloc 8
	return

enemytest.asm

spritemem=0
nbasic_temp2=256
reset_game=257
joya=258
joyb=259
joyup=260
joydown=261
joyright=262
joyleft=263
joyselect=264
joystart=265
frame=266
inflight=267
direction=268
facing=269
i=270
scrollval=271
screen_x=272
screen_xoff=273
sack_x=274
sack_xoff=275
spritex=276
sack_x2=277
spritey=278
sack_sprite=279
sack_moveframe=280
musicframe=281
notelength=282
whichnote=283
enemy_x=284
enemy_y=286
enemy_xoff=288
enemy_yoff=290
enemy_type=292
enemy_status=294
enemy_dir=296
enemy_frame=297
which_enemy=298
maxenemies=299
goomba_feet=300
deadsecs=301
deadframes=302
enemy_typevar=303
enemy_sprite=304
enemy_yloc=305
enemy_tile=306
nbasic_temp=307
enemy_xloc=308
enemy_colorbit=309
idx=310
collide_right=311
collide_left=312
collide_down=313
sack_dead_secs=314
sack_dead_frames=315
is_crouching=316
okjump=317
collide_low=318
collide_top=319
gravindex=320
gravity_delta=321
collide_y1=322
collide_y2=323
collide_x1=324
collide_x2=325
collide_result=326
column_read=327
which_column=329
my_x=330
temp_column=331
highbyte=332
lowbyte=333
numcolumns=334
.inesprg 2
.ineschr 1
.inesmir 1
.inesmap 0

.org $8000
.bank 0
.db $ff,$ff,$ff,$ff,0,0,0,0,0,0,0,0,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,0,0,0,0,0,0,0,0
.db $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,0,0,0,0,0,0,0,0
.db $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,0,0,0,0,0,0,0,0
.db $ff,$ff,$ff,$ff

start:
jsr initsound
jsr vwait
lda #48
sta $2000
lda #4
sta $2001
jsr palette
jsr clearsprites
jsr varsetup
jsr musicsetup
jsr enemysetup
jsr vwait
jsr loadbackground
lda #48
sta $2000
lda #28
sta $2001
mainloop:
jsr joystick
jsr joyhandler
jsr jumphandler
jsr enemyhandler
jsr drawsack
jsr musicloop
jsr vwait
jsr drawstuff
lda #1
sta nbasic_temp2
lda reset_game
cmp nbasic_temp2
bne nbasic_autolabel1
jmp start
nbasic_autolabel1:
jmp mainloop
varsetup:
lda #0
sta joya
lda #0
sta joyb
lda #0
sta joyup
lda #0
sta joydown
lda #0
sta joyright
lda #0
sta joyleft
lda #0
sta joyselect
lda #0
sta joystart
lda #0
sta frame
lda #2
sta inflight
lda #0
sta direction
lda #1
sta facing
lda #0
sta i
lda #0
sta scrollval
lda #0
sta screen_x
lda #0
sta screen_xoff
lda #2
sta sack_x
lda #0
sta sack_xoff
lda sack_x
asl a
asl a
asl a
asl a
sta spritex
lda spritex
sta sack_x2
lda #60
sta spritey
lda #0
sta reset_game
lda #32
sta sack_sprite
lda #0
sta sack_moveframe
rts
initsound:
lda #0
sta $4015
lda #31
sta $4015
rts
musicsetup:
lda #0
sta musicframe
lda #0
sta notelength
lda #0
sta whichnote
rts
musicloop:
lda #0
sta nbasic_temp2
lda notelength
cmp nbasic_temp2
beq nbasic_autolabel2
dec notelength
rts
nbasic_autolabel2:
lda #91
sta nbasic_temp2
lda whichnote
cmp nbasic_temp2
bmi nbasic_autolabel3
lda #0
sta whichnote
nbasic_autolabel3:
ldx whichnote
lda musicdata, x
sta notelength
lda #0
sta nbasic_temp2
lda notelength
cmp nbasic_temp2
bne nbasic_autolabel4
inc whichnote
ldx whichnote
lda musicdata, x
sta notelength
inc whichnote
lda #0
sta $4004
sta $4005
sta $4006
sta $4007
rts
nbasic_autolabel4:
inc whichnote
ldx whichnote
lda musicdata, x
sta $4004
inx
lda musicdata, x
sta $4005
inx
lda musicdata, x
sta $4006
inx
lda musicdata, x
sta $4007
inx
lda whichnote
clc
adc #4
sta whichnote
rts
musicdata:
.db 23,145,0,253,48
.db 22,145,0,239,48
.db 23,145,0,201,48
.db 22,145,0,190,48
.db 23,145,0,201,48
.db 22,145,0,239,48
.db 23,145,0,253,48
.db 22,145,0,239,48
.db 23,145,0,201,48
.db 22,145,0,190,48
.db 23,145,0,201,48
.db 22,145,0,239,48
.db 23,145,0,253,48
.db 23,145,0,239,48
.db 0,22
.db 22,145,0,253,48
.db 23,145,0,239,48
.db 0,22
.db 23,145,0,239,48
.db 0,22
enemysetup:
lda #1
sta enemy_type
lda #8
sta enemy_xoff
lda #0
sta enemy_yoff
lda #3
sta enemy_x
lda #3
sta enemy_y
lda #0
sta enemy_dir
lda #0
sta enemy_frame
lda #0
sta which_enemy
lda #0
sta maxenemies
lda #0
sta goomba_feet
lda #6
sta deadsecs
lda #120
sta deadframes
rts
enemyhandler:
lda enemy_type
sta enemy_typevar
jsr goomba_move
rts
goomba_move:
lda #0
sta nbasic_temp2
lda enemy_frame
cmp nbasic_temp2
beq nbasic_autolabel5
jmp goomba_move_2
nbasic_autolabel5:
lda #255
sta nbasic_temp2
lda enemy_dir
cmp nbasic_temp2
bne nbasic_autolabel6
jmp goomba_dead
nbasic_autolabel6:
lda #0
sta nbasic_temp2
lda enemy_dir
cmp nbasic_temp2
bne nbasic_autolabel7
jsr goomba_request_right
jmp goomba_move_2
nbasic_autolabel7:
lda #1
sta nbasic_temp2
lda enemy_dir
cmp nbasic_temp2
bne nbasic_autolabel8
jsr goomba_request_left
nbasic_autolabel8:
goomba_move_2:
jsr goomba_request_fall
inc enemy_frame
lda #4
sta nbasic_temp2
lda enemy_frame
cmp nbasic_temp2
bne nbasic_autolabel9
lda #0
sta enemy_frame
nbasic_autolabel9:
lda #20
sta enemy_sprite
lda enemy_x
sta nbasic_temp2
lda screen_x
clc
adc #1
cmp nbasic_temp2
bmi nbasic_autolabel10
beq nbasic_autolabel10
lda #241
sta enemy_yloc
jmp goomba_move_3
nbasic_autolabel10:
lda enemy_x
sta nbasic_temp2
lda screen_x
clc
adc #14
cmp nbasic_temp2
bpl nbasic_autolabel11
lda #241
sta enemy_yloc
jmp goomba_move_3
nbasic_autolabel11:
lda #12
sta enemy_tile
lda enemy_y
asl a
asl a
asl a
asl a
clc
adc enemy_yoff
sta enemy_yloc
lda enemy_x
sec
sbc screen_x
asl a
asl a
asl a
asl a
pha
lda enemy_xoff
sec
sbc screen_xoff
sta nbasic_temp
pla
clc
adc nbasic_temp
sta enemy_xloc
goomba_move_3:
lda #12
sta nbasic_temp2
lda goomba_feet
cmp nbasic_temp2
bpl nbasic_autolabel12
beq nbasic_autolabel12
lda #2
sta enemy_colorbit
jsr draw_enemy
nbasic_autolabel12:
lda #12
sta nbasic_temp2
lda goomba_feet
cmp nbasic_temp2
bmi nbasic_autolabel13
lda #66
sta enemy_colorbit
jsr draw_enemy_reverse
nbasic_autolabel13:
inc goomba_feet
lda #24
sta nbasic_temp2
lda goomba_feet
cmp nbasic_temp2
bne nbasic_autolabel14
lda #0
sta goomba_feet
nbasic_autolabel14:
rts
goomba_dead:
jsr goomba_request_fall
lda #130
sta enemy_colorbit
lda enemy_y
asl a
asl a
asl a
asl a
clc
adc enemy_yoff
sta enemy_yloc
lda enemy_x
sta nbasic_temp2
lda screen_x
clc
adc #14
cmp nbasic_temp2
bpl nbasic_autolabel15
lda #245
sta enemy_yloc
nbasic_autolabel15:
lda enemy_x
sta nbasic_temp2
lda screen_x
clc
adc #1
cmp nbasic_temp2
bmi nbasic_autolabel16
beq nbasic_autolabel16
lda #245
sta enemy_yloc
nbasic_autolabel16:
lda enemy_x
sec
sbc screen_x
asl a
asl a
asl a
asl a
pha
lda enemy_xoff
sec
sbc screen_xoff
sta nbasic_temp
pla
clc
adc nbasic_temp
sta enemy_xloc
jsr draw_enemy
dec deadframes
lda #0
sta nbasic_temp2
lda deadframes
cmp nbasic_temp2
bne nbasic_autolabel17
lda #120
sta deadframes
dec deadsecs
lda #0
sta nbasic_temp2
lda deadsecs
cmp nbasic_temp2
bne nbasic_autolabel18
lda #6
sta deadsecs
lda #1
sta enemy_dir
nbasic_autolabel18:
nbasic_autolabel17:
rts
goomba_request_right:
lda enemy_y
asl a
asl a
asl a
asl a
clc
adc enemy_x
clc
adc #1
sta idx
ldx idx
lda leveldata, x
sta collide_right
lda #16
sta nbasic_temp2
lda enemy_x
cmp nbasic_temp2
bmi nbasic_autolabel19
ldx idx
lda leveldata2, x
sta collide_right
nbasic_autolabel19:
goomba_request_right_2:
lda #0
sta nbasic_temp2
lda collide_right
cmp nbasic_temp2
bne nbasic_autolabel20
inc enemy_xoff
lda #16
sta nbasic_temp2
lda enemy_xoff
cmp nbasic_temp2
bne nbasic_autolabel21
lda #0
sta enemy_xoff
inc enemy_x
nbasic_autolabel21:
rts
nbasic_autolabel20:
lda #1
sta enemy_dir
rts
goomba_request_left:
lda enemy_y
asl a
asl a
asl a
asl a
clc
adc enemy_x
sta idx
ldx idx
lda leveldata, x
sta collide_left
lda #16
sta nbasic_temp2
lda enemy_x
cmp nbasic_temp2
bmi nbasic_autolabel22
ldx idx
lda leveldata2, x
sta collide_left
nbasic_autolabel22:
lda #0
sta nbasic_temp2
lda collide_left
cmp nbasic_temp2
bne nbasic_autolabel23
dec enemy_xoff
lda #255
sta nbasic_temp2
lda enemy_xoff
cmp nbasic_temp2
bne nbasic_autolabel24
lda #15
sta enemy_xoff
dec enemy_x
nbasic_autolabel24:
rts
nbasic_autolabel23:
lda #0
sta enemy_dir
rts
goomba_request_fall:
lda enemy_y
asl a
asl a
asl a
asl a
clc
adc enemy_x
clc
adc #16
sta idx
ldx idx
lda leveldata, x
sta collide_down
lda #16
sta nbasic_temp2
lda enemy_x
cmp nbasic_temp2
bmi nbasic_autolabel25
lda idx
sec
sbc #16
sta idx
ldx idx
lda leveldata2, x
sta collide_down
nbasic_autolabel25:
lda #0
sta nbasic_temp2
lda collide_down
cmp nbasic_temp2
bne nbasic_autolabel26
inc enemy_yoff
lda #16
sta nbasic_temp2
lda enemy_yoff
cmp nbasic_temp2
bne nbasic_autolabel27
lda #0
sta enemy_yoff
inc enemy_y
nbasic_autolabel27:
rts
nbasic_autolabel26:
rts
draw_enemies:
lda #0
sta which_enemy
nbasic_autolabel28:
ldx which_enemy
lda enemy_type, x
sta enemy_typevar
lda #1
sta nbasic_temp2
lda enemy_typevar
cmp nbasic_temp2
bne nbasic_autolabel29
jsr draw_enemy
nbasic_autolabel29:
sta nbasic_temp
inc which_enemy
lda which_enemy
cmp nbasic_temp
bmi nbasic_autolabel28
beq nbasic_autolabel28
rts
draw_enemy:
ldx #16
lda enemy_yloc
sta spritemem, x
ldx #17
lda enemy_tile
sta spritemem, x
ldx #18
lda enemy_colorbit
sta spritemem, x
ldx #19
lda enemy_xloc
sta spritemem, x
ldx #20
lda enemy_yloc
sta spritemem, x
ldx #21
lda enemy_tile
clc
adc #2
sta spritemem, x
ldx #22
lda enemy_colorbit
sta spritemem, x
ldx #23
lda enemy_xloc
clc
adc #8
sta spritemem, x
rts
draw_enemy_reverse:
ldx #16
lda enemy_yloc
sta spritemem, x
ldx #17
lda enemy_tile
clc
adc #2
sta spritemem, x
ldx #18
lda enemy_colorbit
sta spritemem, x
ldx #19
lda enemy_xloc
sta spritemem, x
ldx #20
lda enemy_yloc
sta spritemem, x
ldx #21
lda enemy_tile
sta spritemem, x
ldx #22
lda enemy_colorbit
sta spritemem, x
ldx #23
lda enemy_xloc
clc
adc #8
sta spritemem, x
rts
joyhandler:
lda #0
sta nbasic_temp2
lda sack_dead_secs
cmp nbasic_temp2
beq nbasic_autolabel30
lda #32
sta sack_sprite
jsr jumphandler
dec sack_dead_frames
lda #0
sta nbasic_temp2
lda sack_dead_frames
cmp nbasic_temp2
bne nbasic_autolabel31
lda #60
sta sack_dead_frames
dec sack_dead_secs
nbasic_autolabel31:
rts
nbasic_autolabel30:
lda #0
sta direction
lda #0
sta is_crouching
lda #1
sta nbasic_temp2
lda joyright
cmp nbasic_temp2
bne nbasic_autolabel32
lda #1
sta direction
lda #1
sta facing
jmp joyhandler2
nbasic_autolabel32:
lda #1
sta nbasic_temp2
lda joyleft
cmp nbasic_temp2
bne nbasic_autolabel33
lda #255
sta direction
lda #0
sta facing
jmp joyhandler2
nbasic_autolabel33:
lda #32
sta sack_sprite
joyhandler2:
lda #1
sta nbasic_temp2
lda joydown
cmp nbasic_temp2
bne nbasic_autolabel34
lda #56
sta sack_sprite
lda #1
sta is_crouching
nbasic_autolabel34:
jsr sack_collide_enemy
lda #0
sta nbasic_temp2
lda direction
cmp nbasic_temp2
beq nbasic_autolabel35
jsr request_move
nbasic_autolabel35:
lda #1
sta nbasic_temp2
lda joya
cmp nbasic_temp2
bne nbasic_autolabel36
lda #1
sta nbasic_temp2
lda okjump
cmp nbasic_temp2
bne nbasic_autolabel37
jsr jumpstart
nbasic_autolabel37:
nbasic_autolabel36:
lda #1
sta nbasic_temp2
lda joyselect
cmp nbasic_temp2
bne nbasic_autolabel38
lda #1
sta reset_game
nbasic_autolabel38:
rts
request_move:
inc sack_moveframe
lda #12
sta nbasic_temp2
lda sack_moveframe
cmp nbasic_temp2
bne nbasic_autolabel39
lda #0
sta sack_moveframe
lda #32
sta nbasic_temp2
lda sack_sprite
cmp nbasic_temp2
bne nbasic_autolabel40
lda #40
sta sack_sprite
jmp request_move_2
nbasic_autolabel40:
lda #32
sta sack_sprite
nbasic_autolabel39:
request_move_2:
lda #255
sta nbasic_temp2
lda direction
cmp nbasic_temp2
bne nbasic_autolabel41
jmp request_left
nbasic_autolabel41:
request_right:
lda sack_x2
clc
adc #8
lsr a
lsr a
lsr a
lsr a
sta idx
lda spritey
and #240
clc
adc idx
sta idx
ldx idx
lda leveldata, x
sta collide_low
lda idx
sec
sbc #16
tax
lda leveldata, x
sta collide_top
lda #16
sta nbasic_temp2
lda sack_x
cmp nbasic_temp2
bmi nbasic_autolabel42
ldx idx
lda leveldata2, x
sta collide_low
lda idx
sec
sbc #16
tax
lda leveldata2, x
sta collide_top
nbasic_autolabel42:
lda #0
sta nbasic_temp2
lda collide_low
cmp nbasic_temp2
beq nbasic_autolabel43
jmp collision
nbasic_autolabel43:
lda #1
sta nbasic_temp2
lda is_crouching
cmp nbasic_temp2
bne nbasic_autolabel44
lda #0
sta collide_top
nbasic_autolabel44:
lda #0
sta nbasic_temp2
lda collide_top
cmp nbasic_temp2
beq nbasic_autolabel45
jmp collision
nbasic_autolabel45:
jsr move_right
lda #0
sta nbasic_temp2
lda inflight
cmp nbasic_temp2
bne nbasic_autolabel46
lda #2
sta inflight
nbasic_autolabel46:
rts
request_left:
lda sack_x2
sec
sbc #8
lsr a
lsr a
lsr a
lsr a
sta idx
lda spritey
and #240
clc
adc idx
sta idx
ldx idx
lda leveldata, x
sta collide_low
lda idx
sec
sbc #16
tax
lda leveldata, x
sta collide_top
lda #17
sta nbasic_temp2
lda sack_x
cmp nbasic_temp2
bmi nbasic_autolabel47
ldx idx
lda leveldata2, x
sta collide_low
lda idx
sec
sbc #16
tax
lda leveldata2, x
sta collide_top
nbasic_autolabel47:
lda #0
sta nbasic_temp2
lda collide_low
cmp nbasic_temp2
beq nbasic_autolabel48
jmp collision
nbasic_autolabel48:
lda #1
sta nbasic_temp2
lda is_crouching
cmp nbasic_temp2
bne nbasic_autolabel49
lda #0
sta collide_top
nbasic_autolabel49:
lda #0
sta nbasic_temp2
lda collide_top
cmp nbasic_temp2
beq nbasic_autolabel50
jmp collision
nbasic_autolabel50:
jsr move_left
lda #0
sta nbasic_temp2
lda inflight
cmp nbasic_temp2
bne nbasic_autolabel51
lda #2
sta inflight
nbasic_autolabel51:
rts
collision:
lda #0
sta direction
rts
move_right:
lda #31
sta nbasic_temp2
lda sack_x
cmp nbasic_temp2
bne nbasic_autolabel52
rts
nbasic_autolabel52:
inc sack_xoff
lda #16
sta nbasic_temp2
lda sack_xoff
cmp nbasic_temp2
bne nbasic_autolabel53
lda #0
sta sack_xoff
inc sack_x
nbasic_autolabel53:
lda #10
sta nbasic_temp2
lda sack_x
sec
sbc screen_x
cmp nbasic_temp2
bmi nbasic_autolabel54
beq nbasic_autolabel54
jsr scroll_right
nbasic_autolabel54:
jsr set_x_coords
rts
move_left:
lda #0
sta nbasic_temp2
lda sack_x
cmp nbasic_temp2
bne nbasic_autolabel55
rts
nbasic_autolabel55:
dec sack_xoff
lda #255
sta nbasic_temp2
lda sack_xoff
cmp nbasic_temp2
bne nbasic_autolabel56
lda #15
sta sack_xoff
dec sack_x
nbasic_autolabel56:
lda #6
sta nbasic_temp2
lda sack_x
sec
sbc screen_x
cmp nbasic_temp2
bpl nbasic_autolabel57
beq nbasic_autolabel57
jsr scroll_left
nbasic_autolabel57:
jsr set_x_coords
rts
set_x_coords:
lda sack_x
sec
sbc screen_x
asl a
asl a
asl a
asl a
pha
lda sack_xoff
sec
sbc screen_xoff
sta nbasic_temp
pla
clc
adc nbasic_temp
sta spritex
lda #16
sta nbasic_temp2
lda sack_x
cmp nbasic_temp2
bmi nbasic_autolabel58
lda sack_x
sec
sbc #16
asl a
asl a
asl a
asl a
clc
adc sack_xoff
sta sack_x2
rts
nbasic_autolabel58:
lda sack_x
asl a
asl a
asl a
asl a
clc
adc sack_xoff
sta sack_x2
rts
jumpstart:
lda #1
sta nbasic_temp2
lda okjump
cmp nbasic_temp2
beq nbasic_autolabel59
rts
nbasic_autolabel59:
jsr playsound_jump
lda #1
sta inflight
lda #50
sta gravindex
lda #0
sta gravity_delta
lda #0
sta okjump
rts
highjump:
lda #1
sta inflight
lda #64
sta gravindex
lda #0
sta gravity_delta
lda #0
sta okjump
rts
gravity:
.db 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1
.db 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1
.db 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
.db 3, 3, 3, 3, 3, 3
.db 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 2, 1, 1
.db 2, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 2, 3, 3, 3, 2
.db 3, 3, 3, 3, 3, 3, 4, 3, 3, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4
.db 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
jumphandler:
lda #0
sta nbasic_temp2
lda inflight
cmp nbasic_temp2
bne nbasic_autolabel60
lda #0
sta nbasic_temp2
lda joya
cmp nbasic_temp2
bne nbasic_autolabel61
lda #1
sta okjump
nbasic_autolabel61:
rts
nbasic_autolabel60:
ldx gravindex
lda gravity, x
sta gravity_delta
lda #1
sta nbasic_temp2
lda inflight
cmp nbasic_temp2
bne nbasic_autolabel62
lda #48
sta sack_sprite
lda sack_x2
lsr a
lsr a
lsr a
lsr a
sta idx
lda spritey
sec
sbc #16
sec
sbc gravity_delta
and #240
clc
adc idx
sta idx
ldx idx
lda leveldata, x
sta collide_top
lda #16
sta nbasic_temp2
lda sack_x
cmp nbasic_temp2
bmi nbasic_autolabel63
ldx idx
lda leveldata2, x
sta collide_top
nbasic_autolabel63:
lda #0
sta nbasic_temp2
lda collide_top
cmp nbasic_temp2
beq nbasic_autolabel64
lda #2
sta inflight
dec gravindex
rts
nbasic_autolabel64:
lda spritey
sec
sbc gravity_delta
sta spritey
lda #0
sta nbasic_temp2
lda gravindex
cmp nbasic_temp2
bmi nbasic_autolabel65
beq nbasic_autolabel65
dec gravindex
rts
nbasic_autolabel65:
lda #2
sta inflight
rts
nbasic_autolabel62:
lda sack_x2
lsr a
lsr a
lsr a
lsr a
sta idx
lda spritey
clc
adc gravity_delta
and #240
clc
adc idx
sta idx
ldx idx
lda leveldata, x
sta collide_low
lda #16
sta nbasic_temp2
lda sack_x
cmp nbasic_temp2
bmi nbasic_autolabel66
ldx idx
lda leveldata2, x
sta collide_low
nbasic_autolabel66:
lda #0
sta nbasic_temp2
lda collide_low
cmp nbasic_temp2
beq nbasic_autolabel67
lda #54
sta nbasic_temp2
lda gravindex
cmp nbasic_temp2
bmi nbasic_autolabel68
jsr playsound_thump
nbasic_autolabel68:
lda #0
sta inflight
lda #0
sta nbasic_temp2
lda joya
cmp nbasic_temp2
bne nbasic_autolabel69
lda #1
sta okjump
nbasic_autolabel69:
lda #6
sta gravindex
rts
nbasic_autolabel67:
lda spritey
clc
adc gravity_delta
sta spritey
lda #55
sta nbasic_temp2
lda gravindex
cmp nbasic_temp2
bpl nbasic_autolabel70
lda #0
sta okjump
inc gravindex
lda #48
sta sack_sprite
rts
nbasic_autolabel70:
lda #2
sta inflight
lda #48
sta sack_sprite
rts
sack_collide_enemy:
lda #255
sta nbasic_temp2
lda enemy_dir
cmp nbasic_temp2
bne nbasic_autolabel71
rts
nbasic_autolabel71:
lda #0
sta nbasic_temp2
lda sack_dead_secs
cmp nbasic_temp2
beq nbasic_autolabel72
rts
nbasic_autolabel72:
lda enemy_y
asl a
asl a
asl a
asl a
clc
adc enemy_yoff
sta collide_y1
lda spritey
sec
sbc collide_y1
sta collide_y2
lda collide_y1
sta nbasic_temp2
lda spritey
cmp nbasic_temp2
bpl nbasic_autolabel73
beq nbasic_autolabel73
rts
nbasic_autolabel73:
lda #24
sta nbasic_temp2
lda collide_y2
cmp nbasic_temp2
bmi nbasic_autolabel74
beq nbasic_autolabel74
rts
nbasic_autolabel74:
lda enemy_x
asl a
asl a
asl a
pha
lda enemy_xoff
lsr a
sta nbasic_temp
pla
clc
adc nbasic_temp
sta collide_x1
lda sack_x
asl a
asl a
asl a
pha
lda sack_xoff
lsr a
sta nbasic_temp
pla
clc
adc nbasic_temp
sta collide_x2
lda collide_x2
sec
sbc collide_x1
sta collide_result
lda collide_x2
sta nbasic_temp2
lda collide_x1
cmp nbasic_temp2
bmi nbasic_autolabel75
beq nbasic_autolabel75
lda #254
sta nbasic_temp2
lda collide_result
cmp nbasic_temp2
bmi nbasic_autolabel76
jmp sack_collide_enemy_right
nbasic_autolabel76:
nbasic_autolabel75:
lda collide_x2
sta nbasic_temp2
lda collide_x1
cmp nbasic_temp2
bpl nbasic_autolabel77
beq nbasic_autolabel77
lda #12
sta nbasic_temp2
lda collide_result
cmp nbasic_temp2
bpl nbasic_autolabel78
jmp sack_collide_enemy_left
nbasic_autolabel78:
nbasic_autolabel77:
rts
sack_collide_enemy_right:
lda #2
sta nbasic_temp2
lda inflight
cmp nbasic_temp2
bne nbasic_autolabel79
lda #1
sta nbasic_temp2
lda collide_y2
cmp nbasic_temp2
bpl nbasic_autolabel80
jmp sack_collide_enemy_bottom
nbasic_autolabel80:
nbasic_autolabel79:
lda #0
sta enemy_dir
lda #1
sta nbasic_temp2
lda direction
cmp nbasic_temp2
bne nbasic_autolabel81
lda #0
sta direction
nbasic_autolabel81:
lda #6
sta sack_dead_secs
lda #60
sta sack_dead_frames
rts
sack_collide_enemy_left:
lda #2
sta nbasic_temp2
lda inflight
cmp nbasic_temp2
bne nbasic_autolabel82
lda #4
sta nbasic_temp2
lda collide_y2
cmp nbasic_temp2
bpl nbasic_autolabel83
beq nbasic_autolabel83
jmp sack_collide_enemy_bottom
nbasic_autolabel83:
nbasic_autolabel82:
lda #1
sta enemy_dir
lda #255
sta nbasic_temp2
lda direction
cmp nbasic_temp2
bne nbasic_autolabel84
lda #0
sta direction
nbasic_autolabel84:
lda #6
sta sack_dead_secs
lda #60
sta sack_dead_frames
rts
sack_collide_enemy_bottom:
jsr playsound_squish
lda #255
sta enemy_dir
lda #1
sta inflight
lda #25
sta gravindex
lda #1
sta nbasic_temp2
lda joya
cmp nbasic_temp2
bne nbasic_autolabel85
jsr highjump
nbasic_autolabel85:
rts
joystick:
lda #$01 ;//strobe the joystick
sta $4016
lda #$00
sta $4016
lda $4016 ;//now read values
and #$01
sta joya
lda $4016
and #$01
sta joyb
lda $4016
and #$01
sta joyselect
lda $4016
and #$01
sta joystart
lda $4016
and #$01
sta joyup
lda $4016
and #$01
sta joydown
lda $4016
and #$01
sta joyleft
lda $4016
and #$01
sta joyright
rts
playsound_jump:
lda #152
sta $4000
lda #140
sta $4001
lda #77
sta $4002
lda #149
sta $4003
rts
playsound_thump:
lda #159
sta $4000
lda #132
sta $4001
lda #211
sta $4002
lda #252
sta $4003
rts
playsound_squish:
lda #136
sta $4000
lda #72
sta $4001
lda #37
sta $4002
lda #75
sta $4003
rts
scrollhandler:
lda screen_x
asl a
asl a
asl a
asl a
clc
adc screen_xoff
sta $2005
lda #0
sta $2005
rts
scroll_right:
lda #15
sta nbasic_temp2
lda screen_x
cmp nbasic_temp2
beq nbasic_autolabel86
inc screen_xoff
lda #16
sta nbasic_temp2
lda screen_xoff
cmp nbasic_temp2
bne nbasic_autolabel87
lda #0
sta screen_xoff
inc screen_x
nbasic_autolabel87:
rts
nbasic_autolabel86:
lda #15
sta nbasic_temp2
lda screen_xoff
cmp nbasic_temp2
bne nbasic_autolabel88
rts
nbasic_autolabel88:
inc screen_xoff
rts
scroll_left:
lda #0
sta nbasic_temp2
lda screen_x
cmp nbasic_temp2
beq nbasic_autolabel89
dec screen_xoff
lda #255
sta nbasic_temp2
lda screen_xoff
cmp nbasic_temp2
bne nbasic_autolabel90
lda #15
sta screen_xoff
dec screen_x
nbasic_autolabel90:
rts
nbasic_autolabel89:
lda #0
sta nbasic_temp2
lda screen_xoff
cmp nbasic_temp2
bne nbasic_autolabel91
rts
nbasic_autolabel91:
dec screen_xoff
rts
marker:
lda #20
sta $2003
pla ;//y val
sta $2004
lda #1
sta $2004 ;//sprite index
sta $2004 ;//color bit
pla ;//x val
sta $2004
rts
drawsack:
lda #0
sta nbasic_temp2
lda sack_dead_secs
cmp nbasic_temp2
beq nbasic_autolabel92
jsr drawdead
rts
nbasic_autolabel92:
lda #1
sta nbasic_temp2
lda facing
cmp nbasic_temp2
bne nbasic_autolabel93
jsr drawright
rts
nbasic_autolabel93:
jsr drawleft
rts
clearattrib:
lda #35
sta $2006
lda #192
sta $2006
ldy #63
clearlabel0:
lda #0
sta $2007
dey
cpy #0
bne clearlabel0
rts
clearsprites:
lda #0
sta $2003
lda #0
sta i
nbasic_autolabel94:
lda #245
sta $2004
lda #0
sta $2004
lda #0
sta $2004
lda #0
sta $2004
sta nbasic_temp
inc i
lda i
cmp nbasic_temp
bmi nbasic_autolabel94
beq nbasic_autolabel94
rts
drawleft:
ldx #0
lda spritey
sec
sbc #32
sta spritemem, x
ldx #1
lda sack_sprite
sta spritemem, x
ldx #2
lda #65
sta spritemem, x
ldx #3
lda spritex
sta spritemem, x
ldx #4
lda spritey
sec
sbc #16
sta spritemem, x
ldx #5
lda sack_sprite
clc
adc #2
sta spritemem, x
ldx #6
lda #65
sta spritemem, x
ldx #7
lda spritex
sta spritemem, x
ldx #8
lda spritey
sec
sbc #32
sta spritemem, x
ldx #9
lda sack_sprite
clc
adc #4
sta spritemem, x
ldx #10
lda #65
sta spritemem, x
ldx #11
lda spritex
sec
sbc #8
sta spritemem, x
ldx #12
lda spritey
sec
sbc #16
sta spritemem, x
ldx #13
lda sack_sprite
clc
adc #6
sta spritemem, x
ldx #14
lda #65
sta spritemem, x
ldx #15
lda spritex
sec
sbc #8
sta spritemem, x
rts
drawright:
ldx #0
lda spritey
sec
sbc #32
sta spritemem, x
ldx #1
lda sack_sprite
sta spritemem, x
ldx #2
lda #1
sta spritemem, x
ldx #3
lda spritex
sec
sbc #8
sta spritemem, x
ldx #4
lda spritey
sec
sbc #16
sta spritemem, x
ldx #5
lda sack_sprite
clc
adc #2
sta spritemem, x
ldx #6
lda #1
sta spritemem, x
ldx #7
lda spritex
sec
sbc #8
sta spritemem, x
ldx #8
lda spritey
sec
sbc #32
sta spritemem, x
ldx #9
lda sack_sprite
clc
adc #4
sta spritemem, x
ldx #10
lda #1
sta spritemem, x
ldx #11
lda spritex
sta spritemem, x
ldx #12
lda spritey
sec
sbc #16
sta spritemem, x
ldx #13
lda sack_sprite
clc
adc #6
sta spritemem, x
ldx #14
lda #1
sta spritemem, x
ldx #15
lda spritex
sta spritemem, x
rts
drawdead:
ldx #0
lda spritey
sec
sbc #22
sta spritemem, x
ldx #1
lda sack_sprite
clc
adc #6
sta spritemem, x
ldx #2
lda #193
sta spritemem, x
ldx #3
lda spritex
sec
sbc #8
sta spritemem, x
ldx #4
lda spritey
sec
sbc #6
sta spritemem, x
ldx #5
lda sack_sprite
clc
adc #4
sta spritemem, x
ldx #6
lda #193
sta spritemem, x
ldx #7
lda spritex
sec
sbc #8
sta spritemem, x
ldx #8
lda spritey
sec
sbc #22
sta spritemem, x
ldx #9
lda sack_sprite
clc
adc #2
sta spritemem, x
ldx #10
lda #193
sta spritemem, x
ldx #11
lda spritex
sta spritemem, x
ldx #12
lda spritey
sec
sbc #6
sta spritemem, x
ldx #13
lda sack_sprite
sta spritemem, x
ldx #14
lda #193
sta spritemem, x
ldx #15
lda spritex
sta spritemem, x
rts
vwait:
lda $2002
bpl vwait ;//wait for start of retrace
rts ;//RETURN FOR NOW. THIS IS INCOMPATIBLE WITH OTHER EMULATORS
vwait2:
lda $2002
bmi vwait2 ;//wait for end of retrace
inc frame
rts
ppuinit:
jsr vwait
lda #48
sta $2000
lda #28
sta $2001
rts
titlepal:
;// .db $00,$05,$09,$28,$00,$18,$09,$28,$00,$19,$18,$0c,$00,$03,$07,$00

.db $28,$38,$37,$08, $28,$21,$37,$38, $28,$38,$01,$08, $28,$21,$37,$01
.db $27,13,32,3,0,13,32,$10,0,13,57,24,0,10,11,12 ;//foreground palette
palette:
lda #63
sta $2006
lda #0
sta $2006
lda #0
sta i
palette_2:
ldx i
lda titlepal, x
sta $2007
inc i
lda #32
sta nbasic_temp2
lda i
cmp nbasic_temp2
bne nbasic_autolabel95
rts
nbasic_autolabel95:
jmp palette_2
drawstuff:
jsr scrollhandler
lda #0
sta $4014
rts
nmi:
rti
high_bytes:
;//name table 0
.db $20,$20,$20,$20,$20,$20,$20,$20
.db $21,$21,$21,$21,$21,$21,$21,$21
.db $22,$22,$22,$22,$22,$22,$22,$22
.db $23,$23,$23,$23,$23,$23,$23,$23
high_bytes2:
;//name table 1
.db $24,$24,$24,$24,$24,$24,$24,$24
.db $25,$25,$25,$25,$25,$25,$25,$25
.db $26,$26,$26,$26,$26,$26,$26,$26
.db $27,$27,$27,$27,$27,$27,$27,$27
low_bytes:
;//name table 0
.db 0,32,64,96,128,160,192,224
.db 0,32,64,96,128,160,192,224
.db 0,32,64,96,128,160,192,224
.db 0,32,64,96,128,160,192,224
low_bytes2:
;//name table 1
.db 0,32,64,96,128,160,192,224
.db 0,32,64,96,128,160,192,224
.db 0,32,64,96,128,160,192,224
.db 0,32,64,96,128,160,192,224
loadbackground:
lda #0
sta which_column
loadbackground_2:
jsr loadcolumn
jsr load_attrib_column
jsr vwait
inc which_column
lda #16
sta nbasic_temp2
lda which_column
cmp nbasic_temp2
bpl nbasic_autolabel96
jmp loadbackground_2
nbasic_autolabel96:
rts
loadcolumn:
lda #8
sta nbasic_temp2
lda which_column
cmp nbasic_temp2
bmi nbasic_autolabel97
jmp loadhighcolumn
nbasic_autolabel97:
lda which_column
asl a
asl a
asl a
asl a
asl a
sec
sbc which_column
sec
sbc which_column
sta my_x
write_column_work_0:
ldy #0
ldx my_x
write_column_work_1:
;//set ppu memory address
lda high_bytes,y
sta $2006
lda which_column
asl a
asl a
clc
adc low_bytes,y
sta $2006
;//write top blocks
clc
lda the_level, x
sta $2007
adc #1
sta $2007
inx
lda the_level,x
sta $2007
adc #1
sta $2007
dex
;//now write the blocks under
iny
lda high_bytes,y
sta $2006
lda which_column
asl a
asl a
clc
adc low_bytes,y
sta $2006
clc
lda the_level, x
adc #16
sta $2007
adc #1
sta $2007
inx
lda the_level,x
adc #16
sta $2007
adc #1
sta $2007
inx
;//now check if we're done with the column
iny
cpy #30
bne write_column_work_1
rts
loadhighcolumn:
lda which_column
sec
sbc #8
sta temp_column
lda temp_column
asl a
asl a
asl a
asl a
asl a
sec
sbc temp_column
sec
sbc temp_column
sta my_x
ldy #0
ldx my_x
write_column_work_2:
;//set ppu memory address
lda high_bytes2,y
sta $2006
lda temp_column
asl a
asl a
clc
adc low_bytes2,y
sta $2006
;//write top blocks
clc
lda the_level2, x
sta $2007
adc #1
sta $2007
inx
lda the_level2,x
sta $2007
adc #1
sta $2007
dex
;//now write the blocks under
iny
lda high_bytes2,y
sta $2006
lda temp_column
asl a
asl a
clc
adc low_bytes2,y
sta $2006
clc
lda the_level2, x
adc #16
sta $2007
adc #1
sta $2007
inx
lda the_level2,x
adc #16
sta $2007
adc #1
sta $2007
inx
;//now check if we're done with the column
iny
cpy #30
bne write_column_work_2
rts
load_attrib_column:
lda #8
sta nbasic_temp2
lda which_column
cmp nbasic_temp2
bpl nbasic_autolabel98
beq nbasic_autolabel98
lda #35
sta highbyte
lda #192
clc
adc which_column
sta lowbyte
jmp load_attrib_column_1
nbasic_autolabel98:
lda #39
sta highbyte
lda #184
clc
adc which_column
sta lowbyte
load_attrib_column_1:
lda which_column
asl a
asl a
asl a
sta idx
lda #0
sta numcolumns
load_attrib_column_2:
lda highbyte
sta $2006
lda lowbyte
sta $2006
ldx idx
lda attrib_table, x
sta $2007
lda lowbyte
clc
adc #8
sta lowbyte
inc idx
inc numcolumns
lda #8
sta nbasic_temp2
lda numcolumns
cmp nbasic_temp2
bne nbasic_autolabel99
rts
nbasic_autolabel99:
jmp load_attrib_column_2
the_level:
.incbin "level/name1.tbl"
the_level2:
.incbin "level/name2.tbl"
attrib_table:
.incbin "level/attrib.tbl"
leveldata:
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,0
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.db 0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
.db 0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0
.db 0,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1
.db 0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0
.db 0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1
leveldata2:
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.db 1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0
.db 0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1
.db 0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0
.db 0,0,1,1,1,1,1,0,0,0,1,1,1,1,0,0
.db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
.db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
.bank 3
.org $fffa
.dw nmi ;//NMI
.dw start ;//Reset
.dw start ;//BRK
.bank 4
.org $0000
.incbin "foreground.chr"
.incbin "background.chr"
;//end of file

enemytest.bas

//ines header setup
asm
	.inesprg 2
	.ineschr 1
	.inesmir 1
	.inesmap 0
	
	.org $8000
	.bank 0
endasm
//test sound, address $8000, 64 bytes
asm
	.db $ff,$ff,$ff,$ff,0,0,0,0,0,0,0,0,$ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,0,0,0,0,0,0,0,0
	.db $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,0,0,0,0,0,0,0,0
	.db $ff,$ff,$ff,$ff,$ff,$ff,$ff,$ff,0,0,0,0,0,0,0,0
	.db $ff,$ff,$ff,$ff
endasm

array spritemem 256

//program start
start:
	gosub initsound
	gosub vwait
	set $2000 %00110000
	set $2001 %00000100
	gosub palette
	gosub clearsprites
	gosub varsetup
	gosub musicsetup
	gosub enemysetup
	gosub vwait
	gosub loadbackground
	set $2000 %00110000
	set $2001 %00011100
mainloop:
	gosub joystick
	gosub joyhandler
	gosub jumphandler
	gosub enemyhandler
	gosub drawsack
	gosub musicloop
	gosub vwait
	gosub drawstuff
	if reset_game = 1 goto start
	goto mainloop

//initialization
varsetup:
	set joya 0
	set joyb 0
	set joyup 0
	set joydown 0
	set joyright 0
	set joyleft 0
	set joyselect 0
	set joystart 0
	set frame 0
	set inflight 2
	set direction 0
	set facing 1
	set i 0
	set scrollval 0
	set screen_x 0
	set screen_xoff 0
	set sack_x 2
	set sack_xoff 0
	set spritex << sack_x 4
	set sack_x2 spritex
	set spritey 60
	set reset_game 0
	set sack_sprite 32
	set sack_moveframe 0
	return

initsound:
	set $4015 0 //turn off all channels
	set $4015 %00011111 //turn them back on
//	set $4001 0
	return

musicsetup:
	set musicframe 0
	set notelength 0
	set whichnote 0
	return

musicloop:
	if notelength <> 0 then
		dec notelength
		return
		endif
	if whichnote >= 91 set whichnote 0
	set notelength [ musicdata whichnote ]
	if notelength = 0 then
		//rest handler
		inc whichnote
		set notelength [ musicdata whichnote ]
		inc whichnote
//		asm
//			lda $4015
//			and %11111101
//			sta $4015 ;//turn off square 2
//		endasm
		asm
			lda #0
			sta $4004
			sta $4005
			sta $4006
			sta $4007
		endasm
//		set $4004 0
		return
		endif
	inc whichnote
	asm
		ldx whichnote
		lda musicdata, x
		sta $4004
		inx
		lda musicdata, x
		sta $4005
		inx
		lda musicdata, x
		sta $4006
		inx
		lda musicdata, x
		sta $4007
		inx
	endasm
//	set $4015 %00011111
	set whichnote + whichnote 4
	return

musicdata:
	asm
  .db 23,145,0,253,48
  .db 22,145,0,239,48
  .db 23,145,0,201,48
  .db 22,145,0,190,48
  .db 23,145,0,201,48
  .db 22,145,0,239,48
  .db 23,145,0,253,48
  .db 22,145,0,239,48
  .db 23,145,0,201,48
  .db 22,145,0,190,48
  .db 23,145,0,201,48
  .db 22,145,0,239,48
  .db 23,145,0,253,48
  .db 23,145,0,239,48
  .db 0,22
  .db 22,145,0,253,48
  .db 23,145,0,239,48
  .db 0,22
  .db 23,145,0,239,48
  .db 0,22
	endasm

array enemy_x		2
array enemy_y		2
array enemy_xoff	2
array enemy_yoff	2
array enemy_type	2
array enemy_status 2

enemysetup:
	set enemy_type  1
	set enemy_xoff  8
	set enemy_yoff  0
	set enemy_x  3
	set enemy_y  3
	set enemy_dir 0
	set enemy_frame 0
	set which_enemy 0
	set maxenemies 0 //number of enemies -1
	set goomba_feet 0
	set deadsecs 6
	set deadframes 120
	return

enemyhandler:
	set enemy_typevar enemy_type
	gosub goomba_move
//	for which_enemy = 0 to maxenemies
//		set enemy_typevar [ enemy_type which_enemy ]
//		if enemy_typevar = 1 gosub goomba_move
//	next which_enemy
	return

//requires which_enemy
goomba_move:
	if enemy_frame <> 0 goto goomba_move_2
	if enemy_dir = 255 goto goomba_dead
	if enemy_dir = 0 then
		gosub goomba_request_right
		goto goomba_move_2
		endif
	if enemy_dir = 1
		gosub goomba_request_left
goomba_move_2:
	gosub goomba_request_fall
	inc enemy_frame
	if enemy_frame = 4 set enemy_frame 0
	set enemy_sprite 20
	if + screen_x 1 > enemy_x then
		set enemy_yloc 241
		goto goomba_move_3
		endif
	if + screen_x 14 <= enemy_x then
		set enemy_yloc 241
		goto goomba_move_3
		endif
	set enemy_tile 12
	set enemy_yloc + << enemy_y 4 enemy_yoff
	set enemy_xloc + << - enemy_x screen_x 4 - enemy_xoff screen_xoff
goomba_move_3:
	if goomba_feet < 12 then
		set enemy_colorbit 2
		gosub draw_enemy
		endif
	if goomba_feet >= 12 then
		set enemy_colorbit 66
		gosub draw_enemy_reverse
		endif
	inc goomba_feet
	if goomba_feet = 24 set goomba_feet 0
	return

goomba_dead:
	gosub goomba_request_fall
	set enemy_colorbit %10000010
	set enemy_yloc + << enemy_y 4 enemy_yoff
	if + screen_x 14 <= enemy_x set enemy_yloc 245 //hide off-screen
	if + screen_x 1 > enemy_x set enemy_yloc 245 //hide off-screen
	set enemy_xloc + << - enemy_x screen_x 4 - enemy_xoff screen_xoff
	gosub draw_enemy
	dec deadframes
	if deadframes = 0 then
		set deadframes 120
		dec deadsecs
		if deadsecs = 0 then
			set deadsecs 6
			set enemy_dir 1
			endif
		endif
	return

goomba_request_right:
	set idx + + << enemy_y 4 enemy_x 1
	set collide_right [ leveldata idx ]
	if enemy_x >= 16 set collide_right [ leveldata2 idx ]
goomba_request_right_2:
	if collide_right = 0 then
		inc enemy_xoff
		if enemy_xoff = 16 then
			set enemy_xoff 0
			inc enemy_x
			endif
		return
		endif
	set enemy_dir 1 //go left now
	return

goomba_request_left:
	set idx + << enemy_y 4 enemy_x
	set collide_left [ leveldata idx ]
	if enemy_x >= 16 set collide_left [ leveldata2 idx ]
	if collide_left = 0 then
		dec enemy_xoff
		if enemy_xoff = 255 then
			set enemy_xoff 15
			dec enemy_x
			endif
		return
		endif
	set enemy_dir 0 //go right now
	return

goomba_request_fall:
	set idx + + << enemy_y 4 enemy_x 16
	set collide_down [ leveldata idx ]
	if enemy_x >= 16 then
		set idx - idx 16
		set collide_down [ leveldata2 idx ]
		endif
	if collide_down = 0 then
		inc enemy_yoff
		if enemy_yoff = 16 then
			set enemy_yoff 0
			inc enemy_y
			endif
		return
		endif
	return

draw_enemies:
	for which_enemy = 0 to maxenemies
		set enemy_typevar [ enemy_type which_enemy ]
		if enemy_typevar = 1 gosub draw_enemy
	next which_enemy
	return

//requires enemy_sprite, enemy_tile, enemy_xloc, enemy_yloc, enemy_colorbit
draw_enemy:
	set [ spritemem 16 ] enemy_yloc
	set [ spritemem 17 ] enemy_tile
	set [ spritemem 18 ] enemy_colorbit
	set [ spritemem 19 ] enemy_xloc

	set [ spritemem 20 ] enemy_yloc
	set [ spritemem 21 ] + enemy_tile 2
	set [ spritemem 22 ] enemy_colorbit
	set [ spritemem 23 ] + enemy_xloc 8
	return

draw_enemy_reverse:
	set [ spritemem 16 ] enemy_yloc
	set [ spritemem 17 ] + enemy_tile 2
	set [ spritemem 18 ] enemy_colorbit
	set [ spritemem 19 ] enemy_xloc

	set [ spritemem 20 ] enemy_yloc
	set [ spritemem 21 ] enemy_tile
	set [ spritemem 22 ] enemy_colorbit
	set [ spritemem 23 ] + enemy_xloc 8
	return
//act on joystick buttons
joyhandler:
	if sack_dead_secs <> 0 then
		set sack_sprite 32
		gosub jumphandler
		dec sack_dead_frames
		if sack_dead_frames = 0 then
			set sack_dead_frames 60
			dec sack_dead_secs
			endif
		return
		endif
	//set left and right facing
	set direction 0
	set is_crouching 0
	if joyright = 1 then
		set direction 1
		set facing 1
		goto joyhandler2
		endif
	if joyleft = 1 then
		set direction 255
		set facing 0
		goto joyhandler2
		endif
	set sack_sprite 32 //no movement, use still sprite
	//handle jump and gravity
	joyhandler2:
		if joydown = 1 then
			set sack_sprite 56
			set is_crouching 1
			endif
		gosub sack_collide_enemy
		if direction <> 0 gosub request_move
		if joya = 1 if okjump = 1 gosub jumpstart
	if joyselect = 1 set reset_game 1
	return

//collision detection left and right
request_move:
	inc sack_moveframe
	if sack_moveframe = 12 then //number of frames before sack changes moving sprite
		set sack_moveframe 0
		if sack_sprite = 32 then
			set sack_sprite 40 //set to the other sprite
			goto request_move_2
			endif
		set sack_sprite 32
		endif
	request_move_2:
	if direction = 255 goto request_left
		//else fall to request_right
	request_right:
		set idx >> + sack_x2 8 4
		set idx + & spritey %11110000 idx
		set collide_low [ leveldata idx ]
		set collide_top [ leveldata - idx 16 ]
		if sack_x >= 16 then
			set collide_low [ leveldata2 idx ]
			set collide_top [ leveldata2 - idx 16 ]
		endif
		if collide_low <> 0 goto collision
		if is_crouching = 1 set collide_top 0
		if collide_top <> 0 goto collision
		gosub move_right //no collision, move right
		if inflight = 0 set inflight 2
		return
	request_left:
		set idx >> - sack_x2 8 4
		set idx + & spritey %11110000 idx
		set collide_low [ leveldata idx ]
		set collide_top [ leveldata - idx 16 ]
		if sack_x >= 17 then
			set collide_low [ leveldata2 idx ]
			set collide_top [ leveldata2 - idx 16 ]
		endif
		if collide_low <> 0 goto collision
		if is_crouching = 1 set collide_top 0
		if collide_top <> 0 goto collision
		gosub move_left //no collision, move left
		if inflight = 0 set inflight 2
		return
	collision:
		set direction 0
		return

move_right:
	if sack_x = 31 return
	inc sack_xoff
	if sack_xoff = 16 then
		set sack_xoff 0
		inc sack_x
		endif
	if - sack_x screen_x > 10 gosub scroll_right
	gosub set_x_coords
	return
		
move_left:
	if sack_x = 0 return
	dec sack_xoff
	if sack_xoff = 255 then
		set sack_xoff 15
		dec sack_x
		endif
	if - sack_x screen_x < 6 gosub scroll_left
	gosub set_x_coords
	return

set_x_coords:
	set spritex + << - sack_x screen_x 4 - sack_xoff screen_xoff
	if sack_x >= 16 then
		set sack_x2 + << - sack_x 16 4 sack_xoff
		return
		endif
	set sack_x2 + << sack_x 4 sack_xoff
	return

//start a jump action
jumpstart:
	if okjump <> 1 return
//	if inflight <> 0 return
	gosub playsound_jump
	set inflight 1 //1=up, 2=down
	set gravindex 50
	set gravity_delta 0
	set okjump 0
	return

highjump:
	set inflight 1
	set gravindex 64
	set gravity_delta 0
	set okjump 0
	return

//max height=48
//max gravity index=50
gravity:
	//old gravity array
	asm
	.db 0, 0, 0, 0, 0, 0, 1, 0, 0, 1, 0, 0, 1, 0, 1, 0, 1, 1, 0, 1
	.db 1, 0, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 2, 1, 1, 2, 1, 1, 2, 1
	.db 2, 1, 2, 2, 1, 2, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2, 2
	.db 3, 3, 3, 3, 3, 3
	endasm
	//new gravity array
	asm
	.db 0, 0, 0, 0, 1, 0, 0, 1, 0, 1, 1, 0, 1, 1, 1, 1, 1, 2, 1, 1
	.db 2, 1, 2, 1, 2, 2, 2, 2, 2, 2, 2, 2, 3, 2, 3, 2, 3, 3, 3, 2
	.db	3, 3, 3, 3, 3, 3, 4, 3, 3, 4, 4, 4, 3, 4, 4, 4, 4, 4, 4, 4
	.db 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4, 4
	endasm

//called each frame. advances gravity	
jumphandler:
	if inflight = 0 then
		if joya = 0 set okjump 1
		return
		endif
	set gravity_delta [ gravity gravindex ]
	if inflight = 1 then //jump up
		set sack_sprite 48
		set idx >> sack_x2 4
		set idx + & - - spritey 16 gravity_delta %11110000 idx
		set collide_top [ leveldata idx ]
		if sack_x >= 16 set collide_top [ leveldata2 idx ]
		if collide_top <> 0 then
			set inflight 2
			dec gravindex
//			if joya = 0 set okjump 1
			return
			endif
		set spritey - spritey gravity_delta
		if gravindex > 0 then
			dec gravindex
			return
			endif
		set inflight 2
		return
		endif
	//else jump down
		set idx >> sack_x2 4
		set idx + & + spritey gravity_delta %11110000 idx
		set collide_low [ leveldata idx ]
		if sack_x >= 16 set collide_low [ leveldata2 idx ]
		if collide_low <> 0 then
			if gravindex >= 54 gosub playsound_thump //hard landing
			set inflight 0
			if joya = 0 set okjump 1
			set gravindex 6 //the first "1" in gravity array
			return
			endif
		set spritey + spritey gravity_delta
		if gravindex <= 55 then
			set okjump 0
			inc gravindex
			set sack_sprite 48
			return
			endif
		set inflight 2
		set sack_sprite 48
		return

sack_collide_enemy:
	if enemy_dir = 255 return //he's dead
	if sack_dead_secs <> 0 return //sack is dead
	set collide_y1 + << enemy_y 4 enemy_yoff
	set collide_y2 - spritey collide_y1
//	set collide_y1 - spritey + << enemy_y 4 enemy_yoff
	if spritey < collide_y1 return
	//if spritey > collide_y1 
	if collide_y2 > 24 return
//	if >> spritey 4 <> enemy_y return
	set collide_x1 + << enemy_x 3 >> enemy_xoff 1
	set collide_x2 + << sack_x 3 >> sack_xoff 1
	set collide_result - collide_x2 collide_x1
	if collide_x1 > collide_x2 if collide_result >= 254 goto sack_collide_enemy_right
	if collide_x1 < collide_x2 if collide_result <= 12 goto sack_collide_enemy_left
	return //no collision
	sack_collide_enemy_right:
		if inflight = 2 if collide_y2 <= 1 goto sack_collide_enemy_bottom
		set enemy_dir 0
		if direction = 1 set direction 0
		set sack_dead_secs 6
		set sack_dead_frames 60
		return
	sack_collide_enemy_left:
		if inflight = 2 if collide_y2 < 4 goto sack_collide_enemy_bottom
		set enemy_dir 1
		if direction = 255 set direction 0
		set sack_dead_secs 6
		set sack_dead_frames 60
		return
	sack_collide_enemy_bottom: //sack on top of enemy
		gosub playsound_squish
		set enemy_dir 255
		set inflight 1
		set gravindex 25
		if joya = 1 gosub highjump
		return

joystick:
	asm
	lda #$01	;//strobe the joystick
	sta $4016
	lda #$00
	sta $4016
	lda $4016		;//now read values
	and #$01
	sta joya
	lda $4016
	and #$01
	sta joyb
	lda $4016
	and #$01
	sta joyselect
	lda $4016
	and #$01
	sta joystart
	lda $4016
	and #$01
	sta joyup
	lda $4016
	and #$01
	sta joydown
	lda $4016
	and #$01
	sta joyleft
	lda $4016
	and #$01
	sta joyright
	endasm
	return

playsound_jump:
	set $4000 %10011000
	set $4001 %10001100
	set $4002 %01001101
	set $4003 %10010101
	return

playsound_thump:
	set $4000 %10011111
	set $4001 %10000100
	set $4002 %11010011
	set $4003 %11111100
	return

playsound_squish:
	set $4000 %10001000
	set $4001 %01001000
	set $4002 %00100101
	set $4003 %01001011
	return

array column_read 2

scrollhandler:
	set $2005 + << screen_x 4 screen_xoff
	set $2005 0
	return

scroll_right:
	if screen_x <> 15 then
		inc screen_xoff
		if screen_xoff = 16 then
			set screen_xoff 0
			inc screen_x
			endif
		return
		endif
	if screen_xoff = 15 return
	inc screen_xoff
	return

scroll_left:
	if screen_x <> 0 then
		dec screen_xoff
		if screen_xoff = 255 then
			set screen_xoff 15
			dec screen_x
			endif
		return
		endif
	if screen_xoff = 0 return
	dec screen_xoff
	return


marker:
	set $2003 20
	asm
	pla ;//y val
	sta $2004
	lda #1
	sta $2004 ;//sprite index
	sta $2004 ;//color bit
	pla ;//x val
	sta $2004
	endasm
	return


drawsack:
	if sack_dead_secs <> 0 then
		gosub drawdead
		return
		endif
	if facing = 1 then
		gosub drawright
		return
		endif
	//else if facing <> 1
		gosub drawleft
	return

clearattrib:
	set $2006 $23
	set $2006 $c0
	asm
	ldy #63
clearlabel0:
	lda #0
	sta $2007
	dey
	cpy #0
	bne clearlabel0
	endasm
	return
	
clearsprites:
	set $2003 0
	for i = 0 to 63
		set $2004 245
		set $2004 0
		set $2004 0
		set $2004 0
	next i
	return

//*******************************************************************
//*******************************************************************
	
//drawsprite:
//	set $2004 sprite_yloc
//	set $2004 sprite_indx
//	set $2004 sprite_cbit
//	set $2004 sprite_xloc
//	return

//spritex, spritey is bottom middle of sack
drawleft:
	set [ spritemem 0 ] - spritey 32
	set [ spritemem 1 ] sack_sprite
	set [ spritemem 2 ] 65
	set [ spritemem 3 ] spritex

	set [ spritemem 4 ] - spritey 16
	set [ spritemem 5 ] + sack_sprite 2
	set [ spritemem 6 ] 65
	set [ spritemem 7 ] spritex

	set [ spritemem 8 ] - spritey 32
	set [ spritemem 9 ] + sack_sprite 4
	set [ spritemem 10 ] 65
	set [ spritemem 11 ] - spritex 8

	set [ spritemem 12 ] - spritey 16
	set [ spritemem 13 ] + sack_sprite 6
	set [ spritemem 14 ] 65
	set [ spritemem 15 ] - spritex 8
	return	

//spritex, spritey is middle of sack
drawright:
	set [ spritemem 0 ] - spritey 32
	set [ spritemem 1 ] sack_sprite
	set [ spritemem 2 ] 1
	set [ spritemem 3 ] - spritex 8

	set [ spritemem 4 ] - spritey 16
	set [ spritemem 5 ] + sack_sprite 2
	set [ spritemem 6 ] 1
	set [ spritemem 7 ] - spritex 8

	set [ spritemem 8 ] - spritey 32
	set [ spritemem 9 ] + sack_sprite 4
	set [ spritemem 10 ] 1
	set [ spritemem 11 ] spritex

	set [ spritemem 12 ] - spritey 16
	set [ spritemem 13 ] + sack_sprite 6
	set [ spritemem 14 ] 1
	set [ spritemem 15 ] spritex
	return

drawdead:
	set [ spritemem 0 ] - spritey 22
	set [ spritemem 1 ] + sack_sprite 6
	set [ spritemem 2 ] %11000001
	set [ spritemem 3 ] - spritex 8

	set [ spritemem 4 ] - spritey 6
	set [ spritemem 5 ] + sack_sprite 4
	set [ spritemem 6 ] %11000001
	set [ spritemem 7 ] - spritex 8

	set [ spritemem 8 ] - spritey 22
	set [ spritemem 9 ] + sack_sprite 2
	set [ spritemem 10 ] %11000001
	set [ spritemem 11 ] spritex

	set [ spritemem 12 ] - spritey 6
	set [ spritemem 13 ] sack_sprite
	set [ spritemem 14 ] %11000001
	set [ spritemem 15 ] spritex
	return

//*******************************************************************
//*******************************************************************

vwait:
	asm
	lda $2002
	bpl vwait ;//wait for start of retrace
	rts ;//RETURN FOR NOW. THIS IS INCOMPATIBLE WITH OTHER EMULATORS
vwait2:
	lda $2002
	bmi vwait2 ;//wait for end of retrace
	endasm
	inc frame
	return

ppuinit:
	gosub vwait
	set $2000 %00110000
	set $2001 %00011100
	return

titlepal:
	asm
;//	.db $00,$05,$09,$28,$00,$18,$09,$28,$00,$19,$18,$0c,$00,$03,$07,$00

	.db $28,$38,$37,$08, $28,$21,$37,$38, $28,$38,$01,$08, $28,$21,$37,$01
	.db $27,13,32,3,0,13,32,$10,0,13,57,24,0,10,11,12 ;//foreground palette
	endasm

palette:
	set $2006 $3f
	set $2006 0
	set i 0
	palette_2:
	set $2007 [ titlepal i ]
	inc i
	if i = 32 return
	goto palette_2

drawstuff:
	gosub scrollhandler
	set $4014 0 //sprite DMA
	return
		
nmi:
	resume

//***************************************************************
high_bytes:
	asm
	;//name table 0
	.db $20,$20,$20,$20,$20,$20,$20,$20
	.db $21,$21,$21,$21,$21,$21,$21,$21
	.db $22,$22,$22,$22,$22,$22,$22,$22
	.db $23,$23,$23,$23,$23,$23,$23,$23
high_bytes2:
	;//name table 1
	.db $24,$24,$24,$24,$24,$24,$24,$24
	.db $25,$25,$25,$25,$25,$25,$25,$25
	.db $26,$26,$26,$26,$26,$26,$26,$26
	.db $27,$27,$27,$27,$27,$27,$27,$27
	endasm

low_bytes:
	asm
	;//name table 0
	.db 0,32,64,96,128,160,192,224
	.db 0,32,64,96,128,160,192,224
	.db 0,32,64,96,128,160,192,224
	.db 0,32,64,96,128,160,192,224
low_bytes2:
	;//name table 1
	.db 0,32,64,96,128,160,192,224
	.db 0,32,64,96,128,160,192,224
	.db 0,32,64,96,128,160,192,224
	.db 0,32,64,96,128,160,192,224
	endasm

loadbackground:
	set which_column 0
loadbackground_2:
	gosub loadcolumn
	gosub load_attrib_column
	gosub vwait
	inc which_column
	if which_column <= 16 goto loadbackground_2
	return

loadcolumn:
	if which_column >= 8 goto loadhighcolumn
	set my_x - - << which_column 5 which_column which_column //30*column
	//setup index regs
	write_column_work_0:
		asm
		ldy #0
		ldx my_x
	write_column_work_1:
	;//set ppu memory address
		lda high_bytes,y
		sta $2006
		lda which_column
		asl a
		asl a
		clc
		adc low_bytes,y
		sta $2006
	;//write top blocks
		clc
		lda the_level, x
		sta $2007
		adc #1
		sta $2007
		inx
		lda the_level,x
		sta $2007
		adc #1
		sta $2007
		dex
	;//now write the blocks under
		iny
		lda high_bytes,y
		sta $2006
		lda which_column
		asl a
		asl a
		clc
		adc low_bytes,y
		sta $2006
		clc
		lda the_level, x
		adc #16
		sta $2007
		adc #1
		sta $2007
		inx
		lda the_level,x
		adc #16
		sta $2007
		adc #1
		sta $2007
		inx
	;//now check if we're done with the column
		iny
		cpy #30
		bne write_column_work_1
	endasm
	return

loadhighcolumn:
	set temp_column - which_column 8
	set my_x - - << temp_column 5 temp_column temp_column //30*column
	//setup index regs
		asm
		ldy #0
		ldx my_x
	write_column_work_2:
	;//set ppu memory address
		lda high_bytes2,y
		sta $2006
		lda temp_column
		asl a
		asl a
		clc
		adc low_bytes2,y
		sta $2006
	;//write top blocks
		clc
		lda the_level2, x
		sta $2007
		adc #1
		sta $2007
		inx
		lda the_level2,x
		sta $2007
		adc #1
		sta $2007
		dex
	;//now write the blocks under
		iny
		lda high_bytes2,y
		sta $2006
		lda temp_column
		asl a
		asl a
		clc
		adc low_bytes2,y
		sta $2006
		clc
		lda the_level2, x
		adc #16
		sta $2007
		adc #1
		sta $2007
		inx
		lda the_level2,x
		adc #16
		sta $2007
		adc #1
		sta $2007
		inx
	;//now check if we're done with the column
		iny
		cpy #30
		bne write_column_work_2
	endasm
	return
	
load_attrib_column:
	if which_column < 8 then
		set highbyte $23
		set lowbyte + $c0 which_column
		goto load_attrib_column_1
		endif
	//else name table 2
		set highbyte $27
		set lowbyte + $b8 which_column
	load_attrib_column_1:
	set idx << which_column 3
	set numcolumns 0
	load_attrib_column_2:
		set $2006 highbyte
		set $2006 lowbyte
		set $2007 [ attrib_table idx ]
		set lowbyte + lowbyte 8
		inc idx
		inc numcolumns
		if numcolumns = 8 return
//		if & idx %00000111 = 0 return
	goto load_attrib_column_2
//the level data, vertical RLE
//byte, repeat. set upper left block of 4-block area
//  tilenum:  n    n+2
//            n+1  n+3
the_level:
	asm
	.incbin "level/name1.tbl"
the_level2:
	.incbin "level/name2.tbl"
	endasm
attrib_table:
	asm
	.incbin "level/attrib.tbl"
	endasm

//the level, RLE for display, uncompressed for collision detection
asm
leveldata:
	.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	.db 0,0,0,0,0,0,0,1,0,0,0,0,0,0,0,0
	.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	.db 0,0,0,0,0,0,0,0,1,0,0,0,0,0,0,0
	.db 0,0,0,0,0,0,1,1,1,1,0,0,1,1,1,0
	.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	.db 0,1,1,0,0,0,0,0,0,0,0,0,0,0,0,0
	.db 0,1,1,1,1,1,0,0,0,0,0,0,0,0,0,0
	.db 0,1,1,1,1,1,1,1,1,0,0,1,1,1,1,1
	.db 0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0
	.db 0,1,1,1,1,1,1,1,1,0,0,0,0,0,0,0
	.db 0,0,0,0,0,0,0,0,0,0,0,1,1,1,1,1
leveldata2:
	.db 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,1
	.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	.db 1,1,0,0,0,0,0,0,0,0,0,0,0,0,0,1
	.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	.db 0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
	.db 0,0,0,0,0,0,0,0,0,0,0,0,0,1,1,0
	.db 0,1,1,0,0,0,0,0,0,0,0,0,0,1,0,0
	.db 0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,0
	.db 0,0,0,0,0,0,0,0,0,0,0,0,0,1,0,1
	.db 0,0,0,1,1,0,0,0,0,0,0,0,1,1,0,0
	.db 0,0,1,1,1,1,1,0,0,0,1,1,1,1,0,0
	.db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,0
	.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	.db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0
	.db 1,1,1,1,1,1,1,1,1,1,1,1,1,1,1,1
endasm
asm
	.bank 3
	.org $fffa
	.dw nmi		;//NMI
	.dw start	;//Reset
	.dw start	;//BRK
	.bank 4
	.org $0000
	.incbin "foreground.chr"
	.incbin "background.chr"
endasm
asm
	;//end of file
endasm

已发布

分类

来自

标签:

评论

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注