Skip to content

Commit

Permalink
Unroll to 8 pixels = 1 word source.
Browse files Browse the repository at this point in the history
Each pixel uses 4 random bits from 32-bit seed.
Remove vsync for single buffer.
  • Loading branch information
kieranhj committed Feb 14, 2020
1 parent a61b0e0 commit c23c9c4
Showing 1 changed file with 89 additions and 22 deletions.
111 changes: 89 additions & 22 deletions doom-fire.asm
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -515,63 +515,130 @@ 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

.1:
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

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)
Expand Down

0 comments on commit c23c9c4

Please sign in to comment.