From 8fea33ceef5285190cd2dec3fc8825361b411c61 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Sedat=20Kapano=C4=9Flu?= Date: Tue, 2 May 2023 13:39:32 -0700 Subject: [PATCH] use firmware calls for RND --- README.md | 40 ++++++++++++++++++++++++---------------- maze.asm | 45 +++++++++++++++++++++++++++------------------ maze.bin | 1 - maze.dsk | Bin 194816 -> 194816 bytes winape.asm | 2 +- 5 files changed, 52 insertions(+), 36 deletions(-) diff --git a/README.md b/README.md index 87a66d7..240e7ad 100644 --- a/README.md +++ b/README.md @@ -1,16 +1,24 @@ -# mazecpc 1.1 -Maze CPC is a maze generator in 14 bytes for Amstrad CPC series 8-bit computers. - -![screen shot](https://raw.githubusercontent.com/ssg/mazecpc/master/screenshot.png) - -# history -There is a book called "[10 PRINT CHR$ (205.5 + RND (1)); : GOTO 10](http://10print.org/)". Yes that's the title. It's about a small code piece in BASIC language that generates a maze. An interesting read for programmers. It delves into attempts to create it in assembly as small as possible, which [seems to have become a trend](http://csdb.dk/release/?id=113300) in Commodore 64 demoscene. - -Recently I saw [a blog post from Trixter](http://trixter.oldskool.org/2012/12/17/maze-generation-in-thirteen-bytes/) who tried to port it to PC. It eventually got down to 10 bytes. - -Tonight I wanted to give it a shot on Amstrad CPC and here it is, 11 bytes14-bytes maze generator, created in couple of hours. - -# technical notes -I found it very hard to produce a series of "random bits" on a Z80 CPU. There is R register which increases every cycle but naturally deterministic in loops. To keep the code short, however, I relied on it and interrupts to introduce a slight entropy. I'm sure there is room for improvement. Update Dec 29th, 2018: I made the random generator much better by sacrificing 3 more bytes. It's a 14-byte maze generator now. - -SSG / arteffect, March 24th 2015 +# mazecpc 1.2 + +Maze CPC is a maze generator in 12 bytes for Amstrad CPC664/6128 8-bit computers. + +![screen shot](https://raw.githubusercontent.com/ssg/mazecpc/master/screenshot.png) + +# history + +There is a book called "[10 PRINT CHR$ (205.5 + RND (1)); : GOTO 10](http://10print.org/)". Yes that's the title. It's about a small code piece in BASIC language that generates a maze. An interesting read for programmers. It delves into attempts to create it in assembly as small as possible, which [seems to have become a trend](http://csdb.dk/release/?id=113300) in Commodore 64 demoscene. + +I saw [a blog post from Trixter](http://trixter.oldskool.org/2012/12/17/maze-generation-in-thirteen-bytes/) who tried to port it to PC. It eventually got down to 10 bytes. + +Tonight I wanted to give it a shot on Amstrad CPC and here it is, 11 14 12-bytes maze generator, created in a couple of hours. + +# technical notes + +I found it very hard to produce a series of "random bits" on a Z80 CPU. There is R register which increases every cycle but naturally deterministic in loops. To keep the code short, however, I relied on it and interrupts to introduce a slight entropy. I'm sure there is room for improvement. + +_Update Dec 29th, 2018: I made the random generator much better by sacrificing 3 more bytes. It's a 14-byte maze generator now._ + +_Update May 2nd, 2023: I resorted to using firmware call for RND to get the random number, +saving another 2 bytes. But, the code doesn't run on CPC464 now due to missing firmware call. The 14-byte CPC464 version still exists in `maze464.asm`_ + +SSG / arteffect, March 24th 2015 diff --git a/maze.asm b/maze.asm index a67ce31..66aae21 100644 --- a/maze.asm +++ b/maze.asm @@ -1,18 +1,27 @@ -org &4000 -write direct "maze.bin" - -CHAR equ &cc -TXT_WR_CHAR equ &bb5d - -run $ - -.loop: - ld a, r - rrca - rrca - rrca - and 1 - or CHAR - call TXT_WR_CHAR - jr loop - +; This is the 12-byte CPC664/CPC6128 version. + +org &4000 +write "maze.bin" +write direct "maze.bin" + +CHAR equ &CC +TXT_WR_CHAR equ &BB5D +REAL_RND equ &BD7F ; CPC464 doesn't have this endpoint. + +run $ +loop: + ; REAL_RND call normally works on the memory at HL register + ; we ignore that and use the destroyed A value because somehow + ; it also varies quite randomly, saving us 2 bytes in the end. + ; This trick causes RND to output junk pixels to the scroll + ; position due to HL value destroyed by TXT_WR_CHAR, but it + ; gets painted over anyway. + call REAL_RND + and 1 + or CHAR + call TXT_WR_CHAR + jr loop + +result: + +close \ No newline at end of file diff --git a/maze.bin b/maze.bin index 3ae187d..e69de29 100644 --- a/maze.bin +++ b/maze.bin @@ -1 +0,0 @@ -í_æöÌÍ]»ò \ No newline at end of file diff --git a/maze.dsk b/maze.dsk index 4c650c60347c5210525e5172ff4d5b3609c22bca..3974f6b076c1d02719f56399691bb310118b7cf7 100644 GIT binary patch delta 55 zcmZqp#NF_TdxL}!3l9T>!^A`tRv@jwJTcLl?`-|vXN=#@oQ>Tr@kQd(W=EzX#wL+A K5yoXAOiuv`pA(V* delta 27 jcmZqp#NF_TdxM0~WC@P4&5le(j7=hKB8 diff --git a/winape.asm b/winape.asm index b52dba2..f929c03 100644 --- a/winape.asm +++ b/winape.asm @@ -1,2 +1,2 @@ -; this is to avoid using winape's own editor +; this is to avoid using winape's own editor read "maze.asm" \ No newline at end of file