polio: fix comms

This commit is contained in:
2025-10-03 23:27:27 +02:00
parent a55c7c47e0
commit 5bb49da246
4 changed files with 41 additions and 38 deletions

View File

@@ -22,6 +22,7 @@ static uint8_t miso_recvbuf[256];
static uint8_t miso_size; static uint8_t miso_size;
static uint8_t miso_received_nibbles; static uint8_t miso_received_nibbles;
static uint8_t miso_state; static uint8_t miso_state;
recv_cb miso_recv_cb;
static void swapbuffers() { static void swapbuffers() {
mosi_sendbuf = mosi_workbuf[mosi_workbuf_idx]; mosi_sendbuf = mosi_workbuf[mosi_workbuf_idx];
@@ -92,19 +93,21 @@ void paracomm_feed(uint8_t n) {
miso_received_nibbles += 1; miso_received_nibbles += 1;
if (miso_received_nibbles == 2 * miso_size) { if (miso_received_nibbles == 2 * miso_size) {
miso_recv_cb(miso_recvbuf, miso_size);
miso_state = 0; miso_state = 0;
} }
} break; } break;
} }
} }
void paracomm_init() { void paracomm_init(recv_cb miso_cb) {
mosi_size = 0; mosi_size = 0;
mosi_workbuf_idx = 0; mosi_workbuf_idx = 0;
mosi_workbuf_size = 0; mosi_workbuf_size = 0;
mosi_state = 0; mosi_state = 0;
miso_state = 0; miso_state = 0;
miso_recv_cb = miso_cb;
} }
int paracomm_send(uint8_t b) { int paracomm_send(uint8_t b) {
@@ -119,20 +122,6 @@ int paracomm_send(uint8_t b) {
return 0; 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() { uint8_t paracomm_busy() {
return mosi_state != 0 || miso_state != 0; return mosi_state != 0 || miso_state != 0;
} }

View File

@@ -2,19 +2,16 @@
#include <stdint.h> #include <stdint.h>
typedef void (*recv_cb)(const uint8_t* buf, uint8_t size);
/** Must call first **/ /** Must call first **/
void paracomm_init(); void paracomm_init(recv_cb cb);
/** Sends a single byte. /** Sends a single byte.
* Returns: 0 if no error, non-0 otherwise. * Returns: 0 if no error, non-0 otherwise.
*/ */
int paracomm_send(uint8_t b); 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 */ /** Call after reading a nibble from the port */
void paracomm_feed(uint8_t n); void paracomm_feed(uint8_t n);

View File

@@ -12,7 +12,7 @@
#define kParallelDataPort 0x3bc #define kParallelDataPort 0x3bc
#define kParallelStatusPort 0x3bd #define kParallelStatusPort 0x3bd
#define kParallelControlPort 0x3be #define kParallelControlPort 0x3be
#define kParaDelay 400 #define kParaDelay 100
#define kRecvBufferSize 256 #define kRecvBufferSize 256
void dosdbt(); void dosdbt();
@@ -51,15 +51,16 @@ static void __delay__(int n) {
} }
} }
uint8_t xferpara() { uint8_t xferpara(uint8_t until_idle) {
uint8_t mosib = paracomm_nextbyte(); do {
__outb__(kParallelDataPort, mosib); uint8_t mosib = paracomm_nextbyte();
__outb__(kParallelControlPort, 1); __outb__(kParallelDataPort, mosib);
__delay__(kParaDelay); __outb__(kParallelControlPort, 1);
__outb__(kParallelControlPort, 0); __delay__(kParaDelay);
__delay__(kParaDelay); __outb__(kParallelControlPort, 0);
uint8_t mison = __inb__(kParallelStatusPort) >> 4; uint8_t mison = __inb__(kParallelStatusPort) >> 4;
paracomm_feed(mison); paracomm_feed(mison);
} while (until_idle && paracomm_busy());
return paracomm_busy(); return paracomm_busy();
} }
@@ -74,6 +75,23 @@ uint8_t parasend(uint8_t* addr, uint8_t size) {
return i; 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() { int main() {
dosdbt(); dosdbt();
parasize = 0; parasize = 0;

View File

@@ -6,7 +6,7 @@
.global _start .global _start
_start: _start:
cli cli
mov ax, 0x2000 # stack address mov ax, 0x2000 # stack address, shared with polmon
mov sp, ax # ss should already be 0 mov sp, ax # ss should already be 0
sti sti
jmp main jmp main
@@ -143,7 +143,7 @@ recvpara:
mov ax, [bp+0] mov ax, [bp+0]
add ax, si add ax, si
mov dx, [bp+2] mov dx, [bp+2]
call paracomm_recv call pararecv
ret ret
.section .text.int80h .section .text.int80h
@@ -157,12 +157,11 @@ int80h:
xor cx, cx xor cx, cx
mov es, cx mov es, cx
mov ds, cx mov ds, cx
shl ah xchg ah, cl
cmp ah, offset int80h_entries shl cl
cmp cl, offset int80h_entries
jge 0f jge 0f
mov al, ah mov si, cx
xor ah, ah
mov si, ax
mov bp, sp mov bp, sp
lea bp, [bp + 16] # 10 for us, 6 for the interrupt lea bp, [bp + 16] # 10 for us, 6 for the interrupt
call cs:[int80h_table+si] call cs:[int80h_table+si]