home *** CD-ROM | disk | FTP | other *** search
/ APDL Public Domain 2 / APDL_PD2A.iso / magazines / _tyrant2 / pages / page11 < prev    next >
Encoding:
Text File  |  1995-05-27  |  2.9 KB  |  93 lines

  1. >SIDE Left
  2. >POSITION 20,1900
  3. >STYLE Heading
  4. ARM coding graphics
  5. >STYLE Sub
  6. The principle
  7. >STYLE Body
  8. One thing that usually stops people writing games is the problem of plotting
  9. sprites quickly.  Hopefully I can clear this up so anybody with a rudimentary
  10. knowledge of ARM code can set about writing a game.  (If you don't know
  11. any thing about ARM code then I reccomend 'Archimedes Assembly Language'
  12. By Dabs presss)  The Idea behind plotting sprites is simple:
  13. Get some bytes form the sprite and store them in the screen memory.
  14. First of course, you must load the sprite into memory, and then must get the
  15. address of the screen memory.
  16.  
  17. THis sprite plottor is intended for use in mode 13 with a 16 by 16 sprite.
  18. However, this can eiasly be changed for use in a different mode or with a
  19. different sized sprite.
  20.  
  21. >STYLE Sub
  22. Putting theroy into practise.
  23. >STYLE Body
  24. First then, to load the sprite file in use this:
  25.  
  26. >FONT Corpus.Medium
  27. >COLOUR 
  28. &0A0A8500
  29. &FFFFFF00
  30. sprite_file%=OPENIN "<Obey$Dir>.Sprites"                 
  31. size%=EXT#sprite_file%+4:CLOSE#sprite_file%              
  32. DIM spritearea% size%                                    
  33. !spritearea%=size%:spritearea%!8=16                      
  34. SYS "OS_SpriteOp",&10A,spritearea%,"<Obey$Dir>.Sprites"  
  35.  
  36. >STYLE Body
  37. The first two lines get the size of the sprite file.
  38. The second two lines setup the sprite area.
  39. The last line loads the sprite file into the sprite area.
  40. Then all that needs to be done is write the actual plotting routine! This is it:
  41.   
  42. >FONT Corpus.Medium
  43. >COLOUR 
  44. &0A0A8500
  45. &FFFFFF00
  46. DEF PROCassemble
  47. pic%=spritearea%+60
  48. DIM p_page% 1000
  49. SYS"OS_ReadDynamicArea",2 TO screen%
  50. FOR pass=0 TO 2 STEP 2
  51. P%=p_page%
  52. [OPT pass
  53. .plot LDR r12,spriteat ;call with: r0 as x
  54.       LDR r11,screenat ;           r1 as y
  55.       MOV r4,#&14000   ;           r2 as screen bank
  56.       MUL r3,r4,r2     ;Get correct memory for bank
  57.       ADD r11,r11,r3   ;add to position in screen mem
  58.       MOV r4,#&140     ;&140 is one 'row' of memory
  59.       MUL r3,r1,r4     ;get y offset
  60.       ADD r11,r11,r3   ;Add it to position in memory
  61.       ADD r11,r11,r0   ;Add x offset
  62. >POSITION 1300,2000
  63. >SIDE Right
  64.       MOV r0,#0            ;row counter
  65. .loop LDMIA r12!,{r3-r6}   ;loads 32 bytes of pic
  66.       STMIA r11,{r3-r6}    ;stores the bytes at screen
  67.       ADD r11,r11,#320     ;add row to screen memory
  68.       ADD r0,r0,#1         ;add 1 to row count
  69.       CMP r0,#16           ;check if plotted all rows
  70.       BLT loop             ;if not goto loop
  71.       MOV PC,r14
  72.  
  73. .spriteat DCD 0
  74. .screenat DCD 0
  75.  
  76. ]NEXT   
  77.  
  78. !spriteat=pic%+56
  79. !screenat=screen%
  80. ENDPROC
  81.  
  82. >STYLE Body
  83. The problems with this are that the sprite's width in pixels must be divisible by 4 
  84. and that the plotter can only be used in mode 13.
  85.  
  86. A program that uses these routines can be found in the Magazine's Extras
  87. directory.
  88.  
  89. >STYLE Sub
  90. Thanks...
  91. >STYLE Body
  92. Thanks to chris Hubble for the code in this article.  - You're a GREAT guy,
  93. I love you! - Ooer. - Getting a bit carried away.