Skip to content

Commit 1ac7749

Browse files
committed
[cbm][fuji] Refactor where cmd_args data is held and cmd set
1 parent 3793ee9 commit 1ac7749

File tree

4 files changed

+8
-15
lines changed

4 files changed

+8
-15
lines changed

commodore/src/fn_fuji/open_close.c

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

6-
extern uint8_t cmd_args[2];
7-
86
// no data to send in this version, it's just the command for immediate actions, no return data. we do query the status though.
97
bool open_close(uint8_t cmd)
108
{
11-
cmd_args[1] = cmd;
129
if (!open_or_write(cmd)) {
10+
// the current status is set for us as there was a critical error, so we just return false, and allow client to check the status.
1311
return false;
1412
}
1513

14+
// Data transfers etc were fine, but was the result of operation a success?
1615
return get_fuji_status(true);
1716
}

commodore/src/fn_fuji/open_close_data.c

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

6-
// All commands are <01><cmd>, we reuse this buffer to send all data, and only have to set 2nd byte
7-
uint8_t cmd_args[2] = { 0x01, 0x00 };
8-
96
// this is a command that has no return data, so just push command, its data, and read the status
107
bool open_close_data(uint8_t cmd, bool should_close, uint16_t params_size, uint8_t *cmd_params)
118
{
129
int bytes_written;
1310
bool is_success;
14-
cmd_args[1] = cmd;
1511

1612
if (!open_or_write(cmd)) {
1713
return false;
@@ -24,7 +20,6 @@ bool open_close_data(uint8_t cmd, bool should_close, uint16_t params_size, uint8
2420

2521
// we only use is_success if the write succeeded. We have to get the status either way.
2622
// so just store the is_success value and then decide whether to use it or not.
27-
// cbm_close(FUJI_CMD_CHANNEL);
2823
is_success = get_fuji_status(should_close);
2924

3025
if (bytes_written != params_size) {

commodore/src/fn_fuji/open_read_close.c

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

6-
extern char cmd_args[2];
6+
// All commands are <01><cmd>, we reuse this buffer to send all data, and only have to set 2nd byte
7+
uint8_t cmd_args[2] = { 0x01, 0x00 };
78

89
bool open_or_write(uint8_t cmd)
910
{
1011
int bytes_written;
1112
uint8_t err_code = 0;
13+
14+
cmd_args[1] = cmd;
1215
if (is_open) {
1316
// this is a continuation, so use the existing channel and write the data instead of
1417
bytes_written = cbm_write(FUJI_CMD_CHANNEL, cmd_args, 2);
@@ -33,7 +36,6 @@ bool open_or_write(uint8_t cmd)
3336
bool open_read_close(uint8_t cmd, bool should_close, int *bytes_read, uint16_t result_size, uint8_t *result_data)
3437
{
3538
int bytes_written;
36-
cmd_args[1] = cmd;
3739

3840
if (!open_or_write(cmd)) {
3941
*bytes_read = 0;

commodore/src/fn_fuji/open_read_close_data.c

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

6-
extern char cmd_args[2];
76
extern uint8_t __oserror;
87

98
// All the things, it has data to write with the command, and reads a value back, and a status
109
bool open_read_close_data(uint8_t cmd, bool should_close, int *bytes_read, uint16_t params_size, uint8_t *cmd_params, uint16_t result_size, uint8_t *result_data)
1110
{
1211
int bytes_written;
1312
bool is_success;
14-
cmd_args[1] = cmd;
1513

1614
if (!open_or_write(cmd)) {
1715
return false;
@@ -29,12 +27,11 @@ bool open_read_close_data(uint8_t cmd, bool should_close, int *bytes_read, uint1
2927
*bytes_read = cbm_read(FUJI_CMD_CHANNEL, result_data, result_size);
3028
}
3129

32-
// cbm_close(FUJI_CMD_CHANNEL);
3330
is_success = get_fuji_status(should_close);
3431

3532
if (bytes_written != params_size) {
36-
// failure sending command, e.g. wrong parameters sent. status string etc will be in _fuji_status
37-
// force a close if it wouldn't have happened in the status
33+
// Failure sending command, e.g. wrong parameters sent. status string etc will be in _fuji_status.
34+
// 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
3835
if (!should_close) cbm_close(FUJI_CMD_CHANNEL);
3936
is_open = false;
4037
return false;

0 commit comments

Comments
 (0)