-
Notifications
You must be signed in to change notification settings - Fork 0
/
octopeg.8o
2976 lines (2472 loc) · 63.6 KB
/
octopeg.8o
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
###############################################
# #
# #
# # # #
# #
# OCTOPEG ### #
# ### #
# #
###############################################
# By Chromatophore
# A program for Octo, a chip-8 interpreter:
# https://github.com/JohnEarnest/Octo
# colours?
#113152 #Background
#acd5ff #Foreground 1
#264c74 #Buzzer??
# Todo List:
# All done!!
#############################
# ALIASES!
#############################
# I ended up using quite a lot of my aliasses too much. But well, whatever.
# v0, 1 and 2 are temp registers that I just use by name constantly
:alias ssa v3 # temp register - stores the streak
:alias ssb v4 # temp register - stores the pegs hit this turn
:alias ssc v5 # temp register - stores the position of the gutter
# ALL THE BALL STUFFS WOOO
:alias px v6 # horizontal position
:alias py v7 # vertical position
:alias vx v8 # hoizontal velocity
:alias vy v9 # vertical velocity
:alias sx va # x subpixels
:alias sy vb # y subpixels
:alias signx vc # sign bit for quicker overflow work
:alias signy vd # sign bit for quicker overflow work
# random doing stuff with register
# middle management register
:alias mm ve
#############################
## Title and Game End screen text positions
:const Title-x 11
:const Title-y 10
:const endtext-x 0x2
:const endtext-y 0x12
:const endscore-x 0x32
:const endscore-y 0x19
#############################
# Arena specifics
# Constants for a few things, like the floor and walls
:const thefloor 0x3C
:const thefloorp1 0x3D
:const thetop 0x0c
:const thetopp1 0x0b
:const theothertop 0x03
:const toparea-left 0x23
:const toparea-right 0x5B
:const wallleft 0x0b
:const wallright 0x73
#############################
# Ball related constants
# Gravity
:const gravity 0x03
:const negravi -0x03
# Horizontal Degradation
:const airres 0x01
:const negair -0x01
:const vposspeedcap 0xFC
:const vnegspeedcap 0x04
:const hposspeedcap 0xFC
:const hnegspeedcap 0x04
:const BallDeathY 0x3e
#############################
# Hud display stuff
:const lifewrap 10
:const livesxshift 3
:const livesyshift 3
:const livesxpos 1
:const livesypos 1
:const lifespritesize 2
:const scorexshift -5
:const scorexpos 0x80
:const scoreypos 1
:const between-shot-BigD-x 0x5d
:const between-shot-BigD-y 0x04
:const between-shot-text-x 0x24
:const between-shot-text-y 0x04
:const BarBottomFill 0x3e # This is 62
:const NegBarBottomFill -62
#############################
# Gameplay related constants
:const maxlevels 8
:const startlives 7
:const maxlives 20
:const lifebarsize 27
:const feverbarsize 52
:const feverbaradjust 2
#############################
# Some bumper related constants, where they start:
:const bumperxpos 0x17
:const bumperypos 0x3a
# How far apart they are
:const bumperxshift 0x13
# How many there are
:const bumpers 5
# The point at which you fall to your doom
:const max-bump-collide 0x3d
#############################
# Aim Mode stuff
# Cannon position
:const cannonx 0x3c
:const cannony 0x03
# Maximum Aim area
:const minxaim 0x63
:const maxxaim 0x9e
:const minyaim 0x7f
:const maxyaim 0x9f
:const ballstartx 0x3f
:const ballstarty 0x05
:const ballstartxl2 0x3d # should be the above - 2
:const ballstartyl2 0x03
#############################
# Bonus related stuff, like free balls and fever
:const barflashes 9 # must be an odd number!
:const textflashes 16 # must be an even number!
:const feverflashes 16
# How frequently the free ball area moves, moves ever overflow
:const freeballstep-aim 4 # extra, since aim mode has lower fps
:const freeballstep-play 4
:const freeball-filter 0xf0
# max x difference above the position that counts
:const freeball-window 14
# free ball text position
:const freeball-text-x 0x25
:const freeball-text-y 0x04 #0x1d
# Fever shot text position
:const fevershot-text-x 0x2f
:const fevershot-text-y 0x04 #0x1d
:const feverflash-x 0x7a
:const feverflash-y 0x0a
# The letter F:
#:const feverletterf 0x22
# Bonus points accrued for each hit in fever
:const feverbonus 20
#############################
#############################
#############################
#############################
# Score related functions
#############################
## Give Points, our go to to apply whatever it is we've setup into our score
: givepoints
# this will allow us to grant arbitrary numbers of points, which, I think will be important
# Our points will be in little endian arrangement.
# you MUST SET load-BigDecimalB yourself before calling this
# It would look something like this
# set the bonus address;
# :unpack 0xA multiplymem # << your address here
# i := load-BigDecimalB
# save v1
setupscore
# setup the x position of our text
v2 := scorexpos
BigDecimalMath
;
## Setup score - sets up the BigDecimal to address into our points
: setupscore
:unpack 0xA scoremem
i := load-BigDecimalA
save v1
i := load-BigDecimalC
save v1
:unpack 0x1 ScoreDraw-shift
i := jump-BigDecimalHook1
save v1
:unpack 0x1 ScoreDraw
i := jump-BigDecimalHook2
save v1
;
## BigDecimalMath - this is my workhorse function for doing big decimal carry math
# it works in little endian order, with 0 to 9 in each byte - inefficient, as we could store 0-99 easily
: BigDecimalMath
# This requires QUITE A FEW registers.
# v0 is used directly
# v1 is used directly
# v2 is not touched and is available for your use, I use it for my score x position. Y position is loaded from a constant (bummer)
# vf is used directly
# We need 3 additional registers
:alias BigD-AVal v3
:alias BigD-BProg v4
:alias BigD-Carry v5
# And if we want allow > 10 values in an individual register but still only doing 10s, we'd need another
# :alias BigD-Over ve
# Because it uses so many registers, it also uses self modifying code to not need to keep track
# of digits. It would probably be a lot faster if I just used another register.
# Anyway:
# This will add two large numbers together in memory.
# These will be chosen in advance by setting certain parts of our code to certain values, load-BigDecimalA-C
# Objective is to take A + B = C. C can equal A or B, probably.
# Set up current carry as 0
BigD-Carry := 0
# set BigD-BProg to be 1, we use this to work out when we're at the end of B yet
BigD-BProg := 1
loop
if BigD-BProg == 1 begin
# function to call line of code we will have modified to address the current bonus digit
address-BigDecimalB
load v0
if v0 == 0xff begin
# we're at the end of the bonus
# if we have no more carry to do, end here
if BigD-Carry == 0 then return
# otherwise...
# pretend this value is 0
v0 := 0
# and that we no longer need to process B
BigD-BProg := 0
else
# otherwise, increase our carry by this quantity
##vf := v0 ## what was this for?
# Have a roll over variable in memory, only count 100 pins at a time
# should make things easy
BigD-Carry += v0
end
end
# function to call line of code we will have modified to address the current score digit.
address-BigDecimalA
load v0
BigD-AVal := v0
# BigD-AVal now contains our current digit of A
# BigD-Carry contains the amount we must increase it by
# Run our first hook
# v0 := BigD-AVal # (it already is)
BigDecimalHook1
# Add our stored value to this unit, retaining it for later
v0 := BigD-AVal
v0 += BigD-Carry
if v0 > 9 begin
# since we're using a stream of decimal digits, if we go over 10, we know we just carry 1.
# we don't need anything fancy here.
# if we need to increase the next unit
# This is my old code to repeatedly decrease by 10 until we underflow, so we know how many extra times to carry
# we really don't need to do this though. Probably.
#v1 := 10
#BigD-Over := 0xFF
#loop
# BigD-Over += 1
# v0 -= v1
# if vf == 1 then
#again
# Sort out v0, and update BigD-Carry with our quantity to carry
v0 += -10
BigD-AVal := v0
BigD-Carry := 1
# BigD-Carry += BigD-Over # Might be off by one, old code!
# now we need to save this digit
address-BigDecimalC
save v0
# select the next score address
next-BigDecimalA
next-BigDecimalC
v0 := BigD-AVal
else # v0 is <= 9
# We don't need to carry forward any digits
# But, we might have more bonus numbers to deal with.
BigD-AVal := v0
BigD-Carry := 0
# but we do still need to save this digit
address-BigDecimalC
save v0
end
# draw the NEW score digit:
# v0 := BigD-AVal # This time, it will have been blown up by next-BigDecimal, so we fix that in the above if statement
BigDecimalHook2
# update the bonus position if we haven't hit the bonus terminator
if BigD-BProg == 1 begin
# if we haven't selected the next DecimalA address, we'll need to do that now
if BigD-Carry == 0 begin
next-BigDecimalA
next-BigDecimalC
end
next-BigDecimalB
end
# Check if we need to proceed:
v0 := BigD-Carry
v0 += BigD-BProg
if v0 != 0 then
again
;
: address-BigDecimalA
: load-BigDecimalA 0x00 0x00
;
: next-BigDecimalA
# now we need to update the address to read from
i := load-BigDecimalA
load v1
vf := 1
v1 += vf
v0 += vf
i := load-BigDecimalA
save v1
;
: address-BigDecimalB
: load-BigDecimalB 0x00 0x00
;
: next-BigDecimalB
# now we need to update the address to read from
i := load-BigDecimalB
load v1
vf := 1
v1 += vf
v0 += vf
i := load-BigDecimalB
save v1
;
: address-BigDecimalC
: load-BigDecimalC 0x00 0x00
;
: next-BigDecimalC
# now we need to update the address to read from
i := load-BigDecimalC
load v1
vf := 1
v1 += vf
v0 += vf
i := load-BigDecimalC
save v1
;
: BigDecimalHook1
: jump-BigDecimalHook1 0x00 0x00
;
: BigDecimalHook2
: jump-BigDecimalHook2 0x00 0x00
;
#############################
# HUD and Arena Stuff (long!)
#############################
## These are our functions that we're going to tie up to our BigD hooks
: ScoreDraw-shift
# select our x position
v2 += scorexshift
: ScoreDraw
i := hex v0
vf := scoreypos
sprite v2 vf 5
;
## Redraws the score when there is not one any more.
# This iterates through the whole deal
: redraw-score
v1 := 0
v2 := scorexpos
mm := 0
loop
i := scoremem
i += v1
v1 += 1
load v0
ScoreDraw-shift
mm += 1
if mm != 6 then
again
;
## ?????????????????? do this or not
## Draw Bonusses BigDecimal subroutine - draws a set up big decimal address to the screen. I use this for showing the points, streak, and bonus after your turn
: draw-bonusses-bigD-sub
i += v1
v1 += 1
load v0
if v0 == 0xff then v0 := 0
i := hex v0
sprite ssa ssb 5
mm += 1
;
: end-life-draw-PTT
ssa := between-shot-BigD-x
ssb := between-shot-BigD-y
mm := 0
v1 := 0
loop
i := multiplymem-makeitx10
ssa += scorexshift
draw-bonusses-bigD-sub
if mm != 6 then
again
vf := 0
v1 := between-shot-text-x
v2 := between-shot-text-y
loop
i := points-text
drawtext
if vf != 0xff then
again
;
: end-life-draw-Streak
ssa := between-shot-BigD-x
ssb := between-shot-BigD-y
mm := 0
v1 := 0
loop
i := streakmem
ssa += scorexshift
draw-bonusses-bigD-sub
if mm != 3 then
again
vf := 0
v1 := between-shot-text-x
v2 := between-shot-text-y
loop
i := streak-text
drawtext
if vf != 0xff then
again
;
: end-life-draw-Bonus
ssa := between-shot-BigD-x
ssb := between-shot-BigD-y
mm := 0
v1 := 0
loop
: keep-Bonus 0x00 0x00
ssa += scorexshift
draw-bonusses-bigD-sub
if mm != 5 then
again
vf := 0
v1 := between-shot-text-x
v2 := between-shot-text-y
loop
i := bonus-text
drawtext
if vf != 0xff then
again
;
## Redraws all the lives at the beginning of a level
# Iterates through the whole thing, but doesn't actually refer to lives, hence fake
: draw-fakelives
i := lives
load v0
v1 := livesxpos
v2 := livesypos
#i := life
i := ball
mm := 0
loop
sprite v1 v2 lifespritesize
mm += 1
v1 += livesxshift
if mm == lifewrap begin
v1 := livesxpos
v2 += livesyshift
end
if mm != v0 then
again
;
## Take Life - Takes a life away and undraws it
: take-life
i := lives
load v0
draw-life
v0 += 255
i := lives
save v0
;
## Draw Life - given a value in v0, draws a life sprite in that # location
: draw-life
v1 := livesxpos
v2 := livesypos
#i := life
i := ball
if v0 != 1 begin
mm := 1
loop
v1 += livesxshift
if mm == lifewrap begin
v1 := livesxpos
v2 += livesyshift
end
mm += 1
if mm != v0 then
again
end
sprite v1 v2 lifespritesize
;
## Increases lives by 1
: boost-life
i := lives
load v0
if v0 == maxlives begin
# don't give an extra life, maybe just give points?
# TODO do something
else
v0 += 1
end
i := lives
save v0
draw-life
;
## Pump Freeball - this increases the value of the free ball chute. It also handles undrawing + redrawing it when it has increased enough to move. Aim mode runs at a lower frame rate, so it has a bonus increase to keep it visually consistent.
: pump-freeball-aim
ssc += freeballstep-aim
: pump-freeball
ssc += freeballstep-play
if ssc == 0 begin
i := freeball-locate
load v0
draw-freeball
v0 += 4
if v0 == 40 then v0 := 0
draw-freeball
i := freeball-locate
save v0
end
;
## Redraw/draw Freeball - redraws or draws the free ball chute indicator.
: redraw-freeball
i := freeball-locate
load v0
: draw-freeball
i := freeball
v2 := 0x3f
get-bumper-pos
sprite v1 v2 1
;
## Draw Arena. Draws the arena, obviously enough. I pretty much just hacked it together. I don't think it needs the :const treatment
: draw-arena
i := cornerTL
v0 := 0x08
v1 := 0x08
sprite v0 v1 8
v0 := 0x20
v1 := 0
sprite v0 v1 8
v0 := 0x58
i := cornerTR
sprite v0 v1 8
v1 += 8
v0 := 0x70
sprite v0 v1 8
v0 := 0x58
i := invcornerTR
sprite v0 v1 8
v0 := 0x20
i := invcornerTL
sprite v0 v1 8
v0 := 0x08
#v1 := 0x08
i := sideT
loop
v0 += 8
sprite v0 v1 8
if v0 != 0x18 then
again
v0 := 0x58
loop
v0 += 8
sprite v0 v1 8
if v0 != 0x68 then
again
v0 := 0x20
v1 := 0
loop
v0 += 8
sprite v0 v1 8
if v0 != 0x50 then
again
i := sideR
v0 := 0x70
v1 := 0x08
loop
v1 += 8
sprite v0 v1 8
if v1 != 0x38 then
again
i := sideL
v0 := 0x08
v1 := 0x08
loop
v1 += 8
sprite v0 v1 8
if v1 != 0x38 then
again
draw-bumpers
;
## Draw Bars - draws the LIFE and COMBO bar onto the screen
: draw-bars
i := barbottom
v0 := 0
v1 := 0x38
sprite v0 v1 8
v0 := 0x78
sprite v0 v1 8
i := bartop
v1 := 0x08
sprite v0 v1 8
v0 := 0
sprite v0 v1 8
i := barbody
loop
v1 += 0x08
sprite v0 v1 8
if v1 != 0x30 then
again
v1 := 0x08
v0 := 0x78
loop
v1 += 0x08
sprite v0 v1 8
if v1 != 0x30 then
again
redraw-ballbar
;
## Draw Bumpers - draws the bumpers onto the screen
: draw-bumpers
i := bumper
v1 := bumperxpos
v2 := bumperypos
mm := 0
loop
sprite v1 v2 6
mm += 1
v1 += bumperxshift
if mm != bumpers then
again
;
## Get Bumper Pos - gets the position of the bumper vased on the value of v0, which will be 0-9 or something, and then wraps around. I'm pretty sure the last 0x0D is never used.
: get-bumper-pos
jump0 freeballxpos
: freeballxpos
v1 := 0x0D ;
v1 := 0x20 ;
v1 := 0x33 ;
v1 := 0x46 ;
v1 := 0x59 ;
v1 := 0x6C ;
v1 := 0x59 ;
v1 := 0x46 ;
v1 := 0x33 ;
v1 := 0x20 ;
#v1 := 0x0D ;
## Redraw Ballbar - Redraws the LIFE bar filling between stages
: redraw-ballbar
i := peghits
load v0
if v0 != 0 begin
v1 := 0x00
v2 := BarBottomFill
i := barfill
loop
v0 += -1
v2 += -2
sprite v1 v2 2
if v0 != 0 then
again
end
;
## Boost Ballbar - Adds a count to the LIFE bar. Also accounts for when it fills up
: boost-ballbar
i := peghits
load v0
v0 += 1
i := peghits
save v0
v1 := 0x00
v2 <<= v0
vf := BarBottomFill
v2 =- vf
i := barfill
if v0 == lifebarsize begin
v0 := v2
mm := 0
# do sweet bar flashing
loop
v2 := v0
v2 += 0x02
clear-bar
mm += 1
# lock the framerate of this program via the delay timer:
quick-delay
if mm != barflashes then
again
v0 := 1
i := peghits
save v0
# creep up slightly so we draw our new block in the right place:
v2 += 0x02
i := barfill
sprite v1 v2 2
boost-life
return
end
sprite v1 v2 2
;
## Clear Feverbar / Clear bar - clears out the filling of the fever or 'a' bar for us. Useful to make the bar flash
: clear-feverbar
i := barfill
v1 := 0x78
v2 := 0x0a
: clear-bar
sprite v1 v2 8
v2 += 0x08
sprite v1 v2 8
v2 += 0x08
sprite v1 v2 8
v2 += 0x08
sprite v1 v2 8
v2 += 0x08
sprite v1 v2 8
v2 += 0x08
sprite v1 v2 8
v2 += 0x08
sprite v1 v2 4
;
## Boost Feverbar - Adds a segment to the combo bar. Also catches when the bar is full.
: boost-feverbar
i := peghits2
load v0
if v0 == feverbarsize begin
# we are at fever cap
# let's give extra points!
# let's set fever to on, actually, so you have to get it with your ball
# rather than having a shot you can do what you want with
v1 := v0
i := fevershot-bool
load v0
if v0 == 0 begin
# We are NEWLY in fever mode.
# Display FEVER! text
mm := 0
loop
vf := 0
v1 := fevershot-text-x
v2 := fevershot-text-y
loop
i := fevershot-text
drawtext
if vf != 0xff then
again
mm += 1
normal-delay
if mm != feverflashes then
again
# Now turn on the byte we checked!
i := fevershot-bool
v0 := 1
save v0
end
# we can have ssc, which holds the increasing 'move the
# free ball' indicator do the constantly flashing of the bar maybe?
# Get the value back, load it, and add a bonus for each hit
v0 := v1
v0 += feverbonus
return
end
v0 += 1
i := peghits2
save v0
v1 := 0x78
v2 := v0
vf := BarBottomFill
v2 =- vf
i := barfill
sprite v1 v2 1
;
## Freeball get text - displays the FREE BALL text on the screen.
: freeball-get-text
# must be even number of flashes
mm := 0
loop
vf := 0
v1 := freeball-text-x
v2 := freeball-text-y
loop
i := freeball-text
drawtext
if vf != 0xff then
again
mm += 1
normal-delay
if mm != textflashes then
again
;
#############################
# Peg Level Drawing Things
#############################
:alias peg-x v3 # Our current y pos to render
:alias peg-y v4 # Our current x pos to render
:alias cur-bit v5 # Our current bit within a block
:alias hstep v6 # Our current horizontal block
:alias vstep v7 # Our current vertical block
:alias fulldraw v8 # Our full draws so far, not actually used
:alias repeatmode v9 # Our repeat state
:alias cmd-hi va # High bits of cmd
:alias cmd-lo vb # Low bits of cmd
:alias amode-reps vc # Repeats until pass a 0xc0 command
:const pegreadstartx 16 # The start X of where we draw pegs
:const pegreadstarty 16 # The start Y of where we draw pegs
:const mpegx 2 # The X gap between pegs
:const mpegy 10 # The Y gap between pegs
:const mpegx_skip 16 # If our value is 0, we skip the block, and move this much
:const mpegcappx 6 # We go 6 blocks on X before we wrap
:const mpegcappy 4 # We go 4 blocks on Y before we wrap
:const pegrightshift -96 # But our Y wrap is deliberately imperfect, so we can have multiple stacked pegs with small y offsets
:const pegdownshift -38 # But our Y wrap is deliberately imperfect, so we can have multiple stacked pegs with small y offsets
:const maxoverrows 5 # Actually deliberately disabled. but would stop us reading data when we hit our 6th? attempt to run through (which would draw on top of our first row)
## Micropeg Render - Draws an individual peg
: micropeg-render
sprite peg-x peg-y 1
;
## Peg Renderer - Goes through a byte of data, and renders a peg if the bit is 1. Is Big Endian, so 10000000 draws a peg on the left
: peg-renderer
# for all 8 bits...
cur-bit := 8
loop
# rotate out our msb
v0 <<= v0
# if it's true, render a peg
if vf == 1 then micropeg-render
# increment peg-x, our peg-x coord
peg-x += mpegx
# reduce number of bits to test
cur-bit += -1
# and check if we're done
if cur-bit != 0 then
again
# increment horizontal block
;
## Address LevelPegs - Self Modifying code target for changing where we are in the peg data
: address-levelpegs
: load-peg 0x00 0x00
;
: increment-levelpegs
i := load-peg
load v1
vf := v2
v1 += vf
v0 += vf
i := load-peg
save v1