Discussion:
Interrupt code.... specifically for mockingboard?
(too old to reply)
Tom Porter
2017-09-24 01:45:54 UTC
Permalink
Raw Message
Would anybody be able to show a very simple example code of an interrupt setup routine... Most useful for the way a mockingboard timer is used... I would love to upgrade my midi2mockingboard software but cant wrap my head around how to init the timer...

(I know once the routine is in memory, you link it to the JSR at 1022 and 1023... and use the RTI...) But how to you keep the timer, or reset it also? Just the most basic code needed, I can mod it... doesn't even have to be music code... just an interrupt I can mess with !
Antoine Vignau
2017-09-24 05:19:15 UTC
Permalink
Raw Message
Ah... 3FE and 3FF...
Tom Porter
2017-09-24 14:14:43 UTC
Permalink
Raw Message
1 PRINT CHR$ (4);"BLOAD INT1"
2 PRINT CHR$ (4);"BLOAD INT2"
3 CALL 30000
4 B = B + 1: PRINT B: GOTO 4


init1
7530- 18 CLC
7531- A9 40 LDA #$40
7533- 8D 0B C4 STA $C40B
7536- A9 7F LDA #$7F
7538- 8D 0E C4 STA $C40E
753B- A9 C0 LDA #$C0
753D- 8D 0D C4 STA $C40D
7540- 8D 0E C4 STA $C40E
7543- A9 FF LDA #$FF
7545- 8D 04 C4 STA $C404
7548- A9 40 LDA #$40
754A- 8D 05 C4 STA $C405
754D- A9 00 LDA #$00
754F- 8D FE 03 STA $03FE
7552- A9 85 LDA #$85
7554- 8D FF 03 STA $03FF
7557- 58 CLI
7558- 60 RTS

init2
8500- 48 PHA
8501- 8A TXA
8502- 48 PHA
8503- 98 TYA
8504- 48 PHA
8505- A9 C0 LDA #$C0
8507- 8D 0D C4 STA $C40D
850A- 20 DD FB JSR $FBDD F8ROM:BELL1
850D- 68 PLA
850E- A8 TAY
850F- 68 PLA
8510- AA TAX
8511- 68 PLA
8512- A5 45 LDA $45
8514- 40 RTI


I don't know much about $45 except its mentioned that DOS can screw it up,
and its part of the MCS code...

this program should continue beeping... along with printing increasing value
of B ... I think perhaps I should sta something else other then one thing in the 2nd routine...
Michael 'AppleWin Debugger Dev'
2017-09-25 07:34:17 UTC
Permalink
Raw Message
Your bug is this line:
8505- A9 C0 LDA #$C0

In order to clear the Timer 1 IRQ flag it should be this:
8505- A9 C0 LDA #$40


Here is a copy/paste script:

CALL-151
7530:18
7531:A9 40
7533:8D 0B C4
7536:A9 7F
7538:8D 0E C4
753B:A9 C0
753D:8D 0D C4
7540:8D 0E C4
7543:A9 FF
7545:8D 04 C4
7548:A9 40
754A:8D 05 C4
754D:A9 00
754F:8D FE 03
7552:A9 85
7554:8D FF 03
7557:58
7558:60
8500:48
8501:8A
8502:48
8503:98
8504:48
8505:A9 40
8507:8D 0D C4
850A:20 DD FB
850D:68
850E:A8
850F:68
8510:AA
8511:68
8512:A5 45
8514:40
3D0G
NEW
3 CALL 30000
4 B = B + 1: PRINT B: GOTO 4
RUN
Antoine Vignau
2017-09-25 08:55:54 UTC
Permalink
Raw Message
Why push pull A if you finish with A5 45?!?
I am Rob
2017-09-25 14:04:38 UTC
Permalink
Raw Message
Post by Antoine Vignau
Why push pull A if you finish with A5 45?!?
I don't use DOS any more, but when I did, nibble magazine suggested I do it this way.

LDA $45
PHA
TYA
PHA
TXA
PHA
...
PLA
TAX
PLA
TAY
PLA
RTS


Rob
I am Rob
2017-09-25 14:18:07 UTC
Permalink
Raw Message
Post by Tom Porter
1 PRINT CHR$ (4);"BLOAD INT1"
2 PRINT CHR$ (4);"BLOAD INT2"
3 CALL 30000
4 B = B + 1: PRINT B: GOTO 4
init1
7530- 18 CLC
7531- A9 40 LDA #$40
7533- 8D 0B C4 STA $C40B
7536- A9 7F LDA #$7F
7538- 8D 0E C4 STA $C40E
753B- A9 C0 LDA #$C0
753D- 8D 0D C4 STA $C40D
7540- 8D 0E C4 STA $C40E
7543- A9 FF LDA #$FF
7545- 8D 04 C4 STA $C404
7548- A9 40 LDA #$40
754A- 8D 05 C4 STA $C405
754D- A9 00 LDA #$00
754F- 8D FE 03 STA $03FE
7552- A9 85 LDA #$85
7554- 8D FF 03 STA $03FF
7557- 58 CLI
7558- 60 RTS
init2
8500- 48 PHA
8501- 8A TXA
8502- 48 PHA
8503- 98 TYA
8504- 48 PHA
8505- A9 C0 LDA #$C0
8507- 8D 0D C4 STA $C40D
850A- 20 DD FB JSR $FBDD F8ROM:BELL1
850D- 68 PLA
850E- A8 TAY
850F- 68 PLA
8510- AA TAX
8511- 68 PLA
8512- A5 45 LDA $45
8514- 40 RTI
I don't know much about $45 except its mentioned that DOS can screw it up,
and its part of the MCS code...
this program should continue beeping... along with printing increasing value
of B ... I think perhaps I should sta something else other then one thing in the 2nd routine...
Why push pull A if you finish with A5 45?!?
I don't use DOS any more, but when I did, nibble magazine suggested I do it this way.


LDA $45
PHA
TYA
PHA
TXA
PHA
...
PLA
TAX
PLA
TAY
PLA
RTI



for Prodos

PHP
SEI
JSR $BF00
HEX 40
DW SETINTPARM
PLP
JMP $BE09

SETINTPARM EQU *
DFB 02
DFB 00
DA INTROUT

INTROUT EQU *
CLD
LDA $45
PHA
TYA
PHA
TXA
PHA
PHP ; push interrupt state
SEI ; disable interrupts
...
PLA
TAX
PLA
TAY
PLA
STA $45
PLP ; pull previous interrupt state
RTS ; for Prodos this is not a RTI
I am Rob
2017-09-25 14:20:04 UTC
Permalink
Raw Message
Post by I am Rob
Post by Tom Porter
1 PRINT CHR$ (4);"BLOAD INT1"
2 PRINT CHR$ (4);"BLOAD INT2"
3 CALL 30000
4 B = B + 1: PRINT B: GOTO 4
init1
7530- 18 CLC
7531- A9 40 LDA #$40
7533- 8D 0B C4 STA $C40B
7536- A9 7F LDA #$7F
7538- 8D 0E C4 STA $C40E
753B- A9 C0 LDA #$C0
753D- 8D 0D C4 STA $C40D
7540- 8D 0E C4 STA $C40E
7543- A9 FF LDA #$FF
7545- 8D 04 C4 STA $C404
7548- A9 40 LDA #$40
754A- 8D 05 C4 STA $C405
754D- A9 00 LDA #$00
754F- 8D FE 03 STA $03FE
7552- A9 85 LDA #$85
7554- 8D FF 03 STA $03FF
7557- 58 CLI
7558- 60 RTS
init2
8500- 48 PHA
8501- 8A TXA
8502- 48 PHA
8503- 98 TYA
8504- 48 PHA
8505- A9 C0 LDA #$C0
8507- 8D 0D C4 STA $C40D
850A- 20 DD FB JSR $FBDD F8ROM:BELL1
850D- 68 PLA
850E- A8 TAY
850F- 68 PLA
8510- AA TAX
8511- 68 PLA
8512- A5 45 LDA $45
8514- 40 RTI
I don't know much about $45 except its mentioned that DOS can screw it up,
and its part of the MCS code...
this program should continue beeping... along with printing increasing value
of B ... I think perhaps I should sta something else other then one thing in the 2nd routine...
Why push pull A if you finish with A5 45?!?
I don't use DOS any more, but when I did, nibble magazine suggested I do it this way.
LDA $45
PHA
TYA
PHA
TXA
PHA
...
PLA
TAX
PLA
TAY
PLA
RTI
for Prodos
PHP
SEI
JSR $BF00
HEX 40
DW SETINTPARM
PLP
JMP $BE09
SETINTPARM EQU *
DFB 02
DFB 00
DA INTROUT
INTROUT EQU *
CLD
LDA $45
PHA
TYA
PHA
TXA
PHA
PHP ; push interrupt state
SEI ; disable interrupts
...
PLA
TAX
PLA
TAY
PLA
STA $45
PLP ; pull previous interrupt state
RTS ; for Prodos this is not a RTI
Ouch! My keyboard has Cerebral Palsy. Disregard these 2 replies to Antoine.
I am Rob
2017-09-25 14:21:43 UTC
Permalink
Raw Message
Post by Tom Porter
1 PRINT CHR$ (4);"BLOAD INT1"
2 PRINT CHR$ (4);"BLOAD INT2"
3 CALL 30000
4 B = B + 1: PRINT B: GOTO 4
init1
7530- 18 CLC
7531- A9 40 LDA #$40
7533- 8D 0B C4 STA $C40B
7536- A9 7F LDA #$7F
7538- 8D 0E C4 STA $C40E
753B- A9 C0 LDA #$C0
753D- 8D 0D C4 STA $C40D
7540- 8D 0E C4 STA $C40E
7543- A9 FF LDA #$FF
7545- 8D 04 C4 STA $C404
7548- A9 40 LDA #$40
754A- 8D 05 C4 STA $C405
754D- A9 00 LDA #$00
754F- 8D FE 03 STA $03FE
7552- A9 85 LDA #$85
7554- 8D FF 03 STA $03FF
7557- 58 CLI
7558- 60 RTS
init2
8500- 48 PHA
8501- 8A TXA
8502- 48 PHA
8503- 98 TYA
8504- 48 PHA
8505- A9 C0 LDA #$C0
8507- 8D 0D C4 STA $C40D
850A- 20 DD FB JSR $FBDD F8ROM:BELL1
850D- 68 PLA
850E- A8 TAY
850F- 68 PLA
8510- AA TAX
8511- 68 PLA
8512- A5 45 LDA $45
8514- 40 RTI
I don't know much about $45 except its mentioned that DOS can screw it up,
and its part of the MCS code...
this program should continue beeping... along with printing increasing value
of B ... I think perhaps I should sta something else other then one thing in the 2nd routine...
Why push pull A if you finish with A5 45?!?
I don't use DOS any more, but when I did, nibble magazine suggested I do it this way.


LDA $45
PHA
TYA
PHA
TXA
PHA
...
PLA
TAX
PLA
TAY
PLA
RTI



for Prodos

PHP
SEI
JSR $BF00
HEX 40
DW SETINTPARM
PLP
JMP $BE09

SETINTPARM EQU *
DFB 02
DFB 00
DA INTROUT

INTROUT EQU *
CLD
LDA $45
PHA
TYA
PHA
TXA
PHA
PHP ; push interrupt state
SEI ; disable interrupts
...
PLA
TAX
PLA
TAY
PLA
STA $45
PLP ; pull previous interrupt state
RTS ; for Prodos this is not a RTI
Tom Porter
2017-09-26 17:00:50 UTC
Permalink
Raw Message
yes IT WORKS... it took forever. The code above still didn't work as advertised but I appreciate all the effort... dug into the 6522 manuals and really didn't understand much of them... but found the answer... if you looking for MULTI_TASKING code with a mockingboard, at least in DOS here you go! Now to figure out how to make the timer longer, and then rewrite Midi-2-Mock from the ground up for better and interrupt music.. Thank you People!

PS... this does a 2 byte counter in the middle of the screen... you need a mockingboard (of course) for it to work)... you can take the code and do whatever you want with it... (In the future, I will be doing a super-simple few page manual writeup for most functions in Mockingboard to make music ect in pretty much layman's terms... something that's sorely needed!


1 PRINT CHR$(4);"BLOAD INT1"
2 PRINT CHR$(4);"BLOAD INT2":POKE 34056,127
3 CALL 30040:HOME
4 VTAB 10:PRINT PEEK(32000),PEEK(32001):GOTO 4



7558- A9 00 LDA #$00
755A- 8D FE 03 STA $03FE
755D- A9 85 LDA #$85
755F- 8D FF 03 STA $03FF
7562- A9 40 LDA #$40
7564- 8D 0B C4 STA $C40B
7567- A9 7F LDA #$7F
7569- 8D 0E C4 STA $C40E
756C- A9 C0 LDA #$C0
756E- 8D 0D C4 STA $C40D
7571- 8D 0E C4 STA $C40E
7574- A9 FF LDA #$FF
7576- 8D 04 C4 STA $C404
7579- A9 40 LDA #$40
757B- 8D 05 C4 STA $C405
757E- 58 CLI
757F- 60 RTS

8500- A5 45 LDA $45
8502- 48 PHA
8503- 98 TYA
8504- 48 PHA
8505- 8A TXA
8506- 48 PHA
8507- A9 02 LDA #$02
8509- 8D 0D C4 STA $C40D
850C- EE 00 7D INC $7D00
850F- D0 03 BNE $8514
8511- EE 01 7D INC $7D01
8514- 68 PLA
8515- AA TAX
8516- 68 PLA
8517- A8 TAY
8518- 68 PLA
8519- 40 RTI

-----------DECIMAL BELOW...----------

IDIOT DISASEMBLER V.57
FILE: INT1

30040- A9 00 LDA #0
30042- 8D FE 03 STA 1022
30045- A9 85 LDA #133
30047- 8D FF 03 STA 1023
30050- A9 40 LDA #64
30052- 8D 0B C4 STA 50187
30055- A9 7F LDA #127
30057- 8D 0E C4 STA 50190
30060- A9 C0 LDA #192
30062- 8D 0D C4 STA 50189
30065- 8D 0E C4 STA 50190
30068- A9 FF LDA #255
30070- 8D 04 C4 STA 50180
30073- A9 40 LDA #64
30075- 8D 05 C4 STA 50181
30078- 58 CLI
30079- 60 RTS

IDIOT DISASEMBLER V.57
FILE: INT2

34048- A5 45 LDA 69
34050- 48 PHA
34051- 98 TYA
34052- 48 PHA
34053- 8A TXA
34054- 48 PHA
34055- A9 02 LDA #2
34057- 8D 0D C4 STA 50189
34060- EE 00 7D INC 32000
34063- D0 03 BNE 34068
34065- EE 01 7D INC 32001
34068- 68 PLA
34069- AA TAX
34070- 68 PLA
34071- A8 TAY
34072- 68 PLA
34073- 40 RTI
Michael 'AppleWin Debugger Dev'
2017-09-27 14:56:28 UTC
Permalink
Raw Message
Minified script. Also compacted, and relocated to page $3

- - - 8< - - -

CALL-151
300:00 00

302:A9 30
304:8D FE 03
307:A9 03
309:8D FF 03
30C:A9 40
30E:8D 0B C4
311:A9 7F
313:8D 0E C4
316:A9 C0
318:8D 0D C4
31B:8D 0E C4
31E:A9 FF
320:8D 04 C4
323:A9 40
325:8D 05 C4
328:58
329:60

330:A5 45
332:48
333:98
334:48
335:8A
336:48
337:A9 7F
339:8D 0D C4
33C:EE 00 03
33F:D0 03
341:EE 01 03
344:68
345:AA
346:68
347:A8
348:68
349:40

E000G
3 TEXT:HOME:CALL 770
4 VTAB 10:PRINT PEEK(768),PEEK(769):GOTO 4
RUN
Michael 'AppleWin Debugger Dev'
2017-09-27 15:57:08 UTC
Permalink
Raw Message
Post by Tom Porter
Now to figure out how to make the timer longer,
Base+5 and Base+6 control the timer 1 counter.

LDA #$__ ; Quantum Lo
STA $C405 ; Timer 1 Lo
LDA #$__ ; Quantum Hi
STA $C406 ; Timer 1 Hi

Can anyone else confirm this?

* Min timer delay can't go below $3000. That is 1,022,727 / 12,288 = ~83 Hz max frequency.
* Max timer delay is $FFFF. That is 1,022,727 / 65,535 = ~15 Hz min frequency.


Examples:

For 50 Hz NTSC = ceil( 1,022,727 Hz / 50 Hz ) = 20,455 = $4FE7

CALL-151
31E:A9 E7
320:8D 04 C4
323:A9 4F
325:8D 05 C4

33C:EE 00 03
33F:AD 00 03
342:C9 32
344:90 08
346:A9 00
348:8D 00 03
34B:EE 01 03
34E:68
34F:AA
350:68
351:A8
352:68
353:40
E003G
RUN



For 20 Hz NTSC = ceil( 1,022,727 Hz / 20 Hz ) = 51,137 = $C7C1

CALL-151
31E:A9 C1
320:8D 04 C4
323:A9 C7
325:8D 05 C4

33C:EE 00 03
33F:AD 00 03
342:C9 14
344:90 08
346:A9 00
348:8D 00 03
34B:EE 01 03
34E:68
34F:AA
350:68
351:A8
352:68
353:40
E003G
RUN
geoff body
2017-09-28 04:27:51 UTC
Permalink
Raw Message
The only thing I would consider when about to change the interrupt vector, is to disable interrupts first incase there are other active routines already configured. Also consider chaining to the existing routine once your finished your own routine.

Geoff B

Loading...