WACCI 136 Index - Home Page www.wacci.org.uk

01 - Thanx & Stuff 02 - WACCI On-line 03 - French Connection 04 - Scart Connections
05 - Contributing 06 - Pirates Ahoy! 07 - Ask The Internet 08 - 101 Uses For A Dead CPC
09 - Breaking Your CPC 10 - Programmers' Patch 11 - A-Z Of Computing 12 - A Word From Dave
13 - Famous Last Words

img_136_10_01.gif - 2,629 bytes

Programmers' Patch

Matthew Phillips puts the obscure RAM Music Machine to good use by connecting an Acorn RiscPC to his faithful CPC

Well, it’s a year now since this column last appeared in WACCI, and that one had been written just after the WACCI gathering in Peterborough in September 1999, so what have I been up to in all that time? What delight of programming expertise (ahem) will be served up for your delight? Hang on, that’s “delight” twice in one sentence. Bother.
  Last time we were looking at the possibility of installing a “virtual” hard drive on the CPC, by writing some clever software to communicate with a bigger computer over an RS232 serial link, and get the bigger computer to store the data and pretend to be a hard drive. Unfortunately, despite having such a long break, I had done very little towards this goal, so with just two days to the magazine deadline, I got out my notes and started working out how to patch CP/M Plus as I had promised.
  I knew that the files I needed were somewhere on a floppy disc. I have most of my old discs copied as DSK files (disc images) on the Acorn RiscPC which we use most of the time. The disc images are useful for using with Andreas Stroiczek’s CPC emulator, which we probably use more than the real CPC now!
  Unfortunately the disc I wanted was not among these, so I turned on the CPC and started going through the discs. I found the files quite quickly on a data formatted 3.5 inch disc. To get them to the Acorn, however, I needed to copy them to a 3 inch disc, and then put a PC format disc in the 3.5 inch drive to copy the files across. This was where I hit a problem. None of the discs I put in the old 3 inch A drive worked. I just got “disc missing”, and “read fail”. As I was feeling adventurous, I took the computer and disc drive apart and gave them a good vacuum clean, but that did not help. I think it must be the drive belt, and I do not have a spare. Time to order one from that nice Mr Watson.
  Except that I need the files now to write the article for Monday’s deadline.
  Perhaps I can use the PCW to transfer the file. My PCW has a 3.5 inch drive, and PCWs read data format discs. I could copy the file to the M drive, put a PCW format disc in drive B, and save it to that. The Acorn reads PCW format discs fine. There is one problem. While the PCW reads data format discs in the 3 inch A drive, it does not read them in the 3.5 inch B drive, because it assumes that the forty tracks are spread twice as wide as as they really are. So that solution will not work.
  Right! The CPC has an RS232 interface, and so does the Acorn. Can I hook them up and transfer the file like that? Probably, but one of the things I still need to do is to learn how to program the serial interface properly, so I have no ready-written code to hand. It could take a while to get it to work.

Talking computers

What about MIDI? The CPC and the Acorn each have a MIDI interface. I have never programmed the Acorn’s MIDI interface, but it might not be too hard, and I have a useful little RSX to transmit bytes from the CPC which appeared in this column in issue 120 (March/April 1998). It is also on the Programmers’ Patch disc, which you can get from the WACCI PD library. Funnily enough, I have a copy of that disc, so I dug it out to see what I could do.
  The listings in with this article are the result! There is a CPC BASIC listing which poke in the machine code needed to do the job. The machine code is listed in the assembly language listing, so you can see how it works. Finally, there is a BBC BASIC listing for the RiscPC (or any RISC OS computer).
  Though intended for musical instruments to talk to each other, MIDI is just a special kind of serial link which transmits data in bytes. I was hoping just to be able to send the files I wanted byte by byte over the MIDI link and receive them on the Acorn. However, the Acorn MIDI interface knows rather more about MIDI than the CPC does, and tries to fill in “missing” commands (running status is the technical MIDI term), so this can muck things up. I therefore had to develop a protocol to send the file safely.
  The whole file is packaged into a system exclusive message. This is a special MIDI message beginning with the byte &F0 which is designed for manufacturers to use to send special data. We can then send whatever bytes we wish without the Acorn MIDI interface inserting extra command codes for us. After sending &F0, the program then sends the filename, terminated by a null byte.
  It is not safe to send some bytes greater than 128 in a system exclusive message, so for those, I decided to send them as a null byte followed by the value with 128 subtracted. To send the null byte itself, we send two nulls in a row.
  If you look at the assembly language listing (over the page), you will see how the CPC sends the file, byte by byte, doing these conversions as required. The BBC BASIC program then does exactly the opposite to receive the file and save it to disc. To send a file from the CPC, you just set a string variable to the name of the file you want to transfer, and then do:

CALL &8000,@filename$,0

That’s assuming you are using a RAM Music Machine. The zero should be changed to 1 for the EMR MIDI interface, or 2 for the DHCP interface.
  All in all, it took just an hour to get it all working. The assembly listing was written on the Acorn and assembled using the ZMAC assembler. This is different from the CP/M ZMAC on one of the PD discs. The Acorn ZMAC is a port of an assembler which is maintained by Mark Rison, who is writing CPC/IP for connecting CPCs to the internet. After assembling on the Acorn, I then typed the hex codes in on the CPC to make the CPC BASIC listing. Once the utility was working, I then used it to transfer the listing back to the Acorn so that I could e-mail it to Richard for the magazine!

In an ideal world…

Of course, many improvements could be made, for example to have a checksum so that you can verify that the data has transferred correctly. Also, it only copes with ASCII files at present, so that needs sorting out if I am to use it regularly. If I can get it read and transfer the contents of a whole disc, then that could be a quick method of copying the rest of my discs across to the Acorn.
  Now I have transferred the files, perhaps by next time, I will have put them to use in patching CP/M Plus like I originally intended. If any of you want particular things covered in this column, just write in to Fair Comment, or e-mail me on progpatch@sinenomine.freeserve.co.uk – it’s always good to hear what people have found useful. I would be particularly interested to hear from anyone who has a MIDI interface or an RS232 interface, and what you use it for.

The CPC BASIC loader

1 REM Sends ASCII files over MIDI
2 REM using very simple protocol
3 REM CALL &8000,@filename$,i%
4 REM where i%=0 RAM Music Machine
5 REM       i%=1 EMR interface
6 REM       i%=2 DHCP interface
7 :
20 RESTORE 100:er=0:addr=HIMEM+1
30 FOR i%=0 TO 16:READ cod$:chk%=0
40 FOR j%=0 TO 11:a%=VAL("&"+MID$(cod$,j%*2+1,2))
50 POKE addr,a%:chk%=chk%+a%:addr=addr+1:NEXT
60 IF chk%VAL("&"+RIGHT$(cod$,3)) THEN PRINT"Error in line"100+i%*10:er=1
80 IF er=0 THEN PRINT"Sendfile installed"
90 :
100 DATA FE02C0DD7E0011698001060041C
110 DATA 216F80B728093D2175802803376
120 DATA 217B80EDB0CD6980DD6E02DD699
130 DATA 660346235E23666B110052E536C
140 DATA C5CD77BCD1E1D03EF0CD6C8082E
150 DATA 7E23CD6C801520F8AFCD6C805EF
160 DATA CD80BC3015FE81380857AFCD5E0
170 DATA 6C807AD680CD6C80B7CC6C806E4
180 DATA 18E6CD7ABC3EF71803C38180615
190 DATA C39E80C38180C39E80C38D80756
200 DATA C3AD80C39980C3BC8001ECF87B0
210 DATA 3E03ED793E15ED79C901F2F8614
220 DATA 3E03ED793E16ED79C901E0F8603
230 DATA 18F201EEF8F5ED78E60228FA755
240 DATA F10DED79C901F2F8F5ED78E6858
250 DATA 0228FAF10CED79C901E0F818641
260 DATA EF00000000000000000000000EF

An Election Broadcast on behalf of the Acorn Party

Some of you may not know what I mean when I talk about our Acorn RISC OS computer. Acorn were perhaps most famous for designing the BBC Micro, but in 1988 they brought out the Archimedes, based around the ARM processor which they had designed themselves (I believe Brian Watson knows one of the people involved). It was very popular in schools, but if you have met RISC OS computers there, they were probably old ones, rather than the modern machines which are still being made and developed. RISC OS is used in all sorts of situations where people need a robust computer system, such as in harbour radar systems and to run TV’s “Who wants to be a millionnaire?”.
  There has been fuss in the past about whether WACCI should cover PCs, but for me the objection has always been that PCs are such boring computers. They are so common, and they are not half so much fun to program. Take a quick look at the BBC BASIC listing for the Acorn, and you will see the SYS command. This allows you to call the firmware directly, using a name for the routine rather than a meaningless address. You can specify what is to go in the registers upon entry, and you can read back the registers and flags on exit. Simplicity itself. For more information on RISC OS computers, see www.riscos.org.

CPC assembly listing

ORG &8000

CP 2
RET NZ        ;exit if no. of parameters <> 2

;set up jumpblocks for chosen MIDI interface
LD A,(IX+0)
LD DE,jmpreset
LD BC,emrblocks-ramblocks
LD HL,ramblocks
JR Z,copyblocks
LD HL,emrblocks
JR Z,copyblocks
LD HL,dhcpblocks
CALL jmpreset    ;reset the interface

;find filename and open file
LD L,(IX+2)
LD H,(IX+3)
LD B,(HL)    ;length of string is now in B
LD L,E        ;address of string is now in HL
LD DE,&5200    ;address of 2k buffer
CALL &BC77    ;open the file to read
RET NC        ;exit if error

;send &F0 to start a system exclusive message
LD A,&F0
CALL jmpmidisend

;send the filename terminated by a NULL byte
CALL jmpmidisend
JR NZ,sendname
CALL jmpmidisend

;read the file a byte at a time
JR NC,close    ;finish upon EOF or error
CP &81
JR C,notbig
;if the byte is greater than 128...
;...first send a null byte...
CALL jmpmidisend
;...then send the byte less 128.
SUB &80
CALL jmpmidisend
;if the byte was an actual zero, send it again.
CALL Z,jmpmidisend
JR readloop

LD A,&F7
JR jmpmidisend    ;end system exclusive message
;these are altered to suit chosen interface

JP ramreset
JP ramsend

JP ramreset
JP ramsend

JP emrreset
JP emrsend

JP dhcpreset
JP dhcpsend

LD A,3
LD A,&15

LD A,3
LD A,&16

JR ehrcommon

IN A,(C)
JR Z,ramslp

IN A,(C)
JR Z,ehsslp

JR ehscommon 

Acorn BASIC listing

REM Reset MIDI interface
SYS”MIDI_Init”,0 TO ,h%

REM Wait for a system exclusive message

REM Read the null-terminated filename
WHILE a%<>0
REM Convert “.” to “/” for RISC OS
  IF a%=ASC(“.”) THEN a%=ASC(“/”)
  IF a%>32 THEN filename$+=CHR$(a%)

REM Open the file for output
PRINT”Receiving “filename$

REM Read the rest of the bytes
WHILE a%<>&F7
  REM Zero is a special case
  IF a%=0 THEN
    IF a%>0 THEN a%+=128
OSCLI(“SetType “+filename$+” Text”)
PRINT”File received and saved.”

SYS”MIDI_RxByte”,0 TO byte%
UNTIL byte% AND 1<<24
=byte% AND &FF 

01 - Thanx & Stuff 02 - WACCI On-line 03 - French Connection 04 - Scart Connections
05 - Contributing 06 - Pirates Ahoy! 07 - Ask The Internet 08 - 101 Uses For A Dead CPC
09 - Breaking Your CPC 10 - Programmers' Patch 11 - A-Z Of Computing 12 - A Word From Dave
13 - Famous Last Words

WACCI 136 Index - Home Page www.wacci.org.uk