I needed a small size routine to convert PSG frequencies to MSX-MUSIC, but I couldn't find any ready made. After some iterations I came up with this horrific piece of assembly nightmare... I wanted to share it, because I must say I feel pretty proud of how small I was able to squeeze it in the end.
PSG2FM: ; PSG to MSX-MUSIC frequency converter ; Made By: NYYRIKKI 2021 ; ; IN: DE = MSX PSG channel frequency (12bit) ; OUT: B:A = MSX-MUSIC 3bit floating point octave(*512) + 9bit F-number mantissa ; Changes: AF,BC,HL XOR A LD H,A LD L,9 LD B,16 LD C,41 SBC HL,DE JR NC,$+4 ADD HL,DE SCF CCF ADC A,A JR C,$+4 DJNZ $-11 INC B RL B RET
Login or register to post comments