From ec5e38617a6bbb00bac0411d7d0125afb5a1f5c3 Mon Sep 17 00:00:00 2001 From: Christian Groessler Date: Tue, 2 Apr 2019 21:11:11 +0200 Subject: [PATCH] atari5200: implement bgcolor() and textcolor() Includes some other small fixes/cleanups. --- asminc/atari5200.inc | 10 ++++ include/atari.h | 2 +- include/atari5200.h | 14 +++++ libsrc/atari/chline.s | 4 -- libsrc/atari/cvline.s | 4 -- libsrc/atari5200/bgcolor.s | 1 + libsrc/atari5200/chline.s | 27 ++++++++- libsrc/atari5200/conioscreen.s | 9 +++ libsrc/atari5200/cputc.s | 18 +++--- libsrc/atari5200/cvline.s | 32 ++++++++++- libsrc/atari5200/gotox.s | 3 +- libsrc/atari5200/gotoxy.s | 3 +- libsrc/atari5200/gotoy.s | 3 +- libsrc/atari5200/textcolor.s | 28 +++++++++ libsrc/atari5200/wherex.s | 13 +++++ libsrc/atari5200/wherey.s | 13 +++++ samples/hello.c | 2 +- testcode/lib/atari5200/hello.c | 101 +++++++++++++++++++++++++++++++++ 18 files changed, 261 insertions(+), 26 deletions(-) create mode 100644 libsrc/atari5200/bgcolor.s create mode 100644 libsrc/atari5200/textcolor.s create mode 100644 libsrc/atari5200/wherex.s create mode 100644 libsrc/atari5200/wherey.s create mode 100644 testcode/lib/atari5200/hello.c diff --git a/asminc/atari5200.inc b/asminc/atari5200.inc index 91fae4a9a..a1fe624e6 100644 --- a/asminc/atari5200.inc +++ b/asminc/atari5200.inc @@ -10,6 +10,16 @@ ATEOL = $9B ; END-OF-LINE, used by CONIO +;------------------------------------------------------------------------- +; CONIO CHARACTER DEFS +;------------------------------------------------------------------------- + +CH_ULCORNER = $0B ; '+' sign +CH_URCORNER = $0B +CH_LLCORNER = $0B +CH_LRCORNER = $0B +CH_HLINE = $0D ; dash +CH_VLINE = $01 ; exclamation mark ;------------------------------------------------------------------------- ; Zero Page diff --git a/include/atari.h b/include/atari.h index 899a6ac51..455c43260 100644 --- a/include/atari.h +++ b/include/atari.h @@ -491,7 +491,7 @@ extern void atrx15p2_tgi[]; #define PxCTL_IRQ_STATUS 0x80 -/* The following #defines will cause the matching functions calls in conio.h +/* The following #define will cause the matching function calls in conio.h ** to be overlaid by macros with the same names, saving the function call ** overhead. */ diff --git a/include/atari5200.h b/include/atari5200.h index 67c11c1df..10cd32fe9 100644 --- a/include/atari5200.h +++ b/include/atari5200.h @@ -53,6 +53,14 @@ extern void atr5200std_joy[]; /* referred to by joy_static_stddrv[] */ #define JOY_RIGHT_MASK 0x08 #define JOY_BTN_1_MASK 0x10 +/* Character codes */ +#define CH_ULCORNER 0x0B /* '+' sign */ +#define CH_URCORNER 0x0B +#define CH_LLCORNER 0x0B +#define CH_LRCORNER 0x0B +#define CH_HLINE 0x0D /* dash */ +#define CH_VLINE 0x01 /* exclamation mark */ + /* get_tv return values */ #define AT_NTSC 0 #define AT_PAL 1 @@ -69,5 +77,11 @@ extern void atr5200std_joy[]; /* referred to by joy_static_stddrv[] */ #include <_antic.h> #define ANTIC (*(struct __antic*)0xD400) +/* The following #define will cause the matching function calls in conio.h +** to be overlaid by macros with the same names, saving the function call +** overhead. +*/ +#define _bordercolor(color) 0 + /* End of atari5200.h */ #endif diff --git a/libsrc/atari/chline.s b/libsrc/atari/chline.s index 194fe0bb3..f4931dd4f 100644 --- a/libsrc/atari/chline.s +++ b/libsrc/atari/chline.s @@ -9,11 +9,7 @@ .import gotoxy, cputdirect, setcursor .importzp tmp1 -.ifdef __ATARI5200__ -CHRCODE = 14 -.else CHRCODE = $12+64 -.endif _chlinexy: pha ; Save the length diff --git a/libsrc/atari/cvline.s b/libsrc/atari/cvline.s index 1b4ba0b1b..735e47dd2 100644 --- a/libsrc/atari/cvline.s +++ b/libsrc/atari/cvline.s @@ -10,11 +10,7 @@ .import gotoxy, putchar, setcursor .importzp tmp1 -.ifdef __ATARI5200__ -CHRCODE = 1 ; exclamation mark -.else CHRCODE = $7C ; Vertical bar -.endif _cvlinexy: pha ; Save the length diff --git a/libsrc/atari5200/bgcolor.s b/libsrc/atari5200/bgcolor.s new file mode 100644 index 000000000..1f9f77260 --- /dev/null +++ b/libsrc/atari5200/bgcolor.s @@ -0,0 +1 @@ +.include "../atari/bgcolor.s" diff --git a/libsrc/atari5200/chline.s b/libsrc/atari5200/chline.s index d5872f149..47c57966b 100644 --- a/libsrc/atari5200/chline.s +++ b/libsrc/atari5200/chline.s @@ -1 +1,26 @@ -.include "../atari/chline.s" +; +; Ullrich von Bassewitz, 08.08.1998 +; +; void chlinexy (unsigned char x, unsigned char y, unsigned char length); +; void chline (unsigned char length); +; + + .export _chlinexy, _chline + .import gotoxy, cputdirect + .importzp tmp1 + .include "atari5200.inc" + +_chlinexy: + pha ; Save the length + jsr gotoxy ; Call this one, will pop params + pla ; Restore the length + +_chline: + cmp #0 ; Is the length zero? + beq L9 ; Jump if done + sta tmp1 +L1: lda #CH_HLINE ; Horizontal line, screen code + jsr cputdirect ; Direct output + dec tmp1 + bne L1 +L9: rts diff --git a/libsrc/atari5200/conioscreen.s b/libsrc/atari5200/conioscreen.s index 30c0e0788..2c6a8a4e4 100644 --- a/libsrc/atari5200/conioscreen.s +++ b/libsrc/atari5200/conioscreen.s @@ -8,6 +8,12 @@ SCREEN_BUF_SIZE = 20 * 24 SCREEN_BUF = $4000 - SCREEN_BUF_SIZE .export screen_setup_20x24 + .export screen_width, screen_height + .export conio_color + +screen_width = 20 +screen_height = 24 + .segment "ONCE" @@ -57,6 +63,9 @@ clrscr: sta (SAVMSC),y rts + .data + +conio_color: .byte 0 .segment "DLIST" diff --git a/libsrc/atari5200/cputc.s b/libsrc/atari5200/cputc.s index 185ad8da8..8fc00fcdc 100644 --- a/libsrc/atari5200/cputc.s +++ b/libsrc/atari5200/cputc.s @@ -11,8 +11,9 @@ .export _cputcxy, _cputc .export plot, cputdirect, putchar .import gotoxy, _mul20 + .import conio_color + .importzp screen_width, screen_height .importzp ptr4 - .import setcursor .constructor screen_setup, 26 .import screen_setup_20x24 @@ -44,7 +45,7 @@ L4: cmp #$0A ; LF and #3 tax tya - and #$9f + and #$9F ora ataint,x cputdirect: ; accepts screen code @@ -53,7 +54,7 @@ cputdirect: ; accepts screen code ; advance cursor inc COLCRS_5200 lda COLCRS_5200 - cmp #20 + cmp #screen_width bcc plot lda #0 sta COLCRS_5200 @@ -62,12 +63,11 @@ cputdirect: ; accepts screen code newline: inc ROWCRS_5200 lda ROWCRS_5200 - cmp #24 + cmp #screen_height bne plot lda #0 sta ROWCRS_5200 -plot: jsr setcursor - ldy COLCRS_5200 +plot: ldy COLCRS_5200 ldx ROWCRS_5200 rts @@ -83,10 +83,12 @@ putchar: sta ptr4+1 pla ; get char again +; and #$C0 ; without this we are compatible with the old version. user must not try to output a char >= $3F + ora conio_color + ldy COLCRS_5200 sta (ptr4),y - jmp setcursor + rts .rodata ataint: .byte 64,0,32,96 - diff --git a/libsrc/atari5200/cvline.s b/libsrc/atari5200/cvline.s index d987bcb62..204d90382 100644 --- a/libsrc/atari5200/cvline.s +++ b/libsrc/atari5200/cvline.s @@ -1 +1,31 @@ -.include "../atari/cvline.s" +; +; Ullrich von Bassewitz, 08.08.1998 +; +; void cvlinexy (unsigned char x, unsigned char y, unsigned char length); +; void cvline (unsigned char length); +; + .include "atari5200.inc" + + .export _cvlinexy, _cvline + .import gotoxy, putchar + .importzp tmp1 + +_cvlinexy: + pha ; Save the length + jsr gotoxy ; Call this one, will pop params + pla ; Restore the length and run into _cvline + +_cvline: + cmp #0 ; Is the length zero? + beq L9 ; Jump if done + sta tmp1 +L1: lda COLCRS_5200 + pha + lda #CH_VLINE ; Vertical bar + jsr putchar ; Write, no cursor advance + pla + sta COLCRS_5200 + inc ROWCRS_5200 + dec tmp1 + bne L1 +L9: rts diff --git a/libsrc/atari5200/gotox.s b/libsrc/atari5200/gotox.s index 99f7cfd22..04fc46223 100644 --- a/libsrc/atari5200/gotox.s +++ b/libsrc/atari5200/gotox.s @@ -6,8 +6,7 @@ .include "atari5200.inc" .export _gotox - .import setcursor _gotox: sta COLCRS_5200 ; Set X - jmp setcursor + rts diff --git a/libsrc/atari5200/gotoxy.s b/libsrc/atari5200/gotoxy.s index 24e2c2e35..dce5b6c2a 100644 --- a/libsrc/atari5200/gotoxy.s +++ b/libsrc/atari5200/gotoxy.s @@ -8,7 +8,6 @@ .export gotoxy, _gotoxy .import popa - .import setcursor gotoxy: jsr popa ; Get Y @@ -17,4 +16,4 @@ _gotoxy: ; Set the cursor position sta ROWCRS_5200 ; Set Y jsr popa ; Get X sta COLCRS_5200 ; Set X - jmp setcursor + rts diff --git a/libsrc/atari5200/gotoy.s b/libsrc/atari5200/gotoy.s index fcdd05e4c..ef7c2e565 100644 --- a/libsrc/atari5200/gotoy.s +++ b/libsrc/atari5200/gotoy.s @@ -6,8 +6,7 @@ .include "atari5200.inc" .export _gotoy - .import setcursor _gotoy: sta ROWCRS_5200 ; Set Y - jmp setcursor + rts diff --git a/libsrc/atari5200/textcolor.s b/libsrc/atari5200/textcolor.s new file mode 100644 index 000000000..061e84088 --- /dev/null +++ b/libsrc/atari5200/textcolor.s @@ -0,0 +1,28 @@ +; +; Christian Groessler, 02-Apr-2019 +; +; unsigned char __fastcall__ textcolor (unsigned char color); + + .export _textcolor + .import conio_color + + .include "atari.inc" + + +_textcolor: + ; move bits #0 and #1 to bits #6 and #7 + and #3 + clc + ror a + ror a + ror a ; new conio_color value + ldx conio_color ; get old value + sta conio_color ; store new value + txa + ; move bits #6 and #7 to bits #0 and #1 + clc + rol a + rol a + rol a + ldx #0 + rts diff --git a/libsrc/atari5200/wherex.s b/libsrc/atari5200/wherex.s new file mode 100644 index 000000000..77f099d88 --- /dev/null +++ b/libsrc/atari5200/wherex.s @@ -0,0 +1,13 @@ +; +; Carsten Strotmann, 30.12.2002 +; +; unsigned char wherex (void); +; + + .export _wherex + .include "atari5200.inc" + +_wherex: + lda COLCRS_5200 + ldx #0 + rts diff --git a/libsrc/atari5200/wherey.s b/libsrc/atari5200/wherey.s new file mode 100644 index 000000000..d2c50427c --- /dev/null +++ b/libsrc/atari5200/wherey.s @@ -0,0 +1,13 @@ +; +; Carsten Strotmann, 30.12.2002 +; +; unsigned char wherey (void); +; + + .export _wherey + .include "atari5200.inc" + +_wherey: + lda ROWCRS_5200 + ldx #0 + rts diff --git a/samples/hello.c b/samples/hello.c index dd15128d2..255dccd00 100644 --- a/samples/hello.c +++ b/samples/hello.c @@ -67,7 +67,7 @@ int main (void) gotoxy ((XSize - strlen (Text)) / 2, YSize / 2); cprintf ("%s", Text); -#if defined(__NES__) || defined(__PCE__) || defined(__GAMATE__) +#if defined(__NES__) || defined(__PCE__) || defined(__GAMATE__) || defined(__ATARI5200__) /* Wait for the user to press a button */ joy_install (joy_static_stddrv); diff --git a/testcode/lib/atari5200/hello.c b/testcode/lib/atari5200/hello.c new file mode 100644 index 000000000..b2088461b --- /dev/null +++ b/testcode/lib/atari5200/hello.c @@ -0,0 +1,101 @@ +/* +** Fancy hello world program using cc65. +** +** Ullrich von Bassewitz (ullrich@von-bassewitz.de) +** +** TEST version for atari5200 conio, using all four colors +*/ + + + +#include +#include +#include +#include + + + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +static const char Text [] = "Hello world!"; + + + +/*****************************************************************************/ +/* Code */ +/*****************************************************************************/ + + + +int main (void) +{ + unsigned char XSize, YSize; + unsigned char PosY; + + /* Set screen colors */ + (void) textcolor (COLOR_WHITE); + (void) bordercolor (COLOR_BLACK); + (void) bgcolor (COLOR_BLACK); + + /* Clear the screen, put cursor in upper left corner */ + clrscr (); + + /* Ask for the screen size */ + screensize (&XSize, &YSize); + + /* Draw a border around the screen */ + + /* Top line */ + cputc (CH_ULCORNER); + chline (XSize - 2); + cputc (CH_URCORNER); + + /* Vertical line, left side */ + cvlinexy (0, 1, YSize - 2); + + /* Bottom line */ + cputc (CH_LLCORNER); + chline (XSize - 2); + cputc (CH_LRCORNER); + + /* Vertical line, right side */ + cvlinexy (XSize - 1, 1, YSize - 2); + + /* Write the greeting in the mid of the screen */ + gotoxy ((XSize - strlen (Text)) / 2, YSize / 2); + cprintf ("%s", Text); + + PosY = wherey () + 1; + textcolor (0); /* switch to color #0 */ + cputsxy(3, PosY++, "COLOR 0"); + textcolor (1); /* switch to color #1 */ + cputsxy(3, PosY++, "COLOR 1"); + textcolor (2); /* switch to color #2 */ + cputsxy(3, PosY++, "COLOR 2"); + textcolor (3); /* switch to color #3 */ + cputsxy(3, PosY, "COLOR 3"); + +#if defined(__NES__) || defined(__PCE__) || defined(__GAMATE__) || defined(__ATARI5200__) + + /* Wait for the user to press a button */ + joy_install (joy_static_stddrv); + while (!joy_read (JOY_1)) ; + joy_uninstall (); + +#else + + /* Wait for the user to press a key */ + cgetc (); + +#endif + + /* Clear the screen again */ + clrscr (); + + /* Done */ + return EXIT_SUCCESS; +} -- 2.39.5