diff --git a/asminc/atari7800.inc b/asminc/atari7800.inc new file mode 100644 index 000000000..a7625aa8a --- /dev/null +++ b/asminc/atari7800.inc @@ -0,0 +1,8 @@ +; Atari 7800 TIA & RIOT read / write registers +; +; Karri Kaksonen (karri@sipo.fi), 2022 + +; TIA, RIOT & MARIA registers mapping +.include "atari7800_tia.inc" +.include "atari7800_riot.inc" +.include "atari7800_maria.inc" diff --git a/asminc/atari7800_maria.inc b/asminc/atari7800_maria.inc new file mode 100644 index 000000000..a8857812d --- /dev/null +++ b/asminc/atari7800_maria.inc @@ -0,0 +1,39 @@ +; Atari 7800 MARIA read / write registers +; + +; Read registers +BKGRND := $00 +P0C1 := $01 +P0C2 := $02 +P0C3 := $03 +MWSYNC := $04 +P1C1 := $05 +P1C2 := $06 +P1C3 := $07 +MSTAT := $08 +P2C1 := $09 +P2C2 := $0A +P2C3 := $0B +DPPH := $0C +P3C1 := $0D +P3C2 := $0E +P3C3 := $0F +DPPL := $10 +P4C1 := $11 +P4C2 := $12 +P4C3 := $13 +CHBASE := $14 +P5C1 := $15 +P5C2 := $16 +P5C3 := $17 +OFFSET := $18 +P6C1 := $19 +P6C2 := $1A +P6C3 := $1B +CTRL := $1C +P7C1 := $1D +P7C2 := $1E +P7C3 := $1F + +; Write registers + diff --git a/asminc/atari7800_riot.inc b/asminc/atari7800_riot.inc new file mode 100644 index 000000000..780e34df3 --- /dev/null +++ b/asminc/atari7800_riot.inc @@ -0,0 +1,20 @@ +; Atari 7800 RIOT read / write registers +; +; Source: DASM - vcs.h +; Details available in: Stella Programmer's Guide by Steve Wright +; +; Florent Flament (contact@florentflament.com), 2017 + +; Read registers +SWCHA := $0280 +CTLSWA := $0281 +SWCHB := $0282 +CTLSWB := $0283 +INTIM := $0284 +TIMINT := $0285 + +; Write registers +TIM1T := $0294 +TIM8T := $0295 +TIM64T := $0296 +T1024T := $0297 diff --git a/asminc/atari7800_tia.inc b/asminc/atari7800_tia.inc new file mode 100644 index 000000000..f4439e421 --- /dev/null +++ b/asminc/atari7800_tia.inc @@ -0,0 +1,69 @@ +; Atari 7800 TIA read / write registers +; +; Source: DASM - vcs.h +; Details available in: Stella Programmer's Guide by Steve Wright +; +; Florent Flament (contact@florentflament.com), 2017 + +; Read registers +VSYNC := $00 +VBLANK := $01 +WSYNC := $02 +RSYNC := $03 +NUSIZ0 := $04 +NUSIZ1 := $05 +COLUP0 := $06 +COLUP1 := $07 +COLUPF := $08 +COLUBK := $09 +CTRLPF := $0A +REFP0 := $0B +REFP1 := $0C +PF0 := $0D +PF1 := $0E +PF2 := $0F +RESP0 := $10 +RESP1 := $11 +RESM0 := $12 +RESM1 := $13 +RESBL := $14 +AUDC0 := $15 +AUDC1 := $16 +AUDF0 := $17 +AUDF1 := $18 +AUDV0 := $19 +AUDV1 := $1A +GRP0 := $1B +GRP1 := $1C +ENAM0 := $1D +ENAM1 := $1E +ENABL := $1F +HMP0 := $20 +HMP1 := $21 +HMM0 := $22 +HMM1 := $23 +HMBL := $24 +VDELP0 := $25 +VDELP1 := $26 +VDELBL := $27 +RESMP0 := $28 +RESMP1 := $29 +HMOVE := $2A +HMCLR := $2B +CXCLR := $2C + +; Write registers +CXM0P := $00 +CXM1P := $01 +CXP0FB := $02 +CXP1FB := $03 +CXM0FB := $04 +CXM1FB := $05 +CXBLPF := $06 +CXPPMM := $07 +INPT0 := $08 +INPT1 := $09 +INPT2 := $0A +INPT3 := $0B +INPT4 := $0C +INPT5 := $0D diff --git a/cfg/atari7800.cfg b/cfg/atari7800.cfg new file mode 100644 index 000000000..a2aa7b36c --- /dev/null +++ b/cfg/atari7800.cfg @@ -0,0 +1,50 @@ +# Atari VCS 7800 linker configuration file for cc65 + +SYMBOLS { + __STACKSIZE__: type = weak, value = $0010; # 16 bytes stack +} + +MEMORY { + ZP: file = "", define = yes, start = $0040, size = $00C0, type = rw; + SP: file = "", define = yes, start = $0140, size = $00C0, type = rw; + RAM1: file = "", define = yes, start = $1800, size = $0840, type = rw; + RAM2: file = "", define = yes, start = $2100, size = $0040, type = rw; + RAM3: file = "", define = yes, start = $2200, size = $0600, type = rw; + # "Normal" cartridge rom. Multiple banks arent supported + # by this script. You may change the rom size, but keep + # two things in mind: + # - start must be a multiple of $1000 + # - ROM must end at $ff79 + ROM: file = %O, define = yes, start = $8000, size = $7f7a, type = ro, fill = yes, fillval = $ff; + # Encryption stuff + ROME: file = %O, start = $ff7a, size = $80, type = ro, fill = yes, fillval = $ff; + # Interrupt vectors + ROMV: file = %O, start = $fffa, size = $6, type = ro, fill = yes, fillval = $ff; +} + +SEGMENTS { + ZEROPAGE: load = ZP, type = zp; + STARTUP: load = ROM, type = ro, define = yes; + CODE: load = ROM, type = ro, define = yes; + RODATA: load = ROM, type = ro, define = yes, align = 256; + DATA: load = ROM, run = RAM1, type = rw, define = yes; + BSS: load = RAM1, type = bss, define = yes; + VECTORS: load = ROM, type = ro, define = yes; + ENCRYPTION: load = ROME, type = ro define = yes; +} + +FEATURES { + CONDES: type = constructor, + label = __CONSTRUCTOR_TABLE__, + count = __CONSTRUCTOR_COUNT__, + segment = ONCE; + CONDES: type = destructor, + label = __DESTRUCTOR_TABLE__, + count = __DESTRUCTOR_COUNT__, + segment = RODATA; + CONDES: type = interruptor, + label = __INTERRUPTOR_TABLE__, + count = __INTERRUPTOR_COUNT__, + segment = RODATA, + import = __CALLIRQ__; +} diff --git a/doc/atari7800.sgml b/doc/atari7800.sgml new file mode 100644 index 000000000..95868bbd9 --- /dev/null +++ b/doc/atari7800.sgml @@ -0,0 +1,122 @@ + + +
+Atari 7800 specific information for cc65 +<author> +<url url="mailto:contact@florentflament.com" name="Florent Flament"><newline> + +<abstract> +An overview over the Atari 7800 runtime system as it is implemented +for the cc65 C compiler. +</abstract> + +<!-- Table of contents --> +<toc> + +<!-- Begin the document --> + +<sect>Overview<p> + +This file contains an overview of the Atari 7800 runtime system as it +comes with the cc65 C compiler. It describes the memory layout, Atari +7800 specific header files and any pitfalls specific to that platform. + +<sect>Binary format<p> + +The default binary output format generated by the linker for the Atari +7800 target is a 4K cartridge image. + +<sect>Memory layout<p> + +cc65 generated programs with the default setup can use RAM from +$0080 to $00FF - __STACKSIZE__, where __STACKSIZE__ is +the size of the system stack with a default value of 16 bytes. The +size of the system stack can be customized by defining the +__STACKSIZE__ linker variable. + +Special locations: + +<descrip> + <tag/Stack/ The C runtime stack is located at $00FF - + __STACKSIZE__ and growing downwards. + + <tag/Heap/ The C heap is located at $0080 and grows upwards. + +</descrip><p> + +<sect>Start-up condition<p> + +When powered-up, the Atari 7800 TIA registers contain random +values. During the initialization phase, the start-up code needs to +initialize the TIA registers to sound values (or else the console has +an unpredictable behavior). In this implementation, zeros are written +to all of TIA registers during the start-up phase. + +Note that RIOT registers (mostly timers) are left uninitialized, as +they don't have any consequence on the console behavior. + +<sect>Platform specific header files<p> + +Programs containing Atari 7800 specific code may use the +<tt/atari7800.h/ header file. + +The following pseudo variables declared in the <tt/atari7800.h/ header +file allow access to the Atari 7800 TIA & RIOT chips registers. + +<descrip> + + <tag><tt/TIA/</tag> The <tt/TIA/ structure allows read/write access + to the Atari 7800 TIA chip registers. See the <tt/_tia.h/ header + file located in the include directory for the declaration of the + structure. Also refer to the Stella Programmer's Guide by Steve + Wright for a detailed description of the chip and its registers. + + <tag><tt/RIOT/</tag> The <tt/RIOT/ structure allows read/write + access to the Atari 7800 RIOT chip registers. See the + <tt/_riot.h/ header file located in the include directory for the + declaration of the structure. Also refer to the Stella Programmer's + Guide by Steve Wright for a detailed description of the chip and its + registers. + +</descrip><p> + + +<sect>Loadable drivers<p> + +There are no drivers for the Atari 7800. + + +<sect>Limitations<p> + +TBD + + +<sect>Other hints<p> + +One may write a custom linker configuration file to tune the memory +layout of a program. See the <tt/atari7800.cfg/ file in the cfg +directory as a starting point. + + +<sect>License<p> + +This software is provided 'as-is', without any expressed or implied +warranty. In no event will the authors be held liable for any damages +arising from the use of this software. + +Permission is granted to anyone to use this software for any purpose, +including commercial applications, and to alter it and redistribute it +freely, subject to the following restrictions: + +<enum> +<item> The origin of this software must not be misrepresented; you must not + claim that you wrote the original software. If you use this software + in a product, an acknowledgment in the product documentation would be + appreciated but is not required. +<item> Altered source versions must be plainly marked as such, and must not + be misrepresented as being the original software. +<item> This notice may not be removed or altered from any source + distribution. +</enum> + +</article> diff --git a/include/_maria.h b/include/_maria.h new file mode 100644 index 000000000..461119fda --- /dev/null +++ b/include/_maria.h @@ -0,0 +1,63 @@ +/*****************************************************************************/ +/* */ +/* _maria.h */ +/* */ +/* Atari 7800, Maria chip register hardware structures */ +/* */ +/* */ +/* This software is provided 'as-is', without any expressed or implied */ +/* warranty. In no event will the authors be held liable for any damages */ +/* arising from the use of this software. */ +/* */ +/* Permission is granted to anyone to use this software for any purpose, */ +/* including commercial applications, and to alter it and redistribute it */ +/* freely, subject to the following restrictions: */ +/* */ +/* 1. The origin of this software must not be misrepresented; you must not */ +/* claim that you wrote the original software. If you use this software */ +/* in a product, an acknowledgment in the product documentation would be */ +/* appreciated but is not required. */ +/* 2. Altered source versions must be plainly marked as such, and must not */ +/* be misrepresented as being the original software. */ +/* 3. This notice may not be removed or altered from any source */ +/* distribution. */ +/* */ +/*****************************************************************************/ + +/* + * MARIA registers + */ +struct __maria { + unsigned char bkgrnd; + unsigned char p0c1; + unsigned char p0c2; + unsigned char p0c3; + unsigned char wsync; + unsigned char p1c1; + unsigned char p1c2; + unsigned char p1c3; + unsigned char mstat; + unsigned char p2c1; + unsigned char p2c2; + unsigned char p2c3; + unsigned char dpph; + unsigned char p3c1; + unsigned char p3c2; + unsigned char p3c3; + unsigned char dppl; + unsigned char p4c1; + unsigned char p4c2; + unsigned char p4c3; + unsigned char chbase; + unsigned char p5c1; + unsigned char p5c2; + unsigned char p5c3; + unsigned char offset; + unsigned char p6c1; + unsigned char p6c2; + unsigned char p6c3; + unsigned char ctrl; + unsigned char p7c1; + unsigned char p7c2; + unsigned char p7c3; +}; diff --git a/include/atari7800.h b/include/atari7800.h new file mode 100644 index 000000000..378f8786a --- /dev/null +++ b/include/atari7800.h @@ -0,0 +1,105 @@ +/*****************************************************************************/ +/* */ +/* Atari VCS 7800 TIA & RIOT registers addresses */ +/* */ +/* Karri Kaksonen (karri@sipo.fi), 2022 */ +/* */ +/* */ +/*****************************************************************************/ + + + +#ifndef _ATARI7800_H +#define _ATARI7800_H + +/* Check for errors */ +#if !defined(__ATARI7800__) +# error This module may only be used when compiling for the Atari 7800! +#endif + +/*****************************************************************************/ +/* Data */ +/*****************************************************************************/ + + + +/* Color defines */ +#define COLOR_BLACK 0x00 +#define COLOR_WHITE 0x0F + +/* TGI color defines (default palette) */ +#define TGI_COLOR_BLACK COLOR_BLACK +#define TGI_COLOR_WHITE COLOR_WHITE + +/* Masks for joy_read */ +#define JOY_RIGHT_MASK 0x80 +#define JOY_LEFT_MASK 0x40 +#define JOY_DOWN_MASK 0x20 +#define JOY_UP_MASK 0x10 +#define JOY_BTN_1_MASK 0x01 +#define JOY_BTN_2_MASK 0x02 + +#define JOY_BTN_A_MASK JOY_BTN_1_MASK +#define JOY_BTN_B_MASK JOY_BTN_2_MASK + +#define JOY_BTN_A(v) ((v) & JOY_BTN_A_MASK) +#define JOY_BTN_B(v) ((v) & JOY_BTN_B_MASK) + +/* No support for dynamically loadable drivers */ +#define DYN_DRV 0 + +#include <_tia.h> +#define TIA (*(struct __tia*)0x0000) + +#include <_riot.h> +#define RIOT (*(struct __riot*)0x0280) + +#include <_maria.h> +#define MARIA (*(struct __maria*)0x0020) + +/* + * Alternative MARIA register definitions. + */ +#define BKGRND MARIA.bkgrnd +#define BACKGRND MARIA.bkgrnd +#define P0C1 MARIA.p0c1 +#define P0C2 MARIA.p0c2 +#define P0C3 MARIA.p0c3 +#define WSYNC MARIA.wsync +#define P1C1 MARIA.p1c1 +#define P1C2 MARIA.p1c2 +#define P1C3 MARIA.p1c3 +#define MSTAT MARIA.mstat +#define P2C1 MARIA.p2c1 +#define P2C2 MARIA.p2c2 +#define P2C3 MARIA.p2c3 +#define DPPH MARIA.dpph +#define DPH MARIA.dpph +#define P3C1 MARIA.p3c1 +#define P3C2 MARIA.p3c2 +#define P3C3 MARIA.p3c3 +#define DPPL MARIA.dppl +#define DPL MARIA.dppl +#define P4C1 MARIA.p4c1 +#define P4C2 MARIA.p4c2 +#define P4C3 MARIA.p4c3 +#define CHBASE MARIA.chbase +#define P5C1 MARIA.p5c1 +#define P5C2 MARIA.p5c2 +#define P5C3 MARIA.p5c3 +#define OFFSET MARIA.offset +#define P6C1 MARIA.p6c1 +#define P6C2 MARIA.p6c2 +#define P6C3 MARIA.p6c3 +#define CTRL MARIA.ctrl +#define P7C1 MARIA.p7c1 +#define P7C2 MARIA.p7c2 +#define P7C3 MARIA.p7c3 + +/* + * MSTAT register constants + */ +#define MSTAT_VBLANK 0x80 /* vblank is on when bit 7 is set */ + +/* End of atari7800.h */ +#endif