-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy patheditor.asm
570 lines (479 loc) · 10.6 KB
/
editor.asm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
; this sub routine
; calculates the visuals
; for the attribute memory display in the
; editor pause menu
; inputs:
; attr_value -> the value to be used
; modifies:
; registers and sprite index for sprite_2 - 5
init_attr_display:
lda attr_value
and #%00000011 ; top left
sta sprite_data_2+1
lda attr_value
and #%00001100 ; bottom left
lsr
lsr
sta sprite_data_4+1
lda attr_value
and #%00110000 ; top right
lsr
lsr
lsr
lsr
sta sprite_data_3+1
lda attr_value
and #%11000000 ; bottom right
lsr
lsr
lsr
lsr
lsr
lsr
sta sprite_data_5+1
rts
; this sub routine inits the color display
; inputs:
; color_select
; side effects:
; calls convert_hex
; overwrites sprites 6-7 tile index
init_color_display:
lda color_select
and #31 ; max color
sta color_select
jsr convert_hex
lda hex_buffer
sta sprite_data_7+1
lda hex_buffer+1
sta sprite_data_6+1
rts
; this sub routine inits the color value display
; inputs:
; color_select
; side effects:
; calls convert_hex
; overwrites sprites 8-9 tile index
init_value_display:
ldy color_select
lda level_palette, y
and #%00111111
sta level_palette, y
jsr convert_hex
lda hex_buffer
sta sprite_data_9+1
lda hex_buffer+1
sta sprite_data_8+1
rts
; transfers attribute visual display back to the attr_value
; inputs:
; sprite_data 2-5
; side effects
; registers and sprite_value
transfert_attr_display:
lda #$00
sta attr_value
lda sprite_data_5+1
asl
asl
asl
asl
asl
asl
sta attr_value
lda sprite_data_3+1
sta src_ptr
asl
asl
asl
asl
ora attr_value
sta attr_value
lda sprite_data_4+1
asl
asl
ora attr_value
sta attr_value
lda sprite_data_2+1
ora attr_value
sta attr_value
rts
.macro inc_dec_attr_macro sprite_data_addr
ldy sprite_data_addr
cpx #$01
bne @.mi.dec
iny
jmp @.mi.add_done
@.mi.dec:
dey
@.mi.add_done:
tya
and #%00000011
sta sprite_data_addr
rts
.endm
; this sub routine incs or decs
; the attribute value
; inputs:
; attr_value -> the attribute value
; x -> 0 = increment, 1 = decrement
; y -> area -> 0=top left, 1=bottom left, 2=top right, 3=bottom right
; side effects:
; modifies registers and attr_value
inc_dec_attr:
cpy #$03
bne @not_br
inc_dec_attr_macro sprite_data_5+1
@not_br:
cpy #$02
bne @not_tr
ldy sprite_data_4+1
inc_dec_attr_macro sprite_data_4+1
@not_tr:
cpy #$01
bne @not_bl
inc_dec_attr_macro sprite_data_3+1
@not_bl:
inc_dec_attr_macro sprite_data_2+1
; inits editor menu
init_editor_menu:
; clear bank select
lda #$00
sta level_data_ptr_bac
lda #$01
sta level_data_ptr_bac+1
; tile replace mode
lda editor_flags
and #%10111111
sta editor_flags
; backup player's location and
; move to cursor position
lda player_x
sta player_x_bac
lda player_y
sta player_y_bac
; copy palette
lda #<palette_data
sta palette_ptr
lda #>palette_data
sta palette_ptr+1
jsr load_palette
; set up initial location (redudant really)
lda #$01
sta player_x
lda #$09
sta player_y
; move sprite 1 to tile select location
lda #$77
sta sprite_data_1
lda #$48
sta sprite_data_1+3
lda #$00
sta sprite_data_1+1
sta sprite_data_1+2
; attributes 0
sta sprite_data_2+2
sta sprite_data_3+2
sta sprite_data_4+2
sta sprite_data_5+2
sta sprite_data_6+2
sta sprite_data_7+2
sta sprite_data_8+2
sta sprite_data_9+2
; set other spirtes to 0/0
sta sprite_data_2
sta sprite_data_2+3
sta sprite_data_3
sta sprite_data_3+3
sta sprite_data_4
sta sprite_data_4+3
; set the tile select's tile index
lda sprite_data+1
sta sprite_data_1+1
lda #<update_editor_menu
sta update_sub
lda #>update_editor_menu
sta update_sub+1
lda #<update_crit_none
sta update_sub_crit
lda #>update_crit_none
sta update_sub_crit+1
; set up player tile to become a pointer
lda #$31
sta sprite_data+1
; move sprites indicating
; attr values to correct position
; sprites_2, 3, 4, 5
lda #$70 ; x position
sta sprite_data_2+3 ; up left
sta sprite_data_3+3 ; bottom left
lda #$7F ; x position
sta sprite_data_4+3 ; up right
sta sprite_data_5+3 ; bottom right
lda #$28 ; y positon
sta sprite_data_2 ; up left
sta sprite_data_4 ; up right
lda #$38 ; y position
sta sprite_data_3 ; bottom left
sta sprite_data_5 ; bottom right
; move sprites incating color palette value
; 4 sprites one for color select
; one for value select
; sprites 6, 7, 8, 9
lda #19*8 ; x position
sta sprite_data_6+3
sta sprite_data_8+3
lda #20*8
sta sprite_data_7+3 ; x position
sta sprite_data_9+3
lda #10*8 ; y position
sta sprite_data_6
sta sprite_data_7
lda #12*8 ; y position
sta sprite_data_8
sta sprite_data_9
; sprite counter location
lda #21*8
sta sprite_data_A+3
lda #14*8
sta sprite_data_A
lda #20*8
sta sprite_data_B+3
lda #14*8
sta sprite_data_B
; move sprites for bank, address, and value
; to correct location
; 3 pairs of sprites
; x positions are always the same, y is different for each pair
lda #19*8 ; x position
sta sprite_data_C+3
sta sprite_data_E+3
sta sprite_data_10+3
lda #20*8 ; x position
sta sprite_data_D+3
sta sprite_data_F+3
sta sprite_data_11+3
lda #18*8 ; y position
sta sprite_data_C
sta sprite_data_D
lda #19*8
sta sprite_data_E
sta sprite_data_F
lda #20*8
sta sprite_data_10
sta sprite_data_11
lda #18*8 ; y position
sta sprite_data_C
sta sprite_data_D
jsr init_attr_display
jsr init_color_display
jsr init_value_display
rts
; init editor
init_editor:
jsr transfert_attr_display
; restore player's location
lda player_x_bac
sta player_x
lda player_y_bac
sta player_y
; copy palette
lda #<level_palette
sta palette_ptr
lda #>level_palette
sta palette_ptr+1
jsr load_palette
; set the tile select's tile index
lda sprite_data_1+1
sta sprite_data+1
; hide other sprite offscreen
lda #$00
sta sprite_data_1
sta sprite_data_1+3
sta sprite_data_5
sta sprite_data_5+3
sta sprite_data_6
sta sprite_data_6+3
sta sprite_data_7
sta sprite_data_7+3
sta sprite_data_8
sta sprite_data_8+3
sta sprite_data_9
sta sprite_data_9+3
sta sprite_data_A
sta sprite_data_A+3
sta sprite_data_B
sta sprite_data_B+3
sta sprite_data_C
sta sprite_data_C+3
sta sprite_data_D
sta sprite_data_D+3
sta sprite_data_E
sta sprite_data_E+3
sta sprite_data_F
sta sprite_data_F+3
sta sprite_data_10
sta sprite_data_10+3
sta sprite_data_11
sta sprite_data_11+3
; attributes 0 for player
sta sprite_data+2
lda #<update_editor
sta update_sub
lda #>update_editor
sta update_sub+1
lda #<update_crit_editor
sta update_sub_crit
lda #>update_crit_editor
sta update_sub_crit+1
; set up other sprites used to attribute drawing
lda #$30 ; corner tile
sta sprite_data_1+1
sta sprite_data_2+1
sta sprite_data_3+1
sta sprite_data_4+1
; set up rotation
lda #%01000000
sta sprite_data_2+2
lda #%10000000
sta sprite_data_3+2
lda #%11000000
sta sprite_data_4+2
rts
; update sub routine for editor menu
; this uses level_data_ptr_bac as temporary storage for
; address and bank offsets
; make sure that addresses dont
; ever attempt to read NES registers
; only ram and cartridge related values
update_editor_menu:
; sprite counter
ldy sprite_tile_size
iny
tya
and #$0F
sta sprite_data_A+1
ldy sprite_tile_size
iny
tya
and #$F0
lsr
lsr
lsr
lsr
sta sprite_data_B+1
lda menu_select
and #EDITOR_MENU_MAX_SELECT ; only 3 possible options
cmp #$0F ; if more than 9, overflow
bcc @no_overflow
lda #$00
@no_overflow:
sta menu_select
tax
; check for bit 1 of flags
lda editor_flags
and #%10000000
beq @not_tile_select_mode
lda #$3B
sta sprite_data+1
; check bounds
lda player_x
cmp #TILE_SELECT_MIN_X
bcs @not_min_x
ldy #TILE_SELECT_MIN_X
sty player_x
@not_min_x:
cmp #TILE_SELECT_MAX_X+1
bcc @not_max_x
ldy #TILE_SELECT_MAX_X
sty player_x
@not_max_x:
lda player_y
cmp #TILE_SELECT_MIN_Y
bcs @not_min_y
ldy #TILE_SELECT_MIN_Y
sty player_y
@not_min_y:
cmp #TILE_SELECT_MAX_Y+1
bcc @not_max_y
ldy #TILE_SELECT_MAX_Y
sty player_y
@not_max_y:
jmp @done
@not_tile_select_mode:
; set sprite at correct position
lda editor_menu_cursor_x, x
sta player_x
lda editor_menu_cursor_y, x
sta player_y
lda editor_menu_cursor_attr, x
sta sprite_data+2
lda #$31
sta sprite_data+1
; set up address related sprites
; bank is temp stored in level_data_ptr_bac
; address is stored in level_data_ptr_bac+1
lda level_data_ptr_bac
and #$0F
sta sprite_data_D+1
lda level_data_ptr_bac
lsr
lsr
lsr
lsr
sta sprite_data_C+1
lda level_data_ptr_bac+1
and #$0F
sta sprite_data_F+1
lda level_data_ptr_bac+1
lsr
lsr
lsr
lsr
sta sprite_data_E+1
lda level_data_ptr_bac
sta src_ptr+1
lda level_data_ptr_bac+1
sta src_ptr
ldy #$00
lda (src_ptr), y ; load value from that location
sta temp ; temporarily store it here
lda temp
and #$0F
sta sprite_data_11+1
lda temp
lsr
lsr
lsr
lsr
sta sprite_data_10+1
@done:
jmp update_done
; update sub routne for editor
update_editor:
; test if player tile is empty
; if so move another sprite in place
; to act as a cursor, otherwise move it offscreen
lda sprite_data+1
cmp #SPACE_TILE
bne @no_cursor
; init cursor
lda sprite_data
sta sprite_data_5
lda sprite_data+3
sta sprite_data_5+3
lda #$3B
sta sprite_data_5+1
jmp update_done
@no_cursor:
lda #$00
sta sprite_data_5
sta sprite_data_5+3
jmp update_done
; crit update for editor
update_crit_editor:
; clear prev inputs to allow holding A and B
lda #$00
sta prev_inputs
sta last_inputs ; also clear last_inputs
jmp update_crit_done