Skip to content

Commit

Permalink
neo6502: Partially update API bindings, fix UExt functions, fix inden…
Browse files Browse the repository at this point in the history
…tation (#383)
  • Loading branch information
asiekierka authored Nov 15, 2024
1 parent 4fc7b2d commit 45c4385
Show file tree
Hide file tree
Showing 17 changed files with 368 additions and 86 deletions.
11 changes: 11 additions & 0 deletions mos-platform/neo6502/api/console.c
Original file line number Diff line number Diff line change
Expand Up @@ -92,3 +92,14 @@ void neo_console_set_text_color(uint8_t fg, uint8_t bg) {
ControlPort.params[1] = bg;
KSendMessage(API_GROUP_CONSOLE, API_FN_SET_TEXT_COLOR);
}

void neo_console_get_text_color(uint8_t *fg, uint8_t *bg) {
KSendMessageSync(API_GROUP_CONSOLE, API_FN_GET_TEXT_COLOR);
if (fg) *fg = ControlPort.params[0];
if (bg) *bg = ControlPort.params[1];
}

void neo_console_set_cursor_visibility(uint8_t value) {
ControlPort.params[0] = value;
KSendMessage(API_GROUP_CONSOLE, API_FN_SET_CURSOR_VISIBILITY);
}
12 changes: 11 additions & 1 deletion mos-platform/neo6502/api/controller.c
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,17 @@
#include "../neo6502.h"
#include "../kernel.h"

uint8_t neo_controller_read(void) {
uint8_t neo_controller_read_default(void) {
KSendMessageSync(API_GROUP_CONTROLLER, API_FN_READ_CONTROLLER);
return ControlPort.params[0];
}

uint8_t neo_controller_count(void) {
KSendMessageSync(API_GROUP_CONTROLLER, API_FN_READ_CONTROLLER_COUNT);
return ControlPort.params[0];
}

uint8_t neo_controller_read(uint8_t index) {
KSendMessageSync(API_GROUP_CONTROLLER, API_FN_READ_CONTROLLER2);
return *((uint32_t*) ControlPort.params);
}
12 changes: 12 additions & 0 deletions mos-platform/neo6502/api/file.c
Original file line number Diff line number Diff line change
Expand Up @@ -220,6 +220,18 @@ void neo_file_set_attr(const char *path, uint8_t attr) {
KWaitMessage();
}

bool neo_file_eof(uint8_t channel) {
ControlPort.params[0] = channel;
KSendMessageSync(API_GROUP_FILEIO, API_FN_FILE_CHECK_EOF);
return ControlPort.params[0] != 0;
}

void neo_file_get_cwd(char *buffer, uint8_t length) {
*((volatile uint16_t*) (ControlPort.params)) = (uint16_t) buffer;
ControlPort.params[2] = length;
KSendMessageSync(API_GROUP_FILEIO, API_FN_GET_CWD);
}

void neo_file_list_filtered_p(const neo_pstring_t *filter) {
*((volatile uint16_t*) (ControlPort.params)) = (uint16_t) filter;
KSendMessage(API_GROUP_FILEIO, API_FN_LIST_FILTERED);
Expand Down
11 changes: 9 additions & 2 deletions mos-platform/neo6502/api/graphics.c
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,13 @@ uint8_t neo_graphics_read_pixel(uint16_t x, uint16_t y) {
return ControlPort.params[0];
}

void neo_graphics_write_pixel(uint16_t x, uint16_t y, uint8_t idx) {
((volatile uint16_t*) ControlPort.params)[0] = x;
((volatile uint16_t*) ControlPort.params)[1] = y;
ControlPort.params[4] = idx;
KSendMessage(API_GROUP_GRAPHICS, API_FN_WRITE_PIXEL);
}

void neo_graphics_reset_palette(void) {
KSendMessage(API_GROUP_GRAPHICS, API_FN_RESET_PALETTE);
}
Expand All @@ -101,8 +108,8 @@ void neo_graphics_set_tilemap(const void *src, uint16_t x, uint16_t y) {
}

long neo_graphics_frame_count(void) {
KSendMessageSync(API_GROUP_GRAPHICS, API_FN_FRAME_COUNT);
return *((long*) ControlPort.params);
KSendMessageSync(API_GROUP_GRAPHICS, API_FN_FRAME_COUNT);
return *((long*) ControlPort.params);
}

void neo_graphics_set_color(uint8_t idx) {
Expand Down
13 changes: 13 additions & 0 deletions mos-platform/neo6502/api/neo/console.h
Original file line number Diff line number Diff line change
Expand Up @@ -130,6 +130,19 @@ void neo_console_clear_region(uint8_t x1, uint8_t y1, uint8_t x2, uint8_t y2);
*/
void neo_console_set_text_color(uint8_t fg, uint8_t bg);

/**
* @brief Fetch the text color.
*
* @param fg Foreground color.
* @param bg Background color.
*/
void neo_console_get_text_color(uint8_t *fg, uint8_t *bg);

/**
* @brief Set the cursor visibility.
*/
void neo_console_set_cursor_visibility(uint8_t value);

#ifdef __cplusplus
}
#endif
Expand Down
14 changes: 12 additions & 2 deletions mos-platform/neo6502/api/neo/controller.h
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,19 @@ extern "C" {
#endif

/**
* @brief Read the default controller's status.'
* @brief Read the default controller's status.
*/
uint8_t neo_controller_read(void);
uint8_t neo_controller_read_default(void);

/**
* @brief Read the connected controller count.
*/
uint8_t neo_controller_count(void);

/**
* @brief Read the specified controller's status.
*/
uint32_t neo_controller_read(uint8_t index);

#ifdef __cplusplus
}
Expand Down
75 changes: 61 additions & 14 deletions mos-platform/neo6502/api/neo/file.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,42 @@ typedef struct neo_file_stat {
uint8_t attr;
} neo_file_stat_t;

#define NEO_FILE_ATTR_DIRECTORY 0x01
#define NEO_FILE_ATTR_SYSTEM 0x02
#define NEO_FILE_ATTR_ARCHIVE 0x04
#define NEO_FILE_ATTR_READ_ONLY 0x08
#define NEO_FILE_ATTR_HIDDEN 0x10
#define NEO_FIOATTR_DIR 0x01
#define NEO_FIOATTR_SYSTEM 0x02
#define NEO_FIOATTR_ARCHIVE 0x04
#define NEO_FIOATTR_READONLY 0x08
#define NEO_FIOATTR_HIDDEN 0x10

#define NEO_FIOERROR_OK 0x00
#define NEO_FIOERROR_UNKNOWN 0x01
#define NEO_FIOERROR_EOF 0x02
#define NEO_FIOERROR_UNIMPLEMENTED 0x03
#define NEO_FIOERROR_NO_FILE 0x11
#define NEO_FIOERROR_NO_PATH 0x12
#define NEO_FIOERROR_INVALID_DRIVE 0x13
#define NEO_FIOERROR_INVALID_NAME 0x14
#define NEO_FIOERROR_INVALID_PARAMETER 0x15
#define NEO_FIOERROR_DENIED 0x21
#define NEO_FIOERROR_EXIST 0x22
#define NEO_FIOERROR_INVALID_OBJECT 0x23
#define NEO_FIOERROR_WRITE_PROTECTED 0x24
#define NEO_FIOERROR_LOCKED 0x25
#define NEO_FIOERROR_DISK_ERR 0x31
#define NEO_FIOERROR_INT_ERR 0x32
#define NEO_FIOERROR_NOT_READY 0x33
#define NEO_FIOERROR_NOT_ENABLED 0x34
#define NEO_FIOERROR_NO_FILESYSTEM 0x35
#define NEO_FIOERROR_MKFS_ABORTED 0x41
#define NEO_FIOERROR_TIMEOUT 0x42
#define NEO_FIOERROR_NOT_ENOUGH_CORE 0x43
#define NEO_FIOERROR_TOO_MANY_OPEN_FILES 0x44

// Legacy synonyms.
#define NEO_FILE_ATTR_DIRECTORY NEO_FIOATTR_DIR
#define NEO_FILE_ATTR_SYSTEM NEO_FIOATTR_SYSTEM
#define NEO_FILE_ATTR_ARCHIVE NEO_FIOATTR_ARCHIVE
#define NEO_FILE_ATTR_READ_ONLY NEO_FIOATTR_READONLY
#define NEO_FILE_ATTR_HIDDEN NEO_FIOATTR_HIDDEN

/**
* @brief Display the listing of files in the current directory.
Expand Down Expand Up @@ -89,7 +120,7 @@ void neo_file_store(const char *filename, const void *src, uint16_t len);
/**
* @brief Open a file channel, using a Pascal string for the filename.
*
* @param channel Channel ID
* @param channel File channel ID
* @param filename Filename (Pascal string)
* @param mode Mode @see neo_file_mode_t
*
Expand All @@ -100,7 +131,7 @@ void neo_file_open_p(uint8_t channel, const neo_pstring_t *filename, uint8_t mod
/**
* @brief Open a file channel, using a C string for the filename.
*
* @param channel Channel ID
* @param channel File channel ID
* @param filename Filename (C string)
* @param mode Mode @see neo_file_mode_t
*
Expand All @@ -111,7 +142,7 @@ void neo_file_open(uint8_t channel, const char *filename, uint8_t mode);
/**
* @brief Close a file channel.
*
* @param channel Channel ID
* @param channel File channel ID
*
* Check errors with @see neo_api_error
*/
Expand All @@ -120,7 +151,7 @@ void neo_file_close(uint8_t channel);
/**
* @brief Seek a file.
*
* @param channel Channel ID
* @param channel File channel ID
* @param pos New file position
*
* Check errors with @see neo_api_error
Expand All @@ -130,7 +161,7 @@ void neo_file_seek(uint8_t channel, uint32_t pos);
/**
* @brief Tell a file's position.
*
* @param channel Channel ID
* @param channel File channel ID
* @return Current file position
*
* Check errors with @see neo_api_error
Expand All @@ -142,7 +173,7 @@ uint32_t neo_file_tell(uint8_t channel);
*
* To read into graphics memory, use @see NEO_FILE_DESTINATION_GRAPHICS .
*
* @param channel Channel ID
* @param channel File channel ID
* @param dest Destination
* @param len Length, in bytes
* @return Amount of data actually read
Expand All @@ -154,7 +185,7 @@ uint16_t neo_file_read(uint8_t channel, void *dest, uint16_t len);
/**
* @brief Write bytes to an open file.
*
* @param channel Channel ID
* @param channel File channel ID
* @param src Source
* @param len Length, in bytes
* @return Amount of data actually written
Expand All @@ -166,7 +197,7 @@ uint32_t neo_file_write(uint8_t channel, const void *src, uint16_t len);
/**
* @brief Get the file's size, in bytes.
*
* @param channel Channel ID
* @param channel File channel ID
* @return File size, in bytes
*
* Check errors with @see neo_api_error
Expand All @@ -176,7 +207,7 @@ uint32_t neo_file_size(uint8_t channel);
/**
* @brief Set the file's size.
*
* @param channel Channel ID
* @param channel File channel ID
* @param size New file size, in bytes
*
* Check errors with @see neo_api_error
Expand Down Expand Up @@ -368,6 +399,22 @@ void neo_file_set_attr_p(const neo_pstring_t *path, uint8_t attr);
*/
void neo_file_set_attr(const char *path, uint8_t attr);

/**
* @brief Check if file is at end of file.
*
* @param channel File channel ID
* @return True if file is at end of file.
*/
bool neo_file_eof(uint8_t channel);

/**
* @brief Retrieve the current working directory.
*
* @param buffer Buffer to write the current working directory to.
* @param length Length of buffer, in bytes.
*/
void neo_file_get_cwd(char *buffer, uint8_t length);

/**
* @brief Display a filtered listing of files in the current directory, using a Pascal string for the needle.
*
Expand Down
9 changes: 9 additions & 0 deletions mos-platform/neo6502/api/neo/graphics.h
Original file line number Diff line number Diff line change
Expand Up @@ -114,6 +114,15 @@ void neo_graphics_set_palette(uint8_t idx, uint8_t r, uint8_t g, uint8_t b);
*/
uint8_t neo_graphics_read_pixel(uint16_t x, uint16_t y);

/**
* @brief Write pixel.
*
* @param x X
* @param y Y
* @param idx Palette index.
*/
void neo_graphics_write_pixel(uint16_t x, uint16_t y, uint8_t idx);

/**
* @brief Reset palette.
*/
Expand Down
5 changes: 5 additions & 0 deletions mos-platform/neo6502/api/neo/sound.h
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,11 @@ void neo_sound_play_effect(uint8_t channel, uint8_t id);
*/
uint8_t neo_sound_status(uint8_t channel);

/**
* @brief Query the number of channels.
*/
uint8_t neo_sound_channel_count(void);

#ifdef __cplusplus
}
#endif
Expand Down
18 changes: 18 additions & 0 deletions mos-platform/neo6502/api/neo/system.h
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,24 @@ void neo_system_locale(const char *locale);
__attribute__((leaf, noreturn))
void neo_system_reset(void);

/**
* @brief Write a character to the debug port.
*
* @param ch Character to write.
*/
void neo_system_debug_putc(char ch);

typedef struct neo_version {
uint8_t major, minor, patch;
} neo_version_t;

/**
* @brief Retrieve the Neo6502 version.
*
* @param version Pointer to neo_version_t structure.
*/
void neo_system_version(neo_version_t *version);

#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 5 additions & 0 deletions mos-platform/neo6502/api/neo/turtle.h
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ void neo_turtle_hide(void);
*/
void neo_turtle_home(void);

/**
* @brief Show the turtle.
*/
void neo_turtle_show(void);

#ifdef __cplusplus
}
#endif
Expand Down
36 changes: 36 additions & 0 deletions mos-platform/neo6502/api/neo/uext.h
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,42 @@ void neo_uext_spi_block_read(uint8_t device, void *dest, uint16_t len);
*/
void neo_uext_spi_block_write(uint8_t device, const void *src, uint16_t len);

/**
* @brief Read a block from an UART device.
*
* Check errors with @see neo_api_error
*/
void neo_uext_uart_block_read(uint8_t device, void *dest, uint16_t len);

/**
* @brief Write a block to an UART device.
*
* Check errors with @see neo_api_error
*/
void neo_uext_uart_block_write(uint8_t device, const void *src, uint16_t len);

#define NEO_UART_PROTOCOL_8N1 0

/**
* @brief Configure the UART baud rate and protocol.
*/
void neo_uext_uart_configure(uint32_t baudrate, uint8_t protocol);

/**
* @brief Write a byte to UART.
*/
void neo_uext_uart_write(uint8_t value);

/**
* @brief Read a byte from UART.
*/
uint8_t neo_uext_uart_read(void);

/**
* @brief Check if a byte can be read from UART.
*/
bool neo_uext_uart_available(void);

#ifdef __cplusplus
}
#endif
Expand Down
5 changes: 5 additions & 0 deletions mos-platform/neo6502/api/sound.c
Original file line number Diff line number Diff line change
Expand Up @@ -39,3 +39,8 @@ uint8_t neo_sound_status(uint8_t channel) {
KSendMessageSync(API_GROUP_SOUND, API_FN_SOUND_STATUS);
return ControlPort.params[0];
}

uint8_t neo_sound_channel_count(void) {
KSendMessageSync(API_GROUP_SOUND, API_FN_GET_CHANNEL_COUNT);
return ControlPort.params[0];
}
Loading

0 comments on commit 45c4385

Please sign in to comment.