Quantcast
Channel: Atari Systems Forums
Viewing all articles
Browse latest Browse all 22482

Darklib ACTION! library development thread

$
0
0
For some time, I am making library for use with my Action code. It simplifies most of tasks and will help all new ACTION! users.

Most of it is general use library, but I've also started to develop functions that would help to make multimedia software such as games. For now only one such function exist, Draw which can be used for drawing tiles in playfield or software sprites.

Library code:
;DarkLib
;Useful Action! functions
;Written by Dariusz "Darkhog"
;G. Jagielski
;Include this AFTER runtime as 
;this lib uses it.

proc draw (byte array image, byte x, byte y, byte w, byte h, card arlen)
;Draws picture to the screen.
;byte array image = array of color
;indices
;x,y = position to draw on
; w = width of image in pixels
; h = height of picture in px
; arlen = length of array you're using
byte xtemp, ytemp
card curstep

for xtemp = x to (x+w)-1
do
  for ytemp=y to y+h
  do	
	curstep = (xtemp-x)+((ytemp-y)*w)
	if curstep<arlen then
	  color=image(curstep)

	else
	  color = 0
	fi
	plot(xtemp,ytemp) 
  od
od
return

PROC ANYKEY()
   BYTE CHR = 764
   CHR = 255
   WHILE CHR=255 DO OD ; HALTING
					   ; TIL PRESSED
					   ; <ANY> KEY.
RETURN

CARD FUNC CARDMUL(CARD A, CARD B)
  ; Reimplementation of 
  ; multiply command so it will work
  ; properly for result values higher
  ; than 32767 (Action assumes that
  ; when multiplying, operands are
  ; INTs so it doesn't work for CARDs
  ; properly)
  CARD I = [0]
  CARD TMP=[0]
  FOR I = 0 TO B
  DO
	TMP = TMP+A
  OD 
RETURN(TMP)

proc Delay(CARD frm)
  ; Halts program execution for X frames
  ; One frame = 1/60 sec.
  BYTE RC1 = 18
  BYTE RC2 = 19
  BYTE RC3 = 20
  CARD RTC
  RC1 = 0
  RC2 = 0
  RC3 = 0
  RTC = 0
  While RTC<frm 
  do
	RTC = CARDMUL(RC2,256)+RC3
  od
return

PROC DelayC(Card Cycles)
  ;Halts program for X cycles
  card i
  for i=0 to cycles
  do
   ;****nop
  od
return

module

API Reference:

While code is well-documented using comments, I'd like to present API reference.

proc draw (byte array image, byte x, byte y, byte w, byte h, card arlen)
Draws picture to the screen.
"Image" array is array used to store image. It is simple array of color indices (i.e. same values you'd pass to color variable when drawing pixel by pixel)
X,Y is position on the screen, relative to the top-left corner of the screen. Warning: X+W (see below) and Y+H shouldn't exceed graphic mode's resolution, or bad things may happen.
W,H - Width and height of image. Needed to properly display it.
arlen - length of array used to store image.

Example program:
;Smile.act
;Draws smile to the screen.

include "D:Darklib.act"

byte array smile =
[0 0 0 1 1 1 0 0 0
 0 0 1 2 2 2 1 0 0
 0 1 2 3 2 3 2 1 0
 1 2 2 2 2 2 2 2 1
 1 2 3 2 2 2 3 2 1
 0 1 2 3 3 3 2 1 0
 0 0 1 2 2 2 1 0 0
 0 0 0 1 1 1 ]

proc Main()
graphics(5)
setcolor(0,14,5)
setcolor(4,0,15)
setcolor(1,14,15)
setcolor(2,13,10)
draw(smile, 2,2, 9,8, 69)
ANYKEY()
return


PROC ANYKEY()
Halts program until you press some key.
Example code:
;any.act
;ANYKEY() demo.

include "D:Darklib.act"
proc Main()
Printe("Press *ANY* Key")
ANYKEY()
return

CARD FUNC CARDMUL(CARD A, CARD B)
Quote from ACTION! manual, page 63:

Quote

TECHNICAL NOTE: using the  * operand results in an INT
type,  so  multiplication of very large CARD values (>
32767) will not work properly.
Because of that, this function was invented. You should only use it if result value can exceed 32767, as this is slower than regular multiplication.

proc Delay(CARD frm)
Halts program for specified number of frames, a.k.a jiffies. It can be used to time game properly (at end of game control loop you add Delay(1) to ensure it is executed only once per frame and thus making game timing constant)

PROC DelayC(Card Cycles)
Similar to Delay, but pauses for specified number of processor cycles. Used when you need more precise timing than Delay can offer you (such as timing music routines).

Viewing all articles
Browse latest Browse all 22482

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>