From 8633a0cad1d1e66e8f0c00014589b170f197a844 Mon Sep 17 00:00:00 2001 From: alpine9000 Date: Thu, 17 Mar 2016 08:28:08 +1100 Subject: [PATCH] Updated calling C example --- 021.calling_c/Makefile | 2 +- 021.calling_c/c_code.c | 33 +++++++++++++++++---------------- 021.calling_c/calling_c.s | 6 +++--- 021.calling_c/init.s | 25 +++++++++++++++---------- 4 files changed, 36 insertions(+), 30 deletions(-) diff --git a/021.calling_c/Makefile b/021.calling_c/Makefile index eb59ecb..8570207 100644 --- a/021.calling_c/Makefile +++ b/021.calling_c/Makefile @@ -1,5 +1,5 @@ SHRINKLER=0 -INTERLACE=0 +INTERLACE=1 HAM_MODE=1 EXAMPLE_NAME=calling_c diff --git a/021.calling_c/c_code.c b/021.calling_c/c_code.c index 365aaff..d034439 100644 --- a/021.calling_c/c_code.c +++ b/021.calling_c/c_code.c @@ -6,27 +6,28 @@ typedef union { } words; } word_extract_t; +typedef struct { + unsigned short pad1; + unsigned short lo; + unsigned short pad2; + unsigned short hi; +} copper_layout_t + + void -PokeBitplanePointers(unsigned short* copper, unsigned char* bitplanes, unsigned offset, unsigned numBitplanes, unsigned screenWidthBytes) +PokeBitplanePointers(unsigned short* copper, unsigned char* bitplanes, unsigned short interlace, unsigned short numBitplanes, unsigned short screenWidthBytes) { - int i; - copper += offset; + char i; + word_extract_t extract; + copper_layout_t *ptr = copper; + + bitplanes += interlace ? screenWidthBytes*numBitplanes : 0; for (i = 0; i < numBitplanes; i++) { - word_extract_t extract; extract.ptr = bitplanes; - *(copper+1) = extract.words.lo; - *(copper+3) = extract.words.hi; + ptr->lo = extract.words.lo; + ptr->hi = extract.words.hi; bitplanes += screenWidthBytes; - copper += 4; + ptr++; } } - -static unsigned short _copperData; -static unsigned char _bitplaneData; - -void -TestCall() -{ - PokeBitplanePointers(&_copperData, &_bitplaneData, 3, 4, 5); -} diff --git a/021.calling_c/calling_c.s b/021.calling_c/calling_c.s index d9a50c2..70c9fdb 100644 --- a/021.calling_c/calling_c.s +++ b/021.calling_c/calling_c.s @@ -1,7 +1,7 @@ include "includes.i" xref InstallColorPalette - ;;xref PokeBitplanePointers + xref PokeBitplanePointers xref copperList xref copperListAlternate xref bitplanes @@ -27,12 +27,12 @@ Entry: bra .mainLoop ;=========================================================== - if 0 + if 1 PokeBitplanePointers: ; d0 = frame offset in bytes; ; a0 = BPLP copper list address movem.l d0-a6,-(sp) - move.l bitplanes,a1 + lea bitplanes,a1 add.l d0,a1 ; Offset for odd/even frames moveq #SCREEN_BIT_DEPTH-1,d0 .bitplaneloop: diff --git a/021.calling_c/init.s b/021.calling_c/init.s index d697881..b1af005 100644 --- a/021.calling_c/init.s +++ b/021.calling_c/init.s @@ -12,22 +12,27 @@ Init: ;; set up default palette jsr InstallColorPalette + ;; Make a call to a C function with the following prototype: + ;; void PokeBitplanePointers(unsigned short* copper, unsigned char* bitplanes, unsigned short interlace, unsigned short numBitplanes, unsigned short screenWidthBytes) + if INTERLACE == 1 ;; poke the bitplane pointers for the two copper lists. - move.l #SCREEN_WIDTH_BYTES*SCREEN_BIT_DEPTH,d0 - lea copperListAlternate,a0 - jsr PokeBitplanePointers + move.l #SCREEN_WIDTH_BYTES,-(sp) ; arguments are pushed onto the stack... + move.l #SCREEN_BIT_DEPTH,-(sp) ; in reverse order. 16 bit variables are passed as 32 bits. + move.l #1,-(sp) ; interlace line. + pea bitplanes ; make sure you push the address... + pea copperListAlternate ; of variables, not the value. + jsr _PokeBitplanePointers ; C adds an _ to all global symbols. + add.l #20,sp ; Need to pop the arguments from the stack. endif - ;; Make a call to a C function with the following prototype: - ;; void PokeBitplanePointers(unsigned short* copper, unsigned char* bitplanes, unsigned offset, unsigned numBitplanes, unsigned screenWidthBytes) move.l #SCREEN_WIDTH_BYTES,-(sp) ; arguments are pushed onto the stack... - move.l #SCREEN_BIT_DEPTH,-(sp) ; in reverse order - move.l #0,-(sp) ; offset == 0 + move.l #SCREEN_BIT_DEPTH,-(sp) ; in reverse order. + move.l #0,-(sp) ; normal line. pea bitplanes ; make sure you push the address... - pea copperList ; of variables, not the value - jsr _PokeBitplanePointers ; C adds an _ to all global symbols - add.l #20,sp ; Need to pop the arguments from the stack + pea copperList ; of variables, not the value. + jsr _PokeBitplanePointers ; C adds an _ to all global symbols. + add.l #20,sp ; Need to pop the arguments from the stack. ;; set up playfield move.w #(RASTER_Y_START<<8)|RASTER_X_START,DIWSTRT(a6)