working box drawing example
This commit is contained in:
parent
807d5b8705
commit
d6893b85a8
|
@ -1,20 +1,67 @@
|
|||
((code
|
||||
(label main
|
||||
; Open screen
|
||||
(load-immediate $0 &screen-namespace)
|
||||
(load-immediate $1 0)
|
||||
(syscall DEVICE-OPEN $0 $1)
|
||||
|
||||
(load-immediate $3 0xE0)
|
||||
(load-immediate $4 36)
|
||||
; Draw red box at (10, 20)
|
||||
(load-immediate $1 0xE0) ; color
|
||||
(push $1)
|
||||
(load-immediate $1 10) ; x
|
||||
(push $1)
|
||||
(load-immediate $1 20) ; y
|
||||
(push $1)
|
||||
(call &draw-box)
|
||||
|
||||
(load-immediate $1 1)
|
||||
(load-immediate $5 50)
|
||||
(label loop-x
|
||||
(store-8 $4 $3)
|
||||
(add-int $4 $4 $1)
|
||||
(jump-lt-int &loop-x $4 $5))
|
||||
; Draw green box at (10, 40)
|
||||
(load-immediate $1 0x1C) ; RGB332 green (00011100)
|
||||
(push $1)
|
||||
(load-immediate $1 10)
|
||||
(push $1)
|
||||
(load-immediate $1 40)
|
||||
(push $1)
|
||||
(call &draw-box)
|
||||
|
||||
; Flush and halt
|
||||
(syscall DEVICE-WRITE $0 $0 $0)
|
||||
(halt)))
|
||||
(halt))
|
||||
|
||||
; draw-box(color, x, y)
|
||||
; Pops: y, x, color
|
||||
(label draw-box
|
||||
; Pop arguments (reverse order)
|
||||
(pop $13) ; y_start
|
||||
(pop $11) ; x_start
|
||||
(pop $3) ; color
|
||||
|
||||
; Constants
|
||||
(load-immediate $1 1) ; increment
|
||||
(load-immediate $2 640) ; row stride
|
||||
(load-immediate $10 36) ; framebuffer base
|
||||
(load-immediate $12 20) ; width
|
||||
(load-immediate $14 20) ; height
|
||||
|
||||
; Compute start address: base + y*640 + x
|
||||
(mul-int $15 $13 $2) ; $15 = y * 640
|
||||
(add-int $15 $15 $11) ; $15 += x
|
||||
(add-int $4 $10 $15) ; $4 = base + offset
|
||||
|
||||
; Outer loop: height times
|
||||
(register-move $5 $14) ; $5 = row counter
|
||||
|
||||
(label draw-box-outer
|
||||
(add-int $6 $4 $12) ; $6 = row end = current + width
|
||||
(register-move $7 $4) ; $7 = pixel pointer
|
||||
|
||||
(label draw-box-inner
|
||||
(store-8 $7 $3) ; write color
|
||||
(add-int $7 $7 $1) ; next pixel
|
||||
(jump-lt-int &draw-box-inner $7 $6))
|
||||
|
||||
(add-int $4 $4 $2) ; next row (+= 640)
|
||||
(sub-int $5 $5 $1) ; decrement row count
|
||||
(jump-gt-int &draw-box-outer $5 0))
|
||||
(return)))
|
||||
(data
|
||||
(label screen-namespace "/dev/screen/0")))
|
||||
|
|
Loading…
Reference in New Issue