From 2ccb0f197c3a8bb7b69b9368517feda853cdd3cd Mon Sep 17 00:00:00 2001 From: Thomas Cherryhomes Date: Fri, 28 Jun 2024 19:56:34 -0500 Subject: [PATCH] [coco][fn_network] implement network_read_nb() for coco. --- common/src/fn_network/network_read_nb.c | 38 +++++++++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/common/src/fn_network/network_read_nb.c b/common/src/fn_network/network_read_nb.c index b95b7f3..92927da 100644 --- a/common/src/fn_network/network_read_nb.c +++ b/common/src/fn_network/network_read_nb.c @@ -1,5 +1,9 @@ #ifdef _CMOC_VERSION_ #include +#include +#include +#include +#include #else #include #include @@ -33,12 +37,19 @@ int16_t network_read_nb(char *devicespec, uint8_t *buf, uint16_t len) uint8_t unit = 0; #endif +#ifdef _CMOC_VERSION_ + uint8_t unit = 0; +#endif + if (len == 0 || buf == NULL) { #ifdef __ATARI__ return -fn_error(132); // invalid command #endif #ifdef __APPLE2__ return -fn_error(SP_ERR_BAD_CMD); +#endif +#ifdef _CMOC_VERSION_ + return -fn_error(132); // invalid command #endif } @@ -56,12 +67,20 @@ int16_t network_read_nb(char *devicespec, uint8_t *buf, uint16_t len) unit = network_unit(devicespec); #endif +#ifdef _CMOC_VERSION_ + unit = network_unit(devicespec); +#endif + #ifdef __ATARI__ r = network_status_unit(unit, &fn_network_bw, &fn_network_conn, &fn_network_error); #endif #ifdef __APPLE2__ r = network_status_no_clr(devicespec, &fn_network_bw, &fn_network_conn, &fn_network_error); #endif +#ifdef _CMOC_VERSION_ + r = network_status(devicespec, &fn_network_bw, &fn_network_conn, &fn_network_error); // TODO: fix return value +#endif + // check if the status failed if (r != 0) return -r; @@ -89,6 +108,25 @@ int16_t network_read_nb(char *devicespec, uint8_t *buf, uint16_t len) memcpy(buf, sp_payload, fetch_size); #endif +#ifdef _CMOC_VERSION_ + struct _r + { + uint8_t opcode; + uint8_t unit; + uint8_t cmd; + uint16_t len; + } rd; + + rd.opcode = OP_NET; + rd.unit = network_unit(devicespec); + rd.cmd = 'R'; + rd.len = fetch_size; + + bus_ready(); + dwwrite((uint8_t *)&rd, sizeof(rd)); + bus_get_response(OP_NET, (uint8_t *)buf, fetch_size); +#endif + fn_bytes_read = fetch_size; // reduce the bytes waiting count. if it hits 0, then we will need a new status, so clean status is then false.