?login_element?

Subversion Repositories NedoOS

Rev

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

  1.  
  2. two_ops:        ;2OP: 0      1       2       3       4      5      6      7
  3.         defw    zbreak,   z_je,   z_jl,   z_jg, z_dck, z_ick,  z_jin, testv
  4.         defw      z_or,  z_and,   z_ta,   z_sa,  z_ca, store, insobj, z_ldw
  5.         defw     z_ldb,   z_gp,  z_gpa,  z_gnp, z_add, z_sub,  z_mul, z_div
  6.         defw     z_mod, call2s, call2n, z_scol, throw,  fail,   fail,  fail
  7. ;
  8. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  9. ;
  10. ;According to the Z-Machine Standards Document, 2OP:0 is possibly a debug
  11. ;breakpoint. So let it call ZXILIV, which is the nearest thing to a
  12. ;debug breakpoint currently in ZXZVM.
  13. ;
  14. zbreak:
  15.         ld      hl,(zpc)        ;<< v1.01 call breakpoint with
  16.         ld      de,(zpc+2)      ;>>       EHL = program counter
  17.         call    ZXILIV
  18.         scf
  19.         ret
  20. ;
  21. z_jg:   ld      hl,(v_arg2)
  22.         ld      de,(v_arg1)
  23.         call    cpsign
  24.         jr      c,branch
  25.         jp      nbranch
  26. ;
  27. z_jl:   ld      hl,(v_arg1)
  28.         ld      de,(v_arg2)
  29.         call    cpsign
  30.         jr      c,branch
  31.         jp      nbranch
  32.  
  33. z_je:   ld      bc,(v_arg1)
  34.         ld      hl,v_arg2
  35.         ld      a,(v_argc)
  36.  
  37. cplp:   dec     a
  38.         jp      z,nbranch
  39.         push    af
  40.         ld      e,(hl)
  41.         inc     hl
  42.         ld      d,(hl)  ;DE = argument to compare with
  43.         inc     hl
  44.         inc     hl
  45.         inc     hl
  46.         call    cpdebc
  47.         jr      z,branch1
  48.         pop     af
  49.         jr      cplp
  50.  
  51. branch1:
  52.         pop     af
  53. branch: call    zpcipeek        ;Branch argument, byte 1
  54.         bit     7,a
  55.         jr      z,rnbrnch       ;Meaning reversed?
  56. rbranch:
  57.         res     7,a
  58.         bit     6,a             ;Far branch?
  59.         jr      z,br_far
  60.         res     6,a
  61. ;
  62. ;Near branch, offset in A
  63. ;
  64. br_near:
  65.         or      a
  66.         jp      z,rfalse
  67.         cp      1
  68.         jp      z,rtrue
  69.         ld      e,a
  70.         ld      d,0
  71.         jr      do_brnch
  72. ;
  73. ;Far branch, get offset into HL.
  74. ;
  75. br_far: ld      h,a
  76.         call    zpcipeek
  77.         ld      l,a             ;HL = offset
  78.         bit     5,h             ;Negative?
  79.         jr      z,pbranch
  80.         ld      a,h
  81.         or      0e0h            ;Extend 14-bit signed int to 16 bits.
  82.         ld      h,a
  83. pbranch:
  84.         ld      a,h             ;IF H is 0 (ie, offset fits in 8 bits)
  85.         or      a               ;then check for rtrue / rfalse
  86.         ld      a,l
  87.         jr      z,br_near
  88.         ex      de,hl
  89. do_brnch:
  90.         dec     de
  91.         dec     de
  92.         ld      hl,(zpc)
  93.         ld      bc,(zpc+2)
  94.         bit     7,d             ;IF backjumping, different code because
  95.         jr      nz,backjmp      ;the high word of PC rolls over differently
  96.         add     hl,de
  97.         jr      nc,dbrnc1
  98.         inc     bc
  99.         jr      dbrnc1
  100. ;
  101. backjmp:
  102.         add     hl,de
  103.         jr      c,dbrnc1
  104.         dec     bc
  105. dbrnc1: ld      (zpc),hl
  106.         ld      (zpc+2),bc
  107.         scf
  108.         ret
  109. ;
  110. nbranch: call    zpcipeek        ;Branch argument, byte 1
  111.          bit     7,a
  112.          jr      z,rbranch       ;Meaning reversed?
  113. rnbrnch:
  114.         bit     6,a
  115.         scf
  116.         ret     nz              ;IF only one byte, skip it.
  117.         jp      zpcipeek        ;Skip 2nd byte
  118. ;
  119. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  120. ;
  121. ;Arithmetic & logic operations
  122. ;
  123. z_and:  ld      hl,(v_arg1)
  124.         ld      de,(v_arg2)
  125.         ld      a,h
  126.         and     d
  127.         ld      h,a
  128.         ld      a,l
  129.         and     e
  130.         ld      l,a
  131.         scf
  132.         jp      ret_hl
  133. ;
  134. z_or:   ld      hl,(v_arg1)
  135.         ld      de,(v_arg2)
  136.         ld      a,h
  137.         or      d
  138.         ld      h,a
  139.         ld      a,l
  140.         or      e
  141.         ld      l,a
  142.         scf
  143.         jp      ret_hl
  144. ;
  145. testv:  ld      hl,(v_arg1)
  146.         ld      de,(v_arg2)
  147.         ld      a,d
  148.         and     h
  149.         cp      d
  150.         jp      nz,nbranch
  151.         ld      a,e
  152.         and     l
  153.         cp      e
  154.         jp      nz,nbranch
  155.         jp      branch
  156. ;
  157. z_add:  ld      hl,(v_arg1)
  158.         ld      de,(v_arg2)
  159.         add     hl,de
  160.         scf
  161.         jp      ret_hl
  162. ;
  163. z_sub:  ld      hl,(v_arg1)
  164.         ld      de,(v_arg2)
  165.         and     a
  166.         sbc     hl,de
  167.         scf
  168.         jp      ret_hl
  169. ;
  170. z_mul:  ld      de,(v_arg1)
  171.         ld      bc,(v_arg2)
  172.         call    mult16
  173.         ex      de,hl
  174.         scf
  175.         jp      ret_hl
  176. ;
  177. z_div:  ld      bc,(v_arg1)
  178.         ld      de,(v_arg2)
  179.         call    sdiv16
  180.         jp      nc,div0
  181.         ld      h,b
  182.         ld      l,c
  183.         jp      ret_hl
  184. ;
  185. z_mod:  ld      bc,(v_arg1)
  186.         ld      de,(v_arg2)
  187.         call    smod16
  188.         jp      nc,div0
  189.         jp      ret_hl
  190. ;
  191. z_dck:  ld      a,(v_arg1)      ;Variable number
  192.         push    af
  193.         call    get_var         ;value into HL
  194.         pop     af
  195.         dec     hl              ;Decrement
  196.         push    hl
  197.         call    put_var         ;Write back
  198.         pop     hl
  199.         ld      de,(v_arg2)     ;Limit
  200.         call    cpsign          ;Now under limit?
  201.         jp      c,branch
  202.         jp      nbranch
  203. ;
  204. z_ick:  ld      a,(v_arg1)      ;Variable number
  205.         push    af
  206.         call    get_var         ;value into HL
  207.         pop     af
  208.         inc     hl              ;Decrement
  209.         push    hl
  210.         call    put_var         ;Write back
  211.         pop     de
  212.         ld      hl,(v_arg2)     ;Limit
  213.         call    cpsign          ;Limit now < value?
  214.         jp      c,branch
  215.         jp      nbranch
  216. ;
  217. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  218. ;
  219. ;get_property; get_property_addr; get_next_property
  220. ;
  221. z_gp:   ld      de,(v_arg1)     ;Get property - object DE property BC
  222.         ld      a,d             ;<< v1.01 Object 0 error avoidance
  223.         or      e
  224.         jr      z,pret0         ;>> v1.01
  225.         ld      bc,(v_arg2)
  226.         call    gprop
  227.         scf
  228.         jp      ret_hl
  229. ;
  230. z_gpa:  ld      de,(v_arg1)     ;Get property addr - object DE
  231.         ld      a,d             ;<< v1.01 Object 0 error avoidance
  232.         or      e
  233.         jr      z,pret0         ;>> v1.01
  234.         ld      bc,(v_arg2)     ;                    property BC
  235.         call    gpaddr
  236.         scf
  237.         jp      ret_hl
  238. ;
  239. z_gnp:  ld      de,(v_arg1)
  240.         ld      a,d             ;<< v1.01 Object 0 error avoidance
  241.         or      e               ;<< v1.04 This incorrectly returned 0
  242.                                 ;>> v1.04 for objects 0-255
  243.         jr      z,pret0         ;>> v1.01
  244.         ld      bc,(v_arg2)
  245.         call    gnprop
  246.         scf
  247.         jp      ret_hl
  248. ;
  249. ;<< v1.01 Results for Object 0
  250. ;
  251. pret0:  ld      hl,0
  252.         scf
  253.         jp      ret_hl
  254. ;
  255. ;>> v1.01
  256. ;
  257. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  258. ;
  259. ;Setting, clearing and testing attributes
  260. ;
  261. z_ta:   ld      de,(v_arg1)
  262.         ld      a,d             ;<< v1.01 Eliminate Object 0 error
  263.         or      e
  264.         jp      z,nbranch       ;>> v1.01
  265.         ld      bc,(v_arg2)
  266.         call    attradd
  267.         call    peek64
  268.         and     b
  269.         jp      nz,branch
  270.         jp      nbranch
  271. ;
  272. z_sa:   ld      de,(v_arg1)
  273.         ld      a,d             ;<< v1.01 Eliminate Object 0 error
  274.         or      e
  275.         scf
  276.         ret     z               ;>> v1.01
  277.         ld      bc,(v_arg2)
  278.         call    attradd
  279.         call    peek64
  280.         or      b
  281.         call    ZXPOKE
  282.         scf
  283.         ret
  284. ;
  285. z_ca:   ld      de,(v_arg1)
  286.         ld      a,d             ;<< v1.01 Eliminate Object 0 error
  287.         or      e
  288.         scf
  289.         ret     z               ;>> v1.01
  290.         ld      bc,(v_arg2)
  291.         call    attradd
  292.         ld      a,b
  293.         cpl
  294.         ld      b,a
  295.         call    peek64
  296.         and     b
  297.         call    ZXPOKE
  298.         scf
  299.         ret
  300. ;
  301. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  302. ;
  303. ;JIN
  304. ;
  305. z_jin:  ld      de,(v_arg1)
  306.         ld      a,d             ;<< v1.01
  307.         or      e               ;Avoid Zero Error; if 1st operand
  308.         jp      z,nbranch       ;is 0, don't branch. >>
  309.         call    objadd          ;HL->object
  310.         ld      a,(zver)
  311.         cp      4
  312.         jr      c,v3jin
  313.         ld      de,6
  314.         add     hl,de
  315.         ld      e,0
  316.         call    ZXPKWI
  317.         ld      e,c
  318.         ld      d,b             ;DE = parent
  319.         ld      hl,(v_arg2)
  320.         call    cpusgn          ;Unsigned compare DE,HL
  321.         jp      z,branch
  322.         jp      nz,nbranch
  323. ;
  324. v3jin:  ld      de,4
  325.         add     hl,de
  326.         call    peek64   ;Parent
  327.         ld      e,a     ;<< v0.04 >> Bug fix: compare A with parent, not 4!
  328.         ld      a,(v_arg2)
  329.         cp      e
  330.         jp      z,branch
  331.         jp      nbranch
  332. ;
  333. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  334. ;
  335. call2n: ld      a,2             ;CALL with 1 parameter, dump result
  336.         ld      (v_argc),a
  337.         ld      a,1
  338.         jp      call_gen
  339. ;
  340. call2s: ld      a,2             ;CALL with 1 parameter, keep result
  341.         ld      (v_argc),a
  342.         xor     a
  343.         jp      call_gen
  344. ;
  345. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  346. ;
  347. ;Load and store operations
  348. ;
  349. z_ldb:  ld      hl,(v_arg1)
  350.         ld      bc,(v_arg2)
  351.         add     hl,bc
  352.         call    peek64
  353.         ld      l,a
  354.         ld      h,0
  355.         scf
  356.         jp      ret_hl
  357. ;
  358. z_ldw:  ld      hl,(v_arg1)     ;Array
  359.         ld      bc,(v_arg2)     ;Offset
  360.         add     hl,bc
  361.         add     hl,bc
  362.         ld      e,0
  363.         call    ZXPKWI          ;Read word into bc
  364.         ld      h,b
  365.         ld      l,c
  366.         scf
  367.         jp      ret_hl
  368. ;
  369. store:  ld      a,(v_arg1)      ;Variable
  370.         ld      hl,(v_arg2)     ;Value
  371.         scf
  372.         jp      put_var
  373. ;
  374. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  375. ;
  376. z_scol: ld      a,(v_arg1)
  377.         ld      b,a
  378.         ld      a,(v_arg2)
  379.         ld      c,a
  380.         jp      ZXSCOL          ;SET colour
  381. ;
  382. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  383. ;
  384. insobj: ld      de,(v_arg1)
  385.         ld      hl,(v_arg2)
  386.         ld      a,d             ;<< v1.01 avoid Object 0 errors
  387.         or      e
  388.         scf
  389.         ret     z
  390.         ld      a,h
  391.         or      l
  392.         scf
  393.         ret     z               ;>> v1.01
  394.         call    obj_insert
  395.         scf
  396.         ret
  397. ;
  398. ;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;
  399. ;
  400. throw:  ld      de,(v_arg2)     ;Stack frame value
  401.         ld      hl,(zstop)
  402.         and     a
  403.         sbc     hl,de           ;HL -> new ZSP
  404.         ld      (zsp),hl
  405.         ld      hl,(v_arg1)     ;Return value
  406.         jp      z_ret
  407. ;
  408.