Skip to content

Commit 45c4385

Browse files
authored
neo6502: Partially update API bindings, fix UExt functions, fix indentation (#383)
1 parent 4fc7b2d commit 45c4385

File tree

17 files changed

+368
-86
lines changed

17 files changed

+368
-86
lines changed

mos-platform/neo6502/api/console.c

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,3 +92,14 @@ void neo_console_set_text_color(uint8_t fg, uint8_t bg) {
9292
ControlPort.params[1] = bg;
9393
KSendMessage(API_GROUP_CONSOLE, API_FN_SET_TEXT_COLOR);
9494
}
95+
96+
void neo_console_get_text_color(uint8_t *fg, uint8_t *bg) {
97+
KSendMessageSync(API_GROUP_CONSOLE, API_FN_GET_TEXT_COLOR);
98+
if (fg) *fg = ControlPort.params[0];
99+
if (bg) *bg = ControlPort.params[1];
100+
}
101+
102+
void neo_console_set_cursor_visibility(uint8_t value) {
103+
ControlPort.params[0] = value;
104+
KSendMessage(API_GROUP_CONSOLE, API_FN_SET_CURSOR_VISIBILITY);
105+
}

mos-platform/neo6502/api/controller.c

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,17 @@
66
#include "../neo6502.h"
77
#include "../kernel.h"
88

9-
uint8_t neo_controller_read(void) {
9+
uint8_t neo_controller_read_default(void) {
1010
KSendMessageSync(API_GROUP_CONTROLLER, API_FN_READ_CONTROLLER);
1111
return ControlPort.params[0];
1212
}
13+
14+
uint8_t neo_controller_count(void) {
15+
KSendMessageSync(API_GROUP_CONTROLLER, API_FN_READ_CONTROLLER_COUNT);
16+
return ControlPort.params[0];
17+
}
18+
19+
uint8_t neo_controller_read(uint8_t index) {
20+
KSendMessageSync(API_GROUP_CONTROLLER, API_FN_READ_CONTROLLER2);
21+
return *((uint32_t*) ControlPort.params);
22+
}

mos-platform/neo6502/api/file.c

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -220,6 +220,18 @@ void neo_file_set_attr(const char *path, uint8_t attr) {
220220
KWaitMessage();
221221
}
222222

223+
bool neo_file_eof(uint8_t channel) {
224+
ControlPort.params[0] = channel;
225+
KSendMessageSync(API_GROUP_FILEIO, API_FN_FILE_CHECK_EOF);
226+
return ControlPort.params[0] != 0;
227+
}
228+
229+
void neo_file_get_cwd(char *buffer, uint8_t length) {
230+
*((volatile uint16_t*) (ControlPort.params)) = (uint16_t) buffer;
231+
ControlPort.params[2] = length;
232+
KSendMessageSync(API_GROUP_FILEIO, API_FN_GET_CWD);
233+
}
234+
223235
void neo_file_list_filtered_p(const neo_pstring_t *filter) {
224236
*((volatile uint16_t*) (ControlPort.params)) = (uint16_t) filter;
225237
KSendMessage(API_GROUP_FILEIO, API_FN_LIST_FILTERED);

mos-platform/neo6502/api/graphics.c

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -89,6 +89,13 @@ uint8_t neo_graphics_read_pixel(uint16_t x, uint16_t y) {
8989
return ControlPort.params[0];
9090
}
9191

92+
void neo_graphics_write_pixel(uint16_t x, uint16_t y, uint8_t idx) {
93+
((volatile uint16_t*) ControlPort.params)[0] = x;
94+
((volatile uint16_t*) ControlPort.params)[1] = y;
95+
ControlPort.params[4] = idx;
96+
KSendMessage(API_GROUP_GRAPHICS, API_FN_WRITE_PIXEL);
97+
}
98+
9299
void neo_graphics_reset_palette(void) {
93100
KSendMessage(API_GROUP_GRAPHICS, API_FN_RESET_PALETTE);
94101
}
@@ -101,8 +108,8 @@ void neo_graphics_set_tilemap(const void *src, uint16_t x, uint16_t y) {
101108
}
102109

103110
long neo_graphics_frame_count(void) {
104-
KSendMessageSync(API_GROUP_GRAPHICS, API_FN_FRAME_COUNT);
105-
return *((long*) ControlPort.params);
111+
KSendMessageSync(API_GROUP_GRAPHICS, API_FN_FRAME_COUNT);
112+
return *((long*) ControlPort.params);
106113
}
107114

108115
void neo_graphics_set_color(uint8_t idx) {

mos-platform/neo6502/api/neo/console.h

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,19 @@ void neo_console_clear_region(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
130130
*/
131131
void neo_console_set_text_color(uint8_t fg, uint8_t bg);
132132

133+
/**
134+
* @brief Fetch the text color.
135+
*
136+
* @param fg Foreground color.
137+
* @param bg Background color.
138+
*/
139+
void neo_console_get_text_color(uint8_t *fg, uint8_t *bg);
140+
141+
/**
142+
* @brief Set the cursor visibility.
143+
*/
144+
void neo_console_set_cursor_visibility(uint8_t value);
145+
133146
#ifdef __cplusplus
134147
}
135148
#endif

mos-platform/neo6502/api/neo/controller.h

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -15,9 +15,19 @@ extern "C" {
1515
#endif
1616

1717
/**
18-
* @brief Read the default controller's status.'
18+
* @brief Read the default controller's status.
1919
*/
20-
uint8_t neo_controller_read(void);
20+
uint8_t neo_controller_read_default(void);
21+
22+
/**
23+
* @brief Read the connected controller count.
24+
*/
25+
uint8_t neo_controller_count(void);
26+
27+
/**
28+
* @brief Read the specified controller's status.
29+
*/
30+
uint32_t neo_controller_read(uint8_t index);
2131

2232
#ifdef __cplusplus
2333
}

mos-platform/neo6502/api/neo/file.h

Lines changed: 61 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -29,11 +29,42 @@ typedef struct neo_file_stat {
2929
uint8_t attr;
3030
} neo_file_stat_t;
3131

32-
#define NEO_FILE_ATTR_DIRECTORY 0x01
33-
#define NEO_FILE_ATTR_SYSTEM 0x02
34-
#define NEO_FILE_ATTR_ARCHIVE 0x04
35-
#define NEO_FILE_ATTR_READ_ONLY 0x08
36-
#define NEO_FILE_ATTR_HIDDEN 0x10
32+
#define NEO_FIOATTR_DIR 0x01
33+
#define NEO_FIOATTR_SYSTEM 0x02
34+
#define NEO_FIOATTR_ARCHIVE 0x04
35+
#define NEO_FIOATTR_READONLY 0x08
36+
#define NEO_FIOATTR_HIDDEN 0x10
37+
38+
#define NEO_FIOERROR_OK 0x00
39+
#define NEO_FIOERROR_UNKNOWN 0x01
40+
#define NEO_FIOERROR_EOF 0x02
41+
#define NEO_FIOERROR_UNIMPLEMENTED 0x03
42+
#define NEO_FIOERROR_NO_FILE 0x11
43+
#define NEO_FIOERROR_NO_PATH 0x12
44+
#define NEO_FIOERROR_INVALID_DRIVE 0x13
45+
#define NEO_FIOERROR_INVALID_NAME 0x14
46+
#define NEO_FIOERROR_INVALID_PARAMETER 0x15
47+
#define NEO_FIOERROR_DENIED 0x21
48+
#define NEO_FIOERROR_EXIST 0x22
49+
#define NEO_FIOERROR_INVALID_OBJECT 0x23
50+
#define NEO_FIOERROR_WRITE_PROTECTED 0x24
51+
#define NEO_FIOERROR_LOCKED 0x25
52+
#define NEO_FIOERROR_DISK_ERR 0x31
53+
#define NEO_FIOERROR_INT_ERR 0x32
54+
#define NEO_FIOERROR_NOT_READY 0x33
55+
#define NEO_FIOERROR_NOT_ENABLED 0x34
56+
#define NEO_FIOERROR_NO_FILESYSTEM 0x35
57+
#define NEO_FIOERROR_MKFS_ABORTED 0x41
58+
#define NEO_FIOERROR_TIMEOUT 0x42
59+
#define NEO_FIOERROR_NOT_ENOUGH_CORE 0x43
60+
#define NEO_FIOERROR_TOO_MANY_OPEN_FILES 0x44
61+
62+
// Legacy synonyms.
63+
#define NEO_FILE_ATTR_DIRECTORY NEO_FIOATTR_DIR
64+
#define NEO_FILE_ATTR_SYSTEM NEO_FIOATTR_SYSTEM
65+
#define NEO_FILE_ATTR_ARCHIVE NEO_FIOATTR_ARCHIVE
66+
#define NEO_FILE_ATTR_READ_ONLY NEO_FIOATTR_READONLY
67+
#define NEO_FILE_ATTR_HIDDEN NEO_FIOATTR_HIDDEN
3768

3869
/**
3970
* @brief Display the listing of files in the current directory.
@@ -89,7 +120,7 @@ void neo_file_store(const char *filename, const void *src, uint16_t len);
89120
/**
90121
* @brief Open a file channel, using a Pascal string for the filename.
91122
*
92-
* @param channel Channel ID
123+
* @param channel File channel ID
93124
* @param filename Filename (Pascal string)
94125
* @param mode Mode @see neo_file_mode_t
95126
*
@@ -100,7 +131,7 @@ void neo_file_open_p(uint8_t channel, const neo_pstring_t *filename, uint8_t mod
100131
/**
101132
* @brief Open a file channel, using a C string for the filename.
102133
*
103-
* @param channel Channel ID
134+
* @param channel File channel ID
104135
* @param filename Filename (C string)
105136
* @param mode Mode @see neo_file_mode_t
106137
*
@@ -111,7 +142,7 @@ void neo_file_open(uint8_t channel, const char *filename, uint8_t mode);
111142
/**
112143
* @brief Close a file channel.
113144
*
114-
* @param channel Channel ID
145+
* @param channel File channel ID
115146
*
116147
* Check errors with @see neo_api_error
117148
*/
@@ -120,7 +151,7 @@ void neo_file_close(uint8_t channel);
120151
/**
121152
* @brief Seek a file.
122153
*
123-
* @param channel Channel ID
154+
* @param channel File channel ID
124155
* @param pos New file position
125156
*
126157
* Check errors with @see neo_api_error
@@ -130,7 +161,7 @@ void neo_file_seek(uint8_t channel, uint32_t pos);
130161
/**
131162
* @brief Tell a file's position.
132163
*
133-
* @param channel Channel ID
164+
* @param channel File channel ID
134165
* @return Current file position
135166
*
136167
* Check errors with @see neo_api_error
@@ -142,7 +173,7 @@ uint32_t neo_file_tell(uint8_t channel);
142173
*
143174
* To read into graphics memory, use @see NEO_FILE_DESTINATION_GRAPHICS .
144175
*
145-
* @param channel Channel ID
176+
* @param channel File channel ID
146177
* @param dest Destination
147178
* @param len Length, in bytes
148179
* @return Amount of data actually read
@@ -154,7 +185,7 @@ uint16_t neo_file_read(uint8_t channel, void *dest, uint16_t len);
154185
/**
155186
* @brief Write bytes to an open file.
156187
*
157-
* @param channel Channel ID
188+
* @param channel File channel ID
158189
* @param src Source
159190
* @param len Length, in bytes
160191
* @return Amount of data actually written
@@ -166,7 +197,7 @@ uint32_t neo_file_write(uint8_t channel, const void *src, uint16_t len);
166197
/**
167198
* @brief Get the file's size, in bytes.
168199
*
169-
* @param channel Channel ID
200+
* @param channel File channel ID
170201
* @return File size, in bytes
171202
*
172203
* Check errors with @see neo_api_error
@@ -176,7 +207,7 @@ uint32_t neo_file_size(uint8_t channel);
176207
/**
177208
* @brief Set the file's size.
178209
*
179-
* @param channel Channel ID
210+
* @param channel File channel ID
180211
* @param size New file size, in bytes
181212
*
182213
* Check errors with @see neo_api_error
@@ -368,6 +399,22 @@ void neo_file_set_attr_p(const neo_pstring_t *path, uint8_t attr);
368399
*/
369400
void neo_file_set_attr(const char *path, uint8_t attr);
370401

402+
/**
403+
* @brief Check if file is at end of file.
404+
*
405+
* @param channel File channel ID
406+
* @return True if file is at end of file.
407+
*/
408+
bool neo_file_eof(uint8_t channel);
409+
410+
/**
411+
* @brief Retrieve the current working directory.
412+
*
413+
* @param buffer Buffer to write the current working directory to.
414+
* @param length Length of buffer, in bytes.
415+
*/
416+
void neo_file_get_cwd(char *buffer, uint8_t length);
417+
371418
/**
372419
* @brief Display a filtered listing of files in the current directory, using a Pascal string for the needle.
373420
*

mos-platform/neo6502/api/neo/graphics.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -114,6 +114,15 @@ void neo_graphics_set_palette(uint8_t idx, uint8_t r, uint8_t g, uint8_t b);
114114
*/
115115
uint8_t neo_graphics_read_pixel(uint16_t x, uint16_t y);
116116

117+
/**
118+
* @brief Write pixel.
119+
*
120+
* @param x X
121+
* @param y Y
122+
* @param idx Palette index.
123+
*/
124+
void neo_graphics_write_pixel(uint16_t x, uint16_t y, uint8_t idx);
125+
117126
/**
118127
* @brief Reset palette.
119128
*/

mos-platform/neo6502/api/neo/sound.h

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,6 +53,11 @@ void neo_sound_play_effect(uint8_t channel, uint8_t id);
5353
*/
5454
uint8_t neo_sound_status(uint8_t channel);
5555

56+
/**
57+
* @brief Query the number of channels.
58+
*/
59+
uint8_t neo_sound_channel_count(void);
60+
5661
#ifdef __cplusplus
5762
}
5863
#endif

mos-platform/neo6502/api/neo/system.h

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,24 @@ void neo_system_locale(const char *locale);
5959
__attribute__((leaf, noreturn))
6060
void neo_system_reset(void);
6161

62+
/**
63+
* @brief Write a character to the debug port.
64+
*
65+
* @param ch Character to write.
66+
*/
67+
void neo_system_debug_putc(char ch);
68+
69+
typedef struct neo_version {
70+
uint8_t major, minor, patch;
71+
} neo_version_t;
72+
73+
/**
74+
* @brief Retrieve the Neo6502 version.
75+
*
76+
* @param version Pointer to neo_version_t structure.
77+
*/
78+
void neo_system_version(neo_version_t *version);
79+
6280
#ifdef __cplusplus
6381
}
6482
#endif

0 commit comments

Comments
 (0)