OpenCores
URL https://opencores.org/ocsvn/thor/thor/trunk

Subversion Repositories thor

[/] [thor/] [trunk/] [software/] [FMTK/] [source/] [kernel/] [IOFocusc.c] - Blame information for rev 23

Details | Compare with Previous | View Log

Line No. Rev Author Line
1 23 robfinch
#include "types.h"
2
#include "proto.h"
3
 
4
extern JCB *IOFocusNdx;
5
extern int IOFocusTbl[4];
6
extern int iof_sema;
7
 
8
hMBX hFocusSwitchMbx = -1;
9
 
10
void FocusSwitcher()
11
{
12
     int d1,d2,d3;
13
 
14
     if firstcall {
15
         FMTK_AllocMbx(&hFocusSwitchMbx);
16
     }
17
     forever {
18
         FMTK_WaitMsg(hFocusSwitchMbx, &d1, &d2, &d3, 0x7FFFFFFFFFFFFFFFL);
19
         SwitchIOFocus();
20
     }
21
}
22
 
23
 
24
void ForceIOFocus(JCB *j)
25
{
26
    RequestIOFocus(j);   // In case it isn't requested yet.
27
     if (LockSemaphore(&iof_sema,-1)) {
28
        if (j != IOFocusNdx) {
29
            CopyScreenToVirtualScreen();
30
            j->pVidMem = j->pVirtVidMem;
31
            IOFocusNdx = j;
32
            j->pVidMem = 0xFFD00000;
33
            CopyVirtualScreenToScreen();
34
        }
35
        UnlockSemaphore(&iof_sema);
36
     }
37
}
38
 
39
 
40
// First check if it's even possible to switch the focus to another
41
// task. The I/O focus list could be empty or there may be only a
42
// single task in the list. In either case it's not possible to
43
// switch.
44
void SwitchIOFocus()
45
{
46
     JCB *j, *p;
47
 
48
     if (LockSemaphore(&iof_sema,-1)) {
49
         j = IOFocusNdx;
50
         if (j) {
51
             p = IOFocusNdx->iof_next;
52
             if (p <> IOFocusNdx) {
53
                 if (p) {
54
                     CopyScreenToVirtualScreen();
55
                     j->pVidMem = j->pVirtVidMem;
56
                     IOFocusNdx = p;
57
                     p->pVidMem = 0xFFD00000;
58
                     CopyVirtualScreenToScreen();
59
                 }
60
             }
61
         }
62
        UnlockSemaphore(&iof_sema);
63
     }
64
}
65
 
66
//-----------------------------------------------------------------------------
67
// The I/O focus list is an array indicating which jobs are requesting the
68
// I/O focus. The I/O focus is user controlled by pressing ALT-TAB on the
69
// keyboard.
70
//-----------------------------------------------------------------------------
71
 
72
void RequestIOFocus(JCB *j)
73
{
74
     int nj;
75
     int stat;
76
 
77
     nj = j->number;
78
     if (LockSemaphore(&iof_sema,-1)) {
79
        stat = (IOFocusTbl[0] >> nj) & 1;
80
        if (!stat) {
81
           if (IOFocusNdx==null) {
82
               IOFocusNdx = j;
83
               j->iof_next = j;
84
               j->iof_prev = j;
85
           }
86
           else {
87
               j->iof_prev = IOFocusNdx->iof_prev;
88
               j->iof_next = IOFocusNdx;
89
               IOFocusNdx->iof_prev->iof_next = j;
90
               IOFocusNdx->iof_prev = j;
91
           }
92
           IOFocusTbl[0] |= (1 << nj);
93
        }
94
        UnlockSemaphore(&iof_sema);
95
     }
96
}
97
 
98
//-----------------------------------------------------------------------------
99
// Release the IO focus for the current job.
100
//-----------------------------------------------------------------------------
101
void ReleaseIOFocus()
102
{
103
     ForceReleaseIOFocus(GetJCBPtr());
104
}
105
 
106
//-----------------------------------------------------------------------------
107
// Releasing the I/O focus causes the focus to switch if the running job
108
// had the I/O focus.
109
// ForceReleaseIOFocus forces the release of the IO focus for a job
110
// different than the one currently running.
111
//-----------------------------------------------------------------------------
112
 
113
void ForceReleaseIOFocus(JCB * j)
114
{
115
     JCB *p;
116
 
117
     if (LockSemaphore(&iof_sema,-1)) {
118
         if (IOFocusTbl[0] & (1 << (int)j->number)) {
119
             IOFocusTbl[0] &= ~(1 << j->number);
120
             if (j == IOFocusNdx)
121
                SwitchIOFocus();
122
             p = j->iof_next;
123
             if (p) {
124
                  if (p <> j) {
125
                        p->iof_prev = j->iof_prev;
126
                        j->iof_prev->iof_next = p;
127
                  }
128
                  else {
129
                       IOFocusNdx = null;
130
                  }
131
                  j->iof_next = null;
132
                  j->iof_prev = null;
133
             }
134
         }
135
        UnlockSemaphore(&iof_sema);
136
     }
137
}
138
 
139
void CopyVirtualScreenToScreen()
140
{
141
     short int *p, *q;
142
     JCB *j;
143
     int nn, pos;
144
 
145
     j = IOFocusNdx;
146
     p = j->pVidMem;
147
     q = j->pVirtVidMem;
148
     nn = j->VideoRows * j->VideoCols;
149
     for (; nn >= 0; nn--)
150
         p[nn] = q[nn];
151
    pos = j->CursorRow * j->VideoCols + j->CursorCol;
152
    SetVideoReg(11,pos);
153
}
154
 
155
void CopyScreenToVirtualScreen()
156
{
157
     short int *p, *q;
158
     JCB *j;
159
     int nn;
160
 
161
     j = IOFocusNdx;
162
     p = j->pVidMem;
163
     q = j->pVirtVidMem;
164
     nn = j->VideoRows * j->VideoCols;
165
     for (; nn >= 0; nn--)
166
         q[nn] = p[nn];
167
}
168
 

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.