Page 1 of 3
Time for a contest? Simplest maze-like printing..
Posted: 08 Nov 2023, 17:17
by petersieg
I like simple code, that does (un)expected, but still interesting/nice things
From C64 (and probably a dozen more retro computer languages), exist a very nice writeup about a one line basic program, that basically just prints out a slash and a backslash randlomly and endless and therefore produces a maze like picture.
Links:
Homapage:
https://10print.org/
PDF:
https://10print.org/10_PRINT_121114.pdf (BY-NC-SA 3.0)
Video:
https://www.youtube.com/watch?v=B-Cky_2l11U
So I quickly wrote one in glcc (v0) and one that uses two colors (v1). (laby.zip)
(I switched to output < and >, because the(back)slash does not look that nice with Gigatron char set at the moment)
I also tried myself in gtbasic. (laby_gbas.zip)
I am sure, both can be optimized in size and probably also speed.
And one can do even 'better' in gcl, assembler - you name it.
And possible draw bitmaps/sprites instead of simple chars.
So, who is next?
Who can make the smallest gt1?
Who the most beautiful one?
Anyone, have fun if you like
best, Peter
Re: Time for a contest? Simplest maze-like printing..
Posted: 08 Nov 2023, 22:49
by lb3361
This one prints slashes/backslashes in 8x8 squares, avoiding the console and the default font.
Writing the same in GCL or GASM would probably cut the gt1 size by a factor of two or so.
Compile with
Code: Select all
glcc -map=32k -rom=v5a TSTmaze.c -o TSTmaze.gt1 --no-runtime-bss-initialization
- maze2.png (15.25 KiB) Viewed 3812 times
Code: Select all
#include <gigatron/sys.h>
#include <gigatron/console.h>
char * __near addr = 0;
void print_fslash(void)
{
int b;
for (b = 1; (char)b; b <<= 1, addr++)
SYS_VDrawBits(CONSOLE_DEFAULT_FGBG, b, addr);
}
void print_bslash(void)
{
int b;
char *p = addr + 8;
addr = p;
for (b = 1; (char)b; b <<= 1)
SYS_VDrawBits(CONSOLE_DEFAULT_FGBG, b, --p);
}
void scroll(void)
{
byte *p = videoTable;
byte x = *p;
addr = (char*)(x << 8);
for(; p != videoTable + 112 * 2; p += 2)
p[0] = p[16];
for(; p != videoTable + 120 * 2; p += 2, x++)
p[0] = x;
}
void main(void)
{
while(1) {
if (addr == 0) {
scroll();
_console_clear(addr, CONSOLE_DEFAULT_FGBG, 8);
}
if ((int) SYS_Random() < 0)
print_fslash();
else
print_bslash();
if ((char)(unsigned)addr == 160)
addr = 0;
}
}
Re: Time for a contest? Simplest maze-like printing..
Posted: 09 Nov 2023, 00:09
by lb3361
GCL version of the same. ROMv5a and above only because it uses opcode CALLI.
Only 188 bytes. I don't think GLCC will ever match this.
- maze.gcl
- (803 Bytes) Downloaded 249 times
- maze.gt1
- (188 Bytes) Downloaded 237 times
Code: Select all
gcl0x
160 addr=
[do
<addr, 160- [if=0 \scroll!]
\SYS_Random_34 _sysFn= 34!!
[if<0 \print_fslash! else \print_bslash!]
loop]
{ Print a forward slash }
[ _print_fslash=*
\SYS_VDrawBits_134 _sysFn=
$3f20 _sysArgs0=
1 [do b= addr _sysArgs4= 1+ addr= b \sysArgs2. 134!!
1<< \vACL, if<>0loop]
ret]
{ Print a backward slash }
[ _print_bslash=*
\SYS_VDrawBits_134 _sysFn=
$3f20 _sysArgs0=
addr 8+ addr= p=
1 [do b= p 1- p= _sysArgs4= b \sysArgs2. 134!!
1<< \vACL, if<>0loop]
ret]
{ Scroll and clear last line }
[ _scroll=*
\videoTable p= peek x= >addr. 0 <addr.
[do
p 16+ peek p. <p++ <p++
$1e0 p- if<>0loop]
\SYS_SetMemory_v2_54 _sysFn=
[do
x p. >_sysArgs2. 0 <_sysArgs2. $20a0 _sysArgs0= 54!!
<x++ <p++ <p++
$1f0 p- if<>0loop]
ret]
Re: Time for a contest? Simplest maze-like printing..
Posted: 09 Nov 2023, 10:10
by petersieg
VERY nice looking!
Will have a closer look..
Many thx.
Best, Peter
Re: Time for a contest? Simplest maze-like printing..
Posted: 11 Nov 2023, 11:41
by Phibrizzo
Hello
This is my contribution for the contest.
175 bytes.
- maze.gt1
- (175 Bytes) Downloaded 248 times
Pure vCPU v5 code.
Code: Select all
_CPU v5.vcpu
_VAR FC_Main #$20a0
_VAR FC_Slash #$21a0
_VAR FC_BSlash #$22a0
_VAR FC_Scroll #$23a0
_RUN FC_Main
; ---------------
_VAR adres #129
_VAR adresH #130
_ORG FC_Main
LDWI #$0B03 ; SetMemory
STW sysFn
LDI #60
ST sysArg1 ; copy value
_LAB #4
LDWI #$01df ; videoTable + $df
DEEK ; ugly byte swap
STW adres
_LAB #1
LD #$9
XORW #$6
ANDI #1
BNE #2
LDWI FC_Slash
BRA #3
_LAB #2
LDWI FC_BSlash
_LAB #3
CALL vAC
LD adres
XORI #160
BNE #1
LDWI FC_Scroll
CALL vAC
BRA #4
; ---------------
_ORG FC_Slash
LD adresH
ADDI #8
ST adresH
_LAB #1
LD adresH
SUBI #1
ST adresH
LDI #0
POKE adres
INC adres
LD adres
ANDI #7
BNE #1
RET
;----------------
_ORG FC_BSlash
_LAB #1
LDI #0
POKE adres
INC adresH
INC adres
LD adres
ANDI #7
BNE #1
LD adresH
SUBI #8
ST adresH
RET
;----------------
_VAR videoTable #$0100
_VAR source #131
_VAR destin #133
_VAR y #135
_VAR yH #136
_ORG FC_Scroll
LDWI videoTable
ST y ; ugly clear y
STW destin
ADDI #16
STW source
LDW destin
PEEK
ST yH
_LAB #1
LDW source
PEEK
POKE destin
INC source
INC source
INC destin
INC destin
LD destin
XORI #224
BNE #1
_LAB #2
LD yH
POKE destin
LDI #160
ST sysArg0 ; copy count
LDW y
STW sysArg2 ; dest adrr
SYS #54
INC yH
INC destin
INC destin
LD destin
XORI #240
BNE #2
RET
Re: Time for a contest? Simplest maze-like printing..
Posted: 11 Nov 2023, 12:23
by petersieg
Very nice job!
best, Peter
Re: Time for a contest? Simplest maze-like printing..
Posted: 11 Nov 2023, 15:52
by lb3361
Lots of neat tricks in Phibrizzo's code.
Re: Time for a contest? Simplest maze-like printing..
Posted: 11 Nov 2023, 18:13
by lb3361
A different effect, without scroll, 88 bytes.
Code: Select all
gcl0x
$78f8 mask=
[do
\SYS_Random_34 _sysFn=
[do [do 34!! mask& _sysArgs4= \sysArgs4, 160- if>=0loop] \sysArgs5, 8- if<0loop ]
1 x= 34!! [if<0 -1 x= _sysArgs4 7+ _sysArgs4=]
\SYS_VDrawBits_134 _sysFn= $3f00 _sysArgs0=
1 [do \sysArgs2. 1<< b= 134!! _sysArgs4 x+ _sysArgs4= <b, if<>0loop]
loop]
Re: Time for a contest? Simplest maze-like printing..
Posted: 12 Nov 2023, 14:22
by petersieg
Very nice and SMALL too!
Thx, Peter
Re: Time for a contest? Simplest maze-like printing..
Posted: 12 Nov 2023, 20:20
by Phibrizzo
lb3361 wrote: ↑11 Nov 2023, 18:13
A different effect, without scroll, 88 bytes.
I tried to make an effect like yours.
It is shorter but less effective.
Code: Select all
_CPU v5.vcpu
_VAR FC_Main #$20A0
_RUN FC_Main
; -----------------------
_VAR line #129
_VAR sign #131
_ORG FC_Main
LDWI #$04E1 ; VDrawBits
STW sysFn
LDWI #$3F00 ; Colors
STW sysArg0
; -- Random position ---
_LAB #1
LD #$8
ANDI #%11111000
ST sysArg4 ; X
SUBI #160
BGE #1
_LAB #2
LD #$7
ANDI #%01111000
BEQ #2
ST sysArg5 ; Y
; -- Change direction --
LDI #1
ST line
STW sign
LDW #$6
BLE #3
LDI #-1
ST sign
LD sysArg4
ADDI #7
ST sysArg4
; ------ Draw loop ------
_LAB #3
LD line
BEQ #1
ST sysArg2
SYS #134
LD sysArg4
ADDW sign
ST sysArg4
LD line
LSLW
ST line
BRA #3