-
Notifications
You must be signed in to change notification settings - Fork 0
/
SYSTEM.X68
297 lines (277 loc) · 11.3 KB
/
SYSTEM.X68
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
; =============================================================================
; SYSTEM MANAGEMENT (SYSTEM CODE)
; =============================================================================
; -----------------------------------------------------------------------------
SYSINIT
; INITIALIZES THE SYSTEM
; INPUT - NONE
; OUTPUT - NONE
; MODIFIES - NONE
; -----------------------------------------------------------------------------
MOVE.L (A7)+,A0 ; GET RETURN ADDRESS
JSR KBDINIT ; INIT KEYBOARD
JSR SCRINIT ; INIT SCREEN
JSR DMMINIT ; INIT DYNAMIC MEMORY
ANDI.W #$DFFF,SR ; SWITCH TO USER
MOVE.L A0,-(A7) ; PUT RETURN ADDRESS
RTS
; =============================================================================
; SCREEN MANAGEMENT (SYSTEM CODE)
; =============================================================================
; -----------------------------------------------------------------------------
SCRINIT
; INITIALIZES THE SCREEN, SCREEN-RELATED INTERRUPT AND VARS.
; INPUT - NONE
; OUTPUT - NONE
; MODIFIES - D0,D1,D2,D3
; -----------------------------------------------------------------------------
; TO DO:
; - DISABLE INTS (SET INT BITS IN SR TO 111)
ORI.W #$0700,SR
; - DISABLE ALL AUTO-IRQ (SEE TRAP #15 TASK 32)
; - INSTALL SCRUPD INTO TRAP SCRTRAP
MOVE.L #SCRUPD,$80+(SCRTRAP*4)
; - SET RESOLUTION TO SCRWIDTH X SCRHEIGHT
MOVE.B #33,D0
MOVE.L #(SCRWIDTH<<16)+SCRHEIGH,D1
TRAP #15
; - SET WINDOWED MODE
MOVE.L #1,D1
TRAP #15
; - CLEAR VISIBLE BUFFER
MOVE.B #11,D0
MOVE.W #$FF00,D1
TRAP #15
; - ENABLE DOUBLE BUFFER
MOVE.B #92,D0
MOVE.B #17,D1
TRAP #15
; - CLEAR HIDDEN BUFFER
MOVE.L #11,D0
MOVE.W #$FF00,D1
TRAP #15
; - INSTALL SCRISR FOR IRQ SCRIRQ (IRQ INTERRUPT VECTOR BEGINS
; AT $60. INSTALLATION IS SIMILAR TO TRAP INSTALLATION)
MOVE.L #SCRISR,$60+(SCRIRQ*4)
; - ENABLE AUTO-IRQ EVERY SCRTIM MS FOR IRQ SCRIRQ (SEE TRAP #15
; TASK 32)
MOVE.B #32,D0
MOVE.B #6,D1
MOVE.B #%10000001,D2
MOVE.L #SCRTIM,D3
TRAP #15
; - CLEAR SCRINTCT AND SCRCYCCT
CLR.B SCRINTCT
CLR.B SCRCYCCT
; - ENABLE INTS (SET INT BITS IN SR TO 000)
ANDI.W #$F8FF,SR
RTS
; -----------------------------------------------------------------------------
SCRISR
; SCREEN TIMER ISR. INCREASES THE INTERRUPT COUNTER AND UPDATES DOUBLE BUFFER.
; INPUT - NONE
; OUTPUT - NONE
; MODIFIES - NONE
; -----------------------------------------------------------------------------
ADDQ.B #1,(SCRINTCT) ; UPDATE INT FLAG/COUNTER
ADDQ.B #1,(SCRCYCCT) ; UPDATE CYCLE COUNTER
RTE
; -----------------------------------------------------------------------------
SCRUPD
; TRAP SERVICE ROUTINE IN CHARGE OF VISUALIZING CURRENT FRAME AND CLEARING
; BUFFER FOR THE NEXT ONE.
; INPUT - NONE
; OUTPUT - NONE
; MODIFIES - NONE
; -----------------------------------------------------------------------------
; TO DO: UPDATE DOUBLE BUFFER AND CLEAR HIDDEN BUFFER
MOVEM.L D0-D1,-(A7)
MOVE.B #94,D0
TRAP #15
MOVE.B #11,D0
MOVE.W #$FF00,D1
TRAP #15
MOVEM.L (A7)+,D0-D1
RTE
; =============================================================================
; KEYBOARD MANAGEMENT (SYSTEM CODE)
; =============================================================================
; -----------------------------------------------------------------------------
KBDINIT
; INITIALIZES THE SYSTEM VARIABLES KBDSYS AND KBDVAL
; INPUT - NONE
; OUTPUT - NONE
; MODIFIES - NONE
; -----------------------------------------------------------------------------
CLR.B (KBDVAL) ; INIT VARS
CLR.B (KBDEDGE)
MOVE.L #KBDREAD,($80+KBDTRAP*4) ; INSTALL
RTS
; -----------------------------------------------------------------------------
KBDREAD
; TRAP SERVICE ROUTINE.
; UPDATES THE SYSTEM VARIABLES KBDEDGE AND KBDVAL ACCORDING TO THE BITFIELD
; DESCRIBED IN SYSCONST. KBDVAL HOLDS THE CURRENT VALUES AND KBDEFGE HOLDS
; RISING EDGES FROM PREVIOUS CALL TO THE CURRENT ONE.
; INPUT - NONE
; OUTPUT - (KBDVAL) AND (KBDEDGE)
; MODIFIES - NONE
; -----------------------------------------------------------------------------
; TO DO: UPDATE KBDVAL AND KBDEDGE
MOVEM.L D0-D1,-(A7)
MOVE.B #19,D0
MOVE.L #KBDDOWN<<24+KBDRIGHT<<16+KBDUP<<8+KBDLEFT,D1
TRAP #15
CLR.B KBDVAL
BTST.L #0,D1
BEQ .UP
ORI.B #KBDMSKLF,KBDVAL ;LEFT
.UP BTST.L #8,D1
BEQ .RIGHT
ORI.B #KBDMSKUP,KBDVAL ;UP
.RIGHT BTST.L #16,D1
BEQ .DOWN
ORI.B #KBDMSKRT,KBDVAL ;RIGHT
.DOWN BTST.L #24,D1
BEQ .FIRE1
ORI.B #KBDMSKDN,KBDVAL ;DOWN
.FIRE1 MOVE.L #KBDPAUSE<<24+KBDFIRE3<<16+KBDFIRE2<<8+KBDFIRE1,D1
TRAP #15
BTST.L #0,D1
BEQ .FIRE2
ORI.B #KBDMSKF1,KBDVAL ;FIRE1
.FIRE2 BTST.L #8,D1
BEQ .FIRE3
ORI.B #KBDMSKF2,KBDVAL ;FIRE2
.FIRE3 BTST.L #16,D1
BEQ .PAUSE
ORI.B #KBDMSKF3,KBDVAL ;FIRE3
.PAUSE BTST.L #24,D1
BEQ .END
ORI.B #KBDMSKPS,KBDVAL ;PAUSE
.END NOT.B KBDEDGE
MOVE.B KBDVAL,D0
AND.B D0,KBDEDGE
MOVEM.L (A7)+,D0-D1
RTE
; =============================================================================
; DYNAMIC MEMORY MANAGEMENT (SYSTEM CODE)
; DYNAMIC MEMORY IS A SET OF DMMBNUM SLOTS OF DMMBSIZE BYTES EACH ONE.
; DMMBSIZE MUST BE POWER OF TWO. A SLOT HAS:
; - HEADER - 1 WORD. SPECIFIES THE OWNER (0 MEANS OWNED BY SYSTEM)
; - DATA - DMMBSIZE - 2 BYTES. MAY CONTAIN VARS AND ANY KIND OF DATA RELATED
; THE THE OWNER. IF OWNER==0, DATA IS MEANINGLESS.
; =============================================================================
; -----------------------------------------------------------------------------
DMMINIT
; INITIALIZES THE DYNAMIC MEMORY TO ALL OWNED BY SYSTEM.
; INPUT - NONE
; OUTPUT - NONE
; MODIFIES - NONE
; -----------------------------------------------------------------------------
MOVEM.L D0/A0,-(A7)
LEA DMMDATA,A0
MOVE.W #DMMBNUM-1,D0
.LOOP MOVE.W #DMMSYSID,(A0)
ADD.L #DMMBSIZE,A0
DBRA.W D0,.LOOP
MOVEM.L (A7)+,D0/A0
RTS
; -----------------------------------------------------------------------------
DMMFIRST
; SEARCHES THE FIRST MEMORY SLOT NOT OWNED BY SYSTEM AND OUTPUTS A POINTER
; TO THE CORRESPONDING DATA (SLOT ADDRESS+2)
; INPUT - NONE
; OUTPUT - A0 : POINTER TO THE DATA OR 0 IF NOT FOUND
; MODIFIES - NONE (ASIDE OF OUTPUT)
; -----------------------------------------------------------------------------
LEA DMMDATA,A0
DMMFRLOP TST.W (A0)+
BNE DMMFRFND
ADD.L #DMMBSIZE-2,A0
DMMFRCOM CMP.L #DMMDATA+DMMBSIZE*DMMBNUM-1,A0
BLT DMMFRLOP
MOVE.L #0,A0
DMMFRFND RTS
; -----------------------------------------------------------------------------
DMMNEXT
; SEARCHES THE NEXT MEMORY SLOT NOT OWNED BY SYSTEM AND OUTPUTS A POINTER
; TO THE CORRESPONDING DATA (SLOT ADDRESS+2)
; INPUT - A0 : POINTER WITHIN THE CURRENT SLOT
; OUTPUT - A0 : POINTER TO THE DATA OR 0 IF NOT FOUND
; MODIFIES - NONE (ASIDE OF OUTPUT)
; -----------------------------------------------------------------------------
MOVE.L D0,-(A7)
MOVE.L A0,D0
AND.L #-DMMBSIZE,D0 ; TAKE ADVANTAGE OF ALIGNMENT
ADD.L #DMMBSIZE,D0
MOVE.L D0,A0
MOVE.L (A7)+,D0
BRA DMMFRCOM
; -----------------------------------------------------------------------------
DMMFRSTO
; SEARCHES THE FIRST MEMORY SLOT WITH THE SPECIFIED ID AND OUTPUTS A POINTER
; TO THE CORRESPONDING DATA (SLOT ADDRESS+2)
; INPUT - D0.W : ID TO SEARCH
; OUTPUT - A0 : POINTER TO THE DATA OR 0 IF NOT FOUND
; MODIFIES - NONE (ASIDE OF OUTPUT)
; -----------------------------------------------------------------------------
LEA DMMDATA,A0
DMMFLOOP CMP.W (A0)+,D0
BEQ DMMFFND
ADD.L #DMMBSIZE-2,A0
DMMFCOM CMP.L #DMMDATA+DMMBSIZE*DMMBNUM-1,A0
BLT DMMFLOOP
MOVE.L #0,A0
DMMFFND RTS
; -----------------------------------------------------------------------------
DMMNEXTO
; SEARCHES THE NEXT MEMORY SLOT WITH THE SPECIFIED ID AND OUTPUTS A POINTER
; TO THE CORRESPONDING DATA (SLOT ADDRESS+2)
; INPUT - D0.W : ID TO SEARCH
; A0 : POINTER WITHIN THE CURRENT SLOT
; OUTPUT - A0 : POINTER TO THE DATA OR 0 IF NOT FOUND
; MODIFIES - NONE (ASIDE OF OUTPUT)
; -----------------------------------------------------------------------------
MOVE.L D0,-(A7)
MOVE.L A0,D0
AND.L #-DMMBSIZE,D0 ; TAKE ADVANTAGE OF ALIGNMENT
ADD.L #DMMBSIZE,D0
MOVE.L D0,A0
MOVE.L (A7)+,D0
BRA DMMFCOM
; -----------------------------------------------------------------------------
DMMALLOC
; SEARCHES THE FIRST FREE (SYS OWNED) SLOT, ASSIGNS TO THE SPECIFIED OWNER
; AND RETURNS A POINTER TO THE CORRESPONDING DATA (SLOT ADDRESS + 2)
; INPUT - D0.W : ID TO ASSIGN
; OUTPUT - A0 : POINTER TO THE DATA OR 0 IF NOT FREE SPACE
; MODIFIES - NONE (ASIDE OF OUTPUT)
; -----------------------------------------------------------------------------
MOVE.W D0,-(A7)
CLR.W D0
JSR DMMFRSTO
MOVE.W (A7)+,D0
CMP.L #0,A0
BEQ .END
MOVE.W D0,-2(A0)
.END RTS
; -----------------------------------------------------------------------------
DMMFREE
; FREES THE SLOT TO WHICH THE PROVIDED POINTER BELONGS BY SETTING ITS OWNED TO
; SYSTEM (0)
; INPUT - A0 : POINTER BELONGING TO THE SLOT TO FREE
; OUTPUT - NONE
; MODIFIES - NONE
; -----------------------------------------------------------------------------
MOVEM.L D0/A0,-(A7)
MOVE.L A0,D0
AND.L #-DMMBSIZE,D0 ; TAKE ADVANTAGE OF ALIGNMENT
MOVE.L D0,A0
CLR.W (A0)
MOVEM.L (A7)+,D0/A0
RTS
*~Font name~Courier New~
*~Font size~10~
*~Tab type~0~
*~Tab size~4~