อ่าน 5 นาที
โหมด 13 ชั่วโมง
โหมด 13hเป็นโหมดสี 256 สีมาตรฐานบนฮาร์ดแวร์กราฟิกVGA ที่เปิดตัวในปี 1987 พร้อมกับIBM PS/2มีความละเอียด320 × 200พิกเซล " 13h" หมายถึงหมายเลขของโหมดใน VGA BIOSโดย "h"...
โหมด 13 ชั่วโมง


โหมด 13hเป็นโหมดสี 256 สีมาตรฐานบนฮาร์ดแวร์กราฟิกVGA ที่เปิดตัวในปี 1987 พร้อมกับIBM PS/2มีความละเอียด320 × 200พิกเซล[ 1 ] " 13h" หมายถึงหมายเลขของโหมดใน VGA BIOSโดย "h" หมายถึงเลขฐานสิบหก
โหมด 13h ให้หน่วยความจำวิดีโอแบบเชิงเส้นขนาด320 × 200ไบต์ แก่ โปรแกรมเมอร์โดยแต่ละไบต์แทนหนึ่งพิกเซล ซึ่งช่วยให้การเขียนโปรแกรมทำได้ง่าย แต่แลกมาด้วยการเข้าถึงคุณสมบัติที่มีประโยชน์อื่นๆ ของฮาร์ดแวร์ VGA ได้ยากขึ้น
เมื่อพิจารณาอัตราส่วนภาพของ หน้าจอ ความละเอียด320 × 200 สำหรับใช้กับ จอแสดงผล 4:3โหมด 13h จะไม่มีพิกเซลสี่เหลี่ยมจัตุรัส[ 2 ]
รายละเอียดทางเทคนิค
โหมด 13h ค่อนข้างน่าสนใจ เพราะ VGA เป็น อุปกรณ์ แบบระนาบใน มุมมอง ฮาร์ดแวร์และไม่เหมาะกับการทำงานกราฟิกที่ซับซ้อน VGA มีหน่วยความจำวิดีโอ 256 KiBประกอบด้วย 4 ธนาคาร ธนาคารละ 64 KiB ซึ่งเรียกว่าระนาบ (หรือ 'แผนที่' ในเอกสารของ IBM) การจัดเรียงหน่วยความจำแบบระนาบจะแบ่งพิกเซลในแนวนอนออกเป็นกลุ่มละสี่พิกเซล สำหรับไบต์ใดๆ ในหน่วย ความจำวิดีโอ 64 KiB ของพีซี สามารถเข้าถึงพิกเซลสี่พิกเซลบนหน้าจอได้โดยการเลือกระนาบที่ต้องการ วิธีนี้ซับซ้อนกว่าสำหรับโปรแกรมเมอร์ แต่ช่วยให้สามารถเข้าถึงหน่วยความจำวิดีโอที่มีอยู่ทั้งหมดและข้อดีอื่นๆ (ดูโหมด X )
Mode 13h, however, allows the programmer to access the VGA in "chunky" (linear) fashion, where each consecutive address in the aperture represents a consecutive pixel on screen. Planes need not be manipulated to select the correct pixels to modify or read. This is achieved using the VGA 'Chain 4' setting in which the lowest two bits of the 16 bit aperture address are used to select the plane to write to/read from. The upshot is that the programmer has a simple access model; the downside is that now only 214 (16 KiB) of the video plane's address space are accessible (the other 2 bits being used to select planes) so only a total of 64 KiB is addressable (4 × 16 KiB). The upper 48 KiB of each plane remains unused in this mode.
Unlike SVGA and higher color depths, Mode 13h, part of the MCGA set of video modes, has 18 bits of color, 6 per RGB channel. The color palette data is not stored in memory per se, but rather modified, read and written to by low level I/O port calls, to the DAC registers.
The palette data was often copied from the low level ports one at a time to a spot in memory after the screen data so the colors could be saved along with the pixels they belonged to. A mode 13h screen capture is merely 64,000 bytes of values from 0 to 255, each an index of a color from a known palette of multiple colors. If the color palette is jumbled or totally wrong, a green leaf will appear blue, or any other possible color, depending on what that particular color was set for, which particular one out of 256.
Due to the way chunks of memory are allocated in such an environment, the bytes in segment 0xA000 from offset 64000 to 64768, can be written to with no negative effects. This lets the programmer save the additional bytes, 256 (colors) × 3 (color channels) = 768 bytes, at the end of the screen capture file. These have to be read back out again and written to the color port for them to change, when an image containing a footer of color info gets loaded. A method used with this was to have a global palette, and match the colors from an old color palette, to a new color palette. This meant changing the index of each pixel, where it would point to a near perfect match of one color from old to new color set. This also had drawbacks, as sometimes there were not enough gradients, and artifacts and such would appear.
It is not essential to set the graphics mode through the BIOS; it is possible to switch graphics mode in 32-bit protected mode, if a little more complicated. It involves writing size data to the VGA controller.
Variants
โหมดสี 256 สีแบบระนาบทางเลือกสามารถใช้งานได้โดยการปิดใช้งานโหมด Chain 4 (การปลดโซ่) โหมดวิดีโอที่สร้างขึ้นโดยใช้เทคนิคนี้เรียกรวมกันว่าMode Xแม้ว่าเดิมทีคำนี้จะใช้สำหรับโหมด VGA ซึ่งมีพิกเซลสี่เหลี่ยมเช่นกัน ในขณะที่โหมดเหล่านี้ (รวมถึงโหมด VGA อื่นๆ อีกมากมาย) ไม่ได้มีการบันทึกไว้โดยเฉพาะโดย IBM แต่ฟังก์ชันและคุณสมบัติของฮาร์ดแวร์ VGA ที่ใช้ในการใช้งานนั้นได้รับการบันทึกไว้อย่างน้อยที่สุดตั้งแต่ปี 1988 ในเอกสาร อ้างอิงทางเทคนิคของอินเทอร์เฟซฮาร์ดแวร์ PS/2
สัญกรณ์
13hหมายถึงเลข 19 ที่เขียนในรูปแบบเลขฐานสิบหก ซึ่งเป็นรูปแบบทั่วไปของโค้ดแอสเซมบลีสำหรับโปรเซสเซอร์ของ Intel ในภาษาโปรแกรม Cจะเขียนเลขฐานสิบหกเป็น0x1313
ในภาษาแอสเซมบลี x86โหมดวิดีโอจะเข้าสู่โดยการตั้ง ค่ารีจิสเตอร์ ALเป็น 13h รีจิสเตอร์ AHเป็น 0 จากนั้นเรียกการขัดจังหวะ BIOS 10h [ 1 ] รีจิสเตอร์ 8 บิตสองตัวALและAH ประกอบกันเป็น รีจิสเตอร์ AX 16 บิต
แม้ว่าเลขฐานสิบหก 13 จะเท่ากับเลขฐานสิบ 19 แต่ในระบบการกำหนดหมายเลขโหมดหน้าจอของQuickBASIC นั้น มันคือโหมดหน้าจอ 13 (ไม่ใช่เลขฐานสิบหก) [ 3 ]โหมดหน้าจอของ QuickBASIC หลายโหมดมีหมายเลขที่แตกต่างจากโหมด BIOS ที่ใช้เป็นพื้นฐาน[ 4 ]
ตัวอย่างโค้ดแหล่งที่มา
รหัสแอสเซมบลีสำหรับเข้าสู่โหมด 13h:
mov ax , 0013 h int 10 hเพื่อเป็นตัวอย่างของโหมด 13h ในซอร์สโค้ดของวิดีโอเกมWolfenstein 3Dได้รวมฟังก์ชันนี้ไว้ในไฟล์ชื่อ "ID_VL.C" โดยจะเข้าสู่โหมด 13h โดยใช้คำสั่งแอสเซมบลีสองคำสั่ง (ขึ้นต้นด้วยasm) ที่ฝังอยู่ในซอร์สโค้ด C และสลับไปยังโหมดระนาบแบบกำหนดเองที่อนุญาตให้บัฟเฟอร์สามชั้น[ 5 ]
void VL_SetVGAPlaneMode ( void ) { asm mov ax , 0x13 asm int 0x10 VL_DePlaneVGA (); VGAMAPMASK ( 15 ); VL_SetLineWidth ( 40 ); }โค้ดต้นฉบับของ Wolfenstein 3D (ประมาณปี 1992) ที่สั่งให้ BIOS เปลี่ยนไปใช้โหมด 13h
ลิงก์ภายนอก
- การเขียนโปรแกรม VGA 256 สีด้วยภาษา C ของ David Brackeen
- บทนำเกี่ยวกับ VGA ... โหมด 13 ชั่วโมง
- ภาษาแอสเซมบลีสำหรับมือใหม่: โหมด 13 ชั่วโมง
- เอกสารอ้างอิงทางเทคนิคเกี่ยวกับอินเทอร์เฟซฮาร์ดแวร์ IBM PS 2