Tinyrinth ESCAPE - ECCC VCFMW 2018 Preview!
TinyRinth
My entry for the 2001 MiniGame competition was a 512 byte game called "Tinyrinth".
I got 5th place and I had a lot of fun coding it and later writing it up for C=Hacking #21.

TinyRinth - As released with the 2001 MiniGame Competition.

Very very very simple gameplay, collect keys, avoid the red guy:


100 Examples of generated mazes:
TinyRinth animation

To demonstrate how small it is, here it is displayed a few different ways:

Tinyrinth in uue Format: (can copy this and save as tinyrinth.uue and open with winrar/uudecode.)
begin 644 tinyrinth.prg
M`!"B`(93YE.F4X94CH8"J06-(M"%185&($3EJ2"%2*D`A5&-(-"-(="%0X5$
MJH5'H`"**0'P`DE_2?^11\B**0))`DJ%28HI"-`"28A)"`5)P`?0YHHI!/`"
M27I)_Y%'Z!BE1VD(T,;F2*1(P"C0OHPCT*E;C1'0J1B-&-"D1:9&(-\1\!#H
M(-@1\`J((.81\`3*(-$1\#^E2]`7A4F%2N9+R/`.I53P"L94YE&QT0G`D=&F
M2J1)YDG`*/`,(.L1\/.$189&3'\0J0"%2>9*I4K)&=#>\%6I@(V*`HT2U(T/
MU*T;U"D#&&D!A4RD1:9&(,41T.*%2Z9,O?@1D=&]]A&%3:1%ID8@ZQ$%39'1
MI4P@Q1&$189&YD/0#N9$I43)`]`&I4/)Z?`#3'L0[B30YEC00N97T#ZE4\GX
M,`*I^`GPA5>D5:96(.L1D=&D5<C`*#`&ID:&5J``A%6I_R#M$859*<#)P/#F
MR4#0`TP`$*59"8"1T2#D__"R*0.JO<$1JH9.O?@1A4^D1:9&(.L1D=&I`(50
MI4X@Q1$E3]`$I$6F1JG_(.T12"D?"4"1T81%AD9H*<#)P-`'QE'0`TP$$$PJ
M$0(!!`/)`?`6R0+P"\D#\!6(P/_P'M`3R,`H\!?0#,K@__`0T`7HX!GP":D?
0A5`@\.FQT2508`$"!`@!`@``
`
end

Tinyrinth in base64 Format: (can copy this and save as tinyrinth.uu and decode with uudecode.)
begin-base64 755 Tinyrinth
ABCiAIZT5lOlU4VUjYYCqQWNItCFRYVGIETlqVuNEdCpGI0Y0KkghUipAIVRjSDQjSHQqoVHoACK
KQHwAkl/Sf+RR8iKKQJJAkqFSYopCNACSYhJCAVJwAfQ5oopBPACSXpJ/5FH6BilR2kI0MbmSKRI
wCjQvowj0KRFpkYgzhHwEOggxxHwCogg1RHwBMogwBHwP6VL0BeFSYVK5kvI8A6lVPAKxlTmUbHR
CcCR0aZKpEnmScAo8Awg2hHw84RFhkZMexCpAIVJ5kqlSskZ0N7wQ6mAjYoCjRLUjQ/UrRvUKQMY
aQGFTKRFpkYgtBHQ4oVLpky95xGR0b3lEYVNpEWmRiDaEQVNkdGlTCC0EYRFhkZMdxDuJNDmWNBA
5lfQPKVTyfgwAqn4CfCFV6RVplYg2hGR0cjAKDAGpkaGVqAAhFWp/yDcEYVZKcDJwPDmyUDQA0wA
EKVZCYCR0SDk//C0KQOqvbARqoZOvecRhU+kRaZGINoRkdGpAIVQpU4gtBElT9AEpEWmRqn/INwR
SCkfCUCR0YRFhkZoKcDJwNAHxlHQA0wEEMmA0ANMABBMFBECAQQDyQHwFskC8AvJA/AViMD/8B7Q
E8jAKPAX0AzK4P/wENAF6OAZ8AmpH4VQIPDpsdElUGABAgQIAQI=
====

Tinyrinth's bytes as a 16x32 greyscale image:

(a closer look at that..)


Tinyrinth's bits as a 64x64 pixel image:

(a closer look at that..)


Tinyrinth bytes: (with 2-byte load address)
00000000h: 00 10 A2 00 86 53 E6 53 A6 53 86 54 8E 86 02 A9 ; ...SSST.
00000010h: 05 8D 22 D0 85 45 85 46 20 44 E5 A9 20 85 48 A9 ; ."ЅEF D H
00000020h: 00 85 51 8D 20 D0 8D 21 D0 85 43 85 44 AA 85 47 ; .Q Ѝ!ЅCDG
00000030h: A0 00 8A 29 01 F0 02 49 7F 49 FF 91 47 C8 8A 29 ; .)..IIGȊ)
00000040h: 02 49 02 4A 85 49 8A 29 08 D0 02 49 88 49 08 05 ; .I.JI)..II..
00000050h: 49 C0 07 D0 E6 8A 29 04 F0 02 49 7A 49 FF 91 47 ; I.)..IzIG
00000060h: E8 18 A5 47 69 08 D0 C6 E6 48 A4 48 C0 28 D0 BE ; .Gi.HH(о
00000070h: 8C 23 D0 A9 5B 8D 11 D0 A9 18 8D 18 D0 A4 45 A6 ; #Щ[.Щ..ФE
00000080h: 46 20 DF 11 F0 10 E8 20 D8 11 F0 0A 88 20 E6 11 ; F .. .. .
00000090h: F0 04 CA 20 D1 11 F0 3F A5 4B D0 17 85 49 85 4A ; . .?K.IJ
000000a0h: E6 4B C8 F0 0E A5 54 F0 0A C6 54 E6 51 B1 D1 09 ; K.T.TQ.
000000b0h: C0 91 D1 A6 4A A4 49 E6 49 C0 28 F0 0C 20 EB 11 ; ѦJII(. .
000000c0h: F0 F3 84 45 86 46 4C 7F 10 A9 00 85 49 E6 4A A5 ; EFL..IJ
000000d0h: 4A C9 19 D0 DE F0 55 A9 80 8D 8A 02 8D 12 D4 8D ; J.U..ԍ
000000e0h: 0F D4 AD 1B D4 29 03 18 69 01 85 4C A4 45 A6 46 ; .ԭ.)..i.LEF
000000f0h: 20 C5 11 D0 E2 85 4B A6 4C BD F8 11 91 D1 BD F6 ;  .KL.ѽ
00000100h: 11 85 4D A4 45 A6 46 20 EB 11 05 4D 91 D1 A5 4C ; .MEF ..MѥL
00000110h: 20 C5 11 84 45 86 46 E6 43 D0 0E E6 44 A5 44 C9 ;  .EFC.DD
00000120h: 03 D0 06 A5 43 C9 E9 F0 03 4C 7B 10 EE 24 D0 E6 ; ..C.L{.$
00000130h: 58 D0 42 E6 57 D0 3E A5 53 C9 F8 30 02 A9 F8 09 ; XBW>S0..
00000140h: F0 85 57 A4 55 A6 56 20 EB 11 91 D1 A4 55 C8 C0 ; WUV .ѤU
00000150h: 28 30 06 A6 46 86 56 A0 00 84 55 A9 FF 20 ED 11 ; (0.FV.U .
00000160h: 85 59 29 C0 C9 C0 F0 E6 C9 40 D0 03 4C 00 10 A5 ; Y)@.L..
00000170h: 59 09 80 91 D1 20 E4 FF F0 B2 29 03 AA BD C1 11 ; Y. )..
00000180h: AA 86 4E BD F8 11 85 4F A4 45 A6 46 20 EB 11 91 ; N.OEF .
00000190h: D1 A9 00 85 50 A5 4E 20 C5 11 25 4F D0 04 A4 45 ; ѩ.PN .%O.E
000001a0h: A6 46 A9 FF 20 ED 11 48 29 1F 09 40 91 D1 84 45 ; F .H)..@фE
000001b0h: 86 46 68 29 C0 C9 C0 D0 07 C6 51 D0 03 4C 04 10 ; Fh).Q.L..
000001c0h: 4C 2A 11 02 01 04 03 C9 01 F0 16 C9 02 F0 0B C9 ; L*.........
000001d0h: 03 F0 15 88 C0 FF F0 1E D0 13 C8 C0 28 F0 17 D0 ; ....(.
000001e0h: 0C CA E0 FF F0 10 D0 05 E8 E0 19 F0 09 A9 1F 85 ; ......
000001f0h: 50 20 F0 E9 B1 D1 25 50 60 01 02 04 08 01 02    ; P %P`......	

Tinyrinth disassembly:
1000  A2 00     LDX #$00
1002  86 53     STX $53
1004  E6 53     INC $53
1006  A6 53     LDX $53
1008  86 54     STX $54
100A  8E 86 02  STX $0286
100D  A9 05     LDA #$05
100F  8D 22 D0  STA $D022
1012  85 45     STA $45
1014  85 46     STA $46
1016  20 44 E5  JSR $E544
1019  A9 20     LDA #$20
101B  85 48     STA $48
101D  A9 00     LDA #$00
101F  85 51     STA $51
1021  8D 20 D0  STA $D020
1024  8D 21 D0  STA $D021
1027  85 43     STA $43
1029  85 44     STA $44
102B  AA        TAX
102C  85 47     STA $47
102E  A0 00     LDY #$00
1030  8A        TXA
1031  29 01     AND #$01
1033  F0 02     BEQ $1037
1035  49 7F     EOR #$7F
1037  49 FF     EOR #$FF
1039  91 47     STA ($47),Y
103B  C8        INY
103C  8A        TXA
103D  29 02     AND #$02
103F  49 02     EOR #$02
1041  4A        LSR A
1042  85 49     STA $49
1044  8A        TXA
1045  29 08     AND #$08
1047  D0 02     BNE $104B
1049  49 88     EOR #$88
104B  49 08     EOR #$08
104D  05 49     ORA $49
104F  C0 07     CPY #$07
1051  D0 E6     BNE $1039
1053  8A        TXA
1054  29 04     AND #$04
1056  F0 02     BEQ $105A
1058  49 7A     EOR #$7A
105A  49 FF     EOR #$FF
105C  91 47     STA ($47),Y
105E  E8        INX
105F  18        CLC
1060  A5 47     LDA $47
1062  69 08     ADC #$08
1064  D0 C6     BNE $102C
1066  E6 48     INC $48
1068  A4 48     LDY $48
106A  C0 28     CPY #$28
106C  D0 BE     BNE $102C
106E  8C 23 D0  STY $D023
1071  A9 5B     LDA #$5B
1073  8D 11 D0  STA $D011
1076  A9 18     LDA #$18
1078  8D 18 D0  STA $D018
107B  A4 45     LDY $45
107D  A6 46     LDX $46
107F  20 DF 11  JSR $11DF
1082  F0 10     BEQ $1094
1084  E8        INX
1085  20 D8 11  JSR $11D8
1088  F0 0A     BEQ $1094
108A  88        DEY
108B  20 E6 11  JSR $11E6
108E  F0 04     BEQ $1094
1090  CA        DEX
1091  20 D1 11  JSR $11D1
1094  F0 3F     BEQ $10D5
1096  A5 4B     LDA $4B
1098  D0 17     BNE $10B1
109A  85 49     STA $49
109C  85 4A     STA $4A
109E  E6 4B     INC $4B
10A0  C8        INY
10A1  F0 0E     BEQ $10B1
10A3  A5 54     LDA $54
10A5  F0 0A     BEQ $10B1
10A7  C6 54     DEC $54
10A9  E6 51     INC $51
10AB  B1 D1     LDA ($D1),Y
10AD  09 C0     ORA #$C0
10AF  91 D1     STA ($D1),Y
10B1  A6 4A     LDX $4A
10B3  A4 49     LDY $49
10B5  E6 49     INC $49
10B7  C0 28     CPY #$28
10B9  F0 0C     BEQ $10C7
10BB  20 EB 11  JSR $11EB
10BE  F0 F3     BEQ $10B3
10C0  84 45     STY $45
10C2  86 46     STX $46
10C4  4C 7F 10  JMP $107F
10C7  A9 00     LDA #$00
10C9  85 49     STA $49
10CB  E6 4A     INC $4A
10CD  A5 4A     LDA $4A
10CF  C9 19     CMP #$19
10D1  D0 DE     BNE $10B1
10D3  F0 55     BEQ $112A
10D5  A9 80     LDA #$80
10D7  8D 8A 02  STA $028A
10DA  8D 12 D4  STA $D412
10DD  8D 0F D4  STA $D40F
10E0  AD 1B D4  LDA $D41B
10E3  29 03     AND #$03
10E5  18        CLC
10E6  69 01     ADC #$01
10E8  85 4C     STA $4C
10EA  A4 45     LDY $45
10EC  A6 46     LDX $46
10EE  20 C5 11  JSR $11C5
10F1  D0 E2     BNE $10D5
10F3  85 4B     STA $4B
10F5  A6 4C     LDX $4C
10F7  BD F8 11  LDA $11F8,X
10FA  91 D1     STA ($D1),Y
10FC  BD F6 11  LDA $11F6,X
10FF  85 4D     STA $4D
1101  A4 45     LDY $45
1103  A6 46     LDX $46
1105  20 EB 11  JSR $11EB
1108  05 4D     ORA $4D
110A  91 D1     STA ($D1),Y
110C  A5 4C     LDA $4C
110E  20 C5 11  JSR $11C5
1111  84 45     STY $45
1113  86 46     STX $46
1115  E6 43     INC $43
1117  D0 0E     BNE $1127
1119  E6 44     INC $44
111B  A5 44     LDA $44
111D  C9 03     CMP #$03
111F  D0 06     BNE $1127
1121  A5 43     LDA $43
1123  C9 E9     CMP #$E9
1125  F0 03     BEQ $112A
1127  4C 7B 10  JMP $107B
112A  EE 24 D0  INC $D024
112D  E6 58     INC $58
112F  D0 42     BNE $1173
1131  E6 57     INC $57
1133  D0 3E     BNE $1173
1135  A5 53     LDA $53
1137  C9 F8     CMP #$F8
1139  30 02     BMI $113D
113B  A9 F8     LDA #$F8
113D  09 F0     ORA #$F0
113F  85 57     STA $57
1141  A4 55     LDY $55
1143  A6 56     LDX $56
1145  20 EB 11  JSR $11EB
1148  91 D1     STA ($D1),Y
114A  A4 55     LDY $55
114C  C8        INY
114D  C0 28     CPY #$28
114F  30 06     BMI $1157
1151  A6 46     LDX $46
1153  86 56     STX $56
1155  A0 00     LDY #$00
1157  84 55     STY $55
1159  A9 FF     LDA #$FF
115B  20 ED 11  JSR $11ED
115E  85 59     STA $59
1160  29 C0     AND #$C0
1162  C9 C0     CMP #$C0
1164  F0 E6     BEQ $114C
1166  C9 40     CMP #$40
1168  D0 03     BNE $116D
116A  4C 00 10  JMP $1000
116D  A5 59     LDA $59
116F  09 80     ORA #$80
1171  91 D1     STA ($D1),Y
1173  20 E4 FF  JSR $FFE4
1176  F0 B2     BEQ $112A
1178  29 03     AND #$03
117A  AA        TAX
117B  BD C1 11  LDA $11C1,X
117E  AA        TAX
117F  86 4E     STX $4E
1181  BD F8 11  LDA $11F8,X
1184  85 4F     STA $4F
1186  A4 45     LDY $45
1188  A6 46     LDX $46
118A  20 EB 11  JSR $11EB
118D  91 D1     STA ($D1),Y
118F  A9 00     LDA #$00
1191  85 50     STA $50
1193  A5 4E     LDA $4E
1195  20 C5 11  JSR $11C5
1198  25 4F     AND $4F
119A  D0 04     BNE $11A0
119C  A4 45     LDY $45
119E  A6 46     LDX $46
11A0  A9 FF     LDA #$FF
11A2  20 ED 11  JSR $11ED
11A5  48        PHA
11A6  29 1F     AND #$1F
11A8  09 40     ORA #$40
11AA  91 D1     STA ($D1),Y
11AC  84 45     STY $45
11AE  86 46     STX $46
11B0  68        PLA
11B1  29 C0     AND #$C0
11B3  C9 C0     CMP #$C0
11B5  D0 07     BNE $11BE
11B7  C6 51     DEC $51
11B9  D0 03     BNE $11BE
11BB  4C 04 10  JMP $1004
11BE  4C 2A 11  JMP $112A
11C1  02 01 04 03
11C5  C9 01     CMP #$01
11C7  F0 16     BEQ $11DF
11C9  C9 02     CMP #$02
11CB  F0 0B     BEQ $11D8
11CD  C9 03     CMP #$03
11CF  F0 15     BEQ $11E6
11D1  88        DEY
11D2  C0 FF     CPY #$FF
11D4  F0 1E     BEQ $11F4
11D6  D0 13     BNE $11EB
11D8  C8        INY
11D9  C0 28     CPY #$28
11DB  F0 17     BEQ $11F4
11DD  D0 0C     BNE $11EB
11DF  CA        DEX
11E0  E0 FF     CPX #$FF
11E2  F0 10     BEQ $11F4
11E4  D0 05     BNE $11EB
11E6  E8        INX
11E7  E0 19     CPX #$19
11E9  F0 09     BEQ $11F4
11EB  A9 1F     LDA #$1F
11ED  85 50     STA $50
11EF  20 F0 E9  JSR $E9F0
11F2  B1 D1     LDA ($D1),Y
11F4  25 50     AND $50
11F6  60        RTS
11F7  01 02 04 08 01 02

Tinyrinth Documentation:
Tinyrinth 
version 1.05
(a 512b game)
Mark Seelye  mseelye@yahoo.com
(a.k.a. Burning Horizon/FTA)
http://www.burninghorizon.com


512 bytes of Story:  (Read to the tune of almost any Atari 2600 Back cover.)
-------------------------------------------------------------------------------
You are caught in a maze with no way out; you collect the flashing 
keys with hopes of escaping, but I don't think you ever will!

You are the green guy in the lower right corner of the screen, you do not
appear until you hit a key.   The reason you do not appear right away is 
because the nasty flying red MINItaur (not Minotaur) is trying to send you back
to the first level!

Each level adds another key if there is room, also the flying red Minitaur
gets faster and faster!!  

Beware level 15!!!
-------------------------------------------------------------------------------


512 bytes of instructions and stuff:
-------------------------------------------------------------------------------
sys 4096 to start

You are the green box in the lower right corner of the maze you appear after 
the maze finishes drawing and after you hit a key.

I,J,K,L are up, left, down, right respectively.
  (Other keys will work too, but are wacky)

Red box will send you back to the first level. 

Each level the red box will get faster and faster until level 8.

Each maze is completely random and solvable, including level 15!

I have yet to beat level 15, it is hard, so if you beat it then you rUl3!!!
-------------------------------------------------------------------------------


Revision History:
ver 1.00: Proof of concept.
ver 1.01: Early preview, player did not move at all.
ver 1.02: Added additional keys each level, Player moves but was buggy
ver 1.03: Added green "minitaur" got dubbed the Green Buger
          Fixed bottom of the maze bug
ver 1.04: Fixed all known bugs
          Made minitaur go faster each levek
          Made minitaur red
          Made player green
          Made each level change color
ver 1.05: Removed 3 more bytes in case the load address counts
          Moved to $1000(4096)
          Wrote basic loader w/quick instructions
		

Tinyrinth source file:
(Can't find original 1.05 version, this is slightly different/smaller!)
;Tinyrinth 
;version 1.06
;(a 512b game)
;Mark Seelye  mseelye@yahoo.com
;(a.k.a. Burning Horizon/FTA)
;http://www.burninghorizon.com
;
;
;512 bytes of Story:  (Read to the tune of almost any Atari 2600 Back cover.)
;-------------------------------------------------------------------------------
;You are caught in a maze with no way out; you collect the flashing 
;keys with hopes of escaping, but I don't think you ever will!
;
;You are the green guy in the lower right corner of the screen, you do not
;appear until you hit a key.   The reason you do not appear right away is 
;because the nasty flying red MINItaur (not Minotaur) is trying to send you back
;to the first level!
;
;Each level adds another key if there is room, also the flying red Minitaur
;gets faster and faster!!  
;
;Beware level 15!!!
;-------------------------------------------------------------------------------
;
;
;512 bytes of instructions and stuff:
;-------------------------------------------------------------------------------
;sys 4096 to start
;
;You are the green box in the lower right corner of the maze you appear after 
;the maze finishes drawing and after you hit a key.
;
;I,J,K,L are up, left, down, right respectively.
;  (Other keys will work too, but are wacky)
;
;Red box will send you back to the first level. 
;
;Each level the red box will get faster and faster until level 8.
;
;Each maze is completely random and solvable, including level 15!
;
;I have yet to beat level 15, it is hard, so if you beat it then you rUl3!!!
;-------------------------------------------------------------------------------
;
;Revision History:
;ver 1.00: Proof of concept.
;ver 1.01: Early preview, player did not move at all.
;ver 1.02: Added additional keys each level, Player moves but was buggy
;ver 1.03: Added green "minitaur" got dubbed the Green Buger
;          Fixed bottom of the maze bug
;ver 1.04: Fixed all known bugs
;          Made minitaur go faster each levek
;          Made minitaur red
;          Made player green
;          Made each level change color
;ver 1.05: Removed 3 more bytes in case the load address counts
;          Moved to $1000(4096)
;          Wrote basic loader w/quick instructions
;ver 1.06: Changed some trivial things, removed something
;          Between 1.05 and 1.06 to get it down to 482 bytes!

* = $1000

;name   loc     desc       color  ecbm bits
EBCM0 = $d021 ; untouched  black   $00  00
EBCM1 = $d022 ; cursor     red     $40  01
EBCM2 = $d023 ; touched    green   $80  10
EBCM3 = $d024 ; keys       yellow  $c0  11

;ZPs used:  (Consolidation Possible if needed)
;43/44 - Not Used
;45/46 - Current X/Y Position, Maze Generation & Game
;47/48 - CSet Location, CSet Generation
;49    - Temp Storage, CSet Generation
;49/4a - Xpos/Ypos Findgrow, Maze Generation
;4b    - Flag, Findgrow, Maze Generation
;4c    - Temp Storage, randdir, Maze Generation
;4d    - Temp Storage, grow, Maze Generation
;4e/4f - Temp Storage, glmove, Game
;50    - Temp Storage, loadcell, Maze Generation & Game
;51    - NumKeys Left in level (affected by: destroyed & found keys)
;52    - not used
;53    - Current Level 
;54    - # of Keys to try and place, gameinit, Game
;55/56 - X/Y Pos of Minitaur
;57/58 - speed counter for Minitaur

;Collect all keys

; Initialization
setup = *
gameover = *
        ;Setup game variables
        ldx #$00
        stx $53         ; Start at level 1 (to be inc'd)
init = *
        ;Setup level
        inc $53         ; next level
        lda $53
        sta $54         ;Counter for drawing Keys (next level)
        sta $0286       ;Character Color to use on clear (e544)
;asl ; x2
;clc
;adc #$0a
;sta $61
;cmp #$19
;bmi _sz1
;lda #$28
;sta $61
;lda #$19
;_sz1 sta $62

        ;Set Render Cursor Start Pos / Player Color
        lda #$05
        sta EBCM1       ;Set ebcm color PLAYER to GREEN ($d022)
        sta $45         ; Cursor/Player Position X (0-39)
        sta $46         ; Cursor/Player Position Y (0-24)
        ;Clear Screen
        jsr $E544       ;clear screen set to char color ($0286)

        lda #$5b
        sta $d011      ;turn on EBCM
        lda #$18
        sta $d018      ;Activate Cset

        ; Generate Cset!
        lda #$20       ; write hi
        sta $48        ; use zp
        lda #$00       ; write lo
     
        ;Initialize Screen, variables (injected here to save bytes - using lda #$00)
        sta $51           ; Clear actual num keys placed counter (see findgrow)
        sta $d020
        sta EBCM0;  Set BG Color ($d021)
        ;(end of injection)

        tax            ; counter = 0
_again  sta $47        ; use zp
        ldy #$00       ; index
        txa            ; counter to a

;        and #$0f
;        bne _test
;        lda #%10101010
;_zero   sta ($47),y
;        iny
;        cpy #$08
;        bne _zero
;        beq _nxt

_test   and #$01       ; check for top
        beq _ytop      ; yes top
        eor #%01111111 ; 00000001 -> 011111110 -> 10000001
_ytop   eor #%11111111 ; 00000000 -> 111111111    
_6sides sta ($47),y    ; store top/sides to cset
        iny            ; next mem location
        txa            ; counter to a
        and #$02       ; check for right
        eor #%00000010 ; flip
        lsr            ; 00000010 -> 00000001 || 0->0
        sta $49        ; store for right side 
        txa            ; counter to a
        and #$08       ; check for left side
        bne _noleft    ; no left
        eor #%10001000 ; 00000000 -> 10001000 -> 10000000
_noleft eor #%00001000 ; 00001000 -> 00000000
        ora $49        ; merge with right
        cpy #$07       ; 7->15->23->...
        bne _6sides    ; total of 6 side pieces
        txa            ; counter to a
        and #$04       ; check for bottom
        beq _ybot      ; no bottom
        eor #%01111010 ; 00000100 -> 01111110 -> 10000001
_ybot   eor #%11111111 ; 00000000 -> 11111111    
        sta ($47),y    ; store bottom to cset
_nxt    inx            ; next counter
        clc            ; clear carry
        lda $47        ; inc zp
        adc #$08       ; by 8
        bne _again     ; do it again
        inc $48
        ldy $48
        cpy #$28       ;repeat through cset 2000-2800
        bne _again

        sty EBCM2      ;Set Minitaur color ($d023) (using result of cset gen for color value!)
        
        
popgridloop = *
        ;can grow from current?
        ldy $45         ;xpos
        ldx $46         ;ypos
        ;Can grow in any direction?
cangrowxy = *
        jsr cgup        ;check up
        beq _cgxy       ;if 0 then we can grow
        inx             ;offset up check
        jsr cgright     ;check right
        beq _cgxy       ;if 0 then we can grow
        dey             ;offset right check
        jsr cgdown      ;check down
        beq _cgxy       ;if 0 then we can grow
        dex             ;offset down check
        jsr cgleft      ;check left
_cgxy   beq growloop    ;if 0 then we can grow
; *** fall into findgrow
findgrow = *
        lda $4b         ; Check byte 0 != resume findgrow
        bne _fgresume
        sta $49         ;Reset Findgrow Xpos
        sta $4a         ;Reset Findgrow Ypos
        inc $4b         ;Set findgrow flag to resume (<>0)

        ;Place keys in corners (injected here for ease of placement, d1/d2 is pointed at a dead end)
        iny             ; offset left check
        beq _fgresume   ;Do not try when column is 0, it freaks out
        lda $54
        beq _fgresume   ;if 0 then keys are done
        dec $54         ;dec # of keys left to place
        inc $51         ;actual num keys left
        lda ($d1),y     ;load byte
        ora #$c0        ;EBCM value for key!
        sta ($d1),y     ;store new value
        ;(end of injection)

_fgresume = *
_fgx    ldx $4a         ;Findgrow ypos
_fgy    ldy $49         ;Findgrow xpos
        inc $49         ;Next xpos (next round)
        cpy #$28;$61;        ; < 40
        beq _fgcr       ; next line if >= 40
        jsr cgloadcell  ; load cell byte
        beq _fgy        ; if 0 then get next xpos/byte
        sty $45         ;Set Current xpos
        stx $46         ;Set Current ypos
        jmp cangrowxy   ;Check if this can grow
_fgcr   lda #$00        ;Reset Findgrow xpos
        sta $49         ; 0->xpos
        inc $4a         ;Next Findgrow ypos
        lda $4a         
        cmp #$19;$62    ;check ypos (<25)
        bne _fgx        ;If we're at x40y25 we are ready to play!
        beq gameinit    ;Start game logic
        
              
growloop = *        
randdir = *
        ;jsr getrand; not a func, not reused yet
getrand = *
        lda #$80
       sta $028a; Ket Repeat; (injected here for #$80) just using #$80 for smaller code
        sta $d412       ;sta $d404   d412 is V3, d404 is V1!!
        sta $d40f       ;set v3 random # gen bits
        lda $d41b       ; read random number from V3
        and #$03        ; Force Random number to 0-3
        clc
        adc #$01        ; Add 1 to get 1-4
        sta $4c         ; store rand direction
        ldy $45         ; Current Xpos
        ldx $46         ; Current Ypos
        jsr cangrow     ; Check if we can grow in that direction
        bne randdir     ; if <> 0 then Try again
       sta $4b          ; reset findgrow flag (injected here for .a==0)
grow = *
        ldx $4c         ;Get saved rand direction
        lda growinto,x  ; 1-4 (4, 8, 1, 2) Get bit set for new cell
        sta ($d1),y     ; write new location
        lda growfrom,x  ; 1-4 (1, 2, 4, 8) Get bit to set for old
        sta $4d         ; Save growfrom bit
        ldy $45         ; Reload Current xpos
        ldx $46         ; Reload Current ypos
        jsr cgloadcell  ; Load base cell again
        ora $4d         ; Combine with growfrom bit
        sta ($d1),y     ;Modify old cell to connect to new loc
        ;Change current position
        lda $4c         ; Get saved rand direction
        jsr cangrow     ; Get new x y again - (this will only perform next x/y adj, returns <>0)
        sty $45         ; xpos   set to new location
        stx $46         ; ypos
        jmp popgridloop ; Return to populate grid loop


; Game Initializtion and Game Loop
gameinit = *
gameloop=*
        inc EBCM3       ; Flash Keys ($d024)
        inc $58         ; Increase Speed counter #1 (0-255)
        bne moveplayer  ; Skip move
        inc $57         ; Increase Speed counter #2 ($57|#$f0 - 255)
        bne moveplayer  ; Skip Move
        
        ;set Minitaur speed
        lda $53         ;Use level for Speed value
        cmp #%11111000  ;If more than this use default speed
        bmi _dsp        
        lda #%11111000  ;Default speed
_dsp    ora #%11110000  ;Set high nybble so counter counts up to 255
        sta $57         ; Set Speed counter #2


;move Minitaur
moveminitaur = *
        ldy $55         ;Baddy Xpos
        ldx $56         ;Baddy Ypos        
        jsr cgloadcell  ; load the cell/point the zps (ANDs by #$1f)
        sta ($d1),y     ;store cleared value
_newy   iny             ;increase xpos
        cpy #$28;$61    ;less than 40?
        bmi _go         ;don't reset
        ldx $46         ;ypos of player
        stx $56         ;ypos of minitaur
        ldy #$00        ;clear xpos counter
_go     sty $55         ;Set baddy xpos
        lda #$ff        ;Get all bits! (see loadcell)
        jsr loadcell    ;load the cell/point the zps
        sta $59         ;Save cell value (withh all possible bits)
        and #%11000000  ;and by EBCM bits
        cmp #%11000000  ;Check for KEY - (so it can skip over)
        beq _newy       ;Jump ahead 1 more to skip key position
        cmp #%01000000  ;Check for player hit
        bne _nodie      ;Player is not dead
        jmp gameover    ;Game Over!  
_nodie  lda $59         ;Reload stored value
        ora #$80        ;EBCM for minitaur
        sta ($d1),y     ;store value
; *** fall through to Move Player

;Move Player
moveplayer=*
_ffe4   jsr $ffe4       ;Get keypress
        beq gameloop    ;no key - goto gameloop
        and #%00000011  ;.a == 0-3 at this point
        tax             
        lda keytodir,x  ;Loads from keytodir
;Move entity in game
; .a=direction 1-up 2-right 3-down 4-left
glmove  tax
        stx $4e         ; store direction
        lda growinto,x  ; get check bit
        sta $4f         ; store check bit
        ldy $45         ; current xpos
        ldx $46         ; current ypos
        jsr cgloadcell  ; load the cell (and with #$1f)
        sta ($d1),y     ; store the data (clear the EBCM)
        lda #$00        ; Bottom "fall out" fix
        sta $50         ; clear and of cangrow  Bottom "fall out" fix
        lda $4e         ; load direction
        jsr cangrow     ; call cangrow to move xpos/ypos
        and $4f         ; check bit
        bne glmyes         ; if we have a bit then we can move!
        ldy $45         ; reload xpos - do not move
        ldx $46         ; reload ypos - do not move
glmyes  lda #$ff        ; bits to obtain from loadcell
        jsr loadcell    ; load the cell/point the zps
        pha             ; temp store value for later checks
        and #$1f        ; clear other EBCM bits 
        ora #$40        ; EBCM ORA Player/Baddy
        sta ($d1),y     ; store new data
        sty $45         ; store xpos of new position
        stx $46         ; store ypos of new position

        ;Hit checks
        pla             ; load previous value
        and #$c0        ; check for hits "11xxxxxx"
        ;Check for Key!
        cmp #$c0        ; check for key hit
        bne _notkey     ; to next check
        dec $51         ; dec number of keys left in level
        bne _notkey     ; if 0 then we should go to the next level 
        jmp init        ; gen maze again
        ;Check for Mintaur
_notkey = *
        cmp #$80        ; check for minitaur hit!
        bne _back 
        jmp gameover       ; game over
_back   jmp gameloop
        ;more checks here?

;?
keytodir=*
.byte 2,1,4,3


;Check if a cell can grow a direction
;1-up 2-right 3-down 4-left
; (y xpos, x ypos, a=dir)  x/y switched for indirect lda($xx),y below
; return: a == 0 : true (can move)
;         a <> 0 : false (can not move)
cangrow = *
    cmp #$01
    beq cgup
    cmp #$02
    beq cgright
    cmp #$03
    beq cgdown
    ;cmp #$04
    ;beq cgleft *** not needed falling through
cgleft = *
    dey         ;set xpos - 1
    cpy #$ff    ;check xpos
    beq cgno
    bne cgloadcell
cgright = *
    iny             ;set xpos + 1
    cpy #$28;$61    ;check xpos (<40)
    beq cgno
    bne cgloadcell
cgup = *
    dex        ;set ypos - 1
    cpx #$ff   ;check xpos
    beq cgno
    bne cgloadcell
cgdown = *
    inx        ;set ypos + 1
    cpx #$19;$62   ;check ypos (<25)
    beq cgno
    ;*** fallthrough, bne cgloadcell not needed
cgloadcell = *
    lda #$1f
loadcell = *        ;x = ypos, y = xpos, a = and value
    sta $50
    jsr $e9f0   ; sets $d1 $d2
    lda ($d1),y     ;load byte  (x pos in y reg!)
cgno = *
    and $50  ;#$1f = use only low 5 bits! (unless game engine)
    rts
growfrom = *-1
    .byte 1 
growinto = *  
    .byte 2, 4, 8, 1, 2
;explanation of above
;rts 1  2  4  8
;          4  8  1  2
;^0--^1-^2-^3-^4--------growfrom
;       ^0-^1-^2-^3-^4--growinto

;Notes:
;$E9F0:
; Set Pointer to Screen Address of Start of Line
; This subroutine puts the address of the first byte of the screen line
; designated by the .X register into locations 209-210 ($D1-$D2).
;
;Directions: (bits)
; 1 
;8 2
; 4 
;
;Pieces:
;*** * * *** * *
;*0* *1* *2  *3   @  A  B  C
;*** *** *** ***
;
;*** * * *** * *
;*4* *5* *6  *7   D  E  F  G
;* * * * * * * *
;
;*** * * *** * * 
; 8*  9*  a   b   H  I  J  K
;*** *** *** *** 
;
;*** * * *** * * 
; c*  d*  e   f   L  M  N  O
;* * * * * * * * 

; BDFHJLN
;A       A
;B       D
;C       E
;D       H
;E       I
;F       L
;G       M
; ABCHIJK

;Not used stuff

;Very Cool, this is in the c64 already!  no need to dupe it!
;ytablelo=$ecf0 ;table of ytable lo ;.byte $00, $28, $50, $78, $a0, $c8, $f0, $18, $40, $68, $90, $b8, $e0, $08, $30, $58, $80, $a8, $d0, $f8, $20, $48, $70, $98, $c0
;ytablehi=$00d9 ;table of ytable hi .byte $04, $04, $04, $04, $04, $04, $04, $05, $05, $05, $05, $05, $05, $06, $06, $06, $06, $06, $06, $06, $07, $07, $07, $07, $07

;Bad Guy x and y pos
;baddyx=$3000
;baddyy=$3100

;random key placement
;        ;Each level has 1 additional key
;_getx   jsr getrand
;        cmp #$28 ;get number less than 40
;        bpl _getx
;        tay
;_gety   jsr getrand
;        cmp #$19 ;get number less than 25
;        bpl _gety
;        tax
;        jsr cgloadcell  ; load the cell (and with #$1f)
;        ora #$c0        ; key EBCM Value
;        sta ($d1),y     ; store the data
;        dec $54         ; dec counter
;        bne _getx       ; need another key


;Get Random Number
;  return: .a = random number 0-255
;not a function because we're not using it anywhere else
;getrand = *
;        lda #$80
;     sta $028a; Ket Repeat; nothing to do with getrand - just using #$80 for smaller code
;        sta $d412 ;sta $d404   d412 is V3, d404 is V1!!
;        sta $d40f
;        lda $d41b
;        rts
		

All tinyrinth code, images, and such are copyright mark seelye - and may only be used with permission.