-
Notifications
You must be signed in to change notification settings - Fork 19
/
Copy pathozmoo.asm
191 lines (167 loc) · 3.54 KB
/
ozmoo.asm
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
; Which Z-machine to generate binary for
; (usually defined on the acme command line instead)
; Z1, Z2, Z6 and Z7 will (probably) never be supported
;Z3 = 1
;Z4 = 1
;Z5 = 1
;Z8 = 1
!ifdef Z4 {
Z4PLUS = 1
}
!ifdef Z5 {
Z4PLUS = 1
Z5PLUS = 1
}
!ifdef Z8 {
Z4PLUS = 1
Z5PLUS = 1
}
; Define DEBUG for additional runtime printouts
; (usually defined on the acme command line instead)
;DEBUG = 1
!source "constants.asm"
; where to store stack
stack_start = $2c00
stack_size = $0400;
; where to store story data
story_start = stack_start + stack_size
; basic program (10 SYS2061)
!source "basic-boot.asm"
+start_at $080d
jmp .initialize
; global variables
filelength !byte 0, 0, 0
fileblocks !byte 0, 0
c64_model !byte 0 ; 1=NTSC/6567R56A, 2=NTSC/6567R8, 3=PAL/6569
; include other assembly files
!source "streams.asm"
!source "disk.asm"
!source "screen.asm"
!source "memory.asm"
!source "stack.asm"
!source "utilities.asm"
!source "zmachine.asm"
!ifdef USEVM {
!source "vmem.asm"
}
!source "text.asm"
!source "dictionary.asm"
!source "objecttable.asm"
.initialize
; check if PAL or NTSC (needed for read_line timer)
w0 lda $d012
w1 cmp $d012
beq w1
bmi w0
and #$03
sta c64_model
; enable lower case mode
lda #23
sta reg_screen_char_mode
; Default banks during execution: Like standard except Basic ROM is replaced by RAM.
ldx #%00110110
stx zero_processorports
jsr load_dynamic_memory
jsr prepare_static_high_memory
jsr parse_dictionary
jsr parse_object_table
jsr streams_init
jsr stack_init
jsr z_init
jsr z_execute
!ifdef DEBUG {
;jsr test_object_table
;jsr testtext
}
; Back to normal memory banks
ldx #%00110111
stx zero_processorports
rts
load_header
; read the header
lda #>story_start ; first free memory block
ldx #$00 ; first block to read from floppy
ldy #$01 ; read 1 block
stx readblocks_currentblock
sty readblocks_numblocks
sta readblocks_mempos + 1
jsr readblocks
; check z machine version
lda story_start + header_version
!ifdef Z3 {
cmp #3
beq +
}
!ifdef Z4 {
cmp #4
beq +
}
!ifdef Z5 {
cmp #5
beq +
}
!ifdef Z8 {
cmp #8
beq +
}
lda #ERROR_UNSUPPORTED_STORY_VERSION
jsr fatalerror
+ ; check file length
; Start by multiplying file length by 2
lda #0
sta filelength
lda story_start + header_filelength
sta filelength + 1
lda story_start + header_filelength + 1
asl
rol filelength + 1
rol filelength
!ifdef Z4PLUS {
; Multiply file length by 2 again (for Z4, Z5 and Z8)
asl
rol filelength + 1
rol filelength
!ifdef Z8 {
; Multiply file length by 2 again (for Z8)
asl
rol filelength + 1
rol filelength
}
}
sta filelength + 2
ldy filelength
ldx filelength + 1
beq +
inx
bne +
iny
+ sty fileblocks
stx fileblocks + 1
rts
!ifndef USEVM {
load_dynamic_memory
; the default case is to simply treat all as dynamic (r/w)
jsr load_header
; check that the file is not too big
ldx fileblocks
bne +
ldx fileblocks + 1
cpx #>($D000 - story_start) ; don't overwrite $d000
bcc ++
+ lda #ERROR_OUT_OF_MEMORY
jsr fatalerror
; read the rest
++ ldx #>story_start ; first free memory block
inx ; skip header
txa
ldx #$01 ; first block to read from floppy
ldy fileblocks + 1 ; read the rest of the blocks
dey ; skip the header
stx readblocks_currentblock
sty readblocks_numblocks
sta readblocks_mempos + 1
jmp readblocks
prepare_static_high_memory
; the default case is to simply treat all as dynamic (r/w)
rts
}