diff --git a/barbara/barbara.c b/barbara/barbara.c new file mode 100644 index 0000000..0e8f77d --- /dev/null +++ b/barbara/barbara.c @@ -0,0 +1,8 @@ +uint16_t brr_shift(uint16_t s, uint8_t f) { + if(f <= 12) return (s << f) >> 1; + return (s & 0x8) << 8; +} + +int brr_process(brr* b, uint16_t* b) { + +} diff --git a/barbara/barbara.h b/barbara/barbara.h new file mode 100644 index 0000000..e084c35 --- /dev/null +++ b/barbara/barbara.h @@ -0,0 +1,20 @@ +#ifndef BARBARA_H +#define BARBARA_H + +#define B_PACK_STRUCT __attribute__((packed)) + +typedef struct { + uint8_t loop; + uint8_t end; + uint8_t shift; + uint8_t filter; +} brr_status; + +typedef struct { + uint8_t status; + uint8_t samples[8]; +} B_PACK_STRUCT brr; + +#define brr_getstatus(b, s) s->shift = b->status >> 4; s->end = b->status & 1; s->loop = (b->status >> 1) & 1; s->filter = (b->status >> 2) & 3; + +#endif diff --git a/layla/bin/howmany b/layla/bin/howmany deleted file mode 100755 index 1cdd32f..0000000 Binary files a/layla/bin/howmany and /dev/null differ diff --git a/layla/bin/laylatest b/layla/bin/laylatest deleted file mode 100755 index af63dab..0000000 Binary files a/layla/bin/laylatest and /dev/null differ diff --git a/layla/layla.h b/layla/layla.h index 53fd786..975495b 100644 --- a/layla/layla.h +++ b/layla/layla.h @@ -3,7 +3,7 @@ #include -#define PACK_STRUCT __attribute__((packed)) +#define L_PACK_STRUCT __attribute__((packed)) #define ll_swap(X, Y) X ^= Y ^= X ^= Y typedef struct { @@ -15,7 +15,7 @@ typedef struct { uint8_t M : 1; uint8_t V : 1; uint8_t N : 1; -} PACK_STRUCT ll_status_internal; +} L_PACK_STRUCT ll_status_internal; typedef union { uint8_t byte; diff --git a/spencer/main.c b/spencer/main.c index e08c9bb..b63e847 100644 --- a/spencer/main.c +++ b/spencer/main.c @@ -1,12 +1,16 @@ #include -uint8_t mmr(uint8_t reg, uint8_t d, uint8_t rw) { +uint8_t mmr(spc_cpu* s, uint8_t reg, uint8_t d, uint8_t rw) { + +} + +void stop(spc_cpu* s) { } int main(int argc, char** argv) { spc_cpu s; - spc_init(&s, malloc(0x10000), &mmr); + spc_init(&s, malloc(0x10000), &mmr, &stop); // TODO copy in new spc data while(1) { printf( "WAIT: %u\n" diff --git a/spencer/opcodes b/spencer/opcodes deleted file mode 100644 index 1ce02cd..0000000 --- a/spencer/opcodes +++ /dev/null @@ -1,275 +0,0 @@ -Mnemonic Code Bytes Cyc Operation NVPBHIZC - - NOP 00 1 2 do nothing ........ - - CLRP 20 1 2 P = 0 ..0..... - - INC X 3D 1 2 X++ N.....Z. - - SETP 40 1 2 P = 1 ..1..... - - MOV X, A 5D 1 2 X = A N.....Z. - - CLRC 60 1 2 C = 0 .......0 - - SETC 80 1 2 C = 1 .......1 - - EI A0 1 3 I = 1 .....1.. - - INC A BC 1 2 A++ N.....Z. - - DI C0 1 3 I = 0 .....0.. - - CLRV E0 1 2 V = 0, H = 0 .0..0... - - INC Y FC 1 2 Y++ N.....Z. - - - - - TCALL 0 01 1 8 CALL [$FFDE] ........ - SET1 d.0 02 2 4 d.0 = 1 ........ - BBS d.0, r 03 3 5/7 PC+=r if d.0 == 1 ........ - OR A, d 04 2 3 A = A | (d) N.....Z. - OR A, !a 05 3 4 A = A | (a) N.....Z. - OR A, (X) 06 1 3 A = A | (X) N.....Z. - OR A, [d+X] 07 2 6 A = A | ([d+X]) N.....Z. - OR A, #i 08 2 2 A = A | i N.....Z. - OR dd, ds 09 3 6 (dd) = (dd) | (ds) N.....Z. - OR1 C, m.b 0A 3 5 C = C | (m.b) .......C - ASL d 0B 2 4 Left shift (d) as above N.....ZC - ASL !a 0C 3 5 Left shift (a) as above N.....ZC - PUSH PSW 0D 1 4 (SP--) = Flags ........ - TSET1 !a 0E 3 6 (a) = (a)|A, ZN as for A-(a) N.....Z. - BRK 0F 1 8 Push PC and Flags, PC = [$FFDE] ...1.0.. - BPL r 10 2 2/4 PC+=r if N == 0 ........ - TCALL 1 11 1 8 CALL [$FFDC] ........ - CLR1 d.0 12 2 4 d.0 = 0 ........ - BBC d.0, r 13 3 5/7 PC+=r if d.0 == 0 ........ - OR A, d+X 14 2 4 A = A | (d+X) N.....Z. - OR A, !a+X 15 3 5 A = A | (a+X) N.....Z. - OR A, !a+Y 16 3 5 A = A | (a+Y) N.....Z. - OR A, [d]+Y 17 2 6 A = A | ([d]+Y) N.....Z. - OR d, #i 18 3 5 (d) = (d) | i N.....Z. - OR (X), (Y) 19 1 5 (X) = (X) | (Y) N.....Z. - DECW d 1A 2 6 Word (d)-- N.....Z. - ASL d+X 1B 2 5 Left shift (d+X) as above N.....ZC - ASL A 1C 1 2 Left shift A: high->C, 0->low N.....ZC - DEC X 1D 1 2 X-- N.....Z. - CMP X, !a 1E 3 4 X - (a) N.....ZC - JMP [!a+X] 1F 3 6 PC = [a+X] ........ - TCALL 2 21 1 8 CALL [$FFDA] ........ - SET1 d.1 22 2 4 d.1 = 1 ........ - BBS d.1, r 23 3 5/7 PC+=r if d.1 == 1 ........ - AND A, d 24 2 3 A = A & (d) N.....Z. - AND A, !a 25 3 4 A = A & (a) N.....Z. - AND A, (X) 26 1 3 A = A & (X) N.....Z. - AND A, [d+X] 27 2 6 A = A & ([d+X]) N.....Z. - AND A, #i 28 2 2 A = A & i N.....Z. - AND dd, ds 29 3 6 (dd) = (dd) & (ds) N.....Z. - OR1 C, /m.b 2A 3 5 C = C | ~(m.b) .......C - ROL d 2B 2 4 Left shift (d) as above N.....ZC - ROL !a 2C 3 5 Left shift (a) as above N.....ZC - PUSH A 2D 1 4 (SP--) = A ........ - CBNE d, r 2E 3 5/7 CMP A, (d) then BNE ........ - BRA r 2F 2 4 PC+=r ........ - BMI r 30 2 2/4 PC+=r if N == 1 ........ - TCALL 3 31 1 8 CALL [$FFD8] ........ - CLR1 d.1 32 2 4 d.1 = 0 ........ - BBC d.1, r 33 3 5/7 PC+=r if d.1 == 0 ........ - AND A, d+X 34 2 4 A = A & (d+X) N.....Z. - AND A, !a+X 35 3 5 A = A & (a+X) N.....Z. - AND A, !a+Y 36 3 5 A = A & (a+Y) N.....Z. - AND A, [d]+Y 37 2 6 A = A & ([d]+Y) N.....Z. - AND d, #i 38 3 5 (d) = (d) & i N.....Z. - AND (X), (Y) 39 1 5 (X) = (X) & (Y) N.....Z. - INCW d 3A 2 6 Word (d)++ N.....Z. - ROL d+X 3B 2 5 Left shift (d+X) as above N.....ZC - ROL A 3C 1 2 Left shift A: low=C, C=high N.....ZC - CMP X, d 3E 2 3 X - (d) N.....ZC - CALL !a 3F 3 8 (SP--)=PCh, (SP--)=PCl, PC=a ........ - TCALL 4 41 1 8 CALL [$FFD6] ........ - SET1 d.2 42 2 4 d.2 = 1 ........ - BBS d.2, r 43 3 5/7 PC+=r if d.2 == 1 ........ - EOR A, d 44 2 3 A = A EOR (d) N.....Z. - EOR A, !a 45 3 4 A = A EOR (a) N.....Z. - EOR A, (X) 46 1 3 A = A EOR (X) N.....Z. - EOR A, [d+X] 47 2 6 A = A EOR ([d+X]) N.....Z. - EOR A, #i 48 2 2 A = A EOR i N.....Z. - EOR dd, ds 49 3 6 (dd) = (dd) EOR (ds) N.....Z. - AND1 C, m.b 4A 3 4 C = C & (m.b) .......C - LSR d 4B 2 4 Right shift (d) as above N.....ZC - LSR !a 4C 3 5 Right shift (a) as above N.....ZC - PUSH X 4D 1 4 (SP--) = X ........ - TCLR1 !a 4E 3 6 (a) = (a)&~A, ZN as for A-(a) N.....Z. - PCALL u 4F 2 6 CALL $FF00+u ........ - BVC r 50 2 2/4 PC+=r if V == 0 ........ - TCALL 5 51 1 8 CALL [$FFD4] ........ - CLR1 d.2 52 2 4 d.2 = 0 ........ - BBC d.2, r 53 3 5/7 PC+=r if d.2 == 0 ........ - EOR A, d+X 54 2 4 A = A EOR (d+X) N.....Z. - EOR A, !a+X 55 3 5 A = A EOR (a+X) N.....Z. - EOR A, !a+Y 56 3 5 A = A EOR (a+Y) N.....Z. - EOR A, [d]+Y 57 2 6 A = A EOR ([d]+Y) N.....Z. - EOR d, #i 58 3 5 (d) = (d) EOR i N.....Z. - EOR (X), (Y) 59 1 5 (X) = (X) EOR (Y) N.....Z. - CMPW YA, d 5A 2 4 YA - (d) N.....ZC - LSR d+X 5B 2 5 Right shift (d+X) as above N.....ZC - LSR A 5C 1 2 Right shift A: 0->high, low->C N.....ZC - CMP Y, !a 5E 3 4 Y - (a) N.....ZC - JMP !a 5F 3 3 PC = a ........ - TCALL 6 61 1 8 CALL [$FFD2] ........ - SET1 d.3 62 2 4 d.3 = 1 ........ - BBS d.3, r 63 3 5/7 PC+=r if d.3 == 1 ........ - CMP A, d 64 2 3 A - (d) N.....ZC - CMP A, !a 65 3 4 A - (a) N.....ZC - CMP A, (X) 66 1 3 A - (X) N.....ZC - CMP A, [d+X] 67 2 6 A - ([d+X]) N.....ZC - CMP A, #i 68 2 2 A - i N.....ZC - CMP dd, ds 69 3 6 (dd) - (ds) N.....ZC - AND1 C, /m.b 6A 3 4 C = C & ~(m.b) .......C - ROR d 6B 2 4 Right shift (d) as above N.....ZC - ROR !a 6C 3 5 Right shift (a) as above N.....ZC - PUSH Y 6D 1 4 (SP--) = Y ........ - DBNZ d, r 6E 3 5/7 (d)-- then JNZ ........ - RET 6F 1 5 Pop PC ........ - BVS r 70 2 2/4 PC+=r if V == 1 ........ - TCALL 7 71 1 8 CALL [$FFD0] ........ - CLR1 d.3 72 2 4 d.3 = 0 ........ - BBC d.3, r 73 3 5/7 PC+=r if d.3 == 0 ........ - CMP A, d+X 74 2 4 A - (d+X) N.....ZC - CMP A, !a+X 75 3 5 A - (a+X) N.....ZC - CMP A, !a+Y 76 3 5 A - (a+Y) N.....ZC - CMP A, [d]+Y 77 2 6 A - ([d]+Y) N.....ZC - CMP d, #i 78 3 5 (d) - i N.....ZC - CMP (X), (Y) 79 1 5 (X) - (Y) N.....ZC - ADDW YA, d 7A 2 5 YA = YA + (d), H on high byte NV..H.ZC - ROR d+X 7B 2 5 Right shift (d+X) as above N.....ZC - ROR A 7C 1 2 Right shift A: high=C, C=low N.....ZC - MOV A, X 7D 1 2 A = X N.....Z. - CMP Y, d 7E 2 3 Y - (d) N.....ZC - RET1 7F 1 6 Pop Flags, PC NVPBHIZC - TCALL 8 81 1 8 CALL [$FFCE] ........ - SET1 d.4 82 2 4 d.4 = 1 ........ - BBS d.4, r 83 3 5/7 PC+=r if d.4 == 1 ........ - ADC A, d 84 2 3 A = A+(d)+C NV..H.ZC - ADC A, !a 85 3 4 A = A+(a)+C NV..H.ZC - ADC A, (X) 86 1 3 A = A+(X)+C NV..H.ZC - ADC A, [d+X] 87 2 6 A = A+([d+X])+C NV..H.ZC - ADC A, #i 88 2 2 A = A+i+C NV..H.ZC - ADC dd, ds 89 3 6 (dd) = (dd)+(d)+C NV..H.ZC - EOR1 C, m.b 8A 3 5 C = C EOR (m.b) .......C - DEC d 8B 2 4 (d)-- N.....Z. - DEC !a 8C 3 5 (a)-- N.....Z. - MOV Y, #i 8D 2 2 Y = i N.....Z. - POP PSW 8E 1 4 Flags = (++SP) NVPBHIZC - MOV d, #i 8F 3 5 (d) = i (read) ........ - BCC r 90 2 2/4 PC+=r if C == 0 ........ - TCALL 9 91 1 8 CALL [$FFCC] ........ - CLR1 d.4 92 2 4 d.4 = 0 ........ - BBC d.4, r 93 3 5/7 PC+=r if d.4 == 0 ........ - ADC A, d+X 94 2 4 A = A+(d+X)+C NV..H.ZC - ADC A, !a+X 95 3 5 A = A+(a+X)+C NV..H.ZC - ADC A, !a+Y 96 3 5 A = A+(a+Y)+C NV..H.ZC - ADC A, [d]+Y 97 2 6 A = A+([d]+Y)+C NV..H.ZC - ADC d, #i 98 3 5 (d) = (d)+i+C NV..H.ZC - ADC (X), (Y) 99 1 5 (X) = (X)+(Y)+C NV..H.ZC - SUBW YA, d 9A 2 5 YA = YA - (d), H on high byte NV..H.ZC - DEC d+X 9B 2 5 (d+X)-- N.....Z. - DEC A 9C 1 2 A-- N.....Z. - MOV X, SP 9D 1 2 X = SP N.....Z. - DIV YA, X 9E 1 12 A=YA/X, Y=mod(YA,X) NV..H.Z. - XCN A 9F 1 5 A = (A>>4) | (A<<4) N.....Z. - - - TCALL 10 A1 1 8 CALL [$FFCA] ........ - SET1 d.5 A2 2 4 d.5 = 1 ........ - BBS d.5, r A3 3 5/7 PC+=r if d.5 == 1 ........ - SBC A, d A4 2 3 A = A-(d)-!C NV..H.ZC - SBC A, !a A5 3 4 A = A-(a)-!C NV..H.ZC - SBC A, (X) A6 1 3 A = A-(X)-!C NV..H.ZC - SBC A, [d+X] A7 2 6 A = A-([d+X])-!C NV..H.ZC - SBC A, #i A8 2 2 A = A-i-!C NV..H.ZC - SBC dd, ds A9 3 6 (dd) = (dd)-(ds)-!C NV..H.ZC - MOV1 C, m.b AA 3 4 C = (m.b) .......C - INC d AB 2 4 (d)++ N.....Z. - INC !a AC 3 5 (a)++ N.....Z. - CMP Y, #i AD 2 2 Y - i N.....ZC - POP A AE 1 4 A = (++SP) ........ - MOV (X)+, A AF 1 4 (X++) = A (no read) ........ - BCS r B0 2 2/4 PC+=r if C == 1 ........ - TCALL 11 B1 1 8 CALL [$FFC8] ........ - CLR1 d.5 B2 2 4 d.5 = 0 ........ - BBC d.5, r B3 3 5/7 PC+=r if d.5 == 0 ........ - SBC A, d+X B4 2 4 A = A-(d+X)-!C NV..H.ZC - SBC A, !a+X B5 3 5 A = A-(a+X)-!C NV..H.ZC - SBC A, !a+Y B6 3 5 A = A-(a+Y)-!C NV..H.ZC - SBC A, [d]+Y B7 2 6 A = A-([d]+Y)-!C NV..H.ZC - SBC d, #i B8 3 5 (d) = (d)-i-!C NV..H.ZC - SBC (X), (Y) B9 1 5 (X) = (X)-(Y)-!C NV..H.ZC - MOVW YA, d BA 2 5 YA = word (d) N.....Z. - INC d+X BB 2 5 (d+X)++ N.....Z. - MOV SP, X BD 1 2 SP = X ........ - DAS A BE 1 3 decimal adjust for subtraction N.....ZC - MOV A, (X)+ BF 1 4 A = (X++) N.....Z. - TCALL 12 C1 1 8 CALL [$FFC6] ........ - SET1 d.6 C2 2 4 d.6 = 1 ........ - BBS d.6, r C3 3 5/7 PC+=r if d.6 == 1 ........ - MOV d, A C4 2 4 (d) = A (read) ........ - MOV !a, A C5 3 5 (a) = A (read) ........ - MOV (X), A C6 1 4 (X) = A (read) ........ - MOV [d+X], A C7 2 7 ([d+X]) = A (read) ........ - CMP X, #i C8 2 2 X - i N.....ZC - MOV !a, X C9 3 5 (a) = X (read) ........ - MOV1 m.b, C CA 3 6 (m.b) = C ........ - MOV d, Y CB 2 4 (d) = Y (read) ........ - MOV !a, Y CC 3 5 (a) = Y (read) ........ - MOV X, #i CD 2 2 X = i N.....Z. - POP X CE 1 4 X = (++SP) ........ - MUL YA CF 1 9 YA = Y * A, NZ on Y only N.....Z. - BNE r D0 2 2/4 PC+=r if Z == 0 ........ - TCALL 13 D1 1 8 CALL [$FFC4] ........ - CLR1 d.6 D2 2 4 d.6 = 0 ........ - BBC d.6, r D3 3 5/7 PC+=r if d.6 == 0 ........ - MOV d+X, A D4 2 5 (d+X) = A (read) ........ - MOV !a+X, A D5 3 6 (a+X) = A (read) ........ - MOV !a+Y, A D6 3 6 (a+Y) = A (read) ........ - MOV [d]+Y, A D7 2 7 ([d]+Y) = A (read) ........ - MOV d, X D8 2 4 (d) = X (read) ........ - MOV d+Y, X D9 2 5 (d+Y) = X (read) ........ - MOVW d, YA DA 2 5 word (d) = YA (read low only) ........ - MOV d+X, Y DB 2 5 (d+X) = Y (read) ........ - DEC Y DC 1 2 Y-- N.....Z. - MOV A, Y DD 1 2 A = Y N.....Z. - CBNE d+X, r DE 3 6/8 CMP A, (d+X) then BNE ........ - DAA A DF 1 3 decimal adjust for addition N.....ZC - TCALL 14 E1 1 8 CALL [$FFC2] ........ - SET1 d.7 E2 2 4 d.7 = 1 ........ - BBS d.7, r E3 3 5/7 PC+=r if d.7 == 1 ........ - MOV A, d E4 2 3 A = (d) N.....Z. - MOV A, !a E5 3 4 A = (a) N.....Z. - MOV A, (X) E6 1 3 A = (X) N.....Z. - MOV A, [d+X] E7 2 6 A = ([d+X]) N.....Z. - MOV A, #i E8 2 2 A = i N.....Z. - MOV X, !a E9 3 4 X = (a) N.....Z. - NOT1 m.b EA 3 5 m.b = ~m.b ........ - MOV Y, d EB 2 3 Y = (d) N.....Z. - MOV Y, !a EC 3 4 Y = (a) N.....Z. - NOTC ED 1 3 C = !C .......C - POP Y EE 1 4 Y = (++SP) ........ - SLEEP EF 1 ? Halts the processor ........ - BEQ r F0 2 2/4 PC+=r if Z == 1 ........ - TCALL 15 F1 1 8 CALL [$FFC0] ........ - CLR1 d.7 F2 2 4 d.7 = 0 ........ - BBC d.7, r F3 3 5/7 PC+=r if d.7 == 0 ........ - MOV A, d+X F4 2 4 A = (d+X) N.....Z. - MOV A, !a+X F5 3 5 A = (a+X) N.....Z. - MOV A, !a+Y F6 3 5 A = (a+Y) N.....Z. - MOV A, [d]+Y F7 2 6 A = ([d]+Y) N.....Z. - MOV X, d F8 2 3 X = (d) N.....Z. - MOV X, d+Y F9 2 4 X = (d+Y) N.....Z. - MOV dd, ds FA 3 5 (dd) = (ds) (no read) ........ - MOV Y, d+X FB 2 4 Y = (d+X) N.....Z. - MOV Y, A FD 1 2 Y = A N.....Z. - DBNZ Y, r FE 2 4/6 Y-- then JNZ ........ - STOP FF 1 ? Halts the processor ........ diff --git a/spencer/spctest b/spencer/spctest deleted file mode 100755 index 75a71ce..0000000 Binary files a/spencer/spctest and /dev/null differ diff --git a/spencer/spencer.c b/spencer/spencer.c index 2f97462..9d284f5 100644 --- a/spencer/spencer.c +++ b/spencer/spencer.c @@ -6,10 +6,12 @@ // needs printf #include -void spc_init(spc_cpu* s, void* mem, uint8_t(*mmr)(uint8_t, uint8_t, uint8_t)) { +void spc_init(spc_cpu* s, void* mem, uint8_t(*mmr)(spc_cpu*, uint8_t, uint8_t, uint8_t), void(*stop)(spc_cpu*)) { + if(!mmr || !stop) return; // just dont initialize. bad data in, bad data out memset(s, 0, sizeof(spc_cpu)); - s->mmr = mmr; + s->mmr = (uint8_t(*)(void*, uint8_t, uint8_t, uint8_t))mmr; s->mem = mem; + s->stop = (void(*)(void*))stop; s->initialized = 0x59C700; } @@ -21,14 +23,19 @@ const uint8_t spc_ipl[0x40] = { }; uint8_t spc_r(spc_cpu* s, uint16_t p) { - if((p >= 0xF0 && p <= 0xF7) || (p >= 0xFA && p <= 0xFF)) return s->mmr(p - 0xF0, 0, S_R); - if(p >= 0xFFC0 && s->mmr(0xF1, 0, S_R) >> 7) return spc_ipl[p - 0xFFC0]; + if((p >= 0xF0 && p <= 0xF7) || (p >= 0xFA && p <= 0xFF)) return s->mmr(s, p - 0xF0, 0, S_R); + if(p >= 0xFFC0 && s->mmr(s, 0xF1, 0, S_R|S_I) >> 7) return spc_ipl[p - 0xFFC0]; return s->mem[p]; } +uint8_t spc_intr(spc_cpu* s, uint16_t p) { + if((p >= 0xF0 && p <= 0xF7) || (p >= 0xFA && p <= 0xFF)) return s->mmr(s, p - 0xF0, 0, S_R|S_I); + return spc_r(s, p); +} + void spc_w(spc_cpu* s, uint16_t p, uint8_t d) { if((p >= 0xF0 && p <= 0xF7) || (p >= 0xFA && p <= 0xFF)) { - s->mmr(p - 0xF0, d, S_W); + s->mmr(s, p - 0xF0, d, S_W); return; } s->mem[p] = d; @@ -49,58 +56,58 @@ void spc_w(spc_cpu* s, uint16_t p, uint8_t d) { #define spc_pull(C) spc_r(C, C->SP++) -#define NUL 0 +#define spc_setbf(C, S) C |= (1 << S) +#define spc_unsetbf(C, S) C &= ~(1 << S) +#define spc_issetbf(C, S) ((C >> S) & 1) + +#define SPC_VT -1 int spc_cycles[256] = { // -1: length returned by spc_eval // 0 1 2 3 4 5 6 7 8 9 a b c d e f - 2, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // 0 - NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // 1 - 2, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // 2 - NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, 2, NUL, NUL, // 3 - 2, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // 4 - NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, 2, NUL, NUL, // 5 - 2, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // 6 - NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // 7 - 2, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // 8 - NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // 9 - 3, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // a - NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, 2, NUL, NUL, NUL, // b - 3, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // c - NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // d - 2, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // e - NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, 2, NUL, NUL, NUL // f + 2, 8, 4, SPC_VT, 3, 4, 3, 6, 2, 6, 5, 4, 5, 4, 6, 8, // 0 + SPC_VT, 8, 4, SPC_VT, 4, 5, 5, 6, 5, 5, 6, 5, 2, 2, 4, 6, // 1 + 2, 8, 4, SPC_VT, 3, 4, 3, 6, 2, 6, 5, 6, 5, 4, SPC_VT, 4, // 2 + SPC_VT, 8, 4, SPC_VT, 4, 5, 5, 6, 5, 5, 6, 5, 2, 2, 3, 8, // 3 + 2, 8, 4, SPC_VT, 3, 4, 3, 6, 2, 6, 4, 4, 5, 4, 6, 6, // 4 + SPC_VT, 8, 4, SPC_VT, 4, 5, 5, 6, 5, 5, 4, 5, 2, 2, 4, 3, // 5 + 2, 8, 4, SPC_VT, 3, 4, 3, 6, 2, 6, 4, 4, 5, 4, SPC_VT, 5, // 6 + SPC_VT, 8, 4, SPC_VT, 4, 5, 5, 6, 5, 5, 5, 5, 2, 2, 3, 6, // 7 + 2, 8, 4, SPC_VT, 3, 4, 3, 6, 2, 6, 5, 4, 5, 2, 4, 5, // 8 + SPC_VT, 8, 4, SPC_VT, 4, 5, 5, 6, 5, 5, 5, 5, 2, 2, 12, 5, // 9 + 3, 8, 4, SPC_VT, 3, 4, 3, 6, 2, 6, 4, 4, 5, 2, 4, 4, // a + SPC_VT, 8, 4, SPC_VT, 4, 5, 5, 6, 5, 5, 5, 5, 2, 2, 3, 4, // b + 3, 8, 4, SPC_VT, 4, 5, 4, 7, 2, 5, 6, 4, 5, 2, 4, 9, // c + SPC_VT, 8, 4, SPC_VT, 5, 6, 6, 7, 4, 5, 5, 5, 2, 2, SPC_VT, 3, // d + 2, 8, 4, SPC_VT, 3, 4, 3, 6, 2, 4, 5, 3, 4, 3, 4, SPC_VT, // e + SPC_VT, 8, 4, SPC_VT, 4, 5, 5, 6, 3, 4, 5, 4, 2, 2, SPC_VT, SPC_VT // f }; uint8_t spc_len[256] = { // 0 1 2 3 4 5 6 7 8 9 a b c d e f - 1, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // 0 - NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // 1 - 1, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // 2 - NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, 1, NUL, NUL, // 3 - 1, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // 4 - NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, 1, NUL, NUL, // 5 - 1, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // 6 - NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // 7 - 1, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // 8 - NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // 9 - 1, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // a - NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, 1, NUL, NUL, NUL, // b - 1, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // c - NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // d - 1, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, // e - NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, NUL, 1, NUL, NUL, NUL // f + 1, 1, 2, 3, 2, 3, 1, 2, 2, 3, 3, 2, 3, 1, 3, 1, // 0 + 2, 1, 2, 3, 2, 3, 3, 2, 3, 1, 2, 2, 1, 1, 3, 3, // 1 + 1, 1, 2, 3, 2, 3, 1, 2, 2, 3, 3, 2, 3, 1, 3, 2, // 2 + 2, 1, 2, 3, 2, 3, 3, 2, 3, 1, 2, 2, 1, 1, 2, 3, // 3 + 1, 1, 2, 3, 2, 3, 1, 2, 2, 3, 3, 2, 3, 1, 3, 2, // 4 + 2, 1, 2, 3, 2, 3, 3, 2, 3, 1, 2, 2, 1, 1, 3, 3, // 5 + 1, 1, 2, 3, 2, 3, 1, 2, 2, 3, 3, 2, 3, 1, 3, 1, // 6 + 2, 1, 2, 3, 2, 3, 3, 2, 3, 1, 2, 2, 1, 1, 2, 1, // 7 + 1, 1, 2, 3, 2, 3, 1, 2, 2, 3, 3, 2, 3, 2, 1, 3, // 8 + 2, 1, 2, 3, 2, 3, 3, 2, 3, 1, 2, 2, 1, 1, 1, 1, // 9 + 1, 1, 2, 3, 2, 3, 1, 2, 2, 3, 3, 2, 3, 2, 1, 1, // a + 2, 1, 2, 3, 2, 3, 3, 2, 3, 1, 2, 2, 1, 1, 1, 1, // b + 1, 1, 2, 3, 2, 3, 1, 2, 2, 3, 3, 2, 3, 2, 1, 1, // c + 2, 1, 2, 3, 2, 3, 3, 2, 2, 2, 2, 2, 1, 1, 3, 1, // d + 1, 1, 2, 3, 2, 3, 1, 2, 2, 3, 3, 2, 3, 1, 1, 1, // e + 2, 1, 2, 3, 2, 3, 3, 2, 2, 2, 3, 2, 1, 1, 2, 1 // f }; -int spc_eval(spc_cpu* s, int* err) { - int cycles = 0; +void spc_eval(spc_cpu* s, int* d) { switch(spc_r(s, s->PC)) { case 0x00: break; case 0x20: spc_unsetp(s); break; - case 0xBC: - spc_inc(s, s->A); - break; case 0x3D: spc_inc(s, s->X); break; @@ -119,6 +126,9 @@ int spc_eval(spc_cpu* s, int* err) { case 0xA0: spc_seti(s); break; + case 0xBC: + spc_inc(s, s->A); + break; case 0xC0: spc_unseti(s); break; @@ -126,27 +136,109 @@ int spc_eval(spc_cpu* s, int* err) { spc_unsetv(s); spc_unseth(s); break; + case 0xED: + s->P ^= 1; + break; + case 0xEF: + s->stop(s); + break; case 0xFC: spc_inc(s, s->Y); break; + case 0xFF: + s->stop(s); + break; default: printf("unimplemented opcode: 0x%02X\n", spc_r(s, s->PC)); - *err = 1; + *d = 1; break; } - s->PC += spc_len[spc_r(s, s->PC)]; - return cycles; +} + +int spc_cyc(spc_cpu* s) { + switch(spc_r(s, s->PC)) { + case 0x03: + break; + case 0x10: + break; + case 0x13: + break; + case 0x23: + break; + case 0x2E: + break; + case 0x30: + break; + case 0x33: + break; + case 0x43: + break; + case 0x50: + break; + case 0x53: + break; + case 0x63: + break; + case 0x6E: + break; + case 0x70: + break; + case 0x73: + break; + case 0x83: + break; + case 0x90: + break; + case 0x93: + break; + case 0xA3: + break; + case 0xB0: + break; + case 0xB3: + break; + case 0xC3: + break; + case 0xD0: + break; + case 0xD3: + break; + case 0xDE: + break; + case 0xE3: + break; + case 0xEF: + s->stp = 0xEF; + s->stop(s); + return 0; + break; + case 0xF0: + break; + case 0xF3: + break; + case 0xFE: + break; + case 0xFF: + s->stp = 0xFF; + s->stop(s); + return 0; + break; + default: + break; + } + return spc_cycles[spc_r(s, s->PC)] - 1; } int spc_loop(spc_cpu* s) { if(s->initialized != 0x59C700) return !printf("SPENCER UNINITIALIZED\n") - 1; + if(!s->use) s->use = !!(s->wait = spc_cyc(s)); + if(s->stop) return 0; int err = 0; if(s->wait == 0) { printf("-- EVAL --\n"); - int w = spc_cycles[spc_r(s, s->PC)], c = spc_eval(s, &err); - if(w == -1) s->wait = c; - else s->wait = w; - s->wait--; + spc_eval(s, &err); + s->PC += spc_len[spc_r(s, s->PC)]; + s->wait = spc_cyc(s); } else s->wait--; return err; } diff --git a/spencer/spencer.h b/spencer/spencer.h index 7af743a..efe101e 100644 --- a/spencer/spencer.h +++ b/spencer/spencer.h @@ -14,18 +14,22 @@ typedef struct { uint16_t PC; // 2 byte registers uint8_t* mem; // 0x10000 bytes + // the void*s in the function declarations are spc_cpus + /* MMR arguments: * * width description * ------------------------- * u8 | register number (0-15) * u8 | data to write (if reading anything is fine) - * u8 | S_R to read, S_W to write + * u8 | S_R to read, S_W to write, or with S_I to prevent resetting data */ - uint8_t(*mmr)(uint8_t, uint8_t, uint8_t); + uint8_t(*mmr)(void*, uint8_t, uint8_t, uint8_t); + void(*stop)(void*); unsigned int wait; unsigned int initialized; - uint8_t sleeping; + uint8_t stp; + uint8_t use; } spc_cpu; #define spc_getn(CPU) (CPU->P >> 7)