?login_element?

Subversion Repositories NedoOS

Rev

Rev 632 | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

  1. ;
  2. ; ccc.asm:
  3. ;
  4.  
  5. ;
  6. ; This is the declaration parser....
  7. ;
  8.  
  9. bst:    xor a
  10.         sta stelf
  11.         sta unflg
  12.         sta forml
  13.         sta clevb
  14.         sta sf
  15.         sta newid
  16.         inc a
  17.         sta clevt
  18.         call initst
  19.         ld hl,0
  20.         shld stor
  21.         shld stno
  22.         ld hl,st
  23.         shld stp
  24.         call initps
  25.         dec de
  26.  
  27. bst1:   inc de
  28. bst2:   call pascd
  29.         jp nz,bst2a
  30.         lda clev
  31.         or a
  32.         ret nz
  33.         lhld stor
  34.         shld extsa
  35.         ret
  36.  
  37. bst2a:  cp lbrcd        ;open curly-brace?
  38.         jp nz,bst3
  39.  
  40.         call ckabrt     ;a convenient place to check for abortion...
  41.  
  42.         lda forml       ;yes. have we been processing a formal declaration
  43.         or a            ;list?
  44.         jp nz,bst2b     ;if so, switch state to being out of formal area.
  45.  
  46.         lda clevb       ;else if still at top level, then there
  47.         or a            ; is an error here somewhere.
  48.         jp nz,bst2c     ;at top level? if not, all OK.
  49.  
  50.         ld hl,stgilc    ;if at top level, bad curly-brace encountered.
  51. fatal:  jp perrab
  52.  
  53. bst2b:  ld hl,0
  54.         shld stor
  55.  
  56. bst2c:  xor a           ;turn off formal flag
  57.         sta forml
  58.         ld hl,clevb
  59.         inc (hl)                ;bump curly count
  60.         jp bst1 ;and go for more
  61.  
  62. bst3:   cp rbrcd        ;right curly bracket?
  63.         jp nz,bst5
  64.         lda clevb       ;yes.
  65.         or a            ; were we already at top level?
  66.         jp nz,bst4
  67.         ld hl,stg12     ;if so, then error.
  68.         jp fatal
  69.  
  70. bst4:   dec a           ;debump curly-count
  71.         sta clevb
  72.         jp nz,bst1      ;and go loop if not back to top level
  73.         lda clev        ;now at top level. bump func count
  74.         inc a
  75.         sta clevt
  76.         xor a           ;set clev to zero (external)
  77.         sta clev
  78.         lhld stor       ;set local stack frame size for func just completed
  79.         ld b,h          ; processing.
  80.         ld c,l
  81.         lhld fndad      ;this is the address of where the sf size will go
  82.         inc hl
  83.         inc hl
  84.         ld (hl),c               ;well, now it is. store it.
  85.         inc hl
  86.         ld (hl),b
  87.         lhld extsa      ;and restore the external storge allocation value
  88.         shld stor       ;to the storge allocator.
  89.         jp bst1 ;and go for more external stuff.
  90.  
  91.  
  92. bst5:   call tstty      ;no. a type specifier?
  93.         jp nc,bst5a
  94.         cp regcd        ;no. "register"?
  95.         jp z,bst5b
  96.         cp shrtcd
  97.         jp nz,bst6
  98. bst5b:  push de         ;yes.
  99.         lhld nlcnt      ;ignore it.
  100.         push hl
  101.         inc de
  102.         call igsht
  103.         pop hl
  104.         shld nlcnt
  105.         pop de
  106.         call tstty      ;if not followed by type, assume "int"
  107.         jp nc,bst5z
  108.         ld a,81h        ;"int" code
  109.         ld (de),a
  110.         jp bst5a
  111.  
  112. bst5z:  ld a,0ffh       ;delete "register" code
  113.         ld (de),a
  114.         jp bst1
  115.  
  116. bst5a:  call declp      ;process declarations of this type
  117.         jp bst1 ;and loop for more text
  118.  
  119. bst6:   ld a,(de)               ;not a declaration. an identifier?
  120.         call varch
  121.         jp c,bst1               ;if not, then not interesting. look for something else
  122.         call finds      ;yes. is it in the symbol table?
  123.         jp c,bst8
  124.         lda clev        ;yes. are we processing externals?
  125.         or a
  126.         jp nz,bst6a
  127.         ld a,negone     ;if so, might be typeless function def; insert "int".
  128.         call mvtxt
  129.         ld a,81h        ;"int" code
  130.         ld (de),a
  131.         jp bst5a
  132.  
  133. bst6a:  call cknex      ;not external. make sure it isn't an external
  134.         push hl         ; redeclaration.
  135.         ld a,c          ;relde text of identifier and replace it with
  136.         sub 3           ; the special 3-byte symbol table pointer.
  137.         call mvtxt
  138.         pop hl
  139.         call bstz2
  140.         lda flev
  141.         or a
  142.         jp nz,bst1      ;ignore if already local
  143.         push de         ;else must create local instance of an identifier
  144.         ld de,st+8      ;having an external namesake...
  145.         add hl,hl
  146.         add hl,hl      
  147.         add hl,hl
  148.         add hl,hl
  149.         add hl,de
  150.         ld a,(hl)
  151.         and 1
  152.         jp nz,bst6f     ;go do it if needed.
  153.         pop de          ;else already declared locally. nothing else to do.
  154.         jp bst1 ;go process some more text
  155.  
  156. ;
  157. ; So, now we know we have a usage of a function defined
  158. ; externally... let's make an st entry for it locally:
  159. ;
  160.  
  161. bst6f:  ld de,-8
  162.         add hl,de       ;HL--> ext def.
  163.         ex de,hl
  164.         lhld stp
  165.         ld b,16
  166. bst6f1: ld a,(de)
  167.         ld (hl),a
  168.         inc hl
  169.         inc de
  170.         dec b
  171.         jp nz,bst6f1
  172.  
  173.         ld de,-8
  174.         add hl,de
  175.         ld a,(hl)
  176.         or 3
  177.         ld (hl),a
  178.         inc hl
  179.         ld a,(hl)
  180.         and 0e0h
  181.         ld b,a
  182.         lda clev
  183.         add b
  184.         ld (hl),a
  185.         inc hl
  186.         pop de
  187.         dec de
  188.         dec de
  189.         jp bstf3
  190.  
  191.  
  192. cknex:  push af
  193.         lda clev
  194.         or a
  195.         jp z,ck2
  196.         pop af
  197.         ret
  198.  
  199. ck2:    ld hl,stg15
  200.         call perr
  201.         call fsemi
  202.         pop hl
  203.         pop hl
  204.         jp bst1
  205.  
  206. bst8:   push de
  207.         lhld nlcnt
  208.         push hl
  209.         call pasvr
  210.         pop hl
  211.         shld nlcnt
  212.         pop de
  213.         cp open
  214.         jp z,bstf
  215.         call cknex
  216.         cp openb
  217.         jp z,bste
  218.         cp arrow
  219.         jp z,bste
  220. ;       cp period
  221. ;       jp nz,bst10
  222.  
  223. bste:   call bvarm      ;bad variable message
  224.         call pasvr
  225.         jp bst1
  226.  
  227. ;bst10: call bvarm
  228. ;       call bstl
  229. ;       jp bst1
  230.  
  231. bstl:   call instt
  232.         ld a,c
  233.         sub 3
  234.         sta tmpbs
  235.         call mvtxt
  236.         lda forml       ;if formal, set formal bit
  237.         rlca
  238.         rlca
  239.         and 04h
  240.         or 10h          ;always set to int type
  241.         ld (hl),a
  242.         inc hl
  243.         lda clev
  244.         or a
  245.         jp nz,bstlb
  246.  
  247. bstla:  ld hl,stg15
  248.         call perr
  249.         jp bst1
  250.  
  251. bstlb:  ld (hl),a
  252.         inc hl
  253.         push hl
  254.         lhld stor
  255.         ld b,h
  256.         ld c,l
  257.         inc hl
  258.         inc hl
  259.         shld stor
  260.  
  261. bstlc:  pop hl
  262.         call bstz
  263.         ret
  264.  
  265.  
  266. bstf:   lda clev
  267.         or a
  268.         jp nz,bstf2
  269.         call fnnt
  270.         jp bst1
  271.  
  272. bstf2:  call instt
  273.         ld a,c
  274.         sub 3
  275.         call mvtxt
  276.         ld (hl),13h
  277.         inc hl
  278.         lda clev
  279.         or a
  280.         jp z,bstla
  281.         ld (hl),a
  282.         inc hl
  283. bstf3:  push hl
  284.         lhld fnc
  285.         ld b,h
  286.         ld c,l
  287.         inc hl
  288.         shld fnc
  289.         pop hl
  290.         call bstz
  291.         jp bst1
  292.  
  293.  
  294. bstz:   ld (hl),c
  295.         inc hl
  296.         ld (hl),b
  297.         inc hl
  298.         inc hl
  299.         inc hl
  300.         inc hl
  301.         inc hl
  302.         shld stp
  303.         lhld stno
  304.         push hl
  305.         inc hl
  306.         shld stno
  307.         pop hl
  308.  
  309. bstz2:  ld a,varcd
  310.         ld (de),a
  311.         inc de
  312.         ld a,l
  313.         ld (de),a
  314.         inc de
  315.         ld a,h
  316.         ld (de),a
  317.         ret
  318.  
  319. fnnt:   push de
  320.         ld a,-1 and 255
  321.         call mvtxt
  322.         ld a,81h
  323.         jp dclp1
  324.  
  325. declp:  xor a
  326.         sta what        ;"what" defaults to variable
  327.         inc a
  328.         sta type        ;"type" defaults to int (bug fix 11/19/80)
  329.         ld a,(de)
  330.         push de
  331.         cp uncd
  332.         jp z,dclp0
  333.         cp sttcd
  334.         jp nz,dclp1
  335. dclp0:  call decs
  336.         jp dclp1c
  337.  
  338. dclp1:  sub 80h
  339.         sta type
  340.         inc de
  341.         call igsht
  342.         cp regcd        ;ignore "register" keyword
  343.         jp nz,dclp1b
  344.         inc de
  345. dclp1b: xor a
  346.         sta what
  347.         call declst
  348.  
  349. dclp1c: ld a,(de)
  350.         cp semi
  351.         jp nz,decf
  352.         pop hl
  353.         dec hl
  354. dclp2:  inc hl
  355.         ld a,(hl)
  356.         cp nlcd
  357.         jp z,dclp3
  358.         ld (hl),0ffh
  359. dclp3:  call cmphd
  360.         jp nz,dclp2
  361.         ret
  362.  
  363. ; Relde text between start of function def
  364. ; and start of formal param list:
  365.  
  366. decf:   lda lind        ;check for illegal func def of type struct or union
  367.         or a
  368.         jp nz,decf00
  369.         lda type
  370.         cp 6
  371.         jp nz,decf00
  372.  
  373.         ld hl,stgbft    ;bad function type (function cannot return a struct)
  374.         call perr
  375.        
  376. decf00: lhld opena
  377.         ex de,hl                ;put start of formal param list ptr in DE
  378.         pop hl          ;get --> start of declaration
  379. decf01: call cmphd
  380.         jp z,decf03
  381.         ld a,(hl)               ;except for newlines, that is...
  382.         cp nlcd
  383.         jp z,decf02
  384.         ld (hl),0ffh
  385. decf02: inc hl
  386.         jp decf01
  387.  
  388. decf03: ld a,-3 and 255 ;make room for function code
  389.         call mvtxt
  390.  
  391. decf0:
  392.         ld a,varcd
  393.         ld (de),a
  394.         inc de
  395.         lhld stno
  396.         dec hl
  397.         lda pdfd        ;use original st# if declared previously
  398.         or a
  399.         jp z,decf1
  400.         lhld pdfdno
  401. decf1:  ld a,l
  402.         ld (de),a
  403.         inc de
  404.         ld a,h
  405.         ld (de),a
  406.         inc de
  407.         call igsht      ;now find param list
  408.         inc de
  409.         ld a,1
  410.         sta forml       ;set formal flag
  411.         lhld stor
  412.         shld extsa      ;save external storge count
  413.         ld hl,1         ;reset local function count number
  414.         shld fnc
  415.         dec hl          ;and clear local storge allocator
  416.         shld stor
  417. decf2:  call igsht      ;scan formal parm list
  418. decf3:  cp close        ;end?
  419.         ret z           ;if so, all done
  420.         call varch      ;else legal identifier?
  421.         jp nc,decf4
  422.         ld hl,stg23     ;if not, complain
  423.         call perr
  424.         ld a,close      ;and skip rest of list
  425.         call findc
  426.         ret
  427.  
  428. decf4:  call finds      ;does identifier already exist?
  429.         jp nc,decf5
  430. decf4a: call bstl       ;no. install as simple formal int
  431.         jp decf6        ;and go for more
  432.  
  433. decf5:  lda flev        ;exists already. External in its formal
  434.         or a            ;incarnation?
  435.         jp z,decf4a     ;if so, simply ignore external one.
  436.         push hl
  437.         push bc
  438.         ld hl,stg24     ;else redeclaration error (only possibility
  439.         call bvarm2     ;is an identical id earlier in parm list)
  440.         pop bc
  441.         ld a,c
  442.         sub 3
  443.         call mvtxt
  444.         pop hl
  445.         call bstz2
  446. decf6:  inc de          ;go on to next parm
  447.         call igsht
  448.         cp comma
  449.         jp nz,decf3            
  450.         inc de
  451.         jp decf2
  452.  
  453.  
  454. ;
  455. ; Process structure declaration:
  456. ;
  457.  
  458. decs:   sta tmpsu
  459.         ld a,1
  460.         sta modaf
  461. decs0:  inc de
  462.         call igsht
  463.         cp regcd        ;ignore "register" keyword
  464.         jp z,decs0
  465.  
  466.         cp lbrcd        ;immediate structure listing?
  467.         jp z,decsl
  468.         call finds      ;if not, must be struct identifier
  469.         jp nc,decse     ;if known identifier, go handle it
  470.         call instt      ;otherwise install new struct identifier name
  471.         ld a,1
  472.         sta newid
  473.         call pasvr
  474.         jp decs1
  475.  
  476. decsl:  push de         ;if no identifier given, use a dummy name
  477.         ld de,stgdu
  478.         call instt
  479.         pop de
  480.  
  481. decs1:  lda forml       ;save state of formal, since it is meandngless
  482.         push af ;for a structure type definition
  483.         lda what
  484.         push af
  485.         ld a,2
  486.         sta what
  487.         ld hl,0
  488.         shld dmsiz
  489.         dec hl
  490.         shld size
  491.         xor a
  492.         sta forml
  493.         sta lind
  494.         sta ptfnf
  495.         call wrapup
  496.         pop af
  497.         sta what
  498.         pop af
  499.         sta forml
  500.         lhld stno
  501.         dec hl
  502.         shld size
  503.  
  504. decsf:  call igsht      ;see what follows the identifier
  505.         cp lbrcd        ;left brace?
  506.         jp z,decsd      ;if so, go handle definition
  507.         jp decsd6       ;else go process declarator list
  508.  
  509. decse:  xor a
  510.         sta newid
  511.         shld size
  512.         push hl
  513.         push de
  514.         call getsz
  515.         ex de,hl
  516.         shld strsz
  517.         pop de
  518.         pop hl
  519.         push hl
  520.         call cvtst
  521.         and 3
  522.         cp 2
  523.         jp z,decse2
  524.         pop hl
  525.         ld hl,stg28
  526.  
  527. decse1: call perr
  528.         call fsemi
  529.         ret
  530.  
  531. decse2: push hl
  532.         push de
  533.         lhld nlcnt
  534.         push hl
  535.         call pasvr     
  536.         pop hl
  537.         shld nlcnt
  538.         pop de
  539.         pop hl
  540.         cp lbrcd
  541.         jp nz,decse3
  542.  
  543.         inc hl
  544.         inc hl
  545.         inc hl
  546.         inc hl 
  547.         inc hl
  548.         ld a,(hl)
  549.         cp 255
  550.         jp z,decse3
  551.         ld hl,stg24
  552.         call bvarm2     ;"redeclaration of: name"
  553.  
  554. decse3: pop hl
  555.         call pasvr
  556.         jp decsf
  557.  
  558.  
  559. decsd:  lda forml
  560.         push af
  561.         xor a
  562.         sta forml
  563.         push hl
  564.         lhld stor
  565.         push hl
  566.         lhld mxsiz
  567.         push hl
  568.         lda stelf
  569.         push af
  570.         lda unflg
  571.         push af
  572.         ld hl,0
  573.         shld stor
  574.         shld mxsiz
  575.         ld a,1
  576.         sta stelf
  577.         xor a
  578.         sta unflg
  579.         inc de
  580.         lda tmpsu
  581.         cp uncd
  582.         jp nz,decsd2
  583.         sta unflg
  584.  
  585. decsd2: call igsht
  586.         cp rbrcd
  587.         jp z,decsd4
  588.         call tstty
  589.         jp nc,decsd3
  590.         ld hl,stg16
  591.         call perr
  592.         call fsemi
  593.         inc de
  594.         jp decsd2
  595.  
  596. decsd3: call declp
  597.         jp decsd2
  598.  
  599. decsd4: inc de
  600.         lda unflg
  601.         or a
  602.         jp z,decsd5
  603.         lhld mxsiz
  604.         shld stor
  605. decsd5: pop af
  606.         sta unflg
  607.         pop af
  608.         sta stelf
  609.         lhld stor
  610.         shld strsz
  611.         ld b,h
  612.         ld c,l
  613.         pop hl
  614.         shld mxsiz
  615.         pop hl
  616.         shld stor
  617.         pop hl
  618.         shld size
  619.         push de
  620.         call getsz
  621.         ld (hl),c
  622.         inc hl 
  623.         ld (hl),b
  624.         pop de
  625.         pop af
  626.         sta forml
  627.         xor a
  628.         sta newid       ;identifier no longer new after definition
  629.  
  630. decsd6: ld a,6
  631.         sta type
  632.         call declst
  633.         xor a
  634.         sta newid       ;clear newid flag
  635.         ret
  636.  
  637. getsz:  add hl,hl
  638.         add hl,hl
  639.         add hl,hl
  640.         add hl,hl
  641.         ld de,st+12
  642.         add hl,de
  643.         ld e,(hl)
  644.         inc hl
  645.         ld d,(hl)      
  646.         dec hl
  647.         ret
  648.  
  649.  
  650.  
  651. declst: call igsht
  652.         cp semi
  653.         ret z
  654.  
  655. decls1: lda what
  656.         push af
  657.         call dec
  658.  
  659. ;
  660. ; Check for forward references to undefined structures:
  661. ;
  662.  
  663.         lda type
  664.         cp 6
  665.         jp nz,decls0    ;structure?
  666.         lda lind        ;yes. indirection?
  667.         or a
  668.         jp nz,decls0
  669.         lda newid       ;no. brand new, undefined struct id?
  670.         or a
  671.         jp z,decls0
  672.         ld hl,stg28a    ;using undefined structure id
  673.         call perr
  674.  
  675. decls0: call igsht
  676.         cp comma
  677.         inc de
  678.         jp nz,decls2
  679.         pop af
  680.         sta what
  681.         jp decls1
  682.  
  683. decls2: dec de
  684.         pop bc  ;clean up stack
  685.         cp semi
  686.         ret z
  687.         lda what
  688.         cp 1
  689.         ret z
  690.         ld hl,stg25
  691.         call perr
  692.         call fsemi
  693.         ret
  694.  
  695. dec:    xor a
  696.         sta ptfnf
  697.         sta lind
  698.         sta sf
  699.         inc a
  700.         sta modaf
  701.         ld hl,0
  702.         shld dmsiz
  703.         shld tmpa
  704.         lhld stor
  705.         shld adrs
  706.         xor a
  707.         sta frmrf
  708.         sta pdfd
  709.         call decr
  710.         lda pdfd
  711.         or a
  712.         call z,wrapup
  713.         lda frmrf       ;was it a formal resolution?
  714.         or a
  715.         jp z,dec2
  716.         lhld savsta     ;yes. restore storge allocation count
  717.         shld stor
  718. dec2:   lda funcf
  719.         or a
  720.         ret z
  721.         lda clevt
  722.         sta clev
  723.         cp 64           ;max # of funcs specifiable in 6 bits
  724.         ret c
  725.         ld hl,stgtmf   
  726.         jp pstgab
  727.  
  728. decr:   xor a
  729.         sta funcf
  730.         call igsht
  731.         cp open
  732.         jp nz,decr1
  733.         inc de
  734.         call decr
  735.         cp close
  736.         inc de
  737.         jp z,deca
  738.         ld hl,stg16
  739.  
  740. decr0:  call perr
  741.         call fsemi
  742.         ret
  743.  
  744. decr1:  cp mulcd
  745.         jp nz,decr2
  746.         inc de
  747.         call decr
  748.         ld hl,lind
  749.         inc (hl)
  750.         ld a,(hl)
  751.         cp 4
  752.         jp c,deca
  753.         ld de,stgtmi    ;too much indirection
  754.         call perr
  755.         jp deca
  756.  
  757. decr2:  call varch
  758.         jp nc,decr3
  759.         ld hl,stg17
  760.         jp decr0
  761.  
  762. decr3:  call finds      ;symbol exist already?
  763.         jp nc,dec3a
  764.  
  765.         lda forml       ;no. are we processing formal declarations?
  766.         or a
  767.         jp z,decr3a     ;if not, no problem
  768.                         ;OK, we're definitely doing formal declarations:
  769.         lda stelf       ;processing structure definition?
  770.         or a
  771.         jp nz,decr3a    ;if so, allow it (wierd but OK, I guess...)
  772.  
  773. decr3e: ld hl,stgbfd    ;else error.
  774.         call bvarm2     ; "idendtifier not in formal list: name"
  775.         jp decr3a
  776.  
  777. dec3a:  shld pdfdno
  778.         lda clev        ;are we at external level?
  779.         or a
  780.         jp z,decr3x     ;if so, go handle that case
  781.         lda flev        ;we're local. Is identifier also an external
  782.         or a            ;variable?
  783.         jp nz,decr3z
  784.  
  785.         lda stelf       ;if in a structure def, don't look too hard...
  786.         or a
  787.         jp nz,decr3a
  788.  
  789.         lda forml       ;yes. If we're formal, bad news.
  790.         or a
  791.         jp nz,decr3e
  792.         jp decr3a       ;else just make a local instance of the identifier.
  793.  
  794. decr3z: lda stelf       ;now we know: we're local & we have a previously
  795.         or a            ; defined local identifier to process.
  796.         jp nz,dr3za     ;are we processing a structure definition?
  797.  
  798.         lda forml       ;if not, it BETTER be a formal parameter decl...
  799.         or a
  800.         jp z,dec3ze     ;if not, it is a redeclaration error.
  801.  
  802.         ld a,0          ;else must set things up specially for wrapup
  803.         sta modaf       ;make sure stp and stno aren't bumped in wrapup
  804.         inc a
  805.         sta frmrf       ;set formal resolution flag
  806.  
  807.         lhld stor       ;save current storge allocator
  808.         shld savsta     ;to be restored AFTER the wrapup
  809.  
  810.         lhld inadsv     ;get pointer to ST entry of formal parameter
  811.         dec hl
  812.         shld tempd
  813.         inc hl
  814.         inc hl
  815.         ld a,(hl)               ;get address from ST entry
  816.         inc hl
  817.         ld h,(hl)
  818.         ld l,a
  819.         shld adrs       ;make current for wrapup
  820.         jp decr4        ;and handle rest of declaration normally
  821.  
  822. dr3za:  lhld inadsv
  823.         dec hl
  824.         shld tempd
  825.         lda what
  826.         or a
  827.         jp nz,dec3ze
  828.         ld a,(hl)
  829.         and 8
  830.         jp z,dec3ze
  831.         ld a,(hl)
  832.         rlca
  833.         rlca
  834.         rlca
  835.         rlca
  836.         and 7
  837.         ld b,a
  838.         lda type
  839.         cp b
  840.         jp nz,dec3z1
  841.         inc hl
  842.         inc hl
  843.         ld c,(hl)
  844.         inc hl
  845.         ld b,(hl)
  846.         lhld stor
  847.         ld a,b
  848.         cp h
  849.         jp nz,dec3z1
  850.         ld a,c
  851.         cp l
  852.         jp nz,dec3z1
  853.         xor a
  854.         sta modaf
  855.         jp decr4
  856.  
  857. dec3ze: ld hl,stg24
  858.         call bvarm2
  859.         call fsemi
  860.         ret
  861.  
  862. dec3z2: call perr
  863.         call fsemi
  864.         ret
  865.  
  866. dec3z1: ld hl,stgbsd
  867.         jp dec3z2
  868.  
  869. decr3x: call cvtst
  870.         shld tempdp
  871.         and 3
  872.         cp 3            ;is previously declared identifier a function ref?
  873.         jp z,decr3y     ;if so, go handle as a "previously declared func def"f
  874.         ld a,(hl)               ;else is it a structure element?
  875.         and 8
  876.         jp nz,decr3z    ;if so, handle as such and let errors happen there
  877.         call dec3ze     ;else barf on it.
  878.         jp errab
  879.  
  880. decr3y: ld a,1
  881.         sta pdfd
  882.         ld a,(hl)
  883.         and 0fdh        ;change from func ref to func def
  884.         ld (hl),a
  885.         jp decr4
  886.  
  887. decr3a: call instt      ;install new identifier
  888. decr4:  lhld nlcnt
  889.         push hl
  890.         call pasvr
  891.         pop hl
  892.         cp open
  893.         jp z,decr4a
  894.         lda pdfd
  895.         or a
  896.         jp nz,dec3ze
  897.         jp deca
  898.  
  899. decr4a: ex de,hl
  900.         shld opena
  901.         ex de,hl
  902.         push hl
  903.         call mtchp
  904.         pop hl
  905.         cp semi
  906.         jp z,decr5
  907.         cp comma
  908.         jp nz,decr7
  909.  
  910. decr5:  shld nlcnt
  911.         lhld opena
  912.         ex de,hl
  913.         jp deca
  914.  
  915. decr7:  lda clev        ;found a function definition--process it
  916.         or a
  917.         jp z,decr8
  918.         ld hl,stg19
  919.         jp decr0
  920.  
  921. decr8:  ld a,1
  922.         sta funcf
  923.         sta what
  924.         shld nlcnt      ;restore line count at start of func name ident
  925.         ld hl,0
  926.         shld adrs
  927.         lhld tempd
  928.         lda pdfd
  929.         or a
  930.         jp z,decr9
  931.         lhld tempdp
  932. decr9:  shld fndad
  933.         ret
  934.  
  935. deca:   call igsht
  936.         cp open
  937.         jp nz,deca3
  938.         lda lind
  939.         or a
  940.         jp z,deca2
  941.         dec a
  942.         sta lind
  943.         ld a,1
  944.         sta ptfnf
  945.         call mtchp
  946.         ret
  947.  
  948. deca2:  ld a,3
  949.         sta what
  950.         lhld fnc
  951.         shld adrs
  952.         inc hl
  953.         shld fnc
  954.         call mtchp
  955.         ret
  956.  
  957. deca3:  cp openb
  958.         ret nz
  959.         lda lind
  960.         sta sf
  961.         ld hl,1
  962.         call gdim
  963.         shld tmpa
  964.         lda forml
  965.         or a
  966.         jp nz,deca4
  967.         lda csf
  968.         or a
  969.         jp nz,deca4
  970.  
  971. dca3a:  ld hl,stg20
  972.         call gdim1a
  973.  
  974. deca4:  call igsht
  975.         cp openb
  976.         jp z,deca5
  977.         ld hl,0ff00h
  978.         shld dmsiz
  979.         ret
  980.  
  981. deca5:  call gdim
  982.         call multa
  983.         lda csf
  984.         or a
  985.         jp z,dca3a
  986.         call igsht
  987.         cp openb
  988.         jp nz,deca6
  989.  
  990. deca5a: ld hl,stg21
  991.         call gdim1a
  992.  
  993. deca6:  shld dmsiz
  994.         ret
  995.  
  996. gdim:   inc de
  997.         xor a
  998.         sta csf
  999.         call igsht
  1000.         inc de
  1001.         cp closb
  1002.         ret z
  1003.         dec de
  1004.         ld a,1
  1005.         sta csf
  1006.         ld a,(de)
  1007.         cp concd
  1008.         jp z,gdim2
  1009.  
  1010. gdim1:  ld hl,stg22
  1011. gdim1a: call perr
  1012.         call fsemi
  1013.         pop hl
  1014.         pop hl
  1015.         ret
  1016.  
  1017. gdim2:  inc de
  1018.         ld a,(de)
  1019.         ld l,a
  1020.         inc de
  1021.         ld a,(de)
  1022.         ld h,a
  1023.         inc de
  1024.         call igsht
  1025.         cp closb
  1026.         inc de
  1027.         ret z
  1028.         jp gdim1
  1029.  
  1030.  
  1031. mult:   push de
  1032.         ld d,h
  1033.         ld e,l
  1034.         ld hl,0
  1035.  
  1036. mult2:  add hl,de
  1037.         dec bc
  1038.         ld a,b
  1039.         or c
  1040.         jp nz,mult2
  1041.         pop de
  1042.         ret
  1043.  
  1044. multa:  push hl
  1045.         ld b,h
  1046.         ld c,l
  1047.         lhld tmpa
  1048.         call mult
  1049.         shld tmpa
  1050.         pop hl
  1051.         ret
  1052.  
  1053.  
  1054. wrapup: push de
  1055.         lda what
  1056.         ld b,a
  1057.         lda forml
  1058.         add a
  1059.         add a
  1060.         add b
  1061.         ld b,a
  1062.         lda stelf
  1063.         add a
  1064.         add a
  1065.         add a
  1066.         add b
  1067.         ld b,a
  1068.         lda type
  1069.         add a
  1070.         add a
  1071.         add a
  1072.         add a
  1073.         add b
  1074.         ld b,a
  1075.         lda ptfnf
  1076.         rrca
  1077.         add b
  1078.         lhld tempd
  1079.         ld (hl),a
  1080.         inc hl
  1081.         lda lind
  1082.         rrca
  1083.         rrca
  1084.         and 0c0h
  1085.         ld b,a
  1086.         lda clev
  1087.         add b
  1088.         ld (hl),a
  1089.         inc hl
  1090.         ex de,hl
  1091.         lhld adrs
  1092.         ex de,hl
  1093.         ld (hl),e
  1094.         inc hl
  1095.         ld (hl),d
  1096.         inc hl
  1097.         ex de,hl
  1098.         lhld size
  1099.         ex de,hl
  1100.         ld (hl),e
  1101.         inc hl
  1102.         ld (hl),d
  1103.         inc hl
  1104.         ex de,hl
  1105.         lhld dmsiz
  1106.         ex de,hl
  1107.         ld (hl),e
  1108.         inc hl
  1109.         ld (hl),d
  1110.         inc hl
  1111.         lda modaf
  1112.         or a
  1113.         jp z,wrap2
  1114.         shld stp
  1115.         lhld stno
  1116.         inc hl
  1117.         shld stno
  1118. wrap2:  pop de
  1119.         lda what
  1120.         or a
  1121.         ret nz
  1122.  
  1123.         ld bc,1
  1124.         lhld tmpa
  1125.         ld a,h
  1126.         or l
  1127.         jp z,wrapf
  1128.         lda sf
  1129.         or a
  1130.         jp nz,wrapf
  1131.         lda forml
  1132.         or a
  1133.         jp nz,wrapf
  1134.         ld b,h
  1135.         ld c,l
  1136.  
  1137. wrapf:  ld h,b
  1138.         ld l,c
  1139.  
  1140.         lda lind
  1141.         or a
  1142.         ld bc,2         ;if any levels of indirection, make object size
  1143.         jp nz,wrpf3     ;equal to two
  1144.  
  1145.         lda ptfnf       ;pointer to function is a special case of indirection
  1146.         or a
  1147.         jp nz,wrpf3
  1148.        
  1149.         lda forml
  1150.         or a
  1151.         jp nz,wrpf3
  1152.         lda type
  1153.         cp 6
  1154.         jp nz,wrpf2
  1155.         push hl
  1156.         lhld strsz
  1157.         ld b,h
  1158.         ld c,l
  1159.         pop hl
  1160.         ld a,b
  1161.         cp 0ffh
  1162.         jp nz,wrpf3
  1163.         push hl
  1164.         ld hl,stg28
  1165.         call perr
  1166.         ld bc,1
  1167.         pop hl
  1168.         jp wrpf3
  1169.  
  1170. wrpf2:  dec bc
  1171.         or a
  1172.         jp z,wrpf3
  1173.         inc bc
  1174.         cp 3
  1175.         jp c,wrpf3
  1176.         inc bc
  1177.         inc bc
  1178.         cp 5
  1179.         jp c,wrpf3
  1180.         inc bc
  1181.         inc bc
  1182.         inc bc
  1183.         inc bc
  1184.  
  1185. wrpf3:  call mult
  1186.         ld b,h
  1187.         ld c,l
  1188.         lhld stor
  1189.         lda unflg
  1190.         or a
  1191.         jp z,wrpf4
  1192.         lhld mxsiz
  1193.         call max
  1194.         shld mxsiz
  1195.         ld hl,0
  1196.         jp wrpf5
  1197. wrpf4:  add hl,bc
  1198. wrpf5:  shld stor
  1199.         xor a
  1200.         sta sf
  1201.         ret
  1202.  
  1203. max:    ld a,b
  1204.         cp h
  1205.         ret c
  1206.         jp z,max2
  1207.  
  1208. max1:   ld h,b
  1209.         ld l,c
  1210.         ret
  1211.  
  1212. max2:   ld a,c
  1213.         cp l
  1214.         ret c
  1215.         ld h,b
  1216.         ld l,c
  1217.         ret
  1218.  
  1219.  
  1220. ;
  1221. ; Definitions of some scratch variables and buffers
  1222. ; used by passc: Since passc happens after bst is all
  1223. ; done, we put all passc's temp space on top of the bst
  1224. ; code:
  1225. ;
  1226.  
  1227. cntt:   equ bst         ;(ds 220)
  1228. cntp:   equ bst+220     ;(ds 2)
  1229. swtc:   equ bst+222     ;(ds 1)
  1230. swtt:   equ bst+223     ;(ds 800)
  1231. swtp:   equ bst+1023    ;(ds 2)
  1232. defp:   equ bst+1025    ;(ds 2)
  1233. defflg: equ bst+1027    ;(ds 1)
  1234. tmpnl:  equ bst+1028    ;(ds 2)
  1235. fbuf:   equ bst+1030    ;(ds 350)
  1236. ;
  1237. ; "Expendable" routines: the following code gets
  1238. ; overwritten by the symbol table after it is used...
  1239. ;
  1240.  
  1241.         ds 4
  1242. st:     equ ($+15) and 0fff0h
  1243.  
  1244.  
  1245. stg11:  db 'Illegal colon+'
  1246. stg26:  db 'Undefined label used+'
  1247. stg99:  db 'Syntax error+'
  1248. stg8:   db 'Bad constant+'
  1249. stg8a:  db 'Bad octal digit+'
  1250. stg8b:  db 'Bad decimal digit+'
  1251. stgsuf: db 'Curly-braces mismatched somewhere in this definition+'
  1252.  
  1253. ;
  1254. ; The following strings used only by "readf", so their storge
  1255. ; areas may be used by other routines afterwards...
  1256. ;
  1257.  
  1258. stg4:   db 'Disk read error+'
  1259. stgie:  db 'Cannot open ',0
  1260. stgine: db '#include files nested too deep+'
  1261. stgnua: db 'No user area prefix allowed+'
  1262. stgucc: db 'Unterminated comment begins here+'
  1263.  
  1264.         IF NOT ALPHA
  1265. stg0:   db 'BD Software C Compiler '
  1266.         ENDIF
  1267.  
  1268.         IF ZSYSTEM
  1269.         db '(for ZCPR3) '
  1270.         ENDIF
  1271.  
  1272.         IF ALPHA
  1273. stg0:   db 'BDS Alpha-C Compiler '
  1274.         ENDIF
  1275.  
  1276.         if not ZSYSTEM
  1277.         db 'v1.'
  1278.         db version
  1279.         db updatn+'0'
  1280.         endif
  1281.  
  1282.         if ZSYSTEM
  1283.         db 'vZ'
  1284.         db version
  1285.         db '.'
  1286.         db updatn+'0'
  1287.         ENDIF
  1288.  
  1289.         IF UPDATY                       ;if there is a secondary update number,
  1290.              db updaty                  ;then specify it,
  1291.              db ' '
  1292.         ENDIF
  1293.  
  1294.         IF NOT UPDATY
  1295.              db '  '
  1296.         ENDIF
  1297.  
  1298.         db '(part I)'
  1299.        
  1300.         IF PREREL
  1301.            db '  pre-release'
  1302.         ENDIF
  1303.  
  1304.         db cr,lf
  1305.  
  1306.         IF      DEMO
  1307.         db      '       ==== DEMO COPY ====    **** NOT FOR DISTRIBUTION ****'
  1308.         db cr,lf
  1309.         db      '       This compiler package is available through this store,'
  1310.         db cr,lf
  1311.         db      '       or directly from:',             cr,lf
  1312.         db      '               BD Software, Inc.',     cr,lf
  1313.         db      '               P.O. Box 2368',         cr,lf
  1314.         db      '               Cambridge, Ma. 02238',  cr,lf
  1315.         db      '               Phone: (617) 576-3828', cr,lf
  1316.         db      '               Price:    $150 (8" SSSD format)',cr,lf
  1317.         ENDIF
  1318.  
  1319.         db 0
  1320.  
  1321.         IF CPM
  1322. stg1:   db 'Usage: ',cr,lf
  1323.         db 'call c,<source_file> [-p] [-o] [-a <x>] [-d <x>]'
  1324.         ENDIF
  1325.  
  1326.         IF CPM AND NOT ALPHA
  1327.         db ' [-m <addr>]'
  1328.         ENDIF
  1329.  
  1330.         IF CPM
  1331.         db ' [-e <addr>] [-r <n>]'
  1332.         ENDIF
  1333.  
  1334.         db '+'
  1335.  
  1336. savadr: equ $           ;this is where readf will go....
  1337.  
  1338.  
  1339. ;
  1340. ; The following storage is for routines in the expendable portion of
  1341. ; the program. The sections for each (independent) pass are org-ed to
  1342. ; start at "stg4", to conserve memory
  1343. ;
  1344.  
  1345.         org stg4        ; "prep" data area:
  1346.  
  1347. deformt: ds 50          ; (prep) for scratch space later on
  1348. txbuf:  ds 200          ; (prep) scratch space
  1349. nlcsav: ds 2            ; (prep) nlcnt gets saved here while text is hacked
  1350. def2p:  ds 2            ; (prep) string table pointer for preprocessor
  1351. deftmp: ds 2            ; (prep)
  1352. dstgf:  ds 1            ; (prep)
  1353. nestl:  ds 1            ; (prep) nesting level for preprocessor
  1354. active: ds 1            ; (prep) active conditional compilation flag
  1355. didelse: ds 1           ; (prep) true if "#else" already done
  1356. parenc: ds 1            ; (prep) paren nesting count, used by "deform"
  1357.  
  1358.         org stg4        ; "passx" and "lblpr" data area:
  1359.  
  1360. opstp:  ds 2            ; (passx) op stack pointer for constant expr evaluator
  1361. opstk:  ds 30           ; (passx) operator stack for const. expr evaluator
  1362. valsp:  ds 2            ; (passx) val stack ptr for const. expr eval.
  1363. valstk: ds 50           ; (passx) val stack for const. expr. eval.
  1364. savnlc: ds 2            ; (lblpr) for saving function starting line #s
  1365.  
  1366.  
  1367. ;
  1368. ; Read in the source file from disk, process
  1369. ; #includes on the fly, recursively
  1370. ;
  1371.  
  1372.         org savadr
  1373.  
  1374. readf:  ld hl,st        ;initialize code address to follow
  1375.         ex de,hl                ;       variable-sized symbol table
  1376.         lhld stsiz
  1377.         add hl,de
  1378.         shld coda
  1379.  
  1380.         ld hl,inclstk   ;set up #include processing stack after code ends
  1381.         shld fsp
  1382.         lhld coda
  1383.         shld textp
  1384.  
  1385.         IF CPM
  1386.         xor a           ;don't put out user number on main filename
  1387.         sta udiag
  1388.         inc a           ;allow automatic ".c" tacking for main file
  1389.         sta dodotc
  1390.         ENDIF
  1391.  
  1392.         call initps
  1393.  
  1394. ;gen fcb from filename
  1395. filenameaddr=$+1
  1396.         ld de,0
  1397.         push de
  1398. readf_fspac:
  1399.         ld a,(de)
  1400.         or a
  1401.         jr z,readf_fspac_skip
  1402.         inc de
  1403.         cp ' '
  1404.         jr nz,readf_fspac
  1405.         dec de
  1406.         xor a
  1407.         ld (de),a
  1408. readf_fspac_skip
  1409.         pop de
  1410.         ld hl,fcb+1;fcb_filename ;Pointer to 11 byte buffer
  1411.         OS_PARSEFNAME
  1412.  
  1413.         ;ld hl,fcbwas
  1414.         ;ld de,fcb
  1415.         ;ld bc,FCB_sz
  1416.         ;ldir
  1417.  
  1418.         call readm
  1419.         or a            ;successful?
  1420.         jp z,errab      ;go abort if not
  1421.         ld (hl),0
  1422.         inc hl
  1423.         ld (hl),1ah
  1424.         shld eofad
  1425.         shld meofad
  1426.         ret
  1427.  
  1428. ;fcbwas
  1429. ;        db 0
  1430. ;fcbwas_filename
  1431. ;        db "ex      c  "
  1432. ;        ds fcbwas+FCB_sz-$
  1433.  
  1434. ;
  1435. ; Read in a source module from disk. Filename and user number have
  1436. ; been preset by calling routine (file info at default fcb):
  1437. ;
  1438.  
  1439. readm:  push de
  1440.         ld de,fcb
  1441.         call openg
  1442.         pop de
  1443.         jp nz,rm2               ;if no error, goto rm2
  1444.  
  1445.         IF CPM          ;try ".c" if no extension given.
  1446.         lda dodotc      ;allowing automatic ".C" tacking?
  1447.         or a
  1448.         jp z,reade      ;if not, then open simply failed.
  1449.  
  1450.         ld de,fcb+9     ;else try tacking ".C" if no extension given.
  1451.         ld a,(de)
  1452.         cp ' '
  1453.         jp nz,reade     ;if extension given, simple error.
  1454.         ld a,'C'        ;else tack on the .C extension
  1455.         ld (de),a
  1456.         jp readm        ;and go try opening it THAT way
  1457.         ENDIF
  1458.  
  1459. reade:  lda modstc      ;at top level?
  1460.         or a
  1461.         ld hl,stgie     ;"Cannot open: "
  1462.         push af
  1463.         call z,pstg
  1464.         pop af
  1465.         call nz,perr
  1466.         call prfnm      ;<filename>
  1467.         call crlf
  1468.         xor a           ;return zero to indicate failure
  1469.         lhld textp      ;return HL still valid so we don't botch up memory
  1470.         ret
  1471.  
  1472. prfnm:
  1473.         IF CPM
  1474.         lda udiag       ;printing user number as part of filename?
  1475.         or a
  1476.         jp z,prfnm2
  1477.         lda defusr
  1478.         cp 0ffh ;if default user area is always the current one,
  1479.         lda curusr      ;   don't mention it in error report
  1480.         call nz,prads   ;print decimal number and slash
  1481. prfnm2:
  1482.         ENDIF
  1483.         call pfnam
  1484.         ret
  1485.  
  1486. ;
  1487. ; Module opened OK. Set up for reading:
  1488. ;
  1489.  
  1490. rm2:    xor a           ;initialize comment nesting level count
  1491.         sta cmntf
  1492.         sta quotf       ;not in a quoted string
  1493.  
  1494.         IF CPM
  1495.         sta dodotc      ;don't append ".C" on first try
  1496.         ENDIF
  1497.  
  1498.         IF NOT ALPHA
  1499.         inc a
  1500.         ENDIF
  1501.  
  1502.         sta udiag       ;print user number in filename diagnostics from now on
  1503.         ld hl,tbuff+secsiz-1    ;set up sector buffer so the next call to
  1504.  
  1505.         IF NOT CPM
  1506.         ld hl,secbuf+secsiz-1
  1507.         ENDIF
  1508.  
  1509.         shld sptr       ;init sector pointer
  1510.  
  1511.         ld hl,0         ;clear line number for unmatched comment diagnostics
  1512.         shld nlcnt
  1513.         shld atcnt      ;clear active text line counter, also for above
  1514.  
  1515.         lhld textp
  1516.         ld (hl),modbeg  ;install module-begin code and filename in text...
  1517.         inc hl
  1518.         push hl
  1519.         call insrtm     ;install module name into text
  1520.         pop de
  1521.         call pushmn     ;push module name onto modstk
  1522.         ex de,hl       
  1523.  
  1524. rm2a:   ld a,cr
  1525.         sta lastc
  1526.  
  1527. rm3:    call getc       ;get a character
  1528.         jp c,rm3ab0     ;on EOF, go check for last-line CR and close the file
  1529.  
  1530. rm3aa:  call kludge     ;reverse cr's and lf's for some strange reason...
  1531.         ld a,c          ;always save CR's
  1532.         cp cr
  1533.         jp nz,rm3ab
  1534.  
  1535.         call bumpnl     ;bump line count
  1536.         call ckabrt     ;check once in a while for abortions
  1537.         jp storc
  1538.  
  1539. rm3ab:
  1540.         cp 1ah          ;if control-Z, check for proper final line termination
  1541.         jp nz,rm3ac
  1542.  
  1543. ;
  1544. ; Perform end-of-file consistency check, to make sure final line of the
  1545. ; file was properly terminated with a newline:
  1546. ;
  1547.  
  1548. rm3ab0: push hl         ;save text pointer
  1549. rm3ab1: dec hl
  1550.         ld a,(hl)
  1551.         cp cr
  1552.         jp z,rm3ab2     ;if found CR, last line was properly terminated...
  1553.         cp 0ffh
  1554.         jp z,rm3ab1     ;ignore FF's
  1555.         pop hl          ;else last line was NOT properly terminated. insert CR
  1556.         ld (hl),cr
  1557.         inc hl
  1558.         jp rm3ab3       ;and go close file
  1559.  
  1560. rm3ab2: pop hl
  1561. rm3ab3: call closef
  1562.         ld (hl),modend  ;module-end marker
  1563.         inc hl
  1564.         call popmn      ;pop module name off module stack
  1565.  
  1566.         lda cmntf
  1567.         or a            ;file ends in the middle of a comment?
  1568.         ld a,1          ;return success code if not
  1569.         ret z
  1570.         push hl
  1571.  
  1572.         call pfnam      ;print file name
  1573.         ld a,':'
  1574.         call outch
  1575.         ld a,' '
  1576.         call outch
  1577.  
  1578.         lhld atcnt      ;get last active line number
  1579.         call prhcs
  1580.         ld hl,stgucc    ;"UNCLOSED COMMENT" diagnostic
  1581.         call pstg
  1582.         pop hl
  1583.         xor a           ;return 0 -- error condition
  1584.         ret
  1585.  
  1586. rm3ac:  cp 0ch          ;formfeeds turn into nulls
  1587.         jp z,storff
  1588.  
  1589.         cp lf           ;so do linefeeds
  1590.         jp z,storff
  1591.  
  1592.         or a            ;nulls are totally ignored
  1593.         jp z,rm3
  1594.  
  1595.         lda cmntf
  1596.         or a            ;are we in a comment?
  1597.         jp nz,rm3ac2    ;if so, go test for in-comment conditions
  1598.  
  1599.         push hl         ;save line number as last active line number
  1600.         lhld nlcnt
  1601.         shld atcnt
  1602.         pop hl
  1603.         jp storc        ;and go save character in memory
  1604.  
  1605. rm3ac2: ld a,c          ;we're in a comment.
  1606.         cp '/'          ;have we encountered a close comment?
  1607.         jp nz,rm3a
  1608.         lda lastc
  1609.         cp '*'
  1610.         ld a,'/'
  1611.         jp nz,rm3a
  1612.         lda cmntf       ;yes. decrement comment count.
  1613.         dec a
  1614.         cp 255
  1615.         jp z,rm2a               ;don't store back if too many closes!
  1616.         sta cmntf
  1617.         jp rm2a
  1618.  
  1619. rm3a:   cp '*'          ;have we encountered another open comment?
  1620.         jp nz,rm3b
  1621.         lda lastc
  1622.         cp '/'
  1623.         ld a,'*'
  1624.         jp nz,rm3b     
  1625.         lda cnflag      ;do comments nest?
  1626.         or a
  1627.         jp z,rm2a               ;if not, ignore this new open comment.
  1628.         lda cmntf       ;yes. bump comment count.
  1629.         inc a
  1630.         sta cmntf
  1631.         jp rm2a
  1632.  
  1633. rm3b:   sta lastc       ;still in comment. keep scanning.
  1634.         jp rm3
  1635.  
  1636. storc:  ld (hl),c               ;not in a comment. store the character
  1637.        
  1638.         ld a,c
  1639.         call mapuc
  1640.         cp '#'          ;preprocessor directive?
  1641.         jp nz,rm4
  1642.         lda lastc       ;get char before "#" for later check
  1643.         sta lastc2      ;to make sure it is a CR.
  1644.         shld pndsav
  1645.         ld a,'#'
  1646. rm3r:   inc hl
  1647. rm3s:   sta lastc
  1648.         jp rm3
  1649.  
  1650. storff: ld a,0ffh
  1651.         ld (hl),a
  1652.         jp rm3r
  1653.  
  1654. rm4:    cp '"'          ;check for quote
  1655.         jp nz,rm4b
  1656.         lda quotf       ;is this a closing or opening quote?
  1657.         or a
  1658.         jp nz,rm40      ;if closing, don't check for '"' case
  1659.         lda lastc       ;was last char a single quote?
  1660.         cp ''''
  1661.         jp z,rm6
  1662. rm40:   lda quotf       ;found one. Already in a string?
  1663.         or a
  1664.         ld a,1 
  1665.         jp z,rm4a               ;if not, set the string flag
  1666.         xor a           ;else clear the string flag
  1667. rm4a:   sta quotf       ;set "in a string" flag
  1668.         ld a,'"'
  1669.         jp rm6 
  1670.  
  1671. rm4b:   cp '\'          ;check for backslash in quoted string
  1672.         jp nz,rm4c
  1673.  
  1674.         lda quotf       ;in a quoted string?
  1675.         or a
  1676.         ld a,'\'
  1677.         jp z,rm6                ;if not, ignore backslash
  1678.         inc hl
  1679.         call getcef
  1680.         cp '"'
  1681.         jp z,rm4ba
  1682.         cp '\'
  1683.         jp z,rm4ba
  1684.         jp rm3aa
  1685.  
  1686. rm4ba:  ld (hl),a
  1687.         jp rm6
  1688.  
  1689. rm4c:   cp '*'          ;have we encountered an open comment?
  1690.         jp nz,rm5
  1691.         lda lastc       ;maybe...we have a '*'
  1692.         cp '/'          ;was last character a '/'?
  1693.         ld a,'*'        ;if not, just store the '*'
  1694.         jp nz,rm6
  1695.                         ;OK, we found a '/*' sequence...
  1696.         lda quotf       ;in a quoted string?
  1697.         or a
  1698.         ld a,'*'        ;if so, don't regard the '/*' as a comment delimiter
  1699.         jp nz,rm6
  1700.  
  1701.         dec hl          ;definitely a comment delimiter. kill the '/'
  1702.         ld a,1          ;and set comment count.
  1703.         sta cmntf
  1704.         jp rm2a
  1705.  
  1706. rm5:    cp 'I'          ;possibly part of "include" keyword?
  1707.         jp nz,rm6
  1708.         lda lastc2      ;if a possible #include, make sure
  1709.         cp cr           ;the char before the "#" was a CR..
  1710.         jp nz,rm6
  1711.         xor a
  1712.         sta lastc2
  1713.         lda lastc
  1714.         cp '#'
  1715.         jp z,doincl
  1716.  
  1717. rm6:    sta lastc
  1718.         inc hl
  1719.         jp rm3
  1720.  
  1721.  
  1722. ;
  1723. ; Handle "#include":
  1724. ;
  1725. ; At this point, we've seen "#i"...let's make sure
  1726. ; we see at least another "n", then skip the rest, and
  1727. ; then process the file...
  1728. ;
  1729.  
  1730. angleu: ds 1            ;true if angle bracket surrounds filename
  1731.  
  1732. doincl: xor a
  1733.         sta angleu
  1734.         shld textp
  1735.         inc hl
  1736. doin0:  call getcef
  1737.         ld c,a
  1738.         call mapuc
  1739.         cp 'N'
  1740.         jp nz,storc
  1741.        
  1742.         call getcef
  1743.         call mapuc
  1744.         cp 'C'
  1745.         jp nz,rm6               ;just makin' sure we got "#inc"...
  1746.  
  1747. doinz:  call getcef     ;pass by rest of "#include" keyword
  1748.         call twsp
  1749.         jp nz,doinz
  1750.  
  1751. doinz2: call getcef     ;find filename argument
  1752.         call twsp
  1753.         jp z,doinz2
  1754.  
  1755.         IF CPM
  1756.         push af
  1757.         lda curdsk      ;by default, new disk and user area
  1758.         sta newdsk      ;are the same as current disk and user
  1759.         lda curusr      ;area.
  1760.         sta newusr
  1761.         pop af
  1762.         ENDIF
  1763.  
  1764.         ld de,fnbuf     ;copy name to buffer
  1765.         push de
  1766.  
  1767.         cp '"'          ;ignore 1st char if quote
  1768.         jp z,doin1
  1769.         cp '<'
  1770.         jp nz,doin1a    ;if angle bracket, assume a special directory is
  1771.                         ;to be searched (under CP/M, a disk and user area)
  1772.                         ;       << Handle Angle Brackets now: >>
  1773.         IF CPM
  1774.         sta angleu      ;note that angle bracket was found
  1775.         lda defdsk      ;get default disk drive for file yanking
  1776.         cp 0ffh ;default to current?
  1777.         jp nz,doiny1    ;if not, use as is
  1778.  
  1779.         lda origdsk     ;get current disk drive when compiler invoked
  1780. ;       lda curdsk      ;if so, make it the new disk
  1781.  
  1782. doiny1: sta newdsk
  1783.  
  1784.         lda defusr      ;set new user area
  1785.         cp 0ffh ;default to current?
  1786.         jp nz,doiny2
  1787.  
  1788.         lda origusr     ;get current user number when compiler invoked
  1789. ;       lda curusr      ;if so, make new user area the current one
  1790.  
  1791. doiny2: sta newusr
  1792.         ENDIF  
  1793.  
  1794. doin1:  push de
  1795.         call getc      
  1796.         pop de
  1797.         jp c,closef
  1798.  
  1799. doin1a: cp lf           ;CR,LF,space,tab,", and > all terminate name.
  1800.         jp nz,doin1b
  1801.         push hl
  1802.         lhld sptr
  1803.         dec hl
  1804.         shld sptr
  1805.         pop hl
  1806.         jp doin2
  1807.  
  1808. doin1b: cp cr
  1809.         jp z,doin2
  1810.         call twsp
  1811.         jp z,doin2
  1812.         cp '>'
  1813.         jp z,doin2
  1814.         cp '"'
  1815.         jp z,doin2
  1816.         ld (de),a
  1817.         inc de
  1818.         jp doin1
  1819.  
  1820.  
  1821.                         ;simplified 12/27/85
  1822.         IF 0
  1823. doin2:
  1824.         cp lf
  1825.         call z,bumpnl   ;bump line count
  1826.         jp z,doin3
  1827.                         ;ignore rest of line, but treat a comment
  1828.                         ;as a special case because of lousy design...
  1829. doin20: call getcsd
  1830.         cp '/'          ;possible start of comment?
  1831.         jp nz,doin2     ;if not, keep on throwing away the line
  1832.         call getcsd     ;yes. next character
  1833.         cp '*'          ;a star?
  1834.         jp nz,doin2     ;if not, keep throwing line away...
  1835.  
  1836. doin2a: call getcsd     ;else look for closing comment characters, and preserve
  1837.         cp lf           ;linefeeds.
  1838.         jp nz,doin2b    ;a linefeed?
  1839.         call bumpnl
  1840.         lhld pndsav     ;if so, store it and bump pointer...
  1841.         ld (hl),cr
  1842.         inc hl
  1843.         shld pndsav
  1844.         jp doin2a       ;and go on processing comment
  1845.        
  1846. doin2b: cp '*'          ;possible end of comment?
  1847.         jp nz,doin2a    ;if not, keep on scanning comment
  1848.         call getcsd     ;yes...followed by a slash?
  1849.         cp '/'
  1850.         jp nz,doin2b    ;if not, might have been a star...
  1851.         jp doin2        ;else done with comment. go process rest of this line.
  1852.  
  1853.  
  1854. getcsd: push de
  1855.         call getc
  1856.         pop de
  1857.         ret nc
  1858.         pop bc
  1859.         jp closef
  1860.         ENDIF
  1861.  
  1862. twsp:   cp ' '
  1863.         ret z
  1864.         cp 0ffh
  1865.         ret z
  1866.         cp 9
  1867.         ret
  1868.  
  1869. doin2: 
  1870. doin3:  xor a
  1871.         ld (de),a
  1872.         call pushf
  1873.  
  1874.         pop de          ;check for explicit user area prefix on filename
  1875.         push de         ;save ptr in case of no legal user number prefix
  1876.         call gdec       ;test for decimal number (gdec sets Cy if none)
  1877.         jp c,doin3a     ;if no prefix, don't futz with user number
  1878.         ld a,(de)               ;check for trailing slash
  1879.         cp '/'
  1880.         jp nz,doin3a    ;if none, not a legal user number
  1881.         ld a,b          ;else it is. Make it the new user number
  1882.         sta newusr
  1883.         inc de          ;bump text pointer past user number prefix
  1884.         pop hl          ;discard pushed text pointer from stack
  1885.         jp doin3b       ;and go process remainder of filename          
  1886.  
  1887. doin3a: pop de          ;under CP/M, set up default fcb with filename
  1888. doin3b: ld hl,fcb
  1889.         call setfcb     ;set up fcb, return Cy if explicit drive name given
  1890.         jp c,doin3d     ;if explicit drive given, don't be intelligent...
  1891.                         ;at this point: no explicit drive name given. Only
  1892.                         ;allow the source file disk to determine new-disk for
  1893.                         ;the included file IFF no angle bracket was used...
  1894.         lda angleu      ;was angle bracket used?
  1895.         or a           
  1896.         jp nz,doin3e    ;if so, IGNORE default source disk (sdisk)
  1897.                         ;inserted by setfcb.
  1898.                         ;If no <...> used, allow sdisk to determine source disk
  1899. doin3d: lda fcb         ;see if explicit disk given in #include op
  1900.         or a            ;if non-zero, an explicit disk was given,
  1901.         jp nz,doin3c    ;       so go log that in as new current disk
  1902.        
  1903. doin3e: lda newdsk      ;if no disk designator given, set disk byte
  1904.         inc a           ;with appropriately offset new disk value
  1905.         sta fcb ;TODO remove?
  1906.  
  1907. doin3c: dec a           ;change fcb-based disk code to BDOS call disk code
  1908.         sta newdsk
  1909. doin4:  ;ld e,a
  1910.         ;ld c,select
  1911.         ;call bdos      ;select disk
  1912.  
  1913.         lda curdsk      ;save current disk and user area on stack
  1914.         push af
  1915.         lda curusr
  1916.         push af
  1917.  
  1918.         lda newdsk      ;and set up new disk and user area for this file
  1919.         sta curdsk
  1920.         lda newusr
  1921.         sta curusr
  1922.        
  1923.         ld e,a          ;select new user area
  1924.  
  1925.         IF NOT ALPHA
  1926.         ;lda nouser
  1927.         ;or a
  1928.         ;jp nz,doin40   ;skip setting user area if 'nouser' true
  1929.         ;ld c,sguser
  1930.         ;call bdos
  1931.         ENDIF
  1932.  
  1933.         IF NOT CPM
  1934.         pop hl          ;else put filename in HL
  1935.         shld fnam       ;and save for pfnam printout (on error only)
  1936.         ENDIF
  1937.  
  1938.  
  1939. doin40: lhld nlcnt      ;save line count
  1940.         push hl
  1941.  
  1942.         lhld pndsav
  1943.         shld textp
  1944.  
  1945.         call readm      ;read in the included file
  1946.  
  1947.         sta okflag      ;save return condition from readm in okflag
  1948.  
  1949.         ex de,hl                ;save HL in DE
  1950.         pop hl          ;restore line count
  1951.         shld nlcnt
  1952.         shld atcnt      ;match active text to current line number
  1953.         ex de,hl                ;restore text ptr into HL
  1954.  
  1955.         pop af          ;they were before the include file was being processed.
  1956.         sta curusr      ;first the user number:
  1957.         push hl         ;save HL during BDOS calls
  1958.         ld e,a
  1959.  
  1960.         IF NOT ALPHA
  1961.         ;lda nouser
  1962.         ;or a
  1963.         ;jp nz,doin5a   ;skip setting user area if 'nouser' true
  1964.         ;ld c,sguser
  1965.         ;call bdos
  1966.         ENDIF
  1967.  
  1968. doin5a: pop hl          ;pop HL so we can get at pushed psw...
  1969.         pop af          ;and then set the current disk:
  1970.         sta curdsk
  1971.         ;push hl                ;save HL for BDOS call
  1972.         ;ld e,a
  1973.         ;ld c,select
  1974.         ;call bdos      ;select disk
  1975.         ;pop hl         ;restore HL after BDOS futzing
  1976.  
  1977.         call popf      
  1978.         lda okflag      ;was the readm successful?
  1979.         or a
  1980.         jp nz,rm3               ;if so, go on
  1981.         jp errab        ;and  all done
  1982.  
  1983. ;
  1984. ; Get next char from current file, and go close file and return to
  1985. ; caller one level higher if EOF encountered:
  1986. ;
  1987.  
  1988. getcef: call getc
  1989.         jp c,getcf2
  1990.         cp 1ah          ;end of file character?
  1991.         ret nz
  1992. getcf2: pop bc
  1993.         jp closef
  1994.  
  1995. ;
  1996. ; Get next character from current text input file:
  1997. ;
  1998.  
  1999. getc:
  2000.         ex de,hl                ;save text pointer in DE
  2001.         lhld sptr       ;get sector pointer in HL
  2002.         inc hl          ;bump it
  2003.         ld a,l          ;exhausted current sector? look at low byte of ptr
  2004.  
  2005.         IF CPM 
  2006.         or a            ;check for 00 (end of tbuff) under CP/M
  2007.         ENDIF
  2008.  
  2009.         jp nz,getc1
  2010.         call reads      ;yes. read in next sector
  2011.  
  2012.         IF CPM
  2013.         ld hl,tbuff     ;and reset sector pointer
  2014.         ENDIF
  2015.  
  2016.         IF NOT CPM
  2017.         ld hl,secbuf
  2018.         ENDIF
  2019.  
  2020.         ex de,hl                ;put text pointer back in HL in case of return...
  2021.         ret c           ;if EOF, restore textp into HL and return
  2022.  
  2023.         call ckov       ;check HL for memory overflow
  2024.         ex de,hl                ;put text ptr in DE, get sector pointer in HL
  2025.  
  2026. getc1:  ld a,(hl)               ;get next char from sector buffer
  2027.  
  2028. stripp: and 7fh         ;strip parity -- substitute "nop-or a" for "and 7fh"
  2029.                         ;               to allow bit 7 to be high on input text
  2030.         shld sptr       ;save sector pointer
  2031.         ex de,hl                ;get back text pointer in HL
  2032.         ret
  2033.  
  2034.  
  2035. ;
  2036. ; Install current filespec (from default fcb) into text buffer at HL,
  2037. ; and bump HL past the filename:
  2038. ;
  2039.  
  2040. insrtm: push bc
  2041.         push hl
  2042.         push de
  2043.         ld b,12
  2044.         ld de,fcb
  2045.         call ldrc
  2046.         pop de
  2047.         pop hl
  2048.         pop bc
  2049.         ret
  2050.  
  2051.  
  2052. pushf:  push hl
  2053.         push de
  2054.         ld c,0
  2055.         lhld fsp
  2056.         call ldstf
  2057.         shld fsp
  2058.         pop de
  2059.         pop hl
  2060.         ret
  2061.  
  2062. popf:   push hl
  2063.         push de
  2064.         ld c,1
  2065.         lhld fsp
  2066.  
  2067.         IF CPM
  2068.         ld de,-164      ; 33 (fcb) + 128 (buffer) + 2 (ptr) + 1 (rederf) = 164
  2069.         ENDIF
  2070.  
  2071.         add hl,de
  2072.         shld fsp
  2073.         call ldstf     
  2074.         pop de
  2075.         pop hl
  2076.         ret
  2077.  
  2078. ldstf:
  2079.         IF CPM
  2080.         ld de,fcb
  2081.         ld b,33
  2082.         call ldram
  2083.         ld de,tbuff
  2084.         ld b,128
  2085.         call ldram
  2086.         ld de,sptr
  2087.         ld b,3
  2088.         call ldram
  2089.         ret
  2090.         ENDIF
  2091.  
  2092.         IF CPM          ;set default FCB, return Cy set if explicit drive used:
  2093. setfcb: ld b,8
  2094.         push hl
  2095.         inc de
  2096.         ld a,(de)
  2097.         dec de
  2098.         cp ':'
  2099.         lda sdisk       ;default disk is disk source file came from
  2100.         scf
  2101.         ccf
  2102.         push af ;push Cy reset in case explicit disk not given
  2103.         jp nz,setf1
  2104.         pop af
  2105.         scf
  2106.         push af ;push Cy set, since explicit disk IS given
  2107.         ld a,(de)
  2108.         call mapuc
  2109.         sub '@'
  2110.         inc de
  2111.         inc de
  2112. setf1:  ld (hl),a
  2113.         inc hl
  2114.         call setnm
  2115.         ld a,(de)
  2116.         cp '.'
  2117.         jp nz,setfcb2
  2118.         inc de
  2119. setfcb2:ld b,3
  2120.         call setnm
  2121.         ld (hl),0
  2122.         ld de,20
  2123.         add hl,de
  2124.         ld (hl),0
  2125.         pop af          ;restore return flag (Cy set if d: given)
  2126.         pop de          ;restore fcb address in DE for BDOS call forthcoming
  2127.         ret
  2128.  
  2129. setnm:  push bc
  2130. setnm2: ld a,(de)
  2131.         call legfc
  2132.         jp c,pad
  2133.         ld (hl),a
  2134.         inc hl
  2135.         inc de
  2136.         dec b  
  2137.         jp nz,setnm2
  2138.         pop bc
  2139. setnm3: ld a,(de)
  2140.         call legfc
  2141.         ret c
  2142.         inc de
  2143.         jp setnm3
  2144.  
  2145. pad:    ld a,' '
  2146.         ld (hl),a
  2147.         inc hl
  2148.         dec b  
  2149.         jp nz,pad
  2150.         pop bc
  2151.         ret
  2152.  
  2153. legfc:  call mapuc
  2154.         cp '.'
  2155.         scf
  2156.         ret z
  2157.         or a
  2158.         scf
  2159.         ret z
  2160.         ccf
  2161.         ret
  2162.  
  2163.         ENDIF
  2164.  
  2165. reads:
  2166.         IF CPM          ;read a sector of 128 bytes under CP/M
  2167.         push hl
  2168.         push de
  2169.          ld de,0x0080
  2170.          ld c,sdma
  2171.          call bdos
  2172.         ld de,fcb
  2173.         ld c,rsequen
  2174.         call bdos
  2175.         or a
  2176.         pop de
  2177.         pop hl
  2178.         ret z ;ok, full sector
  2179.          cp 128 ;EOF in NedoOS
  2180.          jr z,reads_eof
  2181. ;CP/M has eofs in the end of last sector?
  2182. ;do this by hand:
  2183. ;a=128+bytes loaded
  2184.         neg
  2185. ;a=128-bytes loaded
  2186.         push de
  2187.         ld b,a
  2188.         ld de,0x0080+127        ; Point to buffer end
  2189.         ld a,0x1a
  2190.         ld (de),a
  2191.         dec de
  2192.         djnz $-2
  2193.         pop de
  2194.         or a
  2195.         ret ;ok, not full sector
  2196. reads_eof
  2197.         ;cp 1
  2198.         ;jp nz,rds2 ;???
  2199.         scf ;error
  2200.         ret
  2201.         ENDIF
  2202.  
  2203. rds2:
  2204.         ld hl,stg4
  2205.         jp pstgab
  2206.  
  2207.  
  2208. kludge: cp cr
  2209.         ld c,lf
  2210.         ret z
  2211.         cp lf
  2212.         ld c,cr
  2213.         ret z
  2214.         ld c,a
  2215.         ret
  2216.  
  2217.         ;IF LASM
  2218.         ;link ccd
  2219.         ;ENDIF
  2220.