polio: fix comms
This commit is contained in:
@@ -22,6 +22,7 @@ static uint8_t miso_recvbuf[256];
|
||||
static uint8_t miso_size;
|
||||
static uint8_t miso_received_nibbles;
|
||||
static uint8_t miso_state;
|
||||
recv_cb miso_recv_cb;
|
||||
|
||||
static void swapbuffers() {
|
||||
mosi_sendbuf = mosi_workbuf[mosi_workbuf_idx];
|
||||
@@ -92,19 +93,21 @@ void paracomm_feed(uint8_t n) {
|
||||
miso_received_nibbles += 1;
|
||||
|
||||
if (miso_received_nibbles == 2 * miso_size) {
|
||||
miso_recv_cb(miso_recvbuf, miso_size);
|
||||
miso_state = 0;
|
||||
}
|
||||
} break;
|
||||
}
|
||||
}
|
||||
|
||||
void paracomm_init() {
|
||||
void paracomm_init(recv_cb miso_cb) {
|
||||
mosi_size = 0;
|
||||
mosi_workbuf_idx = 0;
|
||||
mosi_workbuf_size = 0;
|
||||
mosi_state = 0;
|
||||
|
||||
miso_state = 0;
|
||||
miso_recv_cb = miso_cb;
|
||||
}
|
||||
|
||||
int paracomm_send(uint8_t b) {
|
||||
@@ -119,20 +122,6 @@ int paracomm_send(uint8_t b) {
|
||||
return 0;
|
||||
}
|
||||
|
||||
uint8_t paracomm_recv(uint8_t* buf, uint8_t size) {
|
||||
if (miso_state != 0) {
|
||||
return 0;
|
||||
}
|
||||
if (size > miso_size) {
|
||||
size = miso_size;
|
||||
}
|
||||
memcpy(buf, miso_recvbuf, size);
|
||||
memcpy(miso_recvbuf, miso_recvbuf+size, miso_size - size);
|
||||
miso_size -= size;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
uint8_t paracomm_busy() {
|
||||
return mosi_state != 0 || miso_state != 0;
|
||||
}
|
||||
|
@@ -2,19 +2,16 @@
|
||||
|
||||
#include <stdint.h>
|
||||
|
||||
typedef void (*recv_cb)(const uint8_t* buf, uint8_t size);
|
||||
|
||||
/** Must call first **/
|
||||
void paracomm_init();
|
||||
void paracomm_init(recv_cb cb);
|
||||
|
||||
/** Sends a single byte.
|
||||
* Returns: 0 if no error, non-0 otherwise.
|
||||
*/
|
||||
int paracomm_send(uint8_t b);
|
||||
|
||||
/** Receive some bytes.
|
||||
* Returns: number of bytes copied
|
||||
*/
|
||||
uint8_t paracomm_recv(uint8_t* buf, uint8_t size);
|
||||
|
||||
/** Call after reading a nibble from the port */
|
||||
void paracomm_feed(uint8_t n);
|
||||
|
||||
|
@@ -12,7 +12,7 @@
|
||||
#define kParallelDataPort 0x3bc
|
||||
#define kParallelStatusPort 0x3bd
|
||||
#define kParallelControlPort 0x3be
|
||||
#define kParaDelay 400
|
||||
#define kParaDelay 100
|
||||
#define kRecvBufferSize 256
|
||||
|
||||
void dosdbt();
|
||||
@@ -51,15 +51,16 @@ static void __delay__(int n) {
|
||||
}
|
||||
}
|
||||
|
||||
uint8_t xferpara() {
|
||||
uint8_t mosib = paracomm_nextbyte();
|
||||
__outb__(kParallelDataPort, mosib);
|
||||
__outb__(kParallelControlPort, 1);
|
||||
__delay__(kParaDelay);
|
||||
__outb__(kParallelControlPort, 0);
|
||||
__delay__(kParaDelay);
|
||||
uint8_t mison = __inb__(kParallelStatusPort) >> 4;
|
||||
paracomm_feed(mison);
|
||||
uint8_t xferpara(uint8_t until_idle) {
|
||||
do {
|
||||
uint8_t mosib = paracomm_nextbyte();
|
||||
__outb__(kParallelDataPort, mosib);
|
||||
__outb__(kParallelControlPort, 1);
|
||||
__delay__(kParaDelay);
|
||||
__outb__(kParallelControlPort, 0);
|
||||
uint8_t mison = __inb__(kParallelStatusPort) >> 4;
|
||||
paracomm_feed(mison);
|
||||
} while (until_idle && paracomm_busy());
|
||||
|
||||
return paracomm_busy();
|
||||
}
|
||||
@@ -74,6 +75,23 @@ uint8_t parasend(uint8_t* addr, uint8_t size) {
|
||||
return i;
|
||||
}
|
||||
|
||||
uint8_t pararecv(uint8_t* buf, uint8_t size) {
|
||||
if (parasize == 0) {
|
||||
return 0;
|
||||
}
|
||||
if (size > parasize) {
|
||||
size = parasize;
|
||||
}
|
||||
memcpy(buf, parabuf, size);
|
||||
if (size < parasize) {
|
||||
memcpy(parabuf, parabuf+size, parasize - size);
|
||||
}
|
||||
parasize -= size;
|
||||
|
||||
return size;
|
||||
}
|
||||
|
||||
|
||||
int main() {
|
||||
dosdbt();
|
||||
parasize = 0;
|
||||
|
13
src/polio.s
13
src/polio.s
@@ -6,7 +6,7 @@
|
||||
.global _start
|
||||
_start:
|
||||
cli
|
||||
mov ax, 0x2000 # stack address
|
||||
mov ax, 0x2000 # stack address, shared with polmon
|
||||
mov sp, ax # ss should already be 0
|
||||
sti
|
||||
jmp main
|
||||
@@ -143,7 +143,7 @@ recvpara:
|
||||
mov ax, [bp+0]
|
||||
add ax, si
|
||||
mov dx, [bp+2]
|
||||
call paracomm_recv
|
||||
call pararecv
|
||||
ret
|
||||
|
||||
.section .text.int80h
|
||||
@@ -157,12 +157,11 @@ int80h:
|
||||
xor cx, cx
|
||||
mov es, cx
|
||||
mov ds, cx
|
||||
shl ah
|
||||
cmp ah, offset int80h_entries
|
||||
xchg ah, cl
|
||||
shl cl
|
||||
cmp cl, offset int80h_entries
|
||||
jge 0f
|
||||
mov al, ah
|
||||
xor ah, ah
|
||||
mov si, ax
|
||||
mov si, cx
|
||||
mov bp, sp
|
||||
lea bp, [bp + 16] # 10 for us, 6 for the interrupt
|
||||
call cs:[int80h_table+si]
|
||||
|
Reference in New Issue
Block a user