.{memory, log} := @use("../../../libraries/stn/src/lib.hb"); .{bit5} := @use("bits.hb") init := fn(): void { memory.outb(0x64, 0xAD) memory.outb(0x64, 0xA7) //Disables ports to make sure that they won't interfere with the setup process. loop if (memory.inb(0x64) & 1) == 0 break else memory.inb(0x60) //Flushes any output because apperantly that might interfere with stuff. memory.outb(0x64, 0xA8) //Enables port 2. memory.outb(0x64, 0x20) //Gimme configuration byte. loop if (memory.inb(0x64) & 1) == 1 break ports[1].exists = bit5(memory.inb(0x60)) == false if ports[1].exists { memory.outb(0x64, 0xA7) } loop if (memory.inb(0x64) & 1) == 0 break else memory.inb(0x60) //Flushes any output because apperantly that might interfere with stuff. memory.outb(0x64, 0xAB) loop if (memory.inb(0x64) & 1) == 1 break ports[0].exists = memory.inb(0x60) == 0x0 //Test port 1. if ports[1].exists { memory.outb(0x64, 0xA9) loop if (memory.inb(0x64) & 1) == 1 break ports[1].exists = memory.inb(0x60) == 0x0 } //Test port 2. if (ports[0].exists | ports[1].exists) == false { log.error("No ports detected! No input will be processed! Cannot handle this!\0") } if ports[0].exists { log.info("Port 1 exists.\0") memory.outb(0x64, 0xAE) //Enables port 1. ports[0].commands_queued = 1 } if ports[1].exists { log.info("Port 2 exists.\0") memory.outb(0x64, 0xA8) //Enables port 2. ports[1].commands_queued = 1 } }