Rev 922 | Details | Compare with Previous | Last modification | View Log
| Rev | Author | Line No. | Line |
|---|---|---|---|
| 630 | alone | 1 | DEVICE ZXSPECTRUM128 |
| 2 | include "../_sdk/sys_h.asm" |
||
| 3 | include "8080.asm" |
||
| 4 | |||
| 5 | ; |
||
| 6 | ; Main source driver for CC2.ASM: |
||
| 7 | ; |
||
| 8 | |||
| 9 | ;page 76 |
||
| 10 | ;title 'CC2.ASM v1.6 3/86' |
||
| 11 | |||
| 12 | true: equ 0ffffh |
||
| 13 | false: equ not true |
||
| 14 | |||
| 15 | ZSYSTEM equ true |
||
| 16 | SLRMAC: equ true;false |
||
| 17 | LASM: equ not SLRMAC |
||
| 18 | |||
| 19 | trs80: equ false ;true if TRS-80 (org 4200h) version |
||
| 20 | |||
| 21 | ALPHA: equ false ;true for Alpha-C version |
||
| 22 | MARC: equ false ;true if MARC version |
||
| 23 | CPM: equ not MARC ;true if CPM version |
||
| 24 | |||
| 25 | if not ZSYSTEM |
||
| 26 | version: equ '6' ;the 'x' in 'v1.x' |
||
| 27 | updatn: equ 0 ;the `y' in `v1.xy' (number) |
||
| 28 | updaty: equ 0 ;the `z' in `v1.xyz', or zero if none (character) |
||
| 29 | endif |
||
| 30 | |||
| 31 | if ZSYSTEM |
||
| 32 | version: equ '2' ;the 'x' in 'vZx.yz' |
||
| 33 | updatn: equ 0 ;the `y' in `vZx.yz' (number) |
||
| 34 | updaty: equ 0 ;the `z' in `vZx.yz', or zero if none (character) |
||
| 35 | endif |
||
| 36 | |||
| 37 | debug: equ false |
||
| 38 | I80: equ true |
||
| 39 | I86: equ false |
||
| 40 | |||
| 41 | |||
| 42 | IF LASM |
||
| 43 | ;sym |
||
| 44 | ENDIF |
||
| 45 | |||
| 46 | |||
| 47 | ram: equ 0 ;start of ram area (either 0 or 4200h) for compiler |
||
| 48 | |||
| 49 | cr: equ 0dh |
||
| 50 | lf: equ 0ah |
||
| 51 | |||
| 52 | IF CPM |
||
| 53 | bdos: equ ram+5 |
||
| 632 | alone | 54 | NEDOOSMEMTOP=0xff00;bdosp: equ ram+6 |
| 630 | alone | 55 | fcb: equ ram+5ch |
| 56 | nr: equ fcb+32 |
||
| 57 | ENDIF |
||
| 58 | |||
| 59 | tbuff: equ ram+80h |
||
| 60 | extbas: equ 0015h ;external base pointer in C.CCC |
||
| 61 | |||
| 62 | fnlen: equ 12 |
||
| 63 | nestmax: equ 5 |
||
| 64 | |||
| 65 | |||
| 66 | IF CPM |
||
| 632 | alone | 67 | ;coninp: equ 1 |
| 68 | ;conout: equ 2 |
||
| 69 | ;readbuf: equ 10 |
||
| 70 | ;intcon: equ 11 |
||
| 71 | ;select: equ 14 |
||
| 630 | alone | 72 | openfil: equ 15 |
| 73 | closefil: equ 16 |
||
| 74 | delete: equ 19 |
||
| 75 | rsequen: equ 20 |
||
| 76 | wsequen: equ 21 |
||
| 77 | makfil: equ 22 |
||
| 632 | alone | 78 | ;gdisk: equ 25 |
| 630 | alone | 79 | sdma: equ 26 |
| 632 | alone | 80 | ;sguser: equ 32 |
| 630 | alone | 81 | ENDIF |
| 82 | |||
| 83 | org PROGSTART;ram+100h ;start of TPA |
||
| 84 | begin |
||
| 85 | ;IF SLRMAC |
||
| 930 | alone | 86 | include cc2a.asm |
| 87 | include cc2b.asm |
||
| 88 | include cc2c.asm |
||
| 89 | include cc2d.asm |
||
| 90 | include cc2e.asm |
||
| 683 | alone | 91 | include "../_sdk/stdio.asm" |
| 630 | alone | 92 | ;ENDIF |
| 93 | |||
| 683 | alone | 94 | ; |
| 95 | ; Initialization code, placed over table storge not used until |
||
| 96 | ; after completion of initialization |
||
| 97 | ; |
||
| 98 | |||
| 99 | c2init: |
||
| 100 | |||
| 101 | IF CPM |
||
| 102 | ld de,tbuff |
||
| 103 | ld c,sdma |
||
| 104 | call bdos ;set default DMA buffer |
||
| 105 | ENDIF |
||
| 106 | |||
| 107 | lda erasub ;bit 1 of erasub is werrs flag |
||
| 108 | ld b,a |
||
| 109 | and 2 |
||
| 110 | sta werrs ;set werrs |
||
| 111 | ld a,b |
||
| 112 | and 1 |
||
| 113 | sta erasub |
||
| 114 | |||
| 115 | |||
| 116 | ld a,1 |
||
| 117 | sta prerrs ;print out errors |
||
| 118 | sta entn |
||
| 119 | sta codflg ;enable code generation |
||
| 120 | dec a |
||
| 121 | sta errf ;no errors yet |
||
| 122 | sta prnflg ;not inside parentheses |
||
| 123 | sta modstc ;clear module nesting count |
||
| 124 | sta errsin |
||
| 125 | |||
| 126 | call clrdir ;clear 512 byte directory area |
||
| 127 | call opsin ;initailize operator stacks |
||
| 128 | call minit ;adjust macro table for -z optimizations |
||
| 129 | |||
| 130 | call readf ;read in CCI file, or copy down from hi ram |
||
| 131 | shld eofad ;set EOF address |
||
| 132 | |||
| 133 | ld hl,direc ;init directory pointer |
||
| 134 | shld dirp |
||
| 135 | |||
| 136 | lhld st-4 |
||
| 137 | push hl |
||
| 138 | ld b,3 |
||
| 139 | cc21: xor a ;compute # of entries in symbol table |
||
| 140 | ld a,h ;by dividing size of table by 8 |
||
| 141 | rra |
||
| 142 | push af |
||
| 143 | and 7fh |
||
| 144 | ld h,a |
||
| 145 | pop af |
||
| 146 | ld a,l |
||
| 147 | rra |
||
| 148 | ld l,a |
||
| 149 | dec b |
||
| 150 | jp nz,cc21 |
||
| 151 | shld stno ;and store # of entries |
||
| 152 | pop hl ;HL is size of symbol table |
||
| 153 | |||
| 154 | ld de,st ;get base of sym tab in DE |
||
| 155 | add hl,de ;now HL is base of func name tab |
||
| 156 | shld fntb |
||
| 157 | ex de,hl ;put in DE |
||
| 158 | lhld st-2 ;get length of sym tab |
||
| 159 | add hl,de ;now HL is start of CCI code |
||
| 160 | push hl ;as well as base of generated code area. Save it |
||
| 161 | shld start ;on stack and at "start" |
||
| 162 | |||
| 163 | dec h ;compute code area offset, which |
||
| 164 | dec h ; when added to a pointer to an absolute |
||
| 165 | call cmh ; location in generated code during code |
||
| 166 | shld cdao ; generation, yields final addr of that code |
||
| 167 | ; in the generated CRL file. |
||
| 168 | pop hl ;get start of CCI code area |
||
| 169 | push hl |
||
| 170 | call mvup ;lde CCI code up to high memory |
||
| 171 | shld cdp ;Save pointer to CCI code at "cdp". |
||
| 172 | pop hl ;get back code area pointer |
||
| 173 | |||
| 174 | lda eflag ;has -e option been used? |
||
| 175 | or a |
||
| 176 | jp z,cc22 ;if not, go put zeroes in the first 3 bytes of code |
||
| 177 | |||
| 178 | ld (hl),0bdh ;else stick in a famous "BD" byte to indicate |
||
| 179 | inc hl ;an explicit external address for CLINK |
||
| 180 | ex de,hl |
||
| 181 | lhld exaddr ;get the explicit external address |
||
| 182 | ex de,hl |
||
| 183 | ld (hl),e |
||
| 184 | inc hl |
||
| 185 | ld (hl),d |
||
| 186 | jp cc23 ;and rejoin the mainstream. |
||
| 187 | |||
| 188 | cc22: xor a ;fill first 3 bytes of 5th sector with zeros |
||
| 189 | ld (hl),a ;if explicit external starting address not given. |
||
| 190 | inc hl |
||
| 191 | ld (hl),a |
||
| 192 | inc hl |
||
| 193 | ld (hl),a |
||
| 194 | |||
| 195 | cc23: inc hl |
||
| 196 | ex de,hl |
||
| 197 | lhld st-6 ;get external data area size |
||
| 198 | ex de,hl ;and put it here at 4th byte of 5th sector |
||
| 199 | ld (hl),e |
||
| 200 | inc hl |
||
| 201 | ld (hl),d |
||
| 202 | inc hl |
||
| 203 | shld codp ;save code area pointer |
||
| 204 | |||
| 205 | ld hl,lblt ;Initialize label table |
||
| 206 | shld lblp |
||
| 207 | |||
| 208 | ld hl,modstk ;initialize module stack |
||
| 209 | shld modstp |
||
| 210 | |||
| 211 | call fstgs ;find the collected text strings |
||
| 212 | |||
| 213 | ld hl,ltab ;initialize logical conditional branch label table |
||
| 214 | shld ltabp ;(first 5 bytes aren't used, but why play with fire?) |
||
| 215 | |||
| 216 | ld hl,pshptb ;initialize "push optimization" table |
||
| 217 | shld pshpp |
||
| 218 | |||
| 219 | ld hl,8000h ;and "symbolic label" name (number) generator |
||
| 220 | shld lbln |
||
| 221 | |||
| 222 | ld hl,modstk ;initialize module stack |
||
| 223 | shld modstp |
||
| 224 | |||
| 225 | ld hl,0 |
||
| 226 | shld nlcnt ;initialize line count |
||
| 227 | ret |
||
| 228 | |||
| 229 | |||
| 230 | IF NOT ALPHA |
||
| 231 | s0: db 'BD Software C Compiler' |
||
| 232 | ENDIF |
||
| 233 | |||
| 234 | IF ALPHA |
||
| 235 | s0: db 'BDS Alpha-C Compiler' |
||
| 236 | ENDIF |
||
| 237 | |||
| 238 | IF NOT ZSYSTEM |
||
| 239 | db ' v1.' |
||
| 240 | db version |
||
| 241 | db updatn + '0' |
||
| 242 | ENDIF |
||
| 243 | |||
| 244 | IF ZSYSTEM |
||
| 245 | db ' (for ZCPR3) vZ' |
||
| 246 | db version |
||
| 247 | db '.' |
||
| 248 | db updatn + '0' |
||
| 249 | ENDIF |
||
| 250 | |||
| 251 | db ' (part II)+' |
||
| 252 | |||
| 253 | ; |
||
| 254 | ; Clear new directory for the CRL file about to be created: |
||
| 255 | ; |
||
| 256 | |||
| 257 | clrdir: ld bc,512 |
||
| 258 | ld hl,direc |
||
| 259 | clrdr2: ld (hl),0 |
||
| 260 | inc hl |
||
| 261 | dec bc |
||
| 262 | ld a,b |
||
| 263 | or c |
||
| 264 | jp nz,clrdr2 |
||
| 265 | ret |
||
| 266 | |||
| 267 | |||
| 268 | if 1==0 ;killed by a bug!!! |
||
| 269 | ; |
||
| 270 | ; Initialize operator stack and operand |
||
| 271 | ; information stack: |
||
| 272 | ; |
||
| 273 | |||
| 274 | opsin: push hl |
||
| 275 | ld hl,opstk |
||
| 276 | shld opstp |
||
| 277 | ld (hl),0ffh |
||
| 278 | ld hl,infstk |
||
| 279 | shld infsp |
||
| 280 | pop hl |
||
| 281 | ret |
||
| 282 | endif |
||
| 283 | |||
| 284 | ; |
||
| 285 | ; Read in the CCI file from disk, or lde it down from high |
||
| 286 | ; memory if left there by CC1: |
||
| 287 | ; |
||
| 288 | |||
| 289 | readf: lda chainf ;chained to from CC1? |
||
| 290 | or a |
||
| 291 | |||
| 292 | IF CPM |
||
| 293 | jp z,readf0 ;if not, load cci file under CP/M |
||
| 294 | ENDIF |
||
| 295 | |||
| 296 | lhld curtop ;yes. copy down to low ram |
||
| 297 | ld de,-35 |
||
| 298 | add hl,de |
||
| 299 | push hl ;save last addr + 1 |
||
| 300 | ld a,(hl) |
||
| 301 | inc hl |
||
| 302 | ld h,(hl) |
||
| 303 | ld l,a ;HL = first address |
||
| 304 | inc hl ;or rather, it does now |
||
| 305 | ld b,h |
||
| 306 | ld c,l ;BC = 1st address of text |
||
| 307 | ld a,st/256 ;make sure we have enough room... |
||
| 308 | cp b ;hi byte of symbol table area must be less |
||
| 309 | jp nc,rdf4 ;than high byte of cci code area |
||
| 310 | |||
| 311 | call cmh |
||
| 312 | pop de |
||
| 313 | add hl,de |
||
| 314 | ex de,hl ;DE = length |
||
| 315 | ld hl,st-6 ;HL = destination |
||
| 316 | rloop: ld a,(bc) |
||
| 317 | ld (hl),a |
||
| 318 | inc hl |
||
| 319 | inc bc |
||
| 320 | dec de |
||
| 321 | ld a,d |
||
| 322 | or e |
||
| 323 | jp nz,rloop |
||
| 324 | shld eofad ;save end address |
||
| 325 | ld (hl),1ah |
||
| 326 | ret |
||
| 327 | |||
| 328 | |||
| 329 | readf0: |
||
| 330 | IF CPM |
||
| 331 | ld hl,fcb+9 |
||
| 332 | ld (hl),'C' |
||
| 333 | inc hl |
||
| 334 | ld (hl),'C' |
||
| 335 | inc hl |
||
| 336 | ld (hl),'I' |
||
| 337 | |||
| 338 | call fopen |
||
| 339 | |||
| 340 | ld hl,st-6 |
||
| 341 | rdf2: call reads |
||
| 342 | jp nc,rdf2a |
||
| 343 | call fclose |
||
| 344 | ret |
||
| 345 | |||
| 346 | rdf2a: ld de,tbuff |
||
| 347 | ld b,80h |
||
| 348 | rdf3: ld a,(de) |
||
| 349 | ld (hl),a |
||
| 350 | inc hl |
||
| 351 | inc de |
||
| 352 | dec b |
||
| 353 | jp nz,rdf3 |
||
| 354 | |||
| 355 | lda curtop+1 |
||
| 356 | ld c,a |
||
| 357 | dec c |
||
| 358 | ld a,h |
||
| 359 | cp c |
||
| 360 | jp c,rdf2 |
||
| 361 | ENDIF |
||
| 362 | |||
| 363 | rdf4: ld de,stgom |
||
| 364 | call perrab |
||
| 365 | |||
| 366 | |||
| 367 | |||
| 368 | ; |
||
| 369 | ; lde the CCI code up out of the way to make room for |
||
| 370 | ; code generation: |
||
| 371 | ; |
||
| 372 | |||
| 373 | mvup: call cmh ;put -(base of cci code)... |
||
| 374 | ex de,hl ; ...into DE |
||
| 375 | lhld eofad ;end of cci code |
||
| 376 | push hl ;save end of source area |
||
| 377 | add hl,de ;end of cci code - base of cci code |
||
| 378 | inc hl ;end of code - base of code + 1 |
||
| 379 | ld b,h ;this is the length of the code; |
||
| 380 | ld c,l ;block length in BC |
||
| 381 | |||
| 382 | pop de ;DE is end of source area |
||
| 383 | |||
| 384 | lhld curtop ;HL is end of memory (destination area) |
||
| 385 | dec hl ;just below BDOS |
||
| 386 | dec hl ; but one more for good measure |
||
| 387 | |||
| 388 | mvup2: ld a,2 ;check to see if we're on a Z80 |
||
| 389 | inc a |
||
| 390 | jp pe,mvup80 |
||
| 391 | |||
| 392 | ex de,hl ;Z80. put source in HL and destination in DE |
||
| 393 | db 0edh,0b8h ;Z80 block lde |
||
| 394 | ex de,hl ;flip registers again |
||
| 395 | jp mvup3 |
||
| 396 | |||
| 397 | mvup80: ld a,(de) ;get byte of source |
||
| 398 | ld (hl),a ;lde up |
||
| 399 | dec hl ;debump dest |
||
| 400 | dec de ;and source |
||
| 401 | dec bc ;and count |
||
| 402 | ld a,b |
||
| 403 | or c |
||
| 404 | jp nz,mvup80 ;loop till done |
||
| 405 | |||
| 406 | mvup3: inc hl ;restore HL to first character of CCI code |
||
| 407 | ret ;and return with HL pointing to start of CCI code |
||
| 408 | |||
| 409 | |||
| 410 | |||
| 411 | |||
| 412 | ; |
||
| 413 | ; Find the location of the string constant table in |
||
| 414 | ; the just-read-in .CCI file: |
||
| 415 | ; |
||
| 416 | |||
| 417 | fstgs: lhld cdp |
||
| 418 | fstg1: call pascd2 |
||
| 419 | push af |
||
| 420 | cp swtcd |
||
| 421 | jp nz,fstg2 |
||
| 422 | inc hl |
||
| 423 | call igsht |
||
| 424 | call mtchp |
||
| 425 | fstg1a: ld a,(hl) |
||
| 426 | cp nlcd |
||
| 427 | inc hl |
||
| 428 | jp z,fstg1a |
||
| 429 | ld e,(hl) |
||
| 430 | ld d,0 |
||
| 431 | inc hl |
||
| 432 | add hl,de |
||
| 433 | add hl,de |
||
| 434 | add hl,de |
||
| 435 | add hl,de |
||
| 436 | inc hl |
||
| 437 | fstg2: pop af |
||
| 438 | inc hl |
||
| 439 | jp nz,fstg1 |
||
| 440 | shld stgad |
||
| 441 | ret |
||
| 442 | |||
| 443 | |||
| 444 | ; |
||
| 445 | ; The following data storge is overlayed on pass 2 initialization code: |
||
| 446 | ; |
||
| 447 | |||
| 448 | ;org c2init |
||
| 449 | |||
| 450 | opstk=c2init ;: ds 40 ;operator stack for expression evaluation |
||
| 451 | infstk=opstk+40;: ds 250 ;info stack for expression evaluation (where |
||
| 452 | ;info on each value is pushed and popped as |
||
| 453 | ;needed.) |
||
| 454 | |||
| 455 | relt=infstk+250;: ds 1600 ;relocation table |
||
| 456 | |||
| 457 | ds relt+1600-$ |
||
| 458 | |||
| 459 | lblt: ds 1700 ;label table |
||
| 460 | |||
| 461 | lbrt: ds 1600 ;label reference table |
||
| 462 | |||
| 463 | ; ds 300 |
||
| 464 | ;stack: equ $ |
||
| 465 | |||
| 466 | strsz: equ 200 |
||
| 467 | |||
| 468 | strtb: ds strsz+3 ;up to (strsz/4) intelligently handled strings |
||
| 469 | |||
| 470 | ltab: ds 200 ;logical label table |
||
| 471 | ltabp: ds 2 ;logical label table pointer |
||
| 472 | |||
| 473 | pshptb: ds 30 ;push-optimization history table |
||
| 474 | pshpp: ds 2 ;push-optimization table pointer |
||
| 475 | |||
| 476 | direc: ds 512 ;area where CRL directory is built up |
||
| 477 | endir: equ $ |
||
| 478 | |||
| 479 | ; |
||
| 480 | ; This is where the .CCI file gets loaded: |
||
| 481 | ; |
||
| 482 | |||
| 483 | ds 6 |
||
| 484 | st: equ $ |
||
| 485 | |||
| 486 | |||
| 630 | alone | 487 | ;IF LASM |
| 683 | alone | 488 | ;end |
| 630 | alone | 489 | ;ENDIF |
| 490 | |||
| 491 | end |
||
| 492 | savebin "cc2.com",begin,end-begin |
||
| 493 | |||
| 632 | alone | 494 | LABELSLIST "../../us/user.l" |