diff --git a/joeylib/build.sh b/joeylib/build.sh index 37aa55e..f41f22b 100755 --- a/joeylib/build.sh +++ b/joeylib/build.sh @@ -90,6 +90,7 @@ function doIIgsBuild() { popd cp -f "${OUT}/joeylib" "${DIST}/joeylib#b20000" + cp -f "${JOEY}/sdks/IIgs/Tool035#ba0000" "${JOEY}/dist/IIgs/." cp -f "${JOEY}/sdks/IIgs/Tool222#ba0000" "${JOEY}/dist/IIgs/." cp -f "${JOEY}/joeylib/scripts/build-IIgs.helper.sh" "${JOEY}/dist/." @@ -102,15 +103,20 @@ function doIIgsBuild() { cp "${JOEY}/joeylib/joeylib/src/kanga.img" "${OUT}/kanga.img#060000" cp "${JOEY}/joeylib/joeylib/src/font.img" "${OUT}/font.img#060000" cp "${JOEY}/joeylib/joeylib/src/font.stn" "${OUT}/font.stn#060000" + cp "${JOEY}/joeylib/joeylib/src/biff.img" "${OUT}/biff.img#060000" + cp "${JOEY}/joeylib/joeylib/src/biff.stn" "${OUT}/biff.stn#060000" cp "${JOEY}/joeylib/joeylib/src/music.ntp" "${OUT}/music.ntp#D50008" "${CADIUS}" createvolume "${IMPORT}" ${VOL} 32MB > /dev/null "${CADIUS}" createfolder "${IMPORT}" ${VOL}/data > /dev/null "${CADIUS}" addfile "${IMPORT}" ${VOL} "${OUT}/Test#b3db03" > /dev/null + "${CADIUS}" addfile "${IMPORT}" ${VOL}/data "${JOEY}/dist/IIgs/Tool035#ba0000" > /dev/null "${CADIUS}" addfile "${IMPORT}" ${VOL}/data "${JOEY}/dist/IIgs/Tool222#ba0000" > /dev/null "${CADIUS}" addfile "${IMPORT}" ${VOL}/data "${OUT}/kanga.img#060000" > /dev/null "${CADIUS}" addfile "${IMPORT}" ${VOL}/data "${OUT}/font.img#060000" > /dev/null "${CADIUS}" addfile "${IMPORT}" ${VOL}/data "${OUT}/font.stn#060000" > /dev/null + "${CADIUS}" addfile "${IMPORT}" ${VOL}/data "${OUT}/biff.img#060000" > /dev/null + "${CADIUS}" addfile "${IMPORT}" ${VOL}/data "${OUT}/biff.stn#060000" > /dev/null "${CADIUS}" addfile "${IMPORT}" ${VOL}/data "${OUT}/music.ntp#D50008" > /dev/null pushd "${JOEY}/sdks/IIgs/gsplus" diff --git a/joeylib/src/biff-stencil.png b/joeylib/src/biff-stencil.png new file mode 100644 index 0000000..b74ecce Binary files /dev/null and b/joeylib/src/biff-stencil.png differ diff --git a/joeylib/src/biff.png b/joeylib/src/biff.png new file mode 100644 index 0000000..290275f Binary files /dev/null and b/joeylib/src/biff.png differ diff --git a/joeylib/src/jIIgs.asm b/joeylib/src/jIIgs.asm index 513cb55..91a8bb2 100644 --- a/joeylib/src/jIIgs.asm +++ b/joeylib/src/jIIgs.asm @@ -29,7 +29,8 @@ GlobalData data ScTable ds 400 ; 400 bytes for 200 scanline offsets StTable ds 50 ; 50 bytes for 25 stencil table offsets MaTable ds 256 ; 4 bit stencil to mask word table -VblRate ds 2 ; Either 5 or 6 depending on PAL or NTSC. +VblIsPal ds 2 ; Is this machine PAL or NTSC? +VblExtra ds 2 ; Integer "extra tick" counter to keep PAL at a fake 60Hz timer VblTime ds 2 ; Integer Counter end @@ -47,8 +48,17 @@ yc equ 7 ; Y Counter jsubroutine (4:surface,4:tiles,2:sx,2:sy,2:tx,2:ty),10 using GlobalData +; Is 'tiles' null? + lda tiles + ora tiles+2 + bne tilesOK + lda #$2000 ; Set it to $012000 + sta tiles + lda #$01 + sta tiles+2 + ; Find offset into tile memory - lda sy ; Load sy to get index into scanline table +tilesOK lda sy ; Load sy to get index into scanline table asl a ; Multiply by two to get offset into scanline table (two bytes per entry in table) tay ; Divide source horizontal position by two since there are two pixels per byte @@ -128,8 +138,17 @@ tile_pix equ 13 jsubroutine (4:surface,4:tiles,4:stencil,2:sx,2:sy,2:tx,2:ty),16 using GlobalData +; Is 'tiles' null? + lda tiles + ora tiles+2 + bne tilesOK + lda #$2000 ; Set it to $012000 + sta tiles + lda #$01 + sta tiles+2 + ; Find offset into tile memory - lda sy ; Load sy to get index into scanline table +tilesOK lda sy ; Load sy to get index into scanline table asl a ; Multiply by two to get offset into scanline table (two bytes per entry in table) tay @@ -1359,7 +1378,7 @@ stenB equ 1 ; Stencil byte (only lower nibble is used) stenC equ 3 ; Stencil byte counter maskW equ 5 ; Mask word - jsubroutine (2:id,2:hertz),6 + jsubroutine (2:id,2:isPal),6 using GlobalData ldy #0 ; Load 0 into y register @@ -1430,11 +1449,12 @@ nextPix dex ; Decrement pixel counter in X cpy #256 ; Compare y to 512 (128 stencil patterns) bcc tMask ; Repeat Mask Table Loop until we do all 128 bit patterns - lda hertz ; Store refresh rate / 10 in VblCount and VblRate - sta >VblRate + lda isPal ; Is this a PAL machine? + sta >VblIsPal - lda #0 ; Reset timer - sta >VblTime + lda #0 + sta >VblTime ; Reset timer + sta >VblExtra ; Reset "extra tick" counter ph4 #VblHdr ; Start VBL interrupt task ldx #$1203 ;_SetHeartBeat @@ -1463,21 +1483,38 @@ asmStop start ;---------------------------------------- -; Increment time counter using VBLs every 1/10 second +; Increment time counter using VBLs every 1/60 second ;---------------------------------------- VblHdr start dc i4'0' ; Space for task pointer -VblCount dc i2'1' ; How many VBLs between calls (1 only on initial call) +VblCount dc i2'1' ; Call on every VBL dc i2'$A55A' ; Task signature using GlobalData long m,i - lda >VblRate ; Reset hearbeat counter + + lda #1 ; Reset task counter sta >VblCount - lda >VblTime ; Increment timer + + lda >VblIsPal ; Is this a PAL machine? + bne ntsc + + lda >VblExtra ; Load extra tick counter for PAL clock + inc a ; Increment it + cmp #5 ; Do we need an additional tick? + bne noTick + lda >VblTime ; Increment timer an extra tick inc a sta >VblTime + lda #0 ; Reset extra tick counter + +noTick sta >VblExtra ; Store count for next time + +ntsc lda >VblTime ; Increment timer + inc a + sta >VblTime + short m,i rtl end diff --git a/joeylib/src/jIIgs.c b/joeylib/src/jIIgs.c index 6935a14..c40802e 100644 --- a/joeylib/src/jIIgs.c +++ b/joeylib/src/jIIgs.c @@ -59,7 +59,7 @@ extern void asmGrOff(void); extern void asmGrOn(void); extern int asmJoy(void); extern void asmSlam(void); -extern void asmStart(jint16 myID, jint16 hertzBy10); +extern void asmStart(jint16 myID, jint16 isPal); extern void asmStop(void); @@ -125,26 +125,17 @@ jlSurfaceT jlDrawSurfaceGet(void) { void jlDrawSurfaceSet(jlSurfaceT target) { _jlDrawTarget = target; - if (target == NULL) { - _jlDrawTargetActual = (jlSurfaceT)0x012000L; - } + _jlDrawTargetActual = (target == NULL) ? (jlSurfaceT)0x012000L : target; } int jlGameGetAxis(byte which) { - static jint16 paddles = 0; jint16 r; if (which == 0) { - if (xRead) { - paddles = asmJoy(); - } - r = paddles & 0x00ff; + r = asmJoy() & 0x00ff; } else { - if (yRead) { - paddles = asmJoy(); - } - r = (paddles & 0xff00) >> 8; + r = (asmJoy() & 0xff00) >> 8; } return r - 128; @@ -352,11 +343,9 @@ void jlUtilShutdown(void) { // Shutdown tools NTPShutDown(); // NinjaTracker UnloadOneTool(222); - /* MSShutDown(); // MIDI Synth UnloadOneTool(35); SoundShutDown(); // Sound Tool Set - */ MTShutDown(); // Misc Tools DisposeAll(userid()); MMShutDown(userid()); // Memory Manager @@ -387,7 +376,6 @@ void jlUtilStartup(char *appTitle) { tempHandle = NewHandle((LongWord)0x8000, userid(), (Word)(attrLocked | attrFixed | attrAddr | attrBank), (Pointer)0x012000); JOEY_CHECK_TOOL_ERROR("NewHandle SHR") - /* // Sound Tool Set tempHandle = NewHandle((Long)DPTotal, userid(), (Word)(attrLocked | attrFixed | attrPage | attrBank), (Long)0); JOEY_CHECK_TOOL_ERROR("NewHandle Sound") @@ -404,11 +392,11 @@ void jlUtilStartup(char *appTitle) { JOEY_CHECK_TOOL_ERROR("Tool035") SetTSPtr(0, 35, initialLoad.startAddr); MSBootInit(); - JOEY_CHECK_TOOL_ERROR("MSBootInit") + // Do not JOEY_CHECK_TOOL_ERROR("MSBootInit") - it will fail when in fact it's just garbage in the A register. + // If we REALLY want to know, check carry clear. } MSStartUp(); // MIDI Synth JOEY_CHECK_TOOL_ERROR("MSStartUp") - */ // Try to load NinjaTrackerPlus from SYSTEM:TOOLS LoadOneTool(222, 0); @@ -424,8 +412,8 @@ void jlUtilStartup(char *appTitle) { } // Start assembly module - _jlHertz = (int)ReadBParam((Word)0x1D) == 0 ? 60 : 50; // Is this a PAL or NTSC machine? - asmStart(userid(), _jlHertz / 10); + _jlHertz = (int)ReadBParam((Word)0x1D) == 0 ? 60 : 50; // Is this a PAL or NTSC (0) machine? + asmStart(userid(), _jlHertz == 60 ? 0 : 1); // SHR on asmGrOn(); diff --git a/joeylib/src/jSDL2.c b/joeylib/src/jSDL2.c index 94e4e36..e10d849 100644 --- a/joeylib/src/jSDL2.c +++ b/joeylib/src/jSDL2.c @@ -168,6 +168,10 @@ void jlDrawBlit8x8(jlSurfaceT source, jint16 sx, jint16 sy, jint16 tx, jint16 ty jlPixelPairT *pixels = (jlPixelPairT *)source; jlPixelPairT *target = (jlPixelPairT *)_jlDrawTargetActual; + if (pixels == NULL) { + pixels = (jlPixelPairT *)_jlBackingStore->pixels; + } + if (jlUtilIsOdd(sx)) sx--; // sx must be even because there are two pixels per byte o1 = sy * 160 + (int)(sx * 0.5); // This is in pixels... @@ -196,6 +200,10 @@ void jlDrawBlit8x8a(jlSurfaceT source, jlStnT *stencil, jint16 sx, jint16 sy, ji jlPixelPairT *pixels = (jlPixelPairT *)source; jlPixelPairT *target = (jlPixelPairT *)_jlDrawTargetActual; + if (pixels == NULL) { + pixels = (jlPixelPairT *)_jlBackingStore->pixels; + } + if (jlUtilIsOdd(sx)) sx--; // sx must be even because there are two pixels per byte so = sy * 160 + (int)(sx * 0.5); // This is in pixels... @@ -355,9 +363,7 @@ jlSurfaceT jlDrawSurfaceGet(void) { void jlDrawSurfaceSet(jlSurfaceT target) { _jlDrawTarget = target; - if (target == NULL) { - _jlDrawTargetActual = (jlSurfaceT)_jlBackingStore->pixels; - } + _jlDrawTargetActual = (target == NULL) ? (jlSurfaceT)_jlBackingStore->pixels : target; } @@ -752,8 +758,8 @@ void jlUtilStartup(char *appTitle) { jlDrawColorSet(15); jlDisplayPresent(); - // Start 1/10th second timer - _jlTimerId = SDL_AddTimer(100, _jlUtilTimer, NULL); + // Start 1/60th second timer + _jlTimerId = SDL_AddTimer(1000 / 60, _jlUtilTimer, NULL); } diff --git a/joeylib/src/joey.c b/joeylib/src/joey.c index 8a3e01d..4db943f 100644 --- a/joeylib/src/joey.c +++ b/joeylib/src/joey.c @@ -612,11 +612,11 @@ void jlUtilRandomSeedSet(juint32 seed) { } -void jlUtilSleep(juint16 tenths) { +void jlUtilSleep(juint16 sixtieths) { juint16 t = jlUtilTimer(); juint16 d = 0; - while ((d < tenths) && !jlUtilMustExit()) { + while ((d < sixtieths) && !jlUtilMustExit()) { d = jlUtilTimeSpan(t, jlUtilTimer()); } } diff --git a/joeylib/src/joey.h b/joeylib/src/joey.h index 116f534..a33d505 100644 --- a/joeylib/src/joey.h +++ b/joeylib/src/joey.h @@ -310,7 +310,7 @@ juint16 jlUtilRandom(void); juint32 jlUtilRandomSeedGet(void); void jlUtilRandomSeedSet(juint32 seed); void jlUtilShutdown(void) __attribute__((noreturn)); -void jlUtilSleep(juint16 tenths); +void jlUtilSleep(juint16 sixtieths); #define jlUtilStackPop(stack) _jlUtilStackPop((jlStackT **)&(stack)) // Syntatic Sugar void *_jlUtilStackPop(jlStackT **stack); #define jlUtilStackPush(stack, data) _jlUtilStackPush((jlStackT **)&(stack), data) // Syntatic Sugar diff --git a/joeylib/src/test.c b/joeylib/src/test.c index 7c3d600..369203d 100644 --- a/joeylib/src/test.c +++ b/joeylib/src/test.c @@ -354,7 +354,7 @@ void showStencil(void) { jlDrawClear(); jlDrawColorSet(15); - // Draw stencil by pixel location + // Draw stencil by pixel location - this fails on the IIgs for (y=0; y<200; y++) { for (x=0; x<320; x++) { index = (y * 320 + x); @@ -372,15 +372,84 @@ void showStencil(void) { } +void stencilTest(void) { + jlImgT *kangaI = NULL; + jlImgT *biffI = NULL; + jlStnT *biffS = NULL; + jint16 y; + jint16 x; + jint16 i; + jint16 j; + + if (!jlImgLoad(kangaI, "kanga")) jlUtilDie("Unable to load kanga.img!"); + if (!jlImgLoad(biffI, "biff")) jlUtilDie("Unable to load biff.img!"); + if (!jlStnLoad(biffS, "biff")) jlUtilDie("Unable to load biff.stn!"); + + jlImgDisplay(kangaI); + + y = 50; + + while (!jlKeyPressed()) { + // Draw Biff & grab background + for (x=0; x<319-32; x++) { + for (i=0; i<3; i++) { + for (j=0; j<4; j++) { + jlDrawSurfaceSet(jlImgSurfaceGet(biffI)); + jlDrawBlit8x8(JOEY_DISPLAY, x + (j * 8), y + (i * 8), j * 8 + 32, i * 8 + 32); + jlDrawSurfaceSet(JOEY_DISPLAY); + jlDrawBlit8x8a(jlImgSurfaceGet(biffI), biffS, j * 8, i * 8, x + (j * 8), y + (i * 8)); + } + } + jlDisplayPresent(); + // Erase Biff + for (i=0; i<3; i++) { + for (j=0; j<4; j++) { + jlDrawBlit8x8(jlImgSurfaceGet(biffI), j * 8 + 32, i * 8 + 32, x + (j * 8), y + (i * 8)); + } + } + // Check for early quit + if (jlKeyPressed()) { + break; + } + } + } + jlKeyRead(); + + jlStnFree(biffS); + jlImgFree(biffI); + jlImgFree(kangaI); +} + + +void timerTest(void) { + jlImgT *font = NULL; + + if (!jlImgLoad(font, "font")) jlUtilDie("Unable to load font.img!"); + + jlDrawColorSet(0); + jlDrawClear(); + + while (!jlKeyPressed()) { + fontPrint(font, NULL, 1, 1, "Timer: %d ", jlUtilTimer()); + jlDisplayPresent(); + } + jlKeyRead(); + + jlImgFree(font); +} + + int main(void) { jlUtilStartup("JoeyLib Test"); //blitTest(); - exerciseAPI(); + //exerciseAPI(); //grid(); //lineTest(); //musicTest(); //showStencil(); + stencilTest(); + //timerTest(); jlUtilShutdown(); } diff --git a/scripts/build-IIgs.helper.sh b/scripts/build-IIgs.helper.sh index 3cbaae1..74c6217 100644 --- a/scripts/build-IIgs.helper.sh +++ b/scripts/build-IIgs.helper.sh @@ -62,6 +62,7 @@ function buildIIgs() { ${CADIUS} createvolume ${IMPORT} ${VOL} 32MB > /dev/null ${CADIUS} createfolder ${IMPORT} ${VOL}/data > /dev/null ${CADIUS} addfile ${IMPORT} ${VOL} ${TARGET}/${PROJECT}#b3db03 > /dev/null + ${CADIUS} addfile ${IMPORT} ${VOL}/data ${JOEY}/dist/IIgs/Tool035#ba0000 > /dev/null ${CADIUS} addfile ${IMPORT} ${VOL}/data ${JOEY}/dist/IIgs/Tool222#ba0000 > /dev/null for F in "${DATA[@]}"; do N=${WORK}/data/`basename ${F}`#060000