Skip to content

Commit 3e0a8a3

Browse files
committed
add commodore network implementations
1 parent 910a1b3 commit 3e0a8a3

36 files changed

+443
-191
lines changed

atari/src/fn_fuji/fuji_appkey_open_read.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ bool fuji_read_appkey(uint8_t key_id, uint16_t *count, uint8_t *data)
3535
if (!buffer) return false;
3636

3737
open_data[0] = ak_creator_id & 0xFF;
38-
open_data[1] = (ak_creator_id >> 8) & 0xFF;
38+
open_data[1] = ak_creator_id >> 8;
3939
open_data[2] = ak_app_id;
4040
open_data[3] = key_id;
4141
open_data[4] = mode;

commodore/src/fn_fuji/fuji_data.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,4 +3,4 @@
33
#include "fujinet-fuji.h"
44

55
FNStatus _fuji_status;
6-
bool is_open = false;
6+
bool fuji_is_open = false;

commodore/src/fn_fuji/get_fuji_status.c

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
#include "fujinet-fuji.h"
55
#include "fujinet-fuji-cbm.h"
66

7+
// Use 0x, and NOT string literals to avoid CC65 charmap translations. These are bytes not chars.
78
uint8_t status_cmd[2] = { 0x01, 0x53 };
89

910
// An internal version of fuji_status called at the end of the open_ commands
@@ -18,18 +19,18 @@ bool get_fuji_status(bool should_close)
1819
memset(&_fuji_status.raw[0], 0, sizeof(FNStatus));
1920

2021
// do a status call to find out if anything went wrong. Using the current open channel, so just write our bytes
21-
bytes_written = cbm_write(FUJI_CMD_CHANNEL, status_cmd, 2);
22+
bytes_written = cbm_write(CBM_CMD_CHANNEL, status_cmd, 2);
2223
if (bytes_written != 2) {
2324
// always close on an error
24-
cbm_close(FUJI_CMD_CHANNEL);
25+
cbm_close(CBM_CMD_CHANNEL);
2526
status_error(ERROR_STATUS_FAILED_TO_WRITE, 0x53);
2627
return false;
2728
}
2829

29-
bytes_read = cbm_read(FUJI_CMD_CHANNEL, &_fuji_status.raw[0], sizeof(FNStatus));
30+
bytes_read = cbm_read(CBM_CMD_CHANNEL, &_fuji_status.raw[0], sizeof(FNStatus));
3031
if (should_close) {
31-
cbm_close(FUJI_CMD_CHANNEL);
32-
is_open = false;
32+
cbm_close(CBM_CMD_CHANNEL);
33+
fuji_is_open = false;
3334
}
3435

3536
// return true if the error is 0 (i.e. no error)

commodore/src/fn_fuji/open_close_data.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,10 @@ bool open_close_data(uint8_t cmd, bool should_close, uint16_t params_size, uint8
1313
return false;
1414
}
1515

16-
is_open = true;
16+
fuji_is_open = true;
1717

1818
// write the cmd parameters
19-
bytes_written = cbm_write(FUJI_CMD_CHANNEL, cmd_params, params_size);
19+
bytes_written = cbm_write(CBM_CMD_CHANNEL, cmd_params, params_size);
2020

2121
// we only use is_success if the write succeeded. We have to get the status either way.
2222
// so just store the is_success value and then decide whether to use it or not.
@@ -25,8 +25,8 @@ bool open_close_data(uint8_t cmd, bool should_close, uint16_t params_size, uint8
2525
if (bytes_written != params_size) {
2626
// write failed, this is an out and out failure. The _fuji_status values will hold error strings etc.
2727
// force a close if it wouldn't have happened in the status
28-
if (!should_close) cbm_close(FUJI_CMD_CHANNEL);
29-
is_open = false;
28+
if (!should_close) cbm_close(CBM_CMD_CHANNEL);
29+
fuji_is_open = false;
3030
return false;
3131
}
3232

commodore/src/fn_fuji/open_read_close.c

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#include "fujinet-fuji.h"
44
#include "fujinet-fuji-cbm.h"
55

6+
// Use 0x, and NOT string literals to avoid CC65 charmap translations. These are bytes not chars.
67
// All commands are <01><cmd>, we reuse this buffer to send all data, and only have to set 2nd byte
78
uint8_t cmd_args[2] = { 0x01, 0x00 };
89

@@ -12,21 +13,21 @@ bool open_or_write(uint8_t cmd)
1213
uint8_t err_code = 0;
1314

1415
cmd_args[1] = cmd;
15-
if (is_open) {
16+
if (fuji_is_open) {
1617
// this is a continuation, so use the existing channel and write the data instead of
17-
bytes_written = cbm_write(FUJI_CMD_CHANNEL, cmd_args, 2);
18+
bytes_written = cbm_write(CBM_CMD_CHANNEL, cmd_args, 2);
1819
if (bytes_written != 2) {
1920
err_code = ERROR_OPEN_WRITE_CMD_FAILED;
2021
}
2122
} else {
22-
if (fuji_cbm_open(FUJI_CMD_CHANNEL, FUJI_CBM_DEV, FUJI_CMD_CHANNEL, 2, cmd_args) != 0) {
23+
if (fuji_cbm_open(CBM_CMD_CHANNEL, CBM_DEV_FUJI, CBM_CMD_CHANNEL, 2, cmd_args) != 0) {
2324
err_code = ERROR_OPEN_CMD_FAILED;
2425
}
2526
}
2627
if (err_code != 0) {
2728
status_error(err_code, cmd);
28-
cbm_close(FUJI_CMD_CHANNEL);
29-
is_open = false;
29+
cbm_close(CBM_CMD_CHANNEL);
30+
fuji_is_open = false;
3031
return false;
3132
}
3233
return true;
@@ -42,6 +43,6 @@ bool open_read_close(uint8_t cmd, bool should_close, int *bytes_read, uint16_t r
4243
return false;
4344
}
4445

45-
*bytes_read = cbm_read(FUJI_CMD_CHANNEL, result_data, result_size);
46+
*bytes_read = cbm_read(CBM_CMD_CHANNEL, result_data, result_size);
4647
return get_fuji_status(should_close);
4748
}

commodore/src/fn_fuji/open_read_close_data.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -15,25 +15,25 @@ bool open_read_close_data(uint8_t cmd, bool should_close, int *bytes_read, uint1
1515
return false;
1616
}
1717

18-
is_open = true;
18+
fuji_is_open = true;
1919

20-
bytes_written = cbm_write(FUJI_CMD_CHANNEL, cmd_params, params_size);
20+
bytes_written = cbm_write(CBM_CMD_CHANNEL, cmd_params, params_size);
2121
if (bytes_written != params_size) {
2222
*bytes_read = 0;
2323
}
2424

2525
if (bytes_written == params_size) {
2626
// only do the read if the command data was sent successfully
27-
*bytes_read = cbm_read(FUJI_CMD_CHANNEL, result_data, result_size);
27+
*bytes_read = cbm_read(CBM_CMD_CHANNEL, result_data, result_size);
2828
}
2929

3030
is_success = get_fuji_status(should_close);
3131

3232
if (bytes_written != params_size) {
3333
// Failure sending command, e.g. wrong parameters sent. status string etc will be in _fuji_status.
3434
// Force a close if it wouldn't have happened in the status. We definitely want to close, but if "should_close" was false we need to manually do it here
35-
if (!should_close) cbm_close(FUJI_CMD_CHANNEL);
36-
is_open = false;
35+
if (!should_close) cbm_close(CBM_CMD_CHANNEL);
36+
fuji_is_open = false;
3737
return false;
3838
}
3939
return is_success;

commodore/src/fn_fuji/status_error.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,8 @@
44
#include "fujinet-fuji.h"
55
#include "fujinet-fuji-cbm.h"
66

7-
// 19 bytes, if you change this, change the define
7+
// 19 bytes, if you change this, change the define.
8+
// This will translate to PETSCII locally which is fine, as it is not transmit, but simply displayed on host
89
char *status_error_message = "status error";
910
#define STATUS_ERR_MESSAGE_LENGTH 12
1011

commodore/src/fn_network/fn_error.c

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,5 +4,6 @@
44

55
uint8_t fn_error(uint8_t code)
66
{
7+
// TODO: convert incoming CBM errors to FujiNet network type errors
78
return 0;
89
}
Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,20 @@
11
#include <stdbool.h>
22
#include <stdint.h>
33
#include "fujinet-network.h"
4+
#include "fujinet-network-cbm.h"
45

56
uint8_t network_close(char* devicespec)
67
{
7-
return 0;
8+
uint8_t device_number;
9+
const char *after;
10+
uint8_t data_channel = getDeviceNumber(devicespec, &after) + CBM_DATA_CHANNEL_0;
11+
12+
cbm_close(data_channel);
13+
network_num_channels_open--;
14+
15+
// if all open data connections are closed, also close the command channel
16+
if (network_num_channels_open == 0) {
17+
cbm_close(CBM_CMD_CHANNEL);
18+
}
19+
return FN_ERR_OK;
820
}
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
#include <stdbool.h>
2+
#include <stdint.h>
3+
#include "fujinet-fuji.h"
4+
5+
// bool network_is_open = false;
6+
uint8_t network_num_channels_open = 0;

0 commit comments

Comments
 (0)