Skip to content

Commit fd57c48

Browse files
committed
start double-buffering
Amazing how much difference it makes even when the implementation is so naive and slow.
1 parent 2952a29 commit fd57c48

File tree

3 files changed

+48
-8
lines changed

3 files changed

+48
-8
lines changed

313index-bounds-check.subx

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -33,9 +33,7 @@ __check-mu-array-bounds: # index: int, elem-size: int, arr-size: int, function-
3333
(draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 " is too large for array '" 3 0) # 3=cyan
3434
(draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 *(ebp+0x18) 3 0) # 3=cyan
3535
(draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "'" 3 0) # 3=cyan
36-
{
37-
eb/jump loop/disp8
38-
}
36+
(abort "")
3937
# never gets here
4038
$__check-mu-array-bounds:end:
4139
# . restore registers
@@ -53,9 +51,7 @@ __check-mu-array-bounds:overflow:
5351
(draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 ": offset to array '" 3 0) # 3=cyan
5452
(draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 *(ebp+0x18) 3 0) # 3=cyan
5553
(draw-text-wrapping-right-then-down-from-cursor-over-full-screen 0 "' overflowed 32 bits" 3 0) # 3=cyan
56-
{
57-
eb/jump loop/disp8
58-
}
54+
(abort "")
5955
# never gets here
6056

6157
__mu-abort-null-index-base-address:

500fake-screen.mu

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -516,3 +516,42 @@ fn pixel-index _screen: (addr screen), x: int, y: int -> _/ecx: int {
516516
result <- add x
517517
return result
518518
}
519+
520+
# double-buffering primitive
521+
# 'screen' must be a fake screen. 'target-screen' is usually real.
522+
# Both screens must have the same size.
523+
fn copy-pixels _screen: (addr screen), target-screen: (addr screen) {
524+
var screen/esi: (addr screen) <- copy _screen
525+
var pixels-ah/eax: (addr handle array byte) <- get screen, pixels
526+
var _pixels/eax: (addr array byte) <- lookup *pixels-ah
527+
var pixels/edi: (addr array byte) <- copy _pixels
528+
var width-a/edx: (addr int) <- get screen, width
529+
var width/edx: int <- copy *width-a
530+
width <- shift-left 3/log2-font-width
531+
var height-a/ebx: (addr int) <- get screen, height
532+
var height/ebx: int <- copy *height-a
533+
height <- shift-left 4/log2-font-height
534+
var i/esi: int <- copy 0
535+
var y/ecx: int <- copy 0
536+
{
537+
# screen top left pixels x y width height
538+
compare y, height
539+
break-if->=
540+
var x/eax: int <- copy 0
541+
{
542+
compare x, width
543+
break-if->=
544+
{
545+
var color-addr/ebx: (addr byte) <- index pixels, i
546+
var color/ebx: byte <- copy-byte *color-addr
547+
var color2/ebx: int <- copy color
548+
pixel target-screen, x, y, color2
549+
}
550+
x <- increment
551+
i <- increment
552+
loop
553+
}
554+
y <- increment
555+
loop
556+
}
557+
}

hest-life.mu

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,20 @@ fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk)
1616
var env-storage: environment
1717
var env/esi: (addr environment) <- address env-storage
1818
initialize-environment env
19-
render screen, env
19+
var second-buffer: screen
20+
var second-screen/edi: (addr screen) <- address second-buffer
21+
initialize-screen second-screen, 0x80, 0x30, 1/include-pixels
22+
render second-screen, env
23+
copy-pixels second-screen, screen
2024
{
2125
edit keyboard, env
2226
var play?/eax: (addr boolean) <- get env, play?
2327
compare *play?, 0/false
2428
{
2529
break-if-=
2630
step env
27-
render screen, env
31+
render second-screen, env
32+
copy-pixels second-screen, screen
2833
}
2934
linger env
3035
loop

0 commit comments

Comments
 (0)