A machine language version of my Truchet tile graphic demo.
; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ; ; Truchet Tiles ML ; Steven Reid (c) 2025 ; An ML version of my truchet tiles demo. ; v1 07/17/2025 - initial build ; ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ; ; Header and startup ; ; start up stuff ORG 16514 ; stored in REM at top (ZX81) jr start ; needed for z80asm ; title and copyright (will show when LISTed) copy: DB _as,_t_,_r_,_u_,_c_,_h_,_e_,_t_,_mi,_m_ DB _l_,_as,_s_,_l_,_r_,_sl,_2_,_0_,_2_,_5_ DB _as,$76 ; **AAAAAAA**SLR/2025** ; starting routines (if any) start: ; call slow ; SLOW is required. ; call cls ; clear/expand screen ; ; end header and startup ; ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ; ; Main program ; mainloop: ld de,(d_file) ; grab display file inc de ; add one ld b,12 ; height x 2 y_loop: ld c,16 ; width x 2 x_loop: push bc ; save loop call print_a_tile pop bc ; restore loop call delay ; done with x? dec c jp nz,x_loop push bc ld bc,34 ; jump ahead ex de,hl add hl,bc ; to next row ex de,hl pop bc ; de at start of next row ; done with y? djnz y_loop jp mainloop ; start again! ; ; end main ; ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ; ; Routines ; ; +++ ; Print a tile print_a_tile: ; get tile ld hl,tile_1 ; set to 1st tile data call rnd ; get which tile cp 127 ; compare to 50% jp m, print_tile ; print first tile ld hl,tile_2 ; set to 2nd tile data print_tile: ; de = points to display file ; hl = points to tile pattern ld bc,33 ; next row ; print 1st row ldi ; print 1st char ldi ; print 2nd char push de ; save display location ex de,hl add hl,bc ; to print tile ex de,hl ; print 2nd row ldi ; print 1st char ldi ; print 2nd char pop de ; restore location ret ; end print tile ; --- ; +++ ; Break ; ; preserves state, but will exit if SPACE is pushed check_break: exx ; save register states ; did the player press break key (space)? call $0f46 ; was break pressed? (break-1 ROM routine) jr nc,break ; no, then return exx ; restore registers ret ; and return ; yes, exit the program as normal break: rst $0008 ; call ERROR-1 reset DB $ff ; with error code 0 (normal exit) ; end break ; --- ; +++ ; Delay and test ; ; Will break out of program if SPACE is pressed ; Will end early if a key is pressed ; vars: d = delay ; uses: ac,hl ; keeps: hl,de,bc ; returns: none delay_count: DW $0000 delay: push hl ld hl,100 ; time to delay delay_loop: ld (delay_count),hl ; save delay call check_break ; pressed break? ; check if done ld hl,(delay_count) ; grab what to test dec hl ; subtract 1 ld a,h ; check if done or l jr nz,delay_loop ; not zero, keep going! pop hl ret ; pause is done! ; end delay and test ; --- ; +++ ; Random number ; ; vars: none ; uses: a ; keeps: hl,de,bc ; returns: a rnd: ; random routine with refresh push hl ; save hl seed: ld hl,0 ; seed value ld a,r ; grab the refresh register add a,l ; add msb of seed (l) ld l,a ; and save it as the new value ld a,r ; grab the refresh register again add a,h ; add lsb of seed (h) and $1f ; mask it to stay in ZX81 ROM (lower 8K) ld h,a ; set pointer back within ROM ld (seed+1),hl ; save current pointer (self modifying code!!!) ld a,(hl) ; get value in ROM pop hl ; restore hl ret ; back to mainprogram ; end rnd ; --- ; ; end routines ; ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ; ; Data ; ; Truchet tiles patterns tile_1: DB $06,$00,$00,$06 tile_2: DB $00,$86,$86,$00 ; ; end data ; ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * ; ; Defines ; ; ZX81 system vars d_file: EQU $400c df_cc: EQU 16398 last_k: EQU 16421 margin: EQU 16424 s_posn: EQU 16441 frames: EQU 16436 ; ZX81 ROM functions kscan: EQU $02bb findchar: EQU $07bd stop: EQU $0cdc slow: EQU $0f2b fast: EQU $02e7 save: EQU $02f9 printat: EQU $08f5 pause: EQU $0f35 cls: EQU $0a2a ; ZX81 Characters (not ASCII) _sp: EQU $00 _qu: EQU $0b _lb: EQU $0c _dl: EQU $0d _cl: EQU $0e _lp: EQU $10 _rp: EQU $11 _gt: EQU $12 _lt: EQU $13 _eq: EQU $14 _pl: EQU $15 _mi: EQU $16 _as: EQU $17 _sl: EQU $18 _sc: EQU $19 _cm: EQU $1a _pr: EQU $1b _0_: EQU $1c _1_: EQU $1d _2_: EQU $1e _3_: EQU $1f _4_: EQU $20 _5_: EQU $21 _6_: EQU $22 _7_: EQU $23 _8_: EQU $24 _9_: EQU $25 _a_: EQU $26 _b_: EQU $27 _c_: EQU $28 _d_: EQU $29 _e_: EQU $2a _f_: EQU $2b _g_: EQU $2c _h_: EQU $2d _i_: EQU $2e _j_: EQU $2f _k_: EQU $30 _l_: EQU $31 _m_: EQU $32 _n_: EQU $33 _o_: EQU $34 _p_: EQU $35 _q_: EQU $36 _r_: EQU $37 _s_: EQU $38 _t_: EQU $39 _u_: EQU $3a _v_: EQU $3b _w_: EQU $3c _x_: EQU $3d _y_: EQU $3e _z_: EQU $3f ; ; end defines ; ; * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *