forked from aburguera/SFIGHTER
-
Notifications
You must be signed in to change notification settings - Fork 0
/
SYSTEM.X68
267 lines (250 loc) · 11 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
; =============================================================================
; TITLE : SYSTEM MANAGEMENT (SYSTEM CODE)
; AUTHOR : ANTONI BURGUERA
; COMMENTS : IT IS DIVIDED IN THREE BLOCKS:
; - SYS : GENERIC.
; - SCR : SCREEN MANAGEMENT.
; - KBD : KEYBOARD MANAGEMENT.
; HISTORY : XX-XXX-201X - CREATION
; 11-OCT-2020 - MINOR CHANGES
; =============================================================================
; -----------------------------------------------------------------------------
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
; -----------------------------------------------------------------------------
ORI.W #$0700,SR ; DISABLE ALL INT
MOVE.L #SCRUPD,($80+SCRTRAP*4) ; INSTALL TRAP
MOVE.L #SCRWIDTH<<16|SCRHEIGH,D1 ; SET RESOLUTION
MOVE.B #33,D0
TRAP #15
MOVE.L #1,D1 ; SET WINDOWED MODE
TRAP #15
MOVE.W #$FF00,D1 ; CLEAR VISIBLE BUFFER
MOVE.B #11,D0
TRAP #15
MOVE.B #17,D1 ; ENABLE DOUBLE BUFFER
MOVE.B #92,D0
TRAP #15
MOVE.W #$FF00,D1 ; CLEAR HIDDEN BUFFER
MOVE.B #11,D0
TRAP #15
MOVE.L #SCRISR,($60+SCRIRQ*4) ; SET EXCEPTION VECTOR
MOVE.B #5,D1 ; ENABLE EXCEPTION PROCESSING
MOVE.B #32,D0
TRAP #15
MOVE.B #%10000000|SCRIRQ,D2 ; ENABLE AUTO-IRQ
MOVE.B #SCRTIM,D3
MOVE.B #6,D1
MOVE.B #32,D0
TRAP #15
CLR.B (SCRINTCT) ; PREPARE INTERRUPT FLAG
CLR.B (SCRCYCCT) ; PREPARE CYCLE COUNTER
ANDI.W #$F8FF,SR ; ENABLE INTS
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
; -----------------------------------------------------------------------------
MOVEM.W D0-D1,-(A7)
MOVE.B #94,D0 ; UPDATE DOUBLE BUFFER
TRAP #15
MOVE.W #$FF00,D1 ; CLEAR HIDDEN BUFFER
MOVE.B #11,D0
TRAP #15
MOVEM.W (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
; -----------------------------------------------------------------------------
MOVEM.L D0-D3,-(A7)
MOVE.B #19,D0
MOVE.L #KBDPAUSE<<24+KBDFIRE3<<16+KBDFIRE2<<8+KBDFIRE1,D1
TRAP #15
BSR .STORE ; STORE FIRE1,FIRE2,FIRE3 AND PAUSE
MOVE.L #KBDDOWN<<24+KBDRIGHT<<16+KBDUP<<8+KBDLEFT,D1
TRAP #15
BSR .STORE ; STORE KEY UP,DOWN,LEFT AND RIGTH.
MOVE.B (KBDVAL),D0 ; COMPUTE EDGE.
NOT.B D0 ; EDGE=NOT(PREVIOUS) AND CURRENT.
AND.B D2,D0
MOVE.B D2,(KBDVAL) ; STORE VALUES (PRESS AND EDGE)
MOVE.B D0,(KBDEDGE)
MOVEM.L (A7)+,D0-D3
RTE
.STORE MOVE.W #3,D3 ; TRANSLATES THE 8-BIT ENCODING
.LOOP LSL.L #8,D1 ; OF TRAP #15 TASK 19 INTO A 1-BIT
ROXL.B #1,D2 ; PER KEYPRESS ENCODING
DBRA.W D3,.LOOP
RTS
; =============================================================================
; 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