Skip to content

Commit

Permalink
Merge pull request #521 from sneakywumpus/dev
Browse files Browse the repository at this point in the history
Re-format, boolify, fix message queue id bug in David McNaughton's code
  • Loading branch information
udo-munk authored Jan 19, 2025
2 parents 97ead60 + abc3c7b commit 8bad196
Show file tree
Hide file tree
Showing 17 changed files with 3,772 additions and 3,627 deletions.
42 changes: 21 additions & 21 deletions iodevices/cromemco-88ccc.c
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@
static const char *TAG = "88CCC";

/* 88CCC stuff */
static int state;
static bool state;
static WORD dma_addr;
static BYTE flags;
static BYTE format;
Expand Down Expand Up @@ -64,27 +64,28 @@ static void *store_image(void *arg)

while (state) { /* do until total frame is received */
if (net_device_alive(DEV_88ACC)) {

msg.auxiliary = flags & 0x0f;
msg.bias = (flags & 0x20) >> 5;
msg.fields = format & 0x0f;
msg.interval = (format & 0x30) >> 4;

msgB = format | (msg.bias << 6);

LOGD(TAG, "CCC/ACC Capture: to addr %04x, fields: %d, interval %d", dma_addr, msg.fields, msg.interval);
LOGD(TAG, "CCC/ACC Capture: to addr %04x, fields: %d, interval %d",
dma_addr, msg.fields, msg.interval);

net_device_send(DEV_88ACC, (char *)&msgB, sizeof(msgB));
net_device_send(DEV_88ACC, (char *) &msgB, sizeof(msgB));

for (i = 0; i < msg.fields; i++) {
len = net_device_get_data(DEV_88ACC, (char *) buffer, FIELDSIZE);
if (len != FIELDSIZE) {
LOGW(TAG,"Error in frame length, received %d of %d bytes.", len, FIELDSIZE);
LOGW(TAG, "Error in frame length, received %d of %d bytes.",
len, FIELDSIZE);
} else {
LOGD(TAG, "received frame %d, length %d, %d stored at %04x", i, len, (BYTE)*buffer, dma_addr + (i * FIELDSIZE));
for (j = 0; j < FIELDSIZE; j++) {
dma_write(dma_addr + (i * FIELDSIZE) + j, buffer[j]);
}
LOGD(TAG, "received frame %d, length %d, %d stored at %04x",
i, len, (BYTE) *buffer, dma_addr + (i * FIELDSIZE));
for (j = 0; j < FIELDSIZE; j++)
dma_write(dma_addr + i * FIELDSIZE + j, buffer[j]);
}
}
} else {
Expand All @@ -93,35 +94,34 @@ static void *store_image(void *arg)
}

/* frame done, calculate total frame time */
j = msg.fields * (msg.interval +1) * 2;
j = msg.fields * (msg.interval + 1) * 2;

/* sleep_for_ms(j); */

/* sleep rest of total frame time */
t2 = get_clock_us();
tdiff = t2 - t1;
if (tdiff < (j*1000))
sleep_for_ms(j - tdiff/1000);
if (tdiff < (j * 1000))
sleep_for_ms(j - tdiff / 1000);

LOGD(TAG, "Time: %d", tdiff);

state = 0;
state = false;
}

/* DMA complete, end the thread */
state = 0;
state = false;
thread = 0;
pthread_exit(NULL);
}

void cromemco_88ccc_ctrl_a_out(BYTE data)
{

flags = data & 0x7f;

if (data & 0x80) {
if (net_device_alive(DEV_88ACC)) {
state = 1;
state = true;

if (thread == 0) {
if (pthread_create(&thread, NULL, store_image, (void *) NULL)) {
Expand All @@ -134,11 +134,11 @@ void cromemco_88ccc_ctrl_a_out(BYTE data)
} else {
/* No 88ACC camera attached */
LOGW(TAG, "No Cromemeco Cyclops 88ACC attached.");
state = 0;
state = false;
}
} else {
if (state == 1) {
state = 0;
if (state) {
state = false;
sleep_for_ms(50); /* Arbitrary 50ms timeout to let
thread exit after state change,
TODO: maybe should end thread? */
Expand All @@ -154,13 +154,13 @@ void cromemco_88ccc_ctrl_b_out(BYTE data)
void cromemco_88ccc_ctrl_c_out(BYTE data)
{
/* get DMA address for storage memory */
dma_addr = (WORD)data << 7;
dma_addr = (WORD) data << 7;
}

BYTE cromemco_88ccc_ctrl_a_in(void)
{
/* return flags along with state in the msb */
return flags | (state << 7);
return flags | (state ? 128 : 0);
}

#endif /* HAS_NETSERVER && HAS_CYCLOPS */
4 changes: 2 additions & 2 deletions iodevices/cromemco-88ccc.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* cromemco-88ccc.h
*
*
* Emulation of the Cromemco 88 CCC - Cyclops Camera Controller
*
* Copyright (C) 2018 by David McNaughton
*
*
* History:
* 14-AUG-2018 1.0 Initial Release
* 04-NOV-2019 remove fake DMA bus request
Expand Down
42 changes: 20 additions & 22 deletions iodevices/cromemco-d+7a.c
Original file line number Diff line number Diff line change
Expand Up @@ -31,44 +31,42 @@ static BYTE inPort[PORT_COUNT];
static BYTE outPort[PORT_COUNT];

#ifdef HAS_NETSERVER
static void cromemco_d7a_callback(BYTE *data) {
static void cromemco_d7a_callback(BYTE *data)
{
int i;

int i;
inPort[0] = *data++;
for (i=1; i < PORT_COUNT; i++) {
inPort[i] = (*data++) - 128;
}
inPort[0] = *data++;
for (i = 1; i < PORT_COUNT; i++)
inPort[i] = (*data++) - 128;
}
#endif

void cromemco_d7a_init(void) {

inPort[0] = 0xFF;
void cromemco_d7a_init(void)
{
inPort[0] = 0xFF;

#ifdef HAS_NETSERVER
if (n_flag) {
net_device_service(DEV_D7AIO, cromemco_d7a_callback);
}
if (n_flag)
net_device_service(DEV_D7AIO, cromemco_d7a_callback);
#endif

}

static void cromemco_d7a_out(BYTE port, BYTE data)
{
outPort[port] = data;
outPort[port] = data;

LOGD(TAG, "Output %d on port %d", data, port);
LOGD(TAG, "Output %d on port %d", data, port);

#ifdef HAS_NETSERVER
if (n_flag) {
// if (net_device_alive(DEV_D7AIO)) {
net_device_send(DEV_D7AIO, (char *)&data, 1);
// }
}
if (n_flag) {
// if (net_device_alive(DEV_D7AIO)) {
net_device_send(DEV_D7AIO, (char *) &data, 1);
// }
}
#endif
}

void cromemco_d7a_D_out(BYTE data) { cromemco_d7a_out(0, data); }
void cromemco_d7a_D_out (BYTE data) { cromemco_d7a_out(0, data); }
void cromemco_d7a_A1_out(BYTE data) { cromemco_d7a_out(1, data); }
void cromemco_d7a_A2_out(BYTE data) { cromemco_d7a_out(2, data); }
void cromemco_d7a_A3_out(BYTE data) { cromemco_d7a_out(3, data); }
Expand All @@ -82,7 +80,7 @@ static BYTE cromemco_d7a_in(BYTE port)
return inPort[port];
}

BYTE cromemco_d7a_D_in(void) { return cromemco_d7a_in(0); };
BYTE cromemco_d7a_D_in (void) { return cromemco_d7a_in(0); };
BYTE cromemco_d7a_A1_in(void) { return cromemco_d7a_in(1); };
BYTE cromemco_d7a_A2_in(void) { return cromemco_d7a_in(2); };
BYTE cromemco_d7a_A3_in(void) { return cromemco_d7a_in(3); };
Expand Down
6 changes: 3 additions & 3 deletions iodevices/cromemco-d+7a.h
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
/**
* cromemco-d+7a.h
*
* Emulation of the Cromemco D+7A I/O
*
* Emulation of the Cromemco D+7A I/O
*
* Copyright (C) 2020 by David McNaughton
*
*
* History:
* 14-JAN-2020 1.0 Initial Release
*/
Expand Down
1 change: 1 addition & 0 deletions iodevices/cromemco-dazzler.c
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
#ifdef HAS_DAZZLER

#ifdef HAS_NETSERVER
#include <string.h>
#include "netsrv.h"
#endif

Expand Down
Loading

0 comments on commit 8bad196

Please sign in to comment.