General Category > LisaList2

Directly BEEPING on the Lisa by writing to VIA register

(1/5) > >>

rayarachelian:
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?


--- Quote from: kewatsdop on January 28, 2022, 02:09:17 pm ---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.

--- End quote ---

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: ---MOVE d0, $0000DD81

--- End code ---

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: ---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)

--- End code ---

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

kewatsdop:
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.

rayarachelian:

--- Quote from: kewatsdop on January 28, 2022, 05:28:26 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.

--- End quote ---

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.)

stepleton:
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.

kewatsdop:
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.

Navigation

[0] Message Index

[#] Next page

Go to full version