Merge pull request #371 from jedeoric/master

Create an Oric Telestrat target library
This commit is contained in:
Oliver Schmidt
2017-02-10 23:47:13 +01:00
committed by GitHub
21 changed files with 1250 additions and 2 deletions

View File

@@ -31,7 +31,8 @@ TARGETS = apple2 \
pce \
sim6502 \
sim65c02 \
supervision
supervision\
telestrat
DRVTYPES = emd \
joy \

View File

@@ -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

16
libsrc/telestrat/close.s Normal file
View File

@@ -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

91
libsrc/telestrat/crt0.s Normal file
View File

@@ -0,0 +1,91 @@
;
; Startup code for cc65 (Oric version)
;
; By Debrune J<>r<EFBFBD>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

299
libsrc/telestrat/ctype.s Normal file
View File

@@ -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 ___________

120
libsrc/telestrat/mainargs.s Normal file
View File

@@ -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

33
libsrc/telestrat/open.s Normal file
View File

@@ -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

View File

@@ -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

41
libsrc/telestrat/read.s Normal file
View File

@@ -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

42
libsrc/telestrat/sound.s Normal file
View File

@@ -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

View File

@@ -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"

77
libsrc/telestrat/write.s Normal file
View File

@@ -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