1 ; _____________________________________________ 2 ; | | 3 ; | Project: APPLER | 4 ; | File: TASKCTRL.ASM | 5 ; | Compiler: 16-bit TASM (2.5) | 6 ; | | 7 ; | Subject: Task Manager | 8 ; | | 9 ; | Author: Emil Dotchevski | 10 ; |_____________________________________________| 11 12 include GLOBALS.INC 13 include INTERFAC.INC 14 15 TaskControl segment public 16 assume CS:TaskControl,DS:TaskControl,ES:Emulate,SS:Data 17 18 PROCESSES_NUM = 9 19 20 CurrentProcessID db PID_EMULATOR 21 Stacks dw SP_Emulator 22 dw SP_Debugger 23 dw SP_FileManager 24 dw SP_FloppyDiskManager 25 dw SP_KeyboardSetup 26 dw SP_AboutScreen 27 dw SP_HelpScreen 28 dw SP_DosShell 29 dw SP_QuitAppler 30 PackedSPs dw PROCESSES_NUM dup (0) 31 StackPointers dw PROCESSES_NUM dup (0) 32 33 INinits dd EmulatorInInit,DebugInInit,FMInInit,DMInInit 34 dd KBDsetupInInit,AboutInInit,HelpInInit,NoInit,NoInit 35 OUTinits dd EmulatorOutInit,DebugOutInit,FMOutInit,DMOutInit 36 dd KBDsetupOutInit,AboutOutInit,HelpOutInit,NoInit,NoInit 37 38 EnableTaskSwitch db 1 39 PreviousProcessID db PID_DONT_SWITCH 40 TaskSwitch proc far ; Proces ID in AL 41 pushf 42 SaveAll 43 cmp cs:EnableTaskSwitch,0 44 jz TS_DontSwitch 45 cmp al,PID_DONT_SWITCH 46 je TS_DontSwitch 47 cmp al,PID_PREVIOUS_PROCESS 48 jne TS_NotPrevious 49 mov al,cs:PreviousProcessID 50 TS_NotPrevious: cli 51 mov bx,ss 52 mov ds,bx 53 mov es,bx 54 xor bh,bh 55 mov bl,cs:CurrentProcessID 56 mov cs:PreviousProcessID,bl 57 mov cs:CurrentProcessID,al 58 shl bx,1 59 mov cs:StackPointers[bx],sp 60 shl bx,1 61 call cs:OUTinits[bx] 62 shr bx,1 63 mov si,sp 64 mov cx,offset SP_MainStack 65 sub cx,sp 66 mov di,cs:Stacks[bx] 67 sub di,cx 68 mov cs:PackedSPs[bx],di 69 shr cx,1 70 cld 71 rep movsw 72 xor bh,bh 73 mov bl,cs:CurrentProcessID 74 shl bx,1 75 mov si,cs:PackedSPs[bx] 76 mov di,cs:StackPointers[bx] 77 mov sp,di 78 mov cx,offset SP_MainStack 79 sub cx,di 80 shr cx,1 81 rep movsw 82 shl bx,1 83 call cs:INinits[bx] 84 TS_DontSwitch: RestoreAll 85 popf 86 ret 87 TaskSwitch endp 88 89 S_Address struc 90 RetSegment dw ? 91 RetOffset dw ? 92 S_Address ends 93 StartupAdr macro Adr 94 S_Address 95 endm 96 RetAddresses label S_Address 97 StartupAdr ? 98 StartupAdr DebugMainRet 99 StartupAdr FM_MainRet 100 StartupAdr DM_MainRet 101 StartupAdr KBDsetupRET 102 StartupAdr AboutMainRet 103 StartupAdr HelpMainRet 104 StartupAdr CtrlAltEsc 105 StartupAdr CtrlAltDel 106 107 CALLpowerON proc far 108 cli 109 mov ax,18*4 110 mov cx,seg HelpMessage 111 mov dx,offset HelpMessage 112 call TimerReq 113 push cs 114 pop ds 115 mov cx,PROCESSES_NUM 116 xor bx,bx 117 mov si,bx 118 mov ax,7200h ; Valid flags 119 InitStacksLoop: mov sp,Stacks[si] 120 push RetAddresses[bx].RetSegment 121 push RetAddresses[bx].RetOffset 122 push ax ; Valid flags 123 sub sp,9*2 124 mov PackedSPs[si],sp 125 mov StackPointers[si],offset SP_MainStack - (1+1+1+9)*2 126 add bx,4 127 add si,2 128 loop InitStacksLoop 129 mov ax,Emulate 130 mov es,ax 131 mov CurrentProcessID,PID_EMULATOR 132 mov sp,offset SP_MainStack 133 mov SaveStack,sp 134 jmp far ptr PowerON 135 CALLpowerON endp 136 137 138 139 HelpMsg db ' Press for Help ' 140 HelpMessage proc far 141 push ax cx si di ds es 142 mov ah,0Fh 143 int 10h 144 cmp al,1 145 jne HM_Ret 146 push cs 147 pop ds 148 mov ax,Video 149 mov es,ax 150 mov si,offset HelpMsg 151 mov di,40*24*2+9*2 152 mov cx,offset HelpMessage - offset HelpMsg 153 mov ah,2Fh 154 HM_Loop: lodsb 155 stosw 156 loop HM_Loop 157 mov ax,18*7 158 mov cx,seg HideHelpMessage 159 mov dx,offset HideHelpMessage 160 call TimerReq 161 HM_Ret: pop es ds di si cx ax 162 ret 163 HelpMessage endp 164 165 HideHelpMessage proc far 166 push ax cx di es 167 mov ah,0Fh 168 int 10h 169 cmp al,1 170 jne HHM_Ret 171 mov ax,Video 172 mov es,ax 173 mov di,40*24*2+9*2 174 mov cx,offset HelpMessage- offset HelpMsg 175 mov ax,0 176 rep stosw 177 HHM_Ret: pop es di cx ax 178 ret 179 HideHelpMessage endp 180 181 182 assume CS:TaskControl,DS:nothing,ES:nothing,SS:Data 183 WIE_HELP dw 0 184 WIE_Counter dw 1 185 WaitInstrEnd proc far 186 xchg bp,sp 187 cmp byte ptr [bp],0 188 je WaitInstrEnd1 189 xchg sp,bp 190 iret 191 WaitInstrEnd1: cmp word ptr [bp+2],Emulate 192 je WaitInstrEnd2 193 xchg sp,bp 194 iret 195 WaitInstrEnd2: mov [WIE_HELP],ax 196 mov ax,[bp] 197 cmp ah,DS:[si-1] 198 mov ax,[WIE_HELP] 199 xchg sp,bp 200 je WaitInstrEnd3 201 iret 202 WaitInstrEnd3: dec [WIE_Counter] 203 jz WaitInstrEnd4 204 iret 205 WaitInstrEnd4: mov ax,seg F1_or_Invalid? 206 mov es,ax 207 assume es:seg F1_or_Invalid? 208 mov byte ptr es:F1_or_Invalid?,0 209 pop ax 210 pop es 211 pop ax 212 jmp DO_RETapple 213 WaitInstrEnd endp 214 215 assume DS:TaskControl, ES:Emulate 216 217 r_A db 0 218 r_X db 0 219 r_Y db 0 220 r_S db 0 221 r_P db 0 222 r_PC dw 0 223 T_Iflags db 00000010b 224 RetWhere? db 0 225 Emulator proc far 226 RETapple: pushf ; Invalid Opcode Entry Point 227 xor ax,ax 228 push ax 229 popf 230 mov ax,Debug 231 mov es,ax 232 assume es:Debug 233 mov es:F1_or_Invalid?,1 234 mov cs:RetWhere?,PID_DEBUGGER 235 pop ax 236 DO_RETapple: push cs ; WaitInstrEnd Entry Point 237 pop ds 238 mov bx,Emulate 239 mov es,bx 240 assume es:Emulate 241 and al,11000000b 242 shl ax,1 243 rol al,3 244 shr ax,1 245 or al,dh 246 or al,AppleFlags 247 mov r_P,al 248 mov r_A,dl 249 mov r_X,cl 250 mov ax,bp 251 mov r_Y,al 252 mov ax,AppleSP 253 mov r_S,al 254 dec si 255 mov r_PC,si 256 257 mov sp,offset SP_MainStack 258 mov al,RetWhere? 259 call TaskSwitch 260 261 cli 262 push cs 263 pop ds 264 mov ax,Emulate 265 mov es,ax 266 mov SaveStack,sp 267 mov dl,r_A 268 xor ax,ax 269 mov al,r_X 270 mov cx,ax 271 mov al,r_Y 272 mov bp,ax 273 mov al,r_S 274 mov byte ptr AppleSP,al 275 mov si,r_PC 276 mov al,r_P 277 mov ah,al 278 mov bh,al 279 mov dh,al 280 and ah,00111100b 281 and bh,00001000b 282 and dh,01000001b 283 mov AppleFlags,ah 284 cbw 285 shr al,1 286 ror al,1 287 shr ax,1 288 xor ah,ah 289 mov bl,ah 290 or ah,T_Iflags 291 shl bh,2 292 or bh,0D8h 293 push ax 294 push es 295 push bx 296 mov ax,Apple 297 mov bx,Video 298 mov ds,ax 299 mov es,bx 300 xor bl,bl 301 mov cs:WIE_Counter,2 302 iret 303 Emulator endp 304 305 EmulatorInInit proc far 306 mov cs:RetWhere?,PID_DEBUGGER 307 ret 308 EmulatorInInit endp 309 310 EmulatorOutInit proc far 311 push ax cx di es 312 mov ax,seg SwapFlag 313 mov es,ax 314 assume es:seg SwapFlag 315 mov es:SwapFlag,1 316 assume es:Emulate 317 mov ax,Apple 318 mov es,ax 319 mov di,0C700h 320 mov cx,11 321 xor al,al 322 rep stosb 323 pop es di cx ax 324 ret 325 EmulatorOutInit endp 326 327 CtrlAltEsc: call DosShell 328 SwitchToProcess PID_EMULATOR 329 jmp CtrlAltEsc 330 331 CtrlAltDel: call QuitAppler 332 jmp CtrlAltDel 333 334 NoInit proc far 335 ret 336 NoInit endp 337 338 TaskControl ends 339 340 341 DATA segment stack 'stack' 342 343 dw 24+000h dup (0) 344 SP_Emulator label word 345 dw 24+080h dup (0) 346 SP_Debugger label word 347 dw 24+060h dup (0) 348 SP_FileManager label word 349 dw 24+060h dup (0) 350 SP_FloppyDiskManager label word 351 dw 24+060h dup (0) 352 SP_KeyboardSetup label word 353 dw 24+030h dup (0) 354 SP_AboutScreen label word 355 dw 24+030h dup (0) 356 SP_HelpScreen label word 357 dw 24+020h dup (0) 358 SP_DosShell label word 359 dw 24+000h dup (0) 360 SP_QuitAppler label word 361 dw 0C0h dup (0) 362 SP_MainStack label word 363 364 DATA ends 365 366 END