2021-01-16 04:30:07 +00:00
|
|
|
# Use the built-in font to draw a grapheme to real screen.
|
|
|
|
#
|
|
|
|
# We need to do this in machine code because Mu doesn't have global variables
|
2021-04-01 04:17:20 +00:00
|
|
|
# yet (for the start of the font).
|
2021-01-23 00:44:23 +00:00
|
|
|
#
|
|
|
|
# There are uncomfortable assumptions baked in here about english/latin
|
|
|
|
# script. We convert the grid of pixels into a fixed-width grid of graphemes,
|
|
|
|
# which may not work well with other language families.
|
2021-01-14 05:41:45 +00:00
|
|
|
|
|
|
|
== code
|
|
|
|
|
2021-01-23 00:44:23 +00:00
|
|
|
# The Mu computer's screen is 1024px wide and 768px tall.
|
|
|
|
# The Mu computer's font is 8px wide and 16px tall.
|
|
|
|
# Therefore 'x' here is in [0, 128), and 'y' is in [0, 48)
|
2021-02-06 04:35:23 +00:00
|
|
|
# Doesn't update the cursor; where the cursor should go after printing the
|
|
|
|
# current grapheme is a higher-level concern.
|
2021-01-20 06:17:05 +00:00
|
|
|
draw-grapheme-on-real-screen: # g: grapheme, x: int, y: int, color: int, background-color: int
|
2021-01-10 01:04:21 +00:00
|
|
|
# . prologue
|
|
|
|
55/push-ebp
|
|
|
|
89/<- %ebp 4/r32/esp
|
|
|
|
# . save registers
|
|
|
|
50/push-eax
|
|
|
|
51/push-ecx
|
|
|
|
52/push-edx
|
|
|
|
53/push-ebx
|
|
|
|
56/push-esi
|
2021-06-13 04:43:33 +00:00
|
|
|
# esi = g
|
2021-06-13 04:41:50 +00:00
|
|
|
8b/-> *(ebp+8) 6/r32/esi
|
2021-06-13 04:43:33 +00:00
|
|
|
# if (g >= 128) return # characters beyond ASCII currently not supported
|
|
|
|
81 7/subop/compare %esi 0x80/imm32
|
|
|
|
7d/jump-if->= $draw-grapheme-on-real-screen:end/disp8
|
|
|
|
# var letter-bitmap/esi = font[g]
|
2021-01-10 01:04:21 +00:00
|
|
|
c1 4/subop/shift-left %esi 4/imm8
|
2021-03-16 03:32:26 +00:00
|
|
|
81 0/subop/add %esi Font/imm32
|
2021-01-23 00:44:23 +00:00
|
|
|
# var ycurr/edx: int = y*16
|
2021-06-13 04:41:50 +00:00
|
|
|
8b/-> *(ebp+0x10) 2/r32/edx
|
2021-01-23 00:44:23 +00:00
|
|
|
c1 4/subop/shift-left %edx 4/imm8
|
|
|
|
# var ymax/ebx: int = ycurr + 16
|
2021-06-13 04:41:50 +00:00
|
|
|
8b/-> *(ebp+0x10) 3/r32/ebx
|
2021-01-23 00:44:23 +00:00
|
|
|
c1 4/subop/shift-left %ebx 4/imm8
|
2021-01-10 01:04:21 +00:00
|
|
|
81 0/subop/add %ebx 0x10/imm32
|
|
|
|
{
|
2021-01-23 00:44:23 +00:00
|
|
|
# if (ycurr >= ymax) break
|
2021-01-10 01:04:21 +00:00
|
|
|
39/compare %edx 3/r32/ebx
|
|
|
|
7d/jump-if->= break/disp8
|
2021-01-23 00:44:23 +00:00
|
|
|
# var xcurr/eax: int = x*8 + 7
|
2021-06-13 04:41:50 +00:00
|
|
|
8b/-> *(ebp+0xc) 0/r32/eax # font-width - 1
|
2021-01-23 00:44:23 +00:00
|
|
|
c1 4/subop/shift-left %eax 3/imm8
|
2021-05-15 06:12:31 +00:00
|
|
|
05/add-to-eax 7/imm32
|
2021-01-23 00:44:23 +00:00
|
|
|
# var xmin/ecx: int = x*8
|
2021-06-13 04:41:50 +00:00
|
|
|
8b/-> *(ebp+0xc) 1/r32/ecx
|
2021-01-23 00:44:23 +00:00
|
|
|
c1 4/subop/shift-left %ecx 3/imm8
|
2021-01-10 01:04:21 +00:00
|
|
|
# var row-bitmap/ebx: int = *letter-bitmap
|
|
|
|
53/push-ebx
|
|
|
|
8b/-> *esi 3/r32/ebx
|
|
|
|
{
|
2021-01-23 00:44:23 +00:00
|
|
|
# if (xcurr < xmin) break
|
2021-01-10 01:04:21 +00:00
|
|
|
39/compare %eax 1/r32/ecx
|
|
|
|
7c/jump-if-< break/disp8
|
|
|
|
# shift LSB from row-bitmap into carry flag (CF)
|
|
|
|
c1 5/subop/shift-right-logical %ebx 1/imm8
|
2021-01-20 06:17:05 +00:00
|
|
|
# if LSB, draw a pixel in the given color
|
2021-01-10 01:04:21 +00:00
|
|
|
{
|
|
|
|
73/jump-if-not-CF break/disp8
|
2021-06-13 04:41:50 +00:00
|
|
|
(pixel-on-real-screen %eax %edx *(ebp+0x14))
|
|
|
|
eb/jump $draw-grapheme-on-real-screen:continue/disp8
|
2021-01-10 01:04:21 +00:00
|
|
|
}
|
2021-01-20 06:17:05 +00:00
|
|
|
# otherwise use the background color
|
2021-06-13 04:41:50 +00:00
|
|
|
(pixel-on-real-screen %eax %edx *(ebp+0x18))
|
|
|
|
$draw-grapheme-on-real-screen:continue:
|
2021-01-10 01:04:21 +00:00
|
|
|
# --x
|
|
|
|
48/decrement-eax
|
|
|
|
#
|
|
|
|
eb/jump loop/disp8
|
|
|
|
}
|
|
|
|
# reclaim row-bitmap
|
|
|
|
5b/pop-to-ebx
|
|
|
|
# ++y
|
|
|
|
42/increment-edx
|
|
|
|
# next bitmap row
|
|
|
|
46/increment-esi
|
|
|
|
#
|
|
|
|
eb/jump loop/disp8
|
|
|
|
}
|
2021-06-13 04:41:50 +00:00
|
|
|
$draw-grapheme-on-real-screen:end:
|
2021-01-10 01:04:21 +00:00
|
|
|
# . restore registers
|
|
|
|
5e/pop-to-esi
|
|
|
|
5b/pop-to-ebx
|
|
|
|
5a/pop-to-edx
|
|
|
|
59/pop-to-ecx
|
|
|
|
58/pop-to-eax
|
|
|
|
# . epilogue
|
|
|
|
89/<- %esp 5/r32/ebp
|
|
|
|
5d/pop-to-ebp
|
|
|
|
c3/return
|
2021-01-13 07:52:24 +00:00
|
|
|
|
2021-01-16 04:30:07 +00:00
|
|
|
cursor-position-on-real-screen: # -> _/eax: int, _/ecx: int
|
2021-01-13 07:52:24 +00:00
|
|
|
# . prologue
|
|
|
|
55/push-ebp
|
|
|
|
89/<- %ebp 4/r32/esp
|
|
|
|
# TODO: support fake screen; we currently assume 'screen' is always 0 (real)
|
2021-01-23 03:57:33 +00:00
|
|
|
8b/-> *Real-screen-cursor-x 0/r32/eax
|
|
|
|
8b/-> *Real-screen-cursor-y 1/r32/ecx
|
2021-01-17 23:52:22 +00:00
|
|
|
$cursor-position-on-real-screen:end:
|
2021-01-13 07:52:24 +00:00
|
|
|
# . epilogue
|
|
|
|
89/<- %esp 5/r32/ebp
|
|
|
|
5d/pop-to-ebp
|
|
|
|
c3/return
|
|
|
|
|
2021-01-23 16:45:51 +00:00
|
|
|
set-cursor-position-on-real-screen: # x: int, y: int
|
2021-01-13 08:02:35 +00:00
|
|
|
# . prologue
|
|
|
|
55/push-ebp
|
|
|
|
89/<- %ebp 4/r32/esp
|
|
|
|
# . save registers
|
|
|
|
50/push-eax
|
2021-01-23 03:57:33 +00:00
|
|
|
#
|
2021-01-16 04:30:07 +00:00
|
|
|
8b/-> *(ebp+8) 0/r32/eax
|
2021-01-23 03:57:33 +00:00
|
|
|
89/<- *Real-screen-cursor-x 0/r32/eax
|
2021-01-16 04:30:07 +00:00
|
|
|
8b/-> *(ebp+0xc) 0/r32/eax
|
2021-01-23 03:57:33 +00:00
|
|
|
89/<- *Real-screen-cursor-y 0/r32/eax
|
2021-01-17 23:52:22 +00:00
|
|
|
$set-cursor-position-on-real-screen:end:
|
2021-01-13 08:02:35 +00:00
|
|
|
# . restore registers
|
|
|
|
58/pop-to-eax
|
|
|
|
# . epilogue
|
|
|
|
89/<- %esp 5/r32/ebp
|
|
|
|
5d/pop-to-ebp
|
|
|
|
c3/return
|
|
|
|
|
2021-03-09 07:49:07 +00:00
|
|
|
# Not a real `show-cursor` primitive:
|
2021-01-23 16:45:51 +00:00
|
|
|
# - does not clear previous location cursor was shown at.
|
|
|
|
# - does not preserve what was at the cursor. Caller is responsible for
|
|
|
|
# tracking what was on the screen at this position before and passing it
|
|
|
|
# in again.
|
2021-02-06 04:35:23 +00:00
|
|
|
# - does not stop showing the cursor at this location when the cursor moves
|
2021-03-09 07:49:07 +00:00
|
|
|
draw-cursor-on-real-screen: # g: grapheme
|
2021-01-23 16:45:51 +00:00
|
|
|
# . prologue
|
|
|
|
55/push-ebp
|
|
|
|
89/<- %ebp 4/r32/esp
|
|
|
|
# . save registers
|
|
|
|
50/push-eax
|
|
|
|
51/push-ecx
|
|
|
|
#
|
|
|
|
(cursor-position-on-real-screen) # => eax, ecx
|
|
|
|
(draw-grapheme-on-real-screen *(ebp+8) %eax %ecx 0 7)
|
2021-03-09 07:49:07 +00:00
|
|
|
$draw-cursor-on-real-screen:end:
|
2021-01-23 16:45:51 +00:00
|
|
|
# . restore registers
|
|
|
|
59/pop-to-ecx
|
|
|
|
58/pop-to-eax
|
|
|
|
# . epilogue
|
|
|
|
89/<- %esp 5/r32/ebp
|
|
|
|
5d/pop-to-ebp
|
|
|
|
c3/return
|
|
|
|
|
2021-01-13 07:52:24 +00:00
|
|
|
== data
|
|
|
|
|
2021-01-23 03:57:33 +00:00
|
|
|
# The cursor is where certain Mu functions (usually of the form
|
2021-01-23 16:45:51 +00:00
|
|
|
# 'draw*cursor*') print to by default.
|
|
|
|
#
|
|
|
|
# We don't bother displaying the cursor when drawing. It only becomes visible
|
2021-03-09 07:49:07 +00:00
|
|
|
# on draw-cursor, which is quite rickety (see above)
|
2021-01-23 16:45:51 +00:00
|
|
|
#
|
|
|
|
# It's up to applications to manage cursor display:
|
|
|
|
# - clean up where it used to be
|
|
|
|
# - display the cursor before waiting for a key
|
|
|
|
# - ensure its location appropriately suggests the effect keystrokes will have
|
|
|
|
# - ensure its contents (and colors) appropriately reflect the state of the
|
|
|
|
# screen
|
2021-01-23 03:57:33 +00:00
|
|
|
#
|
2021-01-23 16:45:51 +00:00
|
|
|
# There's no blinking, etc. We aren't using any hardware-supported text mode
|
|
|
|
# here.
|
2021-01-23 03:57:33 +00:00
|
|
|
Real-screen-cursor-x:
|
2021-01-13 07:52:24 +00:00
|
|
|
0/imm32
|
2021-01-23 03:57:33 +00:00
|
|
|
Real-screen-cursor-y:
|
2021-01-13 07:52:24 +00:00
|
|
|
0/imm32
|