Skip to content

Commit

Permalink
Cx16 kernal support (#131)
Browse files Browse the repository at this point in the history
* use void* vs unsigned int

* update cx16 kernal and add cbm kernal globals

* fix uint64_t printf warning

* add cx16 kernal wrappers and headers

* WIP cx16 kernal wrappers

* add kernal routine CINT

* rework for new llvm reg layout, needs more testing

* Squashed commit of the following:

commit f0b30a6
Author: Adrian Siekierka <[email protected]>
Date:   Sun Jun 25 08:05:43 2023 +0200

    Update README.md to list all currently supported platforms

commit d3caa19
Author: Adrian Siekierka <[email protected]>
Date:   Sat Jun 24 22:53:36 2023 +0200

    [PCE] Fix issues.

commit 2b05b08
Author: Adrian Siekierka <[email protected]>
Date:   Sat Jun 24 22:35:24 2023 +0200

    [PCE] Remove pce_memcpy/pce_memmove/pce_memset first pass implementations.

    They are not suitable as a general replacement for memcpy/memmove/memset, as
    they stall interrupts while they are being executed.

    These can be reinstated in a separate PR, once the best way to expose this
    to the end user is evaluated.

commit 6dd6af1
Author: Adrian Siekierka <[email protected]>
Date:   Sat Jun 24 22:27:50 2023 +0200

    [PCE] Downgrade virtual bank system to a much less complex physical bank offset mapping system.

commit 5763cf6
Author: Adrian Siekierka <[email protected]>
Date:   Sat Jun 24 14:31:28 2023 +0200

    [PCE] Fix typo.

commit 82d1ee7
Author: Adrian Siekierka <[email protected]>
Date:   Sat Jun 24 14:22:09 2023 +0200

    [PCE] Add pce_sgx_detect().

commit 8e38046
Author: Adrian Siekierka <[email protected]>
Date:   Sat Jun 24 11:14:40 2023 +0200

    [PCE] Add PCE_FREQ_TO_TIMER define, fully derive its origin.

commit f176029
Author: Adrian Siekierka <[email protected]>
Date:   Sat Jun 24 11:04:19 2023 +0200

    [PCE] Add missing newlines.

commit eb8c933
Author: Adrian Siekierka <[email protected]>
Date:   Thu Jun 22 23:24:00 2023 +0200

    [PCE] Fix pce_rom_vbankN_call safety.

commit 71876fc
Author: Adrian Siekierka <[email protected]>
Date:   Thu Jun 22 20:55:58 2023 +0200

    [PCE] Add pce_rom_vbankN_bank getter

commit 5e74a93
Author: Adrian Siekierka <[email protected]>
Date:   Wed Jun 21 22:17:52 2023 +0200

    [PCE] Fix set_resolution optimization regression, add pce_sgx_vdc_init

commit 101d0bc
Author: Adrian Siekierka <[email protected]>
Date:   Wed Jun 21 21:58:37 2023 +0200

    [PCE] Add support for two VDCs in vdc.c.

commit dbd398e
Author: Adrian Siekierka <[email protected]>
Date:   Wed Jun 21 21:39:30 2023 +0200

    [PCE] Add SuperGrafx MMIO defines.

commit d61c0a5
Author: Adrian Siekierka <[email protected]>
Date:   Wed Jun 21 18:10:36 2023 +0200

    [PCE] Adjust color-cycle.c example to use interrupts.

commit b802a2c
Author: Adrian Siekierka <[email protected]>
Date:   Wed Jun 21 17:37:41 2023 +0200

    [PCE] Finish writing initial VDC functions.

commit 07e4b21
Author: Adrian Siekierka <[email protected]>
Date:   Wed Jun 21 17:17:06 2023 +0200

    [PCE] Bugfixes, add VDC/VCE/PSG reset routines.

commit dabf4c8
Author: Adrian Siekierka <[email protected]>
Date:   Wed Jun 21 16:48:29 2023 +0200

    [PCE] Further unify VBank naming conventions.

commit 3f9a307
Author: Adrian Siekierka <[email protected]>
Date:   Wed Jun 21 01:03:59 2023 +0200

    [PCE] Implement VDC enable/disable routines, fixes.

commit 5ddc148
Author: Adrian Siekierka <[email protected]>
Date:   Wed Jun 21 00:17:30 2023 +0200

    [PCE] Implement VDC/VCE copy routines.

commit c8f201a
Author: Adrian Siekierka <[email protected]>
Date:   Tue Jun 20 22:01:05 2023 +0200

    [PCE] Add pce_memop, minor cleanup.

commit bc2bf2f
Author: Adrian Siekierka <[email protected]>
Date:   Tue Jun 20 20:50:05 2023 +0200

    [PCE] Add VDC resolution configuration functions, PCE_ROM_FIXED_BANK_SIZE define

commit cc36ab5
Author: Adrian Siekierka <[email protected]>
Date:   Tue Jun 20 19:00:21 2023 +0200

    [PCE] Fix hardware stack init regression.

commit 7e9981b
Author: Adrian Siekierka <[email protected]>
Date:   Tue Jun 20 18:58:18 2023 +0200

    [PCE] Implement optimized zero-bss handlers.

commit 4af4ac9
Author: Adrian Siekierka <[email protected]>
Date:   Tue Jun 20 18:33:32 2023 +0200

    [PCE] Support changing the size of virtual bank 0.

commit 6f32c9e
Author: Adrian Siekierka <[email protected]>
Date:   Mon Jun 19 22:46:18 2023 +0200

    [PCE] Add optimized memcpy/memmove/memset implementations.

commit 7fd8bca
Author: Adrian Siekierka <[email protected]>
Date:   Mon Jun 19 20:38:00 2023 +0200

    [PCE] Document libpce functions.

commit 6d91920
Author: Adrian Siekierka <[email protected]>
Date:   Mon Jun 19 20:18:41 2023 +0200

    [PCE] Add Arcade Card and Super System Card hardware defines.

commit 864f1a7
Author: Adrian Siekierka <[email protected]>
Date:   Mon Jun 19 19:54:02 2023 +0200

    [PCE] Add to README.

commit 06c447d
Author: Adrian Siekierka <[email protected]>
Date:   Mon Jun 19 19:18:27 2023 +0200

    [PCE] Fix banking example.

commit a343c94
Author: Adrian Siekierka <[email protected]>
Date:   Mon Jun 19 18:53:59 2023 +0200

    [PCE] vbank system refactors, add support for SGX RAM

commit 673b243
Author: Adrian Siekierka <[email protected]>
Date:   Sun Jun 18 23:24:32 2023 +0200

    [PCE] Initial interrupt implementation.

commit f2d4373
Author: Adrian Siekierka <[email protected]>
Date:   Sun Jun 18 22:34:21 2023 +0200

    [PCE] Fix soft stack location.

commit 9116694
Author: Adrian Siekierka <[email protected]>
Date:   Sun Jun 18 21:51:57 2023 +0200

    [PCE] Adjust linkscript symbol convention to match NES target

commit bf1618f
Author: Adrian Siekierka <[email protected]>
Date:   Sun Jun 18 20:17:33 2023 +0200

    [PCE] Adjust linkscript symbols for llvm-mlb.

commit 9acebcf
Author: Adrian Siekierka <[email protected]>
Date:   Sun Jun 18 18:10:01 2023 +0200

    [PCE] Add pce_vbank_call helper routines.

commit 0d05f4d
Author: Adrian Siekierka <[email protected]>
Date:   Sun Jun 18 15:48:59 2023 +0200

    [PCE] Clean up bank.h/.c/.S after figuring out the banking system.

commit 33566e1
Author: Adrian Siekierka <[email protected]>
Date:   Sun Jun 18 15:41:05 2023 +0200

    [PCE] Optimize vbank_set for 8KB vbanks, fix PCE_VBANK_DECLARE for >8KB vbanks.

commit 3aed2ec
Author: Adrian Siekierka <[email protected]>
Date:   Sun Jun 18 15:22:28 2023 +0200

    [PCE] Banking improvements.

    - Provide missing one-bank getters and setters.
    - Use C where using ASM provides no "bank chain" size advantage to allow for
      inlining opportunities.

commit 219b83c
Author: Adrian Siekierka <[email protected]>
Date:   Sun Jun 18 15:03:05 2023 +0200

    [PCE] Introduce banking system.

commit fb2f650
Author: Adrian Siekierka <[email protected]>
Date:   Sun Jun 18 12:35:15 2023 +0200

    Initial pce (PC Engine) platform.

    Banking is not yet implemented, so limited to eight-kilobyte ROMs.
    This will be improved soon...

* working nicely saving extra regs per X16 docs

* new funcs, cc65 funcs, new tests, some debugging

* spelling fix, consistent license comments

* Cleanup PR

* Revert erroneous PCE changes

* Merge branch 'main' into cx16_kernal_support

---------

Co-authored-by: Xark <[email protected]>
Co-authored-by: Daniel Thornburgh <[email protected]>
  • Loading branch information
3 people authored Jul 4, 2023
1 parent fdb1bd0 commit 37bde1b
Show file tree
Hide file tree
Showing 92 changed files with 2,430 additions and 51 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,2 +1,3 @@
llvm-mos-sdk.code-workspace
.vscode
build
3 changes: 3 additions & 0 deletions examples/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -36,3 +36,6 @@ endif()
if(PLATFORM MATCHES rpc8e)
add_subdirectory(rpc8e)
endif()
if(PLATFORM MATCHES ^cx16)
add_subdirectory(cx16)
endif()
11 changes: 11 additions & 0 deletions examples/cx16/CMakeLists.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
add_executable(k_console_test.prg k_console_test.c)
install_example(k_console_test.prg)

add_executable(k_datetime_test.prg k_datetime_test.c)
install_example(k_datetime_test.prg)

add_executable(k_graph_test.prg k_graph_test.c)
install_example(k_graph_test.prg)

add_executable(k_graph_line_test.prg k_graph_line_test.c)
install_example(k_graph_line_test.prg)
54 changes: 54 additions & 0 deletions examples/cx16/k_console_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
// llvm-mos-sdk cx16 kernel test
//
// vim: set et ts=4 sw=4

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

#include <cbm.h>
#include <cx16.h>

unsigned char face[64] = {
1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 0, 0, 0, 0, 1, 1,
1, 0, 1, 0, 0, 1, 0, 1,
1, 0, 0, 0, 0, 0, 0, 1,
1, 0, 1, 0, 0, 1, 0, 1,
1, 0, 0, 1, 1, 0, 0, 1,
1, 1, 0, 0, 0, 0, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1
};

void wait_key(void)
{
while (cbm_k_getin() == 0)
;
}

void console_puts(const char *str, unsigned char wordwrap)
{
uint8_t c = 0;
while ((c = *str++) != 0)
{
cx16_k_console_put_char(c, wordwrap);
}
}

int main(void)
{
cx16_k_screen_mode_set(128);
cx16_k_graph_set_colors(1, 0, 0);
cx16_k_console_init(0, 0, 0, 0);
console_puts("\x92Hello Commander X16!", 0);

wait_key();

// BUG: I don't understand why this clears/scrolls screen...
cx16_k_console_put_image(face, 8, 8);

wait_key();

cx16_k_screen_mode_set(0);
printf("DONE.\n");
}
70 changes: 70 additions & 0 deletions examples/cx16/k_datetime_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,70 @@
// llvm-mos-sdk cx16 kernel test
//
// vim: set et ts=4 sw=4

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

#include <cbm.h>
#include <cx16.h>

static void hexdump(const void *ptr, size_t bytes)
{
uint8_t *p = (uint8_t *)ptr;
for (size_t i = 0; i < bytes; i++)
{
if ((i & 0xf) == 0)
{
if (i)
{
printf("\n");
}
printf("%04x: ", i);
}
else
{
printf(", ");
}
printf("%02x", p[i]);
}
printf("\n");
}

int main(void)
{
static cx16_date_time_t tm;

putchar(15); // ISO mode
printf("llvm-mos-sdk CX16 Kernal Test\n\n");

printf("\ncx16_k_clock_get_date_time(&tm);\n");
cx16_k_clock_get_date_time(&tm);

printf("Result: year=%d, mon=%d, day=%d, hour=%d, min=%d, sec=%d, jif=%d\n",
1900 + tm.year,
tm.mon,
tm.day,
tm.hour,
tm.min,
tm.sec,
tm.jif);
hexdump(&tm, sizeof(tm));

printf("\ncx16_k_clock_set_date_time(2023-1900, 4, 5, 10, 12, 13, 42);\n");
cx16_k_clock_set_date_time(2023 - 1900, 4, 5, 10, 12, 13, 42);

cx16_k_clock_get_date_time(&tm);

printf("Result: year=%d, mon=%d, day=%d, hour=%d, min=%d, sec=%d, jif=%d\n",
1900 + tm.year,
tm.mon,
tm.day,
tm.hour,
tm.min,
tm.sec,
tm.jif);
hexdump(&tm, sizeof(tm));

printf("Done\n"); // finished
}
37 changes: 37 additions & 0 deletions examples/cx16/k_graph_line_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
// llvm-mos-sdk cx16 kernel test
//
// vim: set et ts=4 sw=4

#include <stddef.h>
#include <stdint.h>

#include <cbm.h>
#include <cx16.h>

int main(void)
{
int16_t x, y;
uint8_t c;

cx16_k_screen_mode_set(128); // 320x240x8-bpp
cx16_k_graph_init(NULL); // initialize kernal graph with defaults
c = 0; // initialize color

// draw line pattern
for (y = 0; y < 240; y += 3)
{
cx16_k_graph_set_colors(c++, 0, 0);
cx16_k_graph_draw_line(0, y, 319, 239 - y);
}

for (x = 0; x < 320; x += 3)
{
cx16_k_graph_set_colors(c++, 0, 0);
cx16_k_graph_draw_line(x, 0, 319 - x, y);
}

while (cbm_k_getin() == 0) // wait for a keypress
;

cx16_k_screen_mode_set(0); // reset screen mode to 80x30
}
129 changes: 129 additions & 0 deletions examples/cx16/k_graph_test.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
// llvm-mos-sdk cx16 kernel test
//
// vim: set et ts=4 sw=4

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

#include <cbm.h>
#include <cx16.h>

unsigned char face[64] = {1, 1, 1, 1, 1, 1, 1, 1,
1, 1, 0, 0, 0, 0, 1, 1,
1, 0, 5, 0, 0, 5, 0, 1,
1, 0, 0, 0, 0, 0, 0, 1,
1, 0, 1, 0, 0, 1, 0, 1,
1, 0, 0, 1, 1, 0, 0, 1,
1, 1, 0, 0, 0, 0, 1, 1,
1, 1, 1, 1, 1, 1, 1, 1
};

void wait_key(void)
{
while (cbm_k_getin() == 0)
;
}

void graph_put_string(unsigned int x, unsigned int y, const char *str)
{
graph_pos_t pos;
pos.x = x;
pos.y = y;
uint8_t c = 0;
while ((c = *str++) != 0)
{
cx16_k_graph_put_char(&pos, c);
}
}

int main(void)
{
uint8_t scolor = 1; // stroke color
int16_t xpos = 160, ypos = 120; // initial face position
int8_t xd = 1; // initial face direction

// set 320x240x8-bpp
cx16_k_screen_mode_set(128);

// init default graphics driver
cx16_k_graph_init(0);

// default font
cx16_k_graph_set_font(0);

// draw outline box
cx16_k_graph_set_colors(4, 0, 0);
cx16_k_graph_draw_line(10, 10, 320 - 10, 10);
cx16_k_graph_draw_line(320 - 10, 10, 320 - 10, 240 - 10);
cx16_k_graph_draw_line(320 - 10, 240 - 10, 10, 240 - 10);
cx16_k_graph_draw_line(10, 240 - 10, 10, 10);

// welcome message
cx16_k_graph_set_colors(0, 0, 0);
graph_put_string(75, 20, "Hello Commander X16 and llvm-mos!\n\n Basic cx16_k_graph* wrapper test...");

// window clipping test
cx16_k_graph_set_window(0, 0, 320 / 2, 240);
cx16_k_graph_set_colors(4, 0, 0);
graph_put_string(50, 60, "This text is using clipping to draw in two colors.");
cx16_k_graph_set_window(320 / 2, 0, 320 / 2, 240);
cx16_k_graph_set_colors(5, 0, 0);
graph_put_string(50, 60, "This text is using clipping to draw in two colors.");

// full screen window
cx16_k_graph_set_window(0, 0, 0, 0);

// draw outline rectangle
cx16_k_graph_set_colors(6, 0, 0);
cx16_k_graph_draw_rect(50, 50, 42, 14, 0, 0);
// move (copy) rectangle
cx16_k_graph_move_rect(50, 50, 65, 65, 42, 15);

// label moved rectangle
cx16_k_graph_set_colors(0, 0, 0);
graph_put_string(110, 75, "<- rectangle moved here");

// stop message
graph_put_string(110, 240 - 20, "Press a key to stop");

// until a key is pressed, bounce face and rectangle
while (cbm_k_getin() == 0)
{
// draw 8x8 "face" image
cx16_k_graph_draw_image(xpos, ypos, face, 8, 8);

// update x position
xpos += xd;

// if near edges, reverse direction
if (xpos < 64 || xpos > 320 - 64)
{
xd = -xd;
}

// draw filled rectangle offset from face using incrementing color
scolor += 1;
cx16_k_graph_set_colors(scolor, scolor + 1, 0);
cx16_k_graph_draw_rect(xpos - 12, ypos + 20, 8, 16, 0, 1);

waitvsync();
}

// erase old message
cx16_k_graph_set_colors(1, 1, 1);
cx16_k_graph_draw_rect(20, 240 - 20 - 10, 280, 20, 0, 1);

// exit message
cx16_k_graph_set_colors(0, 0, 0);
graph_put_string(110, 240 - 20, "Press a key to exit");

// wait for final key press
wait_key();

// restore 80x60 text mode
cx16_k_screen_mode_set(0);

// done message
printf("DONE.\n");
}
2 changes: 1 addition & 1 deletion mos-platform/atari8-common/atari.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
// information.

// Originally from cc65. Modififed from original version.
// Originally from cc65. Modified from original version.

/*****************************************************************************/
/* */
Expand Down
2 changes: 1 addition & 1 deletion mos-platform/c64/c64.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
// information.

// Originally from cc65. Modififed from original version.
// Originally from cc65. Modified from original version.

/*****************************************************************************/
/* */
Expand Down
3 changes: 2 additions & 1 deletion mos-platform/commodore/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,8 @@ add_platform_library(commodore-c
cbm_k_chkin.s
cbm_k_chrin.c
cbm_k_chrout.c
cbm_k_ciout.c
cbm_k_cint.c
cbm_k_ciout.c
cbm_k_ckout.s
cbm_k_clall.c
cbm_k_close.c
Expand Down
7 changes: 4 additions & 3 deletions mos-platform/commodore/cbm.h
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
// See https://github.com/llvm-mos/llvm-mos-sdk/blob/main/LICENSE for license
// information.

// Originally from cc65. Modififed from original version.
// Originally from cc65. Modified from original version.

/*****************************************************************************/
/* */
Expand Down Expand Up @@ -206,6 +206,7 @@ void cbm_k_bsout (unsigned char C);
unsigned char cbm_k_chkin (unsigned char FN);
unsigned char cbm_k_chrin (void);
void cbm_k_chrout (unsigned char C);
void cbm_k_cint (void);
void cbm_k_ciout (unsigned char C);
unsigned char cbm_k_ckout (unsigned char FN);
void cbm_k_clall (void);
Expand All @@ -214,10 +215,10 @@ void cbm_k_clrch (void);
unsigned char cbm_k_getin (void);
unsigned cbm_k_iobase (void);
void cbm_k_listen (unsigned char dev);
unsigned int cbm_k_load(unsigned char flag, unsigned addr);
void *cbm_k_load(unsigned char flag, void *startaddr);
unsigned char cbm_k_open (void);
unsigned char cbm_k_readst (void);
unsigned char cbm_k_save(unsigned int start, unsigned int end);
unsigned char cbm_k_save(void *startaddr, void *endaddr_plusone);
void cbm_k_scnkey (void);
void cbm_k_second (unsigned char addr);
void cbm_k_setlfs (unsigned char LFN, unsigned char DEV,
Expand Down
5 changes: 5 additions & 0 deletions mos-platform/commodore/cbm_k_cint.c
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
extern void __CINT(void);

void cbm_k_cint(void) {
__CINT();
}
Loading

0 comments on commit 37bde1b

Please sign in to comment.