summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/kiro-trb.c18
-rw-r--r--src/kiro-trb.h2
2 files changed, 13 insertions, 7 deletions
diff --git a/src/kiro-trb.c b/src/kiro-trb.c
index 6a4a080..c3ed968 100644
--- a/src/kiro-trb.c
+++ b/src/kiro-trb.c
@@ -187,7 +187,7 @@ kiro_trb_get_raw_buffer (KiroTrb *self)
void *
-kiro_trb_get_element (KiroTrb *self, uint64_t element)
+kiro_trb_get_element (KiroTrb *self, glong element_in)
{
g_return_val_if_fail (self != NULL, NULL);
KiroTrbPrivate *priv = KIRO_TRB_GET_PRIVATE (self);
@@ -195,12 +195,18 @@ kiro_trb_get_element (KiroTrb *self, uint64_t element)
if (priv->initialized != 1)
return NULL;
- uint64_t relative = 0;
+ gulong offset = element_in;
+ if (0 <= element_in) {
+ offset %= priv->max_elements;
+ offset = priv->max_elements - offset;
+ }
+ else {
+ offset *= -1;
+ offset %= priv->max_elements;
+ }
- if (priv->iteration == 0)
- relative = element * priv->element_size;
- else
- relative = ((priv->current - priv->frame_top) + (priv->element_size * element)) % (priv->buff_size - sizeof (struct KiroTrbInfo));
+ gulong relative = (priv->current - priv->frame_top) + (offset * priv->element_size);
+ relative %= (priv->buff_size - sizeof(struct KiroTrbInfo));
return priv->frame_top + relative;
}
diff --git a/src/kiro-trb.h b/src/kiro-trb.h
index 806ad5e..6620191 100644
--- a/src/kiro-trb.h
+++ b/src/kiro-trb.h
@@ -199,7 +199,7 @@ void* kiro_trb_get_raw_buffer (KiroTrb *trb);
* See also:
* kiro_trb_get_element_size, kiro_trb_get_raw_buffer
*/
-void* kiro_trb_get_element (KiroTrb *trb, uint64_t index);
+void* kiro_trb_get_element (KiroTrb *trb, glong index);
/**