Skip to content

Commit

Permalink
Improve and slightly repair clock handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ckormanyos committed Jan 9, 2024
1 parent 305f33c commit b000186
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 17 deletions.
12 changes: 7 additions & 5 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,9 @@ This is intended to simulate an LED-blinky by _toggling_ between _ON_ and _OFF_.

The blinky _ON_/_OFF_ timebase is derived from a $1s$ tick,
resulting in a toggle-frequency of ${\sim}{\frac{1}{2}}Hz$.
The underlying timer resides on `port 0x45`. It is only available on the TI-84,
not the TI-83.
The underlying 32-bit timer resides on ports `0x41`-`0x44`,
where the lower byte at port `0x41` is used.
This timer is only available on the TI-84, not the TI-83.

The blinky _ON_/_OFF_ text messages are printed
at row $2$, column $7$.
Expand Down Expand Up @@ -104,15 +105,16 @@ the [license](./LICENSE) details.
Some of this software has been reverse engineered
from other projects or terse technical notes.
In addition, the software writes to calculator `ports`,
such as `port 0x41`.
such as ports `0x40` and `0x41`.

Personally. I do not consider this to be a $100\\%$ sound basis
for project reliability and/or stability.

Nonetheless, empirical evidence shows a working,
and fully/properly initialized C-language application.
It provides a basis that seems to adhere to the established, common
rules of modern C. Larger projects could be built or modelled from this.
It provides a basis that seems to adhere to the established,
common rules of modern C. Larger projects could be built or modelled
from this.

Origins
- This project has been inspired by and influenced by numerous previous works, including (but not limited to) the [azertyfun/LibTI](https://github.com/azertyfun/LibTI) project.
Expand Down
19 changes: 7 additions & 12 deletions src/startup/clock.c
Original file line number Diff line number Diff line change
Expand Up @@ -14,14 +14,6 @@ static void clock_seconds_do_start (void) ATTRIBUTE_NAKED;
static void clock_seconds_do_stop (void) ATTRIBUTE_NAKED;
static uint8_t clock_seconds_do_get (void) ATTRIBUTE_NAKED;

void _clock(void) ATTRIBUTE_NAKED
{
// Mysterious _clock() method.

__asm__("ld a, #0x2\n");
__asm__("ret\n");
}

void clock_seconds_start(void)
{
const uint8_t clock_seconds_run_bit_value = (uint8_t) (clock_seconds_get_port40() & (uint8_t) UINT8_C(1));
Expand Down Expand Up @@ -59,23 +51,26 @@ static void clock_seconds_do_start(void) ATTRIBUTE_NAKED
{
// Reset the lower byte of the 32-bit clock.
__asm__("xor a\n");
__asm__("out (0x44), a\n");
__asm__("out (0x41), a\n");

// Ensure that the set command bit is off since its transition
// to high will actually set the clock.
__asm__("ld a, #0x1\n");
__asm__("in a, (0x40)\n");
__asm__("and a, #0xFC\n");
__asm__("or a, #0x1\n");
__asm__("out (0x40), a\n");

// Set and start the clock.
__asm__("ld a, #0x3\n");
__asm__("or a, #0x3\n");
__asm__("out (0x40), a\n");
__asm__("ret\n");
}

static void clock_seconds_do_stop(void) ATTRIBUTE_NAKED
{
// Stop the clock.
__asm__("ld a, #0x0\n");
__asm__("in a, (0x40)\n");
__asm__("and a, #0xFE\n");
__asm__("out (0x40), a\n");
__asm__("ret\n");
}
Expand Down

0 comments on commit b000186

Please sign in to comment.