Skip to content

Commit

Permalink
Clear screen via crt0.c (#38)
Browse files Browse the repository at this point in the history
* Minimal OSI C1P implementation

All boilerplate except for the custom _exit implementation
that jumps to the PROM monitor prompt.

* __putchar() for OSI target

* Remove obsolete comment

* Switch to loop exit implementation

This does make more sense with the existing examples that
otherweise would jump directly to the PROM monitor.

* Switch to exit-loop implementation

The endless  loop in the abort implementation is
obsolete with the switch to the common-exit-loop
implementation.

* Address review comments

Use ' ' consistently for space character.
Fix incorrect encoding for CR and LF.

* C standard semantics of '\n'

* Attempt to implement crt0.c

This is a first broken attempt to hook up a call for clearing the screen
before entering main.

* Missing newline

* Fix problem with crt0.c

The CMake call for merge_libraries for common-crt0-o was missing.
This caused an invalid executable being generated where main itself
was missing.

* Adapt to new library merging strategy

It is no longer necessary to merge the crt0.o module explicitly
with the parent library crt0.o module.

* Fix incorrect argument for memset()

Fixed the bug that the address of function scr_base was passed
to memset() instead of calling scr_base() and passing the
result to memset().

* Fix C++ namespace pollution

Fix pollution of C++ namespace by class name that is
not prefixed by underscores.

Fixes #39.

* Simplify clear screen in crt0

Replaced crt0 C module containing inline assembly with
plain assembler module where __clrscr is called directly
without involving an additional C function.
  • Loading branch information
smuehlst committed May 26, 2022
1 parent 4565c07 commit 91cd402
Show file tree
Hide file tree
Showing 4 changed files with 24 additions and 7 deletions.
2 changes: 2 additions & 0 deletions mos-platform/osi-c1p/CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@ if(NOT CMAKE_CROSSCOMPILING)
return()
endif()

add_platform_object_file(osi-c1p-crt0-o crt0.o crt0.s)

add_platform_library(osi-c1p-crt0)
merge_libraries(osi-c1p-crt0
common-copy-data
Expand Down
6 changes: 6 additions & 0 deletions mos-platform/osi-c1p/crt0.s
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
; Assembler crt0 file to clear the screen before the
; call to main.

.section .init.40,"axR",@progbits
jsr __clrscr

4 changes: 2 additions & 2 deletions mos-platform/osi-c1p/osi_screen.h
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ template <
unsigned int screen_firstchar = 0x85, // offset of cursor position (0, 0) from base of video RAM
unsigned int scroll_dist = 0x20 // memory distance for scrolling by one line
>
class osi_screen
class __osi_screen
{
private:
static unsigned char cursor_x;
Expand Down Expand Up @@ -58,7 +58,7 @@ class osi_screen
public:
static void clrscr(void)
{
memset((void *) scr_base, ' ', video_ram_size);
memset((void *) scr_base(), ' ', video_ram_size);
cursor_x = cursor_y = 0;
}

Expand Down
19 changes: 14 additions & 5 deletions mos-platform/osi-c1p/putchar.cc
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@ template<unsigned int scr_base_int, unsigned int video_ram_size,
unsigned int screen_width, unsigned int screen_height,
unsigned int screen_firstchar, unsigned int scroll_dist>
unsigned char
osi_screen<scr_base_int, video_ram_size, screen_width, screen_height,
__osi_screen<scr_base_int, video_ram_size, screen_width, screen_height,
screen_firstchar, scroll_dist>::cursor_x;

template<unsigned int scr_base_int, unsigned int video_ram_size,
unsigned int screen_width, unsigned int screen_height,
unsigned int screen_firstchar, unsigned int scroll_dist>
unsigned char
osi_screen<scr_base_int, video_ram_size, screen_width, screen_height,
__osi_screen<scr_base_int, video_ram_size, screen_width, screen_height,
screen_firstchar, scroll_dist>::cursor_y;

using c1p_screen = osi_screen<>;
using __osic1p_screen = __osi_screen<>;

/**
* @brief __putchar implementation for Challenger 1P
Expand All @@ -34,8 +34,17 @@ void __putchar(char c)
*/
if (c == '\n')
{
c1p_screen::cputc('\r');
__osic1p_screen::cputc('\r');
}

c1p_screen::cputc(c);
__osic1p_screen::cputc(c);
}

/**
* @brief __clrscr clear the screen
*/
extern "C"
void __clrscr(void)
{
__osic1p_screen::clrscr();
}

0 comments on commit 91cd402

Please sign in to comment.