James Cat's rough && ready blog

4th A&B computing article > Machine Code Made Easy #4

Posted in 6502 by zzjames on January 23, 2013

These are scans from volume 1 number 13 of A&B magazine which introduce BBC machine code programming, this one is from pages 84-86.

This one plays a tune, uses the interrupt system provided by the hardware, but still there’s enough of code to demonstrate each of the different kinds of instructions.

below the article (click to expand jpegs) and then the code, for some reason I had to alter the slashes for the comments, not convinced the emulator is getting the right ascii codes…

lc-p084

lc-p085

lc-p086

Now the code: (watch the line breaks they shouldn’t happen in a comment)


REM ----------------------------------------------
REM READ AND SAVE NOTES FOR MUSIC
REM ----------------------------------------------
FOR X% = 0 TO 19 : READ P%,D% : ?(&0D80+X%*2) = P% : ?(&0D80+X%*2+1) = D% : NEXT
DATA 69,16, 69,4, 73,4, 73,12, 69,2, 73,8, 69,2, 61,8, 53,2, 49,16, 81,12, 73,12, 69,2, 53,2, 73,2, 81,6, 73,6, 69,12, 61,12, 53,12

REM ———————————————-
REM ASSEMBLE MACHINE CODE
REM ———————————————-
FOR I% = 0 TO 3 STEP 3
P%=&0D00
[OPT I%
LDA#0 : STA&72 : STA&76 : STA&78 : LDA#&FF : STA&74 \ set the fixed parameters of the OSWORD parameter block in zero-page
STX&79 : STY&7A \ collect the tune length and the data offset from x% and y% respectively

\ store the variable parameters in the block including collecting the first note from the data store
.start
LDA#1 : STA&71 : LDA#&F1 : STA&73 : LDY&7A : LDA&0D80,Y : STA&75 : LDA&0D81,Y : STA&77

.check
LDY#&FF : LDX#&FA : LDA#&80 : JSR&FFF4 : TXA : BEQcheck \ check the sound buffer to see if there is space in it, check again until there is
LDX#&71 : LDY#0 : LDA#7 : JSR&FFF1 \ set x&y registers to indicate the parameter block and call OSWORD with a=7 – the SOUND command – feeds note to channel 1
LDA#&F6 : STA&73 : LDA#2 : STA&71 \ change the volume to -10 and the channel to 2
LDX#&71 : LDY#0 : CLC : LDA&75 : ADC#&60 : STA&75 : LDA#7 : JSR&FFF1 \ reset to the parameter block and add 2 octaves (96) to the pitch, then feed the note to channel 2
\ increment the data pointer to the next note data – 2 bytes forward – and decrement the number of notes to be played – if zero finish else go and do another note
INC&7A : INC&7A : DEC&79 : BEQend : JMPstart
.end RTS
]
NEXT
MODE 7 : PRINTTAB(5,10) “yeah yeah”
X% = 20 : Y% = 0 : CALL&D00
END

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )

Connecting to %s

%d bloggers like this: