├── LICENSE ├── README.md ├── assert.asm ├── assert.macros ├── backup ├── cc.asm ├── cc.macros ├── ctype.asm ├── equates.asm ├── fcntl.asm ├── fcntl.macros ├── int64.asm ├── int64.macros ├── locale.asm ├── locale.macros ├── m16.int64 ├── make ├── obj └── README.txt ├── orca.asm ├── orca.macros ├── setjmp.asm ├── settypes ├── signal.asm ├── signal.macros ├── smac ├── stdio.asm ├── stdio.macros ├── stdlib.asm ├── stdlib.macros ├── string.asm ├── string.macros ├── time.asm ├── time.macros ├── toolglue.asm ├── toolglue.macros ├── uchar.asm ├── uchar.macros ├── vars.asm └── vars.macros /LICENSE: -------------------------------------------------------------------------------- 1 | ORCALib is released by the copyright holder under the terms of the original copyright. 2 | 3 | The Byte Works, Inc. grants you the right to use this source code privately, fork it, and change it. 4 | 5 | You may not redistribute the code in any form other than submission to this repository without the written permission of the copyright holder. 6 | 7 | The copyright holder decided to do things this way for two reasons: 8 | 9 | 1. Reserve commercial distribution rights. 10 | 11 | 2. Ensure that any contributions and updates are available from a centralized source (this GitHib repository, for now). 12 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # ORCALib 2 | Libraries for the ORCA language suite (ORCA/C, ORCA/M, ORCA/Pascal) for the Apple IIGS 3 | 4 | If you would like to make changes to this compiler and distribute them to others, feel free to submit them here. If the changes apply to the Apple IIGS, they will generally be approved for distribution on the master branch. For changes that retarget the library to generate code for a different platform, the project will either be forked or a new repository will be created, as appropriate. 5 | 6 | The general conditions that must be met before a change is released on master are: 7 | 8 | 1. The modified library must compile under the currently released version of ORCA/M. 9 | 10 | 2. The various languages that make use of the library mush still pass their respective test suites, or changes to those test suites must also be submitted. 11 | 12 | Contact support@byteworks.us if you need contributor access. 13 | 14 | A complete distribution of the ORCA languages, including installers and documentation, is available from the Juiced GS store at https://juiced.gs/store/category/software/. It is distributed as part of the Opus ][ package. 15 | -------------------------------------------------------------------------------- /assert.asm: -------------------------------------------------------------------------------- 1 | keep obj/assert 2 | mcopy assert.macros 3 | case on 4 | **************************************************************** 5 | * 6 | * Assert - Condition assertion macro 7 | * 8 | * This code implements the subroutines needed to support the 9 | * standard C library assert. 10 | * 11 | * October 1991 12 | * Mike Westerfield 13 | * 14 | * Copyright 1991 15 | * Byte Works, Inc. 16 | * 17 | **************************************************************** 18 | * 19 | Assert start dummy routine 20 | 21 | end 22 | 23 | **************************************************************** 24 | * 25 | * void __assert (char *f, unsigned l, char *s) 26 | * 27 | * Inputs: 28 | * f - pointer to the file name 29 | * l - line number 30 | * s - assertion string 31 | * 32 | **************************************************************** 33 | * 34 | __assert start 35 | 36 | csubroutine (4:f,2:l,4:s),0 37 | 38 | ph4 stderr 43 | jsl fprintf 44 | jsl abort 45 | 46 | creturn 47 | 48 | msg dc c'Assertion failed: file %s, line %u; assertion: %s',i1'10,0' 49 | end 50 | 51 | **************************************************************** 52 | * 53 | * void __assert2 (char *f, unsigned l, char *fn, char *s) 54 | * 55 | * Inputs: 56 | * f - pointer to the file name 57 | * l - line number 58 | * fn - function name 59 | * s - assertion string 60 | * 61 | **************************************************************** 62 | * 63 | __assert2 start 64 | 65 | csubroutine (4:f,2:l,4:fn,4:s),0 66 | 67 | ph4 stderr 73 | jsl fprintf 74 | jsl abort 75 | 76 | creturn 77 | 78 | msg dc c'Assertion failed: file %s, line %u, function %s; assertion: %s',i1'10,0' 79 | end 80 | -------------------------------------------------------------------------------- /assert.macros: -------------------------------------------------------------------------------- 1 | macro 2 | &l ph2 &n1 3 | &l anop 4 | aif "&n1"="*",.f 5 | lclc &c 6 | &c amid &n1,1,1 7 | aif "&c"="#",.d 8 | aif s:longa=1,.a 9 | rep #%00100000 10 | .a 11 | aif "&c"<>"{",.b 12 | &c amid &n1,l:&n1,1 13 | aif "&c"<>"}",.g 14 | &n1 amid &n1,2,l:&n1-2 15 | lda (&n1) 16 | pha 17 | ago .e 18 | .b 19 | aif "&c"="<",.c 20 | lda &n1 21 | pha 22 | ago .e 23 | .c 24 | &n1 amid &n1,2,l:&n1-1 25 | pei &n1 26 | ago .e 27 | .d 28 | &n1 amid &n1,2,l:&n1-1 29 | pea &n1 30 | ago .f 31 | .e 32 | aif s:longa=1,.f 33 | sep #%00100000 34 | .f 35 | mexit 36 | .g 37 | mnote "Missing closing '}'",16 38 | mend 39 | macro 40 | &l ph4 &n1 41 | &l anop 42 | aif "&n1"="*",.f 43 | lclc &c 44 | &c amid &n1,1,1 45 | aif "&c"="#",.d 46 | aif s:longa=1,.a 47 | rep #%00100000 48 | .a 49 | aif "&c"<>"{",.b 50 | &c amid &n1,l:&n1,1 51 | aif "&c"<>"}",.g 52 | &n1 amid &n1,2,l:&n1-2 53 | ldy #2 54 | lda (&n1),y 55 | pha 56 | lda (&n1) 57 | pha 58 | ago .e 59 | .b 60 | aif "&c"<>"[",.c 61 | ldy #2 62 | lda &n1,y 63 | pha 64 | lda &n1 65 | pha 66 | ago .e 67 | .c 68 | aif "&c"<>"<",.c1 69 | &n1 amid &n1,2,l:&n1-1 70 | pei &n1+2 71 | pei &n1 72 | ago .e 73 | .c1 74 | lda &n1+2 75 | pha 76 | lda &n1 77 | pha 78 | ago .e 79 | .d 80 | &n1 amid &n1,2,l:&n1-1 81 | pea +(&n1)|-16 82 | pea &n1 83 | ago .f 84 | .e 85 | aif s:longa=1,.f 86 | sep #%00100000 87 | .f 88 | mexit 89 | .g 90 | mnote "Missing closing '}'",16 91 | mend 92 | MACRO 93 | &lab csubroutine &parms,&work 94 | &lab anop 95 | aif c:&work,.a 96 | lclc &work 97 | &work setc 0 98 | .a 99 | gbla &totallen 100 | gbla &worklen 101 | &worklen seta &work 102 | &totallen seta 0 103 | aif c:&parms=0,.e 104 | lclc &len 105 | lclc &p 106 | lcla &i 107 | &i seta 1 108 | .b 109 | &p setc &parms(&i) 110 | &len amid &p,2,1 111 | aif "&len"=":",.c 112 | &len amid &p,1,2 113 | &p amid &p,4,l:&p-3 114 | ago .d 115 | .c 116 | &len amid &p,1,1 117 | &p amid &p,3,l:&p-2 118 | .d 119 | &p equ &totallen+4+&work 120 | &totallen seta &totallen+&len 121 | &i seta &i+1 122 | aif &i<=c:&parms,^b 123 | .e 124 | tsc 125 | aif &work=0,.f 126 | sec 127 | sbc #&work 128 | tcs 129 | .f 130 | phd 131 | tcd 132 | mend 133 | MACRO 134 | &lab creturn &r 135 | &lab anop 136 | lclc &len 137 | aif c:&r,.a 138 | lclc &r 139 | &r setc 0 140 | &len setc 0 141 | ago .h 142 | .a 143 | &len amid &r,2,1 144 | aif "&len"=":",.b 145 | &len amid &r,1,2 146 | &r amid &r,4,l:&r-3 147 | ago .c 148 | .b 149 | &len amid &r,1,1 150 | &r amid &r,3,l:&r-2 151 | .c 152 | aif &len<>2,.d 153 | ldy &r 154 | ago .h 155 | .d 156 | aif &len<>4,.e 157 | ldx &r+2 158 | ldy &r 159 | ago .h 160 | .e 161 | aif &len<>10,.g 162 | ldy #&r 163 | ldx #^&r 164 | ago .h 165 | .g 166 | mnote 'Not a valid return length',16 167 | mexit 168 | .h 169 | aif &totallen=0,.i 170 | lda &worklen+2 171 | sta &worklen+&totallen+2 172 | lda &worklen+1 173 | sta &worklen+&totallen+1 174 | .i 175 | pld 176 | tsc 177 | clc 178 | adc #&worklen+&totallen 179 | tcs 180 | aif &len=0,.j 181 | tya 182 | .j 183 | rtl 184 | mend 185 | -------------------------------------------------------------------------------- /backup: -------------------------------------------------------------------------------- 1 | if "{#}" != "1" 2 | echo Form: backup [day] 3 | exit 65535 4 | end 5 | 6 | set dest /library/mike/{1}/ORCALib 7 | 8 | set list make backup smac equates.asm 9 | set list {list} assert.asm assert.macros 10 | set list {list} cc.asm cc.macros 11 | set list {list} ctype.asm 12 | set list {list} fcntl.asm fcntl.macros 13 | set list {list} orca.asm orca.macros 14 | set list {list} setjmp.asm 15 | set list {list} signal.asm signal.macros 16 | set list {list} ctype.asm 17 | set list {list} stdio.asm stdio.macros 18 | set list {list} stdlib.asm stdlib.macros 19 | set list {list} string.asm string.macros 20 | set list {list} time.asm time.macros 21 | set list {list} toolglue.asm toolglue.macros 22 | set list {list} vars.asm vars.macros 23 | 24 | unset exit 25 | create {dest} >.null >&.null 26 | for i in {list} 27 | newer {dest}/{i} {i} 28 | if {Status} != 0 29 | copy -c {i} {dest}/{i} 30 | end 31 | end 32 | -------------------------------------------------------------------------------- /cc.macros: -------------------------------------------------------------------------------- 1 | macro 2 | &l ph2 &n1 3 | &l anop 4 | aif "&n1"="*",.f 5 | lclc &c 6 | &c amid &n1,1,1 7 | aif "&c"="#",.d 8 | aif s:longa=1,.a 9 | rep #%00100000 10 | .a 11 | aif "&c"<>"{",.b 12 | &c amid &n1,l:&n1,1 13 | aif "&c"<>"}",.g 14 | &n1 amid &n1,2,l:&n1-2 15 | lda (&n1) 16 | pha 17 | ago .e 18 | .b 19 | aif "&c"="<",.c 20 | lda &n1 21 | pha 22 | ago .e 23 | .c 24 | &n1 amid &n1,2,l:&n1-1 25 | pei &n1 26 | ago .e 27 | .d 28 | &n1 amid &n1,2,l:&n1-1 29 | pea &n1 30 | ago .f 31 | .e 32 | aif s:longa=1,.f 33 | sep #%00100000 34 | .f 35 | mexit 36 | .g 37 | mnote "Missing closing '}'",16 38 | mend 39 | macro 40 | &l ph4 &n1 41 | &l anop 42 | aif "&n1"="*",.f 43 | lclc &c 44 | &c amid &n1,1,1 45 | aif "&c"="#",.d 46 | aif s:longa=1,.a 47 | rep #%00100000 48 | .a 49 | aif "&c"<>"{",.b 50 | &c amid &n1,l:&n1,1 51 | aif "&c"<>"}",.g 52 | &n1 amid &n1,2,l:&n1-2 53 | ldy #2 54 | lda (&n1),y 55 | pha 56 | lda (&n1) 57 | pha 58 | ago .e 59 | .b 60 | aif "&c"<>"[",.c 61 | ldy #2 62 | lda &n1,y 63 | pha 64 | lda &n1 65 | pha 66 | ago .e 67 | .c 68 | aif "&c"<>"<",.c1 69 | &n1 amid &n1,2,l:&n1-1 70 | pei &n1+2 71 | pei &n1 72 | ago .e 73 | .c1 74 | lda &n1+2 75 | pha 76 | lda &n1 77 | pha 78 | ago .e 79 | .d 80 | &n1 amid &n1,2,l:&n1-1 81 | pea +(&n1)|-16 82 | pea &n1 83 | ago .f 84 | .e 85 | aif s:longa=1,.f 86 | sep #%00100000 87 | .f 88 | mexit 89 | .g 90 | mnote "Missing closing '}'",16 91 | mend 92 | MACRO 93 | &lab error &e 94 | &lab ph2 &e 95 | jsl SystemError 96 | mend 97 | MACRO 98 | &LAB MOVE4 &F,&T 99 | &LAB ~SETM 100 | LDA 2+&F 101 | STA 2+&T 102 | LDA &F 103 | STA &T 104 | ~RESTM 105 | MEND 106 | MACRO 107 | &LAB PUTS &N1,&F1,&CR,&ERROUT 108 | &LAB ~SETM 109 | LCLC &C 110 | &C AMID "&N1",1,1 111 | AIF "&C"<>"#",.C 112 | AIF L:&N1>127,.A 113 | BRA ~&SYSCNT 114 | AGO .B 115 | .A 116 | BRL ~&SYSCNT 117 | .B 118 | &N1 AMID "&N1",2,L:&N1-1 119 | ~L&SYSCNT DC I1"L:~S&SYSCNT" 120 | ~S&SYSCNT DC C&N1 121 | ~&SYSCNT ANOP 122 | &N1 SETC ~L&SYSCNT-1 123 | .C 124 | ~PUSHA &N1 125 | AIF C:&F1,.C1 126 | PEA 0 127 | AGO .C2 128 | .C1 129 | PH2 &F1 130 | .C2 131 | PH2 #C:&CR 132 | PH2 #C:&ERROUT 133 | JSL ~PUTS 134 | ~RESTM 135 | MEND 136 | MACRO 137 | &LAB ~PUSHA &N1 138 | LCLC &C 139 | &LAB ANOP 140 | &C AMID &N1,1,1 141 | AIF "&C"<>"{",.B 142 | &C AMID &N1,L:&N1,1 143 | AIF "&C"<>"}",.G 144 | &N1 AMID &N1,2,L:&N1-2 145 | SEP #$20 146 | LONGA OFF 147 | LDA #0 148 | PHA 149 | REP #$20 150 | LONGA ON 151 | PHK 152 | LDA &N1 153 | PHA 154 | MEXIT 155 | .B 156 | AIF "&C"<>"[",.C 157 | &N1 AMID &N1,2,L:&N1-2 158 | LDA &N1+2 159 | PHA 160 | LDA &N1 161 | PHA 162 | MEXIT 163 | .C 164 | PEA +(&N1)|-16 165 | PEA &N1 166 | MEXIT 167 | .G 168 | MNOTE "Missing closing '}'",16 169 | MEND 170 | MACRO 171 | &LAB ~SETM 172 | &LAB ANOP 173 | AIF C:&~LA,.B 174 | GBLB &~LA 175 | GBLB &~LI 176 | .B 177 | &~LA SETB S:LONGA 178 | &~LI SETB S:LONGI 179 | AIF S:LONGA.AND.S:LONGI,.A 180 | REP #32*(.NOT.&~LA)+16*(.NOT.&~LI) 181 | LONGA ON 182 | LONGI ON 183 | .A 184 | MEND 185 | MACRO 186 | &LAB ~RESTM 187 | &LAB ANOP 188 | AIF (&~LA+&~LI)=2,.I 189 | SEP #32*(.NOT.&~LA)+16*(.NOT.&~LI) 190 | AIF &~LA,.H 191 | LONGA OFF 192 | .H 193 | AIF &~LI,.I 194 | LONGI OFF 195 | .I 196 | MEND 197 | MACRO 198 | &LAB ADD4 &M1,&M2,&M3 199 | LCLB &YISTWO 200 | LCLC &C 201 | &LAB ~SETM 202 | AIF C:&M3,.A 203 | &C AMID "&M2",1,1 204 | AIF "&C"<>"#",.A 205 | &C AMID "&M1",1,1 206 | AIF "&C"="{",.A 207 | AIF "&C"="[",.A 208 | &C AMID "&M2",2,L:&M2-1 209 | AIF &C>=65536,.A 210 | CLC 211 | ~LDA &M1 212 | ~OP ADC,&M2 213 | ~STA &M1 214 | BCC ~&SYSCNT 215 | ~OP.H INC,&M1 216 | ~&SYSCNT ANOP 217 | AGO .C 218 | .A 219 | AIF C:&M3,.B 220 | LCLC &M3 221 | &M3 SETC &M1 222 | .B 223 | CLC 224 | ~LDA &M1 225 | ~OP ADC,&M2 226 | ~STA &M3 227 | ~LDA.H &M1 228 | ~OP.H ADC,&M2 229 | ~STA.H &M3 230 | .C 231 | ~RESTM 232 | MEND 233 | MACRO 234 | &LAB ~OP.H &OPC,&OP 235 | &LAB ANOP 236 | LCLC &C 237 | &C AMID "&OP",1,1 238 | AIF "&C"="[",.B 239 | AIF "&C"<>"{",.D 240 | &C AMID "&OP",L:&OP,1 241 | AIF "&C"="}",.A 242 | MNOTE "Missing closing '}'",2 243 | &OP SETC &OP} 244 | .A 245 | &OP AMID "&OP",2,L:&OP-2 246 | &OP SETC (&OP) 247 | .B 248 | AIF &YISTWO,.C 249 | &YISTWO SETB 1 250 | LDY #2 251 | &OP SETC "&OP,Y" 252 | .C 253 | &OPC &OP 254 | MEXIT 255 | .D 256 | AIF "&C"<>"#",.E 257 | &OP AMID "&OP",2,L:&OP-1 258 | &OP SETC "#^&OP" 259 | &OPC &OP 260 | MEXIT 261 | .E 262 | &OPC 2+&OP 263 | MEND 264 | MACRO 265 | &LAB ~LDA.H &OP 266 | &LAB ANOP 267 | LCLC &C 268 | &C AMID "&OP",1,1 269 | AIF "&C"="[",.B 270 | AIF "&C"<>"{",.D 271 | &C AMID "&OP",L:&OP,1 272 | AIF "&C"="}",.A 273 | MNOTE "Missing closing '}'",2 274 | &OP SETC &OP} 275 | .A 276 | &OP AMID "&OP",2,L:&OP-2 277 | &OP SETC (&OP) 278 | .B 279 | AIF &YISTWO,.C 280 | &YISTWO SETB 1 281 | LDY #2 282 | &OP SETC "&OP,Y" 283 | .C 284 | LDA &OP 285 | MEXIT 286 | .D 287 | AIF "&C"<>"#",.E 288 | &OP AMID "&OP",2,L:&OP-1 289 | &OP SETC "#^&OP" 290 | LDA &OP 291 | MEXIT 292 | .E 293 | LDA 2+&OP 294 | MEND 295 | MACRO 296 | &LAB ~STA.H &OP 297 | &LAB ANOP 298 | LCLC &C 299 | &C AMID "&OP",1,1 300 | AIF "&C"="[",.B 301 | AIF "&C"<>"{",.D 302 | &C AMID "&OP",L:&OP,1 303 | AIF "&C"="}",.A 304 | MNOTE "Missing closing '}'",2 305 | &OP SETC &OP} 306 | .A 307 | &OP AMID "&OP",2,L:&OP-2 308 | &OP SETC (&OP) 309 | .B 310 | AIF &YISTWO,.C 311 | &YISTWO SETB 1 312 | LDY #2 313 | &OP SETC "&OP,Y" 314 | .C 315 | STA &OP 316 | MEXIT 317 | .D 318 | STA 2+&OP 319 | MEND 320 | MACRO 321 | &LAB ~LDA &OP 322 | LCLC &C 323 | &C AMID "&OP",1,1 324 | AIF "&C"<>"{",.B 325 | &C AMID "&OP",L:&OP,1 326 | AIF "&C"="}",.A 327 | MNOTE "Missing closing '}'",2 328 | &OP SETC &OP} 329 | .A 330 | &OP AMID "&OP",2,L:&OP-2 331 | &OP SETC (&OP) 332 | .B 333 | &LAB LDA &OP 334 | MEND 335 | MACRO 336 | &LAB ~STA &OP 337 | LCLC &C 338 | &C AMID "&OP",1,1 339 | AIF "&C"<>"{",.B 340 | &C AMID "&OP",L:&OP,1 341 | AIF "&C"="}",.A 342 | MNOTE "Missing closing '}'",2 343 | &OP SETC &OP} 344 | .A 345 | &OP AMID "&OP",2,L:&OP-2 346 | &OP SETC (&OP) 347 | .B 348 | &LAB STA &OP 349 | MEND 350 | MACRO 351 | &LAB ~OP &OPC,&OP 352 | LCLC &C 353 | &C AMID "&OP",1,1 354 | AIF "&C"<>"{",.B 355 | &C AMID "&OP",L:&OP,1 356 | AIF "&C"="}",.A 357 | MNOTE "Missing closing '}'",2 358 | &OP SETC &OP} 359 | .A 360 | &OP AMID "&OP",2,L:&OP-2 361 | &OP SETC (&OP) 362 | .B 363 | &LAB &OPC &OP 364 | MEND 365 | MACRO 366 | &LAB INC4 &A 367 | &LAB ~SETM 368 | INC &A 369 | BNE ~&SYSCNT 370 | INC 2+&A 371 | ~&SYSCNT ~RESTM 372 | MEND 373 | MACRO 374 | &LAB LONG &A,&B 375 | LCLB &I 376 | LCLB &M 377 | &A AMID &A,1,1 378 | &M SETB ("&A"="M").OR.("&A"="m") 379 | &I SETB ("&A"="I").OR.("&A"="i") 380 | AIF C:&B=0,.A 381 | &B AMID &B,1,1 382 | &M SETB ("&B"="M").OR.("&B"="m").OR.&M 383 | &I SETB ("&B"="I").OR.("&B"="i").OR.&I 384 | .A 385 | &LAB REP #&M*32+&I*16 386 | AIF .NOT.&M,.B 387 | LONGA ON 388 | .B 389 | AIF .NOT.&I,.C 390 | LONGI ON 391 | .C 392 | MEND 393 | MACRO 394 | &LAB PL4 &N1 395 | LCLC &C 396 | &LAB ANOP 397 | AIF S:LONGA=1,.A 398 | REP #%00100000 399 | .A 400 | &C AMID &N1,1,1 401 | AIF "&C"<>"{",.B 402 | &C AMID &N1,L:&N1,1 403 | AIF "&C"<>"}",.F 404 | &N1 AMID &N1,2,L:&N1-2 405 | PLA 406 | STA (&N1) 407 | LDY #2 408 | PLA 409 | STA (&N1),Y 410 | AGO .D 411 | .B 412 | AIF "&C"<>"[",.C 413 | PLA 414 | STA &N1 415 | LDY #2 416 | PLA 417 | STA &N1,Y 418 | AGO .D 419 | .C 420 | PLA 421 | STA &N1 422 | PLA 423 | STA &N1+2 424 | .D 425 | AIF S:LONGA=1,.E 426 | SEP #%00100000 427 | .E 428 | MEXIT 429 | .F 430 | MNOTE "Missing closing '}'",16 431 | MEND 432 | MACRO 433 | &LAB SHORT &A,&B 434 | LCLB &I 435 | LCLB &M 436 | &A AMID &A,1,1 437 | &M SETB ("&A"="M").OR.("&A"="m") 438 | &I SETB ("&A"="I").OR.("&A"="i") 439 | AIF C:&B=0,.A 440 | &B AMID &B,1,1 441 | &M SETB ("&B"="M").OR.("&B"="m").OR.&M 442 | &I SETB ("&B"="I").OR.("&B"="i").OR.&I 443 | .A 444 | &LAB SEP #&M*32+&I*16 445 | AIF .NOT.&M,.B 446 | LONGA OFF 447 | .B 448 | AIF .NOT.&I,.C 449 | LONGI OFF 450 | .C 451 | MEND 452 | MACRO 453 | &LAB _NEWHANDLE 454 | &LAB LDX #$0902 455 | JSL $E10000 456 | MEND 457 | MACRO 458 | &lab csubroutine &parms,&work 459 | &lab anop 460 | aif c:&work,.a 461 | lclc &work 462 | &work setc 0 463 | .a 464 | gbla &totallen 465 | gbla &worklen 466 | &worklen seta &work 467 | &totallen seta 0 468 | aif c:&parms=0,.e 469 | lclc &len 470 | lclc &p 471 | lcla &i 472 | &i seta 1 473 | .b 474 | &p setc &parms(&i) 475 | &len amid &p,2,1 476 | aif "&len"=":",.c 477 | &len amid &p,1,2 478 | &p amid &p,4,l:&p-3 479 | ago .d 480 | .c 481 | &len amid &p,1,1 482 | &p amid &p,3,l:&p-2 483 | .d 484 | &p equ &totallen+4+&work 485 | &totallen seta &totallen+&len 486 | &i seta &i+1 487 | aif &i<=c:&parms,^b 488 | .e 489 | tsc 490 | aif &work=0,.f 491 | sec 492 | sbc #&work 493 | tcs 494 | .f 495 | phd 496 | tcd 497 | mend 498 | MACRO 499 | &lab creturn &r 500 | &lab anop 501 | lclc &len 502 | aif c:&r,.a 503 | lclc &r 504 | &r setc 0 505 | &len setc 0 506 | ago .h 507 | .a 508 | &len amid &r,2,1 509 | aif "&len"=":",.b 510 | &len amid &r,1,2 511 | &r amid &r,4,l:&r-3 512 | ago .c 513 | .b 514 | &len amid &r,1,1 515 | &r amid &r,3,l:&r-2 516 | .c 517 | aif &len<>2,.d 518 | ldy &r 519 | ago .h 520 | .d 521 | aif &len<>4,.e 522 | ldx &r+2 523 | ldy &r 524 | ago .h 525 | .e 526 | aif &len<>10,.g 527 | ldy #&r 528 | ldx #^&r 529 | ago .h 530 | .g 531 | mnote 'Not a valid return length',16 532 | mexit 533 | .h 534 | aif &totallen=0,.i 535 | lda &worklen+2 536 | sta &worklen+&totallen+2 537 | lda &worklen+1 538 | sta &worklen+&totallen+1 539 | .i 540 | pld 541 | tsc 542 | clc 543 | adc #&worklen+&totallen 544 | tcs 545 | aif &len=0,.j 546 | tya 547 | .j 548 | rtl 549 | mend 550 | macro 551 | &l dec4 &a 552 | &l ~setm 553 | lda &a 554 | bne ~&SYSCNT 555 | dec 2+&a 556 | ~&SYSCNT dec &a 557 | ~restm 558 | mend 559 | -------------------------------------------------------------------------------- /equates.asm: -------------------------------------------------------------------------------- 1 | **************************************************************** 2 | * 3 | * This file contains constant values defined in the C interfaces 4 | * that are also used in the assembly language portion of the 5 | * libraries. 6 | * 7 | **************************************************************** 8 | ; 9 | ; error numbers 10 | ; 11 | EDOM gequ 1 domain error 12 | ERANGE gequ 2 # too large, too small, or illegal 13 | ENOMEM gequ 3 Not enough memory 14 | ENOENT gequ 4 No such file or directory 15 | EIO gequ 5 I/O error 16 | EINVAL gequ 6 Invalid argument 17 | EBADF gequ 7 bad file descriptor 18 | EMFILE gequ 8 too many files are open 19 | EACCES gequ 9 access bits prevent the operation 20 | EEXIST gequ 10 the file exists 21 | ENOSPC gequ 11 the file is too large 22 | EILSEQ gequ 12 encoding error 23 | ; 24 | ; masks for the __ctype array 25 | ; 26 | _digit gequ $01 ['0'..'9'] 27 | _upper gequ $02 ['A'..'Z'] 28 | _lower gequ $04 ['a'..'z'] 29 | _control gequ $08 [chr(0)..chr(31),chr(127)] 30 | _punctuation gequ $10 [' ','!'..'/',':'..'@','['..'`','{'..'~'] 31 | _space gequ $20 [chr(9)..chr(13),' '] 32 | _hex gequ $40 ['0'..'9','a'..'f','A'..'F'] 33 | _print gequ $80 [' '..'~'] 34 | ; 35 | ; masks for the __ctype2 array 36 | ; 37 | _csym gequ $01 ['0'..'9','A'..'Z','a'..'z','_'] 38 | _csymf gequ $02 ['A'..'Z','a'..'z'.'_'] 39 | _octal gequ $04 ['0'..'7'] 40 | _blank gequ $08 ['\t', ' '] 41 | ; 42 | ; signal numbers 43 | ; 44 | SIGABRT gequ 1 45 | SIGFPE gequ 2 46 | SIGILL gequ 3 47 | SIGINT gequ 4 48 | SIGSEGV gequ 5 49 | SIGTERM gequ 6 50 | ; 51 | ; The FILE record 52 | ; 53 | ! flags 54 | ! ----- 55 | _IOFBF gequ $0001 full buffering 56 | _IONBF gequ $0002 no buffering 57 | _IOLBF gequ $0004 flush when a \n is written 58 | _IOREAD gequ $0008 currently reading 59 | _IOWRT gequ $0010 currently writing 60 | _IORW gequ $0020 read/write enabled 61 | _IOMYBUF gequ $0040 buffer was allocated by stdio 62 | _IOEOF gequ $0080 has an EOF been found? 63 | _IOERR gequ $0100 has an error occurred? 64 | _IOTEXT gequ $0200 is this file a text file? 65 | _IOTEMPFILE gequ $0400 was this file created by tmpfile()? 66 | _IOAPPEND gequ $0800 is this file open in append mode? 67 | 68 | ! record structure 69 | ! ---------------- 70 | FILE_next gequ 0 disp to next pointer (must stay 0!) 71 | FILE_ptr gequ FILE_next+4 next location to write to 72 | FILE_base gequ FILE_ptr+4 first byte of the buffer 73 | FILE_end gequ FILE_base+4 end of the file buffer 74 | FILE_size gequ FILE_end+4 size of the file buffer 75 | FILE_cnt gequ FILE_size+4 # chars that can be read/written to buffer 76 | FILE_pbk gequ FILE_cnt+4 put back character 77 | FILE_flag gequ FILE_pbk+4 buffer flags 78 | FILE_file gequ FILE_flag+2 GS/OS file ID 79 | 80 | sizeofFILE gequ FILE_file+2 size of the record 81 | 82 | BUFSIZ gequ 1024 default file buffer size 83 | _LBUFSIZ gequ 255 line buffer size 84 | 85 | L_tmpnam gequ 9 size of a temp name 86 | TMP_MAX gequ 10000 # of uniq temp names 87 | ; 88 | ; Seek codes for fseek 89 | ; 90 | SEEK_SET gequ 0 seek from start of file 91 | SEEK_CUR gequ 1 seek from current position 92 | SEEK_END gequ 2 seek from end of file 93 | ; 94 | ; Values for fcntl.h 95 | ; 96 | OPEN_MAX gequ 30 files in the file array 97 | 98 | F_DUPFD gequ 1 dup file flag (fcntl) 99 | 100 | O_RDONLY gequ $0001 file is read only 101 | O_WRONLY gequ $0002 file is write only 102 | O_RDWR gequ $0004 file is read/write 103 | O_NDELAY gequ $0008 not used 104 | O_APPEND gequ $0010 append to file on all writes 105 | O_CREAT gequ $0020 create a new file if needed 106 | O_TRUNC gequ $0040 erase old file 107 | O_EXCL gequ $0080 don't create a new file 108 | O_BINARY gequ $0100 file is binary 109 | ; 110 | ; Misc. 111 | ; 112 | EOF gequ -1 end of file character 113 | 114 | stdinID gequ -1 standard in file ID 115 | stdoutID gequ -2 standard out file ID 116 | stderrID gequ -3 error out file ID 117 | -------------------------------------------------------------------------------- /fcntl.asm: -------------------------------------------------------------------------------- 1 | keep obj/fcntl 2 | mcopy fcntl.macros 3 | case on 4 | 5 | **************************************************************** 6 | * 7 | * fcntl - UNIX primitive input/output facilities 8 | * 9 | * This code implements the tables and subroutines needed to 10 | * support a subset of the UNIX library FCNTL. 11 | * 12 | * October 1989 13 | * Mike Westerfield 14 | * 15 | * Copyright 1989 16 | * Byte Works, Inc. 17 | * 18 | **************************************************************** 19 | * 20 | FCNTL start dummy segment 21 | copy equates.asm 22 | strSize gequ 255 max size of a GS/OS path name 23 | 24 | end 25 | 26 | **************************************************************** 27 | * 28 | * ctoosstr - convert a C string to a GS/OS input string 29 | * 30 | * Inputs: 31 | * cstr - pointer to the c string 32 | * 33 | * Outputs: 34 | * returns a pointer to the OS string 35 | * 36 | * Notes: 37 | * If the C string is longer than strSize bytes, the 38 | * string is truncated without warning. 39 | * 40 | **************************************************************** 41 | * 42 | ctoosstr private 43 | osptr equ 1 os string pointer 44 | 45 | csubroutine (4:cstr),4 46 | 47 | phb use a local B reg 48 | phk 49 | plb 50 | short M copy over the characters 51 | ldy #0 52 | lb1 lda [cstr],Y 53 | beq lb2 54 | sta osstr+2,Y 55 | iny 56 | cpy #strSize 57 | bne lb1 58 | lb2 sty osstr set the string length 59 | long M 60 | lla osptr,osstr set the address of the string 61 | plb restore caller's B 62 | 63 | creturn 4:osptr return osptr 64 | 65 | osstr ds 2+strSize GS/OS string buffer 66 | end 67 | 68 | **************************************************************** 69 | * 70 | * int chmod(char *path, int mode); 71 | * 72 | * Changes the access bits. 73 | * 74 | * Inputs: 75 | * path - name of the file 76 | * mode - zero or more flags to set: 77 | * 0x0100 - read 78 | * 0x0080 - write 79 | * 0x1000 - delete 80 | * 0x2000 - rename 81 | * 0x4000 - backup 82 | * 0x8000 - invisible 83 | * 84 | * Outputs: 85 | * returns 0 if successful; else -1 86 | * errno - set if an error occurred 87 | * 88 | **************************************************************** 89 | * 90 | chmod start 91 | err equ 1 error return code 92 | 93 | csubroutine (4:path,2:mode),2 94 | 95 | phb use local B 96 | phk 97 | plb 98 | stz err err = 0 {no error} 99 | lda mode convert mode to ProDOS format 100 | jsr unixtoprodos 101 | sta siAccess 102 | ph4 errno 116 | dec err 117 | lb2 plb 118 | 119 | creturn 2:err 120 | 121 | cbRec dc i'1' ClearBackup record 122 | cbPathname ds 4 123 | 124 | siRec dc i'2' SetFileInfo record 125 | siPathname ds 4 126 | siAccess ds 2 127 | end 128 | 129 | **************************************************************** 130 | * 131 | * int close(int filds); 132 | * 133 | * Close a file. 134 | * 135 | * Inputs: 136 | * filds - file ID of the file to close 137 | * 138 | * Outputs: 139 | * returns 0 if successful; else -1 140 | * errno - set if an error occurred 141 | * 142 | **************************************************************** 143 | * 144 | close start 145 | err equ 1 error return code 146 | 147 | csubroutine (2:filds),2 148 | 149 | stz err err = 0 {no error} 150 | lda filds error if there are too many open files 151 | cmp #OPEN_MAX 152 | bge lb2 153 | asl A get the file reference number 154 | asl A 155 | tax 156 | lda >files,X 157 | beq lb2 158 | sta >clRefnum 159 | lda #0 free the file record 160 | sta >files,X 161 | ldx #OPEN_MAX*4-4 for each file record do 162 | lda >clRefnum if the file is a duplicate then 163 | lb1 cmp >files,X 164 | beq lb3 skip the close 165 | dex 166 | dex 167 | dex 168 | dex 169 | bpl lb1 170 | OSClose clRec close the file 171 | bcc lb3 172 | 173 | lb2 lda #EBADF an error occurred - set errno 174 | sta >errno 175 | dec err err = -1 176 | 177 | lb3 creturn 2:err 178 | 179 | clRec dc i'1' close record 180 | clRefnum ds 2 181 | end 182 | 183 | **************************************************************** 184 | * 185 | * int creat(char *path, int mode); 186 | * 187 | * Create a file. 188 | * 189 | * Inputs: 190 | * path - name of the file 191 | * mode - zero or more flags to set: 192 | * 0x0100 - read 193 | * 0x0080 - write 194 | * 0x1000 - delete 195 | * 0x2000 - rename 196 | * 0x4000 - backup 197 | * 0x8000 - invisible 198 | * 199 | * Outputs: 200 | * returns 0 if successful; else -1 201 | * errno - set if an error occurred 202 | * 203 | **************************************************************** 204 | * 205 | creat start 206 | err equ 1 error return code 207 | 208 | csubroutine (4:path,2:mode),2 209 | 210 | ph2 #O_WRONLY+O_TRUNC+O_CREAT 211 | ph2 errno 279 | bra lb7 280 | 281 | lb1 lda filds error if there are too many open files 282 | cmp #OPEN_MAX 283 | bge lb2 284 | asl A get the file reference number 285 | asl A 286 | tax 287 | lda >files,X 288 | bne lb3 289 | lb2 dec err flag an invalid filds error 290 | lda #EBADF 291 | sta >errno 292 | bra lb7 293 | lb3 sta refnum 294 | lda >files+2,X get the file flags 295 | sta flags 296 | 297 | lda arg find a new filds 298 | cmp #OPEN_MAX 299 | bge lb5 300 | asl A 301 | asl A 302 | lb4 lda >files,X 303 | beq lb6 304 | inx 305 | inx 306 | inx 307 | inx 308 | cpx #OPEN_MAX*4 309 | bne lb4 310 | lb5 dec err none are available -- flag the error 311 | lda #EMFILE 312 | sta >errno 313 | bra lb7 314 | lb6 lda refnum set the new refnum 315 | sta >files,X 316 | lda flags set the new flags 317 | sta >files+2,X 318 | txa return the filds 319 | lsr A 320 | lsr A 321 | sta err 322 | 323 | lb7 creturn 2:err 324 | end 325 | 326 | **************************************************************** 327 | * 328 | * files - array of file records 329 | * 330 | * There are OPEN_MAX elements, each with the following format: 331 | * 332 | * bytes use 333 | * ----- --- 334 | * 2 file reference number; 0 if element is free 335 | * 2 flags; set by open command 336 | * 337 | * Notes: Array calculations throughout the module depend on 338 | * a record size within the array of exactly 4 bytes. 339 | * 340 | **************************************************************** 341 | * 342 | files private 343 | 344 | ds 4*OPEN_MAX 345 | end 346 | 347 | **************************************************************** 348 | * 349 | * long lseek(int filds, long offset, int whence); 350 | * 351 | * Set the file mark 352 | * 353 | * Inputs: 354 | * filds - file ID of file 355 | * offset - new file mark 356 | * whence - set the mark in relation to: 357 | * 0 - file start 358 | * 1 - current mark 359 | * 2 - file end 360 | * 361 | * Outputs: 362 | * returns file pointer if successful; -1 for an error 363 | * errno - set if an error occurred 364 | * 365 | **************************************************************** 366 | * 367 | lseek start 368 | mark equ 1 new file mark 369 | 370 | csubroutine (2:filds,4:offset,2:whence),4 371 | 372 | lda #$FFFF assume we will get an error 373 | sta mark 374 | sta mark+2 375 | lda filds get the file refnum 376 | cmp #OPEN_MAX 377 | bge lb1 378 | asl A 379 | asl A 380 | tax 381 | lda >files,X 382 | bne lb2 383 | lb1 bra lb4a bad refnum error 384 | 385 | lb2 sta >smRefnum set the file refnum 386 | sta >gmRefnum 387 | lda whence convert from UNIX whence to GS/OS base 388 | cmp #SEEK_SET if whence == 0 (SEEK_SET) 389 | bne lb2a 390 | lda offset+2 if offset is negative 391 | bmi lb4 fail with EINVAL 392 | lda #0 set mark to offset 393 | bra lb3 394 | lb2a cmp #SEEK_END else if whence == 2 (SEEK_END) 395 | bne lb2c 396 | lda offset+2 if offset > 0 397 | bmi lb2b 398 | ora offset 399 | bne lb4 fail with EINVAL 400 | lb2b sub4 #0,offset,offset negate offset 401 | lda #1 set mark to EOF - offset 402 | bra lb3 403 | lb2c cmp #SEEK_CUR else if whence == 1 (SEEK_CUR) 404 | bne lb4 405 | lda offset if offset is positive or 0 406 | bmi lb2d 407 | lda #2 set mark to old mark + offset 408 | bra lb3 else 409 | lb2d sub4 #0,offset,offset negate offset 410 | lda #3 set mark to old mark - offset 411 | lb3 sta >smBase save the base parameter 412 | lb3a lda offset set the displacement 413 | sta >smDisplacement 414 | lda offset+2 415 | sta >smDisplacement+2 416 | OSSet_Mark smRec set the file mark 417 | bcc lb5 418 | cmp #$4D out of range error => fail with EINVAL 419 | bne lb4a 420 | lb4 lda #EINVAL 421 | bra lb4b 422 | lb4a lda #EBADF bad refnum error 423 | lb4b sta >errno 424 | bra lb6 425 | lb5 OSGet_Mark gmRec get the new mark 426 | bcs lb4a 427 | lda >gmDisplacement 428 | sta mark 429 | lda >gmDisplacement+2 430 | sta mark+2 431 | 432 | lb6 creturn 4:mark 433 | 434 | smRec dc i'3' SetMark record 435 | smRefnum ds 2 436 | smBase ds 2 437 | smDisplacement ds 4 438 | 439 | gmRec dc i'2' GetMark record 440 | gmRefnum ds 2 441 | gmDisplacement ds 4 442 | end 443 | 444 | **************************************************************** 445 | * 446 | * int open(char *path, int oflag); 447 | * 448 | * Open a file 449 | * 450 | * Inputs: 451 | * path - name of the file 452 | * oflag - output flags 453 | * 454 | * Outputs: 455 | * returns 0 if successful; else -1 456 | * errno - set if an error occurred 457 | * 458 | **************************************************************** 459 | * 460 | open start 461 | err equ 1 error return code 462 | 463 | csubroutine (4:path,2:oflag),2 464 | 465 | ph2 errno 524 | brl lb11 525 | lb2 stx index save the index to the file 526 | 527 | ph4 errno 557 | bra lb11 558 | lb4a ph2 errno 568 | bra lb11 569 | lb7 OSCreate crRec create the file 570 | bcs lb9 571 | lb8 anop 572 | 573 | OSOpen opRec open the file 574 | bcs lb9 575 | lda oflag if the O_TRUNC flag is set then 576 | and #O_TRUNC 577 | beq lb10 578 | lda opRefnum set the EOF to 0 579 | sta efRefnum 580 | OSSet_EOF efRec 581 | bcc lb10 582 | lb9 dec err flag an I/O error 583 | lda #EACCES 584 | sta >errno 585 | bra lb11 586 | 587 | lb10 lda opRefnum save the reference number 588 | ldx index 589 | sta files,X 590 | txa set the return file index 591 | lsr A 592 | lsr A 593 | sta err 594 | 595 | lb11 plb restore the caller's B 596 | 597 | creturn 2:err 598 | 599 | crRec dc i'3' Create record 600 | crPathname ds 4 601 | crAccess ds 2 602 | crFileType ds 2 603 | 604 | giRec dc i'2' GetFileInfo record 605 | giPathname ds 4 606 | ds 2 607 | 608 | opRec dc i'2' Open record 609 | opRefnum ds 2 610 | opPathname ds 4 611 | 612 | efRec dc i'3' SetEOF record 613 | efRefnum ds 2 614 | dc i'0' 615 | dc i4'0' 616 | end 617 | 618 | **************************************************************** 619 | * 620 | * int read(int filds, char *buf, int n); 621 | * 622 | * Read from a file 623 | * 624 | * Inputs: 625 | * filds - file ID of file 626 | * buf - file buffer 627 | * n - # of bytes to read 628 | * 629 | * Outputs: 630 | * returns 0 if successful; else -1 631 | * errno - set if an error occurred 632 | * 633 | **************************************************************** 634 | * 635 | read start 636 | err equ 1 error return code 637 | 638 | csubroutine (2:filds,4:buf,2:n),2 639 | 640 | stz err err = 0 {no error} 641 | 642 | phb use our B 643 | phk 644 | plb 645 | lda filds error if the file has not been opened 646 | cmp #OPEN_MAX 647 | bge lb0 648 | asl A get the file reference number 649 | asl A 650 | tax 651 | lda files,X 652 | beq lb0 653 | sta rdRefnum 654 | stx filds 655 | lda files+2,X make sure the file is open for reading 656 | and #O_RDONLY+O_RDWR 657 | bne lb0a 658 | 659 | lb0 lda #EBADF errno = EBANF 660 | sta >errno 661 | dec err return = -1 662 | bra lb5 663 | 664 | lb0a move4 buf,rdDataBuffer set the location to read to 665 | lda n set the number of bytes to read 666 | sta rdRequestCount 667 | OSRead rdRec read the bytes 668 | bcc lb1 if an error occurred 669 | cmp #$4C and it was not EOF then 670 | beq lb1 671 | lda #EIO errno = EIO 672 | sta >errno 673 | dec err return -1 674 | bra lb5 675 | lb1 ldy rdTransferCount return the bytes read 676 | sty err 677 | beq lb5 678 | lb2 ldx filds if the file is not binary then 679 | lda files+2,X 680 | and #O_BINARY 681 | bne lb5 682 | dey for each byte do 683 | beq lb4a 684 | short M 685 | lb3 lda [buf],Y if the byte is \r then 686 | cmp #13 687 | bne lb4 688 | lda #10 change it to \n 689 | sta [buf],Y 690 | lb4 dey next byte 691 | bne lb3 692 | lb4a lda [buf] if the first byte is \r then 693 | cmp #13 694 | bne lb4b 695 | lda #10 change it to \n 696 | sta [buf] 697 | lb4b long M 698 | 699 | lb5 plb restore B 700 | creturn 2:err 701 | 702 | rdRec dc i'4' Read record 703 | rdRefnum ds 2 704 | rdDataBuffer ds 4 705 | rdRequestCount ds 4 706 | rdTransferCount ds 4 707 | end 708 | 709 | **************************************************************** 710 | * 711 | * unixtoprodos - Convert UNIX access flags to ProDOS access flags 712 | * 713 | * Inputs: 714 | * A - UNIX access flags 715 | * 716 | * Outputs: 717 | * A - ProDOS access flags 718 | * 719 | **************************************************************** 720 | * 721 | unixtoprodos private 722 | bits equ 3 ProDOS bits 723 | 724 | pea 0 set ProDOS bits to 0 725 | phd set up a stack frame 726 | tax 727 | tsc 728 | tcd 729 | txa 730 | 731 | bit #$1000 if unix delete bit is set then 732 | beq lb1 733 | sec set the ProDOS delete bit 734 | rol bits 735 | 736 | lb1 bit #$2000 if unix rename bit is set then 737 | beq lb2 738 | sec set the ProDOS rename bit 739 | bra lb3 else 740 | lb2 clc clear the ProDOS rename bit 741 | lb3 rol bits 742 | 743 | bit #$4000 if unix backup bit is set then 744 | beq lb4 745 | sec set the ProDOS backup bit 746 | bra lb5 else 747 | lb4 clc clear the ProDOS backup bit 748 | lb5 rol bits 749 | 750 | rol bits roll in the two unused bit fields 751 | rol bits 752 | 753 | bit #$8000 if unix invisible bit is set then 754 | beq lb6 755 | sec set the ProDOS invisible bit 756 | bra lb7 else 757 | lb6 clc clear the ProDOS invisible bit 758 | lb7 rol bits 759 | 760 | bit #$0080 if unix write bit is set then 761 | beq lb8 762 | sec set the ProDOS write bit 763 | bra lb9 else 764 | lb8 clc clear the ProDOS write bit 765 | lb9 rol bits 766 | 767 | bit #$0100 if unix read bit is set then 768 | beq lb10 769 | sec set the ProDOS read bit 770 | bra lb11 else 771 | lb10 clc clear the ProDOS read bit 772 | lb11 rol bits 773 | 774 | pld return the new flags 775 | pla 776 | rts 777 | end 778 | 779 | **************************************************************** 780 | * 781 | * int write(filds, char *buf, unsigned n); 782 | * 783 | * Write to a file 784 | * 785 | * Inputs: 786 | * filds - file ID of file 787 | * buf - file buffer 788 | * n - # of bytes to write 789 | * 790 | * Outputs: 791 | * returns 0 if successful; else -1 792 | * errno - set if an error occurred 793 | * 794 | **************************************************************** 795 | * 796 | write start 797 | err equ 1 error return code 798 | nbuff equ 3 new buffer pointer 799 | 800 | csubroutine (2:filds,4:buf,2:n),6 801 | 802 | stz err err = 0 {no error} 803 | 804 | phb use our B 805 | phk 806 | plb 807 | lda filds error if the file has not been opened 808 | cmp #OPEN_MAX 809 | bge lb0 810 | asl A get the file reference number 811 | asl A 812 | tax 813 | lda files,X 814 | beq lb0 815 | sta wrRefnum 816 | sta smRefnum 817 | stx filds 818 | lda files+2,X make sure the file is open for writing 819 | and #O_WRONLY+O_RDWR 820 | bne lb0a 821 | 822 | lb0 lda #EBADF errno = EBADF 823 | sta >errno 824 | dec err return = -1 825 | brl lb5 826 | 827 | lb0a move4 buf,wrDataBuffer set the location to write from 828 | lda n set the number of bytes to read 829 | sta wrRequestCount 830 | 831 | stz nbuff nbuff == nil 832 | stz nbuff+2 833 | ldx filds if the file is not binary then 834 | lda files+2,X 835 | and #O_BINARY 836 | bne lb0g 837 | pea 0 reserve a file buffer 838 | ph2 errno 847 | bra lb5 848 | lb0b ldy n move the bytes to the new buffer, 849 | beq lb0f converting \n chars to \r chars 850 | dey in the process 851 | beq lb0da 852 | short M 853 | lb0c lda [buf],Y 854 | cmp #10 855 | bne lb0d 856 | lda #13 857 | lb0d sta [nbuff],Y 858 | dey 859 | bne lb0c 860 | lb0da lda [buf] 861 | cmp #10 862 | bne lb0e 863 | lda #13 864 | lb0e sta [nbuff] 865 | long M 866 | lb0f move4 nbuff,wrDataBuffer set the data buffer start 867 | 868 | lb0g ldx filds if the file is in O_APPEND mode then 869 | lda files+2,X 870 | and #O_APPEND 871 | beq lb0h 872 | OSSet_Mark smRec set mark to EOF 873 | lb0h OSWrite wrRec write the bytes 874 | bcc lb1 if an error occurred then 875 | lda #EIO errno = EIO 876 | sta >errno 877 | dec err return -1 878 | bra lb5 879 | lb1 ldy wrTransferCount return the bytes read 880 | sty err 881 | 882 | lda nbuff if nbuff <> NULL then 883 | ora nbuff+2 884 | beq lb2 885 | ph4 "{",.b 12 | &c amid &n1,l:&n1,1 13 | aif "&c"<>"}",.g 14 | &n1 amid &n1,2,l:&n1-2 15 | lda (&n1) 16 | pha 17 | ago .e 18 | .b 19 | aif "&c"="<",.c 20 | lda &n1 21 | pha 22 | ago .e 23 | .c 24 | &n1 amid &n1,2,l:&n1-1 25 | pei &n1 26 | ago .e 27 | .d 28 | &n1 amid &n1,2,l:&n1-1 29 | pea &n1 30 | ago .f 31 | .e 32 | aif s:longa=1,.f 33 | sep #%00100000 34 | .f 35 | mexit 36 | .g 37 | mnote "Missing closing '}'",16 38 | mend 39 | macro 40 | &l ph4 &n1 41 | &l anop 42 | aif "&n1"="*",.f 43 | lclc &c 44 | &c amid &n1,1,1 45 | aif "&c"="#",.d 46 | aif s:longa=1,.a 47 | rep #%00100000 48 | .a 49 | aif "&c"<>"{",.b 50 | &c amid &n1,l:&n1,1 51 | aif "&c"<>"}",.g 52 | &n1 amid &n1,2,l:&n1-2 53 | ldy #2 54 | lda (&n1),y 55 | pha 56 | lda (&n1) 57 | pha 58 | ago .e 59 | .b 60 | aif "&c"<>"[",.c 61 | ldy #2 62 | lda &n1,y 63 | pha 64 | lda &n1 65 | pha 66 | ago .e 67 | .c 68 | aif "&c"<>"<",.c1 69 | &n1 amid &n1,2,l:&n1-1 70 | pei &n1+2 71 | pei &n1 72 | ago .e 73 | .c1 74 | lda &n1+2 75 | pha 76 | lda &n1 77 | pha 78 | ago .e 79 | .d 80 | &n1 amid &n1,2,l:&n1-1 81 | pea +(&n1)|-16 82 | pea &n1 83 | ago .f 84 | .e 85 | aif s:longa=1,.f 86 | sep #%00100000 87 | .f 88 | mexit 89 | .g 90 | mnote "Missing closing '}'",16 91 | mend 92 | MACRO 93 | &LAB MOVE4 &F,&T 94 | &LAB ~SETM 95 | LDA 2+&F 96 | STA 2+&T 97 | LDA &F 98 | STA &T 99 | ~RESTM 100 | MEND 101 | MACRO 102 | &lab csubroutine &parms,&work 103 | &lab anop 104 | aif c:&work,.a 105 | lclc &work 106 | &work setc 0 107 | .a 108 | gbla &totallen 109 | gbla &worklen 110 | &worklen seta &work 111 | &totallen seta 0 112 | aif c:&parms=0,.e 113 | lclc &len 114 | lclc &p 115 | lcla &i 116 | &i seta 1 117 | .b 118 | &p setc &parms(&i) 119 | &len amid &p,2,1 120 | aif "&len"=":",.c 121 | &len amid &p,1,2 122 | &p amid &p,4,l:&p-3 123 | ago .d 124 | .c 125 | &len amid &p,1,1 126 | &p amid &p,3,l:&p-2 127 | .d 128 | &p equ &totallen+4+&work 129 | &totallen seta &totallen+&len 130 | &i seta &i+1 131 | aif &i<=c:&parms,^b 132 | .e 133 | tsc 134 | aif &work=0,.f 135 | sec 136 | sbc #&work 137 | tcs 138 | .f 139 | phd 140 | tcd 141 | mend 142 | MACRO 143 | &lab creturn &r 144 | &lab anop 145 | lclc &len 146 | aif c:&r,.a 147 | lclc &r 148 | &r setc 0 149 | &len setc 0 150 | ago .h 151 | .a 152 | &len amid &r,2,1 153 | aif "&len"=":",.b 154 | &len amid &r,1,2 155 | &r amid &r,4,l:&r-3 156 | ago .c 157 | .b 158 | &len amid &r,1,1 159 | &r amid &r,3,l:&r-2 160 | .c 161 | aif &len<>2,.d 162 | ldy &r 163 | ago .h 164 | .d 165 | aif &len<>4,.e 166 | ldx &r+2 167 | ldy &r 168 | ago .h 169 | .e 170 | aif &len<>10,.g 171 | ldy #&r 172 | ldx #^&r 173 | ago .h 174 | .g 175 | mnote 'Not a valid return length',16 176 | mexit 177 | .h 178 | aif &totallen=0,.i 179 | lda &worklen+2 180 | sta &worklen+&totallen+2 181 | lda &worklen+1 182 | sta &worklen+&totallen+1 183 | .i 184 | pld 185 | tsc 186 | clc 187 | adc #&worklen+&totallen 188 | tcs 189 | aif &len=0,.j 190 | tya 191 | .j 192 | rtl 193 | mend 194 | MACRO 195 | &LAB ~SETM 196 | &LAB ANOP 197 | AIF C:&~LA,.B 198 | GBLB &~LA 199 | GBLB &~LI 200 | .B 201 | &~LA SETB S:LONGA 202 | &~LI SETB S:LONGI 203 | AIF S:LONGA.AND.S:LONGI,.A 204 | REP #32*(.NOT.&~LA)+16*(.NOT.&~LI) 205 | LONGA ON 206 | LONGI ON 207 | .A 208 | MEND 209 | MACRO 210 | &LAB ~RESTM 211 | &LAB ANOP 212 | AIF (&~LA+&~LI)=2,.I 213 | SEP #32*(.NOT.&~LA)+16*(.NOT.&~LI) 214 | AIF &~LA,.H 215 | LONGA OFF 216 | .H 217 | AIF &~LI,.I 218 | LONGI OFF 219 | .I 220 | MEND 221 | MACRO 222 | &LAB LONG &A,&B 223 | LCLB &I 224 | LCLB &M 225 | &A AMID &A,1,1 226 | &M SETB ("&A"="M").OR.("&A"="m") 227 | &I SETB ("&A"="I").OR.("&A"="i") 228 | AIF C:&B=0,.A 229 | &B AMID &B,1,1 230 | &M SETB ("&B"="M").OR.("&B"="m").OR.&M 231 | &I SETB ("&B"="I").OR.("&B"="i").OR.&I 232 | .A 233 | &LAB REP #&M*32+&I*16 234 | AIF .NOT.&M,.B 235 | LONGA ON 236 | .B 237 | AIF .NOT.&I,.C 238 | LONGI ON 239 | .C 240 | MEND 241 | MACRO 242 | &LAB SHORT &A,&B 243 | LCLB &I 244 | LCLB &M 245 | &A AMID &A,1,1 246 | &M SETB ("&A"="M").OR.("&A"="m") 247 | &I SETB ("&A"="I").OR.("&A"="i") 248 | AIF C:&B=0,.A 249 | &B AMID &B,1,1 250 | &M SETB ("&B"="M").OR.("&B"="m").OR.&M 251 | &I SETB ("&B"="I").OR.("&B"="i").OR.&I 252 | .A 253 | &LAB SEP #&M*32+&I*16 254 | AIF .NOT.&M,.B 255 | LONGA OFF 256 | .B 257 | AIF .NOT.&I,.C 258 | LONGI OFF 259 | .C 260 | MEND 261 | MACRO 262 | &LAB OSREAD &DCB 263 | &LAB JSL $E100A8 264 | DC I2'$2012' 265 | DC I4'&DCB' 266 | MEND 267 | MACRO 268 | &LAB OSCLOSE &DCB 269 | &LAB JSL $E100A8 270 | DC I2'$2014' 271 | DC I4'&DCB' 272 | MEND 273 | MACRO 274 | &LAB OSSET_MARK &DCB 275 | &LAB JSL $E100A8 276 | DC I2'$2016' 277 | DC I4'&DCB' 278 | MEND 279 | MACRO 280 | &LAB OSGET_MARK &DCB 281 | &LAB JSL $E100A8 282 | DC I2'$2017' 283 | DC I4'&DCB' 284 | MEND 285 | MACRO 286 | &LAB OSSET_FILE_INFO &DCB 287 | &LAB JSL $E100A8 288 | DC I2'$2005' 289 | DC I4'&DCB' 290 | MEND 291 | MACRO 292 | &LAB OSCLEAR_BACKUP &DCB 293 | &LAB JSL $E100A8 294 | DC I2'$200B' 295 | DC I4'&DCB' 296 | MEND 297 | MACRO 298 | &LAB LLA &AD1,&AD2 299 | &LAB ANOP 300 | LCLA &L 301 | LCLB &LA 302 | AIF S:LONGA,.A 303 | REP #%00100000 304 | LONGA ON 305 | &LA SETB 1 306 | .A 307 | LDA #&AD2 308 | &L SETA C:&AD1 309 | .B 310 | STA &AD1(&L) 311 | &L SETA &L-1 312 | AIF &L,^B 313 | LDA #^&AD2 314 | &L SETA C:&AD1 315 | .C 316 | STA 2+&AD1(&L) 317 | &L SETA &L-1 318 | AIF &L,^C 319 | AIF &LA=0,.D 320 | SEP #%00100000 321 | LONGA OFF 322 | .D 323 | MEND 324 | MACRO 325 | &LAB OSCREATE &DCB 326 | &LAB JSL $E100A8 327 | DC I2'$2001' 328 | DC I4'&DCB' 329 | MEND 330 | MACRO 331 | &LAB OSGET_FILE_INFO &DCB 332 | &LAB JSL $E100A8 333 | DC I2'$2006' 334 | DC I4'&DCB' 335 | MEND 336 | MACRO 337 | &LAB OSOPEN &DCB 338 | &LAB JSL $E100A8 339 | DC I2'$2010' 340 | DC I4'&DCB' 341 | MEND 342 | MACRO 343 | &LAB OSWRITE &DCB 344 | &LAB JSL $E100A8 345 | DC I2'$2013' 346 | DC I4'&DCB' 347 | MEND 348 | MACRO 349 | &LAB OSSET_EOF &DCB 350 | &LAB JSL $E100A8 351 | DC I2'$2018' 352 | DC I4'&DCB' 353 | MEND 354 | MACRO 355 | &LAB SUB4 &M1,&M2,&M3 356 | LCLB &YISTWO 357 | LCLC &C 358 | &LAB ~SETM 359 | AIF C:&M3,.A 360 | &C AMID "&M2",1,1 361 | AIF "&C"<>"#",.A 362 | &C AMID "&M1",1,1 363 | AIF "&C"="{",.A 364 | AIF "&C"="[",.A 365 | &C AMID "&M2",2,L:&M2-1 366 | AIF &C>=65536,.A 367 | SEC 368 | ~LDA &M1 369 | ~OP SBC,&M2 370 | ~STA &M1 371 | BCS ~&SYSCNT 372 | ~OP.H DEC,&M1 373 | ~&SYSCNT ANOP 374 | AGO .C 375 | .A 376 | AIF C:&M3,.B 377 | LCLC &M3 378 | &M3 SETC &M1 379 | .B 380 | SEC 381 | ~LDA &M1 382 | ~OP SBC,&M2 383 | ~STA &M3 384 | ~LDA.H &M1 385 | ~OP.H SBC,&M2 386 | ~STA.H &M3 387 | .C 388 | ~RESTM 389 | MEND 390 | MACRO 391 | &LAB ~OP.H &OPC,&OP 392 | &LAB ANOP 393 | LCLC &C 394 | &C AMID "&OP",1,1 395 | AIF "&C"="[",.B 396 | AIF "&C"<>"{",.D 397 | &C AMID "&OP",L:&OP,1 398 | AIF "&C"="}",.A 399 | MNOTE "Missing closing '}'",2 400 | &OP SETC &OP} 401 | .A 402 | &OP AMID "&OP",2,L:&OP-2 403 | &OP SETC (&OP) 404 | .B 405 | AIF &YISTWO,.C 406 | &YISTWO SETB 1 407 | LDY #2 408 | &OP SETC "&OP,Y" 409 | .C 410 | &OPC &OP 411 | MEXIT 412 | .D 413 | AIF "&C"<>"#",.E 414 | &OP AMID "&OP",2,L:&OP-1 415 | &OP SETC "#^&OP" 416 | &OPC &OP 417 | MEXIT 418 | .E 419 | &OPC 2+&OP 420 | MEND 421 | MACRO 422 | &LAB ~LDA.H &OP 423 | &LAB ANOP 424 | LCLC &C 425 | &C AMID "&OP",1,1 426 | AIF "&C"="[",.B 427 | AIF "&C"<>"{",.D 428 | &C AMID "&OP",L:&OP,1 429 | AIF "&C"="}",.A 430 | MNOTE "Missing closing '}'",2 431 | &OP SETC &OP} 432 | .A 433 | &OP AMID "&OP",2,L:&OP-2 434 | &OP SETC (&OP) 435 | .B 436 | AIF &YISTWO,.C 437 | &YISTWO SETB 1 438 | LDY #2 439 | &OP SETC "&OP,Y" 440 | .C 441 | LDA &OP 442 | MEXIT 443 | .D 444 | AIF "&C"<>"#",.E 445 | &OP AMID "&OP",2,L:&OP-1 446 | &OP SETC "#^&OP" 447 | LDA &OP 448 | MEXIT 449 | .E 450 | LDA 2+&OP 451 | MEND 452 | MACRO 453 | &LAB ~STA.H &OP 454 | &LAB ANOP 455 | LCLC &C 456 | &C AMID "&OP",1,1 457 | AIF "&C"="[",.B 458 | AIF "&C"<>"{",.D 459 | &C AMID "&OP",L:&OP,1 460 | AIF "&C"="}",.A 461 | MNOTE "Missing closing '}'",2 462 | &OP SETC &OP} 463 | .A 464 | &OP AMID "&OP",2,L:&OP-2 465 | &OP SETC (&OP) 466 | .B 467 | AIF &YISTWO,.C 468 | &YISTWO SETB 1 469 | LDY #2 470 | &OP SETC "&OP,Y" 471 | .C 472 | STA &OP 473 | MEXIT 474 | .D 475 | STA 2+&OP 476 | MEND 477 | MACRO 478 | &LAB ~LDA &OP 479 | LCLC &C 480 | &C AMID "&OP",1,1 481 | AIF "&C"<>"{",.B 482 | &C AMID "&OP",L:&OP,1 483 | AIF "&C"="}",.A 484 | MNOTE "Missing closing '}'",2 485 | &OP SETC &OP} 486 | .A 487 | &OP AMID "&OP",2,L:&OP-2 488 | &OP SETC (&OP) 489 | .B 490 | &LAB LDA &OP 491 | MEND 492 | MACRO 493 | &LAB ~STA &OP 494 | LCLC &C 495 | &C AMID "&OP",1,1 496 | AIF "&C"<>"{",.B 497 | &C AMID "&OP",L:&OP,1 498 | AIF "&C"="}",.A 499 | MNOTE "Missing closing '}'",2 500 | &OP SETC &OP} 501 | .A 502 | &OP AMID "&OP",2,L:&OP-2 503 | &OP SETC (&OP) 504 | .B 505 | &LAB STA &OP 506 | MEND 507 | MACRO 508 | &LAB ~OP &OPC,&OP 509 | LCLC &C 510 | &C AMID "&OP",1,1 511 | AIF "&C"<>"{",.B 512 | &C AMID "&OP",L:&OP,1 513 | AIF "&C"="}",.A 514 | MNOTE "Missing closing '}'",2 515 | &OP SETC &OP} 516 | .A 517 | &OP AMID "&OP",2,L:&OP-2 518 | &OP SETC (&OP) 519 | .B 520 | &LAB &OPC &OP 521 | MEND 522 | -------------------------------------------------------------------------------- /int64.asm: -------------------------------------------------------------------------------- 1 | keep obj/int64 2 | mcopy int64.macros 3 | case off 4 | 5 | **************************************************************** 6 | * 7 | * Int64 - 64-bit integer math routines. 8 | * 9 | * This code implements routines called by ORCA/C generated 10 | * code for operations on 64-bit integers. 11 | * 12 | **************************************************************** 13 | * 14 | Int64 private dummy segment 15 | end 16 | 17 | **************************************************************** 18 | * 19 | * ~UMUL8 - Eight Byte Unsigned Integer Multiply 20 | * 21 | * Inputs: 22 | * NUM1,NUM2 - operands 23 | * 24 | * Outputs: 25 | * NUM2 - result 26 | * X - next 16 bits of true result (bits 64-79) 27 | * 28 | **************************************************************** 29 | * 30 | ~UMUL8 START 31 | 32 | ANS EQU 3 33 | RETURN EQU ANS+16 34 | NUM1 EQU RETURN+3 35 | NUM2 EQU NUM1+8 36 | 37 | LDA #0 set up initial working value 38 | PHA 39 | PHA 40 | PHA 41 | PHA 42 | LDA 18,s initially, ANS = NUM1 43 | PHA 44 | LDA 18,s 45 | PHA 46 | LDA 18,s 47 | PHA 48 | LDA 18,s 49 | PHA 50 | PHD 51 | TSC 52 | TCD 53 | ; 54 | ; Do a 64 bit by 64 bit multiply. 55 | ; 56 | LDY #64 64 bit multiply 57 | ML1 LDA ANS 58 | LSR A 59 | BCC ML2 60 | CLC add multiplicand to the partial product 61 | LDA ANS+8 62 | ADC NUM2 63 | STA ANS+8 64 | LDA ANS+10 65 | ADC NUM2+2 66 | STA ANS+10 67 | LDA ANS+12 68 | ADC NUM2+4 69 | STA ANS+12 70 | LDA ANS+14 71 | ADC NUM2+6 72 | STA ANS+14 73 | ML2 ROR ANS+14 shift the interim result 74 | ROR ANS+12 75 | ROR ANS+10 76 | ROR ANS+8 77 | ROR ANS+6 78 | ROR ANS+4 79 | ROR ANS+2 80 | ROR ANS 81 | DEY loop until done 82 | BNE ML1 83 | 84 | move4 ANS,NUM2 move return value and address 85 | move4 ANS+4,NUM2+4 86 | move4 RETURN-1,NUM1+4 87 | LDX ANS+8 set X to next 16 bits of result 88 | PLD fix stack, DP 89 | TSC 90 | CLC 91 | ADC #24 92 | TCS 93 | RTL 94 | END 95 | 96 | **************************************************************** 97 | * 98 | * ~CDIV8 - Eight Byte Signed Integer Divide, 99 | * with C-style remainder computation 100 | * 101 | * Inputs: 102 | * NUM1 - numerator 103 | * NUM2 - denominator 104 | * 105 | * Outputs: 106 | * ANS - result 107 | * REM - remainder 108 | * V - set for division by zero 109 | * 110 | * Notes 111 | * 1) Uses ~SIG8. 112 | * 113 | **************************************************************** 114 | * 115 | ~CDIV8 START 116 | SIGN EQU 1 sign of answer 117 | NUM1 EQU 36 118 | NUM2 EQU 28 119 | ANS EQU 9 answer 120 | REM EQU 17 remainder 121 | RETURN EQU 25 122 | ; 123 | ; Initialize 124 | ; 125 | TSC set up DP 126 | SEC 127 | SBC #24 128 | TCS 129 | PHD 130 | TCD 131 | LDA NUM2 check for division by zero 132 | ORA NUM2+2 133 | ORA NUM2+4 134 | ORA NUM2+6 135 | BNE DV1 136 | 137 | PLD division by zero 138 | TSC 139 | CLC 140 | ADC #24 141 | TCS 142 | SEP #%01000000 143 | RTL 144 | 145 | DV1 JSL ~SIG8 convert to positive numbers 146 | ; 147 | ; 64 BIT DIVIDE 148 | ; 149 | LDY #64 64 bits to go 150 | DV3 ASL ANS roll up the next number 151 | ROL ANS+2 152 | ROL ANS+4 153 | ROL ANS+6 154 | ROL ANS+8 155 | ROL ANS+10 156 | ROL ANS+12 157 | ROL ANS+14 158 | SEC subtract for this digit 159 | LDA ANS+8 160 | SBC NUM2 161 | TAX 162 | LDA ANS+10 163 | SBC NUM2+2 164 | STA SIGN+2 165 | LDA ANS+12 166 | SBC NUM2+4 167 | STA SIGN+4 168 | LDA ANS+14 169 | SBC NUM2+6 170 | BCC DV4 branch if minus 171 | STX ANS+8 save partial numerator 172 | STA ANS+14 173 | LDA SIGN+2 174 | STA ANS+10 175 | LDA SIGN+4 176 | STA ANS+12 177 | INC ANS turn the bit on 178 | DV4 DEY next bit 179 | BNE DV3 180 | ; 181 | ; SET SIGN 182 | ; 183 | LDA SIGN branch if positive 184 | BEQ DV10 185 | SEC negate the result 186 | LDA #0 187 | SBC ANS 188 | STA ANS 189 | LDA #0 190 | SBC ANS+2 191 | STA ANS+2 192 | LDA #0 193 | SBC ANS+4 194 | STA ANS+4 195 | LDA #0 196 | SBC ANS+6 197 | STA ANS+6 198 | DV10 LDA NUM1+6 if numerator is negative 199 | BPL DV11 200 | SEC negate the remainder 201 | LDA #0 202 | SBC REM 203 | STA REM 204 | LDA #0 205 | SBC REM+2 206 | STA REM+2 207 | LDA #0 208 | SBC REM+4 209 | STA REM+4 210 | LDA #0 211 | SBC REM+6 212 | STA REM+6 213 | DV11 LDX #14 move answer, remainder to stack 214 | DV12 LDA ANS,X 215 | STA NUM2,X 216 | DEX 217 | DEX 218 | BPL DV12 219 | CLV 220 | PLD fix stack, DP 221 | TSC 222 | CLC 223 | ADC #24 224 | TCS 225 | RTL 226 | END 227 | 228 | **************************************************************** 229 | * 230 | * ~UDIV8 - Eight Byte Unsigned Integer Divide 231 | * 232 | * Inputs: 233 | * NUM1 - numerator 234 | * NUM2 - denominator 235 | * 236 | * Outputs: 237 | * ANS - result 238 | * REM - remainder 239 | * V - set for division by zero 240 | * 241 | **************************************************************** 242 | * 243 | ~UDIV8 START 244 | TEMP EQU 1 245 | NUM1 EQU 32 246 | NUM2 EQU 24 247 | ANS EQU 5 answer 248 | REM EQU 13 remainder 249 | RETURN EQU 21 250 | ; 251 | ; Initialize 252 | ; 253 | TSC set up DP 254 | SEC 255 | SBC #20 256 | TCS 257 | PHD 258 | TCD 259 | LDA NUM2 check for division by zero 260 | ORA NUM2+2 261 | ORA NUM2+4 262 | ORA NUM2+6 263 | BNE DV1 264 | 265 | PLD division by zero 266 | TSC 267 | CLC 268 | ADC #20 269 | TCS 270 | SEP #%01000000 271 | RTL 272 | 273 | DV1 STZ REM initialize REM to 0 274 | STZ REM+2 275 | STZ REM+4 276 | STZ REM+6 277 | move4 NUM1,ANS initialize ANS to NUM1 278 | move4 NUM1+4,ANS+4 279 | ; 280 | ; 64 BIT DIVIDE 281 | ; 282 | LDY #64 64 bits to go 283 | DV3 ASL ANS roll up the next number 284 | ROL ANS+2 285 | ROL ANS+4 286 | ROL ANS+6 287 | ROL ANS+8 288 | ROL ANS+10 289 | ROL ANS+12 290 | ROL ANS+14 291 | SEC subtract for this digit 292 | LDA ANS+8 293 | SBC NUM2 294 | TAX 295 | LDA ANS+10 296 | SBC NUM2+2 297 | STA TEMP 298 | LDA ANS+12 299 | SBC NUM2+4 300 | STA TEMP+2 301 | LDA ANS+14 302 | SBC NUM2+6 303 | BCC DV4 branch if minus 304 | STX ANS+8 save partial numerator 305 | STA ANS+14 306 | LDA TEMP 307 | STA ANS+10 308 | LDA TEMP+2 309 | STA ANS+12 310 | INC ANS turn the bit on 311 | DV4 DEY next bit 312 | BNE DV3 313 | 314 | DV10 LDX #14 move answer, remainder to stack 315 | DV11 LDA ANS,X 316 | STA NUM2,X 317 | DEX 318 | DEX 319 | BPL DV11 320 | CLV 321 | PLD fix stack, DP 322 | TSC 323 | CLC 324 | ADC #20 325 | TCS 326 | RTL 327 | END 328 | 329 | **************************************************************** 330 | * 331 | * ~SCMP8 - Eight Byte Signed Integer Compare 332 | * 333 | * Inputs: 334 | * NUM1 - first argument 335 | * NUM2 - second argument 336 | * 337 | * Outputs: 338 | * C - set if NUM1 >= NUM2, else clear 339 | * Z - set if NUM1 = NUM2, else clear 340 | * 341 | **************************************************************** 342 | * 343 | ~SCMP8 START 344 | NUM1 EQU 12 first argument 345 | NUM2 EQU 4 second argument 346 | RETURN EQU 0 P reg and return addr 347 | 348 | TDC set up DP 349 | TAX 350 | TSC 351 | TCD 352 | LDA NUM1+6 if numbers are of opposite sign then 353 | EOR NUM2+6 354 | BPL LB1 355 | LDA NUM2+6 reverse sense of compare 356 | CMP NUM1+6 357 | BRA LB2 else 358 | LB1 LDA NUM1+6 compare numbers 359 | CMP NUM2+6 360 | BNE LB2 361 | LDA NUM1+4 362 | CMP NUM2+4 363 | BNE LB2 364 | LDA NUM1+2 365 | CMP NUM2+2 366 | BNE LB2 367 | LDA NUM1 368 | CMP NUM2 369 | LB2 ANOP endif 370 | PHP save result 371 | LDA RETURN move P and return addr 372 | STA NUM1+4 373 | LDA RETURN+2 374 | STA NUM1+6 375 | CLC remove 16 bytes from stack 376 | TSC 377 | ADC #16 378 | TCS 379 | TXA restore DP 380 | TCD 381 | PLP restore P 382 | RTL return 383 | END 384 | 385 | **************************************************************** 386 | * 387 | * ~LShr8 - Shift an unsigned long long value right 388 | * 389 | * Inputs: 390 | * num1 - value to shift 391 | * A - # of bits to shift by 392 | * 393 | * Outputs: 394 | * num1 - result 395 | * 396 | **************************************************************** 397 | * 398 | ~LShr8 start 399 | num1 equ 4 400 | 401 | tax save shift count 402 | beq rtl return if it is 0 403 | 404 | tsc 405 | phd 406 | tcd 407 | 408 | txa 409 | loop0 cmp #16 shift by 16s first 410 | blt loop1 411 | ldy num1+2 412 | sty num1 413 | ldy num1+4 414 | sty num1+2 415 | ldy num1+6 416 | sty num1+4 417 | stz num1+6 418 | ; sec 419 | sbc #16 420 | bne loop0 421 | bra rt0 422 | 423 | loop1 lsr num1+6 do the remaining shift 424 | ror num1+4 425 | ror num1+2 426 | ror num1 427 | dec a 428 | bne loop1 429 | 430 | rt0 pld 431 | rtl rtl 432 | end 433 | 434 | **************************************************************** 435 | * 436 | * ~AShr8 - Shift a signed long long value right 437 | * 438 | * Inputs: 439 | * num1 - value to shift 440 | * A - # of bits to shift by 441 | * 442 | * Outputs: 443 | * num1 - result 444 | * 445 | **************************************************************** 446 | * 447 | ~AShr8 start 448 | num1 equ 4 449 | 450 | tax save shift count 451 | beq rtl return if it is 0 452 | 453 | tsc 454 | phd 455 | tcd 456 | 457 | loop1 lda num1+6 do the shift 458 | asl a 459 | ror num1+6 460 | ror num1+4 461 | ror num1+2 462 | ror num1 463 | dex 464 | bne loop1 465 | 466 | pld 467 | rtl rtl 468 | end 469 | 470 | **************************************************************** 471 | * 472 | * ~Shl8 - Shift a signed long long value left 473 | * 474 | * Inputs: 475 | * num1 - value to shift 476 | * A - # of bits to shift by 477 | * 478 | * Outputs: 479 | * num1 - result 480 | * 481 | **************************************************************** 482 | * 483 | ~Shl8 start 484 | num1 equ 4 485 | 486 | tax save shift count 487 | beq rtl return if it is 0 488 | 489 | tsc 490 | phd 491 | tcd 492 | 493 | txa 494 | loop0 cmp #16 shift by 16s first 495 | blt loop1 496 | ldy num1+4 497 | sty num1+6 498 | ldy num1+2 499 | sty num1+4 500 | ldy num1 501 | sty num1+2 502 | stz num1 503 | ; sec 504 | sbc #16 505 | bne loop0 506 | bra rt0 507 | 508 | loop1 asl num1 do the remaining shift 509 | rol num1+2 510 | rol num1+4 511 | rol num1+6 512 | dec a 513 | bne loop1 514 | 515 | rt0 pld 516 | rtl rtl 517 | end 518 | -------------------------------------------------------------------------------- /int64.macros: -------------------------------------------------------------------------------- 1 | macro 2 | &l move4 &m1,&m2 3 | lclb &yistwo 4 | &l ~setm 5 | ~lda &m1 6 | ~sta &m2 7 | ~lda.h &m1 8 | ~sta.h &m2 9 | ~restm 10 | mend 11 | macro 12 | &l ~lda &op 13 | lclc &c 14 | &c amid "&op",1,1 15 | aif "&c"<>"{",.b 16 | &c amid "&op",l:&op,1 17 | aif "&c"="}",.a 18 | mnote "Missing closing '}'",2 19 | &op setc &op} 20 | .a 21 | &op amid "&op",2,l:&op-2 22 | &op setc (&op) 23 | .b 24 | &l lda &op 25 | mend 26 | macro 27 | &l ~lda.h &op 28 | &l anop 29 | lclc &c 30 | &c amid "&op",1,1 31 | aif "&c"="[",.b 32 | aif "&c"<>"{",.d 33 | &c amid "&op",l:&op,1 34 | aif "&c"="}",.a 35 | mnote "Missing closing '}'",2 36 | &op setc &op} 37 | .a 38 | &op amid "&op",2,l:&op-2 39 | &op setc (&op) 40 | .b 41 | aif &yistwo,.c 42 | &yistwo setb 1 43 | ldy #2 44 | .c 45 | &op setc "&op,y" 46 | lda &op 47 | mexit 48 | .d 49 | aif "&c"<>"#",.e 50 | &op amid "&op",2,l:&op-1 51 | &op setc "#^&op" 52 | lda &op 53 | mexit 54 | .e 55 | lda 2+&op 56 | mend 57 | macro 58 | &l ~restm 59 | &l anop 60 | aif (&~la+&~li)=2,.i 61 | sep #32*(.not.&~la)+16*(.not.&~li) 62 | aif &~la,.h 63 | longa off 64 | .h 65 | aif &~li,.i 66 | longi off 67 | .i 68 | mend 69 | macro 70 | &l ~setm 71 | &l anop 72 | aif c:&~la,.b 73 | gblb &~la 74 | gblb &~li 75 | .b 76 | &~la setb s:longa 77 | &~li setb s:longi 78 | aif s:longa.and.s:longi,.a 79 | rep #32*(.not.&~la)+16*(.not.&~li) 80 | longa on 81 | longi on 82 | .a 83 | mend 84 | macro 85 | &l ~sta &op 86 | lclc &c 87 | &c amid "&op",1,1 88 | aif "&c"<>"{",.b 89 | &c amid "&op",l:&op,1 90 | aif "&c"="}",.a 91 | mnote "Missing closing '}'",2 92 | &op setc &op} 93 | .a 94 | &op amid "&op",2,l:&op-2 95 | &op setc (&op) 96 | .b 97 | &l sta &op 98 | mend 99 | macro 100 | &l ~sta.h &op 101 | &l anop 102 | lclc &c 103 | &c amid "&op",1,1 104 | aif "&c"="[",.b 105 | aif "&c"<>"{",.d 106 | &c amid "&op",l:&op,1 107 | aif "&c"="}",.a 108 | mnote "Missing closing '}'",2 109 | &op setc &op} 110 | .a 111 | &op amid "&op",2,l:&op-2 112 | &op setc (&op) 113 | .b 114 | aif &yistwo,.c 115 | &yistwo setb 1 116 | ldy #2 117 | .c 118 | &op setc "&op,y" 119 | sta &op 120 | mexit 121 | .d 122 | sta 2+&op 123 | mend 124 | -------------------------------------------------------------------------------- /locale.asm: -------------------------------------------------------------------------------- 1 | keep obj/locale 2 | mcopy locale.macros 3 | case on 4 | **************************************************************** 5 | * 6 | * Locale - locale support 7 | * 8 | * This currently implements a minimalistic version of the 9 | * functions, supporting only the "C" locale. 10 | * 11 | **************************************************************** 12 | * 13 | Locale private dummy routine 14 | end 15 | 16 | **************************************************************** 17 | * 18 | * char *setlocale(int category, const char *locale); 19 | * 20 | * Set or query current locale 21 | * 22 | * Inputs: 23 | * category - locale category to set or query 24 | * locale - locale name (or NULL for query) 25 | * 26 | * Outputs: 27 | * returns locale string (for relevant category), 28 | * or NULL if locale cannot be set as requested 29 | * 30 | **************************************************************** 31 | * 32 | setlocale start 33 | LC_MAX equ 5 maximum valid LC_* value 34 | 35 | csubroutine (2:category,4:locale),0 36 | 37 | lda category if category is invalid 38 | cmp #LC_MAX+1 39 | bge err return NULL 40 | lda locale if querying the current locale 41 | ora locale+2 42 | beq good return "C" 43 | lda [locale] 44 | cmp #'C' if locale is "C" or "", we are good 45 | beq good 46 | and #$00FF 47 | bne err 48 | good lda #C_str if successful, return "C" 49 | sta locale 50 | lda #^C_str 51 | sta locale+2 52 | bra ret 53 | err stz locale otherwise, return NULL for error 54 | stz locale+2 55 | ret creturn 4:locale 56 | 57 | C_str dc c'C',i1'0' 58 | end 59 | 60 | **************************************************************** 61 | * 62 | * struct lconv *localeconv(void); 63 | * 64 | * Get numeric formatting conventions 65 | * 66 | * Outputs: 67 | * returns pointer to a struct lconv containing 68 | * appropriate values for the current locale 69 | * 70 | **************************************************************** 71 | * 72 | localeconv start 73 | CHAR_MAX equ 255 74 | 75 | ldx #^C_locale_lconv 76 | lda #C_locale_lconv 77 | rtl 78 | 79 | C_locale_lconv anop 80 | decimal_point dc a4'period' 81 | thousands_sep dc a4'emptystr' 82 | grouping dc a4'emptystr' 83 | mon_decimal_point dc a4'emptystr' 84 | mon_thousands_sep dc a4'emptystr' 85 | mon_grouping dc a4'emptystr' 86 | positive_sign dc a4'emptystr' 87 | negative_sign dc a4'emptystr' 88 | currency_symbol dc a4'emptystr' 89 | frac_digits dc i1'CHAR_MAX' 90 | p_cs_precedes dc i1'CHAR_MAX' 91 | n_cs_precedes dc i1'CHAR_MAX' 92 | p_sep_by_space dc i1'CHAR_MAX' 93 | n_sep_by_space dc i1'CHAR_MAX' 94 | p_sign_posn dc i1'CHAR_MAX' 95 | n_sign_posn dc i1'CHAR_MAX' 96 | int_curr_symbol dc a4'emptystr' 97 | int_frac_digits dc i1'CHAR_MAX' 98 | int_p_cs_precedes dc i1'CHAR_MAX' 99 | int_n_cs_precedes dc i1'CHAR_MAX' 100 | int_p_sep_by_space dc i1'CHAR_MAX' 101 | int_n_sep_by_space dc i1'CHAR_MAX' 102 | int_p_sign_posn dc i1'CHAR_MAX' 103 | int_n_sign_posn dc i1'CHAR_MAX' 104 | 105 | period dc c'.',i1'0' 106 | emptystr dc i1'0' 107 | end 108 | -------------------------------------------------------------------------------- /locale.macros: -------------------------------------------------------------------------------- 1 | MACRO 2 | &lab csubroutine &parms,&work 3 | &lab anop 4 | aif c:&work,.a 5 | lclc &work 6 | &work setc 0 7 | .a 8 | gbla &totallen 9 | gbla &worklen 10 | &worklen seta &work 11 | &totallen seta 0 12 | aif c:&parms=0,.e 13 | lclc &len 14 | lclc &p 15 | lcla &i 16 | &i seta 1 17 | .b 18 | &p setc &parms(&i) 19 | &len amid &p,2,1 20 | aif "&len"=":",.c 21 | &len amid &p,1,2 22 | &p amid &p,4,l:&p-3 23 | ago .d 24 | .c 25 | &len amid &p,1,1 26 | &p amid &p,3,l:&p-2 27 | .d 28 | &p equ &totallen+4+&work 29 | &totallen seta &totallen+&len 30 | &i seta &i+1 31 | aif &i<=c:&parms,^b 32 | .e 33 | tsc 34 | aif &work=0,.f 35 | sec 36 | sbc #&work 37 | tcs 38 | .f 39 | phd 40 | tcd 41 | mend 42 | MACRO 43 | &lab creturn &r 44 | &lab anop 45 | lclc &len 46 | aif c:&r,.a 47 | lclc &r 48 | &r setc 0 49 | &len setc 0 50 | ago .h 51 | .a 52 | &len amid &r,2,1 53 | aif "&len"=":",.b 54 | &len amid &r,1,2 55 | &r amid &r,4,l:&r-3 56 | ago .c 57 | .b 58 | &len amid &r,1,1 59 | &r amid &r,3,l:&r-2 60 | .c 61 | aif &len<>2,.d 62 | ldy &r 63 | ago .h 64 | .d 65 | aif &len<>4,.e 66 | ldx &r+2 67 | ldy &r 68 | ago .h 69 | .e 70 | aif &len<>10,.g 71 | ldy #&r 72 | ldx #^&r 73 | ago .h 74 | .g 75 | mnote 'Not a valid return length',16 76 | mexit 77 | .h 78 | aif &totallen=0,.i 79 | lda &worklen+2 80 | sta &worklen+&totallen+2 81 | lda &worklen+1 82 | sta &worklen+&totallen+1 83 | .i 84 | pld 85 | tsc 86 | clc 87 | adc #&worklen+&totallen 88 | tcs 89 | aif &len=0,.j 90 | tya 91 | .j 92 | rtl 93 | mend 94 | -------------------------------------------------------------------------------- /m16.int64: -------------------------------------------------------------------------------- 1 | ; 2 | ; New and improved macros for operations on 64-bit integers 3 | ; 4 | 5 | ; Negate a 64-bit value (DP, absolute, or absolute long) 6 | macro 7 | &l negate8 &n1 8 | &l ~setm 9 | sec 10 | ldy #0 11 | tya 12 | sbc &n1 13 | sta &n1 14 | tya 15 | sbc &n1+2 16 | sta &n1+2 17 | tya 18 | sbc &n1+4 19 | sta &n1+4 20 | tya 21 | sbc &n1+6 22 | sta &n1+6 23 | ~restm 24 | mend 25 | 26 | 27 | ; Improved ph8 macro: 28 | ; - Generates more effecient code for constants 29 | ; - Supports "ph8 "{",.c 41 | &c amid &n1,l:&n1,1 42 | aif "&c"<>"}",.g 43 | &n1 amid &n1,2,l:&n1-2 44 | &n1 setc (&n1) 45 | .b 46 | ldy #6 47 | ~&SYSCNT lda &n1,y 48 | pha 49 | dey 50 | dey 51 | bpl ~&SYSCNT 52 | ago .e 53 | .c 54 | aif "&c"<>"<",.c1 55 | pei &n1+6 56 | pei &n1+4 57 | pei &n1+2 58 | pei &n1 59 | ago .e 60 | .c1 61 | ldx #6 62 | ~&SYSCNT lda &n1,x 63 | pha 64 | dex 65 | dex 66 | bpl ~&SYSCNT 67 | ago .e 68 | .d 69 | &n1 amid &n1,2,l:&n1-1 70 | pea +(&n1)|-48 71 | pea +(&n1)|-32 72 | pea +(&n1)|-16 73 | pea &n1 74 | .e 75 | aif s:longa=1,.f 76 | sep #%00100000 77 | .f 78 | mexit 79 | .g 80 | mnote "Missing closing '}'",16 81 | mend 82 | -------------------------------------------------------------------------------- /make: -------------------------------------------------------------------------------- 1 | unset exit 2 | unset cc >&/work 3 | unset cg >&/work 4 | 5 | if {#} == 0 6 | Newer obj/stdio.a stdio.asm equates.asm 7 | if {Status} != 0 8 | set exit on 9 | echo assemble +e +t stdio.asm 10 | assemble +e +t stdio.asm 11 | unset exit 12 | end 13 | 14 | Newer obj/assert.a assert.asm 15 | if {Status} != 0 16 | set exit on 17 | echo assemble +e +t assert.asm 18 | assemble +e +t assert.asm 19 | unset exit 20 | end 21 | 22 | for i in cc ctype string stdlib time setjmp orca fcntl vars toolglue signal int64 locale uchar 23 | Newer obj/{i}.a {i}.asm 24 | if {Status} != 0 25 | set exit on 26 | echo assemble +e +t {i}.asm 27 | assemble +e +t {i}.asm 28 | unset exit 29 | end 30 | end 31 | else 32 | set exit on 33 | for i 34 | assemble +e +t {i}.asm 35 | end 36 | end 37 | 38 | echo delete orcalib 39 | delete orcalib 40 | 41 | set list vars.a assert.a cc.a setjmp.a ctype.a string.a stdlib.a 42 | set list {list} time.a signal.a toolglue.a orca.a fcntl.a stdio.a int64.a 43 | set list {list} locale.a uchar.a 44 | for i in {list} 45 | echo makelib orcalib +obj/{i} 46 | makelib orcalib +obj/{i} 47 | end 48 | 49 | set echo on 50 | -------------------------------------------------------------------------------- /obj/README.txt: -------------------------------------------------------------------------------- 1 | This directory is used by the make file for storing object files. -------------------------------------------------------------------------------- /orca.asm: -------------------------------------------------------------------------------- 1 | keep obj/orca 2 | mcopy orca.macros 3 | case on 4 | 5 | **************************************************************** 6 | * 7 | * ORCA - ORCA/C specific libraries 8 | * 9 | * This code implements the tables and subroutines needed to 10 | * support the ORCA/C library ORCA. 11 | * 12 | * March 1989 13 | * Mike Westerfield 14 | * 15 | * Copyright 1989 16 | * Byte Works, Inc. 17 | * 18 | **************************************************************** 19 | * 20 | ORCA start dummy segment 21 | end 22 | 23 | **************************************************************** 24 | * 25 | * char *commandline(void) 26 | * 27 | * Inputs: 28 | * ~CommandLine - address of the command line 29 | * 30 | **************************************************************** 31 | * 32 | commandline start 33 | 34 | ldx #0 35 | lda ~COMMANDLINE 36 | ora ~COMMANDLINE+2 37 | beq lb1 38 | 39 | lda ~COMMANDLINE 40 | ldx ~COMMANDLINE+2 41 | clc 42 | adc #8 43 | bcc lb1 44 | inx 45 | lb1 rtl 46 | end 47 | 48 | **************************************************************** 49 | * 50 | * void enddesk(void) 51 | * 52 | **************************************************************** 53 | * 54 | enddesk start 55 | 56 | brl ~ENDDESK 57 | end 58 | 59 | **************************************************************** 60 | * 61 | * void endgraph(void) 62 | * 63 | **************************************************************** 64 | * 65 | endgraph start 66 | 67 | brl ~ENDGRAPH 68 | end 69 | 70 | **************************************************************** 71 | * 72 | * char *shellid(void) 73 | * 74 | * Inputs: 75 | * ~CommandLine - address of the command line 76 | * 77 | **************************************************************** 78 | * 79 | shellid start 80 | 81 | ldx #0 return NULL if there is no command line 82 | lda >~COMMANDLINE 83 | ora >~COMMANDLINE+2 84 | bne lb1 85 | rtl 86 | 87 | lb1 lda >~COMMANDLINE+2 88 | pha 89 | lda >~COMMANDLINE 90 | pha 91 | phd 92 | tsc 93 | tcd 94 | phb 95 | phk 96 | plb 97 | ldy #6 98 | lb2 lda [3],Y 99 | sta id,Y 100 | dey 101 | dey 102 | bpl lb2 103 | plb 104 | pld 105 | pla 106 | pla 107 | lda #id 108 | ldx #^id 109 | rtl 110 | 111 | id dc 8c' ',i1'0' 112 | end 113 | 114 | **************************************************************** 115 | * 116 | * void startdesk(int width) 117 | * 118 | **************************************************************** 119 | * 120 | startdesk start 121 | 122 | brl ~STARTDESK 123 | end 124 | 125 | **************************************************************** 126 | * 127 | * void startgraph(int width) 128 | * 129 | **************************************************************** 130 | * 131 | startgraph start 132 | 133 | brl ~STARTGRAPH 134 | end 135 | 136 | **************************************************************** 137 | * 138 | * int toolerror(void) 139 | * 140 | **************************************************************** 141 | * 142 | toolerror start 143 | 144 | lda >~TOOLERROR 145 | rtl 146 | end 147 | 148 | **************************************************************** 149 | * 150 | * int userid(void) 151 | * 152 | **************************************************************** 153 | * 154 | userid start 155 | 156 | lda >~USER_ID 157 | rtl 158 | end 159 | -------------------------------------------------------------------------------- /orca.macros: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/byteworksinc/ORCALib/5b04986f082a413e91bd8b69a6a73d4c333a9d11/orca.macros -------------------------------------------------------------------------------- /setjmp.asm: -------------------------------------------------------------------------------- 1 | keep obj/setjmp 2 | case on 3 | 4 | **************************************************************** 5 | * 6 | * SetJmp - Set jump library 7 | * 8 | * This code implements the subroutines needed to support the 9 | * standard C library SETJMP. 10 | * 11 | * January 1989 12 | * Mike Westerfield 13 | * 14 | * Copyright 1989 15 | * Byte Works, Inc. 16 | * 17 | **************************************************************** 18 | * 19 | SetJmp start dummy segment 20 | 21 | end 22 | 23 | **************************************************************** 24 | * 25 | * int setjmp(env) 26 | * jmp_buf env; 27 | * 28 | * Inputs: 29 | * env - pointer to the environment array 30 | * 31 | * Outputs: 32 | * Returns 0. 33 | * 34 | **************************************************************** 35 | * 36 | setjmp start 37 | env equ 4 pointer to array 38 | ret equ 1 return address 39 | 40 | tsc set up addressing 41 | phd 42 | tcd 43 | clc save the correct stack pointer 44 | adc #4 45 | sta [env] 46 | ldy #2 save D 47 | lda 1,S 48 | sta [env],Y 49 | ldy #4 save the return address 50 | lda ret-1 51 | sta [env],Y 52 | iny 53 | iny 54 | lda ret+1 55 | sta [env],Y 56 | pld repair the stack 57 | phb 58 | plx 59 | ply 60 | pla 61 | pla 62 | phy 63 | phx 64 | plb 65 | lda #0 return 0 66 | rtl 67 | end 68 | 69 | **************************************************************** 70 | * 71 | * void longjmp(env,status) 72 | * jmp_buf env; 73 | * int status; 74 | * 75 | * Inputs: 76 | * env - pointer to the environment array 77 | * status - status to return 78 | * 79 | **************************************************************** 80 | * 81 | longjmp start 82 | env equ 4 environment pointer 83 | status equ 8 status to return 84 | 85 | tsc set up the local stack frame 86 | tcd 87 | phb 88 | phk 89 | plb 90 | ldx status get the status 91 | bne lb1 92 | inx 93 | lb1 ldy #6 get the env record 94 | lb2 lda [env],Y 95 | sta lenv,Y 96 | dey 97 | dey 98 | bpl lb2 99 | plb 100 | lda >stackPtr reset the stack pointer 101 | tcs 102 | lda >ret+2 reset the return address 103 | sta 2,S 104 | lda >ret 105 | sta 0,S 106 | lda >dp reset the dp 107 | tcd 108 | txa return the status 109 | rtl 110 | 111 | lenv anop local copy of *env 112 | stackPtr ds 2 113 | dp ds 2 114 | ret ds 4 115 | end 116 | -------------------------------------------------------------------------------- /settypes: -------------------------------------------------------------------------------- 1 | filetype -p =.asm src; change -p =.asm asm65816 2 | filetype -p =.macros src; change -p =.macros asm65816 3 | filetype m16.int64 src; change m16.int64 exec 4 | filetype smac src; change smac asm65816 5 | filetype backup src; change backup exec 6 | filetype make src; change make exec 7 | filetype settypes src; change settypes exec 8 | filetype LICENSE txt 9 | filetype README.md txt 10 | filetype obj:README.txt txt 11 | -------------------------------------------------------------------------------- /signal.asm: -------------------------------------------------------------------------------- 1 | keep obj/signal 2 | mcopy signal.macros 3 | case on 4 | 5 | **************************************************************** 6 | * 7 | * signal - Asynchronous event signal handler 8 | * 9 | * April 1990 10 | * Mike Westerfield 11 | * 12 | * Copyright 1990 13 | * Byte Works, Inc. 14 | * 15 | **************************************************************** 16 | * 17 | SIGNAL start dummy segment 18 | copy equates.asm 19 | SIG_DFL gequ -3 20 | SIG_IGN gequ -2 21 | SIG_ERR gequ -1 22 | 23 | SIGMAX gequ 6 maximum number of signals 24 | end 25 | 26 | **************************************************************** 27 | * 28 | * void (*signal(int sig, void (*func) (int)))(int); 29 | * 30 | * Set the interrupt handler 31 | * 32 | * Inputs: 33 | * sig - signal number 34 | * func - signal handler 35 | * 36 | * Returns: 37 | * Pointer to the last signal handler; SIG_ERR if sig 38 | * is out of range. 39 | * 40 | **************************************************************** 41 | * 42 | signal start 43 | using signalCommon 44 | ptr equ 1 old signal handler 45 | 46 | csubroutine (2:sig,4:func),4 47 | 48 | lla ptr,SIG_ERR assume we will find an error 49 | lda sig if (!sig in [1..6]) 50 | beq lb1 51 | cmp #SIGMAX+1 52 | blt lb2 53 | lb1 lda #ERANGE errno = ERANGE 54 | sta >errno 55 | bra lb3 56 | 57 | lb2 asl A get the old signal handler address 58 | asl A 59 | tax 60 | lda >subABRT-4,X 61 | sta ptr 62 | lda >subABRT-2,X 63 | sta ptr+2 64 | lda func set the new signal handler address 65 | sta >subABRT-4,X 66 | lda func+2 67 | sta >subABRT-2,X 68 | 69 | lb3 creturn 4:ptr 70 | end 71 | 72 | **************************************************************** 73 | * 74 | * int raise(int sig); 75 | * 76 | * Raise a signal. 77 | * 78 | * Inputs: 79 | * sig - signal number 80 | * 81 | * Returns: 82 | * 0 if successful, -1 if sig is out of range 83 | * 84 | **************************************************************** 85 | * 86 | raise start 87 | using signalCommon 88 | val equ 1 value to return 89 | 90 | csubroutine (2:sig),2 91 | 92 | stz val no error 93 | lda sig if (!sig in [1..6]) 94 | beq lb1 95 | cmp #SIGMAX+1 96 | blt lb2 97 | lb1 lda #-1 val = -1 98 | sta val 99 | lda #ERANGE errno = ERANGE 100 | sta >errno 101 | bra lb3 102 | 103 | lb2 asl A get the signal handler address 104 | asl A 105 | tax 106 | lda >subABRT-4,X 107 | tay 108 | lda >subABRT-2,X 109 | bmi lb3 skip if it is SIG_DFL or SIG_IGN 110 | xba set up the call address 111 | sta >jsl+2 112 | tya 113 | sta >jsl+1 114 | ph2 "{",.b 12 | &c amid &n1,l:&n1,1 13 | aif "&c"<>"}",.g 14 | &n1 amid &n1,2,l:&n1-2 15 | lda (&n1) 16 | pha 17 | ago .e 18 | .b 19 | aif "&c"="<",.c 20 | lda &n1 21 | pha 22 | ago .e 23 | .c 24 | &n1 amid &n1,2,l:&n1-1 25 | pei &n1 26 | ago .e 27 | .d 28 | &n1 amid &n1,2,l:&n1-1 29 | pea &n1 30 | ago .f 31 | .e 32 | aif s:longa=1,.f 33 | sep #%00100000 34 | .f 35 | mexit 36 | .g 37 | mnote "Missing closing '}'",16 38 | mend 39 | MACRO 40 | &lab csubroutine &parms,&work 41 | &lab anop 42 | aif c:&work,.a 43 | lclc &work 44 | &work setc 0 45 | .a 46 | gbla &totallen 47 | gbla &worklen 48 | &worklen seta &work 49 | &totallen seta 0 50 | aif c:&parms=0,.e 51 | lclc &len 52 | lclc &p 53 | lcla &i 54 | &i seta 1 55 | .b 56 | &p setc &parms(&i) 57 | &len amid &p,2,1 58 | aif "&len"=":",.c 59 | &len amid &p,1,2 60 | &p amid &p,4,l:&p-3 61 | ago .d 62 | .c 63 | &len amid &p,1,1 64 | &p amid &p,3,l:&p-2 65 | .d 66 | &p equ &totallen+4+&work 67 | &totallen seta &totallen+&len 68 | &i seta &i+1 69 | aif &i<=c:&parms,^b 70 | .e 71 | tsc 72 | aif &work=0,.f 73 | sec 74 | sbc #&work 75 | tcs 76 | .f 77 | phd 78 | tcd 79 | mend 80 | MACRO 81 | &lab creturn &r 82 | &lab anop 83 | lclc &len 84 | aif c:&r,.a 85 | lclc &r 86 | &r setc 0 87 | &len setc 0 88 | ago .h 89 | .a 90 | &len amid &r,2,1 91 | aif "&len"=":",.b 92 | &len amid &r,1,2 93 | &r amid &r,4,l:&r-3 94 | ago .c 95 | .b 96 | &len amid &r,1,1 97 | &r amid &r,3,l:&r-2 98 | .c 99 | aif &len<>2,.d 100 | ldy &r 101 | ago .h 102 | .d 103 | aif &len<>4,.e 104 | ldx &r+2 105 | ldy &r 106 | ago .h 107 | .e 108 | aif &len<>10,.g 109 | ldy #&r 110 | ldx #^&r 111 | ago .h 112 | .g 113 | mnote 'Not a valid return length',16 114 | mexit 115 | .h 116 | aif &totallen=0,.i 117 | lda &worklen+2 118 | sta &worklen+&totallen+2 119 | lda &worklen+1 120 | sta &worklen+&totallen+1 121 | .i 122 | pld 123 | tsc 124 | clc 125 | adc #&worklen+&totallen 126 | tcs 127 | aif &len=0,.j 128 | tya 129 | .j 130 | rtl 131 | mend 132 | MACRO 133 | &LAB LLA &AD1,&AD2 134 | &LAB ANOP 135 | LCLA &L 136 | LCLB &LA 137 | AIF S:LONGA,.A 138 | REP #%00100000 139 | LONGA ON 140 | &LA SETB 1 141 | .A 142 | LDA #&AD2 143 | &L SETA C:&AD1 144 | .B 145 | STA &AD1(&L) 146 | &L SETA &L-1 147 | AIF &L,^B 148 | LDA #^&AD2 149 | &L SETA C:&AD1 150 | .C 151 | STA 2+&AD1(&L) 152 | &L SETA &L-1 153 | AIF &L,^C 154 | AIF &LA=0,.D 155 | SEP #%00100000 156 | LONGA OFF 157 | .D 158 | MEND 159 | MACRO 160 | &LAB LONG &A,&B 161 | LCLB &I 162 | LCLB &M 163 | &A AMID &A,1,1 164 | &M SETB ("&A"="M").OR.("&A"="m") 165 | &I SETB ("&A"="I").OR.("&A"="i") 166 | AIF C:&B=0,.A 167 | &B AMID &B,1,1 168 | &M SETB ("&B"="M").OR.("&B"="m").OR.&M 169 | &I SETB ("&B"="I").OR.("&B"="i").OR.&I 170 | .A 171 | &LAB REP #&M*32+&I*16 172 | AIF .NOT.&M,.B 173 | LONGA ON 174 | .B 175 | AIF .NOT.&I,.C 176 | LONGI ON 177 | .C 178 | MEND 179 | MACRO 180 | &LAB SHORT &A,&B 181 | LCLB &I 182 | LCLB &M 183 | &A AMID &A,1,1 184 | &M SETB ("&A"="M").OR.("&A"="m") 185 | &I SETB ("&A"="I").OR.("&A"="i") 186 | AIF C:&B=0,.A 187 | &B AMID &B,1,1 188 | &M SETB ("&B"="M").OR.("&B"="m").OR.&M 189 | &I SETB ("&B"="I").OR.("&B"="i").OR.&I 190 | .A 191 | &LAB SEP #&M*32+&I*16 192 | AIF .NOT.&M,.B 193 | LONGA OFF 194 | .B 195 | AIF .NOT.&I,.C 196 | LONGI OFF 197 | .C 198 | MEND 199 | -------------------------------------------------------------------------------- /smac: -------------------------------------------------------------------------------- 1 | macro 2 | &lab cstr &s 3 | &lab dc c"&s",i1'0' 4 | mend 5 | 6 | MACRO 7 | &LAB MOVE4 &F,&T 8 | &LAB ~SETM 9 | LDA 2+&F 10 | STA 2+&T 11 | LDA &F 12 | STA &T 13 | ~RESTM 14 | MEND 15 | 16 | macro 17 | &lab csubroutine &parms,&work 18 | &lab anop 19 | aif c:&work,.a 20 | lclc &work 21 | &work setc 0 22 | .a 23 | gbla &totallen 24 | gbla &worklen 25 | &worklen seta &work 26 | &totallen seta 0 27 | aif c:&parms=0,.e 28 | lclc &len 29 | lclc &p 30 | lcla &i 31 | &i seta 1 32 | .b 33 | &p setc &parms(&i) 34 | &len amid &p,2,1 35 | aif "&len"=":",.c 36 | &len amid &p,1,2 37 | &p amid &p,4,l:&p-3 38 | ago .d 39 | .c 40 | &len amid &p,1,1 41 | &p amid &p,3,l:&p-2 42 | .d 43 | &p equ &totallen+4+&work 44 | &totallen seta &totallen+&len 45 | &i seta &i+1 46 | aif &i<=c:&parms,^b 47 | .e 48 | tsc 49 | aif &work=0,.f 50 | sec 51 | sbc #&work 52 | tcs 53 | .f 54 | phd 55 | tcd 56 | mend 57 | 58 | 59 | macro 60 | &lab creturn &r 61 | &lab anop 62 | lclc &len 63 | aif c:&r,.a 64 | lclc &r 65 | &r setc 0 66 | &len setc 0 67 | ago .h 68 | .a 69 | &len amid &r,2,1 70 | aif "&len"=":",.b 71 | &len amid &r,1,2 72 | &r amid &r,4,l:&r-3 73 | ago .c 74 | .b 75 | &len amid &r,1,1 76 | &r amid &r,3,l:&r-2 77 | .c 78 | aif &len<>2,.d 79 | ldy &r 80 | ago .h 81 | .d 82 | aif &len<>4,.e 83 | ldx &r+2 84 | ldy &r 85 | ago .h 86 | .e 87 | aif &len<>10,.g 88 | ldy #&r 89 | ldx #^&r 90 | ago .h 91 | .g 92 | mnote 'Not a valid return length',16 93 | mexit 94 | .h 95 | aif &totallen=0,.i 96 | lda &worklen+2 97 | sta &worklen+&totallen+2 98 | lda &worklen+1 99 | sta &worklen+&totallen+1 100 | .i 101 | pld 102 | tsc 103 | clc 104 | adc #&worklen+&totallen 105 | tcs 106 | aif &len=0,.j 107 | tya 108 | .j 109 | rtl 110 | mend 111 | -------------------------------------------------------------------------------- /stdio.macros: -------------------------------------------------------------------------------- 1 | macro 2 | &l ph2 &n1 3 | &l anop 4 | aif "&n1"="*",.f 5 | lclc &c 6 | &c amid &n1,1,1 7 | aif "&c"="#",.d 8 | aif s:longa=1,.a 9 | rep #%00100000 10 | .a 11 | aif "&c"<>"{",.b 12 | &c amid &n1,l:&n1,1 13 | aif "&c"<>"}",.g 14 | &n1 amid &n1,2,l:&n1-2 15 | lda (&n1) 16 | pha 17 | ago .e 18 | .b 19 | aif "&c"="<",.c 20 | lda &n1 21 | pha 22 | ago .e 23 | .c 24 | &n1 amid &n1,2,l:&n1-1 25 | pei &n1 26 | ago .e 27 | .d 28 | &n1 amid &n1,2,l:&n1-1 29 | pea &n1 30 | ago .f 31 | .e 32 | aif s:longa=1,.f 33 | sep #%00100000 34 | .f 35 | mexit 36 | .g 37 | mnote "Missing closing '}'",16 38 | mend 39 | macro 40 | &l ph4 &n1 41 | &l anop 42 | aif "&n1"="*",.f 43 | lclc &c 44 | &c amid &n1,1,1 45 | aif "&c"="#",.d 46 | aif s:longa=1,.a 47 | rep #%00100000 48 | .a 49 | aif "&c"<>"{",.b 50 | &c amid &n1,l:&n1,1 51 | aif "&c"<>"}",.g 52 | &n1 amid &n1,2,l:&n1-2 53 | ldy #2 54 | lda (&n1),y 55 | pha 56 | lda (&n1) 57 | pha 58 | ago .e 59 | .b 60 | aif "&c"<>"[",.c 61 | ldy #2 62 | lda &n1,y 63 | pha 64 | lda &n1 65 | pha 66 | ago .e 67 | .c 68 | aif "&c"<>"<",.c1 69 | &n1 amid &n1,2,l:&n1-1 70 | pei &n1+2 71 | pei &n1 72 | ago .e 73 | .c1 74 | lda &n1+2 75 | pha 76 | lda &n1 77 | pha 78 | ago .e 79 | .d 80 | &n1 amid &n1,2,l:&n1-1 81 | pea +(&n1)|-16 82 | pea &n1 83 | ago .f 84 | .e 85 | aif s:longa=1,.f 86 | sep #%00100000 87 | .f 88 | mexit 89 | .g 90 | mnote "Missing closing '}'",16 91 | mend 92 | macro 93 | &l negate8 &n1 94 | &l ~setm 95 | sec 96 | ldy #0 97 | tya 98 | sbc &n1 99 | sta &n1 100 | tya 101 | sbc &n1+2 102 | sta &n1+2 103 | tya 104 | sbc &n1+4 105 | sta &n1+4 106 | tya 107 | sbc &n1+6 108 | sta &n1+6 109 | ~restm 110 | mend 111 | macro 112 | &l ph8 &n1 113 | lclc &c 114 | &l anop 115 | &c amid &n1,1,1 116 | aif s:longa=1,.a 117 | rep #%00100000 118 | .a 119 | aif "&c"="#",.d 120 | aif "&c"="[",.b 121 | aif "&c"<>"{",.c 122 | &c amid &n1,l:&n1,1 123 | aif "&c"<>"}",.g 124 | &n1 amid &n1,2,l:&n1-2 125 | &n1 setc (&n1) 126 | .b 127 | ldy #6 128 | ~&SYSCNT lda &n1,y 129 | pha 130 | dey 131 | dey 132 | bpl ~&SYSCNT 133 | ago .e 134 | .c 135 | aif "&c"<>"<",.c1 136 | pei &n1+6 137 | pei &n1+4 138 | pei &n1+2 139 | pei &n1 140 | ago .e 141 | .c1 142 | ldx #6 143 | ~&SYSCNT lda &n1,x 144 | pha 145 | dex 146 | dex 147 | bpl ~&SYSCNT 148 | ago .e 149 | .d 150 | &n1 amid &n1,2,l:&n1-1 151 | pea +(&n1)|-48 152 | pea +(&n1)|-32 153 | pea +(&n1)|-16 154 | pea &n1 155 | .e 156 | aif s:longa=1,.f 157 | sep #%00100000 158 | .f 159 | mexit 160 | .g 161 | mnote "Missing closing '}'",16 162 | mend 163 | MACRO 164 | &lab cstr &s 165 | &lab dc c"&s",i1'0' 166 | mend 167 | MACRO 168 | &LAB MOVE4 &F,&T 169 | &LAB ~SETM 170 | LDA 2+&F 171 | STA 2+&T 172 | LDA &F 173 | STA &T 174 | ~RESTM 175 | MEND 176 | MACRO 177 | &lab csubroutine &parms,&work 178 | &lab anop 179 | aif c:&work,.a 180 | lclc &work 181 | &work setc 0 182 | .a 183 | gbla &totallen 184 | gbla &worklen 185 | &worklen seta &work 186 | &totallen seta 0 187 | aif c:&parms=0,.e 188 | lclc &len 189 | lclc &p 190 | lcla &i 191 | &i seta 1 192 | .b 193 | &p setc &parms(&i) 194 | &len amid &p,2,1 195 | aif "&len"=":",.c 196 | &len amid &p,1,2 197 | &p amid &p,4,l:&p-3 198 | ago .d 199 | .c 200 | &len amid &p,1,1 201 | &p amid &p,3,l:&p-2 202 | .d 203 | &p equ &totallen+4+&work 204 | &totallen seta &totallen+&len 205 | &i seta &i+1 206 | aif &i<=c:&parms,^b 207 | .e 208 | tsc 209 | aif &work=0,.f 210 | sec 211 | sbc #&work 212 | tcs 213 | .f 214 | phd 215 | tcd 216 | mend 217 | MACRO 218 | &lab creturn &r 219 | &lab anop 220 | lclc &len 221 | aif c:&r,.a 222 | lclc &r 223 | &r setc 0 224 | &len setc 0 225 | ago .h 226 | .a 227 | &len amid &r,2,1 228 | aif "&len"=":",.b 229 | &len amid &r,1,2 230 | &r amid &r,4,l:&r-3 231 | ago .c 232 | .b 233 | &len amid &r,1,1 234 | &r amid &r,3,l:&r-2 235 | .c 236 | aif &len<>2,.d 237 | ldy &r 238 | ago .h 239 | .d 240 | aif &len<>4,.e 241 | ldx &r+2 242 | ldy &r 243 | ago .h 244 | .e 245 | aif &len<>10,.g 246 | ldy #&r 247 | ldx #^&r 248 | ago .h 249 | .g 250 | mnote 'Not a valid return length',16 251 | mexit 252 | .h 253 | aif &totallen=0,.i 254 | lda &worklen+2 255 | sta &worklen+&totallen+2 256 | lda &worklen+1 257 | sta &worklen+&totallen+1 258 | .i 259 | pld 260 | tsc 261 | clc 262 | adc #&worklen+&totallen 263 | tcs 264 | aif &len=0,.j 265 | tya 266 | .j 267 | rtl 268 | mend 269 | MACRO 270 | &LAB ~SETM 271 | &LAB ANOP 272 | AIF C:&~LA,.B 273 | GBLB &~LA 274 | GBLB &~LI 275 | .B 276 | &~LA SETB S:LONGA 277 | &~LI SETB S:LONGI 278 | AIF S:LONGA.AND.S:LONGI,.A 279 | REP #32*(.NOT.&~LA)+16*(.NOT.&~LI) 280 | LONGA ON 281 | LONGI ON 282 | .A 283 | MEND 284 | MACRO 285 | &LAB ~RESTM 286 | &LAB ANOP 287 | AIF (&~LA+&~LI)=2,.I 288 | SEP #32*(.NOT.&~LA)+16*(.NOT.&~LI) 289 | AIF &~LA,.H 290 | LONGA OFF 291 | .H 292 | AIF &~LI,.I 293 | LONGI OFF 294 | .I 295 | MEND 296 | MACRO 297 | &LAB SUB2 &N1,&N2,&N3 298 | AIF C:&N3,.A 299 | LCLC &N3 300 | &N3 SETC &N1 301 | .A 302 | &LAB ~SETM 303 | SEC 304 | ~LDA &N1 305 | ~OP SBC,&N2 306 | ~STA &N3 307 | ~RESTM 308 | MEND 309 | MACRO 310 | &LAB ~LDA &OP 311 | LCLC &C 312 | &C AMID "&OP",1,1 313 | AIF "&C"<>"{",.B 314 | &C AMID "&OP",L:&OP,1 315 | AIF "&C"="}",.A 316 | MNOTE "Missing closing '}'",2 317 | &OP SETC &OP} 318 | .A 319 | &OP AMID "&OP",2,L:&OP-2 320 | &OP SETC (&OP) 321 | .B 322 | &LAB LDA &OP 323 | MEND 324 | MACRO 325 | &LAB ~STA &OP 326 | LCLC &C 327 | &C AMID "&OP",1,1 328 | AIF "&C"<>"{",.B 329 | &C AMID "&OP",L:&OP,1 330 | AIF "&C"="}",.A 331 | MNOTE "Missing closing '}'",2 332 | &OP SETC &OP} 333 | .A 334 | &OP AMID "&OP",2,L:&OP-2 335 | &OP SETC (&OP) 336 | .B 337 | &LAB STA &OP 338 | MEND 339 | MACRO 340 | &LAB ~OP &OPC,&OP 341 | LCLC &C 342 | &C AMID "&OP",1,1 343 | AIF "&C"<>"{",.B 344 | &C AMID "&OP",L:&OP,1 345 | AIF "&C"="}",.A 346 | MNOTE "Missing closing '}'",2 347 | &OP SETC &OP} 348 | .A 349 | &OP AMID "&OP",2,L:&OP-2 350 | &OP SETC (&OP) 351 | .B 352 | &LAB &OPC &OP 353 | MEND 354 | MACRO 355 | &LAB ADD4 &M1,&M2,&M3 356 | LCLB &YISTWO 357 | LCLC &C 358 | &LAB ~SETM 359 | AIF C:&M3,.A 360 | &C AMID "&M2",1,1 361 | AIF "&C"<>"#",.A 362 | &C AMID "&M1",1,1 363 | AIF "&C"="{",.A 364 | AIF "&C"="[",.A 365 | &C AMID "&M2",2,L:&M2-1 366 | AIF &C>=65536,.A 367 | CLC 368 | ~LDA &M1 369 | ~OP ADC,&M2 370 | ~STA &M1 371 | BCC ~&SYSCNT 372 | ~OP.H INC,&M1 373 | ~&SYSCNT ANOP 374 | AGO .C 375 | .A 376 | AIF C:&M3,.B 377 | LCLC &M3 378 | &M3 SETC &M1 379 | .B 380 | CLC 381 | ~LDA &M1 382 | ~OP ADC,&M2 383 | ~STA &M3 384 | ~LDA.H &M1 385 | ~OP.H ADC,&M2 386 | ~STA.H &M3 387 | .C 388 | ~RESTM 389 | MEND 390 | MACRO 391 | &LAB DIV4 &N1,&N2,&N3 392 | &LAB ~SETM 393 | PH4 &N1 394 | PH4 &N2 395 | JSL ~DIV4 396 | AIF C:&N3,.A 397 | PL4 &N1 398 | AGO .B 399 | .A 400 | PL4 &N3 401 | .B 402 | PLA 403 | PLA 404 | ~RESTM 405 | MEND 406 | MACRO 407 | &LAB MUL4 &N1,&N2,&N3 408 | &LAB ~SETM 409 | PH4 &N1 410 | PH4 &N2 411 | JSL ~MUL4 412 | AIF C:&N3,.A 413 | PL4 &N1 414 | AGO .B 415 | .A 416 | PL4 &N3 417 | .B 418 | ~RESTM 419 | MEND 420 | MACRO 421 | &LAB ~OP.H &OPC,&OP 422 | &LAB ANOP 423 | LCLC &C 424 | &C AMID "&OP",1,1 425 | AIF "&C"="[",.B 426 | AIF "&C"<>"{",.D 427 | &C AMID "&OP",L:&OP,1 428 | AIF "&C"="}",.A 429 | MNOTE "Missing closing '}'",2 430 | &OP SETC &OP} 431 | .A 432 | &OP AMID "&OP",2,L:&OP-2 433 | &OP SETC (&OP) 434 | .B 435 | AIF &YISTWO,.C 436 | &YISTWO SETB 1 437 | LDY #2 438 | &OP SETC "&OP,Y" 439 | .C 440 | &OPC &OP 441 | MEXIT 442 | .D 443 | AIF "&C"<>"#",.E 444 | &OP AMID "&OP",2,L:&OP-1 445 | &OP SETC "#^&OP" 446 | &OPC &OP 447 | MEXIT 448 | .E 449 | &OPC 2+&OP 450 | MEND 451 | MACRO 452 | &LAB ~LDA.H &OP 453 | &LAB ANOP 454 | LCLC &C 455 | &C AMID "&OP",1,1 456 | AIF "&C"="[",.B 457 | AIF "&C"<>"{",.D 458 | &C AMID "&OP",L:&OP,1 459 | AIF "&C"="}",.A 460 | MNOTE "Missing closing '}'",2 461 | &OP SETC &OP} 462 | .A 463 | &OP AMID "&OP",2,L:&OP-2 464 | &OP SETC (&OP) 465 | .B 466 | AIF &YISTWO,.C 467 | &YISTWO SETB 1 468 | LDY #2 469 | &OP SETC "&OP,Y" 470 | .C 471 | LDA &OP 472 | MEXIT 473 | .D 474 | AIF "&C"<>"#",.E 475 | &OP AMID "&OP",2,L:&OP-1 476 | &OP SETC "#^&OP" 477 | LDA &OP 478 | MEXIT 479 | .E 480 | LDA 2+&OP 481 | MEND 482 | MACRO 483 | &LAB ~STA.H &OP 484 | &LAB ANOP 485 | LCLC &C 486 | &C AMID "&OP",1,1 487 | AIF "&C"="[",.B 488 | AIF "&C"<>"{",.D 489 | &C AMID "&OP",L:&OP,1 490 | AIF "&C"="}",.A 491 | MNOTE "Missing closing '}'",2 492 | &OP SETC &OP} 493 | .A 494 | &OP AMID "&OP",2,L:&OP-2 495 | &OP SETC (&OP) 496 | .B 497 | AIF &YISTWO,.C 498 | &YISTWO SETB 1 499 | LDY #2 500 | &OP SETC "&OP,Y" 501 | .C 502 | STA &OP 503 | MEXIT 504 | .D 505 | STA 2+&OP 506 | MEND 507 | MACRO 508 | &LAB BLE &BP 509 | &LAB BLT &BP 510 | BEQ &BP 511 | MEND 512 | MACRO 513 | &LAB DEC4 &A 514 | &LAB ~SETM 515 | LDA &A 516 | BNE ~&SYSCNT 517 | DEC 2+&A 518 | ~&SYSCNT DEC &A 519 | ~RESTM 520 | MEND 521 | MACRO 522 | &LAB INC4 &A 523 | &LAB ~SETM 524 | INC &A 525 | BNE ~&SYSCNT 526 | INC 2+&A 527 | ~&SYSCNT ~RESTM 528 | MEND 529 | MACRO 530 | &LAB JCS &BP 531 | &LAB BCC *+5 532 | BRL &BP 533 | MEND 534 | MACRO 535 | &LAB JEQ &BP 536 | &LAB BNE *+5 537 | BRL &BP 538 | MEND 539 | MACRO 540 | &LAB JNE &BP 541 | &LAB BEQ *+5 542 | BRL &BP 543 | MEND 544 | MACRO 545 | &LAB LLA &AD1,&AD2 546 | &LAB ANOP 547 | LCLA &L 548 | LCLB &LA 549 | AIF S:LONGA,.A 550 | REP #%00100000 551 | LONGA ON 552 | &LA SETB 1 553 | .A 554 | LDA #&AD2 555 | &L SETA C:&AD1 556 | .B 557 | STA &AD1(&L) 558 | &L SETA &L-1 559 | AIF &L,^B 560 | LDA #^&AD2 561 | &L SETA C:&AD1 562 | .C 563 | STA 2+&AD1(&L) 564 | &L SETA &L-1 565 | AIF &L,^C 566 | AIF &LA=0,.D 567 | SEP #%00100000 568 | LONGA OFF 569 | .D 570 | MEND 571 | MACRO 572 | &LAB LONG &A,&B 573 | LCLB &I 574 | LCLB &M 575 | &A AMID &A,1,1 576 | &M SETB ("&A"="M").OR.("&A"="m") 577 | &I SETB ("&A"="I").OR.("&A"="i") 578 | AIF C:&B=0,.A 579 | &B AMID &B,1,1 580 | &M SETB ("&B"="M").OR.("&B"="m").OR.&M 581 | &I SETB ("&B"="I").OR.("&B"="i").OR.&I 582 | .A 583 | &LAB REP #&M*32+&I*16 584 | AIF .NOT.&M,.B 585 | LONGA ON 586 | .B 587 | AIF .NOT.&I,.C 588 | LONGI ON 589 | .C 590 | MEND 591 | MACRO 592 | &LAB MOVE &AD1,&AD2,&LEN 593 | &LAB ANOP 594 | LCLB &LA 595 | LCLB &LI 596 | LCLC &C 597 | AIF C:&LEN,.A1 598 | LCLC &LEN 599 | &LEN SETC #2 600 | .A1 601 | &LA SETB S:LONGA 602 | &LI SETB S:LONGI 603 | AIF S:LONGA.AND.S:LONGI,.A 604 | REP #32*(.NOT.&LA)+16*(.NOT.&LI) 605 | LONGA ON 606 | LONGI ON 607 | .A 608 | &C AMID &LEN,1,1 609 | AIF "&C"<>"#",.D 610 | &C AMID &LEN,2,L:&LEN-1 611 | AIF &C<>2,.D 612 | &C AMID &AD1,1,1 613 | AIF "&C"<>"{",.B 614 | &AD1 AMID &AD1,2,L:&AD1-2 615 | &AD1 SETC (&AD1) 616 | .B 617 | LDA &AD1 618 | &C AMID &AD2,1,1 619 | AIF "&C"<>"{",.C 620 | &AD2 AMID &AD2,2,L:&AD2-2 621 | &AD2 SETC (&AD2) 622 | .C 623 | STA &AD2 624 | AGO .G 625 | .D 626 | &C AMID &AD1,1,1 627 | AIF "&C"="#",.F 628 | &C AMID &LEN,1,1 629 | AIF "&C"<>"{",.E 630 | &LEN AMID &LEN,2,L:&LEN-2 631 | &LEN SETC (&LEN) 632 | .E 633 | &C AMID &LEN,1,1 634 | AIF "&C"="#",.E1 635 | LDA &LEN 636 | DEC A 637 | AGO .E2 638 | .E1 639 | LDA &LEN-1 640 | .E2 641 | LDX #&AD1 642 | LDY #&AD2 643 | MVN &AD1,&AD2 644 | AGO .G 645 | .F 646 | LDA &AD1 647 | STA &AD2 648 | LDA &LEN-1 649 | LDX #&AD2 650 | LDY #&AD2+1 651 | MVN &AD2,&AD2 652 | .G 653 | AIF (&LA+&LI)=2,.I 654 | SEP #32*(.NOT.&LA)+16*(.NOT.&LI) 655 | AIF &LA,.H 656 | LONGA OFF 657 | .H 658 | AIF &LI,.I 659 | LONGI OFF 660 | .I 661 | MEND 662 | MACRO 663 | &LAB PL4 &N1 664 | LCLC &C 665 | &LAB ANOP 666 | AIF S:LONGA=1,.A 667 | REP #%00100000 668 | .A 669 | &C AMID &N1,1,1 670 | AIF "&C"<>"{",.B 671 | &C AMID &N1,L:&N1,1 672 | AIF "&C"<>"}",.F 673 | &N1 AMID &N1,2,L:&N1-2 674 | PLA 675 | STA (&N1) 676 | LDY #2 677 | PLA 678 | STA (&N1),Y 679 | AGO .D 680 | .B 681 | AIF "&C"<>"[",.C 682 | PLA 683 | STA &N1 684 | LDY #2 685 | PLA 686 | STA &N1,Y 687 | AGO .D 688 | .C 689 | PLA 690 | STA &N1 691 | PLA 692 | STA &N1+2 693 | .D 694 | AIF S:LONGA=1,.E 695 | SEP #%00100000 696 | .E 697 | MEXIT 698 | .F 699 | MNOTE "Missing closing '}'",16 700 | MEND 701 | MACRO 702 | &LAB SHORT &A,&B 703 | LCLB &I 704 | LCLB &M 705 | &A AMID &A,1,1 706 | &M SETB ("&A"="M").OR.("&A"="m") 707 | &I SETB ("&A"="I").OR.("&A"="i") 708 | AIF C:&B=0,.A 709 | &B AMID &B,1,1 710 | &M SETB ("&B"="M").OR.("&B"="m").OR.&M 711 | &I SETB ("&B"="I").OR.("&B"="i").OR.&I 712 | .A 713 | &LAB SEP #&M*32+&I*16 714 | AIF .NOT.&M,.B 715 | LONGA OFF 716 | .B 717 | AIF .NOT.&I,.C 718 | LONGI OFF 719 | .C 720 | MEND 721 | MACRO 722 | &LAB OSCREATE &DCB 723 | &LAB JSL $E100A8 724 | DC I2'$2001' 725 | DC I4'&DCB' 726 | MEND 727 | MACRO 728 | &LAB OSDESTROY &DCB 729 | &LAB JSL $E100A8 730 | DC I2'$2002' 731 | DC I4'&DCB' 732 | MEND 733 | MACRO 734 | &LAB OSCHANGE_PATH &DCB 735 | &LAB JSL $E100A8 736 | DC I2'$2004' 737 | DC I4'&DCB' 738 | MEND 739 | MACRO 740 | &LAB OSGET_PREFIX &DCB 741 | &LAB JSL $E100A8 742 | DC I2'$200A' 743 | DC I4'&DCB' 744 | MEND 745 | MACRO 746 | &LAB OSOPEN &DCB 747 | &LAB JSL $E100A8 748 | DC I2'$2010' 749 | DC I4'&DCB' 750 | MEND 751 | MACRO 752 | &LAB OSREAD &DCB 753 | &LAB JSL $E100A8 754 | DC I2'$2012' 755 | DC I4'&DCB' 756 | MEND 757 | MACRO 758 | &LAB OSWRITE &DCB 759 | &LAB JSL $E100A8 760 | DC I2'$2013' 761 | DC I4'&DCB' 762 | MEND 763 | MACRO 764 | &LAB OSCLOSE &DCB 765 | &LAB JSL $E100A8 766 | DC I2'$2014' 767 | DC I4'&DCB' 768 | MEND 769 | MACRO 770 | &LAB OSSET_MARK &DCB 771 | &LAB JSL $E100A8 772 | DC I2'$2016' 773 | DC I4'&DCB' 774 | MEND 775 | MACRO 776 | &LAB OSGET_MARK &DCB 777 | &LAB JSL $E100A8 778 | DC I2'$2017' 779 | DC I4'&DCB' 780 | MEND 781 | MACRO 782 | &LAB OSSET_EOF &DCB 783 | &LAB JSL $E100A8 784 | DC I2'$2018' 785 | DC I4'&DCB' 786 | MEND 787 | MACRO 788 | &LAB OSGET_EOF &DCB 789 | &LAB JSL $E100A8 790 | DC I2'$2019' 791 | DC I4'&DCB' 792 | MEND 793 | MACRO 794 | &LAB _INT2DEC 795 | &LAB LDX #$260B 796 | JSL $E10000 797 | MEND 798 | MACRO 799 | &LAB _LONG2DEC 800 | &LAB LDX #$270B 801 | JSL $E10000 802 | MEND 803 | MACRO 804 | &LAB JMI &BP 805 | &LAB BPL *+5 806 | BRL &BP 807 | MEND 808 | MACRO 809 | &LAB OSGET_FILE_INFO &DCB 810 | &LAB JSL $E100A8 811 | DC I2'$2006' 812 | DC I4'&DCB' 813 | MEND 814 | macro 815 | &l getrefinfogs &p 816 | &l jsl $E100A8 817 | dc i2'$2039' 818 | dc i4'&p' 819 | mend 820 | macro 821 | &l destroygs &p 822 | &l jsl $E100A8 823 | dc i2'$2002' 824 | dc i4'&p' 825 | mend 826 | macro 827 | &l pl8 &n1 828 | lclc &c 829 | &l anop 830 | aif s:longa=1,.a 831 | rep #%00100000 832 | .a 833 | &c amid &n1,1,1 834 | aif "&c"<>"{",.b 835 | &c amid &n1,l:&n1,1 836 | aif "&c"<>"}",.f 837 | &n1 amid &n1,2,l:&n1-2 838 | pla 839 | sta (&n1) 840 | ldy #2 841 | pla 842 | sta (&n1),y 843 | ldy #4 844 | pla 845 | sta (&n1),y 846 | ldy #6 847 | pla 848 | sta (&n1),y 849 | ago .d 850 | .b 851 | aif "&c"<>"[",.c 852 | pla 853 | sta &n1 854 | ldy #2 855 | pla 856 | sta &n1,y 857 | ldy #4 858 | pla 859 | sta &n1,y 860 | ldy #6 861 | pla 862 | sta &n1,y 863 | ago .d 864 | .c 865 | pla 866 | sta &n1 867 | pla 868 | sta &n1+2 869 | pla 870 | sta &n1+4 871 | pla 872 | sta &n1+6 873 | .d 874 | aif s:longa=1,.e 875 | sep #%00100000 876 | .e 877 | mexit 878 | .f 879 | mnote "Missing closing '}'",16 880 | mend 881 | macro 882 | &l jpl &bp 883 | &l bmi *+5 884 | brl &bp 885 | mend 886 | macro 887 | &l lret &r 888 | &l anop 889 | lclc &len 890 | aif c:&r,.a 891 | lclc &r 892 | &r setc 0 893 | &len setc 0 894 | ago .h 895 | .a 896 | &len amid &r,2,1 897 | aif "&len"=":",.b 898 | &len amid &r,1,2 899 | &r amid &r,4,l:&r-3 900 | ago .c 901 | .b 902 | &len amid &r,1,1 903 | &r amid &r,3,l:&r-2 904 | .c 905 | aif &len<>2,.d 906 | ldy &r 907 | ago .h 908 | .d 909 | aif &len<>4,.e 910 | ldx &r+2 911 | ldy &r 912 | ago .h 913 | .e 914 | aif &len<>10,.g 915 | ldy #&r 916 | ldx #^&r 917 | ago .h 918 | .g 919 | mnote 'Not a valid return length',16 920 | mexit 921 | .h 922 | aif &totallen=0,.i 923 | lda &worklen+1 924 | sta &worklen+&totallen+1 925 | .i 926 | pld 927 | tsc 928 | clc 929 | adc #&worklen+&totallen 930 | tcs 931 | aif &len=0,.j 932 | tya 933 | .j 934 | rts 935 | mend 936 | macro 937 | &l lsub &parms,&work 938 | &l anop 939 | aif c:&work,.a 940 | lclc &work 941 | &work setc 0 942 | .a 943 | gbla &totallen 944 | gbla &worklen 945 | &worklen seta &work 946 | &totallen seta 0 947 | aif c:&parms=0,.e 948 | lclc &len 949 | lclc &p 950 | lcla &i 951 | &i seta c:&parms 952 | .b 953 | &p setc &parms(&i) 954 | &len amid &p,2,1 955 | aif "&len"=":",.c 956 | &len amid &p,1,2 957 | &p amid &p,4,l:&p-3 958 | ago .d 959 | .c 960 | &len amid &p,1,1 961 | &p amid &p,3,l:&p-2 962 | .d 963 | &p equ &totallen+3+&work 964 | &totallen seta &totallen+&len 965 | &i seta &i-1 966 | aif &i,^b 967 | .e 968 | tsc 969 | aif &work=0,.f 970 | sec 971 | sbc #&work 972 | tcs 973 | .f 974 | phd 975 | tcd 976 | mend 977 | -------------------------------------------------------------------------------- /stdlib.macros: -------------------------------------------------------------------------------- 1 | macro 2 | &l ph2 &n1 3 | &l anop 4 | aif "&n1"="*",.f 5 | lclc &c 6 | &c amid &n1,1,1 7 | aif "&c"="#",.d 8 | aif s:longa=1,.a 9 | rep #%00100000 10 | .a 11 | aif "&c"<>"{",.b 12 | &c amid &n1,l:&n1,1 13 | aif "&c"<>"}",.g 14 | &n1 amid &n1,2,l:&n1-2 15 | lda (&n1) 16 | pha 17 | ago .e 18 | .b 19 | aif "&c"="<",.c 20 | lda &n1 21 | pha 22 | ago .e 23 | .c 24 | &n1 amid &n1,2,l:&n1-1 25 | pei &n1 26 | ago .e 27 | .d 28 | &n1 amid &n1,2,l:&n1-1 29 | pea &n1 30 | ago .f 31 | .e 32 | aif s:longa=1,.f 33 | sep #%00100000 34 | .f 35 | mexit 36 | .g 37 | mnote "Missing closing '}'",16 38 | mend 39 | macro 40 | &l ph4 &n1 41 | &l anop 42 | aif "&n1"="*",.f 43 | lclc &c 44 | &c amid &n1,1,1 45 | aif "&c"="#",.d 46 | aif s:longa=1,.a 47 | rep #%00100000 48 | .a 49 | aif "&c"<>"{",.b 50 | &c amid &n1,l:&n1,1 51 | aif "&c"<>"}",.g 52 | &n1 amid &n1,2,l:&n1-2 53 | ldy #2 54 | lda (&n1),y 55 | pha 56 | lda (&n1) 57 | pha 58 | ago .e 59 | .b 60 | aif "&c"<>"[",.c 61 | ldy #2 62 | lda &n1,y 63 | pha 64 | lda &n1 65 | pha 66 | ago .e 67 | .c 68 | aif "&c"<>"<",.c1 69 | &n1 amid &n1,2,l:&n1-1 70 | pei &n1+2 71 | pei &n1 72 | ago .e 73 | .c1 74 | lda &n1+2 75 | pha 76 | lda &n1 77 | pha 78 | ago .e 79 | .d 80 | &n1 amid &n1,2,l:&n1-1 81 | pea +(&n1)|-16 82 | pea &n1 83 | ago .f 84 | .e 85 | aif s:longa=1,.f 86 | sep #%00100000 87 | .f 88 | mexit 89 | .g 90 | mnote "Missing closing '}'",16 91 | mend 92 | macro 93 | &l negate8 &n1 94 | &l ~setm 95 | sec 96 | ldy #0 97 | tya 98 | sbc &n1 99 | sta &n1 100 | tya 101 | sbc &n1+2 102 | sta &n1+2 103 | tya 104 | sbc &n1+4 105 | sta &n1+4 106 | tya 107 | sbc &n1+6 108 | sta &n1+6 109 | ~restm 110 | mend 111 | macro 112 | &l ph8 &n1 113 | lclc &c 114 | &l anop 115 | &c amid &n1,1,1 116 | aif s:longa=1,.a 117 | rep #%00100000 118 | .a 119 | aif "&c"="#",.d 120 | aif "&c"="[",.b 121 | aif "&c"<>"{",.c 122 | &c amid &n1,l:&n1,1 123 | aif "&c"<>"}",.g 124 | &n1 amid &n1,2,l:&n1-2 125 | &n1 setc (&n1) 126 | .b 127 | ldy #6 128 | ~&SYSCNT lda &n1,y 129 | pha 130 | dey 131 | dey 132 | bpl ~&SYSCNT 133 | ago .e 134 | .c 135 | aif "&c"<>"<",.c1 136 | pei &n1+6 137 | pei &n1+4 138 | pei &n1+2 139 | pei &n1 140 | ago .e 141 | .c1 142 | ldx #6 143 | ~&SYSCNT lda &n1,x 144 | pha 145 | dex 146 | dex 147 | bpl ~&SYSCNT 148 | ago .e 149 | .d 150 | &n1 amid &n1,2,l:&n1-1 151 | pea +(&n1)|-48 152 | pea +(&n1)|-32 153 | pea +(&n1)|-16 154 | pea &n1 155 | .e 156 | aif s:longa=1,.f 157 | sep #%00100000 158 | .f 159 | mexit 160 | .g 161 | mnote "Missing closing '}'",16 162 | mend 163 | MACRO 164 | &LAB MOVE4 &F,&T 165 | &LAB ~SETM 166 | LDA 2+&F 167 | STA 2+&T 168 | LDA &F 169 | STA &T 170 | ~RESTM 171 | MEND 172 | MACRO 173 | &lab csubroutine &parms,&work 174 | &lab anop 175 | aif c:&work,.a 176 | lclc &work 177 | &work setc 0 178 | .a 179 | gbla &totallen 180 | gbla &worklen 181 | &worklen seta &work 182 | &totallen seta 0 183 | aif c:&parms=0,.e 184 | lclc &len 185 | lclc &p 186 | lcla &i 187 | &i seta 1 188 | .b 189 | &p setc &parms(&i) 190 | &len amid &p,2,1 191 | aif "&len"=":",.c 192 | &len amid &p,1,2 193 | &p amid &p,4,l:&p-3 194 | ago .d 195 | .c 196 | &len amid &p,1,1 197 | &p amid &p,3,l:&p-2 198 | .d 199 | &p equ &totallen+4+&work 200 | &totallen seta &totallen+&len 201 | &i seta &i+1 202 | aif &i<=c:&parms,^b 203 | .e 204 | tsc 205 | aif &work=0,.f 206 | sec 207 | sbc #&work 208 | tcs 209 | .f 210 | phd 211 | tcd 212 | mend 213 | MACRO 214 | &lab creturn &r 215 | &lab anop 216 | lclc &len 217 | aif c:&r,.a 218 | lclc &r 219 | &r setc 0 220 | &len setc 0 221 | ago .h 222 | .a 223 | &len amid &r,2,1 224 | aif "&len"=":",.b 225 | &len amid &r,1,2 226 | &r amid &r,4,l:&r-3 227 | ago .c 228 | .b 229 | &len amid &r,1,1 230 | &r amid &r,3,l:&r-2 231 | .c 232 | aif &len<>2,.d 233 | ldy &r 234 | ago .h 235 | .d 236 | aif &len<>4,.e 237 | ldx &r+2 238 | ldy &r 239 | ago .h 240 | .e 241 | aif &len<>10,.g 242 | ldy #&r 243 | ldx #^&r 244 | ago .h 245 | .g 246 | mnote 'Not a valid return length',16 247 | mexit 248 | .h 249 | aif &totallen=0,.i 250 | lda &worklen+2 251 | sta &worklen+&totallen+2 252 | lda &worklen+1 253 | sta &worklen+&totallen+1 254 | .i 255 | pld 256 | tsc 257 | clc 258 | adc #&worklen+&totallen 259 | tcs 260 | aif &len=0,.j 261 | tya 262 | .j 263 | rtl 264 | mend 265 | MACRO 266 | &LAB ~SETM 267 | &LAB ANOP 268 | AIF C:&~LA,.B 269 | GBLB &~LA 270 | GBLB &~LI 271 | .B 272 | &~LA SETB S:LONGA 273 | &~LI SETB S:LONGI 274 | AIF S:LONGA.AND.S:LONGI,.A 275 | REP #32*(.NOT.&~LA)+16*(.NOT.&~LI) 276 | LONGA ON 277 | LONGI ON 278 | .A 279 | MEND 280 | MACRO 281 | &LAB ~RESTM 282 | &LAB ANOP 283 | AIF (&~LA+&~LI)=2,.I 284 | SEP #32*(.NOT.&~LA)+16*(.NOT.&~LI) 285 | AIF &~LA,.H 286 | LONGA OFF 287 | .H 288 | AIF &~LI,.I 289 | LONGI OFF 290 | .I 291 | MEND 292 | MACRO 293 | &LAB ADD4 &M1,&M2,&M3 294 | LCLB &YISTWO 295 | LCLC &C 296 | &LAB ~SETM 297 | AIF C:&M3,.A 298 | &C AMID "&M2",1,1 299 | AIF "&C"<>"#",.A 300 | &C AMID "&M1",1,1 301 | AIF "&C"="{",.A 302 | AIF "&C"="[",.A 303 | &C AMID "&M2",2,L:&M2-1 304 | AIF &C>=65536,.A 305 | CLC 306 | ~LDA &M1 307 | ~OP ADC,&M2 308 | ~STA &M1 309 | BCC ~&SYSCNT 310 | ~OP.H INC,&M1 311 | ~&SYSCNT ANOP 312 | AGO .C 313 | .A 314 | AIF C:&M3,.B 315 | LCLC &M3 316 | &M3 SETC &M1 317 | .B 318 | CLC 319 | ~LDA &M1 320 | ~OP ADC,&M2 321 | ~STA &M3 322 | ~LDA.H &M1 323 | ~OP.H ADC,&M2 324 | ~STA.H &M3 325 | .C 326 | ~RESTM 327 | MEND 328 | MACRO 329 | &LAB MUL4 &N1,&N2,&N3 330 | &LAB ~SETM 331 | PH4 &N1 332 | PH4 &N2 333 | JSL ~MUL4 334 | AIF C:&N3,.A 335 | PL4 &N1 336 | AGO .B 337 | .A 338 | PL4 &N3 339 | .B 340 | ~RESTM 341 | MEND 342 | MACRO 343 | &LAB SUB4 &M1,&M2,&M3 344 | LCLB &YISTWO 345 | LCLC &C 346 | &LAB ~SETM 347 | AIF C:&M3,.A 348 | &C AMID "&M2",1,1 349 | AIF "&C"<>"#",.A 350 | &C AMID "&M1",1,1 351 | AIF "&C"="{",.A 352 | AIF "&C"="[",.A 353 | &C AMID "&M2",2,L:&M2-1 354 | AIF &C>=65536,.A 355 | SEC 356 | ~LDA &M1 357 | ~OP SBC,&M2 358 | ~STA &M1 359 | BCS ~&SYSCNT 360 | ~OP.H DEC,&M1 361 | ~&SYSCNT ANOP 362 | AGO .C 363 | .A 364 | AIF C:&M3,.B 365 | LCLC &M3 366 | &M3 SETC &M1 367 | .B 368 | SEC 369 | ~LDA &M1 370 | ~OP SBC,&M2 371 | ~STA &M3 372 | ~LDA.H &M1 373 | ~OP.H SBC,&M2 374 | ~STA.H &M3 375 | .C 376 | ~RESTM 377 | MEND 378 | MACRO 379 | &LAB ~OP.H &OPC,&OP 380 | &LAB ANOP 381 | LCLC &C 382 | &C AMID "&OP",1,1 383 | AIF "&C"="[",.B 384 | AIF "&C"<>"{",.D 385 | &C AMID "&OP",L:&OP,1 386 | AIF "&C"="}",.A 387 | MNOTE "Missing closing '}'",2 388 | &OP SETC &OP} 389 | .A 390 | &OP AMID "&OP",2,L:&OP-2 391 | &OP SETC (&OP) 392 | .B 393 | AIF &YISTWO,.C 394 | &YISTWO SETB 1 395 | LDY #2 396 | &OP SETC "&OP,Y" 397 | .C 398 | &OPC &OP 399 | MEXIT 400 | .D 401 | AIF "&C"<>"#",.E 402 | &OP AMID "&OP",2,L:&OP-1 403 | &OP SETC "#^&OP" 404 | &OPC &OP 405 | MEXIT 406 | .E 407 | &OPC 2+&OP 408 | MEND 409 | MACRO 410 | &LAB ~LDA.H &OP 411 | &LAB ANOP 412 | LCLC &C 413 | &C AMID "&OP",1,1 414 | AIF "&C"="[",.B 415 | AIF "&C"<>"{",.D 416 | &C AMID "&OP",L:&OP,1 417 | AIF "&C"="}",.A 418 | MNOTE "Missing closing '}'",2 419 | &OP SETC &OP} 420 | .A 421 | &OP AMID "&OP",2,L:&OP-2 422 | &OP SETC (&OP) 423 | .B 424 | AIF &YISTWO,.C 425 | &YISTWO SETB 1 426 | LDY #2 427 | &OP SETC "&OP,Y" 428 | .C 429 | LDA &OP 430 | MEXIT 431 | .D 432 | AIF "&C"<>"#",.E 433 | &OP AMID "&OP",2,L:&OP-1 434 | &OP SETC "#^&OP" 435 | LDA &OP 436 | MEXIT 437 | .E 438 | LDA 2+&OP 439 | MEND 440 | MACRO 441 | &LAB ~STA.H &OP 442 | &LAB ANOP 443 | LCLC &C 444 | &C AMID "&OP",1,1 445 | AIF "&C"="[",.B 446 | AIF "&C"<>"{",.D 447 | &C AMID "&OP",L:&OP,1 448 | AIF "&C"="}",.A 449 | MNOTE "Missing closing '}'",2 450 | &OP SETC &OP} 451 | .A 452 | &OP AMID "&OP",2,L:&OP-2 453 | &OP SETC (&OP) 454 | .B 455 | AIF &YISTWO,.C 456 | &YISTWO SETB 1 457 | LDY #2 458 | &OP SETC "&OP,Y" 459 | .C 460 | STA &OP 461 | MEXIT 462 | .D 463 | STA 2+&OP 464 | MEND 465 | MACRO 466 | &LAB ~LDA &OP 467 | LCLC &C 468 | &C AMID "&OP",1,1 469 | AIF "&C"<>"{",.B 470 | &C AMID "&OP",L:&OP,1 471 | AIF "&C"="}",.A 472 | MNOTE "Missing closing '}'",2 473 | &OP SETC &OP} 474 | .A 475 | &OP AMID "&OP",2,L:&OP-2 476 | &OP SETC (&OP) 477 | .B 478 | &LAB LDA &OP 479 | MEND 480 | MACRO 481 | &LAB ~STA &OP 482 | LCLC &C 483 | &C AMID "&OP",1,1 484 | AIF "&C"<>"{",.B 485 | &C AMID "&OP",L:&OP,1 486 | AIF "&C"="}",.A 487 | MNOTE "Missing closing '}'",2 488 | &OP SETC &OP} 489 | .A 490 | &OP AMID "&OP",2,L:&OP-2 491 | &OP SETC (&OP) 492 | .B 493 | &LAB STA &OP 494 | MEND 495 | MACRO 496 | &LAB ~OP &OPC,&OP 497 | LCLC &C 498 | &C AMID "&OP",1,1 499 | AIF "&C"<>"{",.B 500 | &C AMID "&OP",L:&OP,1 501 | AIF "&C"="}",.A 502 | MNOTE "Missing closing '}'",2 503 | &OP SETC &OP} 504 | .A 505 | &OP AMID "&OP",2,L:&OP-2 506 | &OP SETC (&OP) 507 | .B 508 | &LAB &OPC &OP 509 | MEND 510 | MACRO 511 | &LAB BGT &BP 512 | &LAB BEQ *+4 513 | BGE &BP 514 | MEND 515 | MACRO 516 | &LAB DEC4 &A 517 | &LAB ~SETM 518 | LDA &A 519 | BNE ~&SYSCNT 520 | DEC 2+&A 521 | ~&SYSCNT DEC &A 522 | ~RESTM 523 | MEND 524 | MACRO 525 | &LAB INC4 &A 526 | &LAB ~SETM 527 | INC &A 528 | BNE ~&SYSCNT 529 | INC 2+&A 530 | ~&SYSCNT ~RESTM 531 | MEND 532 | MACRO 533 | &LAB LONG &A,&B 534 | LCLB &I 535 | LCLB &M 536 | &A AMID &A,1,1 537 | &M SETB ("&A"="M").OR.("&A"="m") 538 | &I SETB ("&A"="I").OR.("&A"="i") 539 | AIF C:&B=0,.A 540 | &B AMID &B,1,1 541 | &M SETB ("&B"="M").OR.("&B"="m").OR.&M 542 | &I SETB ("&B"="I").OR.("&B"="i").OR.&I 543 | .A 544 | &LAB REP #&M*32+&I*16 545 | AIF .NOT.&M,.B 546 | LONGA ON 547 | .B 548 | AIF .NOT.&I,.C 549 | LONGI ON 550 | .C 551 | MEND 552 | MACRO 553 | &LAB PL4 &N1 554 | LCLC &C 555 | &LAB ANOP 556 | AIF S:LONGA=1,.A 557 | REP #%00100000 558 | .A 559 | &C AMID &N1,1,1 560 | AIF "&C"<>"{",.B 561 | &C AMID &N1,L:&N1,1 562 | AIF "&C"<>"}",.F 563 | &N1 AMID &N1,2,L:&N1-2 564 | PLA 565 | STA (&N1) 566 | LDY #2 567 | PLA 568 | STA (&N1),Y 569 | AGO .D 570 | .B 571 | AIF "&C"<>"[",.C 572 | PLA 573 | STA &N1 574 | LDY #2 575 | PLA 576 | STA &N1,Y 577 | AGO .D 578 | .C 579 | PLA 580 | STA &N1 581 | PLA 582 | STA &N1+2 583 | .D 584 | AIF S:LONGA=1,.E 585 | SEP #%00100000 586 | .E 587 | MEXIT 588 | .F 589 | MNOTE "Missing closing '}'",16 590 | MEND 591 | MACRO 592 | &LAB SHORT &A,&B 593 | LCLB &I 594 | LCLB &M 595 | &A AMID &A,1,1 596 | &M SETB ("&A"="M").OR.("&A"="m") 597 | &I SETB ("&A"="I").OR.("&A"="i") 598 | AIF C:&B=0,.A 599 | &B AMID &B,1,1 600 | &M SETB ("&B"="M").OR.("&B"="m").OR.&M 601 | &I SETB ("&B"="I").OR.("&B"="i").OR.&I 602 | .A 603 | &LAB SEP #&M*32+&I*16 604 | AIF .NOT.&M,.B 605 | LONGA OFF 606 | .B 607 | AIF .NOT.&I,.C 608 | LONGI OFF 609 | .C 610 | MEND 611 | MACRO 612 | &LAB EXECUTE &DCB 613 | &LAB ~SETM 614 | JSL $E100A8 615 | DC I2'$010D' 616 | DC I4'&DCB' 617 | ~RESTM 618 | MEND 619 | MACRO 620 | &LAB _LONGMUL 621 | &LAB LDX #$0C0B 622 | JSL $E10000 623 | MEND 624 | MACRO 625 | &LAB LLA &AD1,&AD2 626 | &LAB ANOP 627 | LCLA &L 628 | LCLB &LA 629 | AIF S:LONGA,.A 630 | REP #%00100000 631 | LONGA ON 632 | &LA SETB 1 633 | .A 634 | LDA #&AD2 635 | &L SETA C:&AD1 636 | .B 637 | STA &AD1(&L) 638 | &L SETA &L-1 639 | AIF &L,^B 640 | LDA #^&AD2 641 | &L SETA C:&AD1 642 | .C 643 | STA 2+&AD1(&L) 644 | &L SETA &L-1 645 | AIF &L,^C 646 | AIF &LA=0,.D 647 | SEP #%00100000 648 | LONGA OFF 649 | .D 650 | MEND 651 | MACRO 652 | &LAB SUB2 &N1,&N2,&N3 653 | AIF C:&N3,.A 654 | LCLC &N3 655 | &N3 SETC &N1 656 | .A 657 | &LAB ~SETM 658 | SEC 659 | ~LDA &N1 660 | ~OP SBC,&N2 661 | ~STA &N3 662 | ~RESTM 663 | MEND 664 | MACRO 665 | &LAB READ_VARIABLE &DCB 666 | &LAB ~SETM 667 | JSL $E100A8 668 | DC I2'$010B' 669 | DC I4'&DCB' 670 | ~RESTM 671 | MEND 672 | macro 673 | &l pl8 &n1 674 | lclc &c 675 | &l anop 676 | aif s:longa=1,.a 677 | rep #%00100000 678 | .a 679 | &c amid &n1,1,1 680 | aif "&c"<>"{",.b 681 | &c amid &n1,l:&n1,1 682 | aif "&c"<>"}",.f 683 | &n1 amid &n1,2,l:&n1-2 684 | pla 685 | sta (&n1) 686 | ldy #2 687 | pla 688 | sta (&n1),y 689 | ldy #4 690 | pla 691 | sta (&n1),y 692 | ldy #6 693 | pla 694 | sta (&n1),y 695 | ago .d 696 | .b 697 | aif "&c"<>"[",.c 698 | pla 699 | sta &n1 700 | ldy #2 701 | pla 702 | sta &n1,y 703 | ldy #4 704 | pla 705 | sta &n1,y 706 | ldy #6 707 | pla 708 | sta &n1,y 709 | ago .d 710 | .c 711 | pla 712 | sta &n1 713 | pla 714 | sta &n1+2 715 | pla 716 | sta &n1+4 717 | pla 718 | sta &n1+6 719 | .d 720 | aif s:longa=1,.e 721 | sep #%00100000 722 | .e 723 | mexit 724 | .f 725 | mnote "Missing closing '}'",16 726 | mend 727 | macro 728 | &l jge &bp 729 | &l blt *+5 730 | brl &bp 731 | mend 732 | macro 733 | &l jeq &bp 734 | &l bne *+5 735 | brl &bp 736 | mend 737 | macro 738 | &l cmpl &n1,&n2 739 | lclb &yistwo 740 | &l ~setm 741 | ~lda.h &n1 742 | ~op.h cmp,&n2 743 | bne ~a&SYSCNT 744 | ~lda &n1 745 | ~op cmp,&n2 746 | ~a&SYSCNT anop 747 | ~restm 748 | mend 749 | -------------------------------------------------------------------------------- /string.macros: -------------------------------------------------------------------------------- 1 | macro 2 | &l ph4 &n1 3 | &l anop 4 | aif "&n1"="*",.f 5 | lclc &c 6 | &c amid &n1,1,1 7 | aif "&c"="#",.d 8 | aif s:longa=1,.a 9 | rep #%00100000 10 | .a 11 | aif "&c"<>"{",.b 12 | &c amid &n1,l:&n1,1 13 | aif "&c"<>"}",.g 14 | &n1 amid &n1,2,l:&n1-2 15 | ldy #2 16 | lda (&n1),y 17 | pha 18 | lda (&n1) 19 | pha 20 | ago .e 21 | .b 22 | aif "&c"<>"[",.c 23 | ldy #2 24 | lda &n1,y 25 | pha 26 | lda &n1 27 | pha 28 | ago .e 29 | .c 30 | aif "&c"<>"<",.c1 31 | &n1 amid &n1,2,l:&n1-1 32 | pei &n1+2 33 | pei &n1 34 | ago .e 35 | .c1 36 | lda &n1+2 37 | pha 38 | lda &n1 39 | pha 40 | ago .e 41 | .d 42 | &n1 amid &n1,2,l:&n1-1 43 | pea +(&n1)|-16 44 | pea &n1 45 | ago .f 46 | .e 47 | aif s:longa=1,.f 48 | sep #%00100000 49 | .f 50 | mexit 51 | .g 52 | mnote "Missing closing '}'",16 53 | mend 54 | MACRO 55 | &LAB MOVE4 &F,&T 56 | &LAB ~SETM 57 | LDA 2+&F 58 | STA 2+&T 59 | LDA &F 60 | STA &T 61 | ~RESTM 62 | MEND 63 | MACRO 64 | &lab csubroutine &parms,&work 65 | &lab anop 66 | aif c:&work,.a 67 | lclc &work 68 | &work setc 0 69 | .a 70 | gbla &totallen 71 | gbla &worklen 72 | &worklen seta &work 73 | &totallen seta 0 74 | aif c:&parms=0,.e 75 | lclc &len 76 | lclc &p 77 | lcla &i 78 | &i seta 1 79 | .b 80 | &p setc &parms(&i) 81 | &len amid &p,2,1 82 | aif "&len"=":",.c 83 | &len amid &p,1,2 84 | &p amid &p,4,l:&p-3 85 | ago .d 86 | .c 87 | &len amid &p,1,1 88 | &p amid &p,3,l:&p-2 89 | .d 90 | &p equ &totallen+4+&work 91 | &totallen seta &totallen+&len 92 | &i seta &i+1 93 | aif &i<=c:&parms,^b 94 | .e 95 | tsc 96 | aif &work=0,.f 97 | sec 98 | sbc #&work 99 | tcs 100 | .f 101 | phd 102 | tcd 103 | mend 104 | MACRO 105 | &lab creturn &r 106 | &lab anop 107 | lclc &len 108 | aif c:&r,.a 109 | lclc &r 110 | &r setc 0 111 | &len setc 0 112 | ago .h 113 | .a 114 | &len amid &r,2,1 115 | aif "&len"=":",.b 116 | &len amid &r,1,2 117 | &r amid &r,4,l:&r-3 118 | ago .c 119 | .b 120 | &len amid &r,1,1 121 | &r amid &r,3,l:&r-2 122 | .c 123 | aif &len<>2,.d 124 | ldy &r 125 | ago .h 126 | .d 127 | aif &len<>4,.e 128 | ldx &r+2 129 | ldy &r 130 | ago .h 131 | .e 132 | aif &len<>10,.g 133 | ldy #&r 134 | ldx #^&r 135 | ago .h 136 | .g 137 | mnote 'Not a valid return length',16 138 | mexit 139 | .h 140 | aif &totallen=0,.i 141 | lda &worklen+2 142 | sta &worklen+&totallen+2 143 | lda &worklen+1 144 | sta &worklen+&totallen+1 145 | .i 146 | pld 147 | tsc 148 | clc 149 | adc #&worklen+&totallen 150 | tcs 151 | aif &len=0,.j 152 | tya 153 | .j 154 | rtl 155 | mend 156 | MACRO 157 | &LAB ~SETM 158 | &LAB ANOP 159 | AIF C:&~LA,.B 160 | GBLB &~LA 161 | GBLB &~LI 162 | .B 163 | &~LA SETB S:LONGA 164 | &~LI SETB S:LONGI 165 | AIF S:LONGA.AND.S:LONGI,.A 166 | REP #32*(.NOT.&~LA)+16*(.NOT.&~LI) 167 | LONGA ON 168 | LONGI ON 169 | .A 170 | MEND 171 | MACRO 172 | &LAB ~RESTM 173 | &LAB ANOP 174 | AIF (&~LA+&~LI)=2,.I 175 | SEP #32*(.NOT.&~LA)+16*(.NOT.&~LI) 176 | AIF &~LA,.H 177 | LONGA OFF 178 | .H 179 | AIF &~LI,.I 180 | LONGI OFF 181 | .I 182 | MEND 183 | MACRO 184 | &LAB ADD2 &N1,&N2,&N3 185 | AIF C:&N3,.A 186 | LCLC &N3 187 | &N3 SETC &N1 188 | .A 189 | &LAB ~SETM 190 | CLC 191 | ~LDA &N1 192 | ~OP ADC,&N2 193 | ~STA &N3 194 | ~RESTM 195 | MEND 196 | MACRO 197 | &LAB ~LDA &OP 198 | LCLC &C 199 | &C AMID "&OP",1,1 200 | AIF "&C"<>"{",.B 201 | &C AMID "&OP",L:&OP,1 202 | AIF "&C"="}",.A 203 | MNOTE "Missing closing '}'",2 204 | &OP SETC &OP} 205 | .A 206 | &OP AMID "&OP",2,L:&OP-2 207 | &OP SETC (&OP) 208 | .B 209 | &LAB LDA &OP 210 | MEND 211 | MACRO 212 | &LAB ~STA &OP 213 | LCLC &C 214 | &C AMID "&OP",1,1 215 | AIF "&C"<>"{",.B 216 | &C AMID "&OP",L:&OP,1 217 | AIF "&C"="}",.A 218 | MNOTE "Missing closing '}'",2 219 | &OP SETC &OP} 220 | .A 221 | &OP AMID "&OP",2,L:&OP-2 222 | &OP SETC (&OP) 223 | .B 224 | &LAB STA &OP 225 | MEND 226 | MACRO 227 | &LAB ~OP &OPC,&OP 228 | LCLC &C 229 | &C AMID "&OP",1,1 230 | AIF "&C"<>"{",.B 231 | &C AMID "&OP",L:&OP,1 232 | AIF "&C"="}",.A 233 | MNOTE "Missing closing '}'",2 234 | &OP SETC &OP} 235 | .A 236 | &OP AMID "&OP",2,L:&OP-2 237 | &OP SETC (&OP) 238 | .B 239 | &LAB &OPC &OP 240 | MEND 241 | MACRO 242 | &LAB ADD4 &M1,&M2,&M3 243 | LCLB &YISTWO 244 | LCLC &C 245 | &LAB ~SETM 246 | AIF C:&M3,.A 247 | &C AMID "&M2",1,1 248 | AIF "&C"<>"#",.A 249 | &C AMID "&M1",1,1 250 | AIF "&C"="{",.A 251 | AIF "&C"="[",.A 252 | &C AMID "&M2",2,L:&M2-1 253 | AIF &C>=65536,.A 254 | CLC 255 | ~LDA &M1 256 | ~OP ADC,&M2 257 | ~STA &M1 258 | BCC ~&SYSCNT 259 | ~OP.H INC,&M1 260 | ~&SYSCNT ANOP 261 | AGO .C 262 | .A 263 | AIF C:&M3,.B 264 | LCLC &M3 265 | &M3 SETC &M1 266 | .B 267 | CLC 268 | ~LDA &M1 269 | ~OP ADC,&M2 270 | ~STA &M3 271 | ~LDA.H &M1 272 | ~OP.H ADC,&M2 273 | ~STA.H &M3 274 | .C 275 | ~RESTM 276 | MEND 277 | MACRO 278 | &LAB SUB4 &M1,&M2,&M3 279 | LCLB &YISTWO 280 | LCLC &C 281 | &LAB ~SETM 282 | AIF C:&M3,.A 283 | &C AMID "&M2",1,1 284 | AIF "&C"<>"#",.A 285 | &C AMID "&M1",1,1 286 | AIF "&C"="{",.A 287 | AIF "&C"="[",.A 288 | &C AMID "&M2",2,L:&M2-1 289 | AIF &C>=65536,.A 290 | SEC 291 | ~LDA &M1 292 | ~OP SBC,&M2 293 | ~STA &M1 294 | BCS ~&SYSCNT 295 | ~OP.H DEC,&M1 296 | ~&SYSCNT ANOP 297 | AGO .C 298 | .A 299 | AIF C:&M3,.B 300 | LCLC &M3 301 | &M3 SETC &M1 302 | .B 303 | SEC 304 | ~LDA &M1 305 | ~OP SBC,&M2 306 | ~STA &M3 307 | ~LDA.H &M1 308 | ~OP.H SBC,&M2 309 | ~STA.H &M3 310 | .C 311 | ~RESTM 312 | MEND 313 | MACRO 314 | &LAB ~OP.H &OPC,&OP 315 | &LAB ANOP 316 | LCLC &C 317 | &C AMID "&OP",1,1 318 | AIF "&C"="[",.B 319 | AIF "&C"<>"{",.D 320 | &C AMID "&OP",L:&OP,1 321 | AIF "&C"="}",.A 322 | MNOTE "Missing closing '}'",2 323 | &OP SETC &OP} 324 | .A 325 | &OP AMID "&OP",2,L:&OP-2 326 | &OP SETC (&OP) 327 | .B 328 | AIF &YISTWO,.C 329 | &YISTWO SETB 1 330 | LDY #2 331 | &OP SETC "&OP,Y" 332 | .C 333 | &OPC &OP 334 | MEXIT 335 | .D 336 | AIF "&C"<>"#",.E 337 | &OP AMID "&OP",2,L:&OP-1 338 | &OP SETC "#^&OP" 339 | &OPC &OP 340 | MEXIT 341 | .E 342 | &OPC 2+&OP 343 | MEND 344 | MACRO 345 | &LAB ~LDA.H &OP 346 | &LAB ANOP 347 | LCLC &C 348 | &C AMID "&OP",1,1 349 | AIF "&C"="[",.B 350 | AIF "&C"<>"{",.D 351 | &C AMID "&OP",L:&OP,1 352 | AIF "&C"="}",.A 353 | MNOTE "Missing closing '}'",2 354 | &OP SETC &OP} 355 | .A 356 | &OP AMID "&OP",2,L:&OP-2 357 | &OP SETC (&OP) 358 | .B 359 | AIF &YISTWO,.C 360 | &YISTWO SETB 1 361 | LDY #2 362 | &OP SETC "&OP,Y" 363 | .C 364 | LDA &OP 365 | MEXIT 366 | .D 367 | AIF "&C"<>"#",.E 368 | &OP AMID "&OP",2,L:&OP-1 369 | &OP SETC "#^&OP" 370 | LDA &OP 371 | MEXIT 372 | .E 373 | LDA 2+&OP 374 | MEND 375 | MACRO 376 | &LAB ~STA.H &OP 377 | &LAB ANOP 378 | LCLC &C 379 | &C AMID "&OP",1,1 380 | AIF "&C"="[",.B 381 | AIF "&C"<>"{",.D 382 | &C AMID "&OP",L:&OP,1 383 | AIF "&C"="}",.A 384 | MNOTE "Missing closing '}'",2 385 | &OP SETC &OP} 386 | .A 387 | &OP AMID "&OP",2,L:&OP-2 388 | &OP SETC (&OP) 389 | .B 390 | AIF &YISTWO,.C 391 | &YISTWO SETB 1 392 | LDY #2 393 | &OP SETC "&OP,Y" 394 | .C 395 | STA &OP 396 | MEXIT 397 | .D 398 | STA 2+&OP 399 | MEND 400 | MACRO 401 | &LAB DEC4 &A 402 | &LAB ~SETM 403 | LDA &A 404 | BNE ~&SYSCNT 405 | DEC 2+&A 406 | ~&SYSCNT DEC &A 407 | ~RESTM 408 | MEND 409 | MACRO 410 | &LAB INC4 &A 411 | &LAB ~SETM 412 | INC &A 413 | BNE ~&SYSCNT 414 | INC 2+&A 415 | ~&SYSCNT ~RESTM 416 | MEND 417 | MACRO 418 | &LAB JCS &BP 419 | &LAB BCC *+5 420 | BRL &BP 421 | MEND 422 | MACRO 423 | &LAB LONG &A,&B 424 | LCLB &I 425 | LCLB &M 426 | &A AMID &A,1,1 427 | &M SETB ("&A"="M").OR.("&A"="m") 428 | &I SETB ("&A"="I").OR.("&A"="i") 429 | AIF C:&B=0,.A 430 | &B AMID &B,1,1 431 | &M SETB ("&B"="M").OR.("&B"="m").OR.&M 432 | &I SETB ("&B"="I").OR.("&B"="i").OR.&I 433 | .A 434 | &LAB REP #&M*32+&I*16 435 | AIF .NOT.&M,.B 436 | LONGA ON 437 | .B 438 | AIF .NOT.&I,.C 439 | LONGI ON 440 | .C 441 | MEND 442 | MACRO 443 | &LAB MOVE &AD1,&AD2,&LEN 444 | &LAB ANOP 445 | LCLB &LA 446 | LCLB &LI 447 | LCLC &C 448 | AIF C:&LEN,.A1 449 | LCLC &LEN 450 | &LEN SETC #2 451 | .A1 452 | &LA SETB S:LONGA 453 | &LI SETB S:LONGI 454 | AIF S:LONGA.AND.S:LONGI,.A 455 | REP #32*(.NOT.&LA)+16*(.NOT.&LI) 456 | LONGA ON 457 | LONGI ON 458 | .A 459 | &C AMID &LEN,1,1 460 | AIF "&C"<>"#",.D 461 | &C AMID &LEN,2,L:&LEN-1 462 | AIF &C<>2,.D 463 | &C AMID &AD1,1,1 464 | AIF "&C"<>"{",.B 465 | &AD1 AMID &AD1,2,L:&AD1-2 466 | &AD1 SETC (&AD1) 467 | .B 468 | LDA &AD1 469 | &C AMID &AD2,1,1 470 | AIF "&C"<>"{",.C 471 | &AD2 AMID &AD2,2,L:&AD2-2 472 | &AD2 SETC (&AD2) 473 | .C 474 | STA &AD2 475 | AGO .G 476 | .D 477 | &C AMID &AD1,1,1 478 | AIF "&C"="#",.F 479 | &C AMID &LEN,1,1 480 | AIF "&C"<>"{",.E 481 | &LEN AMID &LEN,2,L:&LEN-2 482 | &LEN SETC (&LEN) 483 | .E 484 | &C AMID &LEN,1,1 485 | AIF "&C"="#",.E1 486 | LDA &LEN 487 | DEC A 488 | AGO .E2 489 | .E1 490 | LDA &LEN-1 491 | .E2 492 | LDX #&AD1 493 | LDY #&AD2 494 | MVN &AD1,&AD2 495 | AGO .G 496 | .F 497 | LDA &AD1 498 | STA &AD2 499 | LDA &LEN-1 500 | LDX #&AD2 501 | LDY #&AD2+1 502 | MVN &AD2,&AD2 503 | .G 504 | AIF (&LA+&LI)=2,.I 505 | SEP #32*(.NOT.&LA)+16*(.NOT.&LI) 506 | AIF &LA,.H 507 | LONGA OFF 508 | .H 509 | AIF &LI,.I 510 | LONGI OFF 511 | .I 512 | MEND 513 | MACRO 514 | &LAB SHORT &A,&B 515 | LCLB &I 516 | LCLB &M 517 | &A AMID &A,1,1 518 | &M SETB ("&A"="M").OR.("&A"="m") 519 | &I SETB ("&A"="I").OR.("&A"="i") 520 | AIF C:&B=0,.A 521 | &B AMID &B,1,1 522 | &M SETB ("&B"="M").OR.("&B"="m").OR.&M 523 | &I SETB ("&B"="I").OR.("&B"="i").OR.&I 524 | .A 525 | &LAB SEP #&M*32+&I*16 526 | AIF .NOT.&M,.B 527 | LONGA OFF 528 | .B 529 | AIF .NOT.&I,.C 530 | LONGI OFF 531 | .C 532 | MEND 533 | MACRO 534 | &LAB LLA &AD1,&AD2 535 | &LAB ANOP 536 | LCLA &L 537 | LCLB &LA 538 | AIF S:LONGA,.A 539 | REP #%00100000 540 | LONGA ON 541 | &LA SETB 1 542 | .A 543 | LDA #&AD2 544 | &L SETA C:&AD1 545 | .B 546 | STA &AD1(&L) 547 | &L SETA &L-1 548 | AIF &L,^B 549 | LDA #^&AD2 550 | &L SETA C:&AD1 551 | .C 552 | STA 2+&AD1(&L) 553 | &L SETA &L-1 554 | AIF &L,^C 555 | AIF &LA=0,.D 556 | SEP #%00100000 557 | LONGA OFF 558 | .D 559 | MEND 560 | macro 561 | &l jeq &bp 562 | &l bne *+5 563 | brl &bp 564 | mend 565 | macro 566 | &l cmpl &n1,&n2 567 | lclb &yistwo 568 | &l ~setm 569 | ~lda.h &n1 570 | ~op.h cmp,&n2 571 | bne ~a&SYSCNT 572 | ~lda &n1 573 | ~op cmp,&n2 574 | ~a&SYSCNT anop 575 | ~restm 576 | mend 577 | -------------------------------------------------------------------------------- /time.macros: -------------------------------------------------------------------------------- 1 | macro 2 | &l ph2 &n1 3 | &l anop 4 | aif "&n1"="*",.f 5 | lclc &c 6 | &c amid &n1,1,1 7 | aif "&c"="#",.d 8 | aif s:longa=1,.a 9 | rep #%00100000 10 | .a 11 | aif "&c"<>"{",.b 12 | &c amid &n1,l:&n1,1 13 | aif "&c"<>"}",.g 14 | &n1 amid &n1,2,l:&n1-2 15 | lda (&n1) 16 | pha 17 | ago .e 18 | .b 19 | aif "&c"="<",.c 20 | lda &n1 21 | pha 22 | ago .e 23 | .c 24 | &n1 amid &n1,2,l:&n1-1 25 | pei &n1 26 | ago .e 27 | .d 28 | &n1 amid &n1,2,l:&n1-1 29 | pea &n1 30 | ago .f 31 | .e 32 | aif s:longa=1,.f 33 | sep #%00100000 34 | .f 35 | mexit 36 | .g 37 | mnote "Missing closing '}'",16 38 | mend 39 | macro 40 | &l ph4 &n1 41 | &l anop 42 | aif "&n1"="*",.f 43 | lclc &c 44 | &c amid &n1,1,1 45 | aif "&c"="#",.d 46 | aif s:longa=1,.a 47 | rep #%00100000 48 | .a 49 | aif "&c"<>"{",.b 50 | &c amid &n1,l:&n1,1 51 | aif "&c"<>"}",.g 52 | &n1 amid &n1,2,l:&n1-2 53 | ldy #2 54 | lda (&n1),y 55 | pha 56 | lda (&n1) 57 | pha 58 | ago .e 59 | .b 60 | aif "&c"<>"[",.c 61 | ldy #2 62 | lda &n1,y 63 | pha 64 | lda &n1 65 | pha 66 | ago .e 67 | .c 68 | aif "&c"<>"<",.c1 69 | &n1 amid &n1,2,l:&n1-1 70 | pei &n1+2 71 | pei &n1 72 | ago .e 73 | .c1 74 | lda &n1+2 75 | pha 76 | lda &n1 77 | pha 78 | ago .e 79 | .d 80 | &n1 amid &n1,2,l:&n1-1 81 | pea +(&n1)|-16 82 | pea &n1 83 | ago .f 84 | .e 85 | aif s:longa=1,.f 86 | sep #%00100000 87 | .f 88 | mexit 89 | .g 90 | mnote "Missing closing '}'",16 91 | mend 92 | MACRO 93 | &LAB MOVE4 &F,&T 94 | &LAB ~SETM 95 | LDA 2+&F 96 | STA 2+&T 97 | LDA &F 98 | STA &T 99 | ~RESTM 100 | MEND 101 | MACRO 102 | &lab csubroutine &parms,&work 103 | &lab anop 104 | aif c:&work,.a 105 | lclc &work 106 | &work setc 0 107 | .a 108 | gbla &totallen 109 | gbla &worklen 110 | &worklen seta &work 111 | &totallen seta 0 112 | aif c:&parms=0,.e 113 | lclc &len 114 | lclc &p 115 | lcla &i 116 | &i seta 1 117 | .b 118 | &p setc &parms(&i) 119 | &len amid &p,2,1 120 | aif "&len"=":",.c 121 | &len amid &p,1,2 122 | &p amid &p,4,l:&p-3 123 | ago .d 124 | .c 125 | &len amid &p,1,1 126 | &p amid &p,3,l:&p-2 127 | .d 128 | &p equ &totallen+4+&work 129 | &totallen seta &totallen+&len 130 | &i seta &i+1 131 | aif &i<=c:&parms,^b 132 | .e 133 | tsc 134 | aif &work=0,.f 135 | sec 136 | sbc #&work 137 | tcs 138 | .f 139 | phd 140 | tcd 141 | mend 142 | MACRO 143 | &lab creturn &r 144 | &lab anop 145 | lclc &len 146 | aif c:&r,.a 147 | lclc &r 148 | &r setc 0 149 | &len setc 0 150 | ago .h 151 | .a 152 | &len amid &r,2,1 153 | aif "&len"=":",.b 154 | &len amid &r,1,2 155 | &r amid &r,4,l:&r-3 156 | ago .c 157 | .b 158 | &len amid &r,1,1 159 | &r amid &r,3,l:&r-2 160 | .c 161 | aif &len<>2,.d 162 | ldy &r 163 | ago .h 164 | .d 165 | aif &len<>4,.e 166 | ldx &r+2 167 | ldy &r 168 | ago .h 169 | .e 170 | aif &len<>10,.g 171 | ldy #&r 172 | ldx #^&r 173 | ago .h 174 | .g 175 | mnote 'Not a valid return length',16 176 | mexit 177 | .h 178 | aif &totallen=0,.i 179 | lda &worklen+2 180 | sta &worklen+&totallen+2 181 | lda &worklen+1 182 | sta &worklen+&totallen+1 183 | .i 184 | pld 185 | tsc 186 | clc 187 | adc #&worklen+&totallen 188 | tcs 189 | aif &len=0,.j 190 | tya 191 | .j 192 | rtl 193 | mend 194 | MACRO 195 | &LAB ~SETM 196 | &LAB ANOP 197 | AIF C:&~LA,.B 198 | GBLB &~LA 199 | GBLB &~LI 200 | .B 201 | &~LA SETB S:LONGA 202 | &~LI SETB S:LONGI 203 | AIF S:LONGA.AND.S:LONGI,.A 204 | REP #32*(.NOT.&~LA)+16*(.NOT.&~LI) 205 | LONGA ON 206 | LONGI ON 207 | .A 208 | MEND 209 | MACRO 210 | &LAB ~RESTM 211 | &LAB ANOP 212 | AIF (&~LA+&~LI)=2,.I 213 | SEP #32*(.NOT.&~LA)+16*(.NOT.&~LI) 214 | AIF &~LA,.H 215 | LONGA OFF 216 | .H 217 | AIF &~LI,.I 218 | LONGI OFF 219 | .I 220 | MEND 221 | MACRO 222 | &LAB ADD4 &M1,&M2,&M3 223 | LCLB &YISTWO 224 | LCLC &C 225 | &LAB ~SETM 226 | AIF C:&M3,.A 227 | &C AMID "&M2",1,1 228 | AIF "&C"<>"#",.A 229 | &C AMID "&M1",1,1 230 | AIF "&C"="{",.A 231 | AIF "&C"="[",.A 232 | &C AMID "&M2",2,L:&M2-1 233 | AIF &C>=65536,.A 234 | CLC 235 | ~LDA &M1 236 | ~OP ADC,&M2 237 | ~STA &M1 238 | BCC ~&SYSCNT 239 | ~OP.H INC,&M1 240 | ~&SYSCNT ANOP 241 | AGO .C 242 | .A 243 | AIF C:&M3,.B 244 | LCLC &M3 245 | &M3 SETC &M1 246 | .B 247 | CLC 248 | ~LDA &M1 249 | ~OP ADC,&M2 250 | ~STA &M3 251 | ~LDA.H &M1 252 | ~OP.H ADC,&M2 253 | ~STA.H &M3 254 | .C 255 | ~RESTM 256 | MEND 257 | MACRO 258 | &LAB DIV4 &N1,&N2,&N3 259 | &LAB ~SETM 260 | PH4 &N1 261 | PH4 &N2 262 | JSL ~DIV4 263 | AIF C:&N3,.A 264 | PL4 &N1 265 | AGO .B 266 | .A 267 | PL4 &N3 268 | .B 269 | PLA 270 | PLA 271 | ~RESTM 272 | MEND 273 | MACRO 274 | &LAB MOD4 &N1,&N2,&N3 275 | &LAB ~SETM 276 | PH4 &N1 277 | PH4 &N2 278 | JSL ~MOD4 279 | PLA 280 | PLA 281 | AIF C:&N3,.A 282 | PL4 &N1 283 | AGO .B 284 | .A 285 | PL4 &N3 286 | .B 287 | ~RESTM 288 | MEND 289 | MACRO 290 | &LAB MUL4 &N1,&N2,&N3 291 | &LAB ~SETM 292 | PH4 &N1 293 | PH4 &N2 294 | JSL ~MUL4 295 | AIF C:&N3,.A 296 | PL4 &N1 297 | AGO .B 298 | .A 299 | PL4 &N3 300 | .B 301 | ~RESTM 302 | MEND 303 | MACRO 304 | &LAB SUB4 &M1,&M2,&M3 305 | LCLB &YISTWO 306 | LCLC &C 307 | &LAB ~SETM 308 | AIF C:&M3,.A 309 | &C AMID "&M2",1,1 310 | AIF "&C"<>"#",.A 311 | &C AMID "&M1",1,1 312 | AIF "&C"="{",.A 313 | AIF "&C"="[",.A 314 | &C AMID "&M2",2,L:&M2-1 315 | AIF &C>=65536,.A 316 | SEC 317 | ~LDA &M1 318 | ~OP SBC,&M2 319 | ~STA &M1 320 | BCS ~&SYSCNT 321 | ~OP.H DEC,&M1 322 | ~&SYSCNT ANOP 323 | AGO .C 324 | .A 325 | AIF C:&M3,.B 326 | LCLC &M3 327 | &M3 SETC &M1 328 | .B 329 | SEC 330 | ~LDA &M1 331 | ~OP SBC,&M2 332 | ~STA &M3 333 | ~LDA.H &M1 334 | ~OP.H SBC,&M2 335 | ~STA.H &M3 336 | .C 337 | ~RESTM 338 | MEND 339 | MACRO 340 | &LAB ~OP.H &OPC,&OP 341 | &LAB ANOP 342 | LCLC &C 343 | &C AMID "&OP",1,1 344 | AIF "&C"="[",.B 345 | AIF "&C"<>"{",.D 346 | &C AMID "&OP",L:&OP,1 347 | AIF "&C"="}",.A 348 | MNOTE "Missing closing '}'",2 349 | &OP SETC &OP} 350 | .A 351 | &OP AMID "&OP",2,L:&OP-2 352 | &OP SETC (&OP) 353 | .B 354 | AIF &YISTWO,.C 355 | &YISTWO SETB 1 356 | LDY #2 357 | &OP SETC "&OP,Y" 358 | .C 359 | &OPC &OP 360 | MEXIT 361 | .D 362 | AIF "&C"<>"#",.E 363 | &OP AMID "&OP",2,L:&OP-1 364 | &OP SETC "#^&OP" 365 | &OPC &OP 366 | MEXIT 367 | .E 368 | &OPC 2+&OP 369 | MEND 370 | MACRO 371 | &LAB ~LDA.H &OP 372 | &LAB ANOP 373 | LCLC &C 374 | &C AMID "&OP",1,1 375 | AIF "&C"="[",.B 376 | AIF "&C"<>"{",.D 377 | &C AMID "&OP",L:&OP,1 378 | AIF "&C"="}",.A 379 | MNOTE "Missing closing '}'",2 380 | &OP SETC &OP} 381 | .A 382 | &OP AMID "&OP",2,L:&OP-2 383 | &OP SETC (&OP) 384 | .B 385 | AIF &YISTWO,.C 386 | &YISTWO SETB 1 387 | LDY #2 388 | &OP SETC "&OP,Y" 389 | .C 390 | LDA &OP 391 | MEXIT 392 | .D 393 | AIF "&C"<>"#",.E 394 | &OP AMID "&OP",2,L:&OP-1 395 | &OP SETC "#^&OP" 396 | LDA &OP 397 | MEXIT 398 | .E 399 | LDA 2+&OP 400 | MEND 401 | MACRO 402 | &LAB ~STA.H &OP 403 | &LAB ANOP 404 | LCLC &C 405 | &C AMID "&OP",1,1 406 | AIF "&C"="[",.B 407 | AIF "&C"<>"{",.D 408 | &C AMID "&OP",L:&OP,1 409 | AIF "&C"="}",.A 410 | MNOTE "Missing closing '}'",2 411 | &OP SETC &OP} 412 | .A 413 | &OP AMID "&OP",2,L:&OP-2 414 | &OP SETC (&OP) 415 | .B 416 | AIF &YISTWO,.C 417 | &YISTWO SETB 1 418 | LDY #2 419 | &OP SETC "&OP,Y" 420 | .C 421 | STA &OP 422 | MEXIT 423 | .D 424 | STA 2+&OP 425 | MEND 426 | MACRO 427 | &LAB ~LDA &OP 428 | LCLC &C 429 | &C AMID "&OP",1,1 430 | AIF "&C"<>"{",.B 431 | &C AMID "&OP",L:&OP,1 432 | AIF "&C"="}",.A 433 | MNOTE "Missing closing '}'",2 434 | &OP SETC &OP} 435 | .A 436 | &OP AMID "&OP",2,L:&OP-2 437 | &OP SETC (&OP) 438 | .B 439 | &LAB LDA &OP 440 | MEND 441 | MACRO 442 | &LAB ~STA &OP 443 | LCLC &C 444 | &C AMID "&OP",1,1 445 | AIF "&C"<>"{",.B 446 | &C AMID "&OP",L:&OP,1 447 | AIF "&C"="}",.A 448 | MNOTE "Missing closing '}'",2 449 | &OP SETC &OP} 450 | .A 451 | &OP AMID "&OP",2,L:&OP-2 452 | &OP SETC (&OP) 453 | .B 454 | &LAB STA &OP 455 | MEND 456 | MACRO 457 | &LAB ~OP &OPC,&OP 458 | LCLC &C 459 | &C AMID "&OP",1,1 460 | AIF "&C"<>"{",.B 461 | &C AMID "&OP",L:&OP,1 462 | AIF "&C"="}",.A 463 | MNOTE "Missing closing '}'",2 464 | &OP SETC &OP} 465 | .A 466 | &OP AMID "&OP",2,L:&OP-2 467 | &OP SETC (&OP) 468 | .B 469 | &LAB &OPC &OP 470 | MEND 471 | MACRO 472 | &LAB INC4 &A 473 | &LAB ~SETM 474 | INC &A 475 | BNE ~&SYSCNT 476 | INC 2+&A 477 | ~&SYSCNT ~RESTM 478 | MEND 479 | MACRO 480 | &LAB LLA &AD1,&AD2 481 | &LAB ANOP 482 | LCLA &L 483 | LCLB &LA 484 | AIF S:LONGA,.A 485 | REP #%00100000 486 | LONGA ON 487 | &LA SETB 1 488 | .A 489 | LDA #&AD2 490 | &L SETA C:&AD1 491 | .B 492 | STA &AD1(&L) 493 | &L SETA &L-1 494 | AIF &L,^B 495 | LDA #^&AD2 496 | &L SETA C:&AD1 497 | .C 498 | STA 2+&AD1(&L) 499 | &L SETA &L-1 500 | AIF &L,^C 501 | AIF &LA=0,.D 502 | SEP #%00100000 503 | LONGA OFF 504 | .D 505 | MEND 506 | MACRO 507 | &LAB PL4 &N1 508 | LCLC &C 509 | &LAB ANOP 510 | AIF S:LONGA=1,.A 511 | REP #%00100000 512 | .A 513 | &C AMID &N1,1,1 514 | AIF "&C"<>"{",.B 515 | &C AMID &N1,L:&N1,1 516 | AIF "&C"<>"}",.F 517 | &N1 AMID &N1,2,L:&N1-2 518 | PLA 519 | STA (&N1) 520 | LDY #2 521 | PLA 522 | STA (&N1),Y 523 | AGO .D 524 | .B 525 | AIF "&C"<>"[",.C 526 | PLA 527 | STA &N1 528 | LDY #2 529 | PLA 530 | STA &N1,Y 531 | AGO .D 532 | .C 533 | PLA 534 | STA &N1 535 | PLA 536 | STA &N1+2 537 | .D 538 | AIF S:LONGA=1,.E 539 | SEP #%00100000 540 | .E 541 | MEXIT 542 | .F 543 | MNOTE "Missing closing '}'",16 544 | MEND 545 | MACRO 546 | &LAB _READTIMEHEX 547 | &LAB LDX #$0D03 548 | JSL $E10000 549 | MEND 550 | MACRO 551 | &LAB _GETTICK 552 | &LAB LDX #$2503 553 | JSL $E10000 554 | MEND 555 | macro 556 | &l ble &bp 557 | &l blt &bp 558 | beq &bp 559 | mend 560 | MACRO 561 | &lab _ReadBParam 562 | &lab ldx #$0C03 563 | jsl $E10000 564 | MEND 565 | macro 566 | &l long &a,&b 567 | lclb &i 568 | lclb &m 569 | &a amid &a,1,1 570 | &m setb ("&a"="M").or.("&a"="m") 571 | &i setb ("&a"="I").or.("&a"="i") 572 | aif c:&b=0,.a 573 | &b amid &b,1,1 574 | &m setb ("&b"="M").or.("&b"="m").or.&m 575 | &i setb ("&b"="I").or.("&b"="i").or.&i 576 | .a 577 | &l rep #&m*32+&i*16 578 | aif .not.&m,.b 579 | longa on 580 | .b 581 | aif .not.&i,.c 582 | longi on 583 | .c 584 | mend 585 | macro 586 | &l short &a,&b 587 | lclb &i 588 | lclb &m 589 | &a amid &a,1,1 590 | &m setb ("&a"="M").or.("&a"="m") 591 | &i setb ("&a"="I").or.("&a"="i") 592 | aif c:&b=0,.a 593 | &b amid &b,1,1 594 | &m setb ("&b"="M").or.("&b"="m").or.&m 595 | &i setb ("&b"="I").or.("&b"="i").or.&i 596 | .a 597 | &l sep #&m*32+&i*16 598 | aif .not.&m,.b 599 | longa off 600 | .b 601 | aif .not.&i,.c 602 | longi off 603 | .c 604 | mend 605 | macro 606 | &l dec4 &a 607 | &l ~setm 608 | lda &a 609 | bne ~&SYSCNT 610 | dec 2+&a 611 | ~&SYSCNT dec &a 612 | ~restm 613 | mend 614 | MACRO 615 | &LAB _INT2DEC 616 | &LAB LDX #$260B 617 | JSL $E10000 618 | MEND 619 | MACRO 620 | &lab _tiStatus 621 | &lab ldx #$0638 622 | jsl $E10000 623 | MEND 624 | MACRO 625 | &lab _tiGetTimePrefs 626 | &lab ldx #$0938 627 | jsl $E10000 628 | MEND 629 | MACRO 630 | &lab _tiOffset2TimeZoneString 631 | &lab ldx #$1138 632 | jsl $E10000 633 | MEND 634 | MACRO 635 | &lab _LongMul 636 | &lab ldx #$0C0B 637 | jsl $E10000 638 | MEND 639 | macro 640 | &l negate8 &n1 641 | &l ~setm 642 | sec 643 | ldy #0 644 | tya 645 | sbc &n1 646 | sta &n1 647 | tya 648 | sbc &n1+2 649 | sta &n1+2 650 | tya 651 | sbc &n1+4 652 | sta &n1+4 653 | tya 654 | sbc &n1+6 655 | sta &n1+6 656 | ~restm 657 | mend 658 | macro 659 | &l cmpl &n1,&n2 660 | lclb &yistwo 661 | &l ~setm 662 | ~lda.h &n1 663 | ~op.h cmp,&n2 664 | bne ~a&SYSCNT 665 | ~lda &n1 666 | ~op cmp,&n2 667 | ~a&SYSCNT anop 668 | ~restm 669 | mend 670 | -------------------------------------------------------------------------------- /toolglue.asm: -------------------------------------------------------------------------------- 1 | keep obj/toolglue 2 | mcopy toolglue.macros 3 | case on 4 | **************************************************************** 5 | * 6 | * ToolGlue - Glue routines for tools that return records 7 | * 8 | * June 1989 9 | * Mike Westerfield 10 | * 11 | * Copyright 1989, 1990, 1992 12 | * Byte Works, Inc. 13 | * 14 | **************************************************************** 15 | * 16 | * November 1992 17 | * 18 | * Parameter orders corrected. 19 | * 20 | **************************************************************** 21 | * 22 | * August 1990 23 | * 24 | * 1. Restart() has been corrected to expect a single 25 | * parameter. In the previous version of the library, 26 | * it expected the same parameter list as InitialLoad(). 27 | * 28 | * 2. All tool calls now store the tool error number returned 29 | * by the toolbox in ~toolError. 30 | * 31 | **************************************************************** 32 | * 33 | ToolGlue start dummy routine 34 | 35 | end 36 | 37 | **************************************************************** 38 | * 39 | * MiscTool - Miscellaneous tool kit 40 | * 41 | **************************************************************** 42 | * 43 | * FWEntry - Firmware Entry 44 | * 45 | * Inputs: 46 | * aRegValue, xRegValue, yRegValue - registers on entry 47 | * eModeEntryPt - call address 48 | * 49 | * Outputs: 50 | * Returns a pointer to a record with the following 51 | * structure: 52 | * 53 | * typedef struct FWRec { 54 | * int yRegExit; 55 | * int xRegExit; 56 | * int aRegExit; 57 | * int status; 58 | * } 59 | * 60 | **************************************************************** 61 | * 62 | FWEntry start 63 | addr equ 1 work pointer 64 | 65 | csubroutine (2:aRegValue,2:xRegValue,2:yRegValue,2:eModeEntryPt),4 66 | 67 | pha 68 | pha 69 | pha 70 | pha 71 | ph2 ~TOOLERROR 77 | pl2 >yRegExit 78 | pl2 >xRegExit 79 | pl2 >aRegExit 80 | pl2 >status 81 | lla addr,yRegExit 82 | 83 | creturn 4:addr 84 | 85 | yRegExit ds 2 record returned 86 | xRegExit ds 2 87 | aRegExit ds 2 88 | status ds 2 89 | end 90 | 91 | **************************************************************** 92 | * 93 | * GetAbsClamp - returns the absolute device clamp 94 | * 95 | * Outputs: 96 | * Returns a pointer to a record with the following 97 | * structure: 98 | * 99 | * typedef struct ClampRec { 100 | * int yMaxClamp; 101 | * int yMinClamp; 102 | * int xMaxClamp; 103 | * int xMinClamp; 104 | * } 105 | * 106 | **************************************************************** 107 | * 108 | GetAbsClamp start 109 | 110 | pha 111 | pha 112 | pha 113 | pha 114 | _GetAbsClamp 115 | sta >~TOOLERROR 116 | pl2 >yMaxClamp 117 | pl2 >yMinClamp 118 | pl2 >xMaxClamp 119 | pl2 >xMinClamp 120 | 121 | lda #yMaxClamp 122 | ldx #^yMaxClamp 123 | rtl 124 | 125 | yMaxClamp ds 2 record returned 126 | yMinClamp ds 2 127 | xMaxClamp ds 2 128 | xMinClamp ds 2 129 | end 130 | 131 | **************************************************************** 132 | * 133 | * GetMouseClamp - returns the mouse clamp 134 | * 135 | * Outputs: 136 | * Returns a pointer to a record with the following 137 | * structure: 138 | * 139 | * typedef struct ClampRec { 140 | * int yMaxClamp; 141 | * int yMinClamp; 142 | * int xMaxClamp; 143 | * int xMinClamp; 144 | * } 145 | * 146 | **************************************************************** 147 | * 148 | GetMouseClamp start 149 | 150 | pha 151 | pha 152 | pha 153 | pha 154 | _GetMouseClamp 155 | sta >~TOOLERROR 156 | pl2 >yMaxClamp 157 | pl2 >yMinClamp 158 | pl2 >xMaxClamp 159 | pl2 >xMinClamp 160 | 161 | lda #yMaxClamp 162 | ldx #^yMaxClamp 163 | rtl 164 | 165 | yMaxClamp ds 2 record returned 166 | yMinClamp ds 2 167 | xMaxClamp ds 2 168 | xMinClamp ds 2 169 | end 170 | 171 | **************************************************************** 172 | * 173 | * ReadMouse - return mouse statistics 174 | * 175 | * Outputs: 176 | * Returns a pointer to a record with the following 177 | * structure: 178 | * 179 | * typedef struct MouseRec { 180 | * char mouseMode; 181 | * char mouseStatus; 182 | * int yPos; 183 | * int xPos; 184 | * } 185 | * 186 | **************************************************************** 187 | * 188 | ReadMouse start 189 | 190 | pha 191 | pha 192 | pha 193 | _ReadMouse 194 | sta >~TOOLERROR 195 | pl2 >mouseMode 196 | pl2 >yPos 197 | pl2 >xPos 198 | 199 | lda #mouseMode 200 | ldx #^mouseMode 201 | rtl 202 | 203 | mouseMode ds 1 204 | mouseStatus ds 1 205 | yPos ds 2 206 | xPos ds 2 207 | end 208 | 209 | **************************************************************** 210 | * 211 | * ReadMouse2 - return mouse statistics 212 | * 213 | * Outputs: 214 | * Returns a pointer to a record with the following 215 | * structure: 216 | * 217 | * typedef struct MouseRec { 218 | * char mouseMode; 219 | * char mouseStatus; 220 | * int yPos; 221 | * int xPos; 222 | * } 223 | * 224 | **************************************************************** 225 | * 226 | ReadMouse2 start 227 | 228 | pha 229 | pha 230 | pha 231 | _ReadMouse2 232 | sta >~TOOLERROR 233 | pl2 >mouseMode 234 | pl2 >yPos 235 | pl2 >xPos 236 | 237 | lda #mouseMode 238 | ldx #^mouseMode 239 | rtl 240 | 241 | mouseMode ds 1 242 | mouseStatus ds 1 243 | yPos ds 2 244 | xPos ds 2 245 | end 246 | 247 | **************************************************************** 248 | * 249 | * ReadTimeHex - returns the time in hex format 250 | * 251 | * Outputs: 252 | * Returns a pointer to a record with the following 253 | * structure: 254 | * 255 | * typedef struct TimeRec { 256 | * char second; 257 | * char minute; 258 | * char hour; 259 | * char year; 260 | * char day; 261 | * char month; 262 | * char extra; 263 | * char weekDay; 264 | * } 265 | * 266 | **************************************************************** 267 | * 268 | ReadTimeHex start 269 | 270 | pha 271 | pha 272 | pha 273 | pha 274 | _ReadTimeHex 275 | sta >~TOOLERROR 276 | pl2 >second 277 | pl2 >hour 278 | pl2 >day 279 | pl2 >extra 280 | 281 | lda #second 282 | ldx #^second 283 | rtl 284 | 285 | second ds 1 286 | minute ds 1 287 | hour ds 1 288 | year ds 1 289 | day ds 1 290 | month ds 1 291 | extra ds 1 292 | weekDay ds 1 293 | end 294 | 295 | **************************************************************** 296 | * 297 | * IntMath - Integer Math Tool Kit 298 | * 299 | **************************************************************** 300 | * 301 | * extern LongDivRec LongDivide(); 302 | * 303 | * typedef struct LongDivRec { 304 | * Longint quotient; /* LongDivRec - Quotient from LongDiv*/ 305 | * Longint remainder; /* LongDivRec - remainder from LongDiv*/ 306 | * } 307 | * 308 | **************************************************************** 309 | * 310 | LongDivide start 311 | addr equ 1 312 | 313 | csubroutine (4:dividend,4:divisor),4 314 | 315 | tsc 316 | sec 317 | sbc #8 318 | tcs 319 | ph4 ~TOOLERROR 323 | pl4 >quotient 324 | pl4 >remainder 325 | 326 | lla addr,quotient 327 | 328 | creturn 4:addr 329 | 330 | quotient ds 4 331 | remainder ds 4 332 | end 333 | 334 | **************************************************************** 335 | * 336 | * extern LongMulRec LongMul(); 337 | * 338 | * typedef struct LongMulRec { 339 | * Longint lsResult; /* LongMulRec - Low Long of result*/ 340 | * Longint msResult; /* LongMulRec - High long of result*/ 341 | * } 342 | * 343 | **************************************************************** 344 | * 345 | LongMul start 346 | addr equ 1 347 | 348 | csubroutine (4:multiplicand,4:multiplier),4 349 | 350 | tsc 351 | sec 352 | sbc #8 353 | tcs 354 | ph4 ~TOOLERROR 358 | pl4 >lsResult 359 | pl4 >msResult 360 | 361 | lla addr,lsResult 362 | 363 | creturn 4:addr 364 | 365 | lsResult ds 4 366 | msResult ds 4 367 | end 368 | 369 | **************************************************************** 370 | * 371 | * extern IntDivRec SDivide(); 372 | * 373 | * typedef struct IntDivRec { 374 | * Integer quotient; /* IntDivRec - quotient from SDivide*/ 375 | * Integer remainder; /* IntDivRec - remainder from SDivide*/ 376 | * } IntDivRec, *IntDivRecPtr ; 377 | * 378 | **************************************************************** 379 | * 380 | SDivide start 381 | addr equ 1 382 | 383 | csubroutine (2:dividend,2:divisor),4 384 | 385 | pha 386 | pha 387 | ph2 ~TOOLERROR 391 | pl2 >quotient 392 | pl2 >remainder 393 | 394 | lla addr,quotient 395 | 396 | creturn 4:addr 397 | 398 | quotient ds 2 399 | remainder ds 2 400 | end 401 | 402 | **************************************************************** 403 | * 404 | * extern IntDivRec UDivide(); 405 | * 406 | * typedef struct IntDivRec { 407 | * Integer quotient; /* IntDivRec - quotient from SDivide*/ 408 | * Integer remainder; /* IntDivRec - remainder from SDivide*/ 409 | * } IntDivRec, *IntDivRecPtr ; 410 | * 411 | **************************************************************** 412 | * 413 | UDivide start 414 | addr equ 1 415 | 416 | csubroutine (2:dividend,2:divisor),4 417 | 418 | pha 419 | pha 420 | ph2 ~TOOLERROR 424 | pl2 >quotient 425 | pl2 >remainder 426 | 427 | lla addr,quotient 428 | 429 | creturn 4:addr 430 | 431 | quotient ds 2 432 | remainder ds 2 433 | end 434 | 435 | **************************************************************** 436 | * 437 | * Loader 438 | * 439 | **************************************************************** 440 | * 441 | * extern InitialLoadOutputRec InitialLoad(); 442 | * 443 | * typedef struct InitialLoadOutputRec { 444 | * Word userID; 445 | * Pointer startAddr; 446 | * Word dPageAddr; 447 | * Word buffSize; 448 | * } 449 | * 450 | **************************************************************** 451 | * 452 | InitialLoad start 453 | 454 | addr equ 1 455 | 456 | csubroutine (2:uID,4:stAddr,2:dpAddr),4 457 | 458 | tsc 459 | sec 460 | sbc #10 461 | tcs 462 | ph2 ~TOOLERROR 467 | pl2 >userID 468 | pl4 >startAddr 469 | pl2 >dPageAddr 470 | pl2 >buffSize 471 | 472 | lla addr,userID 473 | 474 | creturn 4:addr 475 | 476 | userID ds 2 477 | startAddr ds 4 478 | dPageAddr ds 2 479 | buffSize ds 2 480 | end 481 | 482 | **************************************************************** 483 | * 484 | * extern InitialLoadOutputRec InitialLoad2(); 485 | * 486 | * typedef struct InitialLoadOutputRec { 487 | * Word buffSize; 488 | * Word dPageAddr; 489 | * Pointer startAddr; 490 | * Word userID; 491 | * } 492 | * 493 | **************************************************************** 494 | * 495 | InitialLoad2 start 496 | 497 | addr equ 1 498 | 499 | csubroutine (2:uID,4:buffAddr,2:flagWord,2:inputType),4 500 | 501 | tsc 502 | sec 503 | sbc #10 504 | tcs 505 | ph2 ~TOOLERROR 511 | pl2 >userID 512 | pl4 >startAddr 513 | pl2 >dPageAddr 514 | pl2 >buffSize 515 | 516 | lla addr,userID 517 | 518 | creturn 4:addr 519 | 520 | userID ds 2 521 | startAddr ds 4 522 | dPageAddr ds 2 523 | buffSize ds 2 524 | end 525 | 526 | **************************************************************** 527 | * 528 | * extern LoadSegNameOut LoadSegName(); 529 | * 530 | * typedef struct LoadSegNameOut { 531 | * Pointer segAddr; 532 | * Word userID; 533 | * Word fileNum; 534 | * Word segNum; 535 | * } 536 | * 537 | **************************************************************** 538 | * 539 | LoadSegName start 540 | 541 | addr equ 1 542 | 543 | csubroutine (2:uID,4:fName,4:sName),4 544 | 545 | tsc 546 | sec 547 | sbc #10 548 | tcs 549 | ph2 ~TOOLERROR 554 | pl4 >segAddr 555 | pl2 >userID 556 | pl2 >fileNum 557 | pl2 >segNum 558 | 559 | lla addr,segAddr 560 | 561 | creturn 4:addr 562 | 563 | segAddr ds 4 564 | userID ds 2 565 | fileNum ds 2 566 | segNum ds 2 567 | end 568 | 569 | **************************************************************** 570 | * 571 | * extern InitialLoadOutputRec Restart(); 572 | * 573 | * typedef struct InitialLoadOutputRec { 574 | * Word userID; 575 | * Pointer startAddr; 576 | * Word dPageAddr; 577 | * Word buffSize; 578 | * } 579 | * 580 | **************************************************************** 581 | * 582 | Restart start 583 | 584 | addr equ 1 585 | 586 | csubroutine (2:uID),4 587 | 588 | tsc 589 | sec 590 | sbc #10 591 | tcs 592 | ph2 ~TOOLERROR 595 | pl2 >userID 596 | pl4 >startAddr 597 | pl2 >dPageAddr 598 | pl2 >buffSize 599 | 600 | lla addr,userID 601 | 602 | creturn 4:addr 603 | 604 | userID ds 2 605 | startAddr ds 4 606 | dPageAddr ds 2 607 | buffSize ds 2 608 | end 609 | 610 | **************************************************************** 611 | * 612 | * extern UnloadSegOutRec UnloadSeg(); 613 | * 614 | * typedef struct UnloadSegOutRec { 615 | * Word userID; 616 | * Word fileNum; 617 | * Word segNum; 618 | * } UnloadSegOutRec, *UnloadSegOutRecPtr ; 619 | * 620 | **************************************************************** 621 | * 622 | UnloadSeg start 623 | 624 | addr equ 1 625 | 626 | csubroutine (4:segaddr),4 627 | 628 | pha 629 | pha 630 | pha 631 | ph4 ~TOOLERROR 634 | pl2 >userID 635 | pl2 >fileNum 636 | pl2 >segNum 637 | 638 | lla addr,userID 639 | 640 | creturn 4:addr 641 | 642 | userID ds 2 643 | fileNum ds 2 644 | segNum ds 2 645 | end 646 | 647 | **************************************************************** 648 | * 649 | * midiSynth - MIDI Synth Tool Kit 650 | * 651 | **************************************************************** 652 | * 653 | * extern LongDivRec LongDivide(); 654 | * 655 | * typedef struct LongDivRec { 656 | * Longint quotient; /* LongDivRec - Quotient from LongDiv*/ 657 | * Longint remainder; /* LongDivRec - remainder from LongDiv*/ 658 | * } 659 | * 660 | **************************************************************** 661 | * 662 | GetMSData start 663 | 664 | csubroutine (4:reserved,4:DP),0 665 | 666 | tsc 667 | sec 668 | sbc #8 669 | tcs 670 | _GetMSData 671 | sta >~TOOLERROR 672 | ldy #2 673 | pla 674 | sta [DP] 675 | pla 676 | sta [DP],Y 677 | pla 678 | sta [reserved] 679 | pla 680 | sta [reserved],Y 681 | 682 | creturn 683 | end 684 | 685 | **************************************************************** 686 | * 687 | * Note Sequencer 688 | * 689 | **************************************************************** 690 | * 691 | * extern LocRec GetLoc(); 692 | * 693 | * typedef struct LocRec { 694 | * Word curPhraseItem; 695 | * Word curPattItem; 696 | * Word curLevel; 697 | * } LocRec, *LocRecPtr, **LocRecHndl; 698 | * 699 | **************************************************************** 700 | * 701 | GetLoc start 702 | 703 | pha 704 | pha 705 | pha 706 | _GetLoc 707 | sta >~TOOLERROR 708 | pl2 >curLevel 709 | pl2 >curPattItem 710 | pl2 >curPhraseItem 711 | lda #curPhraseItem 712 | ldx #^curPhraseItem 713 | rtl 714 | 715 | curPhraseItem ds 2 716 | curPattItem ds 2 717 | curLevel ds 2 718 | end 719 | 720 | **************************************************************** 721 | * 722 | * TextTools 723 | * 724 | **************************************************************** 725 | * 726 | * extern TxtMaskRec GetErrGlobals(); 727 | * 728 | * typedef struct TxtMaskRec { 729 | * Word orMask; 730 | * Word andMask; 731 | * } TxtMaskRec, *TxtMaskRecPtr, **TxtMaskRecHndl ; 732 | * 733 | **************************************************************** 734 | * 735 | GetErrGlobals start 736 | 737 | pha 738 | pha 739 | _GetErrGlobals 740 | sta >~TOOLERROR 741 | pl2 >orMask 742 | pl2 >andMask 743 | lda #orMask 744 | ldx #^orMask 745 | rtl 746 | 747 | orMask ds 2 748 | andMask ds 2 749 | end 750 | 751 | **************************************************************** 752 | * 753 | * extern DeviceRec GetErrorDevice(); 754 | * 755 | * typedef struct DeviceRec { 756 | * LongWord ptrOrSlot; /* DeviceRec - slot number or jump table ptr*/ 757 | * Word deviceType; /* DeviceRec - type of input device*/ 758 | * } DeviceRec, *DeviceRecPtr, **DeviceRecHndl ; 759 | * 760 | **************************************************************** 761 | * 762 | GetErrorDevice start 763 | 764 | pha 765 | pha 766 | pha 767 | _GetErrorDevice 768 | sta >~TOOLERROR 769 | pl4 >ptrOrSlot 770 | pl2 >deviceType 771 | lda #ptrOrSlot 772 | ldx #^ptrOrSlot 773 | rtl 774 | 775 | ptrOrSlot ds 4 776 | deviceType ds 2 777 | end 778 | 779 | **************************************************************** 780 | * 781 | * extern TxtMaskRec GetInGlobals(); 782 | * 783 | * typedef struct TxtMaskRec { 784 | * Word orMask; 785 | * Word andMask; 786 | * } TxtMaskRec, *TxtMaskRecPtr, **TxtMaskRecHndl ; 787 | * 788 | **************************************************************** 789 | * 790 | GetInGlobals start 791 | 792 | pha 793 | pha 794 | _GetInGlobals 795 | sta >~TOOLERROR 796 | pl2 >orMask 797 | pl2 >andMask 798 | lda #orMask 799 | ldx #^orMask 800 | rtl 801 | 802 | orMask ds 2 803 | andMask ds 2 804 | end 805 | 806 | **************************************************************** 807 | * 808 | * extern DeviceRec GetInputDevice(); 809 | * 810 | * typedef struct DeviceRec { 811 | * LongWord ptrOrSlot; /* DeviceRec - slot number or jump table ptr*/ 812 | * Word deviceType; /* DeviceRec - type of input device*/ 813 | * } DeviceRec, *DeviceRecPtr, **DeviceRecHndl ; 814 | * 815 | **************************************************************** 816 | * 817 | GetInputDevice start 818 | 819 | pha 820 | pha 821 | pha 822 | _GetInputDevice 823 | sta >~TOOLERROR 824 | pl4 >ptrOrSlot 825 | pl2 >deviceType 826 | lda #ptrOrSlot 827 | ldx #^ptrOrSlot 828 | rtl 829 | 830 | ptrOrSlot ds 4 831 | deviceType ds 2 832 | end 833 | 834 | **************************************************************** 835 | * 836 | * extern TxtMaskRec GetOutGlobals(); 837 | * 838 | * typedef struct TxtMaskRec { 839 | * Word orMask; 840 | * Word andMask; 841 | * } TxtMaskRec, *TxtMaskRecPtr, **TxtMaskRecHndl ; 842 | * 843 | **************************************************************** 844 | * 845 | GetOutGlobals start 846 | 847 | pha 848 | pha 849 | _GetOutGlobals 850 | sta >~TOOLERROR 851 | pl2 >orMask 852 | pl2 >andMask 853 | lda #orMask 854 | ldx #^orMask 855 | rtl 856 | 857 | orMask ds 2 858 | andMask ds 2 859 | end 860 | 861 | **************************************************************** 862 | * 863 | * extern DeviceRec GetOutputDevice(); 864 | * 865 | * typedef struct DeviceRec { 866 | * LongWord ptrOrSlot; /* DeviceRec - slot number or jump table ptr*/ 867 | * Word deviceType; /* DeviceRec - type of input device*/ 868 | * } DeviceRec, *DeviceRecPtr, **DeviceRecHndl ; 869 | * 870 | **************************************************************** 871 | * 872 | GetOutputDevice start 873 | 874 | pha 875 | pha 876 | pha 877 | _GetOutputDevice 878 | sta >~TOOLERROR 879 | pl4 >ptrOrSlot 880 | pl2 >deviceType 881 | lda #ptrOrSlot 882 | ldx #^ptrOrSlot 883 | rtl 884 | 885 | ptrOrSlot ds 4 886 | deviceType ds 2 887 | end 888 | -------------------------------------------------------------------------------- /toolglue.macros: -------------------------------------------------------------------------------- 1 | macro 2 | &l ph2 &n1 3 | &l anop 4 | aif "&n1"="*",.f 5 | lclc &c 6 | &c amid &n1,1,1 7 | aif "&c"="#",.d 8 | aif s:longa=1,.a 9 | rep #%00100000 10 | .a 11 | aif "&c"<>"{",.b 12 | &c amid &n1,l:&n1,1 13 | aif "&c"<>"}",.g 14 | &n1 amid &n1,2,l:&n1-2 15 | lda (&n1) 16 | pha 17 | ago .e 18 | .b 19 | aif "&c"="<",.c 20 | lda &n1 21 | pha 22 | ago .e 23 | .c 24 | &n1 amid &n1,2,l:&n1-1 25 | pei &n1 26 | ago .e 27 | .d 28 | &n1 amid &n1,2,l:&n1-1 29 | pea &n1 30 | ago .f 31 | .e 32 | aif s:longa=1,.f 33 | sep #%00100000 34 | .f 35 | mexit 36 | .g 37 | mnote "Missing closing '}'",16 38 | mend 39 | macro 40 | &l ph4 &n1 41 | &l anop 42 | aif "&n1"="*",.f 43 | lclc &c 44 | &c amid &n1,1,1 45 | aif "&c"="#",.d 46 | aif s:longa=1,.a 47 | rep #%00100000 48 | .a 49 | aif "&c"<>"{",.b 50 | &c amid &n1,l:&n1,1 51 | aif "&c"<>"}",.g 52 | &n1 amid &n1,2,l:&n1-2 53 | ldy #2 54 | lda (&n1),y 55 | pha 56 | lda (&n1) 57 | pha 58 | ago .e 59 | .b 60 | aif "&c"<>"[",.c 61 | ldy #2 62 | lda &n1,y 63 | pha 64 | lda &n1 65 | pha 66 | ago .e 67 | .c 68 | aif "&c"<>"<",.c1 69 | &n1 amid &n1,2,l:&n1-1 70 | pei &n1+2 71 | pei &n1 72 | ago .e 73 | .c1 74 | lda &n1+2 75 | pha 76 | lda &n1 77 | pha 78 | ago .e 79 | .d 80 | &n1 amid &n1,2,l:&n1-1 81 | pea +(&n1)|-16 82 | pea &n1 83 | ago .f 84 | .e 85 | aif s:longa=1,.f 86 | sep #%00100000 87 | .f 88 | mexit 89 | .g 90 | mnote "Missing closing '}'",16 91 | mend 92 | MACRO 93 | &LAB LLA &AD1,&AD2 94 | &LAB ANOP 95 | LCLA &L 96 | LCLB &LA 97 | AIF S:LONGA,.A 98 | REP #%00100000 99 | LONGA ON 100 | &LA SETB 1 101 | .A 102 | LDA #&AD2 103 | &L SETA C:&AD1 104 | .B 105 | STA &AD1(&L) 106 | &L SETA &L-1 107 | AIF &L,^B 108 | LDA #^&AD2 109 | &L SETA C:&AD1 110 | .C 111 | STA 2+&AD1(&L) 112 | &L SETA &L-1 113 | AIF &L,^C 114 | AIF &LA=0,.D 115 | SEP #%00100000 116 | LONGA OFF 117 | .D 118 | MEND 119 | MACRO 120 | &LAB PL2 &N1 121 | LCLC &C 122 | &LAB ANOP 123 | AIF S:LONGA=1,.A 124 | REP #%00100000 125 | .A 126 | &C AMID &N1,1,1 127 | AIF "&C"<>"{",.B 128 | &C AMID &N1,L:&N1,1 129 | AIF "&C"<>"}",.F 130 | &N1 AMID &N1,2,L:&N1-2 131 | PLA 132 | STA (&N1) 133 | AGO .D 134 | .B 135 | PLA 136 | STA &N1 137 | .D 138 | AIF S:LONGA=1,.E 139 | SEP #%00100000 140 | .E 141 | MEXIT 142 | .F 143 | MNOTE "Missing closing '}'",16 144 | MEND 145 | MACRO 146 | &LAB _READTIMEHEX 147 | &LAB LDX #$0D03 148 | JSL $E10000 149 | MEND 150 | MACRO 151 | &LAB _FWENTRY 152 | &LAB LDX #$2403 153 | JSL $E10000 154 | MEND 155 | MACRO 156 | &LAB _GETMOUSECLAMP 157 | &LAB LDX #$1D03 158 | JSL $E10000 159 | MEND 160 | MACRO 161 | &LAB _READMOUSE 162 | &LAB LDX #$1703 163 | JSL $E10000 164 | MEND 165 | MACRO 166 | &LAB _GETABSCLAMP 167 | &LAB LDX #$2B03 168 | JSL $E10000 169 | MEND 170 | MACRO 171 | &lab csubroutine &parms,&work 172 | &lab anop 173 | aif c:&work,.a 174 | lclc &work 175 | &work setc 0 176 | .a 177 | gbla &totallen 178 | gbla &worklen 179 | &worklen seta &work 180 | &totallen seta 0 181 | aif c:&parms=0,.e 182 | lclc &len 183 | lclc &p 184 | lcla &i 185 | &i seta 1 186 | .b 187 | &p setc &parms(&i) 188 | &len amid &p,2,1 189 | aif "&len"=":",.c 190 | &len amid &p,1,2 191 | &p amid &p,4,l:&p-3 192 | ago .d 193 | .c 194 | &len amid &p,1,1 195 | &p amid &p,3,l:&p-2 196 | .d 197 | &p equ &totallen+4+&work 198 | &totallen seta &totallen+&len 199 | &i seta &i+1 200 | aif &i<=c:&parms,^b 201 | .e 202 | tsc 203 | aif &work=0,.f 204 | sec 205 | sbc #&work 206 | tcs 207 | .f 208 | phd 209 | tcd 210 | mend 211 | MACRO 212 | &lab creturn &r 213 | &lab anop 214 | lclc &len 215 | aif c:&r,.a 216 | lclc &r 217 | &r setc 0 218 | &len setc 0 219 | ago .h 220 | .a 221 | &len amid &r,2,1 222 | aif "&len"=":",.b 223 | &len amid &r,1,2 224 | &r amid &r,4,l:&r-3 225 | ago .c 226 | .b 227 | &len amid &r,1,1 228 | &r amid &r,3,l:&r-2 229 | .c 230 | aif &len<>2,.d 231 | ldy &r 232 | ago .h 233 | .d 234 | aif &len<>4,.e 235 | ldx &r+2 236 | ldy &r 237 | ago .h 238 | .e 239 | aif &len<>10,.g 240 | ldy #&r 241 | ldx #^&r 242 | ago .h 243 | .g 244 | mnote 'Not a valid return length',16 245 | mexit 246 | .h 247 | aif &totallen=0,.i 248 | lda &worklen+2 249 | sta &worklen+&totallen+2 250 | lda &worklen+1 251 | sta &worklen+&totallen+1 252 | .i 253 | pld 254 | tsc 255 | clc 256 | adc #&worklen+&totallen 257 | tcs 258 | aif &len=0,.j 259 | tya 260 | .j 261 | rtl 262 | mend 263 | MACRO 264 | &LAB PL4 &N1 265 | LCLC &C 266 | &LAB ANOP 267 | AIF S:LONGA=1,.A 268 | REP #%00100000 269 | .A 270 | &C AMID &N1,1,1 271 | AIF "&C"<>"{",.B 272 | &C AMID &N1,L:&N1,1 273 | AIF "&C"<>"}",.F 274 | &N1 AMID &N1,2,L:&N1-2 275 | PLA 276 | STA (&N1) 277 | LDY #2 278 | PLA 279 | STA (&N1),Y 280 | AGO .D 281 | .B 282 | AIF "&C"<>"[",.C 283 | PLA 284 | STA &N1 285 | LDY #2 286 | PLA 287 | STA &N1,Y 288 | AGO .D 289 | .C 290 | PLA 291 | STA &N1 292 | PLA 293 | STA &N1+2 294 | .D 295 | AIF S:LONGA=1,.E 296 | SEP #%00100000 297 | .E 298 | MEXIT 299 | .F 300 | MNOTE "Missing closing '}'",16 301 | MEND 302 | MACRO 303 | &LAB _LONGDIVIDE 304 | &LAB LDX #$0D0B 305 | JSL $E10000 306 | MEND 307 | MACRO 308 | &LAB _LONGMUL 309 | &LAB LDX #$0C0B 310 | JSL $E10000 311 | MEND 312 | MACRO 313 | &LAB _SDIVIDE 314 | &LAB LDX #$0A0B 315 | JSL $E10000 316 | MEND 317 | MACRO 318 | &LAB _UDIVIDE 319 | &LAB LDX #$0B0B 320 | JSL $E10000 321 | MEND 322 | MACRO 323 | &LAB _INITIALLOAD 324 | &LAB LDX #$0911 325 | JSL $E10000 326 | MEND 327 | MACRO 328 | &LAB _RESTART 329 | &LAB LDX #$0A11 330 | JSL $E10000 331 | MEND 332 | MACRO 333 | &LAB _LOADSEGNAME 334 | &LAB LDX #$0D11 335 | JSL $E10000 336 | MEND 337 | MACRO 338 | &LAB _UNLOADSEG 339 | &LAB LDX #$0E11 340 | JSL $E10000 341 | MEND 342 | MACRO 343 | &LAB _GETLOC 344 | &LAB LDX #$0C1A 345 | JSL $E10000 346 | MEND 347 | MACRO 348 | &LAB _GETERRGLOBALS 349 | &LAB LDX #$0E0C 350 | JSL $E10000 351 | MEND 352 | MACRO 353 | &LAB _GETINGLOBALS 354 | &LAB LDX #$0C0C 355 | JSL $E10000 356 | MEND 357 | MACRO 358 | &LAB _GETINPUTDEVICE 359 | &LAB LDX #$120C 360 | JSL $E10000 361 | MEND 362 | MACRO 363 | &LAB _GETOUTGLOBALS 364 | &LAB LDX #$0D0C 365 | JSL $E10000 366 | MEND 367 | MACRO 368 | &LAB _GETOUTPUTDEVICE 369 | &LAB LDX #$130C 370 | JSL $E10000 371 | MEND 372 | MACRO 373 | &LAB _GETERRORDEVICE 374 | &LAB LDX #$140C 375 | JSL $E10000 376 | MEND 377 | MACRO 378 | &LAB _INITIALLOAD2 379 | &LAB LDX #$2011 380 | JSL $E10000 381 | MEND 382 | MACRO 383 | &lab _GetMSData 384 | &lab ldx #$1F23 385 | jsl $E10000 386 | MEND 387 | MACRO 388 | &lab _ReadMouse2 389 | &lab ldx #$3303 390 | jsl $E10000 391 | MEND 392 | -------------------------------------------------------------------------------- /uchar.asm: -------------------------------------------------------------------------------- 1 | keep obj/uchar 2 | mcopy uchar.macros 3 | case on 4 | 5 | **************************************************************** 6 | * 7 | * UChar - Unicode utilities 8 | * 9 | * This code implements conversions to and from Unicode. 10 | * It assumes the multibyte character set is Mac OS Roman. 11 | * 12 | **************************************************************** 13 | * 14 | uchar private 15 | copy equates.asm 16 | end 17 | 18 | **************************************************************** 19 | * 20 | * size_t mbrtoc16(char16_t * pc16, const char * s, size_t n, 21 | * mbstate_t * ps); 22 | * 23 | * size_t mbrtoc32(char32_t * pc32, const char * s, size_t n, 24 | * mbstate_t * ps); 25 | * 26 | * Convert a multibyte character to UTF-16 or UTF-32. 27 | * 28 | * Inputs: 29 | * pc16 or pc32 - pointer to output location 30 | * s - pointer to multibyte character 31 | * n - maximum number of bytes to examine 32 | * ps - conversion state 33 | * 34 | * Outputs: 35 | * *pc16 or *pc32 - UTF-16 or UTF-32 code unit 36 | * Returns number of bytes in multibyte character or 37 | * 0 for null character. 38 | * 39 | **************************************************************** 40 | * 41 | mbrtoc16 start 42 | clv v flag clear => doing mbrtoc16 43 | bra csub 44 | 45 | mbrtoc32 entry 46 | sep #$40 v flag set => doing mbrtoc32 47 | 48 | csub csubroutine (4:pc16,4:s,4:n,4:ps),0 49 | 50 | lda s if s == NULL 51 | ora s+2 52 | bne check_n 53 | stz n call is equivalent to 54 | stz n+2 mbrtoc16(NULL, "", 1, ps), 55 | bra ret so return 0 56 | check_n lda n if n = 0 57 | ora n+2 58 | bne getchar 59 | dec a return (size_t)(-2) 60 | sta n+2 61 | dec a 62 | sta n 63 | bra ret 64 | getchar ldy #1 assume return value is 1 65 | lda [s] load character *s 66 | and #$00ff 67 | bne set_rv if *s == '\0' 68 | dey return value is 0 69 | set_rv sty n set return value 70 | stz n+2 71 | cmp #$0080 if *s is an ASCII character 72 | blt output store it as-is 73 | asl a else 74 | and #$00FF 75 | tax 76 | lda >macRomanToUCS,x convert it to Unicode 77 | output ldx pc16 if pc16 != NULL 78 | bne storeit 79 | ldx pc16+2 80 | beq ret 81 | storeit sta [pc16] store result to *pc16 82 | bvc ret if doing mbrtoc32 83 | lda #0 84 | ldy #2 85 | sta [pc16],y store 0 as high word of result 86 | 87 | ret creturn 4:n 88 | end 89 | 90 | 91 | **************************************************************** 92 | * 93 | * size_t c16rtomb(char * s, char16_t c16, mbstate_t * ps); 94 | * 95 | * Convert a UTF-16 code unit to a multibyte character. 96 | * 97 | * Inputs: 98 | * s - pointer to output location 99 | * c16 - UTF-16 code unit 100 | * ps - conversion state 101 | * 102 | * Outputs: 103 | * *s - converted character 104 | * Returns number of bytes stored, or -1 for error. 105 | * 106 | **************************************************************** 107 | * 108 | c16rtomb start 109 | 110 | csubroutine (4:s,2:c16,4:ps),0 111 | 112 | lda s if s == NULL, call is equivalent to 113 | ora s+2 c16rtomb(internal_buf, 0, ps), 114 | beq return_1 so return 1 115 | lda c16 if c16 is an ASCII character 116 | cmp #$0080 117 | blt storeit store it as-is 118 | short I 119 | ldx #0 120 | cvt_loop lda >macRomanToUCS,x for each entry in macRomanToUCS 121 | cmp c16 if it matches c16 122 | beq gotit break and handle the mapping 123 | inx 124 | inx 125 | bne cvt_loop 126 | lda #EILSEQ if no mapping was found 127 | sta >errno errno = EILSEQ 128 | lda #-1 return -1 129 | sta s 130 | sta s+2 131 | long I 132 | bra ret 133 | gotit longi off 134 | txa if we found a mapping 135 | lsr a compute the MacRoman character 136 | ora #$0080 137 | storeit short M store the character 138 | sta [s] 139 | long M,I 140 | return_1 lda #1 return 1 141 | sta s 142 | stz s+2 143 | 144 | ret creturn 4:s 145 | end 146 | 147 | 148 | **************************************************************** 149 | * 150 | * size_t c32rtomb(char * s, char16_t c16, mbstate_t * ps); 151 | * 152 | * Convert a UTF-32 code unit to a multibyte character. 153 | * 154 | * Inputs: 155 | * s - pointer to output location 156 | * c16 - UTF-32 code unit 157 | * ps - conversion state 158 | * 159 | * Outputs: 160 | * *s - converted character 161 | * Returns number of bytes stored, or -1 for error. 162 | * 163 | **************************************************************** 164 | * 165 | c32rtomb start 166 | 167 | lda 10,s if char is outside the BMP 168 | beq fixstack 169 | lda #$FFFD substitute REPLACEMENT CHARACTER 170 | bra fs2 171 | 172 | fixstack lda 8,s adjust stack for call to c16rtomb 173 | fs2 sta 10,s 174 | lda 6,s 175 | sta 8,s 176 | lda 4,s 177 | sta 6,s 178 | lda 2,s 179 | sta 4,s 180 | pla 181 | sta 1,s 182 | jml c16rtomb do the equivalent c16rtomb call 183 | end 184 | 185 | 186 | macRomanToUCS private 187 | dc i2'$00C4, $00C5, $00C7, $00C9, $00D1, $00D6, $00DC, $00E1' 188 | dc i2'$00E0, $00E2, $00E4, $00E3, $00E5, $00E7, $00E9, $00E8' 189 | dc i2'$00EA, $00EB, $00ED, $00EC, $00EE, $00EF, $00F1, $00F3' 190 | dc i2'$00F2, $00F4, $00F6, $00F5, $00FA, $00F9, $00FB, $00FC' 191 | dc i2'$2020, $00B0, $00A2, $00A3, $00A7, $2022, $00B6, $00DF' 192 | dc i2'$00AE, $00A9, $2122, $00B4, $00A8, $2260, $00C6, $00D8' 193 | dc i2'$221E, $00B1, $2264, $2265, $00A5, $00B5, $2202, $2211' 194 | dc i2'$220F, $03C0, $222B, $00AA, $00BA, $03A9, $00E6, $00F8' 195 | dc i2'$00BF, $00A1, $00AC, $221A, $0192, $2248, $2206, $00AB' 196 | dc i2'$00BB, $2026, $00A0, $00C0, $00C3, $00D5, $0152, $0153' 197 | dc i2'$2013, $2014, $201C, $201D, $2018, $2019, $00F7, $25CA' 198 | dc i2'$00FF, $0178, $2044, $00A4, $2039, $203A, $FB01, $FB02' 199 | dc i2'$2021, $00B7, $201A, $201E, $2030, $00C2, $00CA, $00C1' 200 | dc i2'$00CB, $00C8, $00CD, $00CE, $00CF, $00CC, $00D3, $00D4' 201 | dc i2'$F8FF, $00D2, $00DA, $00DB, $00D9, $0131, $02C6, $02DC' 202 | dc i2'$00AF, $02D8, $02D9, $02DA, $00B8, $02DD, $02DB, $02C7' 203 | end 204 | -------------------------------------------------------------------------------- /uchar.macros: -------------------------------------------------------------------------------- 1 | MACRO 2 | &lab csubroutine &parms,&work 3 | &lab anop 4 | aif c:&work,.a 5 | lclc &work 6 | &work setc 0 7 | .a 8 | gbla &totallen 9 | gbla &worklen 10 | &worklen seta &work 11 | &totallen seta 0 12 | aif c:&parms=0,.e 13 | lclc &len 14 | lclc &p 15 | lcla &i 16 | &i seta 1 17 | .b 18 | &p setc &parms(&i) 19 | &len amid &p,2,1 20 | aif "&len"=":",.c 21 | &len amid &p,1,2 22 | &p amid &p,4,l:&p-3 23 | ago .d 24 | .c 25 | &len amid &p,1,1 26 | &p amid &p,3,l:&p-2 27 | .d 28 | &p equ &totallen+4+&work 29 | &totallen seta &totallen+&len 30 | &i seta &i+1 31 | aif &i<=c:&parms,^b 32 | .e 33 | tsc 34 | aif &work=0,.f 35 | sec 36 | sbc #&work 37 | tcs 38 | .f 39 | phd 40 | tcd 41 | mend 42 | MACRO 43 | &lab creturn &r 44 | &lab anop 45 | lclc &len 46 | aif c:&r,.a 47 | lclc &r 48 | &r setc 0 49 | &len setc 0 50 | ago .h 51 | .a 52 | &len amid &r,2,1 53 | aif "&len"=":",.b 54 | &len amid &r,1,2 55 | &r amid &r,4,l:&r-3 56 | ago .c 57 | .b 58 | &len amid &r,1,1 59 | &r amid &r,3,l:&r-2 60 | .c 61 | aif &len<>2,.d 62 | ldy &r 63 | ago .h 64 | .d 65 | aif &len<>4,.e 66 | ldx &r+2 67 | ldy &r 68 | ago .h 69 | .e 70 | aif &len<>10,.g 71 | ldy #&r 72 | ldx #^&r 73 | ago .h 74 | .g 75 | mnote 'Not a valid return length',16 76 | mexit 77 | .h 78 | aif &totallen=0,.i 79 | lda &worklen+2 80 | sta &worklen+&totallen+2 81 | lda &worklen+1 82 | sta &worklen+&totallen+1 83 | .i 84 | pld 85 | tsc 86 | clc 87 | adc #&worklen+&totallen 88 | tcs 89 | aif &len=0,.j 90 | tya 91 | .j 92 | rtl 93 | mend 94 | macro 95 | &l long &a,&b 96 | lclb &i 97 | lclb &m 98 | &a amid &a,1,1 99 | &m setb ("&a"="M").or.("&a"="m") 100 | &i setb ("&a"="I").or.("&a"="i") 101 | aif c:&b=0,.a 102 | &b amid &b,1,1 103 | &m setb ("&b"="M").or.("&b"="m").or.&m 104 | &i setb ("&b"="I").or.("&b"="i").or.&i 105 | .a 106 | &l rep #&m*32+&i*16 107 | aif .not.&m,.b 108 | longa on 109 | .b 110 | aif .not.&i,.c 111 | longi on 112 | .c 113 | mend 114 | macro 115 | &l short &a,&b 116 | lclb &i 117 | lclb &m 118 | &a amid &a,1,1 119 | &m setb ("&a"="M").or.("&a"="m") 120 | &i setb ("&a"="I").or.("&a"="i") 121 | aif c:&b=0,.a 122 | &b amid &b,1,1 123 | &m setb ("&b"="M").or.("&b"="m").or.&m 124 | &i setb ("&b"="I").or.("&b"="i").or.&i 125 | .a 126 | &l sep #&m*32+&i*16 127 | aif .not.&m,.b 128 | longa off 129 | .b 130 | aif .not.&i,.c 131 | longi off 132 | .c 133 | mend 134 | -------------------------------------------------------------------------------- /vars.asm: -------------------------------------------------------------------------------- 1 | keep obj/vars 2 | mcopy vars.macros 3 | case on 4 | **************************************************************** 5 | * 6 | * VARS.ASM 7 | * 8 | * This module contains the global variables used by C. When 9 | * using the large memory module, these variables are replaced by 10 | * GVARS.ASM, which places the variables in the ~GLOBALS 11 | * segment. 12 | * 13 | **************************************************************** 14 | * 15 | Dummy start (dummy root segment) 16 | 17 | copy equates.asm 18 | end 19 | 20 | **************************************************************** 21 | * 22 | * Global variables used by C 23 | * 24 | **************************************************************** 25 | * 26 | ~CVars start 27 | 28 | errno entry library error number 29 | ds 2 30 | _ownerid entry user ID (C) 31 | ~USER_ID entry user ID (Pascal, libraries) 32 | ds 2 33 | sys_nerr entry # of error messages 34 | dc i'13' 35 | _toolErr entry last error in a tool call (C) 36 | ~TOOLERROR entry last error in a tool call (Pascal) 37 | ds 2 38 | __useTimeTool entry use Time Tool in functions? 39 | ds 2 40 | end 41 | 42 | **************************************************************** 43 | * 44 | * ~InitIO - initialize the standard I/O files 45 | * 46 | **************************************************************** 47 | * 48 | ~InitIO start 49 | 50 | ldx #sizeofFILE-4-2 set up the file records 51 | lb1 lda stderr+4+sizeofFILE,X 52 | sta stderr+8,X 53 | lda stdin+4+sizeofFILE,X 54 | sta stdin+8,X 55 | lda stdout+4+sizeofFILE,X 56 | sta stdout+8,X 57 | dex 58 | dex 59 | bpl lb1 60 | lla stderr,stderr+4 set up the file pointers 61 | lla stdin,stdin+4 62 | lla stdout,stdout+4 63 | rtl 64 | end 65 | 66 | **************************************************************** 67 | * 68 | * stderr - error out file 69 | * 70 | **************************************************************** 71 | * 72 | stderr start 73 | 74 | dc a4'lb1' 75 | 76 | lb1 dc a4'0' next file 77 | dc a4'0' next location to write to 78 | dc a4'0' first byte of buffer 79 | dc a4'0' end of the file buffer 80 | dc i4'0' size of the file buffer 81 | dc i4'0' count 82 | dc i'EOF,EOF' putback buffer 83 | dc i'_IONBF+_IOWRT+_IOTEXT' no buffering; allow writes; text file 84 | dc i'stderrID' error out 85 | 86 | dc a4'0' next location to write to 87 | dc a4'0' first byte of buffer 88 | dc a4'0' end of the file buffer 89 | dc i4'0' size of the file buffer 90 | dc i4'0' count 91 | dc i'EOF,EOF' putback buffer 92 | dc i'_IONBF+_IOWRT+_IOTEXT' no buffering; allow writes; text file 93 | dc i'stderrID' error out 94 | end 95 | 96 | **************************************************************** 97 | * 98 | * stdin - standard in file 99 | * 100 | **************************************************************** 101 | * 102 | stdin start 103 | 104 | dc a4'lb1' 105 | 106 | lb1 dc a4'stdout+4' next file 107 | dc a4'0' next location to write to 108 | dc a4'0' first byte of buffer 109 | dc a4'0' end of the file buffer 110 | dc i4'0' size of the file buffer 111 | dc i4'0' count 112 | dc i'EOF,EOF' putback buffer 113 | dc i'_IONBF+_IOREAD+_IOTEXT' no buffering; allow reads; text file 114 | dc i'stdinID' standard in 115 | 116 | dc a4'0' next location to write to 117 | dc a4'0' first byte of buffer 118 | dc a4'0' end of the file buffer 119 | dc i4'0' size of the file buffer 120 | dc i4'0' count 121 | dc i'EOF,EOF' putback buffer 122 | dc i'_IONBF+_IOREAD+_IOTEXT' no buffering; allow reads; text file 123 | dc i'stdinID' standard in 124 | end 125 | 126 | **************************************************************** 127 | * 128 | * stdout - standard out file 129 | * 130 | **************************************************************** 131 | * 132 | stdout start 133 | 134 | dc a4'lb1' 135 | 136 | lb1 dc a4'stderr+4' next file 137 | dc a4'0' next location to write to 138 | dc a4'0' first byte of buffer 139 | dc a4'0' end of the file buffer 140 | dc i4'0' size of the file buffer 141 | dc i4'0' count 142 | dc i'EOF,EOF' putback buffer 143 | dc i'_IONBF+_IOWRT+_IOTEXT' no buffering; allow writes; text file 144 | dc i'stdoutID' standard out 145 | 146 | dc a4'0' next location to write to 147 | dc a4'0' first byte of buffer 148 | dc a4'0' end of the file buffer 149 | dc i4'0' size of the file buffer 150 | dc i4'0' count 151 | dc i'EOF,EOF' putback buffer 152 | dc i'_IONBF+_IOWRT+_IOTEXT' no buffering; allow writes; text file 153 | dc i'stdoutID' standard out 154 | end 155 | -------------------------------------------------------------------------------- /vars.macros: -------------------------------------------------------------------------------- 1 | MACRO 2 | &LAB LLA &AD1,&AD2 3 | &LAB ANOP 4 | LCLA &L 5 | LCLB &LA 6 | AIF S:LONGA,.A 7 | REP #%00100000 8 | LONGA ON 9 | &LA SETB 1 10 | .A 11 | LDA #&AD2 12 | &L SETA C:&AD1 13 | .B 14 | STA &AD1(&L) 15 | &L SETA &L-1 16 | AIF &L,^B 17 | LDA #^&AD2 18 | &L SETA C:&AD1 19 | .C 20 | STA 2+&AD1(&L) 21 | &L SETA &L-1 22 | AIF &L,^C 23 | AIF &LA=0,.D 24 | SEP #%00100000 25 | LONGA OFF 26 | .D 27 | MEND 28 | --------------------------------------------------------------------------------