Joystick/Sound in Supervisor mode?

Anything QL Software or Programming Related.
User avatar
t0nyt
Gold Card
Posts: 384
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Re: Joystick/Sound in Supervisor mode?

Post by t0nyt »

Many thanks for the explanation Tofro

Got the code from a website, but will scrap it

Many thanks


User avatar
tofro
Font of All Knowledge
Posts: 2702
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Joystick/Sound in Supervisor mode?

Post by tofro »

I tend to use code like that:

Code: Select all

timerLinkage
timer_pllk      ds.l    1               ; Polling interrupt linkage
timer_plad      ds.l    1               ; Polling interrupt service routine address  


**********************************************************************************
* initTimer
* initialize timer
**********************************************************************************
initTimer
                ;DEBUG   {'InitTimer'}
                lea     timerTick,a0
                move.l  a0,timer_plad(a6)
                lea     timerLinkage(a6),a0
                QDOSMT$ MT.LPOLL
                rts
**********************************************************************************
* timerRemove
* initialize timer
**********************************************************************************
timerRemove
                ;DEBUG   {'TimerRemove'}
                lea     timerLinkage(a6),a0
                QDOSMT$ MT.RPOLL
                rts

**********************************************************************************
* timerTick
* Called in the polling interrupt, maintains a ms timer
**********************************************************************************
timerTick       
                add.l   #MSPERTICK,ticksMillis+8(a3)    ; we're no driver, thus look 8 
                                                        ; bytes further on for data!
                rts
There is, however, an even better method that also unlinks the polling routine when you end the program by Marcel somewhere here on the site.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
t0nyt
Gold Card
Posts: 384
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Re: Joystick/Sound in Supervisor mode?

Post by t0nyt »

tofro wrote: Thu Feb 22, 2024 1:07 pm I tend to use code like that:

Code: Select all

timerLinkage
timer_pllk      ds.l    1               ; Polling interrupt linkage
timer_plad      ds.l    1               ; Polling interrupt service routine address  


**********************************************************************************
* initTimer
* initialize timer
**********************************************************************************
initTimer
                ;DEBUG   {'InitTimer'}
                lea     timerTick,a0
                move.l  a0,timer_plad(a6)
                lea     timerLinkage(a6),a0
                QDOSMT$ MT.LPOLL
                rts
**********************************************************************************
* timerRemove
* initialize timer
**********************************************************************************
timerRemove
                ;DEBUG   {'TimerRemove'}
                lea     timerLinkage(a6),a0
                QDOSMT$ MT.RPOLL
                rts

**********************************************************************************
* timerTick
* Called in the polling interrupt, maintains a ms timer
**********************************************************************************
timerTick       
                add.l   #MSPERTICK,ticksMillis+8(a3)    ; we're no driver, thus look 8 
                                                        ; bytes further on for data!
                rts
There is, however, an even better method that also unlinks the polling routine when you end the program by Marcel somewhere here on the site.
Many thanks!


Silvester
Gold Card
Posts: 436
Joined: Thu Dec 12, 2013 10:14 am
Location: UK

Re: Joystick/Sound in Supervisor mode?

Post by Silvester »

tofro wrote: Thu Feb 22, 2024 1:07 pmThere is, however, an even better method that also unlinks the polling routine when you end the program by Marcel somewhere here on the site.
? https://www.qlforum.co.uk/viewtopic.php ... =10#p45932


David
User avatar
t0nyt
Gold Card
Posts: 384
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Re: Joystick/Sound in Supervisor mode?

Post by t0nyt »

tofro wrote: Thu Feb 22, 2024 1:07 pm I tend to use code like that:

Code: Select all

timerLinkage
timer_pllk      ds.l    1               ; Polling interrupt linkage
timer_plad      ds.l    1               ; Polling interrupt service routine address  


**********************************************************************************
* initTimer
* initialize timer
**********************************************************************************
initTimer
                ;DEBUG   {'InitTimer'}
                lea     timerTick,a0
                move.l  a0,timer_plad(a6)
                lea     timerLinkage(a6),a0
                QDOSMT$ MT.LPOLL
                rts
**********************************************************************************
* timerRemove
* initialize timer
**********************************************************************************
timerRemove
                ;DEBUG   {'TimerRemove'}
                lea     timerLinkage(a6),a0
                QDOSMT$ MT.RPOLL
                rts

**********************************************************************************
* timerTick
* Called in the polling interrupt, maintains a ms timer
**********************************************************************************
timerTick       
                add.l   #MSPERTICK,ticksMillis+8(a3)    ; we're no driver, thus look 8 
                                                        ; bytes further on for data!
                rts
There is, however, an even better method that also unlinks the polling routine when you end the program by Marcel somewhere here on the site.
I can't get most of this to assemble especially anything referencing "(A6)" which throws "relocatable value not allowed here"

I have the Dickens book, and others, so I think I'll work my way through those so I can fully understand what's what

Many thanks


User avatar
janbredenbeek
Super Gold Card
Posts: 633
Joined: Wed Jan 21, 2015 4:54 pm
Location: Hilversum, The Netherlands

Re: Joystick/Sound in Supervisor mode?

Post by janbredenbeek »

t0nyt wrote: Thu Feb 22, 2024 3:11 pm
tofro wrote: Thu Feb 22, 2024 1:07 pm I tend to use code like that:

Code: Select all

timerLinkage
timer_pllk      ds.l    1               ; Polling interrupt linkage
timer_plad      ds.l    1               ; Polling interrupt service routine address  
...
I can't get most of this to assemble especially anything referencing "(A6)" which throws "relocatable value not allowed here"
You are declaring these variables within a SECTION, which produces relocatable values. You should declare them within an OFFSET section (e.g. OFFSET 0), which declares them as simple (scalar) values from the specified offset (normally starting at zero). Then reserve some space for it (normally in the job's dataspace but it can be in code space too) and let A6 point to it.


User avatar
janbredenbeek
Super Gold Card
Posts: 633
Joined: Wed Jan 21, 2015 4:54 pm
Location: Hilversum, The Netherlands

Re: Joystick/Sound in Supervisor mode?

Post by janbredenbeek »

tofro wrote: Thu Feb 22, 2024 12:48 pm Just a short explanation on why you shouldn't be fiddling with PC_INTR ($18021) directly:

If you write directly to that address (a hardware register), you're confusing the system that normally maintains a copy on what was last written there. Next, you seem to be writing $ff there, which re-arms all interrupts, not just the vsync. When you read that address, you're not checking the vsync bit only (which is in fact the frame interrupt), but rather check for non-zero, which basically triggers on any interrupts the QL has. So, in case people have special hardware that uses the external interrupt or you have microdrives running or network or serial traffic incoming, your routine will also assume 0.02s have passed... If you want exactly that, a simple HALT would do he same (It just waits for the next interrupt which is effectively what your loop does).
There is an excellent explanation of all PC.INTR bits on read and write in Minerva's source code: https://github.com/janbredenbeek/Minerv ... n/m/inc/pc

In short:

bits 0-4 are gap/interface/transmit/frame/external interrupt bits (reading a 1 means the interrupt has been asserted, writing a 1 signals the interrupt has been processed).
bits 5-7 are gap/interface/transmit enable/disable on write (1 to enable). So you cannot disable frame and external unless you set the interrupt bits in the 68000's SR.
Reading bits 5-7 has no practical use unless you want to do something with the ZX8302's clock or BAUDx4 signal...


User avatar
t0nyt
Gold Card
Posts: 384
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Re: Joystick/Sound in Supervisor mode?

Post by t0nyt »

janbredenbeek wrote: Thu Feb 22, 2024 3:58 pm
t0nyt wrote: Thu Feb 22, 2024 3:11 pm
tofro wrote: Thu Feb 22, 2024 1:07 pm I tend to use code like that:

Code: Select all

timerLinkage
timer_pllk      ds.l    1               ; Polling interrupt linkage
timer_plad      ds.l    1               ; Polling interrupt service routine address  
...
I can't get most of this to assemble especially anything referencing "(A6)" which throws "relocatable value not allowed here"
You are declaring these variables within a SECTION, which produces relocatable values. You should declare them within an OFFSET section (e.g. OFFSET 0), which declares them as simple (scalar) values from the specified offset (normally starting at zero). Then reserve some space for it (normally in the job's dataspace but it can be in code space too) and let A6 point to it.
Thanks Jan, but I don't currently even understand what you mean by "Then reserve some space for it (normally in the job's dataspace but it can be in code space too) ". I'll have to read up on this as I don't see how the code in the OFFSET ends up in the reserved space in some way. And the last part of the code references stuff that isn't declared anywhere in the code so I'm totally lost

I'll work thru my books to try and get an understanding

Many thanks


User avatar
tofro
Font of All Knowledge
Posts: 2702
Joined: Sun Feb 13, 2011 10:53 pm
Location: SW Germany

Re: Joystick/Sound in Supervisor mode?

Post by tofro »

Well, QDOS programs normally tend to store their data in the data space (hence the name :) ). That is an area of memory normally after your program code which is allocated for you to work with. You tell the assembler (if you assemble with "-NOLINK") using the DATA directive how much you want (or it will allocate a default of 4k for you). When your program is started, a6+a4 points to the bottom of that space, so one of the first instructions in most of my programs is

Code: Select all

	lea.l   0(a6,a4.l),a6                   ; let a6 point to data space
and a6 is never touched again later on. You can then use a6 to point into that space to use it for variables. This is done so that multiple jobs executing the same program can share the code, but have separate data. Maybe not so relevant for a game, though.


ʎɐqǝ ɯoɹɟ ǝq oʇ ƃuᴉoƃ ʇou sᴉ pɹɐoqʎǝʞ ʇxǝu ʎɯ 'ɹɐǝp ɥO
User avatar
t0nyt
Gold Card
Posts: 384
Joined: Wed Nov 22, 2023 6:46 pm
Location: UK

Re: Joystick/Sound in Supervisor mode?

Post by t0nyt »

tofro wrote: Thu Feb 22, 2024 5:00 pm Well, QDOS programs normally tend to store their data in the data space (hence the name :) ). That is an area of memory normally after your program code which is allocated for you to work with. You tell the assembler (if you assemble with "-NOLINK") using the DATA directive how much you want (or it will allocate a default of 4k for you). When your program is started, a6+a4 points to the bottom of that space, so one of the first instructions in most of my programs is

Code: Select all

	lea.l   0(a6,a4.l),a6                   ; let a6 point to data space
and a6 is never touched again later on. You can then use a6 to point into that space to use it for variables. This is done so that multiple jobs executing the same program can share the code, but have separate data. Maybe not so relevant for a game, though.
Thanks Tofro, so "OFFSET 0" puts the code at the start of the 4kb?

It still won't assemble code after an OFFSET though (the offset section is at the end of my source file)

Screenshot 2024-02-22 at 17.07.59.png


Post Reply