{"action":"created","issue":{"url":"https://api.github.com/repos/AppleWin/AppleWin/issues/265","labels_url":"https://api.github.com/repos/AppleWin/AppleWin/issues/265/labels{/name}","comments_url":"https://api.github.com/repos/AppleWin/AppleWin/issues/265/comments","events_url":"https://api.github.com/repos/AppleWin/AppleWin/issues/265/events","html_url":"https://github.com/AppleWin/AppleWin/issues/265","id":57056054,"number":265,"title":"Asking for the way Applewin handles VBL and mouse interrupts.","user":{"login":"benoit0123","id":6728352,"avatar_url":"https://avatars.githubusercontent.com/u/6728352?v=3","gravatar_id":"","url":"https://api.github.com/users/benoit0123","html_url":"https://github.com/benoit0123","followers_url":"https://api.github.com/users/benoit0123/followers","following_url":"https://api.github.com/users/benoit0123/following{/other_user}","gists_url":"https://api.github.com/users/benoit0123/gists{/gist_id}","starred_url":"https://api.github.com/users/benoit0123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benoit0123/subscriptions","organizations_url":"https://api.github.com/users/benoit0123/orgs","repos_url":"https://api.github.com/users/benoit0123/repos","events_url":"https://api.github.com/users/benoit0123/events{/privacy}","received_events_url":"https://api.github.com/users/benoit0123/received_events","type":"User","site_admin":false},"labels":[],"state":"open","locked":false,"assignee":null,"milestone":null,"comments":4,"created_at":"2015-02-09T16:45:05Z","updated_at":"2015-02-12T11:03:46Z","closed_at":null,"body":"This post just to advise that Applewin and Virtual][ handle the same program differently (crash on Applewin, not on Virtual2) and asking for help...\r\nForgive me for the verbosity of this post and the lack of fluency in English (which is not my mother language). A similar post was posted to comp.sys.apple2.emulators some time ago.\r\nLet's begin:\r\nI am in the process of adding some features to a utility I began working on\r\nsome years ago.\r\nThe newly added feature would be to enable high level \"handling\" of hardware\r\ninterrupts  (mouse moves, mouse button presses and VBL for the time being)\r\nby Applesoft \"user written\" subroutines (the ones being invoked with a GOSUB\r\nstatement and usually ending their flow with a RETURN statement).\r\nThe architecture is based on two components only being lazily bound\r\ntogether:\r\nA generic hardware interrupt handling which is inserted at the user IRQ\r\nvector (daisy chain). This hardware will handle mouse interface interrupts\r\nthe apple way (which I hope so) and passing on the IRQ to the original IRQ\r\nvector it found when installed ($FF65 monitor ROM routine address if none).\r\nAn intercept at the level of the Applesoft interpreter eval loop for\r\ncreating Applesoft GOSUB stack frames ex nihilo and \"passing control\" to\r\nregistered Applesoft subroutines (one for mouse related and one for\r\ntimer/VBL related).\r\nThe issue I've met here is:\r\na) As the mechanism works great in my main developement environment which is\r\nthe Virtual ][ emulator under Mac OS X (emulates an enhanced Apple //e with\r\nmouse interface card in slot 5).\r\nb) The same mechanism leads to a monitor prompt under the Applewin emulator\r\n(trying  to handle both VBL and mouse moves/button presses concurrently\r\n(i.e. mouse interface mode being $0F) as soon as a mouse move occurs.\r\nHowever if I restrict myself to handle VBL only interupts (mouse interface\r\nmode being $08), the mechanism works great on Applewin as it does on Virtual\r\n][.\r\nBy the way, I observe the same behavior in Sweet16 as in Applewin :-( .. But\r\nwhat I do not understand is that the program works great on Virtual 2.\r\n\r\n*** My asking is: at which level is the mouse emulated within Applewin? Does\r\nApplewin emulate the Apple mouse card at the harware level (i.e. r/w access\r\nto page $C0), or does it include its own firmware  for emulating an Apple\r\nmouse //? ***\r\nFor your information here is the extract which might be useful for\r\ninvestigation (65C02 variant).\r\nRSRVM        =        1        SERVMOUSE reason code\r\nRREAD        =        2        READMOUSE reason code\r\nBAMBS        EQU        $0778        Base address for mouse status\r\n* Begin of our generic hardware interrupt handlig routine\r\nIRQHDLR LDX        #RSRVM\r\n        JSR        TOMOUSE\r\n        BCS        :2\r\n        LDX        MOSL        ;Mouse slot #, 4 in case Applewin is the host\r\n        LDA        BAMBS,X\r\n        LSR\r\n* Move interrupt bit in b0\r\n* Button press interrupt bit in b1\r\n* VBL interrupt bit in b2\r\n        AND        #7        Mask out other bits\r\n        TAX                X must be greater than 0\r\n        LDA        MSTATUS,X        one of the $40/$80/$C0 values\r\n        STA        WORKPL1\r\n        LDX        #RREAD\r\n        JSR        TOMOUSE\r\n        BIT        WORKPL1\r\n        BPL        :1        Branch if no VBL this time...\r\n* Only if TIINC decremented reaches zero, do we perform\r\n* the forwarding to Applesoft higher level\r\n        LDX        TIINC\r\n        BNE        *+5\r\n        DEC        TIINC+1\r\n        DEX\r\n        STX        TIINC\r\n        BNE        :3        Not yet zero..\r\n        LDA        TIINC+1\r\n        BEQ        :00        Yes, reinit the counter..\r\n:3        LDA        #$80        Mask out the VBL interrupt flag\r\n        TRB        WORKPL1\r\n:1        LDA        WORKPL1\r\n        TSB        MIRQST\r\n:2        RTI\r\n:00        LDA        KTINC        reinstate the counter value\r\n        STA        TIINC\r\n        LDA        KTINC+1\r\n        STA        TIINC+1\r\n        BRA        :1\r\nTOMOUSE\r\n        LDY        OM_DEB,X        offset of handling routine from start of $C4 page\r\n        LDX        MOCN        ;$C4 value within Applewin context\r\n        PHP                        ; (in Applewin context)\r\n        SEI                        ;Ensure no interrupt during the call to apple firmware\r\n        STY        MVECTOR\r\n        LDY        MON0        ;$40 value within Applewin context\r\n        JSR        :0\r\n        BCS        :1\r\n        PLP\r\n        CLC\r\n        RTS\r\n:1        PLP\r\n        SEC\r\n        RTS\r\n:0        JMP        (MVECTOR)        MVECTOR high byte already set to $C4 (Applewin context)\r\n*  MSTATUTS b7 set iif VBL occured, b6 set iif mouse move or button pressed.\r\nMSTATUS HEX        0040404080C0C0C0\r\nKTINC        DA        60        So that VBL interrupts are signaled only every second to\r\nApplesoft..\r\nTIINC        DS        0        Running 16bits counter from KTINC downto 0 within interrupt.\r\nWORKPL1 DS        1        Workplace memory slot private for interrupt routine use\r\nMIRQST DS        1        IRQ status as raised from hardware routine above to Applesoft\r\neval.\r\nMOCN        DS        1        $C4 value in Applewin context\r\nMON0        DS        1        $40 value in Applewin value\r\nOM_DEB DS        10        Table of offsets as computed when the utility boots.\r\n* for RSRVM, the value is $C4 (meaning the routine handling the SERVMOUSE\r\nAPI starts at adress $C4C4, for RREAD in Applewin, the value is $9B (address\r\n$C49B in AppleWin).\r\nI have put the disk archive on my web site for the convenience of those who\r\nwould like to help me \"find the culprit\". The URL is\r\nhttp://bgilon.free.fr/apple2/P15preview.zip\r\nThe D34Peersoftv15.do is the executable disk image, just boot it, select the\r\n65C02 variant of the Peersoft utility at boot time. Once it is loaded the\r\nexemple program to try is the MOUSTST4 Applesoft program. After rebooting\r\nand reloaded the Peersoft utility, the program to try is the TIMRTST1 which\r\nworks great even in the Applewin environment.  The D34Sources -\r\nPeersoftv15.do contain the sources files (Merlin format).\r\n\r\nThank you for reading,\r\nBenoît\r\n"},"comment":{"url":"https://api.github.com/repos/AppleWin/AppleWin/issues/comments/74053479","html_url":"https://github.com/AppleWin/AppleWin/issues/265#issuecomment-74053479","issue_url":"https://api.github.com/repos/AppleWin/AppleWin/issues/265","id":74053479,"user":{"login":"benoit0123","id":6728352,"avatar_url":"https://avatars.githubusercontent.com/u/6728352?v=3","gravatar_id":"","url":"https://api.github.com/users/benoit0123","html_url":"https://github.com/benoit0123","followers_url":"https://api.github.com/users/benoit0123/followers","following_url":"https://api.github.com/users/benoit0123/following{/other_user}","gists_url":"https://api.github.com/users/benoit0123/gists{/gist_id}","starred_url":"https://api.github.com/users/benoit0123/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/benoit0123/subscriptions","organizations_url":"https://api.github.com/users/benoit0123/orgs","repos_url":"https://api.github.com/users/benoit0123/repos","events_url":"https://api.github.com/users/benoit0123/events{/privacy}","received_events_url":"https://api.github.com/users/benoit0123/received_events","type":"User","site_admin":false},"created_at":"2015-02-12T11:03:46Z","updated_at":"2015-02-12T11:03:46Z","body":"I plan to deliver an exec and a source code dedicated for testing on this issue w/o all the sideways aspect of the utility itself thus we can communiate on this hopefully tiny code (planned delivery for  this week end).\r\nOne asking: Is there a way to confirgure Applewin on its behavior when encountering an invalid opcode in memory? sorry to ask this newbie question but the CHM Applewin file on my \"workstation\" is not operational (WIndows 7 x64) as the content panel (right pannel) is all blank whatever the item is selected on the navigation tree on the left panel.\r\n\r\nRegards,\r\nBenoît\r\n"}}