From bdd7fe6971912602b68ccf80a35f57dbc6b24a36 Mon Sep 17 00:00:00 2001 From: Scott Duensing Date: Tue, 12 Feb 2019 20:31:09 -0600 Subject: [PATCH] IIgs nibble swap working. --- joeylib/build-PC.sh | 1 + joeylib/src/jIIgs.asm | 57 ++++++++++++++++++++++++++++++++++++++++- joeylib/src/jIIgs.c | 2 +- joeylib/src/jIIgs.macro | 3 +-- joeylib/src/jPC.c | 13 +++++++++- joeylib/src/joey.c | 2 +- joeylib/src/joey.h | 13 ++++++---- joeylib/src/test.c | 17 ++++++++---- 8 files changed, 92 insertions(+), 16 deletions(-) diff --git a/joeylib/build-PC.sh b/joeylib/build-PC.sh index bec2637..6f77a81 100755 --- a/joeylib/build-PC.sh +++ b/joeylib/build-PC.sh @@ -6,6 +6,7 @@ SRC="${JOEY}/joeylib/joeylib/src" function doBuild() { + echo "*** Starting ${DIST}" if [ -d "${BUILD}" ]; then rm -rf "${BUILD}" fi diff --git a/joeylib/src/jIIgs.asm b/joeylib/src/jIIgs.asm index ad544ae..b254043 100644 --- a/joeylib/src/jIIgs.asm +++ b/joeylib/src/jIIgs.asm @@ -1,6 +1,6 @@ ;---------------------------------------- ; JoeyLib -; Copyright (C) 2018 Scott Duensing +; Copyright (C) 2018-2019 Scott Duensing ; ; This software is provided 'as-is', without any express or implied ; warranty. In no event will the authors be held liable for any damages @@ -370,6 +370,61 @@ gotpdl0 xba ; 3c jreturn 2:pret0 end +;---------------------------------------- +; Swaps nibble values +; +; Psychotically commented to help learn ASM :-) +;---------------------------------------- +asmNSwap start + +hnibo equ 1 ; High nibble old color value +hnibn equ 2 ; High nibble new color value + + jsubroutine (4:P,2:C,2:O,2:N),2 + + short m ; Use 8 bit accumulator + lda N ; Load new color to use + asl a ; Shift it up a nibble + asl a + asl a + asl a + sta hnibn ; Store it for later + lda O ; Load old color to use (16 bit argument) + asl a ; Shift it up a nibble + asl a + asl a + asl a + sta hnibo ; Store it for later + + ldy #0 ; Load Y (our counter) with 0 + +NSLow lda [P],y ; Get byte to check + and #$0F ; Isolate low nibble + cmp O ; Compare to old value + bne NSHigh ; Not equal, skip to high nibble + lda [P],y ; Get byte to modify + and #$F0 ; Clear low nibble + ora N ; Set low nibble to new color + sta [P],y ; Store it back + +NSHigh lda [P],y ; Get byte to check + and #$F0 ; Isolate high nibble + cmp hnibo ; Compare to old color + bne NSEnd ; Not equal, skip to next byte + lda [P],y ; Get byte to modify + and #$0F ; Clear high nibble + ora hnibn ; Set high nibble to new color + sta [P],y ; Store it back + +NSEnd iny ; Increment Y + clc ; Clear carry + cpy C ; Compare Y to number of bytes to modify + bcc NSLow ; Keep going + + long m ; Back to 16 bit accumulator + jreturn + end + ;---------------------------------------- ; Plots a point in a given color ; diff --git a/joeylib/src/jIIgs.c b/joeylib/src/jIIgs.c index 276ccd4..1d52aac 100644 --- a/joeylib/src/jIIgs.c +++ b/joeylib/src/jIIgs.c @@ -1,6 +1,6 @@ /* * JoeyLib - * Copyright (C) 2018 Scott Duensing + * Copyright (C) 2018-2019 Scott Duensing * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/joeylib/src/jIIgs.macro b/joeylib/src/jIIgs.macro index 892cf9b..dbc8987 100644 --- a/joeylib/src/jIIgs.macro +++ b/joeylib/src/jIIgs.macro @@ -1,6 +1,6 @@ ;---------------------------------------- ; JoeyLib -; Copyright (C) 2018 Scott Duensing +; Copyright (C) 2018-2019 Scott Duensing ; ; This software is provided 'as-is', without any express or implied ; warranty. In no event will the authors be held liable for any damages @@ -26,7 +26,6 @@ MACRO &lab jsubroutine &parms,&work &lab anop - using savedDBR ; ADDED aif c:&work,.a lclc &work &work setc 0 diff --git a/joeylib/src/jPC.c b/joeylib/src/jPC.c index ef0c8e4..a4d8c99 100644 --- a/joeylib/src/jPC.c +++ b/joeylib/src/jPC.c @@ -1,6 +1,6 @@ /* * JoeyLib - * Copyright (C) 2018 Scott Duensing + * Copyright (C) 2018-2019 Scott Duensing * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -460,6 +460,17 @@ bool jlUtilMustExit(void) { } +void jlUtilNibbleSwap(byte *mem, jint16 count, byte old, byte new) { + int x; + jlPixelPairT *b; + for (x=0; xl == old) b->l = new; + if (b->r == old) b->r = new; + } +} + + void jlUtilShutdown(void) { int x; diff --git a/joeylib/src/joey.c b/joeylib/src/joey.c index ab6bb91..3b329e6 100644 --- a/joeylib/src/joey.c +++ b/joeylib/src/joey.c @@ -1,6 +1,6 @@ /* * JoeyLib - * Copyright (C) 2018 Scott Duensing + * Copyright (C) 2018-2019 Scott Duensing * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages diff --git a/joeylib/src/joey.h b/joeylib/src/joey.h index 7402330..012eb08 100644 --- a/joeylib/src/joey.h +++ b/joeylib/src/joey.h @@ -1,6 +1,6 @@ /* * JoeyLib - * Copyright (C) 2018 Scott Duensing + * Copyright (C) 2018-2019 Scott Duensing * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -255,6 +255,7 @@ void jlUtilIdle(void); #define jlUtilIsOdd(x) (((x & 1) == 1) ? true : false) char *jlUtilMakePathname(char *filename, char *extension); bool jlUtilMustExit(void); +void jlUtilNibbleSwap(byte *mem, jint16 count, byte old, byte new); void jlUtilShutdown(void) __attribute__((noreturn)); #define jlUtilStackPop(stack) _jlUtilStackPop((jlStackT **)&(stack)) // Syntatic Sugar void *_jlUtilStackPop(jlStackT **stack); @@ -276,12 +277,14 @@ extern void asmB88(byte *p, jint16 cx1, jint16 cy1, jint16 cx2, jint16 cy2); extern void asmPoint(jint16 color, jint16 x, jint16 y); extern jint16 asmGetPoint(jint16 x, jint16 y); extern juint16 asmGetVbl(void); +extern void asmNSwap(byte *mem, jint16 count, jint16 old, jint16 new); // Inlined functions -#define jlDrawBlit8x8(sta, cx1, cy1, cx2, cy2) asmB88((byte *)sta->pixels, cx1, cy1, cx2, cy2); -#define jlDrawGetPixel(x, y) asmGetPoint(x, y) -#define jlDrawPoint(x, y) asmPoint(_jlDrawColorNibbles, x, y) -#define jlUtilTimer asmGetVbl +#define jlDrawBlit8x8(sta, cx1, cy1, cx2, cy2) asmB88((byte *)sta->pixels, cx1, cy1, cx2, cy2) +#define jlDrawGetPixel(x, y) asmGetPoint(x, y) +#define jlDrawPoint(x, y) asmPoint(_jlDrawColorNibbles, x, y) +#define jlUtilNibbleSwap(mem, count, old, new) asmNSwap(mem, count, (jint16)old, (jint16)new) +#define jlUtilTimer asmGetVbl #ifdef JOEY_DEBUG void _jlDebugBorder(jlBorderColorsE color); diff --git a/joeylib/src/test.c b/joeylib/src/test.c index 180922f..4934fe9 100644 --- a/joeylib/src/test.c +++ b/joeylib/src/test.c @@ -1,6 +1,6 @@ /* * JoeyLib - * Copyright (C) 2018 Scott Duensing + * Copyright (C) 2018-2019 Scott Duensing * * This software is provided 'as-is', without any express or implied * warranty. In no event will the authors be held liable for any damages @@ -59,29 +59,36 @@ int main(void) { jlStaT *kanga = NULL; jlStaT *font = NULL; jint16 y; + jint16 color = 15; + jint16 nextColor = 1; jlUtilStartup("JoeyLib Test"); - jlStaLoad(kanga, "kanga"); - jlStaLoad(font, "font"); + if (!jlStaLoad(kanga, "kanga")) jlUtilDie("Unable to load kanga.sta!"); + if (!jlStaLoad(font, "font")) jlUtilDie("Unable to load font.sta!"); jlStaDisplay(kanga); jlDrawColor(1); jlDrawBox(0, 0, 319, 199); - jlSoundMusicPlay("music"); + //jlSoundMusicPlay("music"); jlPaletteSet(15, 15, 15, 15); + printAt(font, 1, 16, "X"); while (!jlKeyPressed()) { y = 17; printAt(font, 1, y++, "X = %d ", jlGameGetAxis(0)); printAt(font, 1, y++, "Y = %d ", jlGameGetAxis(1)); printAt(font, 1, y++, "T = %d ", jlUtilTimer()); jlDisplayPresent(); + jlUtilNibbleSwap((byte *)font->pixels, 32000, (byte)(color), (byte)(nextColor)); + color = nextColor; + nextColor++; + if (nextColor > 15) nextColor = 1; } jlKeyRead(); - jlSoundMusicStop(); + //jlSoundMusicStop(); jlStaFree(font); jlStaFree(kanga);