?login_element?

Subversion Repositories NedoOS

Rev

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

  1. ;
  2. ;Code for accessing variables
  3. ;
  4. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  5. ;
  6. ;Parse a VAR: instruction into arg1,arg2,arg3,arg4
  7. ;
  8. v_arg1: defw    0,0
  9. v_arg2: defw    0,0
  10. v_arg3: defw    0,0
  11. v_arg4: defw    0,0
  12. v_arg5: defw    0,0
  13. v_arg6: defw    0,0
  14. v_arg7: defw    0,0
  15. v_arg8: defw    0,0
  16. v_argc: defb    0
  17. ;
  18. g_addr: defw    0       ;Address of global variables
  19. r_offs: defw    0       ;Offset to routines (v6/7)
  20. s_offs: defw    0       ;Offset to strings (v6/7)
  21. ;
  22. zapargs:
  23.         push    af      ;SET v_arg1 upto v_argc (inclusive) to zero
  24.         push    bc
  25.         push    de
  26.         push    hl
  27.         ld      hl,v_arg1
  28.         ld      d,h
  29.         ld      e,l
  30.         inc     de
  31.         ld      bc,v_argc-v_arg1
  32.         xor     a
  33.         ld      (hl),b
  34.         ldir
  35.         jp      popd
  36. ;
  37. parse_v2:               ;Parse arguments for 8-arg functions. B holds 1st type
  38.                         ;byte, C holds second
  39.         ld      a,b
  40.         push    bc
  41.         call    parse_var
  42.         pop     bc
  43.         ld      a,c
  44.         ld      b,4             ;DE is still set correctly from
  45.         ld      ix,v_arg5       ;last time round the loop
  46.         jr      parlp
  47. ;
  48. parse_var:
  49. ;
  50. ;A = arg type byte
  51. ;
  52.         ld      b,4
  53.         ld      e,b
  54.         ld      ix,v_arg1
  55.         push    af
  56.         xor     a
  57.         ld      d,a
  58.         call    zapargs
  59.         ld      (v_argc),a
  60.         pop     af
  61. parlp:  rlca
  62.         rlca
  63.         push    af
  64.         push    de
  65.         push    bc
  66.         and     3
  67.         ld      l,a
  68.         push    hl
  69.         call    parse_type
  70.         pop     hl
  71.         pop     bc
  72.         pop     de
  73.         ld      a,l
  74.         cp      3
  75.         jr      z,endpar
  76.         ld      a,(v_argc)
  77.         inc     a
  78.         ld      (v_argc),a
  79.         pop     af
  80.         add     ix,de
  81.         djnz    parlp
  82.         scf
  83.         ret
  84. ;
  85. endpar: pop     af
  86.         scf
  87.         ret
  88. ;
  89. parse_type:
  90.         ld      l,a
  91.         ld      h,0     ;HL = 0-3
  92.         add     hl,hl   ;*2
  93.         ld      de,parse_tbl
  94.         add     hl,de
  95.         ld      e,(hl)
  96.         inc     hl
  97.         ld      d,(hl)
  98.         ex      de,hl
  99.         jp      (hl)
  100. ;
  101. parse_tbl:
  102.         defw    p_word
  103.         defw    p_byte
  104.         defw    p_var
  105.         defw    p_none
  106. ;
  107. ;Get byte / word / variable arguments from an instruction.
  108. ;
  109. p_none: ret
  110. ;
  111. p_byte: push    af
  112.         call    zpcipeek
  113.         ld      (ix+0),a
  114.         ld      (ix+1),0
  115.         pop     af
  116.         ret
  117. ;
  118. p_word: push    af
  119.         call    zpcipeek        ;Switch to little-endian
  120.         ld      (ix+1),a
  121.         call    zpcipeek
  122.         ld      (ix+0),a
  123.         pop     af
  124.         ret
  125. ;
  126. p_var:  push    af
  127.         call    zpcipeek
  128.         call    get_var
  129.         ld      (ix+0),l
  130.         ld      (ix+1),h
  131.         pop     af
  132.         ret
  133. ;
  134. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  135. ;
  136. ;Parse a 2OP instruction.
  137. ;
  138. parse_2op:
  139.         ld      ix,v_arg1
  140.         ld      a,(inst)        ;Argument type is part of the instruction
  141.         bit     6,a             ;Type of 1st argument
  142.         call    nz,p_var
  143.         call    z,p_byte
  144.         ld      ix,v_arg2
  145.         bit     5,a
  146.         call    nz,p_var
  147.         call    z,p_byte
  148.         scf
  149.         ret
  150. ;
  151. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  152. ;
  153. ;Parse a 1OP instruction.
  154. ;
  155. parse_1op:
  156.         ld      ix,v_arg1
  157.         ld      a,(inst)
  158.         cp      0A0h
  159.         call    nc,p_var
  160.         ccf
  161.         ret     c
  162.         cp      90h
  163.         call    nc,p_byte
  164.         ccf
  165.         ret     c
  166.         call    p_word
  167.         scf
  168.         ret
  169. ;
  170. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  171. ;
  172. ;Return a value in HL
  173. ;
  174. ret_hl:
  175.         call    zpcipeek
  176.         ret     nc
  177. put_var:
  178.         cp      10h             ;Write value in HL to
  179.         jr      nc,put_glb      ;variable number A
  180.         or      a
  181.         jp      nz,put_lcl
  182. zpush:  push    ix
  183.         ld      ix,(rsp)
  184.         dec     ix
  185.         ld      (ix+0),h
  186.         dec     ix
  187.         ld      (ix+0),l
  188.         ld      (rsp),ix
  189.         pop     ix
  190.         scf
  191.         ret
  192. ;
  193. put_glb:
  194.         ex      de,hl   ;DE = value to store
  195.         sub     10h
  196.         ld      h,0
  197.         ld      l,a     ;Var no.
  198.         ld      bc,(g_addr)
  199.         add     hl,hl
  200.         add     hl,bc   ;Z-address
  201.         ld      a,d
  202.         call    ZXPOKE  ;IN big-endian format
  203.         call    ZXPK64
  204.         cp      d
  205.         jr      nz,put_g1
  206.         inc     hl
  207.         ld      a,e
  208.         ld      d,a
  209.         call    ZXPOKE
  210.         call    ZXPK64
  211.         cp      d
  212.         scf
  213.         ret     z
  214. put_g1: call    ilprint
  215.         defb    13,10,'Memory write has failed! HL=$'
  216.         call    hexhl
  217.         ld      e,d
  218.         ld      d,0
  219.         call    ilprint
  220.         defb    ' Expected $'
  221.         call    hexde
  222.         call    ilprint
  223.         defb    ' Got $'
  224.         call    hexa
  225.         call    ilprint
  226.         defb    13,10,'$'
  227.         ld      c,1
  228.         call    ZXFDOS
  229.         xor     a
  230.         ld      hl,memerr
  231.         ret
  232. ;
  233. put_lcl:
  234.         ex      de,hl   ;DE=value
  235.         ld      hl,(zsp)
  236.         ld      bc,4
  237.         add     hl,bc   ;Start of local vars area
  238.         dec     a
  239.         ld      c,a
  240.         ld      b,0
  241.         add     hl,bc
  242.         add     hl,bc
  243.         ld      (hl),e
  244.         inc     hl
  245.         ld      (hl),d
  246.         scf
  247.         ret
  248.  
  249. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  250. ;
  251. ;Get the contents of a variable
  252. ;
  253. get_var:
  254.         cp      10h
  255.         jr      nc,get_glb
  256.         or      a
  257.         jr      nz,get_lcl
  258. zpop:   push    ix              ;POP the Z-stack
  259.         ld      ix,(rsp)
  260.         ld      l,(ix+0)
  261.         inc     ix
  262.         ld      h,(ix+0)
  263.         inc     ix
  264.         ld      (rsp),ix
  265.         pop     ix
  266.         ret
  267. ;
  268. get_glb:
  269.         sub     10h
  270.         ld      h,0
  271.         ld      l,a     ;Var no.
  272.         ld      de,(g_addr)
  273.         add     hl,hl
  274.         add     hl,de   ;Z-address
  275.         ld      e,0
  276.         call    ZXPKWD
  277.         ld      h,b
  278.         ld      l,c
  279.         ret
  280. ;
  281. get_lcl:                ;Get a local variable
  282.         ld      hl,(zsp)
  283.         ld      bc,4
  284.         add     hl,bc   ;Start of local vars area
  285.         dec     a
  286.         ld      e,a
  287.         ld      d,0
  288.         add     hl,de
  289.         add     hl,de
  290.         ld      a,(hl)
  291.         inc     hl
  292.         ld      h,(hl)
  293.         ld      l,a
  294.         ret
  295. ;
  296. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  297. ;
  298. ;Unpack a packed Z-address (HL -> EHL)
  299. ;
  300. upack_table:
  301.         defw    upack0
  302.         defw    upack1, upack2, upack3, upack4
  303.         defw    upack5, upack6, upack7, upack8
  304.  
  305. upack_addr:
  306.         jp      0
  307. ;
  308. upack1:
  309. upack2:
  310. upack3: push    bc
  311.         ld      b,1
  312.         jr      upack_g
  313. ;
  314. upack4:
  315. upack5: push    bc
  316.         ld      b,2
  317.         jr      upack_g
  318. ;
  319. upack8: push    bc
  320.         ld      b,3
  321. upack_g:
  322.         ld      e,0
  323. upack_l:
  324.         sla     l
  325.         rl      h
  326.         rl      e
  327.         djnz    upack_l
  328.         pop     bc
  329.         ret
  330. ;
  331. upack0:
  332. upack6:
  333. upack7: ld      de,ch_
  334.         ld      c,9
  335.         call    ZXFDOS
  336.         ld      c,1
  337.         call    ZXFDOS
  338.         rst     0       ;Must never happen :-)
  339. ;
  340. ch_:    defb    'You should never see this message!'
  341.         defb    13,10,36
  342.