-
-
Notifications
You must be signed in to change notification settings - Fork 8
/
dgolf.s
2023 lines (1919 loc) · 31.1 KB
/
dgolf.s
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
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
;
; dgolf.s
; NESert Golfing, by Brad Smith 2019
; http://rainwarrior.ca
;
.macpack longbranch
; ===
; RAM
; ===
.segment "ZEROPAGE"
_ptr: .res 2 ; shared pointer for C interface
_seed: .res 4 ; random number seed (only using low 3 bytes)
ppu_post_mode: .res 1
_seedw: .res 4 ; TE dependent seed for wind changes only
_seedf: .res 4 ; TE independent seed for things that can still be random (e.g. rain/snow animation)ppu_post_mode: .res 1
sound_ptr: .res 2
_input: .res 16
mouse_index: .res 1
fourscore_off: .res 1
_gamepad: .res 1
_mouse1: .res 1
_mouse2: .res 1
_mouse3: .res 1
; convenient index/temporary values
_i: .res 1
_j: .res 1
_k: .res 1
_l: .res 1
_mx: .res 2
_nx: .res 2
_ox: .res 2
_px: .res 2
_ux: .res 2
_vx: .res 2
_te: .res 4 ; TE signature for selecting TE mode (first byte is 0/nonzero for TE)
; nesert golfing
_floor_column: .res 1
_weather_tile: .res 1
_weather_attribute: .res 1 ; bits 2-4 are speed of descent
_weather_wind_dir: .res 1 ; wind direction: 0, 1, or -1
_weather_wind_p: .res 1 ; wind probability 0 = never, 255 = almost 1 per frame
_weather_rate_min: .res 1 ; minimum wait until next spawn
_weather_rate_mask: .res 1 ; prng mask add until next spawn
weather_wait: .res 1 ; current wait until next spawn
weather_next: .res 1 ; next spawn index
_hole: .res 1 ; current hole (0 for ending)
_ocean_attribute: .res 1 ; starting byte of ocean attribute (255 before last hole is built)
_tx: .res 2 ; temporary X
_ty: .res 2 ; temporary Y
_tsx: .res 2 ; signed temporary X
_tsy: .res 2 ; signed temporary Y
_ball_x: .res 4
_ball_y: .res 4
_ball_vx: .res 4
_ball_vy: .res 4
_balls_x: .res 16
_balls_y: .res 4
_balls_fx = _balls_x+0
_balls_lx = _balls_x+1
_balls_hx = _balls_x+2
_balls_wx = _balls_x+1
_norm_x: .res 2
_norm_y: .res 2
; sound
apu_out: .res 16 ; last values written to APU
apu_sqh: .res 2 ; last written values to $4003/$4007
sound_pos: .res 1
sound_seed: .res 2
snow_pitch: .res 1
snow_time: .res 1
.segment "BSS"
CSTACK_SIZE = 128
.align 256
_floor_y: .res 512 ; floor height
_floor_a: .res 512 ; floor angle
cstack: .res 128 ; CC65 internal C stack
_floor_render: .res 64 ; floor render buffer
temp: .res 4
.segment "STACK"
sound: .res 2
ppu_2000: .res 1
ppu_2001: .res 1
ppu_2005x: .res 2 ; second byte is high bit (redundant in $2000)
ppu_2005y: .res 2 ; second byte is high bit (redundant in $2000)
_ppu_send_addr: .res 2
_ppu_send_count: .res 1
_ppu_send: .res 64
_palette: .res 32
.segment "OAM"
.align 256
_oam: .res 256
.exportzp _ptr
.exportzp _seed
.exportzp _seedw, _seedf
.exportzp _input, _gamepad, _mouse1, _mouse2, _mouse3
.exportzp _i,_j,_k,_l
.exportzp _mx,_nx,_ox,_px
.exportzp _ux,_vx
.exportzp _te
.exportzp _floor_column
.exportzp _weather_tile
.exportzp _weather_attribute
.exportzp _weather_wind_dir
.exportzp _weather_wind_p
.exportzp _weather_rate_min
.exportzp _weather_rate_mask
.exportzp _hole
.exportzp _ocean_attribute
.exportzp _tx
.exportzp _ty
.exportzp _tsx
.exportzp _tsy
.exportzp _ball_x
.exportzp _ball_y
.exportzp _ball_vx
.exportzp _ball_vy
.exportzp _balls_x
.exportzp _balls_fx
.exportzp _balls_lx
.exportzp _balls_hx
.exportzp _balls_wx
.exportzp _balls_y
.exportzp _norm_x
.exportzp _norm_y
.export _floor_render
.export _floor_y
.export _floor_a
.export _ppu_send_addr
.export _ppu_send_count
.export _ppu_send
.export _palette
.export _oam
.enum
POST_OFF = 1
POST_NONE = 2
POST_UPDATE = 3
POST_DOUBLE = 4
.endenum
; cc65 temporaries
.importzp sp, sreg, regsave
.importzp ptr1, ptr2, ptr3, ptr4
.importzp tmp1, tmp2, tmp3, tmp4
; cc65 library functions
.import popa ; A = byte from cstack, Y=0, sp+=1
.import popax ; A:X = two bytes from cstack, Y=0, sp+=2
.import _seed_start ; TE: from dgolf.c, it should persist on restart
.import _holes
; ==============
; NESert Golfing
; ==============
OCEAN_FLOOR = 224 ; must be multiple of 8 and match parallel definition in dgolf.c
.export _layers_chr
.export _sprite_chr
.export _layerste_chr
.export _LAYERS_CHR_SIZE
.export _SPRITE_CHR_SIZE
.export _LAYERSTE_CHR_SIZE
.export _read_slope
.export _read_norm_x
.export _read_norm_y
.export _floor_render_prepare
.export _weather_shift
.export _weather_animate
.export _fmult
.export _hole
.export _te_switch
.export _soft_reset
.segment "RODATA"
_layers_chr: .incbin "layers.chr"
_LAYERS_CHR_SIZE: .word * - _layers_chr
_sprite_chr: .incbin "sprite.chr"
_SPRITE_CHR_SIZE: .word * - _sprite_chr
_layerste_chr: .incbin "layerste.chr"
_LAYERSTE_CHR_SIZE: .word * - _layerste_chr
.include "temp/slopes.inc"
;slope_y0/1
;norm_x0/1
;norm_y0/1
.segment "CODE"
_read_slope:
tay
ldx slope_y1, Y
lda slope_y0, Y
rts
_read_norm_x:
tay
ldx norm_x1, Y
lda norm_x0, Y
rts
_read_norm_y:
tay
ldx norm_y1, Y
lda norm_y0, Y
rts
.proc _floor_render_prepare
; A = 0,1,2,3,4,5, 6+
; phases:
; 0 - build render data (32 bytes of CHR tile, 30 bytes of nametable)
; 1-4 - prepare CHR tiles for send
; 5 - prepare nametable column for send, increment column
; 6-7 ocean attributes on final hill
cmp #6
jcs floor_send_ocean
cmp #0
beq floor_build
cmp #5
bcs floor_send_nmt
floor_send_chr: ; A = 1-4
tay
; ppu_send_addr =
; vertical: ((A-1) * 256) + 0x800 +
; horizontal: ((column & 15) * 16) +
; slice: (column & 16) * (16 * 4)
; plane: (column & 32) / 4
clc ; vertical
adc #$07
sta _ppu_send_addr+1
lda _floor_column ; slice
and #16
lsr
lsr
clc
adc _ppu_send_addr+1
sta _ppu_send_addr+1
lda _floor_column ; horizontal
;and #15 ; implicit in << 4
asl
asl
asl
asl
sta _ppu_send_addr+0
lda _floor_column ; plane
and #32
lsr
lsr
ora _ppu_send_addr+0
sta _ppu_send_addr+0
; read position = (A-1) * 8
dey
tya
asl
asl
asl
tax
ldy #0
:
lda _floor_render, X
sta _ppu_send, Y
inx
iny
cpy #8
bcc :-
;ldy #8
sty _ppu_send_count
lda #0 ; horizontal update
jsr _ppu_direction
rts
floor_send_nmt: ; A = 5
lda _floor_column
and #31
sta _ppu_send_addr+0
lda _floor_column
and #32
lsr
lsr
lsr
ora #$20
sta _ppu_send_addr+1
; copy nametable data
ldx #0
:
lda _floor_render+32, X
sta _ppu_send, X
inx
cpx #30
bcc :-
;ldx #30
stx _ppu_send_count
lda #1 ; vertical update
jsr _ppu_direction
; increment column
inc _floor_column
lda _floor_column
and #63
sta _floor_column
rts
floor_build: ; A = 0
src = ptr1
min = tmp1
mint = tmp2
tile = tmp3
pass = tmp4
; src = floor_y + (column * 8)
;lda #0
sta src+1
lda _floor_column
.repeat 3
asl
rol src+1
.endrepeat
clc
adc #<_floor_y
sta src+0
lda #>_floor_y
adc src+1
sta src+1
; find minimum
ldy #0
lda #$FF
sta min
@min_loop:
lda (src), Y
cmp min
bcs :+
sta min
:
iny
cpy #8
bcc @min_loop
; min = OCEAN_FLOOR is interpreted as ocean
lda min
cmp #OCEAN_FLOOR
jeq floor_build_ocean
; round down to nearest tile above the minimum (max 28 tiles down)
;lda min
and #%11111000
cmp #(28*8)
bcc :+
lda #(28*8)
:
sta min
lsr
lsr
lsr
sta mint
; generate CHR plane
ldy #0
@chr_loop:
ldx min
lda (src), Y
sta pass
.repeat 64, I
cpx pass
rol _floor_render + I
inx
.endrepeat
iny
cpy #8
jcc @chr_loop
; calculate first tile to use
lda _floor_column
and #15
ora #$80
sta tile
lda _floor_column
and #16
asl
asl
ora tile
sta tile
; generate nametable strip
lda #0 ; blank until mint
ldx #0
:
cpx mint
bcs :+
sta _floor_render+32, X
inx
jmp :-
:
ldy #4 ; 4 tiles
lda tile
:
sta _floor_render+32, X
inx
clc
adc #16
dey
bne :-
lda #$03 ; filled until bottom
:
cpx #32
bcs :+
sta _floor_render+32, X
inx
jmp :-
:
rts
floor_build_ocean:
; the ocean is just tiles of $03 at the bottom
lda #0
tax
:
sta _floor_render, X
inx
cpx #(32+(OCEAN_FLOOR/8))
bcc :-
lda #$03
:
sta _floor_render, X
inx
cpx #64
bcc :-
rts
floor_send_ocean:
; fills the bottom row of attributes to colour the ocean
tax
lda _ocean_attribute
cmp #255
bne :+
rts
:
tay ; Y = _ocean_attribute
lda #8
sta _ppu_send_count
lda #<$23F8
sta _ppu_send_addr+0
cpx #7
bcs :+
lda #>$23F8 ; screen 1
sta _ppu_send_addr+1
lda #%10101010 ; base attribute
jmp :++
:
lda #>$27F8 ; screen 2
sta _ppu_send_addr+1
tya
sec
sbc #8
and #15
tay ; shift ocean coordinate by -8 bytes
lda #%11111111 ; base attribute
:
; fill with base attribute
ldx #0
:
sta _ppu_send, X
inx
cpx #8
bcc :-
; write 6 attribute bytes with ocean colour
ldx #0
:
lda #%00000000 ; ocean attribute
sta _ppu_send, Y
iny
tya
and #15 ; wrap at 16 bytes (the extra 8 bytes is a dummy for other screen)
tay
inx
cpx #6
bcc :-
lda #0 ; horizontal update
jsr _ppu_direction
rts
.endproc
_weather_shift:
; A = value to add to all weather particle X coordinates
sta tmp1
ldx #(32*4)
:
lda tmp1
clc
adc _oam + 3, X
sta _oam + 3, X
inx
inx
inx
inx
bne :-
rts
.proc _weather_animate
; spawn a tile if appropriate
lda _weather_rate_min ; min rate of 0 = no weather
beq animate
lda weather_wait
beq spawn
dec weather_wait
jmp animate
spawn:
ldy weather_next
cpy #(32*4)
bcs :+
ldy #(32*4)
:
lda _oam + 0, Y
cmp #240
bcc spawn_defer ; particle active, try again next frame
lda #0 ;Y
sta _oam + 0, Y
lda _weather_tile
sta _oam + 1, Y
lda _weather_attribute
sta _oam + 2, Y
lda _te
bne :+
jsr _prng ; X
jmp :++
: ; TE uses separated rain PRNG
jsr _prngf
:
sta _oam + 3, Y
; set time until next spawn
lda _te
bne :+
jsr _prng
jmp :++
: ; TE uses separated rain PRNG
jsr _prngf
:
and _weather_rate_mask
clc
adc _weather_rate_min
sta weather_wait
spawn_defer:
; set next spawn index
iny
iny
iny
iny
sty weather_next
animate:
ldx #(32*4)
; iterate through particles
animate_loop:
lda _oam + 0, X
cmp #240
bcs animate_next ; inactive
; vertical fall (add speed stored in attribute bits)
lda _oam + 2, X
and #%00011100
lsr
lsr
tay ; becomes a multiplier for wind
adc _oam + 0, X
sta _oam + 0, X
; wind
lda _te
bne @wind_te ; TE
@wind: ; non-TE uses shared PRNG
jsr prng1
cmp _weather_wind_p
bcs :+
lda _oam + 3, X
clc
adc _weather_wind_dir
sta _oam + 3, X
:
dey ; multiply wind by fall velocity
bne @wind
jmp @collide
@wind_te: ; TE uses separated rain PRNG
jsr prngf1
cmp _weather_wind_p
bcs :+
lda _oam + 3, X
clc
adc _weather_wind_dir
sta _oam + 3, X
:
dey ; multiply wind by fall velocity
bne @wind_te
;jmp @collide
@collide:
; collide with floor
lda _oam + 3, X
clc
adc ppu_2005x+0
sta ptr1+0
lda #0
adc ppu_2005x+1
and #1
.assert (<_floor_y) = 0, error, "_floor_y must be page aligned."
clc
adc #>_floor_y
sta ptr1+1 ; ptr1 = _floor_y + ((particle X + scroll X) & 511)
;ldy #0
lda (ptr1), Y
cmp _oam + 0, X
bcc @hit
bne @miss
@hit:
lda #240
sta _oam + 0, X
@miss:
animate_next:
inx
inx
inx
inx
bne animate_loop
rts
.endproc
.proc _fmult
; A:X operand a (16-bit)
; stack = operand b (16-bit)
ba = ptr1+0
dc = ptr1+1
fe = ptr2+0
hg = ptr2+1
out0 = tmp1
out1 = tmp2
out2 = tmp3
mix = tmp4
sign = ptr3
; retrieve operands, negate and remember is signed
sta ba
stx dc
lda #0
sta sign
cpx #$80
bcs :+
lda #0
jmp :++
:
lda #0
sec
sbc ba
sta ba
lda #0
sbc dc
sta dc
lda #1
:
sta sign
jsr popax
sta fe
stx hg
cpx #$80
bcc :+
lda #0
sec
sbc fe
sta fe
lda #0
sbc hg
sta hg
inc sign
lda fe
:
; unsigned nibble long-multiplcation
; d c b a
; * h g f e
; -------------------
; e--c e--a
; e--d e--b
; f--c f--a
; f--d f--b
; g--d g--b
; g--c g--a
; h--c h--a
; h--b
; |<-keep->| 16 bit result
; out2 out1 out0
;
; 1. e x dcba
tax ; A = fe
lda asl4, X
sta mix ; e0
lda ba
and #$0F
ora mix
tax
lda nmult0, X
sta out0 ; e*a
lda dc
and #$0F
ora mix
tax
lda nmult0, X
sta out1 ; e*c
lda fe
and #$0F
sta mix ; 0e
lda ba
and #$F0
ora mix
tax
lda nmult4, X
clc
adc out0
sta out0
lda nmult8, X
adc out1
sta out1 ; e*b (note: carry to out2 isn't possible)
lda dc
and #$F0
ora mix
tax
lda nmult4, X
;clc
adc out1
sta out1
lda nmult8, X
adc #0
sta out2 ; e*d
; 2. f x dcba
lda fe
and #$F0
sta mix ; f0
lda ba
and #$0F
ora mix
tax
lda nmult4, X
;clc
adc out0
sta out0
lda nmult8, X
adc out1
sta out1
lda out2
adc #0
sta out2 ; f*a
lda dc
and #$0F
ora mix
tax
lda nmult4, X
;clc
adc out1
sta out1
lda nmult8, X
adc out2
sta out2 ; f*c
ldx fe
lda lsr4, X
sta mix ; 0f
lda ba
and #$F0
ora mix
tax
lda nmult0, X
clc
adc out1
sta out1 ; f*b + carry
lda dc
and #$F0
ora mix
tax
lda nmult0, X
adc out2
sta out2 ; f*d
; 3. g x dcba
lda hg
and #$0F
sta mix ;0g
lda ba
and #$F0
ora mix
tax
lda nmult4, X
clc
adc out1
sta out1
lda nmult8, X
adc out2
sta out2 ; g*b
lda dc
and #$F0
ora mix
tax
lda nmult4, X
clc
adc out2
sta out2 ; g*d
ldx hg
lda asl4, X
sta mix ; g0
lda ba
and #$0F
ora mix
tax
lda nmult0, X
clc
adc out1
sta out1 ; g*a + carry
lda dc
and #$0F
ora mix
tax
lda nmult0, X
adc out2
sta out2 ; g*c
; 4. h x dcba
lda hg
and #$F0
sta mix ; h0
lda ba
and #$0F
ora mix
tax
lda nmult4, X
clc
adc out1
sta out1
lda nmult8, X
adc out2
sta out2 ; h*a
lda dc
and #$0F
ora mix
tax
lda nmult4, X
clc
adc out2
sta out2 ; h*c
ldx hg
lda lsr4, X
sta mix ; 0h
lda ba
and #$F0
ora mix
tax
lda nmult0, X
clc
adc out2
;sta out2 ; h*b
ldy sign
cpy #1
beq :+
tax ; A = out2
lda out1
rts
:
; negate the result if sign parity did not match
sta out2
lda #0
sec
sbc out0
;sta out0
lda #0
sbc out1
sta out1
lda #0
sbc out2
tax
lda out1
rts
;
.segment "ALIGN"
.align 256
nmult0: ; ab = 4-bit a * b
.repeat 256, I
.byte (I&15) * (I>>4)
.endrepeat
nmult4: ; ab = 4-bit a * b << 4
.repeat 256, I
.byte <(((I&15) * (I>>4)) << 4)
.endrepeat
nmult8: ; ab = 4-bit a * b >> 4
.repeat 256, I
.byte (((I&15) * (I>>4)) >> 4)
.endrepeat
asl4: ; arithmetic shift left 4 bits
.repeat 256, I
.byte <(I<<4)
.endrepeat
lsr4: ; logical shift right 4 bits
.repeat 256, I
.byte (I>>4)
.endrepeat
.endproc
; =========
; Utilities
; =========
.export _prng
.export _prng1
.export _prngw ; TE
.export _prngw1 ; TE
.export _prngf ; TE
.export _prngf1 ; TE
.export _mouse_sense
.export _input_setup
.export _input_poll
.segment "CODE"
_prng:
ldx #8
prngx:
lda _seed+0
:
asl
rol _seed+1
rol _seed+2
bcc :+
eor #$1B
:
dex
bne :--
sta _seed+0
;ldx #0 ; clear high bits of return value
rts
_prng1:
ldx #0
prng1:
lda _seed+0
asl
rol _seed+1
rol _seed+2
bcc :+
eor #$1B
:
sta _seed+0
rts
_prngw: ; TE
ldx #8
prngwx:
lda _seedw+0
:
asl
rol _seedw+1
rol _seedw+2
bcc :+
eor #$1B
:
dex
bne :--
sta _seedw+0
;ldx #0 ; clear high bits of return value
rts
_prngw1: ; TE
ldx #0
prngw1:
lda _seedw+0
asl
rol _seedw+1
rol _seedw+2
bcc :+
eor #$1B
:
sta _seedw+0
rts
_prngf: ; TE
ldx #8
prngfx:
lda _seedf+0
:
asl
rol _seedf+1
rol _seedf+2
bcc :+
eor #$1B
:
dex
bne :--
sta _seedf+0
;ldx #0 ; clear high bits of return value
rts