24.01.2014 Views

Codice

Codice

Codice

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

«<br />

«<br />

«<br />

«<br />

250 volume VI os16<br />

104.5.18 kernel/ibm_i86/con_char_read.c<br />

Si veda la sezione 103.4.<br />

1180001 |#include <br />

1180002 |#include <br />

1180003 |#include <br />

1180004 |#include <br />

1180005 |#include <br />

1180006 |//----------------------------------------------------------------------<br />

1180007 |int<br />

1180008 |con_char_read (void)<br />

1180009 |{<br />

1180010 | int c;<br />

1180011 | c = int16_01 ();<br />

1180012 | //<br />

1180013 | // Remove special keys that are not used: they have zero in the low<br />

1180014 | // 8 bits, and something in the upper 8 bits.<br />

1180015 | //<br />

1180016 | if ((c & 0xFF00) && !(c & 0x00FF))<br />

1180017 | {<br />

1180018 | int16_00 (); // Remove from buffer and return zero:<br />

1180019 | return (0); // no key.<br />

1180020 | }<br />

1180021 | //<br />

1180022 | // A common key was pressed: filter only che low 8 bits.<br />

1180023 | //<br />

1180024 | c = c & 0x00FF;<br />

1180025 | if (c == 0)<br />

1180026 | {<br />

1180027 | return (c); // There is no key.<br />

1180028 | }<br />

1180029 | if (c == ’\r’) // Convert ‘CR’ to ‘LF’.<br />

1180030 | {<br />

1180031 | c = ’\n’;<br />

1180032 | }<br />

1180033 | int16_00 (); // Remove the key from buffer and return.<br />

1180034 | return (c);<br />

1180035 |}<br />

104.5.19 kernel/ibm_i86/con_char_ready.c<br />

Si veda la sezione 103.4.<br />

1190001 |#include <br />

1190002 |#include <br />

1190003 |#include <br />

1190004 |#include <br />

1190005 |#include <br />

1190006 |//----------------------------------------------------------------------<br />

1190007 |int<br />

1190008 |con_char_ready (void)<br />

1190009 |{<br />

1190010 | int c;<br />

1190011 | c = int16_01 ();<br />

1190012 | //<br />

1190013 | // Remove special keys that are not used: they have zero in the low<br />

1190014 | // 8 bits, and something in the upper 8 bits.<br />

1190015 | //<br />

1190016 | if ((c & 0xFF00) && !(c & 0x00FF))<br />

1190017 | {<br />

1190018 | int16_00 (); // Remove from buffer and return zero:<br />

1190019 | return (0); // no key.<br />

1190020 | }<br />

1190021 | //<br />

1190022 | // A common key was pressed: filter only che low 8 bits.<br />

1190023 | //<br />

1190024 | c = c & 0x00FF;<br />

1190025 | return (c);<br />

1190026 |}<br />

104.5.20 kernel/ibm_i86/con_char_wait.c<br />

Si veda la sezione 103.4.<br />

1200001 |#include <br />

1200002 |#include <br />

1200003 |#include <br />

1200004 |#include <br />

1200005 |#include <br />

1200006 |//----------------------------------------------------------------------<br />

1200007 |int<br />

1200008 |con_char_wait (void)<br />

1200009 |{<br />

1200010 | int c;<br />

1200011 | c = int16_00 ();<br />

1200012 | c = c & 0x00FF;<br />

1200013 | if (c == ’\r’)<br />

1200014 | {<br />

1200015 | c = ’\n’;<br />

1200016 | }<br />

1200017 | return (c);<br />

1200018 |}<br />

104.5.21 kernel/ibm_i86/con_init.c<br />

Si veda la sezione 103.4.<br />

1210001 |#include <br />

1210002 |#include <br />

1210003 |#include <br />

1210004 |#include <br />

1210005 |#include <br />

1210006 |//----------------------------------------------------------------------<br />

1210007 |void<br />

1210008 |con_init (void)<br />

1210009 |{<br />

1210010 | int page;<br />

1210011 | //<br />

1210012 | int10_00 (IBM_I86_VIDEO_MODE);<br />

1210013 | int10_05 (0);<br />

1210014 | //<br />

1210015 | for (page = 0; page < IBM_I86_VIDEO_PAGES; page++)<br />

1210016 | {<br />

Script e sorgenti del kernel 251<br />

1210017 | con_putc (page, ’\n’);<br />

1210018 | }<br />

1210019 |}<br />

104.5.22 kernel/ibm_i86/con_putc.c<br />

Si veda la sezione 103.4.<br />

1220001 |#include <br />

1220002 |#include <br />

1220003 |#include <br />

1220004 |#include <br />

1220005 |#include <br />

1220006 |//----------------------------------------------------------------------<br />

1220007 |void<br />

1220008 |con_putc (int console, int c)<br />

1220009 |{<br />

1220010 | static int cursor[IBM_I86_VIDEO_PAGES];<br />

1220011 | static addr_t address[] = {IBM_I86_VIDEO_ADDRESS};<br />

1220012 | addr_t address_destination;<br />

1220013 | size_t size_screen;<br />

1220014 | size_t size_row;<br />

1220015 | uint16_t cell;<br />

1220016 | uint16_t attribute = 0x0700;<br />

1220017 | int cursor_row;<br />

1220018 | int cursor_column;<br />

1220019 | int cursor_combined;<br />

1220020 |<br />

1220021 | if (console < 0 || console >= IBM_I86_VIDEO_PAGES)<br />

1220022 | {<br />

1220023 | //<br />

1220024 | // No such console.<br />

1220025 | //<br />

1220026 | return;<br />

1220027 | }<br />

1220028 | //<br />

1220029 | // Calculate sizes.<br />

1220030 | //<br />

1220031 | size_row = IBM_I86_VIDEO_COLUMNS;<br />

1220032 | size_screen = size_row * IBM_I86_VIDEO_ROWS;<br />

1220033 | //<br />

1220034 | // See if it is a special character, or if the cursor position<br />

1220035 | // requires a scroll up.<br />

1220036 | //<br />

1220037 | if (c == ’\n’)<br />

1220038 | {<br />

1220039 | con_scroll (console);<br />

1220040 | cursor[console] = (size_screen - size_row);<br />

1220041 | }<br />

1220042 | else if (c == ’\b’)<br />

1220043 | {<br />

1220044 | cursor[console]--;<br />

1220045 | if (cursor[console] < 0)<br />

1220046 | {<br />

1220047 | cursor[console] = 0;<br />

1220048 | }<br />

1220049 | }<br />

1220050 | else if (cursor[console] == (size_screen -1))<br />

1220051 | {<br />

1220052 | //<br />

1220053 | // Scroll up.<br />

1220054 | //<br />

1220055 | con_scroll (console);<br />

1220056 | //<br />

1220057 | cursor[console] -= size_row;<br />

1220058 | }<br />

1220059 | //<br />

1220060 | // If it is not a control character, print it.<br />

1220061 | //<br />

1220062 | if (c != ’\n’ && c != ’\b’)<br />

1220063 | {<br />

1220064 | //<br />

1220065 | // Write the character.<br />

1220066 | //<br />

1220067 | address_destination = address[console];<br />

1220068 | address_destination += (cursor[console] * 2);<br />

1220069 | cell = (attribute | (c & 0x00FF));<br />

1220070 | //<br />

1220071 | mem_write (address_destination, &cell, sizeof (uint16_t));<br />

1220072 | //<br />

1220073 | // and an extra space after it (to be able to show the cursor).<br />

1220074 | //<br />

1220075 | cell = (attribute | ’ ’);<br />

1220076 | address_destination += 2;<br />

1220077 | mem_write (address_destination, &cell, sizeof (uint16_t));<br />

1220078 | //<br />

1220079 | //<br />

1220080 | //<br />

1220081 | cursor[console]++;<br />

1220082 | }<br />

1220083 | //<br />

1220084 | // Update the cursor position on screen.<br />

1220085 | //<br />

1220086 | cursor_row = cursor[console] / size_row;<br />

1220087 | cursor_column = cursor[console] % size_row;<br />

1220088 | cursor_combined = (cursor_row

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!