This commit is contained in:
parent
f66de61392
commit
f774677854
|
@ -12,8 +12,8 @@ Here's the Mu computer running [Conway's Game of Life](https://en.wikipedia.org/
|
|||
```sh
|
||||
$ git clone https://github.com/akkartik/mu
|
||||
$ cd mu
|
||||
$ ./translate life.mu # emit a bootable disk.img
|
||||
$ qemu-system-i386 disk.img
|
||||
$ ./translate life.mu # emit a bootable code.img
|
||||
$ qemu-system-i386 code.img
|
||||
```
|
||||
|
||||
<img alt='screenshot of Game of Life running on the Mu computer' src='html/baremetal-life.png'>
|
||||
|
@ -94,7 +94,7 @@ Mu programs build natively either on Linux or on Windows using [WSL 2](https://d
|
|||
For Macs and other Unix-like systems, use the (much slower) emulator:
|
||||
|
||||
```sh
|
||||
$ ./translate_emulated ex2.mu # ~2 mins to emit disk.img
|
||||
$ ./translate_emulated ex2.mu # ~2 mins to emit code.img
|
||||
```
|
||||
|
||||
Mu programs can be written for two very different environments:
|
||||
|
|
2
bochsrc
2
bochsrc
|
@ -9,7 +9,7 @@
|
|||
|
||||
display_library: sdl2
|
||||
|
||||
ata0-master: type=disk, path="disk.img", mode=flat, cylinders=20, heads=16, spt=63 # 10MB, 512 bytes per sector
|
||||
ata0-master: type=disk, path="code.img", mode=flat, cylinders=20, heads=16, spt=63 # 10MB, 512 bytes per sector
|
||||
boot: disk
|
||||
mouse: enabled=1, toggle=ctrl+f10
|
||||
log: -
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
|
||||
display_library: sdl2
|
||||
|
||||
ata0-master: type=disk, path="disk.img", mode=flat, cylinders=20, heads=16, spt=63 # 10MB, 512 bytes per sector
|
||||
ata0-master: type=disk, path="code.img", mode=flat, cylinders=20, heads=16, spt=63 # 10MB, 512 bytes per sector
|
||||
ata0-slave: type=disk, path="data.img", mode=flat, cylinders=20, heads=16, spt=63 # 10MB, 512 bytes per sector
|
||||
boot: disk
|
||||
mouse: enabled=1, toggle=ctrl+f10
|
||||
|
|
|
@ -9,14 +9,14 @@
|
|||
# halts.
|
||||
#
|
||||
# To convert to a disk image, first prepare a realistically sized disk image:
|
||||
# dd if=/dev/zero of=disk.img count=20160 # 512-byte sectors, so 10MB
|
||||
# dd if=/dev/zero of=code.img count=20160 # 512-byte sectors, so 10MB
|
||||
# Now fill in sectors:
|
||||
# bootstrap/bootstrap run hex < boot0.hex > boot.bin
|
||||
# dd if=boot.bin of=disk.img conv=notrunc
|
||||
# dd if=boot.bin of=code.img conv=notrunc
|
||||
# To run:
|
||||
# qemu-system-i386 disk.img
|
||||
# qemu-system-i386 code.img
|
||||
# Or:
|
||||
# bochs -f bochsrc # bochsrc loads disk.img
|
||||
# bochs -f bochsrc # bochsrc loads code.img
|
||||
#
|
||||
# Since we start out in 16-bit mode, we need instructions SubX doesn't
|
||||
# support.
|
||||
|
|
6
ex10.mu
6
ex10.mu
|
@ -1,11 +1,11 @@
|
|||
# Demo of mouse support.
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex10.mu # emits disk.img
|
||||
# ./translate ex10.mu # emits code.img
|
||||
# To run:
|
||||
# qemu-system-i386 disk.img
|
||||
# qemu-system-i386 code.img
|
||||
# Or:
|
||||
# bochs -f bochsrc # bochsrc loads disk.img
|
||||
# bochs -f bochsrc # bochsrc loads code.img
|
||||
#
|
||||
# Expected output:
|
||||
# Values between -256 and +255 as you move the mouse over the window.
|
||||
|
|
6
ex2.mu
6
ex2.mu
|
@ -1,11 +1,11 @@
|
|||
# Test out the video mode by filling in the screen with pixels.
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex2.mu # emits disk.img
|
||||
# ./translate ex2.mu # emits code.img
|
||||
# To run:
|
||||
# qemu-system-i386 disk.img
|
||||
# qemu-system-i386 code.img
|
||||
# Or:
|
||||
# bochs -f bochsrc # bochsrc loads disk.img
|
||||
# bochs -f bochsrc # bochsrc loads code.img
|
||||
|
||||
fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
|
||||
var y/eax: int <- copy 0
|
||||
|
|
6
ex3.mu
6
ex3.mu
|
@ -2,11 +2,11 @@
|
|||
# and in raster order.
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex3.mu # emits disk.img
|
||||
# ./translate ex3.mu # emits code.img
|
||||
# To run:
|
||||
# qemu-system-i386 disk.img
|
||||
# qemu-system-i386 code.img
|
||||
# Or:
|
||||
# bochs -f bochsrc # bochsrc loads disk.img
|
||||
# bochs -f bochsrc # bochsrc loads code.img
|
||||
#
|
||||
# Expected output: a new green pixel starting from the top left corner of the
|
||||
# screen every time you press a key (letter or digit)
|
||||
|
|
6
ex4.mu
6
ex4.mu
|
@ -1,11 +1,11 @@
|
|||
# Draw a character using the built-in font (GNU unifont)
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex4.mu # emits disk.img
|
||||
# ./translate ex4.mu # emits code.img
|
||||
# To run:
|
||||
# qemu-system-i386 disk.img
|
||||
# qemu-system-i386 code.img
|
||||
# Or:
|
||||
# bochs -f bochsrc # bochsrc loads disk.img
|
||||
# bochs -f bochsrc # bochsrc loads code.img
|
||||
#
|
||||
# Expected output: letter 'A' in green near the top-left corner of screen
|
||||
|
||||
|
|
6
ex5.mu
6
ex5.mu
|
@ -2,11 +2,11 @@
|
|||
# Also demonstrates bounds-checking _before_ drawing.
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex5.mu # emits disk.img
|
||||
# ./translate ex5.mu # emits code.img
|
||||
# To run:
|
||||
# qemu-system-i386 disk.img
|
||||
# qemu-system-i386 code.img
|
||||
# Or:
|
||||
# bochs -f bochsrc # bochsrc loads disk.img
|
||||
# bochs -f bochsrc # bochsrc loads code.img
|
||||
#
|
||||
# Expected output: text in green near the top-left corner of screen
|
||||
|
||||
|
|
6
ex6.mu
6
ex6.mu
|
@ -1,11 +1,11 @@
|
|||
# Drawing ASCII text incrementally.
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex6.mu # emits disk.img
|
||||
# ./translate ex6.mu # emits code.img
|
||||
# To run:
|
||||
# qemu-system-i386 disk.img
|
||||
# qemu-system-i386 code.img
|
||||
# Or:
|
||||
# bochs -f bochsrc # bochsrc loads disk.img
|
||||
# bochs -f bochsrc # bochsrc loads code.img
|
||||
#
|
||||
# Expected output: a box and text that doesn't overflow it
|
||||
|
||||
|
|
6
ex7.mu
6
ex7.mu
|
@ -1,11 +1,11 @@
|
|||
# Cursor-based motions.
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex7.mu # emits disk.img
|
||||
# ./translate ex7.mu # emits code.img
|
||||
# To run:
|
||||
# qemu-system-i386 disk.img
|
||||
# qemu-system-i386 code.img
|
||||
# Or:
|
||||
# bochs -f bochsrc # bochsrc loads disk.img
|
||||
# bochs -f bochsrc # bochsrc loads code.img
|
||||
#
|
||||
# Expected output: an interactive game a bit like "snakes". Try pressing h, j,
|
||||
# k, l.
|
||||
|
|
4
ex8.mu
4
ex8.mu
|
@ -1,9 +1,9 @@
|
|||
# Demo of floating-point support.
|
||||
#
|
||||
# To build a disk image:
|
||||
# ./translate ex8.mu # emits disk.img
|
||||
# ./translate ex8.mu # emits code.img
|
||||
# To run:
|
||||
# bochs -f bochsrc # bochsrc loads disk.img
|
||||
# bochs -f bochsrc # bochsrc loads code.img
|
||||
# Set a breakpoint at 0x7c00 and start stepping.
|
||||
|
||||
fn main screen: (addr screen), keyboard: (addr keyboard), data-disk: (addr disk) {
|
||||
|
|
4
ex9.mu
4
ex9.mu
|
@ -1,7 +1,7 @@
|
|||
# Demo of reading and writing to disk.
|
||||
#
|
||||
# Steps for trying it out:
|
||||
# 1. Translate this example into a disk image disk.img.
|
||||
# 1. Translate this example into a disk image code.img.
|
||||
# ./translate ex9.mu
|
||||
# 2. Build a second disk image data.img containing some text.
|
||||
# dd if=/dev/zero of=data.img count=20160
|
||||
|
@ -9,7 +9,7 @@
|
|||
# 3. Familiarize yourself with how the data disk looks within xxd:
|
||||
# xxd data.img |head
|
||||
# 4. Run in an emulator, either Qemu or Bochs.
|
||||
# qemu-system-i386 -hda disk.img -hdb data.img
|
||||
# qemu-system-i386 -hda code.img -hdb data.img
|
||||
# bochs -f bochsrc.2disks
|
||||
# 5. Exit the emulator.
|
||||
# 6. Notice that the data disk now contains the word count of the original text.
|
||||
|
|
2
life.mu
2
life.mu
|
@ -3,7 +3,7 @@
|
|||
# To build:
|
||||
# $ ./translate life.mu
|
||||
# To run:
|
||||
# $ qemu-system-i386 disk.img
|
||||
# $ qemu-system-i386 code.img
|
||||
|
||||
fn state _grid: (addr array boolean), x: int, y: int -> _/eax: boolean {
|
||||
# clip at the edge
|
||||
|
|
2
rpn.mu
2
rpn.mu
|
@ -7,7 +7,7 @@
|
|||
# $ ./translate rpn.mu
|
||||
#
|
||||
# Example session:
|
||||
# $ qemu-system-i386 disk.img
|
||||
# $ qemu-system-i386 code.img
|
||||
# > 4
|
||||
# 4
|
||||
# > 5 3 -
|
||||
|
|
|
@ -4,12 +4,12 @@ Currently runs a tiny subset of Lisp. Steps to run it from the top-level:
|
|||
|
||||
1. Build it:
|
||||
```sh
|
||||
$ ./translate shell/*.mu # generates disk.img
|
||||
$ ./translate shell/*.mu # generates code.img
|
||||
```
|
||||
|
||||
2. Run it:
|
||||
```sh
|
||||
$ qemu-system-i386 disk.img
|
||||
$ qemu-system-i386 code.img
|
||||
```
|
||||
or:
|
||||
```
|
||||
|
@ -28,7 +28,7 @@ $ echo '(+ 1 1)' |dd of=data.img conv=notrunc
|
|||
|
||||
Now run with both code and data disks:
|
||||
```sh
|
||||
$ qemu-system-i386 -hda disk.img -hdb data.img
|
||||
$ qemu-system-i386 -hda code.img -hdb data.img
|
||||
```
|
||||
or:
|
||||
```
|
||||
|
|
|
@ -30,9 +30,9 @@ cat a.pack |linux/survey_baremetal > a.survey
|
|||
|
||||
cat a.survey |linux/hex > a.bin
|
||||
|
||||
# Create disk.img containing a.bin
|
||||
dd if=/dev/zero of=disk.img count=20160 # 512-byte sectors, so 10MB
|
||||
dd if=a.bin of=disk.img conv=notrunc
|
||||
# Create code.img containing a.bin
|
||||
dd if=/dev/zero of=code.img count=20160 # 512-byte sectors, so 10MB
|
||||
dd if=a.bin of=code.img conv=notrunc
|
||||
|
||||
if [ `stat --printf="%s" a.bin` -ge 193536 ] # 6 tracks * 63 sectors per track * 512 bytes per sector (keep this sync'd with boot.subx)
|
||||
then
|
||||
|
|
|
@ -25,9 +25,9 @@ cat a.pack |linux/bootstrap/bootstrap run linux/survey_baremetal > a.su
|
|||
|
||||
cat a.survey |linux/bootstrap/bootstrap run linux/hex > a.bin
|
||||
|
||||
# Create disk.img containing a.bin
|
||||
dd if=/dev/zero of=disk.img count=20160 # 512-byte sectors, so 10MB
|
||||
dd if=a.bin of=disk.img conv=notrunc
|
||||
# Create code.img containing a.bin
|
||||
dd if=/dev/zero of=code.img count=20160 # 512-byte sectors, so 10MB
|
||||
dd if=a.bin of=code.img conv=notrunc
|
||||
|
||||
if [ `stat --printf="%s" a.bin` -ge 193536 ] # 6 tracks * 63 sectors per track * 512 bytes per sector (keep this sync'd with boot.subx)
|
||||
then
|
||||
|
|
Loading…
Reference in New Issue