Skip to content

Commit

Permalink
mos_api.h updated with SYSVAR struct
Browse files Browse the repository at this point in the history
mos_api.h updated with SYSVAR struct
malloc demo / test added
VDU/VDP examples added as part of developing wrapper for VDP/VDU
  • Loading branch information
pcawte committed Jul 22, 2023
1 parent 4cb67f2 commit b41b627
Show file tree
Hide file tree
Showing 8 changed files with 332 additions and 21 deletions.
6 changes: 6 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,6 +270,12 @@ In the relevant: example, test or any other directory created at the same level.

- `README.md` updated to included documentation on VDP and VDU commands

- `mos_api.h` updated to include a structure for manipulating SYSVAR

- `tests/malloc` updated to demonstrate correct functioning of `malloc()`

- `tests/vdu` added to demonstrate use of VDU commands - part of developing VDP/VDU wrapper library

### To-Do:

- Testing / validation
Expand Down
75 changes: 57 additions & 18 deletions include/mos_api.h
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
* Title: AGON MOS - MOS c header interface
* Author: Jeroen Venema
* Created: 15/10/2022
* Last Updated: 15/10/2022
* Last Updated: 22/07/2023
*
* Modinfo:
* 15/10/2022: Added putch, getch
Expand All @@ -11,6 +11,8 @@
* 25/03/2023: Added MOS 1.03 functions / sysvars
* 16/04/2023: Added MOS 1.03RC4 mos_fread / mos_fwrite / mos_flseek functions
* 19/04/2023: Added mos_getfil
* 02/07/2023: Added struct / union for RTC_DATA
* 22/07/2023: Added structure for SYSVAR
*/

#ifndef _MOS_H
Expand Down Expand Up @@ -53,11 +55,9 @@ typedef enum {
FR_INVALID_PARAMETER /* (19) Given parameter is invalid */
} FRESULT;



// Indexes into sysvar - from mos_api.inc
#define sysvar_time 0x00 // 4: Clock timer in centiseconds (incremented by 2 every VBLANK)
#define sysvar_vpd_pflags 0x04 // 1: Flags to indicate completion of VDP commands
#define sysvar_vdp_pflags 0x04 // 1: Flags to indicate completion of VDP commands
#define sysvar_keyascii 0x05 // 1: ASCII keycode, or 0 if no key is pressed
#define sysvar_keymods 0x06 // 1: Keycode modifiers
#define sysvar_cursorX 0x07 // 1: Cursor X position
Expand Down Expand Up @@ -88,6 +88,59 @@ typedef enum {
#define vdp_pflag_mode 0x10
#define vdp_pflag_rtc 0x20

// Stucture / union for accessing RTC data

typedef union {
uint64_t rtc_data;
struct {
uint8_t year; // offset since 1980
uint8_t month; // (0-11)
uint8_t day; // (1-31)
uint8_t day_of_year; // (0-365) - *** but doesn't fit in 1 byte - wraps round ***
uint8_t day_of_week; // (0-6)
uint8_t hour; // (0-23)
uint8_t minute; // (0-59)
uint8_t second; // (0-59)
};
} RTC_DATA;

// Structure for accesing SYSVAR

typedef struct {
uint32_t time;
uint8_t vpd_pflags;
uint8_t keyascii;
uint8_t keymods;
uint8_t cursorX;
uint8_t cursorY;
uint8_t scrchar;
union {
uint24_t scrpixel;
struct {
uint8_t scrpixelR;
uint8_t scrpixelB;
uint8_t scrpixelG;
};
};
uint8_t audioChannel;
uint8_t audioSuccess;
uint16_t scrWidth;
uint16_t scrHeight;
uint8_t scrCols;
uint8_t scrRows;
uint8_t scrColours;
uint8_t scrpixelIndex;
uint8_t vkeycode;
uint8_t vkeydown;
uint8_t vkeycount;
RTC_DATA rtc;
uint16_t keydelay;
uint16_t keyrate;
uint8_t keyled;
uint8_t scrMode;
} SYSVAR;


// UART settings for open_UART1
typedef struct {
int24_t baudRate ; //!< The baudrate to be used.
Expand Down Expand Up @@ -120,20 +173,6 @@ typedef struct {
uint24_t* dir_ptr; /* Pointer to the directory entry in the win[] (not used at exFAT) */
} FIL;

typedef union {
uint64_t rtc_data;
struct {
uint8_t year; // offset since 1980
uint8_t month; // (0-11)
uint8_t day; // (1-31)
uint8_t day_of_year; // (0-365) - *** but doesn't fit in 1 byte - wraps round ***
uint8_t day_of_week; // (0-6)
uint8_t hour; // (0-23)
uint8_t minute; // (0-59)
uint8_t second; // (0-59)
};
} RTC_DATA;

// Generic IO
extern int putch(int a);
extern char getch(void);
Expand Down
4 changes: 4 additions & 0 deletions tests/malloc/makefile
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@
NAME = malloc
DESCRIPTION = "Ag C Toolchain Demo"
COMPRESSED = NO
LDHAS_ARG_PROCESSING = 0

BSSHEAP_LOW = 060000
BSSHEAP_HIGH = 09FFFF

CFLAGS = -Wall -Wextra -Oz
CXXFLAGS = -Wall -Wextra -Oz
Expand Down
10 changes: 7 additions & 3 deletions tests/malloc/src/malloc.c
Original file line number Diff line number Diff line change
Expand Up @@ -12,19 +12,23 @@

#include <stdio.h>
#include <stdlib.h>
#include <stdint.h>

const int N = 10;
const int N = 17;

extern HEADER _alloc_base;

int main(void)
{
printf("Malloc test\n\r");
printf( "Malloc test\n\n" );
printf( "_alloc_base.ptr %p, _alloc_base.size %d\n\n", _alloc_base.s.ptr, _alloc_base.s.size );

int size = 1;
void *ptr[N];

for (int i = 0; i < N; i++ ){
ptr[i] = malloc( size );
printf("Block %i, size %i, address %p\r\n", i, size, ptr[i] );
printf("Block %i, size %i, address %p\n", i, size, ptr[i] );
size *= 2;
}

Expand Down
18 changes: 18 additions & 0 deletions tests/vdu/makefile
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# ----------------------------
# Makefile Options
# ----------------------------

NAME = vdu
DESCRIPTION = "Ag C Toolchain Demo"
COMPRESSED = NO
LDHAS_ARG_PROCESSING = 0

BSSHEAP_LOW = 060000
BSSHEAP_HIGH = 09FFFF

CFLAGS = -Wall -Wextra -Oz
CXXFLAGS = -Wall -Wextra -Oz

# ----------------------------

include $(shell cedev-config --makefile)
Binary file added tests/vdu/src/img/parrot.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added tests/vdu/src/img/parrot.rgba
Binary file not shown.
Loading

0 comments on commit b41b627

Please sign in to comment.