?login_element?

Subversion Repositories NedoOS

Rev

Rev 126 | Blame | Compare with Previous | Last modification | View Log | Download

  1. ; this is example of "for ... next" like logic recreated by current sjasmplus syntax
  2.  
  3. ; The original example source (coming from one "can I do something like..." discussion):
  4. ;
  5. ;     for half=$0000 to $0800 step $0800       ; This is calculated so it works for any buffer address.
  6. ;         for y=$0000 to $00E0 step $0020        ; (in theory)
  7. ;             for x=$0000 to $0700 step $0100
  8. ;                 dw ScreenBufferCWGI+x+y+half
  9. ;             next
  10. ;         next
  11. ;     next
  12.  
  13. ;; second version, does define "generic" FOR macro, with a subtle catch:
  14. ;; the "code?" argument can be only single expression/instruction/macro
  15. ;; But "single macro" can take you to great lengths...
  16.  
  17.     MACRO FOR var?, from?, to?, step?, code?
  18. var?=from?
  19. dup_count?=-1
  20.         IF from? <= to? && 0 < step?
  21. dup_count?=(to? - from?) / step?
  22.         ENDIF
  23.         IF to? <= from? && step? < 0
  24. dup_count?=(from? - to?) / -step?
  25.         ENDIF
  26.         IF dup_count? < 0
  27.             DISPLAY "illegal from ", from?, " to ", to?, " step ", step?, " => count=", 1+dup_count?
  28.         ELSE
  29.             DUP 1+dup_count?
  30.             code?
  31. var?=var?+step?
  32.             EDUP
  33.         ENDIF
  34.     ENDM
  35.  
  36.     MACRO fn_body
  37.         ;DISPLAY "Doing DW with [half: ", half, " y: ", y, " x: ", x, "]"
  38.         dw ScreenBufferCWGI+x+y+half
  39.     ENDM
  40.  
  41.     OUTPUT "fake_for2.bin"
  42. ScreenBufferCWGI=$4000
  43.     ;FOR half, 0, $800, $800, <FOR y, 0, $E0, $20, <FOR x, 0, $700, $100, dw ScreenBufferCWGI+x+y+half !> >
  44.     ; example with fn_body macro usage (and how to break "single instruction" limit in practice)
  45.     FOR half, 0, $800, $800, <FOR y, 0, $E0, $20, <FOR x, 0, $700, $100, fn_body !> >
  46.