Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.sys.apple2.programmer > #1158 > unrolled thread

Multitasking Mouse Draw Demo

Started byD Finnigan <dog_cow@macgui.com>
First post2014-02-21 19:47 +0000
Last post2014-02-22 17:36 +0000
Articles 7 — 2 participants

Back to article view | Back to comp.sys.apple2.programmer


Contents

  Multitasking Mouse Draw Demo D Finnigan <dog_cow@macgui.com> - 2014-02-21 19:47 +0000
    Documentation for Multitasking Mouse Draw Demo D Finnigan <dog_cow@macgui.com> - 2014-02-21 19:48 +0000
    Source Code for Multitasking Mouse Draw Demo D Finnigan <dog_cow@macgui.com> - 2014-02-21 19:51 +0000
    Source Code for Multitasking Mouse Draw Demo 2 D Finnigan <dog_cow@macgui.com> - 2014-02-21 19:55 +0000
    Re: Multitasking Mouse Draw Demo D Finnigan <dog_cow@macgui.com> - 2014-02-21 19:56 +0000
    Re: Multitasking Mouse Draw Demo Egan Ford <datajerk@gmail.com> - 2014-02-22 09:47 -0700
      Re: Multitasking Mouse Draw Demo D Finnigan <dog_cow@macgui.com> - 2014-02-22 17:36 +0000

#1158 — Multitasking Mouse Draw Demo

FromD Finnigan <dog_cow@macgui.com>
Date2014-02-21 19:47 +0000
SubjectMultitasking Mouse Draw Demo
Message-ID<dog_cow-1393012033@macgui.com>
I wrote a multitasking demonstration this week and today it is finished
enough to show to people. This is a multi-part post. The documentation and
source code will appear in separate followups to this article.

You can email me for a disk image with Merlin source and the binary.

In brief, the system swaps three processes, or threads as we might call
them, between the 6502. The main process will allow the user to make some
doodles on the low-res graphics screen using the mouse. Two background
processes run autonomously plotting red and blue blocks, respectively, to
the screen.

The VBL interrupt on the AppleMouse card provides the IRQ source.

-- 
]DF$
Apple II Book: http://macgui.com/newa2guide/
Usenet: http://macgui.com/usenet/  <-- get posts by email!
Apple II Web & Blog hosting: http://a2hq.com/

[toc] | [next] | [standalone]


#1159 — Documentation for Multitasking Mouse Draw Demo

FromD Finnigan <dog_cow@macgui.com>
Date2014-02-21 19:48 +0000
SubjectDocumentation for Multitasking Mouse Draw Demo
Message-ID<dog_cow-1393012124@macgui.com>
In reply to#1158
Documentation for Multitasking Mouse Draw Demo
20 Feb 14

For the benefit of all Apple II users, the source code is hereby surrendered
into the public domain. I claim no copyright on the source code.


=== General Overview ===

This multitasking demo uses an AppleMouse card as a source of interrupts to
power a small multitasking system. More properly, it might instead be called
a multithreaded system. It has been tested to run on an Apple II Plus, a $FF
ROM Apple IIc, and the Apple IIe standard and enhanced.

There are three processes, or threads, depending on what you want to call
them. They all share the same address space, and they all have a portion of
the 6502 hardware stack devoted exclusively to them. Periodically, as the
AppleMouse generates VBL interrupts, one process will be suspended, and
another will be selected to run for some time. It is also possible for a
process to voluntarily give up its CPU time by calling a yield subroutine.

Together, these three processes cooperate to draw on the low-resolution
graphics screen. There are two autonomous processes, controlled entirely by
the Apple. One will plot a series of red blocks, the other, blue blocks. The
third process is controlled by input from the operator. It will plot white
blocks in the position of the mouse cursor when the mouse button is held
down. When any key on the keyboard is struck, all white blocks will be
changed to black.


=== System Initialization ===

The program loads at address $8000. Its first task is to prepare the screen
by exiting from 80-columns firmware and then by setting the top of the text
window in preparation for split graphics/text mode.

The next objective is to locate an AppleMouse card. The search is performed
"by the book," scanning all slots from 7 to 1 and looking for the ID bytes
in the AppleMouse firmware. If found, BASEADDR will contain the low-byte and
high-byte of the AppleMouse, $00C4, for example. MSLOT will contain the slot
number times 16, $40, for example. These two locations are used for calls to
the AppleMouse firmware. Finally, the slot number will be printed on the
text screen.

If no AppleMouse card could be located, the message "NO MOUSE" is printed on
the screen, and the program will jump to the DOS warm start location.

After the AppleMouse card is found, program execution jumps to the CREATEALL
routine. This routine is responsible for creating the three processes. It
starts by clearing the 6502 interrupt disable flag, then setting the flag.
All changes to the interrupt flag are done "by the book," that is, by using
the combination PHP SEI to disable, then PLP to enable once more.

The first byte of STKTAB, the stack table, contains the total number of
active processes. This number is incremented when each process is created,
but it is never used thereafter. The rest of STKTAB holds the current stack
pointer for each process while it is suspended.

The first process starts with its stack pointer at $D0, the second at $B2,
and the third, $94. These initial values are stored in STKTAB using the
Y-register as a process ID offset.

Next, the three processes are created. The Y-register holds the process ID,
the A-register holds the low-byte of the starting address, and the
X-register holds the high-byte of the starting address.

The subroutine NEWPROC actually creates each process. NEWPROC first compares
the intended process ID with MAXP, which holds the maximum process ID
allowed. This comparison is, obviously, a mere formality in this case.

Newly created processes look as if they have just been suspended by a VBL
interrupt. Therefore, NEWPROC will push the program address in the proper
stack location, indexed from STKTAB, and then will push the starting
processor status and register values, all 0, following. Finally, the initial
stack pointer for the process, which has been decremented with these stack
additions, is stored back in its place within STKTAB.


=== Enabling interrupts ===

At this point so far, the three processes have been created, but interrupts
remain off. Program execution now jumps to the VBLON subroutine to enable
AppleMouse VBL interrupts which occur 60 times each second.

VBLON first sends the mode byte $01 to the AppleMouse, which enables the
mouse firmware, but not interrupts. SETMOUSE and INITMOUSE perform the mouse
initialization.

The address of the interrupt handler, IRQ, is stored at $3FE.

Once the interrupt handler is prepared, the programs sends the mouse status
byte of $09, which enables VBL interrupts, to the AppleMouse firmware.

The final initialization task is to store $FF in ACT, which stores the
active process ID, and $13 in CTR, which stores the interrupt tick counter.

Now the AppleMouse is pulling the IRQ line to ground on the 6502, but these
requests are being masked out by the interrupt disable flag. PLP allows
these interrupts to get through, and the fun begins!


=== The interrupt handler ===

After interrupts are enabled for the first time, the system initialization
program jumps into an idle loop, but this loop will probably never be
executed again because the three processes start running.

Execution should jump immediately to the IRQ handler because of the
AppleMouse VBL interrupt. The problem of how to bootstrap the initial
process is that we want it to run first and we do not want the registers
from the system initialization stage to get mixed in. After system
initialization, each process looks like it has just been suspended. The IRQ
handler has no way to tell that the processes are in fact, newly created,
and have never run.

The solution was to make some special case code and set ACT, the active
process ID, to $FF. Process scheduling is round-robin, and the process ID is
merely incremented to get the next one. So $FF rolls over to $00, and the
first process is selected to run.

The IRQ handler starts by first pushing all the registers on the stack. Each
process gets an exclusive portion on the stack, and the stack pointer is
adjusted when selecting the next process to run, so there is no need to
perform any special routine to save the registers. The very first time the
interrupt handler runs, however, the registers pushed on the stack don't
belong to any of the three processes. They are the registers from system
initialization. This is not a problem, because as mentioned in the previous
paragraph, the next process ID will roll over to $0, and the initial,
zeroed-out registers, will be pulled from the appropriate location in the
stack.

After saving registers, SERVEMOUSE is called to ensure that the AppleMouse
caused the interrupt. If so, READMOUSE is called to get the current cursor
coordinates and button status. These values are saved in some zero page
locations, MOUXPOS, MOUYPOS, and MOUSTAT, so they are accessible to running
processes.

The next step is to increment the tick counter, CTR. This counter increments
for each mouse interrupt, and it gives each process a fair share of CPU
time. A process can also choose to give up its CPU time by calling the YIELD
subroutine, which will be described later. When the counter reaches $14
(decimal 20), the process is suspended and the next one is selected to run. 
Because the AppleMouse interrupts the CPU 60 times per second, this means
that context switches occur approximately 3 times per second. The system
initializes CTR to $13, so it will be incremented to $14, thus process 0
will be the very first process to run.

If CTR did not reach $14 after being incremented, the interrupt handler is
done, and it restores the registers. The stack pointer was not changed, so
RTI leads back to the interrupted instruction of the same process.

However, if CTR did reach $14, then the CPU time for the current process is
expired, and it is time to select the next process to run. CTR is reset to
0, then ACT is loaded to the Y-register to examine its contents. If it
contains $FF, then a special branch is made to bootstrap the initial
process, as has already been explained. If not, the stack pointer is then
stored in the STKTAB, indexed on Y, which contains the process ID of the
process which was just interrupted.

The Y-register is incremented to point to the next process ID. If it equals
MAXP, which is 3, it rolls over to 0 again, since there are only three
process IDs. ACT is updated with the new process ID from the Y-register.

The context switch is simple, consisting of just 3 lines that load the stack
pointer for the next process from the STKTAB. The speaker is clicked to give
audible feedback.

With the stack pointer adjusted, the register restore operations at IRQDONE
pull the correct contents from the stack, and RTI sends the CPU operation
back to where the next process had previously been suspended.


=== Giving up CPU time with YIELD ===

So far, the system described has been operating in a preemptive fashion:
each process is allowed to run for a fraction of a second, then it is
forcibly suspended so that the next process can run.

It is also possible for a process to volunteer for preemption, that is, give
up its remaining CPU time so that the next process may run.

A subroutine called YIELD, which may be classified as a system call,
performs this function. A program will perform a JSR to YIELD to give up its
CPU time.

YIELD needs to account for the difference between a JSR and a CPU interrupt.
In the former, the processor status is not pushed on the stack, and the
return address is pushed, but it is one less than the effective address. An
interrupt, on the other hand, does push the processor status, and the return
address is the effective address for resuming the interrupted program.

YIELD begins by pushing the processor status to the stack, like an interrupt
request does. It then disables interrupts, and proceeds to push the
remaining registers to the stack. The next step is to fix the return address
for the RTI. It needs to be incremented. The stack pointer is transferred to
the X-register, which is then incremented by 5 to point to the low-byte of
the return address. It is incremented, and if necessary, so is the
high-byte. Program execution jumps to RESETCTR to reset the tick counter to
0, then the next program is selected to run, as usual.


=== The processes ===

As already mentioned, there are three processes. Two are completely
controlled by the CPU, and the third is controlled by the user. Thus the two
may be thought of as background daemons with the latter being the foreground
process.

Process 0 performs the setup work for a low-resolution drawing program using
the mouse. It disables interrupts, then it sets the X and Y clamps to be
40x40. It then calls HOMEMOUSE to ensure that the cursor is within these
boundaries. Interrupts are briefly enabled while the MIX and GR
soft-switches are referenced to change the screen to low-resolution graphics
with text.

Most all of the Monitor subroutines are not reentrant because they store
some values in zero-page locations. This means that only one process can
call a Monitor routine at a time, and in order to enforce this policy, the
process must disable interrupts for each Monitor call with PHP SEI, then
enable with PLP afterward.

After the screen is switched to graphics mode, CLRTOP is called to clear the
top 40 rows to black, leaving just the text screen visible, which should
still show the AppleMouse slot number.

The main event loop of process 0 follows. First it will check the keyboard
for any key press. If there is one, the program will jump to :CLRIT to clear
all white blocks. If no key was pressed, then the mouse button status is
examined to see if the button is pressed. If no button was pressed, then the
loop goes back to examine the keyboard again.

If the mouse button is down, a white block is plotted at the cursor
coordinates which are stored in MOUXPOS and MOUYPOS. These are zero-page
locations which were updated by the IRQ handler.

If a key was pressed, the program will loop over the entire 40x40 screen in
search of white blocks with the SCRN Monitor subroutine. If any are found,
they are plotted over with black using the PLOT subroutine. Afterward, the
message CLEAR is printed on the text screen. Interrupts are only disabled
for the SCRN and PLOT subroutine calls.

Processes 1 and 2 operate alike with only one meaningful difference in
respect to multitasking. Both will plot a sequence of blocks on the screen,
starting from the top or bottom row and working toward the opposite side. To
distinguish the two, process 1 only plots red blocks, and process 2 only
plots blue blocks.

The meaningful difference is that process 1 only calls YIELD after it has
plotted an entire row of blocks, whereas process 2 calls YIELD after each
plot.

Due to the use of YIELD in these two processes, the majority of CPU time is
devoted to process 0, and thus the user operating his drawing program does
not perceive any lag or delay.


=== Conclusion and improvements ===

This program demonstrates that it is possible to use interrupt-enabled,
multitasking programs in a meaningful way on the 8-bit Apple II. Defensive
programming practice, exercised by calling YIELD, means that process 0 is
given highest priority. Therefore, the user experience does not suffer when
there are two background processes also using CPU time.

Some improvements of this system would be to allow variable process
priorities by making a CTRTAB, similar to the STKTAB. This would also be
indexed on the process ID in the Y-register, and it would contain a maximum
tick count to be reached before the context switch occurs. This would be in
substitute of the current system, which gives all processes up to $14 ticks
on CTR before a context switch is forced.

Another improvement would be to take advantage of the bank-switching scheme
of the Apple IIe with a RamWorks-style AUX memory card. Each process would
be granted its own stack, which would eliminate the need to subdivide the
single 6502 stack as the program currently does.

[toc] | [prev] | [next] | [standalone]


#1160 — Source Code for Multitasking Mouse Draw Demo

FromD Finnigan <dog_cow@macgui.com>
Date2014-02-21 19:51 +0000
SubjectSource Code for Multitasking Mouse Draw Demo
Message-ID<dog_cow-multitasking-source-20feb14@macgui.com>
In reply to#1158
For the benefit of all Apple II users, the source code is hereby surrendered into the public domain. I claim no copyright on the source code.

Assembler used is Merlin.

                1    SPKR     EQU   $C030      
                2    PRBYTE   EQU   $FDDA      
                3    DOSWARM  EQU   $3D0       
                4    IRQLOC   EQU   $3FE       
                5    COUT     EQU   $FDF0      
                6    VBLINT   EQU   $09        
                7    MOUIDLOC1 EQU  $05        
                8    MOUIDLOC2 EQU  $07        
                9    MOUIDLOC3 EQU  $0B        
                10   MOUIDLOC4 EQU  $0C        
                11   MOUIDLOC5 EQU  $FB        
                12   MOUID1   EQU   $38        
                13   MOUID2   EQU   $18        
                14   MOUID3   EQU   $01        
                15   MOUID4   EQU   $20        
                16   MOUID5   EQU   $D6        
                17   BASEADDR EQU   $06        ; 2-BYTES FOR INDEXED ADDRESSING 
                18   MSLOT    EQU   $08        
                19   CTR      EQU   $09        ; IRQ COUNTER 
                20   ACT      EQU   $19        ; ACTIVE PROCESS 
                21   MAXP     EQU   $03        
                22   * 
8000: A9 00     23   FINDMOUSE LDA  #$00       
8002: 85 06     24            STA   BASEADDR   
8004: A9 C8     25            LDA   #$C8       
8006: 85 07     26            STA   BASEADDR+1 
8008: A2 08     27            LDX   #$08       
800A: CA        28   :LOOP1   DEX              
800B: F0 3D     29            BEQ   :NOMOUSE   
800D: C6 07     30            DEC   BASEADDR+1 
800F: A0 05     31            LDY   #MOUIDLOC1 
8011: B1 06     32            LDA   (BASEADDR),Y 
8013: C9 38     33            CMP   #MOUID1    
8015: D0 F3     34            BNE   :LOOP1     
8017: A0 07     35            LDY   #MOUIDLOC2 
8019: B1 06     36            LDA   (BASEADDR),Y 
801B: C9 18     37            CMP   #MOUID2    
801D: D0 EB     38            BNE   :LOOP1     
801F: A0 0B     39            LDY   #MOUIDLOC3 
8021: B1 06     40            LDA   (BASEADDR),Y 
8023: C9 01     41            CMP   #MOUID3    
8025: D0 E3     42            BNE   :LOOP1     
8027: A0 0C     43            LDY   #MOUIDLOC4 
8029: B1 06     44            LDA   (BASEADDR),Y 
802B: C9 20     45            CMP   #MOUID4    
802D: D0 DB     46            BNE   :LOOP1     
802F: A0 FB     47            LDY   #MOUIDLOC5 
8031: B1 06     48            LDA   (BASEADDR),Y 
8033: C9 D6     49            CMP   #MOUID5    
8035: D0 D3     50            BNE   :LOOP1     
8037: 8A        51            TXA              
8038: 0A        52            ASL              
8039: 0A        53            ASL              
803A: 0A        54            ASL              
803B: 0A        55            ASL              
803C: 85 08     56            STA   MSLOT      
803E: 8A        57            TXA              
803F: 20 DA FD  58            JSR   PRBYTE     
8042: A9 8D     59            LDA   #$8D       
 
 
                              ===== Page 2 ===== 
 
8044: 20 F0 FD  60            JSR   COUT       
8047: 4C 7A 80  61            JMP   CREATEALL  
804A: A9 CE     62   :NOMOUSE LDA   #$CE       
804C: 20 F0 FD  63            JSR   COUT       
804F: A9 CF     64            LDA   #$CF       
8051: 20 F0 FD  65            JSR   COUT       
8054: A9 A0     66            LDA   #$A0       
8056: 20 F0 FD  67            JSR   COUT       
8059: A9 CD     68            LDA   #$CD       
805B: 20 F0 FD  69            JSR   COUT       
805E: A9 CF     70            LDA   #$CF       
8060: 20 F0 FD  71            JSR   COUT       
8063: A9 D5     72            LDA   #$D5       
8065: 20 F0 FD  73            JSR   COUT       
8068: A9 D3     74            LDA   #$D3       
806A: 20 F0 FD  75            JSR   COUT       
806D: A9 C5     76            LDA   #$C5       
806F: 20 F0 FD  77            JSR   COUT       
8072: A9 8D     78            LDA   #$8D       
8074: 20 F0 FD  79            JSR   COUT       
8077: 4C D0 03  80            JMP   DOSWARM    
                81   * 
807A: 58        82   CREATEALL CLI             
807B: 08        83            PHP              
807C: 78        84            SEI              
807D: A9 00     85            LDA   #$00       
807F: 8D 74 81  86            STA   STKTAB     
8082: A8        87            TAY              
8083: A9 E0     88            LDA   #$E0       ; INITIAL SP 
8085: 99 75 81  89            STA   STKTAB+1,Y 
8088: A9 C2     90            LDA   #$C2       
808A: C8        91            INY              
808B: 99 75 81  92            STA   STKTAB+1,Y 
808E: A9 A4     93            LDA   #$A4       
8090: C8        94            INY              
8091: 99 75 81  95            STA   STKTAB+1,Y 
8094: A0 00     96            LDY   #$00       
8096: A9 78     97            LDA   #<PROC1    
8098: A2 81     98            LDX   #>PROC1    
809A: 20 BE 80  99            JSR   NEWPROC    
809D: A0 01     100           LDY   #$01       
809F: A9 8B     101           LDA   #<PROC2    
80A1: A2 81     102           LDX   #>PROC2    
80A3: 20 BE 80  103           JSR   NEWPROC    
80A6: A0 02     104           LDY   #$02       
80A8: A9 9D     105           LDA   #<PROC3    
80AA: A2 81     106           LDX   #>PROC3    
80AC: 20 BE 80  107           JSR   NEWPROC    
80AF: 20 EC 80  108           JSR   VBLON      
80B2: A9 FF     109           LDA   #$FF       
80B4: 85 19     110           STA   ACT        
80B6: A9 13     111           LDA   #$13       
80B8: 85 09     112           STA   CTR        
80BA: 28        113           PLP              ; ENABLE IRQ 
80BB: 4C BB 80  114  :IDLE    JMP   :IDLE      
                115  * 
80BE: C0 03     116  NEWPROC  CPY   #MAXP      
 
 
                              ===== Page 3 ===== 
 
80C0: F0 29     117           BEQ   :DONE      
80C2: EE 74 81  118           INC   STKTAB     
80C5: 48        119           PHA              
80C6: 8A        120           TXA              
80C7: 48        121           PHA              
80C8: BE 75 81  122           LDX   STKTAB+1,Y 
80CB: 68        123           PLA              ; HI-BYTE OF START ADDR 
80CC: 9D 00 01  124           STA   $0100,X    
80CF: CA        125           DEX              
80D0: 68        126           PLA              
80D1: 9D 00 01  127           STA   $0100,X    
80D4: A9 00     128           LDA   #$00       ; INITIAL PROCESSOR STATUS 
80D6: CA        129           DEX              
80D7: 9D 00 01  130           STA   $0100,X    
80DA: CA        131           DEX              
80DB: 9D 00 01  132           STA   $0100,X    ; INITIAL REGISTERS 
80DE: CA        133           DEX              
80DF: 9D 00 01  134           STA   $0100,X    
80E2: CA        135           DEX              
80E3: 9D 00 01  136           STA   $0100,X    
80E6: CA        137           DEX              
80E7: 8A        138           TXA              
80E8: 99 75 81  139           STA   STKTAB+1,Y 
80EB: 60        140  :DONE    RTS              
                141  * 
80EC: A9 01     142  VBLON    LDA   #$01       
80EE: 20 10 81  143           JSR   SETMOUSE   
80F1: 20 04 81  144           JSR   INITMOUSE  
80F4: A9 3B     145           LDA   #<IRQ      
80F6: 8D FE 03  146           STA   IRQLOC     
80F9: A9 81     147           LDA   #>IRQ      
80FB: 8D FF 03  148           STA   IRQLOC+1   
80FE: A9 09     149           LDA   #VBLINT    
8100: 20 10 81  150           JSR   SETMOUSE   ; TURN ON MOUSE VBL INTERRUPTS 
8103: 60        151           RTS              
                152  * 
8104: A0 19     153  INITMOUSE LDY  #$19       
8106: A9 00     154           LDA   #$00       
8108: 85 06     155           STA   BASEADDR   
810A: B1 06     156           LDA   (BASEADDR),Y 
810C: 85 06     157           STA   BASEADDR   
810E: D0 24     158           BNE   MOUSEJMP   
                159  * 
8110: A0 12     160  SETMOUSE LDY   #$12       
8112: AA        161           TAX              
8113: A9 00     162           LDA   #$00       
8115: 85 06     163           STA   BASEADDR   
8117: B1 06     164           LDA   (BASEADDR),Y 
8119: 85 06     165           STA   BASEADDR   
811B: 8A        166           TXA              
811C: 10 16     167           BPL   MOUSEJMP   
                168  * 
811E: A0 13     169  SERVEMOUSE LDY #$13       
8120: A9 00     170           LDA   #$00       
8122: 85 06     171           STA   BASEADDR   
8124: B1 06     172           LDA   (BASEADDR),Y 
8126: 85 06     173           STA   BASEADDR   
 
 
                              ===== Page 4 ===== 
 
8128: D0 0A     174           BNE   MOUSEJMP   
                175  * 
812A: A0 14     176  READMOUSE LDY  #$14       
812C: A9 00     177           LDA   #$00       
812E: 85 06     178           STA   BASEADDR   
8130: B1 06     179           LDA   (BASEADDR),Y 
8132: 85 06     180           STA   BASEADDR   
                181  * 
8134: A6 07     182  MOUSEJMP LDX   BASEADDR+1 
8136: A4 08     183           LDY   MSLOT      
8138: 6C 06 00  184           JMP   (BASEADDR) 
                185  * 
813B: 48        186  IRQ      PHA              
813C: 8A        187           TXA              
813D: 48        188           PHA              
813E: 98        189           TYA              
813F: 48        190           PHA              
8140: 20 1E 81  191           JSR   SERVEMOUSE 
8143: B0 29     192           BCS   :DONE      
8145: A6 09     193           LDX   CTR        
8147: E8        194           INX              
8148: E0 14     195           CPX   #$14       
814A: 86 09     196           STX   CTR        
814C: D0 20     197           BNE   :DONE      
814E: A9 00     198           LDA   #$00       
8150: 85 09     199           STA   CTR        
8152: A4 19     200           LDY   ACT        
8154: 30 05     201           BMI   :NEXT      ; BOOTSTRAP INITIAL PROCESS 
8156: BA        202           TSX              
8157: 8A        203           TXA              
8158: 99 75 81  204           STA   STKTAB+1,Y 
815B: C8        205  :NEXT    INY              
815C: C0 03     206           CPY   #MAXP      
815E: D0 02     207           BNE   :CTXSW     
8160: A0 00     208           LDY   #$00       ; LOOP BACK TO PROCESS 0 
8162: BE 75 81  209  :CTXSW   LDX   STKTAB+1,Y 
8165: 9A        210           TXS              
8166: 84 19     211           STY   ACT        
8168: AD 30 C0  212           LDA   SPKR       
816B: AD 30 C0  213           LDA   SPKR       
816E: 68        214  :DONE    PLA              
816F: A8        215           TAY              
8170: 68        216           PLA              
8171: AA        217           TAX              
8172: 68        218           PLA              
8173: 40        219           RTI              
                220  * 
8174: 00 00 00  221  STKTAB   DS    MAXP+1     
8177: 00 
                222  * 
8178: A2 01     223  PROC1    LDX   #$01       
817A: E0 01     224  :LOOP    CPX   #$01       
817C: D0 0A     225           BNE   :QUIT      
817E: A9 AE     226           LDA   #$AE       
8180: 08        227           PHP              
8181: 78        228           SEI              
8182: 20 F0 FD  229           JSR   COUT       
 
 
                              ===== Page 5 ===== 
 
8185: 28        230           PLP              
8186: D0 F2     231           BNE   :LOOP      
8188: 4C 88 81  232  :QUIT    JMP   :QUIT      
                233  * 
818B: A0 00     234  PROC2    LDY   #$00       
818D: C8        235  :LOOP    INY              
818E: C0 55     236           CPY   #$55       
8190: D0 FB     237           BNE   :LOOP      
8192: A9 C0     238           LDA   #$C0       
8194: 08        239           PHP              
8195: 78        240           SEI              
8196: 20 F0 FD  241           JSR   COUT       
8199: 28        242           PLP              
819A: 4C 8B 81  243           JMP   PROC2      
                244  * 
819D: 4C A2 81  245  PROC3    JMP   :START     
81A0: 00 00     246  ]SUM     DW    $0000      
81A2: 18        247  :START   CLC              
81A3: AD A0 81  248           LDA   ]SUM       
81A6: 69 01     249           ADC   #$01       
81A8: 8D A0 81  250           STA   ]SUM       
81AB: 90 08     251           BCC   :NEXT      
81AD: AD A1 81  252           LDA   ]SUM+1     
81B0: 69 00     253           ADC   #$00       
81B2: 8D A1 81  254           STA   ]SUM+1     
81B5: 4C A2 81  255  :NEXT    JMP   :START     
--End assembly, 440 bytes, Errors: 0 
Symbol table - alphabetical order: 
   ACT     =$19        BASEADDR=$06        COUT    =$FDF0      CREATEALL=$807A 
   CTR     =$09        DOSWARM =$03D0   ?  FINDMOUSE=$8000      INITMOUSE=$8104 
   IRQ     =$813B      IRQLOC  =$03FE      MAXP    =$03        MOUID1  =$38 
   MOUID2  =$18        MOUID3  =$01        MOUID4  =$20        MOUID5  =$D6 
   MOUIDLOC1=$05        MOUIDLOC2=$07        MOUIDLOC3=$0B        MOUIDLOC4=$0C 
   MOUIDLOC5=$FB        MOUSEJMP=$8134      MSLOT   =$08        NEWPROC =$80BE 
   PRBYTE  =$FDDA      PROC1   =$8178      PROC2   =$818B      PROC3   =$819D 
?  READMOUSE=$812A      SERVEMOUSE=$811E      SETMOUSE=$8110      SPKR    =$C030 
   STKTAB  =$8174      VBLINT  =$09        VBLON   =$80EC   V  ]SUM    =$81A0 
Symbol table - numerical order: 
   MOUID3  =$01        MAXP    =$03        MOUIDLOC1=$05        BASEADDR=$06 
   MOUIDLOC2=$07        MSLOT   =$08        VBLINT  =$09        CTR     =$09 
   MOUIDLOC3=$0B        MOUIDLOC4=$0C        MOUID2  =$18        ACT     =$19 
   MOUID4  =$20        MOUID1  =$38        MOUID5  =$D6        MOUIDLOC5=$FB 
   DOSWARM =$03D0      IRQLOC  =$03FE   ?  FINDMOUSE=$8000      CREATEALL=$807A 
   NEWPROC =$80BE      VBLON   =$80EC      INITMOUSE=$8104      SETMOUSE=$8110 
   SERVEMOUSE=$811E   ?  READMOUSE=$812A      MOUSEJMP=$8134      IRQ     =$813B 
   STKTAB  =$8174      PROC1   =$8178      PROC2   =$818B      PROC3   =$819D 
V  ]SUM    =$81A0      SPKR    =$C030      PRBYTE  =$FDDA      COUT    =$FDF0 

[toc] | [prev] | [next] | [standalone]


#1161 — Source Code for Multitasking Mouse Draw Demo 2

FromD Finnigan <dog_cow@macgui.com>
Date2014-02-21 19:55 +0000
SubjectSource Code for Multitasking Mouse Draw Demo 2
Message-ID<dog_cow-multitasking-source2-20feb14@macgui.com>
In reply to#1158
For the benefit of all Apple II users, the source code is hereby surrendered into the public domain. I claim no copyright on the source code.

Assembler used is Merlin.

                1    KBD      EQU   $C000      
                2    KBDSTRB  EQU   $C010      
                3    SPKR     EQU   $C030      
                4    PRBYTE   EQU   $FDDA      
                5    PRNTAX   EQU   $F941      
                6    DOSWARM  EQU   $3D0       
                7    IRQLOC   EQU   $3FE       
                8    COUT     EQU   $FDED      
                9    VBLINT   EQU   $09        
                10   MOUIDLOC1 EQU  $05        
                11   MOUIDLOC2 EQU  $07        
                12   MOUIDLOC3 EQU  $0B        
                13   MOUIDLOC4 EQU  $0C        
                14   MOUIDLOC5 EQU  $FB        
                15   MOUID1   EQU   $38        
                16   MOUID2   EQU   $18        
                17   MOUID3   EQU   $01        
                18   MOUID4   EQU   $20        
                19   MOUID5   EQU   $D6        
                20   BASEADDR EQU   $06        ; 2-BYTES FOR INDEXED ADDRESSING 
                21   MSLOT    EQU   $08        
                22   CTR      EQU   $09        ; IRQ COUNTER 
                23   ACT      EQU   $19        ; ACTIVE PROCESS 
                24   MAXP     EQU   $03        
                25   MOUXPOS  EQU   $1A        ; 2 BYTES FOR MOUSE X-POSITION 
                26   MOUYPOS  EQU   $1C        
                27   MOUSTAT  EQU   $1E        
                28   CLRTOP   EQU   $F836      
                29   SETCOL   EQU   $F864      
                30   PLOT     EQU   $F800      
                31   SCRN     EQU   $F871      
                32   GR       EQU   $C050      
                33   MIX      EQU   $C053      
                34   RED      EQU   $01        
                35   BLUE     EQU   $02        
                36   BLACK    EQU   $00        
                37   WHITE    EQU   $0F        
                38   * 
8000: A9 9B     39            LDA   #$9B       
8002: 20 ED FD  40            JSR   COUT       
8005: A9 91     41            LDA   #$91       ; KILL 80-COLS FIRMWARE 
8007: 20 ED FD  42            JSR   COUT       
800A: A9 14     43            LDA   #$14       
800C: 85 22     44            STA   $22        ; TOP OF TEXT WINDOW 
800E: 85 25     45            STA   $25        
                46   * 
8010: A9 00     47   FINDMOUSE LDA  #$00       
8012: 85 06     48            STA   BASEADDR   
8014: A9 C8     49            LDA   #$C8       
8016: 85 07     50            STA   BASEADDR+1 
8018: A2 08     51            LDX   #$08       
801A: CA        52   :LOOP1   DEX              
801B: F0 42     53            BEQ   :NOMOUSE   
801D: C6 07     54            DEC   BASEADDR+1 
801F: A0 05     55            LDY   #MOUIDLOC1 
8021: B1 06     56            LDA   (BASEADDR),Y 
8023: C9 38     57            CMP   #MOUID1    
8025: D0 F3     58            BNE   :LOOP1     
8027: A0 07     59            LDY   #MOUIDLOC2 
 
 
                              ===== Page 2 ===== 
 
8029: B1 06     60            LDA   (BASEADDR),Y 
802B: C9 18     61            CMP   #MOUID2    
802D: D0 EB     62            BNE   :LOOP1     
802F: A0 0B     63            LDY   #MOUIDLOC3 
8031: B1 06     64            LDA   (BASEADDR),Y 
8033: C9 01     65            CMP   #MOUID3    
8035: D0 E3     66            BNE   :LOOP1     
8037: A0 0C     67            LDY   #MOUIDLOC4 
8039: B1 06     68            LDA   (BASEADDR),Y 
803B: C9 20     69            CMP   #MOUID4    
803D: D0 DB     70            BNE   :LOOP1     
803F: A0 FB     71            LDY   #MOUIDLOC5 
8041: B1 06     72            LDA   (BASEADDR),Y 
8043: C9 D6     73            CMP   #MOUID5    
8045: D0 D3     74            BNE   :LOOP1     
8047: 8A        75            TXA              
8048: 0A        76            ASL              
8049: 0A        77            ASL              
804A: 0A        78            ASL              
804B: 0A        79            ASL              
804C: 85 08     80            STA   MSLOT      
804E: A9 8D     81            LDA   #$8D       
8050: 20 ED FD  82            JSR   COUT       
8053: 8A        83            TXA              
8054: 20 DA FD  84            JSR   PRBYTE     
8057: A9 8D     85            LDA   #$8D       
8059: 20 ED FD  86            JSR   COUT       
805C: 4C 7C 80  87            JMP   CREATEALL  
805F: A0 00     88   :NOMOUSE LDY   #$00       
8061: B9 71 80  89   :LOOP    LDA   NOMOUMSG,Y 
8064: F0 08     90            BEQ   :DONE      
8066: 09 80     91            ORA   #$80       
8068: 20 ED FD  92            JSR   COUT       
806B: C8        93            INY              
806C: D0 F3     94            BNE   :LOOP      
806E: 4C D0 03  95   :DONE    JMP   DOSWARM    
8071: 8D CE CF  96   NOMOUMSG HEX   8DCECFA0CDCFD5D3C58D00 
8074: A0 CD CF D5 D3 C5 8D 00 
                97   * 
807C: 58        98   CREATEALL CLI             
807D: 08        99            PHP              
807E: 78        100           SEI              
807F: A9 00     101           LDA   #$00       
8081: 8D CB 81  102           STA   STKTAB     
8084: A8        103           TAY              
8085: A9 D0     104           LDA   #$D0       ; INITIAL SP 
8087: 99 CC 81  105           STA   STKTAB+1,Y 
808A: A9 B2     106           LDA   #$B2       
808C: C8        107           INY              
808D: 99 CC 81  108           STA   STKTAB+1,Y 
8090: A9 94     109           LDA   #$94       
8092: C8        110           INY              
8093: 99 CC 81  111           STA   STKTAB+1,Y 
8096: A0 00     112           LDY   #$00       
8098: A9 14     113           LDA   #<PROC0    
809A: A2 82     114           LDX   #>PROC0    
809C: 20 C0 80  115           JSR   NEWPROC    
 
 
                              ===== Page 3 ===== 
 
809F: A0 01     116           LDY   #$01       
80A1: A9 EE     117           LDA   #<PROC1    
80A3: A2 81     118           LDX   #>PROC1    
80A5: 20 C0 80  119           JSR   NEWPROC    
80A8: A0 02     120           LDY   #$02       
80AA: A9 CF     121           LDA   #<PROC2    
80AC: A2 81     122           LDX   #>PROC2    
80AE: 20 C0 80  123           JSR   NEWPROC    
80B1: 20 EE 80  124           JSR   VBLON      
80B4: A9 FF     125           LDA   #$FF       
80B6: 85 19     126           STA   ACT        
80B8: A9 13     127           LDA   #$13       
80BA: 85 09     128           STA   CTR        
80BC: 28        129           PLP              ; ENABLE IRQ 
80BD: 4C BD 80  130  :IDLE    JMP   :IDLE      
                131  * 
80C0: C0 03     132  NEWPROC  CPY   #MAXP      
80C2: F0 29     133           BEQ   :DONE      
80C4: EE CB 81  134           INC   STKTAB     
80C7: 48        135           PHA              
80C8: 8A        136           TXA              
80C9: 48        137           PHA              
80CA: BE CC 81  138           LDX   STKTAB+1,Y 
80CD: 68        139           PLA              ; HI-BYTE OF START ADDR 
80CE: 9D 00 01  140           STA   $0100,X    
80D1: CA        141           DEX              
80D2: 68        142           PLA              
80D3: 9D 00 01  143           STA   $0100,X    
80D6: A9 00     144           LDA   #$00       ; INITIAL PROCESSOR STATUS 
80D8: CA        145           DEX              
80D9: 9D 00 01  146           STA   $0100,X    
80DC: CA        147           DEX              
80DD: 9D 00 01  148           STA   $0100,X    ; INITIAL REGISTERS 
80E0: CA        149           DEX              
80E1: 9D 00 01  150           STA   $0100,X    
80E4: CA        151           DEX              
80E5: 9D 00 01  152           STA   $0100,X    
80E8: CA        153           DEX              
80E9: 8A        154           TXA              
80EA: 99 CC 81  155           STA   STKTAB+1,Y 
80ED: 60        156  :DONE    RTS              
                157  * 
80EE: A9 01     158  VBLON    LDA   #$01       
80F0: 20 12 81  159           JSR   SETMOUSE   
80F3: 20 06 81  160           JSR   INITMOUSE  
80F6: A9 6F     161           LDA   #<IRQ      
80F8: 8D FE 03  162           STA   IRQLOC     
80FB: A9 81     163           LDA   #>IRQ      
80FD: 8D FF 03  164           STA   IRQLOC+1   
8100: A9 09     165           LDA   #VBLINT    
8102: 20 12 81  166           JSR   SETMOUSE   ; TURN ON MOUSE VBL INTERRUPTS 
8105: 60        167           RTS              
                168  * 
8106: A0 19     169  INITMOUSE LDY  #$19       
8108: A9 00     170           LDA   #$00       
810A: 85 06     171           STA   BASEADDR   
810C: B1 06     172           LDA   (BASEADDR),Y 
 
 
                              ===== Page 4 ===== 
 
810E: 85 06     173           STA   BASEADDR   
8110: D0 3E     174           BNE   MOUSEJMP   
                175  * 
8112: A0 12     176  SETMOUSE LDY   #$12       
8114: AA        177           TAX              
8115: A9 00     178           LDA   #$00       
8117: 85 06     179           STA   BASEADDR   
8119: B1 06     180           LDA   (BASEADDR),Y 
811B: 85 06     181           STA   BASEADDR   
811D: 8A        182           TXA              
811E: 10 30     183           BPL   MOUSEJMP   
                184  * 
8120: A0 13     185  SERVEMOUSE LDY #$13       
8122: A9 00     186           LDA   #$00       
8124: 85 06     187           STA   BASEADDR   
8126: B1 06     188           LDA   (BASEADDR),Y 
8128: 85 06     189           STA   BASEADDR   
812A: D0 24     190           BNE   MOUSEJMP   
                191  * 
812C: AA        192  CLAMPMOUSE TAX            
812D: A0 17     193           LDY   #$17       
812F: A9 00     194           LDA   #$00       
8131: 85 06     195           STA   BASEADDR   
8133: B1 06     196           LDA   (BASEADDR),Y 
8135: 85 06     197           STA   BASEADDR   
8137: 8A        198           TXA              
8138: 10 16     199           BPL   MOUSEJMP   
                200  * 
813A: A0 18     201  HOMEMOUSE LDY  #$18       
813C: A9 00     202           LDA   #$00       
813E: 85 06     203           STA   BASEADDR   
8140: B1 06     204           LDA   (BASEADDR),Y 
8142: 85 06     205           STA   BASEADDR   
8144: D0 0A     206           BNE   MOUSEJMP   
                207  * 
8146: A0 14     208  READMOUSE LDY  #$14       
8148: A9 00     209           LDA   #$00       
814A: 85 06     210           STA   BASEADDR   
814C: B1 06     211           LDA   (BASEADDR),Y 
814E: 85 06     212           STA   BASEADDR   
                213  * 
8150: A6 07     214  MOUSEJMP LDX   BASEADDR+1 
8152: A4 08     215           LDY   MSLOT      
8154: 6C 06 00  216           JMP   (BASEADDR) 
                217  * 
8157: 08        218  YIELD    PHP              
8158: 78        219           SEI              
8159: 48        220           PHA              
815A: 8A        221           TXA              
815B: 48        222           PHA              
815C: 98        223           TYA              
815D: 48        224           PHA              
815E: BA        225           TSX              ; FIX JSR RETURN FOR RTI 
815F: 8A        226           TXA              
8160: 18        227           CLC              
8161: 69 05     228           ADC   #$05       
8163: AA        229           TAX              
 
 
                              ===== Page 5 ===== 
 
8164: FE 00 01  230           INC   $0100,X    
8167: D0 3C     231           BNE   RESETCTR   
8169: E8        232           INX              
816A: FE 00 01  233           INC   $0100,X    
816D: D0 36     234           BNE   RESETCTR   
                235  
                236  * 
816F: A5 45     237  IRQ      LDA   $45        
8171: 48        238           PHA              
8172: 8A        239           TXA              
8173: 48        240           PHA              
8174: 98        241           TYA              
8175: 48        242           PHA              
8176: 20 20 81  243           JSR   SERVEMOUSE 
8179: B0 4A     244           BCS   IRQDONE    
817B: 20 46 81  245           JSR   READMOUSE  
817E: A5 07     246           LDA   BASEADDR+1 
8180: 29 0F     247           AND   #$F        
8182: AA        248           TAX              
8183: BD 78 04  249           LDA   $478,X     
8186: 85 1A     250           STA   MOUXPOS    
8188: BD F8 04  251           LDA   $4F8,X     
818B: 85 1C     252           STA   MOUYPOS    
818D: BD 78 05  253           LDA   $578,X     
8190: 85 1B     254           STA   MOUXPOS+1  
8192: BD F8 05  255           LDA   $5F8,X     
8195: 85 1D     256           STA   MOUYPOS+1  
8197: BD 78 07  257           LDA   $778,X     
819A: 85 1E     258           STA   MOUSTAT    
819C: A6 09     259           LDX   CTR        
819E: E8        260           INX              
819F: E0 14     261           CPX   #$14       
81A1: 86 09     262           STX   CTR        
81A3: D0 20     263           BNE   IRQDONE    
81A5: A9 00     264  RESETCTR LDA   #$00       
81A7: 85 09     265           STA   CTR        
81A9: A4 19     266           LDY   ACT        
81AB: 30 05     267           BMI   :NEXT      ; BOOTSTRAP INITIAL PROCESS 
81AD: BA        268           TSX              
81AE: 8A        269           TXA              
81AF: 99 CC 81  270           STA   STKTAB+1,Y 
81B2: C8        271  :NEXT    INY              
81B3: C0 03     272           CPY   #MAXP      
81B5: D0 02     273           BNE   :CTXSW     
81B7: A0 00     274           LDY   #$00       ; LOOP BACK TO PROCESS 0 
81B9: BE CC 81  275  :CTXSW   LDX   STKTAB+1,Y 
81BC: 9A        276           TXS              
81BD: 84 19     277           STY   ACT        
81BF: AD 30 C0  278           LDA   SPKR       
81C2: AD 30 C0  279           LDA   SPKR       
81C5: 68        280  IRQDONE  PLA              
81C6: A8        281           TAY              
81C7: 68        282           PLA              
81C8: AA        283           TAX              
81C9: 68        284           PLA              
81CA: 40        285           RTI              
                286  * 
 
 
                              ===== Page 6 ===== 
 
81CB: 00 00 00  287  STKTAB   DS    MAXP+1     
81CE: 00 
                288  * 
81CF: A2 27     289  PROC2    LDX   #$27       
81D1: A0 27     290           LDY   #$27       
81D3: 08        291  :L1      PHP              
81D4: 78        292           SEI              
81D5: A9 02     293           LDA   #BLUE      
81D7: 20 64 F8  294           JSR   SETCOL     
81DA: 8A        295           TXA              
81DB: 20 00 F8  296           JSR   PLOT       
81DE: 28        297           PLP              
81DF: 20 57 81  298           JSR   YIELD      
81E2: 88        299           DEY              
81E3: 10 EE     300           BPL   :L1        
81E5: A0 27     301           LDY   #$27       
81E7: CA        302           DEX              
81E8: 10 E9     303           BPL   :L1        
81EA: A2 27     304           LDX   #$27       
81EC: D0 E5     305           BNE   :L1        
                306  * 
81EE: A0 00     307  PROC1    LDY   #$00       
81F0: A2 00     308           LDX   #$00       
81F2: 08        309  :L1      PHP              
81F3: 78        310           SEI              
81F4: A9 01     311           LDA   #RED       
81F6: 20 64 F8  312           JSR   SETCOL     
81F9: 8A        313           TXA              
81FA: 20 00 F8  314           JSR   PLOT       
81FD: 28        315           PLP              
81FE: C8        316           INY              
81FF: C0 28     317           CPY   #$28       
8201: D0 EF     318           BNE   :L1        
8203: A0 00     319           LDY   #$00       
8205: 20 57 81  320           JSR   YIELD      
8208: E8        321           INX              
8209: E0 28     322           CPX   #$28       
820B: D0 E5     323           BNE   :L1        
820D: A2 00     324           LDX   #$00       
820F: F0 E1     325           BEQ   :L1        
8211: 4C EE 81  326           JMP   PROC1      
                327  * 
8214: 08        328  PROC0    PHP              
8215: 78        329           SEI              
8216: A9 00     330           LDA   #$00       
8218: A2 27     331           LDX   #$27       ; MAX X CLAMP 
821A: 8D 78 04  332           STA   $478       
821D: 8E F8 04  333           STX   $4F8       
8220: 8D 78 05  334           STA   $578       
8223: 8D F8 05  335           STA   $5F8       
8226: 20 2C 81  336           JSR   CLAMPMOUSE 
8229: A0 00     337           LDY   #$00       
822B: A9 01     338           LDA   #$01       
822D: A2 27     339           LDX   #$27       
822F: 8C 78 04  340           STY   $478       
8232: 8E F8 04  341           STX   $4F8       
8235: 8C 78 05  342           STY   $578       
 
 
                              ===== Page 7 ===== 
 
8238: 8C F8 05  343           STY   $5F8       
823B: 20 2C 81  344           JSR   CLAMPMOUSE 
823E: 20 3A 81  345           JSR   HOMEMOUSE  
8241: 28        346           PLP              
8242: AD 53 C0  347           LDA   MIX        
8245: AD 50 C0  348           LDA   GR         
8248: 08        349           PHP              
8249: 78        350           SEI              
824A: 20 36 F8  351           JSR   CLRTOP     
824D: 28        352           PLP              
824E: 2C 00 C0  353  :NEXT    BIT   KBD        
8251: 30 16     354           BMI   :CLRIT     
8253: 08        355           PHP              
8254: 78        356           SEI              
8255: A5 1E     357           LDA   MOUSTAT    ; CHECK BUTTON STATUS 
8257: 10 0C     358           BPL   :PULL      
8259: A9 0F     359           LDA   #WHITE     
825B: 20 64 F8  360           JSR   SETCOL     
825E: A5 1C     361           LDA   MOUYPOS    
8260: A4 1A     362           LDY   MOUXPOS    
8262: 20 00 F8  363           JSR   PLOT       
8265: 28        364  :PULL    PLP              
8266: 4C 4E 82  365           JMP   :NEXT      
8269: 2C 10 C0  366  :CLRIT   BIT   KBDSTRB    
826C: A0 00     367           LDY   #$00       
826E: A2 00     368           LDX   #$00       
8270: 8A        369  :L1      TXA              
8271: 08        370           PHP              
8272: 78        371           SEI              
8273: 20 71 F8  372           JSR   SCRN       
8276: 28        373           PLP              
8277: 48        374           PHA              
8278: 68        375           PLA              
8279: C9 0F     376           CMP   #WHITE     
827B: D0 0C     377           BNE   :L2        
827D: A9 00     378           LDA   #BLACK     
827F: 08        379           PHP              
8280: 78        380           SEI              
8281: 20 64 F8  381           JSR   SETCOL     
8284: 8A        382           TXA              ; VERTICAL POSITION IN A-REG 
8285: 20 00 F8  383           JSR   PLOT       
8288: 28        384           PLP              
8289: C8        385  :L2      INY              
828A: C0 28     386           CPY   #$28       
828C: D0 E2     387           BNE   :L1        
828E: A0 00     388           LDY   #$00       
8290: E8        389           INX              
8291: E0 28     390           CPX   #$28       
8293: D0 DB     391           BNE   :L1        
8295: A0 00     392           LDY   #$00       
8297: B9 AA 82  393  :MSGL    LDA   CLRMSG,Y   
829A: F0 0B     394           BEQ   :MSGDONE   
829C: 09 80     395           ORA   #$80       
829E: 08        396           PHP              
829F: 78        397           SEI              
82A0: 20 ED FD  398           JSR   COUT       
82A3: 28        399           PLP              
 
 
                              ===== Page 8 ===== 
 
82A4: C8        400           INY              
82A5: D0 F0     401           BNE   :MSGL      
82A7: 4C 4E 82  402  :MSGDONE JMP   :NEXT      
82AA: 43 4C 45  403  CLRMSG   ASC   B4CLEARB4 
82AD: 41 52 
82AF: 8D 00     404           HEX   8D00       
--End assembly, 689 bytes, Errors: 0 
Symbol table - alphabetical order: 
   ACT     =$19        BASEADDR=$06        BLACK   =$00        BLUE    =$02 
   CLAMPMOUSE=$812C      CLRMSG  =$82AA      CLRTOP  =$F836      COUT    =$FDED 
   CREATEALL=$807C      CTR     =$09        DOSWARM =$03D0   ?  FINDMOUSE=$8010 
   GR      =$C050      HOMEMOUSE=$813A      INITMOUSE=$8106      IRQ     =$816F 
   IRQDONE =$81C5      IRQLOC  =$03FE      KBD     =$C000      KBDSTRB =$C010 
   MAXP    =$03        MIX     =$C053      MOUID1  =$38        MOUID2  =$18 
   MOUID3  =$01        MOUID4  =$20        MOUID5  =$D6        MOUIDLOC1=$05 
   MOUIDLOC2=$07        MOUIDLOC3=$0B        MOUIDLOC4=$0C        MOUIDLOC5=$FB 
   MOUSEJMP=$8150      MOUSTAT =$1E        MOUXPOS =$1A        MOUYPOS =$1C 
   MSLOT   =$08        NEWPROC =$80C0      NOMOUMSG=$8071      PLOT    =$F800 
   PRBYTE  =$FDDA   ?  PRNTAX  =$F941      PROC0   =$8214      PROC1   =$81EE 
   PROC2   =$81CF      READMOUSE=$8146      RED     =$01        RESETCTR=$81A5 
   SCRN    =$F871      SERVEMOUSE=$8120      SETCOL  =$F864      SETMOUSE=$8112 
   SPKR    =$C030      STKTAB  =$81CB      VBLINT  =$09        VBLON   =$80EE 
   WHITE   =$0F        YIELD   =$8157   
Symbol table - numerical order: 
   BLACK   =$00        MOUID3  =$01        RED     =$01        BLUE    =$02 
   MAXP    =$03        MOUIDLOC1=$05        BASEADDR=$06        MOUIDLOC2=$07 
   MSLOT   =$08        VBLINT  =$09        CTR     =$09        MOUIDLOC3=$0B 
   MOUIDLOC4=$0C        WHITE   =$0F        MOUID2  =$18        ACT     =$19 
   MOUXPOS =$1A        MOUYPOS =$1C        MOUSTAT =$1E        MOUID4  =$20 
   MOUID1  =$38        MOUID5  =$D6        MOUIDLOC5=$FB        DOSWARM =$03D0 
   IRQLOC  =$03FE   ?  FINDMOUSE=$8010      NOMOUMSG=$8071      CREATEALL=$807C 
   NEWPROC =$80C0      VBLON   =$80EE      INITMOUSE=$8106      SETMOUSE=$8112 
   SERVEMOUSE=$8120      CLAMPMOUSE=$812C      HOMEMOUSE=$813A      READMOUSE=$8146 
   MOUSEJMP=$8150      YIELD   =$8157      IRQ     =$816F      RESETCTR=$81A5 
   IRQDONE =$81C5      STKTAB  =$81CB      PROC2   =$81CF      PROC1   =$81EE 
   PROC0   =$8214      CLRMSG  =$82AA      KBD     =$C000      KBDSTRB =$C010 
   SPKR    =$C030      GR      =$C050      MIX     =$C053      PLOT    =$F800 
   CLRTOP  =$F836      SETCOL  =$F864      SCRN    =$F871   ?  PRNTAX  =$F941 
   PRBYTE  =$FDDA      COUT    =$FDED   

[toc] | [prev] | [next] | [standalone]


#1162

FromD Finnigan <dog_cow@macgui.com>
Date2014-02-21 19:56 +0000
Message-ID<dog_cow-1393012590@macgui.com>
In reply to#1158
D Finnigan wrote:
> I wrote a multitasking demonstration this week and today it is finished
> enough to show to people. This is a multi-part post. The documentation and
> source code will appear in separate followups to this article.

Clarification:

There are two source listings. The first is for an earlier prototype. The
second contains the latest source for the mouse drawing program.

[toc] | [prev] | [next] | [standalone]


#1163

FromEgan Ford <datajerk@gmail.com>
Date2014-02-22 09:47 -0700
Message-ID<leakb3$197$1@news.xmission.com>
In reply to#1158
On 2/21/14, 12:47 PM, D Finnigan wrote:
> I wrote a multitasking demonstration this week and today it is finished
> enough to show to people. This is a multi-part post. The documentation and
> source code will appear in separate followups to this article.
>
> You can email me for a disk image with Merlin source and the binary.
>
> In brief, the system swaps three processes, or threads as we might call
> them, between the 6502. The main process will allow the user to make some
> doodles on the low-res graphics screen using the mouse. Two background
> processes run autonomously plotting red and blue blocks, respectively, to
> the screen.
>
> The VBL interrupt on the AppleMouse card provides the IRQ source.
>

Thanks for posting this.

[toc] | [prev] | [next] | [standalone]


#1164

FromD Finnigan <dog_cow@macgui.com>
Date2014-02-22 17:36 +0000
Message-ID<dog_cow-1393090588@macgui.com>
In reply to#1163
Egan Ford wrote:
> On 2/21/14, 12:47 PM, D Finnigan wrote:
>> I wrote a multitasking demonstration this week and today it is finished
>> enough to show to people. This is a multi-part post. The documentation
>> and
>> source code will appear in separate followups to this article.
>>
>> You can email me for a disk image with Merlin source and the binary.
>>
>> In brief, the system swaps three processes, or threads as we might call
>> them, between the 6502. The main process will allow the user to make some
>> doodles on the low-res graphics screen using the mouse. Two background
>> processes run autonomously plotting red and blue blocks, respectively, to
>> the screen.
>>
>> The VBL interrupt on the AppleMouse card provides the IRQ source.
>>
> 
> Thanks for posting this.
>

You're welcome. I started working on the improvements yesterday. I am going
to add a process priority table. Then I am going to turn NEWPROC into a more
general system call like YIELD, so a process can call it to spawn a new
process. I am also going to increase the total number of processes which can
be created in the system.

Lastly, I'm going to add a SLEEP system call, which will put a process to
sleep for a period of time. I think this will work by setting the high-bit
in the priority table, then the low 7 bits become a timer.

I have assessed all of these improvements to be "easy" so I will likely have
this new version posted next week.


Then the next thing I want to mix in is hardware support for the TimeMaster
II H.O. in 1-second interrupt mode, and then the Super Serial Card, also
with interrupts, so we can really max out the system and see what it can do.

I'm holding off with disk access for now. I don't want to go there yet. :-)

-- 
]DF$
Apple II Book: http://macgui.com/newa2guide/
Usenet: http://macgui.com/usenet/  <-- get posts by email!
Apple II Web & Blog hosting: http://a2hq.com/

[toc] | [prev] | [standalone]


Back to top | Article view | comp.sys.apple2.programmer


csiph-web