Skip to content

Instantly share code, notes, and snippets.

org $8000
start: ld a,%00010000 ; load accumulator with any value that sets the 4th bit
out (&fe),a ; send that value to port 254, i.e. hexadecimal FE
xor %00010000 ; flip the 4th bit to the opposite of what it was before
out (&fe),a ; send that value to port 254 again
end start
org $8000
start: ld a,%00010000
ld c,%00010000
out (&fe),a
xor c ; this is faster than xor %00010000
out (&fe),a
end start
; adapted from Pavel Lebedev (Мир звуков Спектрума, https://vtrd.in/book/ZXSWORLD.ZIP)
org $8000
chord: ex af,af' ; swap primary and alternative AF registers
ld b,d ; counter 2
ld c,e ; counter 1
beep: ex af,af' ; swap registers (swap the voice)
dec c ; decrement c
jr nz,cont ; if not zero, go to cont
ld c,e ; restore counter 1
xor 16 ; invert bit 4 of voice 1
org $8000
start: ld de, 500
flip: xor %00010111
out (&fe), a
ld bc, 500
freq: dec c
jr nz, freq
dec b
jr nz, freq
jr flip
org $8000
start: di ; disables interrupts
flip: xor %00010011
out (&fe), a
ld b, 100
freq: dec b
jr nz, freq
jr flip
ei ; re-enables interrupts
end start
// Define Arduino pin constants to correspond with MOS6522 pins
const byte CS1 = 24; // Chip Select 1
const byte CS2 = 23; // Chip Select 2
const byte RS0 = 38; // Register Select 0
const byte RS1 = 37; // Register Select 1
const byte RS2 = 36; // Register Select 2
const byte RS3 = 35; // Register Select 3
const byte RW = 22; // Read-Write Line
const byte D0 = 33; // Data Bus 0
const byte D1 = 32; // Data Bus 1
@podstawek
podstawek / mos6522_shiftout.ino
Last active April 2, 2022 11:59
Primitive but working code to enable Shift Out operation on MOS 6522 VIA from Arduino.
// Define Arduino pin constants to correspond with MOS6522 pins
const byte CS1 = 24; // Chip Select 1
const byte CS2 = 23; // Chip Select 2
const byte RS0 = 38; // Register Select 0
const byte RS1 = 37; // Register Select 1
const byte RS2 = 36; // Register Select 2
const byte RS3 = 35; // Register Select 3
const byte RW = 22; // Read-Write Line
const byte D0 = 33; // Data Bus 0
const byte D1 = 32; // Data Bus 1
@podstawek
podstawek / ladder.ino
Created April 3, 2022 20:26
Simple sketch to drive the resistor ladder circuit.
const byte D0 = 44; // Digital Line 0
const byte D1 = 45; // Digital Line 1
const byte D2 = 46; // Digital Line 2
void setup() {
pinMode(D0, OUTPUT);
pinMode(D1, OUTPUT);
pinMode(D2, OUTPUT);
}
@podstawek
podstawek / pulseTrainShape.ino
Created April 4, 2022 07:15
6522 control code, pulse train shape fragment only
// send a pattern to Shift Register (e.g. 01100101)
digitalWrite(D7, LOW);
digitalWrite(D6, HIGH);
digitalWrite(D5, HIGH);
digitalWrite(D4, LOW);
digitalWrite(D3, LOW);
digitalWrite(D2, HIGH);
digitalWrite(D1, LOW);
digitalWrite(D0, HIGH);
@podstawek
podstawek / set_digital_pins_for_ladder.ino
Last active April 4, 2022 13:36
Resistor ladder control (fragment only)
void loop() {
digitalWrite(D0, LOW);
digitalWrite(D1, LOW);
digitalWrite(D2, LOW);
delay(2);
digitalWrite(D0, LOW);
digitalWrite(D1, LOW);
digitalWrite(D2, HIGH);
delay(2);
; (...end so on...)