MAZE.SRC (2540B)
1 OPTION BINARY ; We want a binary file, not an HP48 one. 2 ALIGN OFF ; And we don't want auto alignement, as some 3 ; data can be made of bytes instead of words. 4 5 6 ; Drawing a random maze like this one consists in drawing random diagonal 7 ; lines. There are two possibilities: right-to-left line, and left-to-right 8 ; line. Each line is composed of a 4*4 bitmap. As the lines must form non- 9 ; circular angles, the two bitmaps won't be '/' and '\'. The first one 10 ; (right line) will be a little bit modified. See at the end of this source. 11 ; 12 ; The maze is composed of 8 lines (as the bitmaps are 4 pixels high), each 13 ; line consists of 16 bitmaps. 14 ; Bitmaps are drawn in random mode. We choose a random value (0 or 1). 15 ; If it is 1, we draw a left line bitmap. If it is 0, we draw a right one. 16 17 18 ; Rsgister usage: 19 ; 20 ; V0: X-coordinate of the bitmap 21 ; V1: Y-coordinate of the bitmap 22 ; V2: Random number 23 24 LD V0, 0 25 LD V1, 0 26 27 LOOP: 28 LD I, LEFT ; We draw a left line by default, as the random number 29 ; is 0 or 1. If we suppose that it will be 1, we keep 30 ; drawing the left line. If it is 0, we change register 31 ; I to draw a right line. 32 33 RND V2, 1 ; Load in V2 a 0...1 random number 34 35 SE V2, 1 ; It is 1 ? If yes, I still refers to the left line 36 ; bitmap. 37 38 LD I, RIGHT ; If not, we change I to make it refer the right line 39 ; bitmap. 40 41 DRW V0, V1, 4 ; And we draw the bitmap at V0, V1. 42 43 ADD V0, 4 ; The next bitmap is 4 pixels right. So we update 44 ; V0 to do so. 45 46 SE V0, 64 ; If V0==64, we finished drawing a complete line, so we 47 ; skip the jump to LOOP, as we have to update V1 too. 48 49 JP LOOP ; We did not draw a complete line ? So we continue ! 50 51 LD V0, 0 ; The first bitmap of each line is located 0, V1. 52 53 ADD V1, 4 ; We update V1. The next line is located 4 pixels doan. 54 55 SE V1, 32 ; Have we drawn all the lines ? If yes, V1==32. 56 JP LOOP ; No ? So we continue ! 57 58 FIN: JP FIN ; Infinite loop... 59 60 RIGHT: ; 4*4 bitmap of the left line 61 62 DB $1....... 63 DB $.1...... 64 DB $..1..... 65 DB $...1.... 66 67 LEFT: ; 4*4 bitmap of the right line 68 ; And YES, it is like that... 69 DB $..1..... 70 DB $.1...... 71 DB $1....... 72 DB $...1....