JSW48 uses 6-bit room numbers, giving rooms 0 to 63, with
room 0 in memory at &C000
. However, the only place where
this is fixed is the code that fetches a room into the room buffer and the
object location table. The current room variable and the room exits in the
room data are all 8-bit values.
This patches the code to allow 7-bit room numbers to increase the number of
rooms that can be used. Rooms.hex is an Intel Hex
patchfile that can be applied to the original JSW48 game engine.
The room fetching code uses OR &C0
to map a room number
from 0 to 63 to an address from &C0xx
to
&FFxx
. This could be changed to ADD &C0
to
use the whole 8-bit value, mapping rooms 192 to 255 to the spare memory
within the code. I chose to change it to XOR &C0
, as this
maps the spare memory to rooms 64 to 127, running on from the existing 0 to
63. Also, a 7-bit room number is easier to fit into an extended object
table.
Patching with POKE 35093,238
gives the following change:
Original code: Changed to:
8912 3A 20 84 LD A,(&8420) 8912 3A 20 84 LD A,(&8420)
8915 F6 C0 OR &C0 8915 EE C0 XOR &C0
This gives 8-bit room numbers, mapped to the following areas of memory:
Room numbers
| Memory
|
0 - 63
| &C000 - &FFFF
|
64 - 127
| &8000 - &BFFF
|
128 - 192
| &4000 - &7FFF
|
192 - 255
| &0000 - &3FFF
|
Rooms 192 to 255 are obviously unusable as they map to memory occupied by
ROM. Rooms 128 to 192 map to memory used by the screen and screen buffers.
Unused space in the code between &8000
and
&BFFF
becomes available as follows:
Address
| Room
| Previous use
|
&9700
| 87
| Unused reset code
|
&9B00
| 91
| Sprites and attributes for password entry
|
&9E00 &9F00
| 94 95
| Password codes unused
|
&A700 &A800 &A900 &AA00
| 103 104 105 106
| unused unused unused unused
|
To be able to use room 91 and room 94, the password code from
&869F
to &87C9
needs to be bypassed. This
makes this space available for patches, etc. Along with rooms 47, 61, 62 and
63, which are unused in the original JSW, this gives an additional 12 rooms
that the game engine can use, making a total of 72.
Extending the object table
As the object table uses 6-bit room numbers, rooms 0+x appear to have the
same objects in them as rooms 64+x.
The code that deals with the object table needs to be modified to allow
7-bit room numbers.
This change allows room editors to use exactly the same object table as
before. The 6-bit object table holds the room number in the bottom six
bits, and bit 8 of the object position in bit 7. Bit 6 is overwritten by
the game engine to hold the "object collected" flag. This modification moves
that flag to bit 6 of the bytes in page &A6, so allowing the room number to
be held in bit 0 to bit 6 of &A4xx.
The first half of page &A6xx holds the toilet sprites. If there are more
than 128 objects, the toilet sprites at &A600 to &A67F need to be moved.
Patching with:
POKE 32769,166 POKE 37842,166
POKE 37847,203 POKE 37848,118 POKE 37849,40
POKE 37850,119 POKE 37851,37 POKE 37852,37
POKE 37853,205 POKE 37854,244 POKE 37855,150
POKE 37867,36
POKE 37950,122 POKE 37951,0
POKE 38644,78 POKE 38645,203 POKE 38646,185
POKE 38647,58 POKE 38648,32 POKE 38649,132
POKE 38650,185 POKE 38651,200 POKE 38652,36
POKE 38653,36 POKE 38654,201
gives the following change:
Original code: Changed to:
8800 26 A4 LD H,&A4 8800 26 A6 LD H,&A6
93D1 26 A4 LD H,&A4 93D1 26 A6 LD H,&A6
93D7 4E LD C,(HL) 93D7 CB 76 BIT 6,(HL)
93D8 CB B9 RES 7,C 93D9 28 77 JR Z,&9452
93DA 3A 20 84 LD A,(&8420) 93DB 25 DEC H
93DD F6 40 OR &40 93DC 25 DEC H
93DF B9 CP C 93DD CD F4 96 CALL &96F4
93EB 25 DEC H 93EB 24 INC H
943E 7E LD A,(HL) 943E 7A LD A,D
943F 07 RLCA 943F 00 NOP
96F4 Spare code space 96F4 4E LD C,(HL)
96F5 CB B9 RES 7,C
96F7 3A 20 84 LD A,(&8420)
96FA B9 CP C
96FB C8 RET Z
96FC 24 INC H
96FD 24 INC H
96FE C9 RET
The JSW48 object table remains in memory from &A3FF to &A5FF:
&A3FF holds 255-number of objects to collect.
&A4xx holds the room number in bits 0-6 and bit 8 of the object position (x+32*y) in bit 7.
&A5xx holds bits 0-7 of the object position.
&A6xx now holds the object collected flags in bit 6 instead of in the object table.