Open Firmware 程序編寫 第二集 彩色繪圖

21 views
Skip to first unread message

胡松涛

unread,
May 25, 2011, 12:31:01 AM5/25/11
to cn...@googlegroups.com

先看錄像: http://forth.foxani.com/files/videos/ofw/02-vga-draw.ogv

這次是說繪圖. 注:請在qemu下面測試.
關于如何對vbox,具體硬件和qemu的顯示支持,請參考後面的作者信件,
我還沒深入研究,有興趣的朋友可以試試.
ROM下載: http://forth.foxani.com/files/emuofw.rom

第一步: 繪制填充的矩形

stdout @ iselect \ 取得設備ihandle
decimal \ 設置為十進制, ofw默認是hex

: 1test
2 50 50 200 20 fill-rectangle \ 填充方塊 色 x y 長 寬
3 50 60 200 20 fill-rectangle
4 50 70 200 20 fill-rectangle
5 50 80 200 20 fill-rectangle
;
1test \ 繪制四個矩形

第二步: 繪制水平線

0 value default-color \ 定義默認顏色
: hline ( y -- ) \ y 決定直線位置
default-color 0 \
rot
800 2 fill-rectangle \ 長800 寬2
;

iunselect \ 關閉設備

第三步: 隨機繪制多彩矩形 來自作者的文件 testrect.fth

重啟qemu
fload c:\testrect.fth


參考:
作者對display的問題回信:

On 5/24/2011 4:10 PM, 胡松涛 wrote:
Hi,

When I learn http://www.openfirmware.org/1275/practice/#graphics
I found that: I Can't get /pci/display ihandle under vbox,

That is because there is no suitable driver in the demo build.

VirtualBox emulates a linear frame buffer that is managed with VESA BIOS
extensions. The demo build, when running under syslinux, has some words
to access VESA BIOS functions - they are defined in
cpu/x86/pc/biosload/callvbe.fth . You could use them to put the display
into VESA linear framebuffer mode, then access the framebuffer with the
functions in dev/video/common/rectangl.fth .

You would need to use a serial console for this, because as soon as you
switched to VESA linear mode, you would lose the text-mode console display.

when I boot
up with usb-disk on my laptop, I can't get ihandle as well.

Again, the problem is the lack of a driver for the graphics card on your
laptop. Modern PC graphics cards are very complex, and often undocumented.

If your laptop has a conventional BIOS that supports VESA, you could use
the VESA technique outlined above to access its display in graphics mode.
If it has an EFI BIOS, some other technique would be required.


but I can get /pci/vga ihandle under qemu. And it works fine with graphics.

qemu emulates an old Cirrus logic display controller for which OFW has a
driver (the source code is in dev/video/cirrus.bth).


--
Hu Songtao
works as an English Teacher in weekends
Skype: idisblueflash
Beijing, China
vga.fth
testrect.fth
run.sh

胡松涛

unread,
May 25, 2011, 5:21:55 AM5/25/11
to cn...@googlegroups.com
在 Wed, 25 May 2011 12:31:01 +0800,胡松涛 <idisbl...@gmail.com> 写道:

>
> 這次是說繪圖. 注:請在qemu下面測試.
> 關于如何對vbox,具體硬件和qemu的顯示支持,請參考後面的作者信件,
> 我還沒深入研究,有興趣的朋友可以試試.
> ROM下載: http://forth.foxani.com/files/emuofw.rom
>

作者升級了svn,版本是2222, 我用這個編譯了一個ofw.c32 見附件.
可以支持usb啟動和彩色繪圖.
我的筆記本測試了一下,效果很不錯!

但是vbox暫時還是無法弄.
ofw.c32

胡松涛

unread,
May 26, 2011, 5:12:41 AM5/26/11
to cn...@googlegroups.com
在 Wed, 25 May 2011 12:31:01 +0800,胡松涛 <idisbl...@gmail.com> 写道:

> 這次是說繪圖. 注:請在qemu下面測試.
> 關于如何對vbox,具體硬件和qemu的顯示支持,請參考後面的作者信件,
> 我還沒深入研究,有興趣的朋友可以試試.

作者升級了程序,支持vbox下,軟盤啟動的繪圖了!
附件是軟盤鏡像,歡迎測試!
floppy.img.zip

xiaohao

unread,
May 26, 2011, 5:31:44 AM5/26/11
to Forth中国社区
太好了,回去我来测试下~

胡松涛

unread,
May 26, 2011, 6:05:29 AM5/26/11
to cn...@googlegroups.com
在 Thu, 26 May 2011 17:31:44 +0800,xiaohao <superc...@gmail.com> 写道:

> 太好了,回去我来测试下~

下載附件裏的最新版本吧. 作者升級速度太快了. 這個版本解決了vbox虛擬的時候,
高cpu占用的問題!
floppy.img.zip
Reply all
Reply to author
Forward
0 new messages