diff --git a/README.md b/README.md index 359fdaa08..f8914c45a 100644 --- a/README.md +++ b/README.md @@ -31,6 +31,7 @@ including - the Watara Supervision console. - the VTech Creativision console. - the Oric Atmos. +- the Oric Telestrat. - the Lynx console. - the Ohio Scientific Challenger 1P. diff --git a/asminc/telestrat.inc b/asminc/telestrat.inc new file mode 100644 index 000000000..2c3502ba8 --- /dev/null +++ b/asminc/telestrat.inc @@ -0,0 +1,148 @@ +; +; Oric Telemon definition +; Telemon 2.4 & Telemon 3.0 +; For telemon 3.0 check http://orix.oric.org +; + + +; --------------------------------------------------------------------------- +; Constants + +SCREEN_XSIZE = 40 ; screen columns +SCREEN_YSIZE = 28 ; screen rows + +FUNCTKEY = $A5 + +FNAME_LEN = 11 ; maximum length of file-name + + +; --------------------------------------------------------------------------- +; Zero page + +; --------------------------------------------------------------------------- +; Page 00 +RES := $00 +RESB := $02 + +TR0 := $0C +TR1 := $0D + +PTR_READ_DEST := $2C ; used for XFREAD and XWRITE only in telemon 3.0 + +HRSX := $46 +HRSY := $47 + +HRS1 := $4D +HRS2 := $4F +HRS3 := $51 +HRS4 := $53 +HRS5 := $55 + + + +; --------------------------------------------------------------------------- +; Low memory + + + + +; --------------------------------------------------------------------------- +; I/O locations + +; 6522 +.struct VIA ; Versatile Interface Adapter + .res $0300 +PRB .byte ; Port Register B +PRA .byte ; Port Register A +DDRB .byte ; Data Direction Register B +DDRA .byte ; Data Direction Register A +T1 .word ; Timer 1 +T1L .word ; Timer 1 Latch +T2 .word ; Timer 2 +SR .byte ; Shift Register +ACR .byte ; Auxiliary Control Register +PCR .byte ; Peripheral Control Register +IFR .byte ; Interrupt Flags Register +IER .byte ; Interrupt Enable Register +PRA2 .byte ; Port Register A without handshaking +.endstruct + + +.struct VIA2 ; Versatile Interface Adapter + .res $0320 +PRB .byte ; Port Register B +PRA .byte ; Port Register A +DDRB .byte ; Data Direction Register B +DDRA .byte ; Data Direction Register A +T1 .word ; Timer 1 +T1L .word ; Timer 1 Latch +T2 .word ; Timer 2 +SR .byte ; Shift Register +ACR .byte ; Auxiliary Control Register +PCR .byte ; Peripheral Control Register +IFR .byte ; Interrupt Flags Register +IER .byte ; Interrupt Enable Register +PRA2 .byte ; Port Register A without handshaking +.endstruct + +; 6551 +.struct ACIA ; Asynchronous Communications Interface Adapter + .res $031C +DATA .byte +STATUS .byte +CMD .byte ; Command register +CTRL .byte ; Control register +.endstruct + +SCREEN := $BB80 + + +; --------------------------------------------------------------------------- +; ROM entries + +; primitives telemon 2.4 +XRD0 = $08 +XRDW0 = $0C +XWR0 = $10 +XWSTR0 = $14 +XTEXT = $19 +XHIRES = $1A +XMINMA = $1F +XFREAD = $27 ; only in TELEMON 3.0 +XOPEN = $30 ; only in TELEMON 3.0 +XCOSCR = $34 ; switch off cursor +XCSSCR = $35 ; switch on cursor +XCLOSE = $3A ; only in TELEMON 3.0 Close file +XFWRITE = $3B ; only in TELEMON 3.0 write file +XSONPS = $40 +XOUPS = $42 +XPLAY = $43 +XSOUND = $44 +XMUSIC = $45 +XZAP = $46 +XSHOOT = $47 +XCIRCL = $8F +XCURSE = $90 +XPAPER = $92 +XINK = $93 +XEXPLO = $9C +XPING = $9D + + +; --------------------------------------------------------------------------- +; Page $500 + +BUFNOM := $517 +BUFEDT := $590 + +MAX_BUFEDT_LENGTH=110 + +; Hardware +CH376_DATA :=$340 +CH376_COMMAND :=$341 + +; MACRO + +.macro BRK_TELEMON value + .byte $00,value +.endmacro diff --git a/cfg/telestrat.cfg b/cfg/telestrat.cfg new file mode 100644 index 000000000..395a936e1 --- /dev/null +++ b/cfg/telestrat.cfg @@ -0,0 +1,40 @@ +SYMBOLS { + __ORIXHDR__: type = import; + __STACKSIZE__: type = weak, value = $0800; # 2K stack + __RAMEND__: type = weak, value = $9800; +} +MEMORY { + ZP: file = "", define = yes, start = $00E0, size = $001A; + ORIXHDR: file = %O, type = ro, start = $0000, size = $001F; + BASHEAD: file = %O, define = yes, start = $0801, size = $000D; + MAIN: file = %O, define = yes, start = __BASHEAD_LAST__, size = __RAMEND__ - __MAIN_START__; + BSS: file = "", start = __ONCE_RUN__, size = __RAMEND__ - __STACKSIZE__ - __ONCE_RUN__; +} +SEGMENTS { + ZEROPAGE: load = ZP, type = zp; + ORIXHDR: load = ORIXHDR, type = ro; + STARTUP: load = MAIN, type = ro; + LOWCODE: load = MAIN, type = ro, optional = yes; + CODE: load = MAIN, type = ro; + RODATA: load = MAIN, type = ro; + DATA: load = MAIN, type = rw; + INIT: load = MAIN, type = rw; + ONCE: load = MAIN, type = ro, define = yes; + BASTAIL: load = MAIN, type = ro, optional = yes; + BSS: load = BSS, type = bss, 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/telestrat.sgml b/doc/telestrat.sgml new file mode 100644 index 000000000..9032156ee --- /dev/null +++ b/doc/telestrat.sgml @@ -0,0 +1,185 @@ + + +
+ +Oric Telestrat-specific information for cc65 +<author> +<url url="mailto:jede@oric.org" name="Jede">,<newline> + +<date>2017-01-22 + +<abstract> +An overview over the Telestrat (Telemon 3.0 : http://orix.oric.org) 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 Telestrat runtime system as it comes with the +cc65 C compiler. It describes the memory layout, Telestrat-specific header files, +available drivers, and any pitfalls specific to that platform. + +Please note that Telestrat-specific functions are just mentioned here, they are +described in detail in the separate <url url="funcref.html" name="function +reference">. Even functions marked as "platform dependent" may be available on +more than one platform. Please see the function reference for more +information. + +<sect>Binary format<p> + +The standard binary output format generated the linker for the Telestrat target +is a machine language program with a 20 bytes header described here : http://orix.oric.org/doku.php?id=orix:header + +This header is used for Telemon 3.0. + +Anyway, for Telemon 2.4, there is no file management, there is no TAPE routine in Telemon, there is no way to load a binary easily. + +Stratsed (the Telestrat operating system) handles files management. Stratsed is loaded to memory from floppy disk. + +There is no tool to insert a binary in a Stratsed floppy disk. + +The only way to load a binary (for Telemon 2.4) is to : +<itemize> +<item>remove the 20 bytes header +<item>download osdk : http://osdk.defence-force.org/index?page=download +<item>use Floppybuilder in OSDK to insert the binary with the tool (please read FloppyBuilder manual to insert your binary, and to start microdisc boot sector when Telestrat starts) +</itemize> + +Please note also, that the binary converted into TAP file, will not produce a right stratsed file when tap2dsk and old2mfm are used. You will be in the case that Telestrat/Stratsed crashed when you do "DIR" command. + +If you know the Stratsed disk format, please contact the author of this doc. + + +<sect>Memory layout<p> + +In the standard setup, cc65-generated programs use the memory from +$0801 to $9800; so, nearly 37K of memory (including the stack) is +available. ROM calls are possible without further precautions. + + +Special locations: + +<descrip> + <tag/Stack/ + The C runtime stack is located at $97FF (or $B3FF), and grows + downwards. + + <tag/Heap/ + The C heap is located at the end of the program, and grows towards the C + runtime stack. + +</descrip><p> + + + +<sect>Platform-specific header files<p> + +Programs containing Telestrat -specific code may use the <tt/telestrat.h/ header file. + + +<sect1>Telestrat-specific functions<p> + +The functions listed below are special for the Telestrat. See the <url +url="funcref.html" name="function reference"> for declaration and usage. + +<itemize> +<item>explode +<item>ping +<item>shoot +<item>zap +<item>oups +</itemize> + + +<sect1>Hardware access<p> + +The following pseudo variables declared in the <tt/telestrat.h/ header file do allow +access to hardware located in the address space. Some variables are +structures; accessing the struct fields will access the chip registers. + +<descrip> + + <tag><tt/VIA/</tag> + Access to the VIA (Versatile Interface Adapter) chip is available via the + <tt/VIA/ variable. The structure behind this variable is explained in <tt/_6522.h/. + +</descrip><p> + + +<sect>Loadable drivers<p> + +<sect1>Extended memory drivers<p> + +No extended memory drivers are currently available for the Telestrat. + + +<sect1>Joystick drivers<p> + +<descrip> + +telemon 2.4 & 3.0 manages joysticks but it had been handled yet. + +</descrip> + + +<sect1>Mouse drivers<p> + +<descrip> + +Telestrat manages also mouse, but it had been no handled yet in this version. + +</descrip> + +<sect1>RS232 device drivers<p> + +<descrip> + +Telestrat has a RS232 port, but it's not used + +</descrip>< + +<sect>Limitations<label id="limitations"><p> + +<sect1>Disk I/O<p> + +Telemon 3.0 handles fopen, fread, fclose primitives. It means that this function will crash the Telestrat because Telemon 2.4 does not have these primitives. +By the way, Telemon 3.0 uses an extension "ch376 card" which handles sdcard and FAT 32 usb key. In the next version of Telemon, FT DOS, Sedoric, Stratsed will be handled in these 3 primitives (fopen, fread, fclose). + +<itemize> +<item>fclose +<item>fopen +<item>fread +</itemize> + + + +<sect>Other hints<p> + + +<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/telestrat.h b/include/telestrat.h new file mode 100644 index 000000000..5a090647b --- /dev/null +++ b/include/telestrat.h @@ -0,0 +1,43 @@ +/*****************************************************************************/ +/* */ +/* telestrat.h */ +/* */ +/* Oric Telestrat system-specific definitions */ +/* */ +/* */ +/* */ +/* (C) 2017 Debrune Jérome, <jede@oric.org> */ +/* */ +/* */ +/* 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. */ +/* */ +/*****************************************************************************/ + + + +void oups(); +void ping(); +void zap(); +void shoot(); +void explode(); + +void kbdclick1(); + + + + diff --git a/libsrc/Makefile b/libsrc/Makefile index 6b9869681..54b54860c 100644 --- a/libsrc/Makefile +++ b/libsrc/Makefile @@ -32,7 +32,8 @@ TARGETS = apple2 \ pce \ sim6502 \ sim65c02 \ - supervision + supervision\ + telestrat DRVTYPES = emd \ joy \ diff --git a/libsrc/telestrat/_scrsize.s b/libsrc/telestrat/_scrsize.s new file mode 100644 index 000000000..75bd456ce --- /dev/null +++ b/libsrc/telestrat/_scrsize.s @@ -0,0 +1,19 @@ +; +; 2003-04-13, Ullrich von Bassewitz +; 2013-07-16, Greg King +; +; Screen size variables +; + + .export screensize + .include "telestrat.inc" + +.proc screensize + + ldx #SCREEN_XSIZE + ldy #SCREEN_YSIZE + rts + +.endproc + + diff --git a/libsrc/telestrat/close.s b/libsrc/telestrat/close.s new file mode 100644 index 000000000..40e2c10b3 --- /dev/null +++ b/libsrc/telestrat/close.s @@ -0,0 +1,16 @@ +; jede jede@oric.org 2017-01-22 + + .export _close + + .import addysp,popax + + .include "zeropage.inc" + .include "telestrat.inc" + .include "errno.inc" + .include "fcntl.inc" + +; int open (const char* name, int flags, ...); /* May take a mode argument */ +.proc _close + BRK_TELEMON XCLOSE ; launch primitive ROM + rts +.endproc diff --git a/libsrc/telestrat/crt0.s b/libsrc/telestrat/crt0.s new file mode 100644 index 000000000..59b1ea642 --- /dev/null +++ b/libsrc/telestrat/crt0.s @@ -0,0 +1,91 @@ +; +; Startup code for cc65 (Oric version) +; +; By Debrune Jérôme <jede@oric.org> and Ullrich von Bassewitz <uz@cc65.org> +; + + .export _exit + .export __STARTUP__ : absolute = 1 ; Mark as startup + + .import initlib, donelib + .import callmain, zerobss + .import __MAIN_START__, __MAIN_SIZE__ + + .include "zeropage.inc" + .include "telestrat.inc" + +; ------------------------------------------------------------------------ +; Place the startup code in a special segment. + +.segment "STARTUP" + + tsx + stx spsave ; Save system stk ptr + +; Save space by putting some of the start-up code in a segment +; that will be re-used. + + jsr init + +; Clear the BSS variables (after the constructors have been run). + + jsr zerobss + +; Push the command-line arguments; and, call main(). + + jsr callmain + +; Call the module destructors. This is also the exit() entry. + +_exit: jsr donelib + +; Restore the system stuff. + + ldx spsave + txs + +; Copy back the zero-page stuff. + + ldx #zpspace - 1 +L2: lda zpsave,x + sta sp,x + dex + bpl L2 + +; Back to BASIC. + + rts + +; ------------------------------------------------------------------------ +; Put this code in a place that will be re-used by BSS, the heap, +; and the C stack. + +.segment "ONCE" + +; Save the zero-page area that we're about to use. + +init: ldx #zpspace - 1 +L1: lda sp,x + sta zpsave,x + dex + bpl L1 + + +; Set up the C stack. + + lda #<(__MAIN_START__ + __MAIN_SIZE__) + ldx #>(__MAIN_START__ + __MAIN_SIZE__) + sta sp + stx sp+1 ; Set argument stack ptr + +; Call the module constructors. + + jmp initlib + +; ------------------------------------------------------------------------ + +.segment "INIT" + +spsave: .res 1 +stsave: .res 1 +zpsave: .res zpspace diff --git a/libsrc/telestrat/ctype.s b/libsrc/telestrat/ctype.s new file mode 100644 index 000000000..79edafbb2 --- /dev/null +++ b/libsrc/telestrat/ctype.s @@ -0,0 +1,299 @@ +; +; Ullrich von Bassewitz, 2003-04-13 +; +; Character specification table. +; + +; The tables are readonly, put them into the rodata segment + +.rodata + +; The following 256 byte wide table specifies attributes for the isxxx type +; of functions. Doing it by a table means some overhead in space, but it +; has major advantages: +; +; * It is fast. If it were'nt for the slow parameter passing of cc65, one +; could even define macros for the isxxx functions (this is usually +; done on other platforms). +; +; * It is highly portable. The only unportable part is the table itself, +; all real code goes into the common library. +; +; * We save some code in the isxxx functions. +; +; +; Bit assignments: +; +; 0 - Lower case char +; 1 - Upper case char +; 2 - Numeric digit +; 3 - Hex digit (both, lower and upper) +; 4 - Control character +; 5 - The space character itself +; 6 - Other whitespace (that is: '\f', '\n', '\r', '\t' and '\v') +; 7 - Space or tab character + + .export __ctype + +__ctype: + .byte $10 ; 0/00 ___ctrl_@___ + .byte $10 ; 1/01 ___ctrl_A___ + .byte $10 ; 2/02 ___ctrl_B___ + .byte $10 ; 3/03 ___ctrl_C___ + .byte $10 ; 4/04 ___ctrl_D___ + .byte $10 ; 5/05 ___ctrl_E___ + .byte $10 ; 6/06 ___ctrl_F___ + .byte $10 ; 7/07 ___ctrl_G___ + .byte $10 ; 8/08 ___ctrl_H___ + .byte $D0 ; 9/09 ___ctrl_I___ + .byte $50 ; 10/0a ___ctrl_J___ + .byte $50 ; 11/0b ___ctrl_K___ + .byte $50 ; 12/0c ___ctrl_L___ + .byte $50 ; 13/0d ___ctrl_M___ + .byte $10 ; 14/0e ___ctrl_N___ + .byte $10 ; 15/0f ___ctrl_O___ + .byte $10 ; 16/10 ___ctrl_P___ + .byte $10 ; 17/11 ___ctrl_Q___ + .byte $10 ; 18/12 ___ctrl_R___ + .byte $10 ; 19/13 ___ctrl_S___ + .byte $10 ; 20/14 ___ctrl_T___ + .byte $10 ; 21/15 ___ctrl_U___ + .byte $10 ; 22/16 ___ctrl_V___ + .byte $10 ; 23/17 ___ctrl_W___ + .byte $10 ; 24/18 ___ctrl_X___ + .byte $10 ; 25/19 ___ctrl_Y___ + .byte $10 ; 26/1a ___ctrl_Z___ + .byte $10 ; 27/1b ___ctrl_[___ + .byte $10 ; 28/1c ___ctrl_\___ + .byte $10 ; 29/1d ___ctrl_]___ + .byte $10 ; 30/1e ___ctrl_^___ + .byte $10 ; 31/1f ___ctrl_____ + .byte $A0 ; 32/20 ___SPACE___ + .byte $00 ; 33/21 _____!_____ + .byte $00 ; 34/22 _____"_____ + .byte $00 ; 35/23 _____#_____ + .byte $00 ; 36/24 _____$_____ + .byte $00 ; 37/25 _____%_____ + .byte $00 ; 38/26 _____&_____ + .byte $00 ; 39/27 _____'_____ + .byte $00 ; 40/28 _____(_____ + .byte $00 ; 41/29 _____)_____ + .byte $00 ; 42/2a _____*_____ + .byte $00 ; 43/2b _____+_____ + .byte $00 ; 44/2c _____,_____ + .byte $00 ; 45/2d _____-_____ + .byte $00 ; 46/2e _____._____ + .byte $00 ; 47/2f _____/_____ + .byte $0C ; 48/30 _____0_____ + .byte $0C ; 49/31 _____1_____ + .byte $0C ; 50/32 _____2_____ + .byte $0C ; 51/33 _____3_____ + .byte $0C ; 52/34 _____4_____ + .byte $0C ; 53/35 _____5_____ + .byte $0C ; 54/36 _____6_____ + .byte $0C ; 55/37 _____7_____ + .byte $0C ; 56/38 _____8_____ + .byte $0C ; 57/39 _____9_____ + .byte $00 ; 58/3a _____:_____ + .byte $00 ; 59/3b _____;_____ + .byte $00 ; 60/3c _____<_____ + .byte $00 ; 61/3d _____=_____ + .byte $00 ; 62/3e _____>_____ + .byte $00 ; 63/3f _____?_____ + + .byte $00 ; 64/40 _____@_____ + .byte $0A ; 65/41 _____A_____ + .byte $0A ; 66/42 _____B_____ + .byte $0A ; 67/43 _____C_____ + .byte $0A ; 68/44 _____D_____ + .byte $0A ; 69/45 _____E_____ + .byte $0A ; 70/46 _____F_____ + .byte $02 ; 71/47 _____G_____ + .byte $02 ; 72/48 _____H_____ + .byte $02 ; 73/49 _____I_____ + .byte $02 ; 74/4a _____J_____ + .byte $02 ; 75/4b _____K_____ + .byte $02 ; 76/4c _____L_____ + .byte $02 ; 77/4d _____M_____ + .byte $02 ; 78/4e _____N_____ + .byte $02 ; 79/4f _____O_____ + .byte $02 ; 80/50 _____P_____ + .byte $02 ; 81/51 _____Q_____ + .byte $02 ; 82/52 _____R_____ + .byte $02 ; 83/53 _____S_____ + .byte $02 ; 84/54 _____T_____ + .byte $02 ; 85/55 _____U_____ + .byte $02 ; 86/56 _____V_____ + .byte $02 ; 87/57 _____W_____ + .byte $02 ; 88/58 _____X_____ + .byte $02 ; 89/59 _____Y_____ + .byte $02 ; 90/5a _____Z_____ + .byte $00 ; 91/5b _____[_____ + .byte $00 ; 92/5c _____\_____ + .byte $00 ; 93/5d _____]_____ + .byte $00 ; 94/5e _____^_____ + .byte $00 ; 95/5f _UNDERLINE_ + .byte $00 ; 96/60 ___grave___ + .byte $09 ; 97/61 _____a_____ + .byte $09 ; 98/62 _____b_____ + .byte $09 ; 99/63 _____c_____ + .byte $09 ; 100/64 _____d_____ + .byte $09 ; 101/65 _____e_____ + .byte $09 ; 102/66 _____f_____ + .byte $01 ; 103/67 _____g_____ + .byte $01 ; 104/68 _____h_____ + .byte $01 ; 105/69 _____i_____ + .byte $01 ; 106/6a _____j_____ + .byte $01 ; 107/6b _____k_____ + .byte $01 ; 108/6c _____l_____ + .byte $01 ; 109/6d _____m_____ + .byte $01 ; 110/6e _____n_____ + .byte $01 ; 111/6f _____o_____ + .byte $01 ; 112/70 _____p_____ + .byte $01 ; 113/71 _____q_____ + .byte $01 ; 114/72 _____r_____ + .byte $01 ; 115/73 _____s_____ + .byte $01 ; 116/74 _____t_____ + .byte $01 ; 117/75 _____u_____ + .byte $01 ; 118/76 _____v_____ + .byte $01 ; 119/77 _____w_____ + .byte $01 ; 120/78 _____x_____ + .byte $01 ; 121/79 _____y_____ + .byte $01 ; 122/7a _____z_____ + .byte $00 ; 123/7b _____{_____ + .byte $00 ; 124/7c _____|_____ + .byte $00 ; 125/7d _____}_____ + .byte $00 ; 126/7e _____~_____ + .byte $40 ; 127/7f ____DEL____ + + .byte $00 ; 128/80 ___________ + .byte $00 ; 129/81 ___________ + .byte $00 ; 130/82 ___________ + .byte $00 ; 131/83 ___________ + .byte $00 ; 132/84 ___________ + .byte $00 ; 133/85 ___________ + .byte $00 ; 134/86 ___________ + .byte $00 ; 135/87 ___________ + .byte $00 ; 136/88 ___________ + .byte $00 ; 137/89 ___________ + .byte $00 ; 138/8a ___________ + .byte $00 ; 139/8b ___________ + .byte $00 ; 140/8c ___________ + .byte $00 ; 141/8d ___________ + .byte $00 ; 142/8e ___________ + .byte $00 ; 143/8f ___________ + .byte $00 ; 144/90 ___________ + .byte $00 ; 145/91 ___________ + .byte $00 ; 146/92 ___________ + .byte $10 ; 147/93 ___________ + .byte $00 ; 148/94 ___________ + .byte $00 ; 149/95 ___________ + .byte $00 ; 150/96 ___________ + .byte $00 ; 151/97 ___________ + .byte $00 ; 152/98 ___________ + .byte $00 ; 153/99 ___________ + .byte $00 ; 154/9a ___________ + .byte $00 ; 155/9b ___________ + .byte $00 ; 156/9c ___________ + .byte $00 ; 157/9d ___________ + .byte $00 ; 158/9e ___________ + .byte $00 ; 159/9f ___________ + + .byte $00 ; 160/a0 ___________ + .byte $00 ; 161/a1 ___________ + .byte $00 ; 162/a2 ___________ + .byte $00 ; 163/a3 ___________ + .byte $00 ; 164/a4 ___________ + .byte $00 ; 165/a5 ___________ + .byte $00 ; 166/a6 ___________ + .byte $00 ; 167/a7 ___________ + .byte $00 ; 168/a8 ___________ + .byte $00 ; 169/a9 ___________ + .byte $00 ; 170/aa ___________ + .byte $00 ; 171/ab ___________ + .byte $00 ; 172/ac ___________ + .byte $00 ; 173/ad ___________ + .byte $00 ; 174/ae ___________ + .byte $00 ; 175/af ___________ + .byte $00 ; 176/b0 ___________ + .byte $00 ; 177/b1 ___________ + .byte $00 ; 178/b2 ___________ + .byte $00 ; 179/b3 ___________ + .byte $00 ; 180/b4 ___________ + .byte $00 ; 181/b5 ___________ + .byte $00 ; 182/b6 ___________ + .byte $00 ; 183/b7 ___________ + .byte $00 ; 184/b8 ___________ + .byte $00 ; 185/b9 ___________ + .byte $00 ; 186/ba ___________ + .byte $00 ; 187/bb ___________ + .byte $00 ; 188/bc ___________ + .byte $00 ; 189/bd ___________ + .byte $00 ; 190/be ___________ + .byte $00 ; 191/bf ___________ + + .byte $02 ; 192/c0 ___________ + .byte $02 ; 193/c1 ___________ + .byte $02 ; 194/c2 ___________ + .byte $02 ; 195/c3 ___________ + .byte $02 ; 196/c4 ___________ + .byte $02 ; 197/c5 ___________ + .byte $02 ; 198/c6 ___________ + .byte $02 ; 199/c7 ___________ + .byte $02 ; 200/c8 ___________ + .byte $02 ; 201/c9 ___________ + .byte $02 ; 202/ca ___________ + .byte $02 ; 203/cb ___________ + .byte $02 ; 204/cc ___________ + .byte $02 ; 205/cd ___________ + .byte $02 ; 206/ce ___________ + .byte $02 ; 207/cf ___________ + .byte $02 ; 208/d0 ___________ + .byte $02 ; 209/d1 ___________ + .byte $02 ; 210/d2 ___________ + .byte $02 ; 211/d3 ___________ + .byte $02 ; 212/d4 ___________ + .byte $02 ; 213/d5 ___________ + .byte $02 ; 214/d6 ___________ + .byte $02 ; 215/d7 ___________ + .byte $02 ; 216/d8 ___________ + .byte $02 ; 217/d9 ___________ + .byte $02 ; 218/da ___________ + .byte $02 ; 219/db ___________ + .byte $02 ; 220/dc ___________ + .byte $02 ; 221/dd ___________ + .byte $02 ; 222/de ___________ + .byte $00 ; 223/df ___________ + .byte $01 ; 224/e0 ___________ + .byte $01 ; 225/e1 ___________ + .byte $01 ; 226/e2 ___________ + .byte $01 ; 227/e3 ___________ + .byte $01 ; 228/e4 ___________ + .byte $01 ; 229/e5 ___________ + .byte $01 ; 230/e6 ___________ + .byte $01 ; 231/e7 ___________ + .byte $01 ; 232/e8 ___________ + .byte $01 ; 233/e9 ___________ + .byte $01 ; 234/ea ___________ + .byte $01 ; 235/eb ___________ + .byte $01 ; 236/ec ___________ + .byte $01 ; 237/ed ___________ + .byte $01 ; 238/ee ___________ + .byte $01 ; 239/ef ___________ + .byte $01 ; 240/f0 ___________ + .byte $01 ; 241/f1 ___________ + .byte $01 ; 242/f2 ___________ + .byte $01 ; 243/f3 ___________ + .byte $01 ; 244/f4 ___________ + .byte $01 ; 245/f5 ___________ + .byte $01 ; 246/f6 ___________ + .byte $01 ; 247/f7 ___________ + .byte $01 ; 248/f8 ___________ + .byte $01 ; 249/f9 ___________ + .byte $01 ; 250/fa ___________ + .byte $01 ; 251/fb ___________ + .byte $01 ; 252/fc ___________ + .byte $01 ; 253/fd ___________ + .byte $01 ; 254/fe ___________ + .byte $00 ; 255/ff ___________ + diff --git a/libsrc/telestrat/mainargs.s b/libsrc/telestrat/mainargs.s new file mode 100644 index 000000000..0c9e799da --- /dev/null +++ b/libsrc/telestrat/mainargs.s @@ -0,0 +1,120 @@ +; +; 2003-03-07, Ullrich von Bassewitz +; 2011-01-28, Stefan Haubenthal +; 2014-09-10, Greg King +; +; Set up arguments for main +; + + .constructor initmainargs, 24 + .import __argc, __argv + .import ptr1 + .include "telestrat.inc" + .macpack generic + +MAXARGS = 10 ; Maximum number of arguments allowed + + + + + +; Assume that the program was loaded, a moment ago, by the traditional LOAD +; statement. Save the "most-recent filename" as argument #0. +initmainargs: + + ldx #0 ; Limit the length +L0: lda BUFEDT,x + beq L3 + cmp #' ' + bne L1 + lda #0 + beq L3 +L1: sta name,x + inx + cpx #FNAME_LEN + bne L0 + lda #0 +L3: + sta name,x + inc __argc ; argc always is equal to, at least, 1 + + + ldy #1 * 2 ; Point to second argv slot + +next: lda BUFEDT,x + beq done ; End of line reached + inx + cmp #' ' ; Skip leading spaces + beq next + +found: cmp #'"' ; Is the argument quoted? + beq setterm ; Jump if so + dex ; Reset pointer to first argument character + + lda #' ' ; A space ends the argument +setterm:sta term ; Set end of argument marker + +; Now, store a pointer, to the argument, into the next slot. + + txa ; Get low byte + clc + adc #<BUFEDT + bcc L4 + inc L5+1 +L4: + sta argv,y ; argv[y]=&arg +L5: + lda #>BUFEDT + sta argv+1,y + iny + iny + inc __argc ; Found another arg + +; Search for the end of the argument + + + +argloop:lda BUFEDT,x + beq done + inx + cmp term + bne argloop + +; We've found the end of the argument. X points one character behind it, and +; A contains the terminating character. To make the argument a valid C string, +; replace the terminating character by a zero. + + lda #0 + sta BUFEDT-1,x + +; Check if the maximum number of command line arguments is reached. If not, +; parse the next one. + + lda __argc ; Get low byte of argument count + cmp #MAXARGS ; Maximum number of arguments reached? + bcc next ; Parse next one if not + + +done: lda #<argv + ldx #>argv + sta __argv + stx __argv + 1 + rts + + +.segment "INIT" + +term: .res 1 + + +.data + +name: .res FNAME_LEN + 1 +args: .res SCREEN_XSIZE * 2 - 1 + +param_found: + .res 1 +; char* argv[MAXARGS+1]={name}; +argv: + .addr name + .res MAXARGS * 2 diff --git a/libsrc/telestrat/open.s b/libsrc/telestrat/open.s new file mode 100644 index 000000000..08910f4f2 --- /dev/null +++ b/libsrc/telestrat/open.s @@ -0,0 +1,33 @@ + .export _open + + .import addysp,popax + + .importzp sp,tmp2,tmp3,tmp1 + + + .include "telestrat.inc" + .include "errno.inc" + .include "fcntl.inc" + +; int open (const char* name, int flags, ...); /* May take a mode argument */ +.proc _open +; Throw away any additional parameters passed through the ellipsis + + dey ; Parm count < 4 shouldn't be needed to be... + dey ; ...checked (it generates a c compiler warning) + dey + dey + beq parmok ; Branch if parameter count ok + jsr addysp ; Fix stack, throw away unused parameters + +; Parameters ok. Pop the flags and save them into tmp3 + +parmok: + jsr popax ; Get flagss + sta tmp3 ; save flags +; Get the filename from stack and parse it. Bail out if is not ok + jsr popax ; Get name + ldy tmp3 ; Get flags again + BRK_TELEMON XOPEN ; launch primitive ROM + rts +.endproc diff --git a/libsrc/telestrat/orixhdr.s b/libsrc/telestrat/orixhdr.s new file mode 100644 index 000000000..6fe2fca73 --- /dev/null +++ b/libsrc/telestrat/orixhdr.s @@ -0,0 +1,35 @@ +; +; By Debrune Jérôme <jede@oric.org> + +; + + ; The following symbol is used by the linker config. file + ; to force this module to be included into the output file. + .export __ORIXHDR__:abs = 1 + + ; These symbols, also, come from the configuration file. + .import __AUTORUN__, __PROGFLAG__ + .import __BASHEAD_START__, __MAIN_LAST__ + + +; ------------------------------------------------------------------------ +; Orix header see http://orix.oric.org/doku.php?id=orix:header for specs + +.segment "ORIXHDR" + + .byte $01, $00 ; non C64 marker (same as o65 format) + + .byte "ori" ; magic number + + .byte $01 ; version of the header + .byte $00,%00000000 ; 6502 only + .byte $00,$00 ; type of language + .byte $00,$00 ; OS version + + .byte $00 ; reserved + .byte $00 ; auto or not + + .word __BASHEAD_START__ ; Address of start of file + .word __MAIN_LAST__ - 1 ; Address of end of file + .word __BASHEAD_START__ ; Address of start of file + diff --git a/libsrc/telestrat/read.s b/libsrc/telestrat/read.s new file mode 100644 index 000000000..75766cda2 --- /dev/null +++ b/libsrc/telestrat/read.s @@ -0,0 +1,41 @@ +; +; jede jede@oric.org 2017-01-22 +; + + .export _read + + .import popax + + .include "zeropage.inc" + .include "telestrat.inc" + +;int read (int fd, void* buf, unsigned count); + +.proc _read + sta ptr1 ; count + stx ptr1+1 ; count + jsr popax ; get buf + + sta PTR_READ_DEST + stx PTR_READ_DEST+1 + sta ptr2 ; in order to calculate nb of bytes read + stx ptr2+1 ; + + ; jsr popax ; fp pointer don't care in this version + + lda ptr1 ; + ldy ptr1+1 ; + BRK_TELEMON XFREAD ; calls telemon30 routine + ; compute nb of bytes read + lda PTR_READ_DEST+1 + sec + sbc ptr2+1 + tax + lda PTR_READ_DEST + sec + sbc ptr2 + ; Here A and X contains number of bytes read + rts +.endproc + + diff --git a/libsrc/telestrat/sound.s b/libsrc/telestrat/sound.s new file mode 100644 index 000000000..3718debd4 --- /dev/null +++ b/libsrc/telestrat/sound.s @@ -0,0 +1,42 @@ +; +; jede jede@oric.org 2017-01-22 + + .export _kbdclick1,_oups,_ping,_explode,_shoot,_zap + .include "telestrat.inc" + +.proc _kbdclick1 + ldx #<sound_bip_keyboard + ldy #>sound_bip_keyboard + BRK_TELEMON XSONPS + rts +sound_bip_keyboard: + .byte $1f,$00,$00,$00,$00,$00,$00,$3e,$10,$00,$00,$1f,$00,$00 +.endproc + +.proc _explode + BRK_TELEMON XEXPLO + rts +.endproc + +.proc _oups + BRK_TELEMON XOUPS + rts +.endproc + +.proc _ping + BRK_TELEMON XPING + rts +.endproc + +.proc _shoot + BRK_TELEMON XSHOOT + rts +.endproc + +.proc _zap + BRK_TELEMON XZAP + rts +.endproc + + + diff --git a/libsrc/telestrat/sysuname.s b/libsrc/telestrat/sysuname.s new file mode 100644 index 000000000..51af1d8fe --- /dev/null +++ b/libsrc/telestrat/sysuname.s @@ -0,0 +1,46 @@ +; +; Ullrich von Bassewitz, 2003-08-12 +; +; unsigned char __fastcall__ _sysuname (struct utsname* buf); +; + + .export __sysuname, utsdata + + .import utscopy + + __sysuname = utscopy + +;-------------------------------------------------------------------------- +; Data. We define a fixed utsname struct here and just copy it. + +.rodata + +utsdata: + ; sysname + .asciiz "cc65" + + ; nodename + .asciiz "" + + ; release + .byte ((.VERSION >> 8) & $0F) + '0' + .byte '.' + .if ((.VERSION >> 4) & $0F) > 9 + .byte ((.VERSION >> 4) & $0F) / 10 + '0' + .byte ((.VERSION >> 4) & $0F) .MOD 10 + '0' + .else + .byte ((.VERSION >> 4) & $0F) + '0' + .endif + .byte $00 + + ; version + .if (.VERSION & $0F) > 9 + .byte (.VERSION & $0F) / 10 + '0' + .byte (.VERSION & $0F) .MOD 10 + '0' + .else + .byte (.VERSION & $0F) + '0' + .endif + .byte $00 + + ; machine + .asciiz "Oric Telestrat" diff --git a/libsrc/telestrat/write.s b/libsrc/telestrat/write.s new file mode 100644 index 000000000..8c2bc08f7 --- /dev/null +++ b/libsrc/telestrat/write.s @@ -0,0 +1,77 @@ +; +; jede jede@oric.org 2017-01-22 + + .export _write + .import popax + .importzp ptr1, ptr2, ptr3, tmp1 + + .include "telestrat.inc" + +; int write (int fd, const void* buf, int count); +.proc _write + + sta ptr3 + stx ptr3+1 ; save count as result + + eor #$FF + sta ptr2 + txa + eor #$FF + sta ptr2+1 ; Remember -count-1 + + jsr popax ; get buf + sta ptr1 + stx ptr1+1 + jsr popax ; get fd and discard + + ; if fd=0001 then it stdout + cpx #0 + beq next + jmp L1 +next: + cmp #1 + beq L1 + + ; Here it's a file opened + lda ptr1 + sta PTR_READ_DEST + lda ptr1+1 + sta PTR_READ_DEST+1 + lda ptr3 + ldy ptr3+1 + BRK_TELEMON XFWRITE + rts + + +L1: inc ptr2 + bne L2 + inc ptr2+1 + beq L9 +L2: ldy #0 + lda (ptr1),y + tax + cpx #$0A ; Check for \n + bne L3 + BRK_TELEMON XWR0 ; Macro send char to screen (channel 0 in telemon terms) + lda #$0D ; return to the beggining of the line + BRK_TELEMON XWR0 ; Macro ; + + + ldx #$0D +L3: + BRK_TELEMON XWR0 ; Macro + + inc ptr1 + bne L1 + inc ptr1+1 + jmp L1 + +; No error, return count + +L9: lda ptr3 + ldx ptr3+1 + rts + +.endproc + + diff --git a/libsrc/zlib/inflatemem.s b/libsrc/zlib/inflatemem.s index ea550c074..27802fbff 100644 --- a/libsrc/zlib/inflatemem.s +++ b/libsrc/zlib/inflatemem.s @@ -1,38 +1,41 @@ ; -; 2003-09-21, Piotr Fusik -; 2016-07-19, Greg King +; 2017-02-12, Piotr Fusik ; ; unsigned __fastcall__ inflatemem (char* dest, const char* source); +; +; NOTE: Be extremely careful with modifications, because this code is heavily +; optimized for size (for example assumes certain register and flag values +; when its internal routines return). Test with the gunzip65 sample. ; .export _inflatemem .import incsp2 - .importzp sp, sreg, ptr1, ptr2, ptr3, ptr4, tmp1 - - .macpack cpu + .importzp sp, sreg, ptr1, ptr2, ptr3, ptr4 ; -------------------------------------------------------------------------- ; ; Constants ; -; Maximum length of a Huffman code. -MAX_BITS = 15 +; Argument values for getBits. +GET_1_BIT = $81 +GET_2_BITS = $82 +GET_3_BITS = $84 +GET_4_BITS = $88 +GET_5_BITS = $90 +GET_6_BITS = $a0 +GET_7_BITS = $c0 -; All Huffman trees are stored in the bitsCount, bitsPointer_l -; and bitsPointer_h arrays. There may be two trees: the literal/length tree -; and the distance tree, or just one - the temporary tree. +; Huffman trees. +TREE_SIZE = 16 +PRIMARY_TREE = 0 +DISTANCE_TREE = TREE_SIZE -; Index in the mentioned arrays for the beginning of the literal/length tree -; or the temporary tree. -PRIMARY_TREE = 0 - -; Index in the mentioned arrays for the beginning of the distance tree. -DISTANCE_TREE = MAX_BITS - -; Size of each array. -TREES_SIZE = 2*MAX_BITS +; Alphabet. +LENGTH_SYMBOLS = 1+29+2 ; EOF, 29 length symbols, two unused symbols +DISTANCE_SYMBOLS = 30 +CONTROL_SYMBOLS = LENGTH_SYMBOLS+DISTANCE_SYMBOLS ; -------------------------------------------------------------------------- @@ -41,30 +44,26 @@ TREES_SIZE = 2*MAX_BITS ; ; Pointer to the compressed data. -inputPointer := ptr1 ; 2 bytes +inputPointer := ptr1 ; 2 bytes ; Pointer to the uncompressed data. -outputPointer := ptr2 ; 2 bytes +outputPointer := ptr2 ; 2 bytes ; Local variables. ; As far as there is no conflict, same memory locations are used ; for different variables. -inflateDynamicBlock_cnt := ptr3 ; 1 byte -inflateCodes_src := ptr3 ; 2 bytes -buildHuffmanTree_src := ptr3 ; 2 bytes -getNextLength_last := ptr3 ; 1 byte -getNextLength_index := ptr3+1 ; 1 byte - -buildHuffmanTree_ptr := ptr4 ; 2 bytes -fetchCode_ptr := ptr4 ; 2 bytes -getBits_tmp := ptr4 ; 1 byte - -moveBlock_len := sreg ; 2 bytes -inflateDynamicBlock_np := sreg ; 1 byte -inflateDynamicBlock_nd := sreg+1 ; 1 byte - -getBit_hold := tmp1 ; 1 byte +inflateStored_pageCounter := ptr3 ; 1 byte +inflateDynamic_symbol := ptr3 ; 1 byte +inflateDynamic_lastLength := ptr3+1 ; 1 byte + .assert ptr4 = ptr3 + 2, error, "Need three bytes for inflateDynamic_tempCodes" +inflateDynamic_tempCodes := ptr3+1 ; 3 bytes +inflateDynamic_allCodes := inflateDynamic_tempCodes+1 ; 1 byte +inflateDynamic_primaryCodes := inflateDynamic_tempCodes+2 ; 1 byte +inflateCodes_sourcePointer := ptr3 ; 2 bytes +inflateCodes_lengthMinus2 := ptr4 ; 1 byte +getBits_base := sreg ; 1 byte +getBit_buffer := sreg+1 ; 1 byte ; -------------------------------------------------------------------------- @@ -78,45 +77,59 @@ _inflatemem: sta inputPointer stx inputPointer+1 ; outputPointer = dest -.if (.cpu & CPU_ISET_65SC02) - lda (sp) ldy #1 -.else - ldy #0 - lda (sp),y - iny -.endif - sta outputPointer lda (sp),y sta outputPointer+1 + dey + lda (sp),y + sta outputPointer -; ldy #1 - sty getBit_hold -inflatemem_1: +; ldy #0 + sty getBit_buffer + +inflate_blockLoop: ; Get a bit of EOF and two bits of block type - ldx #3 - lda #0 +; ldy #0 + sty getBits_base + lda #GET_3_BITS jsr getBits lsr a ; A and Z contain block type, C contains EOF flag ; Save EOF flag php -; Go to the routine decompressing this block - jsr callExtr - plp - bcc inflatemem_1 -; C flag is set! + bne inflateCompressed -; return outputPointer - dest; +; Decompress a 'stored' data block. +; ldy #0 + sty getBit_buffer ; ignore bits until byte boundary + jsr getWord ; skip the length we don't need + jsr getWord ; get the two's complement length + sta inflateStored_pageCounter + bcs inflateStored_firstByte ; jmp +inflateStored_copyByte: + jsr getByte +; sec +inflateStoreByte: + jsr storeByte + bcc inflateCodes_loop +inflateStored_firstByte: + inx + bne inflateStored_copyByte + inc inflateStored_pageCounter + bne inflateStored_copyByte + +; Block decompressed. +inflate_nextBlock: + plp + bcc inflate_blockLoop + +; Decompression complete. +; return outputPointer - dest lda outputPointer -.if (.cpu & CPU_ISET_65SC02) - sbc (sp) ; C flag is set - ldy #1 -.else - ldy #0 - sbc (sp),y ; C flag is set +; ldy #0 +; sec + sbc (sp),y iny -.endif pha lda outputPointer+1 sbc (sp),y @@ -125,442 +138,346 @@ inflatemem_1: ; pop dest jmp incsp2 -; -------------------------------------------------------------------------- -; Go to proper block decoding routine. - -callExtr: - bne inflateCompressedBlock - -; -------------------------------------------------------------------------- -; Decompress a 'stored' data block. - -inflateCopyBlock: -; Ignore bits until byte boundary - ldy #1 - sty getBit_hold -; Get 16-bit length - ldx #0 - lda (inputPointer,x) - sta moveBlock_len - lda (inputPointer),y - sta moveBlock_len+1 -; Skip the length and one's complement of it - lda #4 - clc - adc inputPointer - sta inputPointer - bcc moveBlock - inc inputPointer+1 -; jmp moveBlock - -; -------------------------------------------------------------------------- -; Copy block of length moveBlock_len from (0,x) to the output. - -moveBlock: - ldy moveBlock_len - beq moveBlock_1 -.if (.cpu & CPU_ISET_65SC02) -.else - ldy #0 -.endif - inc moveBlock_len+1 -moveBlock_1: - lda (inputPointer,x) -.if (.cpu & CPU_ISET_65SC02) - sta (outputPointer) -.else - sta (outputPointer),y -.endif - inc inputPointer - bne moveBlock_2 - inc inputPointer+1 -moveBlock_2: - inc outputPointer - bne moveBlock_3 - inc outputPointer+1 -moveBlock_3: -.if (.cpu & CPU_ISET_65SC02) - dey -.else - dec moveBlock_len -.endif - bne moveBlock_1 - dec moveBlock_len+1 - bne moveBlock_1 - rts - -; -------------------------------------------------------------------------- +inflateCompressed: ; Decompress a Huffman-coded data block -; (A = 1: fixed, A = 2: dynamic). +; A=1: fixed block, initialize with fixed codes +; A=2: dynamic block, start by clearing all code lengths +; A=3: invalid compressed data, not handled in this routine + eor #2 -inflateCompressedBlock: - lsr a - bne inflateDynamicBlock -; Note: inflateDynamicBlock may assume that A = 1 - -; -------------------------------------------------------------------------- -; Decompress a Huffman-coded data block with default Huffman trees -; (defined by the DEFLATE format): -; literalCodeLength: 144 times 8, 112 times 9 -; endCodeLength: 7 -; lengthCodeLength: 23 times 7, 6 times 8 -; distanceCodeLength: 30 times 5+DISTANCE_TREE, 2 times 8 -; (two 8-bit codes from the primary tree are not used). - -inflateFixedBlock: - ldx #159 - stx distanceCodeLength+32 - lda #8 -inflateFixedBlock_1: - sta literalCodeLength-1,x - sta literalCodeLength+159-1,x - dex - bne inflateFixedBlock_1 - ldx #112 -; lda #9 -inflateFixedBlock_2: - inc literalCodeLength+144-1,x ; sta - dex - bne inflateFixedBlock_2 - ldx #24 -; lda #7 -inflateFixedBlock_3: - dec endCodeLength-1,x ; sta - dex - bne inflateFixedBlock_3 - ldx #30 - lda #5+DISTANCE_TREE -inflateFixedBlock_4: - sta distanceCodeLength-1,x - dex - bne inflateFixedBlock_4 - beq inflateCodes ; branch always - -; -------------------------------------------------------------------------- -; Decompress a Huffman-coded data block, reading Huffman trees first. - -inflateDynamicBlock: -; numberOfPrimaryCodes = 257 + getBits(5) - ldx #5 -; lda #1 - jsr getBits - sta inflateDynamicBlock_np -; numberOfDistanceCodes = 1 + getBits(5) - ldx #5 - lda #1+29+1 - jsr getBits - sta inflateDynamicBlock_nd -; numberOfTemporaryCodes = 4 + getBits(4) - lda #4 +; ldy #0 +inflateCompressed_setCodeLengths: tax - jsr getBits - sta inflateDynamicBlock_cnt -; Get lengths of temporary codes in the order stored in tempCodeLengthOrder - txa ; lda #0 - tay -inflateDynamicBlock_1: - ldx #3 ; A = 0 - jsr getBits ; does not change Y -inflateDynamicBlock_2: - ldx tempCodeLengthOrder,y - sta literalCodeLength,x - lda #0 + beq inflateCompressed_setLiteralCodeLength +; fixed Huffman literal codes: +; 144 8-bit codes +; 112 9-bit codes + lda #4 + cpy #144 + rol a +inflateCompressed_setLiteralCodeLength: + sta literalSymbolCodeLength,y + beq inflateCompressed_setControlCodeLength +; fixed Huffman control codes: +; 24 7-bit codes +; 6 8-bit codes +; 2 meaningless 8-bit codes +; 30 5-bit distance codes + lda #5+DISTANCE_TREE + cpy #LENGTH_SYMBOLS + bcs inflateCompressed_setControlCodeLength + cpy #24 + adc #$100+2-DISTANCE_TREE +inflateCompressed_setControlCodeLength: + cpy #CONTROL_SYMBOLS + bcs inflateCompressed_noControlSymbol + sta controlSymbolCodeLength,y +inflateCompressed_noControlSymbol: iny - cpy inflateDynamicBlock_cnt - bcc inflateDynamicBlock_1 - cpy #19 - bcc inflateDynamicBlock_2 - ror literalCodeLength+19 ; C flag is set, so this will set b7 + bne inflateCompressed_setCodeLengths + + tax + beq inflateDynamic + +; Decompress a block +inflateCodes: + jsr buildHuffmanTree +inflateCodes_loop: + jsr fetchPrimaryCode + bcc inflateStoreByte + beq inflate_nextBlock +; Copy sequence from look-behind buffer +; ldy #0 + sty getBits_base + cmp #9 + bcc inflateCodes_setSequenceLength + tya +; lda #0 + cpx #1+28 + bcs inflateCodes_setSequenceLength + dex + txa + lsr a + ror getBits_base + inc getBits_base + lsr a + rol getBits_base + jsr getAMinus1BitsMax8 +; sec + adc #0 +inflateCodes_setSequenceLength: + sta inflateCodes_lengthMinus2 + ldx #DISTANCE_TREE + jsr fetchCode + cmp #4 + bcc inflateCodes_setOffsetLowByte + inc getBits_base + lsr a + jsr getAMinus1BitsMax8 +inflateCodes_setOffsetLowByte: + eor #$ff + sta inflateCodes_sourcePointer + lda getBits_base + cpx #10 + bcc inflateCodes_setOffsetHighByte + lda getNPlus1Bits_mask-10,x + jsr getBits + clc +inflateCodes_setOffsetHighByte: + eor #$ff +; clc + adc outputPointer+1 + sta inflateCodes_sourcePointer+1 + jsr copyByte + jsr copyByte +inflateCodes_copyByte: + jsr copyByte + dec inflateCodes_lengthMinus2 + bne inflateCodes_copyByte + beq inflateCodes_loop ; jmp + +inflateDynamic: +; Decompress a block reading Huffman trees first +; ldy #0 +; numberOfPrimaryCodes = 257 + getBits(5) +; numberOfDistanceCodes = 1 + getBits(5) +; numberOfTemporaryCodes = 4 + getBits(4) + ldx #3 +inflateDynamic_getHeader: + lda inflateDynamic_headerBits-1,x + jsr getBits +; sec + adc inflateDynamic_headerBase-1,x + sta inflateDynamic_tempCodes-1,x + dex + bne inflateDynamic_getHeader + +; Get lengths of temporary codes in the order stored in inflateDynamic_tempSymbols +; ldx #0 +inflateDynamic_getTempCodeLengths: + lda #GET_3_BITS + jsr getBits + ldy inflateDynamic_tempSymbols,x + sta literalSymbolCodeLength,y + ldy #0 + inx + cpx inflateDynamic_tempCodes + bcc inflateDynamic_getTempCodeLengths + ; Build the tree for temporary codes jsr buildHuffmanTree ; Use temporary codes to get lengths of literal/length and distance codes - ldx #0 - ldy #1 - stx getNextLength_last -inflateDynamicBlock_3: - jsr getNextLength - sta literalCodeLength,x - inx - bne inflateDynamicBlock_3 -inflateDynamicBlock_4: - jsr getNextLength -inflateDynamicBlock_5: - sta endCodeLength,x - inx - cpx inflateDynamicBlock_np - bcc inflateDynamicBlock_4 - lda #0 - cpx #1+29 - bcc inflateDynamicBlock_5 -inflateDynamicBlock_6: - jsr getNextLength - cmp #0 - beq inflateDynamicBlock_7 - adc #DISTANCE_TREE-1 ; C flag is set -inflateDynamicBlock_7: - sta endCodeLength,x - inx - cpx inflateDynamicBlock_nd - bcc inflateDynamicBlock_6 - ror endCodeLength,x ; C flag is set, so this will set b7 -; jmp inflateCodes - -; -------------------------------------------------------------------------- -; Decompress a data block basing on given Huffman trees. - -inflateCodes: - jsr buildHuffmanTree -inflateCodes_1: - jsr fetchPrimaryCode - bcs inflateCodes_2 -; Literal code -.if (.cpu & CPU_ISET_65SC02) - sta (outputPointer) -.else - ldy #0 - sta (outputPointer),y -.endif - inc outputPointer - bne inflateCodes_1 - inc outputPointer+1 - bcc inflateCodes_1 ; branch always -; End of block -inflateCodes_ret: - rts -inflateCodes_2: - beq inflateCodes_ret -; Restore a block from the look-behind buffer - jsr getValue - sta moveBlock_len - tya - jsr getBits - sta moveBlock_len+1 - ldx #DISTANCE_TREE - jsr fetchCode - jsr getValue - sec - eor #$ff - adc outputPointer - sta inflateCodes_src +; ldx #0 +; sec +inflateDynamic_decodeLength: +; C=1: literal codes +; C=0: control codes + stx inflateDynamic_symbol php - tya - jsr getBits - plp - eor #$ff - adc outputPointer+1 - sta inflateCodes_src+1 - ldx #inflateCodes_src - jsr moveBlock - beq inflateCodes_1 ; branch always - -; -------------------------------------------------------------------------- -; Build Huffman trees basing on code lengths (in bits). -; stored in the *CodeLength arrays. -; A byte with its highest bit set marks the end. - -buildHuffmanTree: - lda #<literalCodeLength - sta buildHuffmanTree_src - lda #>literalCodeLength - sta buildHuffmanTree_src+1 -; Clear bitsCount and bitsPointer_l - ldy #2*TREES_SIZE+1 - lda #0 -buildHuffmanTree_1: - sta bitsCount-1,y - dey - bne buildHuffmanTree_1 - beq buildHuffmanTree_3 ; branch always -; Count number of codes of each length -buildHuffmanTree_2: - tax - inc bitsPointer_l,x - iny - bne buildHuffmanTree_3 - inc buildHuffmanTree_src+1 -buildHuffmanTree_3: - lda (buildHuffmanTree_src),y - bpl buildHuffmanTree_2 -; Calculate a pointer for each length - ldx #0 - lda #<sortedCodes - ldy #>sortedCodes - clc -buildHuffmanTree_4: - sta bitsPointer_l,x - tya - sta bitsPointer_h,x - lda bitsPointer_l+1,x - adc bitsPointer_l,x ; C flag is zero - bcc buildHuffmanTree_5 - iny -buildHuffmanTree_5: - inx - cpx #TREES_SIZE - bcc buildHuffmanTree_4 - lda #>literalCodeLength - sta buildHuffmanTree_src+1 - ldy #0 - bcs buildHuffmanTree_9 ; branch always -; Put codes into their place in sorted table -buildHuffmanTree_6: - beq buildHuffmanTree_7 - tax - lda bitsPointer_l-1,x - sta buildHuffmanTree_ptr - lda bitsPointer_h-1,x - sta buildHuffmanTree_ptr+1 - tya - ldy bitsCount-1,x - inc bitsCount-1,x - sta (buildHuffmanTree_ptr),y - tay -buildHuffmanTree_7: - iny - bne buildHuffmanTree_9 - inc buildHuffmanTree_src+1 - ldx #MAX_BITS-1 -buildHuffmanTree_8: - lda bitsCount,x - sta literalCount,x - dex - bpl buildHuffmanTree_8 -buildHuffmanTree_9: - lda (buildHuffmanTree_src),y - bpl buildHuffmanTree_6 - rts - -; -------------------------------------------------------------------------- -; Decode next code length using temporary codes. - -getNextLength: - stx getNextLength_index - dey - bne getNextLength_1 ; Fetch a temporary code jsr fetchPrimaryCode ; Temporary code 0..15: put this length - ldy #1 - cmp #16 - bcc getNextLength_2 + bpl inflateDynamic_storeLengths ; Temporary code 16: repeat last length 3 + getBits(2) times ; Temporary code 17: put zero length 3 + getBits(3) times ; Temporary code 18: put zero length 11 + getBits(7) times - tay - ldx tempExtraBits-16,y - lda tempBaseValue-16,y + tax jsr getBits - cpy #17 + cpx #GET_3_BITS + bcc inflateDynamic_code16 + beq inflateDynamic_code17 +; sec + adc #7 +inflateDynamic_code17: +; ldy #0 + sty inflateDynamic_lastLength +inflateDynamic_code16: tay - txa ; lda #0 - bcs getNextLength_2 -getNextLength_1: - lda getNextLength_last -getNextLength_2: - sta getNextLength_last - ldx getNextLength_index + lda inflateDynamic_lastLength + iny + iny +inflateDynamic_storeLengths: + iny + plp + ldx inflateDynamic_symbol +inflateDynamic_storeLength: + bcc inflateDynamic_controlSymbolCodeLength + sta literalSymbolCodeLength,x + inx + cpx #1 +inflateDynamic_storeNext: + dey + bne inflateDynamic_storeLength + sta inflateDynamic_lastLength + beq inflateDynamic_decodeLength ; jmp +inflateDynamic_controlSymbolCodeLength: + cpx inflateDynamic_primaryCodes + bcc inflateDynamic_storeControl +; the code lengths we skip here were zero-initialized +; in inflateCompressed_setControlCodeLength + bne inflateDynamic_noStartDistanceTree + ldx #LENGTH_SYMBOLS +inflateDynamic_noStartDistanceTree: + ora #DISTANCE_TREE +inflateDynamic_storeControl: + sta controlSymbolCodeLength,x + inx + cpx inflateDynamic_allCodes + bcc inflateDynamic_storeNext + dey +; ldy #0 + jmp inflateCodes + +; Build Huffman trees basing on code lengths (in bits) +; stored in the *SymbolCodeLength arrays +buildHuffmanTree: +; Clear nBitCode_totalCount, nBitCode_literalCount, nBitCode_controlCount + tya +; lda #0 +buildHuffmanTree_clear: + sta nBitCode_clearFrom,y + iny + bne buildHuffmanTree_clear +; Count number of codes of each length +; ldy #0 +buildHuffmanTree_countCodeLengths: + ldx literalSymbolCodeLength,y + inc nBitCode_literalCount,x + inc nBitCode_totalCount,x + cpy #CONTROL_SYMBOLS + bcs buildHuffmanTree_noControlSymbol + ldx controlSymbolCodeLength,y + inc nBitCode_controlCount,x + inc nBitCode_totalCount,x +buildHuffmanTree_noControlSymbol: + iny + bne buildHuffmanTree_countCodeLengths +; Calculate offsets of symbols sorted by code length +; lda #0 + ldx #$100-3*TREE_SIZE +buildHuffmanTree_calculateOffsets: + sta nBitCode_literalOffset+3*TREE_SIZE-$100,x + clc + adc nBitCode_literalCount+3*TREE_SIZE-$100,x + inx + bne buildHuffmanTree_calculateOffsets +; Put symbols in their place in the sorted array +; ldy #0 +buildHuffmanTree_assignCode: + tya + ldx literalSymbolCodeLength,y + ldy nBitCode_literalOffset,x + inc nBitCode_literalOffset,x + sta codeToLiteralSymbol,y + tay + cpy #CONTROL_SYMBOLS + bcs buildHuffmanTree_noControlSymbol2 + ldx controlSymbolCodeLength,y + ldy nBitCode_controlOffset,x + inc nBitCode_controlOffset,x + sta codeToControlSymbol,y + tay +buildHuffmanTree_noControlSymbol2: + iny + bne buildHuffmanTree_assignCode rts -; -------------------------------------------------------------------------- -; Read a code basing on the primary tree. - +; Read Huffman code using the primary tree fetchPrimaryCode: ldx #PRIMARY_TREE -; jmp fetchCode - -; -------------------------------------------------------------------------- -; Read a code from input basing on the tree specified in X. +; Read a code from input using the tree specified in X. ; Return low byte of this code in A. -; For the literal/length tree, the C flag is set if the code is non-literal. - +; Return C flag reset for literal code, set for length code. fetchCode: - lda #0 -fetchCode_1: +; ldy #0 + tya +fetchCode_nextBit: jsr getBit rol a inx sec - sbc bitsCount-1,x - bcs fetchCode_1 - adc bitsCount-1,x ; C flag is zero - cmp literalCount-1,x - sta fetchCode_ptr - ldy bitsPointer_l-1,x - lda bitsPointer_h-1,x - sta fetchCode_ptr+1 - lda (fetchCode_ptr),y + sbc nBitCode_totalCount,x + bcs fetchCode_nextBit +; clc + adc nBitCode_controlCount,x + bcs fetchCode_control +; clc + adc nBitCode_literalOffset,x + tax + lda codeToLiteralSymbol,x + clc + rts +fetchCode_control: +; sec + adc nBitCode_controlOffset-1,x + tax + lda codeToControlSymbol-1,x + and #$1f ; make distance symbols zero-based + tax + sec rts -; -------------------------------------------------------------------------- -; Decode low byte of a value (length or distance), basing on the code in A. -; The result is the base value for this code plus some bits read from input. - -getValue: - tay - ldx lengthExtraBits-1,y - lda lengthBaseValue_l-1,y - pha - lda lengthBaseValue_h-1,y - tay - pla -; jmp getBits - -; -------------------------------------------------------------------------- -; Read X-bit number from the input and add it to A. -; Increment Y if overflow. -; If X > 8, read only 8 bits. -; On return X holds number of unread bits: X = (X > 8 ? X - 8 : 0); - +; Read A minus 1 bits, but no more than 8 +getAMinus1BitsMax8: + rol getBits_base + tax + cmp #9 + bcs getByte + lda getNPlus1Bits_mask-2,x getBits: - cpx #0 - beq getBits_ret -.if (.cpu & CPU_ISET_65SC02) - stz getBits_tmp - dec getBits_tmp -.else - pha - lda #$ff - sta getBits_tmp - pla -.endif -getBits_1: - jsr getBit - bcc getBits_2 - sbc getBits_tmp ; C flag is set - bcc getBits_2 - iny -getBits_2: - dex - beq getBits_ret - asl getBits_tmp - bmi getBits_1 -getBits_ret: + jsr getBits_loop +getBits_normalizeLoop: + lsr getBits_base + ror a + bcc getBits_normalizeLoop rts -; -------------------------------------------------------------------------- -; Read a single bit from input, return it in the C flag. +; Read 16 bits +getWord: + jsr getByte + tax +; Read 8 bits +getByte: + lda #$80 +getBits_loop: + jsr getBit + ror a + bcc getBits_loop + rts +; Read one bit, return in the C flag getBit: - lsr getBit_hold - bne getBit_ret + lsr getBit_buffer + bne getBit_return pha -.if (.cpu & CPU_ISET_65SC02) - lda (inputPointer) -.else - sty getBit_hold - ldy #0 +; ldy #0 lda (inputPointer),y - ldy getBit_hold -.endif inc inputPointer - bne getBit_1 + bne getBit_samePage inc inputPointer+1 -getBit_1: - ror a ; (C flag was set) - sta getBit_hold +getBit_samePage: + sec + ror a + sta getBit_buffer pla -getBit_ret: +getBit_return: + rts + +; Copy a previously written byte +copyByte: + ldy outputPointer + lda (inflateCodes_sourcePointer),y + ldy #0 +; Write a byte +storeByte: +; ldy #0 + sta (outputPointer),y + inc outputPointer + bne storeByte_return + inc outputPointer+1 + inc inflateCodes_sourcePointer+1 +storeByte_return: rts @@ -570,57 +487,17 @@ getBit_ret: ; .rodata -; -------------------------------------------------------------------------- -; Arrays for the temporary codes. -; Order, in which lengths of the temporary codes are stored. -tempCodeLengthOrder: - .byte 16,17,18,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 +getNPlus1Bits_mask: + .byte GET_1_BIT,GET_2_BITS,GET_3_BITS,GET_4_BITS,GET_5_BITS,GET_6_BITS,GET_7_BITS -; Base values. -tempBaseValue: - .byte 3,3,11 +inflateDynamic_tempSymbols: + .byte GET_2_BITS,GET_3_BITS,GET_7_BITS,0,8,7,9,6,10,5,11,4,12,3,13,2,14,1,15 -; Number of extra bits to read. -tempExtraBits: - .byte 2,3,7 - -; -------------------------------------------------------------------------- -; Arrays for the length and distance codes. - -; Base values. -lengthBaseValue_l: - .byte <3,<4,<5,<6,<7,<8,<9,<10 - .byte <11,<13,<15,<17,<19,<23,<27,<31 - .byte <35,<43,<51,<59,<67,<83,<99,<115 - .byte <131,<163,<195,<227,<258 -distanceBaseValue_l: - .byte <1,<2,<3,<4,<5,<7,<9,<13 - .byte <17,<25,<33,<49,<65,<97,<129,<193 - .byte <257,<385,<513,<769,<1025,<1537,<2049,<3073 - .byte <4097,<6145,<8193,<12289,<16385,<24577 -lengthBaseValue_h: - .byte >3,>4,>5,>6,>7,>8,>9,>10 - .byte >11,>13,>15,>17,>19,>23,>27,>31 - .byte >35,>43,>51,>59,>67,>83,>99,>115 - .byte >131,>163,>195,>227,>258 -distanceBaseValue_h: - .byte >1,>2,>3,>4,>5,>7,>9,>13 - .byte >17,>25,>33,>49,>65,>97,>129,>193 - .byte >257,>385,>513,>769,>1025,>1537,>2049,>3073 - .byte >4097,>6145,>8193,>12289,>16385,>24577 - -; Number of extra bits to read. -lengthExtraBits: - .byte 0,0,0,0,0,0,0,0 - .byte 1,1,1,1,2,2,2,2 - .byte 3,3,3,3,4,4,4,4 - .byte 5,5,5,5,0 -distanceExtraBits: - .byte 0,0,0,0,1,1,2,2 - .byte 3,3,4,4,5,5,6,6 - .byte 7,7,8,8,9,9,10,10 - .byte 11,11,12,12,13,13 +inflateDynamic_headerBits: + .byte GET_4_BITS,GET_5_BITS,GET_5_BITS +inflateDynamic_headerBase: + .byte 3,LENGTH_SYMBOLS,0 ; -------------------------------------------------------------------------- @@ -630,44 +507,28 @@ distanceExtraBits: .bss -; Number of literal codes of each length in the primary tree -; (MAX_BITS bytes, overlap with literalCodeLength). -literalCount: +; Data for building trees. -; -------------------------------------------------------------------------- -; Data for building the primary tree. - -; Lengths of literal codes. -literalCodeLength: +literalSymbolCodeLength: .res 256 -; Length of the end code. -endCodeLength: - .res 1 -; Lengths of length codes. -lengthCodeLength: - .res 29 +controlSymbolCodeLength: + .res CONTROL_SYMBOLS -; -------------------------------------------------------------------------- -; Data for building the distance tree. +; Huffman trees. -; Lengths of distance codes. -distanceCodeLength: - .res 30 -; For two unused codes in the fixed trees and an 'end' mark. - .res 3 +nBitCode_clearFrom: +nBitCode_totalCount: + .res 2*TREE_SIZE +nBitCode_literalCount: + .res TREE_SIZE +nBitCode_controlCount: + .res 2*TREE_SIZE +nBitCode_literalOffset: + .res TREE_SIZE +nBitCode_controlOffset: + .res 2*TREE_SIZE -; -------------------------------------------------------------------------- -; The Huffman trees. - -; Number of codes of each length. -bitsCount: - .res TREES_SIZE -; Pointers to sorted codes of each length. -bitsPointer_l: - .res TREES_SIZE+1 -bitsPointer_h: - .res TREES_SIZE - -; Sorted codes. -sortedCodes: - .res 256+1+29+30+2 +codeToLiteralSymbol: + .res 256 +codeToControlSymbol: + .res CONTROL_SYMBOLS diff --git a/src/ca65/instr.c b/src/ca65/instr.c index 5e7904992..53d3573a6 100644 --- a/src/ca65/instr.c +++ b/src/ca65/instr.c @@ -650,7 +650,7 @@ static const struct { { "BNE", 0x0020000, 0xd0, 0, PutPCRel8 }, { "BPL", 0x0020000, 0x10, 0, PutPCRel8 }, { "BRA", 0x0020000, 0x80, 0, PutPCRel8 }, - { "BRK", 0x0000001, 0x00, 0, PutAll }, + { "BRK", 0x0000005, 0x00, 0, PutAll }, { "BRL", 0x0040000, 0x82, 0, PutPCRel16 }, { "BVC", 0x0020000, 0x50, 0, PutPCRel8 }, { "BVS", 0x0020000, 0x70, 0, PutPCRel8 }, diff --git a/src/ca65/main.c b/src/ca65/main.c index a83cab5b6..3c3daf7f7 100644 --- a/src/ca65/main.c +++ b/src/ca65/main.c @@ -297,7 +297,11 @@ static void SetSys (const char* Sys) case TGT_ATMOS: NewSymbol ("__ATMOS__", 1); - break; + break; + + case TGT_TELESTRAT: + NewSymbol ("__TELESTRAT__", 1); + break; case TGT_NES: NewSymbol ("__NES__", 1); diff --git a/src/cc65/main.c b/src/cc65/main.c index 780c52b57..9ed19b90c 100644 --- a/src/cc65/main.c +++ b/src/cc65/main.c @@ -251,6 +251,10 @@ static void SetSys (const char* Sys) DefineNumericMacro ("__ATMOS__", 1); break; + case TGT_TELESTRAT: + DefineNumericMacro ("__TELESTRAT__", 1); + break; + case TGT_NES: DefineNumericMacro ("__NES__", 1); break; diff --git a/src/common/target.c b/src/common/target.c index 84559b0e7..56ea0a2ff 100644 --- a/src/common/target.c +++ b/src/common/target.c @@ -173,6 +173,7 @@ static const TargetEntry TargetMap[] = { { "sim6502", TGT_SIM6502 }, { "sim65c02", TGT_SIM65C02 }, { "supervision", TGT_SUPERVISION }, + { "telestrat", TGT_TELESTRAT }, { "vic20", TGT_VIC20 }, }; #define MAP_ENTRY_COUNT (sizeof (TargetMap) / sizeof (TargetMap[0])) @@ -203,6 +204,7 @@ static const TargetProperties PropertyTable[TGT_COUNT] = { { "geos-apple", CPU_65C02, BINFMT_BINARY, CTNone }, { "lunix", CPU_6502, BINFMT_O65, CTNone }, { "atmos", CPU_6502, BINFMT_BINARY, CTNone }, + { "telestrat", CPU_6502, BINFMT_BINARY, CTNone }, { "nes", CPU_6502, BINFMT_BINARY, CTNone }, { "supervision", CPU_65SC02, BINFMT_BINARY, CTNone }, { "lynx", CPU_65SC02, BINFMT_BINARY, CTNone }, diff --git a/src/common/target.h b/src/common/target.h index 054c4f2ba..c8e2472d3 100644 --- a/src/common/target.h +++ b/src/common/target.h @@ -75,6 +75,7 @@ typedef enum { TGT_GEOS_APPLE, TGT_LUNIX, TGT_ATMOS, + TGT_TELESTRAT, TGT_NES, TGT_SUPERVISION, TGT_LYNX,