Available for Download from the following Link:
http://www.aztecmuseum.ca/extras/REALTIME.zip
Code Listing Follows:
/* ------------------------------------------------------------------------
System : Manx Aztec C65 Version 3.2b
MS-DOS cross-development environment
Platform : Apple IIe 128K PRODOS 8
Program : realtime (C) Copyright Bill Buckels 2013.
All rights reserved.
Description : Aztec C65 Demo
1. Standalone Program to Read the Date and Time from SMT Peripherals
No-Slot Clock (NSC). If an NSC is installed, using the code shown below,
you can provide sub-second accuracy in an Aztec C65 program, for either
ProDOS 8 or DOS 3.3 (the code is the same for either).
2. This program also demonstrates how Aztec C65's inline assembly can be
used to directly call 6502 machine language subroutines from within an
Aztec C65 program.
This program does not need any of the programs that were distributed with
the NSC Utilites Disk to read the time and date from the NSC because
already embedded within the realtime program (this program) is Craig
Peterson's READ.TIME program (see source code below).
The READ.TIME program is a clock driver which contains 2 subroutines; one
for installing itself, and the other for reading the NSC.
READ.TIME can be installed from within an Aztec C65 Program as easily as it
can be installed by BRUNning it from BASIC (as Craig suggests).
3. To write this program, all I did was to view READ.TIME in CiderPress's
Hex Viewer, and to copy the output to my programmer's editor using the
Windows Clipboard. I then massaged the hex values to change them to a C
language byte array. Rather than loading an external file from disk, I
simply load the code from memory to the location specified in Craig
Peterson's "ReadMe" which is on the NSC Version 1.4 disk. A snippet from
the "Read Me" which explains the details about how all this works is in the
source comments below.
The same technique, or variations thereof, can be applied for running other
machine language modules from within Aztec C65.
Written by : Bill Buckels
Date Written : September 2013
Revision : 1.0 First Release
Licence : You may use this program for whatever you wish as long
as you agree that Bill Buckels has no warranty or
liability obligations whatsoever from said use.
------------------------------------------------------------------------ */
/* Copyright Bill Buckels 2013 */
#define READ_TIME_ADDR 0x260
#define READ_TIME_LEN 366
/* The READ.TIME program Version 1.4 (C) Copyright Craig Peterson 1991 */
char _read_time[READ_TIME_LEN] = {
0xa9,0x00,0x8d,0xde,0x02,0xa9,0x03,0x09,
0xc0,0x8d,0x1f,0x03,0x8d,0x22,0x03,0x8d,
0x31,0x03,0x8d,0x3f,0x03,0xa9,0x03,0x8d,
0xdf,0x02,0xd0,0x16,0x00,0x00,0x00,0x00,
0x00,0x00,0x2f,0x00,0x00,0x2f,0x00,0x00,
0x20,0x00,0x00,0x3a,0x00,0x00,0x3a,0x00,
0x00,0x8d,0x20,0x0b,0x03,0xa2,0x07,0xbd,
0x03,0x03,0xdd,0xe0,0x02,0x90,0x0f,0xdd,
0xe8,0x02,0xb0,0x0a,0xca,0x10,0xf0,0xce,
0xdf,0x02,0xd0,0xe6,0x18,0x60,0xee,0xde,
0x02,0xad,0xde,0x02,0xc9,0x08,0x90,0xaf,
0xd0,0x1d,0xa9,0xc0,0xa0,0x15,0x8d,0x1b,
0x03,0x8c,0x1a,0x03,0xa0,0x07,0x8d,0x1f,
0x03,0x8c,0x1e,0x03,0x88,0x8d,0x6f,0x03,
0x8c,0x6e,0x03,0xa9,0xc8,0xd0,0x95,0xa9,
0x4c,0x8d,0x16,0x03,0x38,0x60,0x00,0x00,
0x00,0x01,0x01,0x01,0x00,0x00,0x00,0x00,
0x64,0x0d,0x20,0x38,0x98,0x3c,0x3c,0x64,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x00,0x00,0x00,0x00,0x00,
0x18,0x90,0x09,0x00,0x00,0x00,0x00,0x00,
0x00,0x00,0x00,0x38,0x08,0x78,0xa9,0x00,
0x8d,0x04,0x03,0x8d,0x80,0x02,0xad,0xa3,
0x03,0xad,0xff,0xcf,0x48,0x8d,0x00,0xc3,
0xad,0x04,0xc3,0xa2,0x08,0xbd,0xbf,0x03,
0x38,0x6a,0x48,0xa9,0x00,0x2a,0xa8,0xb9,
0x00,0xc3,0x68,0x4a,0xd0,0xf4,0xca,0xd0,
0xec,0xa2,0x08,0xa0,0x08,0xad,0x04,0xc3,
0x6a,0x66,0x42,0x88,0xd0,0xf7,0xa5,0x42,
0x9d,0x7f,0x02,0x4a,0x4a,0x4a,0x4a,0xa8,
0xa5,0x42,0xc0,0x00,0xf0,0x08,0x29,0x0f,
0x18,0x69,0x0a,0x88,0xd0,0xfb,0x9d,0x02,
0x03,0xca,0xd0,0xd7,0xad,0x80,0x02,0x8d,
0x83,0x02,0x68,0x30,0x03,0x8d,0xff,0xcf,
0xa0,0x11,0xa2,0x06,0xbd,0xc7,0x03,0x99,
0x80,0x02,0xbd,0x80,0x02,0x48,0x29,0x0f,
0x09,0x30,0x88,0x99,0x80,0x02,0x68,0x4a,
0x4a,0x4a,0x4a,0xd0,0x0c,0xe0,0x01,0xf0,
0x04,0xe0,0x04,0xd0,0x04,0xa9,0x20,0xd0,
0x02,0x09,0x30,0x88,0x99,0x80,0x02,0x88,
0xca,0xd0,0xd1,0x28,0xb0,0x19,0x20,0xbe,
0xde,0x20,0xe3,0xdf,0x20,0x6c,0xdd,0x85,
0x85,0x84,0x86,0xa9,0x80,0xa0,0x02,0xa2,
0x8d,0x20,0xe9,0xe3,0x20,0x9a,0xda,0x60,
0x5c,0xa3,0x3a,0xc5,0x5c,0xa3,0x3a,0xc5,
0x2f,0x2f,0x20,0x3a,0x3a,0x8d};
/*
Snippet from the NSC Version 1.4 "ReadMe"
The READ.TIME program allows you to read the time from the clock while
using BASIC or assembly language programs. You install the program by
typing 'BRUN READ.TIME', which will load READ.TIME in page $300 of your
Apple and automatically find the location of your No-Slot Clock. Then from
BASIC you just type 'CALL 768,T$', and the clock date and time will be
placed in the variable following the comma after '768'. This variable can
be any valid string variable. From assembly language, after 'BRUN'ing
READ.TIME, you just do a 'JSR $30B', and the ascii string representing the
time will be placed at $280-$291. Also, the hex values for the time are
placed at $303-$30A, as was true of the old CLOCKREAD program. If no
clock is present, a null value is returned to T$ and at location $304. See
the STARTUP program on the /No.Slot.Clock disk for an example of using this
call from BASIC. This version 1.4 of the NS.CLOCK.UTILS time setting
program now fully supports the day of the week function of the clock.
READ.TIME will return the day of the week in location 774 ($306). A 1
represents Sunday, a 2 Monday, ... up to a 7 for Saturday. READ.TIME is
not relocatable and will always load in part of page $200 and $300.
*/
/* load the clock driver from the embedded _read_time byte array...
note: this could also have been loaded from the READ.TIME disk file
like any other "well-behaved" subroutine written in 6502 machine code.
*/
initnsc()
{
char *brunptr = (char *)READ_TIME_ADDR;
int i;
/* bload read.clock to $260 */
for (i = 0; i < READ_TIME_LEN; i++) brunptr[i] = _read_time[i];
#asm
jsr $260 ; call init clock
#endasm
}
/* a structure to point into the registers in the NSC READ.TIME
driver... see notes above and the NSC manual for more details */
struct nsctm {
char year;
char month;
char date;
char day;
char hours;
char minutes;
char seconds;
char hundredths;
};
struct nsctm *nsctime = (struct nsctm *)(0x303);
char nscasctime[19];
/* read the current date time and time from the NSC */
readnsc()
{
char *ascptr = (char *)0x280;
int i;
#asm
jsr $30b ; call read clock
#endasm
/* transfer ascii string to our buffer */
nscasctime[18] = 0;
for (i=0;i<18;i++)nscasctime[i] = ascptr[i];
}
main()
{
crt80();
printf("NSClock Test\n");
/* install the NSC driver */
initnsc();
/* call the NSC and get the "new values" each time
a key is pressed... press ESC to end the demo */
for (;;) {
readnsc();
printf("\nCurrent Time: %s",nscasctime);
printf("Year %d Month %d Day %d Dow %d\n",
(int)nsctime->year,(int)nsctime->month,
(int)nsctime->date,(int)nsctime->day);
printf("Hours %d Minutes %d Seconds %d Hundredths %d\n",
(int)nsctime->hours,(int)nsctime->minutes,
(int)nsctime->seconds,(int)nsctime->hundredths);
printf("Press ESC to Exit, Any other key to continue...\n");
if (getch() == 27) break;
}
_exit();
}