?login_element?

Subversion Repositories NedoOS

Rev

Blame | Last modification | View Log | Download | RSS feed

  1. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  2. ;
  3. ;Dictionary operations. Most of these functions are hand-compiled
  4. ;from those in jzip.
  5. ;
  6. d_addr: defw    0       ;Address of the dictionary
  7. toksrc: defw    0       ;Source string
  8. tokdst: defw    0       ;Destination string
  9. tokdct: defw    0       ;Dictionary
  10. punct:  defs    16      ;Punctuation
  11. seps:   defb    9,10,12,13,' .,?'
  12. tokpc:  defb    0       ;Punctuation count
  13. tokcp:  defw    0       ;Pointer to characters
  14. toktp:  defw    0       ;Pointer to tokens
  15. tokmax: defb    0       ;Max tokens allowed in line
  16. tokesz: defb    0       ;Entry size
  17. tokdsz: defw    0       ;Dictionary size
  18. tokchp: defw    0       ;chop
  19. tokwi:  defw    0       ;word index
  20. tokln:  defb    0       ;Token length
  21. tokptr: defw    0       ;Token pointer
  22. tokflg: defb    0       ;Flag
  23. encbuf: defs    32      ;Word encoding buf
  24. llen:   defb    0       ;Length of the line
  25. ;
  26. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  27. ;
  28. ;Check if the character in C is an interpreter-defined 'separator' character
  29. ;
  30. cksepa:
  31.         push    hl
  32.         push    bc
  33.         ld      b,8
  34.         ld      hl,seps
  35.         jr      ckpn1
  36. ;
  37. ;Check if the character in C is a game-defined 'punctuation' character
  38. ;
  39. ckpunct:
  40.         push    hl
  41.         push    bc
  42.         ld      a,(tokpc)
  43.         or      a
  44.         jr      z,ckpn
  45.         ld      b,a     ;Count of special punctuation characters
  46.         ld      hl,punct
  47. ckpn1:  ld      a,(hl)
  48.         cp      c
  49.         scf             ;Carry set if found.
  50.         jr      z,ckpn
  51.         inc     hl
  52.         djnz    ckpn1
  53.         xor     a       ;Carry reset, not found.
  54. ckpn:   pop     bc
  55.         pop     hl
  56.         ret
  57. ;
  58. ;next_token - based on the eponymous routine in jzip
  59. ;
  60. ;HL->string. Returns tokln = token length; tokptr -> token base
  61. ;
  62. next_token:
  63. ;
  64. ;SET the token length to zero
  65. ;
  66.         xor     a
  67.         ld      (tokln),a
  68. ;
  69. ;Step through the string looking for separators
  70. ;
  71. nt1:    ld      a,(llen)
  72.         or      a               ;End of line, reached by counting
  73.         ret     z
  74.         call    peek64
  75.         or      a
  76.         ret     z               ;End of line, reached by 0-termination
  77.         ld      c,a             ;C = current character
  78. ;
  79. ;Look for game specific punctuation
  80. ;
  81.         call    ckpunct         ;Returns Carry set if C is punctuation
  82.         jr      nc,nt2
  83. ;
  84. ;IF a separator is found then return the information.
  85. ;IF length has been set, then just return the word position
  86. ;
  87.         ld      a,(tokln)
  88.         or      a
  89.         ret     nz
  90. ;
  91. ;ELSE set length and token pointer
  92. ;
  93.         inc     a
  94.         ld      (tokln),a
  95.         ld      (tokptr),hl
  96.  
  97.         inc     hl
  98.         call    dllen
  99.         ret
  100. ;
  101. ; Look for statically defined separators last
  102. ;
  103. nt2:    call    cksepa
  104.         jr      nc,nt3
  105. ;
  106. ;IF length has been set then return the word position
  107. ;
  108.         ld      a,(tokln)
  109.         or      a
  110.         jr      z,nt99  ;<< v0.02 >> Skip it, and don't increment length
  111.  
  112.         inc     hl
  113.         call    dllen
  114.         ret
  115. ;
  116. ;IF 1st token character then remember its position
  117. ;
  118. nt3:    ld      a,(tokln)
  119.         or      a
  120.         jr      nz,nt4
  121.         ld      (tokptr),hl
  122. nt4:    inc     a
  123.         ld      (tokln),a
  124.  
  125. nt99:   inc     hl
  126.         call    dllen
  127.         jp      nt1
  128. ;
  129. ;Decrement LLEN
  130. ;
  131. dllen:  push    af
  132.         push    hl
  133.         ld      hl,llen
  134.         dec     (hl)
  135.         pop     hl
  136.         pop     af
  137.         ret
  138. ;
  139. ;Tokenise text at Z-address HL to buffer DE. BC->dictionary
  140. ;
  141. ;Based on tokenise_line() in jzip.
  142. ;
  143. tokenise:
  144.         ld      (tokflg),a      ;A = flag parameter
  145.         ld      a,b
  146.         or      c
  147.         jr      nz,tok1
  148.         ld      bc,(d_addr)     ;BC = dict parameter
  149. tok1:   ld      (toksrc),hl     ;HL = z-address of line
  150.         ld      (tokdst),de     ;DE = z-address of output
  151.         ld      a,255
  152.         ld      (llen),a
  153.         ld      a,(zver)
  154.         cp      5
  155.         jp      c,tok4
  156.         inc     hl
  157.         call    peek64
  158.         ld      (llen),a
  159. tok4:   inc     hl      ;HL -> words
  160.         ld      (tokcp),hl
  161.         ex      de,hl
  162.         call    peek64
  163.         ex      de,hl   ;Max. tokens
  164.         ld      (tokmax),a
  165.         inc     de
  166.         inc     de      ;DE -> destination
  167.         ld      (toktp),de
  168.         ld      ix,0    ;IX = word count
  169.         ld      h,b
  170.         ld      l,c     ;HL->dictionary
  171.  
  172.         call    peek64  ;No. of punctuation characters
  173.  
  174.         push    af
  175.         push    hl
  176.         cp      10h
  177.         jr      c,tok5
  178.         ld      a,10h
  179. tok5:   ld      b,a     ;Punctuation count
  180.         ld      (tokpc),a
  181.         inc     hl
  182.         ld      de,punct
  183. tok6:   call    peek64  ;Read the punctuation characters
  184.         ld      (de),a
  185.         inc     hl
  186.         inc     de
  187.         djnz    tok6
  188.         xor     a
  189.         ld      (de),a
  190.         pop     hl
  191.         pop     af
  192.         inc     hl
  193.         ld      e,a
  194.         ld      d,0
  195.         add     hl,de   ;HL ->entry lengtha
  196.  
  197.         call    peek64
  198.         ld      (tokesz),a
  199.         inc     hl
  200.         call    peek64
  201.         ld      b,a
  202.         inc     hl
  203.         call    peek64  ;Dictionary size
  204.         ld      c,a
  205.         ld      (tokdsz),bc
  206.         inc     hl
  207.         ld      (tokdct),hl     ;Start of dictionary proper
  208. ;
  209. ;Calculate the binary chop start position
  210. ;
  211.         ld      bc,(tokdsz)
  212.         srl     b
  213.         rr      c
  214.         ld      hl,1    ;Chop value
  215. tok7:   ld      a,b
  216.         or      c
  217.         jr      z,tok8
  218.         srl     b
  219.         rr      c
  220.         add     hl,hl
  221.         jr      tok7
  222. ;
  223. tok8:   ld      (tokchp),hl
  224. ;
  225. ;Tokenise
  226. ;
  227. tok9:   ld      hl,(tokcp)
  228.         call    next_token
  229.         ld      (tokcp),hl
  230.         push    ix              ;C = word count
  231.         pop     bc
  232.         ld      a,(tokln)       ;Length=0 => EOL
  233.         or      a
  234.         jp      z,tok99
  235.         ld      hl,(tokdst)     ;Max words
  236.         call    peek64
  237.         cp      c               ;IF C >= A, ok.
  238.         jp      c,tok99
  239. ;
  240. tok10:  ld      a,(tokln)
  241.         ld      hl,(tokptr)
  242.         ld      de,(tokchp)
  243.         call    find_word       ;BC := word no.
  244.         ld      hl,(toktp)
  245.         ld      a,(tokflg)
  246.         or      a
  247.         jr      z,tok11
  248.         ld      a,b
  249.         or      c
  250.         jr      z,tok12
  251. tok11:  ld      a,b
  252.         call    ZXPOKE
  253.         inc     hl
  254.         ld      a,c
  255.         call    ZXPOKE
  256.         inc     hl
  257.         jr      tok14
  258. ;
  259. tok12:  inc     hl
  260.         inc     hl
  261. tok14:
  262.         ld      a,(tokln)
  263.         call    ZXPOKE
  264.         inc     hl
  265.         push    hl
  266.         ld      hl,(tokptr)
  267.         ld      de,(toksrc)
  268.         and     a
  269.         sbc     hl,de
  270.         ld      a,l
  271.         pop     hl
  272.         call    ZXPOKE
  273.         inc     hl
  274.         ld      (toktp),hl
  275.         inc     ix      ;Word count
  276.         jp      tok9
  277.  
  278. tok99:  push    ix
  279.         pop     bc      ;C=no. of words
  280.         ld      hl,(tokdst)
  281.         inc     hl
  282.         ld      a,c
  283.         call    ZXPOKE
  284. ;
  285. ;Diagnostic
  286. ;
  287.         scf
  288.         ret
  289. ;
  290. fwlen:  defb    0
  291. fwchp:  defw    0
  292. fwadd:  defw    0
  293. ;
  294. ;Compare encrypted words at DE and z-address HL, length 4 or 6 bytes.
  295. ;
  296. cpenc:  ld      b,4             ;Returns: Zero set if words match
  297.         ld      a,(zver)        ;Carry set if word at DE is less than at HL.
  298.         cp      4
  299.         jr      c,cpenc1
  300.         ld      b,6
  301. cpenc1: call    peek64          ;Get from Z-memory
  302.         ld      c,a
  303.         ld      a,(de)
  304.         cp      c               ;
  305.         ret     nz
  306.         inc     hl
  307.         inc     de
  308.         djnz    cpenc1
  309.         xor     a
  310.         ret
  311. ;
  312. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  313. ;
  314. fwoffs:
  315. ;
  316. ;HL := (tokwi * tokesz) + tokdct
  317. ;
  318.         push    af
  319.         push    de
  320.         ld      hl,(tokdct)
  321.         ld      de,(tokwi)
  322.         ld      a,(tokesz)
  323. fwolp:  add     hl,de
  324.         dec     a
  325.         jr      nz,fwolp
  326.         pop     de
  327.         pop     af
  328.         ret
  329. ;
  330. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  331. ;
  332. ;Limit tokwi to 0 <= tokwi < abs(tokdsz)
  333. ;
  334. limit_wi:
  335.         push    hl
  336.         push    de
  337.         ld      hl,(tokwi)
  338.         bit     7,h
  339.         jr      nz,limw1
  340.         ld      de,(tokdsz)
  341.         call    absde
  342.         and     a
  343.         sbc     hl,de
  344.         jr      c,limw2
  345.         dec     de
  346.         ld      (tokwi),de
  347.         pop     de
  348.         pop     hl
  349.         ret
  350.  
  351. limw1:  ld      hl,0
  352.         ld      (tokwi),hl
  353. limw2:  pop     de
  354.         pop     hl
  355.         ret
  356. ;
  357. dtok:   push    af
  358.         push    bc
  359.         push    de
  360.         push    hl
  361.         ld      b,a
  362. dtok1:  call    peek64
  363.         push    bc
  364.         cp      20h
  365.         ld      e,a
  366.         ld      c,2
  367.         call    nc,ZXFDOS
  368.         pop     bc
  369.         inc     hl
  370.         djnz    dtok1
  371.  
  372.         jp      popd
  373. ;
  374. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  375. ;
  376. ;From jzip's find_word()
  377. ;
  378. find_word:      ;A=token len HL=addr DE=chop
  379. ;;;     call    dtok
  380.         ld      (fwchp),de
  381.         ld      (fwadd),hl
  382.         ld      (fwlen),a
  383.         ld      bc,(tokdsz)
  384.         ld      a,b
  385.         or      c
  386.         ret     z
  387.         ld      a,(fwlen)       ;A=length
  388.         ld      b,a
  389.         call    encode          ;to z-string at encbuf
  390. ;
  391.         ld      hl,(fwchp)
  392.         dec     hl
  393.         ld      (tokwi),hl
  394.         ld      hl,(tokdsz)
  395.         bit     7,h             ;Dictionary size negative?
  396.         jr      nz,dszlt0
  397. fww1:   ld      bc,(fwchp)      ;while (fwchp)
  398.         ld      a,b
  399.         or      c
  400.         ret     z               ;Not found
  401.         srl     b
  402.         rr      c       ;fwchp /= 2;
  403.         ld      (fwchp),bc
  404.         call    limit_wi
  405. ;
  406.         call    fwoffs  ;HL := offset of word tokwi
  407. ;
  408.         ld      de,encbuf
  409.         push    hl
  410.         call    cpenc
  411.         pop     bc
  412.         jr      c,fww5  ;Go back
  413.         jr      nz,fww4 ;Go forward
  414. ;
  415. ;We have a match!
  416. ;
  417.         ret
  418. ;
  419. fww4:   ld      hl,(tokwi)
  420.         ld      bc,(fwchp)
  421.         add     hl,bc
  422.         ld      (tokwi),hl
  423.         call    limit_wi
  424.         jr      fww1
  425. ;
  426. fww5:   ld      hl,(tokwi)
  427.         ld      bc,(fwchp)
  428.         and     a
  429.         sbc     hl,bc
  430.         ld      (tokwi),hl
  431.         call    limit_wi
  432.         jr      fww1
  433.  
  434. dszlt0: call    absbc   ;BC = word count
  435.         ld      hl,0
  436.         ld      (tokwi),hl
  437. dszlp1: ld      a,b
  438.         or      c
  439.         ret     z
  440.         push    bc
  441.         call    fwoffs
  442.         ld      de,encbuf
  443.         push    hl
  444.         call    cpenc
  445.         pop     bc
  446.         jr      z,dszok
  447.         ld      hl,(tokwi)
  448.         inc     hl
  449.         ld      (tokwi),hl
  450.         pop     bc
  451.         dec     bc
  452.         jr      dszlp1
  453.  
  454. dszok:  pop     de
  455.         ret
  456.