Debian Codegraph @

test/channel-f/lights.asm

raw
1 ; Sean Riddle's lights.asm, the first reallife program ever assembled
2 ; by dasm2. The usual modifications to f8tool source were needed:
3 ; - Needed to add the processor directive at the top of the source.
4 ; - Needed to indent the org directives because dasm2 would parse
5 ; them as labels.
6 ; - The first org directive sets the org fill value to 0, since this
7 ; is what f8tool uses and the reference binary was assembled with
8 ; f8tool.
9 ;
10 ;lights out
11 ;by Sean Riddle
12 ;6/2004
13 ;members.cox.net/seanriddle
14 ;
15 ; Copyright (C) 2004 Sean Riddle (members.cox.net/seanriddle)
16 ;
17 ; lights is free software; you can redistribute it and/or modify
18 ; it under the terms of the GNU General Public License as published by
19 ; the Free Software Foundation; either version 2 of the License, or
20 ; (at your option) any later version.
21 ;
22 ; lights is distributed in the hope that it will be useful,
23 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
24 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
25 ; GNU General Public License for more details.
26 ;
27 ; You should have received a copy of the GNU General Public License
28 ; along with lights; if not, write to the Free Software
29 ; Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
30
31 ;for the Channel F multigame
32 ;it will play in MESS
33 ;it requires MG RAM at $2800 (could be rewritten to use regs only)
34
35 ;instructions:
36 ;make all lights green
37 ;l/r/u/d moves cursor
38 ;push down toggles lights
39 ;pull up replays current pattern
40 ;when complete, the count of moves is shown
41 ;then up replays pattern, down goes to next random
42 ;after all 64 patterns are played randomly, the complements (red<->green) are played
43
44 ;game 1 is normal - all included patterns are solvable
45 ;game 2 is on a torus (wrap-around) !!! not all included patterns are solvable on a torus
46 ;game 3 is lit-only (only lit buttons can be pressed)
47
48 ;mode 1 toggles self and u/d/l/r neighbors - + pattern
49 ;mode 2 only toggles u/d/l/r neighbors !!! not all included patterns are solvable in this mode
50 ;mode 3 toggles self and nw/ne/sw/se neighbors - X pattern
51 ;mode 4 toggles nw/ne/sw/ne - X not self
52
53 ;todo:
54 ;build game 2 or mode 2 patterns from random legal moves
55 ;add random legal moves to patterns to create more
56 ;rotate, invert patterns randomly for more variation
57 ;three-state red, green, gray
58 ;L modes
59 ;more symbols-greek, smilies, arcade,
60 ;currently 12 bytes short of 2K, but there's lots more room
61
62 ;egg - certain game/mode combo, solve certain pattern in minimum moves
63
64 processor f8
65
66 ;BIOS calls
67 clrscrn: equ $00d0 ;uses r31
68 delay: equ $008f
69 pushk: equ $0107 ;used to allow more subroutine stack space
70 popk: equ $011e
71 drawchar: equ $0679
72
73 array: equ $2800 ;use Schach RAM to hold current state of 25 lights
74 history: equ $2900 ;patterns we have already used, so we don't repeat
75 temp4: equ $2a00 ;temp storage of 4 bytes
76
77 org $800,0
78 CartridgeStart: db $55 ; valid cart indicator
79 NOP ; unused byte
80
81 CartridgeEntry:
82 LIS $0 ; init the h/w
83 OUTS 1
84 OUTS 4
85 OUTS 5
86 OUTS 0
87
88 lisu 4 ;r32=complement flag
89 lisl 0
90 lr (IS),a
91
92 LI $d6 ;
93 LR $3,A ; clear screen to gray
94 PI clrscrn ;
95
96 li $11
97 lisu 3 ;init R30 game 1, mode 1
98 lisl 6
99 lr (IS),a
100
101 li $4a ;display G? prompt
102 lr 0,a
103 pi prompt
104 lr a,4
105 sl 4
106 lisu 3 ;r30 low nibble = game
107 lisl 6
108 lr (IS),a ;game 1 - normal, game 2 - wraparound; game 3 - lit only
109
110 pi prompts ;display S?/M? ; mode 1 normal, mode 2 no center toggle
111
112 clrhist: ;clear history of patterns presented
113 dci history
114 li $41 ; # of patterns +1
115 lr 0,a
116 clrhist2:
117 lis 0
118 st
119 ds 0
120 bf 4,clrhist2
121
122 nextpat:
123 lisu 2 ;random #
124 lisl 5
125 lr a,(IS)
126
127 lisu 3
128 lisl 5
129 as (IS) ;add to current pattern...
130 ni $3f ;...mod 64...
131 lr (IS),a ;...to get next pattern
132
133 dci history ;check to see if we've already done this one
134 adc
135 lr q,dc
136 lm
137 ni $ff
138 bt 4,unusedpat ;not yet used, display it
139
140 ;pattern already used, check for unused from top
141 ;if not found, clear array and start over
142
143 dci history
144 checknext:
145 lm
146 ni $ff
147 bf 4,checknext ;will always complete because we zeroed 1 extra byte in clrhist
148 lr q,dc
149 lr a,ql
150 ai $ff ;lm moved us 1 past
151 lr ql,a
152 ci $40 ;all done?
153 bf 4,foundone
154 li $ff
155 lisu 4 ; set flag to start complements (random/rotations later)
156 lisl 0
157 lr (IS),a
158 bf 0,clrhist ;no empty slots, start over
159 foundone:
160 lr (IS),a ;update the current pattern
161
162 unusedpat:
163 lr dc,q ;mark it used
164 li $ff
165 st
166
167 replay:
168 lisu 3 ;current pattern # in r29
169 lisl 5
170 lr a,(IS)
171
172 dci pats
173 adc ; add cur pat to data pointer 5 times to get to the pat data
174 adc
175 adc
176 adc
177 adc
178
179 getpat: lisu 2 ;read bit pattern into regs 16-20
180 lisl 0
181 lis 5
182 lr 1,a
183 getpatloop:
184 lm
185 lr (is)+,a
186 ds 1
187 bf 4,getpatloop
188
189 dci array ;put byte pattern into RAM
190 lis 5
191 lr 2,a
192
193 lisu 4 ;first time through 0, next time FF
194 lisl 0
195 lr a,(IS)
196 lr 3,a ;temp
197
198 lisu 2
199 lisl 0
200 storepatloop2:
201 lis 5
202 lr 1,a
203 lr a,(is)+
204 storepatloop:
205 lr 0,a
206 ni $ff
207
208 lr a,3
209
210 bf 1,onebit
211 bf 0,storepat
212 onebit:
213 com
214 storepat:
215 st
216 lr a,0
217 sl 1
218 lr 0,a
219 ds 1
220 bf 4,storepatloop
221 ds 2
222 bf 4,storepatloop2
223
224 lis 0 ;init variables to 0
225 lisu 3
226 lisl 0
227 lr (IS)+,a ;r24=row (3:0)
228 lr (IS)+,a ;r25=col (3:1)
229 lr (IS)+,a ;r26=cursor (3:2)
230 lr (IS)+,a ;r27=array index (3:3)
231 lr (IS)+,a ;r28=parameter to toggle sub (3:4)
232 lisu 2
233 lisl 6
234 lr (IS)+,a ;r22=press counter lo (2:6)
235 lr (IS)+,a ;r23=press counter hi (2:7)
236
237 dci grid ;draw the grid
238 pi drawlines
239
240 ;draw lights
241 li 24 ;array index
242 lisu 3
243 lisl 3
244 lr (IS),a
245 sqloop:
246 pi drawlight
247 lisu 3
248 lisl 3
249 lr a,(IS)
250 ai $ff
251 lr (IS),a
252 bt 2,sqloop ;branch if >= 0
253
254 dci currows
255 lm
256 lr 5,a ;upper row
257 dci curcols
258 lm
259 lr 4,a ;left col
260 dci cursor ;start with the cursor in light 0
261 pi square
262
263 mainloop:
264 pi readhc
265 lr 0,a ;save controller input
266 lisu 2 ;inc random seed
267 lisl 5
268 lr a,(IS)
269 inc
270 lr (IS),a
271
272 ; redraw current square without cursor
273 lisu 3
274 lisl 2
275 lr a,(IS)+
276 lr (IS),a
277 pi drawlight
278
279 lr a,0
280 ni $0c
281 bt 4,notupdn
282 ci $08
283 bf 4,down
284 lisu 3 ;up
285 lisl 0 ;r24 is row
286 ds (IS) ;prev row
287 bf 2,minrow ;>=0?
288 updcurx:
289 jmp updcur
290 minrow:
291 lis 4
292 lr (IS),a
293 bf 0,updcurx
294 down:
295 lisu 3
296 lisl 0
297 lr a,(IS)
298 inc ;next row
299 lr (IS),a
300 ci 5 ;too far?
301 bt 4,maxrow
302 bf 0,updcurx
303 maxrow:
304 lis 0
305 lr (IS),a
306 bf 0,updcurx
307 notupdn:
308 lr a,0
309 ni $03
310 bt 4,notlfrt
311 ci $02
312 bf 4,right
313 lisu 3 ;left
314 lisl 1 ;r25 is col
315 ds (IS) ;prev col
316 bf 2,prevcol ;>=0?
317 bf 0,updcurx
318 prevcol:
319 lis 4
320 lr (IS),a
321 bf 0,updcurx
322 right:
323 lisu 3
324 lisl 1
325 lr a,(IS)
326 inc ;next col
327 lr (IS),a
328 ci 5 ;too far?
329 bf 4,updcurx
330 lis 0
331 lr (IS),a
332 bf 0,updcurx
333 notlfrt:
334 lr a,0
335 ni $c0
336 bt 4,mainloop
337 ci $80
338 bt 4,pushdown
339 jmp replay ;pull up replays current pattern
340
341 pushdown:
342 lisu 3
343 lisl 6
344 lr a,(IS)
345 ni $f0
346 ci $40 ;if game=3, can only press lit buttons
347 bf 4,allowpress
348
349 lisu 3
350 lisl 2 ; get cursor loc
351 lr a,(IS)
352
353 dci array
354 adc
355 lm
356 ni $ff
357 bf 4,allowpress
358
359 ;make a bad sound
360 li $3f
361 lr 1,a
362 sndloop:
363 li $80
364 outs 5
365 lis 1
366 lr 5,a
367 pi delay
368 lis 0
369 outs 5
370 ds 1
371 bf 4,sndloop
372
373 jmp updcur
374
375 allowpress:
376 lisu 2 ;inc press counter
377 lisl 6
378 lis 1
379 ai $66
380 asd (IS) ;thanks Fredric!
381 lr (IS)+,a
382 bf 2,nocarry
383 lis 1
384 ai $66
385 asd (IS)
386 lr (IS),a
387 nocarry:
388 lisu 3
389 lisl 6 ;if mode=2 or 4, no center toggle
390 lr a,(IS)
391 ni $f ;mode in low nibble
392 ci $2
393 bt 4,nocenter
394 ci $8
395 bt 4,nocenter
396
397 lisu 3
398 lisl 2 ; get cursor loc
399 lr a,(IS)
400
401 lisl 4
402 lr (IS),a
403 pi toggle ;toggle center light
404
405 nocenter:
406 dci plustable
407 lisu 3
408 lisl 6 ;if mode=3 or 4, X toggle
409 lr a,(IS)
410 ni $f ;mode in low nibble
411 ci $4
412 bt 4,xtoggle ;mode 3, X toggle
413 ci $8
414 bt 4,xtoggle ;mode 4, X toggle
415 bf 0,dotoggle
416
417 xtoggle:
418 dci xtable
419 dotoggle:
420 lisl 2
421 lr a,(IS) ;get cursor loc
422 as (IS)
423 as (IS)
424 as (IS) ;*4 for table offset
425 adc
426 lm ;get 4 neighbors
427 lr 0,a
428 lm
429 lr 1,a
430 lm
431 lr 2,a
432 lm
433
434 dci temp4 ;store them temporarily
435 st ;t4
436 lr a,2
437 st ;t3
438 lr a,1
439 st ;t2
440 lr a,0
441 st ;t1
442
443 dci temp4 ;toggle each neighbor
444 li 3
445 adc
446 pi togglem ;t1
447
448 dci temp4
449 lm
450 lm
451 pi togglem ;t2
452
453 dci temp4
454 lm
455 pi togglem ;t3
456
457 dci temp4
458 pi togglem ;t4
459
460 updcur:
461 lisu 3 ;calc index from row and col
462 lisl 0
463 lr a,(IS)
464 as (IS)
465 as (IS)
466 as (IS)
467 as (IS) ;row * 5
468
469 lisu 3
470 lisl 1
471 as (IS)+ ;add in col
472 lr (IS),a
473
474 dci currows ;get row and column to draw cursor
475 lisu 3
476 lisl 0
477 lr a,(IS)+
478 adc
479 lm
480 lr 5,a
481
482 dci curcols
483 lr a,(IS)
484 adc
485 lm
486 lr 4,a
487
488 dci cursor ;draw the cursor
489 pi square
490
491 LI $3F ;debounce by pausing a while
492 LR 5,A
493 pi delay
494
495 ;check for all green (win)
496 dci array
497 li 24 ;array index
498 lisu 3
499 lisl 3
500 lr (IS),a
501 chkloop:
502 lm
503 ni $ff
504 bt 4,lighton
505 jmp mainloop ;not a win
506 lighton:
507 lisu 3
508 lisl 3
509 lr a,(IS)
510 ai $ff
511 lr (IS),a
512 bt 2,chkloop
513
514 ;made it here, all off
515 ;make a winning sound
516 li $3f
517 lr 1,a
518 snd2loop:
519 li $40
520 outs 5
521
522 lr a,1
523 snd2loopa:
524 inc
525 bf 4,snd2loopa
526
527 lis 0
528 outs 5
529 ds 1
530 bf 4,snd2loop
531
532 li 32 ;draw 2 concentric squares
533 lr 4,a
534 li 18
535 lr 5,a
536 dci winsq1
537 pi square
538 li 34
539 lr 4,a
540 li 20
541 lr 5,a
542 dci winsq2
543 pi square
544
545 ;print # of moves from r23/22 (2:7/6)
546 li $1e ;row
547 lr 2,a
548 lisu 2 ;1000s digit
549 lisl 7
550 lr a,(IS)
551 sr 4
552 bt 4,lt1000
553 oi $40
554 lr 0,a
555 li $2a
556 lr 1,a
557 pi drawchar
558 bf 0,d100
559
560 lt1000:
561 li $2c
562 lr 1,a
563 d100:
564 lr a,1
565 inc
566 lr 1,a
567 lisu 2 ;100s digit
568 lisl 7
569 lr a,(IS)
570 ni $f
571 bf 4,gt100
572 lr a,(IS) ;print 0 if x0yz where x > 0
573 ni $ff
574 bt 4,lt100
575 lis 0
576
577 gt100:
578 oi $40
579 lr 0,a
580 pi drawchar
581 bf 0,d10
582
583 lt100:
584 li $30
585 lr 1,a
586 d10:
587 lr a,1
588 inc
589 lr 1,a
590 lisu 2 ;10s digit
591 lisl 6
592 lr a,(IS)
593 sr 4
594 bf 4,gt10
595 lisl 7 ;print 0 if xy0z where x or y > 0
596 lr a,(IS)
597 ni $ff
598 bt 4,lt10
599 lis 0
600 gt10:
601 oi $40
602 lr 0,a
603 pi drawchar
604 bf 0,d1
605
606 lt10:
607 li $34
608 lr 1,a
609 d1:
610 lr a,1
611 inc
612 lr 1,a
613 lisu 2 ;1s digit
614 lisl 6
615 lr a,(IS)
616 ni $f
617 oi $40
618 lr 0,a
619 pi drawchar
620
621 waitupdn:
622 pi readhc ;wait for hc up/down
623 ni $c0
624 bt 4,waitupdn
625 ni $80
626 bt 4,redo
627 jmp nextpat ;down - get next random pattern
628
629 redo:
630 lisu 3
631 lisl 6
632 lr a,(IS)
633 ci $41
634 bf 4,replay2
635
636 lisl 5
637 lr a,(IS)
638 ci 51
639 bf 4,replay2
640
641 lisu 2
642 lisl 7
643 lr a,(IS)-
644 ci 0
645 bf 4,replay2
646 lr a,(IS)
647 ci $18
648 bf 4,replay2
649
650 LI $d6
651 LR $3,A
652 PI clrscrn
653
654 dci blitparm
655 pi blit
656
657 li $3f
658 lr 1,a
659 snd3loop:
660 li $40
661 outs 5
662 li $1
663 lr 5,a
664 pi delay
665 lis 0
666 outs 5
667 ds 1
668 bf 4,snd3loop
669
670 pi readhc
671 LI $d6
672 LR $3,A
673 PI clrscrn
674
675 jmp nextpat
676 replay2:
677 jmp replay ;up - replay current pattern
678
679
680 readhc: ;wait until one of the hand controllers is moved
681 lis 0
682 outs 0
683 lis 0
684 outs 4
685 ins 4
686 com ;un-invert port data
687 ni $cf ;mask off twists, since we don't use them
688 bf 4,gothc
689 outs 1
690 ins 1
691 com
692 ni $cf
693 bt 4,readhc
694 gothc: pop
695
696
697 togglem: ;change a square (index in memory) from red to green or vice versa
698 lr k,p
699 pi pushk
700
701 lm
702 lr 0,a
703 ni $80 ;if high bit set, then this was a wrap
704 bt 4,notwrapped
705
706 lisu 3
707 lisl 6 ;if game=$2x, allow wrap-around
708 lr a,(IS)
709 ni $f0 ;mode in low nibble
710 ci $20
711 bf 4,toggleexit2 ;no wrap allowed
712
713 notwrapped:
714 lr a,0
715 ni $7f ;strip off "wrapped" bit
716 lisu 3
717 lisl 4
718 lr (IS),a
719 bf 0,toggle2
720
721 toggle: ;change a square (index in r28) from red to green or vice versa
722 lr k,p
723 pi pushk
724
725 lisu 3
726 lisl 4
727 lr a,(IS)
728 toggle2:
729 dci array
730 adc
731 lm
732 ni $ff
733 lr a,(IS)
734 dci array
735 adc
736 bt 4,notset
737 lis 0
738 bf 0,toggleexit
739 notset:
740 li $ff
741
742 toggleexit:
743 st
744 lisu 3
745 lisl 4
746 lr a,(IS)-
747 lr (IS),a
748 pi drawlight
749 toggleexit2:
750 pi popk
751 pk
752
753
754 square: ;draw a square
755 ; dci to color,width,height
756 ;r5=upper row
757 ;r4=left col
758 ; uses r2,r3,r6
759 lr k,p
760 pi pushk
761 lm
762 outs 1 ;set the color
763
764 lr a,5
765 com
766 outs 5 ;set the row
767
768 lm ;
769 lr 5,a ;save the width
770
771 lm
772 lr 3,a ;store the height
773
774 squarev:
775 lr a,4
776 lr 2,a ;save col
777 lr a,5 ;get width
778 squareh: lr 6,a ;save temp
779
780 lr a,2
781 com
782 outs 4 ;set the col
783 lr a,2
784 inc ;next col
785 lr 2,a
786
787 pi plot
788
789 lr a,6
790 ai $ff
791 bf 4,squareh ;all done w/row
792
793 ins 5 ;next row
794 ai $ff ;complement, so subtract 1
795 outs 5
796
797 lr a,3
798 ai $ff
799 lr 3,a
800 bf 4,squarev ;done full height?
801 pi popk
802 pk
803
804
805 drawlines: ; dci to table of color,len,row,start col (horiz if len<$80)
806 ; color,len,col,start row (vert if len>$80)
807 ; repeat until $FF
808 ;uses r5
809 lr k,p
810 line2:
811 lm
812 ci $ff
813 bt 4,lineexit ;ff means done
814 outs 1 ;set the color
815
816 lm ;get len
817 ni $ff ;lm doesn't set status flags
818 bf 1,vline ;vertical lines are negative (and sign bit backwards)
819 lr 5,a ;horiz-save len
820 lm
821 com
822 outs 5 ;set the row
823 lm ;get starting column
824 hline2:
825 com
826 outs 4 ;set the column
827 pi plot
828 ds 5
829 bt 4,line2
830 ins 4 ;
831 com
832 inc
833 bf 0,hline2
834 lineexit:
835 pk
836
837 vline:
838 ni $3f ;mask off sign bit, limit len to 63 (height of screen)
839 lr 5,a ;save it
840 lm
841 com
842 outs 4 ;set the column
843 lm ;get starting row
844 vline2:
845 com
846 outs 5 ;set the row
847 pi plot
848 ds 5
849 bt 4,line2
850 ins 5
851 com
852 inc
853 bf 0,vline2
854
855
856 plot: ;this is what you have to do to transfer data to the screen memory
857 ;after setting row, column and color
858 li $60
859 outs 0
860 li $50
861 outs 0
862 lis 6 ; little delay
863 pdelay: ai $ff
864 bf 4,pdelay
865 pop
866
867
868 drawlight: ;draws a red or green square based off value passed in r27
869 lr k,p
870 pi pushk
871
872 lisu 3
873 lisl 3
874 lr a,(IS)
875 dci sqrows
876 adc
877 lm
878 lr 5,a
879
880 lr a,(IS)
881 dci sqcols
882 adc
883 lm
884 lr 4,a
885
886 lr a,(IS) ; read color from array
887 dci array
888 adc
889 lm
890 ni $ff
891 bt 4,dogreen
892 dci redsq
893 bf 0,dosq
894 dogreen:
895 dci greensq
896 dosq:
897 pi square
898 pi popk
899 pk
900
901 ;blit code from cart 26
902 blit:
903 LR K,P
904 pi pushk
905 LISU 0
906 blitloop:
907 LISL 4
908 getparms:
909 LM
910 LR (IS)-,A
911 BR7 getparms
912 LM
913 LR H,DC
914 DCI blitparm
915 ADC
916
917 LIS 1
918 LR $7,A
919 INS 5
920 COM
921 NI $c0
922 AS $1
923 COM
924 blit2z:
925 OUTS 5
926 DS $3
927 BF 2,blitexit
928 LR A,$2
929 LR $5,A
930 LR A,$0
931 COM
932 blit2a:
933 OUTS 4
934 DS $7
935 BF 4,blit2c
936 LIS 8
937 LR $7,A
938 LM
939 LR $6,A
940 LIS 1
941 NS $4
942 BT 4,blit2b
943 LIS 0
944 COM
945 blit2b:
946 ADC
947 blit2c:
948 LR A,$6
949 AS $6
950 LR $6,A
951 LR A,$4
952 BT 2,blit2d
953 LIS 0
954 blit2d:
955 COM
956 OUTS 1
957 LIS 6
958 SL 4
959 OUTS 0
960 SL 1
961 OUTS 0
962 BF 0,blit2e
963 blit2e:
964 AI $60
965 BF 4,blit2e
966 DS $5
967 BT 4,blit2f
968 INS 4
969 AI $ff
970 BF 0,blit2a
971 blit2f:
972 INS 5
973 AI $ff
974 BF 0,blit2z
975 blitexit:
976
977 LR DC,H
978 LIS 2
979 NS $4
980 BT 4,blitloop
981 pi popk
982 PK
983
984
985 ;from the BIOS, but I removed T? (time) prompt
986 prompts: LR K,P ;
987 PI pushk ;
988 prompts2: LI $85 ; red 5 (S)
989 LR $0,A ;
990 PI prompt ;
991 LR A,$4 ;
992 CI $08 ; is it button 4, Start?
993 BF $4,notbut4 ; no, check others
994 notbut2:
995 PI popk ; yes, return
996 PK ;
997
998 notbut4: CI $02 ; is it button 2, Mode?
999 BF $4,notbut2 ;
1000 LI $8e ; red M
1001 LR $0,A ;
1002 PI prompt ;
1003 LISU 3 ;
1004 LISL 6 ;
1005 LR A,(IS) ;
1006 as 4 ;add the mode to the game #
1007 LR (IS),A ;
1008 BF $0,prompts2 ;
1009
1010
1011 ;from the BIOS, but I added random # seed to readbuts
1012 prompt: LR K,P ; $0099 - prints char r0 at row r1, col r2, waits for button
1013 PI pushk ;
1014 LI $33 ; r1=$33
1015 LR $1,A ;
1016 LI $13 ; r2=$13
1017 LR $2,A ;
1018 PI drawchar ;
1019
1020 LI $8b ; r0=8b red ?
1021 LR $0,A ;
1022 PI drawchar ;
1023
1024 PI readbuts ;
1025 LI $33 ; r1=$33
1026 LR $1,A ;
1027 LI $13 ; r2=$13
1028 LR $2,A ;
1029 LIS $d ; r0=$d
1030 LR $0,A ;
1031 PI drawchar ;
1032 PI drawchar ;
1033 PI popk ;
1034 PK ;
1035
1036 readbuts:
1037 lisu 2 ;inc random seed
1038 lisl 5
1039 lr a,(IS)
1040 inc
1041 lr (IS),a
1042
1043 INS 0 ; $00c1 - read buttons
1044 COM ;
1045 NI $0f ;
1046 BT 4,readbuts ;
1047 LR $4,A ;
1048 LI $ff ;
1049 LR $5,A ;
1050 dbounce: DS $5 ;
1051 BF $4,dbounce ;
1052 jmp delay ;
1053
1054
1055 ;colors: $40-red, $80=blue, $0=green, $c0=bkg
1056
1057 ;data to draw lines for grid
1058 grid: ;horiz-color,len,row,start col
1059 db $80,66,7,18
1060 db $80,66,17,18
1061 db $80,66,27,18
1062 db $80,66,37,18
1063 db $80,66,47,18
1064 db $80,66,57,18
1065 ;vert-color,$80+len,col,start row
1066 db $80,179,18,7 ;179=128+51
1067 db $80,179,31,7
1068 db $80,179,44,7
1069 db $80,179,57,7
1070 db $80,179,70,7
1071 db $80,179,83,7
1072 db $ff
1073
1074 ;data to draw squares
1075 redsq: ;color,width,height
1076 db $40,12,9
1077 greensq: ;color,width,height
1078 db $0,12,9
1079 cursor: ;color,width,height
1080 db $c0,4,3
1081 winsq1:
1082 db $40,38,29 ;red
1083 winsq2:
1084 db $c0,34,25 ;bkg
1085
1086 ;locations to draw each light, based on index (0-24)
1087 sqrows:
1088 db 8, 8, 8, 8, 8,18,18,18,18,18,28,28,28,28,28,38,38,38,38,38,48,48,48,48,48
1089 sqcols:
1090 db 19,32,45,58,71,19,32,45,58,71,19,32,45,58,71,19,32,45,58,71,19,32,45,58,71
1091
1092 ;locations to draw cursor, based on row/column
1093 currows:
1094 db 11,21,31,41,51
1095 curcols:
1096 db 23,36,49,62,75
1097
1098 plustable: ;squares to toggle based on cursor N E W S +128 means wrapped
1099 db 148, 1,132, 5
1100 db 149, 2, 0, 6
1101 db 150, 3, 1, 7
1102 db 151, 4, 2, 8
1103 db 152,128, 3, 9
1104
1105 db 0, 6,137, 10
1106 db 1, 7, 5, 11
1107 db 2, 8, 6, 12
1108 db 3, 9, 7, 13
1109 db 4,133, 8, 14
1110
1111 db 5, 11,142, 15
1112 db 6, 12, 10, 16
1113 db 7, 13, 11, 17
1114 db 8, 14, 12, 18
1115 db 9,138, 13, 19
1116
1117 db 10, 16,147, 20
1118 db 11, 17, 15, 21
1119 db 12, 18, 16, 22
1120 db 13, 19, 17, 23
1121 db 14,143, 18, 24
1122
1123 db 15, 21,152,128
1124 db 16, 22, 20,129
1125 db 17, 23, 21,130
1126 db 18, 24, 22,131
1127 db 19,148, 23,132
1128
1129 xtable: ;squares to toggle based on cursor NW NE SW SE +128 means wrapped
1130 db 152,149,137, 6
1131 db 148,150, 5, 7
1132 db 149,151, 6, 8
1133 db 150,152, 7, 9
1134 db 151,148, 8,133
1135
1136 db 132, 1,142, 11
1137 db 0, 2, 10, 12
1138 db 1, 3, 11, 13
1139 db 2, 4, 12, 14
1140 db 3,128, 13,138
1141
1142 db 137, 6,147, 16
1143 db 5, 7, 15, 17
1144 db 6, 8, 16, 18
1145 db 7, 9, 17, 19
1146 db 8,133, 18,143
1147
1148 db 142, 11,152, 21
1149 db 10, 12, 20, 22
1150 db 11, 13, 21, 23
1151 db 12, 14, 22, 24
1152 db 13,138, 23,148
1153
1154 db 147, 16,132,129
1155 db 15, 17,128,130
1156 db 16, 18,129,131
1157 db 17, 19,130,132
1158 db 18,143,132,128
1159
1160 ;the patterns - 1 bit is red, 0 is green
1161 ;other code has to be adjusted to use more or less than 64 patterns
1162 ;not all of these are solvable on a torus or if only the neighbors toggle
1163 pats:
1164 ; db $00,$00,$00,$80,$c0 ; easy one for test
1165
1166 db $20,$50,$88,$F8,$88
1167 db $F0,$88,$88,$88,$F0
1168 db $F8,$80,$F8,$80,$F8
1169 db $F8,$80,$F0,$80,$80
1170 db $88,$88,$F8,$88,$88
1171 db $F8,$20,$20,$20,$F8
1172 db $90,$A0,$C0,$A0,$90
1173 db $80,$80,$80,$80,$F8
1174 db $88,$D8,$A8,$88,$88
1175 db $88,$C8,$A8,$98,$88
1176 db $70,$88,$88,$88,$70
1177 db $70,$88,$A8,$90,$68
1178 db $70,$80,$70,$08,$70
1179 db $F8,$20,$20,$20,$20
1180 db $88,$88,$A8,$D8,$88
1181 db $88,$50,$20,$50,$88
1182 db $88,$50,$20,$20,$20
1183 db $F8,$10,$20,$40,$F8
1184 db $50,$50,$00,$70,$20
1185 db $20,$70,$F8,$70,$20
1186 db $D8,$20,$20,$20,$D8
1187 db $00,$00,$20,$00,$00
1188 db $00,$20,$50,$20,$00
1189 db $20,$00,$88,$00,$20
1190 db $50,$A8,$50,$A8,$50
1191 db $A8,$70,$F8,$70,$A8
1192 db $00,$D8,$50,$D8,$00
1193 db $20,$88,$20,$88,$20
1194 db $F8,$A8,$88,$A8,$F8
1195 db $20,$60,$20,$20,$70
1196 db $70,$08,$70,$80,$F8
1197 db $70,$08,$70,$08,$70
1198 db $F8,$00,$70,$00,$F8
1199 db $70,$88,$70,$88,$70
1200 db $F8,$88,$50,$70,$00
1201 db $F8,$70,$20,$00,$00
1202 db $20,$20,$F8,$20,$20
1203 db $A8,$88,$F8,$88,$A8
1204 db $C0,$A0,$A8,$28,$18
1205 db $18,$08,$20,$80,$C0
1206 db $D8,$88,$50,$88,$D8
1207 db $18,$C0,$18,$C0,$18
1208 db $A8,$A8,$A8,$A8,$A8
1209 db $00,$F8,$00,$F8,$00
1210 db $10,$78,$50,$F0,$40
1211 db $C0,$E0,$70,$38,$18
1212 db $60,$90,$70,$48,$30
1213 db $A8,$A8,$50,$A8,$A8
1214 db $98,$F0,$50,$78,$C8
1215 db $70,$A8,$F8,$F8,$A8
1216 db $A0,$E0,$B8,$10,$38
1217 db $00,$00,$F8,$50,$50 ; pi pattern
1218 db $00,$40,$00,$10,$00
1219 db $00,$50,$00,$50,$00
1220 db $10,$48,$20,$90,$40
1221 db $78,$E8,$F8,$B8,$F0
1222 db $E0,$90,$E0,$90,$E0
1223 db $30,$48,$C0,$48,$30
1224 db $38,$48,$20,$90,$E0
1225 db $00,$38,$00,$E0,$00
1226 db $20,$20,$D8,$20,$20
1227 db $20,$70,$A8,$20,$20
1228 db $C8,$D0,$20,$58,$98
1229 db $00,$70,$50,$70,$00
1230
1231 ;8 bytes available here
1232
1233 org $f00
1234 blitparm:
1235 db $82,19,96,$16,$8,$08,00,00
1236 blitdata:
1237 db $00,$45,$F0,$41,$E1,$01,$F7,$80,$44,$20,$40,$00
1238 db $00,$45,$00,$41,$13,$81,$04,$40,$A4,$20,$A0,$00
1239 db $00,$7D,$E0,$41,$E4,$41,$E7,$81,$14,$21,$10,$00
1240 db $00,$45,$04,$41,$07,$C1,$04,$41,$F4,$21,$F0,$00
1241 db $00,$45,$f3,$81,$04,$41,$F4,$41,$17,$BD,$10,$00
1242 db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
1243 db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
1244 db $F8,$8E,$F1,$C8,$BA,$1E,$04,$50,$72,$22,$3C,$F8
1245 db $81,$44,$8A,$28,$92,$11,$03,$90,$82,$45,$22,$80
1246 db $F2,$24,$F2,$0F,$92,$11,$74,$50,$73,$88,$BC,$F0
1247 db $83,$E4,$8A,$28,$92,$11,$07,$D0,$0A,$4F,$A2,$80
1248 db $82,$2E,$89,$C8,$BB,$DE,$04,$5E,$72,$28,$A2,$F8
1249 db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
1250 db $00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00,$00
1251 db $00,$00,$00,$79,$17,$81,$17,$DF,$20,$00,$00,$00
1252 db $00,$00,$00,$44,$E4,$41,$11,$10,$20,$00,$00,$00
1253 db $00,$00,$00,$45,$17,$81,$11,$1E,$20,$00,$00,$00
1254 db $00,$00,$00,$45,$F4,$41,$11,$10,$00,$00,$00,$00
1255 db $00,$00,$00,$79,$14,$40,$E1,$1F,$20,$00,$00,$00
1256
1257 ;4 bytes available here
1258
1259 org $ff0
1260 db $53,$65,$61,$6e,$20,$52,$69,$64,$64,$6c,$65,$20,$32,$30,$30,$34