diff --git a/sid.4th b/sid.4th index 5d4b2ce..afeba7e 100644 --- a/sid.4th +++ b/sid.4th @@ -1,16 +1,23 @@ ( --- Gforth SID chip stub --- ) -( : SID! SWAP . . ." SID! " ; ) +( : PC! DUP 255 AND . 8 RSHIFT . . CR ; ) ( : >< DUP 8 RSHIFT SWAP 8 LSHIFT 65534 AND OR ; ) -( --- SID chip access --- ) +( --- Library --- ) : PC2! ( b b p-addr -- ) ( Data byte A, high address byte B, port address C ) SWAP >< OR PC! ; +: BIT ( n -- ) ( define bit flag ) + 1 SWAP LSHIFT CONSTANT ; +: BIT+ ( n -- n+1 ) ( define bit flag and next ) + DUP 1+ SWAP BIT ; + +( --- SID chip access --- ) + : SID! ( b n0-31 -- ) ( Send byte to SID { 1data , 4?register | 2?interrupt } ) - 2DUP 128 OR 84 PC2! - 2DUP 127 AND 84 PC2! - 128 OR 84 PC2! ; + 2DUP 128 OR 84 PC2! + 2DUP 127 AND 84 PC2! + 128 OR 84 PC2! ; ( --- Voice selection --- ) @@ -30,14 +37,15 @@ CREATE >VOICE-CTL VOICE-CTLS , ( --- SID chip control register flags --- ) -: GATE 1 ; -: SYNC 2 ; -: RING 4 ; -: TEST 8 ; -: TRI 16 ; -: SAW 32 ; -: PWM 64 ; -: NOISE 128 ; +0 BIT+ GATE + BIT+ SYNC + BIT+ RING + BIT+ TEST + BIT+ TRI + BIT+ SAW + BIT+ PWM + BIT+ NOISE +DROP ( --- Voice register operation --- ) @@ -69,15 +77,16 @@ CREATE >VOICE-CTL VOICE-CTLS , ( Reg 23 - { 4?filter-resonance [0-15] | 1?ext | 1?voice-2 | 1?voice-1 | 1?voice-0 } ) : RES ( n0-15 -- b ) 15 AND 4 LSHIFT ; : VOICE-FILTER ( voice -- b ) 1 SWAP LSHIFT ; -: EXT 8 ; +3 BIT EXT-FILTER : RES|FILTER! ( b -- ) 23 SID! ; ( Reg 24 - { 1?mute-voice-3 | 1?highpass | 1?bandpass | 1?lowpass | 4?volume ) : VOLUME ( n0-15 -- b ) 15 AND ; -: LOWPASS 16 ; -: BANDPASS 32 ; -: HIGHPASS 64 ; -: MUTE-VOICE3 128 ; +4 BIT+ LOWPASS + BIT+ BANDPASS + BIT+ HIGHPASS + BIT+ MUTE-VOICE3 +DROP : MODE|VOLUME! 24 SID! ; ( --- Frequency table --- ) @@ -119,7 +128,7 @@ CREATE TEMPO 40000 , : DELAY ( delay -- ) 0 DO LOOP ; : PAUSE ( delay -- ) DUP DELAY DELAY ; -: PLAY START DUP DELAY DELAY STOP ; +: PLAY START DUP PAUSE STOP ; ( --- Test --- )