diff --git a/doom-fire.asm b/doom-fire.asm index 8e404ee..71f7849 100644 --- a/doom-fire.asm +++ b/doom-fire.asm @@ -146,7 +146,7 @@ main_loop: swi OS_Byte ; Wait for vsync if double buffering - .if Screen_Banks <= 2 + .if Screen_Banks == 2 mov r0, #OSByte_Vsync swi OS_Byte .endif @@ -472,15 +472,15 @@ plot_horizontal_line: .endm .macro DO_RANDOM_BIT - ; update colour with some randomness - and r7, r8, #1 ; rnd & 1 - subs r4, r4, r7 ; colour -= rnd & 1 - ; randomise destination a bit - and r7, r8, #3 + and r7, r7, #3 add r0, r2, r7 subs r0, r0, #1 ; dest_x += (rnd & 3)-1 movlt r0, #0 ; or MOD ScreenWidth + + ; update colour with some randomness + and r7, r7, #1 ; rnd & 1 + subs r4, r4, r7 ; colour -= rnd & 1 .endm .macro PLOT_PIXEL_BIT @@ -515,11 +515,17 @@ do_fire: ldr r8, rnd_seed ; seed mov r9, #1 ; bit - mov r3, #Screen_Height - 64 + mov r3, #Screen_Height - 48 ; R10 = ptr to start of source line add r10, r12, r3, lsl #7 ; r10 = screen_addr + y * 128 add r10, r10, r3, lsl #5 ; r10 += y * 32 = y * 160 + + ; R3 = ptr to end of screen + mov r2, #Screen_Height - 1 + add r3, r12, r2, lsl #7 ; r10 = screen_addr + y * 128 + add r3, r3, r2, lsl #5 ; r10 += y * 32 = y * 160 + ; R12 = ptr to start of dest line sub r12, r10, #Screen_Stride @@ -527,43 +533,104 @@ do_fire: mov r2, #0 .2: - ; source is contiguous - ; could read a source word at a time - ; unroll 8x - ; spread fire + RND - ; read source byte - ldrb r5, [r10], #1 ; load screen byte + ; source is contiguous + ; read source word = 8x pixels + ldr r5, [r10], #4 - ; Left pixel + ; Byte 0 Left pixel ands r4, r5, #0x0F moveq r0, r2 beq .3 - RND DO_RANDOM_BIT .3: PLOT_PIXEL_BIT add r2, r2, #1 - ; Right pixel - movs r4, r5, lsr #4 ; mask out left hand pixel + ; Byte 0 Right pixel + mov r4, r5, lsr #4 + ands r4, r4, #0x0F moveq r0, r2 beq .4 - RND + mov r7, r8, lsr #4 DO_RANDOM_BIT .4: PLOT_PIXEL_BIT add r2, r2, #1 + ; Byte 1 Left pixel + mov r4, r5, lsr #8 + ands r4, r4, #0x0F + moveq r0, r2 + beq .5 + mov r7, r8, lsr #8 + DO_RANDOM_BIT + .5: + PLOT_PIXEL_BIT + add r2, r2, #1 + + ; Byte 1 Right pixel + mov r4, r5, lsr #12 + ands r4, r4, #0x0F + moveq r0, r2 + beq .6 + mov r7, r8, lsr #12 + DO_RANDOM_BIT + .6: + PLOT_PIXEL_BIT + add r2, r2, #1 + + ; Byte 2 Left pixel + mov r4, r5, lsr #16 + ands r4, r4, #0x0F + moveq r0, r2 + beq .7 + mov r7, r8, lsr #16 + DO_RANDOM_BIT + .7: + PLOT_PIXEL_BIT + add r2, r2, #1 + + ; Byte 2 Right pixel + mov r4, r5, lsr #20 + ands r4, r4, #0x0F + moveq r0, r2 + beq .8 + mov r7, r8, lsr #20 + DO_RANDOM_BIT + .8: + PLOT_PIXEL_BIT + add r2, r2, #1 + + ; Byte 3 Left pixel + mov r4, r5, lsr #24 + ands r4, r4, #0x0F + moveq r0, r2 + beq .9 + mov r7, r8, lsr #24 + DO_RANDOM_BIT + .9: + PLOT_PIXEL_BIT + add r2, r2, #1 + + ; Byte 2 Right pixel + movs r4, r5, lsr #28 + moveq r0, r2 + beq .10 + mov r7, r8, lsr #28 + DO_RANDOM_BIT + .10: + PLOT_PIXEL_BIT + add r2, r2, #1 + cmp r2, #Screen_Width blt .2 ; Next line add r12, r12, #Screen_Stride - - add r3, r3, #1 ; could omit this and cmp end of screen buffer instead - cmp r3, #Screen_Height + cmp r12, r3 blt .1 str r8, rnd_seed @@ -571,7 +638,7 @@ do_fire: ldr pc, [sp], #4 rnd_seed: - .long 0x12345678 + .long 0x87654321 rnd: ; enter with seed in R0 (32 bits), R1 (1 bit in least significant bit)