def set640x480x16(): ports.inb(0x3DA) ports.outb(0, 0x3C0) ports.writevec(0x3C4,0x3C5, 1,1,4,0,6) ports.outb(0xe3, 0x3C2) ports.writevec(0x3C4,0x3C5, 3) ports.outb(0x11, 0x3D4) ports.outb( 0, 0x3D5) ports.writevec(0x3D4,0x3D5, 0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0x0b, 0x3e, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xea, 0x8c, 0xdf, 0x28, 0x00, 0xe7, 0x04, 0xe3, 0xff) ports.writevec(0x3CC,0x3CA, 1) ports.writevec(0x3CE,0x3CF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0f, 0xff) ports.inb(0x3DA) ports.writevec(0x3C0,0x3C0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x01, 0x00, 0x0F, 0x00) ports.inb(0x3DA) ports.outb(0x20, 0x3C0)
def set320x200x256(): ports.inb(0x3DA) ports.outb(0, 0x3C0) ports.writevec(0x3C4,0x3C5, 3,1,0xf,0,0xe) # 6 for mode X ports.outb(0x63, 0x3C2) ports.writevec(0x3C4,0x3C5, 3) ports.outb(0x11, 0x3D4) ports.outb( 0, 0x3D5) ports.writevec(0x3D4,0x3D5, 0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0xbf, 0x1f, 0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x0e, 0x8f, 0x28, 0x40, 0x96, 0xb9, 0xa3, # 0x00, ..., 0xe3 for mode X 0xff) ports.writevec(0x3CC,0x3CA, 1) ports.writevec(0x3CE,0x3CF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0f, 0xff) ports.inb(0x3DA) ports.writevec(0x3C0,0x3C0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x41, 0x00, 0x0F, 0x00) ports.inb(0x3DA) ports.outb(0x20, 0x3C0)
def set80x25(): ports.inb(0x3DA) ports.outb(0, 0x3C0) ports.writevec(0x3C4, 0x3C5, 1, 0, 3, 0, 2) ports.outb(0x67, 0x3C2) ports.writevec(0x3C4, 0x3C5, 3) ports.outb(0x11, 0x3D4) ports.outb(0, 0x3D5) ports.writevec(0x3D4, 0x3D5, 0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f, 0x00, 0x4f, 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x8e, 0x8f, 0x28, 0x1f, 0x96, 0xb9, 0xa3, 0xff) ports.writevec(0x3CC, 0x3CA, 1) ports.writevec(0x3CE, 0x3CF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x00, 0xff) ports.inb(0x3DA) ports.writevec(0x3C0, 0x3C0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x0C, 0x00, 0x0F, 0x08) ports.inb(0x3DA) ports.outb(0x20, 0x3C0)
def set640x480x16(): ports.inb(0x3DA) ports.outb(0, 0x3C0) ports.writevec(0x3C4, 0x3C5, 1, 1, 4, 0, 6) ports.outb(0xe3, 0x3C2) ports.writevec(0x3C4, 0x3C5, 3) ports.outb(0x11, 0x3D4) ports.outb(0, 0x3D5) ports.writevec(0x3D4, 0x3D5, 0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0x0b, 0x3e, 0x00, 0x40, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0xea, 0x8c, 0xdf, 0x28, 0x00, 0xe7, 0x04, 0xe3, 0xff) ports.writevec(0x3CC, 0x3CA, 1) ports.writevec(0x3CE, 0x3CF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x0f, 0xff) ports.inb(0x3DA) ports.writevec(0x3C0, 0x3C0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x01, 0x00, 0x0F, 0x00) ports.inb(0x3DA) ports.outb(0x20, 0x3C0)
def set80x25(): ports.inb(0x3DA) ports.outb(0, 0x3C0) ports.writevec(0x3C4,0x3C5, 1,0,3,0,2) ports.outb(0x67, 0x3C2) ports.writevec(0x3C4,0x3C5, 3) ports.outb(0x11, 0x3D4) ports.outb( 0, 0x3D5) ports.writevec(0x3D4,0x3D5, 0x5f, 0x4f, 0x50, 0x82, 0x55, 0x81, 0xbf, 0x1f, 0x00, 0x4f, 0x0d, 0x0e, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x8e, 0x8f, 0x28, 0x1f, 0x96, 0xb9, 0xa3, 0xff) ports.writevec(0x3CC,0x3CA, 1) ports.writevec(0x3CE,0x3CF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x10, 0x0e, 0x00, 0xff) ports.inb(0x3DA) ports.writevec(0x3C0,0x3C0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x0C, 0x00, 0x0F, 0x08) ports.inb(0x3DA) ports.outb(0x20, 0x3C0)
def translate_at(scancode): if scancode == 0x71 and _alt == 1 and _ctl == 1: ports.outb(0xfe, 0x64) # reboot if scancode == 0xE0: return None # FIXME if break_at(scancode) == 1: return None if scancode > 0x60: return None # FIXME if _ctl == 1: return None # chr(ord(shifted[scancode]) & 0x1F) elif _shift == 1: return shft_at[scancode] else: return nosh_at[scancode]
def set320x200x256(): ports.inb(0x3DA) ports.outb(0, 0x3C0) ports.writevec(0x3C4, 0x3C5, 3, 1, 0xf, 0, 0xe) # 6 for mode X ports.outb(0x63, 0x3C2) ports.writevec(0x3C4, 0x3C5, 3) ports.outb(0x11, 0x3D4) ports.outb(0, 0x3D5) ports.writevec( 0x3D4, 0x3D5, 0x5f, 0x4f, 0x50, 0x82, 0x54, 0x80, 0xbf, 0x1f, 0x00, 0x41, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x9c, 0x0e, 0x8f, 0x28, 0x40, 0x96, 0xb9, 0xa3, # 0x00, ..., 0xe3 for mode X 0xff) ports.writevec(0x3CC, 0x3CA, 1) ports.writevec(0x3CE, 0x3CF, 0x00, 0x00, 0x00, 0x00, 0x00, 0x40, 0x05, 0x0f, 0xff) ports.inb(0x3DA) ports.writevec(0x3C0, 0x3C0, 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07, 0x08, 0x09, 0x0A, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F, 0x41, 0x00, 0x0F, 0x00) ports.inb(0x3DA) ports.outb(0x20, 0x3C0)
def vgadefaultpalette(): i = 0 while i < 128: # for i in range(256): ports.outb(i, 0x3C8) ports.outb(r[i], 0x3C9) ports.outb(g[i], 0x3C9) ports.outb(b[i], 0x3C9) i = i + 1
def translate_xt(scancode): global _shift, _ctl, _alt if scancode == 0xE0 and _alt == 1 and _ctl == 1: ports.outb(0xfe, 0x64) # reboot if (scancode & 0x80): # high bit set (key release) if scancode == 0x9D: _ctl = 0; return None elif scancode == 0xAA: _shift = 0; return None elif scancode == 0xB6: _shift = 0; return None elif scancode == 0xB8: _alt = 0; return None return None if scancode == 0x1D: _ctl = 1; return None elif scancode == 0x2A: _shift = 1; return None elif scancode == 0x36: _shift = 1; return None elif scancode == 0x38: _alt = 1; return None if scancode > 0x3F: return None # FIXME if _ctl == 1: return None # chr(ord(shifted[scancode]) & 0x1F) elif _shift == 1: return shft_xt[scancode] else: return nosh_xt[scancode]
def translate_xt(scancode): global _shift, _ctl, _alt if scancode == 0xE0 and _alt == 1 and _ctl == 1: ports.outb(0xfe, 0x64) # reboot if (scancode & 0x80): # high bit set (key release) if scancode == 0x9D: _ctl = 0 return None elif scancode == 0xAA: _shift = 0 return None elif scancode == 0xB6: _shift = 0 return None elif scancode == 0xB8: _alt = 0 return None return None if scancode == 0x1D: _ctl = 1 return None elif scancode == 0x2A: _shift = 1 return None elif scancode == 0x36: _shift = 1 return None elif scancode == 0x38: _alt = 1 return None if scancode > 0x3F: return None # FIXME if _ctl == 1: return None # chr(ord(shifted[scancode]) & 0x1F) elif _shift == 1: return shft_xt[scancode] else: return nosh_xt[scancode]
def vgaunchain(): ports.outb(4, 0x3CE); ports.outb(2, 0x3CF) # plane 2 ports.writevec(0x3C4,0x3C5, 3,1,4,0,6) # unchained ports.outb(0x14, 0x3D4); ports.outb(0x00, 0x3D5) ports.outb(0x17, 0x3D4); ports.outb(0xe3, 0x3D5)
def key_isr(): ports.outb(0xfe, 0x64) # reboot!
def configure_device(adapter_addr, mac_address): print "Configuring network device..." ports.outb(adapter_addr + ds_cmd, DSCM_NODMA | DSCM_PG0 | DSCM_STOP) ports.outb(adapter_addr + ds0_dcr, DSDC_WTS | DSDC_BMS | DSDC_FT1) ports.outb(adapter_addr + ds0_rbcr0, 0) ports.outb(adapter_addr + ds0_rbcr1, 0) ports.outb(adapter_addr + ds0_rcr, DSRC_MON) ports.outb(adapter_addr + ds0_tcr, DSTC_LB0) ports.outb(adapter_addr + ds0_pstart, RBUF / DS_PGSIZE) ports.outb(adapter_addr + ds0_pstop, RBUFEND / DS_PGSIZE) ports.outb(adapter_addr + ds0_bnry, RBUF / DS_PGSIZE) ports.outb(adapter_addr + ds0_isr, 0xFF) ports.outb(adapter_addr + ds0_imr, 0XFF) ports.outb(adapter_addr + ds_cmd, DSCM_NODMA | DSCM_PG1 | DSCM_STOP) for i, b in enumerate(mac_address): ports.outb(adapter_addr + ds1_par0 + i, b) for i in range(8): ports.outb(adapter_addr + ds1_mar0 + i, 0xFF) ports.outb(adapter_addr + ds1_curr, RBUF / DS_PGSIZE) ports.outb(adapter_addr + ds_cmd, DSCM_NODMA | DSCM_PG0 | DSCM_START) ports.outb(adapter_addr + ds0_tcr, 0) ports.outb(adapter_addr + ds0_rcr, DSRC_AB) print "Device successfully configured!"
def vgarechain(): ports.outb(4, 0x3CE) ports.outb(0, 0x3CF) # plane 0 ports.writevec(0x3C4, 0x3C5, 3, 1, 0xf, 0, 0xe) # chain-4 ports.outb(0x14, 0x3D4) ports.outb(0x40, 0x3D5) ports.outb(0x17, 0x3D4) ports.outb(0xa3, 0x3D5)
def fetch(adapter_addr, addr, length): cmd = ports.inb(adapter_addr + ds_cmd) ports.outb(adapter_addr + ds_cmd, DSCM_NODMA | DSCM_PG0 | DSCM_START) ports.outb(adapter_addr + ds0_isr, DSIS_RDC) ports.outb(adapter_addr + ds0_rbcr0, length) ports.outb(adapter_addr + ds0_rbcr1, length >> 8) ports.outb(adapter_addr + ds0_rsar0, addr) ports.outb(adapter_addr + ds0_rsar1, addr >> 8) ports.outb(adapter_addr + ds_cmd, DSCM_RREAD | DSCM_PG0 | DSCM_START) #buffer = ports.repinsw(adapter_addr + ne_data, length / 2) #if length & 1: # buffer += ports.inb(adapter_addr + ne_data) buffer = ports.repinsb(adapter_addr + ne_data, length) while not (ports.inb(adapter_addr + ds0_isr) & DSIS_RDC): pass ports.outb(adapter_addr + ds0_isr, DSIS_RDC) ports.outb(adapter_addr + ds_cmd, cmd) return buffer
def key_isr(): ports.outb(0xfe,0x64) # reboot!
def vgarechain(): ports.outb(4, 0x3CE); ports.outb(0, 0x3CF) # plane 0 ports.writevec(0x3C4,0x3C5, 3,1,0xf,0,0xe) # chain-4 ports.outb(0x14, 0x3D4); ports.outb(0x40, 0x3D5) ports.outb(0x17, 0x3D4); ports.outb(0xa3, 0x3D5)
def send(ch): while not ready(): pass ports.outb(ord(ch), 0x3F8)
import ports # simple synchronous serial port # (enough to debug with, anyway) def ready(): return (ports.inb(0x3FD) & 0x20) def send(ch): while not ready(): pass ports.outb(ord(ch), 0x3F8) ports.outb(0x80,0x3FB) ports.outb(0x01,0x3F8) # baud rate: ports.outb(0x00,0x3F9) # 115200 ports.outb(0x03,0x3FB) ports.outb(0x03,0x3FC) ports.outb(0x00,0x3F9)
def init_device(adapter_addr): print "Initializing network device..." print "Resetting device" val = ports.inb(adapter_addr + ne_reset) pause() ports.outb(adapter_addr + ne_reset, val) ports.outb(adapter_addr + ds_cmd, DSCM_STOP | DSCM_NODMA) i = 20000 while i > 0: i = i - 1 if ports.inb(adapter_addr + ds0_isr) & DSIS_RESET: break if not i: print "FAILURE: reset timed out" return print "Device successfully reset" ports.outb(adapter_addr + ds0_isr, 0xFF) ports.outb(adapter_addr + ds0_dcr, DSDC_WTS | DSDC_BMS | DSDC_FT1) ports.outb(adapter_addr + ds_cmd, DSCM_NODMA | DSCM_PG0 | DSCM_STOP) pause() if ports.inb(adapter_addr + ds_cmd) != (DSCM_NODMA | DSCM_PG0 | DSCM_STOP): print "Initialization failed" return ports.outb(adapter_addr + ds0_tcr, 0) ports.outb(adapter_addr + ds0_rcr, DSRC_MON) ports.outb(adapter_addr + ds0_pstart, RBUF / DS_PGSIZE) ports.outb(adapter_addr + ds0_pstop, RBUFEND / DS_PGSIZE) ports.outb(adapter_addr + ds0_bnry, RBUF / DS_PGSIZE) ports.outb(adapter_addr + ds0_imr, 0) ports.outb(adapter_addr + ds0_isr, 0) ports.outb(adapter_addr + ds_cmd, DSCM_NODMA | DSCM_PG1 | DSCM_STOP) ports.outb(adapter_addr + ds1_curr, RBUF / DS_PGSIZE) ports.outb(adapter_addr + ds_cmd, DSCM_NODMA | DSCM_PG0 | DSCM_STOP) data = fetch(adapter_addr, 0, 16) global mac_address mac_address = data[0], data[2], data[4], data[6], data[8], data[10] print mac_address print "Device successfully initialized!"
def init_device(adapter_addr): print "Initializing network device..." print "Resetting device" val = ports.inb(adapter_addr + ne_reset) pause() ports.outb(adapter_addr + ne_reset, val) ports.outb(adapter_addr + ds_cmd, DSCM_STOP | DSCM_NODMA) i = 20000 while i > 0: i = i - 1 if ports.inb(adapter_addr + ds0_isr) & DSIS_RESET: break if not i: print "FAILURE: reset timed out" return print "Device successfully reset" ports.outb(adapter_addr + ds0_isr, 0xFF); ports.outb(adapter_addr + ds0_dcr, DSDC_WTS | DSDC_BMS | DSDC_FT1) ports.outb(adapter_addr + ds_cmd, DSCM_NODMA | DSCM_PG0 | DSCM_STOP) pause() if ports.inb(adapter_addr + ds_cmd) != (DSCM_NODMA | DSCM_PG0 | DSCM_STOP): print "Initialization failed" return ports.outb(adapter_addr + ds0_tcr, 0) ports.outb(adapter_addr + ds0_rcr, DSRC_MON) ports.outb(adapter_addr + ds0_pstart, RBUF/DS_PGSIZE) ports.outb(adapter_addr + ds0_pstop, RBUFEND/DS_PGSIZE) ports.outb(adapter_addr + ds0_bnry, RBUF/DS_PGSIZE) ports.outb(adapter_addr + ds0_imr, 0) ports.outb(adapter_addr + ds0_isr, 0) ports.outb(adapter_addr + ds_cmd, DSCM_NODMA | DSCM_PG1 | DSCM_STOP) ports.outb(adapter_addr + ds1_curr, RBUF/DS_PGSIZE) ports.outb(adapter_addr + ds_cmd, DSCM_NODMA | DSCM_PG0 | DSCM_STOP) data = fetch(adapter_addr, 0, 16) global mac_address mac_address = data[0], data[2], data[4], data[6], data[8], data[10] print mac_address print "Device successfully initialized!"
def vgaunchain(): ports.outb(4, 0x3CE) ports.outb(2, 0x3CF) # plane 2 ports.writevec(0x3C4, 0x3C5, 3, 1, 4, 0, 6) # unchained ports.outb(0x14, 0x3D4) ports.outb(0x00, 0x3D5) ports.outb(0x17, 0x3D4) ports.outb(0xe3, 0x3D5)
def configure_device(adapter_addr, mac_address): print "Configuring network device..." ports.outb(adapter_addr + ds_cmd, DSCM_NODMA | DSCM_PG0 | DSCM_STOP) ports.outb(adapter_addr + ds0_dcr, DSDC_WTS | DSDC_BMS | DSDC_FT1) ports.outb(adapter_addr + ds0_rbcr0, 0) ports.outb(adapter_addr + ds0_rbcr1, 0) ports.outb(adapter_addr + ds0_rcr, DSRC_MON) ports.outb(adapter_addr + ds0_tcr, DSTC_LB0) ports.outb(adapter_addr + ds0_pstart, RBUF/DS_PGSIZE) ports.outb(adapter_addr + ds0_pstop, RBUFEND/DS_PGSIZE) ports.outb(adapter_addr + ds0_bnry, RBUF/DS_PGSIZE) ports.outb(adapter_addr + ds0_isr, 0xFF) ports.outb(adapter_addr + ds0_imr, 0XFF) ports.outb(adapter_addr + ds_cmd, DSCM_NODMA | DSCM_PG1 | DSCM_STOP) for i, b in enumerate(mac_address): ports.outb(adapter_addr + ds1_par0 + i, b) for i in range(8): ports.outb(adapter_addr + ds1_mar0 + i, 0xFF) ports.outb(adapter_addr + ds1_curr, RBUF/DS_PGSIZE) ports.outb(adapter_addr + ds_cmd, DSCM_NODMA | DSCM_PG0 | DSCM_START) ports.outb(adapter_addr + ds0_tcr, 0) ports.outb(adapter_addr + ds0_rcr, DSRC_AB) print "Device successfully configured!"