From ed5f4e033f469c8a1176218bdd43361642168374 Mon Sep 17 00:00:00 2001 From: Steven Hugg Date: Tue, 19 Jun 2018 02:08:18 -0400 Subject: [PATCH] apple2 C pgms --- presets/apple2/sieve.c | 121 +++++++++++++++++++++++++++++++++++ presets/apple2/skeleton.cc65 | 15 +++++ src/platform/apple2.js | 8 ++- src/worker/workermain.js | 5 +- 4 files changed, 146 insertions(+), 3 deletions(-) create mode 100644 presets/apple2/sieve.c create mode 100644 presets/apple2/skeleton.cc65 diff --git a/presets/apple2/sieve.c b/presets/apple2/sieve.c new file mode 100644 index 00000000..78548ec3 --- /dev/null +++ b/presets/apple2/sieve.c @@ -0,0 +1,121 @@ +/* +** Calculate all primes up to a specific number. +*/ + + + +#include +#include +#include +#include +#include + + +/* Workaround missing clock stuff */ +#ifdef __APPLE2__ +# define clock() 0 +# define CLOCKS_PER_SEC 1 +#endif + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +#define COUNT 16384 /* Up to what number? */ +#define SQRT_COUNT 128 /* Sqrt of COUNT */ + +static unsigned char Sieve[COUNT]; + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +#pragma static-locals(1); + + + +static char ReadUpperKey (void) +/* Read a key from console, convert to upper case and return */ +{ + return toupper (cgetc ()); +} + + + +int main (void) +{ + /* Clock variable */ + clock_t Ticks; + unsigned int Sec; + unsigned int Milli; + + /* This is an example where register variables make sense */ + register unsigned char* S; + register unsigned I; + register unsigned J; + + /* Output a header */ + printf ("Sieve benchmark - calculating primes\n"); + printf ("between 2 and %u\n", COUNT); + printf ("Please wait patiently ...\n"); + + /* Read the clock */ + Ticks = clock(); + + /* Execute the sieve */ + I = 2; + while (I < SQRT_COUNT) { + if (Sieve[I] == 0) { + /* Prime number - mark multiples */ + J = I*2; + S = &Sieve[J]; + while (J < COUNT) { + *S = 1; + S += I; + J += I; + } + } + ++I; + } + + /* Calculate the time used */ + Ticks = clock() - Ticks; + Sec = (unsigned) (Ticks / CLOCKS_PER_SEC); + Milli = ((Ticks % CLOCKS_PER_SEC) * 1000) / CLOCKS_PER_SEC; + + /* Print the time used */ + printf ("Time used: %u.%03u seconds\n", Sec, Milli); + printf ("Q to quit, any other key for list\n"); + + /* Wait for a key and print the list if not 'Q' */ + if (ReadUpperKey () != 'Q') { + /* Print the result */ + J = 0; + for (I = 2; I < COUNT; ++I) { + if (Sieve[I] == 0) { + printf ("%4d\n", I); + if (++J == 23) { + printf ("Q to quit, any other key continues\n"); + if (ReadUpperKey () == 'Q') { + break; + } + J = 0; + } + } + if (kbhit() && ReadUpperKey () == 'Q') { + break; + } + } + } + + return EXIT_SUCCESS; +} + diff --git a/presets/apple2/skeleton.cc65 b/presets/apple2/skeleton.cc65 new file mode 100644 index 00000000..b3e4b33e --- /dev/null +++ b/presets/apple2/skeleton.cc65 @@ -0,0 +1,15 @@ + +#include +#include +#include +#include + +#pragma static-locals(1); + +int main (void) +{ + printf("\nHello! Press a key to reboot...\n"); + cgetc(); + return EXIT_SUCCESS; +} + diff --git a/src/platform/apple2.js b/src/platform/apple2.js index 2e7fc469..0e0edd47 100644 --- a/src/platform/apple2.js +++ b/src/platform/apple2.js @@ -1,6 +1,7 @@ "use strict"; var APPLE2_PRESETS = [ + {id:'sieve.c', name:'Sieve'}, ]; var GR_TXMODE = 1; @@ -19,8 +20,10 @@ var Apple2Platform = function(mainElement) { var kbdlatch = 0; var soundstate = 0; var pgmbin; - var VM_BASE = 0x6000; // where to JMP after pr#6 - var PGM_BASE = 0x6000; // where to load ROM + //var VM_BASE = 0x6000; // where to JMP after pr#6 + //var PGM_BASE = 0x6000; // where to load ROM + var VM_BASE = 0x803; // where to JMP after pr#6 + var PGM_BASE = 0x7ff; // where to load ROM // language card switches var auxRAMselected = false; var auxRAMbank = 1; @@ -965,6 +968,7 @@ var Apple2MAMEPlatform = function(mainElement) { this.start = function() { self.startModule(mainElement, { jsfile:'mameapple2e.js', + //biosfile:['apple2/'], //cfgfile:'nes.cfg', driver:'apple2e', width:256*2, diff --git a/src/worker/workermain.js b/src/worker/workermain.js index ccdf52fb..2c9f0c15 100644 --- a/src/worker/workermain.js +++ b/src/worker/workermain.js @@ -85,11 +85,13 @@ var PLATFORM_PARAMS = { define: '__APPLE2__', cfgfile: 'apple2.cfg', libargs: ['apple2.lib'], + code_offset: 0x803, // TODO }, 'apple2-e': { define: '__APPLE2__', cfgfile: 'apple2.cfg', libargs: ['apple2.lib'], + code_offset: 0x803, // TODO }, 'verilog': { }, @@ -593,10 +595,11 @@ function assemblelinkCA65(code, platform) { } var aout = FS.readFile("main", {encoding:'binary'}); var mapout = FS.readFile("main.map", {encoding:'utf8'}); + //console.log(mapout); var listing = parseCA65Listing(lstout, mapout); //console.log(lstout); //console.log(mapout); - var srclines = parseSourceLines(lstout, /[.]dbg\s+line, "main[.]c", (\d+)/i, /^\s*([0-9A-F]+)r/i); + var srclines = parseSourceLines(lstout, /[.]dbg\s+line, "main[.]c", (\d+)/i, /^\s*([0-9A-F]+)r/i, params.code_offset); return { output:aout.slice(0), lines:listing.lines,