undo previous commit

This commit is contained in:
Kartik K. Agaram 2021-04-05 21:16:45 -07:00
parent 928fd47d68
commit 316bf37541
5 changed files with 123 additions and 149 deletions

View File

@ -43,24 +43,18 @@ write-int32-decimal: # out: (addr stream byte), n: int
51/push-ecx 51/push-ecx
52/push-edx 52/push-edx
53/push-ebx 53/push-ebx
56/push-esi
57/push-edi 57/push-edi
be/copy-to-esi 3/imm32/x
# const ten/ecx = 10 # const ten/ecx = 10
b9/copy-to-ecx 0xa/imm32 b9/copy-to-ecx 0xa/imm32
# push sentinel # push sentinel
68/push 0/imm32/sentinel 68/push 0/imm32/sentinel
# var eax: int = abs(n) # var eax: int = abs(n)
8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 . # copy *(ebp+12) to eax 8b/copy 1/mod/*+disp8 5/rm32/ebp . . . 0/r32/eax 0xc/disp8 . # copy *(ebp+12) to eax
(draw-vertical-line-on-real-screen %eax 0x40 0x50 %eax)
81 0/subop/add %esi 3/imm32
3d/compare-eax-with 0/imm32 3d/compare-eax-with 0/imm32
7d/jump-if->= $write-int32-decimal:read-loop/disp8 7d/jump-if->= $write-int32-decimal:read-loop/disp8
$write-int32-decimal:negative: $write-int32-decimal:negative:
f7 3/subop/negate 3/mod/direct 0/rm32/eax . . . . . . # negate eax f7 3/subop/negate 3/mod/direct 0/rm32/eax . . . . . . # negate eax
$write-int32-decimal:read-loop: $write-int32-decimal:read-loop:
(draw-vertical-line-on-real-screen %esi 0x80 0x90 %esi)
81 0/subop/add %esi 3/imm32
# eax, edx = eax / 10, eax % 10 # eax, edx = eax / 10, eax % 10
99/sign-extend-eax-into-edx 99/sign-extend-eax-into-edx
f7 7/subop/idiv 3/mod/direct 1/rm32/ecx . . . . . . # divide edx:eax by ecx, storing quotient in eax and remainder in edx f7 7/subop/idiv 3/mod/direct 1/rm32/ecx . . . . . . # divide edx:eax by ecx, storing quotient in eax and remainder in edx
@ -110,7 +104,6 @@ $write-int32-decimal:write-break:
$write-int32-decimal:end: $write-int32-decimal:end:
# . restore registers # . restore registers
5f/pop-to-edi 5f/pop-to-edi
5e/pop-to-esi
5b/pop-to-ebx 5b/pop-to-ebx
5a/pop-to-edx 5a/pop-to-edx
59/pop-to-ecx 59/pop-to-ecx

View File

@ -105,15 +105,6 @@ fn draw-text-rightward screen: (addr screen), text: (addr array byte), x: int, x
return xcurr return xcurr
} }
fn draw-int32-decimal-rightward screen: (addr screen), n: int, x: int, xmax: int, y: int, color: int, background-color: int -> _/eax: int {
var stream-storage: (stream byte 0x100)
var stream/esi: (addr stream byte) <- address stream-storage
write-int32-decimal stream, n
#? write-int32-hex stream, n
var xcurr/eax: int <- draw-stream-rightward screen, stream, x, xmax, y, color, background-color
return xcurr
}
# draw a single-line stream from x, y to xmax # draw a single-line stream from x, y to xmax
# return the next 'x' coordinate # return the next 'x' coordinate
# if there isn't enough space, truncate # if there isn't enough space, truncate
@ -253,9 +244,23 @@ fn draw-int32-hex-wrapping-right-then-down screen: (addr screen), n: int, xmin:
var stream-storage: (stream byte 0x100) var stream-storage: (stream byte 0x100)
var stream/esi: (addr stream byte) <- address stream-storage var stream/esi: (addr stream byte) <- address stream-storage
write-int32-hex stream, n write-int32-hex stream, n
var xcurr/eax: int <- copy x var xcurr/edx: int <- copy x
var ycurr/ecx: int <- copy y var ycurr/ecx: int <- copy y
xcurr, ycurr <- draw-stream-wrapping-right-then-down screen, stream, xmin, ymin, xmax, ymax, x, y, color, background-color {
var g/eax: grapheme <- read-grapheme stream
compare g, 0xffffffff/end-of-file
break-if-=
draw-grapheme screen, g, xcurr, ycurr, color, background-color
xcurr <- increment
compare xcurr, xmax
{
break-if-<
xcurr <- copy xmin
ycurr <- increment
}
loop
}
set-cursor-position screen, xcurr, ycurr
return xcurr, ycurr return xcurr, ycurr
} }
@ -292,17 +297,24 @@ fn draw-int32-hex-wrapping-right-then-down-from-cursor-over-full-screen screen:
fn draw-int32-decimal-wrapping-right-then-down screen: (addr screen), n: int, xmin: int, ymin: int, xmax: int, ymax: int, x: int, y: int, color: int, background-color: int -> _/eax: int, _/ecx: int { fn draw-int32-decimal-wrapping-right-then-down screen: (addr screen), n: int, xmin: int, ymin: int, xmax: int, ymax: int, x: int, y: int, color: int, background-color: int -> _/eax: int, _/ecx: int {
var stream-storage: (stream byte 0x100) var stream-storage: (stream byte 0x100)
var stream/esi: (addr stream byte) <- address stream-storage var stream/esi: (addr stream byte) <- address stream-storage
#? compare n, 0x48
#? {
#? break-if-!=
#? abort "aa"
#? }
write-int32-decimal stream, n write-int32-decimal stream, n
#? write-int32-decimal stream, 0x48 var xcurr/edx: int <- copy x
#? write-int32-hex stream, n var ycurr/ecx: int <- copy y
var xcurr/eax: int <- copy 0 {
var ycurr/ecx: int <- copy 0 var g/eax: grapheme <- read-grapheme stream
xcurr, ycurr <- draw-stream-wrapping-right-then-down screen, stream, xmin, ymin, xmax, ymax, x, y, color, background-color compare g, 0xffffffff/end-of-file
break-if-=
draw-grapheme screen, g, xcurr, ycurr, color, background-color
xcurr <- increment
compare xcurr, xmax
{
break-if-<
xcurr <- copy xmin
ycurr <- increment
}
loop
}
set-cursor-position screen, xcurr, ycurr
return xcurr, ycurr return xcurr, ycurr
} }

207
boot.subx
View File

@ -359,125 +359,96 @@ keyboard-interrupt-handler:
3c/compare-al-and 0/imm8 3c/compare-al-and 0/imm8
75/jump-if-!= $keyboard-interrupt-handler:epilogue/disp8 75/jump-if-!= $keyboard-interrupt-handler:epilogue/disp8
# - read keycode # - read keycode
31/xor %eax 0/r32/eax
e4/read-port-into-al 0x60/imm8 e4/read-port-into-al 0x60/imm8
# # - key released
#? 50/push-eax # if (al == 0xaa) shift = false # left shift is being lifted
#? 51/push-ecx {
#? (draw-int32-hex-wrapping-right-then-down-over-full-screen 0 %eax 0 0 7 0) 3c/compare-al-and 0xaa/imm8
#? 59/pop-to-ecx 75/jump-if-!= break/disp8
#? 58/pop-to-eax # *shift = 0
# c7 0/subop/copy *Keyboard-shift-pressed? 0/imm32
#? 50/push-eax }
#? 51/push-ecx # if (al == 0xb6) shift = false # right shift is being lifted
#? (draw-int32-decimal-wrapping-right-then-down 0 %eax 0 2 0x400 2 0 2 7 0) {
89/<- %ecx 0/r32/eax 3c/compare-al-and 0xb6/imm8
# . . push args 75/jump-if-!= break/disp8
68/push 0/imm32/bg # *shift = 0
68/push 7/imm32/fg c7 0/subop/copy *Keyboard-shift-pressed? 0/imm32
68/push 2/imm32/y }
68/push 0x400/imm32/xmax # if (al == 0x9d) ctrl = false # ctrl is being lifted
68/push 0/imm32/xmin {
#? 68/push 0x48/imm32/n 3c/compare-al-and 0x9d/imm8
51/push-ecx 75/jump-if-!= break/disp8
68/push 0/imm32/screen # *ctrl = 0
# . . call c7 0/subop/copy *Keyboard-ctrl-pressed? 0/imm32
#? e8/call draw-int32-hex-wrapping-right-then-down/disp32 }
#? e8/call draw-int32-decimal-wrapping-right-then-down/disp32 # if (al & 0x80) a key is being lifted; return
e8/call draw-int32-decimal-rightward/disp32 50/push-eax
# . . discard args 24/and-al-with 0x80/imm8
81 0/subop/add %esp 0x1c/imm32 3c/compare-al-and 0/imm8
#? 59/pop-to-ecx 58/pop-to-eax
#? 58/pop-to-eax 75/jump-if-!= $keyboard-interrupt-handler:epilogue/disp8
#? # - key released # - key pressed
#? # if (al == 0xaa) shift = false # left shift is being lifted # if (al == 0x2a) shift = true, return # left shift pressed
#? { {
#? 3c/compare-al-and 0xaa/imm8 3c/compare-al-and 0x2a/imm8
#? 75/jump-if-!= break/disp8 75/jump-if-!= break/disp8
#? # *shift = 0 # *shift = 1
#? c7 0/subop/copy *Keyboard-shift-pressed? 0/imm32 c7 0/subop/copy *Keyboard-shift-pressed? 1/imm32
#? } # return
#? # if (al == 0xb6) shift = false # right shift is being lifted eb/jump $keyboard-interrupt-handler:epilogue/disp8
#? { }
#? 3c/compare-al-and 0xb6/imm8 # if (al == 0x36) shift = true, return # right shift pressed
#? 75/jump-if-!= break/disp8 {
#? # *shift = 0 3c/compare-al-and 0x36/imm8
#? c7 0/subop/copy *Keyboard-shift-pressed? 0/imm32 75/jump-if-!= break/disp8
#? } # *shift = 1
#? # if (al == 0x9d) ctrl = false # ctrl is being lifted c7 0/subop/copy *Keyboard-shift-pressed? 1/imm32
#? { # return
#? 3c/compare-al-and 0x9d/imm8 eb/jump $keyboard-interrupt-handler:epilogue/disp8
#? 75/jump-if-!= break/disp8 }
#? # *ctrl = 0 # if (al == 0x1d) ctrl = true, return
#? c7 0/subop/copy *Keyboard-ctrl-pressed? 0/imm32 {
#? } 3c/compare-al-and 0x1d/imm8
#? # if (al & 0x80) a key is being lifted; return 75/jump-if-!= break/disp8
#? 50/push-eax # *ctrl = 1
#? 24/and-al-with 0x80/imm8 c7 0/subop/copy *Keyboard-ctrl-pressed? 1/imm32
#? 3c/compare-al-and 0/imm8 # return
#? 58/pop-to-eax eb/jump $keyboard-interrupt-handler:epilogue/disp8
#? 75/jump-if-!= $keyboard-interrupt-handler:epilogue/disp8 }
#? # - key pressed # - convert key to character
#? # if (al == 0x2a) shift = true, return # left shift pressed # if (shift) use keyboard shift map
#? { {
#? 3c/compare-al-and 0x2a/imm8 81 7/subop/compare *Keyboard-shift-pressed? 0/imm32
#? 75/jump-if-!= break/disp8 74/jump-if-= break/disp8
#? # *shift = 1 # sigils don't currently support labels inside *(eax+label)
#? c7 0/subop/copy *Keyboard-shift-pressed? 1/imm32 05/add-to-eax Keyboard-shift-map/imm32
#? # return 8a/byte-> *eax 0/r32/al
#? eb/jump $keyboard-interrupt-handler:epilogue/disp8 eb/jump $keyboard-interrupt-handler:select-map-done/disp8
#? } }
#? # if (al == 0x36) shift = true, return # right shift pressed # if (ctrl) al = *(ctrl map + al)
#? { {
#? 3c/compare-al-and 0x36/imm8 81 7/subop/compare *Keyboard-ctrl-pressed? 0/imm32
#? 75/jump-if-!= break/disp8 74/jump-if-= break/disp8
#? # *shift = 1 05/add-to-eax Keyboard-ctrl-map/imm32
#? c7 0/subop/copy *Keyboard-shift-pressed? 1/imm32 8a/byte-> *eax 0/r32/al
#? # return eb/jump $keyboard-interrupt-handler:select-map-done/disp8
#? eb/jump $keyboard-interrupt-handler:epilogue/disp8 }
#? } # otherwise al = *(normal map + al)
#? # if (al == 0x1d) ctrl = true, return 05/add-to-eax Keyboard-normal-map/imm32
#? { 8a/byte-> *eax 0/r32/al
#? 3c/compare-al-and 0x1d/imm8 $keyboard-interrupt-handler:select-map-done:
#? 75/jump-if-!= break/disp8 # - if there's no character mapping, return
#? # *ctrl = 1 {
#? c7 0/subop/copy *Keyboard-ctrl-pressed? 1/imm32 3c/compare-al-and 0/imm8
#? # return 74/jump-if-= break/disp8
#? eb/jump $keyboard-interrupt-handler:epilogue/disp8 # - store al in keyboard buffer
#? } 88/<- *ecx 0/r32/al
#? # - convert key to character # increment index
#? # if (shift) use keyboard shift map fe/increment-byte *Keyboard-buffer:write
#? { # clear top nibble of index (keyboard buffer is circular)
#? 81 7/subop/compare *Keyboard-shift-pressed? 0/imm32 80 4/subop/and-byte *Keyboard-buffer:write 0x0f/imm8
#? 74/jump-if-= break/disp8 }
#? # sigils don't currently support labels inside *(eax+label)
#? 05/add-to-eax Keyboard-shift-map/imm32
#? 8a/byte-> *eax 0/r32/al
#? eb/jump $keyboard-interrupt-handler:select-map-done/disp8
#? }
#? # if (ctrl) al = *(ctrl map + al)
#? {
#? 81 7/subop/compare *Keyboard-ctrl-pressed? 0/imm32
#? 74/jump-if-= break/disp8
#? 05/add-to-eax Keyboard-ctrl-map/imm32
#? 8a/byte-> *eax 0/r32/al
#? eb/jump $keyboard-interrupt-handler:select-map-done/disp8
#? }
#? # otherwise al = *(normal map + al)
#? 05/add-to-eax Keyboard-normal-map/imm32
#? 8a/byte-> *eax 0/r32/al
#? $keyboard-interrupt-handler:select-map-done:
#? # - if there's no character mapping, return
#? {
#? 3c/compare-al-and 0/imm8
#? 74/jump-if-= break/disp8
#? # - store al in keyboard buffer
#? 88/<- *ecx 0/r32/al
#? # increment index
#? fe/increment-byte *Keyboard-buffer:write
#? # clear top nibble of index (keyboard buffer is circular)
#? 80 4/subop/and-byte *Keyboard-buffer:write 0x0f/imm8
#? }
$keyboard-interrupt-handler:epilogue: $keyboard-interrupt-handler:epilogue:
# epilogue # epilogue
9d/pop-flags 9d/pop-flags

View File

@ -167,10 +167,9 @@ test-write-int32-decimal-zero:
e8/call clear-stream/disp32 e8/call clear-stream/disp32
# . . discard args # . . discard args
81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp 81 0/subop/add 3/mod/direct 4/rm32/esp . . . . . 4/imm32 # add to esp
b8/copy-to-eax 0x48/imm32
# write-int32-decimal(_test-stream, 0) # write-int32-decimal(_test-stream, 0)
# . . push args # . . push args
50/push-eax 68/push 0/imm32
68/push _test-stream/imm32 68/push _test-stream/imm32
# . . call # . . call
e8/call write-int32-decimal/disp32 e8/call write-int32-decimal/disp32

View File

@ -11,7 +11,6 @@
== code == code
Entry: Entry:
e8/call test-write-int32-decimal-zero/disp32
# exit(42) # exit(42)
bb/copy-to-ebx 0x2a/imm32 # 42 in hex bb/copy-to-ebx 0x2a/imm32 # 42 in hex
e8/call syscall_exit/disp32 e8/call syscall_exit/disp32