@nataliapc/mcp-openmsx 1.1.4 → 1.1.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (49) hide show
  1. package/README.md +46 -2
  2. package/dist/openmsx.js +11 -1
  3. package/dist/server.js +343 -123
  4. package/dist/utils.js +43 -0
  5. package/package.json +4 -1
  6. package/resources/audio/toc.json +31 -0
  7. package/resources/bios/Calling_BIOS_from_MSX-DOS.md +75 -0
  8. package/resources/bios/MSX2_SUBROM_BIOS_calls.md +734 -0
  9. package/resources/bios/MSX_BIOS_calls.md +1046 -0
  10. package/resources/bios/toc.json +24 -0
  11. package/resources/book--msx2-technical-handbook/Appendix1__BIOS_Listing.md +1464 -0
  12. package/resources/book--msx2-technical-handbook/Appendix2__Math-Pack.md +427 -0
  13. package/resources/book--msx2-technical-handbook/Appendix3__Bit_Block_Transfer.md +182 -0
  14. package/resources/book--msx2-technical-handbook/Appendix4__Work_Area_Listing.md +1637 -0
  15. package/resources/book--msx2-technical-handbook/Appendix5__VRAM_Map.md +145 -0
  16. package/resources/book--msx2-technical-handbook/Appendix6__IO_Map.md +128 -0
  17. package/resources/book--msx2-technical-handbook/Appendix8_10__Control_Codes_and_Escape_Sequences.md +76 -0
  18. package/resources/book--msx2-technical-handbook/Chapter1__MSX_System_Overview.md +402 -0
  19. package/resources/book--msx2-technical-handbook/Chapter2__BASIC.md +2148 -0
  20. package/resources/book--msx2-technical-handbook/Chapter3__MSX-DOS.md +2577 -0
  21. package/resources/book--msx2-technical-handbook/Chapter4a__VDP_and_Display_Screen.md +2052 -0
  22. package/resources/book--msx2-technical-handbook/Chapter4b__VDP_and_Display_Screen.md +3311 -0
  23. package/resources/book--msx2-technical-handbook/Chapter5a__Access_to_Peripherals_through_BIOS.md +2714 -0
  24. package/resources/book--msx2-technical-handbook/Chapter5b__Access_to_Peripherals_through_BIOS.md +1263 -0
  25. package/resources/book--msx2-technical-handbook/MSX_Kun_BASIC_Compiler.md +220 -0
  26. package/resources/book--msx2-technical-handbook/toc.json +82 -0
  27. package/resources/book--the-msx-red-book/the_msx_red_book.md +10349 -0
  28. package/resources/book--the-msx-red-book/toc.json +12 -0
  29. package/resources/msx-dos/MSX-DOS_2_Function_Specifications.md +1366 -0
  30. package/resources/msx-dos/MSX-DOS_2_Program_Interface_Specification.md +963 -0
  31. package/resources/msx-dos/toc.json +18 -0
  32. package/resources/msx-unapi/Ethernet_UNAPI_specification_1.1.md +369 -0
  33. package/resources/msx-unapi/Introduction_to_MSX-UNAPI.md +132 -0
  34. package/resources/msx-unapi/MSX_UNAPI_specification_1.1.md +679 -0
  35. package/resources/msx-unapi/TCP-IP_UNAPI_specification.md +2361 -0
  36. package/resources/msx-unapi/toc.json +27 -0
  37. package/resources/others/toc.json +11 -0
  38. package/resources/processors/Z80_R800_instruction_set.md +482 -0
  39. package/resources/processors/toc.json +24 -0
  40. package/resources/processors/z80-undocumented.tex +5617 -0
  41. package/resources/processors/z80_detailed_instruction_set.md +2025 -0
  42. package/resources/programming/toc.json +121 -0
  43. package/resources/system/MSX_IO_ports_overview.md +554 -0
  44. package/resources/system/toc.json +18 -0
  45. package/resources/video/V9938_Technical_Data_Book.md +3623 -0
  46. package/resources/video/V9958_Technical_Data_Book.md +417 -0
  47. package/resources/video/V9990_Programmers_Manual_Banzai.html +1582 -0
  48. package/resources/video/VDP_TMS9918A.txt +709 -0
  49. package/resources/video/toc.json +28 -0
@@ -0,0 +1,1263 @@
1
+ # CHAPTER 5 - ACCESS TO PERIPHERALS THROUGH BIOS (Section 7)
2
+
3
+
4
+ <p>&nbsp;</p>
5
+
6
+ ## 7. SLOTS AND CARTRIDGES
7
+
8
+ The CPU (Z80) used in the MSX can access an address space of only 64K bytes (0000H to FFFFH). MSX is set up to access an effective space of 1M bytes. This is accomplished by using "slots", which allocate more than one memory byte or device to the same address.
9
+
10
+ This chapter introduces the use of the slot and information necessary to connect the cartridge software or the new device to MSX via the slot.
11
+
12
+
13
+ <p>&nbsp;</p>
14
+
15
+ ## Index
16
+
17
+ - [7. SLOTS AND CARTRIDGES](#7-slots-and-cartridges)
18
+ - [7.1 Slots](#71-slots)
19
+ - [7.1.1 Basic slot and expansion slot](#711-basic-slot-and-expansion-slot)
20
+ - [7.1.2 Selecting slots](#712-selecting-slots)
21
+ - [7.2 Inter-slot Calls (calls between slots)](#72-inter-slot-calls-calls-between-slots)
22
+ - [7.2.1 Inter-slot call operation](#721-inter-slot-call-operation)
23
+ - [7.2.2 Inter-slot call use](#722-inter-slot-call-use)
24
+ - [7.2.3 Work area to obtain the slot status](#723-work-area-to-obtain-the-slot-status)
25
+ - [7.3 Developing Cartridge Software](#73-developing-cartridge-software)
26
+ - [7.3.1 Catridge header](#731-catridge-header)
27
+ - [7.3.2 notes on the creation of the cartridge software](#732-notes-on-the-creation-of-the-cartridge-software)
28
+ - [Changes from the original](#changes-from-the-original)
29
+
30
+
31
+ <p>&nbsp;</p>
32
+
33
+ ### 7.1 Slots
34
+
35
+ A slot is an interface to effectively use a large address space, and to interface any memory or devices connected to the MSX address bus installed via the slot. The BASIC ROM inside the machine or RAM at MSX-DOS mode are not exceptions. The place at which the cartridge software is installed is also one of the slots. The following descriptions introduce how the software and the devices are connected to the slot.
36
+
37
+
38
+ <p>&nbsp;</p>
39
+
40
+ #### 7.1.1 Basic slot and expansion slot
41
+
42
+ The slot is either a basic slot or a expansion slot. A "basic slot" is a slot directly connected to the CPU address bus, as shown in [Figure 5.36](#figure-536--basic-slot-and-expansion-slot). The standard MSX machine can have up to four basic slots. The basic slot can be expanded up to four slots by connecting a slot expansion box (in some cases, the expansion is already done inside the machine), and is called "expansion slots". When each of four basic slots is expanded to four expansion slots, the maximum number of slots is 16. If you multiply 16 slots x 64K bytes you will get 1M bytes of accessible address space.
43
+
44
+ Note that the system itself cannot be started when expansion slot boxes are connected to the expansion slot. So the user should only connect expansion slot boxes to the basic slots. (Though the slot for the standard MSX cartridge is always a basic slot, in some cases the connector for the optional hardware of each machine might be connected to the expansion slot).
45
+
46
+
47
+ ##### _Figure 5.36 Basic slot and expansion slot_
48
+
49
+ ```
50
+ ---------
51
+ | |
52
+ | CPU |
53
+ | |
54
+ | |
55
+ ---------
56
+ |
57
+ O
58
+ \
59
+ \
60
+ \
61
+ \
62
+ O O O O
63
+ | | | |
64
+ --------- --------- --------- ---------
65
+ | | | | | | | |
66
+ Basic slot | | | | | | | |
67
+ | | | | | | | |
68
+ | | | | | | | |
69
+ --------- --------- --------- ---------
70
+ Slot #0 O Slot #2 Slot #3
71
+ /
72
+ /
73
+ /
74
+ O O O O
75
+ | | | |
76
+ --------- --------- --------- ---------
77
+ | | | | | | | |
78
+ Expansion | | | | | | | |
79
+ slot | | | | | | | |
80
+ | | | | | | | |
81
+ --------- --------- --------- ---------
82
+ Slot #1-0 Slot #1-1 Slot #1-2 Slot #1-3
83
+ ```
84
+
85
+ Each slot has 64K bytes from 0000H to FFFFH of address space and MSX manages it by dividing it into four "pages" of 16K bytes each. The CPU can select and access any slot for each page, and, as shown in [Figure 5.37](#figure-537--example-of-the-page-selection), it is possible to select and combine portions of several slots. Note that a pages with a given page number cannot be assigned to a page with a different page number (that is, page n of each slot is also page n to the CPU).
86
+
87
+
88
+ ##### _Figure 5.37 Example of the page selection_
89
+
90
+ ```
91
+ ------- ------- ------- ------- -------
92
+ Page 0 | A | | E | | I | | M | <----------> | A |
93
+ |-----| |-----| |-----| |-----| |-----|
94
+ Page 1 | B | | F | | J | | N | <----------> | J |
95
+ |-----| |-----| |-----| |-----| |-----|
96
+ Page 2 | C | | G | | K | | O | <----------> | G |
97
+ |-----| |-----| |-----| |-----| |-----|
98
+ Page 3 | D | | H | | L | | P | <----------> | H |
99
+ ------- ------- ------- ------- -------
100
+ Slot 0 Slot 1 Slot 2 Slot 3 CPU address
101
+ space
102
+ ```
103
+
104
+ <p>&nbsp;</p>
105
+
106
+ #### 7.1.2 Selecting slots
107
+
108
+ Selecting slots is different for the basic slot than for the expansion slot. For basic slots, it is done through the I/O port at A8H (see [Figure 5.38](#figure-538--selecting-the-basic-slot)), and for expansion slots, it is done through the "expansion slot selection register (FFFFH)" of the installed expansion slot (see [Figure 5.39](#figure-539--selecting-the-expansion-slot)). It is not recommended to change them directly, so the user should not switch the slots without careful planning. When the program switches the slot of the page in which it resides, the action is not always predictable. To call the program in another slot, use the inter-slot call described in the next section.
109
+
110
+
111
+ ##### _Figure 5.38 Selecting the basic slot_
112
+
113
+ ```
114
+ I/O port (A8H)
115
+ -----------------------------------------
116
+ | : | : | : | : |
117
+ -----------------------------------------
118
+ | | | | |
119
+ +---------+---------+---------+---------+
120
+ | | | |
121
+ | | | +---> Basic slot number of page 0 (0 to 3)
122
+ | | +-------------> Basic slot number of page 1 (0 to 3)
123
+ | +-----------------------> Basic slot number of page 2 (0 to 3)
124
+ +---------------------------------> Basic slot number of page 3 (0 to 3)
125
+ ```
126
+
127
+ ##### _Figure 5.39 Selecting the expansion slot_
128
+
129
+ ```
130
+ Expansion slot selection (FFFFH in expansion slot)
131
+ -----------------------------------------
132
+ | : | : | : | : |
133
+ -----------------------------------------
134
+ | | | | |
135
+ +---------+---------+---------+---------+
136
+ | | | |
137
+ | | | +---> Expn. slot number of page 0 (0 to 3)
138
+ | | +-------------> Expn. slot number of page 1 (0 to 3)
139
+ | +-----------------------> Expn. slot number of page 2 (0 to 3)
140
+ +---------------------------------> Expn. slot number of page 3 (0 to 3)
141
+ ```
142
+
143
+ **Note:** to identify the kind of slot, in the case of the expansion slot, the value written is read as the reversed value. The value of this register is the same inside the basic slot.
144
+
145
+
146
+ The slot where MAIN-ROM or RAM is installed and the slot number of the slot for the cartridge depend on the machine. Refer to the appropriate manual to see how slots are used on your MSX. But the MSX standard guarantees the normal operation no matter what is in the slots, so it is not necessary to worry about the slot use, as long as you are following the standard.
147
+
148
+ In some cases, however, it is required to know the slot number of the specified software. For example, in the previous version, BASIC MAIN-ROM was placed in basic slot #0 or in expansion slot #0-0 when basic slot #0 was expanded. So when MSX1 is upgraded to have the MSX2 functions by installing MSX-VIDEO and BASIC ver 2.0 ROM, the MAIN ROM should be placed somewhere other than slot #0 or slot #0-0. The slot where MSX2 SUB-ROM resides depends on the machine, but the information about the slot where BASIC interpreter ROM resides can be obtained by referring to the work area described below (the slot information can be obtained in the format shown in [Figure 5.40](#figure-540--format-for-the-slot)). When calling BIOS from DOS, examine the slot of MAIN-ROM in this way.
149
+
150
+ * **EXPTBL (FCC1H, 1)** - the slot of MAIN-ROM
151
+ * **EXBRSA (FAF8H, 1)** - the slot of SUB-ROM (0 for MSX1)
152
+
153
+
154
+ ##### _Figure 5.40 Format for the slot_
155
+
156
+ ```
157
+ MSB LSB
158
+ 7 6 5 4 3 2 1 0
159
+ -----------------------------------------
160
+ | | : : | : | : |
161
+ -----------------------------------------
162
+ | | | | |
163
+ +----+--------------+---------+---------+
164
+ | Unused | |
165
+ | | +---> Basic slot number (0 to 3)
166
+ | +-------------> Expansion slot number (0 to 3)
167
+ |
168
+ +------------------------------------> "1" if expansion slot
169
+ ```
170
+
171
+ When a given routine resides over page 1 and page 2 (4000H to BFFFH), the same slot for page 2 as the one for page 1 should be selected when the jump from page 1 to page 2 occurs within this routine. To do this, you need to examine the slot, in page 1, where the program resides and then to switch page 2 to that slot. To obtain information about the slot where the program currently is, execute the program shown in [List 5.11](#list-511--program-to-know-the-current-slot).
172
+
173
+
174
+ ##### _List 5.11 Program to know the current slot_
175
+
176
+ ```
177
+ ;********************************************************
178
+ ; List 5.11 to know where you are
179
+ ;********************************************************
180
+ ; Suppose your program cartridge is 32K bytes
181
+ ; long (4000h..0BFFFH). You set the ID at 4000H
182
+ ; and 4001H and the execution start address within
183
+ ; page 1 (4000h..7FFFH), MSX passes control
184
+ ; to this address so the part which resides in
185
+ ; page 2 is not yet enabled at this point. You
186
+ ; have to know where you are (in what primary
187
+ ; slot, in what secondary slot) and enable the
188
+ ; part at page 2. Below is the sample program
189
+ ; to do this.
190
+ ;
191
+ ENASLT EQU 0024H ;enable slot
192
+ RSLREG EQU 0138H ;read primary slot select register
193
+ EXPTBL EQU 0FCC1H ;slot is expanded or not
194
+
195
+ ;----- program start -----
196
+
197
+ ENAP2:
198
+ CALL RSLREG ;read primary slot #
199
+ RRCA ;move it to bit 0,1 of [Acc]
200
+ RRCA
201
+ AND 00000011B
202
+ LD C,A
203
+ LD B,0
204
+ LD HL,EXPTBL ;see if this slot is expanded or not
205
+ ADD HL,BC
206
+ LD C,A ;save primary slot #
207
+ LD A,(HL) ;See if the slot is expanded or not
208
+ AND 80H
209
+ OR C ;set MSB if so
210
+ LD C,A ;save it to [C]
211
+ INC HL ;Point to SLTTBL entry
212
+ INC HL
213
+ INC HL
214
+ INC HL
215
+ LD A,(HL) ;Get what is currently output
216
+ ;to expansion slot register
217
+ AND 00001100B
218
+ OR C ;Finally form slot address
219
+ LD H,80H
220
+ JP ENASLT ;enable page 2
221
+
222
+ END
223
+ ```
224
+
225
+
226
+ <p>&nbsp;</p>
227
+
228
+ ### 7.2 Inter-slot Calls (calls between slots)
229
+
230
+ As described above, programs reside in different slots, so a program not in the current slot might be needed in some cases. The most common cases are listed below:
231
+
232
+ (1) calling BIOS in MAIN-ROM from MSX-DOS level
233
+
234
+ (2) calling BIOS in SUB-ROM from BASIC level (only the case of MSX2)
235
+
236
+ (3) calling BIOS in MAIN-ROM or SUB-ROM from cartridge software
237
+
238
+ In doing such calls, to switch slots easily and safely, there is a group of BIOS routines called the inter-slot calls, which can be called from the routine in any slot. This section describes the use of the inter-slot calls.
239
+
240
+
241
+ <p>&nbsp;</p>
242
+
243
+ #### 7.2.1 Inter-slot call operation
244
+
245
+ When calling BIOS in MAIN-ROM from MSX-DOS, the state of slots changes as described below.
246
+
247
+ 1. Since, in the initial MSX-DOS mode, RAM is selected all over 64K address space, BASIC-ROM cannot be accessible in this state (see [Figure 5.41](#figure-541--inter-slot-call)-a).
248
+
249
+ 2. To call BIOS in ROM, switch page 0 to MAIN-ROM or BASIC to access. Then, call BIOS (see [Figure 5.41](#figure-541--inter-slot-call)-b).
250
+
251
+ 3. Restore the original status after BIOS operations and return to the initial address.
252
+
253
+
254
+ ##### _Figure 5.41 Inter-slot call_
255
+
256
+ ```
257
+ a) When using MSX-DOS b) When calling BASIC-ROM BIOS
258
+
259
+ MSX-DOS BASIC-ROM MSX-DOS BASIC-ROM
260
+ ------- ------- ------- -------
261
+ Page 0 | RAM | | ROM | Page 0 | RAM | | ROM | BIOS is
262
+ |-----| |-----| |-----| |-----| called
263
+ Page 1 | RAM | | ROM | Page 1 | RAM | | ROM |
264
+ |-----| |-----| <----------> |-----| |-----|
265
+ Page 2 | RAM | | ___ | Page 2 | RAM | | ___ |
266
+ |-----| |-----| |-----| |-----|
267
+ Page 3 | RAM | | ___ | Page 3 | RAM | | ___ |
268
+ ------- ------- ------- -------
269
+ Slot 3 Slot 0 Slot 3 Slot 0
270
+ ```
271
+
272
+ This is easily done when the program resides in other than page 0, but there can be some problem when the calling program resides in page 0 which is the same page as BIOS of the called program. Care is needed to prevent the program from disappearing itself and generating unpredictable results when it is switched to page 0. The inter-slot call settles this problem by jumping to page 3 temporarily and then switching slots.
273
+
274
+
275
+ <p>&nbsp;</p>
276
+
277
+ #### 7.2.2 Inter-slot call use
278
+
279
+ There are several ways to execute inter-slot calls, as described below. They are included in MAIN-ROM as BIOS calls. Some of them are offered in MSX-DOS, so inter-slot calls can be executed under MSX-DOS.
280
+
281
+
282
+ <p>&nbsp;</p>
283
+
284
+ _(1) Inter-slot call routines in BIOS_
285
+
286
+ #### RDSLT (000CH/MAIN) - read value at specified address of specified slot
287
+
288
+ * **Input**:
289
+ * A register ⟵ slot specification
290
+ * HL register ⟵ address to be read at
291
+ * **Output**: A register ⟵ value which has been read out
292
+ * **Use**: AF, BC, DE
293
+ * **Function**: reads the value at the specified address of the specified slot and stores it in the A register. The slot specification is done using the A register in the form shown in [Figure 5.40](#figure-540--format-for-the-slot). At this point, when the objective slot is the basic slot, set "0" to the 6 high order bits and define the slot #0 to #3 using the 2 low order bits. When specifying the expansion slot, specify the basic slot by bit 0 and bit 1 and the expansion slot by bit 2 and bit 3 and set bit 7 to "1".
294
+
295
+
296
+ <p>&nbsp;</p>
297
+
298
+ #### WRSLT (0014H/MAIN) - write value at specified address of specified slot
299
+
300
+ * **Input**:
301
+ * A register ⟵ slot specification (same format as in Figure 5.40)
302
+ * HL register ⟵ address to be written in
303
+ * E register ⟵ data to be written
304
+ * **Output**: ---
305
+ * **Use**: AF, BC, D
306
+ * **Function**: writes E register value in the address specified by HL register of the slot specified by the A register (the specification format is the same as in [Figure 5.40](#figure-540--format-for-the-slot)).
307
+
308
+
309
+ <p>&nbsp;</p>
310
+
311
+ #### CALSLT (001CH/MAIN) - call specified address of specified slot
312
+
313
+ * **Input**:
314
+ * 8 high order bits of IY register ⟵ slot (same format as in [Figure 5.40](#figure-540--format-for-the-slot))
315
+ * IX register ⟵ address to be called
316
+ * **Output**: depends on the result of the called program
317
+ * **Use**: depends on the result of the called program
318
+ * **Function**: calls the routine at the address specified by IX register of the slot specified by the 8 high order bits of IY register (the specification format is the same as in [Figure 5.40](#figure-540--format-for-the-slot)).
319
+
320
+
321
+ <p>&nbsp;</p>
322
+
323
+ #### ENASLT (0024H/MAIN) - swicth slots
324
+
325
+ * **Input**:
326
+ * A register ⟵ slot (same format as in [Figure 5.40](#figure-540--format-for-the-slot))
327
+ * HL register ⟵ specifies the page to switch the slot by 2 high order bits
328
+ * **Output**: ---
329
+ * **Use**: all
330
+ * **Function**: switches the page specified by the 2 high order bits of the HL register to the slot specified by the A register.
331
+
332
+
333
+ <p>&nbsp;</p>
334
+
335
+ #### CALLF (0030H/MAIN) - call specified address of specified slot
336
+
337
+ * **Input**: specifies the slot and the address in the inline parameter format
338
+ * **Output**: depends on the result of the called program
339
+ * **Use**: depends on the result of the called program
340
+ * **Function**: calls the specified address of the specified slot, but, different from CALSLT described above, the slot and the address is specified in the inline parameter format, as described below. That is, parameters are passet by one byte (same format as RDSLT) to specify that the slot is placed just after the instruction which calls CALLF and the next two bytes to specify the address are placed. "CALL 0030H" may be replaced by the RST (restart) instruction, "RST 30H". In this case, the inter-slot call is done in 4 bytes.
341
+
342
+ ##### _Figure 5.42 Example of the inter-slot call execution_
343
+
344
+ ```
345
+ RST 30H ;interslot call
346
+ DB 00000000B ;select slot#0
347
+ DW 006CH ;call address = 006CH
348
+ ```
349
+
350
+
351
+ <p>&nbsp;</p>
352
+
353
+ #### RSLREG (0138H/MAIN) - read the basic slot selection register
354
+
355
+ * **Input**: ---
356
+ * **Output**: A register ⟵ value which has been read
357
+ * **Use**: ---
358
+ * **Function**: reads the contents of the basic slot selection register and stores it in the A register.
359
+
360
+
361
+ <p>&nbsp;</p>
362
+
363
+ #### WSLREG (013BH/MAIN) - write in the basic slot selection register
364
+
365
+ * **Input**: A register ⟵ value to be written
366
+ * **Output**: ---
367
+ * **Use**: ---
368
+ * **Function**: writes the A register value in the basic slot selection register and selects the slot.
369
+
370
+
371
+ <p>&nbsp;</p>
372
+
373
+ #### SUBROM (015CH/MAIN) - call specified address in SUB-ROM
374
+
375
+ * **Input**: IX register ⟵ address to be called, PUSH IX (see Appendix 2, SUB-ROM list)
376
+ * **Output**: depends on the result of the called program
377
+ * **Use**: background register and IX, IY registers are reserved
378
+ * **Function**: This is the routine to call BASIC SUB-ROM especially. The slot where SUB-ROM resides is automatically examined. Normally, EXTROM, described below, is used.
379
+
380
+
381
+ <p>&nbsp;</p>
382
+
383
+ #### EXTROM (015FH/MAIN) - call specified address in SUB-ROM
384
+
385
+ * **Input**: IX register ⟵ address to be called
386
+ * **Output**: depends on the result of the called program
387
+ * **Use**: background register and IY register are reserved
388
+ * **Function**: This is the routine to call BASIC SUB-ROM. The difference between this and SUB-ROM above is the point whether the IX register value is pushed.
389
+
390
+
391
+ <p>&nbsp;</p>
392
+
393
+ _(2) Inter-slot call in MSX-DOS_
394
+
395
+ In MSX-DOS, five kinds of inter-slot calls are offered and their entry addresses are defined at jump vectors of MSX-DOS. These are the same as ones in BIOS, so refer to BIOS above for their functions or use. Note that these routines should not be used when calling routines in SUB-ROM from MSX-DOS.
396
+
397
+ * RDSLT (000CH) - read value at specified address of specified slot
398
+ * WRSLT (0014H) - write value at specified address of specified slot
399
+ * CALSLT (001CH) - call specified address of specified slot
400
+ * ENASLT (0024H) - make specified slot available
401
+ * CALLF (0030H) - call specified address of specified slot
402
+
403
+
404
+ ##### _List 5.12 Calling BIOS from MSX-DOS_
405
+
406
+ ```
407
+ ;********************************************************
408
+ ; List 5.12 How to use BIOS from MSX-DOS.
409
+ ;********************************************************
410
+ ;
411
+ CALSLT EQU 001CH ;Inter slot call
412
+ EXBRSA EQU 0FAF0H ;Slot address of BIOS (main) ROM
413
+ EXPTBL EQU 0FCC1H ;Slot address of extended ROM
414
+ ;
415
+ ; LD IY,(EXPTBL-1) ;Load slot address of the BIOS ROM
416
+ ; ;in high byte of IY
417
+ ; LD IX,address of the BIOS jump table
418
+ ; CALL CALSLT
419
+ ;
420
+ ;----- Sample program to set text mode -----
421
+
422
+ INITXT EQU 006CH
423
+ LINL40 EQU 0F3AEH
424
+ ;
425
+ TOTEXT: LD B,40
426
+ LD A,(EXBRSA) ;slot address of SUB-ROM
427
+ OR A ;0 if MSX1
428
+ JR Z,TO40
429
+ LD B,80
430
+
431
+ TO40: LD (LINL40),B ;set width into work area
432
+ LD IX,INITXT
433
+ LD IY,(EXPTBL-1) ;get expanded slot status to IYH
434
+ CALL CALSLT ;perform an inter-slot call
435
+ EI ;because CALSLT do DI
436
+ RET
437
+
438
+ END
439
+ ```
440
+
441
+
442
+ <p>&nbsp;</p>
443
+
444
+ #### 7.2.3 Work area to obtain the slot status
445
+
446
+ The following addresses involve the slot work area.
447
+
448
+
449
+ <p>&nbsp;</p>
450
+
451
+ * **EXBRSA (FAF8H, 1)** - SUB-ROM slot
452
+
453
+ ##### _Figure 5.43 SUB-ROM slot_
454
+
455
+ ```
456
+ MSB LSB
457
+ 7 6 5 4 3 2 1 0
458
+ -----------------------------------------
459
+ | | : : | : | : |
460
+ -----------------------------------------
461
+ | | | | |
462
+ +----+--------------+---------+---------+
463
+ | Unused | |
464
+ | | +---> Basic slot number (0 to 3)
465
+ | +-------------> Expansion slot number (0 to 3)
466
+ |
467
+ +------------------------------------> "1" if expansion slot
468
+ ```
469
+
470
+
471
+ <p>&nbsp;</p>
472
+
473
+ * **EXPTBL (FCC1H, 4)** - whether the basic slot is expanded or not
474
+
475
+
476
+ ##### _Figure 5.44 Selecting the basic slot_
477
+
478
+ ```
479
+ MSB LSB
480
+ 7 6 5 4 3 2 1 0
481
+ -----------------------------------------
482
+ [FCC1H] | | : : | : | : | MAIN-ROM slot
483
+ -----------------------------------------
484
+
485
+ -----------------------------------------
486
+ [FCC2H] | | Unused | Slot #1
487
+ -----------------------------------------
488
+
489
+ -----------------------------------------
490
+ [FCC3H] | | Unused | Slot #2
491
+ -----------------------------------------
492
+
493
+ -----------------------------------------
494
+ [FCC4H] | | Unused | Slot #3
495
+ -----------------------------------------
496
+ |
497
+ +--> 0: slot is not expanded
498
+ 1: slot is expanded
499
+ ```
500
+
501
+
502
+ <p>&nbsp;</p>
503
+
504
+ * **SLTTBL (FCC5H, 4)** - preservation area for the expansion slot selection register value
505
+
506
+
507
+ ##### _Figure 5.45 Selecting the expansion slot_
508
+
509
+ ```
510
+ MSB LSB
511
+ 7 6 5 4 3 2 1 0
512
+ ----------------------------------------- expansion slot selection
513
+ [FCC5H] | : | : | : | : | register value of slot #0
514
+ -----------------------------------------
515
+
516
+ ----------------------------------------- expansion slot selection
517
+ [FCC6H] | : | : | : | : | register value of slot #1
518
+ -----------------------------------------
519
+
520
+ ----------------------------------------- expansion slot selection
521
+ [FCC7H] | : | : | : | : | register value of slot #2
522
+ -----------------------------------------
523
+
524
+ ----------------------------------------- expansion slot selection
525
+ [FCC8H] | : | : | : | : | register value of slot #3
526
+ -----------------------------------------
527
+ | | | | |
528
+ +---------+---------+---------+---------+
529
+ | | | |
530
+ | | | +----> exp. slot num. for page 0
531
+ | | +--------------> exp. slot num. for page 1
532
+ | +------------------------> exp. slot num. for page 2
533
+ +----------------------------------> exp. slot num. for page 3
534
+ ```
535
+
536
+
537
+ <p>&nbsp;</p>
538
+
539
+ * **SLTATR (FCC9H, 64)** - test for existance of application in each slot/page
540
+
541
+
542
+ ##### _Figure 5.46 Test for existence of application_
543
+
544
+ ```
545
+ -----------------------------------------
546
+ [FCC9H] | | | | Unused | Slot #0-0, page 0
547
+ |----+----+----+------------------------|
548
+ [FCCAH] | | | | Unused | Slot #0-0, page 1
549
+ |----+----+----+------------------------|
550
+ | | | | |
551
+ . . . .
552
+ . . . .
553
+ . . . .
554
+ | | | | |
555
+ |----+----+----+------------------------|
556
+ [FD08H] | | | | Unused | Slot #3-3, page 3
557
+ -----------------------------------------
558
+ | | |
559
+ | | +--> Routine to process expanded statements 1:yes 0:no
560
+ | +-------> Routine to process expansion device 1:yes 0:no
561
+ +------------> BASIC text 1:yes 0:no
562
+ ```
563
+
564
+ The concrete work area for a given slot and page can be obtained with the following expression:
565
+
566
+ ```
567
+ SLTATR address = FCC9H + 16*basic slot + 4*expansion slot + page
568
+ ```
569
+
570
+
571
+ <p>&nbsp;</p>
572
+
573
+ * **SLTWRK (FD09H, 128)** - work area for application
574
+
575
+
576
+ ##### _Figure 5.47 Work area for application_
577
+
578
+ ```
579
+ ----------------------------------------- Work area for
580
+ [FD09H] | ................................... | slot 0-0 page 0
581
+ |---------------------------------------|
582
+ [FD0BH] | ................................... | Work area for
583
+ |---------------------------------------| slot 0-0 page 1
584
+ | |
585
+ . . .
586
+ . . .
587
+ . . .
588
+ | |
589
+ |---------------------------------------| Work area for
590
+ [FD87H] | ................................... | slot 3-3 page 3
591
+ -----------------------------------------
592
+ ```
593
+
594
+ The concrete work area for a given slot and page can be obtained with the following expression:
595
+
596
+ ```
597
+ SLTWRK address = FD09H + 32*basic slot + 8*expansion slot + 2*page
598
+ ```
599
+
600
+ <p>&nbsp;</p>
601
+
602
+ ### 7.3 Developing Cartridge Software
603
+
604
+ MSX machines usually have at least one external slot and the hardware to be put there is called a "cartridge". There are cartridges such as the ROM cartridges for application programs or games, input-output device cartridges for a disk or RS-232 interface, RAM expansion cartridges for expanding RAM, and slot expansion cartridges for expanding slots. These cartridges make the MSX easy to upgrade. BASIC and assembly language programs can also be stored in ROM cartridge easily. This section describes how to develop cartridge software.
605
+
606
+
607
+ <p>&nbsp;</p>
608
+
609
+ #### 7.3.1 Catridge header
610
+
611
+ MSX cartridges have a 16-bye common header and, when the system is reset, the cartridge is initialised by the information written in this header. For ROM cartridges of BASIC or assembly language programs, they can be automatically started by using the information written in the header. [Figure 5.48](#figure-548--program-cartridge-header) shows the cartridge header configuration.
612
+
613
+
614
+ ##### _Figure 5.48 Program cartridge header_
615
+
616
+ ```
617
+ ------------------- 4000H or 8000H
618
+ +0000H | ID |
619
+ |-----------------|
620
+ +0002H | INIT |
621
+ |-----------------|
622
+ +0004H | STATEMENT |
623
+ |-----------------|
624
+ +0006H | DEVICE |
625
+ |-----------------|
626
+ +0008H | TEXT |
627
+ |-----------------|
628
+ +000AH | |
629
+ | |
630
+ | Reserved | Note: Reserved area should
631
+ | | be filled with 00H.
632
+ | |
633
+ +0010H -------------------
634
+ ```
635
+
636
+ ##### ID
637
+
638
+ In the case of ROM cartridges, these two bytes have codes "AB" (41H, 42H). For SUB-ROM cartridges, the ID is "CD".
639
+
640
+
641
+ ##### INIT
642
+
643
+ When the cartridge is made to initialise the work area or I/O, these two bytes are the addresses for the initialization routine; otherwise 0000H is assumed. After instructions such as getting the work area in the initialization routine are placed, end with "RET". All registers except the SP register may be destroyed. For assembly language programs, such as games, which loop within the cartridge, it is possible to execute the object program from here.
644
+
645
+
646
+ ##### STATEMENT
647
+
648
+ When the cartridge is made to expand the CALL statement, these two bytes are the address for the statement expansion routine; otherwise 0000H is assumed. If so, the statement expansion routine should reside at 4000H to 7FFFH.
649
+
650
+ The CALL statement is described in the following format:
651
+
652
+ ```
653
+ CALL <expression statement name> [(<argument>[, <argument>...])]
654
+ ```
655
+
656
+ The expression statement name can have up to 15 characters. As an abbreviation for CALL, "_" (underscore) is available.
657
+
658
+ When the BASIC interpreter finds a CALL statement, it puts the expansion statement name in PROCNM (FD89H, 16) in the work area and passes the control to cartridges, whose contents of STATEMENT of the header is other than 0, in the order from the one with the smaller slot number. The HL register points to the text address next to the expansion statement name at this point (see [Figure 5.49](#figure-549--input-output-of-the-operation-routine-of-the-expansion-statement)a).
659
+
660
+
661
+ ##### _Figure 5.49 Input-output of the operation routine of the expansion statement_
662
+
663
+ ```
664
+ ---------------------------------------------------------------------
665
+ | |
666
+ a) | Input setup when the interpreter calls routines to process |
667
+ | expanded statements |
668
+ | |
669
+ | CALL ABCDE(0,0,0):A=0 |
670
+ | ^ |
671
+ | | |
672
+ | HL |
673
+ | |
674
+ | CY flag = 1 +---- End of the name |
675
+ | | of the expanded |
676
+ | ------------------------------------- statement |
677
+ | PROCNM | A | B | C | D | E | 00H | |
678
+ | ------------------------------------- |
679
+ | |
680
+ |-------------------------------------------------------------------|
681
+ | |
682
+ b) | Output setup when the expanded statement was not processed |
683
+ | |
684
+ | CALL ABCDE(0,0,0):A=0 |
685
+ | ^ |
686
+ | | |
687
+ | HL |
688
+ | |
689
+ | CY flag = 1 |
690
+ | |
691
+ |-------------------------------------------------------------------|
692
+ | |
693
+ c) | Output setup when the expanded statement was processed |
694
+ | |
695
+ | CALL ABCDE(0,0,0):A=0 |
696
+ | ^ |
697
+ | | |
698
+ | HL |
699
+ | |
700
+ | CY flag = 0 |
701
+ | |
702
+ ---------------------------------------------------------------------
703
+ ```
704
+
705
+ To develop the statement expansion routine, recognise the name of the expansion statement written in PROCNM first, then return with setting "1" to the carry flag without modifying the HL register if the statement is not to be handled (see [Figure 5.49](#figure-549--input-output-of-the-operation-routine-of-the-expansion-statement)b); otherwise, handle it properly and set the HL register (text pointer) to the next handled statement (where 00H or 3AH is placed usually), then return after setting "0" to the carry flag (see [Figure 5.49](#figure-549--input-output-of-the-operation-routine-of-the-expansion-statement)c).
706
+
707
+ The BASIC interpreter determines the status of the carry flag whether a CALL statement has been executed, and, if not, calls the next cartridge. When all cartridges have not executed the statement (when the carry flag has been "1" all the time), it displays "SYNTAX ERROR". To test arguments of the statement, it is convenient to use "internal routines for the statement expansion" in [section 4.4 of chapter 2](Chapter2.md#44-expansion-of-cmd-command).
708
+
709
+
710
+ ##### DEVICE
711
+
712
+ These two bytes are the addresses of the device expansion routine, when the cartridge does the device expansion (the input-output device expansion); otherwise 0000H is used. When doing the device expansion, the device expansion routine should be in 4000H-7FFFH. One cartridge can have up to 4 devices. The name of the expansion device should be less than 16 characters.
713
+
714
+ When the BASIC interpreter finds an undefined device, it stores that in PROCNM (FD89H, 16) and put FFH in the A register and passes control to the cartridge whose contents is not 0 in the order from the one with the smaller slot number (see [Figure 5.50](#figure-550--input-output-to-the-device-expansion-routine)a).
715
+
716
+ When creating device expansion routines, identify the file descriptor of PROCNM first, and, when it is not for the device to be processed, return with setting 1 to the carry flag (see [Figure 5.50](#figure-550--input-output-to-the-device-expansion-routine)b). Otherwise, process it and set the device ID (0-3) in the A register, then return with setting 0 to the carry flag (see [Figure 5.50](#figure-550--input-output-to-the-device-expansion-routine)c).
717
+
718
+ The BASIC interpreter determines by the status of the carry flag whether or not it is processed, and, if not, call the next cartridge. When all cartridges were not processed (that is, when the carry flag was "1" all the time), "Bad file name ERROR" is displayed.
719
+
720
+ When the actual input-output operations are done, the BASIC interpreter sets the device ID (0-3) in DEVICE (FD99H) and sets the request to the device in the A register (see [Table 5.6](#table-56--requests-to-the-device)), then calls the device expansion routine. The device expansion routine should refer to it to handle the request.
721
+
722
+
723
+ ##### _Figure 5.50 Input-output to the device expansion routine_
724
+
725
+ ```
726
+ ---------------------------------------------------------------------
727
+ | |
728
+ a) | Input setup when the interpreter calls routines to process |
729
+ | the expanded device |
730
+ | |
731
+ | OPEN "ABC:"... |
732
+ | |
733
+ | A register = FFH |
734
+ | CY flag = 1 +---- End of the file descriptor |
735
+ | | |
736
+ | ------------------------- |
737
+ | PROCNM | A | B | C | 00H | |
738
+ | ------------------------- |
739
+ | |
740
+ |-------------------------------------------------------------------|
741
+ | |
742
+ b) | Output setup when the expanded device was not processed |
743
+ | |
744
+ | CY flag = 1 |
745
+ | |
746
+ |-------------------------------------------------------------------|
747
+ | |
748
+ c) | Output setup when the expanded device was processed |
749
+ | |
750
+ | A register = device ID (0 to 3) |
751
+ | CY flag = 0 |
752
+ | |
753
+ ---------------------------------------------------------------------
754
+ ```
755
+
756
+ ##### _Table 5.6 Requests to the device_
757
+
758
+ ```
759
+ --------------------------------------
760
+ | Register A | Request |
761
+ |--------------+---------------------|
762
+ | 0 | OPEN |
763
+ |--------------+---------------------|
764
+ | 2 | CLOSE |
765
+ |--------------+---------------------|
766
+ | 4 | Random access |
767
+ |--------------+---------------------|
768
+ | 6 | Sequential output |
769
+ |--------------+---------------------|
770
+ | 8 | Sequential input |
771
+ |--------------+---------------------|
772
+ | 10 | LOC function |
773
+ |--------------+---------------------|
774
+ | 12 | LOF function |
775
+ |--------------+---------------------|
776
+ | 14 | EOF function |
777
+ |--------------+---------------------|
778
+ | 16 | FPOS function |
779
+ |--------------+---------------------|
780
+ | 18 | Backup character |
781
+ --------------------------------------
782
+ ```
783
+
784
+ ##### TEXT
785
+
786
+ These two bytes are text pointers of the BASIC program, when the BASIC program in the cartridge would be auto-started (executed at reset); otherwise they are 0000H. The size of the program must be under 16K bytes, 8000H to BFFFH.
787
+
788
+ The BASIC interpreter examines the contents of TEXT of the header after the initialization (INIT) and after the system is started. When they are not 0000H, it begins the execution from the address as BASIC text pointer (see [Figure 5.51](#figure-551--executing-basic-program-cartridge)). BASIC programs should be stored in the form of the intermediate code and the beginning of it (the address pointed by TEXT) must be 00H, which indicates the beginning of the program.
789
+
790
+ The execution speed of the program will be improved when the objective line number of statements such as GOTO is the absolute address of the objective text pointer.
791
+
792
+
793
+ ##### _Figure 5.51 Executing BASIC program cartridge_
794
+
795
+ ```
796
+ ---------------------
797
+ | | 8000H
798
+ |-------------------|
799
+ | TEXT |----+
800
+ |-------------------| |
801
+ | | |
802
+ | | |
803
+ |-------------------|<---+
804
+ | |
805
+ | BASIC program | The first byte must be 00H
806
+ | |
807
+ |-------------------|
808
+ | |
809
+ | |
810
+ | |
811
+ --------------------- BFFFH
812
+ ```
813
+
814
+ ##### How to place BASIC programs in ROM
815
+
816
+ 1. Change the starting address of BASIC text to 8021H.
817
+
818
+ ```
819
+ POKE &HF676,&H21 : POKE &HF677,&H80 : POKE &H8020,0 : NEW
820
+ ```
821
+
822
+ *Note:* these statements must be in one line.
823
+
824
+ 2. Load the objective BASIC program.
825
+
826
+ ```
827
+ LOAD "PROGRAM"
828
+ ```
829
+
830
+ 3. Create ID.
831
+
832
+ ```
833
+ AD = &H8000
834
+ FOR I = 0 TO 31 ----+
835
+ POKE AD + I, 0 | clears ID area
836
+ NEXT I ----+
837
+ POKE &H8000,ASC("A")
838
+ POKE &H8001,ASC("B")
839
+ POKE &H8008,&H20
840
+ POKE &H8009,&H80
841
+ ```
842
+
843
+ 4. Put 8000H to BFFFH in ROM.
844
+
845
+
846
+ <p>&nbsp;</p>
847
+
848
+ #### 7.3.2 notes on the creation of the cartridge software
849
+
850
+ In programs not requiring software from other cartridges (stand-alone software such as games), the portion with the smaller address than the work area used by BIOS (F380H) can be used freely.
851
+
852
+ But in programs which are executed by using BASIC interpreter functions, the same area cannot be shared as the work area. To do this, there are three methods:
853
+
854
+ 1. Place RAM on the cartridge itself (the safest and most reliable method).
855
+
856
+ 2. When one or two bytes are needed for the work area, use two bytes
857
+ corresponding to itself in SLTWRK (FD09H to ...) as the work area.
858
+
859
+ 3. When more than three bytes are needed for the work area, allocates it
860
+ from RAM used by BASIC. To do this, put the contents of BOTTOM (FC48H)
861
+ to the area corresponding to SLTWRK (FD09H to ...), and increase the
862
+ value of BOTTOM by the needed work area, then allocate it for the
863
+ work area (see [Figure 5.52](#figure-552--allocating-the-work-area)).
864
+
865
+
866
+ ##### _Figure 5.52 Allocating the work area_
867
+
868
+ ```
869
+ 8000H ----------------- <-- (BOTTOM) ----------------- <-- (SLTWRK)
870
+ | | | Work area |
871
+ | | |---------------| <-- (BOTTOM)
872
+ | User's area | | |
873
+ | | ---> | User's area |
874
+ | | | |
875
+ F380H |---------------| |---------------|
876
+ | System work | | System work |
877
+ FFFFH ----------------- -----------------
878
+ ```
879
+
880
+ See the following list for the reference of (2) and (3).
881
+
882
+
883
+ ##### _List 5.13 Example of allocating the work area_
884
+
885
+ ```
886
+ ;********************************************************
887
+ ; List 5.13 subroutines to support slot
888
+ ; for ROM in 1 page
889
+ ;********************************************************
890
+
891
+ RSLGREG EQU 0138H
892
+ EXPTBL EQU 0FCC1H
893
+ BOTTOM EQU 0FC48H
894
+ HIMEM EQU 0FC4AH
895
+ SLTWRK EQU 0FD09H
896
+
897
+ ;--------------------------------------------------------
898
+ ;
899
+ ; GTSL1 Get slot number of designated page
900
+ ; Entry None
901
+ ; Return A Slot address as follows
902
+ ; Modify Flags
903
+ ;
904
+ ; FxxxSSPP
905
+ ; | ||||
906
+ ; | ||++-- primary slot # (0-3)
907
+ ; | ++---- secondary slot # (0-3)
908
+ ; | 00 if not expanded
909
+ ; +--------- 1 if secondary slot # specified
910
+ ;
911
+ ; This value can later be used as an input parameter
912
+ ; for the RDSLT, WRSLT, CALSLT, ENASLT and 'RST 10H'
913
+ ;
914
+ PUBLIC GTSL10
915
+ GETSL10:
916
+ PUSH HL ;Save registers
917
+ PUSH DE
918
+
919
+ CALL RSLREG ;read primary slot #
920
+ RRCA
921
+ RRCA
922
+ AND 11B ;[A]=000000PP
923
+ LD E,A
924
+ LD D,0 ;[DE]=000000PP
925
+ LD HL,EXPTBL
926
+ ADD HL,DE :[HL]=EXPTBL+000000PP
927
+ LD E,A ;[E]=000000PP
928
+ LD A,(HL) ;A=(EXPTBL+000000PP)
929
+ AND 80H ;Use only MSB
930
+ JR Z,GTSL1NOEXP
931
+ OR E ;[A]=F00000PP
932
+ LD E,A ;save primary slot number
933
+ INC HL ;point to SLTTBL entry
934
+ INC HL
935
+ INC HL
936
+ INC HL
937
+ LD A,(HL) ;get current expansion slot register
938
+ RRCA
939
+ RRCA
940
+ AND 11B ;[A] = 000000SS
941
+ RLCA
942
+ RLCA ;[A] = 0000SS00
943
+ OR E ;[A] = F000SSPP
944
+ ;
945
+ GTSL1END:
946
+ POP DE
947
+ POP HL
948
+ RET
949
+ GTSL1NOEXP:
950
+ LD A,E ;[A] = 000000PP
951
+ JR GTSL1END
952
+
953
+
954
+ ;--------------------------------------------------------
955
+ ;
956
+ ; ASLW1 Get address of slot work
957
+ ; Entry None
958
+ ; Return HL address of slot work
959
+ ; Modify None
960
+ ;
961
+ PUBLIC ASLW10
962
+ ASLW10:
963
+ PUSH DE
964
+ PUSH AF
965
+ CALL GTSL10 ;[A] = F000SSPP, SS = 00 if not expanded
966
+ AND 00001111B ;[A] = 0000SSPP
967
+ LD L,A :[A] = 0000SSPP
968
+ RLCA
969
+ RLCA
970
+ RLCA
971
+ RLCA ;[A] = SSPP0000
972
+ AND 00110000B ;[A] = 00PP0000
973
+ OR L ;[A] = 00PPSSPP
974
+ AND 00111100B ;[A] = 00PPSS00
975
+ OR 01B ;[A] = 00PPSSBB
976
+ ;
977
+ ; Now, we have the sequence number for this cartridge
978
+ ; as follows.
979
+ ;
980
+ ; 00PPSSBB
981
+ ; ||||||
982
+ ; ||||++-- higher 2 bits of memory address (1)
983
+ ; ||++---- seconday slot # (0..3)
984
+ ; ++------ primary slot # (0..3)
985
+ ;
986
+ RLCA ;*=2
987
+ LD E,A
988
+ LD D,0 ;[DE] = 0PPSSBB0
989
+ LD HL,SLTWRK
990
+ ADD HL,DE
991
+ POP AF
992
+ POP DE
993
+ RET
994
+
995
+
996
+ ;--------------------------------------------------------
997
+ ;
998
+ ; RSLW1 Read slot work
999
+ ; Entry None
1000
+ ; Return HL Content of slot work
1001
+ ; Modify None
1002
+ ;
1003
+ PUBLIC RSLW10
1004
+ RSLW10:
1005
+ PUSH DE
1006
+ CALL ASLW10 ;[HL] = address of slot work
1007
+ LD E,(HL)
1008
+ INC HL
1009
+ LD D,(HL) ;[DE] = (slot work)
1010
+ EX DE,HL ;[HL] = (slot work)
1011
+ POP DE
1012
+ RET
1013
+
1014
+
1015
+ ;--------------------------------------------------------
1016
+ ;
1017
+ ; WSLW1 Write slot work
1018
+ ; Entry HL Data to write
1019
+ ; Return None
1020
+ ; Modify None
1021
+ ;
1022
+ PUBLIC WSLW10
1023
+ WSLW10:
1024
+ PUSH DE
1025
+ EX DE,HL ;[DE] = data to write
1026
+ CALL ASLW10 ;[HL] = address of slot work
1027
+ LD (HL),E
1028
+ INC HL
1029
+ LD (HL),D
1030
+ EX DE,HL ;[HL] = data tow write
1031
+ POP DE
1032
+ RET
1033
+
1034
+
1035
+ ;--------------------------------------------------------
1036
+ ;
1037
+ ; How to allocate work area for cartridges
1038
+ ; If the work area is greater than 2 bytes, make the SLTWRK point
1039
+ ; to the system variable BOTTOM (0FC48H), then update it by the
1040
+ ; amount of memory required. BOTTOM is set up by the initizalization
1041
+ ; code to point to the bottom of equipped RAM.
1042
+ ;
1043
+ ; Ex, if the program is at 4000H..7FFFH.
1044
+ ;
1045
+ ; WORKB allocate work area from BOTTOM
1046
+ ; (my slot work) <- (old BOTTOM)
1047
+ ; Entry HL required memory size
1048
+ ; Return HL start address of my work area = old BOTTOM
1049
+ ; 0 if cannot allocate
1050
+ ; Modify None
1051
+ ;
1052
+ PUBLIC WORKB0
1053
+ WORKB0:
1054
+ PUSH DE
1055
+ PUSH BC
1056
+ PUSH AF
1057
+
1058
+ EX DE,HL ;[DE] = Size
1059
+ LD HL,(BOTTOM) ;Get current RAM bottom
1060
+ CALL WSLW10 ;Save BOTTOM to slot work
1061
+ PUSH HL ;Save old BOTTOM
1062
+ ADD HL,DE ;[HL] = (BOTTOM) + SIZE
1063
+ LD A,H ;Beyond 0DFFFH?
1064
+ CP 0E0H
1065
+ JR NC,NOROOM ;Yes, cannot allocate this much
1066
+ LD (BOTTOM),HL ;Updtae (BOTTOM)
1067
+ POP HL ;[HL] = old BOTTOM
1068
+ WORKBEND:
1069
+ POP AF
1070
+ POP BC
1071
+ POP DE
1072
+ RET
1073
+ ;
1074
+ ; BOTTOM became greater than 0DFFFH, there is
1075
+ ; no RAM to be allocated.
1076
+ ;
1077
+ NOROOM:
1078
+ LD HL,0
1079
+ CALL WSLW10 ;Clear slot work
1080
+ JR WORKBEND ;Return 0 in [HL]
1081
+
1082
+ END
1083
+ ```
1084
+
1085
+
1086
+ ##### Hook
1087
+
1088
+ The area called "hook" is used for expanding BASIC functions in FD9AH to FFC9H of the work area used by MSX-BASIC. One hook has five bytes, which are normally "RET".
1089
+
1090
+ When MSX-BASIC does a certain operation (such as the one in the description about the hook of the work area), it calls this hook from there once. When the hook is "RET", the control returns immediately; but the function of BASIC can be expanded, when these five bytes were re-written to do the inter-slot call to the program inside the cartridge by the initialization routine (INIT) (see [Figure 5.53](#figure-553--setting-the-hook)).
1091
+
1092
+ [List 5.14](#list-514--using-the-hook) shows an example of the program that the cartridge uses to hook H.KEYI for the timer interrupt ptocess.
1093
+
1094
+
1095
+ ##### _Figure 5.53 Setting the hook_
1096
+
1097
+ ```
1098
+ BASIC internal routine HOOK -----------------
1099
+ . +-----> | RET |
1100
+ . | +--- |---------------|
1101
+ . | | | RET |
1102
+ CALL HOOK ------+ | |---------------|
1103
+ . <--------+ | RET |
1104
+ . |---------------|
1105
+ . | RET |
1106
+ |---------------|
1107
+ | RET |
1108
+ -----------------
1109
+
1110
+ |
1111
+ V
1112
+ Interslot call
1113
+ BASIC internal routine HOOK ----------------- -----> .
1114
+ . +-----> | RST 30H | .
1115
+ . | |---------------| .
1116
+ . | | Slot number | Expanded process
1117
+ CALL HOOK ------+ |---------------| .
1118
+ . <-----+ | Branch | .
1119
+ . | |- address -| .
1120
+ . | | | .
1121
+ | |---------------| .
1122
+ +------ | RET | <---- RET
1123
+ -----------------
1124
+ ```
1125
+
1126
+ ##### _List 5.14 Using the hook_
1127
+
1128
+ ```
1129
+ ;********************************************************
1130
+ ; List 5.14 Sample program to use HOOK
1131
+ ;********************************************************
1132
+ ;
1133
+ ; Start-up initialize entry
1134
+ ; This program will be called when system initializing.
1135
+ ;
1136
+ H.KEYI EQU 0FD9AH ; interrupt hook
1137
+ EXPTBL EQU 0FCC1H ; slots expanded or not
1138
+ PSLTRG EQU 0A8H ; I/O port address of primary slot register
1139
+ EXT MYINT
1140
+
1141
+ INIT:
1142
+ ; <<< Please insert other initialization routine here, if you need. >>>
1143
+
1144
+ ; Set interrupt entry
1145
+
1146
+ DI ; start of critical region
1147
+
1148
+ ; Get old interrupt entry inter-slot call hook
1149
+
1150
+ LD DE,OLDINT ; get address of old int. hook saved area
1151
+ LD HL,H.KEYI ; get address of interrupt entry hook
1152
+ LD BC,5 ; lenght of hook is 5 bytes
1153
+ LDIR ; transfer
1154
+
1155
+ ; Which slot address is this cartridge placed?
1156
+
1157
+ CALL GETMSLT ; get my slot address
1158
+
1159
+ ; Set new inter-slot call of interrupt entry
1160
+
1161
+ LD (H.KEYI+1),A ; set slot address
1162
+ LD A,0F7H ; 'RST 30H' inter-slot call operation code
1163
+ LD (H.KEYI),A ; set new hook op-code
1164
+ LD HL,INTENT ; get our interrupt entry point
1165
+ LD (H.KEYI+2),HL ; set new interrupt entry point
1166
+ LD A,0C9H ; 'RET' operation code
1167
+ LD (H.KEYI+4),A ; set operation code of 'RET'
1168
+ EI ; end of critical region
1169
+ RET
1170
+
1171
+
1172
+ ;--------------------------------------------------------
1173
+ ; Which slot address is the cartridge placed?
1174
+ ; Entry: No
1175
+ ; Action: Compute my slot address
1176
+ ; Return: A = slot address
1177
+ ; Modify: Flag
1178
+
1179
+ GTMSLT:
1180
+ PUSH BC ; save environment
1181
+ PUSH HL
1182
+ IN A,(PSLTRG) ; read primary slot register
1183
+ RRCA ; move it to bit 0,1 of A
1184
+ RRCA
1185
+ AND 00000011B ; get bit 1,0
1186
+ LD C,A ; set primary slot No.
1187
+ LD B,0
1188
+ LD HL,EXPTBL ; see if the slot is expanded or not
1189
+ ADD HL,BC
1190
+ OR (HL) ; set MSB if so
1191
+ LD C,A
1192
+ INC HL ; point to SLTTBL entry
1193
+ INC HL
1194
+ INC HL
1195
+ INC HL
1196
+ LD A,(HL) ; get what is currently output to
1197
+ ; expansion slot register
1198
+
1199
+ AND 00001100B ; get bits 3,2
1200
+ OR C ; finally form slot address
1201
+
1202
+ POP HL ; restore environment
1203
+ POP BC
1204
+ RET ; return to main
1205
+
1206
+ ;----- Interrupt entry -----
1207
+
1208
+ INTENT:
1209
+ CALL MYINT ; call interrupt handler
1210
+ JP OLDINT ; go to old interrupt handler
1211
+
1212
+ ;----- HOOK save area -----
1213
+
1214
+ OLDINT: DS 5
1215
+
1216
+ END
1217
+ ```
1218
+
1219
+
1220
+ ##### Stack pointer initialisation
1221
+
1222
+ When MSX has an internal disk, sometimes the disk interface ROM does the initialisation before the cartridge does, depending on the slot location, and pushes down the stack pointer in the direction of the low order address to allocate the work area. In this case, software not using the disk should set the stack pointer again after the cartridge received control; otherwise, the stack area might be exhausted and a system crash might occur. Remember to initialise the stack pointer at the beginning of the program.
1223
+
1224
+
1225
+ ##### Testing the performance of the expansion slot
1226
+
1227
+ When general software in the market is put in the expansion slot or when RAM resides in the expansion slot, sometimes the application program do not work. Since most MSX2 machines use the expansion slot inside, problems may sometime result. Software to be sold in the market should be thoroughly tested in both cases that it is put in the expansion slot and that RAM resides in expansion slot.
1228
+
1229
+ Since the expansion slot register is placed in FFFFH, do not use it as if it were RAM. For example, setting the stack in FFFFH using "LD SP, 0" in the program causes machines using the expansion slot to go out of control.
1230
+
1231
+
1232
+ ##### Notes on CALSLT use
1233
+
1234
+ Executing the inter-slot call in CALSLT and CALLF destroys the contents of IX, IY, and the background processing register. When returning from this routine, in MSX1 the interrupt is inhibited, but in MSX2 the state before the call is restored.
1235
+
1236
+ When using CALSLT or CALLF to execute the inter-slot call, the interrupt is always inhibited when calling the object program (see 2 in the figure below) and when returning to the calling program (see 6 below).
1237
+
1238
+ ```
1239
+ Caller Interslot call Called
1240
+
1241
+ LD IY,SLOT (3)
1242
+ +-----------------> CALLME:
1243
+ LD IX,CALLME | .
1244
+ (1) |(2) .
1245
+ CALL CALSLT ------------------+ .
1246
+ (4) .
1247
+ +------------------ RET
1248
+ (6) |(5)
1249
+ <-----------------+
1250
+ ```
1251
+
1252
+ In MSX2, the state of the interrupt is reserved before and after the inter-slot call. That is, 3 in the figure is in the same state as 1, and 6 is in the same state as 4. Note when the called program executes "EI" or "DI".
1253
+
1254
+
1255
+ ## Changes from the original
1256
+
1257
+ - In description of [SUBROM](#subrom-015chmain---call-specified-address-in-sub-rom) routine, comment "see page 352" has been changed to "see appendix 2..."
1258
+
1259
+ - In description of SLTATR and SLTWRK [work areas](#723-work-area-to-obtain-the-slot-status), expressions for calculate the concrete work area for a given slot and page have been added.
1260
+
1261
+ - In the first line after beginning of [section 7.2.3](#723-work-area-to-obtain-the-slot-status), "The following routines..." has been corrected to "The following addresses..."
1262
+
1263
+ - In [Figure 5.52](#figure-552--allocating-the-work-area), indication of F380H address was placed in the middle of the user's area. It has been moved to the beginning of system work.