Skip to content

Commit

Permalink
Merge pull request #49 from ckormanyos/update_syntax
Browse files Browse the repository at this point in the history
Update syntax
  • Loading branch information
ckormanyos authored Jul 8, 2024
2 parents 11b2535 + 992ed99 commit 3a79580
Show file tree
Hide file tree
Showing 13 changed files with 122 additions and 118 deletions.
16 changes: 8 additions & 8 deletions bin/refapp.asm
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
;--------------------------------------------------------
; File Created by SDCC : free open source ISO C Compiler
; Version 4.4.0 #14579 (MINGW64)
; Version 4.4.0 #14620 (MINGW32)
;--------------------------------------------------------
.module app_main
.optsdcc -mz80
Expand Down Expand Up @@ -44,23 +44,23 @@
; code
;--------------------------------------------------------
.area _CODE
;c:\users\user\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:11: void main(void)
;c:\users\ckorm\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:11: void main(void)
; ---------------------------------
; Function main
; ---------------------------------
_main::
;c:\users\user\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:19: mcal_gpt_init();
;c:\users\ckorm\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:19: mcal_gpt_init();
call _mcal_gpt_init
;c:\users\user\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:22: app_lcd_util_init();
;c:\users\ckorm\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:22: app_lcd_util_init();
call _app_lcd_util_init
;c:\users\user\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:27: os_schedule();
;c:\users\ckorm\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:27: os_schedule();
call _os_schedule
;c:\users\user\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:30: mcal_gpt_de_init();
;c:\users\ckorm\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:30: mcal_gpt_de_init();
call _mcal_gpt_de_init
;c:\users\user\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:39: __asm__("rst 0x28\n" ".dw #0x4027\n");
;c:\users\ckorm\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:39: ASM("rst 0x28\n" ".dw #0x4027\n");
rst 0x28
.dw #0x4027
;c:\users\user\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:40: }
;c:\users\ckorm\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:40: }
ret
.area _CODE
.area _INITIALIZER
Expand Down
18 changes: 9 additions & 9 deletions bin/refapp.lk
Original file line number Diff line number Diff line change
@@ -1,15 +1,15 @@
-mjwx
-i C:/Users/User/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/../bin/refapp.ihx
-i C:/Users/ckorm/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/../bin/refapp.ihx
-b _CODE = 0x9d9b
-b _DATA = 0x0000
-k C:\Program Files\SDCC\bin\..\lib\z80
-k C:\Program Files (x86)\SDCC\bin\..\lib\z80
-l z80
C:/Users/User/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/../bin/refapp.rel
C:/Users/User/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/app_hello.rel
C:/Users/User/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/app_lcd_util.rel
C:/Users/User/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/app_led.rel
C:/Users/User/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/mcal_gpt.rel
C:/Users/User/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/os.rel
C:/Users/User/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/crt0.rel
C:/Users/ckorm/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/../bin/refapp.rel
C:/Users/ckorm/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/app_hello.rel
C:/Users/ckorm/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/app_lcd_util.rel
C:/Users/ckorm/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/app_led.rel
C:/Users/ckorm/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/mcal_gpt.rel
C:/Users/ckorm/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/os.rel
C:/Users/ckorm/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/crt0.rel

-e
16 changes: 8 additions & 8 deletions bin/refapp.lst
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
1 ;--------------------------------------------------------
2 ; File Created by SDCC : free open source ISO C Compiler
3 ; Version 4.4.0 #14579 (MINGW64)
3 ; Version 4.4.0 #14620 (MINGW32)
4 ;--------------------------------------------------------
5 .module app_main
6 .optsdcc -mz80
Expand Down Expand Up @@ -44,23 +44,23 @@
44 ; code
45 ;--------------------------------------------------------
46 .area _CODE
47 ;c:\users\user\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:11: void main(void)
47 ;c:\users\ckorm\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:11: void main(void)
48 ; ---------------------------------
49 ; Function main
50 ; ---------------------------------
000000 51 _main::
52 ;c:\users\user\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:19: mcal_gpt_init();
52 ;c:\users\ckorm\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:19: mcal_gpt_init();
000000 CDr00r00 [17] 53 call _mcal_gpt_init
54 ;c:\users\user\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:22: app_lcd_util_init();
54 ;c:\users\ckorm\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:22: app_lcd_util_init();
000003 CDr00r00 [17] 55 call _app_lcd_util_init
56 ;c:\users\user\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:27: os_schedule();
56 ;c:\users\ckorm\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:27: os_schedule();
000006 CDr00r00 [17] 57 call _os_schedule
58 ;c:\users\user\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:30: mcal_gpt_de_init();
58 ;c:\users\ckorm\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:30: mcal_gpt_de_init();
000009 CDr00r00 [17] 59 call _mcal_gpt_de_init
60 ;c:\users\user\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:39: __asm__("rst 0x28\n" ".dw #0x4027\n");
60 ;c:\users\ckorm\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:39: ASM("rst 0x28\n" ".dw #0x4027\n");
00000C EF [11] 61 rst 0x28
00000D 27 40 62 .dw #0x4027
63 ;c:\users\user\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:40: }
63 ;c:\users\ckorm\documents\ks\uc_software\boards\ti84-ref_app\src\app\app_main.c:40: }
00000F C9 [10] 64 ret
65 .area _CODE
66 .area _INITIALIZER
Expand Down
14 changes: 7 additions & 7 deletions bin/refapp.map
Original file line number Diff line number Diff line change
Expand Up @@ -113,19 +113,19 @@ _HEADER0 00000000 00000008 = 8. bytes (A

Files Linked [ module(s) ]

C:/Users/User/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/../bin/refapp.rel
C:/Users/ckorm/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/../bin/refapp.rel
[ app_main ]
C:/Users/User/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/app_hello.rel
C:/Users/ckorm/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/app_hello.rel
[ app_hello ]
C:/Users/User/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/app_lcd_util.rel
C:/Users/ckorm/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/app_lcd_util.rel
[ app_lcd_util ]
C:/Users/User/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/app_led.rel
C:/Users/ckorm/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/app_led.rel
[ app_led ]
C:/Users/User/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/mcal_gpt.rel
C:/Users/ckorm/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/mcal_gpt.rel
[ mcal_gpt ]
C:/Users/User/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/os.rel
C:/Users/ckorm/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/os.rel
[ os ]
C:/Users/User/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/crt0.rel
C:/Users/ckorm/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/obj/crt0.rel
[ crt ]

ASxxxx Linker V03.00/V05.40 + sdld, page 10.
Expand Down
2 changes: 1 addition & 1 deletion bin/refapp.noi
Original file line number Diff line number Diff line change
Expand Up @@ -36,4 +36,4 @@ DEF _mcal_gpt_init 0x9E50
DEF _mcal_gpt_de_init 0x9E63
DEF _mcal_gpt_get_time_elapsed 0x9E6C
DEF _os_schedule 0x9E9A
LOAD C:/Users/User/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/../bin/refapp.ihx
LOAD C:/Users/ckorm/Documents/Ks/uC_Software/Boards/ti84-ref_app/build/../bin/refapp.ihx
13 changes: 7 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,14 +25,15 @@ of its associated ASCII-text messages.
The text sequences _ON_/_OFF_ and _hello_/_world_ are presented in
cyclic, alternating fashion(s) on the calculator screen.
Text is used since there is no actual LED present on the calculator-target system.
This is intended to simulate an LED-blinky by _toggling_ between _ON_ and _OFF_
and support an independent _hello_-_world_-task as well.
The _ON_/_OFF_ messages are printed every $1s$ and the _hello_/_world_ messages every $3s$.
This is intended to simulate an LED-blinky by _toggling_ between _ON_ and _OFF_.
To make the program a little more interesting, an independent _hello_-_world_-task
is supported as well. The _ON_/_OFF_ messages are printed every $1s$
and the _hello_/_world_ messages every $3s$.

## Implementation details

The cooperative multitasking timebase is derived from a $1s$ tick.
The underlying 32-bit timer resides on ports `0x45`-`0x48`,
The underlying $32$-bit timer resides on ports `0x45`-`0x48`,
where the lower byte at port `0x45` is used.
This timer is only available on the TI-84, not the TI-83.

Expand All @@ -49,7 +50,7 @@ and
[`app_hello_task()`](https://github.com/ckormanyos/ti84-ref_app/blob/8291393f971d234c3493e18589b60421d22f61cc/src/app/app_hello.c#L10)
based on their cycle times.

The application is written in C23.
The application is written in the C language using the C23 standard.
There is minimal use of assembly for startup and to interface with
[TI-83 Plus System Routines](https://education.ti.com/html/eguides/discontinued/computer-software/EN/SDK-TI-83-System-Routines_EN.pdf).

Expand Down Expand Up @@ -100,7 +101,7 @@ The build system:
### Build on `Win*`

Prerequisites:
- Install [`sdcc`](https://sdcc.sourceforge.net) version 4.3 or higher.
- Install [`sdcc`](https://sdcc.sourceforge.net) version 4.4 or higher.
- Install python.

Then build in the command shell with:
Expand Down
18 changes: 9 additions & 9 deletions src/app/app_lcd_util.c
Original file line number Diff line number Diff line change
Expand Up @@ -28,8 +28,8 @@ void app_lcd_util_row(const uint8_t row) ATTRIBUTE_NAKED

// curRow #0x844B

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

void app_lcd_util_col(const uint8_t col) ATTRIBUTE_NAKED
Expand All @@ -38,18 +38,18 @@ void app_lcd_util_col(const uint8_t col) ATTRIBUTE_NAKED

// curCol #0x844C

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

void app_lcd_util_init(void) ATTRIBUTE_NAKED
{
// _ClrLCDFull #0x4540
// _HomeUp #0x4558

__asm__("rst 0x28\n" ".dw #0x4540\n");
__asm__("rst 0x28\n" ".dw #0x4558\n");
__asm__("ret\n");
ASM("rst 0x28\n" ".dw #0x4540\n");
ASM("rst 0x28\n" ".dw #0x4558\n");
ASM("ret\n");
}

static void app_lcd_util_putc(char c) ATTRIBUTE_NAKED
Expand All @@ -58,6 +58,6 @@ static void app_lcd_util_putc(char c) ATTRIBUTE_NAKED

// _PutC #0x4504

__asm__("rst 0x28\n" ".dw #0x4504\n");
__asm__("ret\n");
ASM("rst 0x28\n" ".dw #0x4504\n");
ASM("ret\n");
}
4 changes: 2 additions & 2 deletions src/app/app_lcd_util.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,10 @@
#ifndef APP_LCD_UTIL_2024_01_07_H
#define APP_LCD_UTIL_2024_01_07_H

#include <stdint.h>

#include <startup/asm_util.h>

#include <stdint.h>

void app_lcd_util_puts(const char* p_str);

void app_lcd_util_row(const uint8_t row) ATTRIBUTE_NAKED;
Expand Down
2 changes: 1 addition & 1 deletion src/app/app_main.c
Original file line number Diff line number Diff line change
Expand Up @@ -36,5 +36,5 @@ void main(void)

// _JForceCmdNoChar #0x4027

__asm__("rst 0x28\n" ".dw #0x4027\n");
ASM("rst 0x28\n" ".dw #0x4027\n");
}
60 changes: 28 additions & 32 deletions src/mcal/mcal_gpt.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
// Distributed under The Unlicense
//

#include <startup/asm_util.h>
#include <mcal/mcal_gpt.h>
#include <startup/asm_util.h>

// The clock is a 32-bit value that represents the number of seconds
// after midnight, January 1st, 1970.
Expand Down Expand Up @@ -47,62 +47,58 @@ uint8_t mcal_gpt_get_time_elapsed(void)

static uint8_t clock_seconds_read_port40(void) ATTRIBUTE_NAKED
{
__asm__("in a, (0x40)\n");
__asm__("ld h, a\n");
__asm__("ret\n");
ASM("in a, (0x40)\n");
ASM("ld h, a\n");
ASM("ret\n");

#if defined(_MSC_VER)
return (uint8_t) UINT8_C(0);
#endif
RETURN_FROM_NAKED((uint8_t) UINT8_C(0));
}

static void clock_seconds_start(void) ATTRIBUTE_NAKED
{
__asm__("in a, (0x48)\n"); // Read byte3 of the actual clock.
__asm__("out (0x44), a\n"); // Set byte3 of the clock shadow (using the value read above).
__asm__("in a, (0x47)\n"); // Read byte2 of the actual clock.
__asm__("out (0x43), a\n"); // Set byte2 of the clock shadow (using the value read above).
__asm__("in a, (0x46)\n"); // Read byte1 of the actual clock.
__asm__("out (0x42), a\n"); // Set byte1 of the clock shadow (using the value read above).
__asm__("xor a\n"); // Clear register a.
__asm__("out (0x41), a\n"); // Clear byte0 of the clock shadow.
ASM("in a, (0x48)\n"); // Read byte3 of the actual clock.
ASM("out (0x44), a\n"); // Set byte3 of the clock shadow (using the value read above).
ASM("in a, (0x47)\n"); // Read byte2 of the actual clock.
ASM("out (0x43), a\n"); // Set byte2 of the clock shadow (using the value read above).
ASM("in a, (0x46)\n"); // Read byte1 of the actual clock.
ASM("out (0x42), a\n"); // Set byte1 of the clock shadow (using the value read above).
ASM("xor a\n"); // Clear register a.
ASM("out (0x41), a\n"); // Clear byte0 of the clock shadow.

// Ensure that the set command bit is off since its transition
// to high will actually set the clock. The setting uses the values
// from the clock shadow at ports:45-48.

__asm__("in a, (0x40)\n");
__asm__("and a, #0xFC\n");
__asm__("or a, #0x1\n");
__asm__("out (0x40), a\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__("or a, #0x3\n");
__asm__("out (0x40), a\n");
__asm__("ret\n");
ASM("or a, #0x3\n");
ASM("out (0x40), a\n");
ASM("ret\n");
}

static void clock_seconds_stop(void) ATTRIBUTE_NAKED
{
// Stop the clock.

__asm__("in a, (0x40)\n");
__asm__("and a, #0xFE\n");
__asm__("out (0x40), a\n");
__asm__("ret\n");
ASM("in a, (0x40)\n");
ASM("and a, #0xFE\n");
ASM("out (0x40), a\n");
ASM("ret\n");
}

static uint8_t clock_seconds_value(void) ATTRIBUTE_NAKED
{
// Return the lower 8-bits of the clock, where port:45 is
// the least significant byte of the clock.

__asm__("in a, (0x45)\n");
__asm__("ld h, a\n");
__asm__("ret\n");
ASM("in a, (0x45)\n");
ASM("ld h, a\n");
ASM("ret\n");

#if defined(_MSC_VER)
return (uint8_t) UINT8_C(0);
#endif
RETURN_FROM_NAKED((uint8_t) UINT8_C(0));
}
28 changes: 13 additions & 15 deletions src/os/os.c
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,13 @@
// Distributed under The Unlicense
//

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

#include <mcal/mcal_gpt.h>
#include <os/os.h>
#include <startup/asm_util.h>

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

typedef void(*os_function_type)(void);

typedef struct os_task_control_block
Expand All @@ -20,7 +20,7 @@ typedef struct os_task_control_block
}
os_task_control_block;

#define OS_COUNTOF(a) ((size_t) (sizeof(a) / sizeof((a)[(size_t) UINT8_C(0)])))
#define TASK_COUNT (uint8_t) (sizeof(os_task_list) / sizeof((os_task_list)[(size_t) UINT8_C(0)]))

#define OS_TIMER_TIMEOUT(T) (bool) (((uint8_t) ((uint8_t) (mcal_gpt_get_time_elapsed() - (T)) & (uint8_t) UINT8_C(0x80)) == (uint8_t) UINT8_C(0)) ? true : false)

Expand All @@ -39,7 +39,7 @@ void os_schedule(void)
{
while(!os_wants_exit())
{
for(uint8_t task_index = (uint8_t) UINT8_C(0); task_index < (uint8_t) OS_COUNTOF(os_task_list); ++task_index)
for(uint8_t task_index = (uint8_t) UINT8_C(0); task_index < TASK_COUNT; ++task_index)
{
if(OS_TIMER_TIMEOUT(os_task_list[task_index].timer))
{
Expand All @@ -53,15 +53,13 @@ void os_schedule(void)

static bool os_wants_exit(void) ATTRIBUTE_NAKED
{
__asm__("rst 0x28\n" ".dw #0x4018\n");
__asm__("ld h, #0x0\n");
__asm__("cp #0x9\n");
__asm__("jp nz, no_exit\n");
__asm__("ld h, #0x1\n");
__asm__("no_exit:\n");
__asm__("ret\n");
ASM("rst 0x28\n" ".dw #0x4018\n");
ASM("ld h, #0x0\n");
ASM("cp #0x9\n");
ASM("jp nz, no_exit\n");
ASM("ld h, #0x1\n");
ASM("no_exit:\n");
ASM("ret\n");

#if defined(_MSC_VER)
return false;
#endif
RETURN_FROM_NAKED(false);
}
Loading

0 comments on commit 3a79580

Please sign in to comment.