From 9ed846b2c53224e056ebca0d8f8b63842ba39d5a Mon Sep 17 00:00:00 2001 From: Toni Wilen Date: Fri, 10 May 2019 18:59:23 +0300 Subject: [PATCH] Updates. --- utilities/stateload/asm.S | 71 +++++++++++++++++++++++++++------- utilities/stateload/header.h | 6 ++- utilities/stateload/main.c | 68 +++++++++++++++++++++++--------- utilities/stateload/readme.txt | 5 ++- 4 files changed, 114 insertions(+), 36 deletions(-) diff --git a/utilities/stateload/asm.S b/utilities/stateload/asm.S index 693c6591..9590d059 100644 --- a/utilities/stateload/asm.S +++ b/utilities/stateload/asm.S @@ -68,16 +68,52 @@ _runit: subq.l #8,sp lea 0xdff000,a6 - | wait for first line + | find last line + moveq #0,d5 + lea 0x6(a6),a2 .wait1: - move.l 4(a6),d0 - lsr.l #8,d0 - and.w #511,d0 - cmp.w #258,d0 - bne .wait1 + cmp.b #250,(a2) + bne.s .wait1 +.wait1a: + cmp.b #2,(a2) + bne.s .wait1a +.wait1b: + move.w 4(a6),d0 + btst #0,d0 + beq.s .wait1c + move.b (a2),d0 + cmp.b d0,d5 + bcc.s .wait1b + move.b d0,d5 + bra.s .wait1b +.wait1c: + cmp.b #160,(a2) + bne.s .wait1c + + | last line - 14 + sub.b #14,d5 +.wait3: + cmp.b (a2),d5 + bne.s .wait3 move.w #0x1234,0xfc0004 + move.l CUSTOM_CHUNK(a4),a0 + move.w 4+0x96(a0),d0 | DMACON + and.w #15,d0 + or.w #0x8200,d0 + | enable audio DMA + move.w d0,0x96(a6) + + | wait few lines, enough time for audio channels to enter normal 2/3 states + addq.w #4,d5 +.wait4: + cmp.b (a2),d5 + bne.s .wait4 + | restore latched AUDxLEN and AUDxPT + move.l a4,(sp) + bsr _set_audio_final + | restore possible side-effect causing | custom bits as late as possible @@ -97,9 +133,9 @@ _runit: move.l 4+4+60+4+2+2(a0),a1 | USP move.l a1,USP cmp.l #68020,(a0) - bcs .cpu68010 + bcs.s .cpu68010 btst #1,d1 - beq .cpu68010 + beq.s .cpu68010 lea 4+4+60+4+2+2+4+4+2+4+4+4+4(a0),a1 move.l (a1)+,d0 movec d0,CAAR @@ -109,9 +145,9 @@ _runit: movec d0,MSP .cpu68010: cmp.l #68010,(a0) - bcs .cpu68000 + bcs.s .cpu68000 btst #0,d1 - beq .cpu68000 + beq.s .cpu68000 lea 4+4+60+4+2+2+4+4+2+4(a0),a1 move.l (a1)+,d0 movec d0,DFC @@ -121,7 +157,14 @@ _runit: movec d0,VBR .cpu68000: btst #0,d1 - beq .nocpu68010 + beq.s .nocpu68010 + btst #1,d1 + beq.s .nocpu68020 + btst #0,3(a4) | nocache? + beq.s .nocpu68020 + moveq #0,d0 + movec d0,CACR +.nocpu68020: move.w #0x0020,-(sp) | Format 0, Trap #0 .nocpu68010: @@ -144,10 +187,10 @@ _runit: lea 0xbfde00,a1 - | wait line 0 + | wait last line .wait2: - tst.b 0xdff005 - bne .wait2 + tst.b 0xdff006 + bne.s .wait2 | start timers move.b d6,0xbfee01-0xbfde00(a1) diff --git a/utilities/stateload/header.h b/utilities/stateload/header.h index e39842a2..125a7470 100644 --- a/utilities/stateload/header.h +++ b/utilities/stateload/header.h @@ -31,6 +31,10 @@ struct MemoryBank #define MAPROM_ACA500P (1<<1) #define MAPROM_ACA1221EC (1<<2) +#define FLAGS_NOCACHE 1 +#define FLAGS_FORCEPAL 2 +#define FLAGS_FORCENTSC 4 + struct uaestate { ULONG flags; @@ -65,5 +69,3 @@ struct uaestate UBYTE testmode; }; -void set_custom_final(UBYTE*); -void set_cia_final(UBYTE*, ULONG); diff --git a/utilities/stateload/main.c b/utilities/stateload/main.c index 44fd6585..3fe11f7a 100644 --- a/utilities/stateload/main.c +++ b/utilities/stateload/main.c @@ -2,7 +2,7 @@ /* Real hardware UAE state file loader */ /* Copyright 2019 Toni Wilen */ -#define VER "0.5" +#define VER "0.6" #include #include @@ -171,30 +171,49 @@ static void set_floppy(UBYTE *p, ULONG num) ciab->ciaprb |= CIAF_DSKSEL0 << num; } +// current AUDxLEN and AUDxPT static void set_audio(UBYTE *p, ULONG num) { - volatile UWORD *c = (volatile UWORD*)(0xdff0a0 + 16 * num); - c[8 / 2] = p[1]; // AUDxVOL - c[4 / 2] = getword(p, 1 + 1 + 1 + 1 + 2); // AUDxLEN - c[6 / 2] = getword(p, 1 + 1 + 1 + 1 + 2 + 2 + 2); // AUDxPER - c[0 / 2] = getword(p, 1 + 1 + 1 + 1 + 2 + 2 + 2 + 2); // AUDxLCH - c[2 / 2] = getword(p, 1 + 1 + 1 + 1 + 2 + 2 + 2 + 2 + 2); // AUDxLCL + volatile struct Custom *c = (volatile struct Custom*)0xdff000; + ULONG l; + c->aud[num].ac_vol = p[1]; // AUDxVOL + c->aud[num].ac_per = getword(p, 1 + 1 + 1 + 1 + 2 + 2 + 2); // AUDxPER + c->aud[num].ac_len = getword(p, 1 + 1 + 1 + 1 + 2); // AUDxLEN + l = getword(p, 1 + 1 + 1 + 1 + 2 + 2 + 2 + 2 + 2 + 2) << 16; // AUDxLCH + l |= getword(p, 1 + 1 + 1 + 1 + 2 + 2 + 2 + 2 + 2 + 2 + 2); // AUDxLCL + c->aud[num].ac_ptr = (UWORD*)l; +} + +// latched AUDxLEN and AUDxPT +void set_audio_final(struct uaestate *st) +{ + volatile struct Custom *c = (volatile struct Custom*)0xdff000; + for (UWORD num = 0; num < 4; num++) { + UBYTE *p = st->audio_chunk[num]; + ULONG l; + c->aud[num].ac_len = getword(p, 1 + 1 + 1 + 1); // AUDxLEN + l = getword(p, 1 + 1 + 1 + 1 + 2 + 2 + 2 + 2) << 16; // AUDxLCH + l |= getword(p, 1 + 1 + 1 + 1 + 2 + 2 + 2 + 2 + 2); // AUDxLCL + c->aud[num].ac_ptr = (UWORD*)l; + } } static void set_sprite(UBYTE *p, ULONG num) { - volatile UWORD *cpt = (volatile UWORD*)(0xdff120 + 4 * num); - volatile UWORD *c = (volatile UWORD*)(0xdff140 + 8 * num); + volatile struct Custom *c = (volatile struct Custom*)0xdff000; + ULONG l; - cpt[0 / 2] = getword(p, 0); // SPRxPTH - cpt[2 / 2] = getword(p, 2); // SPRxPTL - c[0 / 2] = getword(p, 2 + 2); // SPRxPOS - c[2 / 2] = getword(p, 2 + 2 + 2); // SPRxCTL + l = getword(p, 0) << 16; // SPRxPTH + l |= getword(p, 2); // SPRxPTL + c->sprpt[num] = (APTR)l; + c->spr[num].pos = getword(p, 2 + 2); // SPRxPOS + c->spr[num].ctl = getword(p, 2 + 2 + 2); // SPRxCTL } -static void set_custom(UBYTE *p) +static void set_custom(struct uaestate *st) { volatile UWORD *c = (volatile UWORD*)0xdff000; + UBYTE *p = st->custom_chunk; p += 4; for (WORD i = 0; i < 0x1fe; i += 2, c++) { @@ -272,6 +291,10 @@ static void set_custom(UBYTE *p) // BEAMCON0: PAL/NTSC only if (i == 0x1dc) { + if (st->flags & FLAGS_FORCEPAL) + v = 0x20; + else if (st->flags & FLAGS_FORCENTSC) + v = 0x00; v &= 0x20; } @@ -289,7 +312,6 @@ void set_custom_final(UBYTE *p) volatile struct Custom *c = (volatile struct Custom*)0xdff000; c->intena = 0x7fff; c->intreq = 0x7fff; - c->dmacon = 0x7fff; c->vposw = getword(p, 4 + 0x04) & 0x8000; // LOF c->dmacon = getword(p, 4 + 0x96) | 0x8000; c->intena = getword(p, 4 + 0x9a) | 0x8000; @@ -983,10 +1005,10 @@ static int parse_pass_1(FILE *f, struct uaestate *st) if (saga && !aga) { printf("- WARNING: OCS/ECS statefile but system is AGA.\n"); } - if (!sntsc && !ecs && ntsc) { + if (!sntsc && !secs && ntsc) { printf("- WARNING: NTSC statefile but system is OCS PAL.\n"); } - if (sntsc && !ecs && !ntsc) { + if (sntsc && !secs && !ntsc) { printf("- WARNING: PAL statefile but system is OCS NTSC.\n"); } st->agastate = aga; @@ -1076,7 +1098,7 @@ static void processstate(struct uaestate *st) c->color[0] = 0x444; set_agacolor(st->aga_colors_chunk); - set_custom(st->custom_chunk); + set_custom(st); for (int i = 0; i < 4; i++) { set_audio(st->audio_chunk[i], i); } @@ -1187,6 +1209,8 @@ int main(int argc, char *argv[]) printf("- debug = enable debug output.\n"); printf("- test = test mode.\n"); printf("- nomaprom = do not use map rom.\n"); + printf("- nocache = disable caches before starting (68020+)\n"); + printf("- pal/ntsc = set PAL or NTSC mode (ECS/AGA only)\n"); return 0; } @@ -1209,8 +1233,14 @@ int main(int argc, char *argv[]) st->testmode = 1; if (!stricmp(argv[i], "nomaprom")) st->usemaprom = 0; + if (!stricmp(argv[i], "nocache")) + st->flags |= FLAGS_NOCACHE; + if (!stricmp(argv[i], "pal")) + st->flags |= FLAGS_FORCEPAL; + if (!stricmp(argv[i], "ntsc")) + st->flags |= FLAGS_FORCENTSC; } - + if (!parse_pass_1(f, st)) { fseek(f, 0, SEEK_SET); if (!parse_pass_2(f, st)) { diff --git a/utilities/stateload/readme.txt b/utilities/stateload/readme.txt index f2ba1545..95184e52 100644 --- a/utilities/stateload/readme.txt +++ b/utilities/stateload/readme.txt @@ -8,7 +8,7 @@ Supported hardware configurations: Information: -CPU should match statefile config but it only causes warning. Mismatched CPU most likely won't work. +CPU should match statefile config but it only causes warning. Mismatched CPU most likely won't work but it is fully supported by ussload. RAM config must match and at least one RAM address space must be 512k larger. Both compressed and uncompressed statefiles are supported. HD compatible (statefile is completely loaded before system take over) @@ -35,6 +35,9 @@ Command line parameters: - debug = show debug information. - test = parse and load statefile, exit before system take over. - nomaprom = do not use map rom. +- nocache = disable caches before starting loaded program (68020+ only) +- pal = force PAL mode (ECS/AGA only) +- ntsc = force NTSC mode (ECS/AGA only) Background colors: -- 2.47.3