Revision: 141
Author: yujian.zhang
Date: Tue May 11 00:18:12 2010
Log: Add print, println, printcrlf, getchar, putchar, get-cursor,
set-cursor, forward-cursor, and skeleton of REPL.
http://code.google.com/p/yalo/source/detail?r=141
Modified:
/trunk/cc/bootloader.lisp
=======================================
--- /trunk/cc/bootloader.lisp Tue Mar 3 05:23:40 2009
+++ /trunk/cc/bootloader.lisp Tue May 11 00:18:12 2010
@@ -19,7 +19,7 @@
(mov es ax)
(mov fs ax)
(mov gs ax)
- (mov ss ax)
+ (mov ss ax)
;; Load other sectors from floppy disk.
;; AL: # of sectors
@@ -40,22 +40,132 @@
;; Real start up code.
real-start
- ;; Get current cursor position.
- (mov ah 3)
- (xor bh bh)
- (int #x10)
-
- ;; Write string.
+ (mov cx (- end-banner banner))
+ (mov bp banner)
+ (call println)
+ (jmp short read-start)
+ (db banner "Start your journey on yalo v0.0.0!")
+ end-banner
+
+ ;;; REPL: read
+ read-start
+ (mov cx (- read repl))
+ (mov bp repl)
+ (call print)
+ (jmp short read)
+ (db repl ("REPL>"))
+ read
+ (call getchar)
+ (cmp al 13)
+ (je eval-start)
+ (call putchar)
+ (call forward-cursor)
+ (jmp short read)
+
+ ;;; REPL: eval
+ eval-start
+
+ ;;; REPL: print
+ (call printcrlf)
+ (call printcrlf)
+
+ ;;; REPL: loop
+ (jmp short read-start)
+
+ ;;; Function println. Write a string and start a new line.
+ ;;; It is equivalent to calling print twice: first to print the string,
+ ;;; and then print CR/LF.
+ println
+ (call print)
+ (call printcrlf)
+
+ ;;; Function printcrlf. Print crlf only.
+ ;;; Input: None
+ ;;; Output: None
+ ;;; Modified reisters: AX, BX, CX, and DX.
+ printcrlf
+ (mov cx 2)
+ (mov bp crlf)
+ (call print)
+ (ret)
+ (db crlf (13 10))
+
+ ;;; Function print. Write string to screen.
+ ;;; Input:
+ ;;; CX: string length
+ ;;; BP: points to starting address.
+ ;;; Output: None
+ ;;; Modified registers: AX, BX, and DX.
+ print
+ (push cx)
+ (call get-cursor)
+ (pop cx)
+ ;; Write the string.
(mov ax #x1301)
(mov bx #xf)
- (mov cx (- endmsg msg))
- (mov bp msg)
- (int #x10)
-
- ;; Infinite loop.
- (jmp short $)
-
- (db msg ("Hello World! " 13 10))
- endmsg
+ (int #x10)
+ (ret)
+
+ ;;; Function getchar. Get keystroke from keyboard without echo. If
+ ;;; keystroke is available, it is removed from keyboard buffer.
+
+ ;;; Input: None
+ ;;; Output:
+ ;;; AH: BIOS scan code
+ ;;; AL: ASCII character
+ getchar
+ (xor ah ah)
+ (int #x16)
+ (ret)
+
+ ;;; Function putchar. Writer character at cursor position.
+ ;;; Input:
+ ;;; AL: character to display
+ ;;; BH: page number
+ ;;; CX: number of times to writer character.
+ ;;; Output: None
+ ;;; Modified registers: AX, BH, CX.
+ putchar
+ (mov ah #x9)
+ (xor bh bh) ; Page number (0)
+ (mov cx 1) ; Number of times to writer character.
+ (int #x10)
+ (ret)
+
+ ;;; Function get-cursor. Get current cursor position, stored in CX and
DX.
+ ;;; Input: None
+ ;;; Output:
+ ;;; DH: row
+ ;;; DL: column
+ ;;; CH: cursor start line
+ ;;; CL: cursor bottom line
+ get-cursor
+ (mov ah 3)
+ (xor bh bh) ; Page number (0)
+ (int #x10)
+ (ret)
+
+ ;;; Function set-curor. Set cursor position.
+ ;;; Input:
+ ;;; DH: row
+ ;;; DL: column
+ ;;; Output: None
+ ;;; Modified registers AH, BH.
+ set-cursor
+ (mov ah 2)
+ (xor bh bh) ; Page number (0)
+ (int #x10)
+ (ret)
+
+ ;;; Function forward-cursor. Forward cursor position to right by 1
char.
+ ;;; Note that wrap and scrolling not considered.
+ ;;; Input: None
+ ;;; Output: None
+ ;;; Modifie registers: AH, BH, CX, DX
+ forward-cursor
+ (call get-cursor)
+ (inc dl)
+ (call set-cursor)
+ (ret)
kernel-end))
--
You received this message because you are subscribed to the Google Groups "yalo-commit" group.
To post to this group, send email to
yalo-...@googlegroups.com.
To unsubscribe from this group, send email to
yalo-commit...@googlegroups.com.
For more options, visit this group at
http://groups.google.com/group/yalo-commit?hl=en.