LisaList2

Advanced search  

News:

2022.06.03 added links to LisaList1 and LisaFAQ to the General Category

Pages: [1] 2   Go Down

Author Topic: Directly BEEPING on the Lisa by writing to VIA register  (Read 17617 times)

rayarachelian

  • Administrator
  • Hero Member
  • *****
  • Karma: +105/-0
  • Offline Offline
  • Posts: 772
  • writing the code,writing the code,writing the code
    • LisaEm
Directly BEEPING on the Lisa by writing to VIA register
« on: January 28, 2022, 03:00:57 pm »

Split from: https://lisalist2.com/index.php/topic,240.0.html

Just had another thought, perhaps the Beep procedure runs asynchronously? That is it immediately returns to the caller, but then in that case, your executable would immediately quit, perhaps stopping the beep from happening.
Maybe you can add some kind of Sleep() or Delay() procedure before quitting to see if it does anything different?

Sure will do. Thank you Ray for helping. Also in about 10-12 days from now I'll have an opportunity to test this on a physical Lisa...

I will have other newbie questions too, but not sure if I should start a separate thread; I'm new to this forum and don't know the local netiquette. One thing for example is why, no matter how I try, I cannot set the 6552 Shift Register to any value in assembly code. I'm trying to do e.g. MOVE d0, $00FCDD81 or MOVE d0, $0000DD81 (documentation says sometimes former, sometimes latter for the VIA memory location) plus $14 offset to access the Shift Register and it always gives me ADDRESS ERROR when running the program from Pascal. Any ideas what I'm doing wrong? Sorry if this is not for this thread, will start a new one if needed.

Yes, please open a new topic with this and give details as to how you're doing this, etc.

I can tell you that this is incorrect:
Code: [Select]
MOVE d0, $0000DD81

Because there's no VIA at that address. All I/O exists at $00fcxxxx - but this is only available in context 0 (supervisor mode). If you're running that from LPW, it will never work because your code won't run in supervisor mode, and only the OS has access to I/O (and SIO) spaces.

You'd ofc have to set the ACR on via #1 to enable the CB1 or CB2 output of the shift register of the VIA, but sounds like you already know about that. Also take a look at the Lisa Boot ROM source code, should be available on bitsavers which has code for beeping.

Code: [Select]
0AF6|                       ;  Routine to beep the speaker
0AF6|                       ;  Assumes regs set up as
0AF6|                       ;    D0 = desired frequency ($00 - $AA)
0AF6|                       ;    D1 = duration (0 = .5 msec)
0AF6|                       ;    D2 = volume (0,2,4,...,E)
0AF6|                       ;-------------------------------------------------------------------------
0AF6|
0AF6| 48E7 1088             TONE    MOVEM.L A0/A4/D3,-(SP)  ;save regs
0AFA|                               BSRS4   TONE2           ;go do tone
0AFA| 49FA 0004            #          LEA      @1,A4
0AFE| 6006                 #          BRA.S    TONE2
0B00|                      #@1
0B00| 4CDF 1108                     MOVEM.L (SP)+,A0/A4/D3  ;restore and exit
0B04| 4E75                          RTS
0B06|
0B06|                       ;  separate entry point for call without memory usage
0B06|
0B06| 207C 00FC DD81        TONE2   MOVEA.L #VIA1BASE,A0    ;set VIA ptr
0B0C| 0028 000E 0004                ORI.B   #$0E,DDRB1(A0)  ;set volume bits for output
0B12| 0210 00F1                     ANDI.B  #$F1,ORB1(A0)   ;clear and then
0B16| 8510                          OR.B    D2,ORB1(A0)     ; set volume bits
0B18| 0228 00E3 0016                ANDI.B  #$E3,ACR1(A0)   ;clear shift mode bits
0B1E| 0028 0010 0016                ORI.B   #$10,ACR1(A0)   ;set shift reg for continuous rotate
0B24|
0B24|                       ; check system type
0B24|
0B24| 4A39 00FC C031                TST.B   DISKROM         ;test for Lisa 1 board                  CHG014
0B2A| 6A10                          BPL.S   @3              ;no changes if yes                      CHG014
0B2C| 0839 0005 00FC C031           BTST    #SLOTMR,DISKROM ;else check if slow timers              CHG029
0B34| 6606                          BNE.S   @3              ;skip if yes                            CHG029
0B36| 1600                          MOVE.B  D0,D3           ;else adjust input parm                 CHG014
0B38| E40B                          LSR.B   #2,D3           ; by factor of .25                      CHG014
0B3A| D003                          ADD.B   D3,D0           ;                                       CHG014
0B3C|
0B3C| 1140 0010             @3      MOVE.B  D0,T2CL1(A0)    ;set frequency
0B40| 117C 000F 0014                MOVE.B  #$0F,SHR1(A0)   ;set for square wave and trigger
0B46|
0B46|                       ;  Do time delay -  enter with count in D1 (about .5 msec per count)
0B46|
0B46| 363C 00D0             @1      MOVE.W  #$00D0,D3       ;set delay constant
0B4A| 51CB FFFE             @2      DBF     D3,@2
0B4E| 51C9 FFF6                     DBF     D1,@1
0B52|
0B52| 0228 00E3 0016        SILENCE ANDI.B  #$E3,ACR1(A0)   ;disable tone
0B58|                               RTS4                    ;and return
0B58| 4ED4                 #          JMP      (A4)

You might be able to do this from Service Mode, or by writing your code to a floppy in the 1st boot sector (it will start to execute from $20000) by setting tags 4,5 on that sector 0 to AA,AA.

If you dislike Service mode, you can also mess around with my nanoBug image - https://github.com/rayarachelian/nanobug  but you'll need to use the serial port for this.

Neither Service Mode, nor nanoBug have built in assemblers, so you'd assemble your code, copy your hex values somewhere and then enter them again in these and then execute the code and see what happens.
You can find prebuilt ones here: https://lisalist2.com/index.php/topic,241.0.html (just uploaded them.)

Another option is to run your code from MacWorks - that is inside of MacOS using something like Macsbug or whatever assembler, or C/Pascal compiler you like. MacWorks runs in MMU context 0 and therefore has full access to I/O address space.

As "newbie" as you might be, you're doing awesome. Welcome to LisaList2  :D
« Last Edit: January 28, 2022, 03:26:32 pm by rayarachelian »
Logged
You don't know what it's like, you don't have a clue, if you did you'd find yourselves doing the same thing, too, Writing the code, Writing the code

kewatsdop

  • Full Member
  • ***
  • Karma: +8/-0
  • Offline Offline
  • Posts: 28
Re: Directly BEEPING on the Lisa by writing to VIA register
« Reply #1 on: January 28, 2022, 05:28:26 pm »

Amazing. Thank you Ray!!! I am going to look closer at your answers and study them closely before trying out, as I'm very fresh to this. But I already know I will probably want to follow the "write to floppy" path as I need full control over the beeper.

For full disclosure, I'm the author of http://forgottencomputer.com/retro/sound/ and I'm learning while writing that article. My goal is simple: to understand, practice and - only if I succeed - document, how Lisa generates sound at low level.

Many thanks for helping me here, and for your work on LisaEm. I'll be updating in the 2 threads on progress as time allows me to focus on this.
Logged

rayarachelian

  • Administrator
  • Hero Member
  • *****
  • Karma: +105/-0
  • Offline Offline
  • Posts: 772
  • writing the code,writing the code,writing the code
    • LisaEm
Re: Directly BEEPING on the Lisa by writing to VIA register
« Reply #2 on: January 28, 2022, 05:58:17 pm »

For full disclosure, I'm the author of http://forgottencomputer.com/retro/sound/ and I'm learning while writing that article. My goal is simple: to understand, practice and - only if I succeed - document, how Lisa generates sound at low level.

Many thanks for helping me here, and for your work on LisaEm. I'll be updating in the 2 threads on progress as time allows me to focus on this.

Sure, you're welcome. Sound on the Lisa works similar to sound on the Commodore PETs, since they both use VIA6522' SR output on the CB2 line for this. However, the Lisa has a real speaker (regular, non-piezo and is amplified), it has different clock timings so the frequencies are going to differ, and there's also a master volume control. (Also note that the Lisa 2/10 has a different clock than the Lisa 1s, 2s, and 2/5s so the frequencies there are off by a factor of 4.)

Fun tidbit, a long time ago, Commodore wrote a crappy little "PET Emulator" for the C64 and moved the video page address to match the same one in memory of a PET. (Maybe that's where Apple got the idea of writing MacWorks?)

But the C64's PET Emulator didn't do sound. So I added a piezo speaker to the CIA output (CIA is the next version of the VIA) and then I hand modified the sound pokes in a few PET games to match the C64's CIA and get sound and it sounded almost the same. (Unfortunately for whatever reason the C64 used BASIC 2.0 vs BASIC 4.0 so most games didn't work right anyway.)


I'd suggest you take this script that builds nanoBug (you'll also need lisafsh-tool), and https://github.com/rayarachelian/nanoBug/blob/master/make-nanobug2.sh and add some code at the top that calls https://github.com/rayarachelian/EASy68K-asm to assemble your code. The script that builds nanoBug just injects a small binary into the boot sector.

This way you could build yourself a nice scripted pipeline to build your test code and feed those to LisaEm. :)

(You could also look at some of the stuff Tom Stepleton build using python to generate disk images such as his NeoWidEx code, etc. if you find that better.)
« Last Edit: January 28, 2022, 06:02:06 pm by rayarachelian »
Logged
You don't know what it's like, you don't have a clue, if you did you'd find yourselves doing the same thing, too, Writing the code, Writing the code

stepleton

  • Sr. Member
  • ****
  • Karma: +127/-0
  • Offline Offline
  • Posts: 425
Re: Directly BEEPING on the Lisa by writing to VIA register
« Reply #3 on: January 28, 2022, 08:42:49 pm »

Thanks for the plug, Ray :-)
For a direct link, this one Python (2.7) script creates a bootable .dc42 floppy image from any raw binary code that fits on the disk.
Logged

kewatsdop

  • Full Member
  • ***
  • Karma: +8/-0
  • Offline Offline
  • Posts: 28
Re: Directly BEEPING on the Lisa by writing to VIA register
« Reply #4 on: January 29, 2022, 03:20:45 pm »

Thank you Ray and stepleton!

Great. So the help message for dc42_build_bootable_disk.py reads 68000 program to load+run (starting address $800). Does it mean I can put org $800 in my source code, cross-compile on my Mac e.g. using vasm to M680x0 architecture, and just pass it as an argument? That would be cool.
« Last Edit: January 29, 2022, 03:24:57 pm by kewatsdop »
Logged

stepleton

  • Sr. Member
  • ****
  • Karma: +127/-0
  • Offline Offline
  • Posts: 425
Re: Directly BEEPING on the Lisa by writing to VIA register
« Reply #5 on: January 29, 2022, 04:41:42 pm »

Yes, that's correct! Here's a small 68000 assembly program of my own that does exactly this.
Logged

kewatsdop

  • Full Member
  • ***
  • Karma: +8/-0
  • Offline Offline
  • Posts: 28
Re: Directly BEEPING on the Lisa by writing to VIA register
« Reply #6 on: January 30, 2022, 06:14:40 am »

Thank you Tom. I tried it out: compiled your Mandelbrot demo using vasmm68k_mot -Faout LisaMandelbrot.X68, and then created a floppy image using python dc42_build_bootable_disk.py a.out -f sony_800k -o floppy.dc42.

All worked fine!!! Thank you so much for this useful script.

Now I'm off to playing with 6522 register and trying to produce sounds in bare machine code...

One follow-up question. Is it easy to create a physical floppy disk out of a *.dc42 image? Would it be as easy as using dd if=floppy.dc42 of=/dev/myusbfloppydrive? I will be wanting to try my code also on an actual Lisa.

Logged

stepleton

  • Sr. Member
  • ****
  • Karma: +127/-0
  • Offline Offline
  • Posts: 425
Re: Directly BEEPING on the Lisa by writing to VIA register
« Reply #7 on: January 30, 2022, 06:38:47 am »

No, it won't work to use dd: a DC42 disk image has metadata at the front, and it also breaks each 524-byte sector into two pieces and stores them in different parts of the file, for reasons that make sense in an Apple context. Refer to these resources for details:

https://web.archive.org/web/20161028130400/https://wiki.68kmla.org/index.php?title=DiskCopy_4.2_format_specification
http://sigmasevensystems.com/blumanual.html Appendix E

If you have an older Mac, you can use Disk Copy 4.2 to write the disk image to a floppy. If you don't, then you still have some options. LisaEm includes a tool called dc42-to-raw which can convert a DC42 disk image to a raw file that you can use with dd. Or, you can boot up BLU on your Lisa and send the DC42 file to the Lisa via the serial port. BLU understands the format and can write the data to a floppy.

Lastly, you could buy a Floppy Emu and use that instead of your Lisa's floppy drive. Floppy Emu can work with DC42 files.
« Last Edit: January 30, 2022, 06:41:14 am by stepleton »
Logged

kewatsdop

  • Full Member
  • ***
  • Karma: +8/-0
  • Offline Offline
  • Posts: 28
Re: Directly BEEPING on the Lisa by writing to VIA register
« Reply #8 on: January 30, 2022, 07:02:55 am »

Thank you for the detailed answer! Ok, so even if it is not straightforward, there are several options to choose from. I'll be trying them out a couple of weeks from now. Before that happens, let me use the excellent LisaEm.
« Last Edit: January 30, 2022, 07:06:43 am by kewatsdop »
Logged

kewatsdop

  • Full Member
  • ***
  • Karma: +8/-0
  • Offline Offline
  • Posts: 28
Re: Directly BEEPING on the Lisa by writing to VIA register
« Reply #9 on: January 30, 2022, 07:38:29 am »

Hmmm. I wrote this as a stub and template:

; zero
                ORG     $800

SOUNDTEST:
                NOP

                END SOUNDTEST

                             

...and built myself a script to compile -> build disk...:

filename=$1
filename="${filename%.*}"

echo "Filename without extension is ${filename}"

echo -n "Compiling $1 with vasm... " &&\
vasmm68k_mot -Faout $1 &&\
echo "done." &&\
echo "Creating bootable floppy... " &&\
python ../bootloader-master/dc42_build_bootable_disk.py a.out -f sony_800k -o ${filename}.dc42 &&\
echo "done."


...which nicely produces a.out, and then the floppy image, but I'm getting boot ROM error 75 when trying to start from such a floppy image. What am I missing?
Logged

blusnowkitty

  • Sr. Member
  • ****
  • Karma: +75/-0
  • Offline Offline
  • Posts: 255
Re: Directly BEEPING on the Lisa by writing to VIA register
« Reply #10 on: January 30, 2022, 10:53:52 am »

Thank you for the detailed answer! Ok, so even if it is not straightforward, there are several options to choose from. I'll be trying them out a couple of weeks from now. Before that happens, let me use the excellent LisaEm.

Plus there is also the issue of all of the Apple 3.5 inch floppy drives have variable spindle speeds whereas PC floppy drives have a fixed spindle speed. This makes it physically impossible for PC and USB drives to write out Apple 400 and 800k disks.
Logged
You haven't lived until you've heard the sound of a Sony 400k drive.

rayarachelian

  • Administrator
  • Hero Member
  • *****
  • Karma: +105/-0
  • Offline Offline
  • Posts: 772
  • writing the code,writing the code,writing the code
    • LisaEm
Re: Directly BEEPING on the Lisa by writing to VIA register
« Reply #11 on: January 30, 2022, 12:40:58 pm »

Plus there is also the issue of all of the Apple 3.5 inch floppy drives have variable spindle speeds whereas PC floppy drives have a fixed spindle speed. This makes it physically impossible for PC and USB drives to write out Apple 400 and 800k disks.

That shouldn't be an issue with a real Lisa, you can use BLU for that and get BLU running through Service Mode and the serial port: http://sigmasevensystems.com/BLU

Access to an old world Mac with a 1.44M superdrive or even 800K drive and ethernet is also a really useful way to transfer things to a Lisa.
(However a superdrive would also allow you to transfer data to PCs if you don't have ethernet.)

I use a 5300ce for this which runs System 9 but since it has PCMCIA slots, I use an FAT32 formatted SDHC card inside PCMCIA adapter and use that to sneakernet disk images to my Linux machine. The 5300ce can easily create or image Lisa floppies.

Logged
You don't know what it's like, you don't have a clue, if you did you'd find yourselves doing the same thing, too, Writing the code, Writing the code

rayarachelian

  • Administrator
  • Hero Member
  • *****
  • Karma: +105/-0
  • Offline Offline
  • Posts: 772
  • writing the code,writing the code,writing the code
    • LisaEm
Re: Directly BEEPING on the Lisa by writing to VIA register
« Reply #12 on: January 30, 2022, 12:44:19 pm »

...which nicely produces a.out, and then the floppy image, but I'm getting boot ROM error 75 when trying to start from such a floppy image. What am I missing?

Well that's pretty obvious. You don't have any code there. That NOP will fall through to the next address which is likely all zeros and then eventually run wild and fail.

You should create some code to do something and not return to the boot ROM. For example, create a loop that generates sounds and loops around with DBRA as a time delay, etc. or fill the video memory addresses with something, etc.


Logged
You don't know what it's like, you don't have a clue, if you did you'd find yourselves doing the same thing, too, Writing the code, Writing the code

stepleton

  • Sr. Member
  • ****
  • Karma: +127/-0
  • Offline Offline
  • Posts: 425
Re: Directly BEEPING on the Lisa by writing to VIA register
« Reply #13 on: January 30, 2022, 05:05:08 pm »

As for something for your code to do, I recommend calling routines in the boot ROM. You can learn about them in this file:

http://www.bitsavers.org/pdf/apple/lisa/Lisa_Boot_ROM_Manual_V1.3_Feb84.pdf

starting at PDF page 28. I'd recommend calling $FE0084, "ROM Monitor", which is a convenient way for your program to quit to the boot ROM. Point A3 at a null-terminated string (uppercase letters only!) to print a message to the user.

As you're doing bare-metal programming, you might enjoy using routines from my lisa_io library. There's nothing in there for beeping though!
Logged

kewatsdop

  • Full Member
  • ***
  • Karma: +8/-0
  • Offline Offline
  • Posts: 28
Re: Directly BEEPING on the Lisa by writing to VIA register
« Reply #14 on: January 31, 2022, 01:53:57 pm »

Thank you for the help so far. The Lisa Boot ROM Manual looks very helpful indeed, but I'm not getting what I expect here:

I tried its BEEP routine (page 39 in that manual) by executing:

                ORG $800

playsound:
                MOVE.w #$10,D0
                MOVE.w #$F0,D1
                MOVE.w #$6,D2
                JSR $FE00B8

                MOVE.w #$A0,D0
                MOVE.w #$F0,D1
                MOVE.w #$A,D2
                JSR $FE00B8

                MOVE.w #$19,D0
                MOVE.w #$82,D1
                MOVE.w #$8,D2
                JSR $FE00B8

                MOVE.w #$A0,D0
                MOVE.w #$34,D1
                MOVE.w #$E,D2
                JSR $FE00B8

                end playsound


This does something with the speaker (short noisy sound), but definitely not the 4 sounds expected. Then it returns to ROM where I can diagnose the memory, etc.

Is there something I'm still doing wrong here or do you think this is related to the sound issue in LisaEm (as discussed here: https://lisalist2.com/index.php/topic,240.0.html) or am I missing something in my code again?
Logged
Pages: [1] 2   Go Up