Close

Screen Handler Code

A project log for OSI SD Card Operating System (OSISDOS)

Ohio Scientific / UK101 SD Card based Operating System under Multicomp FPGA Computer

land-boardscomland-boards.com 08/08/2020 at 11:380 Comments

Now that the low level SD card code is working well it's time to give some attention to the command handler. Making this work will require screen/keyboard I/O and cc65 does provide support for I/O. 

This is where things start to get a bit ugly. To start with, there is no stdio.h support for the C1P in cc65

conio on the C1P

There is a conio.h file in cc65 which supports command style I/O from the console but it has serious limitations. For instance, from this page:

... conio doesn't scroll the screen when moving below the last line. 
In fact, allowing that to happen might spell disaster on several
machines because, for performance reasons, there are no checks.

The example code from the tutorial works with some changes but it is flakey. I removed the text section from the example but will probably need to add it back in later when moving this code to the ROM.

/* hello.c example    */
/* conio.h docs - Not sure how well it matches    */
/*     https://digitalmars.com/rtl/conio.html     */

#include <conio.h>    /* Console I/O    */
#include <stdlib.h>

int main (void)
{
    clrscr ();
    cprintf ("\r\nPress <RETURN>.");
    cgetc ();
    return EXIT_SUCCESS;
}

The result is that the "Press <RETURN>" message is printed to the right on the screen. It does wait for a key to be pressed so it's basically working. 

The example above is built using this command line.

"..\..\..\PC Tools\srecord\srec_cat.exe" hello.o -bin -of 0x300 -o hello.c1p -os -esa=0x300

The function three functions do work (at least intermittently in the case of the cprintf function):

The screen size on the UK101 Multicomp build is currently 48 columns x 16 rows. The default C1P screen is formatted for a different size:

By default the conio library uses a 24 columns by 24 lines 
screen layout for the Challenger 1P.

There is a module screen-c1p-24x24.o in the OSI-specific 
cc65 runtime library that contains all conio functions that 
depend on the screen layout. 
No further configuration is needed for using the default screen 
layout of the Challenger 1P.

There is support for other screen layouts but they are limited to:

For other screen layouts additional versions of the screen module 
are available.
The linker finds these modules without further configuration if 
they are specified on the compiler or linker command line. 
The extra module then overrides the default module.

Sample cl65 command line to override the default screen module with 
the module osic1p-screen-s3-32x28.o:

cl65 -o hello -t osic1p osic1p-screen-s3-32x28.o hello.c

Currently the following extra screen configuration modules are 
implemented:

osic1p-screen-s3-32x28.o: 32 columns by 28 lines mode for 
Briel Superboard ///

It looks like all that needs to be done is to create a version of the osic1p-screen-s3-32x28.o file for our screen and have it override the default resolution.

Here is the source code for the 24x24 display. with a few comments added:

;
; Implementation of screen-layout related functions for Challenger 1P
;

        .include        "osiscreen.inc"

C1P_SCR_BASE    := $D000        ; Base of C1P video RAM
C1P_VRAM_SIZE   = $0400         ; Size of C1P video RAM (1 kB)
C1P_SCR_WIDTH   = $18           ; Screen width (24)
C1P_SCR_HEIGHT  = $18           ; Screen height (24)
C1P_SCR_FIRSTCHAR = $85         ; Offset of cursor position (0, 0) from base
                                ; of video RAM
C1P_SCROLL_DIST = $20           ; Memory distance for scrolling by one line (32 chars/line)

osi_screen_funcs C1P_SCR_BASE, C1P_VRAM_SIZE, C1P_SCR_FIRSTCHAR, \
                        C1P_SCR_WIDTH, C1P_SCR_HEIGHT, C1P_SCROLL_DIST

The windows distribution of cc65 does not include the source tree for the C1P libraries but it is on the GitHub repository located here. Changing the screen requires making a new screen file with:

;
; Implementation of 48x16 screen-layout related functions for Challenger 1P
;

        .include        "osiscreen.inc"

C1P_SCR_BASE    := $D040        ; Base of C1P video RAM
C1P_VRAM_SIZE   = $0400         ; Size of C1P video RAM (1 kB)
C1P_SCR_WIDTH   = $30           ; Screen width (48)
C1P_SCR_HEIGHT  = $10           ; Screen height (16)
C1P_SCR_FIRSTCHAR = $0b         ; Offset of cursor position (0, 0) from base
                                ; of video RAM
C1P_SCROLL_DIST = $40           ; Memory distance for scrolling by one line (48 chars/line)

osi_screen_funcs C1P_SCR_BASE, C1P_VRAM_SIZE, C1P_SCR_FIRSTCHAR, \
                        C1P_SCR_WIDTH, C1P_SCR_HEIGHT, C1P_SCROLL_DIST

The library does not have to be rebuilt for the C1P since the over-ride is on the command line for cl65. This also requires a couple of other files from the GitHub source tree osiscreen.inc and extzp.inc.   The new command lines are:

cl65 --start-addr 0x300 -Wl -D,__HIMEM__=$2000,-D,__STACKSIZE__=$0200 -t osic1p -vm -m hello.map --listing hello.lst -o hello.o screen-c1p-48x16.s hello.c
"..\..\..\PC Tools\srecord\srec_cat.exe" hello.o -bin -of 0x300 -o hello.c1p -os -esa=0x300
"C:\Users\HPz420\Documents\GitHub\Doug Gilliland\Retro-Computers\6502\RetroAssembler\retroassembler.exe" -d -D=0x0300 hello.o hello.DIS

That did compile without error.

Problems

The screen code seemed flakey. Sometimes it worked and other times it failed to work. The function cgetc() seems to always work fine.

After some fine tuning of screen-c1p-48x16.s it seems to be much more reliable.

Code Size

The code generated is around 0xd00 long or just under 4 KB. 

Discussions