bound.asm 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465
  1. ; ---------------------------------------------------------
  2. ; Copyleft (k)2011 by Jose Rodriguez (a.k.a. Boriel)
  3. ; http://www.boriel.com
  4. ; ZX BASIC Compiler http://www.zxbasic.net
  5. ; This code is released under the BSD License
  6. ; ---------------------------------------------------------
  7. ; Implements bothe the LBOUND(array, N) and RBOUND(array, N) function
  8. ; Parameters:
  9. ; HL = N (dimension)
  10. ; [stack - 2] -> LBound table for the var
  11. ; Returns entry [N] in HL
  12. ;
  13. __BOUND:
  14. asl z80_l ;- add hl,hl ; hl *= 2
  15. rol z80_h
  16. lda z80_e ;- ex_de_hl
  17. ldx z80_l
  18. stx z80_e
  19. sta z80_l
  20. lda z80_d
  21. ldx z80_h
  22. stx z80_d
  23. sta z80_h
  24. pla ;- pop hl
  25. sta z80_h
  26. pla
  27. sta z80_l
  28. tsx ;- ex (sp),hl ; __CALLEE
  29. lda $0103,x
  30. ldy z80_h
  31. sta z80_h
  32. tya
  33. sta $0103,x
  34. lda $0104,x
  35. ldy z80_l
  36. sta z80_l
  37. tya
  38. sta $104,x
  39. clc ;- add hl,de ; hl += OFFSET __LBOUND._xxxx
  40. lda z80_l
  41. adc z80_e
  42. sta z80_l
  43. lda z80_h
  44. adc z80_d
  45. sta z80_h
  46. ldy #$00 ;- ld e,(hl) ; de = (hl)
  47. lda (z80_hl),y
  48. sta z80_e
  49. inc z80_l ;- inc hl
  50. bne *+4
  51. inc z80_h
  52. ldy #$00 ;- ld d,(hl)
  53. lda (z80_hl),y
  54. sta z80_d
  55. lda z80_e ;- ex de,hl ; hl = de => returns result in HL
  56. ldx z80_l
  57. stx z80_e
  58. sta z80_l
  59. lda z80_d
  60. ldx z80_h
  61. stx z80_d
  62. sta z80_h
  63. rts ;- ret