home *** CD-ROM | disk | FTP | other *** search
/ ticalc.org / ticalc_org_rev_b.iso / archives / 85 / asm / source / routines / drawmap.asm < prev    next >
Encoding:
Assembly Source File  |  2001-07-01  |  4.1 KB  |  95 lines

  1. ;Draw Map    version 1.1
  2. ; This is a very simple moderately fast map drawing routine. It requires 10 bytes ;of RAM, 6 of which are for internal counters, the other two are the pointer to ;the map and the ofset into the map. It also requires that 6 constants be defined ;within the program somewhere. The PutSprite routine must also preserve ix.  ;DrawMap also requires a list of pointers to the sprites available for maps.
  3. ;This routine is a highly modified version of Jim Reardon's DrawMap. Like his ;routine this was designed to be easily modified.
  4. ;    Steve Teater
  5.  
  6. ;Constants:
  7. ; ColStart  -  (byte) the column at which drawing starts, relative to the width of
  8. ;              the sprite
  9. ; RowStart  -  (byte) the row at which drawing starts, relative to sprite height
  10. ; MapTotal  -  (word) the total number of sprites to draw
  11. ; NextYAt   -  (byte) number of sprites per row
  12. ; SHeight   -  (byte) height of sprite, whatever unit the sprite routine uses
  13. ; SWidth    -  (byte) width of sprite, whatever unit the sprite routine uses
  14.  
  15. ;Variable:
  16. ; MapPointer - (word) pointer to map to draw
  17. ; MapOffsetX - (byte) offset into map in the x direction
  18. ; MapOffsetY - (byte) offset into map in the y direction
  19.  
  20. ;These are the temporary variables:
  21. ; MapCurrent - (word) used to keep track of how many sprites are left
  22. ; MapWidth   - (word) holds the width of the map
  23. ; MapCoords  - (word) where to draw the next sprite
  24.  
  25. ;MapFormat:
  26. ; .db    width
  27. ; .db    spriteNumbers
  28.  
  29. DrawMap:
  30.  ld     b,ColStart * SWidth
  31.  ld     c,RowStart * SHeight
  32.  ld     (MapCoords),bc          ; store the starting draw coords
  33.  ld     ix,(MapPointer)        ; ix -> current map
  34.  ld     a,(ix)                  ; get map width
  35.  inc    ix                      ; get past width byte
  36.  ld     (MapWidth),a            ; store map width
  37.  ld    b,a
  38.  ld     a,(MapOffsetY)           ; get y coordinate of offset
  39.  ld     e,a            ; this is the same as call MUL_HL
  40.  ld    h,0            ; but it eliminates the call, jp, ret, and is
  41.  ld    d,h            ; 2 bytes shorter than rom (10.0) version
  42.  ld    l,h
  43. DrawMapMultLoop:
  44.  add    hl,de
  45.  djnz    DrawMapMultLoop         ; hl = mapwidth * offset.y
  46.  ld     a,(MapOffsetX)          ; get x coordinate of offset
  47.  ld     e,a
  48.  ld     d,0
  49.  add    hl,de                   ; hl = mapwidth * offset.y + offset.x
  50.  ex     de,hl
  51.  add    ix,de                   ; ix -> start of visible map
  52.  ld     hl,MapTotal
  53. DrawMapLoop:
  54.  ld     (MapCurrent),hl         ; save away number of sprites left
  55.  ld     a,(ix + 00)             ; get sprite num from map
  56.  inc    ix                      ; increment map pointer
  57.  ld     hl,&SpriteTable
  58.  ld     e,a
  59.  ld     d,0
  60.  add    hl,de                   ; done twice, because pointers are
  61.  add    hl,de                   ; 2 bytes
  62.  ld    a,(hl)            ; same as call LD_HL_MHL, but faster
  63.  inc    hl            ; (no call and ret)
  64.  ld    h,(hl)
  65.  ld    l,a
  66.  ld     de,(PROGRAM_ADDR)
  67.  add    hl,de                   ; relocation doesn't work here
  68.  ld     bc,(MapCoords)
  69. ; push   ix                      ; if your PutSprite does not save ix
  70.  call   &PutSprite              ; the sprite is drawn
  71. ; pop    ix                      ; if your PutSprite does not save ix
  72.  ld     a,(MapCoords + 1)       ; get x draw coordinate
  73.  add    a,SWidth                ; make equal to next location
  74.  cp     NextYAt * SWidth        ; time for a new row?
  75.  jr       c,DrawMapNoUpdate        ; 
  76. DrawMapUpdate:                  ; updates coords for a new row
  77.  ld     a,(MapCoords)           ; get y draw coord
  78.  add    a,SHeight               ; next row down
  79.  ld     (MapCoords),a           ; save y draw coord
  80.  ld     a,ColStart              ; return with beginning value of x coord
  81.                                 ; in a
  82.  ld     hl,(MapWidth)           ; get width of map
  83.  ld     de, -NextYAt / SWidth + ColStart
  84.                                 ; messy math
  85.  add    hl,de
  86.  ex     de,hl
  87.  add    ix,de                   ; make ix point to beginning of new row
  88. DrawMapNoUpdate:
  89.  ld     (MapCoords + 1),a
  90.  ld     hl,(MapCurrent)
  91.  dec    hl                      ; one sprite done
  92.  ld     a,h
  93.  or     l                       ; same as cp hl,0
  94.  jr     nz,DrawMapLoop          ; more sprites to draw?
  95.  ret