Jump to content
IGNORED

issue with "Demo IIe Interrupt Code"


Recommended Posts

When I typed source into Applewin 1.24.0, CALL 768 brings me no result, no sound.

 Source:http://compgroups.net/comp.sys.apple2.programmer/demo-iie-interrupt-code/2174106
*300L

0300-   4C 15 03    JMP   $0315
0303-   48          PHA
0304-   B1 06       LDA   ($06),Y
0306-   A2 C4       LDX   #$C4
0308-   A0 40       LDY   #$40
030A-   8D 37 03    STA   $0337
030D-   8E 38 03    STX   $0338
0310-   68          PLA
0311-   20 36 03    JSR   $0336
0314-   60          RTS
0315-   A9 C4       LDA   #$C4
0317-   85 07       STA   $07
0319-   A0 19       LDY   #$19
031B-   20 03 03    JSR   $0303
031E-   A9 30       LDA   #$30
0320-   8D FE 03    STA   $03FE
0323-   A9 03       LDA   #$03
0325-   8D FF 03    STA   $03FF
0328-   A0 12       LDY   #$12
032A-   A9 08       LDA   #$08
032C-   20 03 03    JSR   $0303
032F-   60          RTS
0330-   AD 30 C0    LDA   $C030
0333-   A5 45       LDA   $45
0335-   40          RTI
0336-   4C 00 00    JMP   $0000

Is possible to use interrupt?

Link to comment
https://forums.atariage.com/topic/234547-issue-with-demo-iie-interrupt-code/
Share on other sites

When I typed source into Applewin 1.24.0, CALL 768 brings me no result, no sound.

<snip>

Is possible to use interrupt?

I'm not even going to try to figure out what code with no labels or comments is doing.

However, there is no vertical blank interrupt on the Apple II.

I had to use one of the timers on the Mockingboard to generate a recurring interrupt for my music player.

I believe you can also get an interrupt from the mouse card and a few others but I haven't used any of them.

Looks like this was from the following:

https://groups.google.com/forum/#!topic/comp.sys.apple2.programmer/UnNYbNPzFPA

 

Which goes on to say:

"Working on unenhanced IIe with AppleMouse Card in Slot 4. Produces a rather high-pitched tone on the loud speaker."

 

So... not going to work on an emulator without the AppleMouse card in slot 4.

but AppleWin emulates Multitasking Demo 1.1

That doesn't mean the code you are trying to use is complete either.

If the interrupt isn't set up properly you won't get any sound.

 

The code is a little odd. Maybe I'm interpreting it wrong though since I haven't spent much time on it.

They are using a JMP and I'm not sure where it is going; mostly because I don't know what is on page zero.

It appears to be some addresses like $C4xx which is the ROM for a peripheral card. Perhaps it's calling routines in the mouse card ROM.

$03FE is the IRQ handler address and it's obvious where it is being set but the interrupt handler doesn't save and restore registers so it's not what I would call a good example.

 

0300-   4C 15 03    JMP   $0315   ;skip to the main code


0303-   48          PHA
0304-   B1 06       LDA   ($06),Y  ; Y is changed by the caller
0306-   A2 C4       LDX   #$C4
0308-   A0 40       LDY   #$40
030A-   8D 37 03    STA   $0337   ;self modifying code, change JMP address
030D-   8E 38 03    STX   $0338
0310-   68          PLA

0311-   20 36 03    JSR   $0336   ;call the JMP
0314-   60          RTS

;main
0315-   A9 C4       LDA   #$C4
0317-   85 07       STA   $07    ; setup page zero
0319-   A0 19       LDY   #$19   ; page zero index?
031B-   20 03 03    JSR   $0303  ; call the subroutine to perform a jump

;set the interrupt handler address to $0330
031E-   A9 30       LDA   #$30   ;self modifying code, change jump to $0330
0320-   8D FE 03    STA   $03FE
0323-   A9 03       LDA   #$03
0325-   8D FF 03    STA   $03FF

; pass an address to the ROM routine the JMP is calling?
0328-   A0 12       LDY   #$12
032A-   A9 08       LDA   #$08
032C-   20 03 03    JSR   $0303
032F-   60          RTS

;the interrupt handler
0330-   AD 30 C0    LDA   $C030   ;click the speaker
0333-   A5 45       LDA   $45     ; *modifying a register within an interrupt without saving and restoring it is a bad idea*
0335-   40          RTI           ;return from the interrupt

;perform a jump to different handlers?
0336-   4C 00 00    JMP   $0000   ;address is changed by self modifying code

Edited by JamesD

One of my comments is wrong. Oops.

Ignore the part that says ";self modifying code,..."

;set the interrupt handler address to $0330
031E-   A9 30       LDA   #$30   ;self modifying code, change jump to $0330
0320-   8D FE 03    STA   $03FE
0323-   A9 03       LDA   #$03
0325-   8D FF 03    STA   $03FF

The LDY #$ before each JSR $303 is an offset into the $C400 page to get another offset for each of these mouse calls.

 

They are as follows:

 

Setmouse ($12) - sets the mode of the mouse - transparent or passive
Servmouse ($13) - verifies mouse was cause of interrupt
Readmouse ($14) - updates screenholes and mouse posn
Clearmouse ($15) - clears mouse screenholes to 0; for delta mode
Posmouse ($16) - positions mouse cursor
Clampmouse ($17) - sets the screen clamps
Homemouse ($18) - sets coords to top left of window
Initmouse ($19) - initialize mouse

 

The instruction at $32A has a LDA #$08.

This turns on interrupts for the mouse but the mouse is in passive mode and only some calls work in passive.

 

Try changing that to a LDA #$09, which puts the mouse in transparent mode.

or go into the monitor and change to this: 032B:09

 

Although the code is not quite complete as it stands, assuming the mouse is the only device creating interrupts on your computer,

this routine does claim any and all interrupts as its own. But to do that there should be a CLC just before the RTI at $0335.

Like I said before, this code is incomplete and was probably part of a larger program.

As is, it still may not work until interrupts are turned on.

 

Add a CLI just before the RTS at $033F to enable interrupts to be processed by the computer.

And remember that the 6502 interrupt doesn't preserve A so if you want to update the mouse from within a program that actually does something then this interrupt handler will cause your code to malfunction.

All what i found is A stored into $45

The code loads $45 into A in the interrupt, it does not save A into $45. It also does so after modifying A.


I think I would have the JMP subroutine calls switched to JSRs inline and have an init routine that modifies the addresses once instead of doing it repeatedly.
Without more docs on the mouse routines I wouldn't know exactly how to handle the interrupt but it would probably involve these steps:

IRQ_Handler:
;push modified registers to stack 
   pha
;  txa
;  pha
;  tya
;  pha

;check to see if interrupt was caused by mouse
   jsr   $0000   ; modify with address of Servmouse

;if not, skip to interrupt exit
;I have no idea what Servmouse does so ???????
;  beq bne interrupt_exit:

;update mouse
; check what the mouse did and call the appropriate mouse routine?
; Readmouse Posmouse?

interrupt_exit:
;pull registers
;  pla
;  tay
;  pla
;  tax
  pla
  rti
Edited by JamesD

Are you just trying to see how an interrupt handler works or are you trying to see how to make the Apple II mouse work?

I posted the code for my music player in another thread and it has an interrupt handler.
You can find it in this thread. The code is much larger but it might be of some help. No promises I posted every fix to the code though.
Link

I'll have to install Ciderpress or an emulator on my new machine before I could look at it.
The easiest approach to doing what you want is to simply get it working without the interrupt.
You can try polling the address that lets you read the vertical blank signal.

If you create a WaitVBlank subroutine and call it from a main loop you could test for a signal from an interrupt or poll the address looking for VBlank.
I think you just need to create a loop that checks if $C019 > 127 based on what I could find. I don't think it works on all Apples but then not all Apples have a mouse card either.
*edit*
Actually, I think you loop while that address is > 127. Not sure if emulators support this btw.
This page talks about it:
http://rich12345.tripod.com/aiivideo/vbl.html

Edited by JamesD

rich12345 also has a copy of Have an Apple Split by Bob Bishop, Softalk, October 1982.

The Bottom Line is, "What is not generally known is that the blanking can be detected by the Apple II, even though it lacks the special hardware found in those other machines."

MarkO

so, the point is "forget about interrupts"?

 

Probably....

 

Unless you have an Apple //c or ][gs, with standard Hardware to generate an Interrupt, you will need to make sure you Target Machine has Additional Hardware to make that happen.. e.g. The MOS6522 or equivalent on the Mouse Card/Interface is used for generating Interrupts. Mocking Board, Echo ][+, John Bell MOS6522 Card, etc...

 

Interrupts are tricky on the Apple ][, because all the Disk ][ Access are Timing Critical, so Interrupts are Disabled while performing Disk Access.

 

Apple DOS 3.3 is very poor with Interrupts, ProDOS has better support for Interrupts.

 

vertical blank signal detection can be done by the above posted links..

 

MarkO

It's not "better", just easier. The only reason you might have to use an interrupt is if you want to do something without stopping to poll but still have something take place at a closely timed interval.
This makes interrupts ideal for things that need to keep running no matter what else you are doing.
A person could reserve some memory, load a music player into it and then play music from a BASIC game, have a countdown timer, maintain a software clock, etc...


If you get it working without the interrupt you can always add it later and you aren't debugging the interrupt at the same time as the rest of the code.
Just remember, the IIe is the most abundant model out there and it requires a mouse card to support the interrupt you want to use and most IIe machines don't have a mouse card.
The IIc, IIc+ and IIgs have the mouse card built in but they are less abundant.

This is really a problem with the II series you just can't get around.
To get a demo to run on the most machines you'll have to test what machine you are running on since different models behave differently.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...