$NetBSD: patch-an,v 1.1 2006/06/30 12:54:38 tron Exp $

--- src/loaders/med_load.c.orig	2001-01-13 19:58:02.000000000 +0000
+++ src/loaders/med_load.c	2006-06-30 13:48:59.000000000 +0100
@@ -31,6 +31,25 @@
 
 static int bpmon, bpmlen;
 
+static void big_endian_uint16_t(void *p)
+{
+	uint16	*x16p, x16;
+
+	x16p = p;
+	x16 = *x16p;
+	B_ENDIAN16(x16);
+	*x16p = x16; 
+}
+
+static void big_endian_uint32_t(void *p)
+{
+	uint32	*x32p, x32;
+
+	x32p = p;
+	x32 = *x32p;
+	B_ENDIAN32(x32);
+	*x32p = x32; 
+}
 
 static void xlat_fx (uint8 *fxt, uint8 *fxp)
 {
@@ -136,11 +155,11 @@
 
     header = (struct MMD0 *)mmd;
 
-    B_ENDIAN32 ((uint32)header->modlen);
-    B_ENDIAN32 ((uint32)header->song);
-    B_ENDIAN32 ((uint32)header->blockarr);
-    B_ENDIAN32 ((uint32)header->smplarr);
-    B_ENDIAN32 ((uint32)header->expdata);
+    big_endian_uint32_t(&header->modlen);
+    big_endian_uint32_t(&header->song);
+    big_endian_uint32_t(&header->blockarr);
+    big_endian_uint32_t(&header->smplarr);
+    big_endian_uint32_t(&header->expdata);
 
     song = (struct MMD0song *)(mmd + (uint32)header->song);
     song2 = (struct MMD2song *)(mmd + (uint32)header->song);
@@ -148,21 +167,21 @@
 	(uint32)header->expdata) : NULL;
 
     if (expdata) {
-	B_ENDIAN32 ((uint32)expdata->nextmod);
-	B_ENDIAN32 ((uint32)expdata->exp_smp);
-	B_ENDIAN16 ((uint16)expdata->s_ext_entries);
-	B_ENDIAN16 ((uint16)expdata->s_ext_entrsz);
-	B_ENDIAN32 ((uint32)expdata->annotxt);
-	B_ENDIAN32 ((uint32)expdata->annolen);
-	B_ENDIAN32 ((uint32)expdata->iinfo);
-	B_ENDIAN16 ((uint16)expdata->i_ext_entries);
-	B_ENDIAN16 ((uint16)expdata->i_ext_entrsz);
-	B_ENDIAN32 ((uint32)expdata->jumpmask);
-	B_ENDIAN32 ((uint32)expdata->rgbtable);
-	B_ENDIAN32 ((uint32)expdata->n_info);
-	B_ENDIAN32 ((uint32)expdata->songname);
-	B_ENDIAN32 ((uint32)expdata->songnamelen);
-	B_ENDIAN32 ((uint32)expdata->dumps);
+	big_endian_uint32_t(&expdata->nextmod);
+	big_endian_uint32_t(&expdata->exp_smp);
+	big_endian_uint16_t(&expdata->s_ext_entries);
+	big_endian_uint16_t(&expdata->s_ext_entrsz);
+	big_endian_uint32_t(&expdata->annotxt);
+	big_endian_uint32_t(&expdata->annolen);
+	big_endian_uint32_t(&expdata->iinfo);
+	big_endian_uint16_t(&expdata->i_ext_entries);
+	big_endian_uint16_t(&expdata->i_ext_entrsz);
+	big_endian_uint32_t(&expdata->jumpmask);
+	big_endian_uint32_t(&expdata->rgbtable);
+	big_endian_uint32_t(&expdata->n_info);
+	big_endian_uint32_t(&expdata->songname);
+	big_endian_uint32_t(&expdata->songnamelen);
+	big_endian_uint32_t(&expdata->dumps);
     }
 
     for (i = 0; i < 63; i++) {
@@ -198,7 +217,7 @@
 
     for (i = 0; i < xxh->ins; i++) {
 	bytecopy(&instr, mmd + (uint32)header->smplarr + i * 4, 4);
-	B_ENDIAN32 ((uint32)instr);
+	big_endian_uint32_t(&instr);
 	if (!instr)
 	    continue;
 	instr = (struct InstrHdr *)(mmd + (uint32)instr);
@@ -225,16 +244,16 @@
     if (ver < 2) {
 	memcpy (xxo, song->playseq, xxh->len);
     } else {
-	B_ENDIAN32 ((uint32)song2->playseqtable);
+	big_endian_uint32_t(&song2->playseqtable);
 	playseq = (struct PlaySeq **)(mmd + (uint32)song2->playseqtable);
-	B_ENDIAN32 ((uint32)playseq[0]);
+	big_endian_uint32_t(&playseq[0]);
 	playseq[0] = (struct PlaySeq *)(mmd + (uint32)playseq[0]);
-	B_ENDIAN16 ((uint16)playseq[0]->length);
+	big_endian_uint16_t(&playseq[0]->length);
 	xxh->len = playseq[0]->length;
 	if (xxh->len > 0xff)
 	    xxh->len = 0xff;
 	for (i = 0; i < xxh->len; i++) {
-	    B_ENDIAN16 ((uint16)playseq[0]->seq[i]);
+	    big_endian_uint16_t(&playseq[0]->seq[i]);
 	    xxo[i] = playseq[0]->seq[i];
 	}
     }
@@ -243,7 +262,7 @@
 
     for (i = 0; i < xxh->pat; i++) {
 	bytecopy(&block0, mmd + (uint32)header->blockarr + i * 4, 4);
-	B_ENDIAN32 ((uint32)block0);
+	big_endian_uint32_t(&block0);
 	block0 = (struct MMD0Block *)(mmd + (uint32)block0);
 	block1 = (struct MMD1Block *)block0;
 
@@ -283,7 +302,7 @@
 
     for (i = 0; i < xxh->pat; i++) {
 	bytecopy(&block0, mmd + (uint32)header->blockarr + i * 4, 4);
-	B_ENDIAN32 ((uint32)block0);
+	big_endian_uint32_t(&block0);
 	block0 = (struct MMD0Block *)(mmd + (uint32)block0);
 	block1 = (struct MMD1Block *)block0;
 
@@ -345,7 +364,7 @@
 
     for (smp_idx = i = 0; i < xxh->ins; i++) {
 	bytecopy(&instr, mmd + (uint32)header->smplarr + i * 4, 4);
-	B_ENDIAN32 ((uint32)instr);
+	big_endian_uint32_t(&instr);
 	if (!instr)
 	    continue;
 	instr = (struct InstrHdr *)(mmd + (uint32)instr);
@@ -381,7 +400,7 @@
 	    xxih[i].vts = synth->volspeed;
 	    xxih[i].wts = synth->wfspeed;
 
-	    B_ENDIAN32 ((uint32)synth->wf[0]);
+	    big_endian_uint32_t(&synth->wf[0]);
 	    instr = (struct InstrHdr *)((char *)synth + (uint32)synth->wf[0]);
 	    B_ENDIAN32 (instr->length);
 	    B_ENDIAN16 (instr->type);
@@ -438,7 +457,7 @@
 	    xxih[i].wts = synth->wfspeed;
 
 	    for (j = 0; j < synth->wforms; j++) {
-	        B_ENDIAN32 ((uint32)synth->wf[j]);
+	        big_endian_uint32_t(&synth->wf[j]);
 
 		xxi[i][j].pan = 0x80;
 		xxi[i][j].vol = song->sample[i].svol;
