@gaialabs/iog-baserom 0.2.2 → 0.2.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,843 +0,0 @@
1
- ; =============================================================================
2
- ; Widescreen Patch for Illusion of Gaia
3
- ; =============================================================================
4
- ;
5
- ; Enables bsnes-hd widescreen support (384x224, 16:9 at 1:1 pixel ratio).
6
- ; Requires bsnes-hd emulator with matching .bso configuration file.
7
- ;
8
- ; Strategy: always-on widescreen (BSO b1B1) with ROM-side tilemap management.
9
- ; The game detects camera window width and handles two cases:
10
- ; - Multi-screen rooms: camera offset ensures 64px of valid map data on
11
- ; both margins. No blank tiles needed during gameplay.
12
- ; - Single-screen rooms: camera stays at cameraOffsetX. CameraFullRefresh
13
- ; blanks nametable columns outside the map with $0000 tiles.
14
- ;
15
- ; This follows the wide-snes approach (VitorVilela7/wide-snes) adapted for
16
- ; IOG's camera window system.
17
- ;
18
- ; =============================================================================
19
-
20
- ?INCLUDE 'camera_scroll_controller'
21
- ?INCLUDE 'camera_tilemap'
22
- ?INCLUDE 'sprite_composition'
23
-
24
- ; --- Widescreen Constants ---
25
- ; 64 extra pixels per side = 384px total (256 + 128)
26
- ; 384x224 = exact 16:9 at 1:1 pixel aspect ratio
27
-
28
- !WS_EXTRA 0040
29
- !WS_RIGHT_EDGE 0140
30
- !WS_MULTI_WIDTH 0180
31
- !WS_CULL_WIDTH 0180
32
- !WS_OAM_BIAS 0040
33
- !WS_OAM_CULL 01D0
34
- !WS_OAM_UNBIAS 0050
35
- !WS_PREFETCH_RIGHT 0140
36
- !WS_PREFETCH_LEFT FFC0
37
- !WS_RIGHT_MARGIN_THRESH 00C1
38
-
39
- ; =============================================================================
40
- ; CAMERA BOUNDS OVERRIDE — camera_scroll_controller
41
- ; =============================================================================
42
- ; Detects whether the current camera window is multi-screen or single-screen.
43
- ;
44
- ; Multi-screen (cameraBoundsX - cameraOffsetX >= 384):
45
- ; Camera minimum = cameraOffsetX + 64, maximum = cameraBoundsX - 320.
46
- ; This guarantees both widescreen margins always have valid map data.
47
- ;
48
- ; Single-screen (cameraBoundsX - cameraOffsetX < 384):
49
- ; Camera fixed at cameraOffsetX. The room is centered by bsnes-hd, and
50
- ; CameraFullRefresh blanks the margin nametable columns.
51
-
52
- code_00EAF0! {
53
- LDA #$1000
54
- TSB $12
55
- COP [SetEntryContinue]
56
- LDA $layerPriorityFlag
57
- BIT #$0200
58
- BEQ ws_cam_active
59
- RTL
60
-
61
- ws_cam_active:
62
- PHD
63
- LDA $playerActorDp
64
- TCD
65
- LDA $14
66
- SEC
67
- SBC #$0008
68
- STA $playerXPos
69
- LSR
70
- LSR
71
- LSR
72
- LSR
73
- STA $playerXTile
74
- LDA $16
75
- SEC
76
- SBC #$0010
77
- STA $playerYPos
78
- LSR
79
- LSR
80
- LSR
81
- LSR
82
- STA $playerYTile
83
- LDA $playerFlags
84
- BIT #$0100
85
- BNE ws_cam_delta
86
-
87
- ; --- X axis: detect single-screen vs multi-screen ---
88
- LDA $cameraBoundsX
89
- SEC
90
- SBC $cameraOffsetX
91
- CMP #$WS_MULTI_WIDTH ; camera window >= 384px?
92
- BCS ws_cam_x_multi
93
-
94
- ; --- SINGLE-SCREEN: fix camera at cameraOffsetX ---
95
- LDA $cameraOffsetX
96
- BRA ws_cam_xset
97
-
98
- ws_cam_x_multi:
99
- ; --- MULTI-SCREEN: camera with widescreen offsets ---
100
- LDA $14
101
- SEC
102
- SBC #$0080 ; proposed = playerX - 128
103
- BMI ws_cam_xmin ; negative → clamp to minimum
104
-
105
- ; Check against effective minimum (cameraOffsetX + WS_EXTRA)
106
- STA $cameraTargetX ; temp store proposed
107
- LDA $cameraOffsetX
108
- CLC
109
- ADC #$WS_EXTRA ; effective min = cameraOffsetX + 64
110
- CMP $cameraTargetX ; effective min vs proposed
111
- BEQ ws_cam_xright
112
- BPL ws_cam_xmin ; proposed < effective min → clamp
113
-
114
- ws_cam_xright:
115
- ; Proposed >= minimum. Check right edge.
116
- LDA $cameraTargetX ; reload proposed
117
- CLC
118
- ADC #$WS_RIGHT_EDGE ; + 320 = widescreen right edge
119
- CMP $cameraBoundsX
120
- BMI ws_cam_xedge ; within bounds
121
- LDA $cameraBoundsX
122
- BRA ws_cam_xedge
123
-
124
- ws_cam_xmin:
125
- LDA $cameraOffsetX
126
- CLC
127
- ADC #$WS_EXTRA ; min scroll = cameraOffsetX + 64
128
- BRA ws_cam_xset
129
-
130
- ws_cam_xedge:
131
- SEC
132
- SBC #$WS_RIGHT_EDGE ; - 320 = convert right edge back to scroll
133
-
134
- ws_cam_xset:
135
- STA $cameraTargetX
136
-
137
- ; --- Y axis camera targeting (unchanged) ---
138
- LDA $16
139
- SEC
140
- SBC #$0080
141
- BMI ws_cam_ymin
142
- CMP $cameraOffsetY
143
- BMI ws_cam_ymin
144
- CLC
145
- ADC #$0100
146
- CMP $cameraBoundsY
147
- BMI ws_cam_yedge
148
- LDA $cameraBoundsY
149
- BRA ws_cam_yedge
150
-
151
- ws_cam_ymin:
152
- LDA $cameraOffsetY
153
- BRA ws_cam_yset
154
-
155
- ws_cam_yedge:
156
- SEC
157
- SBC #$0100
158
-
159
- ws_cam_yset:
160
- STA $cameraTargetY
161
-
162
- ws_cam_delta:
163
- LDA $cameraTargetX
164
- SEC
165
- SBC $bg1ScrollH
166
- STA $effectDeltaX
167
- LDA $cameraTargetY
168
- SEC
169
- SBC $bg2ScrollH
170
- STA $effectDeltaY
171
- PLD
172
- RTL
173
- }
174
-
175
- ; =============================================================================
176
- ; FULL TILEMAP REFRESH — CameraFullRefresh
177
- ; =============================================================================
178
- ; On scene load, populates the entire 512px nametable. Starts 64px earlier
179
- ; than the scroll position to fill the widescreen left margin with valid data.
180
- ;
181
- ; For each column: checks if the position is within the map data range
182
- ; [0, mapBoundsX). If outside, calls BlankScrollColumn to write $0000 tiles.
183
- ; This handles both single-screen rooms (most columns blank) and multi-screen
184
- ; rooms at map edges.
185
- ;
186
- ; The loop advances $18 by 16 without wrapping. The VRAM column address
187
- ; computation naturally wraps via AND masking, so every nametable column
188
- ; gets exactly one write.
189
-
190
- CameraFullRefresh! {
191
- PHP
192
- REP #$20
193
-
194
- ; --- Clamp cameraTargetX within map bounds ---
195
- LDA $cameraTargetX, X
196
- CMP $mapBoundsX, X
197
- BCC ws_cfr_xok
198
- LDA $mapBoundsX, X
199
- DEC
200
- STA $00
201
- LDA $cameraTargetX, X
202
- AND $00
203
- STA $cameraTargetX, X
204
-
205
- ws_cfr_xok:
206
- STA $bg1ScrollH, X
207
- AND #$FFF0
208
- STA $18
209
-
210
- ; --- Start 64px earlier to fill widescreen left margin ---
211
- LDA $bg1ScrollH, X
212
- SEC
213
- SBC #$WS_EXTRA
214
- BCS ws_cfr_adj_ok
215
- LDA #$0000
216
-
217
- ws_cfr_adj_ok:
218
- AND #$FFF0
219
- STA $18
220
-
221
- ; --- Clamp cameraTargetY within map bounds ---
222
- ws_cfr_y:
223
- LDA $cameraTargetY, X
224
- BMI ws_cfr_yok
225
- CMP $mapBoundsY, X
226
- BCC ws_cfr_yok
227
- LDA $mapBoundsY, X
228
- DEC
229
- STA $00
230
- LDA $cameraTargetY, X
231
- AND $00
232
- STA $cameraTargetY, X
233
-
234
- ws_cfr_yok:
235
- STA $bg2ScrollH, X
236
- AND #$FFF0
237
- STA $1C
238
-
239
- ; --- DMA setup ---
240
- SEP #$20
241
- LDA #$81
242
- STA $VMAIN
243
- LDA #$01
244
- STA $DMAP0
245
- LDA #$18
246
- STA $BBAD0
247
- LDA #$7E
248
- STA $A1B0
249
- REP #$20
250
- LDA #$0020 ; 32 column iterations
251
-
252
- ws_cfr_loop:
253
- PHA
254
-
255
- ; --- Bounds check: is $18 within valid map data? ---
256
- LDA $18
257
- CMP $mapBoundsX, X ; position >= map width?
258
- BCS ws_cfr_blank ; yes → fill with blank tiles
259
-
260
- ; --- Render valid map column ---
261
- JSR $&RenderScrollRow
262
- BRA ws_cfr_dma
263
-
264
- ws_cfr_blank:
265
- ; --- Fill column with blank ($0000) tiles ---
266
- JSR $&BlankScrollColumn
267
-
268
- ws_cfr_dma:
269
- ; --- DMA staging buffer to VRAM ---
270
- PHX
271
- LDA $06B2, X
272
- TAX
273
- LDA $7E0000, X
274
- TAY
275
- JSR $&DmaHorizontalStrip
276
- PLX
277
-
278
- ; --- Advance $18 by 16 (no wrapping — blank columns advance linearly) ---
279
- LDA $18
280
- CLC
281
- ADC #$0010
282
- STA $18
283
-
284
- PLA
285
- DEC
286
- BNE ws_cfr_loop
287
-
288
- ; --- Clear dirty staging flags ---
289
- LDA #$0000
290
- STA $tilemapStaging
291
- STA $7E3288
292
- STA $7E3184
293
- STA $7E330C
294
- JSL $@system_init.UploadCgramPalette
295
- PLP
296
- RTL
297
- }
298
-
299
- ; =============================================================================
300
- ; BLANK SCROLL COLUMN — BlankScrollColumn
301
- ; =============================================================================
302
- ; Fills a nametable column's staging buffer with blank ($0000) tiles.
303
- ; Computes the VRAM column address from $18 (same math as RenderScrollRow)
304
- ; and zeros the tile data. Used for widescreen margin columns outside the map.
305
- ;
306
- ; Input: X = layer (0 or 2), $18 = column pixel X position
307
- ; Output: staging buffer at $06B2+X filled with VRAM address and blank tiles
308
- ; Preserves: X (layer index)
309
-
310
- BlankScrollColumn {
311
- PHX ; save layer index
312
-
313
- ; --- Compute VRAM column address from $18 ---
314
- LDA $06B2, X ; staging buffer base for this layer
315
- PHA ; save staging ptr on stack
316
- LDA $18
317
- LSR
318
- LSR
319
- LSR
320
- AND #$003E ; column index × 2 (0-62)
321
- BIT #$0020 ; bit 5: left or right nametable half?
322
- BNE ws_bsc_right
323
-
324
- ; --- Left nametable half ---
325
- CLC
326
- ADC $06BA, X ; + VRAM tilemap base
327
- PLX ; X = staging buffer pointer
328
- STA $0000, X ; store VRAM addr for half A
329
- INC
330
- STA $0042, X ; store VRAM addr for half B (adjacent column)
331
- BRA ws_bsc_fill
332
-
333
- ws_bsc_right:
334
- ; --- Right nametable half ---
335
- AND #$001E
336
- CLC
337
- ADC $06BA, X ; + VRAM tilemap base
338
- CLC
339
- ADC #$0400 ; + $400 for right nametable half
340
- PLX ; X = staging buffer pointer
341
- STA $0000, X ; store VRAM addr for half A
342
- INC
343
- STA $0042, X ; store VRAM addr for half B
344
-
345
- ws_bsc_fill:
346
- ; --- Zero 128 bytes of tile data (64 per half) ---
347
- ; Half A: staging+$02 to staging+$41 (32 words)
348
- ; Half B: staging+$44 to staging+$83 (32 words)
349
- LDA #$0000
350
- LDY #$0020 ; 32 iterations
351
- ws_bsc_loop:
352
- STA $0002, X ; half A tile word
353
- STA $0044, X ; half B tile word
354
- INX
355
- INX
356
- DEY
357
- BNE ws_bsc_loop
358
-
359
- PLX ; restore layer index
360
- RTS
361
- }
362
-
363
- ; =============================================================================
364
- ; TILEMAP PRE-FETCH — UpdateScrollColumn
365
- ; =============================================================================
366
- ; Overrides the per-frame column pre-fetch to use widescreen-edge offsets.
367
- ;
368
- ; Original offsets (+256 right, +0 left) pre-fetch at the 256px viewport edges.
369
- ; With 384px widescreen, columns in the 64px margins beyond those edges become
370
- ; stale after scrolling. The fix: pre-fetch at the WIDESCREEN edges instead
371
- ; (+320 right, -64 left). This ensures the entire 384px visible area has
372
- ; up-to-date tile data as the camera scrolls.
373
- ;
374
- ; Over a full right+left scroll sweep, all 32 nametable columns get refreshed.
375
- ; During one-directional scrolling, any un-refreshed columns remain in the
376
- ; off-screen nametable buffer (128px past the widescreen edge).
377
- ;
378
- ; Bounds check: if the pre-fetch position exceeds mapBoundsX (or wraps
379
- ; negative), the column is filled with blank tiles via BlankScrollColumn.
380
-
381
- UpdateScrollColumn! {
382
- LDA #$WS_PREFETCH_LEFT ; -64 ($FFC0) for leftward scroll
383
- LDY $scrollDeltaXClamped, X
384
- BMI ws_usc_offset
385
- LDA #$WS_PREFETCH_RIGHT ; +320 ($0140) for rightward scroll
386
-
387
- ws_usc_offset:
388
- CLC
389
- ADC $bg1ScrollH, X ; column = scroll + offset
390
- STA $18
391
- LDA $bg2ScrollH, X
392
- STA $1C
393
-
394
- ; --- Bounds check: is column within valid map range? ---
395
- LDA $18
396
- BMI ws_usc_blank ; negative (unsigned overflow from -64) → blank
397
- CMP $mapBoundsX, X ; >= map width?
398
- BCS ws_usc_blank ; yes → blank fill
399
-
400
- ; --- Normal rendering ---
401
- JSR $&RenderScrollRow
402
- RTS
403
-
404
- ws_usc_blank:
405
- ; --- Blank fill for out-of-bounds column ---
406
- JSR $&BlankScrollColumn
407
- RTS
408
- }
409
-
410
- ; =============================================================================
411
- ; ROW PRE-FETCH — UpdateScrollRow
412
- ; =============================================================================
413
- ; Widescreen-aware row pre-fetch. RenderScrollColumn covers 2 map pages
414
- ; (512px). With 384px widescreen, the viewport can span 3 pages:
415
- ;
416
- ; Left margin issue: scroll_low in [$00, $3F] AND scroll >= $100
417
- ; Page P-1 needed for left margin, but render covers P, P+1.
418
- ;
419
- ; Right margin issue: scroll_low in [$C1, $FF]
420
- ; Page P+2 needed for right margin, but render covers P, P+1.
421
- ;
422
- ; No issue: scroll_low in [$40, $C0] (or scroll < $100)
423
- ; Both margins fit within 2 rendered pages.
424
- ;
425
- ; Fix: double render + merge. Render the row twice with different page
426
- ; selections, save the correct margin entries from one render, then
427
- ; patch them into the other render's staging buffer.
428
- ;
429
- ; Left margin: shifted render ($18=scroll-64) → save slot 0 entries 12-15
430
- ; original render ($18=scroll) → restore to slot 1 entries 12-15
431
- ;
432
- ; Right margin: shifted render ($18=scroll+64) → save slot 1 entries 0-3
433
- ; original render ($18=scroll) → restore to slot 0 entries 0-3
434
-
435
- UpdateScrollRow! {
436
- LDA $bg1ScrollH, X
437
- STA $18
438
-
439
- ; --- Y axis setup (shared by all paths) ---
440
- LDA #$FFF0 ; default = −16 (top edge for upward scroll)
441
- LDY $scrollDeltaYClamped, X
442
- BMI ws_usr_yoffset
443
- LDA #$00E0 ; scrolling down: +224 for bottom screen edge
444
-
445
- ws_usr_yoffset:
446
- CLC
447
- ADC $bg2ScrollH, X
448
-
449
- ws_usr_ywrap:
450
- STA $1C
451
- CMP $mapBoundsY, X
452
- BCC ws_usr_ready
453
- SEC
454
- SBC $mapBoundsY, X
455
- BRA ws_usr_ywrap
456
-
457
- ws_usr_ready:
458
- ; --- Determine which case applies ---
459
- LDA $bg1ScrollH, X
460
- AND #$00FF
461
- CMP #$WS_EXTRA ; low byte < 64?
462
- BCS ws_usr_not_left ; >= 64 → check right margin
463
-
464
- ; Low byte [0, 63] → possible left margin issue
465
- LDA $bg1ScrollH, X
466
- CMP #$0100
467
- BCC ws_usr_simple ; page 0 → no crossing possible
468
- BRL ws_usr_double_left ; page 1+ → left margin fix (long branch)
469
-
470
- ws_usr_not_left:
471
- CMP #$WS_RIGHT_MARGIN_THRESH ; low byte >= 193?
472
- BCC ws_usr_simple ; [64, 192] → simple path
473
- BRL ws_usr_double_right ; [193, 255] → right margin fix (long branch)
474
-
475
- ws_usr_simple:
476
- ; === SIMPLE PATH (single render covers both margins) ===
477
- JSR $&RenderScrollColumn
478
- RTS
479
-
480
- ; =================================================================
481
- ; LEFT MARGIN DOUBLE RENDER
482
- ; =================================================================
483
- ; Shifted render ($18 = scroll-64): slot 0 has page P-1 (left margin).
484
- ; Original render ($18 = scroll): slot 1 overwrites left margin with
485
- ; wrong page P+1 data. Save entries 12-15 from shifted slot 0 and
486
- ; patch into original slot 1.
487
-
488
- ws_usr_double_left:
489
- PHB
490
- SEP #$20
491
- LDA #$7E
492
- PHA
493
- PLB
494
- REP #$20
495
-
496
- ; Render 1: shifted (covers left margin page P-1)
497
- LDA $bg1ScrollH, X
498
- SEC
499
- SBC #$WS_EXTRA
500
- STA $18
501
- JSR $&RenderScrollColumn
502
-
503
- ; Save entries 12-15 from slot 0
504
- STX $00
505
- LDA $06B6, X
506
- TAX
507
- LDA $0032, X
508
- PHA
509
- LDA $0034, X
510
- PHA
511
- LDA $0036, X
512
- PHA
513
- LDA $0038, X
514
- PHA
515
- LDA $003A, X
516
- PHA
517
- LDA $003C, X
518
- PHA
519
- LDA $003E, X
520
- PHA
521
- LDA $0040, X
522
- PHA
523
- LDA $0072, X
524
- PHA
525
- LDA $0074, X
526
- PHA
527
- LDA $0076, X
528
- PHA
529
- LDA $0078, X
530
- PHA
531
- LDA $007A, X
532
- PHA
533
- LDA $007C, X
534
- PHA
535
- LDA $007E, X
536
- PHA
537
- LDA $0080, X
538
- PHA
539
- LDX $00
540
-
541
- ; Render 2: original (covers right margin page P+1)
542
- LDA $bg1ScrollH, X
543
- STA $18
544
- JSR $&RenderScrollColumn
545
-
546
- ; Restore entries 12-15 into slot 1
547
- STX $00
548
- LDA $06B6, X
549
- CLC
550
- ADC #$0082
551
- TAX
552
- PLA
553
- STA $0080, X
554
- PLA
555
- STA $007E, X
556
- PLA
557
- STA $007C, X
558
- PLA
559
- STA $007A, X
560
- PLA
561
- STA $0078, X
562
- PLA
563
- STA $0076, X
564
- PLA
565
- STA $0074, X
566
- PLA
567
- STA $0072, X
568
- PLA
569
- STA $0040, X
570
- PLA
571
- STA $003E, X
572
- PLA
573
- STA $003C, X
574
- PLA
575
- STA $003A, X
576
- PLA
577
- STA $0038, X
578
- PLA
579
- STA $0036, X
580
- PLA
581
- STA $0034, X
582
- PLA
583
- STA $0032, X
584
- LDX $00
585
-
586
- PLB
587
- RTS
588
-
589
- ; =================================================================
590
- ; RIGHT MARGIN DOUBLE RENDER
591
- ; =================================================================
592
- ; Shifted render ($18 = scroll+64): slot 1 has page P+2 (right margin).
593
- ; Original render ($18 = scroll): slot 0 overwrites right margin with
594
- ; wrong page P data. Save entries 0-3 from shifted slot 1 and
595
- ; patch into original slot 0.
596
-
597
- ws_usr_double_right:
598
- PHB
599
- SEP #$20
600
- LDA #$7E
601
- PHA
602
- PLB
603
- REP #$20
604
-
605
- ; Render 1: shifted (covers right margin page P+2)
606
- LDA $bg1ScrollH, X
607
- CLC
608
- ADC #$WS_EXTRA
609
- STA $18
610
- JSR $&RenderScrollColumn
611
-
612
- ; Save entries 0-3 from slot 1 (second pass = page P+2)
613
- STX $00
614
- LDA $06B6, X
615
- CLC
616
- ADC #$0082
617
- TAX
618
- LDA $0002, X
619
- PHA
620
- LDA $0004, X
621
- PHA
622
- LDA $0006, X
623
- PHA
624
- LDA $0008, X
625
- PHA
626
- LDA $000A, X
627
- PHA
628
- LDA $000C, X
629
- PHA
630
- LDA $000E, X
631
- PHA
632
- LDA $0010, X
633
- PHA
634
- LDA $0042, X
635
- PHA
636
- LDA $0044, X
637
- PHA
638
- LDA $0046, X
639
- PHA
640
- LDA $0048, X
641
- PHA
642
- LDA $004A, X
643
- PHA
644
- LDA $004C, X
645
- PHA
646
- LDA $004E, X
647
- PHA
648
- LDA $0050, X
649
- PHA
650
- LDX $00
651
-
652
- ; Render 2: original (covers left margin page P)
653
- LDA $bg1ScrollH, X
654
- STA $18
655
- JSR $&RenderScrollColumn
656
-
657
- ; Restore entries 0-3 into slot 0 (first pass)
658
- STX $00
659
- LDA $06B6, X
660
- TAX
661
- PLA
662
- STA $0050, X
663
- PLA
664
- STA $004E, X
665
- PLA
666
- STA $004C, X
667
- PLA
668
- STA $004A, X
669
- PLA
670
- STA $0048, X
671
- PLA
672
- STA $0046, X
673
- PLA
674
- STA $0044, X
675
- PLA
676
- STA $0042, X
677
- PLA
678
- STA $0010, X
679
- PLA
680
- STA $000E, X
681
- PLA
682
- STA $000C, X
683
- PLA
684
- STA $000A, X
685
- PLA
686
- STA $0008, X
687
- PLA
688
- STA $0006, X
689
- PLA
690
- STA $0004, X
691
- PLA
692
- STA $0002, X
693
- LDX $00
694
-
695
- PLB
696
- RTS
697
- }
698
- ; =============================================================================
699
- ; Extends the on-screen X range from [0, 256) to [-64, 320) by biasing the
700
- ; screen-relative coordinate by +64 and comparing against 384 (widescreen width).
701
- ;
702
- ; Original: screenX = actorX - originX - scroll; on-screen if [0, 256)
703
- ; Patched: biasedX = screenX + 64; on-screen if biasedX in [0, 384)
704
-
705
- loc_03C610! {
706
- LDA $14 ; actorX
707
- SEC
708
- SBC $18 ; - originX
709
- SEC
710
- SBC $bg1ScrollH ; = screenX relative to scroll origin
711
- CLC
712
- ADC #$WS_EXTRA ; + 64 = bias to widescreen coordinate space
713
- CMP #$WS_CULL_WIDTH ; 384 = widescreen width
714
- BCC loc_03C631 ; biasedX in [0, 384) → on screen
715
- BMI loc_03C623 ; biasedX < 0 → actor left of widescreen, check right edge
716
- JMP $&SortActors_OffScreen
717
- }
718
-
719
- loc_03C623! {
720
- LDA $14 ; actorX
721
- CLC
722
- ADC $1C ; + actor width
723
- SEC
724
- SBC $bg1ScrollH ; = right edge screenX
725
- CLC
726
- ADC #$WS_EXTRA ; + 64 = bias to widescreen coordinate space
727
- CMP #$WS_CULL_WIDTH ; 384 = widescreen width
728
- BCS SortActors_OffScreen ; right edge also off widescreen → fully off screen
729
- }
730
-
731
- ; =============================================================================
732
- ; SUB-SPRITE OAM CLIPPING — DecomposeActorMetasprites
733
- ; =============================================================================
734
- ; The per-sub-sprite X bounds check clips individual tiles at CMP #$0110 (272px).
735
- ; $18 = actorScreenX + 16 (origin margin). The original SBC #$000F with C=0
736
- ; subtracts 16 (removing the margin) before storing the OAM X value.
737
- ;
738
- ; For widescreen: bias +64 to handle negative screen X from the left margin,
739
- ; then compare against 464 (384 + 16 + 64). After the check, SEC + SBC #$50
740
- ; removes BOTH the +64 bias AND the +16 origin margin (net -80), matching the
741
- ; original's net -16 subtraction.
742
-
743
- loc_03C8DE! {
744
- AND #$00FF
745
- CLC
746
- ADC $18
747
- CLC
748
- ADC #$WS_OAM_BIAS ; +64 bias for signed widescreen range check
749
- CMP #$WS_OAM_CULL ; 464 = 384 + 16 + 64
750
- BCS loc_03C920
751
- SEC
752
- SBC #$WS_OAM_UNBIAS ; SEC;SBC #$50 = subtract 80 (64 bias + 16 origin margin)
753
- SEP #$20
754
- STA $0422, Y
755
- XBA
756
- LSR
757
- ROR $00
758
- LDA $0000, X
759
- LSR
760
- ROR $00
761
- DEC $0E
762
- BNE loc_03C909
763
- LDA $00
764
- STA ($06)
765
- INC $06
766
- LDA #$04
767
- STA $0E
768
- }
769
-
770
- ; =============================================================================
771
- ; SUB-SPRITE OAM CLIPPING — DecomposePlayerSprites
772
- ; =============================================================================
773
- ; Same fix as actor metasprites: +64 bias, CMP 464, then SEC;SBC #$50 removes
774
- ; the bias AND origin margin to produce the correct OAM X value.
775
-
776
- loc_03C9BB! {
777
- AND #$00FF
778
- CLC
779
- ADC $18
780
- CLC
781
- ADC #$WS_OAM_BIAS
782
- CMP #$WS_OAM_CULL
783
- BCS PlayerSprite_OffScreen
784
- SEC
785
- SBC #$WS_OAM_UNBIAS
786
- SEP #$20
787
- STA $0422, Y
788
- XBA
789
- LSR
790
- ROR $00
791
- LDA $0000, X
792
- LSR
793
- ROR $00
794
- DEC $0E
795
- BNE loc_03C9E6
796
- LDA $00
797
- STA ($06)
798
- INC $06
799
- LDA #$04
800
- STA $0E
801
- }
802
-
803
- ; =============================================================================
804
- ; SUB-SPRITE OAM CLIPPING — RenderComposeBuffer
805
- ; =============================================================================
806
- ; Compose buffer sprites compute screen X as bufferX − bg1ScrollH (no origin
807
- ; margin). Bias +64 to handle negative widescreen X, compare against 464
808
- ; (384 + 16 tolerance + 64 bias). After the check, SEC + SBC #$40 removes
809
- ; ONLY the bias (no origin margin to remove for compose buffer sprites).
810
-
811
- loc_03C79E! {
812
- LDA $7F3102, X
813
- SEC
814
- SBC $bg2ScrollH
815
- CMP #$00F0
816
- BCS loc_03C7E8
817
- STA $0423, Y
818
- LDA $7F3104, X
819
- STA $0424, Y
820
- LDA $oamComposeBuffer, X
821
- SEC
822
- SBC $bg1ScrollH
823
- CLC
824
- ADC #$WS_OAM_BIAS ; +64 bias for widescreen left margin
825
- CMP #$WS_OAM_CULL ; 464 = 384 + 16 tolerance + 64 bias
826
- BCS loc_03C7E8
827
- SEC
828
- SBC #$WS_OAM_BIAS ; SEC;SBC #$40 = subtract 64 (bias only, no margin)
829
- SEP #$20
830
- STA $0422, Y
831
- XBA
832
- LSR
833
- ROR $00
834
- CLC
835
- ROR $00
836
- DEC $0E
837
- BNE loc_03C7DC
838
- LDA $00
839
- STA ($06)
840
- INC $06
841
- LDA #$04
842
- STA $0E
843
- }