Develop and Download Open Source Software

Browse Subversion Repository

Contents of /users/dbug/UpgradeTime/Encounter/FloppyBuilderVersion/code/bytestream.s

Parent Directory Parent Directory | Revision Log Revision Log


Revision 1716 - (show annotations) (download)
Sun Nov 26 13:22:24 2023 UTC (5 months, 2 weeks ago) by dbug
File size: 5256 byte(s)
Started migrating the bytestream commands into separate functions to implement them more efficiently in a separate assembler module (bytestream.s).
Added a COMMAND_STOP_BREAKPOINT command to make debugging easier
Moved the stream pointer in zero page to facilitate the assembler implementation.

Free memory: 2914 bytes 
1 ;
2 ; Bytestream module.
3 ; This implement a kind of bytecode based scripting system with simple compact commands.
4 ; This is not definitely not as fast as pure assembler, but it's much more compact
5 ;
6 #include "params.h"
7
8 .zero
9
10 _gCurrentStream
11 _gCurrentStreamInt .dsb 2
12 _gCurrentStreamStop .dsb 1
13 _gDelayStream .dsb 2
14
15 _gStreamItemPtr .dsb 2
16
17 .text
18
19 _ByteStreamCallbacks
20 .word _ByteStreamCommandEnd
21 .word _ByteStreamCommandRECTANGLE
22 .word _ByteStreamCommandFILL_RECTANGLE
23 .word _ByteStreamCommandTEXT
24 .word _ByteStreamCommandBUBBLE
25 .word _ByteStreamCommandWait
26 .word _ByteStreamCommandBITMAP
27 .word _ByteStreamCommandFADE_BUFFER
28 .word _ByteStreamCommandJUMP
29 .word _ByteStreamCommandJUMP_IF_TRUE
30 .word _ByteStreamCommandJUMP_IF_FALSE
31 .word _ByteStreamCommandINFO_MESSAGE
32 .word _ByteStreamCommandFULLSCREEN_ITEM
33 .word _ByteStreamCommandStopBreakpoint
34
35
36 ; Fetch the value in _gCurrentStream, increment the pointer, return the value in X
37 _ByteStreamGetNextByte
38 .(
39 ldy #0
40 lda (_gCurrentStream),y
41 tax
42 inc _gCurrentStream+0
43 bne skip
44 inc _gCurrentStream+1
45 skip
46 rts
47 .)
48
49
50 ; A=Item ID
51 ; Return a pointer on the item in _gStreamItemPtr
52 _ByteStreamComputeItemPtr
53 // Item ID
54 sta _gStreamItemPtr+0
55 lda #0
56 sta _gStreamItemPtr+1
57
58 // x2
59 asl _gStreamItemPtr+0
60 rol _gStreamItemPtr+1
61
62 // x4
63 lda _gStreamItemPtr+0
64 asl
65 sta tmp0+0
66 lda _gStreamItemPtr+1
67 rol
68 sta tmp0+1
69
70 // x6
71 clc
72 lda _gStreamItemPtr+0
73 adc tmp0+0
74 sta _gStreamItemPtr+0
75 lda _gStreamItemPtr+1
76 adc tmp0+1
77 sta _gStreamItemPtr+1
78
79 // Item pointer
80 clc
81 lda _gStreamItemPtr+0
82 adc #<_gItems
83 sta _gStreamItemPtr+0
84 lda _gStreamItemPtr+1
85 adc #>_gItems
86 sta _gStreamItemPtr+1
87
88 rts
89
90
91 _ByteStreamCommandStopBreakpoint
92 jmp _ByteStreamCommandStopBreakpoint
93 rts
94
95
96 _ByteStreamCommandEnd
97 lda #0
98 sta _gCurrentStream+0
99 sta _gCurrentStream+1
100 sta _gDelayStream
101
102 lda #1
103 sta _gCurrentStreamStop
104 rts
105
106
107 _ByteStreamCommandWait
108 ; In theory the delay could be 8 or 16 bits based on the value, but the code does not use that at the moment
109 jsr _ByteStreamGetNextByte
110 stx _gDelayStream+0
111
112 lda #1
113 sta _gCurrentStreamStop
114 rts
115
116
117 _ByteStreamCommandFADE_BUFFER
118 jmp _BlitBufferToHiresWindow
119
120
121 _ByteStreamCommandJUMP
122 //gCurrentStreamInt = (unsigned int*) *gCurrentStreamInt++;
123 ldy #0
124 lda (_gCurrentStream),y
125 tax ; Temporary so we don't change the stream pointer while using it
126 iny
127 lda (_gCurrentStream),y
128 stx _gCurrentStream+0
129 sta _gCurrentStream+1
130 rts
131
132
133
134 _ByteStreamCommandJUMP_IF_TRUE
135 lda #OPCODE_BEQ
136 bne common
137 _ByteStreamCommandJUMP_IF_FALSE
138 lda #OPCODE_BNE
139 common
140 .(
141 sta conditionCheck+0
142 ldy #2
143 lda (_gCurrentStream),y
144 bne checkItemFlag
145
146 checkItemLocation // OPERATOR_CHECK_ITEM_LOCATION 0
147 ; check = (gItems[itemId].location == locationId);
148 iny
149 lda (_gCurrentStream),y // item ID
150 jsr _ByteStreamComputeItemPtr
151 iny
152 lda (_gCurrentStream),y // location id
153 ldy #2
154 cmp (_gStreamItemPtr),y // gItems->location (+2)
155 jmp conditionCheck
156
157 checkItemFlag // OPERATOR_CHECK_ITEM_FLAG 1
158 ; check = (gItems[itemId].flags & flagId);
159 iny
160 lda (_gCurrentStream),y // item ID
161 jsr _ByteStreamComputeItemPtr
162 iny
163 lda (_gCurrentStream),y // flag ID
164 ldy #4
165 cmp (_gStreamItemPtr),y // gItems->flags (+4)
166 ;jmp conditionCheck
167
168 conditionCheck
169 bne _ByteStreamCommandJUMP // BNE/BEQ depending of the command
170
171 +_ByteStreamMoveBy5 ; Continue (jump not taken)
172 clc
173 lda _gCurrentStream+0
174 adc #5
175 sta _gCurrentStream+0
176 lda _gCurrentStream+1
177 adc #0
178 sta _gCurrentStream+1
179 rts
180 .)
181
182
183 _ByteStreamCommandFetchRectangleData
184 .(
185 ; Fetch x/y/width/height/pattern parameters
186 ldy #0
187 loop
188 lda (_gCurrentStream),y
189 sta _gDrawPosX,y
190 iny
191 cpy #5
192 bne loop
193 ; Increment the pointer
194 jmp _ByteStreamMoveBy5
195 .)
196
197
198 _ByteStreamCommandRECTANGLE
199 jsr _ByteStreamCommandFetchRectangleData
200 jmp _DrawFilledRectangle
201
202
203 _ByteStreamCommandFILL_RECTANGLE
204 jsr _ByteStreamCommandFetchRectangleData
205 jmp _DrawFilledRectangle
206
207
208 _ByteStreamCommandTEXT
209 ; Fetch x/y/pattern
210 ldy #0
211 lda (_gCurrentStream),y
212 sta _gDrawPosX
213
214 iny
215 lda (_gCurrentStream),y
216 sta _gDrawPosY
217
218 iny
219 lda (_gCurrentStream),y
220 sta _gDrawPattern
221
222 ; Store the current pointer
223 clc
224 lda _gCurrentStream+0
225 adc #3
226 sta _gDrawExtraData+0
227 lda _gCurrentStream+1
228 adc #0
229 sta _gDrawExtraData+1
230
231 ; Print the string (modifies the ExtraData pointer to point to the next string)
232 jsr _PrintFancyFont
233
234 ; Update the pointer
235 lda _gDrawExtraData+0
236 sta _gCurrentStream+0
237 lda _gDrawExtraData+1
238 sta _gCurrentStream+1
239 rts
240

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26